Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/TLuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ void TLuaEngine::operator()() {
}
}

// now call onInitFinal after all states have completed their onInit
auto FinalFutures = TriggerEvent("onInitFinal", "");
WaitForAll(FinalFutures, std::chrono::seconds(5));
for (const auto& Future : FinalFutures) {
if (Future->Error && Future->ErrorMessage != BeamMPFnNotFoundError) {
beammp_lua_error("Calling \"onInitFinal\" on \"" + Future->StateId + "\" failed: " + Future->ErrorMessage);
}
}

auto ResultCheckThread = std::thread([&] {
RegisterThread("ResultCheckThread");
while (!Application::IsShuttingDown()) {
Expand Down Expand Up @@ -433,6 +442,7 @@ void TLuaEngine::EnsureStateExists(TLuaStateId StateId, const std::string& Name,
auto DataPtr = std::make_unique<StateThreadData>(Name, StateId, *this);
mLuaStates[StateId] = std::move(DataPtr);
RegisterEvent("onInit", StateId, "onInit");
RegisterEvent("onInitFinal", StateId, "onInitFinal");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this line added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to create the event?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is something up to the scripter so that the server doesn't implicitly call functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why do it for “onInit”?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure but it might be left over from the old scripting engine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I know I just followed what had already been done at the time. I think the implementation is fine. If in the future we have to redo the entire basis of the system, I would do it again, but I find it a bit strange to do things halfway. We might as well redo everything properly in the future.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best solution would be to remove both of those calls and see if anything breaks.

if (!DontCallOnInit) {
auto Res = EnqueueFunctionCall(StateId, "onInit", {}, "onInit");
Res->WaitUntilReady();
Expand Down
2 changes: 1 addition & 1 deletion src/TServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void TServer::HandleEvent(TClient& c, const std::string& RawData) {
std::string Name = RawData.substr(2, NameDataSep - 2);
std::string Data = RawData.substr(NameDataSep + 1);

std::vector<std::string> exclude = {"onInit", "onFileChanged","onVehicleDeleted","onConsoleInput","onPlayerAuth","postPlayerAuth", "onPlayerDisconnect",
std::vector<std::string> exclude = {"onInit", "onInitFinal", "onFileChanged","onVehicleDeleted","onConsoleInput","onPlayerAuth","postPlayerAuth", "onPlayerDisconnect",
"onPlayerConnecting","onPlayerJoining","onPlayerJoin","onChatMessage","postChatMessage","onVehicleSpawn","postVehicleSpawn","onVehicleEdited", "postVehicleEdited",
"onVehicleReset","onVehiclePaintChanged","onShutdown"};

Expand Down