Fix custom key bindings not being loaded, sprites are now rotated diagonally.

This commit is contained in:
UnknownShadow200 2015-09-27 08:48:51 +10:00
parent 067f87ce37
commit a12ffa3730
8 changed files with 52 additions and 51 deletions

View File

@ -128,7 +128,7 @@
<Compile Include="Map\MapCw.Exporter.cs" /> <Compile Include="Map\MapCw.Exporter.cs" />
<Compile Include="Map\MapCw.Importer.cs" /> <Compile Include="Map\MapCw.Importer.cs" />
<Compile Include="Map\MapDat.Importer.cs" /> <Compile Include="Map\MapDat.Importer.cs" />
<Compile Include="Map\MapFcm3.Exporter.cs" /> <Compile Include="Map\MapFcm3.Importer.cs" />
<Compile Include="Model\BlockModel.cs" /> <Compile Include="Model\BlockModel.cs" />
<Compile Include="Model\ChickenModel.cs" /> <Compile Include="Model\ChickenModel.cs" />
<Compile Include="Model\CreeperModel.cs" /> <Compile Include="Model\CreeperModel.cs" />

View File

@ -192,7 +192,7 @@ namespace ClassicalSharp {
!(Inventory.CanPlace[block] && Inventory.CanDelete[block]))); !(Inventory.CanPlace[block] && Inventory.CanDelete[block])));
} }
public KeyMap Keys = new KeyMap(); public KeyMap Keys;
} }
public enum KeyMapping { public enum KeyMapping {
@ -279,11 +279,6 @@ namespace ClassicalSharp {
for( int i = 0; i < names.Length; i++ ) { for( int i = 0; i < names.Length; i++ ) {
Options.Set( "key-" + names[i], Keys[i].ToString() ); Options.Set( "key-" + names[i], Keys[i].ToString() );
} }
try {
Options.Save();
} catch( IOException ) {
Utils.LogWarning( "Unable to sace options.txt" );
}
} }
} }
} }

View File

@ -49,7 +49,7 @@ namespace ClassicalSharp {
internal string skinServer, chatInInputBuffer, defaultTexPack; internal string skinServer, chatInInputBuffer, defaultTexPack;
internal int defaultIb; internal int defaultIb;
public bool CanUseThirdPersonCamera = true; public bool CanUseThirdPersonCamera = true;
FpsScreen fpsScreen; FpsScreen fpsScreen;
public IPAddress IPAddress; public IPAddress IPAddress;
public string Username; public string Username;
@ -97,6 +97,7 @@ namespace ClassicalSharp {
} catch( IOException ) { } catch( IOException ) {
Utils.LogWarning( "Unable to load options.txt" ); Utils.LogWarning( "Unable to load options.txt" );
} }
Keys = new KeyMap();
ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 ); ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 );
defaultIb = Graphics.MakeDefaultIb(); defaultIb = Graphics.MakeDefaultIb();
ModelCache = new ModelCache( this ); ModelCache = new ModelCache( this );
@ -159,7 +160,6 @@ namespace ClassicalSharp {
ViewDistance = distance; ViewDistance = distance;
Utils.LogDebug( "setting view distance to: " + distance ); Utils.LogDebug( "setting view distance to: " + distance );
Options.Set( "viewdist", distance.ToString() ); Options.Set( "viewdist", distance.ToString() );
Options.Save();
Raise( ViewDistanceChanged ); Raise( ViewDistanceChanged );
UpdateProjection(); UpdateProjection();
} }
@ -206,7 +206,7 @@ namespace ClassicalSharp {
MapRenderer.Render( e.Time ); MapRenderer.Render( e.Time );
if( SelectedPos.Valid ) if( SelectedPos.Valid )
Picking.Render( e.Time, SelectedPos ); Picking.Render( e.Time, SelectedPos );
WeatherRenderer.Render( e.Time ); WeatherRenderer.Render( e.Time );
SelectionManager.Render( e.Time ); SelectionManager.Render( e.Time );
bool left = IsMousePressed( MouseButton.Left ); bool left = IsMousePressed( MouseButton.Left );
bool right = IsMousePressed( MouseButton.Right ); bool right = IsMousePressed( MouseButton.Right );
@ -351,6 +351,14 @@ namespace ClassicalSharp {
Graphics.DeleteTexture( ref CloudsTextureId ); Graphics.DeleteTexture( ref CloudsTextureId );
Graphics.DeleteTexture( ref RainTextureId ); Graphics.DeleteTexture( ref RainTextureId );
Graphics.DeleteTexture( ref SnowTextureId ); Graphics.DeleteTexture( ref SnowTextureId );
if( Options.HasChanged ) {
try {
Options.Save();
} catch( IOException ) {
Utils.LogWarning( "Unable to save options.txt" );
}
}
base.Dispose(); base.Dispose();
} }
} }

View File

