Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarEntityFactory.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/game/StarEntityFactory.hpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/game/StarEntityFactory.hpp')
-rw-r--r--source/game/StarEntityFactory.hpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/source/game/StarEntityFactory.hpp b/source/game/StarEntityFactory.hpp
new file mode 100644
index 0000000..8286dcf
--- /dev/null
+++ b/source/game/StarEntityFactory.hpp
@@ -0,0 +1,55 @@
+#ifndef STAR_ENTITY_FACTORY_HPP
+#define STAR_ENTITY_FACTORY_HPP
+
+#include "StarVersioningDatabase.hpp"
+#include "StarEntity.hpp"
+
+namespace Star {
+
+STAR_CLASS(VersioningDatabase);
+STAR_CLASS(PlayerFactory);
+STAR_CLASS(MonsterDatabase);
+STAR_CLASS(ObjectDatabase);
+STAR_CLASS(ProjectileDatabase);
+STAR_CLASS(NpcDatabase);
+
+STAR_CLASS(EntityFactory);
+
+STAR_EXCEPTION(EntityFactoryException, StarException);
+
+class EntityFactory {
+public:
+ EntityFactory();
+
+ ByteArray netStoreEntity(EntityPtr const& entity) const;
+ EntityPtr netLoadEntity(EntityType type, ByteArray const& netStore) const;
+
+ Json diskStoreEntity(EntityPtr const& entity) const;
+ EntityPtr diskLoadEntity(EntityType type, Json const& diskStore) const;
+
+ Json loadVersionedJson(VersionedJson const& versionedJson, EntityType expectedType) const;
+ VersionedJson storeVersionedJson(EntityType type, Json const& store) const;
+
+ // Wraps the normal Json based Entity store / load in a VersionedJson, and
+ // uses sripts in the VersionedingDatabase to bring the version of the store
+ // forward to match the current version.
+ EntityPtr loadVersionedEntity(VersionedJson const& versionedJson) const;
+ VersionedJson storeVersionedEntity(EntityPtr const& entityPtr) const;
+
+private:
+ static EnumMap<EntityType> const EntityStorageIdentifiers;
+
+ mutable RecursiveMutex m_mutex;
+
+ PlayerFactoryConstPtr m_playerFactory;
+ MonsterDatabaseConstPtr m_monsterDatabase;
+ ObjectDatabaseConstPtr m_objectDatabase;
+ ProjectileDatabaseConstPtr m_projectileDatabase;
+ NpcDatabaseConstPtr m_npcDatabase;
+ VehicleDatabaseConstPtr m_vehicleDatabase;
+ VersioningDatabaseConstPtr m_versioningDatabase;
+};
+
+}
+
+#endif