replace defines where possible

This commit is contained in:
Ara
2023-12-04 21:34:51 +06:00
parent 24b3048c73
commit e0eacb51be
5 changed files with 50 additions and 50 deletions
+4 -4
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;
+18 -18
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();
} }
+1 -1
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);
+10 -10
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"
+16 -16
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_