@ -172,9 +172,8 @@ namespace ClassicalSharp {
countIndex += TileSide.Top; countIndex += TileSide.Top;
if( counts[countIndex] != 0 ) { if( counts[countIndex] != 0 ) {
X = x; Y = y; Z = z; X = x; Y = y; Z = z;
int count = StretchX( xx, countIndex, x, y, z, chunkIndex, tile, TileSide.Top ); AddSpriteVertices( tile, 1 );
AddSpriteVertices( tile, count ); counts[countIndex] = 1;
counts[countIndex] = (byte)count;
} }
} else { } else {
X = x; Y = y; Z = z; X = x; Y = y; Z = z;

View File

@ -45,7 +45,7 @@ namespace ClassicalSharp {
if( vertices == null || vCount > vertices.Length ) { if( vertices == null || vCount > vertices.Length ) {
vertices = new VertexPos3fTex2fCol4b[vCount]; vertices = new VertexPos3fTex2fCol4b[vCount];
} }
vIndex.left = spriteCount / 6 * 4; vIndex.left = spriteCount / 6 * 4;
vIndex.right = vIndex.left + Count.left / 6 * 4; vIndex.right = vIndex.left + Count.left / 6 * 4;
vIndex.front = vIndex.right + Count.right / 6 * 4; vIndex.front = vIndex.right + Count.right / 6 * 4;
@ -167,7 +167,7 @@ namespace ClassicalSharp {
int texId = info.GetTextureLoc( tile, TileSide.Left ); int texId = info.GetTextureLoc( tile, TileSide.Left );
int i; int i;
TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
FastColour col = emitsLight ? FastColour.White : FastColour col = emitsLight ? FastColour.White :
X > 0 ? ( Y > map.heightmap[( Z * width ) + (X - 1)] ? map.SunlightXSide : map.ShadowlightXSide ) : map.SunlightXSide; X > 0 ? ( Y > map.heightmap[( Z * width ) + (X - 1)] ? map.SunlightXSide : map.ShadowlightXSide ) : map.SunlightXSide;
if( blockHeight != 1 ) { if( blockHeight != 1 ) {
rec.V2 = rec.V1 + blockHeight * invVerElementSize; rec.V2 = rec.V1 + blockHeight * invVerElementSize;
@ -184,7 +184,7 @@ namespace ClassicalSharp {
int texId = info.GetTextureLoc( tile, TileSide.Right ); int texId = info.GetTextureLoc( tile, TileSide.Right );
int i; int i;
TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
FastColour col = emitsLight ? FastColour.White : FastColour col = emitsLight ? FastColour.White :
X < maxX ? ( Y > map.heightmap[( Z * width ) + (X + 1)] ? map.SunlightXSide : map.ShadowlightXSide ) : map.SunlightXSide; X < maxX ? ( Y > map.heightmap[( Z * width ) + (X + 1)] ? map.SunlightXSide : map.ShadowlightXSide ) : map.SunlightXSide;
if( blockHeight != 1 ) { if( blockHeight != 1 ) {
rec.V2 = rec.V1 + blockHeight * invVerElementSize; rec.V2 = rec.V1 + blockHeight * invVerElementSize;
@ -201,7 +201,7 @@ namespace ClassicalSharp {
int texId = info.GetTextureLoc( tile, TileSide.Back ); int texId = info.GetTextureLoc( tile, TileSide.Back );
int i; int i;
TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
FastColour col = emitsLight ? FastColour.White : FastColour col = emitsLight ? FastColour.White :
Z < maxZ ? ( Y > map.heightmap[( (Z + 1) * width ) + X] ? map.SunlightZSide : map.ShadowlightZSide ) : map.SunlightZSide; Z < maxZ ? ( Y > map.heightmap[( (Z + 1) * width ) + X] ? map.SunlightZSide : map.ShadowlightZSide ) : map.SunlightZSide;
if( blockHeight != 1 ) { if( blockHeight != 1 ) {
rec.V2 = rec.V1 + blockHeight * invVerElementSize; rec.V2 = rec.V1 + blockHeight * invVerElementSize;
@ -218,7 +218,7 @@ namespace ClassicalSharp {
int texId = info.GetTextureLoc( tile, TileSide.Front ); int texId = info.GetTextureLoc( tile, TileSide.Front );
int i; int i;
TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
FastColour col = emitsLight ? FastColour.White : FastColour col = emitsLight ? FastColour.White :
Z > 0 ? ( Y > map.heightmap[( (Z - 1) * width ) + X] ? map.SunlightZSide : map.ShadowlightZSide ) : map.SunlightZSide; Z > 0 ? ( Y > map.heightmap[( (Z - 1) * width ) + X] ? map.SunlightZSide : map.ShadowlightZSide ) : map.SunlightZSide;
if( blockHeight != 1 ) { if( blockHeight != 1 ) {
rec.V2 = rec.V1 + blockHeight * invVerElementSize; rec.V2 = rec.V1 + blockHeight * invVerElementSize;
@ -235,7 +235,7 @@ namespace ClassicalSharp {
int texId = info.GetTextureLoc( tile, TileSide.Bottom ); int texId = info.GetTextureLoc( tile, TileSide.Bottom );
int i; int i;
TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
FastColour col = emitsLight ? FastColour.White : FastColour col = emitsLight ? FastColour.White :
Y > 0 ? ( (Y - 1) > map.heightmap[( Z * width ) + X] ? map.SunlightYBottom : map.ShadowlightYBottom ) : map.SunlightYBottom; Y > 0 ? ( (Y - 1) > map.heightmap[( Z * width ) + X] ? map.SunlightYBottom : map.ShadowlightYBottom ) : map.SunlightYBottom;
DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i]; DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i];
@ -249,7 +249,7 @@ namespace ClassicalSharp {
int texId = info.GetTextureLoc( tile, TileSide.Top ); int texId = info.GetTextureLoc( tile, TileSide.Top );
int i; int i;
TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); TextureRectangle rec = atlas.GetTexRec( texId, count, out i );
FastColour col = emitsLight ? FastColour.White : FastColour col = emitsLight ? FastColour.White :
Y < maxY ? ( Y > map.heightmap[( Z * width ) + X] ? map.Sunlight : map.Shadowlight ) : map.Sunlight; Y < maxY ? ( Y > map.heightmap[( Z * width ) + X] ? map.Sunlight : map.Shadowlight ) : map.Sunlight;
DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i]; DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i];
@ -262,29 +262,22 @@ namespace ClassicalSharp {
void DrawSprite( int count ) { void DrawSprite( int count ) {
int texId = info.GetTextureLoc( tile, TileSide.Right ); int texId = info.GetTextureLoc( tile, TileSide.Right );
int i; int i;
TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); TextureRectangle rec = atlas.GetTexRec( texId, 1, out i );
FastColour col = Y < maxY ? ( emitsLight || Y > map.heightmap[( Z * width ) + X] ? map.Sunlight : map.Shadowlight ) FastColour col = Y < maxY ? ( emitsLight || Y > map.heightmap[( Z * width ) + X] ? map.Sunlight : map.Shadowlight )
: map.Sunlight; : map.Sunlight;
DrawInfo part = drawInfoNormal[i]; DrawInfo part = drawInfoNormal[i];
// Draw stretched Z axis // Draw Z axis
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 0.5f, rec.U2, rec.V2, col ); part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 2.5f/16, rec.U2, rec.V2, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 0.5f, rec.U2, rec.V1, col ); part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 2.5f/16, rec.U2, rec.V1, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 0.5f, rec.U1, rec.V1, col ); part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 13.5f/16, rec.U1, rec.V1, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 0.5f, rec.U1, rec.V2, col ); part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 13.5f/16, rec.U1, rec.V2, col );
// Draw X axis // Draw X axis
rec.U2 = 1; part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 13.5f/16, rec.U1, rec.V2, col );
int startX = X; part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 13.5f/16, rec.U1, rec.V1, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 2.5f/16, rec.U2, rec.V1, col );
for( int j = 0; j < count; j++ ) { part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 2.5f/16, rec.U2, rec.V2, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y, Z, rec.U1, rec.V2, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z, rec.U1, rec.V1, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y, Z + 1, rec.U2, rec.V2, col );
X++;
}
X = startX;
} }
} }
} }

