Player Attributes (#578)
* feat: add max interaction distance functionality to Player class and Lua bindings * feat: add getter and setter for max interaction distance in Player class documentation * feat: add speed and gravity scale properties with corresponding getters and setters in Player class * fix: replace deprecated __max and __min with std::max and std::min in setMaxInteractionDistance * feat: add time scale functionality with getters and setters in World and Engine classes * remove speed and gravity scale functions from player and world libraries * remove time scale setting on world open and close * rename interaction distance functions for consistency * refactor: update interaction distance functions and remove time scale methods * refactor: revert classes.lua to dev * refactor: remove time scale functionality from Engine and World classes * fix: Now I’ve definitely rolled back `classes.lua`. * refactor: remove unused player attributes and clean up player class * Update Player.hpp removed unused methods from Player.cpp
This commit is contained in:
parent
4c815db222
commit
792ee63f22
@ -89,6 +89,13 @@ player.set_loading_chunks(playerid: int, bool)
|
|||||||
|
|
||||||
Getter and setter of the property that determines whether the player is loading chunks.
|
Getter and setter of the property that determines whether the player is loading chunks.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
player.get_interaction_distance(playerid: int) -> float
|
||||||
|
player.set_interaction_distance(playerid: int, distance: float)
|
||||||
|
```
|
||||||
|
|
||||||
|
Getter and setter of the property for max interaction distance.
|
||||||
|
|
||||||
``` lua
|
``` lua
|
||||||
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
|
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
|
||||||
player.get_spawnpoint(playerid: int) -> number, number, number
|
player.get_spawnpoint(playerid: int) -> number, number, number
|
||||||
|
|||||||
@ -89,6 +89,13 @@ player.set_loading_chunks(playerid: int, bool)
|
|||||||
|
|
||||||
Геттер и сеттер свойства, определяющего, прогружает ли игрок чанки вокруг.
|
Геттер и сеттер свойства, определяющего, прогружает ли игрок чанки вокруг.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
player.get_interaction_distance(playerid: int) -> float
|
||||||
|
player.set_interaction_distance(playerid: int, distance: float)
|
||||||
|
```
|
||||||
|
|
||||||
|
Геттер и сеттер свойства, определяющего максимальную дистанцию взаимодействия.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
|
player.set_spawnpoint(playerid: int, x: number, y: number, z: number)
|
||||||
player.get_spawnpoint(playerid: int) -> number, number, number
|
player.get_spawnpoint(playerid: int) -> number, number, number
|
||||||
|
|||||||
@ -289,4 +289,4 @@ network.__process_events = function()
|
|||||||
cleaned = true
|
cleaned = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -488,7 +488,7 @@ void PlayerController::updateInteraction(const Input& inputEvents, float delta)
|
|||||||
}
|
}
|
||||||
const auto& bindings = inputEvents.getBindings();
|
const auto& bindings = inputEvents.getBindings();
|
||||||
bool xkey = bindings.active(BIND_PLAYER_FAST_INTERACTOIN);
|
bool xkey = bindings.active(BIND_PLAYER_FAST_INTERACTOIN);
|
||||||
float maxDistance = xkey ? 200.0f : 10.0f;
|
float maxDistance = xkey ? 200.0f : player.getMaxInteractionDistance();
|
||||||
bool longInteraction = interactionTimer <= 0 || xkey;
|
bool longInteraction = interactionTimer <= 0 || xkey;
|
||||||
bool lclick = bindings.jactive(BIND_PLAYER_DESTROY) ||
|
bool lclick = bindings.jactive(BIND_PLAYER_DESTROY) ||
|
||||||
(longInteraction && bindings.active(BIND_PLAYER_DESTROY));
|
(longInteraction && bindings.active(BIND_PLAYER_DESTROY));
|
||||||
|
|||||||
@ -181,6 +181,20 @@ static int l_set_loading_chunks(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_interaction_distance(lua::State* L) {
|
||||||
|
if (auto player = get_player(L, 1)) {
|
||||||
|
return lua::pushnumber(L, player->getMaxInteractionDistance());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_set_interaction_distance(lua::State* L) {
|
||||||
|
if (auto player = get_player(L, 1)) {
|
||||||
|
player->setMaxInteractionDistance( static_cast<float>(lua::tonumber(L, 2)) );
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_get_selected_block(lua::State* L) {
|
static int l_get_selected_block(lua::State* L) {
|
||||||
if (auto player = get_player(L, 1)) {
|
if (auto player = get_player(L, 1)) {
|
||||||
if (player->selection.vox.id == BLOCK_VOID) {
|
if (player->selection.vox.id == BLOCK_VOID) {
|
||||||
@ -328,6 +342,8 @@ const luaL_Reg playerlib[] = {
|
|||||||
{"set_instant_destruction", lua::wrap<l_set_instant_destruction>},
|
{"set_instant_destruction", lua::wrap<l_set_instant_destruction>},
|
||||||
{"is_loading_chunks", lua::wrap<l_is_loading_chunks>},
|
{"is_loading_chunks", lua::wrap<l_is_loading_chunks>},
|
||||||
{"set_loading_chunks", lua::wrap<l_set_loading_chunks>},
|
{"set_loading_chunks", lua::wrap<l_set_loading_chunks>},
|
||||||
|
{"get_interaction_distance", lua::wrap<l_get_interaction_distance>},
|
||||||
|
{"set_interaction_distance", lua::wrap<l_set_interaction_distance>},
|
||||||
{"set_selected_slot", lua::wrap<l_set_selected_slot>},
|
{"set_selected_slot", lua::wrap<l_set_selected_slot>},
|
||||||
{"get_selected_block", lua::wrap<l_get_selected_block>},
|
{"get_selected_block", lua::wrap<l_get_selected_block>},
|
||||||
{"get_selected_entity", lua::wrap<l_get_selected_entity>},
|
{"get_selected_entity", lua::wrap<l_get_selected_entity>},
|
||||||
|
|||||||
@ -16,7 +16,6 @@ namespace network {
|
|||||||
using ServerDatagramCallback = std::function<void(u64id_t sid, const std::string& addr, int port, const char* buffer, size_t length)>;
|
using ServerDatagramCallback = std::function<void(u64id_t sid, const std::string& addr, int port, const char* buffer, size_t length)>;
|
||||||
using ClientDatagramCallback = std::function<void(u64id_t cid, const char* buffer, size_t length)>;
|
using ClientDatagramCallback = std::function<void(u64id_t cid, const char* buffer, size_t length)>;
|
||||||
|
|
||||||
|
|
||||||
class Requests {
|
class Requests {
|
||||||
public:
|
public:
|
||||||
virtual ~Requests() {}
|
virtual ~Requests() {}
|
||||||
|
|||||||
@ -196,6 +196,14 @@ void Player::setLoadingChunks(bool flag) {
|
|||||||
loadingChunks = flag;
|
loadingChunks = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Player::getMaxInteractionDistance() const {
|
||||||
|
return maxInteractionDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::setMaxInteractionDistance(float distance) {
|
||||||
|
maxInteractionDistance = std::max(1.0f, std::min(200.0f, distance));
|
||||||
|
}
|
||||||
|
|
||||||
entityid_t Player::getEntity() const {
|
entityid_t Player::getEntity() const {
|
||||||
return eid;
|
return eid;
|
||||||
}
|
}
|
||||||
@ -250,6 +258,7 @@ dv::value Player::serialize() const {
|
|||||||
root["rotation"] = dv::to_value(rotation);
|
root["rotation"] = dv::to_value(rotation);
|
||||||
root["spawnpoint"] = dv::to_value(spawnpoint);
|
root["spawnpoint"] = dv::to_value(spawnpoint);
|
||||||
|
|
||||||
|
root["max-interaction-distance"] = maxInteractionDistance;
|
||||||
root["flight"] = flight;
|
root["flight"] = flight;
|
||||||
root["noclip"] = noclip;
|
root["noclip"] = noclip;
|
||||||
root["suspended"] = suspended;
|
root["suspended"] = suspended;
|
||||||
@ -283,6 +292,8 @@ void Player::deserialize(const dv::value& src) {
|
|||||||
const auto& sparr = src["spawnpoint"];
|
const auto& sparr = src["spawnpoint"];
|
||||||
setSpawnPoint(glm::vec3(
|
setSpawnPoint(glm::vec3(
|
||||||
sparr[0].asNumber(), sparr[1].asNumber(), sparr[2].asNumber()));
|
sparr[0].asNumber(), sparr[1].asNumber(), sparr[2].asNumber()));
|
||||||
|
|
||||||
|
if (src.has("max-interaction-distance")) maxInteractionDistance = src["max-interaction-distance"].asNumber();
|
||||||
|
|
||||||
flight = src["flight"].asBoolean();
|
flight = src["flight"].asBoolean();
|
||||||
noclip = src["noclip"].asBoolean();
|
noclip = src["noclip"].asBoolean();
|
||||||
|
|||||||
@ -46,6 +46,7 @@ class Player : public Serializable {
|
|||||||
int64_t id;
|
int64_t id;
|
||||||
std::string name;
|
std::string name;
|
||||||
float speed;
|
float speed;
|
||||||
|
|
||||||
int chosenSlot;
|
int chosenSlot;
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 spawnpoint {};
|
glm::vec3 spawnpoint {};
|
||||||
@ -56,6 +57,10 @@ class Player : public Serializable {
|
|||||||
bool infiniteItems = true;
|
bool infiniteItems = true;
|
||||||
bool instantDestruction = true;
|
bool instantDestruction = true;
|
||||||
bool loadingChunks = true;
|
bool loadingChunks = true;
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
float maxInteractionDistance = 10.0f;
|
||||||
|
|
||||||
entityid_t eid = ENTITY_AUTO;
|
entityid_t eid = ENTITY_AUTO;
|
||||||
entityid_t selectedEid = 0;
|
entityid_t selectedEid = 0;
|
||||||
|
|
||||||
@ -90,6 +95,7 @@ public:
|
|||||||
void setChosenSlot(int index);
|
void setChosenSlot(int index);
|
||||||
|
|
||||||
int getChosenSlot() const;
|
int getChosenSlot() const;
|
||||||
|
|
||||||
float getSpeed() const;
|
float getSpeed() const;
|
||||||
|
|
||||||
bool isSuspended() const;
|
bool isSuspended() const;
|
||||||
@ -110,6 +116,9 @@ public:
|
|||||||
bool isLoadingChunks() const;
|
bool isLoadingChunks() const;
|
||||||
void setLoadingChunks(bool flag);
|
void setLoadingChunks(bool flag);
|
||||||
|
|
||||||
|
float getMaxInteractionDistance() const;
|
||||||
|
void setMaxInteractionDistance(float distance);
|
||||||
|
|
||||||
entityid_t getEntity() const;
|
entityid_t getEntity() const;
|
||||||
void setEntity(entityid_t eid);
|
void setEntity(entityid_t eid);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user