diff --git a/rwgame/states/BenchmarkState.cpp b/rwgame/states/BenchmarkState.cpp index baba4cf6..6277373f 100644 --- a/rwgame/states/BenchmarkState.cpp +++ b/rwgame/states/BenchmarkState.cpp @@ -1,116 +1,102 @@ #include "BenchmarkState.hpp" -#include "RWGame.hpp" #include #include +#include "RWGame.hpp" BenchmarkState::BenchmarkState(RWGame* game, const std::string& benchfile) - : State(game) - , benchfile(benchfile) - , benchmarkTime(0.f) - , frameCounter(0) -{ + : State(game), benchfile(benchfile), benchmarkTime(0.f), frameCounter(0) { } -void BenchmarkState::enter() -{ - getWindow().hideCursor(); +void BenchmarkState::enter() { + getWindow().hideCursor(); - std::ifstream benchstream(benchfile); + std::ifstream benchstream(benchfile); - unsigned int clockHour; - unsigned int clockMinute; - benchstream >> clockHour; - benchstream.seekg(1,std::ios_base::cur); - benchstream >> clockMinute; + unsigned int clockHour; + unsigned int clockMinute; + benchstream >> clockHour; + benchstream.seekg(1, std::ios_base::cur); + benchstream >> clockMinute; - game->getWorld()->state->basic.gameHour = clockHour; - game->getWorld()->state->basic.gameMinute = clockMinute; + game->getWorld()->state->basic.gameHour = clockHour; + game->getWorld()->state->basic.gameMinute = clockMinute; - float time = 0.f; - glm::vec3 tmpPos; - while (benchstream) - { - TrackPoint point; - benchstream >> point.time; - if (!benchstream) break; - benchstream >> point.position.x; - if (!benchstream) break; - benchstream >> point.position.y; - if (!benchstream) break; - benchstream >> point.position.z; - if (!benchstream) break; - benchstream >> point.angle.x; - if (!benchstream) break; - benchstream >> point.angle.y; - if (!benchstream) break; - benchstream >> point.angle.z; - if (!benchstream) break; - benchstream >> point.angle.w; - if (!benchstream) break; - if (track.size() == 0) { - tmpPos = point.position; - } - float pointDist = glm::distance(tmpPos, point.position); - tmpPos = point.position; - point.time = time + pointDist / 50.f; - time = point.time; - duration = std::max(duration, point.time); - track.push_back(point); - } + float time = 0.f; + glm::vec3 tmpPos; + while (benchstream) { + TrackPoint point; + benchstream >> point.time; + if (!benchstream) break; + benchstream >> point.position.x; + if (!benchstream) break; + benchstream >> point.position.y; + if (!benchstream) break; + benchstream >> point.position.z; + if (!benchstream) break; + benchstream >> point.angle.x; + if (!benchstream) break; + benchstream >> point.angle.y; + if (!benchstream) break; + benchstream >> point.angle.z; + if (!benchstream) break; + benchstream >> point.angle.w; + if (!benchstream) break; + if (track.size() == 0) { + tmpPos = point.position; + } + float pointDist = glm::distance(tmpPos, point.position); + tmpPos = point.position; + point.time = time + pointDist / 50.f; + time = point.time; + duration = std::max(duration, point.time); + track.push_back(point); + } - std::cout << "Loaded " << track.size() << " points" << std::endl; + std::cout << "Loaded " << track.size() << " points" << std::endl; } -void BenchmarkState::exit() -{ - std::cout << "Results =============\n" - << "Benchmark: " << benchfile << "\n" - << "Frames: " << frameCounter << "\n" - << "Duration: " << duration << " seconds\n" - << "Avg frametime: " << std::setprecision(3) << (duration/frameCounter) - << " (" << (frameCounter/duration) << " fps)" << std::endl; +void BenchmarkState::exit() { + std::cout << "Results =============\n" + << "Benchmark: " << benchfile << "\n" + << "Frames: " << frameCounter << "\n" + << "Duration: " << duration << " seconds\n" + << "Avg frametime: " << std::setprecision(3) + << (duration / frameCounter) << " (" << (frameCounter / duration) + << " fps)" << std::endl; } -void BenchmarkState::tick(float dt) -{ - if (track.size() > 0) - { - TrackPoint& a = track.front(); - TrackPoint& b = track.back(); - for (TrackPoint& p : track) - { - if (benchmarkTime < p.time) - { - b = p; - break; - } - a = p; - } - if (benchmarkTime > duration) { - StateManager::get().exit(); - } - if (b.time != a.time) - { - float alpha = (benchmarkTime - a.time) / (b.time - a.time); - trackCam.position = glm::mix(a.position, b.position, alpha); - trackCam.rotation = glm::slerp(a.angle, b.angle, alpha); - } - benchmarkTime += dt; - } +void BenchmarkState::tick(float dt) { + if (track.size() > 0) { + TrackPoint& a = track.front(); + TrackPoint& b = track.back(); + for (TrackPoint& p : track) { + if (benchmarkTime < p.time) { + b = p; + break; + } + a = p; + } + if (benchmarkTime > duration) { + StateManager::get().exit(); + } + if (b.time != a.time) { + float alpha = (benchmarkTime - a.time) / (b.time - a.time); + trackCam.position = glm::mix(a.position, b.position, alpha); + trackCam.rotation = glm::slerp(a.angle, b.angle, alpha); + } + benchmarkTime += dt; + } } -void BenchmarkState::draw(GameRenderer* r) -{ - frameCounter++; - State::draw(r); +void BenchmarkState::draw(GameRenderer* r) { + frameCounter++; + State::draw(r); } -void BenchmarkState::handleEvent(const SDL_Event& e) -{ - State::handleEvent(e); +void BenchmarkState::handleEvent(const SDL_Event& e) { + State::handleEvent(e); } -const ViewCamera &BenchmarkState::getCamera() -{ - return trackCam; +const ViewCamera& BenchmarkState::getCamera() { + return trackCam; } diff --git a/rwgame/states/BenchmarkState.hpp b/rwgame/states/BenchmarkState.hpp index 0f1f1fb8..96915179 100644 --- a/rwgame/states/BenchmarkState.hpp +++ b/rwgame/states/BenchmarkState.hpp @@ -3,34 +3,34 @@ #include "State.hpp" -class BenchmarkState : public State -{ - struct TrackPoint { - float time; - glm::vec3 position; - glm::quat angle; - }; - std::vector track; +class BenchmarkState : public State { + struct TrackPoint { + float time; + glm::vec3 position; + glm::quat angle; + }; + std::vector track; - ViewCamera trackCam; + ViewCamera trackCam; - std::string benchfile; + std::string benchfile; + + float benchmarkTime; + float duration; + uint32_t frameCounter; - float benchmarkTime; - float duration; - uint32_t frameCounter; public: - BenchmarkState(RWGame* game, const std::string& benchfile); + BenchmarkState(RWGame* game, const std::string& benchfile); - virtual void enter(); - virtual void exit(); + virtual void enter(); + virtual void exit(); - virtual void tick(float dt); - virtual void draw(GameRenderer* r); + virtual void tick(float dt); + virtual void draw(GameRenderer* r); - virtual void handleEvent(const SDL_Event& event); + virtual void handleEvent(const SDL_Event& event); - const ViewCamera& getCamera(); + const ViewCamera& getCamera(); }; #endif diff --git a/rwgame/states/DebugState.cpp b/rwgame/states/DebugState.cpp index edc891c9..89c55ee0 100644 --- a/rwgame/states/DebugState.cpp +++ b/rwgame/states/DebugState.cpp @@ -1,47 +1,43 @@ #include "DebugState.hpp" -#include "RWGame.hpp" #include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include #include -#include -#include +#include "RWGame.hpp" constexpr float kDebugEntryHeight = 14.f; const glm::vec2 kDebugMenuOffset = glm::vec2(10.f, 50.f); -static void jumpCharacter(RWGame* game, CharacterObject* player, const glm::vec3& target, bool ground = true) -{ - glm::vec3 newPosition = target; - if (ground) { - newPosition = game->getWorld()->getGroundAtPosition(newPosition) + glm::vec3(0.f, 0.f, 1.f); - } - if( player ) - { - if( player->getCurrentVehicle() ) - { - player->getCurrentVehicle()->setPosition(newPosition); - } - else - { - player->setPosition(newPosition); - } - } +static void jumpCharacter(RWGame* game, CharacterObject* player, + const glm::vec3& target, bool ground = true) { + glm::vec3 newPosition = target; + if (ground) { + newPosition = game->getWorld()->getGroundAtPosition(newPosition) + + glm::vec3(0.f, 0.f, 1.f); + } + if (player) { + if (player->getCurrentVehicle()) { + player->getCurrentVehicle()->setPosition(newPosition); + } else { + player->setPosition(newPosition); + } + } } -Menu* DebugState::createDebugMenu() -{ - CharacterObject* player = nullptr; - if (game->getPlayer()) { - player = game->getPlayer()->getCharacter(); - } +Menu* DebugState::createDebugMenu() { + CharacterObject* player = nullptr; + if (game->getPlayer()) { + player = game->getPlayer()->getCharacter(); + } - Menu* m = new Menu(2); - m->offset = kDebugMenuOffset; + Menu* m = new Menu(2); + m->offset = kDebugMenuOffset; #if 0 m->addEntry(Menu::lambda("Random Vehicle", [this] { auto it = getWorld()->vehicleTypes.begin(); @@ -84,432 +80,414 @@ Menu* DebugState::createDebugMenu() }, entryHeight)); } #endif - m->addEntry(Menu::lambda("Jump to Debug Camera", [=] { - jumpCharacter(game, player, _debugCam.position + _debugCam.rotation * glm::vec3(3.f, 0.f, 0.f), false); - }, kDebugEntryHeight)); + m->addEntry(Menu::lambda("Jump to Debug Camera", + [=] { + jumpCharacter(game, player, + _debugCam.position + + _debugCam.rotation * + glm::vec3(3.f, 0.f, 0.f), + false); + }, + kDebugEntryHeight)); - m->addEntry(Menu::lambda("-Map", [=] { - this->enterMenu(createMapMenu()); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("-Vehicles", [=] { - this->enterMenu(createVehicleMenu()); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("-AI", [=] { - this->enterMenu(createAIMenu()); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("-Weapons", [=] { - this->enterMenu(createWeaponMenu()); - }, kDebugEntryHeight)); + m->addEntry(Menu::lambda("-Map", [=] { this->enterMenu(createMapMenu()); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda("-Vehicles", + [=] { this->enterMenu(createVehicleMenu()); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda("-AI", [=] { this->enterMenu(createAIMenu()); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda("-Weapons", + [=] { this->enterMenu(createWeaponMenu()); }, + kDebugEntryHeight)); - m->addEntry(Menu::lambda("Set Super Jump", [=] { - player->setJumpSpeed(20.f); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Set Normal Jump", [=] { - player->setJumpSpeed(CharacterObject::DefaultJumpSpeed); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Full Health", [=] { - player->getCurrentState().health = 100.f; - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Full Armour", [=] { - player->getCurrentState().armour = 100.f; - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Cull Here", [=] { - game->getRenderer()->setCullOverride(true, _debugCam); - }, kDebugEntryHeight)); + m->addEntry(Menu::lambda("Set Super Jump", + [=] { player->setJumpSpeed(20.f); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Set Normal Jump", + [=] { player->setJumpSpeed(CharacterObject::DefaultJumpSpeed); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda("Full Health", + [=] { player->getCurrentState().health = 100.f; }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda("Full Armour", + [=] { player->getCurrentState().armour = 100.f; }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Cull Here", + [=] { game->getRenderer()->setCullOverride(true, _debugCam); }, + kDebugEntryHeight)); + // Optional block if the player is in a vehicle + auto cv = player->getCurrentVehicle(); + if (cv) { + m->addEntry(Menu::lambda( + "Flip vehicle", + [=] { + cv->setRotation( + cv->getRotation() * + glm::quat(glm::vec3(0.f, glm::pi(), 0.f))); + }, + kDebugEntryHeight)); + } - // Optional block if the player is in a vehicle - auto cv = player->getCurrentVehicle(); - if(cv) { - m->addEntry(Menu::lambda("Flip vehicle", [=] { - cv->setRotation(cv->getRotation() * glm::quat(glm::vec3(0.f, glm::pi(), 0.f))); - }, kDebugEntryHeight)); - } - - return m; + return m; } -Menu* DebugState::createMapMenu() -{ - CharacterObject* player = nullptr; - if (game->getPlayer()) { - player = game->getPlayer()->getCharacter(); - } +Menu* DebugState::createMapMenu() { + CharacterObject* player = nullptr; + if (game->getPlayer()) { + player = game->getPlayer()->getCharacter(); + } - Menu* m = new Menu(2); - m->offset = kDebugMenuOffset; + Menu* m = new Menu(2); + m->offset = kDebugMenuOffset; - m->addEntry(Menu::lambda("Back", [=] { - this->enterMenu(createDebugMenu()); - }, kDebugEntryHeight)); + m->addEntry(Menu::lambda("Back", + [=] { this->enterMenu(createDebugMenu()); }, + kDebugEntryHeight)); - m->addEntry(Menu::lambda("Jump to Docks", [=] { - jumpCharacter(game, player, glm::vec3(1390.f, -837.f, 100.f)); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Jump to Garage", [=] { - jumpCharacter(game, player, glm::vec3(270.f, -605.f, 40.f)); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Jump to Airport", [=] { - jumpCharacter(game, player, glm::vec3(-950.f, -980.f, 12.f)); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Jump to Hideout", [=] { - jumpCharacter(game, player, glm::vec3(875.0, -309.0, 100.0)); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Jump to Luigi's", [=] { - jumpCharacter(game, player, glm::vec3(902.75, -425.56, 100.0)); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Jump to Hospital", [=] { - jumpCharacter(game, player, glm::vec3(1123.77, -569.15, 100.0)); - }, kDebugEntryHeight)); - m->addEntry(Menu::lambda("Unsolid garage doors", [=] { + m->addEntry(Menu::lambda( + "Jump to Docks", + [=] { jumpCharacter(game, player, glm::vec3(1390.f, -837.f, 100.f)); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Jump to Garage", + [=] { jumpCharacter(game, player, glm::vec3(270.f, -605.f, 40.f)); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Jump to Airport", + [=] { jumpCharacter(game, player, glm::vec3(-950.f, -980.f, 12.f)); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Jump to Hideout", + [=] { jumpCharacter(game, player, glm::vec3(875.0, -309.0, 100.0)); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Jump to Luigi's", + [=] { jumpCharacter(game, player, glm::vec3(902.75, -425.56, 100.0)); }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Jump to Hospital", + [=] { + jumpCharacter(game, player, glm::vec3(1123.77, -569.15, 100.0)); + }, + kDebugEntryHeight)); + m->addEntry(Menu::lambda( + "Unsolid garage doors", + [=] { - std::vector garageDoorModels { - "8ballsuburbandoor", - "amcogaragedoor", - "bankjobdoor", - "bombdoor", - "crushercrush", - "crushertop", - "door2_garage", - "door3_garage", - "door4_garage", - "door_bombshop", - "door_col_compnd_01", - "door_col_compnd_02", - "door_col_compnd_03", - "door_col_compnd_04", - "door_col_compnd_05", - "door_jmsgrage", - "door_sfehousegrge", - "double_garage_dr", - "impex_door", - "impexpsubgrgdoor", - "ind_plyrwoor", - "ind_slidedoor", - "jamesgrge_kb", - "leveldoor2", - "oddjgaragdoor", - "plysve_gragedoor", - "SalvGarage", - "shedgaragedoor", - "Sub_sprayshopdoor", - "towergaragedoor1", - "towergaragedoor2", - "towergaragedoor3", - "vheistlocdoor" - }; + std::vector garageDoorModels{ + "8ballsuburbandoor", "amcogaragedoor", + "bankjobdoor", "bombdoor", + "crushercrush", "crushertop", + "door2_garage", "door3_garage", + "door4_garage", "door_bombshop", + "door_col_compnd_01", "door_col_compnd_02", + "door_col_compnd_03", "door_col_compnd_04", + "door_col_compnd_05", "door_jmsgrage", + "door_sfehousegrge", "double_garage_dr", + "impex_door", "impexpsubgrgdoor", + "ind_plyrwoor", "ind_slidedoor", + "jamesgrge_kb", "leveldoor2", + "oddjgaragdoor", "plysve_gragedoor", + "SalvGarage", "shedgaragedoor", + "Sub_sprayshopdoor", "towergaragedoor1", + "towergaragedoor2", "towergaragedoor3", + "vheistlocdoor"}; - auto gw = game->getWorld(); - for(auto& i : gw->instancePool.objects) { - auto obj = static_cast(i.second); - if (std::find(garageDoorModels.begin(), garageDoorModels.end(), obj->model->name) != garageDoorModels.end()) { - obj->setSolid(false); - } - } - }, kDebugEntryHeight)); + auto gw = game->getWorld(); + for (auto& i : gw->instancePool.objects) { + auto obj = static_cast(i.second); + if (std::find(garageDoorModels.begin(), garageDoorModels.end(), + obj->model->name) != garageDoorModels.end()) { + obj->setSolid(false); + } + } + }, + kDebugEntryHeight)); - return m; + return m; } -Menu* DebugState::createVehicleMenu() -{ - Menu* m = new Menu(2); - m->offset = kDebugMenuOffset; +Menu* DebugState::createVehicleMenu() { + Menu* m = new Menu(2); + m->offset = kDebugMenuOffset; - m->addEntry(Menu::lambda("Back", [=] { - this->enterMenu(createDebugMenu()); - }, kDebugEntryHeight)); + m->addEntry(Menu::lambda("Back", + [=] { this->enterMenu(createDebugMenu()); }, + kDebugEntryHeight)); - const std::map kVehicleTypes = { - {"Landstalker", 90}, - {"Taxi", 110}, - {"Firetruck", 97}, - {"Police", 116}, - {"Ambulance", 106}, - {"Bobcat", 112}, - {"Banshee", 119}, - {"Rhino", 122}, - {"Barracks", 123}, - {"Rumpo", 130}, - {"Columbian", 138}, - {"Dodo", 126}, - {"Speeder", 142}, - {"Yakuza", 136}, - }; + const std::map kVehicleTypes = { + {"Landstalker", 90}, {"Taxi", 110}, {"Firetruck", 97}, + {"Police", 116}, {"Ambulance", 106}, {"Bobcat", 112}, + {"Banshee", 119}, {"Rhino", 122}, {"Barracks", 123}, + {"Rumpo", 130}, {"Columbian", 138}, {"Dodo", 126}, + {"Speeder", 142}, {"Yakuza", 136}, + }; - for (auto& e : kVehicleTypes) { - m->addEntry(Menu::lambda(e.first, [=] { spawnVehicle(e.second); }, - kDebugEntryHeight)); - } + for (auto& e : kVehicleTypes) { + m->addEntry(Menu::lambda(e.first, [=] { spawnVehicle(e.second); }, + kDebugEntryHeight)); + } - return m; + return m; } -Menu* DebugState::createAIMenu() -{ - Menu* m = new Menu(2); - m->offset = kDebugMenuOffset; +Menu* DebugState::createAIMenu() { + Menu* m = new Menu(2); + m->offset = kDebugMenuOffset; - m->addEntry(Menu::lambda("Back", [=] { - this->enterMenu(createDebugMenu()); - }, kDebugEntryHeight)); + m->addEntry(Menu::lambda("Back", + [=] { this->enterMenu(createDebugMenu()); }, + kDebugEntryHeight)); - const std::map kPedTypes = { - {"Triad", 12}, - {"Cop", 1}, - {"SWAT", 2}, - {"FBI", 3}, - {"Fireman", 6}, - {"Construction", 74}, - }; + const std::map kPedTypes = { + {"Triad", 12}, {"Cop", 1}, {"SWAT", 2}, + {"FBI", 3}, {"Fireman", 6}, {"Construction", 74}, + }; - for (auto& e : kPedTypes) { - m->addEntry(Menu::lambda(e.first + " Follower", [=] { - spawnFollower(e.second); - }, kDebugEntryHeight)); - } + for (auto& e : kPedTypes) { + m->addEntry(Menu::lambda(e.first + " Follower", + [=] { spawnFollower(e.second); }, + kDebugEntryHeight)); + } - m->addEntry(Menu::lambda("Kill All Peds", [=] { - for (auto& p : game->getWorld()->pedestrianPool.objects) { - if (p.second->getLifetime() == GameObject::PlayerLifetime) { - continue; - } - p.second->takeDamage({p.second->getPosition(), - p.second->getPosition(), 100.f, - GameObject::DamageInfo::Explosion, 0.f}); - } - }, kDebugEntryHeight)); - return m; + m->addEntry(Menu::lambda( + "Kill All Peds", + [=] { + for (auto& p : game->getWorld()->pedestrianPool.objects) { + if (p.second->getLifetime() == GameObject::PlayerLifetime) { + continue; + } + p.second->takeDamage({p.second->getPosition(), + p.second->getPosition(), 100.f, + GameObject::DamageInfo::Explosion, 0.f}); + } + }, + kDebugEntryHeight)); + return m; } -Menu*DebugState::createWeaponMenu() -{ - Menu* m = new Menu(2); - m->offset = kDebugMenuOffset; +Menu* DebugState::createWeaponMenu() { + Menu* m = new Menu(2); + m->offset = kDebugMenuOffset; - m->addEntry(Menu::lambda("Back", [=] { - this->enterMenu(createDebugMenu()); - }, kDebugEntryHeight)); + m->addEntry(Menu::lambda("Back", + [=] { this->enterMenu(createDebugMenu()); }, + kDebugEntryHeight)); - for (int i = 1; i < maxInventorySlots; ++i) { - auto item = getWorld()->getInventoryItem(i); - auto& name = getWorld()->data->weaponData[i]->name; - m->addEntry(Menu::lambda(name, [=] { - giveItem(item); - }, kDebugEntryHeight)); - } + for (int i = 1; i < maxInventorySlots; ++i) { + auto item = getWorld()->getInventoryItem(i); + auto& name = getWorld()->data->weaponData[i]->name; + m->addEntry( + Menu::lambda(name, [=] { giveItem(item); }, kDebugEntryHeight)); + } - return m; + return m; } DebugState::DebugState(RWGame* game, const glm::vec3& vp, const glm::quat& vd) - : State(game) - , _invertedY(game->getConfig().getInputInvertY()) -{ - this->enterMenu(createDebugMenu()); + : State(game), _invertedY(game->getConfig().getInputInvertY()) { + this->enterMenu(createDebugMenu()); - _debugCam.position = vp; - _debugCam.rotation = vd; + _debugCam.position = vp; + _debugCam.rotation = vd; } -void DebugState::enter() -{ - getWindow().showCursor(); +void DebugState::enter() { + getWindow().showCursor(); } -void DebugState::exit() -{ - +void DebugState::exit() { } -void DebugState::tick(float dt) -{ - /*if(debugObject) { - auto p = debugObject->getPosition(); - ss << "Position: " << p.x << " " << p.y << " " << p.z << std::endl; - ss << "Health: " << debugObject->mHealth << std::endl; - if(debugObject->model) { - auto m = debugObject->model; - ss << "Textures: " << std::endl; - for(auto it = m->geometries.begin(); it != m->geometries.end(); - ++it ) - { - auto g = *it; - for(auto itt = g->materials.begin(); itt != g->materials.end(); - ++itt) - { - for(auto tit = itt->textures.begin(); tit != itt->textures.end(); - ++tit) - { - ss << " " << tit->name << std::endl; - } - } - } - } - if(debugObject->type() == GameObject::Vehicle) { - GTAVehicle* vehicle = static_cast(debugObject); - ss << "ID: " << vehicle->info->handling.ID << std::endl; - } - }*/ +void DebugState::tick(float dt) { + /*if(debugObject) { + auto p = debugObject->getPosition(); + ss << "Position: " << p.x << " " << p.y << " " << p.z << std::endl; + ss << "Health: " << debugObject->mHealth << std::endl; + if(debugObject->model) { + auto m = debugObject->model; + ss << "Textures: " << std::endl; + for(auto it = m->geometries.begin(); it != m->geometries.end(); + ++it ) + { + auto g = *it; + for(auto itt = g->materials.begin(); itt != g->materials.end(); + ++itt) + { + for(auto tit = itt->textures.begin(); tit != + itt->textures.end(); + ++tit) + { + ss << " " << tit->name << std::endl; + } + } + } + } + if(debugObject->type() == GameObject::Vehicle) { + GTAVehicle* vehicle = static_cast(debugObject); + ss << "ID: " << vehicle->info->handling.ID << std::endl; + } + }*/ - if (_freeLook) { - _debugCam.rotation = glm::angleAxis(_debugLook.x, glm::vec3(0.f, 0.f, 1.f)) - * glm::angleAxis(_debugLook.y, glm::vec3(0.f, 1.f, 0.f)); + if (_freeLook) { + _debugCam.rotation = + glm::angleAxis(_debugLook.x, glm::vec3(0.f, 0.f, 1.f)) * + glm::angleAxis(_debugLook.y, glm::vec3(0.f, 1.f, 0.f)); - _debugCam.position += _debugCam.rotation * _movement * dt * (_sonicMode ? 500.f : 50.f); - } + _debugCam.position += + _debugCam.rotation * _movement * dt * (_sonicMode ? 500.f : 50.f); + } } -void DebugState::draw(GameRenderer* r) -{ - // Draw useful information like camera position. - std::stringstream ss; - ss << "Camera Position: " << glm::to_string(_debugCam.position); +void DebugState::draw(GameRenderer* r) { + // Draw useful information like camera position. + std::stringstream ss; + ss << "Camera Position: " << glm::to_string(_debugCam.position); - TextRenderer::TextInfo ti; - ti.text = GameStringUtil::fromString(ss.str()); - ti.font = 2; - ti.screenPosition = glm::vec2( 10.f, 10.f ); - ti.size = 15.f; - ti.baseColour = glm::u8vec3(255); - r->text.renderText(ti); + TextRenderer::TextInfo ti; + ti.text = GameStringUtil::fromString(ss.str()); + ti.font = 2; + ti.screenPosition = glm::vec2(10.f, 10.f); + ti.size = 15.f; + ti.baseColour = glm::u8vec3(255); + r->text.renderText(ti); - State::draw(r); + State::draw(r); } -void DebugState::handleEvent(const SDL_Event& event) -{ - switch(event.type) { - case SDL_KEYDOWN: - switch(event.key.keysym.sym) { - case SDLK_ESCAPE: - StateManager::get().exit(); - break; - case SDLK_w: - _movement.x = 1.f; - break; - case SDLK_s: - _movement.x =-1.f; - break; - case SDLK_a: - _movement.y = 1.f; - break; - case SDLK_d: - _movement.y =-1.f; - break; - case SDLK_f: - _freeLook = !_freeLook; - if (_freeLook) - getWindow().hideCursor(); - else - getWindow().showCursor(); - break; - case SDLK_p: - printCameraDetails(); - break; - case SDLK_LSHIFT: - _sonicMode = true; - break; - default: break; - } +void DebugState::handleEvent(const SDL_Event& event) { + switch (event.type) { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_ESCAPE: + StateManager::get().exit(); + break; + case SDLK_w: + _movement.x = 1.f; + break; + case SDLK_s: + _movement.x = -1.f; + break; + case SDLK_a: + _movement.y = 1.f; + break; + case SDLK_d: + _movement.y = -1.f; + break; + case SDLK_f: + _freeLook = !_freeLook; + if (_freeLook) + getWindow().hideCursor(); + else + getWindow().showCursor(); + break; + case SDLK_p: + printCameraDetails(); + break; + case SDLK_LSHIFT: + _sonicMode = true; + break; + default: + break; + } - break; + break; - case SDL_KEYUP: - switch(event.key.keysym.sym) { - case SDLK_w: - case SDLK_s: - _movement.x = 0.f; - break; - case SDLK_a: - case SDLK_d: - _movement.y = 0.f; - break; - case SDLK_LSHIFT: - _sonicMode = false; - break; - default: break; - } + case SDL_KEYUP: + switch (event.key.keysym.sym) { + case SDLK_w: + case SDLK_s: + _movement.x = 0.f; + break; + case SDLK_a: + case SDLK_d: + _movement.y = 0.f; + break; + case SDLK_LSHIFT: + _sonicMode = false; + break; + default: + break; + } - break; + break; - case SDL_MOUSEMOTION: - if (game->hasFocus()) - { - glm::ivec2 screenSize = getWindow().getSize(); - glm::vec2 mouseMove(event.motion.xrel / static_cast(screenSize.x), - event.motion.yrel / static_cast(screenSize.y)); + case SDL_MOUSEMOTION: + if (game->hasFocus()) { + glm::ivec2 screenSize = getWindow().getSize(); + glm::vec2 mouseMove( + event.motion.xrel / static_cast(screenSize.x), + event.motion.yrel / static_cast(screenSize.y)); - if (!_invertedY) - mouseMove.y = -mouseMove.y; + if (!_invertedY) mouseMove.y = -mouseMove.y; - _debugLook.x -= mouseMove.x; + _debugLook.x -= mouseMove.x; - float qpi = glm::half_pi(); - _debugLook.y -= glm::clamp(mouseMove.y, -qpi, qpi); - } - break; + float qpi = glm::half_pi(); + _debugLook.y -= glm::clamp(mouseMove.y, -qpi, qpi); + } + break; - default: break; - } - State::handleEvent(event); + default: + break; + } + State::handleEvent(event); } -void DebugState::printCameraDetails() -{ - std::cout << " " << _debugCam.position.x << " " << _debugCam.position.y << " " << _debugCam.position.z - << " " << _debugCam.rotation.x << " " << _debugCam.rotation.y << " " << _debugCam.rotation.z - << " " << _debugCam.rotation.w << std::endl; +void DebugState::printCameraDetails() { + std::cout << " " << _debugCam.position.x << " " << _debugCam.position.y + << " " << _debugCam.position.z << " " << _debugCam.rotation.x + << " " << _debugCam.rotation.y << " " << _debugCam.rotation.z + << " " << _debugCam.rotation.w << std::endl; } -void DebugState::spawnVehicle(unsigned int id) -{ - auto ch = game->getPlayer()->getCharacter(); - if (!ch) - return; +void DebugState::spawnVehicle(unsigned int id) { + auto ch = game->getPlayer()->getCharacter(); + if (!ch) return; - auto playerRot = ch->getRotation(); - auto spawnPos = ch->getPosition(); - spawnPos += playerRot * glm::vec3(0.f, 3.f, 0.f); - auto spawnRot = glm::quat( - glm::vec3(0.f, 0.f, glm::roll(playerRot) + glm::half_pi())); - getWorld()->createVehicle(id, spawnPos, spawnRot); + auto playerRot = ch->getRotation(); + auto spawnPos = ch->getPosition(); + spawnPos += playerRot * glm::vec3(0.f, 3.f, 0.f); + auto spawnRot = glm::quat( + glm::vec3(0.f, 0.f, glm::roll(playerRot) + glm::half_pi())); + getWorld()->createVehicle(id, spawnPos, spawnRot); } -void DebugState::spawnFollower(unsigned int id) -{ - auto ch = game->getPlayer()->getCharacter(); - if(! ch) return; +void DebugState::spawnFollower(unsigned int id) { + auto ch = game->getPlayer()->getCharacter(); + if (!ch) return; - glm::vec3 fwd = ch->rotation * glm::vec3(0.f, 1.f, 0.f); + glm::vec3 fwd = ch->rotation * glm::vec3(0.f, 1.f, 0.f); - glm::vec3 hit, normal; - if(game->hitWorldRay(ch->position + (fwd * 10.f), {0.f, 0.f, -2.f}, hit, normal)) { - auto spawnPos = hit + normal; - auto follower = game->getWorld()->createPedestrian(id, spawnPos); - jumpCharacter(game, follower, spawnPos); - follower->controller->setGoal(CharacterController::FollowLeader); - follower->controller->setTargetCharacter(ch); - } + glm::vec3 hit, normal; + if (game->hitWorldRay(ch->position + (fwd * 10.f), {0.f, 0.f, -2.f}, hit, + normal)) { + auto spawnPos = hit + normal; + auto follower = game->getWorld()->createPedestrian(id, spawnPos); + jumpCharacter(game, follower, spawnPos); + follower->controller->setGoal(CharacterController::FollowLeader); + follower->controller->setTargetCharacter(ch); + } } -void DebugState::giveItem(InventoryItem* item) -{ - CharacterObject* player = nullptr; - if (game->getPlayer()) { - player = game->getPlayer()->getCharacter(); - } +void DebugState::giveItem(InventoryItem* item) { + CharacterObject* player = nullptr; + if (game->getPlayer()) { + player = game->getPlayer()->getCharacter(); + } - if (player) { - player->addToInventory(item); - auto& wep = - player->getCurrentState().weapons[item->getInventorySlot()]; - wep.bulletsTotal = 100; - wep.bulletsClip = 0; - } + if (player) { + player->addToInventory(item); + auto& wep = player->getCurrentState().weapons[item->getInventorySlot()]; + wep.bulletsTotal = 100; + wep.bulletsClip = 0; + } } -const ViewCamera &DebugState::getCamera() -{ - return _debugCam; +const ViewCamera& DebugState::getCamera() { + return _debugCam; } diff --git a/rwgame/states/DebugState.hpp b/rwgame/states/DebugState.hpp index 12a92c4a..86257cad 100644 --- a/rwgame/states/DebugState.hpp +++ b/rwgame/states/DebugState.hpp @@ -3,39 +3,39 @@ #include "State.hpp" -class DebugState : public State -{ - ViewCamera _debugCam; - glm::vec3 _movement; - glm::vec2 _debugLook; - bool _freeLook = false; - bool _sonicMode = false; - bool _invertedY; +class DebugState : public State { + ViewCamera _debugCam; + glm::vec3 _movement; + glm::vec2 _debugLook; + bool _freeLook = false; + bool _sonicMode = false; + bool _invertedY; - Menu* createDebugMenu(); - Menu* createMapMenu(); - Menu* createVehicleMenu(); - Menu* createAIMenu(); - Menu* createWeaponMenu(); + Menu* createDebugMenu(); + Menu* createMapMenu(); + Menu* createVehicleMenu(); + Menu* createAIMenu(); + Menu* createWeaponMenu(); public: - DebugState(RWGame* game, const glm::vec3& vp = {}, const glm::quat& vd = {}); + DebugState(RWGame* game, const glm::vec3& vp = {}, + const glm::quat& vd = {}); - virtual void enter(); - virtual void exit(); + virtual void enter(); + virtual void exit(); - virtual void tick(float dt); - virtual void draw(GameRenderer* r); + virtual void tick(float dt); + virtual void draw(GameRenderer* r); - virtual void handleEvent(const SDL_Event& event); + virtual void handleEvent(const SDL_Event& event); - void printCameraDetails(); + void printCameraDetails(); - void spawnVehicle(unsigned int id); - void spawnFollower(unsigned int id); - void giveItem(InventoryItem* item); + void spawnVehicle(unsigned int id); + void spawnFollower(unsigned int id); + void giveItem(InventoryItem* item); - const ViewCamera& getCamera(); + const ViewCamera& getCamera(); }; -#endif // DEBUGSTATE_HPP +#endif // DEBUGSTATE_HPP diff --git a/rwgame/states/IngameState.cpp b/rwgame/states/IngameState.cpp index f7260e71..88c22b1d 100644 --- a/rwgame/states/IngameState.cpp +++ b/rwgame/states/IngameState.cpp @@ -1,20 +1,20 @@ #include "IngameState.hpp" -#include "RWGame.hpp" -#include "PauseState.hpp" #include "DebugState.hpp" #include "DrawUI.hpp" +#include "PauseState.hpp" +#include "RWGame.hpp" #include -#include -#include -#include -#include #include -#include -#include -#include -#include