From 68f3ea56bdcf4664ee119016a0745d46f2c31a65 Mon Sep 17 00:00:00 2001 From: faketruth Date: Sat, 10 Mar 2012 02:39:36 +0000 Subject: You can change axis ordering by setting AXIS_ORDER to AXIS_ORDER_XZY in cChunk.h !THIS WILL SCREW UP YOUR WORLDS THOUGH! Still need to update world storage schemes, converters and such git-svn-id: http://mc-server.googlecode.com/svn/trunk@390 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cChunk.cpp | 4 ++++ source/cChunk.h | 35 ++++++++++++++++++++++------------- source/cChunk.inl.h | 8 ++++++++ source/cWorldGenerator.cpp | 4 ++-- source/packets/cPacket_MapChunk.cpp | 10 ++++++++++ 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/source/cChunk.cpp b/source/cChunk.cpp index 74aad7a09..f1f7300c6 100644 --- a/source/cChunk.cpp +++ b/source/cChunk.cpp @@ -539,7 +539,11 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom) case E_BLOCK_GRASS: { +#if AXIS_ORDER == AXIS_ORDER_YZX char AboveBlock = GetBlock( Index+1 ); +#else if AXIS_ORDER == AXIS_ORDER_XZY + char AboveBlock = GetBlock( Index + (c_ChunkWidth*c_ChunkWidth) ); +#endif if (!( (AboveBlock == 0) || (g_BlockOneHitDig[AboveBlock]) || (g_BlockTransparent[AboveBlock]) ) ) //changed to not allow grass if any one hit object is on top { FastSetBlock( m_BlockTickX, m_BlockTickY, m_BlockTickZ, E_BLOCK_DIRT, GetNibble( m_BlockMeta, Index ) ); diff --git a/source/cChunk.h b/source/cChunk.h index 1e250fcdd..85a67b466 100644 --- a/source/cChunk.h +++ b/source/cChunk.h @@ -26,6 +26,10 @@ It will help us when the new chunk format comes out and we need to patch everyth */ #define ZERO_CHUNK_Y 0 +// Used to smoothly convert to new axis ordering. One will be removed when deemed stable. +#define AXIS_ORDER_YZX 1 // Original (1.1-) +#define AXIS_ORDER_XZY 2 // New (1.2+) +#define AXIS_ORDER AXIS_ORDER_YZX @@ -234,23 +238,28 @@ public: inline static unsigned int MakeIndexNoCheck(int x, int y, int z) { - return y + (z * c_ChunkHeight) + (x * c_ChunkHeight * c_ChunkWidth); // 1.1 is YZX - //return x + (z * c_ChunkWidth) + (y * c_ChunkWidth * c_ChunkHeight); // 1.2 is XZY + #if AXIS_ORDER == AXIS_ORDER_XZY + return x + (z * c_ChunkWidth) + (y * c_ChunkWidth * c_ChunkWidth); // 1.2 is XZY + #else if AXIS_ORDER == AXIS_ORDER_YZX + return y + (z * c_ChunkHeight) + (x * c_ChunkHeight * c_ChunkWidth); // 1.1 is YZX + #endif } inline static Vector3i IndexToCoordinate( unsigned int index ) { -// return Vector3i( // 1.2 -// index % c_ChunkWidth, // X -// index / (c_ChunkHeight * c_ChunkWidth), // Y -// (index / c_ChunkWidth) % c_ChunkWidth // Z -// ); - - return Vector3i( // 1.1 - index / (c_ChunkHeight * c_ChunkWidth), // X - index % c_ChunkHeight, // Y - (index / c_ChunkHeight) % c_ChunkWidth // Z - ); + #if AXIS_ORDER == AXIS_ORDER_XZY + return Vector3i( // 1.2 + index % c_ChunkWidth, // X + index / (c_ChunkWidth * c_ChunkWidth), // Y + (index / c_ChunkWidth) % c_ChunkWidth // Z + ); + #else if AXIS_ORDER == AXIS_ORDER_YZX + return Vector3i( // 1.1 + index / (c_ChunkHeight * c_ChunkWidth), // X + index % c_ChunkHeight, // Y + (index / c_ChunkHeight) % c_ChunkWidth // Z + ); + #endif } inline void MarkDirty(void) diff --git a/source/cChunk.inl.h b/source/cChunk.inl.h index 4301f0486..0f0c25c09 100644 --- a/source/cChunk.inl.h +++ b/source/cChunk.inl.h @@ -38,7 +38,11 @@ char cChunk::GetNibble(char* a_Buffer, int x, int y, int z) if( x < c_ChunkWidth && x > -1 && y < c_ChunkHeight && y > -1 && z < c_ChunkWidth && z > -1 ) { const int cindex = MakeIndexNoCheck(x, y, z)/2; +#if AXIS_ORDER == AXIS_ORDER_XZY + if( (x & 1) == 0 ) +#else if AXIS_ORDER == AXIS_ORDER_YZX if( (y & 1) == 0 ) +#endif { // First half byte return (a_Buffer[cindex] & 0x0f); } @@ -83,7 +87,11 @@ void cChunk::SetNibble(char* a_Buffer, int x, int y, int z, char light) if( x < c_ChunkWidth && x > -1 && y < c_ChunkHeight && y > -1 && z < c_ChunkWidth && z > -1 ) { int cindex = MakeIndexNoCheck(x, y, z)/2; +#if AXIS_ORDER == AXIS_ORDER_XZY + if( (x & 1) == 0 ) +#else if AXIS_ORDER == AXIS_ORDER_YZX if( (y & 1) == 0 ) +#endif { // First half byte a_Buffer[cindex] &= 0xf0; // Set first half to 0 a_Buffer[cindex] |= (light) & 0x0f; diff --git a/source/cWorldGenerator.cpp b/source/cWorldGenerator.cpp index 2dfd3a8ee..6884d80b3 100644 --- a/source/cWorldGenerator.cpp +++ b/source/cWorldGenerator.cpp @@ -201,7 +201,7 @@ unsigned int cWorldGenerator::MakeIndex(int x, int y, int z ) { ASSERT((x < cChunk::c_ChunkWidth) && (x > -1) && (y < cChunk::c_ChunkHeight) && (y > -1) && (z < cChunk::c_ChunkWidth) && (z > -1)); - return y + (z * cChunk::c_ChunkHeight) + (x * cChunk::c_ChunkHeight * cChunk::c_ChunkWidth); + return cChunk::MakeIndexNoCheck( x, y, z ); } @@ -433,7 +433,7 @@ void cWorldGenerator::GenerateFoliage(int a_ChunkX, int a_ChunkY, int a_ChunkZ) int xx = x + a_ChunkX * cChunk::c_ChunkWidth; int TopY = m_World->GetHeight(xx, zz); - int index = MakeIndex(x, TopY - 1, z); + int index = cChunk::MakeIndexNoCheck(x, MAX(TopY - 1, 0), z); if (BlockType[index] == BLOCK_GRASS) { float val1 = Noise.CubicNoise2D( xx * 0.1f, zz * 0.1f ); diff --git a/source/packets/cPacket_MapChunk.cpp b/source/packets/cPacket_MapChunk.cpp index 6fdd73f12..037b94396 100644 --- a/source/packets/cPacket_MapChunk.cpp +++ b/source/packets/cPacket_MapChunk.cpp @@ -38,6 +38,8 @@ cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cha unsigned int DataSize = (cChunk::c_ChunkHeight / 16) * (4096 + 2048 + 2048 + 2048); std::auto_ptr AllData(new char[ DataSize ]); + +#if AXIS_ORDER == AXIS_ORDER_YZX memset( AllData.get(), 0, DataSize ); unsigned int iterator = 0; @@ -93,6 +95,13 @@ cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cha } } } +#else if AXIS_ORDER == AXIS_ORDER_XZY + for ( int i = 0; i < 16; ++i ) + { + m_BitMap1 |= (1 << i); + } + memcpy( AllData.get(), a_BlockData, DataSize ); +#endif uLongf CompressedSize = compressBound( DataSize ); char * CompressedBlockData = new char[CompressedSize]; @@ -159,6 +168,7 @@ cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy ) void cPacket_MapChunk::Serialize(AString & a_Data) const { + LOG("Sending chunk [%i, %i]", m_PosX, m_PosZ ); AppendByte (a_Data, m_PacketID); #if (MINECRAFT_1_2_2 == 1 ) -- cgit v1.2.3