diff options
author | Treeston <treeston.mmoc@gmail.com> | 2020-02-08 20:22:37 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-12-21 15:16:26 +0100 |
commit | 94a79bac7a06aa0f931e9d651928de7eea0a8b5c (patch) | |
tree | 0f28508689237d951d0a44ae05c85ab3a29d8c62 /src/server/game/Maps/SpawnData.h | |
parent | fe489e2be1312bc559d0c38691c9741ad69cfec8 (diff) |
Core/Misc: Some refactoring, #23603 prep: (#23676)
- Split SpawnMetadata off from SpawnData
- No longer allocate Creature/Gameobject objects in ObjectGridLoader just to check their typeid and delete them afterwards
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
(cherry picked from commit 9304e496cbf6ab6c028671fb8526c732ae5d799f)
Diffstat (limited to 'src/server/game/Maps/SpawnData.h')
-rw-r--r-- | src/server/game/Maps/SpawnData.h | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/src/server/game/Maps/SpawnData.h b/src/server/game/Maps/SpawnData.h index d1023ffbeb2..1b96a70ecc1 100644 --- a/src/server/game/Maps/SpawnData.h +++ b/src/server/game/Maps/SpawnData.h @@ -22,21 +22,30 @@ #include "Position.h" #include <vector> +class AreaTrigger; +class Creature; +class GameObject; +class Pool; +struct PoolTemplate; + // EnumUtils: DESCRIBE THIS enum SpawnObjectType { SPAWN_TYPE_CREATURE = 0, // TITLE Creature SPAWN_TYPE_GAMEOBJECT = 1, // TITLE Gameobject - - SPAWN_TYPE_MAX // SKIP + SPAWN_TYPE_AREATRIGGER = 2,// TITLE AreaTrigger + NUM_SPAWN_TYPES_WITH_DATA, // SKIP + NUM_SPAWN_TYPES = NUM_SPAWN_TYPES_WITH_DATA // SKIP }; enum SpawnObjectTypeMask { SPAWN_TYPEMASK_CREATURE = (1 << SPAWN_TYPE_CREATURE), SPAWN_TYPEMASK_GAMEOBJECT = (1 << SPAWN_TYPE_GAMEOBJECT), + SPAWN_TYPEMASK_AREATRIGGER = (1 << SPAWN_TYPE_AREATRIGGER), - SPAWN_TYPEMASK_ALL = (1 << SPAWN_TYPE_MAX)-1 + SPAWN_TYPEMASK_WITH_DATA = (1 << NUM_SPAWN_TYPES_WITH_DATA)-1, + SPAWN_TYPEMASK_ALL = (1 << NUM_SPAWN_TYPES)-1 }; enum SpawnGroupFlags @@ -59,24 +68,49 @@ struct SpawnGroupTemplateData SpawnGroupFlags flags; }; -struct SpawnData +namespace Trinity { namespace Impl { + template <typename T> + struct SpawnObjectTypeForImpl { static_assert(!std::is_same<T,T>::value, "This type does not have an associated spawn type!"); }; + template <> struct SpawnObjectTypeForImpl<Creature> { static constexpr SpawnObjectType value = SPAWN_TYPE_CREATURE; }; + template <> struct SpawnObjectTypeForImpl<GameObject> { static constexpr SpawnObjectType value = SPAWN_TYPE_GAMEOBJECT; }; + template <> struct SpawnObjectTypeForImpl<AreaTrigger> { static constexpr SpawnObjectType value = SPAWN_TYPE_AREATRIGGER; }; +}} + +struct SpawnData; +struct SpawnMetadata { + static constexpr bool TypeInMask(SpawnObjectType type, SpawnObjectTypeMask mask) { return ((1 << type) & mask); } + static constexpr bool TypeHasData(SpawnObjectType type) { return (type < NUM_SPAWN_TYPES_WITH_DATA); } + static constexpr bool TypeIsValid(SpawnObjectType type) { return (type < NUM_SPAWN_TYPES); } + template <typename T> + static constexpr SpawnObjectType TypeFor = Trinity::Impl::SpawnObjectTypeForImpl<T>::value; + + SpawnData const* ToSpawnData() const { return TypeHasData(type) ? reinterpret_cast<SpawnData const*>(this) : nullptr; } + SpawnObjectType const type; uint64 spawnId = 0; + uint32 mapId = MAPID_INVALID; + bool dbData = true; + SpawnGroupTemplateData const* spawnGroupData = nullptr; + + protected: + SpawnMetadata(SpawnObjectType t) : type(t) {} +}; + +struct SpawnData : public SpawnMetadata +{ uint32 id = 0; // entry in respective _template table - WorldLocation spawnPoint; + Position spawnPoint; uint8 phaseUseFlags = 0; uint32 phaseId = 0; uint32 phaseGroup = 0; int32 terrainSwapMap = -1; int32 spawntimesecs = 0; std::vector<Difficulty> spawnDifficulties; - SpawnGroupTemplateData const* spawnGroupData = nullptr; uint32 scriptId = 0; - bool dbData = true; protected: - SpawnData(SpawnObjectType t) : type(t) {} + SpawnData(SpawnObjectType t) : SpawnMetadata(t) {} }; enum LinkedRespawnType |