Merge branch 'master' of github.com:UnknownShadow200/ClassicalSharp

This commit is contained in:
UnknownShadow200 2016-04-26 23:09:01 +10:00
commit 69783ae297
11 changed files with 47 additions and 65 deletions

View File

@ -50,7 +50,8 @@ namespace ClassicalSharp {
scale = size / (2 * cosY);
// screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
pos.X = x; pos.Y = y; pos.Z = 0;
pos = Utils.RotateY( Utils.RotateX( pos, cosX, -sinX ), cosY, -sinY );
Utils.RotateX( ref pos.Y, ref pos.Z, cosX, -sinX );
Utils.RotateY( ref pos.X, ref pos.Z, cosY, -sinY );
if( info.IsSprite[block] ) {
SpriteXQuad( block, TileSide.Right, false );
@ -171,16 +172,19 @@ namespace ClassicalSharp {
index = 0;
}
lastTexId = texId;
api.BindTexture( texId );
api.BindTexture( texId );
}
static void TransformVertex( ref VertexP3fT2fC4b vertex ) {
Vector3 p = new Vector3( vertex.X, vertex.Y, vertex.Z ) + pos;
static void TransformVertex( ref VertexP3fT2fC4b v ) {
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
//Vector3 p = new Vector3( v.X, v.Y, v.Z ) + pos;
//p = Utils.RotateY( p - pos, time ) + pos;
//v coords = p
// See comment in IGraphicsApi.Draw2DTexture()
p.X -= 0.5f; p.Y -= 0.5f;
p = Utils.RotateX( Utils.RotateY( p, cosY, sinY ), cosX, sinX );
vertex.X = p.X; vertex.Y = p.Y; vertex.Z = p.Z;
v.X -= 0.5f; v.Y -= 0.5f;
Utils.RotateY( ref v.X, ref v.Z, cosY, sinY );
Utils.RotateX( ref v.Y, ref v.Z, cosX, sinX );
}
}
}

View File

