mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-06 17:41:04 +00:00
added player link support
This commit is contained in:
parent
14a64000ea
commit
c17133d80a
6 changed files with 157 additions and 89 deletions
|
@ -18,12 +18,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include "content_cao.h"
|
||||
#include "clientlinkableobject.h"
|
||||
|
||||
/*
|
||||
PlayerCAO
|
||||
*/
|
||||
|
||||
class PlayerCAO : public ClientActiveObject
|
||||
class PlayerCAO : public ClientActiveObject, public ClientLinkableObject
|
||||
{
|
||||
private:
|
||||
core::aabbox3d<f32> m_selection_box;
|
||||
|
@ -212,8 +213,10 @@ public:
|
|||
|
||||
void step(float dtime, ClientEnvironment *env)
|
||||
{
|
||||
if(!isLinked()) {
|
||||
pos_translator.translate(dtime);
|
||||
updateNodePos();
|
||||
}
|
||||
|
||||
if(m_damage_visual_timer > 0){
|
||||
m_damage_visual_timer -= dtime;
|
||||
|
@ -252,6 +255,11 @@ public:
|
|||
m_damage_visual_timer = 0.5;
|
||||
updateTextures("^[brighten");
|
||||
}
|
||||
else if (handleLinkUnlinkMessages(cmd,&is,this->m_env))
|
||||
{
|
||||
//Link unlink already done in handleLinkUnlinkMessages!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void updateTextures(const std::string &mod)
|
||||
|
@ -277,6 +285,27 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
void setPosition(v3f toset, float dtime){
|
||||
if (isLinked()) {
|
||||
this->m_position = toset + this->m_linkOffset;
|
||||
pos_translator.update(this->m_position,false);
|
||||
updateNodePos();
|
||||
|
||||
if(m_is_local_player) {
|
||||
m_local_player->setPosition(this->m_position);
|
||||
}
|
||||
}
|
||||
else {
|
||||
errorstream<<"Got linked position update but not linked"<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void updateLinkState(bool value) {
|
||||
if(m_is_local_player) {
|
||||
m_local_player->Link(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline v3f getPosition() { return m_position; }
|
||||
|
||||
|
|
|
@ -1890,6 +1890,7 @@ void ClientEnvironment::step(float dtime)
|
|||
Get the speed the player is going
|
||||
*/
|
||||
bool is_climbing = lplayer->is_climbing;
|
||||
bool linked = lplayer->m_linked;
|
||||
|
||||
f32 player_speed = lplayer->getSpeed().getLength();
|
||||
|
||||
|
@ -1918,7 +1919,8 @@ void ClientEnvironment::step(float dtime)
|
|||
/*
|
||||
Stuff that has a maximum time increment
|
||||
*/
|
||||
|
||||
//TODO at this position possibly a better solution is required!
|
||||
if (!linked) {
|
||||
u32 loopcount = 0;
|
||||
do
|
||||
{
|
||||
|
@ -2011,6 +2013,7 @@ void ClientEnvironment::step(float dtime)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
A quick draft of lava damage
|
||||
|
|
|
@ -183,7 +183,8 @@ void Player::deSerialize(std::istream &is)
|
|||
LocalPlayer::LocalPlayer(IGameDef *gamedef):
|
||||
Player(gamedef),
|
||||
m_sneak_node(32767,32767,32767),
|
||||
m_sneak_node_exists(false)
|
||||
m_sneak_node_exists(false),
|
||||
m_linked(false)
|
||||
{
|
||||
// Initialize hp to 0, so that no hearts will be shown if server
|
||||
// doesn't support health points
|
||||
|
|
|
@ -251,6 +251,13 @@ public:
|
|||
|
||||
PlayerControl control;
|
||||
|
||||
|
||||
inline void Link(bool value) {
|
||||
m_linked = value;
|
||||
}
|
||||
|
||||
bool m_linked;
|
||||
|
||||
private:
|
||||
// This is used for determining the sneaking range
|
||||
v3s16 m_sneak_node;
|
||||
|
|
|
@ -101,13 +101,17 @@ void ServerRemotePlayer::step(float dtime, bool send_recommended)
|
|||
if(send_recommended == false)
|
||||
return;
|
||||
|
||||
if(isLinked())
|
||||
return;
|
||||
|
||||
|
||||
if(m_position_not_sent)
|
||||
{
|
||||
m_position_not_sent = false;
|
||||
|
||||
std::ostringstream os(std::ios::binary);
|
||||
// command (0 = update position)
|
||||
writeU8(os, 0);
|
||||
writeU8(os,AO_Message_type::SetPosition );
|
||||
// pos
|
||||
writeV3F1000(os, getPosition());
|
||||
// yaw
|
||||
|
@ -173,7 +177,7 @@ void ServerRemotePlayer::punch(ServerActiveObject *puncher,
|
|||
{
|
||||
std::ostringstream os(std::ios::binary);
|
||||
// command (1 = punched)
|
||||
writeU8(os, 1);
|
||||
writeU8(os, AO_Message_type::Punched);
|
||||
// damage
|
||||
writeS16(os, hitprop.hp);
|
||||
// create message and add to list
|
||||
|
@ -323,4 +327,24 @@ s16 ServerRemotePlayer::getHP()
|
|||
return hp;
|
||||
}
|
||||
|
||||
bool ServerRemotePlayer::sendLinkMsg(ServerActiveObject* parent,v3f offset) {
|
||||
std::ostringstream os(std::ios::binary);
|
||||
writeU8(os, AO_Message_type::Link);
|
||||
// parameters
|
||||
writeU16(os, parent->getId());
|
||||
writeV3F1000(os, offset);
|
||||
// create message and add to list
|
||||
ActiveObjectMessage aom(getId(), true, os.str());
|
||||
m_messages_out.push_back(aom);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ServerRemotePlayer::sendUnlinkMsg() {
|
||||
std::ostringstream os(std::ios::binary);
|
||||
writeU8(os, AO_Message_type::UnLink);
|
||||
// create message and add to list
|
||||
ActiveObjectMessage aom(getId(), true, os.str());
|
||||
m_messages_out.push_back(aom);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "player.h"
|
||||
#include "serverobject.h"
|
||||
#include "serverlinkableobject.h"
|
||||
#include "content_object.h" // Object type IDs
|
||||
|
||||
/*
|
||||
Player on the server
|
||||
*/
|
||||
|
||||
class ServerRemotePlayer : public Player, public ServerActiveObject
|
||||
class ServerRemotePlayer : public Player, public ServerActiveObject, public ServerLinkableObject
|
||||
{
|
||||
public:
|
||||
ServerRemotePlayer(ServerEnvironment *env);
|
||||
|
@ -97,6 +98,9 @@ public:
|
|||
// Incremented by step(), read and reset by Server
|
||||
float m_time_from_last_punch;
|
||||
|
||||
bool sendLinkMsg(ServerActiveObject* parent,v3f offset);
|
||||
bool sendUnlinkMsg();
|
||||
|
||||
private:
|
||||
bool m_position_not_sent;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue