diff --git a/rwengine/include/engine/GameWorld.hpp b/rwengine/include/engine/GameWorld.hpp index b30fb491..3edc95e9 100644 --- a/rwengine/include/engine/GameWorld.hpp +++ b/rwengine/include/engine/GameWorld.hpp @@ -4,7 +4,9 @@ class Logger; -#include +#include + +class GameData; #include #include @@ -20,6 +22,7 @@ class InstanceObject; class VehicleObject; #include +#include struct WeaponScan; @@ -58,7 +61,7 @@ class GameWorld { public: - GameWorld(Logger* log, const std::string& gamepath); + GameWorld(Logger* log, GameData* dat); ~GameWorld(); @@ -149,7 +152,7 @@ public: /** * Game data */ - GameData gameData; + GameData* data; /** * Gameplay state diff --git a/rwengine/src/ai/CharacterController.cpp b/rwengine/src/ai/CharacterController.cpp index 456cbf22..82f538ae 100644 --- a/rwengine/src/ai/CharacterController.cpp +++ b/rwengine/src/ai/CharacterController.cpp @@ -386,6 +386,7 @@ bool Activities::ExitVehicle::update(CharacterObject *character, CharacterContro } #include +#include #include bool Activities::ShootWeapon::update(CharacterObject *character, CharacterController *controller) { @@ -397,7 +398,7 @@ bool Activities::ShootWeapon::update(CharacterObject *character, CharacterContro if( wepdata->fireType == WeaponData::INSTANT_HIT ) { if( _item->isFiring() ) { - auto shootanim = character->engine->gameData.animations[wepdata->animation1]; + auto shootanim = character->engine->data->animations[wepdata->animation1]; if( shootanim ) { if( character->animator->getAnimation() != shootanim ) { character->playAnimation(shootanim, false); @@ -427,8 +428,8 @@ bool Activities::ShootWeapon::update(CharacterObject *character, CharacterContro } /// @todo Use Thrown flag instead of project (RPG isn't thrown eg.) else if( wepdata->fireType == WeaponData::PROJECTILE ) { - auto shootanim = character->engine->gameData.animations[wepdata->animation1]; - auto throwanim = character->engine->gameData.animations[wepdata->animation2]; + auto shootanim = character->engine->data->animations[wepdata->animation1]; + auto throwanim = character->engine->data->animations[wepdata->animation2]; if( character->animator->getAnimation() == shootanim ) { if( character->animator->isCompleted() ) { diff --git a/rwengine/src/dynamics/CollisionInstance.cpp b/rwengine/src/dynamics/CollisionInstance.cpp index 2d494136..c25a3cac 100644 --- a/rwengine/src/dynamics/CollisionInstance.cpp +++ b/rwengine/src/dynamics/CollisionInstance.cpp @@ -28,8 +28,8 @@ CollisionInstance::~CollisionInstance() bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string& modelName, DynamicObjectData *dynamics, VehicleHandlingInfo *handling) { - auto phyit = object->engine->gameData.collisions.find(modelName); - if( phyit != object->engine->gameData.collisions.end()) { + auto phyit = object->engine->data->collisions.find(modelName); + if( phyit != object->engine->data->collisions.end()) { btCompoundShape* cmpShape = new btCompoundShape; auto p = object->getPosition(); diff --git a/rwengine/src/engine/GameData.cpp b/rwengine/src/engine/GameData.cpp index e794ee8d..18db948a 100644 --- a/rwengine/src/engine/GameData.cpp +++ b/rwengine/src/engine/GameData.cpp @@ -550,7 +550,7 @@ int GameData::getWaterIndexAt(const glm::vec3 &ws) const if( wX >= 0 && wX < WATER_HQ_DATA_SIZE && wY >= 0 && wY < WATER_HQ_DATA_SIZE ) { int i = (wX*WATER_HQ_DATA_SIZE) + wY; - return engine->gameData.realWater[i]; + return engine->data->realWater[i]; } return 0; } diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 02a381be..3098b263 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -73,12 +74,12 @@ public: } }; -GameWorld::GameWorld(Logger* log, const std::string& path) - : logger(log), gameTime(0.f), gameData(log, path), randomEngine(rand()), +GameWorld::GameWorld(Logger* log, GameData* dat) + : logger(log), gameTime(0.f), data(dat), randomEngine(rand()), _work( new WorkContext( this ) ), cutsceneAudio(nullptr), missionAudio(nullptr), paused(false) { - gameData.engine = this; + data->engine = this; collisionConfig = new btDefaultCollisionConfiguration; collisionDispatcher = new WorldCollisionDispatcher(collisionConfig); @@ -110,7 +111,7 @@ GameWorld::~GameWorld() bool GameWorld::defineItems(const std::string& name) { - auto i = gameData.ideLocations.find(name); + auto i = data->ideLocations.find(name); std::string path = name; LoaderIDE idel; @@ -141,7 +142,7 @@ bool GameWorld::defineItems(const std::string& name) bool GameWorld::placeItems(const std::string& name) { - auto i = gameData.iplLocations.find(name); + auto i = data->iplLocations.find(name); std::string path = name; LoaderIPL ipll; @@ -194,19 +195,19 @@ InstanceObject *GameWorld::createInstance(const uint16_t id, const glm::vec3& po // Ensure the relevant data is loaded. if(! oi->modelName.empty()) { if( modelname != "null" ) { - gameData.loadDFF(modelname + ".dff", false); + data->loadDFF(modelname + ".dff", false); } } if(! texturename.empty()) { - gameData.loadTXD(texturename + ".txd", true); + data->loadTXD(texturename + ".txd", true); } - ModelRef m = gameData.models[modelname]; + ModelRef m = data->models[modelname]; // Check for dynamic data. - auto dyit = gameData.dynamicObjectData.find(oi->modelName); + auto dyit = data->dynamicObjectData.find(oi->modelName); std::shared_ptr dydata; - if( dyit != gameData.dynamicObjectData.end() ) { + if( dyit != data->dynamicObjectData.end() ) { dydata = dyit->second; } @@ -335,15 +336,15 @@ CutsceneObject *GameWorld::createCutsceneObject(const uint16_t id, const glm::ve } if( modelname != "null" ) { - gameData.loadDFF(modelname + ".dff", false); + data->loadDFF(modelname + ".dff", false); } if(! texturename.empty()) { - gameData.loadTXD(texturename + ".txd", true); + data->loadTXD(texturename + ".txd", true); } - ModelRef m = gameData.models[modelname]; + ModelRef m = data->models[modelname]; auto instance = new CutsceneObject( this, @@ -363,19 +364,19 @@ VehicleObject *GameWorld::createVehicle(const uint16_t id, const glm::vec3& pos, logger->info("World", "Creating Vehicle ID " + std::to_string(id) + " (" + vti->gameName + ")"); if(! vti->modelName.empty()) { - gameData.loadDFF(vti->modelName + ".dff"); + data->loadDFF(vti->modelName + ".dff"); } if(! vti->textureName.empty()) { - gameData.loadTXD(vti->textureName + ".txd"); + data->loadTXD(vti->textureName + ".txd"); } glm::u8vec3 prim(255), sec(128); - auto palit = gameData.vehiclePalettes.find(vti->modelName); // modelname is conveniently lowercase (usually) - if(palit != gameData.vehiclePalettes.end() && palit->second.size() > 0 ) { + auto palit = data->vehiclePalettes.find(vti->modelName); // modelname is conveniently lowercase (usually) + if(palit != data->vehiclePalettes.end() && palit->second.size() > 0 ) { std::uniform_int_distribution uniform(0, palit->second.size()-1); int set = uniform(randomEngine); - prim = gameData.vehicleColours[palit->second[set].first]; - sec = gameData.vehicleColours[palit->second[set].second]; + prim = data->vehicleColours[palit->second[set].first]; + sec = data->vehicleColours[palit->second[set].second]; } else { logger->warning("World", "No colour palette for vehicle " + vti->modelName); @@ -385,14 +386,14 @@ VehicleObject *GameWorld::createVehicle(const uint16_t id, const glm::vec3& pos, if( wi ) { if(! wi->textureName.empty()) { - gameData.loadTXD(wi->textureName + ".txd"); + data->loadTXD(wi->textureName + ".txd"); } } - ModelRef& m = gameData.models[vti->modelName]; + ModelRef& m = data->models[vti->modelName]; auto model = m->resource; - auto info = gameData.vehicleInfo.find(vti->handlingID); - if(model && info != gameData.vehicleInfo.end()) { + auto info = data->vehicleInfo.find(vti->handlingID); + if(model && info != data->vehicleInfo.end()) { if( info->second->wheels.size() == 0 && info->second->seats.size() == 0 ) { for( const ModelFrame* f : model->frames ) { const std::string& name = f->getName(); @@ -442,14 +443,14 @@ CharacterObject* GameWorld::createPedestrian(const uint16_t id, const glm::vec3 } if( modelname != "null" ) { - gameData.loadDFF(modelname + ".dff"); + data->loadDFF(modelname + ".dff"); } } if(! texturename.empty()) { - gameData.loadTXD(texturename + ".txd"); + data->loadTXD(texturename + ".txd"); } - ModelRef m = gameData.models[modelname]; + ModelRef m = data->models[modelname]; if(m && m->resource) { auto ped = new CharacterObject( this, pos, rot, m, pt ); @@ -714,7 +715,7 @@ void GameWorld::loadCutscene(const std::string &name) std::string lowerName(name); std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); - auto datfile = gameData.openFile(lowerName + ".dat"); + auto datfile = data->openFile(lowerName + ".dat"); CutsceneData* cutscene = new CutsceneData; @@ -723,13 +724,13 @@ void GameWorld::loadCutscene(const std::string &name) loaderdat.load(cutscene->tracks, datfile); } - gameData.loadIFP(lowerName + ".ifp"); + data->loadIFP(lowerName + ".ifp"); - cutsceneAudioLoaded = gameData.loadAudioStream(name+".mp3"); + cutsceneAudioLoaded = data->loadAudioStream(name+".mp3"); if ( !cutsceneAudioLoaded ) { - cutsceneAudioLoaded = gameData.loadAudioStream(name+".wav"); + cutsceneAudioLoaded = data->loadAudioStream(name+".wav"); } if ( !cutsceneAudioLoaded ) diff --git a/rwengine/src/items/WeaponItem.cpp b/rwengine/src/items/WeaponItem.cpp index f1233fb7..f5ccadaf 100644 --- a/rwengine/src/items/WeaponItem.cpp +++ b/rwengine/src/items/WeaponItem.cpp @@ -6,6 +6,7 @@ #include #include #include +#include void WeaponItem::fireHitscan() { @@ -34,9 +35,9 @@ void WeaponItem::fireHitscan() // - smoke emited at hit point // - gunflash - auto tracerTex = _character->engine->gameData.findTexture("shad_exp")->getName(); - auto flashTex = _character->engine->gameData.findTexture("gunflash2")->getName(); - auto flashTex1 = _character->engine->gameData.findTexture("gunflash1")->getName(); + auto tracerTex = _character->engine->data->findTexture("shad_exp")->getName(); + auto flashTex = _character->engine->data->findTexture("gunflash2")->getName(); + auto flashTex1 = _character->engine->data->findTexture("gunflash1")->getName(); float tracertime = 0.1f; auto distance = glm::distance(fireOrigin, farTarget); diff --git a/rwengine/src/objects/CharacterObject.cpp b/rwengine/src/objects/CharacterObject.cpp index 98b64bf6..5cab26d4 100644 --- a/rwengine/src/objects/CharacterObject.cpp +++ b/rwengine/src/objects/CharacterObject.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -21,33 +22,33 @@ CharacterObject::CharacterObject(GameWorld* engine, const glm::vec3& pos, const mHealth = 100.f; // TODO move AnimationGroup creation somewhere else. - animations.idle = engine->gameData.animations["idle_stance"]; - animations.walk = engine->gameData.animations["walk_player"]; - animations.walk_start = engine->gameData.animations["walk_start"]; - animations.run = engine->gameData.animations["run_player"]; + animations.idle = engine->data->animations["idle_stance"]; + animations.walk = engine->data->animations["walk_player"]; + animations.walk_start = engine->data->animations["walk_start"]; + animations.run = engine->data->animations["run_player"]; - animations.walk_right = engine->gameData.animations["walk_player_right"]; - animations.walk_right_start = engine->gameData.animations["walk_start_right"]; - animations.walk_left = engine->gameData.animations["walk_player_left"]; - animations.walk_left_start = engine->gameData.animations["walk_start_left"]; + animations.walk_right = engine->data->animations["walk_player_right"]; + animations.walk_right_start = engine->data->animations["walk_start_right"]; + animations.walk_left = engine->data->animations["walk_player_left"]; + animations.walk_left_start = engine->data->animations["walk_start_left"]; - animations.walk_back = engine->gameData.animations["walk_player_back"]; - animations.walk_back_start = engine->gameData.animations["walk_start_back"]; + animations.walk_back = engine->data->animations["walk_player_back"]; + animations.walk_back_start = engine->data->animations["walk_start_back"]; - animations.jump_start = engine->gameData.animations["jump_launch"]; - animations.jump_glide = engine->gameData.animations["jump_glide"]; - animations.jump_land = engine->gameData.animations["jump_land"]; + animations.jump_start = engine->data->animations["jump_launch"]; + animations.jump_glide = engine->data->animations["jump_glide"]; + animations.jump_land = engine->data->animations["jump_land"]; - animations.car_sit = engine->gameData.animations["car_sit"]; - animations.car_sit_low = engine->gameData.animations["car_lsit"]; + animations.car_sit = engine->data->animations["car_sit"]; + animations.car_sit_low = engine->data->animations["car_lsit"]; - animations.car_open_lhs = engine->gameData.animations["car_open_lhs"]; - animations.car_getin_lhs = engine->gameData.animations["car_getin_lhs"]; - animations.car_getout_lhs = engine->gameData.animations["car_getout_lhs"]; + animations.car_open_lhs = engine->data->animations["car_open_lhs"]; + animations.car_getin_lhs = engine->data->animations["car_getin_lhs"]; + animations.car_getout_lhs = engine->data->animations["car_getout_lhs"]; - animations.car_open_rhs = engine->gameData.animations["car_open_rhs"]; - animations.car_getin_rhs = engine->gameData.animations["car_getin_rhs"]; - animations.car_getout_rhs = engine->gameData.animations["car_getout_rhs"]; + animations.car_open_rhs = engine->data->animations["car_open_rhs"]; + animations.car_getin_rhs = engine->data->animations["car_getin_rhs"]; + animations.car_getout_rhs = engine->data->animations["car_getout_rhs"]; if(model) { skeleton = new Skeleton; @@ -134,10 +135,10 @@ void CharacterObject::changeCharacterModel(const std::string &name) auto modelName = std::string(name); std::transform(modelName.begin(), modelName.end(), modelName.begin(), ::tolower); - engine->gameData.loadDFF(modelName + ".dff"); - engine->gameData.loadTXD(modelName + ".txd"); + engine->data->loadDFF(modelName + ".dff"); + engine->data->loadTXD(modelName + ".txd"); - auto& models = engine->gameData.models; + auto& models = engine->data->models; auto mfind = models.find(modelName); if( mfind != models.end() ) { model = mfind->second; @@ -237,11 +238,11 @@ void CharacterObject::updateCharacter(float dt) position = glm::vec3(Pos.x(), Pos.y(), Pos.z()); // Handle above waist height water. - auto wi = engine->gameData.getWaterIndexAt(getPosition()); + auto wi = engine->data->getWaterIndexAt(getPosition()); if( wi != NO_WATER_INDEX ) { - float wh = engine->gameData.waterHeights[wi]; + float wh = engine->data->waterHeights[wi]; auto ws = getPosition(); - wh += engine->gameData.getWaveHeightAt(ws); + wh += engine->data->getWaveHeightAt(ws); // If Not in water before // If last position was above water diff --git a/rwengine/src/objects/InstanceObject.cpp b/rwengine/src/objects/InstanceObject.cpp index c7237b81..92f53f2c 100644 --- a/rwengine/src/objects/InstanceObject.cpp +++ b/rwengine/src/objects/InstanceObject.cpp @@ -3,6 +3,7 @@ #include #include #include +#include InstanceObject::InstanceObject(GameWorld* engine, const glm::vec3& pos, @@ -60,10 +61,10 @@ void InstanceObject::tick(float dt) if( wX >= 0 && wX < WATER_HQ_DATA_SIZE && wY >= 0 && wY < WATER_HQ_DATA_SIZE ) { int i = (wX*WATER_HQ_DATA_SIZE) + wY; - int hI = engine->gameData.realWater[i]; + int hI = engine->data->realWater[i]; if( hI < NO_WATER_INDEX ) { - wH = engine->gameData.waterHeights[hI]; - wH += engine->gameData.getWaveHeightAt(ws); + wH = engine->data->waterHeights[hI]; + wH += engine->data->getWaveHeightAt(ws); if( vH <= wH ) { inWater = true; } @@ -83,12 +84,12 @@ void InstanceObject::tick(float dt) // Damper motion body->body->setDamping(0.95f, 0.9f); - auto wi = engine->gameData.getWaterIndexAt(ws); + auto wi = engine->data->getWaterIndexAt(ws); if(wi != NO_WATER_INDEX) { - float h = engine->gameData.waterHeights[wi] + oZ; + float h = engine->data->waterHeights[wi] + oZ; // Calculate wave height - h += engine->gameData.getWaveHeightAt(ws); + h += engine->data->getWaveHeightAt(ws); if ( ws.z <= h ) { /*if( dynamics->uprootForce > 0.f && (body->body->getCollisionFlags() & btRigidBody::CF_STATIC_OBJECT) != 0 ) { diff --git a/rwengine/src/objects/PickupObject.cpp b/rwengine/src/objects/PickupObject.cpp index ca532f26..0d423e51 100644 --- a/rwengine/src/objects/PickupObject.cpp +++ b/rwengine/src/objects/PickupObject.cpp @@ -1,6 +1,7 @@ #include #include #include +#include PickupObject::PickupObject(GameWorld *world, const glm::vec3 &position, int modelID) : GameObject(world, position, glm::quat(), nullptr), @@ -22,7 +23,7 @@ PickupObject::PickupObject(GameWorld *world, const glm::vec3 &position, int mode corona->particle.direction = glm::vec3(0.f, 0.f, 1.f); corona->particle.orientation = VisualFX::ParticleData::Camera; corona->particle.colour = glm::vec4(1.0f, 0.3f, 0.3f, 0.3f); - corona->particle.texture = engine->gameData.findTexture("coronacircle"); + corona->particle.texture = engine->data->findTexture("coronacircle"); setEnabled(true); } diff --git a/rwengine/src/objects/ProjectileObject.cpp b/rwengine/src/objects/ProjectileObject.cpp index 632bbc31..5e751607 100644 --- a/rwengine/src/objects/ProjectileObject.cpp +++ b/rwengine/src/objects/ProjectileObject.cpp @@ -1,5 +1,6 @@ #include #include +#include #include void ProjectileObject::checkPhysicsContact() @@ -71,7 +72,7 @@ void ProjectileObject::explode() }); } - auto tex = engine->gameData.findTexture("explo02"); + auto tex = engine->data->findTexture("explo02"); auto explosion = engine->createEffect(VisualFX::Particle); explosion->particle.size = glm::vec2(exp_size); diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index 0c1bad30..e70438c0 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #define PART_CLOSE_VELOCITY 0.25f @@ -247,10 +248,10 @@ void VehicleObject::tickPhysics(float dt) if( wX >= 0 && wX < WATER_HQ_DATA_SIZE && wY >= 0 && wY < WATER_HQ_DATA_SIZE ) { int i = (wX*WATER_HQ_DATA_SIZE) + wY; - int hI = engine->gameData.realWater[i]; + int hI = engine->data->realWater[i]; if( hI < NO_WATER_INDEX ) { - wH = engine->gameData.waterHeights[hI]; - wH += engine->gameData.getWaveHeightAt(ws); + wH = engine->data->waterHeights[hI]; + wH += engine->data->getWaveHeightAt(ws); // If the vehicle is currently underwater if( vH <= wH ) { // and was not underwater here in the last tick @@ -520,12 +521,12 @@ void VehicleObject::setPartState(VehicleObject::Part* part, VehicleObject::Frame void VehicleObject::applyWaterFloat(const glm::vec3 &relPt) { auto ws = getPosition() + relPt; - auto wi = engine->gameData.getWaterIndexAt(ws); + auto wi = engine->data->getWaterIndexAt(ws); if(wi != NO_WATER_INDEX) { - float h = engine->gameData.waterHeights[wi]; + float h = engine->data->waterHeights[wi]; // Calculate wave height - h += engine->gameData.getWaveHeightAt(ws); + h += engine->data->getWaveHeightAt(ws); if ( ws.z <= h ) { float x = (h - ws.z); diff --git a/rwengine/src/render/GameRenderer.cpp b/rwengine/src/render/GameRenderer.cpp index eead69e1..ad5bb1b0 100644 --- a/rwengine/src/render/GameRenderer.cpp +++ b/rwengine/src/render/GameRenderer.cpp @@ -250,7 +250,7 @@ void GameRenderer::renderWorld(const ViewCamera &camera, float alpha) // Requires a float 0-24 auto weatherID = static_cast(engine->state.currentWeather * 24); - auto weather = engine->gameData.weatherLoader.getWeatherData(weatherID, tod); + auto weather = engine->data->weatherLoader.getWeatherData(weatherID, tod); glm::vec3 skyTop = weather.skyTopColor; glm::vec3 skyBottom = weather.skyBottomColor; @@ -374,10 +374,10 @@ void GameRenderer::renderWorld(const ViewCamera &camera, float alpha) profObjects = renderer->popDebugGroup(); // Render arrows above anything that isn't radar only (or hidden) - ModelRef& arrowModel = engine->gameData.models["arrow"]; + ModelRef& arrowModel = engine->data->models["arrow"]; if( arrowModel && arrowModel->resource ) { - auto arrowTex = engine->gameData.textures[{"copblue",""}]; + auto arrowTex = engine->data->textures[{"copblue",""}]; auto arrowFrame = arrowModel->resource->findFrame( "arrow" ); for( auto& blip : engine->state.radarBlips ) { @@ -456,7 +456,7 @@ void GameRenderer::renderWorld(const ViewCamera &camera, float alpha) GLuint splashTexName = 0; auto fc = engine->state.fadeColour; if((fc.r + fc.g + fc.b) == 0 && engine->state.currentSplash.size() > 0) { - auto splash = engine->gameData.findTexture(engine->state.currentSplash); + auto splash = engine->data->findTexture(engine->state.currentSplash); if ( splash ) { splashTexName = splash->getName(); @@ -563,7 +563,7 @@ void GameRenderer::renderVehicle(VehicleObject *vehicle) for( size_t w = 0; w < vehicle->info->wheels.size(); ++w) { auto woi = engine->findObjectType(vehicle->vehicle->wheelModelID); if( woi ) { - Model* wheelModel = engine->gameData.models["wheels"]->resource; + Model* wheelModel = engine->data->models["wheels"]->resource; auto& wi = vehicle->physVehicle->getWheelInfo(w); if( wheelModel ) { // Construct our own matrix so we can use the local transform @@ -713,7 +713,7 @@ void GameRenderer::renderPickup(PickupObject *pickup) /// @todo Better determination of is this object a weapon. if( odata->ID >= 170 && odata->ID <= 184 ) { - auto weapons = engine->gameData.models["weapons"]; + auto weapons = engine->data->models["weapons"]; if( weapons && weapons->resource && odata ) { model = weapons->resource; itemModel = weapons->resource->findFrame(odata->modelName + "_l0"); @@ -725,7 +725,7 @@ void GameRenderer::renderPickup(PickupObject *pickup) } else { - auto handle = engine->gameData.models[odata->modelName]; + auto handle = engine->data->models[odata->modelName]; if ( handle && handle->resource ) { model = handle->resource; @@ -794,7 +794,7 @@ void GameRenderer::renderProjectile(ProjectileObject *projectile) glm::mat4 modelMatrix = projectile->getTimeAdjustedTransform(_renderAlpha); auto odata = engine->findObjectType(projectile->getProjectileInfo().weapon->modelID); - auto weapons = engine->gameData.models["weapons"]; + auto weapons = engine->data->models["weapons"]; if( weapons && weapons->resource ) { auto itemModel = weapons->resource->findFrame(odata->modelName + "_l0"); auto matrix = glm::inverse(itemModel->getTransform()); @@ -838,7 +838,7 @@ void GameRenderer::renderItem(InventoryItem *item, const glm::mat4 &modelMatrix) { // srhand std::shared_ptr odata = engine->findObjectType(item->getModelID()); - auto weapons = engine->gameData.models["weapons"]; + auto weapons = engine->data->models["weapons"]; if( weapons && weapons->resource ) { auto itemModel = weapons->resource->findFrame(odata->modelName + "_l0"); auto matrix = glm::inverse(itemModel->getTransform()); @@ -878,7 +878,7 @@ void GameRenderer::renderGeometry(Model* model, size_t g, const glm::mat4& model { auto& tC = mat.textures[0].name; auto& tA = mat.textures[0].alphaName; - tex = engine->gameData.findTexture(tC, tA); + tex = engine->data->findTexture(tC, tA); if( ! tex ) { //logger->warning("Renderer", "Missing texture: " + tC + " " + tA); @@ -938,7 +938,7 @@ void GameRenderer::renderAreaIndicator(const AreaIndicatorInfo* info) glm::vec3 scale = info->radius + 0.15f * glm::sin(engine->gameTime * 5.f); Renderer::DrawParameters dp; - dp.textures = {engine->gameData.findTexture("cloud1")->getName()}; + dp.textures = {engine->data->findTexture("cloud1")->getName()}; dp.ambient = 1.f; dp.colour = glm::u8vec4(50, 100, 255, 1); dp.start = 0; diff --git a/rwengine/src/render/MapRenderer.cpp b/rwengine/src/render/MapRenderer.cpp index c118d4be..84bf3a5d 100644 --- a/rwengine/src/render/MapRenderer.cpp +++ b/rwengine/src/render/MapRenderer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -122,7 +123,7 @@ void MapRenderer::draw(const MapInfo& mi) { std::string num = (m < 10 ? "0" : ""); std::string name = "radar" + num + std::to_string(m); - auto texture = world->gameData.textures[{name,""}]; + auto texture = world->data->textures[{name,""}]; glBindTexture(GL_TEXTURE_2D, texture->getName()); @@ -197,7 +198,7 @@ void MapRenderer::drawBlip(const glm::vec2& coord, const glm::mat4& model, const GLuint tex = 0; if ( !texture.empty() ) { - auto sprite= world->gameData.findTexture(texture); + auto sprite= world->data->findTexture(texture); tex = sprite->getName(); renderer->setUniform(rectProg, "colour", glm::vec4(0.f)); } diff --git a/rwengine/src/render/TextRenderer.cpp b/rwengine/src/render/TextRenderer.cpp index a3c466ab..869840ed 100644 --- a/rwengine/src/render/TextRenderer.cpp +++ b/rwengine/src/render/TextRenderer.cpp @@ -235,7 +235,7 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti) Renderer::DrawParameters dp; dp.start = 0; dp.count = gb.getCount(); - auto ftexture = engine->gameData.findTexture(fonts[ti.font]); + auto ftexture = engine->data->findTexture(fonts[ti.font]); dp.textures = {ftexture->getName()}; renderer->getRenderer()->drawArrays(glm::mat4(), &db, dp); diff --git a/rwengine/src/render/WaterRenderer.cpp b/rwengine/src/render/WaterRenderer.cpp index a7e7d73f..2a193304 100644 --- a/rwengine/src/render/WaterRenderer.cpp +++ b/rwengine/src/render/WaterRenderer.cpp @@ -107,7 +107,7 @@ void WaterRenderer::render(GameRenderer* renderer, GameWorld* world) { auto r = renderer->getRenderer(); - auto waterTex = world->gameData.findTexture("water_old"); + auto waterTex = world->data->findTexture("water_old"); Renderer::DrawParameters wdp; wdp.start = 0; diff --git a/rwengine/src/script/modules/GameModule.cpp b/rwengine/src/script/modules/GameModule.cpp index 8be6f5fe..689bbbfe 100644 --- a/rwengine/src/script/modules/GameModule.cpp +++ b/rwengine/src/script/modules/GameModule.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,7 @@ void game_print_big(const ScriptArguments& args) { std::string id(args[0].string); - std::string str = args.getVM()->getWorld()->gameData.texts.text(id); + std::string str = args.getVM()->getWorld()->data->texts.text(id); unsigned short style = args[2].integer; args.getVM()->getWorld()->state.text.push_back({ id, @@ -43,7 +44,7 @@ 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()->gameData.texts.text(id); + std::string str = args.getVM()->getWorld()->data->texts.text(id); int flags = args[2].integer; args.getVM()->getWorld()->state.text.push_back({ id, @@ -123,8 +124,8 @@ void game_set_vehicle_generator_count(const ScriptArguments& args) void game_set_zone_car_info(const ScriptArguments& args) { - auto it = args.getVM()->getWorld()->gameData.zones.find(args[0].string); - if( it != args.getVM()->getWorld()->gameData.zones.end() ) + auto it = args.getVM()->getWorld()->data->zones.find(args[0].string); + if( it != args.getVM()->getWorld()->data->zones.end() ) { auto day = args[1].integer == 1; for(int i = 2; i < args.getParameters().size(); ++i) @@ -158,8 +159,8 @@ void game_reset_camera(const ScriptArguments& args) void game_set_zone_ped_info(const ScriptArguments& args) { - auto it = args.getVM()->getWorld()->gameData.zones.find(args[0].string); - if( it != args.getVM()->getWorld()->gameData.zones.end() ) + auto it = args.getVM()->getWorld()->data->zones.find(args[0].string); + if( it != args.getVM()->getWorld()->data->zones.end() ) { auto day = args[1].integer == 1; for(int i = 2; i < args.getParameters().size(); ++i) @@ -330,7 +331,7 @@ void game_get_runtime(const ScriptArguments& args) void game_print_big_with_number(const ScriptArguments& args) { std::string id(args[0].string); - std::string str = args.getVM()->getWorld()->gameData.texts.text(id); + std::string str = args.getVM()->getWorld()->data->texts.text(id); int number = args[1].integer; str += "\n" + std::to_string(number); @@ -408,8 +409,8 @@ bool game_special_char_loaded(const ScriptArguments& args) { auto chartype = args.getVM()->getWorld()->findObjectType(args[0].integer); if( chartype ) { - auto modelfind = args.getVM()->getWorld()->gameData.models.find(chartype->modelName); - if( modelfind != args.getVM()->getWorld()->gameData.models.end() && modelfind->second->resource != nullptr ) { + auto modelfind = args.getVM()->getWorld()->data->models.find(chartype->modelName); + if( modelfind != args.getVM()->getWorld()->data->models.end() && modelfind->second->resource != nullptr ) { return true; } } @@ -562,7 +563,7 @@ void game_set_cutscene_anim(const ScriptArguments& args) GameObject* object = static_cast(*args[0].handle); std::string animName = args[1].string; std::transform(animName.begin(), animName.end(), animName.begin(), ::tolower); - Animation* anim = args.getVM()->getWorld()->gameData.animations[animName]; + Animation* anim = args.getVM()->getWorld()->data->animations[animName]; if( anim ) { object->animator->setAnimation(anim, false); } @@ -628,7 +629,7 @@ void game_set_head_animation(const ScriptArguments& args) GameObject* object = static_cast(*args[0].handle); std::string animName = args[1].string; std::transform(animName.begin(), animName.end(), animName.begin(), ::tolower); - Animation* anim = args.getVM()->getWorld()->gameData.animations[animName]; + Animation* anim = args.getVM()->getWorld()->data->animations[animName]; if( anim ) { object->animator->setAnimation(anim, false); } @@ -659,8 +660,8 @@ void game_set_last_mission(const ScriptArguments& args) void game_set_zone_ped_group(const ScriptArguments& args) { - auto it = args.getVM()->getWorld()->gameData.zones.find(args[0].string); - if( it != args.getVM()->getWorld()->gameData.zones.end() ) + auto it = args.getVM()->getWorld()->data->zones.find(args[0].string); + if( it != args.getVM()->getWorld()->data->zones.end() ) { auto day = args[1].integer == 1; if( day ) @@ -678,7 +679,7 @@ 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()->gameData.texts.text(str); + 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); @@ -718,9 +719,9 @@ 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()->gameData.loadAudioClip(name + ".wav") ) + if(! args.getVM()->getWorld()->data->loadAudioClip(name + ".wav") ) { - if(! args.getVM()->getWorld()->gameData.loadAudioClip(name + ".mp3") ) + if(! args.getVM()->getWorld()->data->loadAudioClip(name + ".mp3") ) { args.getVM()->getWorld()->logger->error("SCM", "Failed to load audio: " + name); } @@ -755,7 +756,7 @@ void game_play_music_id(const ScriptArguments& args) std::string name = "Miscom"; // TODO play anything other than Miscom.wav - if(! gw->gameData.loadAudioClip( name + ".wav" ) ) + if(! gw->data->loadAudioClip( name + ".wav" ) ) { args.getVM()->getWorld()->logger->error("SCM", "Error loading audio " + name); return; @@ -793,7 +794,7 @@ void game_get_found_hidden_packages(const ScriptArguments& args) void game_display_help(const ScriptArguments& args) { std::string id(args[0].string); - std::string str = args.getVM()->getWorld()->gameData.texts.text(id); + std::string str = args.getVM()->getWorld()->data->texts.text(id); unsigned short style = OnscreenText::Help; args.getVM()->getWorld()->state.text.push_back({ id, @@ -857,7 +858,7 @@ bool game_are_vehicle_cheats_enabled(const ScriptArguments& args) void game_load_splash(const ScriptArguments& args) { - args.getVM()->getWorld()->gameData.loadSplash(args[0].string); + args.getVM()->getWorld()->data->loadSplash(args[0].string); } GameModule::GameModule() diff --git a/rwengine/src/script/modules/ObjectModule.cpp b/rwengine/src/script/modules/ObjectModule.cpp index 29543d83..c546f4aa 100644 --- a/rwengine/src/script/modules/ObjectModule.cpp +++ b/rwengine/src/script/modules/ObjectModule.cpp @@ -360,8 +360,8 @@ bool game_character_in_zone(const ScriptArguments& args) auto controller = static_cast(*args[0].handle); std::string zname(args[1].string); - auto zfind = args.getVM()->getWorld()->gameData.zones.find(zname); - if( zfind != args.getVM()->getWorld()->gameData.zones.end() ) { + auto zfind = args.getVM()->getWorld()->data->zones.find(zname); + if( zfind != args.getVM()->getWorld()->data->zones.end() ) { auto player = controller->getCharacter()->getPosition(); auto& min = zfind->second.min; auto& max = zfind->second.max; @@ -666,8 +666,8 @@ void game_create_pickup(const ScriptArguments& args) std::transform(model.begin(), model.end(), model.begin(), ::tolower); id = args.getVM()->getWorld()->findModelDefinition(model); - args.getVM()->getWorld()->gameData.loadDFF(model+".dff"); - args.getVM()->getWorld()->gameData.loadTXD("icons.txd"); + args.getVM()->getWorld()->data->loadDFF(model+".dff"); + args.getVM()->getWorld()->data->loadTXD("icons.txd"); } else { @@ -675,9 +675,9 @@ void game_create_pickup(const ScriptArguments& args) if ( ! ( id >= 170 && id <= 184 ) ) { - args.getVM()->getWorld()->gameData.loadDFF(data->modelName+".dff"); + args.getVM()->getWorld()->data->loadDFF(data->modelName+".dff"); } - args.getVM()->getWorld()->gameData.loadTXD(data->textureName+".txd"); + args.getVM()->getWorld()->data->loadTXD(data->textureName+".txd"); } @@ -760,7 +760,7 @@ void game_set_vehicle_colours(const ScriptArguments& args) { auto vehicle = (VehicleObject*)(*args[0].handle); - auto& colours = args.getVM()->getWorld()->gameData.vehicleColours; + auto& colours = args.getVM()->getWorld()->data->vehicleColours; vehicle->colourPrimary = colours[args[1].integer]; vehicle->colourSecondary = colours[args[2].integer]; } @@ -907,10 +907,10 @@ void game_change_nearest_model(const ScriptArguments& args) if( o->model->name != oldmodel ) continue; float d = glm::distance(position, o->getPosition()); if( d < radius ) { - args.getVM()->getWorld()->gameData.loadDFF(newmodel + ".dff", false); + args.getVM()->getWorld()->data->loadDFF(newmodel + ".dff", false); InstanceObject* inst = static_cast(o); inst->changeModel(nobj); - inst->model = args.getVM()->getWorld()->gameData.models[newmodel]; + inst->model = args.getVM()->getWorld()->data->models[newmodel]; } } } diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index 72aa0391..bbb3818d 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -88,14 +88,16 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[]) throw std::runtime_error("Invalid game directory path, is " +envname+ " set?"); } - engine = new GameWorld(&log, gamepath); + data = new GameData(&log, gamepath); + + engine = new GameWorld(&log, data); // Initalize all the archives. - engine->gameData.loadIMG("/models/gta3"); - //engine->gameData.loadIMG("/models/txd"); - engine->gameData.loadIMG("/anim/cuts"); + engine->data->loadIMG("/models/gta3"); + //engine->data.loadIMG("/models/txd"); + engine->data->loadIMG("/anim/cuts"); - engine->gameData.load(); + engine->data->load(); // Initialize renderer renderer = new GameRenderer(&log, engine); @@ -110,21 +112,19 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[]) debug->setShaderProgram(renderer->worldProg); engine->dynamicsWorld->setDebugDrawer(debug); - engine->gameData.loadDynamicObjects(gamepath + "/data/object.dat"); + engine->data->loadDynamicObjects(gamepath + "/data/object.dat"); /// @TODO language choices. - engine->gameData.loadGXT("english.gxt"); + engine->data->loadGXT("english.gxt"); - getRenderer()->water.setWaterTable(engine->gameData.waterHeights, 48, engine->gameData.realWater, 128*128); + getRenderer()->water.setWaterTable(data->waterHeights, 48, engine->data->realWater, 128*128); for(int m = 0; m < MAP_BLOCK_SIZE; ++m) { std::string num = (m < 10 ? "0" : ""); std::string name = "radar" + num + std::to_string(m); - engine->gameData.loadTXD(name + ".txd"); + engine->data->loadTXD(name + ".txd"); } - - getRenderer()->water.setWaterTable(engine->gameData.waterHeights, 48, engine->gameData.realWater, 128*128); auto loading = new LoadingState(this); if( newgame ) @@ -150,7 +150,7 @@ RWGame::~RWGame() void RWGame::startScript(const std::string& name) { - SCMFile* f = engine->gameData.loadSCM(name); + SCMFile* f = engine->data->loadSCM(name); if( f ) { if( script ) delete script; diff --git a/rwgame/RWGame.hpp b/rwgame/RWGame.hpp index 458da14f..009a1fba 100644 --- a/rwgame/RWGame.hpp +++ b/rwgame/RWGame.hpp @@ -2,6 +2,7 @@ #define _RWGAME_HPP_ #include +#include #include #include #include