diff --git a/src/assets/AssetsLoader.h b/src/assets/AssetsLoader.h index cac41923..43e3bdca 100644 --- a/src/assets/AssetsLoader.h +++ b/src/assets/AssetsLoader.h @@ -7,10 +7,10 @@ #include #include -#define ASSET_TEXTURE 1 -#define ASSET_SHADER 2 -#define ASSET_FONT 3 -#define ASSET_ATLAS 4 +const short ASSET_TEXTURE = 1; +const short ASSET_SHADER = 2; +const short ASSET_FONT = 3; +const short ASSET_ATLAS = 4; class Assets; diff --git a/src/audio/Audio.cpp b/src/audio/Audio.cpp index 5562d2e9..0b1e6a7c 100644 --- a/src/audio/Audio.cpp +++ b/src/audio/Audio.cpp @@ -17,12 +17,12 @@ std::vector Audio::freebuffers; bool ALSource::setBuffer(ALBuffer* buffer) { alSourcei(id, AL_BUFFER, buffer->id); - return alCheck(); + return alCheckErrorsMacro(); } bool ALSource::play(){ alSourcePlay(id); - return alCheck(); + return alCheckErrorsMacro(); } bool ALSource::isPlaying() { @@ -33,33 +33,33 @@ bool ALSource::isPlaying() { bool ALSource::setPosition(glm::vec3 position) { alSource3f(id, AL_POSITION, position.x, position.y, position.z); - return alCheck(); + return alCheckErrorsMacro(); } bool ALSource::setVelocity(glm::vec3 velocity) { alSource3f(id, AL_VELOCITY, velocity.x, velocity.y, velocity.z); - return alCheck(); + return alCheckErrorsMacro(); } bool ALSource::setLoop(bool loop) { alSourcei(id, AL_LOOPING, AL_TRUE ? loop : AL_FALSE); - return alCheck(); + return alCheckErrorsMacro(); } bool ALSource::setGain(float gain) { alSourcef(id, AL_GAIN, gain); - return alCheck(); + return alCheckErrorsMacro(); } bool ALSource::setPitch(float pitch) { alSourcef(id, AL_PITCH, pitch); - return alCheck(); + return alCheckErrorsMacro(); } bool ALBuffer::load(int format, const char* data, int size, int freq) { alBufferData(id, format, data, size, freq); - return alCheck(); + return alCheckErrorsMacro(); } @@ -72,7 +72,7 @@ bool Audio::initialize() { alcCloseDevice(device); return false; } - if (!alCheck()) + if (!alCheckErrorsMacro()) return false; ALCint size; @@ -91,13 +91,13 @@ bool Audio::initialize() { void Audio::finalize(){ for (ALSource* source : allsources){ if (source->isPlaying()){ - alSourceStop(source->id); alCheck(); + alSourceStop(source->id); alCheckErrorsMacro(); } - alDeleteSources(1, &source->id); alCheck(); + alDeleteSources(1, &source->id); alCheckErrorsMacro(); } for (ALBuffer* buffer : allbuffers){ - alDeleteBuffers(1, &buffer->id); alCheck(); + alDeleteBuffers(1, &buffer->id); alCheckErrorsMacro(); } alcMakeContextCurrent(context); @@ -121,7 +121,7 @@ ALSource* Audio::getFreeSource(){ } ALuint id; alGenSources(1, &id); - if (!alCheck()) + if (!alCheckErrorsMacro()) return nullptr; ALSource* source = new ALSource(id); @@ -141,7 +141,7 @@ ALBuffer* Audio::getFreeBuffer(){ } ALuint id; alGenBuffers(1, &id); - if (!alCheck()) + if (!alCheckErrorsMacro()) return nullptr; ALBuffer* buffer = new ALBuffer(id); @@ -160,7 +160,7 @@ void Audio::freeBuffer(ALBuffer* buffer){ bool Audio::get_available_devices(std::vector& devicesVec){ const ALCchar* devices; devices = alcGetString(device, ALC_DEVICE_SPECIFIER); - if (!alCheck()) + if (!alCheckErrorsMacro()) return false; const char* ptr = devices; @@ -180,9 +180,9 @@ void Audio::setListener(glm::vec3 position, glm::vec3 velocity, glm::vec3 at, gl ALfloat listenerOri[] = { at.x, at.y, at.z, up.x, up.y, up.z }; alListener3f(AL_POSITION, position.x, position.y, position.z); - alCheck(); + alCheckErrorsMacro(); alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z); - alCheck(); + alCheckErrorsMacro(); alListenerfv(AL_ORIENTATION, listenerOri); - alCheck(); + alCheckErrorsMacro(); } diff --git a/src/audio/audioutil.h b/src/audio/audioutil.h index f48c261a..2044aaed 100644 --- a/src/audio/audioutil.h +++ b/src/audio/audioutil.h @@ -7,7 +7,7 @@ #include -#define alCheck() check_al_errors(__FILE__, __LINE__) +#define alCheckErrorsMacro() check_al_errors(__FILE__, __LINE__) bool check_al_errors(const std::string& filename, const std::uint_fast32_t line); diff --git a/src/constants.h b/src/constants.h index 49a97749..fbbab472 100644 --- a/src/constants.h +++ b/src/constants.h @@ -4,27 +4,27 @@ #include #include "typedefs.h" -#define ENGINE_VERSION_MAJOR 0 -#define ENGINE_VERSION_MINOR 15 -#define STR_(x) #x -#define STR(x) STR_(x) -#define ENGINE_VERSION STR(ENGINE_VERSION_MAJOR) "." STR(ENGINE_VERSION_MINOR) +const int ENGINE_VERSION_MAJOR = 0; +const int ENGINE_VERSION_MINOR = 15; +#define TOSTR_MACRO(x) #x +#define ENGINE_VERSION TOSTR_MACRO(ENGINE_VERSION_MAJOR) "." TOSTR_MACRO(ENGINE_VERSION_MINOR); -#define CHUNK_W 16 -#define CHUNK_H 256 -#define CHUNK_D 16 +const int CHUNK_W = 16; +const int CHUNK_H = 256; +const int CHUNK_D = 16; /* Chunk volume (count of voxels per Chunk) */ -#define CHUNK_VOL (CHUNK_W * CHUNK_H * CHUNK_D) +const int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D); /* BLOCK_VOID is block id used to mark non-existing voxel (voxel of missing chunk) */ -#define BLOCK_VOID (blockid_t)((2 << (sizeof(blockid_t)*CHAR_BIT)) - 1) +const blockid_t BLOCK_VOID = UCHAR_MAX; inline uint vox_index(int x, int y, int z, int w=CHUNK_W, int d=CHUNK_D) { return (y * d + z) * w + x; } -#define SHADERS_FOLDER "shaders" +//cannot replace defines with const while used for substitution +#define SHADERS_FOLDER "shaders" #define TEXTURES_FOLDER "textures" #define FONTS_FOLDER "fonts" diff --git a/src/core_defs.h b/src/core_defs.h index ffd26795..f0c46afe 100644 --- a/src/core_defs.h +++ b/src/core_defs.h @@ -3,22 +3,22 @@ /* blocks and bindings used in engine code */ -#define BLOCK_AIR 0 +const int BLOCK_AIR = 0; -#define BIND_MOVE_FORWARD "movement.forward" -#define BIND_MOVE_BACK "movement.back" -#define BIND_MOVE_LEFT "movement.left" -#define BIND_MOVE_RIGHT "movement.right" -#define BIND_MOVE_JUMP "movement.jump" -#define BIND_MOVE_SPRINT "movement.sprint" -#define BIND_MOVE_CROUCH "movement.crouch" -#define BIND_MOVE_CHEAT "movement.cheat" -#define BIND_CAM_ZOOM "camera.zoom" -#define BIND_PLAYER_NOCLIP "player.noclip" -#define BIND_PLAYER_FLIGHT "player.flight" -#define BIND_PLAYER_ATTACK "player.attack" -#define BIND_PLAYER_BUILD "player.build" -#define BIND_PLAYER_PICK "player.pick" -#define BIND_HUD_INVENTORY "hud.inventory" +const std::string BIND_MOVE_FORWARD = "movement.forward"; +const std::string BIND_MOVE_BACK = "movement.back"; +const std::string BIND_MOVE_LEFT = "movement.left"; +const std::string BIND_MOVE_RIGHT = "movement.right"; +const std::string BIND_MOVE_JUMP = "movement.jump"; +const std::string BIND_MOVE_SPRINT = "movement.sprint"; +const std::string BIND_MOVE_CROUCH = "movement.crouch"; +const std::string BIND_MOVE_CHEAT = "movement.cheat"; +const std::string BIND_CAM_ZOOM = "camera.zoom"; +const std::string BIND_PLAYER_NOCLIP = "player.noclip"; +const std::string BIND_PLAYER_FLIGHT = "player.flight"; +const std::string BIND_PLAYER_ATTACK = "player.attack"; +const std::string BIND_PLAYER_BUILD = "player.build"; +const std::string BIND_PLAYER_PICK = "player.pick"; +const std::string BIND_HUD_INVENTORY = "hud.inventory"; #endif // SRC_CORE_DEFS_H_ \ No newline at end of file diff --git a/src/files/WorldFiles.cpp b/src/files/WorldFiles.cpp index f4b76816..9067fbaa 100644 --- a/src/files/WorldFiles.cpp +++ b/src/files/WorldFiles.cpp @@ -25,14 +25,14 @@ #include #include -#define SECTION_POSITION 1 -#define SECTION_ROTATION 2 -#define SECTION_FLAGS 3 -#define PLAYER_FLAG_FLIGHT 0x1 -#define PLAYER_FLAG_NOCLIP 0x2 +const int SECTION_POSITION = 1; +const int SECTION_ROTATION = 2; +const int SECTION_FLAGS = 3; +const int PLAYER_FLAG_FLIGHT = 0x1; +const int PLAYER_FLAG_NOCLIP = 0x2; -#define WORLD_SECTION_MAIN 1 -#define WORLD_SECTION_DAYNIGHT 2 +const int WORLD_SECTION_MAIN = 1; +const int WORLD_SECTION_DAYNIGHT = 2; using glm::ivec2; using glm::vec3; diff --git a/src/files/WorldFiles.h b/src/files/WorldFiles.h index 82628b39..4433fa45 100644 --- a/src/files/WorldFiles.h +++ b/src/files/WorldFiles.h @@ -13,13 +13,13 @@ #include "../typedefs.h" -#define REGION_SIZE_BIT 5 -#define REGION_SIZE (1 << (REGION_SIZE_BIT)) -#define REGION_VOL ((REGION_SIZE) * (REGION_SIZE)) -#define REGION_FORMAT_VERSION 1 +const uint REGION_SIZE_BIT = 5; +const uint REGION_SIZE = (1 << (REGION_SIZE_BIT)); +const uint REGION_VOL = ((REGION_SIZE) * (REGION_SIZE)); +const uint REGION_FORMAT_VERSION = 1; +const uint WORLD_FORMAT_VERSION = 1; #define REGION_FORMAT_MAGIC ".VOXREG" #define WORLD_FORMAT_MAGIC ".VOXWLD" -#define WORLD_FORMAT_VERSION 1 class Player; class Chunk; diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index 35f9cc57..818aaaf7 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -14,9 +14,9 @@ using glm::vec2; using glm::vec3; using glm::vec4; -#define KEY_ESCAPE 256 -#define KEY_ENTER 257 -#define KEY_BACKSPACE 259 +const uint KEY_ESCAPE = 256; +const uint KEY_ENTER = 257; +const uint KEY_BACKSPACE = 259; using namespace gui; diff --git a/src/graphics/Batch2D.cpp b/src/graphics/Batch2D.cpp index a44dc9b6..dce99572 100644 --- a/src/graphics/Batch2D.cpp +++ b/src/graphics/Batch2D.cpp @@ -5,7 +5,7 @@ #include -#define VERTEX_SIZE 8 +const uint B2D_VERTEX_SIZE = 8; using glm::vec2; using glm::vec3; @@ -16,7 +16,7 @@ Batch2D::Batch2D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1 {2}, {2}, {4}, {0} }; - buffer = new float[capacity * VERTEX_SIZE]; + buffer = new float[capacity * B2D_VERTEX_SIZE]; mesh = new Mesh(buffer, 0, attrs); index = 0; @@ -75,7 +75,7 @@ void Batch2D::texture(Texture* new_texture){ } void Batch2D::point(float x, float y, float r, float g, float b, float a){ - if (index + 6*VERTEX_SIZE >= capacity) + if (index + 6*B2D_VERTEX_SIZE >= capacity) render(GL_TRIANGLES); vertex(x, y, 0, 0, r,g,b,a); @@ -83,7 +83,7 @@ void Batch2D::point(float x, float y, float r, float g, float b, float a){ } void Batch2D::line(float x1, float y1, float x2, float y2, float r, float g, float b, float a){ - if (index + 6*VERTEX_SIZE >= capacity) + if (index + 6*B2D_VERTEX_SIZE >= capacity) render(GL_TRIANGLES); vertex(x1, y1, 0, 0, r,g,b,a); @@ -96,7 +96,7 @@ void Batch2D::rect(float x, float y, float w, float h){ const float g = color.g; const float b = color.b; const float a = color.a; - if (index + 6*VERTEX_SIZE >= capacity) + if (index + 6*B2D_VERTEX_SIZE >= capacity) render(GL_TRIANGLES); vertex(x, y, 0, 0, r,g,b,a); @@ -117,7 +117,7 @@ void Batch2D::rect( bool flippedX, bool flippedY, vec4 tint) { - if (index + 6*VERTEX_SIZE >= capacity) + if (index + 6*B2D_VERTEX_SIZE >= capacity) render(GL_TRIANGLES); float centerX = w*ox; @@ -205,7 +205,7 @@ void Batch2D::rect( void Batch2D::rect(float x, float y, float w, float h, float u, float v, float tx, float ty, float r, float g, float b, float a){ - if (index + 6*VERTEX_SIZE >= capacity) + if (index + 6*B2D_VERTEX_SIZE >= capacity) render(GL_TRIANGLES); vertex(x, y, u, v+ty, r,g,b,a); vertex(x+w, y+h, u+tx, v, r,g,b,a); @@ -222,7 +222,7 @@ void Batch2D::rect(float x, float y, float w, float h, float r2, float g2, float b2, float r3, float g3, float b3, float r4, float g4, float b4, int sh){ - if (index + 30*VERTEX_SIZE >= capacity) + if (index + 30*B2D_VERTEX_SIZE >= capacity) render(GL_TRIANGLES); vec2 v0 = vec2(x+h/2,y+h/2); vec2 v1 = vec2(x+w-sh,y); @@ -317,7 +317,7 @@ void Batch2D::blockSprite(float x, float y, float w, float h, const UVRegion reg float scalex = regions[3].u2-regions[3].u1; float scaley = regions[3].v2-regions[3].v1; - if (this->index + 18*VERTEX_SIZE >= capacity) + if (this->index + 18*B2D_VERTEX_SIZE >= capacity) render(); float d = (w + h) * 0.5f; @@ -376,7 +376,7 @@ void Batch2D::blockSprite(float x, float y, float w, float h, const UVRegion reg } void Batch2D::render(unsigned int gl_primitive) { - mesh->reload(buffer, index / VERTEX_SIZE); + mesh->reload(buffer, index / B2D_VERTEX_SIZE); mesh->draw(gl_primitive); index = 0; } diff --git a/src/graphics/Batch3D.cpp b/src/graphics/Batch3D.cpp index 1c4ab995..1fda4c65 100644 --- a/src/graphics/Batch3D.cpp +++ b/src/graphics/Batch3D.cpp @@ -6,7 +6,7 @@ #include #include "../typedefs.h" -#define VERTEX_SIZE 9 +const uint B3D_VERTEX_SIZE = 9; using glm::vec2; using glm::vec3; @@ -19,7 +19,7 @@ Batch3D::Batch3D(size_t capacity) {3}, {2}, {4}, {0} }; - buffer = new float[capacity * VERTEX_SIZE]; + buffer = new float[capacity * B3D_VERTEX_SIZE]; mesh = new Mesh(buffer, 0, attrs); index = 0; @@ -84,7 +84,7 @@ void Batch3D::face(const vec3& coord, float w, float h, const vec3& axisY, const UVRegion& region, const vec4& tint) { - if (index + VERTEX_SIZE * 6 > capacity) { + if (index + B3D_VERTEX_SIZE * 6 > capacity) { flush(); } vertex(coord, region.u1, region.v1, @@ -118,7 +118,7 @@ void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, const UVRe const float g = color.g; const float b = color.b; const float a = color.a; - if (index + 6*VERTEX_SIZE >= capacity) { + if (index + 6*B3D_VERTEX_SIZE >= capacity) { flush(); } @@ -179,7 +179,7 @@ void Batch3D::blockCube(const vec3 size, const UVRegion(&texfaces)[6], const vec } void Batch3D::flush() { - mesh->reload(buffer, index / VERTEX_SIZE); + mesh->reload(buffer, index / B3D_VERTEX_SIZE); mesh->draw(); index = 0; } diff --git a/src/graphics/BlocksRenderer.cpp b/src/graphics/BlocksRenderer.cpp index 7e62fc6a..0e2bb498 100644 --- a/src/graphics/BlocksRenderer.cpp +++ b/src/graphics/BlocksRenderer.cpp @@ -17,7 +17,7 @@ using glm::ivec3; using glm::vec3; using glm::vec4; -#define VERTEX_SIZE 6 +const uint BlocksRenderer::VERTEX_SIZE = 6; BlocksRenderer::BlocksRenderer(size_t capacity, const Content* content, @@ -81,7 +81,7 @@ void BlocksRenderer::face(const vec3& coord, float w, float h, const UVRegion& region, const vec4(&lights)[4], const vec4& tint) { - if (vertexOffset + VERTEX_SIZE * 4 > capacity) { + if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) { overflow = true; return; } @@ -116,7 +116,7 @@ void BlocksRenderer::face(const ivec3& coord, const ivec3& axisZ, const ivec3& laxisZ, const UVRegion& region) { - if (vertexOffset + VERTEX_SIZE * 4 > capacity) { + if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) { overflow = true; return; } @@ -144,7 +144,7 @@ void BlocksRenderer::face(const ivec3& coord_, float height, float depth, const UVRegion& region) { - if (vertexOffset + VERTEX_SIZE * 4 > capacity) { + if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) { overflow = true; return; } @@ -414,7 +414,7 @@ Mesh* BlocksRenderer::render(const Chunk* chunk, int atlas_size, const ChunksSto render(voxels, atlas_size); const vattr attrs[]{ {3}, {2}, {1}, {0} }; - Mesh* mesh = new Mesh(vertexBuffer, vertexOffset / VERTEX_SIZE, indexBuffer, indexSize, attrs); + Mesh* mesh = new Mesh(vertexBuffer, vertexOffset / BlocksRenderer::VERTEX_SIZE, indexBuffer, indexSize, attrs); return mesh; } diff --git a/src/graphics/BlocksRenderer.h b/src/graphics/BlocksRenderer.h index f58c56c8..12c709ac 100644 --- a/src/graphics/BlocksRenderer.h +++ b/src/graphics/BlocksRenderer.h @@ -18,6 +18,7 @@ class ChunksStorage; class ContentGfxCache; class BlocksRenderer { + static const uint VERTEX_SIZE; const Content* const content; float* vertexBuffer; int* indexBuffer; diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index 0abf7962..17b934d9 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -29,7 +29,7 @@ bool Font::isPrintableChar(int c) { } } -#define RES 16 +const int RES = 16; int Font::calcWidth(std::wstring text) { return text.length() * 8; diff --git a/src/graphics/Font.h b/src/graphics/Font.h index 6df79e08..e2e73123 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -7,9 +7,9 @@ class Texture; class Batch2D; -#define STYLE_NONE 0 -#define STYLE_SHADOW 1 -#define STYLE_OUTLINE 2 +const uint STYLE_NONE = 0; +const uint STYLE_SHADOW = 1; +const uint STYLE_OUTLINE = 2; class Font { int lineHeight_; diff --git a/src/graphics/LineBatch.cpp b/src/graphics/LineBatch.cpp index 37a74015..efb41afc 100644 --- a/src/graphics/LineBatch.cpp +++ b/src/graphics/LineBatch.cpp @@ -3,7 +3,7 @@ #include -#define LB_VERTEX_SIZE (3+4) +const uint LB_VERTEX_SIZE = (3+4); LineBatch::LineBatch(size_t capacity) : capacity(capacity) { const vattr attrs[] = { {3},{4}, {0} }; diff --git a/src/logic/ChunksController.cpp b/src/logic/ChunksController.cpp index f7ae440a..936afb45 100644 --- a/src/logic/ChunksController.cpp +++ b/src/logic/ChunksController.cpp @@ -18,8 +18,8 @@ #include "../world/World.h" #include "../maths/voxmaths.h" -#define MAX_WORK_PER_FRAME 16 -#define MIN_SURROUNDING 9 +const uint MAX_WORK_PER_FRAME = 16; +const uint MIN_SURROUNDING = 9; using std::unique_ptr; using std::shared_ptr; diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index c1bb1306..46d6675e 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -15,15 +15,15 @@ #include "../core_defs.h" -#define CAM_SHAKE_OFFSET 0.025f -#define CAM_SHAKE_OFFSET_Y 0.031f -#define CAM_SHAKE_SPEED 1.6f -#define CAM_SHAKE_DELTA_K 10.0f -#define ZOOM_SPEED 16.0f -#define CROUCH_ZOOM 0.9f -#define RUN_ZOOM 1.1f -#define C_ZOOM 0.1f -#define CROUCH_SHIFT_Y -0.2f +const float CAM_SHAKE_OFFSET = 0.025f; +const float CAM_SHAKE_OFFSET_Y = 0.031f; +const float CAM_SHAKE_SPEED = 1.6f; +const float CAM_SHAKE_DELTA_K = 10.0f; +const float ZOOM_SPEED = 16.0f; +const float CROUCH_ZOOM = 0.9f; +const float RUN_ZOOM = 1.1f; +const float C_ZOOM = 0.1f; +const float CROUCH_SHIFT_Y = -0.2f; using glm::vec2; using glm::vec3; diff --git a/src/objects/Player.cpp b/src/objects/Player.cpp index e67ab020..1ff92c25 100644 --- a/src/objects/Player.cpp +++ b/src/objects/Player.cpp @@ -8,13 +8,13 @@ #include -#define CROUCH_SPEED_MUL 0.35f -#define RUN_SPEED_MUL 1.5f -#define PLAYER_GROUND_DAMPING 10.0f -#define PLAYER_AIR_DAMPING 7.0f -#define FLIGHT_SPEED_MUL 4.0f -#define CHEAT_SPEED_MUL 5.0f -#define JUMP_FORCE 7.0f +const float CROUCH_SPEED_MUL = 0.35f; +const float RUN_SPEED_MUL = 1.5f; +const float PLAYER_GROUND_DAMPING = 10.0f; +const float PLAYER_AIR_DAMPING = 7.0f; +const float FLIGHT_SPEED_MUL = 4.0f; +const float CHEAT_SPEED_MUL = 5.0f; +const float JUMP_FORCE = 7.0f; Player::Player(glm::vec3 position, float speed, Camera* camera) : speed(speed), diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index 6eb82af9..a8b8f09a 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -5,7 +5,7 @@ #include "../voxels/Block.h" #include "../voxels/Chunks.h" -#define E 0.03 +const double E = 0.03; using glm::vec3; diff --git a/src/voxels/Block.h b/src/voxels/Block.h index 7d8ebc58..fa6002db 100644 --- a/src/voxels/Block.h +++ b/src/voxels/Block.h @@ -7,14 +7,14 @@ #include "../maths/aabb.h" #include "../typedefs.h" -#define FACE_MX 0 -#define FACE_PX 1 -#define FACE_MY 2 -#define FACE_PY 3 -#define FACE_MZ 4 -#define FACE_PZ 5 +const uint FACE_MX = 0; +const uint FACE_PX = 1; +const uint FACE_MY = 2; +const uint FACE_PY = 3; +const uint FACE_MZ = 4; +const uint FACE_PZ = 5; -#define BLOCK_AABB_GRID 16 +const uint BLOCK_AABB_GRID = 16; struct CoordSystem { glm::ivec3 axisX; diff --git a/src/voxels/Chunk.h b/src/voxels/Chunk.h index 8e751386..31c1cd32 100644 --- a/src/voxels/Chunk.h +++ b/src/voxels/Chunk.h @@ -4,11 +4,13 @@ #include #include "../constants.h" -#define CHUNK_MODIFIED 0x1 -#define CHUNK_READY 0x2 -#define CHUNK_LOADED 0x4 -#define CHUNK_LIGHTED 0x8 -#define CHUNK_UNSAVED 0x10 +struct ChunkFlag{ + static const int MODIFIED = 0x1; + static const int READY = 0x2; + static const int LOADED = 0x4; + static const int LIGHTED = 0x8; + static const int UNSAVED = 0x10; +}; #define CHUNK_DATA_LEN (CHUNK_VOL*2) struct voxel; @@ -19,10 +21,6 @@ struct RenderData { size_t size; }; -#define BIT_ON(f,i) do{f|= i;} while(0) -#define BIT_OFF(f,i) do{f&=~(i);} while(0) -#define BITSET(f,i,s) if (s) BIT_ON(f,i); else BIT_OFF(f,i); - class Chunk { public: int x, z; @@ -43,26 +41,33 @@ public: Chunk* clone() const; // flags getters/setters below + + void SETFLAGS(int mask, bool value){ + if (value) + flags |= mask; + else + flags &= ~(mask); + } - inline bool isUnsaved() const {return flags & CHUNK_UNSAVED;} + inline bool isUnsaved() const {return flags & ChunkFlag::UNSAVED;} - inline bool isModified() const {return flags & CHUNK_MODIFIED;} + inline bool isModified() const {return flags & ChunkFlag::MODIFIED;} - inline bool isLighted() const {return flags & CHUNK_LIGHTED;} + inline bool isLighted() const {return flags & ChunkFlag::LIGHTED;} - inline bool isLoaded() const {return flags & CHUNK_LOADED;} + inline bool isLoaded() const {return flags & ChunkFlag::LOADED;} - inline bool isReady() const {return flags & CHUNK_READY;} + inline bool isReady() const {return flags & ChunkFlag::READY;} - inline void setUnsaved(bool flag) {BITSET(flags, CHUNK_UNSAVED, flag);} + inline void setUnsaved(bool newState) {SETFLAGS(ChunkFlag::UNSAVED, newState);} - inline void setModified(bool flag) {BITSET(flags, CHUNK_MODIFIED, flag);} + inline void setModified(bool newState) {SETFLAGS(ChunkFlag::MODIFIED, newState);} - inline void setLoaded(bool flag) {BITSET(flags, CHUNK_LOADED, flag);} + inline void setLoaded(bool newState) {SETFLAGS(ChunkFlag::LOADED, newState);} - inline void setLighted(bool flag) {BITSET(flags, CHUNK_LIGHTED, flag);} + inline void setLighted(bool newState) {SETFLAGS(ChunkFlag::LIGHTED, newState);} - inline void setReady(bool flag) {BITSET(flags, CHUNK_READY, flag);} + inline void setReady(bool newState) {SETFLAGS(ChunkFlag::READY, newState);} ubyte* encode() const; bool decode(ubyte* data); diff --git a/src/voxels/WorldGenerator.cpp b/src/voxels/WorldGenerator.cpp index aabb2997..f0a01969 100644 --- a/src/voxels/WorldGenerator.cpp +++ b/src/voxels/WorldGenerator.cpp @@ -16,7 +16,7 @@ #include "../maths/voxmaths.h" #include "../core_defs.h" -#define SEA_LEVEL 55 +const int SEA_LEVEL = 55; class Map2D { int x, z;