1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 15:02:34 +02:00

Refactor GameWorld into GameState

+ GameState now contains a GameWorld point to store the runtime world
data
This commit is contained in:
Daniel Evans 2015-04-27 15:31:39 +01:00
parent 0507bfdae6
commit 25f62a0a47
19 changed files with 356 additions and 317 deletions

View File

@ -7,6 +7,7 @@
#include <map>
#include <vector>
class GameWorld;
class GameObject;
class PlayerController;
struct CutsceneData;
@ -95,7 +96,8 @@ struct BlipData
};
/**
* Global Gameplay data, that mostly persists across game saves.
* Gameplay state object that holds persistent state, and references runtime
* world state.
*/
struct GameState
{
@ -169,6 +171,11 @@ struct GameState
std::map<int, BlipData> radarBlips;
/**
* World to use for this state, this isn't saved, just used at runtime
*/
GameWorld* world;
GameState();
/**

View File

@ -7,7 +7,7 @@ class Logger;
#include <GL/glew.h>
class GameData;
#include <engine/GameState.hpp>
class GameState;
#include <ai/AIGraphNode.hpp>
#include <ai/AIGraph.hpp>
@ -151,7 +151,7 @@ public:
/**
* Gameplay state
*/
GameState state;
GameState* state;
/**
* State of playing sounds

View File

@ -17,7 +17,7 @@
* the native pointer size */
#define SCM_VARIABLE_SIZE sizeof(void*)
class GameWorld;
class GameState;
class SCMFile;
@ -146,7 +146,7 @@ struct SCMBreakpoint
class ScriptMachine
{
public:
ScriptMachine(GameWorld* world, SCMFile* file, SCMOpcodes* ops);
ScriptMachine(GameState* state, SCMFile* file, SCMOpcodes* ops);
~ScriptMachine();
SCMFile* getFile() const { return _file; }
@ -155,7 +155,7 @@ public:
SCMByte* getGlobals();
GameWorld* getWorld() const { return _world; }
GameState* getState() const { return state; }
typedef std::function<void (const SCMBreakpoint&)> BreakpointHandler;
@ -187,7 +187,7 @@ public:
private:
SCMFile* _file;
SCMOpcodes* _ops;
GameWorld* _world;
GameState* state;
std::vector<SCMThread> _activeThreads;

View File

@ -11,6 +11,9 @@ class ScriptMachine;
class ScriptModule;
struct SCMThread;
class GameState;
class GameWorld;
typedef uint16_t SCMOpcode;
typedef char SCMByte;
@ -84,7 +87,10 @@ public:
const SCMParams& getParameters() const { return *parameters; }
SCMThread* getThread() const { return thread; }
ScriptMachine* getVM() const { return machine; }
// Helper method to get the current state
GameState* getState() const;
GameWorld* getWorld() const;
const SCMOpcodeParameter& operator[](unsigned int arg) const
{
return parameters->at(arg);

View File

@ -1,5 +1,6 @@
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <engine/GameState.hpp>
#include <loaders/LoaderIPL.hpp>
#include <loaders/LoaderDFF.hpp>
#include <loaders/LoaderIDE.hpp>
@ -551,7 +552,7 @@ void GameData::loadSplash(const std::string &name)
loadTXD(lower + ".txd", false);
engine->state.currentSplash = lower;
engine->state->currentSplash = lower;
}
FileHandle GameData::openFile(const std::string &name)

View File

@ -25,7 +25,8 @@ hour(0),
minute(0),
cameraNear(0.1f),
cameraFixed(false),
cameraTarget(nullptr)
cameraTarget(nullptr),
world(nullptr)
{
}

View File

@ -1,5 +1,6 @@
#include <engine/GameWorld.hpp>
#include <engine/GameData.hpp>
#include <engine/GameState.hpp>
#include <core/Logger.hpp>
@ -245,8 +246,8 @@ CutsceneObject *GameWorld::createCutsceneObject(const uint16_t id, const glm::ve
{
if( type->second->class_type == ObjectInformation::_class("HIER") )
{
modelname = state.specialModels[id];
texturename = state.specialModels[id];
modelname = state->specialModels[id];
texturename = state->specialModels[id];
}
else
{
@ -267,15 +268,15 @@ CutsceneObject *GameWorld::createCutsceneObject(const uint16_t id, const glm::ve
if(! modelname.compare(0, specialPrefix.size(), specialPrefix) ) {
auto sid = modelname.substr(specialPrefix.size());
unsigned short specialID = std::atoi(sid.c_str());
modelname = state.specialCharacters[specialID];
texturename = state.specialCharacters[specialID];
modelname = state->specialCharacters[specialID];
texturename = state->specialCharacters[specialID];
}
}
}
}
if( id == 0 ) {
modelname = state.player->getCharacter()->model->name;
modelname = state->player->getCharacter()->model->name;
}
// Ensure the relevant data is loaded.
@ -387,8 +388,8 @@ CharacterObject* GameWorld::createPedestrian(const uint16_t id, const glm::vec3
if(! modelname.compare(0, specialPrefix.size(), specialPrefix) ) {
auto sid = modelname.substr(specialPrefix.size());
unsigned short specialID = std::atoi(sid.c_str());
modelname = state.specialCharacters[specialID];
texturename = state.specialCharacters[specialID];
modelname = state->specialCharacters[specialID];
texturename = state->specialCharacters[specialID];
}
if( modelname != "null" ) {
@ -536,12 +537,12 @@ void GameWorld::doWeaponScan(const WeaponScan &scan)
int GameWorld::getHour()
{
return state.hour;
return state->hour;
}
int GameWorld::getMinute()
{
return state.minute;
return state->minute;
}
glm::vec3 GameWorld::getGroundAtPosition(const glm::vec3 &pos) const
@ -688,18 +689,18 @@ void GameWorld::loadCutscene(const std::string &name)
}
if( state.currentCutscene ) {
delete state.currentCutscene;
if( state->currentCutscene ) {
delete state->currentCutscene;
}
state.currentCutscene = cutscene;
state.currentCutscene->meta.name = name;
state->currentCutscene = cutscene;
state->currentCutscene->meta.name = name;
logger->info("World", "Loaded cutscene: " + name);
}
void GameWorld::startCutscene()
{
state.cutsceneStartTime = gameTime;
state.skipCutscene = false;
state->cutsceneStartTime = gameTime;
state->skipCutscene = false;
if( cutsceneAudio ) {
cutsceneAudio->play();
}
@ -720,20 +721,20 @@ void GameWorld::clearCutscene()
cutsceneAudio = nullptr;
}
delete state.currentCutscene;
state.currentCutscene = nullptr;
state.isCinematic = false;
state.cutsceneStartTime = -1.f;
delete state->currentCutscene;
state->currentCutscene = nullptr;
state->isCinematic = false;
state->cutsceneStartTime = -1.f;
}
bool GameWorld::isCutsceneDone()
{
if( state.currentCutscene ) {
float time = gameTime - state.cutsceneStartTime;
if( state.skipCutscene ) {
if( state->currentCutscene ) {
float time = gameTime - state->cutsceneStartTime;
if( state->skipCutscene ) {
return true;
}
return time > state.currentCutscene->tracks.duration;
return time > state->currentCutscene->tracks.duration;
}
return true;
}
@ -744,7 +745,7 @@ void GameWorld::loadSpecialCharacter(const unsigned short index, const std::stri
std::string lowerName(name);
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
/// @todo a bit more smarter than this
state.specialCharacters[index] = lowerName;
state->specialCharacters[index] = lowerName;
}
void GameWorld::loadSpecialModel(const unsigned short index, const std::string &name)
@ -752,7 +753,7 @@ void GameWorld::loadSpecialModel(const unsigned short index, const std::string &
std::string lowerName(name);
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
/// @todo a bit more smarter than this
state.specialModels[index] = lowerName;
state->specialModels[index] = lowerName;
}
void GameWorld::disableAIPaths(AIGraphNode::NodeType type, const glm::vec3& min, const glm::vec3& max)

View File

@ -1,6 +1,7 @@
#include <render/GameRenderer.hpp>
#include <engine/GameWorld.hpp>
#include <engine/Animator.hpp>
#include <engine/GameState.hpp>
#include <render/TextureAtlas.hpp>
#include <render/Model.hpp>
@ -247,10 +248,10 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera &camera, float
glBindVertexArray( vao );
float tod = world->state.hour + world->state.minute/60.f;
float tod = world->state->hour + world->state->minute/60.f;
// Requires a float 0-24
auto weatherID = static_cast<WeatherLoader::WeatherCondition>(world->state.currentWeather * 24);
auto weatherID = static_cast<WeatherLoader::WeatherCondition>(world->state->currentWeather * 24);
auto weather = world->data->weatherLoader.getWeatherData(weatherID, tod);
glm::vec3 skyTop = weather.skyTopColor;
@ -266,7 +267,7 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera &camera, float
};
sunDirection = glm::normalize(sunDirection);
_camera.frustum.near = world->state.cameraNear;
_camera.frustum.near = world->state->cameraNear;
_camera.frustum.far = weather.farClipping;
auto view = _camera.getView();
@ -380,7 +381,7 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera &camera, float
{
auto arrowTex = world->data->textures[{"copblue",""}];
auto arrowFrame = arrowModel->resource->findFrame( "arrow" );
for( auto& blip : world->state.radarBlips )
for( auto& blip : world->state->radarBlips )
{
if( blip.second.display == BlipData::Show )
{
@ -455,21 +456,21 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera &camera, float
glDisable(GL_DEPTH_TEST);
GLuint splashTexName = 0;
auto fc = world->state.fadeColour;
if((fc.r + fc.g + fc.b) == 0 && world->state.currentSplash.size() > 0) {
auto splash = world->data->findTexture(world->state.currentSplash);
auto fc = world->state->fadeColour;
if((fc.r + fc.g + fc.b) == 0 && world->state->currentSplash.size() > 0) {
auto splash = world->data->findTexture(world->state->currentSplash);
if ( splash )
{
splashTexName = splash->getName();
}
}
if( (world->state.isCinematic || world->state.currentCutscene ) && splashTexName != 0 ) {
if( (world->state->isCinematic || world->state->currentCutscene ) && splashTexName != 0 ) {
renderLetterbox();
}
float fadeTimer = world->gameTime - world->state.fadeStart;
if( fadeTimer < world->state.fadeTime || !world->state.fadeOut ) {
float fadeTimer = world->gameTime - world->state->fadeStart;
if( fadeTimer < world->state->fadeTime || !world->state->fadeOut ) {
glUseProgram(ssRectProgram);
glUniform2f(ssRectOffset, 0.f, 0.f);
glUniform2f(ssRectSize, 1.f, 1.f);
@ -485,11 +486,11 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera &camera, float
}
float fadeFrac = 0.f;
if( world->state.fadeTime > 0.f ) {
fadeFrac = std::min(fadeTimer / world->state.fadeTime, 1.f);
if( world->state->fadeTime > 0.f ) {
fadeFrac = std::min(fadeTimer / world->state->fadeTime, 1.f);
}
float a = world->state.fadeOut ? 1.f - fadeFrac : fadeFrac;
float a = world->state->fadeOut ? 1.f - fadeFrac : fadeFrac;
glm::vec4 fadeNormed(fc.r / 255.f, fc.g/ 255.f, fc.b/ 255.f, a);
@ -499,7 +500,7 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera &camera, float
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
if( (world->state.isCinematic || world->state.currentCutscene ) && splashTexName == 0 ) {
if( (world->state->isCinematic || world->state->currentCutscene ) && splashTexName == 0 ) {
renderLetterbox();
}
@ -747,7 +748,7 @@ void GameRenderer::renderPickup(PickupObject *pickup)
void GameRenderer::renderCutsceneObject(CutsceneObject *cutscene)
{
if(!_renderWorld->state.currentCutscene) return;
if(!_renderWorld->state->currentCutscene) return;
if(!cutscene->model->resource)
{
@ -757,7 +758,7 @@ void GameRenderer::renderCutsceneObject(CutsceneObject *cutscene)
glm::mat4 matrixModel;
if( cutscene->getParentActor() ) {
matrixModel = glm::translate(matrixModel, _renderWorld->state.currentCutscene->meta.sceneOffset + glm::vec3(0.f, 0.f, 1.f));
matrixModel = glm::translate(matrixModel, _renderWorld->state->currentCutscene->meta.sceneOffset + glm::vec3(0.f, 0.f, 1.f));
//matrixModel = cutscene->getParentActor()->getTimeAdjustedTransform(_renderAlpha);
//matrixModel = glm::translate(matrixModel, glm::vec3(0.f, 0.f, 1.f));
glm::mat4 localMatrix;
@ -769,7 +770,7 @@ void GameRenderer::renderCutsceneObject(CutsceneObject *cutscene)
matrixModel = matrixModel * localMatrix;
}
else {
matrixModel = glm::translate(matrixModel, _renderWorld->state.currentCutscene->meta.sceneOffset + glm::vec3(0.f, 0.f, 1.f));
matrixModel = glm::translate(matrixModel, _renderWorld->state->currentCutscene->meta.sceneOffset + glm::vec3(0.f, 0.f, 1.f));
}
float mindist = 100000.f;

View File

@ -2,6 +2,7 @@
#include <render/GameShaders.hpp>
#include <engine/GameWorld.hpp>
#include <engine/GameData.hpp>
#include <engine/GameState.hpp>
#include <ai/PlayerController.hpp>
#include <objects/CharacterObject.hpp>
@ -145,7 +146,7 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi)
renderer->setUniform(rectProg, "view", view);
for(auto& blip : world->state.radarBlips)
for(auto& blip : world->state->radarBlips)
{
glm::vec2 blippos( blip.second.coord );
if( blip.second.target )
@ -157,7 +158,7 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi)
}
// Draw the player blip
auto player = world->state.player;
auto player = world->state->player;
if( player )
{
glm::vec2 plyblip(player->getCharacter()->getPosition());

View File

@ -175,8 +175,8 @@ void ScriptMachine::executeThread(SCMThread &t, int msPassed)
}
}
ScriptMachine::ScriptMachine(GameWorld *world, SCMFile *file, SCMOpcodes *ops)
: _file(file), _ops(ops), _world(world)
ScriptMachine::ScriptMachine(GameState* _state, SCMFile *file, SCMOpcodes *ops)
: _file(file), _ops(ops), state(_state)
{
startThread(0);
auto globals = _file->getGlobalsSize() / 4;

View File

@ -0,0 +1,13 @@
#include <script/ScriptTypes.hpp>
#include <script/ScriptMachine.hpp>
#include <engine/GameState.hpp>
GameState* ScriptArguments::getState() const
{
return getVM()->getState();
}
GameWorld* ScriptArguments::getWorld() const
{
return getVM()->getState()->world;
}

View File

@ -28,12 +28,12 @@
void game_print_big(const ScriptArguments& args)
{
std::string id(args[0].string);
std::string str = args.getVM()->getWorld()->data->texts.text(id);
std::string str = args.getWorld()->data->texts.text(id);
unsigned short style = args[2].integer;
args.getVM()->getWorld()->state.text.push_back({
args.getWorld()->state->text.push_back({
id,
str,
args.getVM()->getWorld()->gameTime,
args.getWorld()->gameTime,
args[1].integer / 1000.f,
style
});
@ -42,12 +42,12 @@ void game_print_big(const ScriptArguments& args)
void game_print_now(const ScriptArguments& args)
{
std::string id(args[0].string);
std::string str = args.getVM()->getWorld()->data->texts.text(id);
std::string str = args.getWorld()->data->texts.text(id);
int flags = args[2].integer;
args.getVM()->getWorld()->state.text.push_back({
args.getWorld()->state->text.push_back({
id,
str,
args.getVM()->getWorld()->gameTime,
args.getWorld()->gameTime,
args[1].integer / 1000.f,
0
});
@ -55,19 +55,19 @@ void game_print_now(const ScriptArguments& args)
void game_clear_prints(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.text.clear();
args.getWorld()->state->text.clear();
}
void game_get_time(const ScriptArguments& args)
{
*args[0].globalInteger = args.getVM()->getWorld()->getHour();
*args[1].globalInteger = args.getVM()->getWorld()->getMinute();
*args[0].globalInteger = args.getWorld()->getHour();
*args[1].globalInteger = args.getWorld()->getMinute();
}
void game_set_time(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.hour = args[0].integer;
args.getVM()->getWorld()->state.minute = args[1].integer;
args.getWorld()->state->hour = args[0].integer;
args.getWorld()->state->minute = args[1].integer;
}
bool game_is_button_pressed(const ScriptArguments& args)
@ -78,7 +78,7 @@ bool game_is_button_pressed(const ScriptArguments& args)
void game_set_dead_or_arrested(const ScriptArguments& args)
{
*args.getVM()->getWorld()->state.scriptOnMissionFlag = args[0].integer;
*args.getWorld()->state->scriptOnMissionFlag = args[0].integer;
}
bool game_has_death_or_arrest_finished(const ScriptArguments& args)
{
@ -91,7 +91,7 @@ void game_create_vehicle_generator(const ScriptArguments& args)
if(args[4].type == TString)
{
args.getVM()->getWorld()->logger->error("SCM", "Model names not supported for vehicle generator");
args.getWorld()->logger->error("SCM", "Model names not supported for vehicle generator");
return;
}
@ -110,20 +110,20 @@ void game_create_vehicle_generator(const ScriptArguments& args)
vg.lastSpawnTime = 0;
vg.remainingSpawns = 0;
*args[12].globalInteger = args.getVM()->getWorld()->state.vehicleGenerators.size();
*args[12].globalInteger = args.getWorld()->state->vehicleGenerators.size();
args.getVM()->getWorld()->state.vehicleGenerators.push_back(vg);
args.getWorld()->state->vehicleGenerators.push_back(vg);
}
void game_set_vehicle_generator_count(const ScriptArguments& args)
{
VehicleGenerator& generator = args.getVM()->getWorld()->state.vehicleGenerators.at(*args[0].globalInteger);
VehicleGenerator& generator = args.getWorld()->state->vehicleGenerators.at(*args[0].globalInteger);
generator.remainingSpawns = args[1].integer;
}
void game_set_zone_car_info(const ScriptArguments& args)
{
auto it = args.getVM()->getWorld()->data->zones.find(args[0].string);
if( it != args.getVM()->getWorld()->data->zones.end() )
auto it = args.getWorld()->data->zones.find(args[0].string);
if( it != args.getWorld()->data->zones.end() )
{
auto day = args[1].integer == 1;
for(int i = 2; i < args.getParameters().size(); ++i)
@ -145,20 +145,20 @@ void game_camera_follow_character(const ScriptArguments& args)
auto controller = static_cast<CharacterController*>(*args[0].handle);
if( controller != nullptr )
{
args.getVM()->getWorld()->state.cameraTarget = controller->getCharacter();
args.getWorld()->state->cameraTarget = controller->getCharacter();
}
}
void game_reset_camera(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.cameraTarget = nullptr;
args.getVM()->getWorld()->state.cameraFixed = false;
args.getWorld()->state->cameraTarget = nullptr;
args.getWorld()->state->cameraFixed = false;
}
void game_set_zone_ped_info(const ScriptArguments& args)
{
auto it = args.getVM()->getWorld()->data->zones.find(args[0].string);
if( it != args.getVM()->getWorld()->data->zones.end() )
auto it = args.getWorld()->data->zones.find(args[0].string);
if( it != args.getWorld()->data->zones.end() )
{
auto day = args[1].integer == 1;
for(int i = 2; i < args.getParameters().size(); ++i)
@ -180,16 +180,16 @@ void game_camera_fixed_position(const ScriptArguments& args)
glm::vec3 position( args[0].real, args[1].real, args[2].real );
glm::vec3 angles( args[3].real, args[4].real, args[5].real );
args.getVM()->getWorld()->state.cameraFixed = true;
args.getVM()->getWorld()->state.cameraPosition = position;
args.getVM()->getWorld()->state.cameraRotation = glm::quat(angles);
args.getWorld()->state->cameraFixed = true;
args.getWorld()->state->cameraPosition = position;
args.getWorld()->state->cameraRotation = glm::quat(angles);
}
void game_camera_lookat_position(const ScriptArguments& args)
{
glm::vec3 position( args[0].real, args[1].real, args[2].real );
int switchmode = args[3].integer;
auto direction = glm::normalize(position - args.getVM()->getWorld()->state.cameraPosition);
auto direction = glm::normalize(position - args.getWorld()->state->cameraPosition);
auto right = glm::normalize(glm::cross(glm::vec3(0.f, 0.f, 1.f), direction));
auto up = glm::normalize(glm::cross(direction, right));
@ -206,53 +206,53 @@ void game_camera_lookat_position(const ScriptArguments& args)
v[2][1] = right.z;
v[2][2] = up.z;
args.getVM()->getWorld()->state.cameraRotation = glm::inverse(glm::quat_cast(v));
args.getWorld()->state->cameraRotation = glm::inverse(glm::quat_cast(v));
}
void game_remove_blip(const ScriptArguments& args)
{
int blip = *args[0].globalInteger;
args.getVM()->getWorld()->state.removeBlip(blip);
args.getWorld()->state->removeBlip(blip);
}
void game_set_fade_colour(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.fadeColour.r = args[0].integer;
args.getVM()->getWorld()->state.fadeColour.g = args[1].integer;
args.getVM()->getWorld()->state.fadeColour.b = args[2].integer;
args.getWorld()->state->fadeColour.r = args[0].integer;
args.getWorld()->state->fadeColour.g = args[1].integer;
args.getWorld()->state->fadeColour.b = args[2].integer;
}
void game_fade_screen(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.fadeTime = args[0].integer / 1000.f;
args.getVM()->getWorld()->state.fadeOut = !!args[1].integer;
args.getVM()->getWorld()->state.fadeStart = args.getVM()->getWorld()->gameTime;
args.getWorld()->state->fadeTime = args[0].integer / 1000.f;
args.getWorld()->state->fadeOut = !!args[1].integer;
args.getWorld()->state->fadeStart = args.getWorld()->gameTime;
}
bool game_screen_fading(const ScriptArguments& args)
{
if( args.getVM()->getWorld()->state.skipCutscene )
if( args.getWorld()->state->skipCutscene )
{
return false;
}
return args.getVM()->getWorld()->gameTime <
args.getVM()->getWorld()->state.fadeStart + args.getVM()->getWorld()->state.fadeTime;
return args.getWorld()->gameTime <
args.getWorld()->state->fadeStart + args.getWorld()->state->fadeTime;
}
void game_override_restart(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.overrideNextStart = true;
args.getVM()->getWorld()->state.nextRestartLocation = glm::vec4(
args.getWorld()->state->overrideNextStart = true;
args.getWorld()->state->nextRestartLocation = glm::vec4(
args[0].real, args[1].real, args[2].real, args[3].real
);
}
void game_clear_override(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.overrideNextStart = false;
args.getWorld()->state->overrideNextStart = false;
}
void game_link_mission_flag(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.scriptOnMissionFlag = (unsigned int*)args[0].globalInteger;
args.getWorld()->state->scriptOnMissionFlag = (unsigned int*)args[0].globalInteger;
}
void game_add_vehicle_blip(const ScriptArguments& args)
@ -260,7 +260,7 @@ void game_add_vehicle_blip(const ScriptArguments& args)
BlipData data;
data.target = static_cast<VehicleObject*>(*args[0].handle);
data.texture = "";
*args[1].globalInteger = args.getVM()->getWorld()->state.addRadarBlip(data);
*args[1].globalInteger = args.getWorld()->state->addRadarBlip(data);
}
void game_add_character_blip(const ScriptArguments& args)
@ -269,7 +269,7 @@ void game_add_character_blip(const ScriptArguments& args)
auto controller = static_cast<CharacterController*>(*args[0].handle);
data.target = controller->getCharacter();
data.texture = "";
*args[1].globalInteger = args.getVM()->getWorld()->state.addRadarBlip(data);
*args[1].globalInteger = args.getWorld()->state->addRadarBlip(data);
}
void game_add_pickup_blip(const ScriptArguments& args)
@ -277,7 +277,7 @@ void game_add_pickup_blip(const ScriptArguments& args)
BlipData data;
data.target = static_cast<PickupObject*>(*args[0].handle);
data.texture = "";
*args[1].globalInteger = args.getVM()->getWorld()->state.addRadarBlip(data);
*args[1].globalInteger = args.getWorld()->state->addRadarBlip(data);
}
@ -287,13 +287,13 @@ void game_add_location_blip(const ScriptArguments& args)
data.target = nullptr;
data.coord = glm::vec3(args[0].real, args[1].real, args[2].real);
data.texture = "";
*args[3].globalInteger = args.getVM()->getWorld()->state.addRadarBlip(data);
*args[3].globalInteger = args.getWorld()->state->addRadarBlip(data);
}
void game_change_blip_mode(const ScriptArguments& args)
{
int id = *args[0].globalInteger;
BlipData& blip = args.getVM()->getWorld()->state.radarBlips[id];
BlipData& blip = args.getWorld()->state->radarBlips[id];
int mode = args[1].integer;
switch ( mode )
@ -318,28 +318,28 @@ void game_enable_input(const ScriptArguments& args)
void game_set_weather(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.currentWeather = args[0].integer;
args.getWorld()->state->currentWeather = args[0].integer;
}
void game_get_runtime(const ScriptArguments& args)
{
*args[0].globalInteger = args.getVM()->getWorld()->gameTime * 1000;
*args[0].globalInteger = args.getWorld()->gameTime * 1000;
}
void game_print_big_with_number(const ScriptArguments& args)
{
std::string id(args[0].string);
std::string str = args.getVM()->getWorld()->data->texts.text(id);
std::string str = args.getWorld()->data->texts.text(id);
int number = args[1].integer;
str += "\n" + std::to_string(number);
unsigned short style = args[3].integer;
args.getVM()->getWorld()->state.text.push_back({
args.getWorld()->state->text.push_back({
id,
str,
args.getVM()->getWorld()->gameTime,
args.getWorld()->gameTime,
args[2].integer / 1000.f,
style
});
@ -350,19 +350,19 @@ void game_disable_roads(const ScriptArguments& args)
glm::vec3 min(args[0].real,args[1].real,args[2].real);
glm::vec3 max(args[3].real,args[4].real,args[5].real);
args.getVM()->getWorld()->enableAIPaths(AIGraphNode::Vehicle, min, max);
args.getWorld()->enableAIPaths(AIGraphNode::Vehicle, min, max);
}
void game_enabled_roads(const ScriptArguments& args)
{
glm::vec3 min(args[0].real,args[1].real,args[2].real);
glm::vec3 max(args[3].real,args[4].real,args[5].real);
args.getVM()->getWorld()->disableAIPaths(AIGraphNode::Vehicle, min, max);
args.getWorld()->disableAIPaths(AIGraphNode::Vehicle, min, max);
}
void game_max_wanted_level(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.maxWantedLevel = args[0].integer;
args.getWorld()->state->maxWantedLevel = args[0].integer;
}
// This does nothing for us.
@ -381,7 +381,7 @@ void game_create_garage(const ScriptArguments& args)
int garageType = args[6].integer;
auto garageHandle = args[7].handle;
args.getVM()->getWorld()->logger->warning("SCM", "Garages Unimplemented! " + std::to_string(garageType));
args.getWorld()->logger->warning("SCM", "Garages Unimplemented! " + std::to_string(garageType));
}
void game_disable_ped_paths(const ScriptArguments& args)
@ -389,26 +389,26 @@ void game_disable_ped_paths(const ScriptArguments& args)
glm::vec3 min(args[0].real,args[1].real,args[2].real);
glm::vec3 max(args[3].real,args[4].real,args[5].real);
args.getVM()->getWorld()->enableAIPaths(AIGraphNode::Pedestrian, min, max);
args.getWorld()->enableAIPaths(AIGraphNode::Pedestrian, min, max);
}
void game_enable_ped_paths(const ScriptArguments& args)
{
glm::vec3 min(args[0].real,args[1].real,args[2].real);
glm::vec3 max(args[3].real,args[4].real,args[5].real);
args.getVM()->getWorld()->disableAIPaths(AIGraphNode::Pedestrian, min, max);
args.getWorld()->disableAIPaths(AIGraphNode::Pedestrian, min, max);
}
void game_load_special_char(const ScriptArguments& args)
{
args.getVM()->getWorld()->loadSpecialCharacter(args[0].integer, args[1].string);
args.getWorld()->loadSpecialCharacter(args[0].integer, args[1].string);
}
bool game_special_char_loaded(const ScriptArguments& args)
{
auto chartype = args.getVM()->getWorld()->data->findObjectType<CharacterData>(args[0].integer);
auto chartype = args.getWorld()->data->findObjectType<CharacterData>(args[0].integer);
if( chartype ) {
auto modelfind = args.getVM()->getWorld()->data->models.find(chartype->modelName);
if( modelfind != args.getVM()->getWorld()->data->models.end() && modelfind->second->resource != nullptr ) {
auto modelfind = args.getWorld()->data->models.find(chartype->modelName);
if( modelfind != args.getWorld()->data->models.end() && modelfind->second->resource != nullptr ) {
return true;
}
}
@ -419,8 +419,8 @@ bool game_special_char_loaded(const ScriptArguments& args)
void game_cutscene_offset(const ScriptArguments& args)
{
glm::vec3 position(args[0].real, args[1].real, args[2].real);
if( args.getVM()->getWorld()->state.currentCutscene ) {
args.getVM()->getWorld()->state.currentCutscene->meta.sceneOffset = position;
if( args.getWorld()->state->currentCutscene ) {
args.getWorld()->state->currentCutscene->meta.sceneOffset = position;
}
}
@ -438,11 +438,11 @@ bool game_model_loaded(const ScriptArguments& args)
void game_restart_critical_mission(const ScriptArguments& args)
{
args.getVM()->getWorld()->logger->info("SCM", "Restarting Critical Mission");
args.getWorld()->logger->info("SCM", "Restarting Critical Mission");
// Reset player state.
glm::vec3 position(args[0].real, args[1].real, args[2].real + 1.f);
auto controller = args.getVM()->getWorld()->state.player;
auto controller = args.getWorld()->state->player;
glm::vec3 spawnMagic( 0.f, 0.f, 1.f );
@ -473,7 +473,7 @@ void game_controller_mode(const ScriptArguments& args)
void game_set_widescreen(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.isCinematic = !!args[0].integer;
args.getWorld()->state->isCinematic = !!args[0].integer;
}
static const char* sprite_names[] = {
@ -517,7 +517,7 @@ void game_add_contact_blip(const ScriptArguments& args)
bd.target = nullptr;
bd.texture = spriteName;
*args[4].globalInteger = args.getVM()->getWorld()->state.addRadarBlip(bd);
*args[4].globalInteger = args.getWorld()->state->addRadarBlip(bd);
}
void game_add_sprite_blip(const ScriptArguments& args)
@ -537,23 +537,23 @@ void game_add_sprite_blip(const ScriptArguments& args)
bd.target = nullptr;
bd.texture = spriteName;
*args[4].globalInteger = args.getVM()->getWorld()->state.addRadarBlip(bd);
*args[4].globalInteger = args.getWorld()->state->addRadarBlip(bd);
}
void game_load_cutscene(const ScriptArguments& args)
{
args.getVM()->getWorld()->loadCutscene(args[0].string);
args.getVM()->getWorld()->state.cutsceneStartTime = -1.f;
args.getWorld()->loadCutscene(args[0].string);
args.getWorld()->state->cutsceneStartTime = -1.f;
}
void game_create_cutscene_object(const ScriptArguments& args)
{
auto id = args[0].integer;
GameObject* object = object = args.getVM()->getWorld()->createCutsceneObject(id, args.getVM()->getWorld()->state.currentCutscene->meta.sceneOffset );
GameObject* object = object = args.getWorld()->createCutsceneObject(id, args.getWorld()->state->currentCutscene->meta.sceneOffset );
*args[1].handle = object;
if( object == nullptr ) {
args.getVM()->getWorld()->logger->error("SCM", "Could not create cutscene object " + std::to_string(id));
args.getWorld()->logger->error("SCM", "Could not create cutscene object " + std::to_string(id));
}
}
void game_set_cutscene_anim(const ScriptArguments& args)
@ -561,24 +561,24 @@ void game_set_cutscene_anim(const ScriptArguments& args)
GameObject* object = static_cast<GameObject*>(*args[0].handle);
std::string animName = args[1].string;
std::transform(animName.begin(), animName.end(), animName.begin(), ::tolower);
Animation* anim = args.getVM()->getWorld()->data->animations[animName];
Animation* anim = args.getWorld()->data->animations[animName];
if( anim ) {
object->animator->setAnimation(anim, false);
}
else {
args.getVM()->getWorld()->logger->error("SCM", "Failed to load cutscene anim: " + animName);
args.getWorld()->logger->error("SCM", "Failed to load cutscene anim: " + animName);
}
}
void game_start_cutscene(const ScriptArguments& args)
{
args.getVM()->getWorld()->startCutscene();
args.getWorld()->startCutscene();
}
void game_get_cutscene_time(const ScriptArguments& args)
{
float time = args.getVM()->getWorld()->gameTime - args.getVM()->getWorld()->state.cutsceneStartTime;
if( args.getVM()->getWorld()->state.skipCutscene )
float time = args.getWorld()->gameTime - args.getWorld()->state->cutsceneStartTime;
if( args.getWorld()->state->skipCutscene )
{
*args[0].globalInteger = args.getVM()->getWorld()->state.currentCutscene->tracks.duration * 1000;
*args[0].globalInteger = args.getWorld()->state->currentCutscene->tracks.duration * 1000;
}
else
{
@ -587,34 +587,34 @@ void game_get_cutscene_time(const ScriptArguments& args)
}
bool game_cutscene_finished(const ScriptArguments& args)
{
if( args.getVM()->getWorld()->state.currentCutscene ) {
float time = args.getVM()->getWorld()->gameTime - args.getVM()->getWorld()->state.cutsceneStartTime;
if( args.getVM()->getWorld()->state.skipCutscene ) {
if( args.getWorld()->state->currentCutscene ) {
float time = args.getWorld()->gameTime - args.getWorld()->state->cutsceneStartTime;
if( args.getWorld()->state->skipCutscene ) {
return true;
}
return time > args.getVM()->getWorld()->state.currentCutscene->tracks.duration;
return time > args.getWorld()->state->currentCutscene->tracks.duration;
}
return true;
}
void game_clear_cutscene(const ScriptArguments& args)
{
args.getVM()->getWorld()->clearCutscene();
args.getWorld()->clearCutscene();
}
void game_set_hidden_packages(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.numHiddenPackages = args[0].integer;
args.getWorld()->state->numHiddenPackages = args[0].integer;
}
void game_load_special_model(const ScriptArguments& args)
{
args.getVM()->getWorld()->loadSpecialModel(args[0].integer, args[1].string);
args.getWorld()->loadSpecialModel(args[0].integer, args[1].string);
}
void game_create_cutscene_head(const ScriptArguments& args)
{
auto id = args[1].integer;
auto actor = static_cast<GameObject*>(*args[0].handle);
CutsceneObject* object = args.getVM()->getWorld()->createCutsceneObject(id, args.getVM()->getWorld()->state.currentCutscene->meta.sceneOffset );
CutsceneObject* object = args.getWorld()->createCutsceneObject(id, args.getWorld()->state->currentCutscene->meta.sceneOffset );
auto headframe = actor->model->resource->findFrame("shead");
actor->skeleton->setEnabled(headframe, false);
@ -627,39 +627,39 @@ void game_set_head_animation(const ScriptArguments& args)
GameObject* object = static_cast<GameObject*>(*args[0].handle);
std::string animName = args[1].string;
std::transform(animName.begin(), animName.end(), animName.begin(), ::tolower);
Animation* anim = args.getVM()->getWorld()->data->animations[animName];
Animation* anim = args.getWorld()->data->animations[animName];
if( anim ) {
object->animator->setAnimation(anim, false);
}
else {
args.getVM()->getWorld()->logger->error("SCM", "Failed to load cutscene anim: " + animName);
args.getWorld()->logger->error("SCM", "Failed to load cutscene anim: " + animName);
}
}
void game_increment_progress(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.currentProgress += args[0].integer;
args.getWorld()->state->currentProgress += args[0].integer;
}
void game_set_max_progress(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.maxProgress = args[0].integer;
args.getWorld()->state->maxProgress = args[0].integer;
}
void game_set_unique_jumps(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.numUniqueJumps = args[0].integer;
args.getWorld()->state->numUniqueJumps = args[0].integer;
}
void game_set_last_mission(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.lastMissionName = args[0].string;
args.getWorld()->state->lastMissionName = args[0].string;
}
void game_set_zone_ped_group(const ScriptArguments& args)
{
auto it = args.getVM()->getWorld()->data->zones.find(args[0].string);
if( it != args.getVM()->getWorld()->data->zones.end() )
auto it = args.getWorld()->data->zones.find(args[0].string);
if( it != args.getWorld()->data->zones.end() )
{
auto day = args[1].integer == 1;
if( day )
@ -677,26 +677,26 @@ void game_display_text(const ScriptArguments& args)
{
glm::vec2 pos(args[0].real, args[1].real);
std::string str(args[2].string);
str = args.getVM()->getWorld()->data->texts.text(str);
args.getVM()->getWorld()->state.nextText.text = str;
args.getVM()->getWorld()->state.nextText.position = pos;
args.getVM()->getWorld()->state.texts.push_back(args.getVM()->getWorld()->state.nextText);
str = args.getWorld()->data->texts.text(str);
args.getWorld()->state->nextText.text = str;
args.getWorld()->state->nextText.position = pos;
args.getWorld()->state->texts.push_back(args.getWorld()->state->nextText);
}
void game_set_text_colour(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.nextText.colourFG.r = args[0].integer / 255.f;
args.getVM()->getWorld()->state.nextText.colourFG.g = args[1].integer / 255.f;
args.getVM()->getWorld()->state.nextText.colourFG.b = args[2].integer / 255.f;
args.getVM()->getWorld()->state.nextText.colourFG.a = args[3].integer / 255.f;
args.getWorld()->state->nextText.colourFG.r = args[0].integer / 255.f;
args.getWorld()->state->nextText.colourFG.g = args[1].integer / 255.f;
args.getWorld()->state->nextText.colourFG.b = args[2].integer / 255.f;
args.getWorld()->state->nextText.colourFG.a = args[3].integer / 255.f;
}
void game_set_background_colour(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.nextText.colourBG.r = args[0].integer / 255.f;
args.getVM()->getWorld()->state.nextText.colourBG.g = args[1].integer / 255.f;
args.getVM()->getWorld()->state.nextText.colourBG.b = args[2].integer / 255.f;
args.getVM()->getWorld()->state.nextText.colourBG.a = args[3].integer / 255.f;
args.getWorld()->state->nextText.colourBG.r = args[0].integer / 255.f;
args.getWorld()->state->nextText.colourBG.g = args[1].integer / 255.f;
args.getWorld()->state->nextText.colourBG.b = args[2].integer / 255.f;
args.getWorld()->state->nextText.colourBG.a = args[3].integer / 255.f;
}
void game_set_character_model(const ScriptArguments& args)
@ -717,51 +717,51 @@ void game_load_audio(const ScriptArguments& args)
{
std::string name = args[0].string;
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if(! args.getVM()->getWorld()->data->loadAudioClip(name + ".wav") )
if(! args.getWorld()->data->loadAudioClip(name + ".wav") )
{
if(! args.getVM()->getWorld()->data->loadAudioClip(name + ".mp3") )
if(! args.getWorld()->data->loadAudioClip(name + ".mp3") )
{
args.getVM()->getWorld()->logger->error("SCM", "Failed to load audio: " + name);
args.getWorld()->logger->error("SCM", "Failed to load audio: " + name);
}
}
}
bool game_is_audio_loaded(const ScriptArguments& args)
{
auto world = args.getVM()->getWorld();
auto world = args.getWorld();
return world->missionAudio != nullptr;
}
void game_play_mission_audio(const ScriptArguments& args)
{
auto world = args.getVM()->getWorld();
auto world = args.getWorld();
if ( world->missionAudio )
{
world->missionSound.setBuffer(*args.getVM()->getWorld()->missionAudio);
world->missionSound.setBuffer(*args.getWorld()->missionAudio);
world->missionSound.play();
world->missionSound.setLoop(false);
}
}
bool game_is_audio_finished(const ScriptArguments& args)
{
return args.getVM()->getWorld()->missionSound.getStatus() == sf::SoundSource::Stopped;
return args.getWorld()->missionSound.getStatus() == sf::SoundSource::Stopped;
}
void game_play_music_id(const ScriptArguments& args)
{
int id = args[0].integer;
GameWorld* gw = args.getVM()->getWorld();
GameWorld* gw = args.getWorld();
std::string name = "Miscom";
// TODO play anything other than Miscom.wav
if(! gw->data->loadAudioClip( name + ".wav" ) )
{
args.getVM()->getWorld()->logger->error("SCM", "Error loading audio " + name);
args.getWorld()->logger->error("SCM", "Error loading audio " + name);
return;
}
else if ( args.getVM()->getWorld()->missionAudio )
else if ( args.getWorld()->missionAudio )
{
gw->missionSound.setBuffer(* args.getVM()->getWorld()->missionAudio);
gw->missionSound.setBuffer(* args.getWorld()->missionAudio);
gw->missionSound.play();
gw->missionSound.setLoop(false);
}
@ -771,11 +771,11 @@ void game_clear_print(const ScriptArguments& args)
{
std::string id(args[0].string);
for( int i = 0; i < args.getVM()->getWorld()->state.text.size(); )
for( int i = 0; i < args.getWorld()->state->text.size(); )
{
if( args.getVM()->getWorld()->state.text[i].id == id )
if( args.getWorld()->state->text[i].id == id )
{
args.getVM()->getWorld()->state.text.erase(args.getVM()->getWorld()->state.text.begin() + i);
args.getWorld()->state->text.erase(args.getWorld()->state->text.begin() + i);
}
else
{
@ -786,18 +786,18 @@ void game_clear_print(const ScriptArguments& args)
void game_get_found_hidden_packages(const ScriptArguments& args)
{
*args[0].globalInteger = args.getVM()->getWorld()->state.numHiddenPackagesDiscovered;
*args[0].globalInteger = args.getWorld()->state->numHiddenPackagesDiscovered;
}
void game_display_help(const ScriptArguments& args)
{
std::string id(args[0].string);
std::string str = args.getVM()->getWorld()->data->texts.text(id);
std::string str = args.getWorld()->data->texts.text(id);
unsigned short style = OnscreenText::Help;
args.getVM()->getWorld()->state.text.push_back({
args.getWorld()->state->text.push_back({
id,
str,
args.getVM()->getWorld()->gameTime,
args.getWorld()->gameTime,
2.5f,
style
});
@ -805,9 +805,9 @@ void game_display_help(const ScriptArguments& args)
void game_clear_help(const ScriptArguments& args)
{
for( int i = 0; i < args.getVM()->getWorld()->state.text.size(); )
for( int i = 0; i < args.getWorld()->state->text.size(); )
{
auto& texts = args.getVM()->getWorld()->state.text;
auto& texts = args.getWorld()->state->text;
if( texts[i].osTextStyle == OnscreenText::Help )
{
texts.erase(texts.begin() + i);
@ -827,26 +827,26 @@ void game_load_collision(const ScriptArguments& args)
void game_set_rampages(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.numRampages = args[0].integer;
args.getWorld()->state->numRampages = args[0].integer;
}
void game_set_near_clip(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.cameraNear = args[0].real;
args.getWorld()->state->cameraNear = args[0].real;
}
void game_set_missions(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.numMissions = args[0].integer;
args.getWorld()->state->numMissions = args[0].integer;
}
void game_set_sound_fade(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.fadeSound = !!args[0].integer;
args.getWorld()->state->fadeSound = !!args[0].integer;
}
void game_set_is_intro_playing(const ScriptArguments& args)
{
args.getVM()->getWorld()->state.isIntroPlaying = !!args[0].integer;
args.getWorld()->state->isIntroPlaying = !!args[0].integer;
}
bool game_are_vehicle_cheats_enabled(const ScriptArguments& args)
@ -856,7 +856,7 @@ bool game_are_vehicle_cheats_enabled(const ScriptArguments& args)
void game_load_splash(const ScriptArguments& args)
{
args.getVM()->getWorld()->data->loadSplash(args[0].string);
args.getWorld()->data->loadSplash(args[0].string);
}
GameModule::GameModule()

View File

@ -11,6 +11,7 @@
#include <render/Model.hpp>
#include <render/GameRenderer.hpp>
#include <engine/Animator.hpp>
#include <engine/GameState.hpp>
#include <ai/PlayerController.hpp>
#include <ai/DefaultAIController.hpp>
@ -34,13 +35,13 @@ void game_create_player(const ScriptArguments& args)
glm::vec3 position(args[1].real, args[2].real, args[3].real);
if( position.z < -99.f ) {
position = args.getVM()->getWorld()->getGroundAtPosition(position);
position = args.getWorld()->getGroundAtPosition(position);
}
auto pc = args.getVM()->getWorld()->createPedestrian(1, position + spawnMagic);
args.getVM()->getWorld()->state.player = new PlayerController(pc);
auto pc = args.getWorld()->createPedestrian(1, position + spawnMagic);
args.getState()->player = new PlayerController(pc);
*args[4].handle = args.getVM()->getWorld()->state.player;
*args[4].handle = args.getState()->player;
}
void game_set_character_position(const ScriptArguments& args)
@ -89,28 +90,28 @@ void game_create_character(const ScriptArguments& args)
}
if( position.z < -99.f ) {
position = args.getVM()->getWorld()->getGroundAtPosition(position);
position = args.getWorld()->getGroundAtPosition(position);
}
// If there is already a chracter less than this distance away, it will be destroyed.
const float replaceThreshold = 2.f;
for( auto it = args.getVM()->getWorld()->objects.begin();
it != args.getVM()->getWorld()->objects.end();
for( auto it = args.getWorld()->objects.begin();
it != args.getWorld()->objects.end();
++it)
{
if( (*it)->type() == GameObject::Character && glm::distance(position, (*it)->getPosition()) < replaceThreshold )
{
args.getVM()->getWorld()->destroyObjectQueued(*it);
args.getWorld()->destroyObjectQueued(*it);
}
}
auto character = args.getVM()->getWorld()->createPedestrian(id, position + spawnMagic);
auto character = args.getWorld()->createPedestrian(id, position + spawnMagic);
auto controller = new DefaultAIController(character);
if ( args.getThread()->isMission )
{
args.getVM()->getWorld()->state.missionObjects.push_back(character);
args.getState()->missionObjects.push_back(character);
}
*args[5].handle = controller;
@ -122,7 +123,7 @@ void game_destroy_character(const ScriptArguments& args)
if ( controller )
{
args.getVM()->getWorld()->destroyObjectQueued(controller->getCharacter());
args.getWorld()->destroyObjectQueued(controller->getCharacter());
}
}
@ -134,21 +135,21 @@ void game_create_vehicle(const ScriptArguments& args)
// If there is already a vehicle less than this distance away, it will be destroyed.
const float replaceThreshold = 1.f;
for( auto it = args.getVM()->getWorld()->objects.begin();
it != args.getVM()->getWorld()->objects.end();
for( auto it = args.getWorld()->objects.begin();
it != args.getWorld()->objects.end();
++it)
{
if( (*it)->type() == GameObject::Vehicle && glm::distance(position, (*it)->getPosition()) < replaceThreshold )
{
args.getVM()->getWorld()->destroyObjectQueued(*it);
args.getWorld()->destroyObjectQueued(*it);
}
}
auto vehicle = args.getVM()->getWorld()->createVehicle(id, position);
auto vehicle = args.getWorld()->createVehicle(id, position);
if ( args.getThread()->isMission )
{
args.getVM()->getWorld()->state.missionObjects.push_back(vehicle);
args.getState()->missionObjects.push_back(vehicle);
}
*args[4].handle = vehicle;
@ -158,7 +159,7 @@ void game_destroy_vehicle(const ScriptArguments& args)
{
auto vehicle = static_cast<VehicleObject*>(*args[0].handle);
args.getVM()->getWorld()->destroyObjectQueued(vehicle);
args.getWorld()->destroyObjectQueued(vehicle);
}
void game_get_vehicle_position(const ScriptArguments& args)
@ -195,7 +196,7 @@ bool game_character_in_vehicle(const ScriptArguments& args)
bool game_character_in_model(const ScriptArguments& args)
{
auto vdata = args.getVM()->getWorld()->data->findObjectType<VehicleData>(args[1].integer);
auto vdata = args.getWorld()->data->findObjectType<VehicleData>(args[1].integer);
if( vdata )
{
auto controller = (CharacterController*)(*args[0].handle);
@ -240,8 +241,8 @@ bool game_player_in_area_2d_in_vehicle(const ScriptArguments& args)
if( drawCylinder )
{
auto ground = args.getVM()->getWorld()->getGroundAtPosition(glm::vec3(position, 100.f));
args.getVM()->getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, ground + glm::vec3(0.f, 0.f, 4.5f), glm::vec3(radius, 5.f));
auto ground = args.getWorld()->getGroundAtPosition(glm::vec3(position, 100.f));
args.getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, ground + glm::vec3(0.f, 0.f, 4.5f), glm::vec3(radius, 5.f));
}
return false;
@ -263,7 +264,7 @@ bool game_character_near_point_on_foot_3D(const ScriptArguments& args)
if( drawCylinder )
{
args.getVM()->getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, center, size);
args.getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, center, size);
}
return false;
@ -358,8 +359,8 @@ bool game_character_in_zone(const ScriptArguments& args)
auto controller = static_cast<CharacterController*>(*args[0].handle);
std::string zname(args[1].string);
auto zfind = args.getVM()->getWorld()->data->zones.find(zname);
if( zfind != args.getVM()->getWorld()->data->zones.end() ) {
auto zfind = args.getWorld()->data->zones.find(zname);
if( zfind != args.getWorld()->data->zones.end() ) {
auto player = controller->getCharacter()->getPosition();
auto& min = zfind->second.min;
auto& max = zfind->second.max;
@ -378,7 +379,7 @@ void game_create_character_in_vehicle(const ScriptArguments& args)
auto type = args[1].integer;
auto id = args[2].integer;
auto character = args.getVM()->getWorld()->createPedestrian(id, vehicle->getPosition() + spawnMagic);
auto character = args.getWorld()->createPedestrian(id, vehicle->getPosition() + spawnMagic);
auto controller = new DefaultAIController(character);
character->setCurrentVehicle(vehicle, 0);
@ -431,7 +432,7 @@ void game_dont_remove_object(const ScriptArguments& args)
{
auto object = (GameObject*)(*args[0].handle);
auto& mO = args.getVM()->getWorld()->state.missionObjects;
auto& mO = args.getState()->missionObjects;
mO.erase(std::remove(mO.begin(), mO.end(), object), mO.end());
}
@ -464,7 +465,7 @@ bool game_character_stoped_in_volume_in_vehicle(const ScriptArguments& args)
// Request the renderer draw a cylinder here.
if( drawCylinder )
{
args.getVM()->getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, (max+min)/2.f, (max-min)/2.f);
args.getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, (max+min)/2.f, (max-min)/2.f);
}
}
return false;
@ -499,7 +500,7 @@ bool game_character_stoped_in_volume(const ScriptArguments& args)
if( drawCylinder )
{
args.getVM()->getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, (max+min)/2.f, (max-min)/2.f);
args.getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, (max+min)/2.f, (max-min)/2.f);
}
return false;
@ -537,7 +538,7 @@ bool game_objects_in_volume(const ScriptArguments& args)
bool objects = args[9].integer;
bool particles = args[10].integer;
for(GameObject* object : args.getVM()->getWorld()->objects)
for(GameObject* object : args.getWorld()->objects)
{
switch( object->type() )
{
@ -628,7 +629,7 @@ void game_navigate_on_foot(const ScriptArguments& args)
{
auto controller = (CharacterController*)(*args[0].handle);
glm::vec3 target(args[1].real, args[2].real, 0.f);
target = args.getVM()->getWorld()->getGroundAtPosition(target);
target = args.getWorld()->getGroundAtPosition(target);
controller->skipActivity();
@ -663,25 +664,25 @@ void game_create_pickup(const ScriptArguments& args)
auto model = args.getVM()->getFile()->getModels()[id];
std::transform(model.begin(), model.end(), model.begin(), ::tolower);
id = args.getVM()->getWorld()->data->findModelObject(model);
args.getVM()->getWorld()->data->loadDFF(model+".dff");
args.getVM()->getWorld()->data->loadTXD("icons.txd");
id = args.getWorld()->data->findModelObject(model);
args.getWorld()->data->loadDFF(model+".dff");
args.getWorld()->data->loadTXD("icons.txd");
}
else
{
auto data = args.getVM()->getWorld()->data->findObjectType<ObjectData>(id);
auto data = args.getWorld()->data->findObjectType<ObjectData>(id);
if ( ! ( id >= 170 && id <= 184 ) )
{
args.getVM()->getWorld()->data->loadDFF(data->modelName+".dff");
args.getWorld()->data->loadDFF(data->modelName+".dff");
}
args.getVM()->getWorld()->data->loadTXD(data->textureName+".txd");
args.getWorld()->data->loadTXD(data->textureName+".txd");
}
auto pickup = new GenericPickup(args.getVM()->getWorld(), pos, id, type);
auto pickup = new GenericPickup(args.getWorld(), pos, id, type);
args.getVM()->getWorld()->objects.insert(pickup);
args.getWorld()->objects.insert(pickup);
*args[5].handle = pickup;
}
@ -704,7 +705,7 @@ void game_destroy_pickup(const ScriptArguments& args)
if ( pickup )
{
args.getVM()->getWorld()->destroyObjectQueued(pickup);
args.getWorld()->destroyObjectQueued(pickup);
}
}
@ -712,7 +713,7 @@ void game_character_run_to(const ScriptArguments& args)
{
auto controller = (CharacterController*)(*args[0].handle);
glm::vec3 target(args[1].real, args[2].real, 0.f);
target = args.getVM()->getWorld()->getGroundAtPosition(target);
target = args.getWorld()->getGroundAtPosition(target);
controller->setNextActivity(new Activities::GoTo(target));
}
@ -758,7 +759,7 @@ void game_set_vehicle_colours(const ScriptArguments& args)
{
auto vehicle = (VehicleObject*)(*args[0].handle);
auto& colours = args.getVM()->getWorld()->data->vehicleColours;
auto& colours = args.getWorld()->data->vehicleColours;
vehicle->colourPrimary = colours[args[1].integer];
vehicle->colourSecondary = colours[args[2].integer];
}
@ -777,15 +778,15 @@ void game_create_object_world(const ScriptArguments& args)
if( id < 0 ) {
auto& modelname = args.getVM()->getFile()->getModels()[-id];
id = args.getVM()->getWorld()->data->findModelObject(modelname);
id = args.getWorld()->data->findModelObject(modelname);
if( id == (uint16_t)-1 ) {
args.getVM()->getWorld()->logger->error("SCM", "Failed to find model " + modelname);
args.getWorld()->logger->error("SCM", "Failed to find model " + modelname);
}
}
glm::vec3 position(args[1].real, args[2].real, args[3].real);
auto inst = args.getVM()->getWorld()->createInstance(id, position);
auto inst = args.getWorld()->createInstance(id, position);
*args[4].handle = inst;
}
@ -794,7 +795,7 @@ void game_destroy_object(const ScriptArguments& args)
{
auto object = static_cast<GameObject*>(*args[0].handle);
args.getVM()->getWorld()->destroyObjectQueued(object);
args.getWorld()->destroyObjectQueued(object);
}
bool game_is_boat(const ScriptArguments& args)
@ -841,7 +842,7 @@ void game_set_close_object_visible(const ScriptArguments& args)
std::transform(model.begin(), model.end(), model.begin(), ::tolower);
for(auto o : args.getVM()->getWorld()->objects) {
for(auto o : args.getWorld()->objects) {
if( o->type() == GameObject::Instance ) {
if( !o->model ) continue;
if( o->model->name != model ) continue;
@ -894,20 +895,20 @@ void game_change_nearest_model(const ScriptArguments& args)
std::transform(newmodel.begin(), newmodel.end(), newmodel.begin(), ::tolower);
std::transform(oldmodel.begin(), oldmodel.end(), oldmodel.begin(), ::tolower);
auto newobjectid = args.getVM()->getWorld()->data->findModelObject(newmodel);
auto nobj = args.getVM()->getWorld()->data->findObjectType<ObjectData>(newobjectid);
auto newobjectid = args.getWorld()->data->findModelObject(newmodel);
auto nobj = args.getWorld()->data->findObjectType<ObjectData>(newobjectid);
/// @todo Objects need to adopt the new object ID, not just the model.
for(auto o : args.getVM()->getWorld()->objects) {
for(auto o : args.getWorld()->objects) {
if( o->type() == GameObject::Instance ) {
if( !o->model ) continue;
if( o->model->name != oldmodel ) continue;
float d = glm::distance(position, o->getPosition());
if( d < radius ) {
args.getVM()->getWorld()->data->loadDFF(newmodel + ".dff", false);
args.getWorld()->data->loadDFF(newmodel + ".dff", false);
InstanceObject* inst = static_cast<InstanceObject*>(o);
inst->changeModel(nobj);
inst->model = args.getVM()->getWorld()->data->models[newmodel];
inst->model = args.getWorld()->data->models[newmodel];
}
}
}

View File

@ -2,6 +2,7 @@
#include <script/ScriptMachine.hpp>
#include <script/SCMFile.hpp>
#include <engine/GameWorld.hpp>
#include <engine/GameState.hpp>
SCMThread::pc_t localizeLabel(SCMThread* t, int label)
{
@ -158,14 +159,14 @@ void vm_new_mission_thread(const ScriptArguments& args)
void vm_mission_over(const ScriptArguments& args)
{
for( auto& o : args.getVM()->getWorld()->state.missionObjects )
for( auto& o : args.getState()->missionObjects )
{
args.getVM()->getWorld()->destroyObjectQueued(o);
args.getWorld()->destroyObjectQueued(o);
}
args.getVM()->getWorld()->state.missionObjects.clear();
args.getState()->missionObjects.clear();
*args.getVM()->getWorld()->state.scriptOnMissionFlag = 0;
*args.getState()->scriptOnMissionFlag = 0;
}
void vm_name_thread(const ScriptArguments& args)

View File

@ -46,7 +46,7 @@ void drawOnScreenText(GameWorld* world, GameRenderer* renderer)
ti.screenPosition = glm::vec2( 10.f, 10.f );
ti.size = 20.f;
for(OnscreenText& t : world->state.text)
for(OnscreenText& t : world->state->text)
{
glm::vec2 shadowOffset( 0, 0 );
@ -133,7 +133,7 @@ void drawOnScreenText(GameWorld* world, GameRenderer* renderer)
renderer->text.renderText(ti);
}
for(auto& t : world->state.texts) {
for(auto& t : world->state->texts) {
ti.font = 2;
ti.screenPosition = t.position / glm::vec2(640, 480);
ti.screenPosition *= vp;

View File

@ -26,7 +26,7 @@ DebugDraw* debug;
StdOutReciever logPrinter;
RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
: state(nullptr), engine(nullptr), renderer(nullptr), script(nullptr), inFocus(true),
: state(nullptr), world(nullptr), renderer(nullptr), script(nullptr), inFocus(true),
showDebugStats(false), showDebugPaths(false), showDebugPhysics(false),
accum(0.f), timescale(1.f)
{
@ -145,7 +145,7 @@ RWGame::~RWGame()
{
delete script;
delete renderer;
delete engine;
delete world;
delete state;
}
@ -158,13 +158,17 @@ void RWGame::newGame()
}
state = new GameState;
engine = new GameWorld(&log, &work, data);
engine->dynamicsWorld->setDebugDrawer(debug);
world = new GameWorld(&log, &work, data);
world->dynamicsWorld->setDebugDrawer(debug);
// Associate the new world with the new state and vice versa
state->world = world;
world->state = state;
}
void RWGame::startScript(const std::string& name)
{
SCMFile* f = engine->data->loadSCM(name);
SCMFile* f = world->data->loadSCM(name);
if( f ) {
if( script ) delete script;
@ -173,7 +177,7 @@ void RWGame::startScript(const std::string& name)
opcodes->modules.push_back(new GameModule);
opcodes->modules.push_back(new ObjectModule);
script = new ScriptMachine(engine, f, opcodes);
script = new ScriptMachine(state, f, opcodes);
// Set up breakpoint handler
script->setBreakpointHandler(
@ -271,59 +275,59 @@ int RWGame::run()
void RWGame::tick(float dt)
{
// Clear out any per-tick state.
engine->clearTickData();
world->clearTickData();
// Process the Engine's background work.
engine->_work->update();
world->_work->update();
State* state = StateManager::get().states.back();
State* currState = StateManager::get().states.back();
static float clockAccumulator = 0.f;
if (inFocus && state->shouldWorldUpdate() ) {
engine->gameTime += dt;
if (inFocus && currState->shouldWorldUpdate() ) {
world->gameTime += dt;
clockAccumulator += dt;
while( clockAccumulator >= 1.f ) {
engine->state.minute ++;
while( engine->state.minute >= 60 ) {
engine->state.minute = 0;
engine->state.hour ++;
while( engine->state.hour >= 24 ) {
engine->state.hour = 0;
world->state->minute ++;
while( state->minute >= 60 ) {
state->minute = 0;
state->hour ++;
while( state->hour >= 24 ) {
state->hour = 0;
}
}
clockAccumulator -= 1.f;
}
// Clean up old VisualFX
for( int i = 0; i < engine->effects.size(); ++i )
for( int i = 0; i < world->effects.size(); ++i )
{
VisualFX* effect = engine->effects[i];
VisualFX* effect = world->effects[i];
if( effect->getType() == VisualFX::Particle )
{
auto& part = effect->particle;
if( part.lifetime < 0.f ) continue;
if( engine->gameTime >= part.starttime + part.lifetime )
if( world->gameTime >= part.starttime + part.lifetime )
{
engine->destroyEffect( effect );
world->destroyEffect( effect );
--i;
}
}
}
for( GameObject* object : engine->objects ) {
for( GameObject* object : world->objects ) {
object->_updateLastTransform();
object->tick(dt);
}
engine->destroyQueuedObjects();
engine->state.texts.clear();
world->destroyQueuedObjects();
state->texts.clear();
for( int i = 0; i < engine->state.text.size(); )
for( int i = 0; i < state->text.size(); )
{
auto& text = engine->state.text[i];
if( engine->gameTime > text.osTextStart + text.osTextTime )
auto& text = state->text[i];
if( world->gameTime > text.osTextStart + text.osTextTime )
{
engine->state.text.erase(engine->state.text.begin() + i);
state->text.erase(state->text.begin() + i);
}
else
{
@ -331,7 +335,7 @@ void RWGame::tick(float dt)
}
}
engine->dynamicsWorld->stepSimulation(dt, 2, dt);
world->dynamicsWorld->stepSimulation(dt, 2, dt);
if( script ) {
try {
@ -344,18 +348,18 @@ void RWGame::tick(float dt)
}
}
if ( engine->state.player )
if ( state->player )
{
// Use the current camera position to spawn pedestrians.
auto p = nextCam.position;
engine->cleanupTraffic(p);
engine->createTraffic(p);
world->cleanupTraffic(p);
world->createTraffic(p);
}
}
// render() needs two cameras to smoothly interpolate between ticks.
lastCam = nextCam;
nextCam = state->getCamera();
nextCam = currState->getCamera();
}
void RWGame::render(float alpha, float time)
@ -369,10 +373,10 @@ void RWGame::render(float alpha, float time)
ViewCamera viewCam;
viewCam.frustum.fov = glm::radians(90.f);
if( engine->state.currentCutscene != nullptr && engine->state.cutsceneStartTime >= 0.f )
if( state->currentCutscene != nullptr && state->cutsceneStartTime >= 0.f )
{
auto cutscene = engine->state.currentCutscene;
float cutsceneTime = std::min(engine->gameTime - engine->state.cutsceneStartTime,
auto cutscene = state->currentCutscene;
float cutsceneTime = std::min(world->gameTime - state->cutsceneStartTime,
cutscene->tracks.duration);
cutsceneTime += GAME_TIMESTEP * alpha;
glm::vec3 cameraPos = cutscene->tracks.getPositionAt(cutsceneTime),
@ -406,10 +410,10 @@ void RWGame::render(float alpha, float time)
viewCam.position = cameraPos;
viewCam.rotation = glm::inverse(glm::quat_cast(m)) * qtilt;
}
else if( engine->state.cameraFixed )
else if( state->cameraFixed )
{
viewCam.position = engine->state.cameraPosition;
viewCam.rotation = engine->state.cameraRotation;
viewCam.position = state->cameraPosition;
viewCam.rotation = state->cameraRotation;
}
else
{
@ -420,7 +424,7 @@ void RWGame::render(float alpha, float time)
viewCam.frustum.aspectRatio = window.getSize().x / (float) window.getSize().y;
if ( engine->state.isCinematic )
if ( state->isCinematic )
{
viewCam.frustum.fov *= viewCam.frustum.aspectRatio;
}
@ -430,7 +434,7 @@ void RWGame::render(float alpha, float time)
renderer->getRenderer()->pushDebugGroup("World");
renderer->renderWorld(engine, viewCam, alpha);
renderer->renderWorld(world, viewCam, alpha);
auto rendertime = renderer->getRenderer()->popDebugGroup();
@ -446,14 +450,14 @@ void RWGame::render(float alpha, float time)
if( showDebugPhysics )
{
if( engine )
if( world )
{
engine->dynamicsWorld->debugDrawWorld();
world->dynamicsWorld->debugDrawWorld();
debug->flush(renderer);
}
}
drawOnScreenText(engine, renderer);
drawOnScreenText(world, renderer);
}
void RWGame::renderDebugStats(float time, Renderer::ProfileInfo& worldRenderTime)
@ -498,7 +502,7 @@ void RWGame::renderDebugStats(float time, Renderer::ProfileInfo& worldRenderTime
// Count the number of interesting objects.
int peds = 0, cars = 0;
for( GameObject* object : engine->objects )
for( GameObject* object : world->objects )
{
switch ( object->type() )
{
@ -510,10 +514,10 @@ void RWGame::renderDebugStats(float time, Renderer::ProfileInfo& worldRenderTime
ss << "P " << peds << " V " << cars << "\n";
if( engine->state.player ) {
if( state->player ) {
ss << "Player Activity: ";
if( engine->state.player->getCurrentActivity() ) {
ss << engine->state.player->getCurrentActivity()->name();
if( state->player->getCurrentActivity() ) {
ss << state->player->getCurrentActivity()->name();
}
else {
ss << "Idle";
@ -562,7 +566,7 @@ void RWGame::renderDebugPaths(float time)
btVector3 roadColour(1.f, 0.f, 0.f);
btVector3 pedColour(0.f, 0.f, 1.f);
for( AIGraphNode* n : engine->aigraph.nodes )
for( AIGraphNode* n : world->aigraph.nodes )
{
btVector3 p( n->position.x, n->position.y, n->position.z );
auto& col = n->type == AIGraphNode::Pedestrian ? pedColour : roadColour;
@ -584,10 +588,10 @@ void RWGame::globalKeyEvent(const sf::Event& event)
{
switch (event.key.code) {
case sf::Keyboard::LBracket:
engine->state.minute -= 30.f;
state->minute -= 30.f;
break;
case sf::Keyboard::RBracket:
engine->state.minute += 30.f;
state->minute += 30.f;
break;
case sf::Keyboard::Num9:
timescale *= 0.5f;

View File

@ -15,7 +15,7 @@ class RWGame
Logger log;
GameState* state;
GameData* data;
GameWorld* engine;
GameWorld* world;
// must be allocated after Logger setup.
GameRenderer* renderer;
ScriptMachine* script;
@ -51,7 +51,7 @@ public:
GameWorld* getWorld() const
{
return engine;
return world;
}
GameRenderer* getRenderer() const
@ -84,7 +84,7 @@ public:
auto to = btVector3(start.x+direction.x, start.y+direction.y, start.z+direction.z);
btCollisionWorld::ClosestRayResultCallback ray(from, to);
engine->dynamicsWorld->rayTest(from, to, ray);
world->dynamicsWorld->rayTest(from, to, ray);
if( ray.hasHit() )
{
hit = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),

View File

@ -3,6 +3,7 @@
#include <ai/PlayerController.hpp>
#include <objects/CharacterObject.hpp>
#include <objects/VehicleObject.hpp>
#include <engine/GameState.hpp>
#include <sstream>
#include <glm/gtx/string_cast.hpp>
@ -39,7 +40,7 @@ DebugState::DebugState(RWGame* game, const glm::vec3& vp, const glm::quat& vd)
spawnVehicle(it->first);
}, entryHeight));
m->addEntry(Menu::lambda("Open All Doors/Flaps", [=] {
auto pc = getWorld()->state.player->getCharacter();
auto pc = getWorld()->state->player->getCharacter();
auto pv = pc->getCurrentVehicle();
if( pv ) {
for(auto& it : pv->_hingedObjects) {
@ -72,33 +73,33 @@ DebugState::DebugState(RWGame* game, const glm::vec3& vp, const glm::quat& vd)
}
#endif
m->addEntry(Menu::lambda("Jump to Garage", [=] {
jumpCharacter(game, game->getWorld()->state.player, glm::vec3(270.f, -605.f, 40.f));
jumpCharacter(game, game->getWorld()->state->player, glm::vec3(270.f, -605.f, 40.f));
}, entryHeight));
m->addEntry(Menu::lambda("Jump to Airport", [=] {
jumpCharacter(game, game->getWorld()->state.player, glm::vec3(-950.f, -980.f, 12.f));
jumpCharacter(game, game->getWorld()->state->player, glm::vec3(-950.f, -980.f, 12.f));
}, entryHeight));
m->addEntry(Menu::lambda("Jump to Hideout", [=] {
jumpCharacter(game, game->getWorld()->state.player, glm::vec3(875.0, -309.0, 100.0));
jumpCharacter(game, game->getWorld()->state->player, glm::vec3(875.0, -309.0, 100.0));
}, entryHeight));
m->addEntry(Menu::lambda("Jump to Luigi's", [=] {
jumpCharacter(game, game->getWorld()->state.player, glm::vec3(902.75, -425.56, 100.0));
jumpCharacter(game, game->getWorld()->state->player, glm::vec3(902.75, -425.56, 100.0));
}, entryHeight));
m->addEntry(Menu::lambda("Jump to Hospital", [=] {
jumpCharacter(game, game->getWorld()->state.player, glm::vec3(1123.77, -569.15, 100.0));
jumpCharacter(game, game->getWorld()->state->player, glm::vec3(1123.77, -569.15, 100.0));
}, entryHeight));
m->addEntry(Menu::lambda("Add Follower", [=] {
auto spawnPos = game->getWorld()->state.player->getCharacter()->getPosition();
spawnPos += game->getWorld()->state.player->getCharacter()->getRotation() * glm::vec3(-1.f, 0.f, 0.f);
auto spawnPos = game->getWorld()->state->player->getCharacter()->getPosition();
spawnPos += game->getWorld()->state->player->getCharacter()->getRotation() * glm::vec3(-1.f, 0.f, 0.f);
auto follower = game->getWorld()->createPedestrian(12, spawnPos);
jumpCharacter(game, follower->controller, spawnPos);
follower->controller->setGoal(CharacterController::FollowLeader);
follower->controller->setTargetCharacter(game->getWorld()->state.player->getCharacter());
follower->controller->setTargetCharacter(game->getWorld()->state->player->getCharacter());
}, entryHeight));
m->addEntry(Menu::lambda("Set Super Jump", [=] {
game->getWorld()->state.player->getCharacter()->setJumpSpeed(20.f);
game->getWorld()->state->player->getCharacter()->setJumpSpeed(20.f);
}, entryHeight));
m->addEntry(Menu::lambda("Set Normal Jump", [=] {
game->getWorld()->state.player->getCharacter()->setJumpSpeed(CharacterObject::DefaultJumpSpeed);
game->getWorld()->state->player->getCharacter()->setJumpSpeed(CharacterObject::DefaultJumpSpeed);
}, entryHeight));
this->enterMenu(m);
@ -236,7 +237,7 @@ void DebugState::handleEvent(const sf::Event &e)
void DebugState::spawnVehicle(unsigned int id)
{
auto ch = getWorld()->state.player->getCharacter();
auto ch = getWorld()->state->player->getCharacter();
if(! ch) return;
glm::vec3 fwd = ch->rotation * glm::vec3(0.f, 1.f, 0.f);

View File

@ -11,6 +11,7 @@
#include <render/Model.hpp>
#include <items/WeaponItem.hpp>
#include <engine/GameWorld.hpp>
#include <engine/GameState.hpp>
#include <script/ScriptMachine.hpp>
#include <dynamics/RaycastCallbacks.hpp>
@ -26,7 +27,7 @@ void IngameState::startTest()
auto playerChar = getWorld()->createPedestrian(1, {270.f, -605.f, 40.f});
auto player = new PlayerController(playerChar);
getWorld()->state.player = player;
getWorld()->state->player = player;
/*auto bat = new WeaponItem(getWorld()->data.weaponData["ak47"]);
_playerCharacter->addToInventory(bat);
@ -71,7 +72,7 @@ void IngameState::startGame()
PlayerController *IngameState::getPlayer()
{
return getWorld()->state.player;
return getWorld()->state->player;
}
void IngameState::enter()
@ -134,7 +135,7 @@ void IngameState::tick(float dt)
player->updateMovementDirection(angle * _movement, _movement);
auto target = getWorld()->state.cameraTarget;
auto target = getWorld()->state->cameraTarget;
if( target == nullptr )
{
@ -227,7 +228,7 @@ void IngameState::tick(float dt)
void IngameState::draw(GameRenderer* r)
{
if( !getWorld()->state.isCinematic && getWorld()->isCutsceneDone() )
if( !getWorld()->state->isCinematic && getWorld()->isCutsceneDone() )
{
drawHUD(getPlayer(), getWorld(), r);
}
@ -249,9 +250,9 @@ void IngameState::handleEvent(const sf::Event &event)
StateManager::get().enter(new DebugState(game, _look.position, _look.rotation));
break;
case sf::Keyboard::Space:
if( getWorld()->state.currentCutscene )
if( getWorld()->state->currentCutscene )
{
getWorld()->state.skipCutscene = true;
getWorld()->state->skipCutscene = true;
}
else if( player && player->isInputEnabled() ) {
if( player->getCharacter()->getCurrentVehicle() ) {