mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
Only call PickingRender when PickedPos is valid, remove some leftover stuff from UpdateFrame, combine SendPlayerClick functions as one function.
This commit is contained in:
parent
273f4f5611
commit
152133d95c
@ -32,7 +32,6 @@ namespace ClassicalSharp {
|
||||
|
||||
void MouseButtonUp( object sender, MouseButtonEventArgs e ) {
|
||||
if( activeScreen == null || !activeScreen.HandlesMouseUp( e.X, e.Y, e.Button ) ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,8 @@ namespace ClassicalSharp {
|
||||
RenderPlayers( e.Time, t );
|
||||
ParticleManager.Render( e.Time, t );
|
||||
Camera.GetPickedBlock( SelectedPos ); // TODO: only pick when necessary
|
||||
Picking.Render( e.Time );
|
||||
if( SelectedPos.Valid )
|
||||
Picking.Render( e.Time, SelectedPos );
|
||||
EnvRenderer.Render( e.Time );
|
||||
MapRenderer.Render( e.Time );
|
||||
WeatherRenderer.Render( e.Time );
|
||||
|
@ -68,16 +68,10 @@ namespace ClassicalSharp {
|
||||
SendPacket();
|
||||
}
|
||||
|
||||
public void SendPlayerClick( MouseButton button, bool buttonDown, PickedPos pos ) {
|
||||
Player p = Window.LocalPlayer;
|
||||
MakePlayerClick( (byte)button, buttonDown, p.YawDegrees, p.PitchDegrees, 255,
|
||||
pos.BlockPos, pos.BlockFace );
|
||||
}
|
||||
|
||||
public void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId ) {
|
||||
public void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId, PickedPos pos ) {
|
||||
Player p = Window.LocalPlayer;
|
||||
MakePlayerClick( (byte)button, buttonDown, p.YawDegrees, p.PitchDegrees, targetId,
|
||||
new Vector3I( -100, -100, -100 ), 0 );
|
||||
pos.BlockPos, pos.BlockFace );
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
@ -679,13 +679,11 @@ namespace OpenTK
|
||||
get
|
||||
{
|
||||
EnsureUndisposed();
|
||||
GraphicsContext.Assert();
|
||||
return vsync;
|
||||
}
|
||||
set
|
||||
{
|
||||
EnsureUndisposed();
|
||||
GraphicsContext.Assert();
|
||||
Context.VSync = (vsync = value) != VSyncMode.Off;
|
||||
}
|
||||
}
|
||||
@ -733,11 +731,6 @@ namespace OpenTK
|
||||
/// </summary>
|
||||
public event EventHandler<EventArgs> Unload;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when it is time to update a frame.
|
||||
/// </summary>
|
||||
public event EventHandler<FrameEventArgs> UpdateFrame;
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
@ -770,22 +763,6 @@ namespace OpenTK
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUpdateFrame
|
||||
|
||||
/// <summary>
|
||||
/// Called when the frame is updated.
|
||||
/// </summary>
|
||||
/// <param name="e">Contains information necessary for frame updating.</param>
|
||||
/// <remarks>
|
||||
/// Subscribe to the <see cref="UpdateFrame"/> event instead of overriding this method.
|
||||
/// </remarks>
|
||||
protected virtual void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (UpdateFrame != null) UpdateFrame(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnWindowInfoChanged
|
||||
|
||||
/// <summary>
|
||||
@ -831,12 +808,6 @@ namespace OpenTK
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUpdateFrameInternal
|
||||
|
||||
private void OnUpdateFrameInternal(FrameEventArgs e) { if (Exists && !isExiting) OnUpdateFrame(e); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnWindowInfoChangedInternal
|
||||
|
||||
private void OnWindowInfoChangedInternal(EventArgs e)
|
||||
|
@ -105,20 +105,6 @@ namespace OpenTK.Graphics
|
||||
|
||||
#region --- Static Members ---
|
||||
|
||||
#region public static void Assert()
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a GraphicsContext exists in the calling thread and throws a GraphicsContextMissingException if it doesn't.
|
||||
/// </summary>
|
||||
/// <exception cref="GraphicsContextMissingException">Generated when no GraphicsContext is current in the calling thread.</exception>
|
||||
public static void Assert()
|
||||
{
|
||||
if (GraphicsContext.CurrentContext == null)
|
||||
throw new GraphicsContextMissingException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public static IGraphicsContext CurrentContext
|
||||
|
||||
internal delegate ContextHandle GetCurrentContextDelegate();
|
||||
|
@ -67,11 +67,6 @@ namespace OpenTK.Platform
|
||||
/// </summary>
|
||||
event EventHandler<EventArgs> Unload;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when it is time to update a frame.
|
||||
/// </summary>
|
||||
event EventHandler<FrameEventArgs> UpdateFrame;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when it is time to render a frame.
|
||||
/// </summary>
|
||||
|
@ -80,6 +80,8 @@ namespace ClassicalSharp {
|
||||
float dz = Math.Min( Math.Abs( origin.Z - min.Z ), Math.Abs( origin.Z - max.Z ) );
|
||||
|
||||
if( dx * dx + dy * dy + dz * dz > reachSquared ) {
|
||||
pickedPos.BlockPos = Vector3I.MinusOne;
|
||||
pickedPos.BlockFace = (CpeBlockFace)255;
|
||||
pickedPos.Valid = false;
|
||||
return;
|
||||
}
|
||||
|
@ -16,53 +16,49 @@ namespace ClassicalSharp.Renderers {
|
||||
vb = graphics.CreateDynamicVb( VertexFormat.Pos3fCol4b, verticesCount );
|
||||
}
|
||||
|
||||
FastColour col = FastColour.White;
|
||||
FastColour col = FastColour.White;
|
||||
int index = 0;
|
||||
const int verticesCount = 24 * ( 3 * 2 );
|
||||
VertexPos3fCol4b[] vertices = new VertexPos3fCol4b[verticesCount];
|
||||
const float size = 0.0625f;
|
||||
const float offset = 0.01f;
|
||||
|
||||
public void Render( double delta ) {
|
||||
public void Render( double delta, PickedPos pickedPos ) {
|
||||
index = 0;
|
||||
PickedPos pickedPos = window.SelectedPos;
|
||||
Vector3 p1 = pickedPos.Min - new Vector3( offset, offset, offset );
|
||||
Vector3 p2 = pickedPos.Max + new Vector3( offset, offset, offset );
|
||||
|
||||
if( pickedPos.Valid ) {
|
||||
Vector3 p1 = pickedPos.Min - new Vector3( offset, offset, offset );
|
||||
Vector3 p2 = pickedPos.Max + new Vector3( offset, offset, offset );
|
||||
|
||||
// bottom face
|
||||
DrawYPlane( p1.Y, p1.X, p1.Z, p1.X + size, p2.Z );
|
||||
DrawYPlane( p1.Y, p2.X, p1.Z, p2.X - size, p2.Z );
|
||||
DrawYPlane( p1.Y, p1.X, p1.Z, p2.X, p1.Z + size );
|
||||
DrawYPlane( p1.Y, p1.X, p2.Z, p2.X, p2.Z - size );
|
||||
// top face
|
||||
DrawYPlane( p2.Y, p1.X, p1.Z, p1.X + size, p2.Z );
|
||||
DrawYPlane( p2.Y, p2.X, p1.Z, p2.X - size, p2.Z );
|
||||
DrawYPlane( p2.Y, p1.X, p1.Z, p2.X, p1.Z + size );
|
||||
DrawYPlane( p2.Y, p1.X, p2.Z, p2.X, p2.Z - size );
|
||||
// left face
|
||||
DrawXPlane( p1.X, p1.Z, p1.Y, p1.Z + size, p2.Y );
|
||||
DrawXPlane( p1.X, p2.Z, p1.Y, p2.Z - size, p2.Y );
|
||||
DrawXPlane( p1.X, p1.Z, p1.Y, p2.Z, p1.Y + size );
|
||||
DrawXPlane( p1.X, p1.Z, p2.Y, p2.Z, p2.Y - size );
|
||||
// right face
|
||||
DrawXPlane( p2.X, p1.Z, p1.Y, p1.Z + size, p2.Y );
|
||||
DrawXPlane( p2.X, p2.Z, p1.Y, p2.Z - size, p2.Y );
|
||||
DrawXPlane( p2.X, p1.Z, p1.Y, p2.Z, p1.Y + size );
|
||||
DrawXPlane( p2.X, p1.Z, p2.Y, p2.Z, p2.Y - size );
|
||||
// front face
|
||||
DrawZPlane( p1.Z, p1.X, p1.Y, p1.X + size, p2.Y );
|
||||
DrawZPlane( p1.Z, p2.X, p1.Y, p2.X - size, p2.Y );
|
||||
DrawZPlane( p1.Z, p1.X, p1.Y, p2.X, p1.Y + size );
|
||||
DrawZPlane( p1.Z, p1.X, p2.Y, p2.X, p2.Y - size );
|
||||
// back face
|
||||
DrawZPlane( p2.Z, p1.X, p1.Y, p1.X + size, p2.Y );
|
||||
DrawZPlane( p2.Z, p2.X, p1.Y, p2.X - size, p2.Y );
|
||||
DrawZPlane( p2.Z, p1.X, p1.Y, p2.X, p1.Y + size );
|
||||
DrawZPlane( p2.Z, p1.X, p2.Y, p2.X, p2.Y - size );
|
||||
graphics.DrawDynamicVb( DrawMode.Triangles, vb, vertices, VertexFormat.Pos3fCol4b, verticesCount );
|
||||
}
|
||||
// bottom face
|
||||
DrawYPlane( p1.Y, p1.X, p1.Z, p1.X + size, p2.Z );
|
||||
DrawYPlane( p1.Y, p2.X, p1.Z, p2.X - size, p2.Z );
|
||||
DrawYPlane( p1.Y, p1.X, p1.Z, p2.X, p1.Z + size );
|
||||
DrawYPlane( p1.Y, p1.X, p2.Z, p2.X, p2.Z - size );
|
||||
// top face
|
||||
DrawYPlane( p2.Y, p1.X, p1.Z, p1.X + size, p2.Z );
|
||||
DrawYPlane( p2.Y, p2.X, p1.Z, p2.X - size, p2.Z );
|
||||
DrawYPlane( p2.Y, p1.X, p1.Z, p2.X, p1.Z + size );
|
||||
DrawYPlane( p2.Y, p1.X, p2.Z, p2.X, p2.Z - size );
|
||||
// left face
|
||||
DrawXPlane( p1.X, p1.Z, p1.Y, p1.Z + size, p2.Y );
|
||||
DrawXPlane( p1.X, p2.Z, p1.Y, p2.Z - size, p2.Y );
|
||||
DrawXPlane( p1.X, p1.Z, p1.Y, p2.Z, p1.Y + size );
|
||||
DrawXPlane( p1.X, p1.Z, p2.Y, p2.Z, p2.Y - size );
|
||||
// right face
|
||||
DrawXPlane( p2.X, p1.Z, p1.Y, p1.Z + size, p2.Y );
|
||||
DrawXPlane( p2.X, p2.Z, p1.Y, p2.Z - size, p2.Y );
|
||||
DrawXPlane( p2.X, p1.Z, p1.Y, p2.Z, p1.Y + size );
|
||||
DrawXPlane( p2.X, p1.Z, p2.Y, p2.Z, p2.Y - size );
|
||||
// front face
|
||||
DrawZPlane( p1.Z, p1.X, p1.Y, p1.X + size, p2.Y );
|
||||
DrawZPlane( p1.Z, p2.X, p1.Y, p2.X - size, p2.Y );
|
||||
DrawZPlane( p1.Z, p1.X, p1.Y, p2.X, p1.Y + size );
|
||||
DrawZPlane( p1.Z, p1.X, p2.Y, p2.X, p2.Y - size );
|
||||
// back face
|
||||
DrawZPlane( p2.Z, p1.X, p1.Y, p1.X + size, p2.Y );
|
||||
DrawZPlane( p2.Z, p2.X, p1.Y, p2.X - size, p2.Y );
|
||||
DrawZPlane( p2.Z, p1.X, p1.Y, p2.X, p1.Y + size );
|
||||
DrawZPlane( p2.Z, p1.X, p2.Y, p2.X, p2.Y - size );
|
||||
graphics.DrawDynamicVb( DrawMode.Triangles, vb, vertices, VertexFormat.Pos3fCol4b, verticesCount );
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
@ -9,6 +9,7 @@ namespace ClassicalSharp {
|
||||
public static Vector3I UnitX = new Vector3I( 1, 0, 0 );
|
||||
public static Vector3I UnitY = new Vector3I( 0, 1, 0 );
|
||||
public static Vector3I UnitZ = new Vector3I( 0, 0, 1 );
|
||||
public static Vector3I MinusOne = new Vector3I( -1, -1, -1 );
|
||||
|
||||
public int X, Y, Z;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user