View File

@ -59,6 +59,8 @@ namespace ClassicalSharp {
return result; return result;
} }
public Color ToColor() { public Color ToColor() {
return Color.FromArgb( A, R, G, B ); return Color.FromArgb( A, R, G, B );
} }

View File

@ -7,32 +7,36 @@ namespace ClassicalSharp {
public static class Options { public static class Options {
static Dictionary<string, string> OptionsSet = new Dictionary<string, string>(); static Dictionary<string, string> OptionsSet = new Dictionary<string, string>();
public static bool HasChanged;
public static string Get( string key ) { public static string Get( string key ) {
string value; string value;
return OptionsSet.TryGetValue( key, out value ) ? value : null; return OptionsSet.TryGetValue( key, out value ) ? value : null;
} }
public static bool TryGetInt( string key, out int valueInt ) { public static int GetInt( string key, int min, int max, int defValue ) {
string value; string value;
valueInt = 0; int valueInt = 0;
OptionsSet.TryGetValue( key, out value ); if( !OptionsSet.TryGetValue( key, out value ) || String.IsNullOrEmpty( value )
|| !Int32.TryParse( value, out valueInt ) )
if( String.IsNullOrEmpty( value ) ) return false; return defValue;
return Int32.TryParse( value, out valueInt );
Utils.Clamp( ref valueInt, min, max );
return valueInt;
} }
public static int GetInt( string key, int min, int max, int defValue ) { public static bool GetBool( string key, bool defValue ) {
int valueInt = 0; string value;
if( TryGetInt( key, out valueInt ) ) { bool valueBool = false;
Utils.Clamp( ref valueInt, min, max ); if( !OptionsSet.TryGetValue( key, out value ) || String.IsNullOrEmpty( value )
return valueInt; || !Boolean.TryParse( value, out valueBool ) )
} return defValue;
return defValue; return valueBool;
} }
public static void Set( string key, string value ) { public static void Set( string key, string value ) {
OptionsSet[key] = value; OptionsSet[key] = value;
HasChanged = true;
} }
public const string OptionsFile = "options.txt"; public const string OptionsFile = "options.txt";