summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2017-01-14 16:48:49 +0100
committersfan5 <sfan5@live.de>2017-01-18 23:21:01 +0100
commit7279f0b37335396c85f6bdd7dc67ff56e53df0f9 (patch)
treebe0ee716cf8bc6e5379415a663db91b8a358c8ab /src/network
parentc5967f75f0a9827d1b65b384edd6ba07c73ffd2f (diff)
downloadminetest-7279f0b37335396c85f6bdd7dc67ff56e53df0f9.tar.gz
minetest-7279f0b37335396c85f6bdd7dc67ff56e53df0f9.tar.bz2
minetest-7279f0b37335396c85f6bdd7dc67ff56e53df0f9.zip
Add particle animation, glow
This is implemented by reusing and extending the TileAnimation code for the methods used by particles.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientpackethandler.cpp18
-rw-r--r--src/network/networkpacket.cpp2
-rw-r--r--src/network/networkpacket.h5
3 files changed, 23 insertions, 2 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 411982f69..b11f73e86 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "network/clientopcodes.h"
#include "util/serialize.h"
#include "util/srp.h"
+#include "tileanimation.h"
void Client::handleCommand_Deprecated(NetworkPacket* pkt)
{
@@ -896,9 +897,14 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
std::string texture = deSerializeLongString(is);
bool vertical = false;
bool collision_removal = false;
+ struct TileAnimationParams animation;
+ animation.type = TAT_NONE;
+ u8 glow = 0;
try {
vertical = readU8(is);
collision_removal = readU8(is);
+ animation.deSerialize(is, m_proto_ver);
+ glow = readU8(is);
} catch (...) {}
ClientEvent event;
@@ -912,6 +918,8 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
event.spawn_particle.collision_removal = collision_removal;
event.spawn_particle.vertical = vertical;
event.spawn_particle.texture = new std::string(texture);
+ event.spawn_particle.animation = animation;
+ event.spawn_particle.glow = glow;
m_client_event_queue.push(event);
}
@@ -943,12 +951,20 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
bool vertical = false;
bool collision_removal = false;
+ struct TileAnimationParams animation;
+ animation.type = TAT_NONE;
+ u8 glow = 0;
u16 attached_id = 0;
try {
*pkt >> vertical;
*pkt >> collision_removal;
*pkt >> attached_id;
+ // This is horrible but required (why are there two ways to deserialize pkts?)
+ std::string datastring(pkt->getRemainingString(), pkt->getRemainingBytes());
+ std::istringstream is(datastring, std::ios_base::binary);
+ animation.deSerialize(is, m_proto_ver);
+ glow = readU8(is);
} catch (...) {}
ClientEvent event;
@@ -971,6 +987,8 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
event.add_particlespawner.vertical = vertical;
event.add_particlespawner.texture = new std::string(texture);
event.add_particlespawner.id = id;
+ event.add_particlespawner.animation = animation;
+ event.add_particlespawner.glow = glow;
m_client_event_queue.push(event);
}
diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp
index 388afc18e..91e6c58e2 100644
--- a/src/network/networkpacket.cpp
+++ b/src/network/networkpacket.cpp
@@ -63,7 +63,7 @@ void NetworkPacket::putRawPacket(u8 *data, u32 datasize, u16 peer_id)
m_data = std::vector<u8>(&data[2], &data[2 + m_datasize]);
}
-char* NetworkPacket::getString(u32 from_offset)
+const char* NetworkPacket::getString(u32 from_offset)
{
checkReadOffset(from_offset, 0);
diff --git a/src/network/networkpacket.h b/src/network/networkpacket.h
index 524470999..3e436aba9 100644
--- a/src/network/networkpacket.h
+++ b/src/network/networkpacket.h
@@ -41,12 +41,15 @@ public:
u16 getPeerId() { return m_peer_id; }
u16 getCommand() { return m_command; }
const u32 getRemainingBytes() const { return m_datasize - m_read_offset; }
+ const char* getRemainingString() { return getString(m_read_offset); }
// Returns a c-string without copying.
// A better name for this would be getRawString()
- char* getString(u32 from_offset);
+ const char* getString(u32 from_offset);
// major difference to putCString(): doesn't write len into the buffer
void putRawString(const char* src, u32 len);
+ void putRawString(const std::string &src)
+ { putRawString(src.c_str(), src.size()); }
NetworkPacket& operator>>(std::string& dst);
NetworkPacket& operator<<(std::string src);