summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorraymoo <raymoo@users.noreply.github.com>2016-11-11 23:22:39 -0800
committerZeno- <kde.psych@gmail.com>2016-11-12 17:22:39 +1000
commite4031156f13d062b03960e7ef1c9221f749f884b (patch)
tree9c7223d972521560d99a8438cbf1efcc00e3b32c /src/client.cpp
parent67ec2fa92d7441e0dab0fdc222003e916f3b5efa (diff)
downloadminetest-e4031156f13d062b03960e7ef1c9221f749f884b.tar.gz
minetest-e4031156f13d062b03960e7ef1c9221f749f884b.tar.bz2
minetest-e4031156f13d062b03960e7ef1c9221f749f884b.zip
Add control information to player interacts (#4685)
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 62bd274aa..3726f5bc4 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -929,6 +929,30 @@ void Client::Send(NetworkPacket* pkt)
serverCommandFactoryTable[pkt->getCommand()].reliable);
}
+// Will fill up 12 + 12 + 4 + 4 + 4 bytes
+void writePlayerPos(LocalPlayer *myplayer, NetworkPacket *pkt)
+{
+ v3f pf = myplayer->getPosition() * 100;
+ v3f sf = myplayer->getSpeed() * 100;
+ s32 pitch = myplayer->getPitch() * 100;
+ s32 yaw = myplayer->getYaw() * 100;
+ u32 keyPressed = myplayer->keyPressed;
+
+ v3s32 position(pf.X, pf.Y, pf.Z);
+ v3s32 speed(sf.X, sf.Y, sf.Z);
+
+ /*
+ Format:
+ [0] v3s32 position*100
+ [12] v3s32 speed*100
+ [12+12] s32 pitch*100
+ [12+12+4] s32 yaw*100
+ [12+12+4+4] u32 keyPressed
+ */
+
+ *pkt << position << speed << pitch << yaw << keyPressed;
+}
+
void Client::interact(u8 action, const PointedThing& pointed)
{
if(m_state != LC_Ready) {
@@ -938,12 +962,17 @@ void Client::interact(u8 action, const PointedThing& pointed)
return;
}
+ LocalPlayer *myplayer = m_env.getLocalPlayer();
+ if (myplayer == NULL)
+ return;
+
/*
[0] u16 command
[2] u8 action
[3] u16 item
- [5] u32 length of the next item
+ [5] u32 length of the next item (plen)
[9] serialized PointedThing
+ [9 + plen] player position information
actions:
0: start digging (from undersurface) or use
1: stop digging (all parameters ignored)
@@ -963,6 +992,8 @@ void Client::interact(u8 action, const PointedThing& pointed)
pkt.putLongString(tmp_os.str());
+ writePlayerPos(myplayer, &pkt);
+
Send(&pkt);
}
@@ -1291,26 +1322,9 @@ void Client::sendPlayerPos()
assert(myplayer->peer_id == our_peer_id);
- v3f pf = myplayer->getPosition();
- v3f sf = myplayer->getSpeed();
- s32 pitch = myplayer->getPitch() * 100;
- s32 yaw = myplayer->getYaw() * 100;
- u32 keyPressed = myplayer->keyPressed;
-
- v3s32 position(pf.X*100, pf.Y*100, pf.Z*100);
- v3s32 speed(sf.X*100, sf.Y*100, sf.Z*100);
- /*
- Format:
- [0] v3s32 position*100
- [12] v3s32 speed*100
- [12+12] s32 pitch*100
- [12+12+4] s32 yaw*100
- [12+12+4+4] u32 keyPressed
- */
-
NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4);
- pkt << position << speed << pitch << yaw << keyPressed;
+ writePlayerPos(myplayer, &pkt);
Send(&pkt);
}