mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Cleanup SelectionManager, don't show all 64 spaces in ChatInputWidget.
This commit is contained in:
parent
17d54a09d5
commit
c8061b64fd
@ -49,7 +49,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
for( int i = 0; i < index; i++ )
|
for( int i = 0; i < index; i++ )
|
||||||
TransformVertex( ref cache.vertices[i] );
|
TransformVertex( ref cache.vertices[i] );
|
||||||
game.Graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb,
|
game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb,
|
||||||
cache.vertices, index, index * 6 / 4 );
|
cache.vertices, index, index * 6 / 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ namespace ClassicalSharp {
|
|||||||
AddChar( 14, ref index );
|
AddChar( 14, ref index );
|
||||||
|
|
||||||
graphicsApi.BindTexture( posTexture.ID );
|
graphicsApi.BindTexture( posTexture.ID );
|
||||||
graphicsApi.DrawDynamicIndexedVb( DrawMode.Triangles,
|
graphicsApi.UpdateDynamicIndexedVb( DrawMode.Triangles,
|
||||||
game.ModelCache.vb, game.ModelCache.vertices, index, index * 6 / 4 );
|
game.ModelCache.vb, game.ModelCache.vertices, index, index * 6 / 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Texture chatInputTexture, caretTexture;
|
Texture chatInputTexture, caretTexture;
|
||||||
int caretPos = -1, typingLogPos = 0;
|
int caretPos = -1, typingLogPos = 0, defaultHeight;
|
||||||
public int YOffset;
|
public int YOffset;
|
||||||
internal WrappableStringBuffer chatInputText;
|
internal WrappableStringBuffer chatInputText;
|
||||||
readonly Font font, boldFont;
|
readonly Font font, boldFont;
|
||||||
@ -46,6 +46,7 @@ namespace ClassicalSharp {
|
|||||||
game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) :
|
game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) :
|
||||||
game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
||||||
chatInputText.WordWrap( ref parts, ref partLens, 64 );
|
chatInputText.WordWrap( ref parts, ref partLens, 64 );
|
||||||
|
defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height;
|
||||||
|
|
||||||
maxWidth = 0;
|
maxWidth = 0;
|
||||||
args = new DrawTextArgs( null, font, false );
|
args = new DrawTextArgs( null, font, false );
|
||||||
@ -85,7 +86,8 @@ namespace ClassicalSharp {
|
|||||||
Size trimmedSize = game.Drawer2D.MeasureChatSize( ref args );
|
Size trimmedSize = game.Drawer2D.MeasureChatSize( ref args );
|
||||||
caretTexture.X1 = 10 + trimmedSize.Width;
|
caretTexture.X1 = 10 + trimmedSize.Width;
|
||||||
|
|
||||||
args.Text = new String( parts[indexY][indexX], 1 );
|
string line = parts[indexY];
|
||||||
|
args.Text = indexX < line.Length ? new String( line[indexX], 1 ) : " ";
|
||||||
Size charSize = game.Drawer2D.MeasureChatSize( ref args );
|
Size charSize = game.Drawer2D.MeasureChatSize( ref args );
|
||||||
caretTexture.Width = charSize.Width;
|
caretTexture.Width = charSize.Width;
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ namespace ClassicalSharp {
|
|||||||
totalHeight += sizes[i].Height;
|
totalHeight += sizes[i].Height;
|
||||||
Size size = new Size( maxWidth, totalHeight );
|
Size size = new Size( maxWidth, totalHeight );
|
||||||
|
|
||||||
int realHeight = 0, y = 0;
|
int realHeight = 0;
|
||||||
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
|
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
|
||||||
using( IDrawer2D drawer = game.Drawer2D ) {
|
using( IDrawer2D drawer = game.Drawer2D ) {
|
||||||
drawer.SetBitmap( bmp );
|
drawer.SetBitmap( bmp );
|
||||||
@ -115,15 +117,15 @@ namespace ClassicalSharp {
|
|||||||
drawer.DrawChatText( ref args, 0, realHeight );
|
drawer.DrawChatText( ref args, 0, realHeight );
|
||||||
realHeight += sizes[i].Height;
|
realHeight += sizes[i].Height;
|
||||||
}
|
}
|
||||||
y = game.Height - realHeight - YOffset;
|
chatInputTexture = drawer.Make2DTexture( bmp, size, 10, 0 );
|
||||||
chatInputTexture = drawer.Make2DTexture( bmp, size, 10, y );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
caretTexture.Y1 += y;
|
Height = realHeight == 0 ? defaultHeight : realHeight;
|
||||||
Y = y;
|
Y = game.Height - Height - YOffset;
|
||||||
Width = size.Width;
|
chatInputTexture.Y1 = Y;
|
||||||
Height = realHeight;
|
caretTexture.Y1 += Y;
|
||||||
|
Width = size.Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
|
@ -37,7 +37,7 @@ namespace ClassicalSharp.Particles {
|
|||||||
count = Math.Min( count, 1000 );
|
count = Math.Min( count, 1000 );
|
||||||
|
|
||||||
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
||||||
graphics.DrawDynamicIndexedVb( DrawMode.Triangles, vb, vertices, count, count * 6 / 4 );
|
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, count, count * 6 / 4 );
|
||||||
graphics.AlphaTest = false;
|
graphics.AlphaTest = false;
|
||||||
graphics.Texturing = false;
|
graphics.Texturing = false;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ namespace ClassicalSharp {
|
|||||||
api.texVerts[3] = new VertexPos3fTex2fCol4b( Utils.RotateY( x1, y2, 0, cosA, sinA ) + pos, u1, nameTex.V2, col );
|
api.texVerts[3] = new VertexPos3fTex2fCol4b( Utils.RotateY( x1, y2, 0, cosA, sinA ) + pos, u1, nameTex.V2, col );
|
||||||
|
|
||||||
api.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
api.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
||||||
api.DrawDynamicIndexedVb( DrawMode.Triangles, api.texVb, api.texVerts, 4, 6 );
|
api.UpdateDynamicIndexedVb( DrawMode.Triangles, api.texVb, api.texVerts, 4, 6 );
|
||||||
api.Texturing = false;
|
api.Texturing = false;
|
||||||
api.AlphaTest = false;
|
api.AlphaTest = false;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
return GetOrExpand( ref dynamicvBuffers, buffer, iBufferSize );
|
return GetOrExpand( ref dynamicvBuffers, buffer, iBufferSize );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawDynamicVb<T>( DrawMode mode, int vb, T[] vertices, int count ) {
|
public override void UpdateDynamicVb<T>( DrawMode mode, int vb, T[] vertices, int count ) {
|
||||||
int size = count * batchStride;
|
int size = count * batchStride;
|
||||||
DataBuffer buffer = dynamicvBuffers[vb];
|
DataBuffer buffer = dynamicvBuffers[vb];
|
||||||
buffer.SetData( vertices, size, LockFlags.Discard );
|
buffer.SetData( vertices, size, LockFlags.Discard );
|
||||||
@ -231,7 +231,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
device.DrawPrimitives( modeMappings[(int)mode], 0, NumPrimitives( count, mode ) );
|
device.DrawPrimitives( modeMappings[(int)mode], 0, NumPrimitives( count, mode ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawDynamicIndexedVb<T>( DrawMode mode, int vb, T[] vertices, int vCount, int indicesCount ) {
|
public override void UpdateDynamicIndexedVb<T>( DrawMode mode, int vb, T[] vertices, int vCount, int indicesCount ) {
|
||||||
int size = vCount * batchStride;
|
int size = vCount * batchStride;
|
||||||
DataBuffer buffer = dynamicvBuffers[vb];
|
DataBuffer buffer = dynamicvBuffers[vb];
|
||||||
buffer.SetData( vertices, size, LockFlags.Discard );
|
buffer.SetData( vertices, size, LockFlags.Discard );
|
||||||
|
@ -158,13 +158,13 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
/// draw calls will be in the given format. </summary>
|
/// draw calls will be in the given format. </summary>
|
||||||
public abstract void SetBatchFormat( VertexFormat format );
|
public abstract void SetBatchFormat( VertexFormat format );
|
||||||
|
|
||||||
/// <summary> Draws the specified subset of the vertices in the current dynamic vertex buffer<br/>
|
/// <summary> Binds and draws the specified subset of the vertices in the current dynamic vertex buffer<br/>
|
||||||
/// This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. </summary>
|
/// This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. </summary>
|
||||||
public abstract void DrawDynamicVb<T>( DrawMode mode, int vb, T[] vertices, int count ) where T : struct;
|
public abstract void UpdateDynamicVb<T>( DrawMode mode, int vb, T[] vertices, int count ) where T : struct;
|
||||||
|
|
||||||
/// <summary> Draws the specified subset of the vertices in the current dynamic vertex buffer<br/>
|
/// <summary> Binds and draws the specified subset of the vertices in the current dynamic vertex buffer<br/>
|
||||||
/// This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. </summary>
|
/// This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. </summary>
|
||||||
public abstract void DrawDynamicIndexedVb<T>( DrawMode mode, int vb, T[] vertices,
|
public abstract void UpdateDynamicIndexedVb<T>( DrawMode mode, int vb, T[] vertices,
|
||||||
int vCount, int indicesCount ) where T : struct;
|
int vCount, int indicesCount ) where T : struct;
|
||||||
|
|
||||||
/// <summary> Draws the specified subset of the vertices in the current vertex buffer. </summary>
|
/// <summary> Draws the specified subset of the vertices in the current vertex buffer. </summary>
|
||||||
@ -252,7 +252,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
quadVerts[2] = new VertexPos3fCol4b( x + width, y + height, 0, col );
|
quadVerts[2] = new VertexPos3fCol4b( x + width, y + height, 0, col );
|
||||||
quadVerts[3] = new VertexPos3fCol4b( x, y + height, 0, col );
|
quadVerts[3] = new VertexPos3fCol4b( x, y + height, 0, col );
|
||||||
SetBatchFormat( VertexFormat.Pos3fCol4b );
|
SetBatchFormat( VertexFormat.Pos3fCol4b );
|
||||||
DrawDynamicIndexedVb( DrawMode.Triangles, quadVb, quadVerts, 4, 6 );
|
UpdateDynamicIndexedVb( DrawMode.Triangles, quadVb, quadVerts, 4, 6 );
|
||||||
}
|
}
|
||||||
|
|
||||||
internal VertexPos3fTex2fCol4b[] texVerts = new VertexPos3fTex2fCol4b[4];
|
internal VertexPos3fTex2fCol4b[] texVerts = new VertexPos3fTex2fCol4b[4];
|
||||||
@ -270,7 +270,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
texVerts[2] = new VertexPos3fTex2fCol4b( x2, y2, 0, tex.U2, tex.V2, col );
|
texVerts[2] = new VertexPos3fTex2fCol4b( x2, y2, 0, tex.U2, tex.V2, col );
|
||||||
texVerts[3] = new VertexPos3fTex2fCol4b( x1, y2, 0, tex.U1, tex.V2, col );
|
texVerts[3] = new VertexPos3fTex2fCol4b( x1, y2, 0, tex.U1, tex.V2, col );
|
||||||
SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
||||||
DrawDynamicIndexedVb( DrawMode.Triangles, texVb, texVerts, 4, 6 );
|
UpdateDynamicIndexedVb( DrawMode.Triangles, texVb, texVerts, 4, 6 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Make2DQuad( TextureRec xy, TextureRec uv,
|
public static void Make2DQuad( TextureRec xy, TextureRec uv,
|
||||||
|
@ -230,7 +230,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int batchStride;
|
int batchStride;
|
||||||
public override void DrawDynamicVb<T>( DrawMode mode, int id, T[] vertices, int count ) {
|
public override void UpdateDynamicVb<T>( DrawMode mode, int id, T[] vertices, int count ) {
|
||||||
GL.BindBuffer( BufferTarget.ArrayBuffer, id );
|
GL.BindBuffer( BufferTarget.ArrayBuffer, id );
|
||||||
GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( count * batchStride ), vertices );
|
GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( count * batchStride ), vertices );
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
GL.DrawArrays( modeMappings[(int)mode], 0, count );
|
GL.DrawArrays( modeMappings[(int)mode], 0, count );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawDynamicIndexedVb<T>( DrawMode mode, int id, T[] vertices, int vCount, int indicesCount ) {
|
public override void UpdateDynamicIndexedVb<T>( DrawMode mode, int id, T[] vertices, int vCount, int indicesCount ) {
|
||||||
GL.BindBuffer( BufferTarget.ArrayBuffer, id );
|
GL.BindBuffer( BufferTarget.ArrayBuffer, id );
|
||||||
GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( vCount * batchStride ), vertices );
|
GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( vCount * batchStride ), vertices );
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ namespace ClassicalSharp.Model {
|
|||||||
|
|
||||||
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
||||||
DrawPlayerModel( p );
|
DrawPlayerModel( p );
|
||||||
graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
|
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void DrawPlayerModel( Player p );
|
protected abstract void DrawPlayerModel( Player p );
|
||||||
|
@ -72,7 +72,7 @@ namespace ClassicalSharp.Model {
|
|||||||
DrawRotate( 0, 12/16f, 7/16f, p.rightLegXRot, 0, 0, LeftLegBack );
|
DrawRotate( 0, 12/16f, 7/16f, p.rightLegXRot, 0, 0, LeftLegBack );
|
||||||
DrawRotate( 0, 12/16f, 7/16f, p.leftLegXRot, 0, 0, RightLegBack );
|
DrawRotate( 0, 12/16f, 7/16f, p.leftLegXRot, 0, 0, RightLegBack );
|
||||||
// Need to draw the two parts separately.
|
// Need to draw the two parts separately.
|
||||||
graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
|
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
|
||||||
graphics.AlphaTest = true;
|
graphics.AlphaTest = true;
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
|
@ -10,24 +10,41 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public abstract bool IsSinglePlayer { get; }
|
public abstract bool IsSinglePlayer { get; }
|
||||||
|
|
||||||
|
/// <summary> Opens a connection to the given IP address and port, and prepares the initial state of the client. </summary>
|
||||||
public abstract void Connect( IPAddress address, int port );
|
public abstract void Connect( IPAddress address, int port );
|
||||||
|
|
||||||
public abstract void SendChat( string text, bool partial );
|
public abstract void SendChat( string text, bool partial );
|
||||||
|
|
||||||
|
/// <summary> Informs the server of the client's current position and orientation. </summary>
|
||||||
public abstract void SendPosition( Vector3 pos, float yaw, float pitch );
|
public abstract void SendPosition( Vector3 pos, float yaw, float pitch );
|
||||||
|
|
||||||
|
/// <summary> Informs the server that the client placed or deleted a block at the given coordinates. </summary>
|
||||||
public abstract void SendSetBlock( int x, int y, int z, bool place, byte block );
|
public abstract void SendSetBlock( int x, int y, int z, bool place, byte block );
|
||||||
|
|
||||||
|
/// <summary> Informs the server that using the given mouse button,
|
||||||
|
/// the client clicked on a particular block or entity. </summary>
|
||||||
public abstract void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId, PickedPos pos );
|
public abstract void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId, PickedPos pos );
|
||||||
|
|
||||||
public abstract void Tick( double delta );
|
public abstract void Tick( double delta );
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
public string ServerName, ServerMotd;
|
public string ServerName;
|
||||||
|
public string ServerMotd;
|
||||||
|
|
||||||
|
/// <summary> Whether the network processor is currently connected to a server. </summary>
|
||||||
public bool Disconnected;
|
public bool Disconnected;
|
||||||
public bool UsingExtPlayerList, UsingPlayerClick;
|
|
||||||
|
/// <summary> Whether the client should use extended player list management, with group names and ranks. </summary>
|
||||||
|
public bool UsingExtPlayerList;
|
||||||
|
|
||||||
|
/// <summary> Whether the server supports handling PlayerClick packets from the client. </summary>
|
||||||
|
public bool UsingPlayerClick;
|
||||||
|
|
||||||
|
/// <summary> Whether the server can handle partial message packets or not. </summary>
|
||||||
public bool ServerSupportsPatialMessages;
|
public bool ServerSupportsPatialMessages;
|
||||||
|
|
||||||
|
/// <summary> Whether the server supports receiving all code page 437 characters from this client. </summary>
|
||||||
public bool ServerSupportsFullCP437;
|
public bool ServerSupportsFullCP437;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,7 +60,7 @@ namespace ClassicalSharp.Renderers {
|
|||||||
ZQuad( p2.Z, p1.X, p2.Y, p2.X, p2.Y - size );
|
ZQuad( p2.Z, p1.X, p2.Y, p2.X, p2.Y - size );
|
||||||
|
|
||||||
graphics.SetBatchFormat( VertexFormat.Pos3fCol4b );
|
graphics.SetBatchFormat( VertexFormat.Pos3fCol4b );
|
||||||
graphics.DrawDynamicIndexedVb( DrawMode.Triangles, vb, vertices, verticesCount, verticesCount * 6 / 4 );
|
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, verticesCount, verticesCount * 6 / 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
|
@ -52,7 +52,7 @@ namespace ClassicalSharp {
|
|||||||
// fixes crashing on nVidia cards in OpenGL builds.
|
// fixes crashing on nVidia cards in OpenGL builds.
|
||||||
if( index > 0 ) {
|
if( index > 0 ) {
|
||||||
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
||||||
graphics.DrawDynamicIndexedVb( DrawMode.Triangles, weatherVb, vertices, index, index * 6 / 4 );
|
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, weatherVb, vertices, index, index * 6 / 4 );
|
||||||
}
|
}
|
||||||
graphics.AlphaBlending = false;
|
graphics.AlphaBlending = false;
|
||||||
graphics.Texturing = false;
|
graphics.Texturing = false;
|
||||||
|
@ -7,88 +7,74 @@ namespace ClassicalSharp.Selections {
|
|||||||
public class SelectionBox {
|
public class SelectionBox {
|
||||||
|
|
||||||
public short ID;
|
public short ID;
|
||||||
const int VerticesCount = 6 * 4, LineVerticesCount = 12 * 2, IndicesCount = 6 * 6;
|
|
||||||
public int Vb;
|
|
||||||
public IGraphicsApi Graphics;
|
|
||||||
|
|
||||||
public Vector3I Min, Max;
|
public Vector3I Min, Max;
|
||||||
|
public FastColour Colour;
|
||||||
|
|
||||||
public Vector3I Dimensions {
|
public SelectionBox( Vector3I start, Vector3I end, FastColour col ) {
|
||||||
get { return Max - Min + new Vector3I( 1 ); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Render( double delta ) {
|
|
||||||
Graphics.DepthWrite = false;
|
|
||||||
Graphics.BindVb( Vb );
|
|
||||||
Graphics.DrawIndexedVb( DrawMode.Triangles, IndicesCount, 0 );
|
|
||||||
Graphics.DepthWrite = true;
|
|
||||||
Graphics.DrawVb( DrawMode.Lines, VerticesCount, LineVerticesCount );
|
|
||||||
}
|
|
||||||
|
|
||||||
static VertexPos3fCol4b[] vertices = new VertexPos3fCol4b[VerticesCount + LineVerticesCount];
|
|
||||||
public SelectionBox( Vector3I start, Vector3I end, FastColour col, IGraphicsApi graphics ) {
|
|
||||||
Graphics = graphics;
|
|
||||||
Min = Vector3I.Min( start, end );
|
Min = Vector3I.Min( start, end );
|
||||||
Max = Vector3I.Max( start, end );
|
Max = Vector3I.Max( start, end );
|
||||||
int index = 0;
|
Colour = col;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Render( double delta, VertexPos3fCol4b[] vertices, VertexPos3fCol4b[] lineVertices,
|
||||||
|
ref int index, ref int lineIndex ) {
|
||||||
Vector3 p1 = (Vector3)Min + new Vector3( 1/16f, 1/16f, 1/16f );
|
Vector3 p1 = (Vector3)Min + new Vector3( 1/16f, 1/16f, 1/16f );
|
||||||
Vector3 p2 = (Vector3)Max - new Vector3( 1/16f, 1/16f, 1/16f );
|
Vector3 p2 = (Vector3)Max - new Vector3( 1/16f, 1/16f, 1/16f );
|
||||||
|
FastColour col = Colour;
|
||||||
|
|
||||||
YQuad( ref index, p1.X, p1.Z, p2.X, p2.Z, p1.Y, col ); // bottom
|
YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p1.Y, col ); // bottom
|
||||||
YQuad( ref index, p1.X, p1.Z, p2.X, p2.Z, p2.Y, col ); // top
|
YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p2.Y, col ); // top
|
||||||
XQuad( ref index, p1.X, p2.X, p1.Y, p2.Y, p1.Z, col ); // sides
|
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p1.Z, col ); // sides
|
||||||
XQuad( ref index, p1.X, p2.X, p1.Y, p2.Y, p2.Z, col );
|
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p2.Z, col );
|
||||||
ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p1.X, col );
|
ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p1.X, col );
|
||||||
ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p2.X, col );
|
ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p2.X, col );
|
||||||
|
|
||||||
col = new FastColour( (byte)~col.R, (byte)~col.G, (byte)~col.B );
|
col = new FastColour( (byte)~col.R, (byte)~col.G, (byte)~col.B );
|
||||||
// bottom face
|
// bottom face
|
||||||
Line( ref index, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z, col );
|
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z, col );
|
||||||
Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col );
|
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col );
|
||||||
Line( ref index, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col );
|
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col );
|
||||||
Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col );
|
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col );
|
||||||
// top face
|
// top face
|
||||||
Line( ref index, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
|
Line( lineVertices, ref lineIndex, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
|
||||||
Line( ref index, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col );
|
Line( lineVertices, ref lineIndex, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col );
|
||||||
Line( ref index, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
|
Line( lineVertices, ref lineIndex, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
|
||||||
Line( ref index, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col );
|
Line( lineVertices, ref lineIndex, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col );
|
||||||
// side faces
|
// side faces
|
||||||
Line( ref index, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col );
|
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col );
|
||||||
Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
|
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
|
||||||
Line( ref index, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col );
|
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col );
|
||||||
Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
|
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
|
||||||
|
|
||||||
Vb = Graphics.CreateVb( vertices, VertexFormat.Pos3fCol4b, VerticesCount + LineVerticesCount );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Line( ref int index, float x1, float y1, float z1, float x2, float y2, float z2, FastColour col ) {
|
static void ZQuad( VertexPos3fCol4b[] vertices, ref int index, float z1, float y1,
|
||||||
vertices[index++] = new VertexPos3fCol4b( x1, y1, z1, col );
|
float z2, float y2, float x, FastColour col ) {
|
||||||
vertices[index++] = new VertexPos3fCol4b( x2, y2, z2, col );
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZQuad( ref int index, float z1, float z2, float y1, float y2, float x, FastColour col ) {
|
|
||||||
vertices[index++] = new VertexPos3fCol4b( x, y1, z1, col );
|
vertices[index++] = new VertexPos3fCol4b( x, y1, z1, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x, y2, z1, col );
|
vertices[index++] = new VertexPos3fCol4b( x, y2, z1, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x, y2, z2, col );
|
vertices[index++] = new VertexPos3fCol4b( x, y2, z2, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x, y1, z2, col );
|
vertices[index++] = new VertexPos3fCol4b( x, y1, z2, col );
|
||||||
}
|
}
|
||||||
|
|
||||||
void XQuad( ref int index, float x1, float x2, float y1, float y2, float z, FastColour col ) {
|
static void XQuad( VertexPos3fCol4b[] vertices, ref int index, float x1, float y1,
|
||||||
|
float x2, float y2, float z, FastColour col ) {
|
||||||
vertices[index++] = new VertexPos3fCol4b( x1, y1, z, col );
|
vertices[index++] = new VertexPos3fCol4b( x1, y1, z, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x1, y2, z, col );
|
vertices[index++] = new VertexPos3fCol4b( x1, y2, z, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x2, y2, z, col );
|
vertices[index++] = new VertexPos3fCol4b( x2, y2, z, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x2, y1, z, col );
|
vertices[index++] = new VertexPos3fCol4b( x2, y1, z, col );
|
||||||
}
|
}
|
||||||
|
|
||||||
void YQuad( ref int index, float x1, float z1, float x2, float z2, float y, FastColour col ) {
|
static void YQuad( VertexPos3fCol4b[] vertices, ref int index, float x1, float z1,
|
||||||
|
float x2, float z2, float y, FastColour col ) {
|
||||||
vertices[index++] = new VertexPos3fCol4b( x1, y, z1, col );
|
vertices[index++] = new VertexPos3fCol4b( x1, y, z1, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x1, y, z2, col );
|
vertices[index++] = new VertexPos3fCol4b( x1, y, z2, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x2, y, z2, col );
|
vertices[index++] = new VertexPos3fCol4b( x2, y, z2, col );
|
||||||
vertices[index++] = new VertexPos3fCol4b( x2, y, z1, col );
|
vertices[index++] = new VertexPos3fCol4b( x2, y, z1, col );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
static void Line( VertexPos3fCol4b[] vertices, ref int index, float x1, float y1, float z1,
|
||||||
Graphics.DeleteVb( Vb );
|
float x2, float y2, float z2, FastColour col ) {
|
||||||
|
vertices[index++] = new VertexPos3fCol4b( x1, y1, z1, col );
|
||||||
|
vertices[index++] = new VertexPos3fCol4b( x2, y2, z2, col );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ namespace ClassicalSharp.Selections {
|
|||||||
|
|
||||||
protected Game game;
|
protected Game game;
|
||||||
public IGraphicsApi Graphics;
|
public IGraphicsApi Graphics;
|
||||||
|
VertexPos3fCol4b[] vertices, lineVertices;
|
||||||
|
int vb, lineVb;
|
||||||
|
|
||||||
public SelectionManager( Game window ) {
|
public SelectionManager( Game window ) {
|
||||||
game = window;
|
game = window;
|
||||||
@ -18,7 +20,8 @@ namespace ClassicalSharp.Selections {
|
|||||||
|
|
||||||
List<SelectionBox> selections = new List<SelectionBox>( 256 );
|
List<SelectionBox> selections = new List<SelectionBox>( 256 );
|
||||||
public void AddSelection( byte id, Vector3I p1, Vector3I p2, FastColour col ) {
|
public void AddSelection( byte id, Vector3I p1, Vector3I p2, FastColour col ) {
|
||||||
SelectionBox selection = new SelectionBox( p1, p2, col, Graphics );
|
RemoveSelection( id );
|
||||||
|
SelectionBox selection = new SelectionBox( p1, p2, col );
|
||||||
selection.ID = id;
|
selection.ID = id;
|
||||||
selections.Add( selection );
|
selections.Add( selection );
|
||||||
}
|
}
|
||||||
@ -27,42 +30,59 @@ namespace ClassicalSharp.Selections {
|
|||||||
for( int i = 0; i < selections.Count; i++ ) {
|
for( int i = 0; i < selections.Count; i++ ) {
|
||||||
SelectionBox sel = selections[i];
|
SelectionBox sel = selections[i];
|
||||||
if( sel.ID == id ) {
|
if( sel.ID == id ) {
|
||||||
sel.Dispose();
|
|
||||||
selections.RemoveAt( i );
|
selections.RemoveAt( i );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 pos;
|
|
||||||
SelectionBoxComparer comparer = new SelectionBoxComparer();
|
SelectionBoxComparer comparer = new SelectionBoxComparer();
|
||||||
public void Render( double delta ) {
|
public void Render( double delta ) {
|
||||||
Player player = game.LocalPlayer;
|
Player player = game.LocalPlayer;
|
||||||
pos = player.Position;
|
if( selections.Count == 0 ) return;
|
||||||
if( selections.Count == 0 ) return;
|
|
||||||
// TODO: Proper selection box sorting. But this is very difficult because
|
// TODO: Proper selection box sorting. But this is very difficult because
|
||||||
// we can have boxes within boxes, intersecting boxes, etc. Probably not worth it.
|
// we can have boxes within boxes, intersecting boxes, etc. Probably not worth it.
|
||||||
comparer.pos = pos;
|
comparer.pos = player.Position;
|
||||||
selections.Sort( comparer );
|
selections.Sort( comparer );
|
||||||
|
if( vertices == null )
|
||||||
|
InitData(); // lazy init as most servers don't use this.
|
||||||
|
|
||||||
Graphics.SetBatchFormat( VertexFormat.Pos3fCol4b );
|
int index = 0, lineIndex = 0;
|
||||||
Graphics.AlphaBlending = true;
|
|
||||||
for( int i = 0; i < selections.Count; i++ ) {
|
for( int i = 0; i < selections.Count; i++ ) {
|
||||||
SelectionBox box = selections[i];
|
SelectionBox box = selections[i];
|
||||||
box.Render( delta );
|
box.Render( delta, vertices, lineVertices, ref index, ref lineIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Graphics.SetBatchFormat( VertexFormat.Pos3fCol4b );
|
||||||
|
Graphics.UpdateDynamicVb( DrawMode.Lines, lineVb, lineVertices, selections.Count * LineVerticesCount );
|
||||||
|
|
||||||
|
Graphics.DepthWrite = false;
|
||||||
|
Graphics.AlphaBlending = true;
|
||||||
|
Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices,
|
||||||
|
selections.Count * VerticesCount, selections.Count * IndicesCount );
|
||||||
|
Graphics.DepthWrite = true;
|
||||||
Graphics.AlphaBlending = false;
|
Graphics.AlphaBlending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
OnNewMap( null, null );
|
OnNewMap( null, null );
|
||||||
game.Events.OnNewMap -= OnNewMap;
|
game.Events.OnNewMap -= OnNewMap;
|
||||||
|
if( lineVb > 0 ) {
|
||||||
|
Graphics.DeleteDynamicVb( vb );
|
||||||
|
Graphics.DeleteDynamicVb( lineVb );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const int VerticesCount = 6 * 4, LineVerticesCount = 12 * 2, IndicesCount = 6 * 6;
|
||||||
|
void InitData() {
|
||||||
|
vertices = new VertexPos3fCol4b[256 * VerticesCount];
|
||||||
|
lineVertices = new VertexPos3fCol4b[256 * LineVerticesCount];
|
||||||
|
vb = Graphics.CreateDynamicVb( VertexFormat.Pos3fCol4b, vertices.Length );
|
||||||
|
lineVb = Graphics.CreateDynamicVb( VertexFormat.Pos3fCol4b, lineVertices.Length );
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNewMap( object sender, EventArgs e ) {
|
void OnNewMap( object sender, EventArgs e ) {
|
||||||
foreach( SelectionBox sel in selections ) {
|
|
||||||
sel.Dispose();
|
|
||||||
}
|
|
||||||
selections.Clear();
|
selections.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ namespace ClassicalSharp.Singleplayer {
|
|||||||
game.Inventory.CanPlace[i] = true;
|
game.Inventory.CanPlace[i] = true;
|
||||||
game.Inventory.CanDelete[i] = true;
|
game.Inventory.CanDelete[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.Events.RaiseBlockPermissionsChanged();
|
game.Events.RaiseBlockPermissionsChanged();
|
||||||
NewMap();
|
NewMap();
|
||||||
MakeMap( 128, 128, 128 );
|
MakeMap( 128, 128, 128 );
|
||||||
|
@ -12,6 +12,7 @@ namespace ClassicalSharp.TexturePack {
|
|||||||
public string Filename;
|
public string Filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Extracts files from a stream that represents a .zip file. </summary>
|
||||||
public sealed class ZipReader {
|
public sealed class ZipReader {
|
||||||
|
|
||||||
public Action<string, byte[], ZipEntry> ProcessZipEntry;
|
public Action<string, byte[], ZipEntry> ProcessZipEntry;
|
||||||
@ -133,14 +134,14 @@ namespace ClassicalSharp.TexturePack {
|
|||||||
byte[] compressedData = reader.ReadBytes( compressedSize );
|
byte[] compressedData = reader.ReadBytes( compressedSize );
|
||||||
MemoryStream stream = new MemoryStream( compressedData );
|
MemoryStream stream = new MemoryStream( compressedData );
|
||||||
int index = 0, read = 0;
|
int index = 0, read = 0;
|
||||||
DeflateStream deflater = new DeflateStream( stream, CompressionMode.Decompress );
|
DeflateStream inflater = new DeflateStream( stream, CompressionMode.Decompress );
|
||||||
|
|
||||||
while( index < uncompressedSize &&
|
while( index < uncompressedSize &&
|
||||||
( read = deflater.Read( data, index, data.Length - index ) ) > 0 ) {
|
(read = inflater.Read( data, index, data.Length - index)) > 0 ) {
|
||||||
index += read;
|
index += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
deflater.Dispose();
|
inflater.Dispose();
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} else {
|
||||||
Utils.LogDebug( "Unsupported .zip entry compression method: " + compressionMethod );
|
Utils.LogDebug( "Unsupported .zip entry compression method: " + compressionMethod );
|
||||||
|
@ -44,7 +44,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output the used lines
|
// Output the used lines
|
||||||
OutputLines( ref lines, linesCount, lineSize );
|
OutputLines( ref lines, linesCount, lineSize, lineLens );
|
||||||
value = realText;
|
value = realText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +58,13 @@ namespace ClassicalSharp {
|
|||||||
value = wrap;
|
value = wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputLines( ref string[] lines, int linesCount, int lineSize ) {
|
void OutputLines( ref string[] lines, int linesCount, int lineSize, int[] lineLens ) {
|
||||||
for( int i = 0; i < capacity; i++ ) {
|
for( int i = 0; i < capacity; i++ ) {
|
||||||
if( value[i] == '\0' ) value[i] = ' ';
|
if( value[i] == '\0' ) value[i] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < Math.Max( 1, linesCount ); i++ ) {
|
for( int i = 0; i < Math.Max( 1, linesCount ); i++ ) {
|
||||||
lines[i] = new String( value, i * lineSize, lineSize );
|
lines[i] = new String( value, i * lineSize, lineLens[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user