doesnt compile

This commit is contained in:
David Markowitz 2023-06-12 15:32:46 -07:00
parent b2fee29ee0
commit 45bcc80a1b
8 changed files with 38 additions and 62 deletions

View File

@ -504,10 +504,7 @@ void Entity::Initialize() {
}
AddCallbackTimer(0.0f, [this]() {
auto scripts = CppScripts::GetEntityScripts(this);
std::for_each(scripts.begin(), scripts.end(), [this](const auto& script) {
script->OnStartup(this);
});
GetScript()->OnStartup(this);
});
// Load data specific to this LOT first. These act as defaults for the components.
@ -523,7 +520,7 @@ void Entity::Initialize() {
});
/**
* @brief Startup all the components. Some components need or want data from other components so
* Startup all the components. Some components need or want data from other components so
* we want to ensure that
* A) Most if not all components are newed and ready to be accessed.
* B) All components have their personal data loaded and ready to be used.
@ -533,7 +530,7 @@ void Entity::Initialize() {
});
/**
* @brief Load the player save data from XML. Ideally we do this after all initialization so the player
* Load the player save data from XML. Ideally we do this after all initialization so the player
* save data overrides any defaults that may be applied.
*/
if (!IsPlayer()) std::for_each(m_Components.begin(), m_Components.end(), [this](auto& component) {
@ -647,7 +644,7 @@ void Entity::SetGMLevel(eGameMasterLevel value) {
GameMessages::SendGMLevelBroadcast(m_ObjectID, value);
}
void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacketType packetType) {
void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType) {
if (packetType == eReplicaPacketType::CONSTRUCTION) {
outBitStream->Write(m_ObjectID);
outBitStream->Write(m_TemplateID);
@ -768,7 +765,7 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke
}
}
void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType packetType) {
void Entity::WriteComponents(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType) {
}
@ -787,34 +784,36 @@ void Entity::UpdateXMLDoc(tinyxml2::XMLDocument* doc) {
}
}
CppScripts::Script* Entity::GetScript() const {
auto* scriptComponent = GetComponent<ScriptComponent>();
auto* script = scriptComponent->GetScript();
DluAssert(script != nullptr);
return script;
}
void Entity::Update(const float deltaTime) {
uint32_t timerPosition;
timerPosition = 0;
while (timerPosition < m_Timers.size()) {
m_Timers[timerPosition]->Update(deltaTime);
if (m_Timers[timerPosition]->GetTime() <= 0) {
const auto timerName = m_Timers[timerPosition]->GetName();
delete m_Timers[timerPosition];
m_Timers.erase(m_Timers.begin() + timerPosition);
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
script->OnTimerDone(this, timerName);
}
auto namedTimerItr = std::remove_if(m_Timers.begin(), m_Timers.end(), [this, &deltaTime](EntityTimer* timer) {
timer->Update(deltaTime);
if (timer->GetTime() <= 0) {
GetScript()->OnTimerDone(this, timer->GetName());
TriggerEvent(eTriggerEventType::TIMER_DONE, this);
} else {
timerPosition++;
delete timer;
return true;
}
}
return false;
});
m_Timers.erase(namedTimerItr, m_Timers.end());
for (int i = 0; i < m_CallbackTimers.size(); i++) {
m_CallbackTimers[i]->Update(deltaTime);
if (m_CallbackTimers[i]->GetTime() <= 0) {
m_CallbackTimers[i]->GetCallback()();
delete m_CallbackTimers[i];
m_CallbackTimers.erase(m_CallbackTimers.begin() + i);
auto callbackTimerItr = std::remove_if(m_CallbackTimers.begin(), m_CallbackTimers.end(), [this, &deltaTime](EntityCallbackTimer* timer) {
timer->Update(deltaTime);
if (timer->GetTime() <= 0) {
timer->GetCallback()();
delete timer;
return true;
}
}
return false;
});
m_CallbackTimers.erase(callbackTimerItr, m_CallbackTimers.end());
// Add pending timers to the list of timers so they start next tick.
if (m_PendingTimers.size() > 0) {
@ -1294,10 +1293,6 @@ void Entity::CancelTimer(const std::string& name) {
}
void Entity::CancelAllTimers() {
/*for (auto timer : m_Timers) {
if (timer) delete timer;
}*/
for (auto* timer : m_Timers) {
delete timer;
}

View File

@ -223,6 +223,7 @@ public:
virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; }
virtual NiQuaternion GetRespawnRotation() const { return NiQuaternion::IDENTITY; }
CppScripts::Script* GetScript() const;
void Sleep();
void Wake();

View File

@ -36,6 +36,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
"RigidbodyPhantomPhysicsComponent.cpp"
"MultiZoneEntranceComponent.cpp"
"RocketLaunchpadControlComponent.cpp"
"ScriptComponent.cpp"
"ScriptedActivityComponent.cpp"
"ShootingGalleryComponent.cpp"
"SimplePhysicsComponent.cpp"

View File

@ -11,7 +11,6 @@ set(DSCRIPTS_SOURCES
"Darkitect.cpp"
"NPCAddRemoveItem.cpp"
"NtFactionSpyServer.cpp"
"ScriptComponent.cpp"
"ScriptedPowerupSpawner.cpp"
"SpawnPetBaseServer.cpp")

View File

@ -312,7 +312,7 @@
#include "WildNinjaSensei.h"
#include "WildNinjaBricks.h"
InvalidScript* CppScripts::invalidToReturn = new InvalidScript();
std::unique_ptr<InvalidScript> CppScripts::invalidScript = std::make_unique<InvalidScript>();
std::map<std::string, CppScripts::Script*> CppScripts::m_Scripts;
CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scriptName) {
@ -324,7 +324,7 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
return script;
}
script = invalidToReturn;
script = invalidScript.get();
//VE / AG:
if (scriptName == "scripts\\ai\\AG\\L_AG_SHIP_PLAYER_DEATH_TRIGGER.lua")
@ -926,7 +926,7 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
// handle invalid script reporting if the path is greater than zero and it's not an ignored script
// information not really needed for sys admins but is for developers
else if (script == invalidToReturn) {
else if (script == invalidScript.get()) {
if ((scriptName.length() > 0) && !((scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") ||
(scriptName == "scripts\\02_server\\Enemy\\General\\L_BASE_ENEMY_SPIDERLING.lua") ||
(scriptName =="scripts\\ai\\FV\\L_ACT_NINJA_STUDENT.lua") ||
@ -938,22 +938,3 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
m_Scripts[scriptName] = script;
return script;
}
std::vector<CppScripts::Script*> CppScripts::GetEntityScripts(Entity* entity) {
std::vector<CppScripts::Script*> scripts;
auto comps = entity->GetScriptComponents();
for (auto& scriptComp : comps) {
if (scriptComp != nullptr) {
scripts.push_back(scriptComp->GetScript());
}
}
return scripts;
}
CppScripts::Script::Script() {
}
CppScripts::Script::~Script() {
}

View File

@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
@ -14,7 +15,7 @@ enum class eRebuildState : uint32_t;
namespace CppScripts {
extern InvalidScript* invalidToReturn;
extern std::unique_ptr<InvalidScript> invalidScript;
extern std::map<std::string, CppScripts::Script*> m_Scripts;
/**
* Base class for all scripts. Includes virtual methods to be overridden to handle LUA equivelent events.
@ -33,8 +34,7 @@ namespace CppScripts {
*/
class Script {
public:
Script();
~Script();
virtual ~Script() = default;
/**
* Invoked one frame after the script is loaded.
@ -365,5 +365,4 @@ namespace CppScripts {
};
Script* GetScript(Entity* parent, const std::string& scriptName);
std::vector<Script*> GetEntityScripts(Entity* entity);
};