diff --git a/ChangeLog.md b/ChangeLog.md index 6e097d24..8745b14b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,41 +2,46 @@ ## OpenRaider (0.1.4) xythobuz - [ 20140318 ] + [ 20150326 ] + * No longer including gl.h globally, now only using gl33.h where needed. + * No longer including all of glm globally, only the vec2/3/4 and mat4x4. + * No longer re-defining our own assert(), now called orAssert(). + + [ 20150318 ] * Updated imgui to version 1.36 * Can now display all compiled/linked library versions * GLFW windowing interface now supports proper text input - [ 20140313 ] + [ 20150313 ] * Renderer now limits room list size * Updated Doxyfile template to current Doxygen version * Improved documentation ## OpenRaider (0.1.3) xythobuz - [ 20140312 ] + [ 20150312 ] * Now including imguifilesystem dependency * Completely re-wrote Main menu, now reading TOMBPC.DAT scripts * Main menu is now just a full-screen ImGui window - [ 20140310 ] + [ 20150310 ] * Tried to fix moveable loading. Fixed TR1 angle parser, but still not working better. - [ 20140309 ] + [ 20150309 ] * Removed (unused) SSE support script * Added level loading notification in main menu * Can now start/stop individual SoundSources * Added SoundDetail debug UI, improved SoundSources debug UI * Updated imgui to version 1.35 - [ 20140307 ] + [ 20150307 ] * Can now load all TR3 levels without crashing * Sound Sources now working, with (more or less) proper 3D Sound * Fixed bug that caused entities to display the wrong object * Improved Debug UI * Updated imgui - [ 20140306 ] + [ 20150306 ] * Fixed LoaderTR1, can now also open the Unfinished Business levels * Walk key can now be used to increase free-camera movement speed * Removed color definitions in global.h @@ -44,53 +49,53 @@ * Hard-coded controller mapping now supports all available ActionEvents * Fixed TR3 level loading. Only some levels with invalid SoundSources still crash. - [ 20140305 ] + [ 20150305 ] * SoundAL now has more useful error message output. * Fixed TR1 color map parsing, now textures have the proper color values. * Fixed TR1 sound sample parsing. Can now load all TR1 levels without crashing. * Improved parsing and summaries in binspector level reading script. - [ 20140304 ] + [ 20150304 ] * Added (more or less working) support for loading TR1 levels * Updated imgui - [ 20140222 ] + [ 20150222 ] * Updated imgui to version 1.33 - [ 20140219 ] + [ 20150219 ] * Started implementing ability to render into textures (mainly for debugging) * Started implementing camera movement room tracking * Started implementing camera look-at target overlay UI - [ 20140213 ] + [ 20150213 ] * The menu can be navigated using a controller * Vertical camera rotation is now also clamped when using a controller * Worked on rendering SkeletalModels, not yet working correctly * Implemented level loader for TR3, but tries to access invalid textiles - [ 20140211 ] + [ 20150211 ] * Updated imgui to version 1.32 * Included some SDL game controller configurations * Camera movement speed is now clamped when moving in multiple directions * Slightly increased controller dead-zone, now 0.2 - [ 20140204 ] + [ 20150204 ] * Return of textile, animated textile and sprite viewer, in TextureManager - [ 20140203 ] + [ 20150203 ] * Updated imgui to newest version, supporting Images * Texture viewer is back, using imgui Images - [ 20140124 ] + [ 20150124 ] * Started working on Entity system. - [ 20140118 ] + [ 20150118 ] * Added ability to visualize font _outline_. * Updated imgui to newest version, now with its own TTF support. * Fixed drawing of camera view frustum. * Added support for imgui/SDLs IME text input rectangle. - [ 20140117 ] + [ 20150117 ] * Updated imgui, fix for Logging to Clipboard included. * Sprites and SpriteSequences are now stored independently in World. * Added support for Room Sprites displaying. @@ -98,7 +103,7 @@ * Room list is now displayed in reverse. This _fixes_ some transparency issues. * Fixed a bug that sometimes caused distorted Screenshots. - [ 20140111 ] + [ 20150111 ] * Enabled back face culling --> triangles now oriented correctly * Game is now completely static * Shaders drawGL methods can now be given a specific Shader instance. @@ -106,17 +111,17 @@ * Console can now log to the TTY, the clipboard or a file. * Added system clipboard support for imgui in both WindowSDL and WindowGLFW. - [ 20140109 ] + [ 20150109 ] * Display of Bounding Boxes can be individually toggled for Rooms/StaticMeshes * Tightened imgui Style and changed colors to match the _OpenRaider-blue_ - [ 20140108 ] + [ 20150108 ] * FPS and Camera position now displayed in imgui Overlay * Removed many unnecessary includes * Camera now using combination of quaternion and X/Y angle. * Fixes strange bug that sometimes rotated Camera on Z Axis. - [ 20140107 ] + [ 20150107 ] * Fixed problems with FontTTFs Glyph Baseline * No longer using wrong assert() when glm is included * Updated imgui, now Version 1.20 diff --git a/cmake/travis_script_linux.sh b/cmake/travis_script_linux.sh index 883f2c9c..4f6c4134 100755 --- a/cmake/travis_script_linux.sh +++ b/cmake/travis_script_linux.sh @@ -11,10 +11,7 @@ if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.5"; fi #curl -L https://github.com/hpicgs/glbinding/archive/${GLBVER}.tar.gz | tar xzf - #cd glbinding-${GLBVER#v} -# Hacky fix to allow building glbinding with clang on Linux -#sed -i 's/ -Werror/ /g' cmake/PlatformLinuxGCC.cmake - -# Try fix in glbinding master +# Need to use master until a fixed version is released git clone https://github.com/hpicgs/glbinding.git cd glbinding diff --git a/include/RoomData.h b/include/RoomData.h index 120b9efa..f1fde95c 100644 --- a/include/RoomData.h +++ b/include/RoomData.h @@ -35,8 +35,8 @@ class BoundingBox { } glm::vec3 getCorner(int i) { - assertGreaterThanEqual(i, 0); - assertLessThan(i, 8); + orAssertGreaterThanEqual(i, 0); + orAssertLessThan(i, 8); return corner[i]; } @@ -84,8 +84,8 @@ class Portal { glm::vec3 getNormal() { return normal; } glm::vec3 getVertex(int i) { - assertGreaterThanEqual(i, 0); - assertLessThan(i, 4); + orAssertGreaterThanEqual(i, 0); + orAssertLessThan(i, 4); return vert[i]; } diff --git a/include/global.h b/include/global.h index 06091114..f51f131a 100644 --- a/include/global.h +++ b/include/global.h @@ -66,29 +66,21 @@ typedef enum { unknownKey // Should always be at the end } KeyboardButton; -// Globally include OpenGL header -#include -#include -using namespace gl; - -/*! \fixme Is there a better way to handle this? - * We wan't to use our own assert(). Unfortunately, glm includes - * cassert in its headers. So we need to define NDEBUG here. - * To avoid a conflict, our flag is now called NODEBUG instead. - */ -#define NDEBUG -#include +#include +#include +#include +#include // If available, use our own assert that prints the call stack #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) -#ifndef NODEBUG +#ifndef NDEBUG #include #include template -[[noreturn]] void assertEqualImplementation(const char* exp, T a, U b, const char* file, int line, +[[noreturn]] void orAssertImplementation(const char* exp, T a, U b, const char* file, int line, const char* str = nullptr) { const unsigned int maxSize = 128; void* callstack[maxSize]; @@ -108,85 +100,82 @@ template abort(); } -// Evaluating x or y could have side-effects -// So we only do it once! - -#define assert(x) { \ +#define orAssert(x) { \ auto assertEvalTemp = x; \ if (!assertEvalTemp) \ - assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \ + orAssertImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \ } -#define assertEqual(x, y) { \ +#define orAssertEqual(x, y) { \ auto assertEvalTemp = x; \ auto assertEvalTemp2 = y; \ if (assertEvalTemp != assertEvalTemp2) \ - assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \ + orAssertImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \ __FILE__, __LINE__, "!="); \ } -#define assertNotEqual(x, y) { \ +#define orAssertNotEqual(x, y) { \ auto assertEvalTemp = x; \ auto assertEvalTemp2 = y; \ if (assertEvalTemp == assertEvalTemp2) \ - assertEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \ + orAssertImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \ __FILE__, __LINE__, "=="); \ } -#define assertLessThan(x, y) { \ +#define orAssertLessThan(x, y) { \ auto assertEvalTemp = x; \ auto assertEvalTemp2 = y; \ if (assertEvalTemp >= assertEvalTemp2) \ - assertEqualImplementation(#x " < " #y, assertEvalTemp, assertEvalTemp2, \ + orAssertImplementation(#x " < " #y, assertEvalTemp, assertEvalTemp2, \ __FILE__, __LINE__, ">="); \ } -#define assertLessThanEqual(x, y) { \ +#define orAssertLessThanEqual(x, y) { \ auto assertEvalTemp = x; \ auto assertEvalTemp2 = y; \ if (assertEvalTemp > assertEvalTemp2) \ - assertEqualImplementation(#x " <= " #y, assertEvalTemp, assertEvalTemp2, \ + orAssertImplementation(#x " <= " #y, assertEvalTemp, assertEvalTemp2, \ __FILE__, __LINE__, ">"); \ } -#define assertGreaterThan(x, y) { \ +#define orAssertGreaterThan(x, y) { \ auto assertEvalTemp = x; \ auto assertEvalTemp2 = y; \ if (assertEvalTemp <= assertEvalTemp2) \ - assertEqualImplementation(#x " > " #y, assertEvalTemp, assertEvalTemp2, \ + orAssertImplementation(#x " > " #y, assertEvalTemp, assertEvalTemp2, \ __FILE__, __LINE__, "<="); \ } -#define assertGreaterThanEqual(x, y) { \ +#define orAssertGreaterThanEqual(x, y) { \ auto assertEvalTemp = x; \ auto assertEvalTemp2 = y; \ if (assertEvalTemp < assertEvalTemp2) \ - assertEqualImplementation(#x " >= " #y, assertEvalTemp, assertEvalTemp2, \ + orAssertImplementation(#x " >= " #y, assertEvalTemp, assertEvalTemp2, \ __FILE__, __LINE__, "<"); \ } -#else // NODEBUG +#else // NDEBUG -#define assert(x) -#define assertEqual(x, y) -#define assertNotEqual(x, y) -#define assertLessThan(x, y) -#define assertLessThanEqual(x, y) -#define assertGreaterThan(x, y) -#define assertGreaterThanEqual(x, y) +#define orAssert(x) +#define orAssertEqual(x, y) +#define orAssertNotEqual(x, y) +#define orAssertLessThan(x, y) +#define orAssertLessThanEqual(x, y) +#define orAssertGreaterThan(x, y) +#define orAssertGreaterThanEqual(x, y) -#endif // NODEBUG +#endif // NDEBUG #else // EXECINFO // Fall back to the default C assert #include -#define assertEqual(x, y) assert((x) == (y)) -#define assertNotEqual(x, y) assert((x) != (y)) -#define assertLessThan(x, y) assert((x) < (y)) -#define assertLessThanEqual(x, y) assert((x) <= (y)) -#define assertGreaterThan(x, y) assert((x) > (y)) -#define assertGreaterThanEqual(x, y) assert((x) >= (y)) +#define orAssertEqual(x, y) assert((x) == (y)) +#define orAssertNotEqual(x, y) assert((x) != (y)) +#define orAssertLessThan(x, y) assert((x) < (y)) +#define orAssertLessThanEqual(x, y) assert((x) <= (y)) +#define orAssertGreaterThan(x, y) assert((x) > (y)) +#define orAssertGreaterThanEqual(x, y) assert((x) >= (y)) #endif // EXECINFO diff --git a/include/loader/Loader.h b/include/loader/Loader.h index 1ee9aed7..889c994c 100644 --- a/include/loader/Loader.h +++ b/include/loader/Loader.h @@ -28,6 +28,7 @@ class Loader { static LoaderVersion checkFile(std::string f); static std::unique_ptr createLoader(std::string f); + virtual ~Loader(); virtual int load(std::string f) = 0; protected: diff --git a/include/system/Shader.h b/include/system/Shader.h index b3870800..cbc22f4c 100644 --- a/include/system/Shader.h +++ b/include/system/Shader.h @@ -13,6 +13,8 @@ #include "TextureManager.h" +#include + class ShaderBuffer { public: ShaderBuffer() : created(false), buffer(0), boundSize(0) { } @@ -28,7 +30,7 @@ class ShaderBuffer { void bindBuffer(int location, int size); void unbind(int location); - unsigned int getBuffer() { assert(created); return buffer; } + unsigned int getBuffer() { orAssert(created); return buffer; } int getSize() { return boundSize; } private: @@ -74,7 +76,7 @@ class Shader { static void set2DState(bool on, bool depth = true); static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture, - TextureStorage store = TextureStorage::SYSTEM, GLenum = GL_TRIANGLES, + TextureStorage store = TextureStorage::SYSTEM, gl::GLenum = gl::GL_TRIANGLES, ShaderTexture* target = nullptr, Shader& shader = textShader); static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP, @@ -86,10 +88,10 @@ class Shader { Shader& shader = textureShader); static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP, - GLenum mode = GL_TRIANGLES, ShaderTexture* target = nullptr, + gl::GLenum mode = gl::GL_TRIANGLES, ShaderTexture* target = nullptr, Shader& shader = colorShader); static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices, - glm::mat4 MVP, GLenum mode = GL_TRIANGLES, ShaderTexture* target = nullptr, + glm::mat4 MVP, gl::GLenum mode = gl::GL_TRIANGLES, ShaderTexture* target = nullptr, Shader& shader = colorShader); static std::string getVersion(bool linked); diff --git a/include/system/SoundAL.h b/include/system/SoundAL.h index ef33bd89..7be8c50a 100644 --- a/include/system/SoundAL.h +++ b/include/system/SoundAL.h @@ -21,7 +21,7 @@ class SoundAL { static int loadBuffer(unsigned char* buffer, unsigned int length); static int numSources(bool atListener); - static int addSource(int buffer, float volume, bool atListener, bool loop); + static int addSource(int buffer, float vol, bool atListener, bool loop); static int sourceAt(int source, glm::vec3 pos); static void listenAt(glm::vec3 pos, glm::vec3 at, glm::vec3 up); diff --git a/include/system/WindowGLFW.h b/include/system/WindowGLFW.h index 488fcf7b..aea9e32a 100644 --- a/include/system/WindowGLFW.h +++ b/include/system/WindowGLFW.h @@ -11,7 +11,7 @@ #include #include -class GLFWwindow; +struct GLFWwindow; class WindowGLFW { public: diff --git a/src/Camera.cpp b/src/Camera.cpp index 2966cbf0..117f0718 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -17,6 +17,7 @@ #include "system/Window.h" #include "Camera.h" +#include #include #include #include @@ -396,7 +397,7 @@ bool Camera::boxInFrustum(BoundingBox b) { void Camera::displayFrustum(glm::mat4 MVP) { Shader::set2DState(true, false); Shader::drawGL(vertexBuffer, colorBuffer, indexBuffer, MVP); - Shader::drawGL(vertexPointBuffer, colorPointBuffer, MVP, GL_POINTS); + Shader::drawGL(vertexPointBuffer, colorPointBuffer, MVP, gl::GL_POINTS); Shader::set2DState(false, false); } diff --git a/src/Console.cpp b/src/Console.cpp index 5308e796..00e95970 100644 --- a/src/Console.cpp +++ b/src/Console.cpp @@ -110,7 +110,7 @@ void Console::display() { for (unsigned long i = 0; i < Log::size(); i++) { auto& entry = Log::getEntry(i); - assertLessThan(entry.level, LOG_COUNT); + orAssertLessThan(entry.level, LOG_COUNT); if (!visibleLogs[entry.level]) { continue; } diff --git a/src/Entity.cpp b/src/Entity.cpp index d0ec8c39..49b95f57 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -57,8 +57,8 @@ void Entity::display(glm::mat4 VP) { } } - assertGreaterThan(cache, -1); - assertGreaterThan(cacheType, -1); + orAssertGreaterThan(cache, -1); + orAssertGreaterThan(cacheType, -1); } glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z)); @@ -80,8 +80,6 @@ void Entity::display(glm::mat4 VP) { } else if (cacheType == CACHE_MODEL) { if (showEntityModels) getWorld().getSkeletalModel(cache).display(MVP, animation, frame); - } else { - assert(false && "This should not happen..."); } } diff --git a/src/Game.cpp b/src/Game.cpp index 6e583a5a..ba80969d 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -82,7 +82,7 @@ int Game::loadLevel(std::string level) { } void Game::handleAction(ActionEvents action, bool isFinished) { - assertLessThan(action, ActionEventCount); + orAssertLessThan(action, ActionEventCount); if (!mLoaded) return; @@ -113,14 +113,14 @@ void Game::handleControllerAxis(float value, KeyboardButton axis) { } Entity& Game::getLara() { - assertGreaterThanEqual(mLara, 0); - assertLessThan(mLara, getWorld().sizeEntity()); + orAssertGreaterThanEqual(mLara, 0); + orAssertLessThan(mLara, getWorld().sizeEntity()); return getWorld().getEntity(mLara); } void Game::setLara(long lara) { - assertGreaterThanEqual(lara, 0); - assertLessThan(lara, getWorld().sizeEntity()); + orAssertGreaterThanEqual(lara, 0); + orAssertLessThan(lara, getWorld().sizeEntity()); mLara = lara; } diff --git a/src/Log.cpp b/src/Log.cpp index b20655e4..4fc83ee6 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -17,8 +17,8 @@ void Log::initialize() { } LogLevel& Log::get(int level) { - assertGreaterThanEqual(level, 0); - assertLessThan(level, LOG_COUNT); + orAssertGreaterThanEqual(level, 0); + orAssertLessThan(level, LOG_COUNT); return logs.at(level); } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 6da23b46..87e59415 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -9,6 +9,8 @@ #include "TextureManager.h" #include "Mesh.h" +#include + Mesh::Mesh(const std::vector& vert, const std::vector& rect, const std::vector& tri, @@ -78,9 +80,9 @@ void Mesh::prepare() { vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3; } - assertEqual(ind.size() % 3, 0); - assertEqual(vert.size(), tex.size()); - assertEqual(vert.size(), uvBuff.size()); + orAssertEqual(ind.size() % 3, 0); + orAssertEqual(vert.size(), tex.size()); + orAssertEqual(vert.size(), uvBuff.size()); indicesBuff = std::move(ind); vertices.bufferData(vert); @@ -113,8 +115,8 @@ void Mesh::prepare() { vertIndex += (indicesColorBuff.at(i) == 0) ? 4 : 3; } - assertEqual(indCol.size() % 3, 0); - assertEqual(vertCol.size(), cols.size()); + orAssertEqual(indCol.size() % 3, 0); + orAssertEqual(vertCol.size(), cols.size()); indicesColor.bufferData(indCol); verticesColor.bufferData(vertCol); @@ -152,6 +154,6 @@ void Mesh::display(glm::mat4 MVP, ShaderTexture* shaderTexture) { } if (indicesColor.getSize() > 0) - Shader::drawGL(verticesColor, colors, indicesColor, MVP, GL_TRIANGLES, shaderTexture); + Shader::drawGL(verticesColor, colors, indicesColor, MVP, gl::GL_TRIANGLES, shaderTexture); } diff --git a/src/Render.cpp b/src/Render.cpp index e612f125..5a7c6dbf 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -21,6 +21,7 @@ #include "Render.h" #include +#include #include "imgui/imgui.h" #include "stb/stb_image_write.h" @@ -30,7 +31,7 @@ std::vector Render::roomList; bool Render::displayViewFrustum = false; void Render::display() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT); if (mode == RenderMode::LoadScreen) { glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); @@ -40,9 +41,9 @@ void Render::display() { } if (mode == RenderMode::Wireframe) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_LINE); } else { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_FILL); } if (Camera::update()) { @@ -74,7 +75,7 @@ void Render::display() { Camera::displayFrustum(VP); if (mode == RenderMode::Wireframe) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_FILL); } } @@ -119,13 +120,13 @@ void Render::buildRoomList(int room, int budget) { } void Render::screenShot(const char* filenameBase) { - assert(filenameBase != nullptr); + orAssert(filenameBase != nullptr); int w = Window::getSize().x; int h = Window::getSize().y; int sz = w * h; unsigned char* image = new unsigned char[sz * 3]; - glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, image); + gl::glReadPixels(0, 0, w, h, gl::GL_RGB, gl::GL_UNSIGNED_BYTE, image); unsigned char* buffer = new unsigned char[sz * 3]; for (int x = 0; x < w; x++) { diff --git a/src/Room.cpp b/src/Room.cpp index 27da737e..31bd5dd7 100644 --- a/src/Room.cpp +++ b/src/Room.cpp @@ -46,15 +46,15 @@ void Room::display(glm::mat4 VP) { } bool Room::isWall(unsigned long sector) { - assertLessThan(sector, sectors.size()); + orAssertLessThan(sector, sectors.size()); //! \fixme is (sector > 0) correct?? return ((sector > 0) && sectors.at(sector)->isWall()); } long Room::getSector(float x, float z, float* floor, float* ceiling) { - assert(floor != nullptr); - assert(ceiling != nullptr); + orAssert(floor != nullptr); + orAssert(ceiling != nullptr); long sector = getSector(x, z); diff --git a/src/RoomData.cpp b/src/RoomData.cpp index fcffbae7..e09860a3 100644 --- a/src/RoomData.cpp +++ b/src/RoomData.cpp @@ -11,6 +11,7 @@ #include "system/Shader.h" #include "RoomData.h" +#include #include void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot) { @@ -44,7 +45,7 @@ void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot) vert.bufferData(verts); col.bufferData(cols); ind.bufferData(inds); - Shader::drawGL(vert, col, ind, VP, GL_LINE_STRIP); + Shader::drawGL(vert, col, ind, VP, gl::GL_LINE_STRIP); cols.clear(); inds.clear(); @@ -58,7 +59,7 @@ void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot) vert2.bufferData(verts); col2.bufferData(cols); ind2.bufferData(inds); - Shader::drawGL(vert2, col2, ind2, VP, GL_POINTS); + Shader::drawGL(vert2, col2, ind2, VP, gl::GL_POINTS); } // ---------------------------------------------------------------------------- @@ -76,7 +77,7 @@ void StaticModel::display(glm::mat4 VP) { cache = i; } } - assertGreaterThanEqual(cache, 0); + orAssertGreaterThanEqual(cache, 0); } getWorld().getStaticMesh(cache).display(VP * model); diff --git a/src/RoomMesh.cpp b/src/RoomMesh.cpp index 123c0171..3ea3404d 100644 --- a/src/RoomMesh.cpp +++ b/src/RoomMesh.cpp @@ -59,9 +59,9 @@ void RoomMesh::prepare() { vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3; } - assertEqual(ind.size() % 3, 0); - assertEqual(vert.size(), tex.size()); - assertEqual(vert.size(), uvBuff.size()); + orAssertEqual(ind.size() % 3, 0); + orAssertEqual(vert.size(), tex.size()); + orAssertEqual(vert.size(), uvBuff.size()); indicesBuff = std::move(ind); vertices.bufferData(vert); diff --git a/src/RunTime.cpp b/src/RunTime.cpp index e7224ac1..ebb6cf90 100644 --- a/src/RunTime.cpp +++ b/src/RunTime.cpp @@ -54,12 +54,12 @@ void RunTime::initialize() { } KeyboardButton RunTime::getKeyBinding(ActionEvents event) { - assertLessThan(event, ActionEventCount); + orAssertLessThan(event, ActionEventCount); return keyBindings[event]; } void RunTime::setKeyBinding(ActionEvents event, KeyboardButton button) { - assertLessThan(event, ActionEventCount); + orAssertLessThan(event, ActionEventCount); keyBindings[event] = button; } diff --git a/src/Script.cpp b/src/Script.cpp index 276b5664..28ef5b94 100644 --- a/src/Script.cpp +++ b/src/Script.cpp @@ -54,7 +54,7 @@ int Script::load(std::string file) { description = desc; uint16_t gameflowSize = f.readU16(); - assertEqual(gameflowSize, 128); + orAssertEqual(gameflowSize, 128); firstOption = f.readU32(); titleReplace = f.read32(); @@ -150,11 +150,11 @@ void Script::readScriptPackage(BinaryFile& f, std::vector> uint16_t* offset = new uint16_t[n]; for (unsigned int i = 0; i < n; i++) { offset[i] = f.readU16(); - assertEqual(offset[i] % 2, 0); + orAssertEqual(offset[i] % 2, 0); } uint16_t numBytes = f.readU16(); - assertEqual(numBytes % 2, 0); // 16 bit opcodes and operands + orAssertEqual(numBytes % 2, 0); // 16 bit opcodes and operands uint16_t* list = new uint16_t[(numBytes + 6) / 2]; for (uint16_t i = 0; i < (numBytes / 2); i++) { @@ -231,12 +231,12 @@ unsigned int Script::levelCount() { } std::string Script::getLevelName(unsigned int i) { - assertLessThan(i, numLevels); + orAssertLessThan(i, numLevels); return levelNames.at(i); } std::string Script::getLevelFilename(unsigned int i) { - assertLessThan(i, numLevels); + orAssertLessThan(i, numLevels); return levelFilenames.at(i); } @@ -245,7 +245,7 @@ unsigned int Script::pictureCount() { } std::string Script::getPictureFilename(unsigned int i) { - assertLessThan(i, numPictures); + orAssertLessThan(i, numPictures); return pictureFilenames.at(i); } @@ -254,7 +254,7 @@ unsigned int Script::cutsceneCount() { } std::string Script::getCutsceneFilename(unsigned int i) { - assertLessThan(i, numCutscenes); + orAssertLessThan(i, numCutscenes); return cutsceneFilenames.at(i); } @@ -263,7 +263,7 @@ unsigned int Script::titleCount() { } std::string Script::getTitleFilename(unsigned int i) { - assertLessThan(i, numTitles); + orAssertLessThan(i, numTitles); return titleFilenames.at(i); } @@ -272,7 +272,7 @@ unsigned int Script::videoCount() { } std::string Script::getVideoFilename(unsigned int i) { - assertLessThan(i, numFMVs); + orAssertLessThan(i, numFMVs); return fmvFilenames.at(i); } @@ -281,7 +281,7 @@ unsigned int Script::gameStringCount() { } std::string Script::getGameString(unsigned int i) { - assertLessThan(i, numGameStrings); + orAssertLessThan(i, numGameStrings); return gameStrings.at(i); } @@ -290,35 +290,35 @@ unsigned int Script::pcStringCount() { } std::string Script::getPCString(unsigned int i) { - assertLessThan(i, numPCStrings); + orAssertLessThan(i, numPCStrings); return pcStrings.at(i); } std::string Script::getPuzzleString(unsigned int i, unsigned int j) { - assertLessThan(i, 4); - assertLessThan(j, numLevels); + orAssertLessThan(i, 4); + orAssertLessThan(j, numLevels); return puzzles.at(i).at(j); } std::string Script::getPickupString(unsigned int i, unsigned int j) { - assertLessThan(i, 2); - assertLessThan(j, numLevels); + orAssertLessThan(i, 2); + orAssertLessThan(j, numLevels); return pickups.at(i).at(j); } std::string Script::getKeyString(unsigned int i, unsigned int j) { - assertLessThan(i, 4); - assertLessThan(j, numLevels); + orAssertLessThan(i, 4); + orAssertLessThan(j, numLevels); return keys.at(i).at(j); } void Script::registerScriptHandler(ScriptOpCode op, std::function func) { - assertLessThan(op, OP_UNKNOWN); + orAssertLessThan(op, OP_UNKNOWN); scriptHandlers[op] = func; } int Script::runScript(unsigned int level) { - assertLessThan(level, (numLevels + 1)); + orAssertLessThan(level, (numLevels + 1)); std::vector s = script.at(level); for (unsigned int i = 0; i < s.size(); i++) { diff --git a/src/SkeletalModel.cpp b/src/SkeletalModel.cpp index 88c3fe9f..2a2fa71e 100644 --- a/src/SkeletalModel.cpp +++ b/src/SkeletalModel.cpp @@ -29,7 +29,7 @@ unsigned long BoneFrame::size() { } BoneTag& BoneFrame::get(unsigned long i) { - assertLessThan(i, tag.size()); + orAssertLessThan(i, tag.size()); return *tag.at(i); } @@ -49,7 +49,7 @@ unsigned long AnimationFrame::size() { } BoneFrame& AnimationFrame::get(unsigned long i) { - assertLessThan(i, frame.size()); + orAssertLessThan(i, frame.size()); return *frame.at(i); } @@ -64,19 +64,19 @@ class MatrixStack { MatrixStack(glm::mat4 start) : startVal(start) { stack.push_back(startVal); } void push() { - //assertGreaterThan(stack.size(), 0); + //orAssertGreaterThan(stack.size(), 0); if (stack.size() > 0) stack.push_back(stack.at(stack.size() - 1)); } void pop() { - //assertGreaterThan(stack.size(), 0); + //orAssertGreaterThan(stack.size(), 0); if (stack.size() > 0) stack.pop_back(); } glm::mat4 get() { - //assertGreaterThan(stack.size(), 0); + //orAssertGreaterThan(stack.size(), 0); if (stack.size() > 0) return stack.at(stack.size() - 1); return startVal; @@ -101,8 +101,8 @@ SkeletalModel::~SkeletalModel() { #endif void SkeletalModel::display(glm::mat4 MVP, int aframe, int bframe, ShaderTexture* shaderTexture) { - assertLessThan(aframe, size()); - assertLessThan(bframe, get(aframe).size()); + orAssertLessThan(aframe, size()); + orAssertLessThan(bframe, get(aframe).size()); AnimationFrame& anim = get(aframe); BoneFrame& boneframe = anim.get(bframe); @@ -173,7 +173,7 @@ unsigned long SkeletalModel::size() { } AnimationFrame& SkeletalModel::get(unsigned long i) { - assertLessThan(i, animation.size()); + orAssertLessThan(i, animation.size()); return *animation.at(i); } diff --git a/src/Sprite.cpp b/src/Sprite.cpp index bbcc8f40..67166d04 100644 --- a/src/Sprite.cpp +++ b/src/Sprite.cpp @@ -52,8 +52,8 @@ void Sprite::display(glm::mat4 MVP) { // ---------------------------------------------------------------------------- void SpriteSequence::display(glm::mat4 MVP, int index) { - assertGreaterThanEqual(index, 0); - assertLessThan(index, length); + orAssertGreaterThanEqual(index, 0); + orAssertLessThan(index, length); getWorld().getSprite(start + index).display(MVP); } diff --git a/src/TextureManager.cpp b/src/TextureManager.cpp index 0a907897..4a6a8054 100644 --- a/src/TextureManager.cpp +++ b/src/TextureManager.cpp @@ -21,6 +21,8 @@ #include "utils/strings.h" #include "TextureManager.h" +#include + glm::vec2 TextureTile::getUV(unsigned int i) { glm::vec2 uv(vertices.at(i).xPixel, vertices.at(i).yPixel); @@ -60,12 +62,12 @@ std::array TextureManager::colorPalette; std::vector> TextureManager::indexedTextures; int TextureManager::initialize() { - assertEqual(mTextureIdsGame.size(), 0); - assertEqual(mTextureIdsSystem.size(), 0); + orAssertEqual(mTextureIdsGame.size(), 0); + orAssertEqual(mTextureIdsSystem.size(), 0); while (mTextureIdsSystem.size() < 2) { unsigned int id; - glGenTextures(1, &id); + gl::glGenTextures(1, &id); mTextureIdsSystem.push_back(id); } @@ -107,7 +109,7 @@ int TextureManager::initializeSplash() { void TextureManager::shutdown() { while (mTextureIdsSystem.size() > 0) { unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1); - glDeleteTextures(1, &id); + gl::glDeleteTextures(1, &id); mTextureIdsSystem.pop_back(); } @@ -120,7 +122,7 @@ void TextureManager::shutdown() { void TextureManager::clear() { while (mTextureIdsGame.size() > 0) { unsigned int id = mTextureIdsGame.at(mTextureIdsGame.size() - 1); - glDeleteTextures(1, &id); + gl::glDeleteTextures(1, &id); mTextureIdsGame.pop_back(); } @@ -142,63 +144,63 @@ int TextureManager::loadBufferSlot(unsigned char* image, unsigned int width, unsigned int height, ColorMode mode, unsigned int bpp, TextureStorage s, int slot, bool filter) { - assertGreaterThan(width, 0); - assertGreaterThan(height, 0); - assert((mode == ColorMode::RGB) + orAssertGreaterThan(width, 0); + orAssertGreaterThan(height, 0); + orAssert((mode == ColorMode::RGB) || (mode == ColorMode::BGR) || (mode == ColorMode::ARGB) || (mode == ColorMode::RGBA) || (mode == ColorMode::BGRA)); - assert((bpp == 8) || (bpp == 24) || (bpp == 32)); + orAssert((bpp == 8) || (bpp == 24) || (bpp == 32)); if (slot < 0) slot = getIds(s).size(); while (getIds(s).size() <= slot) { unsigned int id; - glGenTextures(1, &id); + gl::glGenTextures(1, &id); getIds(s).push_back(id); } - GLenum glcMode; + gl::GLenum glcMode; switch (mode) { case ColorMode::BGR: - glcMode = GL_BGR; + glcMode = gl::GL_BGR; break; case ColorMode::RGB: - glcMode = GL_RGB; + glcMode = gl::GL_RGB; break; case ColorMode::ARGB: if (image != nullptr) argb2rgba32(image, width, height); - glcMode = GL_RGBA; + glcMode = gl::GL_RGBA; break; case ColorMode::BGRA: - glcMode = GL_BGRA; + glcMode = gl::GL_BGRA; break; case ColorMode::RGBA: - glcMode = GL_RGBA; + glcMode = gl::GL_RGBA; break; } - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gl::glPixelStorei(gl::GL_UNPACK_ALIGNMENT, 1); bindTexture(slot, s); - glTexImage2D(GL_TEXTURE_2D, 0, GLint(GL_RGBA), width, height, 0, glcMode, GL_UNSIGNED_BYTE, image); + gl::glTexImage2D(gl::GL_TEXTURE_2D, 0, gl::GLint(gl::GL_RGBA), width, height, 0, glcMode, gl::GL_UNSIGNED_BYTE, image); if (filter) { // Trilinear filtering - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GLint(GL_REPEAT)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GLint(GL_REPEAT)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GLint(GL_LINEAR)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GLint(GL_LINEAR_MIPMAP_LINEAR)); - glGenerateMipmap(GL_TEXTURE_2D); + gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_WRAP_S, gl::GLint(gl::GL_REPEAT)); + gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_WRAP_T, gl::GLint(gl::GL_REPEAT)); + gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MAG_FILTER, gl::GLint(gl::GL_LINEAR)); + gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MIN_FILTER, gl::GLint(gl::GL_LINEAR_MIPMAP_LINEAR)); + gl::glGenerateMipmap(gl::GL_TEXTURE_2D); } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GLint(GL_NEAREST)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GLint(GL_NEAREST)); + gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MIN_FILTER, gl::GLint(gl::GL_NEAREST)); + gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MAG_FILTER, gl::GLint(gl::GL_NEAREST)); } return slot; @@ -209,15 +211,15 @@ int TextureManager::numTextures(TextureStorage s) { } void TextureManager::bindTextureId(unsigned int n, TextureStorage s, unsigned int unit) { - assertLessThan(n, getIds(s).size()); - assertLessThan(unit, 80); //! \fixme Query GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS + orAssertLessThan(n, getIds(s).size()); + orAssertLessThan(unit, 80); //! \fixme Query GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS - glActiveTexture(GL_TEXTURE0 + unit); - glBindTexture(GL_TEXTURE_2D, getIds(s).at(n)); + gl::glActiveTexture(gl::GL_TEXTURE0 + unit); + gl::glBindTexture(gl::GL_TEXTURE_2D, getIds(s).at(n)); } int TextureManager::bindTexture(unsigned int n, TextureStorage s) { - assertLessThan(n, getIds(s).size()); + orAssertLessThan(n, getIds(s).size()); if ((n < getUnits(s).size()) && (getUnits(s).at(n) >= 0)) { bindTextureId(n, s, getUnits(s).at(n)); @@ -233,7 +235,7 @@ int TextureManager::bindTexture(unsigned int n, TextureStorage s) { } unsigned int TextureManager::getTextureID(int n, TextureStorage s) { - assertLessThan(n, getIds(s).size()); + orAssertLessThan(n, getIds(s).size()); return getIds(s).at(n); } @@ -246,8 +248,8 @@ int TextureManager::numTiles() { } TextureTile& TextureManager::getTile(int index) { - assertGreaterThanEqual(index, 0); - assertLessThan(index, tiles.size()); + orAssertGreaterThanEqual(index, 0); + orAssertLessThan(index, tiles.size()); return *tiles.at(index); } @@ -263,13 +265,13 @@ int TextureManager::numAnimatedTiles() { } int TextureManager::getFirstTileAnimation(int index) { - assertLessThan(index, animations.size()); - assertGreaterThan(animations.at(index).size(), 0); + orAssertLessThan(index, animations.size()); + orAssertGreaterThan(animations.at(index).size(), 0); return animations.at(index).at(0); } int TextureManager::getNextTileAnimation(int index, int tile) { - assertLessThan(index, animations.size()); + orAssertLessThan(index, animations.size()); for (int i = 0; i < animations.at(index).size(); i++) { if (animations.at(index).at(i) == tile) { if (i < (animations.at(index).size() - 1)) @@ -290,14 +292,14 @@ BufferManager* TextureManager::getBufferManager(int tex, TextureStorage store) { } void TextureManager::setPalette(int index, glm::vec4 color) { - assertGreaterThanEqual(index, 0); - assertLessThan(index, COLOR_PALETTE_SIZE); + orAssertGreaterThanEqual(index, 0); + orAssertLessThan(index, COLOR_PALETTE_SIZE); colorPalette[index] = color; } glm::vec4 TextureManager::getPalette(int index) { - assertGreaterThanEqual(index, 0); - assertLessThan(index, COLOR_PALETTE_SIZE); + orAssertGreaterThanEqual(index, 0); + orAssertLessThan(index, COLOR_PALETTE_SIZE); return colorPalette[index]; } diff --git a/src/UI.cpp b/src/UI.cpp index 203ba0e7..d5e96629 100644 --- a/src/UI.cpp +++ b/src/UI.cpp @@ -23,6 +23,7 @@ #include "utils/time.h" #include "UI.h" +#include #include Shader UI::imguiShader; @@ -480,7 +481,7 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) { static ShaderBuffer vert, uv, col; - glEnable(GL_SCISSOR_TEST); + gl::glEnable(gl::GL_SCISSOR_TEST); Shader::set2DState(true); imguiShader.use(); @@ -523,15 +524,15 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) { col.bufferData(colors); auto bm = static_cast(commands[n].texture_id); - assert(bm != nullptr); + orAssert(bm != nullptr); imguiShader.loadUniform(1, bm->getTextureID(), bm->getTextureStorage()); - glScissor(commands[n].clip_rect.x, + gl::glScissor(commands[n].clip_rect.x, Window::getSize().y - commands[n].clip_rect.w, commands[n].clip_rect.z - commands[n].clip_rect.x, commands[n].clip_rect.w - commands[n].clip_rect.y); - glDrawArrays(GL_TRIANGLES, 0, vertices.size()); + gl::glDrawArrays(gl::GL_TRIANGLES, 0, vertices.size()); } } @@ -540,7 +541,7 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) { col.unbind(2); Shader::set2DState(false); - glDisable(GL_SCISSOR_TEST); + gl::glDisable(gl::GL_SCISSOR_TEST); } // -------------------------------------- diff --git a/src/World.cpp b/src/World.cpp index 0c47d9a4..7663710c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -31,7 +31,7 @@ unsigned long World::sizeRoom() { } Room& World::getRoom(unsigned long index) { - assertLessThan(index, mRooms.size()); + orAssertLessThan(index, mRooms.size()); return *mRooms.at(index); } @@ -44,7 +44,7 @@ unsigned long World::sizeSprite() { } Sprite& World::getSprite(unsigned long index) { - assertLessThan(index, mSprites.size()); + orAssertLessThan(index, mSprites.size()); return *mSprites.at(index); } @@ -57,7 +57,7 @@ unsigned long World::sizeSpriteSequence() { } SpriteSequence& World::getSpriteSequence(unsigned long index) { - assertLessThan(index, mSpriteSequences.size()); + orAssertLessThan(index, mSpriteSequences.size()); return *mSpriteSequences.at(index); } @@ -70,7 +70,7 @@ unsigned long World::sizeEntity() { } Entity& World::getEntity(unsigned long index) { - assertLessThan(index, mEntities.size()); + orAssertLessThan(index, mEntities.size()); return *mEntities.at(index); } @@ -83,7 +83,7 @@ unsigned long World::sizeSkeletalModel() { } SkeletalModel& World::getSkeletalModel(unsigned long index) { - assertLessThan(index, mModels.size()); + orAssertLessThan(index, mModels.size()); return *mModels.at(index); } @@ -96,7 +96,7 @@ unsigned long World::sizeStaticMesh() { } StaticMesh& World::getStaticMesh(unsigned long index) { - assertLessThan(index, mStaticMeshes.size()); + orAssertLessThan(index, mStaticMeshes.size()); return *mStaticMeshes.at(index); } @@ -109,7 +109,7 @@ unsigned long World::sizeMesh() { } Mesh& World::getMesh(unsigned long index) { - assertLessThan(index, mMeshes.size()); + orAssertLessThan(index, mMeshes.size()); return *mMeshes.at(index); } diff --git a/src/deps/imgui/imconfig.h b/src/deps/imgui/imconfig.h index fba20e28..96ff366a 100644 --- a/src/deps/imgui/imconfig.h +++ b/src/deps/imgui/imconfig.h @@ -13,7 +13,7 @@ //---- Define assertion handler. Defaults to calling assert(). #include "global.h" -#define IM_ASSERT(_EXPR) assert(_EXPR) +#define IM_ASSERT(_EXPR) orAssert(_EXPR) //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows. //#define IMGUI_API __declspec( dllexport ) diff --git a/src/deps/stb/stb.cpp b/src/deps/stb/stb.cpp index 810d169a..97d540ac 100644 --- a/src/deps/stb/stb.cpp +++ b/src/deps/stb/stb.cpp @@ -8,7 +8,7 @@ #include "global.h" #define STB_IMAGE_IMPLEMENTATION -#define STBI_ASSERT(x) assert(x) +#define STBI_ASSERT(x) orAssert(x) #define STBI_NO_SIMD #include "stb/stb_image.h" @@ -16,10 +16,10 @@ #include "stb/stb_image_write.h" #define STB_RECT_PACK_IMPLEMENTATION -#define STBRP_ASSERT assert +#define STBRP_ASSERT orAssert #include "stb/stb_rect_pack.h" #define STB_TRUETYPE_IMPLEMENTATION -#define STBTT_assert(x) assert(x) +#define STBTT_assert(x) orAssert(x) #include "stb/stb_truetype.h" diff --git a/src/loader/Loader.cpp b/src/loader/Loader.cpp index 6f5811b7..38ffe7ac 100644 --- a/src/loader/Loader.cpp +++ b/src/loader/Loader.cpp @@ -55,3 +55,5 @@ std::unique_ptr Loader::createLoader(std::string f) { } } +Loader::~Loader() { } + diff --git a/src/loader/LoaderTR1.cpp b/src/loader/LoaderTR1.cpp index 027b7254..66b1dcf7 100644 --- a/src/loader/LoaderTR1.cpp +++ b/src/loader/LoaderTR1.cpp @@ -266,11 +266,11 @@ void LoaderTR1::loadSoundSamples() { for (unsigned int i = 0; i < numSampleIndices; i++) { SoundManager::addSampleIndex(i); uint32_t sampleOffset = file.readU32(); - assertLessThan(sampleOffset, soundSampleSize); + orAssertLessThan(sampleOffset, soundSampleSize); char* tmpPtr = reinterpret_cast(&buffer[sampleOffset]); BinaryMemory sample(tmpPtr, soundSampleSize - sampleOffset); int ret = loadSoundFiles(sample, 1); - assertEqual(ret, 1); + orAssertEqual(ret, 1); } if (numSampleIndices > 0) diff --git a/src/loader/LoaderTR2.cpp b/src/loader/LoaderTR2.cpp index bd77c774..114088d4 100644 --- a/src/loader/LoaderTR2.cpp +++ b/src/loader/LoaderTR2.cpp @@ -95,7 +95,7 @@ void LoaderTR2::loadTextures() { int r = TextureManager::loadBufferSlot(img, 256, 256, ColorMode::ARGB, 32, TextureStorage::GAME, i); - assertGreaterThanEqual(r, 0); //! \fixme properly handle error when texture could not be loaded! + orAssertGreaterThanEqual(r, 0); //! \fixme properly handle error when texture could not be loaded! delete [] img; } @@ -137,8 +137,8 @@ void LoaderTR2::loadTextiles() { uint8_t yCoordinate = file.readU8(); uint8_t yPixel = file.readU8(); - assert((xCoordinate == 1) || (xCoordinate == 255) || (xCoordinate == 0)); - assert((yCoordinate == 1) || (yCoordinate == 255) || (yCoordinate == 0)); + orAssert((xCoordinate == 1) || (xCoordinate == 255) || (xCoordinate == 0)); + orAssert((yCoordinate == 1) || (yCoordinate == 255) || (yCoordinate == 0)); t->add(TextureTileVertex(xCoordinate, xPixel, yCoordinate, yPixel)); } @@ -502,9 +502,9 @@ void LoaderTR2::loadSprites() { int16_t negativeLength = file.read16(); // Negative sprite count int16_t offset = file.read16(); // Where sequence starts in sprite texture list - assertLessThan(negativeLength, 0); - assertGreaterThanEqual(offset, 0); - assertLessThanEqual(offset + (negativeLength * -1), numSpriteTextures); + orAssertLessThan(negativeLength, 0); + orAssertGreaterThanEqual(offset, 0); + orAssertLessThanEqual(offset + (negativeLength * -1), numSpriteTextures); SpriteSequence* ss = new SpriteSequence(objectID, offset, (negativeLength * -1)); getWorld().addSpriteSequence(ss); @@ -1197,7 +1197,7 @@ int LoaderTR2::loadSoundFiles(BinaryReader& sfx, unsigned int count) { int ret = Sound::loadBuffer(buff, riffSize + 8); delete [] buff; - assertGreaterThanEqual(ret, 0); + orAssertGreaterThanEqual(ret, 0); riffCount++; } diff --git a/src/main.cpp b/src/main.cpp index da1afe22..50fbedb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,8 @@ #include "system/Window.h" #include "utils/time.h" +#include + static std::string configFileToUse; static std::shared_ptr gWorld; @@ -153,7 +155,7 @@ void renderFrame() { } #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) -#ifndef NODEBUG +#ifndef NDEBUG #include #include @@ -177,6 +179,6 @@ static std::terminate_handler oldTerminateHandler = std::set_terminate(terminate abort(); } -#endif // NODEBUG +#endif // NDEBUG #endif // HAVE_EXECINFO_H && HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS diff --git a/src/system/Font.cpp b/src/system/Font.cpp index dd4e1303..0f177698 100644 --- a/src/system/Font.cpp +++ b/src/system/Font.cpp @@ -122,6 +122,6 @@ void Font::drawFontBox(unsigned int x, unsigned int y, unsigned int w, unsigned uv.bufferData(uvs); Shader::drawGL(vert, uv, glm::vec4(1.0f, 1.0f, 0.0f, 1.0f), TEXTURE_WHITE, - TextureStorage::SYSTEM, GL_LINE_STRIP); + TextureStorage::SYSTEM, gl::GL_LINE_STRIP); } diff --git a/src/system/FontTRLE.cpp b/src/system/FontTRLE.cpp index 9a56b885..53684894 100644 --- a/src/system/FontTRLE.cpp +++ b/src/system/FontTRLE.cpp @@ -26,7 +26,7 @@ void FontTRLE::shutdown() { } int FontTRLE::initialize(std::string font) { - assert(stringEndsWith(font, ".pc") == true); + orAssert(stringEndsWith(font, ".pc") == true); shutdown(); @@ -90,7 +90,7 @@ void FontTRLE::loadLPS(std::string f) { void FontTRLE::writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw, float scale, std::vector& vertices, std::vector& uvs) { - assert(mFontInit == true); + orAssert(mFontInit == true); float width = ((float)offsets[index][2]) * scale * SCALING; float height = ((float)offsets[index][3]) * scale * SCALING; @@ -126,8 +126,8 @@ void FontTRLE::writeChar(unsigned int index, unsigned int xDraw, unsigned int yD } unsigned int FontTRLE::widthText(float scale, std::string s) { - assert(mFontInit == true); - assert(s.length() > 0); + orAssert(mFontInit == true); + orAssert(s.length() > 0); unsigned int width = 0; for (unsigned int i = 0; i < s.length(); i++) { @@ -148,8 +148,8 @@ unsigned int FontTRLE::widthText(float scale, std::string s) { void FontTRLE::drawText(unsigned int x, unsigned int y, float scale, glm::vec4 color, std::string s) { - assert(mFontInit == true); - assert(s.length() > 0); + orAssert(mFontInit == true); + orAssert(s.length() > 0); std::vector vertices; std::vector uvs; @@ -173,8 +173,8 @@ void FontTRLE::drawText(unsigned int x, unsigned int y, float scale, } unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::string s) { - assert(mFontInit == true); - assert(s.length() > 0); + orAssert(mFontInit == true); + orAssert(s.length() > 0); unsigned int x = 0; unsigned int yMax = 0; @@ -207,8 +207,8 @@ unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::strin void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale, glm::vec4 color, unsigned int maxWidth, std::string s) { - assert(mFontInit == true); - assert(s.length() > 0); + orAssert(mFontInit == true); + orAssert(s.length() > 0); unsigned int xStart = x; unsigned int yMax = 0; diff --git a/src/system/FontTTF.cpp b/src/system/FontTTF.cpp index f012d20b..bac49ba0 100644 --- a/src/system/FontTTF.cpp +++ b/src/system/FontTTF.cpp @@ -81,12 +81,12 @@ int FontMapTTF::initialize(unsigned char* fontData, int firstChar) { } bool FontMapTTF::contains(int c) { - assert(begin >= 0); + orAssert(begin >= 0); return (begin >= 0) && (c >= begin) && (c < (begin + MAP_NUM_CHARS)); } void FontMapTTF::getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad) { - assert(contains(c)); + orAssert(contains(c)); stbtt_GetPackedQuad(charInfo, MAP_WIDTH, MAP_HEIGHT, c - begin, xpos, ypos, quad, 0); } @@ -98,7 +98,7 @@ ShaderBuffer FontTTF::vertexBuffer; ShaderBuffer FontTTF::uvBuffer; int FontTTF::initialize(std::string f) { - assert(f.length() > 0); + orAssert(f.length() > 0); std::ifstream file(f, std::ios::binary); if (!file) { @@ -108,7 +108,7 @@ int FontTTF::initialize(std::string f) { file.seekg(0, std::ios::end); auto size = file.tellg(); - assert(size > 0); + orAssert(size > 0); file.seekg(0); maps.clear(); @@ -272,7 +272,7 @@ int FontTTF::getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad) } int map = charIsMapped(c); - assert(map >= 0); + orAssert(map >= 0); maps.at(map).getQuad(c, xpos, ypos, quad); return maps.at(map).getTexture(); } diff --git a/src/system/Shader.cpp b/src/system/Shader.cpp index 3a72991c..40bd38e8 100644 --- a/src/system/Shader.cpp +++ b/src/system/Shader.cpp @@ -12,97 +12,99 @@ #include "system/Window.h" #include "system/Shader.h" +#include + ShaderBuffer::~ShaderBuffer() { if (created) - glDeleteBuffers(1, &buffer); + gl::glDeleteBuffers(1, &buffer); } void ShaderBuffer::bufferData(int elem, int size, void* data) { if (!created) { - glGenBuffers(1, &buffer); + gl::glGenBuffers(1, &buffer); created = true; } boundSize = elem; - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glBufferData(GL_ARRAY_BUFFER, elem * size, data, GL_STATIC_DRAW); + gl::glBindBuffer(gl::GL_ARRAY_BUFFER, buffer); + gl::glBufferData(gl::GL_ARRAY_BUFFER, elem * size, data, gl::GL_STATIC_DRAW); } void ShaderBuffer::bindBuffer() { if (!created) { - glGenBuffers(1, &buffer); + gl::glGenBuffers(1, &buffer); created = true; } - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); + gl::glBindBuffer(gl::GL_ELEMENT_ARRAY_BUFFER, buffer); } void ShaderBuffer::bindBuffer(int location, int size) { if (!created) { - glGenBuffers(1, &buffer); + gl::glGenBuffers(1, &buffer); created = true; } - glEnableVertexAttribArray(location); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE, 0, nullptr); + gl::glEnableVertexAttribArray(location); + gl::glBindBuffer(gl::GL_ARRAY_BUFFER, buffer); + gl::glVertexAttribPointer(location, size, gl::GL_FLOAT, gl::GL_FALSE, 0, nullptr); } void ShaderBuffer::unbind(int location) { - assert(created == true); - glDisableVertexAttribArray(location); + orAssert(created == true); + gl::glDisableVertexAttribArray(location); } // ---------------------------------------------------------------------------- ShaderTexture::ShaderTexture(int w, int h) : width(w), height(h) { - glGenFramebuffers(1, &framebuffer); + gl::glGenFramebuffers(1, &framebuffer); bind(); texture = TextureManager::loadBufferSlot(nullptr, width, height, ColorMode::RGBA, 32, TextureStorage::SYSTEM, -1, false); - glGenRenderbuffers(1, &depth); - glBindRenderbuffer(GL_RENDERBUFFER, depth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth); + gl::glGenRenderbuffers(1, &depth); + gl::glBindRenderbuffer(gl::GL_RENDERBUFFER, depth); + gl::glRenderbufferStorage(gl::GL_RENDERBUFFER, gl::GL_DEPTH_COMPONENT, width, height); + gl::glFramebufferRenderbuffer(gl::GL_FRAMEBUFFER, gl::GL_DEPTH_ATTACHMENT, gl::GL_RENDERBUFFER, depth); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + gl::glFramebufferTexture(gl::GL_FRAMEBUFFER, gl::GL_COLOR_ATTACHMENT0, TextureManager::getTextureID(texture, TextureStorage::SYSTEM), 0); - GLenum drawBuffer = GL_COLOR_ATTACHMENT0; - glDrawBuffers(1, &drawBuffer); + gl::GLenum drawBuffer = gl::GL_COLOR_ATTACHMENT0; + gl::glDrawBuffers(1, &drawBuffer); - assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); + orAssert(gl::glCheckFramebufferStatus(gl::GL_FRAMEBUFFER) == gl::GL_FRAMEBUFFER_COMPLETE); } ShaderTexture::~ShaderTexture() { - glDeleteRenderbuffers(1, &depth); - glDeleteFramebuffers(1, &framebuffer); + gl::glDeleteRenderbuffers(1, &depth); + gl::glDeleteFramebuffers(1, &framebuffer); //! \fixme free texture slot } void ShaderTexture::clear() { bind(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT); } void ShaderTexture::bind() { - glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); - glViewport(0, 0, width, height); + gl::glBindFramebuffer(gl::GL_FRAMEBUFFER, framebuffer); + gl::glViewport(0, 0, width, height); } // ---------------------------------------------------------------------------- Shader::~Shader() { if (programID >= 0) - glDeleteProgram(programID); + gl::glDeleteProgram(programID); } int Shader::addUniform(const char* name) { - assert(programID >= 0); - int r = glGetUniformLocation(programID, name); + orAssert(programID >= 0); + int r = gl::glGetUniformLocation(programID, name); if (r < 0) { Log::get(LOG_ERROR) << "Can't find GLSL Uniform \"" << name << "\"!" << Log::endl; return -1; @@ -112,112 +114,124 @@ int Shader::addUniform(const char* name) { } unsigned int Shader::getUniform(int n) { - assert(n >= 0); - assert(n < uniforms.size()); + orAssert(n >= 0); + orAssert(n < uniforms.size()); return uniforms.at(n); } void Shader::loadUniform(int uni, glm::vec2 vec) { - glUniform2f(getUniform(uni), vec.x, vec.y); + gl::glUniform2f(getUniform(uni), vec.x, vec.y); } void Shader::loadUniform(int uni, glm::vec4 vec) { - glUniform4f(getUniform(uni), vec.r, vec.g, vec.b, vec.a); + gl::glUniform4f(getUniform(uni), vec.r, vec.g, vec.b, vec.a); } void Shader::loadUniform(int uni, glm::mat4 mat) { - glUniformMatrix4fv(getUniform(uni), 1, GL_FALSE, &mat[0][0]); + gl::glUniformMatrix4fv(getUniform(uni), 1, gl::GL_FALSE, &mat[0][0]); } void Shader::loadUniform(int uni, int texture, TextureStorage store) { - glUniform1i(getUniform(uni), TextureManager::bindTexture(texture, store)); + gl::glUniform1i(getUniform(uni), TextureManager::bindTexture(texture, store)); } void Shader::use() { - assert(programID >= 0); - glUseProgram(programID); + orAssert(programID >= 0); + gl::glUseProgram(programID); } int Shader::compile(const char* vertex, const char* fragment) { - assert(vertex != nullptr); - assert(fragment != nullptr); + orAssert(vertex != nullptr); + orAssert(fragment != nullptr); - GLuint vertexID = glCreateShader(GL_VERTEX_SHADER); - GLuint fragmentID = glCreateShader(GL_FRAGMENT_SHADER); + gl::GLuint vertexID = gl::glCreateShader(gl::GL_VERTEX_SHADER); + gl::GLuint fragmentID = gl::glCreateShader(gl::GL_FRAGMENT_SHADER); - GLint result = GLint(GL_FALSE); - GLint logLength = 0; + gl::GLint result = gl::GLint(gl::GL_FALSE); + gl::GLint logLength = 0; // Compile vertex shader - glShaderSource(vertexID, 1, &vertex, nullptr); - glCompileShader(vertexID); + gl::glShaderSource(vertexID, 1, &vertex, nullptr); + gl::glCompileShader(vertexID); // Check vertex shader - glGetShaderiv(vertexID, GL_COMPILE_STATUS, &result); - glGetShaderiv(vertexID, GL_INFO_LOG_LENGTH, &logLength); - if ((logLength > 0) && (result != GLint(GL_TRUE))) { + gl::glGetShaderiv(vertexID, gl::GL_COMPILE_STATUS, &result); + gl::glGetShaderiv(vertexID, gl::GL_INFO_LOG_LENGTH, &logLength); + if ((logLength > 0) && (result != gl::GLint(gl::GL_TRUE))) { std::vector message(logLength + 1); - glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]); + gl::glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]); Log::get(LOG_ERROR) << "Vertex Shader compilation error:" << Log::endl; Log::get(LOG_ERROR) << &message[0] << Log::endl; - glDeleteShader(vertexID); - glDeleteShader(fragmentID); + gl::glDeleteShader(vertexID); + gl::glDeleteShader(fragmentID); return -1; } // Compile fragment shader - glShaderSource(fragmentID, 1, &fragment, nullptr); - glCompileShader(fragmentID); + gl::glShaderSource(fragmentID, 1, &fragment, nullptr); + gl::glCompileShader(fragmentID); // Check fragment shader - glGetShaderiv(fragmentID, GL_COMPILE_STATUS, &result); - glGetShaderiv(fragmentID, GL_INFO_LOG_LENGTH, &logLength); - if ((logLength > 0) && (result != GLint(GL_TRUE))) { + gl::glGetShaderiv(fragmentID, gl::GL_COMPILE_STATUS, &result); + gl::glGetShaderiv(fragmentID, gl::GL_INFO_LOG_LENGTH, &logLength); + if ((logLength > 0) && (result != gl::GLint(gl::GL_TRUE))) { std::vector message(logLength + 1); - glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]); + gl::glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]); Log::get(LOG_ERROR) << "Fragment Shader compilation error:" << Log::endl; Log::get(LOG_ERROR) << &message[0] << Log::endl; - glDeleteShader(vertexID); - glDeleteShader(fragmentID); + gl::glDeleteShader(vertexID); + gl::glDeleteShader(fragmentID); return -2; } // Link both shaders - programID = glCreateProgram(); - glAttachShader(programID, vertexID); - glAttachShader(programID, fragmentID); - glLinkProgram(programID); + programID = gl::glCreateProgram(); + gl::glAttachShader(programID, vertexID); + gl::glAttachShader(programID, fragmentID); + gl::glLinkProgram(programID); // Check resulting program - glGetProgramiv(programID, GL_LINK_STATUS, &result); - glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &logLength); - if ((logLength > 0) && (result != GLint(GL_TRUE))) { + gl::glGetProgramiv(programID, gl::GL_LINK_STATUS, &result); + gl::glGetProgramiv(programID, gl::GL_INFO_LOG_LENGTH, &logLength); + if ((logLength > 0) && (result != gl::GLint(gl::GL_TRUE))) { std::vector message(logLength + 1); - glGetProgramInfoLog(programID, logLength, nullptr, &message[0]); + gl::glGetProgramInfoLog(programID, logLength, nullptr, &message[0]); Log::get(LOG_ERROR) << "Shader link error:" << Log::endl; Log::get(LOG_ERROR) << &message[0] << Log::endl; - glDeleteShader(vertexID); - glDeleteShader(fragmentID); - glDeleteProgram(programID); + gl::glDeleteShader(vertexID); + gl::glDeleteShader(fragmentID); + gl::glDeleteProgram(programID); return -3; } - glDeleteShader(vertexID); - glDeleteShader(fragmentID); + gl::glDeleteShader(vertexID); + gl::glDeleteShader(fragmentID); return programID; } // ---------------------------------------------------------------------------- std::string Shader::getVersion(bool linked) { - std::ostringstream str; - if (!linked) { - str << "OpenGL v" << glGetString(GL_VERSION); + static std::string cache; + static std::string cacheLinked; + static bool cacheFilled = false; + + if (!cacheFilled) { + std::ostringstream str; + str << "OpenGL v" << gl::glGetString(gl::GL_VERSION); + cache = str.str(); + str.str(""); + str << "OpenGL " << gl::glGetString(gl::GL_SHADING_LANGUAGE_VERSION) << " " + << gl::glGetString(gl::GL_RENDERER) << " (" << gl::glGetString(gl::GL_VENDOR) << ")"; + cacheLinked = str.str(); + cacheFilled = true; + } + + if (linked) { + return cacheLinked; } else { - str << "OpenGL " << glGetString(GL_SHADING_LANGUAGE_VERSION) << " " - << glGetString(GL_RENDERER) << " (" << glGetString(GL_VENDOR) << ")"; + return cache; } - return str.str(); } Shader Shader::textShader; @@ -226,19 +240,19 @@ Shader Shader::colorShader; unsigned int Shader::vertexArrayID = 0; int Shader::initialize() { - glGenVertexArrays(1, &vertexArrayID); - glBindVertexArray(vertexArrayID); + gl::glGenVertexArrays(1, &vertexArrayID); + gl::glBindVertexArray(vertexArrayID); // Set background color - glClearColor(0.0f, 0.0f, 0.4f, 1.0f); + gl::glClearColor(0.0f, 0.0f, 0.4f, 1.0f); set2DState(false); - glDepthFunc(GL_LESS); + gl::glDepthFunc(gl::GL_LESS); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + gl::glEnable(gl::GL_BLEND); + gl::glBlendFunc(gl::GL_SRC_ALPHA, gl::GL_ONE_MINUS_SRC_ALPHA); - glPointSize(5.0f); + gl::glPointSize(5.0f); if (textShader.compile(textShaderVertex, textShaderFragment) < 0) return -1; @@ -265,32 +279,32 @@ int Shader::initialize() { } void Shader::shutdown() { - glDeleteVertexArrays(1, &vertexArrayID); + gl::glDeleteVertexArrays(1, &vertexArrayID); } void Shader::set2DState(bool on, bool depth) { if (on) { - glDisable(GL_CULL_FACE); + gl::glDisable(gl::GL_CULL_FACE); if (depth) - glDisable(GL_DEPTH_TEST); + gl::glDisable(gl::GL_DEPTH_TEST); } else { - glEnable(GL_CULL_FACE); + gl::glEnable(gl::GL_CULL_FACE); if (depth) - glEnable(GL_DEPTH_TEST); + gl::glEnable(gl::GL_DEPTH_TEST); } } void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, - unsigned int texture, TextureStorage store, GLenum mode, + unsigned int texture, TextureStorage store, gl::GLenum mode, ShaderTexture* target, Shader& shader) { - assert(vertices.getSize() == uvs.getSize()); - if (mode == GL_TRIANGLES) { - assert((vertices.getSize() % 3) == 0); + orAssert(vertices.getSize() == uvs.getSize()); + if (mode == gl::GL_TRIANGLES) { + orAssert((vertices.getSize() % 3) == 0); } if (target == nullptr) { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, Window::getSize().x, Window::getSize().y); + gl::glBindFramebuffer(gl::GL_FRAMEBUFFER, 0); + gl::glViewport(0, 0, Window::getSize().x, Window::getSize().y); } else { target->bind(); } @@ -303,7 +317,7 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, uvs.bindBuffer(1, 2); set2DState(true); - glDrawArrays(mode, 0, vertices.getSize()); + gl::glDrawArrays(mode, 0, vertices.getSize()); set2DState(false); vertices.unbind(0); @@ -313,12 +327,12 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP, TextureStorage store, ShaderTexture* target, Shader& shader) { - assert(vertices.getSize() == uvs.getSize()); - assert((vertices.getSize() % 3) == 0); + orAssert(vertices.getSize() == uvs.getSize()); + orAssert((vertices.getSize() % 3) == 0); if (target == nullptr) { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, Window::getSize().x, Window::getSize().y); + gl::glBindFramebuffer(gl::GL_FRAMEBUFFER, 0); + gl::glViewport(0, 0, Window::getSize().x, Window::getSize().y); } else { target->bind(); } @@ -328,7 +342,7 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int text shader.loadUniform(1, texture, store); vertices.bindBuffer(0, 3); uvs.bindBuffer(1, 2); - glDrawArrays(GL_TRIANGLES, 0, vertices.getSize()); + gl::glDrawArrays(gl::GL_TRIANGLES, 0, vertices.getSize()); vertices.unbind(0); uvs.unbind(1); } @@ -336,19 +350,19 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int text void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices, unsigned int texture, glm::mat4 MVP, TextureStorage store, ShaderTexture* target, Shader& shader) { - assert(vertices.getSize() == uvs.getSize()); - assert((indices.getSize() % 3) == 0); + orAssert(vertices.getSize() == uvs.getSize()); + orAssert((indices.getSize() % 3) == 0); if (target == nullptr) { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, Window::getSize().x, Window::getSize().y); + gl::glBindFramebuffer(gl::GL_FRAMEBUFFER, 0); + gl::glViewport(0, 0, Window::getSize().x, Window::getSize().y); } else { target->bind(); unsigned int sz = vertices.getSize(); glm::vec3* buffer = new glm::vec3[sz]; - glBindBuffer(GL_ARRAY_BUFFER, vertices.getBuffer()); - glGetBufferSubData(GL_ARRAY_BUFFER, 0, sz * sizeof(glm::vec3), buffer); + gl::glBindBuffer(gl::GL_ARRAY_BUFFER, vertices.getBuffer()); + gl::glGetBufferSubData(gl::GL_ARRAY_BUFFER, 0, sz * sizeof(glm::vec3), buffer); Log::get(LOG_DEBUG) << "drawGL Vertex dump:" << Log::endl; for (unsigned int i = 0; i < sz; i++) { @@ -367,21 +381,21 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& ind vertices.bindBuffer(0, 3); uvs.bindBuffer(1, 2); indices.bindBuffer(); - glDrawElements(GL_TRIANGLES, indices.getSize(), GL_UNSIGNED_SHORT, nullptr); + gl::glDrawElements(gl::GL_TRIANGLES, indices.getSize(), gl::GL_UNSIGNED_SHORT, nullptr); vertices.unbind(0); uvs.unbind(1); } void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP, - GLenum mode, ShaderTexture* target, Shader& shader) { - assert(vertices.getSize() == colors.getSize()); - if (mode == GL_TRIANGLES) { - assert((vertices.getSize() % 3) == 0); + gl::GLenum mode, ShaderTexture* target, Shader& shader) { + orAssert(vertices.getSize() == colors.getSize()); + if (mode == gl::GL_TRIANGLES) { + orAssert((vertices.getSize() % 3) == 0); } if (target == nullptr) { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, Window::getSize().x, Window::getSize().y); + gl::glBindFramebuffer(gl::GL_FRAMEBUFFER, 0); + gl::glViewport(0, 0, Window::getSize().x, Window::getSize().y); } else { target->bind(); } @@ -390,21 +404,21 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP, shader.loadUniform(0, MVP); vertices.bindBuffer(0, 3); colors.bindBuffer(1, 3); - glDrawArrays(mode, 0, vertices.getSize()); + gl::glDrawArrays(mode, 0, vertices.getSize()); vertices.unbind(0); colors.unbind(1); } void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices, - glm::mat4 MVP, GLenum mode, ShaderTexture* target, Shader& shader) { - assert(vertices.getSize() == colors.getSize()); - if (mode == GL_TRIANGLES) { - assert((indices.getSize() % 3) == 0); + glm::mat4 MVP, gl::GLenum mode, ShaderTexture* target, Shader& shader) { + orAssert(vertices.getSize() == colors.getSize()); + if (mode == gl::GL_TRIANGLES) { + orAssert((indices.getSize() % 3) == 0); } if (target == nullptr) { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, Window::getSize().x, Window::getSize().y); + gl::glBindFramebuffer(gl::GL_FRAMEBUFFER, 0); + gl::glViewport(0, 0, Window::getSize().x, Window::getSize().y); } else { target->bind(); } @@ -414,7 +428,7 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& vertices.bindBuffer(0, 3); colors.bindBuffer(1, 3); indices.bindBuffer(); - glDrawElements(mode, indices.getSize(), GL_UNSIGNED_SHORT, nullptr); + gl::glDrawElements(mode, indices.getSize(), gl::GL_UNSIGNED_SHORT, nullptr); vertices.unbind(0); colors.unbind(1); } diff --git a/src/system/SoundAL.cpp b/src/system/SoundAL.cpp index 60ba92ac..26a4fb55 100644 --- a/src/system/SoundAL.cpp +++ b/src/system/SoundAL.cpp @@ -134,7 +134,7 @@ int SoundAL::numSources(bool atListener) { return sources.size(); } -int SoundAL::addSource(int buffer, float volume, bool atListener, bool loop) { +int SoundAL::addSource(int buffer, float vol, bool atListener, bool loop) { if (!init) { Log::get(LOG_ERROR) << "SoundAL Error: Adding source, but not initialized!" << Log::endl; return -1; @@ -156,7 +156,7 @@ int SoundAL::addSource(int buffer, float volume, bool atListener, bool loop) { } alSourcei(id, AL_BUFFER, buffers.at(buffer)); - alSourcef(id, AL_GAIN, volume); + alSourcef(id, AL_GAIN, vol); alSourcef(id, AL_REFERENCE_DISTANCE, referenceDistance); alSourcef(id, AL_MAX_DISTANCE, maxDistance); diff --git a/src/system/Window.cpp b/src/system/Window.cpp index 4ef51e18..ffd07915 100644 --- a/src/system/Window.cpp +++ b/src/system/Window.cpp @@ -18,6 +18,8 @@ #error "No windowing library selected!" #endif +#include + int Window::initialize() { int res; @@ -65,7 +67,7 @@ void Window::setSize(glm::i32vec2 s) { UI::setSize(s); Camera::setSize(s); - glViewport(0, 0, s.x, s.y); + gl::glViewport(0, 0, s.x, s.y); } glm::i32vec2 Window::getSize() { diff --git a/src/system/WindowGLFW.cpp b/src/system/WindowGLFW.cpp index ca607277..a0f5ff10 100644 --- a/src/system/WindowGLFW.cpp +++ b/src/system/WindowGLFW.cpp @@ -18,6 +18,8 @@ #include "system/Window.h" #include "system/WindowGLFW.h" +#include + glm::i32vec2 WindowGLFW::size(DEFAULT_WIDTH, DEFAULT_HEIGHT); bool WindowGLFW::fullscreen = false; bool WindowGLFW::mousegrab = false; @@ -40,7 +42,7 @@ int WindowGLFW::initialize() { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, int(GL_TRUE)); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, int(gl::GL_TRUE)); window = glfwCreateWindow(size.x, size.y, VERSION, fullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr); @@ -89,7 +91,7 @@ void WindowGLFW::shutdown() { } void WindowGLFW::setSize(glm::i32vec2 s) { - assert((s.x > 0) && (s.y > 0)); + orAssert((s.x > 0) && (s.y > 0)); if (window) { if ((size.x != s.x) || (size.y != s.y)) { glfwSetWindowSize(window, s.x, s.y); diff --git a/src/system/WindowSDL.cpp b/src/system/WindowSDL.cpp index 5dc650dd..5241efc2 100644 --- a/src/system/WindowSDL.cpp +++ b/src/system/WindowSDL.cpp @@ -518,7 +518,7 @@ void WindowSDL::shutdown() { } void WindowSDL::setSize(glm::i32vec2 s) { - assert((s.x > 0) && (s.y > 0)); + orAssert((s.x > 0) && (s.y > 0)); if (window) { if ((s.x != size.x) || (s.y != size.y)) { SDL_SetWindowSize(window, s.x, s.y); diff --git a/src/utils/Folder.cpp b/src/utils/Folder.cpp index 79349147..48fbb543 100644 --- a/src/utils/Folder.cpp +++ b/src/utils/Folder.cpp @@ -85,7 +85,7 @@ unsigned long Folder::fileCount() { File& Folder::getFile(unsigned long i) { createFolderItems(); - assert(i < files.size()); + orAssert(i < files.size()); return files.at(i); } @@ -96,7 +96,7 @@ unsigned long Folder::folderCount() { Folder& Folder::getFolder(unsigned long i) { createFolderItems(); - assert(i < folders.size()); + orAssert(i < folders.size()); return folders.at(i); } diff --git a/src/utils/FolderRecursive.cpp b/src/utils/FolderRecursive.cpp index 86640f83..11e46e9b 100644 --- a/src/utils/FolderRecursive.cpp +++ b/src/utils/FolderRecursive.cpp @@ -26,7 +26,7 @@ void Folder::executeRemoveRecursiveFiles(std::function func) { std::string Folder::getRecursiveFileName(unsigned long i) { createFolderItems(); - assert(i < countRecursiveFiles()); + orAssert(i < countRecursiveFiles()); if (i < fileCount()) { return getFile(i).getName(); } else { @@ -40,13 +40,13 @@ std::string Folder::getRecursiveFileName(unsigned long i) { } } - assert(false); + orAssert(false); return ""; } File& Folder::getRecursiveFile(unsigned long i) { createFolderItems(); - assert(i < countRecursiveFiles()); + orAssert(i < countRecursiveFiles()); if (i < fileCount()) { return getFile(i); } else { @@ -59,7 +59,7 @@ File& Folder::getRecursiveFile(unsigned long i) { } } - assert(false); + orAssert(false); return files.at(0); } diff --git a/src/utils/binary.cpp b/src/utils/binary.cpp index 83f591d4..bf1e479b 100644 --- a/src/utils/binary.cpp +++ b/src/utils/binary.cpp @@ -101,7 +101,7 @@ int64_t BinaryReader::read64() { // ---------------------------------------------------------------------------- BinaryFile::BinaryFile(std::string f) { - assertEqual(open(f), 0); + orAssertEqual(open(f), 0); } BinaryFile::~BinaryFile() { @@ -121,12 +121,12 @@ int BinaryFile::open(std::string f) { } long long BinaryFile::tell() { - assert(file.is_open()); + orAssert(file.is_open()); return file.tellg(); } void BinaryFile::seek(long long pos) { - assert(file.is_open()); + orAssert(file.is_open()); file.seekg(pos); } @@ -136,15 +136,15 @@ bool BinaryFile::eof() { } void BinaryFile::read(char* d, int c) { - assert(file.is_open()); - assert(file.good()); + orAssert(file.is_open()); + orAssert(file.good()); file.read(d, c); } // ---------------------------------------------------------------------------- BinaryMemory::BinaryMemory(const char* d, long long m) : data(nullptr), offset(0), max(-1) { - assertEqual(open(d, m), 0); + orAssertEqual(open(d, m), 0); } BinaryMemory::~BinaryMemory() { @@ -164,12 +164,12 @@ int BinaryMemory::open(const char* d, long long m) { } long long BinaryMemory::tell() { - assertGreaterThanEqual(offset, 0); + orAssertGreaterThanEqual(offset, 0); return offset; } void BinaryMemory::seek(long long pos) { - assertGreaterThanEqual(pos, 0); + orAssertGreaterThanEqual(pos, 0); offset = pos; } @@ -178,9 +178,9 @@ bool BinaryMemory::eof() { } void BinaryMemory::read(char* d, int c) { - assertGreaterThanEqual(offset, 0); - assertGreaterThan(c, 0); - assertLessThanEqual(offset + c, max); + orAssertGreaterThanEqual(offset, 0); + orAssertGreaterThan(c, 0); + orAssertLessThanEqual(offset + c, max); for (int i = 0; i < c; i++) { d[i] = data[offset + i]; } diff --git a/src/utils/filesystem.cpp b/src/utils/filesystem.cpp index 4e2d71d6..84b78cba 100644 --- a/src/utils/filesystem.cpp +++ b/src/utils/filesystem.cpp @@ -25,12 +25,12 @@ std::string getCurrentWorkingDirectory() { #if defined(HAVE_UNISTD_H) && defined(HAVE_GETCWD) char path[1024]; - assertEqual(getcwd(path, 1024), path); + orAssertEqual(getcwd(path, 1024), path); return std::string(path); #else - assert(false); + orAssert(false); return ""; #endif @@ -40,13 +40,13 @@ std::string getHomeDirectory() { #if defined(HAVE_STDLIB_H) && defined(HAVE_GETENV) char* path = getenv("HOME"); - assert(path != nullptr); + orAssert(path != nullptr); return path; #elif defined(_WIN32) char path[MAX_PATH]; - assertEqual(SHGetFolderPath(nullptr, CSIDL_PROFILE, nullptr, 0, path), S_OK); + orAssertEqual(SHGetFolderPath(nullptr, CSIDL_PROFILE, nullptr, 0, path), S_OK); size_t lenPath = strlen(path); for (unsigned int i = 0; i < lenPath; i++) if (path[i] == '\\') @@ -55,7 +55,7 @@ std::string getHomeDirectory() { #else - assert(false); + orAssert(false); return ""; #endif diff --git a/src/utils/pcx.cpp b/src/utils/pcx.cpp index a2c4d104..a7c874e7 100644 --- a/src/utils/pcx.cpp +++ b/src/utils/pcx.cpp @@ -15,8 +15,8 @@ #include "utils/pcx.h" int pcxCheck(const char* filename) { - assert(filename != nullptr); - assert(filename[0] != '\0'); + orAssert(filename != nullptr); + orAssert(filename[0] != '\0'); std::ifstream file(filename, std::ios::in | std::ios::binary); @@ -69,13 +69,13 @@ int pcxCheck(const char* filename) { int pcxLoad(const char* filename, unsigned char** image, unsigned int* width, unsigned int* height, ColorMode* mode, unsigned int* bpp) { - assert(filename != nullptr); - assert(filename[0] != '\0'); - assert(image != nullptr); - assert(width != nullptr); - assert(height != nullptr); - assert(mode != nullptr); - assert(bpp != nullptr); + orAssert(filename != nullptr); + orAssert(filename[0] != '\0'); + orAssert(image != nullptr); + orAssert(width != nullptr); + orAssert(height != nullptr); + orAssert(mode != nullptr); + orAssert(bpp != nullptr); std::ifstream file(filename, std::ios::in | std::ios::binary); diff --git a/src/utils/pixel.cpp b/src/utils/pixel.cpp index e864dd7a..75563b19 100644 --- a/src/utils/pixel.cpp +++ b/src/utils/pixel.cpp @@ -10,9 +10,9 @@ unsigned char* generateColorTexture(glm::vec4 rgba, unsigned int width, unsigned int height, unsigned int bpp) { - assert(width > 0); - assert(height > 0); - assert((bpp == 24) || (bpp == 32)); + orAssert(width > 0); + orAssert(height > 0); + orAssert((bpp == 24) || (bpp == 32)); unsigned char* image = new unsigned char[height * width * (bpp / 8)]; for (unsigned int i = 0; i < (width * height); i++) { @@ -27,9 +27,9 @@ unsigned char* generateColorTexture(glm::vec4 rgba, unsigned int width, } void argb2rgba32(unsigned char* image, unsigned int w, unsigned int h) { - assert(image != nullptr); - assert(w > 0); - assert(h > 0); + orAssert(image != nullptr); + orAssert(w > 0); + orAssert(h > 0); for (unsigned int i = 0; i < (w * h); ++i) { // 32-bit ARGB to RGBA @@ -42,9 +42,9 @@ void argb2rgba32(unsigned char* image, unsigned int w, unsigned int h) { } unsigned char* argb16to32(unsigned char* image, unsigned int w, unsigned int h) { - assert(image != nullptr); - assert(w > 0); - assert(h > 0); + orAssert(image != nullptr); + orAssert(w > 0); + orAssert(h > 0); unsigned char* img = new unsigned char[w * h * 4]; for (unsigned int i = 0; i < (w * h); ++i) { @@ -63,9 +63,9 @@ unsigned char* argb16to32(unsigned char* image, unsigned int w, unsigned int h) } unsigned char* grayscale2rgba(unsigned char* image, unsigned int w, unsigned int h) { - assert(image != nullptr); - assert(w > 0); - assert(h > 0); + orAssert(image != nullptr); + orAssert(w > 0); + orAssert(h > 0); unsigned char* img = new unsigned char[w * h * 4]; for (unsigned int i = 0; i < (w * h); i++) { @@ -88,10 +88,10 @@ unsigned char* scaleBuffer(unsigned char* image, unsigned int* w, unsigned int* unsigned int bpp) { unsigned int width = *w; unsigned int height = *h; - assert(image != nullptr); - assert(width > 0); - assert(height > 0); - assert((bpp % 8) == 0); + orAssert(image != nullptr); + orAssert(width > 0); + orAssert(height > 0); + orAssert((bpp % 8) == 0); unsigned int components = bpp / 8; unsigned int original_height = height; diff --git a/src/utils/random.cpp b/src/utils/random.cpp index c8706cbe..ed302d92 100644 --- a/src/utils/random.cpp +++ b/src/utils/random.cpp @@ -21,7 +21,7 @@ int randomInteger(int max, int min) { if (max == min) return max; - assertGreaterThan(max, min); + orAssertGreaterThan(max, min); if (!engineIsSeeded) { engine.seed(std::chrono::system_clock::now().time_since_epoch().count()); diff --git a/test/Script.cpp b/test/Script.cpp index 3d6ed919..d9a5af06 100644 --- a/test/Script.cpp +++ b/test/Script.cpp @@ -163,7 +163,7 @@ static int readPayloadChunk(const unsigned char* data, unsigned int size, const } static int runForPayload(unsigned int n, bool print, bool printData) { - assert(n < testPayloadCount); + orAssert(n < testPayloadCount); // Get temp file name char tmpFile[] = "/tmp/openraider_unit_test_0"; FILE* f; @@ -205,7 +205,7 @@ int main(int argc, char* argv[]) { if (strcmp(argv[1], "--printScript") == 0) { printData = false; } - assert(testPayloadCount < 10); + orAssert(testPayloadCount < 10); if ((argv[2][0] >= '0') && (static_cast(argv[2][0]) <= (testPayloadCount + '0'))) { whichFile = argv[2][0] - '0'; @@ -228,7 +228,7 @@ int main(int argc, char* argv[]) { if (whichFile == -1) { // From given path Script s; - assertEqual(s.load(argv[2]), 0); + orAssertEqual(s.load(argv[2]), 0); return printDataScript(s, printData); } else { // From payload