diff --git a/Minecraft.Client/Network/ClientConnection.cpp b/Minecraft.Client/Network/ClientConnection.cpp index ab03b3403..8494759de 100644 --- a/Minecraft.Client/Network/ClientConnection.cpp +++ b/Minecraft.Client/Network/ClientConnection.cpp @@ -1,5 +1,7 @@ #include "../Platform/stdafx.h" #include "ClientConnection.h" +#include +#include #include "../Level/MultiPlayerLevel.h" #include "../Player/MultiPlayerLocalPlayer.h" #include "../GameState/StatsCounter.h" @@ -43,7 +45,6 @@ #include "../MinecraftServer.h" #include "../ClientConstants.h" #include "../../Minecraft.World/Util/SoundTypes.h" -#include "../../Minecraft.World/Util/BasicTypeContainers.h" #include "../Textures/Packs/TexturePackRepository.h" #ifdef _XBOX #include "../Platform/Common/XUI/XUI_Scene_Trading.h" @@ -2171,12 +2172,11 @@ void ClientConnection::handlePreLogin(std::shared_ptr packet) { // Check this friend against each player, if we find them we // have at least one friend for (int j = 0; j < g_NetworkManager.GetPlayerCount(); j++) { - Platform::String ^ xboxUserId = - ref new Platform::String( - g_NetworkManager.GetPlayerByIndex(j) - ->GetUID() - .toString() - .data()); + Platform::String ^ xboxUserId = ref new Platform::String( + g_NetworkManager.GetPlayerByIndex(j) + ->GetUID() + .toString() + .data()); if (friendsXuid == xboxUserId) { isAtLeastOneFriend = true; break; @@ -2279,8 +2279,8 @@ void ClientConnection::handlePreLogin(std::shared_ptr packet) { // down, because they are trying to lock the incoming critsec when // it's already locked by this thread // Minecraft::GetInstance()->connectionDisconnected( - // m_userIndex , reason ); done = true; connection->flush(); - // connection->close(reason); + // m_userIndex , reason ); done = true; + // connection->flush(); connection->close(reason); // app.SetAction(m_userIndex,eAppAction_ExitPlayer); // 4J-PB - doing this instead @@ -4050,7 +4050,8 @@ void ClientConnection::handleUpdateAttributes( // are we passing in MIN_NORMAL (Java's smallest non-zero value // conforming to IEEE Standard 754 (?)) and MAX_VALUE instance = attributes->registerAttribute(new RangedAttribute( - attribute->getId(), 0, Double::MIN_NORMAL, Double::MAX_VALUE)); + attribute->getId(), 0, std::numeric_limits::min(), + std::numeric_limits::max())); } instance->setBaseValue(attribute->getBase()); @@ -4105,4 +4106,4 @@ ClientConnection::DeferredEntityLinkPacket::DeferredEntityLinkPacket( std::shared_ptr packet) { m_recievedTick = GetTickCount(); m_packet = packet; -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tesselator_SPU.cpp b/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tesselator_SPU.cpp index 2beca98b9..a7df253e1 100644 --- a/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tesselator_SPU.cpp +++ b/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tesselator_SPU.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" - #ifdef SN_TARGET_PS3_SPU #include #include @@ -10,25 +9,24 @@ #include #include #include "../Common/spu_assert.h" -#endif // SN_TARGET_PS3_SPU +#endif // SN_TARGET_PS3_SPU #include "Tesselator_SPU.h" static const bool sc_verbose = false; -// #include "../../../../../Minecraft.World/Util/BasicTypeContainers.h" // #include "../../../../../Minecraft.World/IO/Streams/FloatBuffer.h" // #include "../../../../../Minecraft.World/IO/Streams/IntBuffer.h" // #include "../../../../../Minecraft.World/IO/Streams/ByteBuffer.h" #ifdef SN_TARGET_PS3_SPU -const int GL_LINES = 4;//C4JRender::PRIMITIVE_TYPE_LINE_LIST; -const int GL_LINE_STRIP = 5;//C4JRender::PRIMITIVE_TYPE_LINE_STRIP; -const int GL_QUADS = 3;//C4JRender::PRIMITIVE_TYPE_QUAD_LIST; -const int GL_TRIANGLE_FAN = 2;//C4JRender::PRIMITIVE_TYPE_TRIANGLE_FAN; -const int GL_TRIANGLE_STRIP = 1;//C4JRender::PRIMITIVE_TYPE_TRIANGLE_STRIP; +const int GL_LINES = 4; // C4JRender::PRIMITIVE_TYPE_LINE_LIST; +const int GL_LINE_STRIP = 5; // C4JRender::PRIMITIVE_TYPE_LINE_STRIP; +const int GL_QUADS = 3; // C4JRender::PRIMITIVE_TYPE_QUAD_LIST; +const int GL_TRIANGLE_FAN = 2; // C4JRender::PRIMITIVE_TYPE_TRIANGLE_FAN; +const int GL_TRIANGLE_STRIP = 1; // C4JRender::PRIMITIVE_TYPE_TRIANGLE_STRIP; -#endif +#endif bool Tesselator_SPU::TRIANGLE_MODE = false; // bool Tesselator_SPU::USE_VBO = false; @@ -50,128 +48,110 @@ int normal; */ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// taken from http://my.safaribooksonline.com/book/programming/opengl/9780321563835/gl-half-float-oes/app01lev1sec2 +// taken from +// http://my.safaribooksonline.com/book/programming/opengl/9780321563835/gl-half-float-oes/app01lev1sec2 // -15 stored using a single precision bias of 127 -const unsigned int HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP = 0x38000000; +const unsigned int HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP = 0x38000000; // max exponent value in single precision that will be converted // to Inf or Nan when stored as a half-float -const unsigned int HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP = 0x47800000; +const unsigned int HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP = 0x47800000; // 255 is the max exponent biased value -const unsigned int FLOAT_MAX_BIASED_EXP = (0xFF << 23); +const unsigned int FLOAT_MAX_BIASED_EXP = (0xFF << 23); -const unsigned int HALF_FLOAT_MAX_BIASED_EXP = (0x1F << 10); +const unsigned int HALF_FLOAT_MAX_BIASED_EXP = (0x1F << 10); -typedef unsigned short hfloat; +typedef unsigned short hfloat; -hfloat convertFloatToHFloat(float f) -{ - unsigned int x = *(unsigned int *)&f; - unsigned int sign = (unsigned short)(x >> 31); - unsigned int mantissa; - unsigned int exp; - hfloat hf; +hfloat convertFloatToHFloat(float f) { + unsigned int x = *(unsigned int*)&f; + unsigned int sign = (unsigned short)(x >> 31); + unsigned int mantissa; + unsigned int exp; + hfloat hf; - // get mantissa - mantissa = x & ((1 << 23) - 1); - // get exponent bits - exp = x & FLOAT_MAX_BIASED_EXP; - if (exp >= HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP) - { - // check if the original single precision float number is a NaN - if (mantissa && (exp == FLOAT_MAX_BIASED_EXP)) - { - // we have a single precision NaN - mantissa = (1 << 23) - 1; - } - else - { - // 16-bit half-float representation stores number as Inf - mantissa = 0; - } - hf = (((hfloat)sign) << 15) | (hfloat)(HALF_FLOAT_MAX_BIASED_EXP) | - (hfloat)(mantissa >> 13); - } - // check if exponent is <= -15 - else if (exp <= HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) - { + // get mantissa + mantissa = x & ((1 << 23) - 1); + // get exponent bits + exp = x & FLOAT_MAX_BIASED_EXP; + if (exp >= HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP) { + // check if the original single precision float number is a NaN + if (mantissa && (exp == FLOAT_MAX_BIASED_EXP)) { + // we have a single precision NaN + mantissa = (1 << 23) - 1; + } else { + // 16-bit half-float representation stores number as Inf + mantissa = 0; + } + hf = (((hfloat)sign) << 15) | (hfloat)(HALF_FLOAT_MAX_BIASED_EXP) | + (hfloat)(mantissa >> 13); + } + // check if exponent is <= -15 + else if (exp <= HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) { + // store a denorm half-float value or zero + exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP - exp) >> 23; + mantissa >>= (14 + exp); - // store a denorm half-float value or zero - exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP - exp) >> 23; - mantissa >>= (14 + exp); + hf = (((hfloat)sign) << 15) | (hfloat)(mantissa); + } else { + hf = + (((hfloat)sign) << 15) | + (hfloat)((exp - HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) >> 13) | + (hfloat)(mantissa >> 13); + } - hf = (((hfloat)sign) << 15) | (hfloat)(mantissa); - } - else - { - hf = (((hfloat)sign) << 15) | - (hfloat)((exp - HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) >> 13) | - (hfloat)(mantissa >> 13); - } - - return hf; + return hf; } -float convertHFloatToFloat(hfloat hf) -{ - unsigned int sign = (unsigned int)(hf >> 15); - unsigned int mantissa = (unsigned int)(hf & ((1 << 10) - 1)); - unsigned int exp = (unsigned int)(hf & HALF_FLOAT_MAX_BIASED_EXP); - unsigned int f; +float convertHFloatToFloat(hfloat hf) { + unsigned int sign = (unsigned int)(hf >> 15); + unsigned int mantissa = (unsigned int)(hf & ((1 << 10) - 1)); + unsigned int exp = (unsigned int)(hf & HALF_FLOAT_MAX_BIASED_EXP); + unsigned int f; - if (exp == HALF_FLOAT_MAX_BIASED_EXP) - { - // we have a half-float NaN or Inf - // half-float NaNs will be converted to a single precision NaN - // half-float Infs will be converted to a single precision Inf - exp = FLOAT_MAX_BIASED_EXP; - if (mantissa) - mantissa = (1 << 23) - 1; // set all bits to indicate a NaN - } - else if (exp == 0x0) - { - // convert half-float zero/denorm to single precision value - if (mantissa) - { - mantissa <<= 1; - exp = HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP; - // check for leading 1 in denorm mantissa - while ((mantissa & (1 << 10)) == 0) - { - // for every leading 0, decrement single precision exponent by 1 - // and shift half-float mantissa value to the left - mantissa <<= 1; - exp -= (1 << 23); - } - // clamp the mantissa to 10-bits - mantissa &= ((1 << 10) - 1); - // shift left to generate single-precision mantissa of 23-bits - mantissa <<= 13; - } - } - else - { - // shift left to generate single-precision mantissa of 23-bits - mantissa <<= 13; - // generate single precision biased exponent value - exp = (exp << 13) + HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP; - } + if (exp == HALF_FLOAT_MAX_BIASED_EXP) { + // we have a half-float NaN or Inf + // half-float NaNs will be converted to a single precision NaN + // half-float Infs will be converted to a single precision Inf + exp = FLOAT_MAX_BIASED_EXP; + if (mantissa) + mantissa = (1 << 23) - 1; // set all bits to indicate a NaN + } else if (exp == 0x0) { + // convert half-float zero/denorm to single precision value + if (mantissa) { + mantissa <<= 1; + exp = HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP; + // check for leading 1 in denorm mantissa + while ((mantissa & (1 << 10)) == 0) { + // for every leading 0, decrement single precision exponent by 1 + // and shift half-float mantissa value to the left + mantissa <<= 1; + exp -= (1 << 23); + } + // clamp the mantissa to 10-bits + mantissa &= ((1 << 10) - 1); + // shift left to generate single-precision mantissa of 23-bits + mantissa <<= 13; + } + } else { + // shift left to generate single-precision mantissa of 23-bits + mantissa <<= 13; + // generate single precision biased exponent value + exp = (exp << 13) + HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP; + } - f = (sign << 31) | exp | mantissa; - return *((float *)&f); + f = (sign << 31) | exp | mantissa; + return *((float*)&f); } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // DWORD Tesselator_SPU::tlsIdx = TlsAlloc(); -// -Tesselator_SPU *Tesselator_SPU::getInstance() -{ - return NULL; -// return (Tesselator_SPU *)TlsGetValue(tlsIdx); +// +Tesselator_SPU* Tesselator_SPU::getInstance() { + return NULL; + // return (Tesselator_SPU *)TlsGetValue(tlsIdx); } // void Tesselator_SPU::CreateNewThreadStorage(int bytes) @@ -180,129 +160,131 @@ Tesselator_SPU *Tesselator_SPU::getInstance() // TlsSetValue(tlsIdx, instance); // } - - - void Tesselator_SPU::end() - { -// // if (!tesselating) throw new IllegalStateException("Not tesselating!"); // 4J - removed -// tesselating = false; -// if (vertices > 0) -// { -// // 4J - a lot of stuff taken out here for fiddling round with enable client states etc. -// // that don't matter for our renderer -// if (!hasColor) -// { -// // 4J - TEMP put in fixed vertex colors if we don't have any, until we have a shader that can cope without them -// unsigned int *pColData = (unsigned int *)_array->data; -// pColData += 5; -// for( int i = 0; i < vertices; i++ ) -// { -// *pColData = 0xffffffff; -// pColData += 8; -// } -// } -// if (mode == GL_QUADS && TRIANGLE_MODE) -// { -// // glDrawArrays(GL_TRIANGLES, 0, vertices); // 4J - changed for xbox -// #ifdef _XBOX -// RenderManager.DrawVertices(D3DPT_TRIANGLELIST,vertices,_array->data, -// useCompactFormat360?C4JRender::VERTEX_TYPE_PS3_TS2_CS1:C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, -// useProjectedTexturePixelShader?C4JRender::PIXEL_SHADER_TYPE_PROJECTION:C4JRender::PIXEL_SHADER_TYPE_STANDARD); -// #else -// RenderManager.DrawVertices(C4JRender::PRIMITIVE_TYPE_TRIANGLE_LIST,vertices,_array->data, -// useCompactFormat360?C4JRender::VERTEX_TYPE_COMPRESSED:C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, -// useProjectedTexturePixelShader?C4JRender::PIXEL_SHADER_TYPE_PROJECTION:C4JRender::PIXEL_SHADER_TYPE_STANDARD); -// #endif -// } -// else -// { -// // glDrawArrays(mode, 0, vertices); // 4J - changed for xbox -// // For compact vertices, the vertexCount has to be calculated from the amount of data written, as -// // we insert extra fake vertices to encode supplementary data for more awkward quads that have non -// // axis aligned UVs (eg flowing lava/water) -// #ifdef _XBOX -// int vertexCount = vertices; -// if( useCompactFormat360 ) -// { -// vertexCount = p / 2; -// RenderManager.DrawVertices((D3DPRIMITIVETYPE)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PS3_TS2_CS1, C4JRender::PIXEL_SHADER_TYPE_STANDARD); -// } -// else -// { -// if( useProjectedTexturePixelShader ) -// { -// RenderManager.DrawVertices((D3DPRIMITIVETYPE)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN, C4JRender::PIXEL_SHADER_TYPE_PROJECTION); -// } -// else -// { -// RenderManager.DrawVertices((D3DPRIMITIVETYPE)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, C4JRender::PIXEL_SHADER_TYPE_STANDARD); -// } -// } -// #else -// int vertexCount = vertices; -// if( useCompactFormat360 ) -// { -// RenderManager.DrawVertices((C4JRender::ePrimitiveType)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_COMPRESSED, C4JRender::PIXEL_SHADER_TYPE_STANDARD); -// } -// else -// { -// if( useProjectedTexturePixelShader ) -// { -// RenderManager.DrawVertices((C4JRender::ePrimitiveType)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN, C4JRender::PIXEL_SHADER_TYPE_PROJECTION); -// } -// else -// { -// RenderManager.DrawVertices((C4JRender::ePrimitiveType)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, C4JRender::PIXEL_SHADER_TYPE_STANDARD); -// } -// } -// #endif -// } -// glDisableClientState(GL_VERTEX_ARRAY); -// if (hasTexture) glDisableClientState(GL_TEXTURE_COORD_ARRAY); -// if (hasColor) glDisableClientState(GL_COLOR_ARRAY); -// if (hasNormal) glDisableClientState(GL_NORMAL_ARRAY); -// } -// -// clear(); +void Tesselator_SPU::end() { + // // if (!tesselating) throw new IllegalStateException("Not + // tesselating!"); // 4J - removed + // tesselating = false; + // if (vertices > 0) + // { + // // 4J - a lot of stuff taken out here for fiddling round with + // enable client states etc. + // // that don't matter for our renderer + // if (!hasColor) + // { + // // 4J - TEMP put in fixed vertex colors if we don't have + // any, until we have a shader that can cope without them + // unsigned int *pColData = (unsigned int *)_array->data; + // pColData += 5; for( int i = 0; i < vertices; i++ ) + // { + // *pColData = 0xffffffff; + // pColData += 8; + // } + // } + // if (mode == GL_QUADS && TRIANGLE_MODE) + // { + // // glDrawArrays(GL_TRIANGLES, 0, vertices); // 4J - changed + // for xbox + // #ifdef _XBOX + // RenderManager.DrawVertices(D3DPT_TRIANGLELIST,vertices,_array->data, + // useCompactFormat360?C4JRender::VERTEX_TYPE_PS3_TS2_CS1:C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, + // useProjectedTexturePixelShader?C4JRender::PIXEL_SHADER_TYPE_PROJECTION:C4JRender::PIXEL_SHADER_TYPE_STANDARD); + // #else + // RenderManager.DrawVertices(C4JRender::PRIMITIVE_TYPE_TRIANGLE_LIST,vertices,_array->data, + // useCompactFormat360?C4JRender::VERTEX_TYPE_COMPRESSED:C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, + // useProjectedTexturePixelShader?C4JRender::PIXEL_SHADER_TYPE_PROJECTION:C4JRender::PIXEL_SHADER_TYPE_STANDARD); + // #endif + // } + // else + // { + // // glDrawArrays(mode, 0, vertices); // 4J - changed for xbox + // // For compact vertices, the vertexCount has to be + // calculated from the amount of data written, as + // // we insert extra fake vertices to encode supplementary + // data for more awkward quads that have non + // // axis aligned UVs (eg flowing lava/water) + // #ifdef _XBOX + // int vertexCount = vertices; + // if( useCompactFormat360 ) + // { + // vertexCount = p / 2; + // RenderManager.DrawVertices((D3DPRIMITIVETYPE)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PS3_TS2_CS1, + // C4JRender::PIXEL_SHADER_TYPE_STANDARD); + // } + // else + // { + // if( useProjectedTexturePixelShader ) + // { + // RenderManager.DrawVertices((D3DPRIMITIVETYPE)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN, + // C4JRender::PIXEL_SHADER_TYPE_PROJECTION); + // } + // else + // { + // RenderManager.DrawVertices((D3DPRIMITIVETYPE)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, + // C4JRender::PIXEL_SHADER_TYPE_STANDARD); + // } + // } + // #else + // int vertexCount = vertices; + // if( useCompactFormat360 ) + // { + // RenderManager.DrawVertices((C4JRender::ePrimitiveType)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_COMPRESSED, + // C4JRender::PIXEL_SHADER_TYPE_STANDARD); + // } + // else + // { + // if( useProjectedTexturePixelShader ) + // { + // RenderManager.DrawVertices((C4JRender::ePrimitiveType)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN, + // C4JRender::PIXEL_SHADER_TYPE_PROJECTION); + // } + // else + // { + // RenderManager.DrawVertices((C4JRender::ePrimitiveType)mode,vertexCount,_array->data,C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, + // C4JRender::PIXEL_SHADER_TYPE_STANDARD); + // } + // } + // #endif + // } + // glDisableClientState(GL_VERTEX_ARRAY); + // if (hasTexture) glDisableClientState(GL_TEXTURE_COORD_ARRAY); + // if (hasColor) glDisableClientState(GL_COLOR_ARRAY); + // if (hasNormal) glDisableClientState(GL_NORMAL_ARRAY); + // } + // + // clear(); } -void Tesselator_SPU::clear() -{ +void Tesselator_SPU::clear() { vertices = 0; p = 0; count = 0; } -void Tesselator_SPU::begin() -{ +void Tesselator_SPU::begin() { begin(GL_QUADS); - bounds.reset(); -} - -void Tesselator_SPU::useProjectedTexture(bool enable) -{ - useProjectedTexturePixelShader = enable; + bounds.reset(); } -void Tesselator_SPU::useCompactVertices(bool enable) -{ - useCompactFormat360 = enable; +void Tesselator_SPU::useProjectedTexture(bool enable) { + useProjectedTexturePixelShader = enable; } -bool Tesselator_SPU::setMipmapEnable(bool enable) -{ - bool prev = mipmapEnable; - mipmapEnable = enable; - return prev; +void Tesselator_SPU::useCompactVertices(bool enable) { + useCompactFormat360 = enable; } -void Tesselator_SPU::begin(int mode) -{ - /* // 4J - removed - if (tesselating) { - throw new IllegalStateException("Already tesselating!"); - } */ +bool Tesselator_SPU::setMipmapEnable(bool enable) { + bool prev = mipmapEnable; + mipmapEnable = enable; + return prev; +} + +void Tesselator_SPU::begin(int mode) { + /* // 4J - removed +if (tesselating) { + throw new IllegalStateException("Already tesselating!"); +} */ tesselating = true; clear(); @@ -310,40 +292,32 @@ void Tesselator_SPU::begin(int mode) hasNormal = false; hasColor = false; hasTexture = false; - hasTexture2 = false; + hasTexture2 = false; _noColor = false; } -void Tesselator_SPU::tex(float u, float v) -{ +void Tesselator_SPU::tex(float u, float v) { hasTexture = true; this->u = u; this->v = v; } -void Tesselator_SPU::tex2(int tex2) -{ +void Tesselator_SPU::tex2(int tex2) { hasTexture2 = true; - this->_tex2 = tex2; + this->_tex2 = tex2; } -void Tesselator_SPU::color(float r, float g, float b) -{ - color((int) (r * 255), (int) (g * 255), (int) (b * 255)); +void Tesselator_SPU::color(float r, float g, float b) { + color((int)(r * 255), (int)(g * 255), (int)(b * 255)); } -void Tesselator_SPU::color(float r, float g, float b, float a) -{ - color((int) (r * 255), (int) (g * 255), (int) (b * 255), (int) (a * 255)); +void Tesselator_SPU::color(float r, float g, float b, float a) { + color((int)(r * 255), (int)(g * 255), (int)(b * 255), (int)(a * 255)); } -void Tesselator_SPU::color(int r, int g, int b) -{ - color(r, g, b, 255); -} +void Tesselator_SPU::color(int r, int g, int b) { color(r, g, b, 255); } -void Tesselator_SPU::color(int r, int g, int b, int a) -{ +void Tesselator_SPU::color(int r, int g, int b, int a) { if (_noColor) return; if (r > 255) r = 255; @@ -356,48 +330,54 @@ void Tesselator_SPU::color(int r, int g, int b, int a) if (a < 0) a = 0; hasColor = true; - // 4J - removed little-endian option + // 4J - removed little-endian option col = (r << 24) | (g << 16) | (b << 8) | (a); } -void Tesselator_SPU::color(uint8_t r, uint8_t g, uint8_t b) -{ - color(r & 0xff, g & 0xff, b & 0xff); +void Tesselator_SPU::color(uint8_t r, uint8_t g, uint8_t b) { + color(r & 0xff, g & 0xff, b & 0xff); } -void Tesselator_SPU::vertexUV(float x, float y, float z, float u, float v) -{ +void Tesselator_SPU::vertexUV(float x, float y, float z, float u, float v) { tex(u, v); vertex(x, y, z); } -// Pack the 4 vertices of a quad up into a compact format. This is structured as 8 bytes per vertex, -// arranged in blocks of 4 vertices per quad. Currently this is (one letter per nyblle): +// Pack the 4 vertices of a quad up into a compact format. This is structured as +// 8 bytes per vertex, arranged in blocks of 4 vertices per quad. Currently this +// is (one letter per nyblle): // // cccc xxyy zzll rgbi (vertex 0) // umin xxyy zzll rgbi (vertex 1) // vmin xxyy zzll rgbi (vertex 2) // udvd xxyy zzll rgbi (vertex 3) // -// where: cccc is a 15-bit (5 bits per x/y/z) origin position / offset for the whole quad. Each -// component is unsigned, and offset by 16 so has a range 0 to 31 actually representing -16 to 15 -// xx,yy,zz are 8-bit deltas from this origin to each vertex. These are unsigned 1.7 fixed point, ie +// where: cccc is a 15-bit (5 bits per x/y/z) origin position / offset +// for the whole quad. Each +// component is unsigned, and offset by 16 +// so has a range 0 to 31 actually representing -16 to 15 +// xx,yy,zz are 8-bit deltas from this origin to each vertex. These are +// unsigned 1.7 fixed point, ie // representing a range of 0 to 1.9921875 // rgb is 4:4:4 RGB -// umin, vmin are 3:13 unsigned fixed point UVs reprenting the min u and v required by the quad -// ud,vd are 8-bit unsigned fixed pont UV deltas, which can be added to umin/vmin to get umax, vmax -// and therefore define the 4 corners of an axis aligned UV mapping -// i is a code per vertex that indicates which of umin/umax should be used for u, and which -// of vmin/vmax should be used for v for this vertex. The coding is: -// 0 - u = umin, v = vmin -// 1 - u = umin, v = vmax -// 2 - u = umax, v = vmin -// 3 - u = umax, v = vmax -// 4 - not axis aligned, use uv stored in the vertex data 4 on from this one -// ll is an 8-bit (4 bit per u/v) index into the current lighting texture +// umin, vmin are 3:13 unsigned fixed point UVs reprenting the min u and +// v required by the quad ud,vd are 8-bit unsigned fixed pont +// UV deltas, which can be added to umin/vmin to get umax, vmax +// and therefore define the 4 corners of +// an axis aligned UV mapping +// i is a code per vertex that indicates which of umin/umax +// should be used for u, and which +// of vmin/vmax should be used for v for +// this vertex. The coding is: 0 - u = +// umin, v = vmin 1 - u = umin, v +// = vmax 2 - u = umax, v = vmin +// 3 - u = umax, v = vmax 4 - not +// axis aligned, use uv stored in the vertex data 4 on from this one ll +// is an 8-bit (4 bit per u/v) index into the current lighting texture // -// For quads that don't have axis aligned UVs (ie have a code for 4 in i as described above) the 8 byte vertex -// is followed by a further 8 bytes which have explicit UVs defined for each vertex: +// For quads that don't have axis aligned UVs (ie have a code for 4 in i as +// described above) the 8 byte vertex is followed by a further 8 bytes which +// have explicit UVs defined for each vertex: // // 0000 0000 uuuu vvvv (vertex 0) // 0000 0000 uuuu vvvv (vertex 1) @@ -405,392 +385,377 @@ void Tesselator_SPU::vertexUV(float x, float y, float z, float u, float v) // 0000 0000 uuuu vvvv (vertex 3) // -void Tesselator_SPU::packCompactQuad() -{ - // Offset x/y/z by 16 so that we can deal with a -16 -> 16 range - for( int i = 0; i < 4; i++ ) - { - m_ix[i] += 16 * 128; - m_iy[i] += 16 * 128; - m_iz[i] += 16 * 128; - } - // Find min x/y/z - unsigned int minx = m_ix[0]; - unsigned int miny = m_iy[0]; - unsigned int minz = m_iz[0]; - for( int i = 1; i < 4; i++ ) - { - if( m_ix[i] < minx ) minx = m_ix[i]; - if( m_iy[i] < miny ) miny = m_iy[i]; - if( m_iz[i] < minz ) minz = m_iz[i]; - } - // Everything has been scaled by a factor of 128 to get it into an int, and so - // the minimum now should be in the range of (0->32) * 128. Get the base x/y/z - // that our quad will be referenced from now, which can be stored in 5 bits - unsigned int basex = ( minx >> 7 ); - unsigned int basey = ( miny >> 7 ); - unsigned int basez = ( minz >> 7 ); - // If the min is 32, then this whole quad must be in that plane - make the min 15 instead so - // we can still offset from that with our delta to get to the exact edge - if( basex == 32 ) basex = 31; - if( basey == 32 ) basey = 31; - if( basez == 32 ) basez = 31; - // Now get deltas to each vertex - these have an 8-bit range so they can span a - // full unit range from the base position - for( int i = 0; i < 4; i++ ) - { - m_ix[i] -= basex << 7; - m_iy[i] -= basey << 7; - m_iz[i] -= basez << 7; - } - // Now write the data out - unsigned int *data = (unsigned int *)&_array->data[p]; - - for( int i = 0; i < 4; i++ ) - { - data[i * 2 + 0] = ( m_ix[i] << 8 ) | ( m_iy[i] ); - data[i * 2 + 1] = ( m_iz[i] << 24 ) | ( m_clr[i] ); - } - data[0] |= ( basex << 26 ) | ( basey << 21 )| ( basez << 16 ); +void Tesselator_SPU::packCompactQuad() { + // Offset x/y/z by 16 so that we can deal with a -16 -> 16 range + for (int i = 0; i < 4; i++) { + m_ix[i] += 16 * 128; + m_iy[i] += 16 * 128; + m_iz[i] += 16 * 128; + } + // Find min x/y/z + unsigned int minx = m_ix[0]; + unsigned int miny = m_iy[0]; + unsigned int minz = m_iz[0]; + for (int i = 1; i < 4; i++) { + if (m_ix[i] < minx) minx = m_ix[i]; + if (m_iy[i] < miny) miny = m_iy[i]; + if (m_iz[i] < minz) minz = m_iz[i]; + } + // Everything has been scaled by a factor of 128 to get it into an int, and + // so the minimum now should be in the range of (0->32) * 128. Get the base + // x/y/z that our quad will be referenced from now, which can be stored in 5 + // bits + unsigned int basex = (minx >> 7); + unsigned int basey = (miny >> 7); + unsigned int basez = (minz >> 7); + // If the min is 32, then this whole quad must be in that plane - make the + // min 15 instead so we can still offset from that with our delta to get to + // the exact edge + if (basex == 32) basex = 31; + if (basey == 32) basey = 31; + if (basez == 32) basez = 31; + // Now get deltas to each vertex - these have an 8-bit range so they can + // span a full unit range from the base position + for (int i = 0; i < 4; i++) { + m_ix[i] -= basex << 7; + m_iy[i] -= basey << 7; + m_iz[i] -= basez << 7; + } + // Now write the data out + unsigned int* data = (unsigned int*)&_array->data[p]; - // Now process UVs. First find min & max U & V - unsigned int minu = m_u[0]; - unsigned int minv = m_v[0]; - unsigned int maxu = m_u[0]; - unsigned int maxv = m_v[0]; + for (int i = 0; i < 4; i++) { + data[i * 2 + 0] = (m_ix[i] << 8) | (m_iy[i]); + data[i * 2 + 1] = (m_iz[i] << 24) | (m_clr[i]); + } + data[0] |= (basex << 26) | (basey << 21) | (basez << 16); - for( int i = 1; i < 4; i++ ) - { - if( m_u[i] < minu ) minu = m_u[i]; - if( m_v[i] < minv ) minv = m_v[i]; - if( m_u[i] > maxu ) maxu = m_u[i]; - if( m_v[i] > maxv ) maxv = m_v[i]; - } - // In nearly all cases, all our UVs should be axis aligned for this quad. So the only values they should - // have in each dimension should be the min/max. We're going to store: - // (1) minu/maxu (16 bits each, only actuall needs to store 14 bits to get a 0 to 2 range for each - // (2) du/dv ( ie maxu-minu, maxv-minv) - 8 bits each, to store a range of 0 to 15.9375 texels. This - // should be enough to map the full UV range of a single 16x16 region of the terrain texture, since - // we always pull UVs in by 1/16th of their range at the sides - unsigned int du = maxu - minu; - unsigned int dv = maxv - minv; - if( du > 255 ) du = 255; - if( dv > 255 ) dv = 255; - // Check if this quad has UVs that can be referenced this way. This should only happen for flowing water - // and lava, where the texture coordinates are rotated for the top surface of the tile. - bool axisAligned = true; - for( int i = 0; i < 4; i++ ) - { - if(! ( ( ( m_u[i] == minu ) || ( m_u[i] == maxu ) ) && - ( ( m_v[i] == minv ) || ( m_v[i] == maxv ) ) ) ) - { - axisAligned = false; - } - } + // Now process UVs. First find min & max U & V + unsigned int minu = m_u[0]; + unsigned int minv = m_v[0]; + unsigned int maxu = m_u[0]; + unsigned int maxv = m_v[0]; - if( axisAligned ) - { - // Now go through each vertex, and work out which of the min/max should be used for each dimension, - // and store - for( int i = 0; i < 4; i++ ) - { - unsigned int code = 0; - if( m_u[i] == maxu ) code |= 2; - if( m_v[i] == maxv ) code |= 1; - data[i * 2 + 1] |= code; - data[i * 2 + 1] |= m_t2[i] << 16; - } - // Finally, store the minu/minv/du/dv - data[1 * 2 + 0] |= minu << 16; - data[2 * 2 + 0] |= minv << 16; - data[3 * 2 + 0] |= ( du << 24 | dv << 16 ); + for (int i = 1; i < 4; i++) { + if (m_u[i] < minu) minu = m_u[i]; + if (m_v[i] < minv) minv = m_v[i]; + if (m_u[i] > maxu) maxu = m_u[i]; + if (m_v[i] > maxv) maxv = m_v[i]; + } + // In nearly all cases, all our UVs should be axis aligned for this quad. So + // the only values they should have in each dimension should be the min/max. + // We're going to store: (1) minu/maxu (16 bits each, only actuall needs to + // store 14 bits to get a 0 to 2 range for each (2) du/dv ( ie maxu-minu, + // maxv-minv) - 8 bits each, to store a range of 0 to 15.9375 texels. This + // should be enough to map the full UV range of a single 16x16 region of the + // terrain texture, since we always pull UVs in by 1/16th of their range at + // the sides + unsigned int du = maxu - minu; + unsigned int dv = maxv - minv; + if (du > 255) du = 255; + if (dv > 255) dv = 255; + // Check if this quad has UVs that can be referenced this way. This should + // only happen for flowing water and lava, where the texture coordinates are + // rotated for the top surface of the tile. + bool axisAligned = true; + for (int i = 0; i < 4; i++) { + if (!(((m_u[i] == minu) || (m_u[i] == maxu)) && + ((m_v[i] == minv) || (m_v[i] == maxv)))) { + axisAligned = false; + } + } - incData(4 * 2); - } - else - { - // The UVs aren't axis aligned - store them in the next 4 vertices. These will be indexed from - // our base vertices because we'll set a special code (4) for the UVs. They won't be drawn as actual - // verts when these extra vertices go through the vertex shader, because we'll make sure that - // they get interpreted as a zero area quad and so they'll be quickly eliminated from rendering post-tranform + if (axisAligned) { + // Now go through each vertex, and work out which of the min/max should + // be used for each dimension, and store + for (int i = 0; i < 4; i++) { + unsigned int code = 0; + if (m_u[i] == maxu) code |= 2; + if (m_v[i] == maxv) code |= 1; + data[i * 2 + 1] |= code; + data[i * 2 + 1] |= m_t2[i] << 16; + } + // Finally, store the minu/minv/du/dv + data[1 * 2 + 0] |= minu << 16; + data[2 * 2 + 0] |= minv << 16; + data[3 * 2 + 0] |= (du << 24 | dv << 16); - for( int i = 0; i < 4; i++ ) - { - data[i * 2 + 1] |= ( 4 ); // The special code to indicate they need further data to be fetched - data[i * 2 + 1] |= m_t2[i] << 16; - data[8 + i * 2] = 0; // This includes x/y coordinate of each vert as (0,0) so they will be interpreted as a zero area quad - data[9 + i * 2] = m_u[i] << 16 | m_v[i]; - } + incData(4 * 2); + } else { + // The UVs aren't axis aligned - store them in the next 4 vertices. + // These will be indexed from our base vertices because we'll set a + // special code (4) for the UVs. They won't be drawn as actual verts + // when these extra vertices go through the vertex shader, because we'll + // make sure that they get interpreted as a zero area quad and so + // they'll be quickly eliminated from rendering post-tranform - // Extra 8 bytes required - incData(8 * 2); - } + for (int i = 0; i < 4; i++) { + data[i * 2 + 1] |= (4); // The special code to indicate they need + // further data to be fetched + data[i * 2 + 1] |= m_t2[i] << 16; + data[8 + i * 2] = + 0; // This includes x/y coordinate of each vert as (0,0) so + // they will be interpreted as a zero area quad + data[9 + i * 2] = m_u[i] << 16 | m_v[i]; + } + + // Extra 8 bytes required + incData(8 * 2); + } } -void Tesselator_SPU::vertex(float x, float y, float z) -{ - bounds.addVert(x+xo, y+yo, z+zo); // 4J MGH - added - count++; +void Tesselator_SPU::vertex(float x, float y, float z) { + bounds.addVert(x + xo, y + yo, z + zo); // 4J MGH - added + count++; - // Signal to pixel shader whether to use mipmapping or not, by putting u into > 1 range if it is to be disabled - float uu = mipmapEnable ? u : (u + 1.0f); + // Signal to pixel shader whether to use mipmapping or not, by putting u + // into > 1 range if it is to be disabled + float uu = mipmapEnable ? u : (u + 1.0f); - // 4J - this format added for 360 to keep memory size of tesselated tiles down - - // see comments in packCompactQuad() for exact format - if( useCompactFormat360 ) - { - unsigned int ucol = (unsigned int)col; + // 4J - this format added for 360 to keep memory size of tesselated tiles + // down - see comments in packCompactQuad() for exact format + if (useCompactFormat360) { + unsigned int ucol = (unsigned int)col; #ifdef _XBOX - // Pack as 4:4:4 RGB_ - unsigned short packedcol = (((col & 0xf0000000 ) >> 16 ) | - ((col & 0x00f00000 ) >> 12 ) | - ((col & 0x0000f000 ) >> 8 )); - int ipackedcol = ((int)packedcol) & 0xffff; // 0 to 65535 range + // Pack as 4:4:4 RGB_ + unsigned short packedcol = + (((col & 0xf0000000) >> 16) | ((col & 0x00f00000) >> 12) | + ((col & 0x0000f000) >> 8)); + int ipackedcol = ((int)packedcol) & 0xffff; // 0 to 65535 range - int quadIdx = vertices % 4; - m_ix[ quadIdx ] = (unsigned int)((x + xo) * 128.0f); - m_iy[ quadIdx ] = (unsigned int)((y + yo) * 128.0f); - m_iz[ quadIdx ] = (unsigned int)((z + zo) * 128.0f); - m_clr[ quadIdx ] = (unsigned int)ipackedcol; - m_u[ quadIdx ] = (int)(uu * 4096.0f); - m_v[ quadIdx ] = (int)(v * 4096.0f); - m_t2[ quadIdx ] = ( ( _tex2 & 0x00f00000 ) >> 20 ) | ( _tex2 & 0x000000f0 ); - if( quadIdx == 3 ) - { - packCompactQuad(); - } + int quadIdx = vertices % 4; + m_ix[quadIdx] = (unsigned int)((x + xo) * 128.0f); + m_iy[quadIdx] = (unsigned int)((y + yo) * 128.0f); + m_iz[quadIdx] = (unsigned int)((z + zo) * 128.0f); + m_clr[quadIdx] = (unsigned int)ipackedcol; + m_u[quadIdx] = (int)(uu * 4096.0f); + m_v[quadIdx] = (int)(v * 4096.0f); + m_t2[quadIdx] = ((_tex2 & 0x00f00000) >> 20) | (_tex2 & 0x000000f0); + if (quadIdx == 3) { + packCompactQuad(); + } #else - unsigned short packedcol = ((col & 0xf8000000 ) >> 16 ) | - ((col & 0x00fc0000 ) >> 13 ) | - ((col & 0x0000f800 ) >> 11 ); - int ipackedcol = ((int)packedcol) & 0xffff; // 0 to 65535 range + unsigned short packedcol = ((col & 0xf8000000) >> 16) | + ((col & 0x00fc0000) >> 13) | + ((col & 0x0000f800) >> 11); + int ipackedcol = ((int)packedcol) & 0xffff; // 0 to 65535 range - ipackedcol -= 32768; // -32768 to 32767 range - ipackedcol &= 0xffff; + ipackedcol -= 32768; // -32768 to 32767 range + ipackedcol &= 0xffff; - int16_t* pShortData = (int16_t*)&_array->data[p]; + int16_t* pShortData = (int16_t*)&_array->data[p]; #ifdef __PS3__ -#define INT_ROUND(x) (int)(floorf(x+0.5)) - float tex2U = ((int16_t*)&_tex2)[1] + 8; - float tex2V = ((int16_t*)&_tex2)[0] + 8; - float colVal1 = ((col&0xff000000)>>24)/256.0f; - float colVal2 = ((col&0x00ff0000)>>16)/256.0f; - float colVal3 = ((col&0x0000ff00)>>8)/256.0f; +#define INT_ROUND(x) (int)(floorf(x + 0.5)) + float tex2U = ((int16_t*)&_tex2)[1] + 8; + float tex2V = ((int16_t*)&_tex2)[0] + 8; + float colVal1 = ((col & 0xff000000) >> 24) / 256.0f; + float colVal2 = ((col & 0x00ff0000) >> 16) / 256.0f; + float colVal3 = ((col & 0x0000ff00) >> 8) / 256.0f; - // pShortData[0] = convertFloatToHFloat(x + xo); - // pShortData[1] = convertFloatToHFloat(y + yo); - // pShortData[2] = convertFloatToHFloat(z + zo); - // pShortData[3] = convertFloatToHFloat(uu); - // pShortData[4] = convertFloatToHFloat(tex2U + colVal1); - // pShortData[5] = convertFloatToHFloat(tex2V + colVal2); - // pShortData[6] = convertFloatToHFloat(colVal3); - // pShortData[7] = convertFloatToHFloat(v); + // pShortData[0] = convertFloatToHFloat(x + xo); + // pShortData[1] = convertFloatToHFloat(y + yo); + // pShortData[2] = convertFloatToHFloat(z + zo); + // pShortData[3] = convertFloatToHFloat(uu); + // pShortData[4] = convertFloatToHFloat(tex2U + colVal1); + // pShortData[5] = convertFloatToHFloat(tex2V + colVal2); + // pShortData[6] = convertFloatToHFloat(colVal3); + // pShortData[7] = convertFloatToHFloat(v); - pShortData[0] = ((INT_ROUND((x + xo ) * 1024.0f))&0xffff); - pShortData[1] = ((INT_ROUND((y + yo ) * 1024.0f))&0xffff); - pShortData[2] = ((INT_ROUND((z + zo ) * 1024.0f))&0xffff); - pShortData[3] = ipackedcol; - pShortData[4] = ((INT_ROUND(uu * 8192.0f))&0xffff); - pShortData[5] = ((INT_ROUND(v * 8192.0f))&0xffff); - pShortData[6] = ((INT_ROUND(tex2U * (8192.0f/256.0f)))&0xffff); - pShortData[7] = ((INT_ROUND(tex2V * (8192.0f/256.0f)))&0xffff); - incData(4); + pShortData[0] = ((INT_ROUND((x + xo) * 1024.0f)) & 0xffff); + pShortData[1] = ((INT_ROUND((y + yo) * 1024.0f)) & 0xffff); + pShortData[2] = ((INT_ROUND((z + zo) * 1024.0f)) & 0xffff); + pShortData[3] = ipackedcol; + pShortData[4] = ((INT_ROUND(uu * 8192.0f)) & 0xffff); + pShortData[5] = ((INT_ROUND(v * 8192.0f)) & 0xffff); + pShortData[6] = ((INT_ROUND(tex2U * (8192.0f / 256.0f))) & 0xffff); + pShortData[7] = ((INT_ROUND(tex2V * (8192.0f / 256.0f))) & 0xffff); + incData(4); #else - pShortData[0] = (((int)((x + xo ) * 1024.0f))&0xffff); - pShortData[1] = (((int)((y + yo ) * 1024.0f))&0xffff); - pShortData[2] = (((int)((z + zo ) * 1024.0f))&0xffff); - pShortData[3] = ipackedcol; - pShortData[4] = (((int)(uu * 8192.0f))&0xffff); - pShortData[5] = (((int)(v * 8192.0f))&0xffff); - pShortData[6] = ((int16_t*)&_tex2)[0]; - pShortData[7] = ((int16_t*)&_tex2)[1]; - incData(4); + pShortData[0] = (((int)((x + xo) * 1024.0f)) & 0xffff); + pShortData[1] = (((int)((y + yo) * 1024.0f)) & 0xffff); + pShortData[2] = (((int)((z + zo) * 1024.0f)) & 0xffff); + pShortData[3] = ipackedcol; + pShortData[4] = (((int)(uu * 8192.0f)) & 0xffff); + pShortData[5] = (((int)(v * 8192.0f)) & 0xffff); + pShortData[6] = ((int16_t*)&_tex2)[0]; + pShortData[7] = ((int16_t*)&_tex2)[1]; + incData(4); #endif #endif - vertices++; + vertices++; #ifdef _XBOX - if (vertices % 4 == 0 && ( ( p >= size - 8 * 2 ) || ( ( p / 2 ) >= 65532 ) ) ) // Max 65535 verts in D3D, so 65532 is the last point at the end of a quad to catch it + if (vertices % 4 == 0 && + ((p >= size - 8 * 2) || + ((p / 2) >= + 65532))) // Max 65535 verts in D3D, so 65532 is the last point at + // the end of a quad to catch it #else - if (vertices % 4 == 0 && ( ( p >= size - 4 * 4 ) || ( ( p / 4 ) >= 65532 ) ) ) // Max 65535 verts in D3D, so 65532 is the last point at the end of a quad to catch it + if (vertices % 4 == 0 && + ((p >= size - 4 * 4) || + ((p / 4) >= + 65532))) // Max 65535 verts in D3D, so 65532 is the last point at + // the end of a quad to catch it #endif - { -// end(); - tesselating = true; - } - } - else - { - if (mode == GL_QUADS && TRIANGLE_MODE && count % 4 == 0) - { - for (int i = 0; i < 2; i++) - { - int offs = 8 * (3 - i); - if (hasTexture) - { - _array->data[p + 3] = _array->data[p - offs + 3]; - _array->data[p + 4] = _array->data[p - offs + 4]; - } - if (hasColor) - { - _array->data[p + 5] = _array->data[p - offs + 5]; - } + { + // end(); + tesselating = true; + } + } else { + if (mode == GL_QUADS && TRIANGLE_MODE && count % 4 == 0) { + for (int i = 0; i < 2; i++) { + int offs = 8 * (3 - i); + if (hasTexture) { + _array->data[p + 3] = _array->data[p - offs + 3]; + _array->data[p + 4] = _array->data[p - offs + 4]; + } + if (hasColor) { + _array->data[p + 5] = _array->data[p - offs + 5]; + } - _array->data[p + 0] = _array->data[p - offs + 0]; - _array->data[p + 1] = _array->data[p - offs + 1]; - _array->data[p + 2] = _array->data[p - offs + 2]; + _array->data[p + 0] = _array->data[p - offs + 0]; + _array->data[p + 1] = _array->data[p - offs + 1]; + _array->data[p + 2] = _array->data[p - offs + 2]; - vertices++; - incData(8); - } - } + vertices++; + incData(8); + } + } - if (hasTexture) - { - float *fdata = (float *)(_array->data + p + 3); - *fdata++ = uu; - *fdata++ = v; - } - if (hasColor) - { - _array->data[p + 5] = col; - } - if (hasNormal) - { - _array->data[p + 6] = _normal; - } - if (hasTexture2) - { + if (hasTexture) { + float* fdata = (float*)(_array->data + p + 3); + *fdata++ = uu; + *fdata++ = v; + } + if (hasColor) { + _array->data[p + 5] = col; + } + if (hasNormal) { + _array->data[p + 6] = _normal; + } + if (hasTexture2) { #ifdef _XBOX - _array->data[p + 7] = ( ( _tex2 >> 16 ) & 0xffff ) | ( _tex2 << 16 ); + _array->data[p + 7] = ((_tex2 >> 16) & 0xffff) | (_tex2 << 16); #else #ifdef __PS3__ - int16_t tex2U = ((int16_t*)&_tex2)[1] + 8; - int16_t tex2V = ((int16_t*)&_tex2)[0] + 8; - int16_t* pShortArray = (int16_t*)&_array->data[p + 7]; - pShortArray[0] = tex2U; - pShortArray[1] = tex2V; + int16_t tex2U = ((int16_t*)&_tex2)[1] + 8; + int16_t tex2V = ((int16_t*)&_tex2)[0] + 8; + int16_t* pShortArray = (int16_t*)&_array->data[p + 7]; + pShortArray[0] = tex2U; + pShortArray[1] = tex2V; #else - _array->data[p + 7] = _tex2; + _array->data[p + 7] = _tex2; #endif #endif - } - else - { - // -512 each for u/v will mean that the renderer will use global settings (set via - // RenderManager.StateSetVertexTextureUV) rather than these local ones - *(unsigned int *)(&_array->data[p + 7]) = 0xfe00fe00; - } + } else { + // -512 each for u/v will mean that the renderer will use global + // settings (set via RenderManager.StateSetVertexTextureUV) rather + // than these local ones + *(unsigned int*)(&_array->data[p + 7]) = 0xfe00fe00; + } - float *fdata = (float *)(_array->data + p); - *fdata++ = (x + xo); - *fdata++ = (y + yo); - *fdata++ = (z + zo); - incData(8); + float* fdata = (float*)(_array->data + p); + *fdata++ = (x + xo); + *fdata++ = (y + yo); + *fdata++ = (z + zo); + incData(8); - vertices++; - if (vertices % 4 == 0 && p >= size - 8 * 4) - { -// end(); - tesselating = true; - } - } + vertices++; + if (vertices % 4 == 0 && p >= size - 8 * 4) { + // end(); + tesselating = true; + } + } } -void Tesselator_SPU::color(int c) -{ +void Tesselator_SPU::color(int c) { int r = ((c >> 16) & 255); int g = ((c >> 8) & 255); int b = ((c) & 255); color(r, g, b); } -void Tesselator_SPU::color(int c, int alpha) -{ +void Tesselator_SPU::color(int c, int alpha) { int r = ((c >> 16) & 255); int g = ((c >> 8) & 255); int b = ((c) & 255); color(r, g, b, alpha); } -void Tesselator_SPU::noColor() -{ - _noColor = true; -} +void Tesselator_SPU::noColor() { _noColor = true; } -void Tesselator_SPU::normal(float x, float y, float z) -{ +void Tesselator_SPU::normal(float x, float y, float z) { hasNormal = true; - uint8_t xx = (uint8_t) (x * 127); - uint8_t yy = (uint8_t) (y * 127); - uint8_t zz = (uint8_t) (z * 127); + uint8_t xx = (uint8_t)(x * 127); + uint8_t yy = (uint8_t)(y * 127); + uint8_t zz = (uint8_t)(z * 127); _normal = (xx & 0xff) | ((yy & 0xff) << 8) | ((zz & 0xff) << 16); } -void Tesselator_SPU::offset(float xo, float yo, float zo) -{ +void Tesselator_SPU::offset(float xo, float yo, float zo) { this->xo = xo; this->yo = yo; this->zo = zo; } -void Tesselator_SPU::addOffset(float x, float y, float z) -{ +void Tesselator_SPU::addOffset(float x, float y, float z) { xo += x; yo += y; zo += z; } -void Tesselator_SPU::incData( int numInts ) -{ - p+=numInts; +void Tesselator_SPU::incData(int numInts) { + p += numInts; #ifdef SN_TARGET_PS3_SPU - if(p > 4096) - { - int dmaSize = p*4; - unsigned int dmaTag = 2; - void* src = _array->data; - uintptr_t dest = (uintptr_t)(((char*)m_PPUArray) + m_PPUOffset); - if(sc_verbose) - spu_print("Tesselator : DMA SPU->PPU : 0x%08x -> 0x%08x : size : %d bytes\n", (unsigned int)src, (unsigned int)dest, dmaSize); - cellDmaLargePut(src, dest, dmaSize, dmaTag, 0, 0); - cellDmaWaitTagStatusAll(1 << dmaTag); + if (p > 4096) { + int dmaSize = p * 4; + unsigned int dmaTag = 2; + void* src = _array->data; + uintptr_t dest = (uintptr_t)(((char*)m_PPUArray) + m_PPUOffset); + if (sc_verbose) + spu_print( + "Tesselator : DMA SPU->PPU : 0x%08x -> 0x%08x : size : %d " + "bytes\n", + (unsigned int)src, (unsigned int)dest, dmaSize); + cellDmaLargePut(src, dest, dmaSize, dmaTag, 0, 0); + cellDmaWaitTagStatusAll(1 << dmaTag); -// int copySize = (p-4096); -// for(int i=0;idata[i] = _array->data[4096+i]; - //p -= 4096; - p=0; - m_PPUOffset += dmaSize;//16384; - } -#endif // SN_TARGET_PS3_SPU + // int copySize = (p-4096); + // for(int i=0;idata[i] = _array->data[4096+i]; + // p -= 4096; + p = 0; + m_PPUOffset += dmaSize; // 16384; + } +#endif // SN_TARGET_PS3_SPU } -void Tesselator_SPU::endData() -{ +void Tesselator_SPU::endData() { #ifdef SN_TARGET_PS3_SPU - int dmaSize = p*4; - unsigned int dmaTag = 2; - void* src = _array->data; - uintptr_t dest = (uintptr_t)(((char*)m_PPUArray) + m_PPUOffset); - if(sc_verbose) - spu_print("Tesselator : DMA SPU->PPU : 0x%08x -> 0x%08x : size : %d bytes\n", (unsigned int)src, (unsigned int)dest, dmaSize); - cellDmaLargePut(src, dest, dmaSize, dmaTag, 0, 0); - cellDmaWaitTagStatusAll(1 << dmaTag); - if(sc_verbose) - spu_print("endData - Tesselator : DMA SPU->PPU complete : %d verts, %d bytes in total\n", vertices, m_PPUOffset+ dmaSize); - p=0; - m_PPUOffset += dmaSize; -#else // SN_TARGET_PS3_SPU - m_PPUOffset = p*4; + int dmaSize = p * 4; + unsigned int dmaTag = 2; + void* src = _array->data; + uintptr_t dest = (uintptr_t)(((char*)m_PPUArray) + m_PPUOffset); + if (sc_verbose) + spu_print( + "Tesselator : DMA SPU->PPU : 0x%08x -> 0x%08x : size : %d bytes\n", + (unsigned int)src, (unsigned int)dest, dmaSize); + cellDmaLargePut(src, dest, dmaSize, dmaTag, 0, 0); + cellDmaWaitTagStatusAll(1 << dmaTag); + if (sc_verbose) + spu_print( + "endData - Tesselator : DMA SPU->PPU complete : %d verts, %d bytes " + "in total\n", + vertices, m_PPUOffset + dmaSize); + p = 0; + m_PPUOffset += dmaSize; +#else // SN_TARGET_PS3_SPU + m_PPUOffset = p * 4; #endif } -void Tesselator_SPU::beginData() -{ - p = 0; -} +void Tesselator_SPU::beginData() { p = 0; } diff --git a/Minecraft.Client/Player/EntityTracker.cpp b/Minecraft.Client/Player/EntityTracker.cpp index 81e6b020d..901054c14 100644 --- a/Minecraft.Client/Player/EntityTracker.cpp +++ b/Minecraft.Client/Player/EntityTracker.cpp @@ -17,7 +17,6 @@ #include "../../Minecraft.World/Headers/net.minecraft.network.packet.h" #include "../../Minecraft.World/Headers/net.minecraft.network.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.dimension.h" -#include "../../Minecraft.World/Util/BasicTypeContainers.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.chunk.h" #include "../Network/PlayerConnection.h" @@ -250,4 +249,4 @@ std::shared_ptr EntityTracker::getTracker( return it->second; } return nullptr; -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 313922573..2554b3532 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -1,5 +1,6 @@ #include "../Platform/stdafx.h" #include "LevelRenderer.h" +#include #include "../Textures/Textures.h" #include "../Textures/TextureAtlas.h" #include "Tesselator.h" @@ -59,7 +60,6 @@ #include "../Level/MultiPlayerLevel.h" #include "../../Minecraft.World/Util/SoundTypes.h" #include "FrustumCuller.h" -#include "../../Minecraft.World/Util/BasicTypeContainers.h" // #define DISABLE_SPU_CODE @@ -2920,9 +2920,9 @@ std::shared_ptr LevelRenderer::addParticleInternal( // optimised PS3 code which reverses the logic on the comparison with // particleDistanceSquared and gets the opposite result to what you might // expect. - if (Double::isNaN(x)) return nullptr; - if (Double::isNaN(y)) return nullptr; - if (Double::isNaN(z)) return nullptr; + if (std::isnan(x)) return nullptr; + if (std::isnan(y)) return nullptr; + if (std::isnan(z)) return nullptr; int particleLevel = mc->options->particles; diff --git a/Minecraft.Client/Rendering/Tesselator.cpp b/Minecraft.Client/Rendering/Tesselator.cpp index a08a9f9b9..49e6f5669 100644 --- a/Minecraft.Client/Rendering/Tesselator.cpp +++ b/Minecraft.Client/Rendering/Tesselator.cpp @@ -1,6 +1,5 @@ #include "../Platform/stdafx.h" #include "Tesselator.h" -#include "../../Minecraft.World/Util/BasicTypeContainers.h" #include "../../Minecraft.World/IO/Streams/FloatBuffer.h" #include "../../Minecraft.World/IO/Streams/IntBuffer.h" #include "../../Minecraft.World/IO/Streams/ByteBuffer.h" diff --git a/Minecraft.World/AI/Goals/BreedGoal.cpp b/Minecraft.World/AI/Goals/BreedGoal.cpp index 5281598d9..25281c61d 100644 --- a/Minecraft.World/AI/Goals/BreedGoal.cpp +++ b/Minecraft.World/AI/Goals/BreedGoal.cpp @@ -4,8 +4,8 @@ #include "../../Headers/net.minecraft.world.entity.animal.h" #include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.phys.h" -#include "../../Util/BasicTypeContainers.h" #include "BreedGoal.h" +#include #include "../../Entities/Mobs/ExperienceOrb.h" #include "../../Stats/GenericStats.h" @@ -50,7 +50,7 @@ std::shared_ptr BreedGoal::getFreePartner() { float r = 8; std::vector >* others = level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(r, r, r)); - double dist = Double::MAX_VALUE; + double dist = std::numeric_limits::max(); std::shared_ptr partner = nullptr; for (AUTO_VAR(it, others->begin()); it != others->end(); ++it) { std::shared_ptr p = std::dynamic_pointer_cast(*it); diff --git a/Minecraft.World/AI/Goals/FollowParentGoal.cpp b/Minecraft.World/AI/Goals/FollowParentGoal.cpp index 1bbe808a6..d60dd34a9 100644 --- a/Minecraft.World/AI/Goals/FollowParentGoal.cpp +++ b/Minecraft.World/AI/Goals/FollowParentGoal.cpp @@ -3,8 +3,8 @@ #include "../../Headers/net.minecraft.world.entity.ai.navigation.h" #include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.phys.h" -#include "../../Util/BasicTypeContainers.h" #include "FollowParentGoal.h" +#include FollowParentGoal::FollowParentGoal(Animal* animal, double speedModifier) { timeToRecalcPath = 0; @@ -21,7 +21,7 @@ bool FollowParentGoal::canUse() { animal->bb->grow(8, 4, 8)); std::shared_ptr closest = nullptr; - double closestDistSqr = Double::MAX_VALUE; + double closestDistSqr = std::numeric_limits::max(); for (AUTO_VAR(it, parents->begin()); it != parents->end(); ++it) { std::shared_ptr parent = std::dynamic_pointer_cast(*it); if (parent->getAge() < 0) continue; @@ -53,4 +53,4 @@ void FollowParentGoal::tick() { if (--timeToRecalcPath > 0) return; timeToRecalcPath = 10; animal->getNavigation()->moveTo(parent.lock(), speedModifier); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp b/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp index 1ef14e1ed..a5c511525 100644 --- a/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp +++ b/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp @@ -5,8 +5,8 @@ #include "../../Headers/net.minecraft.world.entity.ai.village.h" #include "../../Headers/net.minecraft.world.entity.h" #include "../../Headers/net.minecraft.world.level.h" -#include "../../Util/BasicTypeContainers.h" #include "MoveThroughVillageGoal.h" +#include #include "../Navigation/Path.h" MoveThroughVillageGoal::MoveThroughVillageGoal(PathfinderMob* mob, @@ -86,7 +86,7 @@ void MoveThroughVillageGoal::stop() { std::shared_ptr MoveThroughVillageGoal::getNextDoorInfo( std::shared_ptr village) { std::shared_ptr closest = nullptr; - int closestDistSqr = Integer::MAX_VALUE; + int closestDistSqr = std::numeric_limits::max(); std::vector >* doorInfos = village->getDoorInfos(); // for (DoorInfo di : doorInfos) @@ -120,4 +120,4 @@ bool MoveThroughVillageGoal::hasVisited(std::shared_ptr di) { void MoveThroughVillageGoal::updateVisited() { if (visited.size() > 15) visited.erase(visited.begin()); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/OcelotSitOnTileGoal.cpp b/Minecraft.World/AI/Goals/OcelotSitOnTileGoal.cpp index 134fc71fb..058565138 100644 --- a/Minecraft.World/AI/Goals/OcelotSitOnTileGoal.cpp +++ b/Minecraft.World/AI/Goals/OcelotSitOnTileGoal.cpp @@ -6,9 +6,9 @@ #include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.level.tile.h" #include "../../Headers/net.minecraft.world.level.tile.entity.h" -#include "../../Util/BasicTypeContainers.h" #include "../../Util/Arrays.h" #include "OcelotSitOnTileGoal.h" +#include const int OcelotSitOnTileGoal::GIVE_UP_TICKS = 3 * SharedConstants::TICKS_PER_SECOND; @@ -77,7 +77,7 @@ void OcelotSitOnTileGoal::tick() { bool OcelotSitOnTileGoal::findNearestTile() { int y = (int)ocelot->y; - double distSqr = Integer::MAX_VALUE; + double distSqr = std::numeric_limits::max(); for (int x = (int)ocelot->x - SEARCH_RANGE; x < ocelot->x + SEARCH_RANGE; x++) { @@ -97,7 +97,7 @@ bool OcelotSitOnTileGoal::findNearestTile() { } } - return distSqr < Integer::MAX_VALUE; + return distSqr < std::numeric_limits::max(); } bool OcelotSitOnTileGoal::isValidTarget(Level* level, int x, int y, int z) { @@ -119,4 +119,4 @@ bool OcelotSitOnTileGoal::isValidTarget(Level* level, int x, int y, int z) { } return false; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/PlayGoal.cpp b/Minecraft.World/AI/Goals/PlayGoal.cpp index 3096e325e..4c933d513 100644 --- a/Minecraft.World/AI/Goals/PlayGoal.cpp +++ b/Minecraft.World/AI/Goals/PlayGoal.cpp @@ -6,8 +6,8 @@ #include "../../Headers/net.minecraft.world.entity.h" #include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.phys.h" -#include "../../Util/BasicTypeContainers.h" #include "PlayGoal.h" +#include PlayGoal::PlayGoal(Villager* mob, double speedModifier) { followFriend = std::weak_ptr(); @@ -26,7 +26,7 @@ bool PlayGoal::canUse() { std::vector >* children = mob->level->getEntitiesOfClass(typeid(Villager), mob->bb->grow(6, 3, 6)); - double closestDistSqr = Double::MAX_VALUE; + double closestDistSqr = std::numeric_limits::max(); // for (Entity c : children) for (AUTO_VAR(it, children->begin()); it != children->end(); ++it) { std::shared_ptr c = *it; @@ -80,4 +80,4 @@ void PlayGoal::tick() { mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speedModifier); } } -} \ No newline at end of file +} diff --git a/Minecraft.World/Commands/KillCommand.cpp b/Minecraft.World/Commands/KillCommand.cpp index ac72f6211..fef099420 100644 --- a/Minecraft.World/Commands/KillCommand.cpp +++ b/Minecraft.World/Commands/KillCommand.cpp @@ -2,8 +2,8 @@ #include "../Headers/net.minecraft.commands.h" #include "../Headers/net.minecraft.world.entity.player.h" #include "../Headers/net.minecraft.world.damagesource.h" -#include "../Util/BasicTypeContainers.h" #include "KillCommand.h" +#include EGameCommand KillCommand::getId() { return eGameCommand_Kill; } @@ -13,8 +13,8 @@ void KillCommand::execute(std::shared_ptr source, byteArray commandData) { std::shared_ptr player = std::dynamic_pointer_cast(source); - player->hurt(DamageSource::outOfWorld, Float::MAX_VALUE); + player->hurt(DamageSource::outOfWorld, std::numeric_limits::max()); source->sendMessage(L"Ouch. That look like it hurt."); // source.sendMessage(ChatMessageComponent.forTranslation("commands.kill.success")); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/LivingEntity.cpp b/Minecraft.World/Entities/LivingEntity.cpp index 18e5369f3..e795f18cf 100644 --- a/Minecraft.World/Entities/LivingEntity.cpp +++ b/Minecraft.World/Entities/LivingEntity.cpp @@ -28,7 +28,6 @@ #include "../../Minecraft.Client/Level/ServerLevel.h" #include "../../Minecraft.Client/Player/EntityTracker.h" #include "../Util/SoundTypes.h" -#include "../Util/BasicTypeContainers.h" #include "../Util/ParticleTypes.h" #include "../Stats/GenericStats.h" #include "ItemEntity.h" @@ -1732,4 +1731,4 @@ bool LivingEntity::isAlliedTo(Team* other) { return getTeam()->isAlliedTo(other); } return false; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mob.cpp b/Minecraft.World/Entities/Mob.cpp index 5ad523917..6b744faf8 100644 --- a/Minecraft.World/Entities/Mob.cpp +++ b/Minecraft.World/Entities/Mob.cpp @@ -25,7 +25,6 @@ #include "Mob.h" #include "../../Minecraft.Client/Textures/Textures.h" #include "../Util/SoundTypes.h" -#include "../Util/BasicTypeContainers.h" #include "../Util/ParticleTypes.h" #include "../Stats/GenericStats.h" #include "ItemEntity.h" @@ -901,4 +900,4 @@ void Mob::setLevel(Level* level) { navigation->setLevel(level); goalSelector.setLevel(level); targetSelector.setLevel(level); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.cpp b/Minecraft.World/Entities/Mobs/EnderDragon.cpp index 920c5c75d..582bda987 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.cpp +++ b/Minecraft.World/Entities/Mobs/EnderDragon.cpp @@ -8,12 +8,12 @@ #include "../../Headers/net.minecraft.world.entity.projectile.h" #include "../../Headers/net.minecraft.world.phys.h" #include "../../Headers/net.minecraft.world.damagesource.h" -#include "../../Util/BasicTypeContainers.h" #include "../../../Minecraft.Client/Textures/Textures.h" #include "../../Headers/net.minecraft.world.entity.boss.enderdragon.h" #include "../../Headers/net.minecraft.world.level.pathfinder.h" #include "../../Util/SharedConstants.h" #include "EnderDragon.h" +#include #define PRINT_DRAGON_STATE_CHANGE_MESSAGES 1 @@ -815,7 +815,7 @@ void EnderDragon::checkCrystals() { bb->grow(maxDist, maxDist, maxDist)); std::shared_ptr crystal = nullptr; - double nearest = Double::MAX_VALUE; + double nearest = std::numeric_limits::max(); // for (Entity ec : crystals) for (AUTO_VAR(it, crystals->begin()); it != crystals->end(); ++it) { std::shared_ptr ec = diff --git a/Minecraft.World/Entities/Mobs/EntityHorse.cpp b/Minecraft.World/Entities/Mobs/EntityHorse.cpp index 288933779..65502c329 100644 --- a/Minecraft.World/Entities/Mobs/EntityHorse.cpp +++ b/Minecraft.World/Entities/Mobs/EntityHorse.cpp @@ -15,8 +15,8 @@ #include "../../Headers/net.minecraft.world.phys.h" #include "../../../Minecraft.Client/Textures/Textures.h" #include "../../../Minecraft.Client/Minecraft.h" -#include "../../Util/BasicTypeContainers.h" #include "EntityHorse.h" +#include const std::wstring EntityHorse::TEX_FOLDER = L"mob/horse/"; @@ -417,7 +417,7 @@ bool EntityHorse::canSpawn() { std::shared_ptr EntityHorse::getClosestMommy( std::shared_ptr baby, double searchRadius) { - double closestDistance = Double::MAX_VALUE; + double closestDistance = std::numeric_limits::max(); std::shared_ptr mommy = nullptr; std::vector >* list = level->getEntities( @@ -1517,4 +1517,4 @@ bool EntityHorse::onLadder() { std::shared_ptr EntityHorse::getOwner() { return level->getPlayerByUUID(getOwnerName()); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/SharedMonsterAttributes.cpp b/Minecraft.World/Entities/Mobs/SharedMonsterAttributes.cpp index c9a45521a..426862dd5 100644 --- a/Minecraft.World/Entities/Mobs/SharedMonsterAttributes.cpp +++ b/Minecraft.World/Entities/Mobs/SharedMonsterAttributes.cpp @@ -1,11 +1,11 @@ #include "../../Platform/stdafx.h" #include "../../Headers/net.minecraft.world.entity.ai.attributes.h" -#include "../../Util/BasicTypeContainers.h" #include "SharedMonsterAttributes.h" +#include Attribute* SharedMonsterAttributes::MAX_HEALTH = (new RangedAttribute(eAttributeId_GENERIC_MAXHEALTH, 20, 0, - Double::MAX_VALUE)) + std::numeric_limits::max())) ->setSyncable(true); Attribute* SharedMonsterAttributes::FOLLOW_RANGE = (new RangedAttribute(eAttributeId_GENERIC_FOLLOWRANGE, 32, 0, 2048)); @@ -13,10 +13,11 @@ Attribute* SharedMonsterAttributes::KNOCKBACK_RESISTANCE = (new RangedAttribute(eAttributeId_GENERIC_KNOCKBACKRESISTANCE, 0, 0, 1)); Attribute* SharedMonsterAttributes::MOVEMENT_SPEED = (new RangedAttribute(eAttributeId_GENERIC_MOVEMENTSPEED, 0.7f, 0, - Double::MAX_VALUE)) + std::numeric_limits::max())) ->setSyncable(true); -Attribute* SharedMonsterAttributes::ATTACK_DAMAGE = new RangedAttribute( - eAttributeId_GENERIC_ATTACKDAMAGE, 2, 0, Double::MAX_VALUE); +Attribute* SharedMonsterAttributes::ATTACK_DAMAGE = + new RangedAttribute(eAttributeId_GENERIC_ATTACKDAMAGE, 2, 0, + std::numeric_limits::max()); ListTag* SharedMonsterAttributes::saveAttributes( BaseAttributeMap* attributes) { @@ -108,4 +109,4 @@ AttributeModifier* SharedMonsterAttributes::loadAttributeModifier( eMODIFIER_ID id = (eMODIFIER_ID)tag->getInt(L"UUID"); return new AttributeModifier(id, tag->getDouble(L"Amount"), tag->getInt(L"Operation")); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Spider.cpp b/Minecraft.World/Entities/Mobs/Spider.cpp index ba427522f..085eb2d49 100644 --- a/Minecraft.World/Entities/Mobs/Spider.cpp +++ b/Minecraft.World/Entities/Mobs/Spider.cpp @@ -9,8 +9,8 @@ #include "../../Headers/net.minecraft.world.entity.h" #include "../../Headers/net.minecraft.world.entity.monster.h" #include "../../Headers/com.mojang.nbt.h" -#include "../../Util/BasicTypeContainers.h" #include "Spider.h" +#include #include "../../../Minecraft.Client/Textures/Textures.h" #include "../../Util/SoundTypes.h" @@ -173,7 +173,8 @@ MobGroupData* Spider::finalizeMobSpawn( if (dynamic_cast(groupData) != NULL) { int effect = ((SpiderEffectsGroupData*)groupData)->effectId; if (effect > 0 && MobEffect::effects[effect] != NULL) { - addEffect(new MobEffectInstance(effect, Integer::MAX_VALUE)); + addEffect( + new MobEffectInstance(effect, std::numeric_limits::max())); } } @@ -195,4 +196,4 @@ void Spider::SpiderEffectsGroupData::setRandomEffect(Random* random) { } else if (selection <= 4) { effectId = MobEffect::invisibility->id; } -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/SyncedEntityData.cpp b/Minecraft.World/Entities/SyncedEntityData.cpp index e12f9b559..d96717301 100644 --- a/Minecraft.World/Entities/SyncedEntityData.cpp +++ b/Minecraft.World/Entities/SyncedEntityData.cpp @@ -1,6 +1,5 @@ #include "../Platform/stdafx.h" #include "../Util/Class.h" -#include "../Util/BasicTypeContainers.h" #include "../IO/Streams/InputOutputStream.h" #include "../Headers/net.minecraft.h" #include "../Headers/net.minecraft.network.packet.h" @@ -542,4 +541,4 @@ int SynchedEntityData::DataItem::getType() { return type; } bool SynchedEntityData::DataItem::isDirty() { return dirty; } -void SynchedEntityData::DataItem::setDirty(bool dirty) { this->dirty = dirty; } \ No newline at end of file +void SynchedEntityData::DataItem::setDirty(bool dirty) { this->dirty = dirty; } diff --git a/Minecraft.World/IO/Streams/DataInputStream.cpp b/Minecraft.World/IO/Streams/DataInputStream.cpp index bb2def07c..4bae236db 100644 --- a/Minecraft.World/IO/Streams/DataInputStream.cpp +++ b/Minecraft.World/IO/Streams/DataInputStream.cpp @@ -1,7 +1,8 @@ #include "../../Platform/stdafx.h" -#include "../../Util/BasicTypeContainers.h" #include "DataInputStream.h" +#include +#include // Creates a DataInputStream that uses the specified underlying InputStream. // Parameters: @@ -146,7 +147,7 @@ unsigned char DataInputStream::readUnsignedByte() { // Reads two input bytes and returns a char value. Let a be the first byte read // and b be the second byte. The value returned is: (char)((a << 8) | (b & -//0xff)) +// 0xff)) // // This method is suitable for reading bytes written by the writeChar method of // interface DataOutput. Returns: the char value read. @@ -229,7 +230,7 @@ bool DataInputStream::readFully(charArray b) { double DataInputStream::readDouble() { int64_t bits = readLong(); - return Double::longBitsToDouble(bits); + return std::bit_cast(bits); } // Reads four input bytes and returns a float value. It does this by first @@ -240,7 +241,7 @@ double DataInputStream::readDouble() { float DataInputStream::readFloat() { int bits = readInt(); - return Float::intBitsToFloat(bits); + return std::bit_cast(bits); } // Reads four input bytes and returns an int value. Let a-d be the first through @@ -308,7 +309,7 @@ int64_t DataInputStream::readLong() { // Reads two input bytes and returns a short value. Let a be the first byte read // and b be the second byte. The value returned is: (short)((a << 8) | (b & -//0xff)) +// 0xff)) // // This method is suitable for reading the bytes written by the writeShort // method of interface DataOutput. Returns: the 16-bit value read. @@ -326,7 +327,8 @@ short DataInputStream::readShort() { unsigned short DataInputStream::readUnsignedShort() { if (stream == NULL) { app.DebugPrintf( - "DataInputStream::readUnsignedShort() but underlying stream is NULL\n"); + "DataInputStream::readUnsignedShort() but underlying stream is " + "NULL\n"); return 0; } int a = stream->read(); @@ -392,8 +394,8 @@ std::wstring DataInputStream::readUTF() { unsigned short UTFLength = (unsigned short)(((a & 0xff) << 8) | (b & 0xff)); //// 4J Stu - I decided while writing DataOutputStream that we didn't need - ///to bother using the UTF8 format / used in the java libs, and just write - ///in/out as wchar_t all the time + /// to bother using the UTF8 format / used in the java libs, and just write + /// in/out as wchar_t all the time /*for( unsigned short i = 0; i < UTFLength; i++) { diff --git a/Minecraft.World/IO/Streams/DataOutputStream.cpp b/Minecraft.World/IO/Streams/DataOutputStream.cpp index c51a666c4..78b63e8c4 100644 --- a/Minecraft.World/IO/Streams/DataOutputStream.cpp +++ b/Minecraft.World/IO/Streams/DataOutputStream.cpp @@ -1,7 +1,8 @@ #include "../../Platform/stdafx.h" -#include "../../Util/BasicTypeContainers.h" #include "DataOutputStream.h" +#include +#include // Creates a new data output stream to write data to the specified underlying // output stream. The counter written is set to zero. Parameters: out - the @@ -86,7 +87,7 @@ void DataOutputStream::writeByte(uint8_t a) { // counter written is incremented by 8. Parameters: v - a double value to be // written. void DataOutputStream::writeDouble(double a) { - int64_t bits = Double::doubleToLongBits(a); + int64_t bits = std::bit_cast(a); writeLong(bits); // TODO 4J Stu - Error handling? @@ -98,7 +99,7 @@ void DataOutputStream::writeDouble(double a) { // as a 4-byte quantity, high byte first. If no exception is thrown, the counter // written is incremented by 4. Parameters: v - a float value to be written. void DataOutputStream::writeFloat(float a) { - int bits = Float::floatToIntBits(a); + int bits = std::bit_cast(a); writeInt(bits); // TODO 4J Stu - Error handling? @@ -149,7 +150,8 @@ void DataOutputStream::writeShort(short a) { void DataOutputStream::writeUnsignedShort(unsigned short a) { if (stream == NULL) { app.DebugPrintf( - "DataOutputStream::writeUnsignedShort() but underlying stream is NULL\n"); + "DataOutputStream::writeUnsignedShort() but underlying stream is " + "NULL\n"); return; } stream->write(static_cast((a >> 8) & 0xff)); diff --git a/Minecraft.World/Level/Level.cpp b/Minecraft.World/Level/Level.cpp index bf7c95ad7..4c8862d2d 100644 --- a/Minecraft.World/Level/Level.cpp +++ b/Minecraft.World/Level/Level.cpp @@ -1,6 +1,5 @@ #include "../Platform/stdafx.h" #include "../Platform/System.h" -#include "../Util/BasicTypeContainers.h" #include "../IO/Files/File.h" #include "../Util/ProgressListener.h" #include "../Headers/net.minecraft.h" @@ -39,7 +38,9 @@ #include "../../Minecraft.Client/Platform/Common/DLC/DLCPack.h" #include "../../Minecraft.Client/Platform/PS3/PS3Extras/ShutdownManager.h" #include "../../Minecraft.Client/MinecraftServer.h" +#include #include +#include // 4J : WESTY : Added for time played stats. #include "../Headers/net.minecraft.stats.h" @@ -1374,10 +1375,8 @@ HitResult* Level::clip(Vec3* a, Vec3* b, bool liquid) { } HitResult* Level::clip(Vec3* a, Vec3* b, bool liquid, bool solidOnly) { - if (Double::isNaN(a->x) || Double::isNaN(a->y) || Double::isNaN(a->z)) - return NULL; - if (Double::isNaN(b->x) || Double::isNaN(b->y) || Double::isNaN(b->z)) - return NULL; + if (std::isnan(a->x) || std::isnan(a->y) || std::isnan(a->z)) return NULL; + if (std::isnan(b->x) || std::isnan(b->y) || std::isnan(b->z)) return NULL; int xTile1 = Mth::floor(b->x); int yTile1 = Mth::floor(b->y); @@ -1403,7 +1402,7 @@ HitResult* Level::clip(Vec3* a, Vec3* b, bool liquid, bool solidOnly) { int maxIterations = 200; while (maxIterations-- >= 0) { - if (Double::isNaN(a->x) || Double::isNaN(a->y) || Double::isNaN(a->z)) + if (std::isnan(a->x) || std::isnan(a->y) || std::isnan(a->z)) return NULL; if (xTile0 == xTile1 && yTile0 == yTile1 && zTile0 == zTile1) return NULL; @@ -2308,13 +2307,12 @@ void Level::tick(std::shared_ptr e, bool actual) { } // SANTITY!! - if (Double::isNaN(e->x) || Double::isInfinite(e->x)) e->x = e->xOld; - if (Double::isNaN(e->y) || Double::isInfinite(e->y)) e->y = e->yOld; - if (Double::isNaN(e->z) || Double::isInfinite(e->z)) e->z = e->zOld; - if (Double::isNaN(e->xRot) || Double::isInfinite(e->xRot)) - e->xRot = e->xRotO; - if (Double::isNaN(e->yRot) || Double::isInfinite(e->yRot)) - e->yRot = e->yRotO; + + if (!std::isfinite(e->x)) e->x = e->xOld; + if (!std::isfinite(e->y)) e->y = e->yOld; + if (!std::isfinite(e->z)) e->z = e->zOld; + if (!std::isfinite(e->xRot)) e->xRot = e->xRotO; + if (!std::isfinite(e->yRot)) e->yRot = e->yRotO; int xcn = Mth::floor(e->x / 16); int ycn = Mth::floor(e->y / 16); @@ -2931,7 +2929,7 @@ void Level::toggleDownfall() { } void Level::buildAndPrepareChunksToPoll() { -#if 0 +#if 0 AUTO_VAR(itEnd, players.end()); for (AUTO_VAR(it, players.begin()); it != itEnd; it++) { @@ -3512,7 +3510,7 @@ std::shared_ptr Level::getClosestEntityOfClass( std::vector >* entities = getEntitiesOfClass(baseClass, bb); std::shared_ptr closest = nullptr; - double closestDistSqr = Double::MAX_VALUE; + double closestDistSqr = std::numeric_limits::max(); // for (Entity entity : entities) for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { std::shared_ptr entity = *it; @@ -4411,4 +4409,4 @@ bool Level::canCreateMore(eINSTANCEOF type, ESPAWN_TYPE spawnType) { } // 4J: Interpret 0 as no limit return max == 0 || count < max; -} \ No newline at end of file +} diff --git a/Minecraft.World/Level/LevelChunk.cpp b/Minecraft.World/Level/LevelChunk.cpp index 6257ca132..71c285e5c 100644 --- a/Minecraft.World/Level/LevelChunk.cpp +++ b/Minecraft.World/Level/LevelChunk.cpp @@ -11,7 +11,7 @@ #include "Storage/SparseLightStorage.h" #include "BlockReplacements.h" #include "LevelChunk.h" -#include "../Util/BasicTypeContainers.h" +#include #include "../../Minecraft.Client/MinecraftServer.h" #include "../../Minecraft.Client/Level/ServerLevel.h" #include "../../Minecraft.Client/Network/ServerChunkCache.h" @@ -499,8 +499,8 @@ void LevelChunk::recalcHeightmapOnly() { // value changed from -999 to 255 int y = Level::maxBuildHeight - 1; - // int p = x << level->depthBitsPlusFour | z << - // level->depthBits; // 4J - removed + // int p = x << level->depthBitsPlusFour | z << + // level->depthBits; // 4J - removed #ifdef __PSVITA__ int Index = ((unsigned)x << 11) + ((unsigned)z << 7); int offset = Level::COMPRESSED_CHUNK_SECTION_TILES; @@ -561,14 +561,14 @@ void LevelChunk::recalcHeightmap() { byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); getBlockData(blockData); #endif - lowestHeightmap = Integer::MAX_VALUE; + lowestHeightmap = std::numeric_limits::max(); int min = Level::maxBuildHeight - 1; for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { int y = Level::maxBuildHeight - 1; - // int p = x << level->depthBitsPlusFour | z << - // level->depthBits; // 4J - removed + // int p = x << level->depthBitsPlusFour | z << + // level->depthBits; // 4J - removed #ifdef __PSVITA__ int Index = ((unsigned)x << 11) + ((unsigned)z << 7); @@ -1747,21 +1747,21 @@ void LevelChunk::getEntitiesOfClass(const std::type_info& ec, AABB* bb, // our class may be derived from, otherwise do a direct comparison // of type_info if (ec == typeid(Player)) - isAssignableFrom = e->instanceof (eTYPE_PLAYER); + isAssignableFrom = e->instanceof(eTYPE_PLAYER); else if (ec == typeid(Entity)) - isAssignableFrom = e->instanceof (eTYPE_ENTITY); + isAssignableFrom = e->instanceof(eTYPE_ENTITY); else if (ec == typeid(Mob)) - isAssignableFrom = e->instanceof (eTYPE_MOB); + isAssignableFrom = e->instanceof(eTYPE_MOB); else if (ec == typeid(LivingEntity)) - isAssignableFrom = e->instanceof (eTYPE_LIVINGENTITY); + isAssignableFrom = e->instanceof(eTYPE_LIVINGENTITY); else if (ec == typeid(ItemEntity)) - isAssignableFrom = e->instanceof (eTYPE_ITEMENTITY); + isAssignableFrom = e->instanceof(eTYPE_ITEMENTITY); else if (ec == typeid(Minecart)) - isAssignableFrom = e->instanceof (eTYPE_MINECART); + isAssignableFrom = e->instanceof(eTYPE_MINECART); else if (ec == typeid(Monster)) - isAssignableFrom = e->instanceof (eTYPE_MONSTER); + isAssignableFrom = e->instanceof(eTYPE_MONSTER); else if (ec == typeid(Zombie)) - isAssignableFrom = e->instanceof (eTYPE_ZOMBIE); + isAssignableFrom = e->instanceof(eTYPE_ZOMBIE); else if (Entity* entity = e.get(); entity != NULL && ec == typeid(*entity)) isAssignableFrom = true; diff --git a/Minecraft.World/Level/Storage/McRegionLevelStorageSource.cpp b/Minecraft.World/Level/Storage/McRegionLevelStorageSource.cpp index aa485816f..d9b13484d 100644 --- a/Minecraft.World/Level/Storage/McRegionLevelStorageSource.cpp +++ b/Minecraft.World/Level/Storage/McRegionLevelStorageSource.cpp @@ -1,6 +1,5 @@ #include "../../Platform/stdafx.h" #include "../../Util/JavaMath.h" -#include "../../Util/BasicTypeContainers.h" #if 0 // 4J - not required anymore #include "Matcher.h" @@ -41,7 +40,7 @@ std::vector* McRegionLevelStorageSource::getLevelList() { { file = *it; //subFolders->at(i); - if (file->isDirectory()) + if (file->isDirectory()) { continue; } @@ -142,7 +141,7 @@ bool McRegionLevelStorageSource::convertLevel(ConsoleSaveFile* saveFile, } int totalCount = normalRegions->size() + netherRegions->size() + enderRegions.size() + normalBaseFolders->size() + netherBaseFolders->size() + enderBaseFolders.size(); - + // System.out.println("Total conversion count is " + totalCount); 4J Jev, TODO // convert normal world @@ -170,7 +169,7 @@ bool McRegionLevelStorageSource::convertLevel(ConsoleSaveFile* saveFile, #if 0 // 4J - not required anymore -void McRegionLevelStorageSource::addRegions(File &baseFolder, std::vector *dest, std::vector *firstLevelFolders) +void McRegionLevelStorageSource::addRegions(File &baseFolder, std::vector *dest, std::vector *firstLevelFolders) { FolderFilter folderFilter; ChunkFilter chunkFilter; @@ -236,7 +235,7 @@ void McRegionLevelStorageSource::convertRegions( int z = chunkFile->getZ(); RegionFile *region = RegionFileCache::getRegionFile(baseFolder, x, z); - if (!region->hasChunk(x & 31, z & 31)) + if (!region->hasChunk(x & 31, z & 31)) { FileInputStream fis = new BufferedInputStream(FileInputStream(*chunkFile->getFile())); DataInputStream istream = DataInputStream(&fis); // 4J - was new GZIPInputStream as well @@ -287,7 +286,7 @@ void McRegionLevelStorageSource::eraseFolders(std::vector* folders, #if 0 // 4J - not required anymore -bool McRegionLevelStorageSource::FolderFilter::accept(File *file) +bool McRegionLevelStorageSource::FolderFilter::accept(File *file) { if (file->isDirectory()) { @@ -298,23 +297,23 @@ bool McRegionLevelStorageSource::FolderFilter::accept(File *file) } -bool McRegionLevelStorageSource::ChunkFilter::accept(File *dir, const std::wstring& name) +bool McRegionLevelStorageSource::ChunkFilter::accept(File *dir, const std::wstring& name) { Matcher matcher( chunkFilePattern, name ); return matcher.matches(); } -McRegionLevelStorageSource::ChunkFile::ChunkFile(File *file) +McRegionLevelStorageSource::ChunkFile::ChunkFile(File *file) { this->file = file; Matcher matcher( ChunkFilter::chunkFilePattern, file->getName() ); - if (matcher.matches()) + if (matcher.matches()) { x = Integer::parseInt(matcher.group(1), 36); z = Integer::parseInt(matcher.group(2), 36); - } + } else { x = 0; @@ -346,18 +345,18 @@ bool McRegionLevelStorageSource::ChunkFile::operator<( ChunkFile *b ) return compareTo( b ) < 0; } -File *McRegionLevelStorageSource::ChunkFile::getFile() +File *McRegionLevelStorageSource::ChunkFile::getFile() { return (File *) file; } -int McRegionLevelStorageSource::ChunkFile::getX() +int McRegionLevelStorageSource::ChunkFile::getX() { return x; } -int McRegionLevelStorageSource::ChunkFile::getZ() +int McRegionLevelStorageSource::ChunkFile::getZ() { return z; } -#endif \ No newline at end of file +#endif diff --git a/Minecraft.World/Network/Packets/CustomPayloadPacket.cpp b/Minecraft.World/Network/Packets/CustomPayloadPacket.cpp index bbc1d275c..795a4a96e 100644 --- a/Minecraft.World/Network/Packets/CustomPayloadPacket.cpp +++ b/Minecraft.World/Network/Packets/CustomPayloadPacket.cpp @@ -1,8 +1,8 @@ #include "../../Platform/stdafx.h" #include "../../IO/Streams/InputOutputStream.h" #include "PacketListener.h" -#include "../../Util/BasicTypeContainers.h" #include "CustomPayloadPacket.h" +#include // Mojang-defined custom packets const std::wstring CustomPayloadPacket::CUSTOM_BOOK_PACKET = L"MC|BEdit"; @@ -25,7 +25,7 @@ CustomPayloadPacket::CustomPayloadPacket(const std::wstring& identifier, if (data.data != NULL) { length = data.length; - if (length > Short::MAX_VALUE) { + if (length > std::numeric_limits::max()) { app.DebugPrintf("Payload may not be larger than 32K\n"); #ifndef _CONTENT_PACKAGE __debugbreak(); @@ -40,7 +40,7 @@ void CustomPayloadPacket::read(DataInputStream* dis) { identifier = readUtf(dis, 20); length = dis->readShort(); - if (length > 0 && length < Short::MAX_VALUE) { + if (length > 0 && length < std::numeric_limits::max()) { if (data.data != NULL) { delete[] data.data; } @@ -63,4 +63,4 @@ void CustomPayloadPacket::handle(PacketListener* listener) { int CustomPayloadPacket::getEstimatedSize() { return 2 + identifier.length() * 2 + 2 + length; -} \ No newline at end of file +} diff --git a/Minecraft.World/Network/Packets/GameCommandPacket.cpp b/Minecraft.World/Network/Packets/GameCommandPacket.cpp index 6cd44bdee..f662e5c29 100644 --- a/Minecraft.World/Network/Packets/GameCommandPacket.cpp +++ b/Minecraft.World/Network/Packets/GameCommandPacket.cpp @@ -1,8 +1,8 @@ #include "../../Platform/stdafx.h" #include "../../IO/Streams/InputOutputStream.h" #include "PacketListener.h" -#include "../../Util/BasicTypeContainers.h" #include "GameCommandPacket.h" +#include GameCommandPacket::GameCommandPacket() { length = 0; } @@ -14,7 +14,7 @@ GameCommandPacket::GameCommandPacket(EGameCommand command, byteArray data) { if (data.data != NULL) { length = data.length; - if (length > Short::MAX_VALUE) { + if (length > std::numeric_limits::max()) { app.DebugPrintf("Payload may not be larger than 32K\n"); #ifndef _CONTENT_PACKAGE __debugbreak(); @@ -31,7 +31,7 @@ void GameCommandPacket::read(DataInputStream* dis) { command = (EGameCommand)dis->readInt(); length = dis->readShort(); - if (length > 0 && length < Short::MAX_VALUE) { + if (length > 0 && length < std::numeric_limits::max()) { if (data.data != NULL) { delete[] data.data; } @@ -52,4 +52,4 @@ void GameCommandPacket::handle(PacketListener* listener) { listener->handleGameCommand(shared_from_this()); } -int GameCommandPacket::getEstimatedSize() { return 2 + 2 + length; } \ No newline at end of file +int GameCommandPacket::getEstimatedSize() { return 2 + 2 + length; } diff --git a/Minecraft.World/Network/Packets/LevelSoundPacket.cpp b/Minecraft.World/Network/Packets/LevelSoundPacket.cpp index 8bbb8fde8..269136de6 100644 --- a/Minecraft.World/Network/Packets/LevelSoundPacket.cpp +++ b/Minecraft.World/Network/Packets/LevelSoundPacket.cpp @@ -1,16 +1,17 @@ #include "../../Platform/stdafx.h" -#include "../../Util/BasicTypeContainers.h" #include "../../IO/Streams/InputOutputStream.h" #include "../../Headers/net.minecraft.network.packet.h" #include "LevelSoundPacket.h" +#include -const float LevelSoundPacket::PITCH_ACCURACY = Byte::MAX_VALUE / 2.0f; +const float LevelSoundPacket::PITCH_ACCURACY = + std::numeric_limits::max() / 2.0; const float LevelSoundPacket::LOCATION_ACCURACY = 8.0f; LevelSoundPacket::LevelSoundPacket() { sound = 0; x = 0; - y = Integer::MAX_VALUE; + y = std::numeric_limits::max(); z = 0; volume = 0.0f; pitch = 0; diff --git a/Minecraft.World/Network/Packets/Packet.cpp b/Minecraft.World/Network/Packets/Packet.cpp index b071f0a2c..2c44c619f 100644 --- a/Minecraft.World/Network/Packets/Packet.cpp +++ b/Minecraft.World/Network/Packets/Packet.cpp @@ -1,6 +1,5 @@ #include "../../Platform/stdafx.h" #include "../../Platform/System.h" -#include "../../Util/BasicTypeContainers.h" #include "../../IO/Streams/InputOutputStream.h" #include "../../Headers/net.minecraft.network.packet.h" #include "PacketListener.h" @@ -483,7 +482,8 @@ void Packet::writeUtf(const std::wstring& value, // should this declare a throws? { #if 0 - if (value.length() > Short::MAX_VALUE) +#include + if (value.length() > std::numeric_limits::max()) { throw new IOException(L"String too big"); } diff --git a/Minecraft.World/Network/Packets/RemoveEntitiesPacket.h b/Minecraft.World/Network/Packets/RemoveEntitiesPacket.h index 68529e5ac..eb95a9115 100644 --- a/Minecraft.World/Network/Packets/RemoveEntitiesPacket.h +++ b/Minecraft.World/Network/Packets/RemoveEntitiesPacket.h @@ -1,13 +1,13 @@ #pragma once -#include "../../Util/BasicTypeContainers.h" +#include #include "Packet.h" class RemoveEntitiesPacket : public Packet, public std::enable_shared_from_this { public: - static const int MAX_PER_PACKET = Byte::MAX_VALUE; + static const int MAX_PER_PACKET = std::numeric_limits::max(); intArray ids; diff --git a/Minecraft.World/Network/Packets/UpdateMobEffectPacket.cpp b/Minecraft.World/Network/Packets/UpdateMobEffectPacket.cpp index b7590c390..5e2ffd3ca 100644 --- a/Minecraft.World/Network/Packets/UpdateMobEffectPacket.cpp +++ b/Minecraft.World/Network/Packets/UpdateMobEffectPacket.cpp @@ -3,8 +3,8 @@ #include "../../IO/Streams/InputOutputStream.h" #include "PacketListener.h" #include "../../WorldGen/Features/BasicTreeFeature.h" -#include "../../Util/BasicTypeContainers.h" #include "UpdateMobEffectPacket.h" +#include UpdateMobEffectPacket::UpdateMobEffectPacket() { entityId = 0; @@ -19,8 +19,8 @@ UpdateMobEffectPacket::UpdateMobEffectPacket(int entityId, effectId = (BYTE)(effect->getId() & 0xff); effectAmplifier = (char)(effect->getAmplifier() & 0xff); - if (effect->getDuration() > Short::MAX_VALUE) { - effectDurationTicks = Short::MAX_VALUE; + if (effect->getDuration() > std::numeric_limits::max()) { + effectDurationTicks = std::numeric_limits::max(); } else { effectDurationTicks = (short)effect->getDuration(); } @@ -41,7 +41,7 @@ void UpdateMobEffectPacket::write(DataOutputStream* dos) { } bool UpdateMobEffectPacket::isSuperLongDuration() { - return effectDurationTicks == Short::MAX_VALUE; + return effectDurationTicks == std::numeric_limits::max(); } void UpdateMobEffectPacket::handle(PacketListener* listener) { @@ -56,4 +56,4 @@ bool UpdateMobEffectPacket::isInvalidatedBy(std::shared_ptr packet) { std::shared_ptr target = std::dynamic_pointer_cast(packet); return target->entityId == entityId && target->effectId == effectId; -} \ No newline at end of file +} diff --git a/Minecraft.World/Util/BasicTypeContainers.cpp b/Minecraft.World/Util/BasicTypeContainers.cpp deleted file mode 100644 index 8b2966b66..000000000 --- a/Minecraft.World/Util/BasicTypeContainers.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "../Platform/stdafx.h" -#include "BasicTypeContainers.h" -#include - -/* 4J Jev TODO, - this is different to Float::MAX_VALUE, javas floats - seem to actually allow values of infinity which c++ does not. -*/ -// A constant holding the positive infinity of type float. It is equal to the -// value returned by Float.intBitsToFloat(0x7f800000). -const float Float::POSITIVE_INFINITY = 0x7f800000; - -const float Float::MAX_VALUE = FLT_MAX; - -const double Double::MAX_VALUE = DBL_MAX; - -const double Double::MIN_NORMAL = DBL_MIN; - -int Integer::parseInt(std::wstring& str, int radix /* = 10*/) { - return wcstol(str.c_str(), NULL, radix); -} \ No newline at end of file diff --git a/Minecraft.World/Util/BasicTypeContainers.h b/Minecraft.World/Util/BasicTypeContainers.h deleted file mode 100644 index 72b3785b1..000000000 --- a/Minecraft.World/Util/BasicTypeContainers.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include - -class Byte { -public: - static const char MAX_VALUE = CHAR_MAX; - static const char MIN_VALUE = CHAR_MIN; -}; - -class Short { -public: - static const short MAX_VALUE = SHRT_MAX; - static const short MIN_VALUE = SHRT_MIN; -}; - -class Integer { -public: - static const int MAX_VALUE = INT_MAX; - static int parseInt(std::wstring& str, int radix = 10); -}; - -class Float { -public: - static const float MAX_VALUE; - static int floatToIntBits(float value) { return *(int*)&value; } - static int floatToRawIntBits(float value) { return *(int*)&value; } - - static float intBitsToFloat(int bits) { return *(float*)&bits; } - - static const float POSITIVE_INFINITY; -}; - -class Double { -public: - static const double MAX_VALUE; - static const double MIN_NORMAL; - - static bool isNaN(double a) { -#ifdef __PS3__ - return isnan(a); -#else - return (a != a); -#endif - } - static bool isInfinite(double a) { return false; /*4J TODO*/ } - - static double longBitsToDouble(int64_t bits) { return *(double*)&bits; } - - static int64_t doubleToLongBits(double d) { return *(int64_t*)&d; } -}; - -// 4J Stu - The String class should only be used if we need to use the -// BaseClass::class type As such I have renamed it so that we don't confuse it -// with places where we should use std::string -class _String {}; \ No newline at end of file diff --git a/Minecraft.World/Util/BinaryHeap.cpp b/Minecraft.World/Util/BinaryHeap.cpp index ac1ab1413..51254f1d1 100644 --- a/Minecraft.World/Util/BinaryHeap.cpp +++ b/Minecraft.World/Util/BinaryHeap.cpp @@ -1,9 +1,10 @@ #include "../Platform/stdafx.h" #include "../AI/Navigation/Node.h" #include "../Platform/System.h" -#include "BasicTypeContainers.h" #include "BinaryHeap.h" +#include + // 4J Jev, add common ctor code. void BinaryHeap::_init() { heap = NodeArray(1024); @@ -113,7 +114,7 @@ void BinaryHeap::downHeap(int idx) { if (rightIdx >= sizeVar) { // Only need to compare with left. rightNode = NULL; - rightCost = Float::POSITIVE_INFINITY; + rightCost = std::numeric_limits::infinity(); } else { rightNode = heap[rightIdx]; rightCost = rightNode->f; @@ -142,4 +143,4 @@ void BinaryHeap::downHeap(int idx) { node->heapIdx = idx; } -bool BinaryHeap::isEmpty() { return sizeVar == 0; } \ No newline at end of file +bool BinaryHeap::isEmpty() { return sizeVar == 0; } diff --git a/Minecraft.World/Util/BinaryHeap.h b/Minecraft.World/Util/BinaryHeap.h index 793800d15..f632934ec 100644 --- a/Minecraft.World/Util/BinaryHeap.h +++ b/Minecraft.World/Util/BinaryHeap.h @@ -3,7 +3,6 @@ #include "../Platform/stdafx.h" #include "../AI/Navigation/Node.h" #include "../Platform/System.h" -#include "BasicTypeContainers.h" class BinaryHeap { private: @@ -31,4 +30,4 @@ private: public: bool isEmpty(); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Util/CombatEntry.cpp b/Minecraft.World/Util/CombatEntry.cpp index 54bae8e8a..485f5512e 100644 --- a/Minecraft.World/Util/CombatEntry.cpp +++ b/Minecraft.World/Util/CombatEntry.cpp @@ -1,8 +1,8 @@ #include "../Platform/stdafx.h" #include "../Headers/net.minecraft.world.damagesource.h" #include "../Headers/net.minecraft.world.entity.h" -#include "BasicTypeContainers.h" #include "CombatEntry.h" +#include CombatEntry::CombatEntry(DamageSource* source, int time, float health, float damage, CombatTracker::eLOCATION location, @@ -45,6 +45,7 @@ std::wstring CombatEntry::getAttackerName() { } float CombatEntry::getFallDistance() { - if (source == DamageSource::outOfWorld) return Float::MAX_VALUE; + if (source == DamageSource::outOfWorld) + return std::numeric_limits::max(); return fallDistance; -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Structures/Village.cpp b/Minecraft.World/WorldGen/Structures/Village.cpp index a5ef99fe9..07e505908 100644 --- a/Minecraft.World/WorldGen/Structures/Village.cpp +++ b/Minecraft.World/WorldGen/Structures/Village.cpp @@ -5,8 +5,8 @@ #include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.level.tile.h" #include "../../Headers/net.minecraft.world.phys.h" -#include "../../Util/BasicTypeContainers.h" #include "Village.h" +#include Village::Aggressor::Aggressor(std::shared_ptr mob, int timeStamp) { @@ -159,7 +159,7 @@ std::vector >* Village::getDoorInfos() { std::shared_ptr Village::getClosestDoorInfo(int x, int y, int z) { std::shared_ptr closest = nullptr; - int closestDistSqr = Integer::MAX_VALUE; + int closestDistSqr = std::numeric_limits::max(); // for (DoorInfo dm : doorInfos) for (AUTO_VAR(it, doorInfos.begin()); it != doorInfos.end(); ++it) { std::shared_ptr dm = *it; @@ -174,7 +174,7 @@ std::shared_ptr Village::getClosestDoorInfo(int x, int y, int z) { std::shared_ptr Village::getBestDoorInfo(int x, int y, int z) { std::shared_ptr closest = nullptr; - int closestDist = Integer::MAX_VALUE; + int closestDist = std::numeric_limits::max(); // for (DoorInfo dm : doorInfos) for (AUTO_VAR(it, doorInfos.begin()); it != doorInfos.end(); ++it) { std::shared_ptr dm = *it; @@ -232,7 +232,7 @@ void Village::addAggressor(std::shared_ptr mob) { std::shared_ptr Village::getClosestAggressor( std::shared_ptr from) { - double closestSqr = Double::MAX_VALUE; + double closestSqr = std::numeric_limits::max(); Aggressor* closest = NULL; // for (int i = 0; i < aggressors.size(); ++i) for (AUTO_VAR(it, aggressors.begin()); it != aggressors.end(); ++it) { @@ -247,7 +247,7 @@ std::shared_ptr Village::getClosestAggressor( std::shared_ptr Village::getClosestBadStandingPlayer( std::shared_ptr from) { - double closestSqr = Double::MAX_VALUE; + double closestSqr = std::numeric_limits::max(); std::shared_ptr closest = nullptr; // for (String player : playerStanding.keySet()) @@ -453,4 +453,4 @@ void Village::rewardAllPlayers(int amount) { ++it) { modifyStanding(it->first, amount); } -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Structures/Villages.cpp b/Minecraft.World/WorldGen/Structures/Villages.cpp index 34bb25098..db20bd608 100644 --- a/Minecraft.World/WorldGen/Structures/Villages.cpp +++ b/Minecraft.World/WorldGen/Structures/Villages.cpp @@ -3,8 +3,8 @@ #include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.level.tile.h" #include "../../Headers/net.minecraft.world.phys.h" -#include "../../Util/BasicTypeContainers.h" #include "Villages.h" +#include const std::wstring Villages::VILLAGE_FILE_ID = L"villages"; @@ -74,7 +74,7 @@ std::vector >* Villages::getVillages() { std::shared_ptr Villages::getClosestVillage(int x, int y, int z, int maxDist) { std::shared_ptr closest = nullptr; - float closestDistSqr = Float::MAX_VALUE; + float closestDistSqr = std::numeric_limits::max(); // for (Village village : villages) for (AUTO_VAR(it, villages.begin()); it != villages.end(); ++it) { std::shared_ptr village = *it; @@ -221,4 +221,4 @@ void Villages::save(CompoundTag* tag) { villageTags->add(villageTag); } tag->put(L"Villages", villageTags); -} \ No newline at end of file +}