Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ready] Garages continuation #490

Merged
merged 1 commit into from Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ documentation/
*swp
*.user*
.DS_Store
.vscode/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such things don't belong in a project gitignore, but your private git configuration.
As vscode is a popular editor, I'd be willing to allow this here. But ideally it wasn't here.

4 changes: 2 additions & 2 deletions rwengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ set(RWENGINE_SOURCES
src/engine/GameState.hpp
src/engine/GameWorld.cpp
src/engine/GameWorld.hpp
src/engine/GarageController.cpp
src/engine/GarageController.hpp
src/engine/Garage.cpp
src/engine/Garage.hpp
src/engine/Payphone.cpp
src/engine/Payphone.hpp
src/engine/SaveGame.cpp
Expand Down
52 changes: 0 additions & 52 deletions rwengine/src/engine/GameState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,56 +211,6 @@ struct BlipData {
}
};

enum class GarageType {
Mission = 1,
BombShop1 = 2,
BombShop2 = 3,
BombShop3 = 4,
Respray = 5,
CollectCars1 = 8,
CollectCars2 = 9,
MissionForCarToComeOut = 11,
Crusher = 13,
MissionKeepCar = 14,
Hideout1 = 16,
Hideout2 = 17,
Hideout3 = 18,
MissionToOpenAndClose = 19,
MissionForSpecificCar = 20,
MissionKeepCarAndRemainClosed = 21,
};

enum class GarageState { Closed, Closing, Opening, Opened };

/**
* Data for garages
*/
struct GarageInfo {
GarageType type;

int id;
glm::vec3 min;
glm::vec3 max;

GameObject* target;

GarageState state;

GarageInfo(int id_, const glm::vec3 min_, const glm::vec3 max_,
GarageType type_)
: type(type_)
, id(id_)
, min(min_)
, max(max_)
, target(nullptr)
, state(GarageState::Closed) {
}

int getScriptObjectID() const {
return id;
}
};

enum class HudFlash {
Disabled = -1,
FlashArmor = 3,
Expand Down Expand Up @@ -406,8 +356,6 @@ class GameState {

std::map<int, BlipData> radarBlips;

std::vector<GarageInfo> garages;

/**
* Bitsets for the car import / export list mission
*/
Expand Down
76 changes: 5 additions & 71 deletions rwengine/src/engine/GameWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,77 +386,11 @@ PickupObject* GameWorld::createPickup(const glm::vec3& pos, int id, int type) {
return pickup;
}

GarageInfo* GameWorld::createGarage(const glm::vec3 coord0,
const glm::vec3 coord1, const int type) {
glm::vec3 min;
glm::vec3 max;
glm::vec3 midpoint;

min.x = std::min(coord0.x, coord1.x);
min.y = std::min(coord0.y, coord1.y);
min.z = std::min(coord0.z, coord1.z);

max.x = std::max(coord0.x, coord1.x);
max.y = std::max(coord0.y, coord1.y);
max.z = std::max(coord0.z, coord1.z);

midpoint.x = (min.x + max.x) / 2;
midpoint.y = (min.y + max.y) / 2;
midpoint.z = (min.z + max.z) / 2;

// Find door object for this garage
InstanceObject* door = nullptr;

for (auto p : instancePool.objects) {
auto o = p.second;
if (!o->getModel()) continue;
if (!SimpleModelInfo::isDoorModel(
o->getModelInfo<BaseModelInfo>()->name))
continue;

// Is this how the game finds door object?
if (glm::distance(midpoint, o->getPosition()) < 20.f) {
door = static_cast<InstanceObject*>(o);
}
}

// Create garage
int id = state->garages.size();
GarageInfo* info =
new GarageInfo{id, min, max, static_cast<GarageType>(type)};
state->garages.push_back(*info);

switch (static_cast<GarageType>(type)) {
case GarageType::Mission:
case GarageType::CollectCars1:
case GarageType::CollectCars2:
case GarageType::MissionForCarToComeOut:
case GarageType::MissionKeepCar:
case GarageType::Hideout1:
case GarageType::Hideout2:
case GarageType::Hideout3:
case GarageType::MissionToOpenAndClose:
case GarageType::MissionForSpecificCar:
case GarageType::MissionKeepCarAndRemainClosed: {
info->state = GarageState::Closed;
break;
}

case GarageType::BombShop1:
case GarageType::BombShop2:
case GarageType::BombShop3:
case GarageType::Respray:
case GarageType::Crusher: {
info->state = GarageState::Opened;
break;
}
}

// Create controller
garageControllers.push_back(
std::make_unique<GarageController>(GarageController(this, info, door)));

return info;
Garage* GameWorld::createGarage(const glm::vec3 coord0, const glm::vec3 coord1,
Garage::Type type) {
const int id = garages.size();
garages.emplace_back(std::make_unique<Garage>(this, id, coord0, coord1, type));
return garages.back().get();
}

Payphone* GameWorld::createPayphone(const glm::vec2 coord) {
Expand Down
10 changes: 5 additions & 5 deletions rwengine/src/engine/GameWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <ai/AIGraphNode.hpp>
#include <audio/SoundManager.hpp>

#include <engine/GarageController.hpp>
#include <engine/Garage.hpp>
#include <engine/Payphone.hpp>
#include <objects/ObjectTypes.hpp>

Expand All @@ -35,7 +35,7 @@ class btSequentialImpulseConstraintSolver;
struct btDbvtBroadphase;

class GameState;
class GarageController;
class Garage;
class Payphone;

class PlayerController;
Expand Down Expand Up @@ -150,8 +150,8 @@ class GameWorld {
/**
* Creates a garage
*/
GarageInfo* createGarage(const glm::vec3 coord0, const glm::vec3 coord1,
const int type);
Garage* createGarage(const glm::vec3 coord0, const glm::vec3 coord1,
Garage::Type type);

/**
* Creates a payphone
Expand Down Expand Up @@ -271,7 +271,7 @@ class GameWorld {

std::vector<PlayerController*> players;

std::vector<std::unique_ptr<GarageController>> garageControllers;
std::vector<std::unique_ptr<Garage>> garages;

std::vector<std::unique_ptr<Payphone>> payphones;

Expand Down
Loading