1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

PlayerSAO/LocalPlayer refactor: (#4612)

* Create UnitSAO, a common part between PlayerSAO & LuaEntitySAO
* Move breath to PlayerSAO & LocalPlayer
* Migrate m_yaw from (Remote)Player & LuaEntitySAO to UnitSAO
* Migrate m_yaw from Player to LocalPlayer for client
* Move some functions outside of player class to PlayerSAO/RemotePlayer or LocalPlayer depending on which class needs it
* Move pitch to LocalPlayer & PlayerSAO
* Move m_position from Player to LocalPlayer
* Move camera_barely_in_ceiling to LocalPlayer as it's used only there
* use PlayerSAO::m_base_position for Server side positions
* remove a unused variable
* ServerActiveObject::setPos now uses const ref
* use ServerEnv::loadPlayer unconditionnaly as it creates RemotePlayer only if it's not already loaded
* Move hp from Player to LocalPlayer
* Move m_hp from LuaEntitySAO to UnitSAO
* Use m_hp from PlayerSAO/UnitSAO instead of RemotePlayer
This commit is contained in:
Ner'zhul 2016-10-30 14:53:26 +01:00 committed by GitHub
parent d43326021a
commit 9d25242c5c
18 changed files with 353 additions and 335 deletions

View file

@ -96,7 +96,7 @@ void RemotePlayer::save(std::string savedir, IGameDef *gamedef)
infostream << "Failed to open " << path << std::endl;
return;
}
testplayer.deSerialize(is, path);
testplayer.deSerialize(is, path, NULL);
is.close();
if (strcmp(testplayer.getName(), m_name) == 0) {
// Open file and serialize
@ -115,37 +115,46 @@ void RemotePlayer::save(std::string savedir, IGameDef *gamedef)
return;
}
void RemotePlayer::deSerialize(std::istream &is, const std::string &playername)
void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
PlayerSAO *sao)
{
Settings args;
if (!args.parseConfigLines(is, "PlayerArgsEnd")) {
throw SerializationError("PlayerArgsEnd of player " +
playername + " not found!");
throw SerializationError("PlayerArgsEnd of player " + playername + " not found!");
}
m_dirty = true;
//args.getS32("version"); // Version field value not used
std::string name = args.get("name");
strlcpy(m_name, name.c_str(), PLAYERNAME_SIZE);
setPitch(args.getFloat("pitch"));
setYaw(args.getFloat("yaw"));
setPosition(args.getV3F("position"));
try {
hp = args.getS32("hp");
} catch(SettingNotFoundException &e) {
hp = PLAYER_MAX_HP;
}
try {
m_breath = args.getS32("breath");
} catch(SettingNotFoundException &e) {
m_breath = PLAYER_MAX_BREATH;
if (sao) {
try {
sao->setHP(args.getS32("hp"), true);
} catch(SettingNotFoundException &e) {
sao->setHP(PLAYER_MAX_HP, true);
}
try {
sao->setBasePosition(args.getV3F("position"));
} catch (SettingNotFoundException &e) {}
try {
sao->setPitch(args.getFloat("pitch"), false);
} catch (SettingNotFoundException &e) {}
try {
sao->setYaw(args.getFloat("yaw"), false);
} catch (SettingNotFoundException &e) {}
try {
sao->setBreath(args.getS32("breath"));
} catch (SettingNotFoundException &e) {}
}
inventory.deSerialize(is);
if(inventory.getList("craftpreview") == NULL) {
if (inventory.getList("craftpreview") == NULL) {
// Convert players without craftpreview
inventory.addList("craftpreview", 1);
@ -167,11 +176,14 @@ void RemotePlayer::serialize(std::ostream &os)
args.setS32("version", 1);
args.set("name", m_name);
//args.set("password", m_password);
args.setFloat("pitch", m_pitch);
args.setFloat("yaw", m_yaw);
args.setV3F("position", m_position);
args.setS32("hp", hp);
args.setS32("breath", m_breath);
if (m_sao) {
args.setS32("hp", m_sao->getHP());
args.setV3F("position", m_sao->getBasePosition());
args.setFloat("pitch", m_sao->getPitch());
args.setFloat("yaw", m_sao->getYaw());
args.setS32("breath", m_sao->getBreath());
}
args.writeLines(os);
@ -180,16 +192,6 @@ void RemotePlayer::serialize(std::ostream &os)
inventory.serialize(os);
}
void RemotePlayer::setPosition(const v3f &position)
{
if (position != m_position)
m_dirty = true;
Player::setPosition(position);
if(m_sao)
m_sao->setBasePosition(position);
}
const RemotePlayerChatResult RemotePlayer::canSendChatMessage()
{
// Rate limit messages