diff --git a/CMakeLists.txt b/CMakeLists.txt index 8794435e..afc1dfc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(OpenRW) # Global Build Configuration set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DRW_DEBUG=1") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pthread -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pthread -Wextra -Wpedantic") # Optional components SET(BUILD_SCRIPT_TOOL TRUE CACHE BOOL "Build script decompiler tool") diff --git a/rwengine/include/render/GameShaders.hpp b/rwengine/include/render/GameShaders.hpp index d27f9acd..2980e87c 100644 --- a/rwengine/include/render/GameShaders.hpp +++ b/rwengine/include/render/GameShaders.hpp @@ -6,7 +6,7 @@ struct Name {\ static const char* VertexShader;\ static const char* FragmentShader;\ -}; +} /** * @brief collection of shaders to make managing them a little easier. @@ -16,12 +16,12 @@ namespace GameShaders { /** * High Quality Projected-Grid water shader */ -SHADER_VF(WaterHQ) +SHADER_VF(WaterHQ); /** * Simple 3D masking shader */ -SHADER_VF(Mask3D) +SHADER_VF(Mask3D); struct Sky { static const char* VertexShader; diff --git a/rwengine/src/engine/GameData.cpp b/rwengine/src/engine/GameData.cpp index 0320489f..8c44524e 100644 --- a/rwengine/src/engine/GameData.cpp +++ b/rwengine/src/engine/GameData.cpp @@ -59,8 +59,9 @@ std::string findPathRealCase(const std::string& base, const std::string& path) } } } + closedir(dp); } - + return ""; #else // Is anything other than Windows likely to fall here? diff --git a/rwengine/src/engine/SaveGame.cpp b/rwengine/src/engine/SaveGame.cpp index 6336f5f0..5c31e72a 100644 --- a/rwengine/src/engine/SaveGame.cpp +++ b/rwengine/src/engine/SaveGame.cpp @@ -565,7 +565,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) BlockDword numScripts; READ_SIZE(numScripts) - Block0RunningScript scripts[numScripts]; + std::vector scripts(numScripts); for (size_t i = 0; i < numScripts; ++i) { READ_VALUE(scripts[i]); @@ -579,7 +579,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) BlockDword playerCount; READ_SIZE(playerCount) - Block1PlayerPed players[playerCount]; + std::vector players(playerCount); for(unsigned int p = 0; p < playerCount; ++p) { Block1PlayerPed& ped = players[p]; READ_VALUE(ped.unknown0) @@ -620,7 +620,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) READ_VALUE(garageData.GA_21lastTime) READ_VALUE(garageData.cars) - StructGarage garages[garageData.garageCount]; + std::vector garages(garageData.garageCount); for (size_t i = 0; i < garageData.garageCount; ++i) { READ_VALUE(garages[i]); @@ -652,7 +652,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) READ_VALUE(vehicleCount) READ_VALUE(boatCount) - Block3Vehicle vehicles[vehicleCount]; + std::vector vehicles(vehicleCount); for(size_t v = 0; v < vehicleCount; ++v) { Block3Vehicle& veh = vehicles[v]; READ_VALUE(veh.unknown1) @@ -663,7 +663,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) std::cout << " v " << veh.modelId << " " << veh.state.position.x << " " << veh.state.position.y << " " << veh.state.position.z << std::endl; #endif } - Block3Boat boats[boatCount]; + std::vector boats(boatCount); for(size_t v = 0; v < boatCount; ++v) { Block3Boat& veh = boats[v]; READ_VALUE(veh.unknown1) @@ -684,7 +684,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) BlockDword objectCount; READ_VALUE(objectCount); - Block4Object objects[objectCount]; + std::vector objects(objectCount); for(size_t o = 0; o < objectCount; ++o) { Block4Object &obj = objects[o]; @@ -772,7 +772,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) Block8Data phoneData; READ_VALUE(phoneData); - Block8Phone phones[phoneData.numPhones]; + std::vector phones(phoneData.numPhones); for (size_t p = 0; p < phoneData.numPhones; ++p) { Block8Phone &phone = phones[p]; READ_VALUE(phone) @@ -922,7 +922,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) Block13Data carGeneratorData; READ_VALUE(carGeneratorData); - Block13CarGenerator carGenerators[carGeneratorData.generatorCount]; + std::vector carGenerators(carGeneratorData.generatorCount); for(size_t g = 0; g < carGeneratorData.generatorCount; ++g) { READ_VALUE(carGenerators[g]) } @@ -943,7 +943,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) BlockDword particleCount; READ_VALUE(particleCount); - Block14Particle particles[particleCount]; + std::vector particles(particleCount); for(size_t p = 0; p < particleCount; ++p) { READ_VALUE(particles[p]) } @@ -963,7 +963,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) BlockDword audioCount; READ_VALUE(audioCount) - Block15AudioObject audioObjects[audioCount]; + std::vector audioObjects(audioCount); for(size_t a = 0; a < audioCount; ++a) { READ_VALUE(audioObjects[a]) } diff --git a/rwengine/src/render/GameRenderer.cpp b/rwengine/src/render/GameRenderer.cpp index c476717f..4caa4f67 100644 --- a/rwengine/src/render/GameRenderer.cpp +++ b/rwengine/src/render/GameRenderer.cpp @@ -159,7 +159,8 @@ GameRenderer::GameRenderer(Logger* log, GameData* _data) skyDbuff.setFaceType(GL_TRIANGLES); glGenBuffers(1, &skydomeIBO); - GLuint skydomeIndBuff[rows*segments*6]; + std::vector skydomeIndBuff; + skydomeIndBuff.resize(rows*segments*6); for( size_t r = 0, i = 0; r < (rows-1); ++r ) { for( size_t s = 0; s < (segments-1); ++s ) { skydomeIndBuff[i++] = r * segments + s; @@ -171,7 +172,7 @@ GameRenderer::GameRenderer(Logger* log, GameData* _data) } } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, skydomeIBO); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(skydomeIndBuff), skydomeIndBuff, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * skydomeIndBuff.size(), skydomeIndBuff.data(), GL_STATIC_DRAW); glBindVertexArray(0); diff --git a/rwlib/source/data/ResourceHandle.hpp b/rwlib/source/data/ResourceHandle.hpp index df740958..24c268b0 100644 --- a/rwlib/source/data/ResourceHandle.hpp +++ b/rwlib/source/data/ResourceHandle.hpp @@ -17,7 +17,7 @@ namespace RW /// Loading the resource failed Failed = 2 }; -}; +} template class ResourceHandle diff --git a/rwlib/source/loaders/LoaderTXD.cpp b/rwlib/source/loaders/LoaderTXD.cpp index 37479062..db7c1854 100644 --- a/rwlib/source/loaders/LoaderTXD.cpp +++ b/rwlib/source/loaders/LoaderTXD.cpp @@ -25,7 +25,7 @@ TextureData::Handle getErrorTexture() GL_RGBA, GL_UNSIGNED_BYTE, gErrorTextureData ); glGenerateMipmap(GL_TEXTURE_2D); - + tex = TextureData::create(errTexName, {2, 2}, false); } return tex; @@ -42,7 +42,7 @@ void processPalette(uint32_t* fullColor, RW::BinaryStreamSection& rootSection) for(size_t j = 0; j < raster_size; ++j) { - fullColor[j] = palette[coldata[j]]; + *(fullColor++) = palette[coldata[j]]; } } @@ -61,26 +61,26 @@ TextureData::Handle createTexture(RW::BSTextureNative& texNative, RW::BinaryStre texNative.rasterformat == RW::BSTextureNative::FORMAT_888; // Export this value bool transparent = !((texNative.rasterformat&RW::BSTextureNative::FORMAT_888) == RW::BSTextureNative::FORMAT_888); - + if(! (isPal8 || isFulc)) { std::cerr << "Unsuported raster format " << std::dec << texNative.rasterformat << std::endl; return getErrorTexture(); } GLuint textureName = 0; - + if(isPal8) { - uint32_t fullColor[texNative.width * texNative.height]; + std::vector fullColor(texNative.width * texNative.height); - processPalette(fullColor, rootSection); + processPalette(fullColor.data(), rootSection); glGenTextures(1, &textureName); glBindTexture(GL_TEXTURE_2D, textureName); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, texNative.width, texNative.height, 0, - GL_RGBA, GL_UNSIGNED_BYTE, fullColor + GL_RGBA, GL_UNSIGNED_BYTE, fullColor.data() ); } else if(isFulc) @@ -187,7 +187,7 @@ bool TextureLoader::loadFromMemory(FileHandle file, TextureArchive &inTextures) std::string alpha = std::string(texNative.alphaName); std::transform(name.begin(), name.end(), name.begin(), ::tolower ); std::transform(alpha.begin(), alpha.end(), alpha.begin(), ::tolower ); - + auto texture = createTexture(texNative, rootSection); inTextures[{name, alpha}] = texture;