all was broken :\

This commit is contained in:
InviseDivine
2026-04-27 23:43:36 +02:00
parent 0645905fc6
commit de72a9a3b7
20 changed files with 141 additions and 127 deletions

View File

@@ -362,10 +362,10 @@ void Minecraft::prepareLevel(const std::string& title) {
if (!level->isNew()) if (!level->isNew())
level->setUpdateLights(false); level->setUpdateLights(false);
int Max = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; int Max = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH;
int pp = 0; int pp = 0;
for (int x = 8; x < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); x += CHUNK_WIDTH) { for (int x = 8; x < (LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH); x += LevelConstants::CHUNK_WIDTH) {
for (int z = 8; z < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); z += CHUNK_WIDTH) { for (int z = 8; z < (LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH); z += LevelConstants::CHUNK_WIDTH) {
progressStagePercentage = 100 * pp++ / Max; progressStagePercentage = 100 * pp++ / Max;
//printf("level generation progress %d\n", progressStagePercentage); //printf("level generation progress %d\n", progressStagePercentage);
B.start(); B.start();
@@ -382,9 +382,9 @@ void Minecraft::prepareLevel(const std::string& title) {
level->setUpdateLights(true); level->setUpdateLights(true);
C.start(); C.start();
for (int x = 0; x < CHUNK_CACHE_WIDTH; x++) for (int x = 0; x < LevelConstants::CHUNK_CACHE_WIDTH; x++)
{ {
for (int z = 0; z < CHUNK_CACHE_WIDTH; z++) for (int z = 0; z < LevelConstants::CHUNK_CACHE_WIDTH; z++)
{ {
LevelChunk* chunk = level->getChunk(x, z); LevelChunk* chunk = level->getChunk(x, z);
if (chunk && !chunk->createdFromSave) if (chunk && !chunk->createdFromSave)

View File

@@ -65,7 +65,7 @@ LevelRenderer::LevelRenderer( Minecraft* mc)
destroyProgress(0) destroyProgress(0)
{ {
#ifdef OPENGL_ES #ifdef OPENGL_ES
int maxChunksWidth = 2 * LEVEL_WIDTH / CHUNK_SIZE + 1; int maxChunksWidth = 2 * LevelConstants::LEVEL_WIDTH / CHUNK_SIZE + 1;
numListsOrBuffers = maxChunksWidth * maxChunksWidth * (128/CHUNK_SIZE) * 3; numListsOrBuffers = maxChunksWidth * maxChunksWidth * (128/CHUNK_SIZE) * 3;
chunkBuffers = new GLuint[numListsOrBuffers]; chunkBuffers = new GLuint[numListsOrBuffers];
glGenBuffers2(numListsOrBuffers, chunkBuffers); glGenBuffers2(numListsOrBuffers, chunkBuffers);

View File

@@ -62,7 +62,7 @@ void ClientSideNetworkHandler::requestNextChunk()
//LOGI("requesting chunks @ (%d, %d)\n", chunk.x, chunk.y); //LOGI("requesting chunks @ (%d, %d)\n", chunk.x, chunk.y);
//raknetInstance->send(new RequestChunkPacket(requestNextChunkPosition % CHUNK_CACHE_WIDTH, requestNextChunkPosition / CHUNK_CACHE_WIDTH)); //raknetInstance->send(new RequestChunkPacket(requestNextChunkPosition % LevelConstants::CHUNK_CACHE_WIDTH, requestNextChunkPosition / LevelConstants::CHUNK_CACHE_WIDTH));
requestNextChunkIndex++; requestNextChunkIndex++;
requestNextChunkPosition++; requestNextChunkPosition++;
} }
@@ -70,16 +70,16 @@ void ClientSideNetworkHandler::requestNextChunk()
bool ClientSideNetworkHandler::areAllChunksLoaded() bool ClientSideNetworkHandler::areAllChunksLoaded()
{ {
return (requestNextChunkPosition >= (CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH)); return (requestNextChunkPosition >= (LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH));
} }
bool ClientSideNetworkHandler::isChunkLoaded(int x, int z) bool ClientSideNetworkHandler::isChunkLoaded(int x, int z)
{ {
if (x < 0 || x >= CHUNK_CACHE_WIDTH || z < 0 || z >= CHUNK_CACHE_WIDTH) { if (x < 0 || x >= LevelConstants::CHUNK_CACHE_WIDTH || z < 0 || z >= LevelConstants::CHUNK_CACHE_WIDTH) {
LOGE("Error: Tried to request chunk (%d, %d)\n", x, z); LOGE("Error: Tried to request chunk (%d, %d)\n", x, z);
return true; return true;
} }
return chunksLoaded[x * CHUNK_CACHE_WIDTH + z]; return chunksLoaded[x * LevelConstants::CHUNK_CACHE_WIDTH + z];
//return areAllChunksLoaded(); //return areAllChunksLoaded();
} }
@@ -100,9 +100,9 @@ void ClientSideNetworkHandler::onUnableToConnect()
void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid) void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid)
{ {
CHUNK_CACHE_WIDTH = 16; LevelConstants::CHUNK_CACHE_WIDTH = 16;
LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; LevelConstants::LEVEL_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH;
LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH; LevelConstants::LEVEL_DEPTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_DEPTH;
// TODO: Good disconnecting // TODO: Good disconnecting
LOGI("onDisconnect\n"); LOGI("onDisconnect\n");
@@ -164,12 +164,12 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, StartGam
// we can put it directly to selectLevel? // we can put it directly to selectLevel?
if (packet->chunkCacheWidth != 0) { if (packet->chunkCacheWidth != 0) {
printf("lol \n"); printf("lol \n");
CHUNK_CACHE_WIDTH = packet->chunkCacheWidth; LevelConstants::CHUNK_CACHE_WIDTH = packet->chunkCacheWidth;
LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; LevelConstants::LEVEL_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH;
LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH; LevelConstants::LEVEL_DEPTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_DEPTH;
} }
NumRequestChunks = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; NumRequestChunks = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH;
requestNextChunkIndexList.resize(NumRequestChunks); requestNextChunkIndexList.resize(NumRequestChunks);
chunksLoaded.resize(NumRequestChunks); chunksLoaded.resize(NumRequestChunks);
@@ -551,19 +551,19 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
//unsigned char* blockIds = chunk->getBlockData(); //unsigned char* blockIds = chunk->getBlockData();
DataLayer& blockData = chunk->data; DataLayer& blockData = chunk->data;
const int setSize = LEVEL_HEIGHT / 8; const int setSize = LevelConstants::LEVEL_HEIGHT / 8;
const int setShift = 4; // power of LEVEL_HEIGHT / 8 const int setShift = 4; // power of LevelConstants::LEVEL_HEIGHT / 8
bool recalcHeight = false; bool recalcHeight = false;
int x0 = 16, x1 = 0, z0 = 16, z1 = 0, y0 = LEVEL_HEIGHT, y1 = 0; int x0 = 16, x1 = 0, z0 = 16, z1 = 0, y0 = LevelConstants::LEVEL_HEIGHT, y1 = 0;
int rx = packet->x << 4; int rx = packet->x << 4;
int rz = packet->z << 4; int rz = packet->z << 4;
unsigned char readBlockBuffer[setSize]; unsigned char readBlockBuffer[setSize];
unsigned char readDataBuffer[setSize / 2]; unsigned char readDataBuffer[setSize / 2];
for (int i = 0; i < CHUNK_COLUMNS; i++) for (int i = 0; i < LevelConstants::CHUNK_COLUMNS; i++)
{ {
unsigned char updateBits = 0; unsigned char updateBits = 0;
packet->chunkData.Read(updateBits); packet->chunkData.Read(updateBits);
@@ -572,8 +572,8 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
{ {
recalcHeight = true; recalcHeight = true;
int colX = (i % CHUNK_WIDTH); int colX = (i % LevelConstants::CHUNK_WIDTH);
int colZ = (i / CHUNK_WIDTH); int colZ = (i / LevelConstants::CHUNK_WIDTH);
int colDataPosition = colX << 11 | colZ << 7; int colDataPosition = colX << 11 | colZ << 7;
for (int set = 0; set < 8; set++) for (int set = 0; set < 8; set++)
@@ -607,26 +607,26 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
{ {
y0 = ((1 << set) << setShift); y0 = ((1 << set) << setShift);
} }
if (((1 << set) << setShift) + (LEVEL_HEIGHT / 8) - 1 > y1) if (((1 << set) << setShift) + (LevelConstants::LEVEL_HEIGHT / 8) - 1 > y1)
{ {
y1 = ((1 << set) << setShift) + (LEVEL_HEIGHT / 8) - 1; y1 = ((1 << set) << setShift) + (LevelConstants::LEVEL_HEIGHT / 8) - 1;
} }
} }
if ((i % CHUNK_WIDTH) < x0) if ((i % LevelConstants::CHUNK_WIDTH) < x0)
{ {
x0 = (i % CHUNK_WIDTH); x0 = (i % LevelConstants::CHUNK_WIDTH);
} }
if ((i % CHUNK_WIDTH) > x1) if ((i % LevelConstants::CHUNK_WIDTH) > x1)
{ {
x1 = (i % CHUNK_WIDTH); x1 = (i % LevelConstants::CHUNK_WIDTH);
} }
if ((i / CHUNK_WIDTH) < z0) if ((i / LevelConstants::CHUNK_WIDTH) < z0)
{ {
z0 = (i / CHUNK_WIDTH); z0 = (i / LevelConstants::CHUNK_WIDTH);
} }
if ((i / CHUNK_WIDTH) > z1) if ((i / LevelConstants::CHUNK_WIDTH) > z1)
{ {
z1 = (i / CHUNK_WIDTH); z1 = (i / LevelConstants::CHUNK_WIDTH);
} }
} }
} }
@@ -655,7 +655,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
//chunk->terrainPopulated = true; //chunk->terrainPopulated = true;
chunk->unsaved = false; chunk->unsaved = false;
chunksLoaded[packet->x * CHUNK_CACHE_WIDTH + packet->z] = true; chunksLoaded[packet->x * LevelConstants::CHUNK_CACHE_WIDTH + packet->z] = true;
if (areAllChunksLoaded()) if (areAllChunksLoaded())
{ {
@@ -703,14 +703,14 @@ void ClientSideNetworkHandler::arrangeRequestChunkOrder() {
clearChunksLoaded(); clearChunksLoaded();
// Default sort is around center of the world // Default sort is around center of the world
int cx = CHUNK_CACHE_WIDTH / 2; int cx = LevelConstants::CHUNK_CACHE_WIDTH / 2;
int cz = CHUNK_CACHE_WIDTH / 2; int cz = LevelConstants::CHUNK_CACHE_WIDTH / 2;
// If player exists, let's sort around him // If player exists, let's sort around him
Player* p = minecraft? minecraft->player : NULL; Player* p = minecraft? minecraft->player : NULL;
if (p) { if (p) {
cx = Mth::floor(p->x / (float)CHUNK_WIDTH); cx = Mth::floor(p->x / (float)LevelConstants::CHUNK_WIDTH);
cz = Mth::floor(p->z / (float)CHUNK_DEPTH); cz = Mth::floor(p->z / (float)LevelConstants::CHUNK_DEPTH);
} }
_ChunkSorter sorter(cx, cz); _ChunkSorter sorter(cx, cz);
@@ -1004,8 +1004,8 @@ void ClientSideNetworkHandler::clearChunksLoaded()
{ {
// Init the chunk positions // Init the chunk positions
for (int i = 0; i < NumRequestChunks; ++i) { for (int i = 0; i < NumRequestChunks; ++i) {
requestNextChunkIndexList[i].x = i/CHUNK_WIDTH; requestNextChunkIndexList[i].x = i / LevelConstants::CHUNK_WIDTH;
requestNextChunkIndexList[i].y = i%CHUNK_WIDTH; requestNextChunkIndexList[i].y = i % LevelConstants::CHUNK_WIDTH;
chunksLoaded[i] = false; chunksLoaded[i] = false;
} }
} }

View File

@@ -274,7 +274,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
gameType, gameType,
newPlayer->entityId, newPlayer->entityId,
newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z, newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z,
CHUNK_CACHE_WIDTH LevelConstants::CHUNK_CACHE_WIDTH
).write(&bitStream); ).write(&bitStream);
rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false); rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false);

View File

@@ -236,9 +236,9 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s)
if (x0 < 0) x0 = 0; if (x0 < 0) x0 = 0;
if (y0 < 0) y0 = 0; if (y0 < 0) y0 = 0;
if (z0 < 0) z0 = 0; if (z0 < 0) z0 = 0;
if (x1 >= LEVEL_WIDTH ) x1 = LEVEL_WIDTH - 1; if (x1 >= LevelConstants::LEVEL_WIDTH ) x1 = LevelConstants::LEVEL_WIDTH - 1;
if (y1 >= LEVEL_HEIGHT) y1 = LEVEL_HEIGHT - 1; if (y1 >= LevelConstants::LEVEL_HEIGHT) y1 = LevelConstants::LEVEL_HEIGHT - 1;
if (z1 >= LEVEL_DEPTH ) z1 = LEVEL_DEPTH - 1; if (z1 >= LevelConstants::LEVEL_DEPTH ) z1 = LevelConstants::LEVEL_DEPTH - 1;
for (int y = y0; y <= y1; ++y) for (int y = y0; y <= y1; ++y)
for (int z = z0; z <= z1; ++z) for (int z = z0; z <= z1; ++z)
@@ -456,7 +456,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s)
sw.start(); sw.start();
// Save a cuboid around the player // Save a cuboid around the player
const int CSize = CHUNK_CACHE_WIDTH; const int CSize = LevelConstants::CHUNK_CACHE_WIDTH;
int cx = (int)e->x / CSize; int cx = (int)e->x / CSize;
int cz = (int)e->z / CSize; int cz = (int)e->z / CSize;
@@ -504,7 +504,7 @@ bool CommandServer::handleCheckpoint(bool doRestore ) {
const int cz = restorePos.z; const int cz = restorePos.z;
const int y0 = restorePos.y; const int y0 = restorePos.y;
const int y1 = y0 + RestoreHeight; const int y1 = y0 + RestoreHeight;
const int CSize = CHUNK_CACHE_WIDTH; const int CSize = LevelConstants::CHUNK_CACHE_WIDTH;
const int numChunkBytes = RestoreHeight * CSize * CSize * 20 / 8; const int numChunkBytes = RestoreHeight * CSize * CSize * 20 / 8;
if (!restoreBuffer) { if (!restoreBuffer) {

View File

@@ -33,18 +33,18 @@ public:
unsigned char* blockIds = chunk->getBlockData(); unsigned char* blockIds = chunk->getBlockData();
DataLayer& blockData = chunk->data; DataLayer& blockData = chunk->data;
const int setSize = LEVEL_HEIGHT / 8; const int setSize = LevelConstants::LEVEL_HEIGHT / 8;
const int setShift = 4; // power of LEVEL_HEIGHT / 8 const int setShift = 4; // power of LevelConstants::LEVEL_HEIGHT / 8
chunkData.Reset(); chunkData.Reset();
for (int i = 0; i < CHUNK_COLUMNS; i++) for (int i = 0; i < LevelConstants::CHUNK_COLUMNS; i++)
{ {
unsigned char updateBits = chunk->updateMap[i]; unsigned char updateBits = chunk->updateMap[i];
chunkData.Write(updateBits); chunkData.Write(updateBits);
if (updateBits > 0) if (updateBits > 0)
{ {
int colDataPosition = (i % CHUNK_WIDTH) << 11 | (i / CHUNK_WIDTH) << 7; int colDataPosition = (i % LevelConstants::CHUNK_WIDTH) << 11 | (i / LevelConstants::CHUNK_WIDTH) << 7;
for (int set = 0; set < 8; set++) for (int set = 0; set < 8; set++)
{ {

View File

@@ -43,7 +43,7 @@ public:
bitStream->Write(x); bitStream->Write(x);
bitStream->Write(y); bitStream->Write(y);
bitStream->Write(z); bitStream->Write(z);
bitStream->Write(CHUNK_CACHE_WIDTH); bitStream->Write(LevelConstants::CHUNK_CACHE_WIDTH);
} }
void read(RakNet::BitStream* bitStream) void read(RakNet::BitStream* bitStream)
@@ -55,7 +55,7 @@ public:
bitStream->Read(x); bitStream->Read(x);
bitStream->Read(y); bitStream->Read(y);
bitStream->Read(z); bitStream->Read(z);
if (bitStream->GetNumberOfUnreadBits() > 0) { if (bitStream->GetNumberOfUnreadBits() > 0) {
bitStream->Read(chunkCacheWidth); bitStream->Read(chunkCacheWidth);
} }

View File

@@ -871,8 +871,8 @@ bool Entity::load( CompoundTag* tag )
// Add a small padding if standing next to the world edges // Add a small padding if standing next to the world edges
const float padding = bbWidth * 0.5f + 0.001f; const float padding = bbWidth * 0.5f + 0.001f;
xx = Mth::clamp(xx, padding, (float)LEVEL_WIDTH - padding); xx = Mth::clamp(xx, padding, (float)LevelConstants::LEVEL_WIDTH - padding);
zz = Mth::clamp(zz, padding, (float)LEVEL_DEPTH - padding); zz = Mth::clamp(zz, padding, (float)LevelConstants::LEVEL_DEPTH - padding);
xo = xOld = x = xx; xo = xOld = x = xx;
yo = yOld = y = yy; yo = yOld = y = yy;

View File

@@ -278,8 +278,8 @@ void Level::tickTiles() {
for (int i = 0; i < pollChunkOffsetsSize; i += 2) { for (int i = 0; i < pollChunkOffsetsSize; i += 2) {
const int xp = xx + pollChunkOffsets[i]; const int xp = xx + pollChunkOffsets[i];
const int zp = zz + pollChunkOffsets[i+1]; const int zp = zz + pollChunkOffsets[i+1];
if (xp >= 0 && xp < CHUNK_CACHE_WIDTH && if (xp >= 0 && xp < LevelConstants::CHUNK_CACHE_WIDTH &&
zp >= 0 && zp < CHUNK_CACHE_WIDTH) zp >= 0 && zp < LevelConstants::CHUNK_CACHE_WIDTH)
_chunksToPoll.insert(ChunkPos(xp, zp)); _chunksToPoll.insert(ChunkPos(xp, zp));
} }
} }
@@ -428,17 +428,17 @@ bool Level::findPath(Path* path, Entity* from, int xBest, int yBest, int zBest,
/*protected*/ /*protected*/
void Level::setInitialSpawn() { void Level::setInitialSpawn() {
isFindingSpawn = true; isFindingSpawn = true;
int xSpawn = CHUNK_CACHE_WIDTH * CHUNK_WIDTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0; int xSpawn = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0;
int ySpawn = 64; int ySpawn = 64;
int zSpawn = CHUNK_CACHE_WIDTH * CHUNK_DEPTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0; int zSpawn = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_DEPTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0;
while (!dimension->isValidSpawn(xSpawn, zSpawn)) { while (!dimension->isValidSpawn(xSpawn, zSpawn)) {
xSpawn += random.nextInt(32) - random.nextInt(32); xSpawn += random.nextInt(32) - random.nextInt(32);
zSpawn += random.nextInt(32) - random.nextInt(32); zSpawn += random.nextInt(32) - random.nextInt(32);
if (xSpawn < 4) xSpawn += 32; if (xSpawn < 4) xSpawn += 32;
if (xSpawn >= LEVEL_WIDTH-4) xSpawn -= 32; if (xSpawn >= LevelConstants::LEVEL_WIDTH-4) xSpawn -= 32;
if (zSpawn < 4) zSpawn += 32; if (zSpawn < 4) zSpawn += 32;
if (zSpawn >= LEVEL_DEPTH-4) zSpawn -= 32; if (zSpawn >= LevelConstants::LEVEL_DEPTH-4) zSpawn -= 32;
} }
levelData.setSpawn(xSpawn, ySpawn, zSpawn); levelData.setSpawn(xSpawn, ySpawn, zSpawn);
isFindingSpawn = false; isFindingSpawn = false;
@@ -456,9 +456,9 @@ void Level::validateSpawn() {
zSpawn += random.nextInt(8) - random.nextInt(8); zSpawn += random.nextInt(8) - random.nextInt(8);
if (xSpawn < 4) xSpawn += 8; if (xSpawn < 4) xSpawn += 8;
if (xSpawn >= LEVEL_WIDTH-4) xSpawn -= 8; if (xSpawn >= LevelConstants::LEVEL_WIDTH-4) xSpawn -= 8;
if (zSpawn < 4) zSpawn += 8; if (zSpawn < 4) zSpawn += 8;
if (zSpawn >= LEVEL_DEPTH-4) zSpawn -= 8; if (zSpawn >= LevelConstants::LEVEL_DEPTH-4) zSpawn -= 8;
} }
levelData.setXSpawn(xSpawn); levelData.setXSpawn(xSpawn);
levelData.setZSpawn(zSpawn); levelData.setZSpawn(zSpawn);
@@ -944,7 +944,7 @@ HitResult Level::clip(const Vec3& A, const Vec3& b, bool liquid /*= false*/, boo
if (solidOnly && tile != NULL && tile->getAABB(this, xTile0, yTile0, zTile0) == NULL) { if (solidOnly && tile != NULL && tile->getAABB(this, xTile0, yTile0, zTile0) == NULL) {
// No collision // No collision
} else if (t > 0 && tile->mayPick(data, liquid)) { } else if (t > 0 && tile->mayPick(data, liquid)) {
if(xTile0 >= 0 && zTile0 >= 0 && xTile0 < LEVEL_WIDTH && zTile0 < LEVEL_WIDTH) { if(xTile0 >= 0 && zTile0 >= 0 && xTile0 < LevelConstants::LEVEL_WIDTH && zTile0 < LevelConstants::LEVEL_WIDTH) {
HitResult r = tile->clip(this, xTile0, yTile0, zTile0, a, b); HitResult r = tile->clip(this, xTile0, yTile0, zTile0, a, b);
if (r.isHit()) return r; if (r.isHit()) return r;
} }
@@ -2222,9 +2222,9 @@ void Level::setNightMode( bool isNightMode ) {
} }
bool Level::inRange( int x, int y, int z ) { bool Level::inRange( int x, int y, int z ) {
return x >= 0 && x < LEVEL_WIDTH return x >= 0 && x < LevelConstants::LEVEL_WIDTH
&& y >= 0 && y < LEVEL_HEIGHT && y >= 0 && y < LevelConstants::LEVEL_HEIGHT
&& z >= 0 && z < LEVEL_DEPTH; && z >= 0 && z < LevelConstants::LEVEL_DEPTH;
} }
// //

View File

@@ -67,8 +67,8 @@ class Level: public LevelSource
public: public:
static const int MAX_LEVEL_SIZE = 32000000; static const int MAX_LEVEL_SIZE = 32000000;
static const short DEPTH = LEVEL_HEIGHT; const short DEPTH = LevelConstants::LEVEL_HEIGHT;
static const short SEA_LEVEL = DEPTH / 2 - 1; const short SEA_LEVEL = DEPTH / 2 - 1;
static const int MAX_BRIGHTNESS = 15; static const int MAX_BRIGHTNESS = 15;
static const int TICKS_PER_DAY = SharedConstants::TicksPerSecond * 60 * 16;// SharedConstants::TicksPerSecond * 60 * 12; // ORG:20*60*20 static const int TICKS_PER_DAY = SharedConstants::TicksPerSecond * 60 * 16;// SharedConstants::TicksPerSecond * 60 * 12; // ORG:20*60*20

View File

@@ -0,0 +1,7 @@
#include "LevelConstants.h"
int LevelConstants::LEVEL_HEIGHT = 128;
int LevelConstants::CHUNK_WIDTH = 16; // in blocks
int LevelConstants::CHUNK_DEPTH = 16;
int LevelConstants::CHUNK_COLUMNS = LevelConstants::CHUNK_WIDTH * LevelConstants::CHUNK_DEPTH;
int LevelConstants::CHUNK_BLOCK_COUNT = LevelConstants::CHUNK_COLUMNS * LevelConstants::LEVEL_HEIGHT;

View File

@@ -1,10 +1,14 @@
#pragma once #pragma once
const int LEVEL_HEIGHT = 128; class LevelConstants {
int CHUNK_CACHE_WIDTH = 16; // in chunks public:
const int CHUNK_WIDTH = 16; // in blocks static int CHUNK_CACHE_WIDTH; // in chunks
const int CHUNK_DEPTH = 16; static int LEVEL_WIDTH;
int LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; static int LEVEL_DEPTH;
int LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH;
const int CHUNK_COLUMNS = CHUNK_WIDTH * CHUNK_DEPTH; static int LEVEL_HEIGHT;
const int CHUNK_BLOCK_COUNT = CHUNK_COLUMNS * LEVEL_HEIGHT; static int CHUNK_WIDTH; // in blocks
static int CHUNK_DEPTH;
static int CHUNK_COLUMNS;
static int CHUNK_BLOCK_COUNT;
};

View File

@@ -10,7 +10,7 @@
#include "../LevelConstants.h" #include "../LevelConstants.h"
class ChunkCache: public ChunkSource { class ChunkCache: public ChunkSource {
//static const int CHUNK_CACHE_WIDTH = CHUNK_CACHE_WIDTH; // WAS 32; //static const int LevelConstants::CHUNK_CACHE_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH; // WAS 32;
static const int MAX_SAVES = 2; static const int MAX_SAVES = 2;
public: public:
ChunkCache(Level* level_, ChunkStorage* storage_, ChunkSource* source_) ChunkCache(Level* level_, ChunkStorage* storage_, ChunkSource* source_)
@@ -25,14 +25,14 @@ public:
//emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0); //emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0);
emptyChunk = new EmptyLevelChunk(level_, NULL, 0, 0); emptyChunk = new EmptyLevelChunk(level_, NULL, 0, 0);
chunks = (LevelChunk *)malloc(CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH); chunks = (LevelChunk *)malloc(LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH);
} }
~ChunkCache() { ~ChunkCache() {
delete source; delete source;
delete emptyChunk; delete emptyChunk;
for (int i = 0; i < CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; i++) for (int i = 0; i < LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH; i++)
{ {
if (&chunks[i]) if (&chunks[i])
{ {
@@ -43,7 +43,7 @@ public:
} }
bool fits(int x, int z) { bool fits(int x, int z) {
return (x >= 0 && z >= 0 && x < CHUNK_CACHE_WIDTH && z < CHUNK_CACHE_WIDTH); return (x >= 0 && z >= 0 && x < LevelConstants::CHUNK_CACHE_WIDTH && z < LevelConstants::CHUNK_CACHE_WIDTH);
} }
bool hasChunk(int x, int z) { bool hasChunk(int x, int z) {
@@ -53,9 +53,9 @@ public:
if (x == xLast && z == zLast && last != NULL) { if (x == xLast && z == zLast && last != NULL) {
return true; return true;
} }
int xs = x & (CHUNK_CACHE_WIDTH - 1); int xs = x & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
int zs = z & (CHUNK_CACHE_WIDTH - 1); int zs = z & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
int slot = xs + zs * CHUNK_CACHE_WIDTH; int slot = xs + zs * LevelConstants::CHUNK_CACHE_WIDTH;
return &chunks[slot] != NULL && (&chunks[slot] == emptyChunk || chunks[slot].isAt(x, z)); return &chunks[slot] != NULL && (&chunks[slot] == emptyChunk || chunks[slot].isAt(x, z));
} }
@@ -72,9 +72,9 @@ public:
} }
if (!fits(x, z)) return emptyChunk; if (!fits(x, z)) return emptyChunk;
//if (!level->isFindingSpawn && !fits(x, z)) return emptyChunk; //if (!level->isFindingSpawn && !fits(x, z)) return emptyChunk;
int xs = x & (CHUNK_CACHE_WIDTH - 1); int xs = x & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
int zs = z & (CHUNK_CACHE_WIDTH - 1); int zs = z & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
int slot = xs + zs * CHUNK_CACHE_WIDTH; int slot = xs + zs * LevelConstants::CHUNK_CACHE_WIDTH;
if (!hasChunk(x, z)) { if (!hasChunk(x, z)) {
if (&chunks[slot] != NULL) { if (&chunks[slot] != NULL) {
chunks[slot].unload(); chunks[slot].unload();
@@ -200,8 +200,8 @@ public:
void saveAll(bool onlyUnsaved) { void saveAll(bool onlyUnsaved) {
if (storage != NULL) { if (storage != NULL) {
std::vector<LevelChunk*> chunks; std::vector<LevelChunk*> chunks;
for (int z = 0; z < CHUNK_CACHE_WIDTH; ++z) for (int z = 0; z < LevelConstants::CHUNK_CACHE_WIDTH; ++z)
for (int x = 0; x < CHUNK_CACHE_WIDTH; ++x) { for (int x = 0; x < LevelConstants::CHUNK_CACHE_WIDTH; ++x) {
LevelChunk* chunk = level->getChunk(x, z); LevelChunk* chunk = level->getChunk(x, z);
if (!onlyUnsaved || chunk->shouldSave(false)) if (!onlyUnsaved || chunk->shouldSave(false))
chunks.push_back( chunk ); chunks.push_back( chunk );
@@ -212,7 +212,7 @@ public:
private: private:
LevelChunk* load(int x, int z) { LevelChunk* load(int x, int z) {
if (storage == NULL) return emptyChunk; if (storage == NULL) return emptyChunk;
if (x < 0 || x >= CHUNK_CACHE_WIDTH || z < 0 || z >= CHUNK_CACHE_WIDTH) if (x < 0 || x >= LevelConstants::CHUNK_CACHE_WIDTH || z < 0 || z >= LevelConstants::CHUNK_CACHE_WIDTH)
{ {
return emptyChunk; return emptyChunk;
} }

View File

@@ -17,8 +17,8 @@ LevelChunk::LevelChunk( Level* level, int x, int z )
: level(level), : level(level),
x(x), x(x),
z(z), z(z),
xt(x * CHUNK_WIDTH), xt(x * LevelConstants::CHUNK_WIDTH),
zt(z * CHUNK_DEPTH) zt(z * LevelConstants::CHUNK_DEPTH)
{ {
init(); init();
} }
@@ -27,8 +27,8 @@ LevelChunk::LevelChunk( Level* level, unsigned char* blocks, int x, int z )
: level(level), : level(level),
x(x), x(x),
z(z), z(z),
xt(x * CHUNK_WIDTH), xt(x * LevelConstants::CHUNK_WIDTH),
zt(z * CHUNK_DEPTH), zt(z * LevelConstants::CHUNK_DEPTH),
blocks(blocks), blocks(blocks),
data(ChunkBlockCount), data(ChunkBlockCount),
skyLight(ChunkBlockCount), skyLight(ChunkBlockCount),
@@ -45,6 +45,9 @@ LevelChunk::~LevelChunk()
void LevelChunk::init() void LevelChunk::init()
{ {
heightmap = (char*)malloc(LevelConstants::CHUNK_COLUMNS * sizeof(char));
updateMap = (unsigned char*)malloc(LevelConstants::CHUNK_COLUMNS * sizeof(unsigned char));
terrainPopulated = false; terrainPopulated = false;
dontSave = false; dontSave = false;
unsaved = false; unsaved = false;

View File

@@ -106,9 +106,9 @@ private:
void recalcHeight(int x, int yStart, int z); void recalcHeight(int x, int yStart, int z);
public: public:
static bool touchedSky; static bool touchedSky;
static const int ChunkBlockCount = CHUNK_BLOCK_COUNT; const int ChunkBlockCount = LevelConstants::CHUNK_BLOCK_COUNT;
static const int ChunkSize = ChunkBlockCount; const int ChunkSize = ChunkBlockCount;
static const int UpdateMapBitShift = 4; // power of (LEVEL_HEIGHT / 8) == 16 static const int UpdateMapBitShift = 4; // power of (LevelConstants::LEVEL_HEIGHT / 8) == 16
int blocksLength; // ? needed or not? (i.e. are all chunks the same size?) int blocksLength; // ? needed or not? (i.e. are all chunks the same size?)
@@ -118,8 +118,8 @@ public:
DataLayer skyLight; DataLayer skyLight;
DataLayer blockLight; DataLayer blockLight;
char heightmap[CHUNK_COLUMNS]; char* heightmap; // [LevelConstants::CHUNK_COLUMNS]
unsigned char updateMap[CHUNK_COLUMNS]; // marks regions within block columns that have been modified unsigned char* updateMap; // marks regions within block columns that have been modified [LevelConstants::CHUNK_COLUMNS]
int minHeight; int minHeight;
int x, z; int x, z;

View File

@@ -64,7 +64,7 @@ RandomLevelSource::~RandomLevelSource() {
/*public*/ /*public*/
void RandomLevelSource::prepareHeights(int xOffs, int zOffs, unsigned char* blocks, /*Biome*/void* biomes, float* temperatures) { void RandomLevelSource::prepareHeights(int xOffs, int zOffs, unsigned char* blocks, /*Biome*/void* biomes, float* temperatures) {
int xChunks = 16 / CHUNK_WIDTH; int xChunks = 16 / LevelConstants::CHUNK_WIDTH;
int waterHeight = Level::DEPTH - 64; int waterHeight = Level::DEPTH - 64;
int xSize = xChunks + 1; int xSize = xChunks + 1;
@@ -87,23 +87,23 @@ void RandomLevelSource::prepareHeights(int xOffs, int zOffs, unsigned char* bloc
float s3a = (buffer[((xc + 1) * zSize + (zc + 1)) * ySize + (yc + 1)] - s3) * yStep; float s3a = (buffer[((xc + 1) * zSize + (zc + 1)) * ySize + (yc + 1)] - s3) * yStep;
for (int y = 0; y < CHUNK_HEIGHT; y++) { for (int y = 0; y < CHUNK_HEIGHT; y++) {
float xStep = 1 / (float) CHUNK_WIDTH; float xStep = 1 / (float) LevelConstants::CHUNK_WIDTH;
float _s0 = s0; float _s0 = s0;
float _s1 = s1; float _s1 = s1;
float _s0a = (s2 - s0) * xStep; float _s0a = (s2 - s0) * xStep;
float _s1a = (s3 - s1) * xStep; float _s1a = (s3 - s1) * xStep;
for (int x = 0; x < CHUNK_WIDTH; x++) { for (int x = 0; x < LevelConstants::CHUNK_WIDTH; x++) {
int offs = (x + xc * CHUNK_WIDTH) << 11 | (0 + zc * CHUNK_WIDTH) << 7 | (yc * CHUNK_HEIGHT + y); int offs = (x + xc * LevelConstants::CHUNK_WIDTH) << 11 | (0 + zc * LevelConstants::CHUNK_WIDTH) << 7 | (yc * CHUNK_HEIGHT + y);
int step = 1 << 7; int step = 1 << 7;
float zStep = 1 / (float) CHUNK_WIDTH; float zStep = 1 / (float) LevelConstants::CHUNK_WIDTH;
float val = _s0; float val = _s0;
float vala = (_s1 - _s0) * zStep; float vala = (_s1 - _s0) * zStep;
for (int z = 0; z < CHUNK_WIDTH; z++) { for (int z = 0; z < LevelConstants::CHUNK_WIDTH; z++) {
// + (zc * CHUNK_WIDTH + z)]; // + (zc * LevelConstants::CHUNK_WIDTH + z)];
float temp = temperatures[(xc * CHUNK_WIDTH + x) * 16 + (zc * CHUNK_WIDTH + z)]; float temp = temperatures[(xc * LevelConstants::CHUNK_WIDTH + x) * 16 + (zc * LevelConstants::CHUNK_WIDTH + z)];
int tileId = 0; int tileId = 0;
if (yc * CHUNK_HEIGHT + y < waterHeight) { if (yc * CHUNK_HEIGHT + y < waterHeight) {
if (temp < SNOW_CUTOFF && yc * CHUNK_HEIGHT + y >= waterHeight - 1) { if (temp < SNOW_CUTOFF && yc * CHUNK_HEIGHT + y >= waterHeight - 1) {

View File

@@ -343,8 +343,8 @@ bool ExternalFileLevelStorage::readPlayerData(const std::string& filename, Level
Vec3& pos = dest.playerData.pos; Vec3& pos = dest.playerData.pos;
if (pos.x < 0.5f) pos.x = 0.5f; if (pos.x < 0.5f) pos.x = 0.5f;
if (pos.z < 0.5f) pos.z = 0.5f; if (pos.z < 0.5f) pos.z = 0.5f;
if (pos.x > (LEVEL_WIDTH - 0.5f)) pos.x = LEVEL_WIDTH - 0.5f; if (pos.x > (LevelConstants::LEVEL_WIDTH - 0.5f)) pos.x = LevelConstants::LEVEL_WIDTH - 0.5f;
if (pos.z > (LEVEL_DEPTH - 0.5f)) pos.z = LEVEL_DEPTH - 0.5f; if (pos.z > (LevelConstants::LEVEL_DEPTH - 0.5f)) pos.z = LevelConstants::LEVEL_DEPTH - 0.5f;
if (pos.y < 0) pos.y = 64; if (pos.y < 0) pos.y = 64;
dest.playerDataVersion = version; dest.playerDataVersion = version;
@@ -362,14 +362,14 @@ void ExternalFileLevelStorage::tick()
LOGI("Saving level...\n"); LOGI("Saving level...\n");
// look for chunks that needs to be saved // look for chunks that needs to be saved
for (int z = 0; z < CHUNK_CACHE_WIDTH; z++) for (int z = 0; z < LevelConstants::CHUNK_CACHE_WIDTH; z++)
{ {
for (int x = 0; x < CHUNK_CACHE_WIDTH; x++) for (int x = 0; x < LevelConstants::CHUNK_CACHE_WIDTH; x++)
{ {
LevelChunk* chunk = level->getChunk(x, z); LevelChunk* chunk = level->getChunk(x, z);
if (chunk && chunk->unsaved) if (chunk && chunk->unsaved)
{ {
int pos = x + z * CHUNK_CACHE_WIDTH; int pos = x + z * LevelConstants::CHUNK_CACHE_WIDTH;
UnsavedChunkList::iterator prev = unsavedChunkList.begin(); UnsavedChunkList::iterator prev = unsavedChunkList.begin();
for ( ; prev != unsavedChunkList.end(); ++prev) for ( ; prev != unsavedChunkList.end(); ++prev)
{ {
@@ -415,13 +415,13 @@ void ExternalFileLevelStorage::save(Level* level, LevelChunk* levelChunk)
// Write chunk // Write chunk
RakNet::BitStream chunkData; RakNet::BitStream chunkData;
chunkData.Write((const char*)levelChunk->getBlockData(), CHUNK_BLOCK_COUNT); chunkData.Write((const char*)levelChunk->getBlockData(), LevelConstants::CHUNK_BLOCK_COUNT);
chunkData.Write((const char*)levelChunk->data.data, CHUNK_BLOCK_COUNT / 2); chunkData.Write((const char*)levelChunk->data.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
chunkData.Write((const char*)levelChunk->skyLight.data, CHUNK_BLOCK_COUNT / 2); chunkData.Write((const char*)levelChunk->skyLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
chunkData.Write((const char*)levelChunk->blockLight.data, CHUNK_BLOCK_COUNT / 2); chunkData.Write((const char*)levelChunk->blockLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
chunkData.Write((const char*)levelChunk->updateMap, CHUNK_COLUMNS); chunkData.Write((const char*)levelChunk->updateMap, LevelConstants::CHUNK_COLUMNS);
regionFile->writeChunk(levelChunk->x, levelChunk->z, chunkData); regionFile->writeChunk(levelChunk->x, levelChunk->z, chunkData);
@@ -453,16 +453,16 @@ LevelChunk* ExternalFileLevelStorage::load(Level* level, int x, int z)
chunkData->ResetReadPointer(); chunkData->ResetReadPointer();
unsigned char* blockIds = new unsigned char[CHUNK_BLOCK_COUNT]; unsigned char* blockIds = new unsigned char[LevelConstants::CHUNK_BLOCK_COUNT];
chunkData->Read((char*)blockIds, CHUNK_BLOCK_COUNT); chunkData->Read((char*)blockIds, LevelConstants::CHUNK_BLOCK_COUNT);
LevelChunk* levelChunk = new LevelChunk(level, blockIds, x, z); LevelChunk* levelChunk = new LevelChunk(level, blockIds, x, z);
chunkData->Read((char*)levelChunk->data.data, CHUNK_BLOCK_COUNT / 2); chunkData->Read((char*)levelChunk->data.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
if (loadedStorageVersion >= ChunkVersion_Light) { if (loadedStorageVersion >= ChunkVersion_Light) {
chunkData->Read((char*)levelChunk->skyLight.data, CHUNK_BLOCK_COUNT / 2); chunkData->Read((char*)levelChunk->skyLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
chunkData->Read((char*)levelChunk->blockLight.data, CHUNK_BLOCK_COUNT / 2); chunkData->Read((char*)levelChunk->blockLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
} }
chunkData->Read((char*)levelChunk->updateMap, CHUNK_COLUMNS); chunkData->Read((char*)levelChunk->updateMap, LevelConstants::CHUNK_COLUMNS);
// This will be difficult to maintain.. Storage version could be per chunk // This will be difficult to maintain.. Storage version could be per chunk
// too (but probably better to just read all -> write all, so that all // too (but probably better to just read all -> write all, so that all
// chunks got same version anyway) // chunks got same version anyway)
@@ -485,7 +485,7 @@ LevelChunk* ExternalFileLevelStorage::load(Level* level, int x, int z)
//bool dbg = (x == 7 && z == 9); //bool dbg = (x == 7 && z == 9);
//int t = 0; //int t = 0;
//for (int i = 0; i < CHUNK_COLUMNS; ++i) { //for (int i = 0; i < LevelConstants::CHUNK_COLUMNS; ++i) {
// char bits = levelChunk->updateMap[i]; // char bits = levelChunk->updateMap[i];
// t += (bits != 0); // t += (bits != 0);
// int xx = x * 16 + i%16; // int xx = x * 16 + i%16;

View File

@@ -47,7 +47,7 @@ bool Mushroom::mayPlaceOn( int tile ) {
} }
bool Mushroom::canSurvive( Level* level, int x, int y, int z ) { bool Mushroom::canSurvive( Level* level, int x, int y, int z ) {
if (y < 0 || y >= LEVEL_HEIGHT/*Level::maxBuildHeight*/) if (y < 0 || y >= LevelConstants::LEVEL_HEIGHT/*Level::maxBuildHeight*/)
return false; return false;
int below = level->getTile(x, y - 1, z); int below = level->getTile(x, y - 1, z);

View File

@@ -53,7 +53,7 @@ bool NetherReactor::canSpawnStartNetherReactor( Level* level, int x, int y, int
if(!allPlayersCloseToReactor(level, x, y, z)) { if(!allPlayersCloseToReactor(level, x, y, z)) {
player->displayClientMessage("All players need to be close to the reactor."); player->displayClientMessage("All players need to be close to the reactor.");
return false; return false;
} else if(y > LEVEL_HEIGHT - 28) { } else if(y > LevelConstants::LEVEL_HEIGHT - 28) {
player->displayClientMessage("The nether reactor needs to be built lower down."); player->displayClientMessage("The nether reactor needs to be built lower down.");
return false; return false;
} else if(y < 2) { } else if(y < 2) {

View File

@@ -130,7 +130,7 @@ Vec3 NetherReactorTileEntity::getSpawnPosition( float minDistance, float varible
void NetherReactorTileEntity::spawnEnemy() { void NetherReactorTileEntity::spawnEnemy() {
Mob* mob = MobFactory::CreateMob(MobTypes::PigZombie, level); Mob* mob = MobFactory::CreateMob(MobTypes::PigZombie, level);
Vec3 enemyPosition = getSpawnPosition(3, 4, -1); Vec3 enemyPosition = getSpawnPosition(3, 4, -1);
while(enemyPosition.x < 0 || enemyPosition.z < 0 || enemyPosition.x >= LEVEL_WIDTH || enemyPosition.z >= LEVEL_DEPTH) { while(enemyPosition.x < 0 || enemyPosition.z < 0 || enemyPosition.x >= LevelConstants::LEVEL_WIDTH || enemyPosition.z >= LevelConstants::LEVEL_DEPTH) {
enemyPosition = getSpawnPosition(3, 4, -1); enemyPosition = getSpawnPosition(3, 4, -1);
} }
MobSpawner::addMob(level, mob, enemyPosition.x, enemyPosition.y, enemyPosition.z, 0, 0, true); MobSpawner::addMob(level, mob, enemyPosition.x, enemyPosition.y, enemyPosition.z, 0, 0, true);
@@ -140,7 +140,7 @@ void NetherReactorTileEntity::spawnEnemy() {
void NetherReactorTileEntity::spawnItem() { void NetherReactorTileEntity::spawnItem() {
Vec3 itemPosition= getSpawnPosition(3, 4, -1); Vec3 itemPosition= getSpawnPosition(3, 4, -1);
while(itemPosition.x < 0 || itemPosition.z < 0 || itemPosition.x >= LEVEL_WIDTH || itemPosition.z >= LEVEL_DEPTH) { while(itemPosition.x < 0 || itemPosition.z < 0 || itemPosition.x >= LevelConstants::LEVEL_WIDTH || itemPosition.z >= LevelConstants::LEVEL_DEPTH) {
itemPosition = getSpawnPosition(3, 4, -1); itemPosition = getSpawnPosition(3, 4, -1);
} }
ItemEntity* item = new ItemEntity(level, itemPosition.x, itemPosition.y, itemPosition.z, getSpawnItem()); ItemEntity* item = new ItemEntity(level, itemPosition.x, itemPosition.y, itemPosition.z, getSpawnItem());