Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Nov 27, 2024
1 parent 3e00ab7 commit 404990e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/script/cpp_api/s_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ void ScriptApiEnv::environment_Step(float dtime)
}

void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &type)
{
player_events.emplace_back(player, type);
}

void ScriptApiEnv::player_event_process()
{
const auto lock = player_events.try_lock_unique_rec();
if (!lock->owns_lock())
return;

for (const auto &e : player_events) {
player_event_real(e.player, e.type);
}

player_events.clear();
}

void ScriptApiEnv::player_event_real(ServerActiveObject *player, const std::string &type)
{
SCRIPTAPI_PRECHECKHEADER

Expand Down
11 changes: 11 additions & 0 deletions src/script/cpp_api/s_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "cpp_api/s_base.h"
#include "irr_v3d.h"
#include "mapnode.h"
#include "threading/concurrent_vector.h"
#include <unordered_set>
#include <vector>

Expand All @@ -26,6 +27,16 @@ class ScriptApiEnv : virtual public ScriptApiBase
// Called on player event
void player_event(ServerActiveObject *player, const std::string &type);

// fm:
void player_event_real(ServerActiveObject *player, const std::string &type);
struct pevent
{
ServerActiveObject *player;
std::string type;
};
concurrent_vector<pevent> player_events;
void player_event_process();
// ==
// Called after emerge of a block queued from core.emerge_area()
void on_emerge_area_completion(v3s16 blockpos, int action,
ScriptCallbackState *state);
Expand Down
4 changes: 4 additions & 0 deletions src/serverenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,10 @@ void ServerEnvironment::step(float dtime, double uptime, unsigned int max_cycle_
g_profiler->avg("SMap: Blocks", getMap().m_blocks.size());
#endif

{
getScriptIface()->player_event_process();
}

/*
Handle players
*/
Expand Down

0 comments on commit 404990e

Please sign in to comment.