Merge pull request #35 from A-lex-Ra/main

Завершение работы с дефайнами
This commit is contained in:
MihailRis 2023-12-04 21:17:53 +03:00 committed by GitHub
commit aedbc230bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 142 additions and 136 deletions

View File

@ -7,10 +7,10 @@
#include <map> #include <map>
#include <queue> #include <queue>
#define ASSET_TEXTURE 1 const short ASSET_TEXTURE = 1;
#define ASSET_SHADER 2 const short ASSET_SHADER = 2;
#define ASSET_FONT 3 const short ASSET_FONT = 3;
#define ASSET_ATLAS 4 const short ASSET_ATLAS = 4;
class Assets; class Assets;

View File

@ -17,12 +17,12 @@ std::vector<ALBuffer*> Audio::freebuffers;
bool ALSource::setBuffer(ALBuffer* buffer) { bool ALSource::setBuffer(ALBuffer* buffer) {
alSourcei(id, AL_BUFFER, buffer->id); alSourcei(id, AL_BUFFER, buffer->id);
return alCheck(); return alCheckErrorsMacro();
} }
bool ALSource::play(){ bool ALSource::play(){
alSourcePlay(id); alSourcePlay(id);
return alCheck(); return alCheckErrorsMacro();
} }
bool ALSource::isPlaying() { bool ALSource::isPlaying() {
@ -33,33 +33,33 @@ bool ALSource::isPlaying() {
bool ALSource::setPosition(glm::vec3 position) { bool ALSource::setPosition(glm::vec3 position) {
alSource3f(id, AL_POSITION, position.x, position.y, position.z); alSource3f(id, AL_POSITION, position.x, position.y, position.z);
return alCheck(); return alCheckErrorsMacro();
} }
bool ALSource::setVelocity(glm::vec3 velocity) { bool ALSource::setVelocity(glm::vec3 velocity) {
alSource3f(id, AL_VELOCITY, velocity.x, velocity.y, velocity.z); alSource3f(id, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
return alCheck(); return alCheckErrorsMacro();
} }
bool ALSource::setLoop(bool loop) { bool ALSource::setLoop(bool loop) {
alSourcei(id, AL_LOOPING, AL_TRUE ? loop : AL_FALSE); alSourcei(id, AL_LOOPING, AL_TRUE ? loop : AL_FALSE);
return alCheck(); return alCheckErrorsMacro();
} }
bool ALSource::setGain(float gain) { bool ALSource::setGain(float gain) {
alSourcef(id, AL_GAIN, gain); alSourcef(id, AL_GAIN, gain);
return alCheck(); return alCheckErrorsMacro();
} }
bool ALSource::setPitch(float pitch) { bool ALSource::setPitch(float pitch) {
alSourcef(id, AL_PITCH, pitch); alSourcef(id, AL_PITCH, pitch);
return alCheck(); return alCheckErrorsMacro();
} }
bool ALBuffer::load(int format, const char* data, int size, int freq) { bool ALBuffer::load(int format, const char* data, int size, int freq) {
alBufferData(id, format, data, size, freq); alBufferData(id, format, data, size, freq);
return alCheck(); return alCheckErrorsMacro();
} }
@ -72,7 +72,7 @@ bool Audio::initialize() {
alcCloseDevice(device); alcCloseDevice(device);
return false; return false;
} }
if (!alCheck()) if (!alCheckErrorsMacro())
return false; return false;
ALCint size; ALCint size;
@ -91,13 +91,13 @@ bool Audio::initialize() {
void Audio::finalize(){ void Audio::finalize(){
for (ALSource* source : allsources){ for (ALSource* source : allsources){
if (source->isPlaying()){ 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){ for (ALBuffer* buffer : allbuffers){
alDeleteBuffers(1, &buffer->id); alCheck(); alDeleteBuffers(1, &buffer->id); alCheckErrorsMacro();
} }
alcMakeContextCurrent(context); alcMakeContextCurrent(context);
@ -121,7 +121,7 @@ ALSource* Audio::getFreeSource(){
} }
ALuint id; ALuint id;
alGenSources(1, &id); alGenSources(1, &id);
if (!alCheck()) if (!alCheckErrorsMacro())
return nullptr; return nullptr;
ALSource* source = new ALSource(id); ALSource* source = new ALSource(id);
@ -141,7 +141,7 @@ ALBuffer* Audio::getFreeBuffer(){
} }
ALuint id; ALuint id;
alGenBuffers(1, &id); alGenBuffers(1, &id);
if (!alCheck()) if (!alCheckErrorsMacro())
return nullptr; return nullptr;
ALBuffer* buffer = new ALBuffer(id); ALBuffer* buffer = new ALBuffer(id);
@ -160,7 +160,7 @@ void Audio::freeBuffer(ALBuffer* buffer){
bool Audio::get_available_devices(std::vector<std::string>& devicesVec){ bool Audio::get_available_devices(std::vector<std::string>& devicesVec){
const ALCchar* devices; const ALCchar* devices;
devices = alcGetString(device, ALC_DEVICE_SPECIFIER); devices = alcGetString(device, ALC_DEVICE_SPECIFIER);
if (!alCheck()) if (!alCheckErrorsMacro())
return false; return false;
const char* ptr = devices; 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 }; ALfloat listenerOri[] = { at.x, at.y, at.z, up.x, up.y, up.z };
alListener3f(AL_POSITION, position.x, position.y, position.z); alListener3f(AL_POSITION, position.x, position.y, position.z);
alCheck(); alCheckErrorsMacro();
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z); alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
alCheck(); alCheckErrorsMacro();
alListenerfv(AL_ORIENTATION, listenerOri); alListenerfv(AL_ORIENTATION, listenerOri);
alCheck(); alCheckErrorsMacro();
} }

View File

@ -7,7 +7,7 @@
#include <AL/al.h> #include <AL/al.h>
#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); bool check_al_errors(const std::string& filename, const std::uint_fast32_t line);

View File

@ -4,26 +4,26 @@
#include <limits.h> #include <limits.h>
#include "typedefs.h" #include "typedefs.h"
#define ENGINE_VERSION_MAJOR 0 const int ENGINE_VERSION_MAJOR = 0;
#define ENGINE_VERSION_MINOR 15 const int ENGINE_VERSION_MINOR = 15;
#define STR_(x) #x #define TOSTR_MACRO(x) #x
#define STR(x) STR_(x) #define ENGINE_VERSION TOSTR_MACRO(ENGINE_VERSION_MAJOR) "." TOSTR_MACRO(ENGINE_VERSION_MINOR);
#define ENGINE_VERSION STR(ENGINE_VERSION_MAJOR) "." STR(ENGINE_VERSION_MINOR)
#define CHUNK_W 16 const int CHUNK_W = 16;
#define CHUNK_H 256 const int CHUNK_H = 256;
#define CHUNK_D 16 const int CHUNK_D = 16;
/* Chunk volume (count of voxels per Chunk) */ /* 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) */ /* 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) { inline uint vox_index(int x, int y, int z, int w=CHUNK_W, int d=CHUNK_D) {
return (y * d + z) * w + x; return (y * d + z) * w + x;
} }
//cannot replace defines with const while used for substitution
#define SHADERS_FOLDER "shaders" #define SHADERS_FOLDER "shaders"
#define TEXTURES_FOLDER "textures" #define TEXTURES_FOLDER "textures"
#define FONTS_FOLDER "fonts" #define FONTS_FOLDER "fonts"

View File

@ -3,22 +3,22 @@
/* blocks and bindings used in engine code */ /* blocks and bindings used in engine code */
#define BLOCK_AIR 0 const int BLOCK_AIR = 0;
#define BIND_MOVE_FORWARD "movement.forward" const std::string BIND_MOVE_FORWARD = "movement.forward";
#define BIND_MOVE_BACK "movement.back" const std::string BIND_MOVE_BACK = "movement.back";
#define BIND_MOVE_LEFT "movement.left" const std::string BIND_MOVE_LEFT = "movement.left";
#define BIND_MOVE_RIGHT "movement.right" const std::string BIND_MOVE_RIGHT = "movement.right";
#define BIND_MOVE_JUMP "movement.jump" const std::string BIND_MOVE_JUMP = "movement.jump";
#define BIND_MOVE_SPRINT "movement.sprint" const std::string BIND_MOVE_SPRINT = "movement.sprint";
#define BIND_MOVE_CROUCH "movement.crouch" const std::string BIND_MOVE_CROUCH = "movement.crouch";
#define BIND_MOVE_CHEAT "movement.cheat" const std::string BIND_MOVE_CHEAT = "movement.cheat";
#define BIND_CAM_ZOOM "camera.zoom" const std::string BIND_CAM_ZOOM = "camera.zoom";
#define BIND_PLAYER_NOCLIP "player.noclip" const std::string BIND_PLAYER_NOCLIP = "player.noclip";
#define BIND_PLAYER_FLIGHT "player.flight" const std::string BIND_PLAYER_FLIGHT = "player.flight";
#define BIND_PLAYER_ATTACK "player.attack" const std::string BIND_PLAYER_ATTACK = "player.attack";
#define BIND_PLAYER_BUILD "player.build" const std::string BIND_PLAYER_BUILD = "player.build";
#define BIND_PLAYER_PICK "player.pick" const std::string BIND_PLAYER_PICK = "player.pick";
#define BIND_HUD_INVENTORY "hud.inventory" const std::string BIND_HUD_INVENTORY = "hud.inventory";
#endif // SRC_CORE_DEFS_H_ #endif // SRC_CORE_DEFS_H_

View File

@ -25,14 +25,14 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#define SECTION_POSITION 1 const int SECTION_POSITION = 1;
#define SECTION_ROTATION 2 const int SECTION_ROTATION = 2;
#define SECTION_FLAGS 3 const int SECTION_FLAGS = 3;
#define PLAYER_FLAG_FLIGHT 0x1 const int PLAYER_FLAG_FLIGHT = 0x1;
#define PLAYER_FLAG_NOCLIP 0x2 const int PLAYER_FLAG_NOCLIP = 0x2;
#define WORLD_SECTION_MAIN 1 const int WORLD_SECTION_MAIN = 1;
#define WORLD_SECTION_DAYNIGHT 2 const int WORLD_SECTION_DAYNIGHT = 2;
using glm::ivec2; using glm::ivec2;
using glm::vec3; using glm::vec3;

View File

@ -13,13 +13,13 @@
#include "../typedefs.h" #include "../typedefs.h"
#define REGION_SIZE_BIT 5 const uint REGION_SIZE_BIT = 5;
#define REGION_SIZE (1 << (REGION_SIZE_BIT)) const uint REGION_SIZE = (1 << (REGION_SIZE_BIT));
#define REGION_VOL ((REGION_SIZE) * (REGION_SIZE)) const uint REGION_VOL = ((REGION_SIZE) * (REGION_SIZE));
#define REGION_FORMAT_VERSION 1 const uint REGION_FORMAT_VERSION = 1;
const uint WORLD_FORMAT_VERSION = 1;
#define REGION_FORMAT_MAGIC ".VOXREG" #define REGION_FORMAT_MAGIC ".VOXREG"
#define WORLD_FORMAT_MAGIC ".VOXWLD" #define WORLD_FORMAT_MAGIC ".VOXWLD"
#define WORLD_FORMAT_VERSION 1
class Player; class Player;
class Chunk; class Chunk;

View File

@ -14,9 +14,9 @@ using glm::vec2;
using glm::vec3; using glm::vec3;
using glm::vec4; using glm::vec4;
#define KEY_ESCAPE 256 const uint KEY_ESCAPE = 256;
#define KEY_ENTER 257 const uint KEY_ENTER = 257;
#define KEY_BACKSPACE 259 const uint KEY_BACKSPACE = 259;
using namespace gui; using namespace gui;

View File

@ -5,7 +5,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#define VERTEX_SIZE 8 const uint B2D_VERTEX_SIZE = 8;
using glm::vec2; using glm::vec2;
using glm::vec3; using glm::vec3;
@ -16,7 +16,7 @@ Batch2D::Batch2D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1
{2}, {2}, {4}, {0} {2}, {2}, {4}, {0}
}; };
buffer = new float[capacity * VERTEX_SIZE]; buffer = new float[capacity * B2D_VERTEX_SIZE];
mesh = new Mesh(buffer, 0, attrs); mesh = new Mesh(buffer, 0, attrs);
index = 0; 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){ 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); render(GL_TRIANGLES);
vertex(x, y, 0, 0, r,g,b,a); 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){ 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); render(GL_TRIANGLES);
vertex(x1, y1, 0, 0, r,g,b,a); 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 g = color.g;
const float b = color.b; const float b = color.b;
const float a = color.a; const float a = color.a;
if (index + 6*VERTEX_SIZE >= capacity) if (index + 6*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES); render(GL_TRIANGLES);
vertex(x, y, 0, 0, r,g,b,a); vertex(x, y, 0, 0, r,g,b,a);
@ -117,7 +117,7 @@ void Batch2D::rect(
bool flippedX, bool flippedX,
bool flippedY, bool flippedY,
vec4 tint) { vec4 tint) {
if (index + 6*VERTEX_SIZE >= capacity) if (index + 6*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES); render(GL_TRIANGLES);
float centerX = w*ox; float centerX = w*ox;
@ -205,7 +205,7 @@ void Batch2D::rect(
void Batch2D::rect(float x, float y, float w, float h, void Batch2D::rect(float x, float y, float w, float h,
float u, float v, float tx, float ty, float u, float v, float tx, float ty,
float r, float g, float b, float a){ float r, float g, float b, float a){
if (index + 6*VERTEX_SIZE >= capacity) if (index + 6*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES); render(GL_TRIANGLES);
vertex(x, y, u, v+ty, r,g,b,a); vertex(x, y, u, v+ty, r,g,b,a);
vertex(x+w, y+h, u+tx, v, 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 r2, float g2, float b2,
float r3, float g3, float b3, float r3, float g3, float b3,
float r4, float g4, float b4, int sh){ float r4, float g4, float b4, int sh){
if (index + 30*VERTEX_SIZE >= capacity) if (index + 30*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES); render(GL_TRIANGLES);
vec2 v0 = vec2(x+h/2,y+h/2); vec2 v0 = vec2(x+h/2,y+h/2);
vec2 v1 = vec2(x+w-sh,y); 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 scalex = regions[3].u2-regions[3].u1;
float scaley = regions[3].v2-regions[3].v1; float scaley = regions[3].v2-regions[3].v1;
if (this->index + 18*VERTEX_SIZE >= capacity) if (this->index + 18*B2D_VERTEX_SIZE >= capacity)
render(); render();
float d = (w + h) * 0.5f; 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) { void Batch2D::render(unsigned int gl_primitive) {
mesh->reload(buffer, index / VERTEX_SIZE); mesh->reload(buffer, index / B2D_VERTEX_SIZE);
mesh->draw(gl_primitive); mesh->draw(gl_primitive);
index = 0; index = 0;
} }

View File

@ -6,7 +6,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include "../typedefs.h" #include "../typedefs.h"
#define VERTEX_SIZE 9 const uint B3D_VERTEX_SIZE = 9;
using glm::vec2; using glm::vec2;
using glm::vec3; using glm::vec3;
@ -19,7 +19,7 @@ Batch3D::Batch3D(size_t capacity)
{3}, {2}, {4}, {0} {3}, {2}, {4}, {0}
}; };
buffer = new float[capacity * VERTEX_SIZE]; buffer = new float[capacity * B3D_VERTEX_SIZE];
mesh = new Mesh(buffer, 0, attrs); mesh = new Mesh(buffer, 0, attrs);
index = 0; index = 0;
@ -84,7 +84,7 @@ void Batch3D::face(const vec3& coord, float w, float h,
const vec3& axisY, const vec3& axisY,
const UVRegion& region, const UVRegion& region,
const vec4& tint) { const vec4& tint) {
if (index + VERTEX_SIZE * 6 > capacity) { if (index + B3D_VERTEX_SIZE * 6 > capacity) {
flush(); flush();
} }
vertex(coord, region.u1, region.v1, 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 g = color.g;
const float b = color.b; const float b = color.b;
const float a = color.a; const float a = color.a;
if (index + 6*VERTEX_SIZE >= capacity) { if (index + 6*B3D_VERTEX_SIZE >= capacity) {
flush(); flush();
} }
@ -179,7 +179,7 @@ void Batch3D::blockCube(const vec3 size, const UVRegion(&texfaces)[6], const vec
} }
void Batch3D::flush() { void Batch3D::flush() {
mesh->reload(buffer, index / VERTEX_SIZE); mesh->reload(buffer, index / B3D_VERTEX_SIZE);
mesh->draw(); mesh->draw();
index = 0; index = 0;
} }

View File

@ -17,7 +17,7 @@ using glm::ivec3;
using glm::vec3; using glm::vec3;
using glm::vec4; using glm::vec4;
#define VERTEX_SIZE 6 const uint BlocksRenderer::VERTEX_SIZE = 6;
BlocksRenderer::BlocksRenderer(size_t capacity, BlocksRenderer::BlocksRenderer(size_t capacity,
const Content* content, const Content* content,
@ -81,7 +81,7 @@ void BlocksRenderer::face(const vec3& coord, float w, float h,
const UVRegion& region, const UVRegion& region,
const vec4(&lights)[4], const vec4(&lights)[4],
const vec4& tint) { const vec4& tint) {
if (vertexOffset + VERTEX_SIZE * 4 > capacity) { if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
overflow = true; overflow = true;
return; return;
} }
@ -116,7 +116,7 @@ void BlocksRenderer::face(const ivec3& coord,
const ivec3& axisZ, const ivec3& axisZ,
const ivec3& laxisZ, const ivec3& laxisZ,
const UVRegion& region) { const UVRegion& region) {
if (vertexOffset + VERTEX_SIZE * 4 > capacity) { if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
overflow = true; overflow = true;
return; return;
} }
@ -144,7 +144,7 @@ void BlocksRenderer::face(const ivec3& coord_,
float height, float height,
float depth, float depth,
const UVRegion& region) { const UVRegion& region) {
if (vertexOffset + VERTEX_SIZE * 4 > capacity) { if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
overflow = true; overflow = true;
return; return;
} }
@ -414,7 +414,7 @@ Mesh* BlocksRenderer::render(const Chunk* chunk, int atlas_size, const ChunksSto
render(voxels, atlas_size); render(voxels, atlas_size);
const vattr attrs[]{ {3}, {2}, {1}, {0} }; 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; return mesh;
} }

View File

@ -18,6 +18,7 @@ class ChunksStorage;
class ContentGfxCache; class ContentGfxCache;
class BlocksRenderer { class BlocksRenderer {
static const uint VERTEX_SIZE;
const Content* const content; const Content* const content;
float* vertexBuffer; float* vertexBuffer;
int* indexBuffer; int* indexBuffer;

View File

@ -29,7 +29,7 @@ bool Font::isPrintableChar(int c) {
} }
} }
#define RES 16 const int RES = 16;
int Font::calcWidth(std::wstring text) { int Font::calcWidth(std::wstring text) {
return text.length() * 8; return text.length() * 8;

View File

@ -7,9 +7,9 @@
class Texture; class Texture;
class Batch2D; class Batch2D;
#define STYLE_NONE 0 const uint STYLE_NONE = 0;
#define STYLE_SHADOW 1 const uint STYLE_SHADOW = 1;
#define STYLE_OUTLINE 2 const uint STYLE_OUTLINE = 2;
class Font { class Font {
int lineHeight_; int lineHeight_;

View File

@ -3,7 +3,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#define LB_VERTEX_SIZE (3+4) const uint LB_VERTEX_SIZE = (3+4);
LineBatch::LineBatch(size_t capacity) : capacity(capacity) { LineBatch::LineBatch(size_t capacity) : capacity(capacity) {
const vattr attrs[] = { {3},{4}, {0} }; const vattr attrs[] = { {3},{4}, {0} };

View File

@ -18,8 +18,8 @@
#include "../world/World.h" #include "../world/World.h"
#include "../maths/voxmaths.h" #include "../maths/voxmaths.h"
#define MAX_WORK_PER_FRAME 16 const uint MAX_WORK_PER_FRAME = 16;
#define MIN_SURROUNDING 9 const uint MIN_SURROUNDING = 9;
using std::unique_ptr; using std::unique_ptr;
using std::shared_ptr; using std::shared_ptr;

View File

@ -15,15 +15,15 @@
#include "../core_defs.h" #include "../core_defs.h"
#define CAM_SHAKE_OFFSET 0.025f const float CAM_SHAKE_OFFSET = 0.025f;
#define CAM_SHAKE_OFFSET_Y 0.031f const float CAM_SHAKE_OFFSET_Y = 0.031f;
#define CAM_SHAKE_SPEED 1.6f const float CAM_SHAKE_SPEED = 1.6f;
#define CAM_SHAKE_DELTA_K 10.0f const float CAM_SHAKE_DELTA_K = 10.0f;
#define ZOOM_SPEED 16.0f const float ZOOM_SPEED = 16.0f;
#define CROUCH_ZOOM 0.9f const float CROUCH_ZOOM = 0.9f;
#define RUN_ZOOM 1.1f const float RUN_ZOOM = 1.1f;
#define C_ZOOM 0.1f const float C_ZOOM = 0.1f;
#define CROUCH_SHIFT_Y -0.2f const float CROUCH_SHIFT_Y = -0.2f;
using glm::vec2; using glm::vec2;
using glm::vec3; using glm::vec3;

View File

@ -8,13 +8,13 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#define CROUCH_SPEED_MUL 0.35f const float CROUCH_SPEED_MUL = 0.35f;
#define RUN_SPEED_MUL 1.5f const float RUN_SPEED_MUL = 1.5f;
#define PLAYER_GROUND_DAMPING 10.0f const float PLAYER_GROUND_DAMPING = 10.0f;
#define PLAYER_AIR_DAMPING 7.0f const float PLAYER_AIR_DAMPING = 7.0f;
#define FLIGHT_SPEED_MUL 4.0f const float FLIGHT_SPEED_MUL = 4.0f;
#define CHEAT_SPEED_MUL 5.0f const float CHEAT_SPEED_MUL = 5.0f;
#define JUMP_FORCE 7.0f const float JUMP_FORCE = 7.0f;
Player::Player(glm::vec3 position, float speed, Camera* camera) : Player::Player(glm::vec3 position, float speed, Camera* camera) :
speed(speed), speed(speed),

View File

@ -5,7 +5,7 @@
#include "../voxels/Block.h" #include "../voxels/Block.h"
#include "../voxels/Chunks.h" #include "../voxels/Chunks.h"
#define E 0.03 const double E = 0.03;
using glm::vec3; using glm::vec3;

View File

@ -7,14 +7,14 @@
#include "../maths/aabb.h" #include "../maths/aabb.h"
#include "../typedefs.h" #include "../typedefs.h"
#define FACE_MX 0 const uint FACE_MX = 0;
#define FACE_PX 1 const uint FACE_PX = 1;
#define FACE_MY 2 const uint FACE_MY = 2;
#define FACE_PY 3 const uint FACE_PY = 3;
#define FACE_MZ 4 const uint FACE_MZ = 4;
#define FACE_PZ 5 const uint FACE_PZ = 5;
#define BLOCK_AABB_GRID 16 const uint BLOCK_AABB_GRID = 16;
struct CoordSystem { struct CoordSystem {
glm::ivec3 axisX; glm::ivec3 axisX;

View File

@ -4,11 +4,13 @@
#include <stdlib.h> #include <stdlib.h>
#include "../constants.h" #include "../constants.h"
#define CHUNK_MODIFIED 0x1 struct ChunkFlag{
#define CHUNK_READY 0x2 static const int MODIFIED = 0x1;
#define CHUNK_LOADED 0x4 static const int READY = 0x2;
#define CHUNK_LIGHTED 0x8 static const int LOADED = 0x4;
#define CHUNK_UNSAVED 0x10 static const int LIGHTED = 0x8;
static const int UNSAVED = 0x10;
};
#define CHUNK_DATA_LEN (CHUNK_VOL*2) #define CHUNK_DATA_LEN (CHUNK_VOL*2)
struct voxel; struct voxel;
@ -19,10 +21,6 @@ struct RenderData {
size_t size; 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 { class Chunk {
public: public:
int x, z; int x, z;
@ -44,25 +42,32 @@ public:
// flags getters/setters below // flags getters/setters below
inline bool isUnsaved() const {return flags & CHUNK_UNSAVED;} void SETFLAGS(int mask, bool value){
if (value)
flags |= mask;
else
flags &= ~(mask);
}
inline bool isModified() const {return flags & CHUNK_MODIFIED;} inline bool isUnsaved() const {return flags & ChunkFlag::UNSAVED;}
inline bool isLighted() const {return flags & CHUNK_LIGHTED;} inline bool isModified() const {return flags & ChunkFlag::MODIFIED;}
inline bool isLoaded() const {return flags & CHUNK_LOADED;} inline bool isLighted() const {return flags & ChunkFlag::LIGHTED;}
inline bool isReady() const {return flags & CHUNK_READY;} inline bool isLoaded() const {return flags & ChunkFlag::LOADED;}
inline void setUnsaved(bool flag) {BITSET(flags, CHUNK_UNSAVED, flag);} inline bool isReady() const {return flags & ChunkFlag::READY;}
inline void setModified(bool flag) {BITSET(flags, CHUNK_MODIFIED, flag);} inline void setUnsaved(bool newState) {SETFLAGS(ChunkFlag::UNSAVED, newState);}
inline void setLoaded(bool flag) {BITSET(flags, CHUNK_LOADED, flag);} inline void setModified(bool newState) {SETFLAGS(ChunkFlag::MODIFIED, newState);}
inline void setLighted(bool flag) {BITSET(flags, CHUNK_LIGHTED, flag);} inline void setLoaded(bool newState) {SETFLAGS(ChunkFlag::LOADED, newState);}
inline void setReady(bool flag) {BITSET(flags, CHUNK_READY, flag);} inline void setLighted(bool newState) {SETFLAGS(ChunkFlag::LIGHTED, newState);}
inline void setReady(bool newState) {SETFLAGS(ChunkFlag::READY, newState);}
ubyte* encode() const; ubyte* encode() const;
bool decode(ubyte* data); bool decode(ubyte* data);

View File

@ -16,7 +16,7 @@
#include "../maths/voxmaths.h" #include "../maths/voxmaths.h"
#include "../core_defs.h" #include "../core_defs.h"
#define SEA_LEVEL 55 const int SEA_LEVEL = 55;
class Map2D { class Map2D {
int x, z; int x, z;