From a54e4a384ed173ffa576ef142329af40f0e5a9b1 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Sat, 4 Apr 2015 17:48:36 +0100 Subject: [PATCH] Improve test state * Move test spawn to the parking garage * Add --test option to start a new testing session * Add information about camera position to DebugState --- rwgame/RWGame.cpp | 7 ++++++- rwgame/debugstate.cpp | 18 ++++++++++++++++++ rwgame/debugstate.hpp | 1 + rwgame/ingamestate.cpp | 29 ++++++++++++----------------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index 9e9008d7..27eef17c 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -32,6 +32,7 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[]) size_t w = GAME_WINDOW_WIDTH, h = GAME_WINDOW_HEIGHT; bool fullscreen = false; bool newgame = false; + bool test = false; bool debugscript = false; for( int i = 1; i < argc; ++i ) @@ -52,6 +53,10 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[]) { newgame = true; } + if( strcmp( "--test", argv[i] ) == 0 ) + { + test = true; + } if( strcmp( "--debug", argv[i] ) == 0 ) { debugscript = true; @@ -123,7 +128,7 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[]) auto loading = new LoadingState(this); if( newgame ) { - loading->setNextState(new IngameState(this)); + loading->setNextState(new IngameState(this,test)); } else { diff --git a/rwgame/debugstate.cpp b/rwgame/debugstate.cpp index 3d690b2f..7bf5762a 100644 --- a/rwgame/debugstate.cpp +++ b/rwgame/debugstate.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include void jumpCharacter(RWGame* game, CharacterController* controller, const glm::vec3& target) { @@ -155,6 +157,22 @@ void DebugState::tick(float dt) } } +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 = ss.str(); + ti.font = 2; + ti.screenPosition = glm::vec2( 10.f, 10.f ); + ti.size = 15.f; + r->text.renderText(ti); + + State::draw(r); +} + void DebugState::handleEvent(const sf::Event &e) { switch(e.type) { diff --git a/rwgame/debugstate.hpp b/rwgame/debugstate.hpp index 6f9d54d8..433f99d4 100644 --- a/rwgame/debugstate.hpp +++ b/rwgame/debugstate.hpp @@ -17,6 +17,7 @@ public: virtual void exit(); virtual void tick(float dt); + virtual void draw(GameRenderer* r); virtual void handleEvent(const sf::Event& event); diff --git a/rwgame/ingamestate.cpp b/rwgame/ingamestate.cpp index 219bcf52..06343414 100644 --- a/rwgame/ingamestate.cpp +++ b/rwgame/ingamestate.cpp @@ -22,7 +22,7 @@ IngameState::IngameState(RWGame* game, bool test) void IngameState::startTest() { - auto playerChar = getWorld()->createPedestrian(1, {-1000.f, -990.f, 13.f}); + auto playerChar = getWorld()->createPedestrian(1, {270.f, -605.f, 40.f}); auto player = new PlayerController(playerChar); getWorld()->state.player = player; @@ -31,7 +31,7 @@ void IngameState::startTest() _playerCharacter->addToInventory(bat); _playerCharacter->setActiveItem(bat->getInventorySlot());*/ - glm::vec3 itemspawn(-1000.f, -980.f, 11.0f); + glm::vec3 itemspawn( 276.5f, -609.f, 36.5f); for( auto& w : getWorld()->gameData.weaponData ) { if( w.first == "unarmed" ) continue; getWorld()->objects.insert(new ItemPickup(getWorld(), itemspawn, @@ -39,8 +39,10 @@ void IngameState::startTest() itemspawn.x += 2.5f; } - auto carPos = glm::vec3( -1000.f, -1000.f, 12.f ); - auto boatPos = glm::vec3( -1000.f, -1040.f, 5.f ); + auto carPos = glm::vec3( 286.f, -591.f, 37.f ); + auto carRot = glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)); + //auto boatPos = glm::vec3( -1000.f, -1040.f, 5.f ); + int i = 0; for( auto& vi : getWorld()->objectTypes ) { switch( vi.first ) { case 140: continue; @@ -48,28 +50,21 @@ void IngameState::startTest() } if( vi.second->class_type == ObjectInformation::_class("CARS") ) { + if ( i++ > 20 ) break; auto vehicle = std::static_pointer_cast(vi.second); - auto sp = carPos; - if( vehicle->type == VehicleData::BOAT ) { - sp = boatPos; - } + auto& sp = carPos; + auto& sr = carRot; + auto v = getWorld()->createVehicle(vi.first, sp, sr); - auto v = getWorld()->createVehicle(vi.first, sp, glm::quat()); - - if( vehicle->type == VehicleData::BOAT ) { - boatPos -= glm::vec3( 2.f + v->info->handling.dimensions.x, 0.f, 0.f); - } - else { - carPos -= glm::vec3( 2.f + v->info->handling.dimensions.x, 0.f, 0.f); - } + sp += sr * glm::vec3( 2.f + v->info->handling.dimensions.x, 0.f, 0.f); } } } void IngameState::startGame() { - game->startScript("data/main.scm"); + game->startScript("data/main.scm"); getWorld()->sound.playBackground( getWorld()->gameData.getDataPath() + "/audio/City.wav" ); }