mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Client now sends player click if server supports it. Still incorrectly misses some clicks.
This commit is contained in:
parent
fa30faf812
commit
ed37fab04a
@ -39,7 +39,7 @@
|
|||||||
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
|
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<RegisterForComInterop>False</RegisterForComInterop>
|
<RegisterForComInterop>False</RegisterForComInterop>
|
||||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||||
<BaseAddress>4194304</BaseAddress>
|
<BaseAddress>4194304</BaseAddress>
|
||||||
@ -65,7 +65,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug_DX32' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug_DX32' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<OutputPath>output\debug\</OutputPath>
|
<OutputPath>output\debug\</OutputPath>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>Full</DebugType>
|
<DebugType>Full</DebugType>
|
||||||
|
@ -32,7 +32,10 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte GetClosetPlayer( Vector3 eyePos, Vector3 dir ) {
|
public byte GetClosetPlayer( Game game ) {
|
||||||
|
Player localP = game.LocalPlayer;
|
||||||
|
Vector3 eyePos = localP.EyePosition;
|
||||||
|
Vector3 dir = Utils.GetDirVector( localP.YawRadians, localP.PitchRadians );
|
||||||
float closestDist = float.PositiveInfinity;
|
float closestDist = float.PositiveInfinity;
|
||||||
byte targetId = 255;
|
byte targetId = 255;
|
||||||
|
|
||||||
|
@ -30,10 +30,20 @@ namespace ClassicalSharp {
|
|||||||
Mouse.ButtonUp += MouseButtonUp;
|
Mouse.ButtonUp += MouseButtonUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool[] buttonsDown = new bool[3];
|
||||||
void MouseButtonUp( object sender, MouseButtonEventArgs e ) {
|
void MouseButtonUp( object sender, MouseButtonEventArgs e ) {
|
||||||
if( activeScreen == null || !activeScreen.HandlesMouseUp( e.X, e.Y, e.Button ) ) {
|
if( activeScreen == null || !activeScreen.HandlesMouseUp( e.X, e.Y, e.Button ) ) {
|
||||||
|
if( SendPlayerClick( e.Button ) && buttonsDown[(int)e.Button] ) {
|
||||||
|
byte targetId = Players.GetClosetPlayer( this );
|
||||||
|
Network.SendPlayerClick( e.Button, false, targetId, SelectedPos );
|
||||||
|
buttonsDown[(int)e.Button] = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SendPlayerClick( MouseButton button ) {
|
||||||
|
return Network.UsingPlayerClick && button <= MouseButton.Middle;
|
||||||
|
}
|
||||||
|
|
||||||
void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
|
void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
|
||||||
if( activeScreen == null || !activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) {
|
if( activeScreen == null || !activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) {
|
||||||
@ -121,12 +131,14 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
DateTime lastClick = DateTime.MinValue;
|
DateTime lastClick = DateTime.MinValue;
|
||||||
void PickBlocks( bool cooldown, bool left, bool right, bool middle ) {
|
void PickBlocks( bool cooldown, bool left, bool right, bool middle ) {
|
||||||
int buttonsDown = ( left ? 1 : 0 ) + ( right ? 1 : 0 ) + ( middle ? 1 : 0 );
|
|
||||||
if( !SelectedPos.Valid || buttonsDown > 1 || ScreenLockedInput || HeldBlock == Block.Air ) return;
|
|
||||||
DateTime now = DateTime.UtcNow;
|
DateTime now = DateTime.UtcNow;
|
||||||
double delta = ( now - lastClick ).TotalMilliseconds;
|
double delta = ( now - lastClick ).TotalMilliseconds;
|
||||||
if( cooldown && delta < 250 ) return; // 4 times per second
|
if( cooldown && delta < 250 ) return; // 4 times per second
|
||||||
lastClick = now;
|
lastClick = now;
|
||||||
|
ButtonStateChanged( !cooldown, left, right, middle );
|
||||||
|
|
||||||
|
int buttonsDown = ( left ? 1 : 0 ) + ( right ? 1 : 0 ) + ( middle ? 1 : 0 );
|
||||||
|
if( !SelectedPos.Valid || buttonsDown > 1 || ScreenLockedInput || HeldBlock == Block.Air ) return;
|
||||||
|
|
||||||
if( middle ) {
|
if( middle ) {
|
||||||
Vector3I pos = SelectedPos.BlockPos;
|
Vector3I pos = SelectedPos.BlockPos;
|
||||||
@ -154,6 +166,19 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ButtonStateChanged( bool fromClick, bool left, bool right, bool middle ) {
|
||||||
|
if( !Network.UsingPlayerClick ) return;
|
||||||
|
|
||||||
|
byte targetId = Players.GetClosetPlayer( this );
|
||||||
|
for( int i = 0; i < buttonsDown.Length; i++ ) {
|
||||||
|
if( !buttonsDown[i] ) continue;
|
||||||
|
|
||||||
|
if( !fromClick )
|
||||||
|
Network.SendPlayerClick( (MouseButton)i, false, targetId, SelectedPos );
|
||||||
|
Network.SendPlayerClick( (MouseButton)i, true, targetId, SelectedPos );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal bool CanPick( byte block ) {
|
internal bool CanPick( byte block ) {
|
||||||
return !( block == 0 || ( BlockInfo.IsLiquid( block ) && !CanPlace[block] && !CanDelete[block] ) );
|
return !( block == 0 || ( BlockInfo.IsLiquid( block ) && !CanPlace[block] && !CanDelete[block] ) );
|
||||||
}
|
}
|
||||||
|
10
Game/Game.cs
10
Game/Game.cs
@ -238,7 +238,7 @@ namespace ClassicalSharp {
|
|||||||
bool middle = IsMousePressed( MouseButton.Middle );
|
bool middle = IsMousePressed( MouseButton.Middle );
|
||||||
PickBlocks( true, left, right, middle );
|
PickBlocks( true, left, right, middle );
|
||||||
} else {
|
} else {
|
||||||
SelectedPos.Valid = false;
|
SelectedPos.SetAsInvalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics.Mode2D( Width, Height );
|
Graphics.Mode2D( Width, Height );
|
||||||
@ -325,6 +325,14 @@ namespace ClassicalSharp {
|
|||||||
screen.Window = this;
|
screen.Window = this;
|
||||||
screen.Init();
|
screen.Init();
|
||||||
}
|
}
|
||||||
|
if( Network.UsingPlayerClick ) {
|
||||||
|
byte targetId = Players.GetClosetPlayer( this );
|
||||||
|
for( int i = 0; i < buttonsDown.Length; i++ ) {
|
||||||
|
if( !buttonsDown[i] ) continue;
|
||||||
|
Network.SendPlayerClick( (MouseButton)i, false, targetId, SelectedPos );
|
||||||
|
buttonsDown[i] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCamera( bool thirdPerson ) {
|
public void SetCamera( bool thirdPerson ) {
|
||||||
|
@ -70,6 +70,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId, PickedPos pos ) {
|
public void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId, PickedPos pos ) {
|
||||||
Player p = Window.LocalPlayer;
|
Player p = Window.LocalPlayer;
|
||||||
|
Console.WriteLine( "CLICK: " + button + "," + buttonDown );
|
||||||
MakePlayerClick( (byte)button, buttonDown, p.YawDegrees, p.PitchDegrees, targetId,
|
MakePlayerClick( (byte)button, buttonDown, p.YawDegrees, p.PitchDegrees, targetId,
|
||||||
pos.BlockPos, pos.BlockFace );
|
pos.BlockPos, pos.BlockFace );
|
||||||
}
|
}
|
||||||
|
@ -80,9 +80,7 @@ namespace ClassicalSharp {
|
|||||||
float dz = Math.Min( Math.Abs( origin.Z - min.Z ), Math.Abs( origin.Z - max.Z ) );
|
float dz = Math.Min( Math.Abs( origin.Z - min.Z ), Math.Abs( origin.Z - max.Z ) );
|
||||||
|
|
||||||
if( dx * dx + dy * dy + dz * dz > reachSquared ) {
|
if( dx * dx + dy * dy + dz * dz > reachSquared ) {
|
||||||
pickedPos.BlockPos = Vector3I.MinusOne;
|
pickedPos.SetAsInvalid();
|
||||||
pickedPos.BlockFace = (CpeBlockFace)255;
|
|
||||||
pickedPos.Valid = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +89,8 @@ namespace ClassicalSharp {
|
|||||||
// since some blocks do not occupy a whole cell.
|
// since some blocks do not occupy a whole cell.
|
||||||
float t0, t1;
|
float t0, t1;
|
||||||
if( Intersection.RayIntersectsBox( origin, dir, min, max, out t0, out t1 ) ) {
|
if( Intersection.RayIntersectsBox( origin, dir, min, max, out t0, out t1 ) ) {
|
||||||
pickedPos.UpdateBlockPos( min, max, origin, dir, t0, t1 );
|
Vector3 intersect = origin + dir * t0;
|
||||||
|
pickedPos.SetAsValid( min, max, intersect );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,14 +123,13 @@ namespace ClassicalSharp {
|
|||||||
public bool Valid = true;
|
public bool Valid = true;
|
||||||
public CpeBlockFace BlockFace;
|
public CpeBlockFace BlockFace;
|
||||||
|
|
||||||
public void UpdateBlockPos( Vector3 p1, Vector3 p2, Vector3 origin, Vector3 dir, float t0, float t1 ) {
|
public void SetAsValid( Vector3 min, Vector3 max, Vector3 intersect ) {
|
||||||
Min = Vector3.Min( p1, p2 );
|
Min = min;
|
||||||
Max = Vector3.Max( p1, p2 );
|
Max = max;
|
||||||
BlockPos = Vector3I.Truncate( Min );
|
BlockPos = Vector3I.Truncate( Min );
|
||||||
Valid = true;
|
Valid = true;
|
||||||
|
|
||||||
Vector3I normal = Vector3I.Zero;
|
Vector3I normal = Vector3I.Zero;
|
||||||
Vector3 intersect = origin + dir * t0;
|
|
||||||
float dist = float.PositiveInfinity;
|
float dist = float.PositiveInfinity;
|
||||||
TestAxis( intersect.X - Min.X, ref dist, -Vector3I.UnitX, ref normal, CpeBlockFace.XMin );
|
TestAxis( intersect.X - Min.X, ref dist, -Vector3I.UnitX, ref normal, CpeBlockFace.XMin );
|
||||||
TestAxis( intersect.X - Max.X, ref dist, Vector3I.UnitX, ref normal, CpeBlockFace.XMax );
|
TestAxis( intersect.X - Max.X, ref dist, Vector3I.UnitX, ref normal, CpeBlockFace.XMax );
|
||||||
@ -142,6 +140,12 @@ namespace ClassicalSharp {
|
|||||||
TranslatedPos = BlockPos + normal;
|
TranslatedPos = BlockPos + normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetAsInvalid() {
|
||||||
|
Valid = false;
|
||||||
|
BlockPos = TranslatedPos = Vector3I.MinusOne;
|
||||||
|
BlockFace = (CpeBlockFace)255;
|
||||||
|
}
|
||||||
|
|
||||||
void TestAxis( float dAxis, ref float dist, Vector3I nAxis, ref Vector3I normal,
|
void TestAxis( float dAxis, ref float dist, Vector3I nAxis, ref Vector3I normal,
|
||||||
CpeBlockFace fAxis) {
|
CpeBlockFace fAxis) {
|
||||||
dAxis = Math.Abs( dAxis );
|
dAxis = Math.Abs( dAxis );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user