@ -201,7 +201,7 @@ namespace ClassicalSharp.Entities {
using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
{
int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
int outPix = inPix & 0xFFFFFF;
int outPix = new FastColour( 0, 0, 0, 0 ).ToArgb();
for( int y = 0; y < fastBmp.Height; y++ ) {
int* row = fastBmp.GetRowPtr( y );
for( int x = 0; x < fastBmp.Width; x++ ) {

View File

@ -53,7 +53,7 @@ namespace ClassicalSharp.Entities {
void UpdateModel() {
BlockModel model = Model as BlockModel;
if( model != null )
model.CalcState( byte.Parse( ModelName ) );
model.CalcState( Utils.FastByte( ModelName ) );
}
public abstract void Tick( double delta );

View File

@ -8,7 +8,6 @@ using System.Collections.Generic;
namespace ClassicalSharp.Generator {
// TODO: figure out how noise functions differ, probably based on rnd.
public sealed partial class NotchyGenerator {
void FillOblateSpheroid( int x, int y, int z, float radius, byte block ) {

View File

@ -18,10 +18,11 @@ namespace ClassicalSharp {
BlockInfo info = game.BlockInfo;
float reachSquared = reach * reach;
int iterations = 0;
Vector3I pOrigin = Vector3I.Floor( origin );
while( iterations < 10000 ) {
int x = tracer.X, y = tracer.Y, z = tracer.Z;
byte block = GetBlock( map, x, y, z, origin );
byte block = GetBlock( map, x, y, z, pOrigin );
Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];
@ -56,15 +57,16 @@ namespace ClassicalSharp {
pickedPos.IntersectPoint = origin + dir * reach;
return;
}
tracer.SetRayData( origin, dir );
tracer.SetRayData( origin, dir );
World map = game.World;
BlockInfo info = game.BlockInfo;
float reachSquared = reach * reach;
int iterations = 0;
Vector3I pOrigin = Vector3I.Floor( origin );
while( iterations < 10000 ) {
int x = tracer.X, y = tracer.Y, z = tracer.Z;
byte block = GetBlock( map, x, y, z, origin );
byte block = GetBlock( map, x, y, z, pOrigin );
Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];
@ -110,10 +112,10 @@ namespace ClassicalSharp {
}
const byte border = (byte)Block.Bedrock;
static byte GetBlock( World map, int x, int y, int z, Vector3 origin ) {
static byte GetBlock( World map, int x, int y, int z, Vector3I origin ) {
bool sides = map.SidesBlock != Block.Air;
int height = Math.Max( 1, map.SidesHeight );
bool insideMap = map.IsValidPos( Vector3I.Floor( origin ) );
bool insideMap = map.IsValidPos( origin );
// handling of blocks inside the map, above, and on borders
if( x >= 0 && z >= 0 && x < map.Width && z < map.Length ) {

View File

@ -67,7 +67,7 @@ namespace ClassicalSharp.Model {
col = FastColour.Scale( baseCol, 0.8f );
block = ((FakePlayer)p).Block;
} else {
block = Byte.Parse( p.ModelName );
block = Utils.FastByte( p.ModelName );
}
CalcState( block );
@ -210,10 +210,10 @@ namespace ClassicalSharp.Model {
void TransformVertices() {
for( int i = 0; i < index; i++ ) {
VertexP3fT2fC4b vertex = cache.vertices[i];
Vector3 newPos = Utils.RotateY( vertex.X, vertex.Y, vertex.Z, cosYaw, sinYaw ) + pos;
vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z;
cache.vertices[i] = vertex;
VertexP3fT2fC4b v = cache.vertices[i];
Utils.RotateY( ref v.X, ref v.Z, cosYaw, sinYaw );
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
cache.vertices[i] = v;
}
}
}

View File

@ -165,7 +165,7 @@ namespace ClassicalSharp.Net {
void HandleCpeSetTextHotkey() {
string label = reader.ReadAsciiString();
string action = reader.ReadAsciiString();
string action = reader.ReadCp437String();
int keyCode = reader.ReadInt32();
byte keyMods = reader.ReadUInt8();
@ -173,7 +173,7 @@ namespace ClassicalSharp.Net {
Key key = LwjglToKey.Map[keyCode];
if( key == Key.Unknown ) return;
Console.WriteLine( "CPE Hotkey added: " + key + "," + keyMods + " : " + action );
Utils.LogDebug( "CPE Hotkey added: " + key + "," + keyMods + " : " + action );
if( action == "" ) {
game.InputHandler.Hotkeys.RemoveHotkey( key, keyMods );
} else if( action[action.Length - 1] == '\n' ) {

View File

@ -66,7 +66,7 @@ namespace ClassicalSharp.Net {
BlockInfo info = game.BlockInfo;
info.ResetBlockInfo( block, false );
info.Name[block] = reader.ReadAsciiString();
info.Name[block] = reader.ReadCp437String();
info.Collide[block] = (CollideType)reader.ReadUInt8();
if( info.Collide[block] != CollideType.Solid ) {
info.IsTransparent[block] = true;

View File

@ -263,7 +263,7 @@ namespace ClassicalSharp.Net {
}
void HandleKick() {
string reason = reader.ReadAsciiString();
string reason = reader.ReadCp437String();
game.Disconnect( "&eLost connection to the server", reason );
Dispose();
}

View File

@ -32,10 +32,10 @@ namespace ClassicalSharp {
public virtual void GetPickedBlock( PickedPos pos ) { }
protected float AdjustPitch( float value ) {
if( value >= 90.00f && value <= 90.25f ) return 90.25f * Utils.Deg2Rad;
if( value >= 89.75f && value <= 90.00f ) return 89.75f * Utils.Deg2Rad;
if( value >= 270.00f && value <= 270.25f ) return 270.25f * Utils.Deg2Rad;
if( value >= 269.75f && value <= 270.00f ) return 269.75f * Utils.Deg2Rad;
if( value >= 90.0f && value <= 90.1f ) return 90.1f * Utils.Deg2Rad;
if( value >= 89.9f && value <= 90.0f ) return 89.9f * Utils.Deg2Rad;
if( value >= 270.0f && value <= 270.1f ) return 270.1f * Utils.Deg2Rad;
if( value >= 269.9f && value <= 270.0f ) return 269.9f * Utils.Deg2Rad;
return value * Utils.Deg2Rad;
}
}

View File

@ -52,7 +52,7 @@ namespace ClassicalSharp {
/// <summary> Returns a string with all the colour codes stripped from it. </summary>
public static string StripColours( string value ) {
if( value.IndexOf( '&' ) == -1 ) return value;
if( value.IndexOf( '&' ) == -1 ) return value;
char[] output = new char[value.Length];
int usedChars = 0;
@ -168,52 +168,19 @@ namespace ClassicalSharp {
return new Vector3( cosA * x - sinA * z, y, sinA * x + cosA * z );
}
/// <summary> Rotates the given 3D coordinates around the x axis. </summary>
public static Vector3 RotateX( Vector3 p, float cosA, float sinA ) {
return new Vector3( p.X, cosA * p.Y + sinA * p.Z, -sinA * p.Y + cosA * p.Z );
}
/// <summary> Rotates the given 3D coordinates around the x axis. </summary>
public static Vector3 RotateX( float x, float y, float z, float cosA, float sinA ) {
return new Vector3( x, cosA * y + sinA * z, -sinA * y + cosA * z );
}
/// <summary> Rotates the given 3D coordinates around the x axis. </summary>
public static void RotateX( ref float y, ref float z, float cosA, float sinA ) {
float y2 = cosA * y + sinA * z, z2 = -sinA * y + cosA * z;
y = y2; z = z2;
}
/// <summary> Rotates the given 3D coordinates around the y axis. </summary>
public static Vector3 RotateY( Vector3 p, float cosA, float sinA ) {
return new Vector3( cosA * p.X - sinA * p.Z, p.Y, sinA * p.X + cosA * p.Z );
}
/// <summary> Rotates the given 3D coordinates around the y axis. </summary>
public static Vector3 RotateY( float x, float y, float z, float cosA, float sinA ) {
return new Vector3( cosA * x - sinA * z, y, sinA * x + cosA * z );
float y2 = cosA * y + sinA * z; z = -sinA * y + cosA * z; y = y2;
}
/// <summary> Rotates the given 3D coordinates around the y axis. </summary>
public static void RotateY( ref float x, ref float z, float cosA, float sinA ) {
float x2 = cosA * x - sinA * z, z2 = sinA * x + cosA * z;
x = x2; z = z2;
}
/// <summary> Rotates the given 3D coordinates around the z axis. </summary>
public static Vector3 RotateZ( Vector3 p, float cosA, float sinA ) {
return new Vector3( cosA * p.X + sinA * p.Y, -sinA * p.X + cosA * p.Y, p.Z );
}
/// <summary> Rotates the given 3D coordinates around the z axis. </summary>
public static Vector3 RotateZ( float x, float y, float z, float cosA, float sinA ) {
return new Vector3( cosA * x + sinA * y, -sinA * x + cosA * y, z );
float x2 = cosA * x - sinA * z; z = sinA * x + cosA * z; x = x2;
}
/// <summary> Rotates the given 3D coordinates around the z axis. </summary>
public static void RotateZ( ref float x, ref float y, float cosA, float sinA ) {
float x2 = cosA * x + sinA * y, y2 = -sinA * x + cosA * y;
x = x2; y = y2;
float x2 = cosA * x + sinA * y; y = -sinA * x + cosA * y; x = x2;
}
/// <summary> Returns the square of the euclidean distance between two points. </summary>
@ -286,6 +253,16 @@ namespace ClassicalSharp {
return a + (b - a) * t;
}
internal static byte FastByte( string s ) {
int sum = 0;
switch( s.Length ) {
case 1: sum = (s[0] - '0'); break;
case 2: sum = (s[0] - '0') * 10 + (s[1] - '0'); break;
case 3: sum = (s[0] - '0') * 100 + (s[1] - '0') * 10 + (s[2] - '0'); break;
}
return (byte)sum;
}
// http://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/billboards/
public static void CalcBillboardPoints( Vector2 size, Vector3 position, ref Matrix4 view, out Vector3 p111,
out Vector3 p121, out Vector3 p212, out Vector3 p222 ) {