Redesigned ID allocator and tangible.actor

This commit is contained in:
2021-10-14 11:43:16 -04:00
parent 50d62d9bfd
commit 796a3c4139
6 changed files with 131 additions and 126 deletions

View File

@@ -207,6 +207,29 @@ public:
//
bool stack_is_clear() const { return lua_gettop(state()) == 0; }
// Set the lthread state.
//
// Whenever lua code is running, and ONLY when lua code is running,
// we store the following information in the world model:
//
// * lthread_actor_id: current actor
// * lthread_place_id: current place
// * lthread_use_ppool: true if we should use the player ID pool.
//
// As soon as the lua code stops executing, these variables are
// cleared.
//
void set_lthread_state(int64_t actor_id, int64_t place_id, bool ppool);
// Allocate a single ID.
//
// The rules are as follows:
// * if lthread_use_ppool is false, uses the global pool.
// * if lthread_actor_id is not a valid actor id, uses the global pool.
// * otherwise, uses the player pool of lthread_actor_id.
//
int64_t alloc_id_predictable();
private:
// Store a pointer to a world model into a lua registry.
@@ -406,10 +429,18 @@ private:
//
Redirects redirects_;
// lthread variables: see set_lthread_state for explanation.
//
int64_t lthread_actor_id_;
int64_t lthread_place_id_;
int64_t lthread_use_ppool_;
friend class Tangible;
friend int lfn_tangible_animate(lua_State *L);
friend int lfn_tangible_build(lua_State *L);
friend int lfn_tangible_redirect(lua_State *L);
friend int lfn_tangible_actor(lua_State *L);
friend int lfn_tangible_place(lua_State *L);
};
#endif // WORLD_HPP