1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 20:02:40 +01:00

Add --newgame switch to RWGame

+ Starts the game script execution without showing the menu
This commit is contained in:
Daniel Evans 2015-04-03 01:26:20 +01:00
parent cdff0aa275
commit c3debe530f
5 changed files with 49 additions and 41 deletions

View File

@ -2,6 +2,8 @@
#include "State.hpp"
#include "loadingstate.hpp"
#include "DrawUI.hpp"
#include "ingamestate.hpp"
#include "menustate.hpp"
#include <engine/GameObject.hpp>
#include <engine/GameState.hpp>
@ -23,6 +25,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;
for( int i = 1; i < argc; ++i )
{
@ -38,6 +41,10 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
{
fullscreen = true;
}
if( strcmp( "--newgame", argv[i] ) == 0 )
{
newgame = true;
}
}
@ -86,7 +93,18 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
engine->gameData.loadTXD(name + ".txd");
}
StateManager::get().enter(new LoadingState(this));
auto loading = new LoadingState(this);
if( newgame )
{
loading->setNextState(new IngameState(this));
}
else
{
loading->setNextState(new MenuState(this));
}
StateManager::get().enter(loading);
engine->logInfo("Started");
}

View File

@ -15,18 +15,8 @@
#define AUTOLOOK_TIME 2.f
IngameState::IngameState(RWGame* game, bool test)
: State(game), autolookTimer(0.f)
: State(game), started(false), test(test), autolookTimer(0.f)
{
if( test ) {
startTest();
}
else {
getWorld()->runScript("data/main.scm");
}
// Start playing city.wav
getWorld()->sound.playBackground( getWorld()->gameData.getDataPath() + "/audio/City.wav" );
}
void IngameState::startTest()
@ -76,27 +66,10 @@ void IngameState::startTest()
}
}
void IngameState::spawnPlayerVehicle()
void IngameState::startGame()
{
#if 0
if(! getWorld()->state.player ) return;
glm::vec3 hit, normal;
if(game->hitWorldRay(hit, normal)) {
// Pick random vehicle.
auto it = getWorld()->vehicleTypes.begin();
std::uniform_int_distribution<int> uniform(0, 9);
for(size_t i = 0, n = uniform(getWorld()->randomEngine); i != n; i++) {
it++;
}
auto spawnpos = hit + normal;
auto vehicle = getWorld()->createVehicle(it->first, spawnpos,
glm::quat(glm::vec3(0.f, 0.f, -_lookAngles.x * PiOver180)));
getWorld()->state.player->getCharacter()->enterVehicle(vehicle, 0);
}
#endif
getWorld()->runScript("data/main.scm");
getWorld()->sound.playBackground( getWorld()->gameData.getDataPath() + "/audio/City.wav" );
}
PlayerController *IngameState::getPlayer()
@ -106,7 +79,16 @@ PlayerController *IngameState::getPlayer()
void IngameState::enter()
{
if( ! started )
{
if( test ) {
startTest();
}
else {
startGame();
}
started = true;
}
}
void IngameState::exit()

View File

@ -7,6 +7,8 @@ class PlayerController;
class IngameState : public State
{
bool started;
bool test;
ViewCamera _look;
glm::vec2 _lookAngles;
glm::vec3 _movement;
@ -15,7 +17,7 @@ public:
IngameState(RWGame* game, bool test = false);
void startTest();
void spawnPlayerVehicle();
void startGame();
/** shortcut for getWorld()->state.player->getCharacter() */
PlayerController* getPlayer();

View File

@ -1,9 +1,8 @@
#include "loadingstate.hpp"
#include "menustate.hpp"
#include "RWGame.hpp"
LoadingState::LoadingState(RWGame* game)
: State(game)
: State(game), next(nullptr)
{
}
@ -35,13 +34,17 @@ void LoadingState::exit()
void LoadingState::tick(float dt)
{
// Check to see if the GameWorld has run out of jobs
// (i.e. it's time to open the main menu)
// If background work is completed, switch to the next state
if( getWorld()->_work->isEmpty() ) {
StateManager::get().exec(new MenuState(game));
StateManager::get().exec(next);
}
}
void LoadingState::setNextState(State* nextState)
{
next = nextState;
}
void LoadingState::handleEvent(const sf::Event &e)
{
State::handleEvent(e);
@ -52,8 +55,8 @@ void LoadingState::draw(GameRenderer* r)
// Display some manner of loading screen.
TextRenderer::TextInfo ti;
ti.text = "Loading...";
ti.screenPosition = glm::vec2( -1.f, 0.5f );
ti.size = 0.1f;
ti.screenPosition = glm::vec2( 50.f, 50.f );
ti.size = 10.f;
ti.font = 2;
r->text.renderText(ti);
}

View File

@ -5,6 +5,7 @@
class LoadingState : public State
{
State* next;
public:
LoadingState(RWGame* game);
@ -15,6 +16,8 @@ public:
virtual void draw(GameRenderer* r);
void setNextState(State* nextState);
virtual void handleEvent(const sf::Event& event);
};