mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-19 10:15:27 +00:00
refactor(spawner): the spawner object's SpawnerComponent owns its spawner
The zone manager keeps an index of spawners by object ID; the spawner now belongs to the SpawnerComponent of its LOT 176 object and goes with it (the component tells the zone manager to stop indexing it). Spawning, timers and the update order are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,7 @@ set(DGAME_DCOMPONENTS_SOURCES
|
||||
"SimplePhysicsComponent.cpp"
|
||||
"SkillComponent.cpp"
|
||||
"SoundTriggerComponent.cpp"
|
||||
"SpawnerComponent.cpp"
|
||||
"SwitchComponent.cpp"
|
||||
"TriggerComponent.cpp"
|
||||
"HavokVehiclePhysicsComponent.cpp"
|
||||
|
||||
17
dGame/dComponents/SpawnerComponent.cpp
Normal file
17
dGame/dComponents/SpawnerComponent.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "SpawnerComponent.h"
|
||||
|
||||
#include "Entity.h"
|
||||
#include "Game.h"
|
||||
#include "Spawner.h"
|
||||
#include "dZoneManager.h"
|
||||
|
||||
SpawnerComponent::SpawnerComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {}
|
||||
|
||||
// The zone manager stops indexing the spawner before it goes with the object
|
||||
SpawnerComponent::~SpawnerComponent() {
|
||||
if (m_Spawner && Game::zoneManager) Game::zoneManager->ForgetSpawner(m_Parent->GetObjectID(), m_Spawner.get());
|
||||
}
|
||||
|
||||
void SpawnerComponent::SetSpawner(std::unique_ptr<Spawner> spawner) {
|
||||
m_Spawner = std::move(spawner);
|
||||
}
|
||||
@@ -1,17 +1,29 @@
|
||||
#ifndef SPAWNERCOMPONENT_H
|
||||
#define SPAWNERCOMPONENT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class Spawner;
|
||||
|
||||
/**
|
||||
* The spawner component (10) of a spawner object (LOT 176), made from the registry as the client makes it.
|
||||
* The spawner component (10) of a spawner object (LOT 176), made from the registry as the client makes it. It owns the
|
||||
* spawner (its nodes, what it spawned and its timers); the zone manager indexes spawners by the object's ID.
|
||||
*/
|
||||
class SpawnerComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SPAWNER;
|
||||
|
||||
SpawnerComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {}
|
||||
SpawnerComponent(Entity* parent, const int32_t componentID);
|
||||
~SpawnerComponent() override;
|
||||
|
||||
void SetSpawner(std::unique_ptr<Spawner> spawner);
|
||||
Spawner* GetSpawner() const { return m_Spawner.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<Spawner> m_Spawner;
|
||||
};
|
||||
|
||||
#endif // SPAWNERCOMPONENT_H
|
||||
|
||||
Reference in New Issue
Block a user