mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
use volatile and interlocked instead of Thread.Volatile
This commit is contained in:
parent
d67e370c9a
commit
c5a19db3ba
@ -25,7 +25,7 @@ namespace MCGalaxy {
|
||||
public abstract class Entity {
|
||||
|
||||
// Raw orientation/position - access must be threadsafe
|
||||
int _rot;
|
||||
volatile uint _rot;
|
||||
long _pos;
|
||||
|
||||
// Last sent orientation/position, for delta calculation
|
||||
@ -46,14 +46,14 @@ namespace MCGalaxy {
|
||||
|
||||
/// <summary> Gets or sets the orientation of this entity. </summary>
|
||||
public Orientation Rot {
|
||||
get { return Orientation.Unpack(Thread.VolatileRead(ref _rot)); }
|
||||
set { Thread.VolatileWrite(ref _rot, value.Pack()); OnSetRot(); }
|
||||
get { return Orientation.Unpack(_rot); }
|
||||
set { _rot = value.Pack(); OnSetRot(); }
|
||||
}
|
||||
|
||||
/// <summary> Gets or sets the position of this entity. </summary>
|
||||
public Position Pos {
|
||||
get { return Position.Unpack(Thread.VolatileRead(ref _pos)); }
|
||||
set { Thread.VolatileWrite(ref _pos, value.Pack()); OnSetPos(); }
|
||||
get { return Position.Unpack(Interlocked.Read(ref _pos)); }
|
||||
set { Interlocked.Exchange(ref _pos, value.Pack()); OnSetPos(); }
|
||||
}
|
||||
|
||||
/// <summary> Sets only the yaw and pitch of the orientation of this entity. </summary>
|
||||
|
@ -43,7 +43,7 @@ namespace MCGalaxy {
|
||||
/// <summary> X block coordinate of this position. </summary>
|
||||
public int BlockX { get { return X >> 5; } }
|
||||
|
||||
/// <summary> T block coordinate of this position. </summary>
|
||||
/// <summary> Y block coordinate of this position. </summary>
|
||||
public int BlockY { get { return Y >> 5; } }
|
||||
|
||||
/// <summary> Z block coordinate of this position. </summary>
|
||||
@ -116,11 +116,11 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
internal int Pack() {
|
||||
return RotX | (RotY << 8) | (RotZ << 16) | (HeadX << 24);
|
||||
internal uint Pack() {
|
||||
return (uint)(RotX | (RotY << 8) | (RotZ << 16) | (HeadX << 24));
|
||||
}
|
||||
|
||||
internal static Orientation Unpack(int raw) {
|
||||
internal static Orientation Unpack(uint raw) {
|
||||
Orientation rot;
|
||||
rot.RotX = (byte)raw; rot.RotY = (byte)(raw >> 8);
|
||||
rot.RotZ = (byte)(raw >> 16); rot.HeadX = (byte)(raw >> 24);
|
||||
|
Loading…
x
Reference in New Issue
Block a user