diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..cecb0a1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,36 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceFolder}/out/build/x64-debug/YuppleMayham/YuppleMayham.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/out/build/x64-debug/YuppleMayham/", + "environment": [], + "console": "externalTerminal" + }, + { + "name": "(gdb) Attach", + "type": "cppdbg", + "request": "attach", + "program": "${workspaceFolder}/YuppleMayham.exe", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + }, + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..6532339 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: cl.exe build active file", + "command": "cl.exe", + "args": [ + "/Zi", + "/EHsc", + "/nologo", + "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", + "${file}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$msCompile" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/YuppleMayham/include/gameplay/entity.h b/YuppleMayham/include/gameplay/entity.h index fb0b00c..29bdb25 100644 --- a/YuppleMayham/include/gameplay/entity.h +++ b/YuppleMayham/include/gameplay/entity.h @@ -47,7 +47,7 @@ public: const std::shared_ptr getShader() const { return shader; } // TODO: right now there is no default behavior, but eventually the Entity class will be expanded to handle physics - virtual void update(float deltaTime) = 0; + virtual void update(double deltaTime) = 0; virtual void render(const std::shared_ptr& camera) = 0; protected: diff --git a/YuppleMayham/include/gameplay/game.h b/YuppleMayham/include/gameplay/game.h index 9c22b18..e507b0c 100644 --- a/YuppleMayham/include/gameplay/game.h +++ b/YuppleMayham/include/gameplay/game.h @@ -27,7 +27,7 @@ public: void handleInput(SDL_Event& e); - void update(float deltaTime); + void update(double deltaTime); void render(); const unsigned getGameState() const { return game_state; } diff --git a/YuppleMayham/include/gameplay/gameactor.h b/YuppleMayham/include/gameplay/gameactor.h index 835b82d..657b939 100644 --- a/YuppleMayham/include/gameplay/gameactor.h +++ b/YuppleMayham/include/gameplay/gameactor.h @@ -25,7 +25,7 @@ public: void addComponent(std::shared_ptr component); void pickupWeapon(std::shared_ptr weapon); void hookEventManager(std::shared_ptr eventManager); - void update(float deltaTime) override; + void update(double deltaTime) override; void render(const std::shared_ptr& camera) override; const std::optional> getHeldWeapon() const; diff --git a/YuppleMayham/include/gameplay/scene.h b/YuppleMayham/include/gameplay/scene.h index c485d84..d7a5983 100644 --- a/YuppleMayham/include/gameplay/scene.h +++ b/YuppleMayham/include/gameplay/scene.h @@ -26,7 +26,7 @@ class Scene public: Scene(SceneType type, std::shared_ptr resources); - void update(float deltaTime); + void update(double deltaTime); void render(); std::shared_ptr getPlayer() const; diff --git a/YuppleMayham/include/gameplay/weapons/bullet.h b/YuppleMayham/include/gameplay/weapons/bullet.h index f422729..78bc5d8 100644 --- a/YuppleMayham/include/gameplay/weapons/bullet.h +++ b/YuppleMayham/include/gameplay/weapons/bullet.h @@ -35,7 +35,7 @@ public: void addComponent(std::shared_ptr component); - void update(float deltaTime) override; + void update(double deltaTime) override; void render(const std::shared_ptr& camera) override; float getBulletDrop() const { return bulletDrop; } diff --git a/YuppleMayham/include/gameplay/weapons/bulletmanager.h b/YuppleMayham/include/gameplay/weapons/bulletmanager.h index 01b9d7b..4d14772 100644 --- a/YuppleMayham/include/gameplay/weapons/bulletmanager.h +++ b/YuppleMayham/include/gameplay/weapons/bulletmanager.h @@ -25,7 +25,7 @@ public: const std::shared_ptr& shader, const std::shared_ptr& sprite); - void update(float deltaTime); + void update(double deltaTime); void render(const std::shared_ptr& camera); void hookEventManager(const std::shared_ptr& eventManager); diff --git a/YuppleMayham/include/gameplay/weapons/weapon.h b/YuppleMayham/include/gameplay/weapons/weapon.h index 9ac11e6..2c3ce20 100644 --- a/YuppleMayham/include/gameplay/weapons/weapon.h +++ b/YuppleMayham/include/gameplay/weapons/weapon.h @@ -39,7 +39,7 @@ public: void hookEventManager(const std::shared_ptr& eventManager); void shoot(); void reload(); - void update(float deltaTime); + void update(double deltaTime); void render(const std::shared_ptr& camera); struct BulletData { diff --git a/YuppleMayham/include/utility/script.h b/YuppleMayham/include/utility/script.h index 7a0c42a..4975865 100644 --- a/YuppleMayham/include/utility/script.h +++ b/YuppleMayham/include/utility/script.h @@ -23,11 +23,6 @@ private: return result.valid(); } void registerGlobalUserTypes(); - - void performIncrementalGC(); - std::chrono::high_resolution_clock::time_point lastGCTime = std::chrono::high_resolution_clock::now(); - std::chrono::milliseconds gcInterval = std::chrono::milliseconds(16); - const int gcStepSize = 500; }; class AIScript : public Script { diff --git a/YuppleMayham/src/gameplay/ai.cpp b/YuppleMayham/src/gameplay/ai.cpp index 67b3093..171375b 100644 --- a/YuppleMayham/src/gameplay/ai.cpp +++ b/YuppleMayham/src/gameplay/ai.cpp @@ -23,8 +23,6 @@ void AI::attachBehaviourScript(const std::shared_ptr& behaviour) patrolFunc = this->behaviour->lua["patrol"]; if (this->behaviour->lua["alert"].valid()) alertFunc = this->behaviour->lua["alert"]; - this->behaviour->lua.set("actor", actor); - this->behaviour->lua.set("target", target); } void AI::update() diff --git a/YuppleMayham/src/gameplay/entity.cpp b/YuppleMayham/src/gameplay/entity.cpp index 7b50097..2b9c174 100644 --- a/YuppleMayham/src/gameplay/entity.cpp +++ b/YuppleMayham/src/gameplay/entity.cpp @@ -38,7 +38,7 @@ void Entity::addPhysicsComponent(const std::shared_ptr& physic this->physics = physics; } -void Entity::update(float deltaTime) +void Entity::update(double deltaTime) { if (physics && physics->rigidBody.velocity != glm::vec3(0.0f)) { diff --git a/YuppleMayham/src/gameplay/game.cpp b/YuppleMayham/src/gameplay/game.cpp index f13f328..cdeb216 100644 --- a/YuppleMayham/src/gameplay/game.cpp +++ b/YuppleMayham/src/gameplay/game.cpp @@ -81,7 +81,7 @@ void Game::handleInput(SDL_Event& e) inputHandler->handleInput(); } -void Game::update(float deltaTime) +void Game::update(double deltaTime) { if (currentScene) currentScene->update(deltaTime); diff --git a/YuppleMayham/src/gameplay/gameactor.cpp b/YuppleMayham/src/gameplay/gameactor.cpp index 02a38af..9b7e39d 100644 --- a/YuppleMayham/src/gameplay/gameactor.cpp +++ b/YuppleMayham/src/gameplay/gameactor.cpp @@ -47,7 +47,7 @@ void GameActor::setRotation(const float& rotation) updateModelMatrix(); } -void GameActor::update(float deltaTime) +void GameActor::update(double deltaTime) { Entity::update(deltaTime); diff --git a/YuppleMayham/src/gameplay/scene.cpp b/YuppleMayham/src/gameplay/scene.cpp index 244bbed..8957a9f 100644 --- a/YuppleMayham/src/gameplay/scene.cpp +++ b/YuppleMayham/src/gameplay/scene.cpp @@ -123,7 +123,7 @@ std::shared_ptr Scene::getPlayer() const return (!player) ? nullptr : player; } -void Scene::update(float deltaTime) +void Scene::update(double deltaTime) { for (const auto& [id, e] : entities) { diff --git a/YuppleMayham/src/gameplay/weapons/bullet.cpp b/YuppleMayham/src/gameplay/weapons/bullet.cpp index 1454067..e976f24 100644 --- a/YuppleMayham/src/gameplay/weapons/bullet.cpp +++ b/YuppleMayham/src/gameplay/weapons/bullet.cpp @@ -9,7 +9,7 @@ void Bullet::addComponent(std::shared_ptr component) components.push_back(component); } -void Bullet::update(float deltaTime) +void Bullet::update(double deltaTime) { Entity::update(deltaTime); diff --git a/YuppleMayham/src/gameplay/weapons/bulletmanager.cpp b/YuppleMayham/src/gameplay/weapons/bulletmanager.cpp index f3fc94b..87dc789 100644 --- a/YuppleMayham/src/gameplay/weapons/bulletmanager.cpp +++ b/YuppleMayham/src/gameplay/weapons/bulletmanager.cpp @@ -39,7 +39,7 @@ void BulletManager::addBullet(const unsigned int owner, const glm::vec3& fireFro bullets.emplace_back(bullet); } -void BulletManager::update(float deltaTime) +void BulletManager::update(double deltaTime) { for (auto& bullet : bullets) { diff --git a/YuppleMayham/src/gameplay/weapons/weapon.cpp b/YuppleMayham/src/gameplay/weapons/weapon.cpp index a9c2086..cc5a165 100644 --- a/YuppleMayham/src/gameplay/weapons/weapon.cpp +++ b/YuppleMayham/src/gameplay/weapons/weapon.cpp @@ -148,7 +148,7 @@ void Weapon::onHitCallback(std::shared_ptr target, std::shared_ptrgetGameState() & GAME_RUNNING) { Uint64 curCounter = SDL_GetPerformanceCounter(); - float deltaTime = ((curCounter - lastCounter) / freq); - deltaTime = (deltaTime < 1.f) ? deltaTime : 1.f; + double deltaTime = ((curCounter - lastCounter) / freq); + deltaTime = (deltaTime < 1.0) ? deltaTime : 1.0; SDL_PollEvent(&e); if (e.type == SDL_QUIT) game->quit(); diff --git a/YuppleMayham/src/utility/ftfont.cpp b/YuppleMayham/src/utility/ftfont.cpp index 7947982..9919f57 100644 --- a/YuppleMayham/src/utility/ftfont.cpp +++ b/YuppleMayham/src/utility/ftfont.cpp @@ -1,4 +1,5 @@ #include "utility/ftfont.h" +#include "utility/logger.h" #include #include @@ -97,6 +98,9 @@ bool Text::loadFonts(const std::string& font_folder) } // load every font in the fonts folder then create corresponding textures for each character of each font. std::filesystem::path folder(font_folder); + if (!std::filesystem::exists(folder) || !std::filesystem::is_directory(font_folder)) + ERROR_LOG("{} folder does not exist!", font_folder); + for (auto& file : std::filesystem::directory_iterator(folder)) { if (!file.path().has_extension() || !file.path().has_filename() || !file.exists() || file.is_directory()) diff --git a/YuppleMayham/src/utility/xmlloader.cpp b/YuppleMayham/src/utility/xmlloader.cpp index 49949f5..38c45ca 100644 --- a/YuppleMayham/src/utility/xmlloader.cpp +++ b/YuppleMayham/src/utility/xmlloader.cpp @@ -9,6 +9,8 @@ bool XMLLoader::loadScenes(const char* sceneFolder) { std::filesystem::path folder(sceneFolder); + if (!std::filesystem::exists(folder) || !std::filesystem::is_directory(folder)) + ERROR_LOG("'{}' folder not found!", sceneFolder); for (auto& file : std::filesystem::directory_iterator(folder)) { if (!file.path().has_extension() || !file.path().has_filename() || !file.exists() || file.is_directory())