refactor: Refactor BlueprintManager, add placeholder blueprint classes
This commit is contained in:
parent
cc2c342bde
commit
8e02dc9004
15 changed files with 442 additions and 21 deletions
|
@ -51,6 +51,13 @@ set(HEADERS
|
|||
src/core/streamutil.h
|
||||
src/core/types.h
|
||||
src/game/area.h
|
||||
src/game/blueprint/blueprints.h
|
||||
src/game/blueprint/creature.h
|
||||
src/game/blueprint/door.h
|
||||
src/game/blueprint/item.h
|
||||
src/game/blueprint/placeable.h
|
||||
src/game/blueprint/trigger.h
|
||||
src/game/blueprint/waypoint.h
|
||||
src/game/characters.h
|
||||
src/game/dialog.h
|
||||
src/game/game.h
|
||||
|
@ -85,8 +92,6 @@ set(HEADERS
|
|||
src/game/script/callbacks.h
|
||||
src/game/script/routines.h
|
||||
src/game/script/util.h
|
||||
src/game/blueprint/item.h
|
||||
src/game/blueprint/blueprints.h
|
||||
src/game/types.h
|
||||
src/game/util.h
|
||||
src/gui/control/button.h
|
||||
|
@ -171,6 +176,13 @@ set(SOURCES
|
|||
src/core/streamutil.cpp
|
||||
src/game/area.cpp
|
||||
src/game/area_actions.cpp
|
||||
src/game/blueprint/blueprints.cpp
|
||||
src/game/blueprint/creature.cpp
|
||||
src/game/blueprint/door.cpp
|
||||
src/game/blueprint/item.cpp
|
||||
src/game/blueprint/placeable.cpp
|
||||
src/game/blueprint/trigger.cpp
|
||||
src/game/blueprint/waypoint.cpp
|
||||
src/game/characters.cpp
|
||||
src/game/dialog.cpp
|
||||
src/game/game.cpp
|
||||
|
@ -207,8 +219,6 @@ set(SOURCES
|
|||
src/game/script/routines_kotor.cpp
|
||||
src/game/script/routines_tsl.cpp
|
||||
src/game/script/util.cpp
|
||||
src/game/blueprint/item.cpp
|
||||
src/game/blueprint/blueprints.cpp
|
||||
src/game/util.cpp
|
||||
src/gui/control/button.cpp
|
||||
src/gui/control/control.cpp
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
#include "blueprints.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "../../core/log.h"
|
||||
#include "../../resources/resources.h"
|
||||
|
||||
|
@ -30,31 +28,58 @@ namespace reone {
|
|||
|
||||
namespace game {
|
||||
|
||||
static map<string, shared_ptr<CreatureBlueprint>> g_creatureCache;
|
||||
static map<string, shared_ptr<DoorBlueprint>> g_doorCache;
|
||||
static map<string, shared_ptr<ItemBlueprint>> g_itemCache;
|
||||
static map<string, shared_ptr<PlaceableBlueprint>> g_placeableCache;
|
||||
static map<string, shared_ptr<TriggerBlueprint>> g_triggerCache;
|
||||
static map<string, shared_ptr<WaypointBlueprint>> g_waypointCache;
|
||||
|
||||
BlueprintManager &BlueprintManager::instance() {
|
||||
static BlueprintManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
shared_ptr<CreatureBlueprint> BlueprintManager::findCreature(const string &resRef) {
|
||||
return find<CreatureBlueprint>(resRef, ResourceType::CreatureBlueprint, g_creatureCache);
|
||||
}
|
||||
|
||||
shared_ptr<DoorBlueprint> BlueprintManager::findDoor(const string &resRef) {
|
||||
return find<DoorBlueprint>(resRef, ResourceType::DoorBlueprint, g_doorCache);
|
||||
}
|
||||
|
||||
shared_ptr<ItemBlueprint> BlueprintManager::findItem(const string &resRef) {
|
||||
auto it = g_itemCache.find(resRef);
|
||||
if (it != g_itemCache.end()) {
|
||||
return find<ItemBlueprint>(resRef, ResourceType::ItemBlueprint, g_itemCache);
|
||||
}
|
||||
|
||||
shared_ptr<PlaceableBlueprint> BlueprintManager::findPlaceable(const string &resRef) {
|
||||
return find<PlaceableBlueprint>(resRef, ResourceType::PlaceableBlueprint, g_placeableCache);
|
||||
}
|
||||
|
||||
shared_ptr<TriggerBlueprint> BlueprintManager::findTrigger(const string &resRef) {
|
||||
return find<TriggerBlueprint>(resRef, ResourceType::TriggerBlueprint, g_triggerCache);
|
||||
}
|
||||
|
||||
shared_ptr<WaypointBlueprint> BlueprintManager::findWaypoint(const string &resRef) {
|
||||
return find<WaypointBlueprint>(resRef, ResourceType::WaypointBlueprint, g_waypointCache);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
shared_ptr<T> BlueprintManager::find(const string &resRef, ResourceType type, map<string, shared_ptr<T>> &cache) {
|
||||
auto it = cache.find(resRef);
|
||||
if (it != cache.end()) {
|
||||
return it->second;
|
||||
}
|
||||
debug("Templates: load item: " + resRef, 2);
|
||||
shared_ptr<GffStruct> gff(ResMan.findGFF(resRef, type));
|
||||
shared_ptr<T> blueprint;
|
||||
|
||||
shared_ptr<GffStruct> uti(ResMan.findGFF(resRef, ResourceType::ItemBlueprint));
|
||||
shared_ptr<ItemBlueprint> item;
|
||||
|
||||
if (uti) {
|
||||
item.reset(new ItemBlueprint());
|
||||
item->load(resRef, *uti);
|
||||
if (gff) {
|
||||
blueprint.reset(new T());
|
||||
blueprint->load(resRef, *gff);
|
||||
} else {
|
||||
warn("Templates: item not found: " + resRef);
|
||||
warn(boost::format("Blueprint: not found: %s %d") % resRef % static_cast<int>(type));
|
||||
}
|
||||
|
||||
auto pair = g_itemCache.insert(make_pair(resRef, item));
|
||||
auto pair = cache.insert(make_pair(resRef, blueprint));
|
||||
|
||||
return pair.first->second;
|
||||
}
|
||||
|
|
|
@ -17,10 +17,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "../../resources/types.h"
|
||||
|
||||
#include "creature.h"
|
||||
#include "door.h"
|
||||
#include "item.h"
|
||||
#include "placeable.h"
|
||||
#include "trigger.h"
|
||||
#include "waypoint.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
|
@ -30,16 +38,24 @@ class BlueprintManager {
|
|||
public:
|
||||
static BlueprintManager &instance();
|
||||
|
||||
std::shared_ptr<CreatureBlueprint> findCreature(const std::string &resRef);
|
||||
std::shared_ptr<DoorBlueprint> findDoor(const std::string &resRef);
|
||||
std::shared_ptr<ItemBlueprint> findItem(const std::string &resRef);
|
||||
std::shared_ptr<PlaceableBlueprint> findPlaceable(const std::string &resRef);
|
||||
std::shared_ptr<TriggerBlueprint> findTrigger(const std::string &resRef);
|
||||
std::shared_ptr<WaypointBlueprint> findWaypoint(const std::string &resRef);
|
||||
|
||||
private:
|
||||
BlueprintManager() = default;
|
||||
|
||||
BlueprintManager(const BlueprintManager &) = delete;
|
||||
BlueprintManager &operator=(const BlueprintManager &) = delete;
|
||||
|
||||
template <class T>
|
||||
std::shared_ptr<T> find(const std::string &resRef, resources::ResourceType type, std::map<std::string, std::shared_ptr<T>> &cache);
|
||||
};
|
||||
|
||||
#define BlueprintMan game::BlueprintManager::instance()
|
||||
#define Blueprints game::BlueprintManager::instance()
|
||||
|
||||
} // namespace game
|
||||
|
||||
|
|
33
src/game/blueprint/creature.cpp
Normal file
33
src/game/blueprint/creature.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "creature.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace reone::resources;
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
void CreatureBlueprint::load(const string &resRef, const GffStruct &utc) {
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
41
src/game/blueprint/creature.h
Normal file
41
src/game/blueprint/creature.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../resources/gfffile.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
class CreatureBlueprint {
|
||||
public:
|
||||
CreatureBlueprint() = default;
|
||||
|
||||
void load(const std::string &resRef, const resources::GffStruct &utc);
|
||||
|
||||
private:
|
||||
CreatureBlueprint(const CreatureBlueprint &) = delete;
|
||||
CreatureBlueprint &operator=(const CreatureBlueprint &) = delete;
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
33
src/game/blueprint/door.cpp
Normal file
33
src/game/blueprint/door.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "door.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace reone::resources;
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
void DoorBlueprint::load(const string &resRef, const GffStruct &utd) {
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
41
src/game/blueprint/door.h
Normal file
41
src/game/blueprint/door.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../resources/gfffile.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
class DoorBlueprint {
|
||||
public:
|
||||
DoorBlueprint() = default;
|
||||
|
||||
void load(const std::string &resRef, const resources::GffStruct &utd);
|
||||
|
||||
private:
|
||||
DoorBlueprint(const DoorBlueprint &) = delete;
|
||||
DoorBlueprint &operator=(const DoorBlueprint &) = delete;
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
33
src/game/blueprint/placeable.cpp
Normal file
33
src/game/blueprint/placeable.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "placeable.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace reone::resources;
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
void PlaceableBlueprint::load(const string &resRef, const GffStruct &utp) {
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
41
src/game/blueprint/placeable.h
Normal file
41
src/game/blueprint/placeable.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../resources/gfffile.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
class PlaceableBlueprint {
|
||||
public:
|
||||
PlaceableBlueprint() = default;
|
||||
|
||||
void load(const std::string &resRef, const resources::GffStruct &utp);
|
||||
|
||||
private:
|
||||
PlaceableBlueprint(const PlaceableBlueprint &) = delete;
|
||||
PlaceableBlueprint &operator=(const PlaceableBlueprint &) = delete;
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
33
src/game/blueprint/trigger.cpp
Normal file
33
src/game/blueprint/trigger.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "trigger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace reone::resources;
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
void TriggerBlueprint::load(const string &resRef, const GffStruct &utt) {
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
41
src/game/blueprint/trigger.h
Normal file
41
src/game/blueprint/trigger.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../resources/gfffile.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
class TriggerBlueprint {
|
||||
public:
|
||||
TriggerBlueprint() = default;
|
||||
|
||||
void load(const std::string &resRef, const resources::GffStruct &utt);
|
||||
|
||||
private:
|
||||
TriggerBlueprint(const TriggerBlueprint &) = delete;
|
||||
TriggerBlueprint &operator=(const TriggerBlueprint &) = delete;
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
33
src/game/blueprint/waypoint.cpp
Normal file
33
src/game/blueprint/waypoint.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "waypoint.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace reone::resources;
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
void WaypointBlueprint::load(const string &resRef, const GffStruct &utw) {
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
41
src/game/blueprint/waypoint.h
Normal file
41
src/game/blueprint/waypoint.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright © 2020 Vsevolod Kremianskii
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../resources/gfffile.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace game {
|
||||
|
||||
class WaypointBlueprint {
|
||||
public:
|
||||
WaypointBlueprint() = default;
|
||||
|
||||
void load(const std::string &resRef, const resources::GffStruct &utw);
|
||||
|
||||
private:
|
||||
WaypointBlueprint(const WaypointBlueprint &) = delete;
|
||||
WaypointBlueprint &operator=(const WaypointBlueprint &) = delete;
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
|
@ -262,7 +262,7 @@ void Creature::popCurrentAction() {
|
|||
}
|
||||
|
||||
void Creature::equip(const string &resRef) {
|
||||
shared_ptr<ItemBlueprint> itemTempl(BlueprintMan.findItem(resRef));
|
||||
shared_ptr<ItemBlueprint> itemTempl(Blueprints.findItem(resRef));
|
||||
|
||||
shared_ptr<Item> item(_objectFactory->newItem());
|
||||
item->load(itemTempl.get());
|
||||
|
|
|
@ -78,7 +78,7 @@ void Placeable::loadBlueprint(const GffStruct &gffs) {
|
|||
if (itemList) {
|
||||
for (auto &itemGffs : itemList->children()) {
|
||||
string resRef(itemGffs.getString("InventoryRes"));
|
||||
shared_ptr<ItemBlueprint> itemTempl(BlueprintMan.findItem(resRef));
|
||||
shared_ptr<ItemBlueprint> itemTempl(Blueprints.findItem(resRef));
|
||||
|
||||
shared_ptr<Item> item(_objectFactory->newItem());
|
||||
item->load(itemTempl.get());
|
||||
|
|
Loading…
Reference in a new issue