mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Fix sprites not being full bright if they should, overhaul fps screen to also display current position and hack states. FPS can be hidden with option 'Show FPS' now.
This commit is contained in:
parent
d084385215
commit
1f54263749
@ -57,8 +57,7 @@ namespace ClassicalSharp {
|
||||
Vector3 pos = new Vector3( vertex.X, vertex.Y, vertex.Z );
|
||||
#if USE_DX
|
||||
// See comment in IGraphicsApi.Draw2DTexture()
|
||||
pos.X -= 0.5f;
|
||||
pos.Y -= 0.5f;
|
||||
pos.X -= 0.5f; pos.Y -= 0.5f;
|
||||
#endif
|
||||
pos = Utils.RotateX( Utils.RotateY( pos, cosY, sinY ), cosX, sinX );
|
||||
vertex.X = pos.X; vertex.Y = pos.Y; vertex.Z = pos.Z;
|
||||
@ -67,7 +66,7 @@ namespace ClassicalSharp {
|
||||
static Vector3 pos = Vector3.Zero;
|
||||
static void DrawYFace( byte block, float y, int side ) {
|
||||
int texId = info.GetTextureLoc( block, side );
|
||||
TextureRectangle rec = atlas.GetTexRec( texId );
|
||||
TextureRec rec = atlas.GetTexRec( texId );
|
||||
FastColour col = colNormal;
|
||||
|
||||
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y - y,
|
||||
@ -82,7 +81,7 @@ namespace ClassicalSharp {
|
||||
|
||||
static void DrawZFace( byte block, float z, int side ) {
|
||||
int texId = info.GetTextureLoc( block, side );
|
||||
TextureRectangle rec = atlas.GetTexRec( texId );
|
||||
TextureRec rec = atlas.GetTexRec( texId );
|
||||
if( blockHeight != 1 )
|
||||
rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize;
|
||||
FastColour col = colZSide;
|
||||
@ -99,7 +98,7 @@ namespace ClassicalSharp {
|
||||
|
||||
static void DrawXFace( byte block, float x, int side ) {
|
||||
int texId = info.GetTextureLoc( block, side );
|
||||
TextureRectangle rec = atlas.GetTexRec( texId );
|
||||
TextureRec rec = atlas.GetTexRec( texId );
|
||||
if( blockHeight != 1 )
|
||||
rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize;
|
||||
FastColour col = colXSide;
|
||||
|
@ -54,7 +54,7 @@ namespace ClassicalSharp {
|
||||
announcementFont = new Font( "Arial", 14 );
|
||||
|
||||
textInput = new TextInputWidget( game, chatFont, chatInputFont );
|
||||
textInput.ChatInputYOffset = ChatInputYOffset;
|
||||
textInput.YOffset = ChatInputYOffset;
|
||||
status = new TextGroupWidget( game, 3, chatFont );
|
||||
status.VerticalDocking = Docking.LeftOrTop;
|
||||
status.HorizontalDocking = Docking.BottomOrRight;
|
||||
|
@ -1,25 +1,32 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public class FpsScreen : Screen {
|
||||
|
||||
readonly Font font;
|
||||
readonly Font font, posFont;
|
||||
StringBuffer text;
|
||||
|
||||
public FpsScreen( Game game ) : base( game ) {
|
||||
font = new Font( "Arial", 13 );
|
||||
posFont = new Font( "Arial", 12, FontStyle.Italic );
|
||||
text = new StringBuffer( 96 );
|
||||
}
|
||||
|
||||
TextWidget fpsTextWidget;
|
||||
|
||||
TextWidget fpsTextWidget, hackStatesWidget;
|
||||
Texture posTexture;
|
||||
public override void Render( double delta ) {
|
||||
UpdateFPS( delta );
|
||||
if( game.HideGui ) return;
|
||||
if( game.HideGui || !game.ShowFPS ) return;
|
||||
|
||||
graphicsApi.Texturing = true;
|
||||
fpsTextWidget.Render( delta );
|
||||
UpdateHackState( false );
|
||||
|
||||
DrawPosition();
|
||||
hackStatesWidget.Render( delta );
|
||||
graphicsApi.Texturing = false;
|
||||
}
|
||||
|
||||
@ -51,11 +58,127 @@ namespace ClassicalSharp {
|
||||
fpsTextWidget = new TextWidget( game, font );
|
||||
fpsTextWidget.Init();
|
||||
fpsTextWidget.SetText( "FPS: no data yet" );
|
||||
MakePosTextWidget();
|
||||
|
||||
hackStatesWidget = new TextWidget( game, posFont );
|
||||
hackStatesWidget.YOffset = fpsTextWidget.Height + posHeight;
|
||||
hackStatesWidget.Init();
|
||||
UpdateHackState( true );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
font.Dispose();
|
||||
posFont.Dispose();
|
||||
fpsTextWidget.Dispose();
|
||||
graphicsApi.DeleteTexture( ref posTexture );
|
||||
}
|
||||
|
||||
void DrawPosition() {
|
||||
int index = 0;
|
||||
TextureRec xy = new TextureRec( 0, posTexture.Y1, baseWidth, posTexture.Height );
|
||||
TextureRec uv = new TextureRec( 0, 0, posTexture.U2, posTexture.V2 );
|
||||
IGraphicsApi.MakeQuad( xy, uv, game.ModelCache.vertices, ref index );
|
||||
|
||||
Vector3I pos = Vector3I.Floor( game.LocalPlayer.Position );
|
||||
curX = baseWidth;
|
||||
AddChar( 13, ref index );
|
||||
AddInt( pos.X, ref index, true );
|
||||
AddInt( pos.Y, ref index, true );
|
||||
AddInt( pos.Z, ref index, false );
|
||||
AddChar( 14, ref index );
|
||||
|
||||
graphicsApi.BindTexture( posTexture.ID );
|
||||
graphicsApi.DrawDynamicIndexedVb( DrawMode.Triangles,
|
||||
game.ModelCache.vb, game.ModelCache.vertices, index, index * 6 / 4 );
|
||||
}
|
||||
|
||||
bool speeding, noclip, fly;
|
||||
void UpdateHackState( bool force ) {
|
||||
LocalPlayer p = game.LocalPlayer;
|
||||
if( force || p.speeding != speeding || p.noClip != noclip || p.flying != fly ) {
|
||||
speeding = p.speeding; noclip = p.noClip; fly = p.flying;
|
||||
int index = 0;
|
||||
text.Clear();
|
||||
|
||||
if( fly ) text.Append( ref index, "Fly ON " );
|
||||
if( speeding ) text.Append( ref index, "Speed ON " );
|
||||
if( noclip ) text.Append( ref index, "Noclip ON " );
|
||||
hackStatesWidget.SetText( text.GetString() );
|
||||
}
|
||||
}
|
||||
|
||||
const string possibleChars = "0123456789-, ()";
|
||||
int[] widths = new int[possibleChars.Length];
|
||||
int baseWidth, curX, posHeight;
|
||||
float texWidth;
|
||||
void MakePosTextWidget() {
|
||||
DrawTextArgs args = new DrawTextArgs( "Feet pos: ", true );
|
||||
for( int i = 0; i < possibleChars.Length; i++ ) {
|
||||
string text = new String( possibleChars[i], 1 );
|
||||
widths[i] = game.Drawer2D.MeasureSize( text, posFont, true ).Width;
|
||||
}
|
||||
|
||||
using( IDrawer2D drawer = game.Drawer2D ) {
|
||||
Size size = game.Drawer2D.MeasureSize( args.Text, posFont, true );
|
||||
baseWidth = size.Width;
|
||||
size.Width += 16 * possibleChars.Length;
|
||||
posHeight = size.Height;
|
||||
|
||||
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
|
||||
drawer.SetBitmap( bmp );
|
||||
drawer.DrawText( posFont, ref args, 0, 0 );
|
||||
|
||||
for( int i = 0; i < possibleChars.Length; i++ ) {
|
||||
args.Text = new String( possibleChars[i], 1 );
|
||||
drawer.DrawText( posFont, ref args, baseWidth + 16 * i, 0 );
|
||||
}
|
||||
|
||||
int y = fpsTextWidget.Height;
|
||||
posTexture = drawer.Make2DTexture( bmp, size, 0, y );
|
||||
posTexture.U2 = (float)baseWidth / bmp.Width;
|
||||
posTexture.Width = baseWidth;
|
||||
texWidth = bmp.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AddChar( int charIndex, ref int index ) {
|
||||
int width = widths[charIndex];
|
||||
TextureRec xy = new TextureRec( curX, posTexture.Y1, width, posTexture.Height );
|
||||
TextureRec uv = new TextureRec( (baseWidth + charIndex * 16) / texWidth, 0, width / texWidth, posTexture.V2 );
|
||||
|
||||
curX += width;
|
||||
IGraphicsApi.MakeQuad( xy, uv, game.ModelCache.vertices, ref index );
|
||||
}
|
||||
|
||||
void AddInt( int value, ref int index, bool more ) {
|
||||
if( value < 0 )
|
||||
AddChar( 10, ref index );
|
||||
|
||||
int count = 0;
|
||||
value = Reverse( Math.Abs( value ), out count );
|
||||
for( int i = 0; i < count; i++ ) {
|
||||
AddChar( value % 10, ref index ); value /= 10;
|
||||
}
|
||||
|
||||
if( more )
|
||||
AddChar( 11, ref index );
|
||||
}
|
||||
|
||||
static int Reverse( int value, out int count ) {
|
||||
int orig = value, reversed = 0;
|
||||
count = 1; value /= 10;
|
||||
while( value > 0 ) {
|
||||
count++; value /= 10;
|
||||
}
|
||||
|
||||
for( int i = 0; i < count; i++ ) {
|
||||
reversed *= 10;
|
||||
reversed += orig % 10;
|
||||
orig /= 10;
|
||||
}
|
||||
return reversed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ namespace ClassicalSharp {
|
||||
INetworkProcessor network = game.Network;
|
||||
|
||||
buttons = new ButtonWidget[] {
|
||||
Make( -140, -50, "Use animations", Docking.Centre, OnWidgetClick,
|
||||
g => g.Animations.Enabled ? "yes" : "no",
|
||||
(g, v) => g.Animations.Enabled = v == "yes" ),
|
||||
Make( -140, -50, "Show FPS", Docking.Centre, OnWidgetClick,
|
||||
g => g.ShowFPS ? "yes" : "no",
|
||||
(g, v) => g.ShowFPS = v == "yes" ),
|
||||
|
||||
Make( -140, 0, "View distance", Docking.Centre, OnWidgetClick,
|
||||
g => g.ViewDistance.ToString(),
|
||||
|
@ -74,7 +74,7 @@ namespace ClassicalSharp {
|
||||
public override void Init() {
|
||||
playerFont = new Font( "Arial", 12 );
|
||||
chat = new ChatScreen( game );
|
||||
const int blockSize = 32;
|
||||
const int blockSize = 40;
|
||||
chat.ChatLogYOffset = blockSize + blockSize;
|
||||
chat.ChatInputYOffset = blockSize + blockSize / 2;
|
||||
chat.Init();
|
||||
|
@ -15,7 +15,7 @@ namespace ClassicalSharp {
|
||||
: this( id, x, y, width, height, 0, u2, 0, v2 ) {
|
||||
}
|
||||
|
||||
public Texture( int id, int x, int y, int width, int height, TextureRectangle rec )
|
||||
public Texture( int id, int x, int y, int width, int height, TextureRec rec )
|
||||
: this( id, x, y, width, height, rec.U1, rec.U2, rec.V1, rec.V2 ) {
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace ClassicalSharp {
|
||||
Color backColour = Color.FromArgb( 120, 60, 60, 60 );
|
||||
int caretPos = -1;
|
||||
int typingLogPos = 0;
|
||||
public int ChatInputYOffset;
|
||||
public int YOffset;
|
||||
internal StringBuffer chatInputText;
|
||||
readonly Font font, boldFont;
|
||||
|
||||
@ -57,7 +57,7 @@ namespace ClassicalSharp {
|
||||
|
||||
void DrawString( Size size, string value, bool skipCheck ) {
|
||||
size.Height = Math.Max( size.Height, chatCaretTexture.Height );
|
||||
int y = game.Height - ChatInputYOffset - size.Height / 2;
|
||||
int y = game.Height - YOffset - size.Height / 2;
|
||||
|
||||
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
|
||||
using( IDrawer2D drawer = game.Drawer2D ) {
|
||||
|
@ -28,7 +28,7 @@ namespace ClassicalSharp {
|
||||
/// <summary> Gets whether the given block blocks sunlight. </summary>
|
||||
public bool[] BlocksLight = new bool[BlocksCount];
|
||||
|
||||
public bool[] EmitsLight = new bool[BlocksCount];
|
||||
public bool[] FullBright = new bool[BlocksCount];
|
||||
|
||||
public string[] Name = new string[BlocksCount];
|
||||
|
||||
@ -90,8 +90,8 @@ namespace ClassicalSharp {
|
||||
MarkSprite( Block.Fire );
|
||||
SetIsLiquid( Block.StillWater ); SetIsLiquid( Block.Water );
|
||||
SetIsLiquid( Block.StillLava ); SetIsLiquid( Block.Lava );
|
||||
SetEmitsLight( Block.Lava, true ); SetEmitsLight( Block.StillLava, true );
|
||||
SetEmitsLight( Block.Magma, true ); SetEmitsLight( Block.Fire, true );
|
||||
SetFullBright( Block.Lava, true ); SetFullBright( Block.StillLava, true );
|
||||
SetFullBright( Block.Magma, true ); SetFullBright( Block.Fire, true );
|
||||
SetupCullingCache();
|
||||
}
|
||||
|
||||
@ -146,8 +146,8 @@ namespace ClassicalSharp {
|
||||
BlocksLight[(int)id] = blocks;
|
||||
}
|
||||
|
||||
void SetEmitsLight( Block id, bool emits ) {
|
||||
EmitsLight[(int)id] = emits;
|
||||
void SetFullBright( Block id, bool emits ) {
|
||||
FullBright[(int)id] = emits;
|
||||
}
|
||||
|
||||
public void ResetBlockInfo( byte id ) {
|
||||
@ -158,7 +158,7 @@ namespace ClassicalSharp {
|
||||
IsLiquid[id] = false;
|
||||
Height[id] = 1;
|
||||
BlocksLight[id] = true;
|
||||
EmitsLight[id] = false;
|
||||
FullBright[id] = false;
|
||||
CullWithNeighbours[id] = true;
|
||||
|
||||
Name[id] = "Invalid";
|
||||
|
@ -189,7 +189,7 @@ namespace ClassicalSharp {
|
||||
Velocity.Y -= gravity;
|
||||
}
|
||||
|
||||
bool jumping, speeding, flying, noClip, flyingDown, flyingUp;
|
||||
internal bool jumping, speeding, flying, noClip, flyingDown, flyingUp;
|
||||
public void ParseHackFlags( string name, string motd ) {
|
||||
string joined = name + motd;
|
||||
if( joined.Contains( "-hax" ) ) {
|
||||
|
@ -7,7 +7,7 @@ namespace ClassicalSharp.Particles {
|
||||
|
||||
public Vector3 Position;
|
||||
public Vector3 Velocity;
|
||||
public TextureRectangle Rectangle;
|
||||
public TextureRec Rectangle;
|
||||
public float Lifetime;
|
||||
protected Game game;
|
||||
protected Vector3 lastPos, nextPos;
|
||||
@ -16,7 +16,7 @@ namespace ClassicalSharp.Particles {
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
public Particle( Game game, Vector3 pos, Vector3 velocity, double lifetime, TextureRectangle rec ) {
|
||||
public Particle( Game game, Vector3 pos, Vector3 velocity, double lifetime, TextureRec rec ) {
|
||||
this.game = game;
|
||||
Position = lastPos = nextPos = pos;
|
||||
Velocity = velocity;
|
||||
|
@ -60,7 +60,7 @@ namespace ClassicalSharp.Particles {
|
||||
public void BreakBlockEffect( Vector3I position, byte block ) {
|
||||
Vector3 startPos = new Vector3( position.X, position.Y, position.Z );
|
||||
int texLoc = game.BlockInfo.GetTextureLoc( block, TileSide.Left );
|
||||
TextureRectangle rec = game.TerrainAtlas.GetTexRec( texLoc );
|
||||
TextureRec rec = game.TerrainAtlas.GetTexRec( texLoc );
|
||||
|
||||
float invSize = TerrainAtlas2D.invElementSize;
|
||||
int cellsCountX = (int)( 0.25f / invSize );
|
||||
@ -78,7 +78,7 @@ namespace ClassicalSharp.Particles {
|
||||
double yOffset = rnd.NextDouble() - 0.125;
|
||||
double zOffset = rnd.NextDouble() - 0.125;
|
||||
Vector3 pos = startPos + new Vector3( (float)xOffset, (float)yOffset, (float)zOffset );
|
||||
TextureRectangle particleRec = rec;
|
||||
TextureRec particleRec = rec;
|
||||
particleRec.U1 = (float)( rec.U1 + rnd.Next( 0, cellsCountX ) * elementXSize );
|
||||
particleRec.V1 = (float)( rec.V1 + rnd.Next( 0, cellsCountY ) * elementYSize );
|
||||
particleRec.U2 = particleRec.U1 + elementXSize;
|
||||
|
@ -8,7 +8,7 @@ namespace ClassicalSharp.Particles {
|
||||
const float gravity = 3.4f;
|
||||
static Vector2 terrainSize = new Vector2( 1/8f, 1/8f );
|
||||
|
||||
public TerrainParticle( Game game, Vector3 pos, Vector3 velocity, double lifetime, TextureRectangle rec )
|
||||
public TerrainParticle( Game game, Vector3 pos, Vector3 velocity, double lifetime, TextureRec rec )
|
||||
: base( game, pos, velocity, lifetime, rec ) {
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace ClassicalSharp {
|
||||
public AsyncDownloader AsyncDownloader;
|
||||
public Matrix4 View, Projection;
|
||||
public int MouseSensitivity = 30;
|
||||
public bool HideGui = false;
|
||||
public bool HideGui = false, ShowFPS = true;
|
||||
public Animations Animations;
|
||||
internal int CloudsTextureId, RainTextureId, SnowTextureId;
|
||||
internal bool screenshotRequested;
|
||||
|
@ -208,10 +208,8 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
#if USE_DX
|
||||
// NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
|
||||
// i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.
|
||||
x1 -= 0.5f;
|
||||
x2 -= 0.5f;
|
||||
y1 -= 0.5f;
|
||||
y2 -= 0.5f;
|
||||
x1 -= 0.5f; x2 -= 0.5f;
|
||||
y1 -= 0.5f; y2 -= 0.5f;
|
||||
#endif
|
||||
texVerts[0] = new VertexPos3fTex2fCol4b( x1, y1, 0, tex.U1, tex.V1, col );
|
||||
texVerts[1] = new VertexPos3fTex2fCol4b( x2, y1, 0, tex.U2, tex.V1, col );
|
||||
@ -221,6 +219,19 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
DrawDynamicIndexedVb( DrawMode.Triangles, texVb, texVerts, 4, 6 );
|
||||
}
|
||||
|
||||
public static void MakeQuad( TextureRec xy, TextureRec uv,
|
||||
VertexPos3fTex2fCol4b[] vertices, ref int index ) {
|
||||
float x1 = xy.U1, y1 = xy.V1, x2 = xy.U2, y2 = xy.V2;
|
||||
#if USE_DX
|
||||
x1 -= 0.5f; x2 -= 0.5f;
|
||||
y1 -= 0.5f; y2 -= 0.5f;
|
||||
#endif
|
||||
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, 0, uv.U1, uv.V1, FastColour.White );
|
||||
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y1, 0, uv.U2, uv.V1, FastColour.White );
|
||||
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y2, 0, uv.U2, uv.V2, FastColour.White );
|
||||
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y2, 0, uv.U1, uv.V2, FastColour.White );
|
||||
}
|
||||
|
||||
public void Draw2DTexture( ref Texture tex ) {
|
||||
Draw2DTexture( ref tex, FastColour.White );
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ namespace ClassicalSharp {
|
||||
int index = ( ( yy << 8 ) + ( zz << 4 ) + xx ) * TileSide.Sides;
|
||||
|
||||
if( info.IsSprite[tile] ) {
|
||||
fullBright = info.FullBright[tile];
|
||||
int count = counts[index + TileSide.Top];
|
||||
if( count != 0 ) {
|
||||
blockHeight = info.Height[tile];
|
||||
@ -133,7 +134,7 @@ namespace ClassicalSharp {
|
||||
if( leftCount == 0 && rightCount == 0 && frontCount == 0 &&
|
||||
backCount == 0 && bottomCount == 0 && topCount == 0 ) return;
|
||||
|
||||
emitsLight = info.EmitsLight[tile];
|
||||
fullBright = info.FullBright[tile];
|
||||
blockHeight = info.Height[tile];
|
||||
isTranslucent = info.IsTranslucent[tile];
|
||||
|
||||
@ -181,7 +182,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
} else {
|
||||
X = x; Y = y; Z = z;
|
||||
emitsLight = info.EmitsLight[tile];
|
||||
fullBright = info.FullBright[tile];
|
||||
TestAndStretchZ( zz, countIndex, tile, chunkIndex, x, 0, TileSide.Left, -1 );
|
||||
TestAndStretchZ( zz, countIndex, tile, chunkIndex, x, maxX, TileSide.Right, 1 );
|
||||
TestAndStretchX( xx, countIndex, tile, chunkIndex, z, 0, TileSide.Front, -extChunkSize );
|
||||
|
@ -9,7 +9,7 @@ namespace ClassicalSharp {
|
||||
DrawInfo[] drawInfoNormal, drawInfoTranslucent;
|
||||
TerrainAtlas1D atlas;
|
||||
int arraysCount = 0;
|
||||
bool emitsLight;
|
||||
bool fullBright;
|
||||
|
||||
void TerrainAtlasChanged( object sender, EventArgs e ) {
|
||||
int newArraysCount = game.TerrainAtlas1D.TexIds.Length;
|
||||
@ -71,22 +71,22 @@ namespace ClassicalSharp {
|
||||
bool IsLit( int x, int y, int z, int face ) {
|
||||
switch( face ) {
|
||||
case TileSide.Left:
|
||||
return emitsLight || x <= 0 || y > map.heightmap[(z * width) + (x - 1)];
|
||||
return fullBright || x <= 0 || y > map.heightmap[(z * width) + (x - 1)];
|
||||
|
||||
case TileSide.Right:
|
||||
return emitsLight || x >= maxX || y > map.heightmap[(z * width) + (x + 1)];
|
||||
return fullBright || x >= maxX || y > map.heightmap[(z * width) + (x + 1)];
|
||||
|
||||
case TileSide.Front:
|
||||
return emitsLight || z <= 0 || y > map.heightmap[((z - 1) * width) + x];
|
||||
return fullBright || z <= 0 || y > map.heightmap[((z - 1) * width) + x];
|
||||
|
||||
case TileSide.Back:
|
||||
return emitsLight || z >= maxZ || y > map.heightmap[((z + 1) * width) + x];
|
||||
return fullBright || z >= maxZ || y > map.heightmap[((z + 1) * width) + x];
|
||||
|
||||
case TileSide.Bottom:
|
||||
return emitsLight || y <= 0 || (y - 1) > map.heightmap[(z * width) + x];
|
||||
return fullBright || y <= 0 || (y - 1) > map.heightmap[(z * width) + x];
|
||||
|
||||
case TileSide.Top:
|
||||
return emitsLight || y >= maxY || y > map.heightmap[(z * width) + x];
|
||||
return fullBright || y >= maxY || y > map.heightmap[(z * width) + x];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -166,8 +166,8 @@ namespace ClassicalSharp {
|
||||
void DrawLeftFace( int count ) {
|
||||
int texId = info.GetTextureLoc( tile, TileSide.Left );
|
||||
int i;
|
||||
TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = emitsLight ? FastColour.White :
|
||||
TextureRec rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = fullBright ? FastColour.White :
|
||||
X > 0 ? (Y > map.heightmap[(Z * width) + (X - 1)] ? map.SunlightXSide : map.ShadowlightXSide) : map.SunlightXSide;
|
||||
if( blockHeight != 1 ) {
|
||||
rec.V2 = rec.V1 + blockHeight * invVerElementSize;
|
||||
@ -183,8 +183,8 @@ namespace ClassicalSharp {
|
||||
void DrawRightFace( int count ) {
|
||||
int texId = info.GetTextureLoc( tile, TileSide.Right );
|
||||
int i;
|
||||
TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = emitsLight ? FastColour.White :
|
||||
TextureRec rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = fullBright ? FastColour.White :
|
||||
X < maxX ? (Y > map.heightmap[(Z * width) + (X + 1)] ? map.SunlightXSide : map.ShadowlightXSide) : map.SunlightXSide;
|
||||
if( blockHeight != 1 ) {
|
||||
rec.V2 = rec.V1 + blockHeight * invVerElementSize;
|
||||
@ -200,8 +200,8 @@ namespace ClassicalSharp {
|
||||
void DrawBackFace( int count ) {
|
||||
int texId = info.GetTextureLoc( tile, TileSide.Back );
|
||||
int i;
|
||||
TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = emitsLight ? FastColour.White :
|
||||
TextureRec rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = fullBright ? FastColour.White :
|
||||
Z < maxZ ? (Y > map.heightmap[((Z + 1) * width) + X] ? map.SunlightZSide : map.ShadowlightZSide) : map.SunlightZSide;
|
||||
if( blockHeight != 1 ) {
|
||||
rec.V2 = rec.V1 + blockHeight * invVerElementSize;
|
||||
@ -217,8 +217,8 @@ namespace ClassicalSharp {
|
||||
void DrawFrontFace( int count ) {
|
||||
int texId = info.GetTextureLoc( tile, TileSide.Front );
|
||||
int i;
|
||||
TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = emitsLight ? FastColour.White :
|
||||
TextureRec rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = fullBright ? FastColour.White :
|
||||
Z > 0 ? (Y > map.heightmap[((Z - 1) * width) + X] ? map.SunlightZSide : map.ShadowlightZSide) : map.SunlightZSide;
|
||||
if( blockHeight != 1 ) {
|
||||
rec.V2 = rec.V1 + blockHeight * invVerElementSize;
|
||||
@ -234,9 +234,8 @@ namespace ClassicalSharp {
|
||||
void DrawBottomFace( int count ) {
|
||||
int texId = info.GetTextureLoc( tile, TileSide.Bottom );
|
||||
int i;
|
||||
TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = emitsLight ? FastColour.White :
|
||||
Y > 0 ? ((Y - 1) > map.heightmap[(Z * width) + X] ? map.SunlightYBottom : map.ShadowlightYBottom) : map.SunlightYBottom;
|
||||
TextureRec rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = fullBright ? FastColour.White : ((Y - 1) > map.heightmap[(Z * width) + X] ? map.SunlightYBottom : map.ShadowlightYBottom);
|
||||
DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i];
|
||||
|
||||
part.vertices[part.vIndex.bottom++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
|
||||
@ -248,9 +247,8 @@ namespace ClassicalSharp {
|
||||
void DrawTopFace( int count ) {
|
||||
int texId = info.GetTextureLoc( tile, TileSide.Top );
|
||||
int i;
|
||||
TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = emitsLight ? FastColour.White :
|
||||
Y < maxY ? (Y > map.heightmap[(Z * width) + X] ? map.Sunlight : map.Shadowlight) : map.Sunlight;
|
||||
TextureRec rec = atlas.GetTexRec( texId, count, out i );
|
||||
FastColour col = fullBright ? FastColour.White : (Y > map.heightmap[(Z * width) + X] ? map.Sunlight : map.Shadowlight);
|
||||
DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i];
|
||||
|
||||
part.vertices[part.vIndex.top++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U2, rec.V1, col );
|
||||
@ -262,9 +260,8 @@ namespace ClassicalSharp {
|
||||
void DrawSprite( int count ) {
|
||||
int texId = info.GetTextureLoc( tile, TileSide.Right );
|
||||
int i;
|
||||
TextureRectangle rec = atlas.GetTexRec( texId, 1, out i );
|
||||
FastColour col = Y < maxY ? (emitsLight || Y > map.heightmap[(Z * width) + X] ? map.Sunlight : map.Shadowlight)
|
||||
: map.Sunlight;
|
||||
TextureRec rec = atlas.GetTexRec( texId, 1, out i );
|
||||
FastColour col = fullBright ? FastColour.White : (Y > map.heightmap[(Z * width) + X] ? map.Sunlight : map.Shadowlight);
|
||||
DrawInfo part = drawInfoNormal[i];
|
||||
|
||||
// Draw Z axis
|
||||
|
@ -63,7 +63,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
void DrawYFace( float y, int side ) {
|
||||
int texId = BlockInfo.GetTextureLoc( block, side );
|
||||
TextureRectangle rec = atlas.GetTexRec( texId );
|
||||
TextureRec rec = atlas.GetTexRec( texId );
|
||||
|
||||
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + -0.5f, pos.Y + y, pos.Z + -0.5f, rec.U1, rec.V1, col );
|
||||
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + 0.5f, pos.Y + y, pos.Z + -0.5f, rec.U2, rec.V1, col );
|
||||
@ -73,7 +73,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
void DrawZFace( float z, int side, bool swapU ) {
|
||||
int texId = BlockInfo.GetTextureLoc( block, side );
|
||||
TextureRectangle rec = atlas.GetTexRec( texId );
|
||||
TextureRec rec = atlas.GetTexRec( texId );
|
||||
if( blockHeight != 1 ) {
|
||||
rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize;
|
||||
}
|
||||
@ -87,7 +87,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
void DrawXFace( float x, int side, bool swapU ) {
|
||||
int texId = BlockInfo.GetTextureLoc( block, side );
|
||||
TextureRectangle rec = atlas.GetTexRec( texId );
|
||||
TextureRec rec = atlas.GetTexRec( texId );
|
||||
if( blockHeight != 1 ) {
|
||||
rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize;
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ namespace ClassicalSharp {
|
||||
info.SetBottom( reader.ReadUInt8(), (Block)block );
|
||||
info.BlocksLight[block] = reader.ReadUInt8() == 0;
|
||||
reader.ReadUInt8(); // walk sound, but we ignore this.
|
||||
info.EmitsLight[block] = reader.ReadUInt8() != 0;
|
||||
info.FullBright[block] = reader.ReadUInt8() != 0;
|
||||
|
||||
byte shape = reader.ReadUInt8();
|
||||
if( shape == 2 ) {
|
||||
|
@ -161,7 +161,7 @@ namespace ClassicalSharp {
|
||||
y2 = y1 + axisSize;
|
||||
if( y2 > endY ) y2 = endY;
|
||||
|
||||
TextureRectangle rec = new TextureRectangle( 0, 0, z2 - z1, y2 - y1 );
|
||||
TextureRec rec = new TextureRec( 0, 0, z2 - z1, y2 - y1 );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V1, col );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x, y2, z1, rec.U1, rec.V2, col );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V2, col );
|
||||
@ -180,7 +180,7 @@ namespace ClassicalSharp {
|
||||
y2 = y1 + axisSize;
|
||||
if( y2 > endY ) y2 = endY;
|
||||
|
||||
TextureRectangle rec = new TextureRectangle( 0, 0, x2 - x1, y2 - y1 );
|
||||
TextureRec rec = new TextureRec( 0, 0, x2 - x1, y2 - y1 );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V1, col );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x1, y2, z, rec.U1, rec.V2, col );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V2, col );
|
||||
@ -199,7 +199,7 @@ namespace ClassicalSharp {
|
||||
z2 = z1 + axisSize;
|
||||
if( z2 > endZ ) z2 = endZ;
|
||||
|
||||
TextureRectangle rec = new TextureRectangle( 0, 0, x2 - x1, z2 - z1 );
|
||||
TextureRec rec = new TextureRec( 0, 0, x2 - x1, z2 - z1 );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, col );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x1, y, z2, rec.U1, rec.V2, col );
|
||||
*vertices++ = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, col );
|
||||
|
@ -17,10 +17,10 @@ namespace ClassicalSharp {
|
||||
this.graphics = graphics;
|
||||
}
|
||||
|
||||
public TextureRectangle GetTexRec( int texId, int uCount, out int index ) {
|
||||
public TextureRec GetTexRec( int texId, int uCount, out int index ) {
|
||||
index = texId / usedElementsPerAtlas1D;
|
||||
int y = texId % usedElementsPerAtlas1D;
|
||||
return new TextureRectangle( 0, y * invElementSize, uCount, invElementSize );
|
||||
return new TextureRec( 0, y * invElementSize, uCount, invElementSize );
|
||||
}
|
||||
|
||||
public int Get1DIndex( int texId ) {
|
||||
|
@ -59,10 +59,10 @@ namespace ClassicalSharp {
|
||||
}
|
||||
}
|
||||
|
||||
public TextureRectangle GetTexRec( int index ) {
|
||||
public TextureRec GetTexRec( int index ) {
|
||||
int x = index & 0x0F;
|
||||
int y = index >> 4;
|
||||
return new TextureRectangle( x * invElementSize, y * invElementSize,
|
||||
return new TextureRec( x * invElementSize, y * invElementSize,
|
||||
invElementSize, invElementSize );
|
||||
}
|
||||
|
||||
|
@ -3,18 +3,18 @@
|
||||
namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Stores the four texture coordinates that bound a textured quad. </summary>
|
||||
public struct TextureRectangle {
|
||||
public struct TextureRec {
|
||||
public float U1, V1, U2, V2;
|
||||
|
||||
public TextureRectangle( float u, float v, float uWidth, float vHeight ) {
|
||||
public TextureRec( float u, float v, float uWidth, float vHeight ) {
|
||||
U1 = u;
|
||||
V1 = v;
|
||||
U2 = u + uWidth;
|
||||
V2 = v + vHeight;
|
||||
}
|
||||
|
||||
public static TextureRectangle FromPoints( float u1, float u2, float v1, float v2 ) {
|
||||
TextureRectangle rec;
|
||||
public static TextureRec FromPoints( float u1, float u2, float v1, float v2 ) {
|
||||
TextureRec rec;
|
||||
rec.U1 = u1;
|
||||
rec.U2 = u2;
|
||||
rec.V1 = v1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user