mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -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++ )
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ namespace ClassicalSharp {
|
||||
AddChar( 14, ref index );
|
||||
|
||||
graphicsApi.BindTexture( posTexture.ID );
|
||||
graphicsApi.DrawDynamicIndexedVb( DrawMode.Triangles,
|
||||
graphicsApi.UpdateDynamicIndexedVb( DrawMode.Triangles,
|
||||
game.ModelCache.vb, game.ModelCache.vertices, index, index * 6 / 4 );
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
Texture chatInputTexture, caretTexture;
|
||||
int caretPos = -1, typingLogPos = 0;
|
||||
int caretPos = -1, typingLogPos = 0, defaultHeight;
|
||||
public int YOffset;
|
||||
internal WrappableStringBuffer chatInputText;
|
||||
readonly Font font, boldFont;
|
||||
@ -46,6 +46,7 @@ namespace ClassicalSharp {
|
||||
game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) :
|
||||
game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
||||
chatInputText.WordWrap( ref parts, ref partLens, 64 );
|
||||
defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height;
|
||||
|
||||
maxWidth = 0;
|
||||
args = new DrawTextArgs( null, font, false );
|
||||
@ -85,7 +86,8 @@ namespace ClassicalSharp {
|
||||
Size trimmedSize = game.Drawer2D.MeasureChatSize( ref args );
|
||||
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 );
|
||||
caretTexture.Width = charSize.Width;
|
||||
|
||||
@ -101,7 +103,7 @@ namespace ClassicalSharp {
|
||||
totalHeight += sizes[i].Height;
|
||||
Size size = new Size( maxWidth, totalHeight );
|
||||
|
||||
int realHeight = 0, y = 0;
|
||||
int realHeight = 0;
|
||||
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
|
||||
using( IDrawer2D drawer = game.Drawer2D ) {
|
||||
drawer.SetBitmap( bmp );
|
||||
@ -115,15 +117,15 @@ namespace ClassicalSharp {
|
||||
drawer.DrawChatText( ref args, 0, realHeight );
|
||||
realHeight += sizes[i].Height;
|
||||
}
|
||||
y = game.Height - realHeight - YOffset;
|
||||
chatInputTexture = drawer.Make2DTexture( bmp, size, 10, y );
|
||||
chatInputTexture = drawer.Make2DTexture( bmp, size, 10, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
caretTexture.Y1 += y;
|
||||
Y = y;
|
||||
Width = size.Width;
|
||||
Height = realHeight;
|
||||
Height = realHeight == 0 ? defaultHeight : realHeight;
|
||||
Y = game.Height - Height - YOffset;
|
||||
chatInputTexture.Y1 = Y;
|
||||
caretTexture.Y1 += Y;
|
||||
Width = size.Width;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
|
@ -37,7 +37,7 @@ namespace ClassicalSharp.Particles {
|
||||
count = Math.Min( count, 1000 );
|
||||
|
||||
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.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.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.AlphaTest = false;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
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;
|
||||
DataBuffer buffer = dynamicvBuffers[vb];
|
||||
buffer.SetData( vertices, size, LockFlags.Discard );
|
||||
@ -231,7 +231,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
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;
|
||||
DataBuffer buffer = dynamicvBuffers[vb];
|
||||
buffer.SetData( vertices, size, LockFlags.Discard );
|
||||
|
@ -158,13 +158,13 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
/// draw calls will be in the given format. </summary>
|
||||
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>
|
||||
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>
|
||||
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;
|
||||
|
||||
/// <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[3] = new VertexPos3fCol4b( x, y + height, 0, col );
|
||||
SetBatchFormat( VertexFormat.Pos3fCol4b );
|
||||
DrawDynamicIndexedVb( DrawMode.Triangles, quadVb, quadVerts, 4, 6 );
|
||||
UpdateDynamicIndexedVb( DrawMode.Triangles, quadVb, quadVerts, 4, 6 );
|
||||
}
|
||||
|
||||
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[3] = new VertexPos3fTex2fCol4b( x1, y2, 0, tex.U1, tex.V2, col );
|
||||
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,
|
||||
|
@ -230,7 +230,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
|
||||
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.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( count * batchStride ), vertices );
|
||||
|
||||
@ -238,7 +238,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
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.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( vCount * batchStride ), vertices );
|
||||
|
||||
|
@ -50,7 +50,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
|
||||
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 );
|
||||
|
@ -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.leftLegXRot, 0, 0, RightLegBack );
|
||||
// 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;
|
||||
index = 0;
|
||||
|
||||
|
@ -10,24 +10,41 @@ namespace ClassicalSharp {
|
||||
|
||||
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 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 );
|
||||
|
||||
/// <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 );
|
||||
|
||||
/// <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 Tick( double delta );
|
||||
|
||||
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 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;
|
||||
|
||||
/// <summary> Whether the server supports receiving all code page 437 characters from this client. </summary>
|
||||
public bool ServerSupportsFullCP437;
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ namespace ClassicalSharp.Renderers {
|
||||
ZQuad( p2.Z, p1.X, p2.Y, p2.X, p2.Y - size );
|
||||
|
||||
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() {
|
||||
|
@ -52,7 +52,7 @@ namespace ClassicalSharp {
|
||||
// fixes crashing on nVidia cards in OpenGL builds.
|
||||
if( index > 0 ) {
|
||||
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.Texturing = false;
|
||||
|
@ -7,88 +7,74 @@ namespace ClassicalSharp.Selections {
|
||||
public class SelectionBox {
|
||||
|
||||
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 FastColour Colour;
|
||||
|
||||
public Vector3I Dimensions {
|
||||
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;
|
||||
public SelectionBox( Vector3I start, Vector3I end, FastColour col ) {
|
||||
Min = Vector3I.Min( start, end );
|
||||
Max = Vector3I.Max( start, end );
|
||||
int index = 0;
|
||||
Max = Vector3I.Max( start, end );
|
||||
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 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( 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( ref index, p1.X, p2.X, p1.Y, p2.Y, p2.Z, col );
|
||||
ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p1.X, col );
|
||||
ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p2.X, col );
|
||||
YQuad( vertices, 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, p2.Y, col ); // top
|
||||
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p1.Z, col ); // sides
|
||||
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p2.Z, col );
|
||||
ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p1.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 );
|
||||
// bottom face
|
||||
Line( ref index, 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( ref index, 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, p1.Z, p2.X, p1.Y, p1.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col );
|
||||
// top face
|
||||
Line( ref index, 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( ref index, 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, p1.Z, p2.X, p2.Y, p1.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col );
|
||||
// side faces
|
||||
Line( ref index, 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( ref index, 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 );
|
||||
|
||||
Vb = Graphics.CreateVb( vertices, VertexFormat.Pos3fCol4b, VerticesCount + LineVerticesCount );
|
||||
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col );
|
||||
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
|
||||
}
|
||||
|
||||
void Line( ref int index, float x1, float y1, float z1, float x2, float y2, float z2, FastColour col ) {
|
||||
vertices[index++] = new VertexPos3fCol4b( x1, y1, z1, 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 ) {
|
||||
static void ZQuad( VertexPos3fCol4b[] vertices, ref int index, float z1, float y1,
|
||||
float z2, float y2, float x, FastColour col ) {
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y1, z1, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y2, z1, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x, y2, 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, y2, z, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y2, 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, z2, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y, z2, col );
|
||||
vertices[index++] = new VertexPos3fCol4b( x2, y, z1, col );
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Graphics.DeleteVb( Vb );
|
||||
static void Line( VertexPos3fCol4b[] vertices, ref int index, float x1, float y1, float z1,
|
||||
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;
|
||||
public IGraphicsApi Graphics;
|
||||
VertexPos3fCol4b[] vertices, lineVertices;
|
||||
int vb, lineVb;
|
||||
|
||||
public SelectionManager( Game window ) {
|
||||
game = window;
|
||||
@ -18,7 +20,8 @@ namespace ClassicalSharp.Selections {
|
||||
|
||||
List<SelectionBox> selections = new List<SelectionBox>( 256 );
|
||||
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;
|
||||
selections.Add( selection );
|
||||
}
|
||||
@ -27,42 +30,59 @@ namespace ClassicalSharp.Selections {
|
||||
for( int i = 0; i < selections.Count; i++ ) {
|
||||
SelectionBox sel = selections[i];
|
||||
if( sel.ID == id ) {
|
||||
sel.Dispose();
|
||||
selections.RemoveAt( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 pos;
|
||||
|
||||
SelectionBoxComparer comparer = new SelectionBoxComparer();
|
||||
public void Render( double delta ) {
|
||||
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
|
||||
// we can have boxes within boxes, intersecting boxes, etc. Probably not worth it.
|
||||
comparer.pos = pos;
|
||||
comparer.pos = player.Position;
|
||||
selections.Sort( comparer );
|
||||
if( vertices == null )
|
||||
InitData(); // lazy init as most servers don't use this.
|
||||
|
||||
Graphics.SetBatchFormat( VertexFormat.Pos3fCol4b );
|
||||
Graphics.AlphaBlending = true;
|
||||
int index = 0, lineIndex = 0;
|
||||
for( int i = 0; i < selections.Count; 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;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
OnNewMap( null, null );
|
||||
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 ) {
|
||||
foreach( SelectionBox sel in selections ) {
|
||||
sel.Dispose();
|
||||
}
|
||||
selections.Clear();
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ namespace ClassicalSharp.Singleplayer {
|
||||
game.Inventory.CanPlace[i] = true;
|
||||
game.Inventory.CanDelete[i] = true;
|
||||
}
|
||||
|
||||
game.Events.RaiseBlockPermissionsChanged();
|
||||
NewMap();
|
||||
MakeMap( 128, 128, 128 );
|
||||
|
@ -12,6 +12,7 @@ namespace ClassicalSharp.TexturePack {
|
||||
public string Filename;
|
||||
}
|
||||
|
||||
/// <summary> Extracts files from a stream that represents a .zip file. </summary>
|
||||
public sealed class ZipReader {
|
||||
|
||||
public Action<string, byte[], ZipEntry> ProcessZipEntry;
|
||||
@ -133,14 +134,14 @@ namespace ClassicalSharp.TexturePack {
|
||||
byte[] compressedData = reader.ReadBytes( compressedSize );
|
||||
MemoryStream stream = new MemoryStream( compressedData );
|
||||
int index = 0, read = 0;
|
||||
DeflateStream deflater = new DeflateStream( stream, CompressionMode.Decompress );
|
||||
DeflateStream inflater = new DeflateStream( stream, CompressionMode.Decompress );
|
||||
|
||||
while( index < uncompressedSize &&
|
||||
( read = deflater.Read( data, index, data.Length - index ) ) > 0 ) {
|
||||
(read = inflater.Read( data, index, data.Length - index)) > 0 ) {
|
||||
index += read;
|
||||
}
|
||||
|
||||
deflater.Dispose();
|
||||
inflater.Dispose();
|
||||
return data;
|
||||
} else {
|
||||
Utils.LogDebug( "Unsupported .zip entry compression method: " + compressionMethod );
|
||||
|
@ -44,7 +44,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
// Output the used lines
|
||||
OutputLines( ref lines, linesCount, lineSize );
|
||||
OutputLines( ref lines, linesCount, lineSize, lineLens );
|
||||
value = realText;
|
||||
}
|
||||
|
||||
@ -58,13 +58,13 @@ namespace ClassicalSharp {
|
||||
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++ ) {
|
||||
if( value[i] == '\0' ) value[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