From ee0d3bacbce612c1abc6016cb7b0d684df25b820 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 1 Dec 2011 18:23:58 +0200 Subject: Player-is-SAO WIP --- src/content_sao.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'src/content_sao.cpp') diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 414d63f2d..a4c9c59f8 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -1799,4 +1799,96 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) m_messages_out.push_back(aom); } +/* + PlayerSAO +*/ + +// Prototype +PlayerSAO proto_PlayerSAO(NULL, v3f(0,0,0), NULL); + +PlayerSAO::PlayerSAO(ServerEnvironment *env, v3f pos, + ServerRemotePlayer *player): + ServerActiveObject(env, pos), + m_player(player), + m_position_updated(true) +{ + if(m_player) + m_player->setSAO(this); +} + +PlayerSAO::~PlayerSAO() +{ + if(m_player) + m_player->setSAO(NULL); +} + +void PlayerSAO::step(float dtime, bool send_recommended) +{ + if(!m_player) + return; + + if(send_recommended == false) + return; + + if(m_position_updated) + { + m_position_updated = false; + + std::ostringstream os(std::ios::binary); + // command (0 = update position) + writeU8(os, 0); + // pos + writeV3F1000(os, m_player->getPosition()); + // yaw + writeF1000(os, m_player->getYaw()); + // create message and add to list + ActiveObjectMessage aom(getId(), false, os.str()); + m_messages_out.push_back(aom); + } +} + +std::string PlayerSAO::getClientInitializationData() +{ + if(!m_player) + return ""; + + std::ostringstream os(std::ios::binary); + // version + writeU8(os, 0); + // name + os<getName()); + // pos + writeV3F1000(os, m_player->getPosition()); + // yaw + writeF1000(os, m_player->getYaw()); + return os.str(); +} + +std::string PlayerSAO::getStaticData() +{ + assert(0); + return ""; +} + +void PlayerSAO::punch(ServerActiveObject *puncher) +{ + infostream<<"TODO: PlayerSAO::punch()"<getName():"(NULL)")<<"\""<