add player.is_suspended, player.set_suspended
This commit is contained in:
parent
40cdebb175
commit
43f0cbe3fe
@ -66,6 +66,9 @@ LevelController::LevelController(
|
||||
|
||||
void LevelController::update(float delta, bool pause) {
|
||||
for (const auto& [_, player] : *level->players) {
|
||||
if (player->isSuspended()) {
|
||||
continue;
|
||||
}
|
||||
glm::vec3 position = player->getPosition();
|
||||
player->chunks->configure(
|
||||
position.x,
|
||||
@ -85,6 +88,9 @@ void LevelController::update(float delta, bool pause) {
|
||||
level->entities->updatePhysics(delta);
|
||||
level->entities->update(delta);
|
||||
for (const auto& [_, player] : *level->players) {
|
||||
if (player->isSuspended()) {
|
||||
continue;
|
||||
}
|
||||
if (playerTickClock.update(delta)) {
|
||||
if (player->getId() % playerTickClock.getParts() ==
|
||||
playerTickClock.getPart()) {
|
||||
|
||||
@ -284,6 +284,20 @@ static int l_delete(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_suspended(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushboolean(L, player->isSuspended());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_set_suspended(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
player->setSuspended(lua::toboolean(L, 2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg playerlib[] = {
|
||||
{"get_pos", lua::wrap<l_get_pos>},
|
||||
{"set_pos", lua::wrap<l_set_pos>},
|
||||
@ -293,6 +307,8 @@ const luaL_Reg playerlib[] = {
|
||||
{"set_rot", lua::wrap<l_set_rot>},
|
||||
{"get_dir", lua::wrap<l_get_dir>},
|
||||
{"get_inventory", lua::wrap<l_get_inv>},
|
||||
{"is_suspended", lua::wrap<l_is_suspended>},
|
||||
{"set_suspended", lua::wrap<l_set_suspended>},
|
||||
{"is_flight", lua::wrap<l_is_flight>},
|
||||
{"set_flight", lua::wrap<l_set_flight>},
|
||||
{"is_noclip", lua::wrap<l_is_noclip>},
|
||||
|
||||
@ -224,6 +224,14 @@ float Player::getSpeed() const {
|
||||
return speed;
|
||||
}
|
||||
|
||||
bool Player::isSuspended() const {
|
||||
return suspended;
|
||||
}
|
||||
|
||||
void Player::setSuspended(bool flag) {
|
||||
suspended = flag;
|
||||
}
|
||||
|
||||
bool Player::isFlight() const {
|
||||
return flight;
|
||||
}
|
||||
|
||||
@ -47,6 +47,7 @@ class Player : public Serializable {
|
||||
glm::vec3 position;
|
||||
glm::vec3 spawnpoint {};
|
||||
std::shared_ptr<Inventory> inventory;
|
||||
bool suspended = false;
|
||||
bool flight = false;
|
||||
bool noclip = false;
|
||||
bool infiniteItems = true;
|
||||
@ -85,6 +86,9 @@ public:
|
||||
int getChosenSlot() const;
|
||||
float getSpeed() const;
|
||||
|
||||
bool isSuspended() const;
|
||||
void setSuspended(bool flag);
|
||||
|
||||
bool isFlight() const;
|
||||
void setFlight(bool flag);
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "items/Inventories.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "world/World.hpp"
|
||||
#include "objects/Entities.hpp"
|
||||
|
||||
Players::Players(Level& level) : level(level) {}
|
||||
|
||||
@ -36,6 +37,26 @@ Player* Players::create() {
|
||||
return player;
|
||||
}
|
||||
|
||||
void Players::suspend(int64_t id) {
|
||||
if (auto player = get(id)) {
|
||||
if (player->isSuspended()) {
|
||||
return;
|
||||
}
|
||||
player->setSuspended(true);
|
||||
level.entities->despawn(player->getEntity());
|
||||
player->setEntity(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Players::resume(int64_t id) {
|
||||
if (auto player = get(id)) {
|
||||
if (!player->isSuspended()) {
|
||||
return;
|
||||
}
|
||||
player->setSuspended(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Players::remove(int64_t id) {
|
||||
players.erase(id);
|
||||
}
|
||||
|
||||
@ -25,6 +25,10 @@ public:
|
||||
|
||||
Player* create();
|
||||
|
||||
void suspend(int64_t id);
|
||||
|
||||
void resume(int64_t id);
|
||||
|
||||
void remove(int64_t id);
|
||||
|
||||
dv::value serialize() const override;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user