From d499ec483837fa7210176ef39beba2d5a3a5a61d Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Fri, 27 May 2016 21:08:23 -0700 Subject: Particles: Add option to remove particles on collision Adds the particle option `collision_removal = bool` Some particles are hard to use right now since they either go through solid blocks (without collision detection), and with collision detection enabled they (e.g. raindrops) would just stop dead on the floor and sit there until they expire, or worse, scrape along a wall or ceiling. We can solve the problem by adding a boolean flag that tells the particle to be removed if it ever collides with something. This will make it easier to add rain that doesn't fall through your roof or stick on the top of it. Or clouds and smoke that don't go through trees. Particles that collide with this flag are marked expired unconditionally, causing them to be treated like normal expired particles and cleaned up normally. Documentation is adjusted accordingly. An added bonus of this patch is that particles can potentially collide many times with nodes, and this reduces the amount of collisions to 1 (max), which may end up reducing particle load on the client. --- src/script/lua_api/l_particles.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/script/lua_api/l_particles.cpp') diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index f6c1725de..263e35407 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -21,13 +21,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_internal.h" #include "common/c_converter.h" #include "server.h" +#include "particles.h" // add_particle({pos=, velocity=, acceleration=, expirationtime=, -// size=, collisiondetection=, vertical=, texture=, player=}) +// size=, collisiondetection=, collision_removal=, vertical=, +// texture=, player=}) // pos/velocity/acceleration = {x=num, y=num, z=num} // expirationtime = num (seconds) // size = num // collisiondetection = bool +// collision_removal = bool // vertical = bool // texture = e.g."default_wood.png" int ModApiParticles::l_add_particle(lua_State *L) @@ -41,8 +44,8 @@ int ModApiParticles::l_add_particle(lua_State *L) float expirationtime, size; expirationtime = size = 1; - bool collisiondetection, vertical; - collisiondetection = vertical = false; + bool collisiondetection, vertical, collision_removal; + collisiondetection = vertical = collision_removal = false; std::string texture = ""; std::string playername = ""; @@ -94,12 +97,14 @@ int ModApiParticles::l_add_particle(lua_State *L) size = getfloatfield_default(L, 1, "size", 1); collisiondetection = getboolfield_default(L, 1, "collisiondetection", collisiondetection); + collision_removal = getboolfield_default(L, 1, + "collision_removal", collision_removal); vertical = getboolfield_default(L, 1, "vertical", vertical); texture = getstringfield_default(L, 1, "texture", ""); playername = getstringfield_default(L, 1, "playername", ""); } - getServer(L)->spawnParticle(playername, pos, vel, acc, - expirationtime, size, collisiondetection, vertical, texture); + getServer(L)->spawnParticle(playername, pos, vel, acc, expirationtime, size, + collisiondetection, collision_removal, vertical, texture); return 1; } @@ -110,6 +115,7 @@ int ModApiParticles::l_add_particle(lua_State *L) // minexptime=, maxexptime=, // minsize=, maxsize=, // collisiondetection=, +// collision_removal=, // vertical=, // texture=, // player=}) @@ -117,6 +123,7 @@ int ModApiParticles::l_add_particle(lua_State *L) // minexptime/maxexptime = num (seconds) // minsize/maxsize = num // collisiondetection = bool +// collision_removal = bool // vertical = bool // texture = e.g."default_wood.png" int ModApiParticles::l_add_particlespawner(lua_State *L) @@ -129,8 +136,8 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) minpos= maxpos= minvel= maxvel= minacc= maxacc= v3f(0, 0, 0); float time, minexptime, maxexptime, minsize, maxsize; time= minexptime= maxexptime= minsize= maxsize= 1; - bool collisiondetection, vertical; - collisiondetection= vertical= false; + bool collisiondetection, vertical, collision_removal; + collisiondetection = vertical = collision_removal = false; std::string texture = ""; std::string playername = ""; @@ -189,6 +196,8 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) maxsize = getfloatfield_default(L, 1, "maxsize", maxsize); collisiondetection = getboolfield_default(L, 1, "collisiondetection", collisiondetection); + collision_removal = getboolfield_default(L, 1, + "collision_removal", collision_removal); vertical = getboolfield_default(L, 1, "vertical", vertical); texture = getstringfield_default(L, 1, "texture", ""); playername = getstringfield_default(L, 1, "playername", ""); @@ -201,6 +210,7 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) minexptime, maxexptime, minsize, maxsize, collisiondetection, + collision_removal, vertical, texture, playername); lua_pushnumber(L, id); -- cgit v1.2.3 From c9e7a27eeb628be78a835abadf8afe1177eb90c5 Mon Sep 17 00:00:00 2001 From: raymoo Date: Thu, 4 Aug 2016 13:09:21 -0700 Subject: Attached particle spawners --- doc/lua_api.txt | 2 + src/client.h | 1 + src/content_sao.cpp | 10 ++++- src/environment.cpp | 24 +++++++++++ src/environment.h | 4 +- src/network/clientpackethandler.cpp | 3 ++ src/particles.cpp | 81 ++++++++++++++++++++++++------------- src/particles.h | 3 +- src/script/lua_api/l_particles.cpp | 11 +++++ src/server.cpp | 17 ++++++-- src/server.h | 2 + src/serverobject.cpp | 1 - src/serverobject.h | 10 +++++ 13 files changed, 132 insertions(+), 37 deletions(-) (limited to 'src/script/lua_api/l_particles.cpp') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 6bdcd4fe4..a1d598e7d 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4120,6 +4120,8 @@ The Biome API is still in an experimental phase and subject to change. collision_removal = false, -- ^ collision_removal: if true then particle is removed when it collides, -- ^ requires collisiondetection = true to have any effect + attached = ObjectRef, + -- ^ attached: if defined, makes particle positions relative to this object. vertical = false, -- ^ vertical: if true faces player using y axis only texture = "image.png", diff --git a/src/client.h b/src/client.h index 6d24c0b1d..9f5bda059 100644 --- a/src/client.h +++ b/src/client.h @@ -201,6 +201,7 @@ struct ClientEvent f32 maxsize; bool collisiondetection; bool collision_removal; + u16 attached_id; bool vertical; std::string *texture; u32 id; diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 5d3ed38bc..375a43c90 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -156,6 +156,11 @@ LuaEntitySAO::~LuaEntitySAO() if(m_registered){ m_env->getScriptIface()->luaentity_Remove(m_id); } + + for (UNORDERED_SET::iterator it = m_attached_particle_spawners.begin(); + it != m_attached_particle_spawners.end(); ++it) { + m_env->deleteParticleSpawner(*it, false); + } } void LuaEntitySAO::addedToEnvironment(u32 dtime_s) @@ -817,7 +822,6 @@ PlayerSAO::~PlayerSAO() { if(m_inventory != &m_player->inventory) delete m_inventory; - } std::string PlayerSAO::getDescription() @@ -844,6 +848,10 @@ void PlayerSAO::removingFromEnvironment() m_player->peer_id = 0; m_env->savePlayer(m_player); m_env->removePlayer(m_player); + for (UNORDERED_SET::iterator it = m_attached_particle_spawners.begin(); + it != m_attached_particle_spawners.end(); ++it) { + m_env->deleteParticleSpawner(*it, false); + } } } diff --git a/src/environment.cpp b/src/environment.cpp index ceaa01d7a..ceaf40d89 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1518,6 +1518,30 @@ u32 ServerEnvironment::addParticleSpawner(float exptime) return id; } +u32 ServerEnvironment::addParticleSpawner(float exptime, u16 attached_id) +{ + u32 id = addParticleSpawner(exptime); + m_particle_spawner_attachments[id] = attached_id; + if (ServerActiveObject *obj = getActiveObject(attached_id)) { + obj->attachParticleSpawner(id); + } + return id; +} + +void ServerEnvironment::deleteParticleSpawner(u32 id, bool remove_from_object) +{ + m_particle_spawners.erase(id); + UNORDERED_MAP::iterator it = m_particle_spawner_attachments.find(id); + if (it != m_particle_spawner_attachments.end()) { + u16 obj_id = (*it).second; + ServerActiveObject *sao = getActiveObject(obj_id); + if (sao != NULL && remove_from_object) { + sao->detachParticleSpawner(id); + } + m_particle_spawner_attachments.erase(id); + } +} + ServerActiveObject* ServerEnvironment::getActiveObject(u16 id) { ActiveObjectMap::iterator n = m_active_objects.find(id); diff --git a/src/environment.h b/src/environment.h index 83ad69562..3f3c1cf2c 100644 --- a/src/environment.h +++ b/src/environment.h @@ -329,7 +329,8 @@ public: void loadDefaultMeta(); u32 addParticleSpawner(float exptime); - void deleteParticleSpawner(u32 id) { m_particle_spawners.erase(id); } + u32 addParticleSpawner(float exptime, u16 attached_id); + void deleteParticleSpawner(u32 id, bool remove_from_object = true); /* External ActiveObject interface @@ -519,6 +520,7 @@ private: // Particles IntervalLimiter m_particle_management_interval; UNORDERED_MAP m_particle_spawners; + UNORDERED_MAP m_particle_spawner_attachments; }; #ifndef SERVER diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index b39356e92..090741f9f 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -944,9 +944,11 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) bool vertical = false; bool collision_removal = false; + u16 attached_id = 0; try { *pkt >> vertical; *pkt >> collision_removal; + *pkt >> attached_id; } catch (...) {} @@ -966,6 +968,7 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) event.add_particlespawner.maxsize = maxsize; event.add_particlespawner.collisiondetection = collisiondetection; event.add_particlespawner.collision_removal = collision_removal; + event.add_particlespawner.attached_id = attached_id; event.add_particlespawner.vertical = vertical; event.add_particlespawner.texture = new std::string(texture); event.add_particlespawner.id = id; diff --git a/src/particles.cpp b/src/particles.cpp index ccca691d1..2efee6ada 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -213,7 +213,7 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, u16 amount, float time, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, float minsize, float maxsize, - bool collisiondetection, bool collision_removal, bool vertical, + bool collisiondetection, bool collision_removal, u16 attached_id, bool vertical, video::ITexture *texture, u32 id, ParticleManager *p_manager) : m_particlemanager(p_manager) { @@ -234,6 +234,7 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, m_maxsize = maxsize; m_collisiondetection = collisiondetection; m_collision_removal = collision_removal; + m_attached_id = attached_id; m_vertical = vertical; m_texture = texture; m_time = 0; @@ -251,6 +252,15 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) { m_time += dtime; + bool unloaded = false; + v3f attached_offset = v3f(0,0,0); + if (m_attached_id != 0) { + if (ClientActiveObject *attached = env->getActiveObject(m_attached_id)) + attached_offset = attached->getPosition() / BS; + else + unloaded = true; + } + if (m_spawntime != 0) // Spawner exists for a predefined timespan { for(std::vector::iterator i = m_spawntimes.begin(); @@ -260,33 +270,41 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) { m_amount--; - v3f pos = random_v3f(m_minpos, m_maxpos); - v3f vel = random_v3f(m_minvel, m_maxvel); - v3f acc = random_v3f(m_minacc, m_maxacc); - float exptime = rand()/(float)RAND_MAX - *(m_maxexptime-m_minexptime) - +m_minexptime; - float size = rand()/(float)RAND_MAX - *(m_maxsize-m_minsize) - +m_minsize; - - Particle* toadd = new Particle( - m_gamedef, - m_smgr, - m_player, - env, - pos, - vel, - acc, - exptime, - size, - m_collisiondetection, - m_collision_removal, - m_vertical, - m_texture, - v2f(0.0, 0.0), - v2f(1.0, 1.0)); - m_particlemanager->addParticle(toadd); + // Pretend to, but don't actually spawn a + // particle if it is attached to an unloaded + // object. + if (!unloaded) { + v3f pos = random_v3f(m_minpos, m_maxpos) + + attached_offset; + v3f vel = random_v3f(m_minvel, m_maxvel); + v3f acc = random_v3f(m_minacc, m_maxacc); + // Make relative to offest + pos += attached_offset; + float exptime = rand()/(float)RAND_MAX + *(m_maxexptime-m_minexptime) + +m_minexptime; + float size = rand()/(float)RAND_MAX + *(m_maxsize-m_minsize) + +m_minsize; + + Particle* toadd = new Particle( + m_gamedef, + m_smgr, + m_player, + env, + pos, + vel, + acc, + exptime, + size, + m_collisiondetection, + m_collision_removal, + m_vertical, + m_texture, + v2f(0.0, 0.0), + v2f(1.0, 1.0)); + m_particlemanager->addParticle(toadd); + } i = m_spawntimes.erase(i); } else @@ -297,11 +315,15 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) } else // Spawner exists for an infinity timespan, spawn on a per-second base { + // Skip this step if attached to an unloaded object + if (unloaded) + return; for (int i = 0; i <= m_amount; i++) { if (rand()/(float)RAND_MAX < dtime) { - v3f pos = random_v3f(m_minpos, m_maxpos); + v3f pos = random_v3f(m_minpos, m_maxpos) + + attached_offset; v3f vel = random_v3f(m_minvel, m_maxvel); v3f acc = random_v3f(m_minacc, m_maxacc); float exptime = rand()/(float)RAND_MAX @@ -453,6 +475,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, event->add_particlespawner.maxsize, event->add_particlespawner.collisiondetection, event->add_particlespawner.collision_removal, + event->add_particlespawner.attached_id, event->add_particlespawner.vertical, texture, event->add_particlespawner.id, diff --git a/src/particles.h b/src/particles.h index bc3ca53b7..eb8c6665d 100644 --- a/src/particles.h +++ b/src/particles.h @@ -119,6 +119,7 @@ class ParticleSpawner float minsize, float maxsize, bool collisiondetection, bool collision_removal, + u16 attached_id, bool vertical, video::ITexture *texture, u32 id, @@ -154,7 +155,7 @@ class ParticleSpawner bool m_collisiondetection; bool m_collision_removal; bool m_vertical; - + u16 m_attached_id; }; /** diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index 263e35407..667ac7272 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "lua_api/l_particles.h" +#include "lua_api/l_object.h" #include "lua_api/l_internal.h" #include "common/c_converter.h" #include "server.h" @@ -138,6 +139,7 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) time= minexptime= maxexptime= minsize= maxsize= 1; bool collisiondetection, vertical, collision_removal; collisiondetection = vertical = collision_removal = false; + ServerActiveObject *attached = NULL; std::string texture = ""; std::string playername = ""; @@ -198,6 +200,14 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) "collisiondetection", collisiondetection); collision_removal = getboolfield_default(L, 1, "collision_removal", collision_removal); + + lua_getfield(L, 1, "attached"); + if (!lua_isnil(L, -1)) { + ObjectRef *ref = ObjectRef::checkobject(L, -1); + lua_pop(L, 1); + attached = ObjectRef::getobject(ref); + } + vertical = getboolfield_default(L, 1, "vertical", vertical); texture = getstringfield_default(L, 1, "texture", ""); playername = getstringfield_default(L, 1, "playername", ""); @@ -211,6 +221,7 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) minsize, maxsize, collisiondetection, collision_removal, + attached, vertical, texture, playername); lua_pushnumber(L, id); diff --git a/src/server.cpp b/src/server.cpp index a93c143c7..e67f37d56 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1678,7 +1678,7 @@ void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f accelerat void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture, u32 id) + u16 attached_id, bool vertical, const std::string &texture, u32 id) { DSTACK(FUNCTION_NAME); @@ -1692,6 +1692,7 @@ void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3 pkt << id << vertical; pkt << collision_removal; + pkt << attached_id; if (peer_id != PEER_ID_INEXISTENT) { Send(&pkt); @@ -3156,7 +3157,7 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture, + ServerActiveObject *attached, bool vertical, const std::string &texture, const std::string &playername) { // m_env will be NULL if the server is initializing @@ -3171,11 +3172,19 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, peer_id = player->peer_id; } - u32 id = m_env->addParticleSpawner(spawntime); + u16 attached_id = attached ? attached->getId() : 0; + + u32 id; + if (attached_id == 0) + id = m_env->addParticleSpawner(spawntime); + else + id = m_env->addParticleSpawner(spawntime, attached_id); + SendAddParticleSpawner(peer_id, amount, spawntime, minpos, maxpos, minvel, maxvel, minacc, maxacc, minexptime, maxexptime, minsize, maxsize, - collisiondetection, collision_removal, vertical, texture, id); + collisiondetection, collision_removal, attached_id, vertical, + texture, id); return id; } diff --git a/src/server.h b/src/server.h index 6ee61a0eb..5fc2a9133 100644 --- a/src/server.h +++ b/src/server.h @@ -258,6 +258,7 @@ public: float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, + ServerActiveObject *attached, bool vertical, const std::string &texture, const std::string &playername); @@ -434,6 +435,7 @@ private: float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, + u16 attached_id, bool vertical, const std::string &texture, u32 id); void SendDeleteParticleSpawner(u16 peer_id, u32 id); diff --git a/src/serverobject.cpp b/src/serverobject.cpp index 236d7e8dc..191247829 100644 --- a/src/serverobject.cpp +++ b/src/serverobject.cpp @@ -98,4 +98,3 @@ bool ServerActiveObject::setWieldedItem(const ItemStack &item) } return false; } - diff --git a/src/serverobject.h b/src/serverobject.h index cfe2b6bcc..63650e3be 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -188,6 +188,15 @@ public: { return 0; } virtual ItemStack getWieldedItem() const; virtual bool setWieldedItem(const ItemStack &item); + inline void attachParticleSpawner(u32 id) + { + m_attached_particle_spawners.insert(id); + } + inline void detachParticleSpawner(u32 id) + { + m_attached_particle_spawners.erase(id); + } + /* Number of players which know about this object. Object won't be @@ -242,6 +251,7 @@ protected: ServerEnvironment *m_env; v3f m_base_position; + UNORDERED_SET m_attached_particle_spawners; private: // Used for creating objects based on type -- cgit v1.2.3 From 93e3555eae2deaeca69ee252cfa9cc9c3e0e49ef Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Mon, 14 Nov 2016 18:09:59 +0400 Subject: Adding particle blend, glow and animation (#4705) --- builtin/common/misc_helpers.lua | 37 +++++++ doc/lua_api.txt | 189 ++++++++++++++++++++++++++++++++- src/client.h | 18 ++++ src/network/clientpackethandler.cpp | 111 ++++++++++++++------ src/nodedef.cpp | 4 +- src/nodedef.h | 11 +- src/particles.cpp | 203 +++++++++++++++++++++++++++++++++--- src/particles.h | 32 +++++- src/script/common/c_content.cpp | 13 +-- src/script/common/c_content.h | 2 +- src/script/common/c_converter.cpp | 22 ++++ src/script/common/c_converter.h | 2 + src/script/lua_api/l_particles.cpp | 166 ++++++++++++++++++++++++++++- src/server.cpp | 44 ++++++-- src/server.h | 27 ++++- 15 files changed, 800 insertions(+), 81 deletions(-) (limited to 'src/script/lua_api/l_particles.cpp') diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index c2dc7514d..a495058d9 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -237,6 +237,43 @@ function math.sign(x, tolerance) return 0 end +-------------------------------------------------------------------------------- +-- Video enums and pack function + +-- E_BLEND_FACTOR +minetest.ebf = { + zero = 0, -- src & dest (0, 0, 0, 0) + one = 1, -- src & dest (1, 1, 1, 1) + dst_color = 2, -- src (destR, destG, destB, destA) + one_minus_dst_color = 3, -- src (1-destR, 1-destG, 1-destB, 1-destA) + src_color = 4, -- dest (srcR, srcG, srcB, srcA) + one_minus_src_color = 5, -- dest (1-srcR, 1-srcG, 1-srcB, 1-srcA) + src_alpha = 6, -- src & dest (srcA, srcA, srcA, srcA) + one_minus_src_alpha = 7, -- src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA) + dst_alpha = 8, -- src & dest (destA, destA, destA, destA) + one_minus_dst_alpha = 9, -- src & dest (1-destA, 1-destA, 1-destA, 1-destA) + src_alpha_saturate = 10,-- src (min(srcA, 1-destA), idem, ...) +} + +-- E_MODULATE_FUNC +minetest.emfn = { + modulate_1x = 1, + modulate_2x = 2, + modulate_4x = 4, +} + +-- E_ALPHA_SOURCE +minetest.eas = { + none = 0, + vertex_color = 1, + texture = 2, +} + +-- BlendFunc = source * sourceFactor + dest * destFactor +function minetest.pack_texture_blend_func(srcFact, dstFact, modulate, alphaSource) + return alphaSource * 4096 + modulate * 256 + srcFact * 16 + dstFact +end + -------------------------------------------------------------------------------- function get_last_folder(text,count) local parts = text:split(DIR_DELIM) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 7d552c980..3b3f17634 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -414,6 +414,119 @@ the word "`alpha`", then each texture pixel will contain the RGB of `` and the alpha of `` multiplied by the alpha of the texture pixel. +Particle blend +-------------- +Blend function is defined by integer number. +There is a huge number of acceptable blend modificators. +Colour of a resulting pixel calculated using formulae: + + red = source_red * source_factor + destination_red * destination_factor + +and so on for every channel. + +Here is a some examples: + +Default value: + + material_type_param = 0, + +Use this value to disable blending. Texture will be applied to existing pixels +using alpha channel of it. Its recomended to use 1-bit alpha +in that case. This value will leave z-buffer writeable. + +Additive blend: + + material_type_param = 12641, + +Source = src_alpha, destination = one, alpha source is a texture and +vertex_color, modulate_1x. +Black color is completely transparent, white color is completely opaque. +Alpha channel still used to calculate result color, but not nessesary. +'destination = one' means that resulting color will be calculated using +overwritten pixels values. +For example with color of source (our texture) RGBA = (0,192,255,63) +"blue-cyan", 1/4 opaque. +and already rendered pixel color (40,192,0) "dark lime green" we will get color: + +R = source_red(0) * source_factor(src_alpha=63/255) + + destination_red(40) * destination_factor(one) = + 0 * 63/255 + 40 * 1 = 40 + +G = 192 * 63/255 + 192 * 1 = 239 +B = 255 * 63/255 + 0 * 1 = 63 + +Result: (40,239,63), "green" (a kind of). +Note, if you made a texture with some kind of shape with colour 662211h +it will appear dark red with a single particle, then yellow with a +several of them and white if player looking thru a lot of them. With +this you could made a nice-looking fire. + +Substractive blend: + + material_type_param = 12548, + +Source = zero, destination = src_color, alpha source is a texture and +vertex_color, modulate_1x. +Texture darkness act like an alpha channel. +Black color is completely opaque, white color is completely transparent. +'destination = src_color' means that destination in multiplied by +a source values. 'source = zero' means that source values ignored +(multiplied by 0). + +Invert blend: + + material_type_param = 12597, + +Source = one_minus_dst_color, destination = one_minus_src_alpha, alpha source +is a texture and vertex_color, modulate_1x. +Pixels invert color if source color value is big enough. If not, they just +black. +'destination = one_minus_src_alpha' means, that effect is masked by a +source alpha channel. + +You can design and use your own blend using those enum values and function +'minetest.pack_texture_blend_func'. Returned value of a function is +your 'material_type_param'. + +A values in a brackets is a multiplicators of a red, green, blue +and alpha channels respectively. + +* 'minetest.ebf': global table, containing blend factor enum values. Such as: + * zero = 0 -- src & dest (0, 0, 0, 0) + * one = 1 -- src & dest (1, 1, 1, 1) + * dst_color = 2 -- src (destR, destG, destB, destA) + * one_minus_dst_color = 3 -- src (1-destR, 1-destG, 1-destB, 1-destA) + * src_color = 4 -- dest (srcR, srcG, srcB, srcA) + * one_minus_src_color = 5 -- dest (1-srcR, 1-srcG, 1-srcB, 1-srcA) + * src_alpha = 6 -- src & dest (srcA, srcA, srcA, srcA) + * one_minus_src_alpha = 7 -- src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA) + * dst_alpha = 8 -- src & dest (destA, destA, destA, destA) + * one_minus_dst_alpha = 9 -- src & dest (1-destA, 1-destA, 1-destA, 1-destA) + * src_alpha_saturate = 10 -- src (min(srcA, 1-destA), idem, ...) + +* 'minetest.emfn': global table, containing modulate enum values. + * Multiply the components of the arguments, and shift the products to the + * left by x bits for brightening. Contain: + * modulate_1x = 1 -- no bit shift + * modulate_2x = 2 -- 1 bits shift + * modulate_4x = 4 -- 2 bits shift + +'modulate_4x' is quite useful when you want to make additive blend stronger +with a lower amount of particles. + +* 'minetest.eas': global table, containing alpha source enum values. Such as: + * none = 0 -- do not use alpha. + * vertex_color = 1 -- use vertex color alpha. + * texture = 2 -- use texture alpha. + +You can use both 'vertex_color' and 'texture' source by using value 3. + +* 'minetest.pack_texture_blend_func(srcFact, dstFact, modulate, alphaSource)': return integer + * Pack texture blend funcion variable. Depending from that variable blend + * function will be applied in time of a render poligons with selected material. + * Therefore resulting pixel will be 'source * srcFact + destination * dstFact' + * Use result of this function as 'material_type_param'. + Sounds ------ Only Ogg Vorbis files are supported. @@ -3650,7 +3763,7 @@ Definition tables ### Tile definition * `"image.png"` -* `{name="image.png", animation={Tile Animation definition}}` +* `{name="image.png", animation={Animation definition}}` * `{name="image.png", backface_culling=bool, tileable_vertical=bool, tileable_horizontal=bool}` * backface culling enabled by default for most nodes @@ -3661,8 +3774,50 @@ Definition tables * deprecated, yet still supported field names: * `image` (name) -### Tile animation definition -* `{type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}` +### Animation definition + +#### Node animation, particle and particle spawners +* `{ type="vertical_frames", + aspect_w=16, + -- ^ specify width of a picture in pixels. + aspect_h=16, + -- ^ specify height of a frame in pixels. + length=3.0 + -- ^ specify full loop length. + first_frame = 0, -- <- only for particles, use + min_first_frame = 0, -- <- for particle spawners + max_first_frame = 0, + loop_animation = true, -- <- only for particles and particle spawners + -- specify if animation should start from beginning after last frame. +}` + +#### Particle and particle spawners only +* `{ + type="2d_animation_sheet", -- <- only for particles and particle spawners + vertical_frame_num = 1, + horizontal_frame_num = 1, + -- ^ specify amount of frames in texture. + -- Can be used both for animation or for texture transform + -- together with first_frame variable. + -- A animation texture separated on equal parts of frames, + -- by horizontal and vertical numbers. For example with + -- vertical_frame_num = 4 and horizontal_frame_num = 3 we got + -- 4*3 = 12 frames in total. Animation sequence start from + -- left top frame and go on to the right until reach end of + -- row. Next row also start from left frame. + first_frame = 0, -- <- only for particles, use + min_first_frame = 0, -- <- for particle spawners + max_first_frame = 0, + -- ^ specify first frame to start animation. + frame_length = -1, + -- ^ specify length of a frame in seconds. Negative and zero values + -- disable animation. A sequence with vertical_frame_num = 4 and + -- horizontal_frame_num = 3, first_frame = 4 and frame_length = 0.1 + -- will end in (4*3-4)*0.1 = 0.8 seconds. + loop_animation = true, + -- specify if animation should start from beginning after last frame. +}` + * All settings are optional. Default values is located in this example. ### Node definition (`register_node`) @@ -4117,6 +4272,20 @@ The Biome API is still in an experimental phase and subject to change. -- ^ Uses texture (string) playername = "singleplayer" -- ^ optional, if specified spawns particle only on the player's client + material_type_param = 12641, + -- ^ optional, if specified spawns particle with + -- specified material type param and disable z-buffer. + -- Some examples: + -- Default value: 0, + -- Additive blend: 12641, + -- Substractive blend: 12548, + -- Invert blend: 12597, + -- See also "Particle blend". + animation = {Animation definition}, + -- ^ see above. Note, that particle and particle spawners have differences. + glow = 15, + -- ^ optional, specify particle self-luminescence in darkness. + values may vary from 0 (no glow) to 15 (bright glow). } ### `ParticleSpawner` definition (`add_particlespawner`) @@ -4151,6 +4320,20 @@ The Biome API is still in an experimental phase and subject to change. -- ^ Uses texture (string) playername = "singleplayer" -- ^ Playername is optional, if specified spawns particle only on the player's client + material_type_param = 12641, + -- ^ optional, if specified spawns particle with specified material type + -- param and disable z-buffer. + -- Some examples: + -- Default value: 0, + -- Additive blend: 12641, + -- Substractive blend: 12548, + -- Invert blend: 12597, + -- See also "Particle blend". + animation = {Animation definition}, + -- ^ see above. Note, that particle and particle spawners have differences. + glow = 15, + -- ^ optional, specify particle self-luminescence in darkness. + values may vary from 0 (no glow) to 15 (bright glow). } ### `HTTPRequest` definition (`HTTPApiTable.fetch_async`, `HTTPApiTable.fetch_async`) diff --git a/src/client.h b/src/client.h index 9f5bda059..c51daf7bc 100644 --- a/src/client.h +++ b/src/client.h @@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "hud.h" #include "particles.h" #include "network/networkpacket.h" +#include "nodedef.h" // AnimationType struct MeshMakeData; class MapBlockMesh; @@ -185,6 +186,14 @@ struct ClientEvent bool collision_removal; bool vertical; std::string *texture; + u32 material_type_param; + AnimationType animation_type; + u16 vertical_frame_num; + u16 horizontal_frame_num; + u16 first_frame; + float frame_length; + bool loop_animation; + u8 glow; } spawn_particle; struct{ u16 amount; @@ -205,6 +214,15 @@ struct ClientEvent bool vertical; std::string *texture; u32 id; + u32 material_type_param; + AnimationType animation_type; + u16 vertical_frame_num; + u16 horizontal_frame_num; + u16 min_first_frame; + u16 max_first_frame; + float frame_length; + bool loop_animation; + u8 glow; } add_particlespawner; struct{ u32 id; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 411982f69..03baf078a 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -896,23 +896,46 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt) std::string texture = deSerializeLongString(is); bool vertical = false; bool collision_removal = false; + u32 material_type_param = 0; + AnimationType animation_type = AT_NONE; + u16 vertical_frame_num = 1; + u16 horizontal_frame_num = 1; + u16 first_frame = 0; + float frame_length = -1; + bool loop_animation = true; + u8 glow = 0; try { vertical = readU8(is); collision_removal = readU8(is); + material_type_param = readU32(is); + animation_type = (AnimationType)readU8(is); + vertical_frame_num = readU16(is); + horizontal_frame_num = readU16(is); + first_frame = readU16(is); + frame_length = readF1000(is); + loop_animation = readU8(is); + glow = readU8(is); } catch (...) {} ClientEvent event; - event.type = CE_SPAWN_PARTICLE; - event.spawn_particle.pos = new v3f (pos); - event.spawn_particle.vel = new v3f (vel); - event.spawn_particle.acc = new v3f (acc); - event.spawn_particle.expirationtime = expirationtime; - event.spawn_particle.size = size; - event.spawn_particle.collisiondetection = collisiondetection; - event.spawn_particle.collision_removal = collision_removal; - event.spawn_particle.vertical = vertical; - event.spawn_particle.texture = new std::string(texture); - + event.type = CE_SPAWN_PARTICLE; + event.spawn_particle.pos = new v3f (pos); + event.spawn_particle.vel = new v3f (vel); + event.spawn_particle.acc = new v3f (acc); + event.spawn_particle.expirationtime = expirationtime; + event.spawn_particle.size = size; + event.spawn_particle.collisiondetection = collisiondetection; + event.spawn_particle.collision_removal = collision_removal; + event.spawn_particle.vertical = vertical; + event.spawn_particle.texture = new std::string(texture); + event.spawn_particle.material_type_param = material_type_param; + event.spawn_particle.animation_type = animation_type; + event.spawn_particle.vertical_frame_num = vertical_frame_num; + event.spawn_particle.horizontal_frame_num = horizontal_frame_num; + event.spawn_particle.first_frame = first_frame; + event.spawn_particle.frame_length = frame_length; + event.spawn_particle.loop_animation = loop_animation; + event.spawn_particle.glow = glow; m_client_event_queue.push(event); } @@ -932,6 +955,15 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) float maxsize; bool collisiondetection; u32 id; + u32 material_type_param = 0; + u8 animation_type = (u8)AT_NONE; + u16 vertical_frame_num = 1; + u16 horizontal_frame_num = 1; + u16 min_first_frame = 0; + u16 max_first_frame = 0; + float frame_length = -1; + bool loop_animation = true; + u8 glow = 0; *pkt >> amount >> spawntime >> minpos >> maxpos >> minvel >> maxvel >> minacc >> maxacc >> minexptime >> maxexptime >> minsize @@ -948,29 +980,46 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) *pkt >> vertical; *pkt >> collision_removal; *pkt >> attached_id; - + *pkt >> material_type_param; + *pkt >> animation_type; + *pkt >> vertical_frame_num; + *pkt >> horizontal_frame_num; + *pkt >> min_first_frame; + *pkt >> max_first_frame; + *pkt >> frame_length; + *pkt >> loop_animation; + *pkt >> glow; } catch (...) {} ClientEvent event; - event.type = CE_ADD_PARTICLESPAWNER; - event.add_particlespawner.amount = amount; - event.add_particlespawner.spawntime = spawntime; - event.add_particlespawner.minpos = new v3f (minpos); - event.add_particlespawner.maxpos = new v3f (maxpos); - event.add_particlespawner.minvel = new v3f (minvel); - event.add_particlespawner.maxvel = new v3f (maxvel); - event.add_particlespawner.minacc = new v3f (minacc); - event.add_particlespawner.maxacc = new v3f (maxacc); - event.add_particlespawner.minexptime = minexptime; - event.add_particlespawner.maxexptime = maxexptime; - event.add_particlespawner.minsize = minsize; - event.add_particlespawner.maxsize = maxsize; - event.add_particlespawner.collisiondetection = collisiondetection; - event.add_particlespawner.collision_removal = collision_removal; - event.add_particlespawner.attached_id = attached_id; - event.add_particlespawner.vertical = vertical; - event.add_particlespawner.texture = new std::string(texture); - event.add_particlespawner.id = id; + event.type = CE_ADD_PARTICLESPAWNER; + event.add_particlespawner.amount = amount; + event.add_particlespawner.spawntime = spawntime; + event.add_particlespawner.minpos = new v3f (minpos); + event.add_particlespawner.maxpos = new v3f (maxpos); + event.add_particlespawner.minvel = new v3f (minvel); + event.add_particlespawner.maxvel = new v3f (maxvel); + event.add_particlespawner.minacc = new v3f (minacc); + event.add_particlespawner.maxacc = new v3f (maxacc); + event.add_particlespawner.minexptime = minexptime; + event.add_particlespawner.maxexptime = maxexptime; + event.add_particlespawner.minsize = minsize; + event.add_particlespawner.maxsize = maxsize; + event.add_particlespawner.collisiondetection = collisiondetection; + event.add_particlespawner.collision_removal = collision_removal; + event.add_particlespawner.attached_id = attached_id; + event.add_particlespawner.vertical = vertical; + event.add_particlespawner.texture = new std::string(texture); + event.add_particlespawner.id = id; + event.add_particlespawner.material_type_param = material_type_param; + event.add_particlespawner.animation_type = (AnimationType)animation_type; + event.add_particlespawner.vertical_frame_num = vertical_frame_num; + event.add_particlespawner.horizontal_frame_num = horizontal_frame_num; + event.add_particlespawner.min_first_frame = min_first_frame; + event.add_particlespawner.max_first_frame = max_first_frame; + event.add_particlespawner.frame_length = frame_length; + event.add_particlespawner.loop_animation = loop_animation; + event.add_particlespawner.glow = glow; m_client_event_queue.push(event); } diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 39ea1a60e..c690e6720 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -211,7 +211,7 @@ void TileDef::deSerialize(std::istream &is, const u8 contenfeatures_version, con { int version = readU8(is); name = deSerializeString(is); - animation.type = (TileAnimationType)readU8(is); + animation.type = (AnimationType)readU8(is); animation.aspect_w = readU16(is); animation.aspect_h = readU16(is); animation.length = readF1000(is); @@ -531,7 +531,7 @@ void ContentFeatures::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, tile->material_flags = 0; if (backface_culling) tile->material_flags |= MATERIAL_FLAG_BACKFACE_CULLING; - if (tiledef->animation.type == TAT_VERTICAL_FRAMES) + if (tiledef->animation.type == AT_VERTICAL_FRAMES) tile->material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES; if (tiledef->tileable_horizontal) tile->material_flags |= MATERIAL_FLAG_TILEABLE_HORIZONTAL; diff --git a/src/nodedef.h b/src/nodedef.h index 80396f992..f47517c4a 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -161,9 +161,10 @@ enum NodeDrawType /* Stand-alone definition of a TileSpec (basically a server-side TileSpec) */ -enum TileAnimationType{ - TAT_NONE=0, - TAT_VERTICAL_FRAMES=1, +enum AnimationType{ + AT_NONE = 0, + AT_VERTICAL_FRAMES = 1, + AT_2D_ANIMATION_SHEET = 2, }; struct TileDef { @@ -172,7 +173,7 @@ struct TileDef bool tileable_horizontal; bool tileable_vertical; struct{ - enum TileAnimationType type; + enum AnimationType type; int aspect_w; // width for aspect ratio int aspect_h; // height for aspect ratio float length; // seconds @@ -184,7 +185,7 @@ struct TileDef backface_culling = true; tileable_horizontal = true; tileable_vertical = true; - animation.type = TAT_NONE; + animation.type = AT_NONE; animation.aspect_w = 1; animation.aspect_h = 1; animation.length = 1.0; diff --git a/src/particles.cpp b/src/particles.cpp index f20fb4083..538487028 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -43,6 +43,22 @@ v3f random_v3f(v3f min, v3f max) rand()/(float)RAND_MAX*(max.Z-min.Z)+min.Z); } +u32 check_material_type_param(u32 material_type_param) +{ + u32 alphaSource = (material_type_param & 0x0000F000) >> 12; + u32 modulo = (material_type_param & 0x00000F00) >> 8; + u32 srcFact = (material_type_param & 0x000000F0) >> 4; + u32 dstFact = material_type_param & 0x0000000F; + if (alphaSource <= 3 && modulo <= 4 && srcFact <= 10 && dstFact <= 10) { + return material_type_param; + } else { + errorstream << "Server send incorrect "; + errorstream << "material_type_param value for particle."; + errorstream << std::endl; + return 0; + } +} + Particle::Particle( IGameDef *gamedef, scene::ISceneManager* smgr, @@ -58,7 +74,14 @@ Particle::Particle( bool vertical, video::ITexture *texture, v2f texpos, - v2f texsize + v2f texsize, + u32 material_type_param, + u16 vertical_frame_num, + u16 horizontal_frame_num, + u16 first_frame, + float frame_length, + bool loop_animation, + u8 glow ): scene::ISceneNode(smgr->getRootSceneNode(), smgr) { @@ -71,11 +94,26 @@ Particle::Particle( m_material.setFlag(video::EMF_BACK_FACE_CULLING, false); m_material.setFlag(video::EMF_BILINEAR_FILTER, false); m_material.setFlag(video::EMF_FOG_ENABLE, true); - m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + if (material_type_param != 0) { + m_material.MaterialType = video::EMT_ONETEXTURE_BLEND; + m_material.MaterialTypeParam = irr::core::FR(material_type_param); + // We must disable z-buffer if we want to avoid transparent pixels + // to overlap pixels with lower z-value. + m_material.setFlag(video::EMF_ZWRITE_ENABLE, false); + } else { + m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + } m_material.setTexture(0, texture); + m_texpos = texpos; m_texsize = texsize; - + m_vertical_frame_num = vertical_frame_num; + m_horizontal_frame_num = horizontal_frame_num; + m_first_frame = first_frame; + m_frame_length = frame_length; + m_loop_animation = loop_animation; + m_texsize.Y /= m_vertical_frame_num; + m_texsize.X /= m_horizontal_frame_num; // Particle related m_pos = pos; @@ -88,6 +126,7 @@ Particle::Particle( m_collisiondetection = collisiondetection; m_collision_removal = collision_removal; m_vertical = vertical; + m_glow = glow; // Irrlicht stuff m_collisionbox = aabb3f @@ -170,16 +209,29 @@ void Particle::updateLight() else light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0); - m_light = decode_light(light); + m_light = decode_light(light + m_glow); } void Particle::updateVertices() { video::SColor c(255, m_light, m_light, m_light); - f32 tx0 = m_texpos.X; - f32 tx1 = m_texpos.X + m_texsize.X; - f32 ty0 = m_texpos.Y; - f32 ty1 = m_texpos.Y + m_texsize.Y; + u16 frame = m_first_frame; + if (m_frame_length > 0) { + if (m_loop_animation) + frame = m_first_frame + (u32)(m_time / m_frame_length) + % (m_vertical_frame_num * + m_horizontal_frame_num - m_first_frame); + else if (m_time >= + (m_vertical_frame_num * m_horizontal_frame_num + - m_first_frame) * m_frame_length) + frame = m_vertical_frame_num * m_horizontal_frame_num - 1; + else + frame = m_first_frame + (u16)(m_time / m_frame_length); + } + f32 tx0 = m_texpos.X + m_texsize.X * (frame % m_horizontal_frame_num); + f32 tx1 = m_texpos.X + m_texsize.X * (frame % m_horizontal_frame_num + 1); + f32 ty0 = m_texpos.Y + m_texsize.Y * (frame / m_horizontal_frame_num); + f32 ty1 = m_texpos.Y + m_texsize.Y * (frame / m_horizontal_frame_num + 1); m_vertices[0] = video::S3DVertex(-m_size/2,-m_size/2,0, 0,0,0, c, tx0, ty1); @@ -214,7 +266,16 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, u16 attached_id, bool vertical, - video::ITexture *texture, u32 id, ParticleManager *p_manager) : + video::ITexture *texture, u32 id, + u32 material_type_param, + u16 vertical_frame_num, + u16 horizontal_frame_num, + u16 min_first_frame, + u16 max_first_frame, + float frame_length, + bool loop_animation, + u8 glow, + ParticleManager *p_manager) : m_particlemanager(p_manager) { m_gamedef = gamedef; @@ -238,6 +299,14 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, m_vertical = vertical; m_texture = texture; m_time = 0; + m_vertical_frame_num = vertical_frame_num; + m_horizontal_frame_num = horizontal_frame_num; + m_min_first_frame = min_first_frame; + m_max_first_frame = max_first_frame; + m_frame_length = frame_length; + m_loop_animation = loop_animation; + m_material_type_param = material_type_param; + m_glow = glow; for (u16 i = 0; i<=m_amount; i++) { @@ -251,7 +320,6 @@ ParticleSpawner::~ParticleSpawner() {} void ParticleSpawner::step(float dtime, ClientEnvironment* env) { m_time += dtime; - bool unloaded = false; v3f attached_offset = v3f(0,0,0); if (m_attached_id != 0) { @@ -285,7 +353,10 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) float size = rand()/(float)RAND_MAX *(m_maxsize-m_minsize) +m_minsize; - + u16 first_frame = m_min_first_frame + + rand() % + (m_max_first_frame - + m_min_first_frame + 1); Particle* toadd = new Particle( m_gamedef, m_smgr, @@ -301,7 +372,14 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) m_vertical, m_texture, v2f(0.0, 0.0), - v2f(1.0, 1.0)); + v2f(1.0, 1.0), + m_material_type_param, + m_vertical_frame_num, + m_horizontal_frame_num, + first_frame, + m_frame_length, + m_loop_animation, + m_glow); m_particlemanager->addParticle(toadd); } i = m_spawntimes.erase(i); @@ -331,7 +409,10 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) float size = rand()/(float)RAND_MAX *(m_maxsize-m_minsize) +m_minsize; - + u16 first_frame = m_min_first_frame + + rand() % + (m_max_first_frame - + m_min_first_frame + 1); Particle* toadd = new Particle( m_gamedef, m_smgr, @@ -347,7 +428,14 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) m_vertical, m_texture, v2f(0.0, 0.0), - v2f(1.0, 1.0)); + v2f(1.0, 1.0), + m_material_type_param, + m_vertical_frame_num, + m_horizontal_frame_num, + first_frame, + m_frame_length, + m_loop_animation, + m_glow); m_particlemanager->addParticle(toadd); } } @@ -459,6 +547,39 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, video::ITexture *texture = gamedef->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture)); + float frame_length = -1; + u16 vertical_frame_num = 1; + u16 horizontal_frame_num = 1; + u32 material_type_param = + check_material_type_param(event->add_particlespawner.material_type_param); + + switch (event->add_particlespawner.animation_type) { + case AT_NONE: + break; + case AT_VERTICAL_FRAMES: { + v2u32 size = texture->getOriginalSize(); + int frame_height = (float)size.X / + (float)event->add_particlespawner.vertical_frame_num * + (float)event->add_particlespawner.horizontal_frame_num; + vertical_frame_num = size.Y / frame_height; + frame_length = + event->add_particlespawner.frame_length / + vertical_frame_num; + break; + } + case AT_2D_ANIMATION_SHEET: { + vertical_frame_num = + event->add_particlespawner.vertical_frame_num; + horizontal_frame_num = + event->add_particlespawner.horizontal_frame_num; + frame_length = + event->add_particlespawner.frame_length; + break; + } + default: + break; + } + ParticleSpawner* toadd = new ParticleSpawner(gamedef, smgr, player, event->add_particlespawner.amount, event->add_particlespawner.spawntime, @@ -478,6 +599,14 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, event->add_particlespawner.vertical, texture, event->add_particlespawner.id, + material_type_param, + vertical_frame_num, + horizontal_frame_num, + event->add_particlespawner.min_first_frame, + event->add_particlespawner.max_first_frame, + frame_length, + event->add_particlespawner.loop_animation, + event->add_particlespawner.glow, this); /* delete allocated content of event */ @@ -502,6 +631,39 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, video::ITexture *texture = gamedef->tsrc()->getTextureForMesh(*(event->spawn_particle.texture)); + float frame_length = -1; + u16 vertical_frame_num = 1; + u16 horizontal_frame_num = 1; + u32 material_type_param = + check_material_type_param(event->spawn_particle.material_type_param); + + switch (event->spawn_particle.animation_type) { + case AT_NONE: + break; + case AT_VERTICAL_FRAMES: { + v2u32 size = texture->getOriginalSize(); + int frame_height = (float)size.X / + (float)event->spawn_particle.vertical_frame_num * + (float)event->spawn_particle.horizontal_frame_num; + vertical_frame_num = size.Y / frame_height; + frame_length = + event->spawn_particle.frame_length / + vertical_frame_num; + break; + } + case AT_2D_ANIMATION_SHEET: { + vertical_frame_num = + event->spawn_particle.vertical_frame_num; + horizontal_frame_num = + event->spawn_particle.horizontal_frame_num; + frame_length = + event->spawn_particle.frame_length; + break; + } + default: + break; + } + Particle* toadd = new Particle(gamedef, smgr, player, m_env, *event->spawn_particle.pos, *event->spawn_particle.vel, @@ -513,13 +675,21 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, event->spawn_particle.vertical, texture, v2f(0.0, 0.0), - v2f(1.0, 1.0)); + v2f(1.0, 1.0), + material_type_param, + vertical_frame_num, + horizontal_frame_num, + event->spawn_particle.first_frame, + frame_length, + event->spawn_particle.loop_animation, + event->spawn_particle.glow); addParticle(toadd); delete event->spawn_particle.pos; delete event->spawn_particle.vel; delete event->spawn_particle.acc; + delete event->spawn_particle.texture; break; } @@ -588,7 +758,8 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* s false, texture, texpos, - texsize); + texsize, + 0, 1, 1, 0, -1, true, 0); addParticle(toadd); } diff --git a/src/particles.h b/src/particles.h index eb8c6665d..6d8c6139f 100644 --- a/src/particles.h +++ b/src/particles.h @@ -50,7 +50,14 @@ class Particle : public scene::ISceneNode bool vertical, video::ITexture *texture, v2f texpos, - v2f texsize + v2f texsize, + u32 material_type_param, + u16 vertical_frame_num, + u16 horizontal_frame_num, + u16 first_frame, + float frame_length, + bool loop_animation, + u8 glow ); ~Particle(); @@ -102,6 +109,12 @@ private: bool m_collision_removal; bool m_vertical; v3s16 m_camera_offset; + u16 m_vertical_frame_num; + u16 m_horizontal_frame_num; + u16 m_first_frame; + float m_frame_length; + bool m_loop_animation; + u8 m_glow; }; class ParticleSpawner @@ -123,8 +136,15 @@ class ParticleSpawner bool vertical, video::ITexture *texture, u32 id, + u32 material_type_param, + u16 vertical_frame_num, + u16 horizontal_frame_num, + u16 min_first_frame, + u16 max_first_frame, + float frame_length, + bool loop_animation, + u8 glow, ParticleManager* p_manager); - ~ParticleSpawner(); void step(float dtime, ClientEnvironment *env); @@ -156,6 +176,14 @@ class ParticleSpawner bool m_collision_removal; bool m_vertical; u16 m_attached_id; + u32 m_material_type_param; + u16 m_vertical_frame_num; + u16 m_horizontal_frame_num; + u16 m_min_first_frame; + u16 m_max_first_frame; + float m_frame_length; + bool m_loop_animation; + u8 m_glow; }; /** diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index f20a65903..d4a25b68b 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -35,10 +35,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "noise.h" #include -struct EnumString es_TileAnimationType[] = +struct EnumString es_AnimationType[] = { - {TAT_NONE, "none"}, - {TAT_VERTICAL_FRAMES, "vertical_frames"}, + {AT_NONE, "none"}, + {AT_VERTICAL_FRAMES, "vertical_frames"}, + {AT_2D_ANIMATION_SHEET, "2d_animation_sheet"}, {0, NULL}, }; @@ -335,9 +336,9 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype) lua_getfield(L, index, "animation"); if(lua_istable(L, -1)){ // {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0} - tiledef.animation.type = (TileAnimationType) - getenumfield(L, -1, "type", es_TileAnimationType, - TAT_NONE); + tiledef.animation.type = (AnimationType) + getenumfield(L, -1, "type", es_AnimationType, + AT_NONE); tiledef.animation.aspect_w = getintfield_default(L, -1, "aspect_w", 16); tiledef.animation.aspect_h = diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 2a2228b6d..32fdb4f04 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -159,6 +159,6 @@ bool push_json_value (lua_State *L, void read_json_value (lua_State *L, Json::Value &root, int index, u8 recursion = 0); -extern struct EnumString es_TileAnimationType[]; +extern struct EnumString es_AnimationType[]; #endif /* C_CONTENT_H_ */ diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index f36298915..cfb5e26db 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -513,6 +513,28 @@ int getintfield_default(lua_State *L, int table, return result; } +int check_material_type_param(lua_State *L, int table, + const char *fieldname, int default_) +{ + int material_type_param = + getintfield_default(L, table, fieldname, default_); + u32 alphaSource = (material_type_param & 0x0000F000) >> 12; + u32 modulo = (material_type_param & 0x00000F00) >> 8; + u32 srcFact = (material_type_param & 0x000000F0) >> 4; + u32 dstFact = material_type_param & 0x0000000F; + if (alphaSource <= 3 && modulo <= 4 && srcFact <= 10 && dstFact <= 10) { + return material_type_param; + } else { + std::ostringstream error_text; + error_text << "Incorrect material_type_param value "; + error_text << "for particle or particle spawner."; + error_text << std::endl; + throw LuaError(error_text.str()); + return 0; + } +} + + float getfloatfield_default(lua_State *L, int table, const char *fieldname, float default_) { diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index a5fbee765..71ac735c1 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -45,6 +45,8 @@ float getfloatfield_default(lua_State *L, int table, const char *fieldname, float default_); int getintfield_default (lua_State *L, int table, const char *fieldname, int default_); +int check_material_type_param(lua_State *L, int table, + const char *fieldname, int default_); bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result); diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index 667ac7272..b0a57ce6d 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_object.h" #include "lua_api/l_internal.h" #include "common/c_converter.h" +#include "common/c_content.h" #include "server.h" #include "particles.h" @@ -34,6 +35,9 @@ with this program; if not, write to the Free Software Foundation, Inc., // collision_removal = bool // vertical = bool // texture = e.g."default_wood.png" +// material_type_param = num +// animation = animation definition +// glow = indexed color or color string int ModApiParticles::l_add_particle(lua_State *L) { MAP_LOCK_REQUIRED; @@ -44,13 +48,24 @@ int ModApiParticles::l_add_particle(lua_State *L) float expirationtime, size; expirationtime = size = 1; + float frame_or_loop_length = -1; + + AnimationType animation_type = AT_NONE; + + u16 vertical_frame_num_or_aspect = 1; + u16 horizontal_frame_num_or_aspect = 1; + u16 first_frame = 0; bool collisiondetection, vertical, collision_removal; collisiondetection = vertical = collision_removal = false; + bool loop_animation = true; std::string texture = ""; std::string playername = ""; + u32 material_type_param = 0; + u8 glow = 0; + if (lua_gettop(L) > 1) // deprecated { log_deprecated(L, "Deprecated add_particle call with individual parameters instead of definition"); @@ -94,8 +109,61 @@ int ModApiParticles::l_add_particle(lua_State *L) acc = lua_istable(L, -1) ? check_v3f(L, -1) : acc; lua_pop(L, 1); - expirationtime = getfloatfield_default(L, 1, "expirationtime", 1); + expirationtime = getfloatfield_default(L, 1, "expirationtime", 1); size = getfloatfield_default(L, 1, "size", 1); + + lua_getfield(L, 1, "animation"); + if (lua_istable(L, -1)) { + animation_type = (AnimationType) + getenumfield(L, -1, "type", es_AnimationType, + AT_NONE); + } + switch (animation_type) { + case AT_NONE: + break; + case AT_2D_ANIMATION_SHEET: + frame_or_loop_length = + getfloatfield_default(L, -1, "frame_length", -1); + vertical_frame_num_or_aspect = + getintfield_default(L, -1, "vertical_frame_num", 1); + horizontal_frame_num_or_aspect = + getintfield_default(L, -1, "horizontal_frame_num", 1); + first_frame = + getintfield_default(L, -1, "first_frame", 0); + loop_animation = + getboolfield_default(L, -1, "loop_animation", true); + break; + case AT_VERTICAL_FRAMES: + frame_or_loop_length = + getfloatfield_default(L, -1, "length", -1); + vertical_frame_num_or_aspect = + getintfield_default(L, -1, "aspect_w", 1); + horizontal_frame_num_or_aspect = + getintfield_default(L, -1, "aspect_h", 1); + first_frame = + getintfield_default(L, -1, "first_frame", 0); + loop_animation = + getboolfield_default(L, -1, "loop_animation", true); + break; + default: + break; + } + lua_pop(L, 1); + + if (animation_type == AT_2D_ANIMATION_SHEET && + first_frame >= vertical_frame_num_or_aspect * + horizontal_frame_num_or_aspect) { + std::ostringstream error_text; + error_text << "first_frame should be lower, than " + << "vertical_frame_num * horizontal_frame_num. " + << "Got first_frame=" << first_frame + << ", vertical_frame_num=" + << vertical_frame_num_or_aspect + << " and horizontal_frame_num=" + << horizontal_frame_num_or_aspect << std::endl; + throw LuaError(error_text.str()); + } + collisiondetection = getboolfield_default(L, 1, "collisiondetection", collisiondetection); collision_removal = getboolfield_default(L, 1, @@ -103,9 +171,16 @@ int ModApiParticles::l_add_particle(lua_State *L) vertical = getboolfield_default(L, 1, "vertical", vertical); texture = getstringfield_default(L, 1, "texture", ""); playername = getstringfield_default(L, 1, "playername", ""); + material_type_param = check_material_type_param(L, 1, "material_type_param", 0); + glow = getintfield_default (L, 1, "glow", 0); } - getServer(L)->spawnParticle(playername, pos, vel, acc, expirationtime, size, - collisiondetection, collision_removal, vertical, texture); + getServer(L)->spawnParticle(playername, pos, vel, acc, expirationtime, + size, collisiondetection, collision_removal, vertical, + texture, material_type_param, + animation_type, + vertical_frame_num_or_aspect, + horizontal_frame_num_or_aspect, + first_frame, frame_or_loop_length, loop_animation, glow); return 1; } @@ -127,21 +202,33 @@ int ModApiParticles::l_add_particle(lua_State *L) // collision_removal = bool // vertical = bool // texture = e.g."default_wood.png" +// material_type_param = num +// animation = animation definition +// glow = indexed color or color string int ModApiParticles::l_add_particlespawner(lua_State *L) { MAP_LOCK_REQUIRED; // Get parameters u16 amount = 1; + u16 vertical_frame_num_or_aspect = 1; + u16 horizontal_frame_num_or_aspect = 1; + u16 min_first_frame = 0; + u16 max_first_frame = 0; v3f minpos, maxpos, minvel, maxvel, minacc, maxacc; minpos= maxpos= minvel= maxvel= minacc= maxacc= v3f(0, 0, 0); float time, minexptime, maxexptime, minsize, maxsize; time= minexptime= maxexptime= minsize= maxsize= 1; + AnimationType animation_type = AT_NONE; + float frame_or_loop_length = -1; bool collisiondetection, vertical, collision_removal; collisiondetection = vertical = collision_removal = false; + bool loop_animation = true; ServerActiveObject *attached = NULL; std::string texture = ""; std::string playername = ""; + u32 material_type_param = 0; + u8 glow = 0; if (lua_gettop(L) > 1) //deprecated { @@ -196,6 +283,65 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) maxexptime = getfloatfield_default(L, 1, "maxexptime", maxexptime); minsize = getfloatfield_default(L, 1, "minsize", minsize); maxsize = getfloatfield_default(L, 1, "maxsize", maxsize); + + + lua_getfield(L, 1, "animation"); + if (lua_istable(L, -1)) { + animation_type = (AnimationType) + getenumfield(L, -1, "type", es_AnimationType, + AT_NONE); + } + switch (animation_type) { + case AT_NONE: + break; + case AT_2D_ANIMATION_SHEET: + frame_or_loop_length = + getfloatfield_default(L, -1, "frame_length", -1); + vertical_frame_num_or_aspect = + getintfield_default(L, -1, "vertical_frame_num", 1); + horizontal_frame_num_or_aspect = + getintfield_default(L, -1, "horizontal_frame_num", 1); + min_first_frame = + getintfield_default(L, -1, "min_first_frame", 0); + max_first_frame = + getintfield_default(L, -1, "max_first_frame", 0); + loop_animation = + getboolfield_default(L, -1, "loop_animation", true); + break; + case AT_VERTICAL_FRAMES: + frame_or_loop_length = + getfloatfield_default(L, -1, "length", -1); + vertical_frame_num_or_aspect = + getintfield_default(L, -1, "aspect_w", 1); + horizontal_frame_num_or_aspect = + getintfield_default(L, -1, "aspect_h", 1); + min_first_frame = + getintfield_default(L, -1, "min_first_frame", 0); + max_first_frame = + getintfield_default(L, -1, "max_first_frame", 0); + loop_animation = + getboolfield_default(L, -1, "loop_animation", true); + break; + default: + break; + } + lua_pop(L, 1); + + if (animation_type == AT_2D_ANIMATION_SHEET && + max_first_frame >= vertical_frame_num_or_aspect * + horizontal_frame_num_or_aspect) { + std::ostringstream error_text; + error_text << "max_first_frame should be lower, than " + << "vertical_frame_num * horizontal_frame_num. " + << "Got max_first_frame=" + << max_first_frame + << ", vertical_frame_num=" + << vertical_frame_num_or_aspect + << " and horizontal_frame_num=" + << horizontal_frame_num_or_aspect << std::endl; + throw LuaError(error_text.str()); + } + collisiondetection = getboolfield_default(L, 1, "collisiondetection", collisiondetection); collision_removal = getboolfield_default(L, 1, @@ -211,6 +357,8 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) vertical = getboolfield_default(L, 1, "vertical", vertical); texture = getstringfield_default(L, 1, "texture", ""); playername = getstringfield_default(L, 1, "playername", ""); + material_type_param = check_material_type_param(L, 1, "material_type_param", 0); + glow = getintfield_default(L, 1, "glow", 0); } u32 id = getServer(L)->addParticleSpawner(amount, time, @@ -223,9 +371,17 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) collision_removal, attached, vertical, - texture, playername); + texture, + playername, + material_type_param, + animation_type, + vertical_frame_num_or_aspect, + horizontal_frame_num_or_aspect, + min_first_frame, max_first_frame, + frame_or_loop_length, + loop_animation, + glow); lua_pushnumber(L, id); - return 1; } diff --git a/src/server.cpp b/src/server.cpp index 48331e4f8..cef57be88 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1658,7 +1658,11 @@ void Server::SendShowFormspecMessage(u16 peer_id, const std::string &formspec, void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture) + bool vertical, const std::string &texture, + u32 material_type_param, AnimationType animation_type, + u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, + float frame_length, bool loop_animation, + u8 glow) { DSTACK(FUNCTION_NAME); @@ -1670,6 +1674,12 @@ void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f accelerat pkt << vertical; pkt << collision_removal; + pkt << material_type_param + << (u8)animation_type + << vertical_frame_num + << horizontal_frame_num << first_frame + << frame_length << loop_animation << glow; + if (peer_id != PEER_ID_INEXISTENT) { Send(&pkt); } @@ -1682,7 +1692,10 @@ void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f accelerat void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, - u16 attached_id, bool vertical, const std::string &texture, u32 id) + u16 attached_id, bool vertical, const std::string &texture, u32 id, + u32 material_type_param, AnimationType animation_type, u16 vertical_frame_num, u16 horizontal_frame_num, + u16 min_first_frame, u16 max_first_frame, float frame_length, + bool loop_animation, u8 glow) { DSTACK(FUNCTION_NAME); @@ -1698,6 +1711,12 @@ void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3 pkt << collision_removal; pkt << attached_id; + pkt << material_type_param + << (u8)animation_type + << vertical_frame_num << horizontal_frame_num + << min_first_frame << max_first_frame + << frame_length << loop_animation << glow; + if (peer_id != PEER_ID_INEXISTENT) { Send(&pkt); } @@ -3147,7 +3166,11 @@ void Server::spawnParticle(const std::string &playername, v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture) + bool vertical, const std::string &texture, + u32 material_type_param, AnimationType animation_type, + u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, + float frame_length, bool loop_animation, + u8 glow) { // m_env will be NULL if the server is initializing if (!m_env) @@ -3163,7 +3186,11 @@ void Server::spawnParticle(const std::string &playername, v3f pos, SendSpawnParticle(peer_id, pos, velocity, acceleration, expirationtime, size, collisiondetection, - collision_removal, vertical, texture); + collision_removal, vertical, texture, + material_type_param, animation_type, + vertical_frame_num, horizontal_frame_num, + first_frame, frame_length, loop_animation, + glow); } u32 Server::addParticleSpawner(u16 amount, float spawntime, @@ -3171,7 +3198,9 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, ServerActiveObject *attached, bool vertical, const std::string &texture, - const std::string &playername) + const std::string &playername, u32 material_type_param, AnimationType animation_type, + u16 vertical_frame_num, u16 horizontal_frame_num, u16 min_first_frame, u16 max_first_frame, + float frame_length, bool loop_animation, u8 glow) { // m_env will be NULL if the server is initializing if (!m_env) @@ -3197,7 +3226,10 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, minpos, maxpos, minvel, maxvel, minacc, maxacc, minexptime, maxexptime, minsize, maxsize, collisiondetection, collision_removal, attached_id, vertical, - texture, id); + texture, id, material_type_param, animation_type, + vertical_frame_num, horizontal_frame_num, + min_first_frame, max_first_frame, frame_length, loop_animation, + glow); return id; } diff --git a/src/server.h b/src/server.h index 9e844e36c..9a8d22b2e 100644 --- a/src/server.h +++ b/src/server.h @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "hud.h" #include "gamedef.h" #include "serialization.h" // For SER_FMT_VER_INVALID +#include "nodedef.h" // AnimationType #include "mods.h" #include "inventorymanager.h" #include "subgame.h" @@ -254,7 +255,11 @@ public: v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture); + bool vertical, const std::string &texture, + u32 material_type_param, AnimationType animation_type, + u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, + float frame_length, bool loop_animation, + u8 glow); u32 addParticleSpawner(u16 amount, float spawntime, v3f minpos, v3f maxpos, @@ -265,7 +270,12 @@ public: bool collisiondetection, bool collision_removal, ServerActiveObject *attached, bool vertical, const std::string &texture, - const std::string &playername); + const std::string &playername, + u32 material_type_param, AnimationType animation_type, + u16 vertical_frame_num, u16 horizontal_frame_num, + u16 min_first_frame, u16 max_first_frame, + float frame_length, bool loop_animation, + u8 glow); void deleteParticleSpawner(const std::string &playername, u32 id); @@ -441,7 +451,12 @@ private: float minsize, float maxsize, bool collisiondetection, bool collision_removal, u16 attached_id, - bool vertical, const std::string &texture, u32 id); + bool vertical, const std::string &texture, u32 id, + u32 material_type_param, AnimationType animation_type, + u16 vertical_frame_num, u16 horizontal_frame_num, + u16 min_first_frame, u16 max_first_frame, + float frame_length, bool loop_animation, + u8 glow); void SendDeleteParticleSpawner(u16 peer_id, u32 id); @@ -450,7 +465,11 @@ private: v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture); + bool vertical, const std::string &texture, + u32 material_type_param, AnimationType animation_type, + u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, + float frame_length, bool loop_animation, + u8 glow); u32 SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas); void SendActiveObjectMessages(u16 peer_id, const std::string &datas, bool reliable = true); -- cgit v1.2.3 From 5fd1ef9b589419e2464f5599ea47a2f28f4d7b7b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 14 Nov 2016 15:28:06 +0100 Subject: Revert "Adding particle blend, glow and animation (#4705)" This reverts commit 93e3555eae2deaeca69ee252cfa9cc9c3e0e49ef. --- builtin/common/misc_helpers.lua | 37 ------- doc/lua_api.txt | 189 +-------------------------------- src/client.h | 18 ---- src/network/clientpackethandler.cpp | 111 ++++++-------------- src/nodedef.cpp | 4 +- src/nodedef.h | 11 +- src/particles.cpp | 203 +++--------------------------------- src/particles.h | 32 +----- src/script/common/c_content.cpp | 13 ++- src/script/common/c_content.h | 2 +- src/script/common/c_converter.cpp | 22 ---- src/script/common/c_converter.h | 2 - src/script/lua_api/l_particles.cpp | 166 +---------------------------- src/server.cpp | 44 ++------ src/server.h | 27 +---- 15 files changed, 81 insertions(+), 800 deletions(-) (limited to 'src/script/lua_api/l_particles.cpp') diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index a495058d9..c2dc7514d 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -237,43 +237,6 @@ function math.sign(x, tolerance) return 0 end --------------------------------------------------------------------------------- --- Video enums and pack function - --- E_BLEND_FACTOR -minetest.ebf = { - zero = 0, -- src & dest (0, 0, 0, 0) - one = 1, -- src & dest (1, 1, 1, 1) - dst_color = 2, -- src (destR, destG, destB, destA) - one_minus_dst_color = 3, -- src (1-destR, 1-destG, 1-destB, 1-destA) - src_color = 4, -- dest (srcR, srcG, srcB, srcA) - one_minus_src_color = 5, -- dest (1-srcR, 1-srcG, 1-srcB, 1-srcA) - src_alpha = 6, -- src & dest (srcA, srcA, srcA, srcA) - one_minus_src_alpha = 7, -- src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA) - dst_alpha = 8, -- src & dest (destA, destA, destA, destA) - one_minus_dst_alpha = 9, -- src & dest (1-destA, 1-destA, 1-destA, 1-destA) - src_alpha_saturate = 10,-- src (min(srcA, 1-destA), idem, ...) -} - --- E_MODULATE_FUNC -minetest.emfn = { - modulate_1x = 1, - modulate_2x = 2, - modulate_4x = 4, -} - --- E_ALPHA_SOURCE -minetest.eas = { - none = 0, - vertex_color = 1, - texture = 2, -} - --- BlendFunc = source * sourceFactor + dest * destFactor -function minetest.pack_texture_blend_func(srcFact, dstFact, modulate, alphaSource) - return alphaSource * 4096 + modulate * 256 + srcFact * 16 + dstFact -end - -------------------------------------------------------------------------------- function get_last_folder(text,count) local parts = text:split(DIR_DELIM) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 3b3f17634..7d552c980 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -414,119 +414,6 @@ the word "`alpha`", then each texture pixel will contain the RGB of `` and the alpha of `` multiplied by the alpha of the texture pixel. -Particle blend --------------- -Blend function is defined by integer number. -There is a huge number of acceptable blend modificators. -Colour of a resulting pixel calculated using formulae: - - red = source_red * source_factor + destination_red * destination_factor - -and so on for every channel. - -Here is a some examples: - -Default value: - - material_type_param = 0, - -Use this value to disable blending. Texture will be applied to existing pixels -using alpha channel of it. Its recomended to use 1-bit alpha -in that case. This value will leave z-buffer writeable. - -Additive blend: - - material_type_param = 12641, - -Source = src_alpha, destination = one, alpha source is a texture and -vertex_color, modulate_1x. -Black color is completely transparent, white color is completely opaque. -Alpha channel still used to calculate result color, but not nessesary. -'destination = one' means that resulting color will be calculated using -overwritten pixels values. -For example with color of source (our texture) RGBA = (0,192,255,63) -"blue-cyan", 1/4 opaque. -and already rendered pixel color (40,192,0) "dark lime green" we will get color: - -R = source_red(0) * source_factor(src_alpha=63/255) + - destination_red(40) * destination_factor(one) = - 0 * 63/255 + 40 * 1 = 40 - -G = 192 * 63/255 + 192 * 1 = 239 -B = 255 * 63/255 + 0 * 1 = 63 - -Result: (40,239,63), "green" (a kind of). -Note, if you made a texture with some kind of shape with colour 662211h -it will appear dark red with a single particle, then yellow with a -several of them and white if player looking thru a lot of them. With -this you could made a nice-looking fire. - -Substractive blend: - - material_type_param = 12548, - -Source = zero, destination = src_color, alpha source is a texture and -vertex_color, modulate_1x. -Texture darkness act like an alpha channel. -Black color is completely opaque, white color is completely transparent. -'destination = src_color' means that destination in multiplied by -a source values. 'source = zero' means that source values ignored -(multiplied by 0). - -Invert blend: - - material_type_param = 12597, - -Source = one_minus_dst_color, destination = one_minus_src_alpha, alpha source -is a texture and vertex_color, modulate_1x. -Pixels invert color if source color value is big enough. If not, they just -black. -'destination = one_minus_src_alpha' means, that effect is masked by a -source alpha channel. - -You can design and use your own blend using those enum values and function -'minetest.pack_texture_blend_func'. Returned value of a function is -your 'material_type_param'. - -A values in a brackets is a multiplicators of a red, green, blue -and alpha channels respectively. - -* 'minetest.ebf': global table, containing blend factor enum values. Such as: - * zero = 0 -- src & dest (0, 0, 0, 0) - * one = 1 -- src & dest (1, 1, 1, 1) - * dst_color = 2 -- src (destR, destG, destB, destA) - * one_minus_dst_color = 3 -- src (1-destR, 1-destG, 1-destB, 1-destA) - * src_color = 4 -- dest (srcR, srcG, srcB, srcA) - * one_minus_src_color = 5 -- dest (1-srcR, 1-srcG, 1-srcB, 1-srcA) - * src_alpha = 6 -- src & dest (srcA, srcA, srcA, srcA) - * one_minus_src_alpha = 7 -- src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA) - * dst_alpha = 8 -- src & dest (destA, destA, destA, destA) - * one_minus_dst_alpha = 9 -- src & dest (1-destA, 1-destA, 1-destA, 1-destA) - * src_alpha_saturate = 10 -- src (min(srcA, 1-destA), idem, ...) - -* 'minetest.emfn': global table, containing modulate enum values. - * Multiply the components of the arguments, and shift the products to the - * left by x bits for brightening. Contain: - * modulate_1x = 1 -- no bit shift - * modulate_2x = 2 -- 1 bits shift - * modulate_4x = 4 -- 2 bits shift - -'modulate_4x' is quite useful when you want to make additive blend stronger -with a lower amount of particles. - -* 'minetest.eas': global table, containing alpha source enum values. Such as: - * none = 0 -- do not use alpha. - * vertex_color = 1 -- use vertex color alpha. - * texture = 2 -- use texture alpha. - -You can use both 'vertex_color' and 'texture' source by using value 3. - -* 'minetest.pack_texture_blend_func(srcFact, dstFact, modulate, alphaSource)': return integer - * Pack texture blend funcion variable. Depending from that variable blend - * function will be applied in time of a render poligons with selected material. - * Therefore resulting pixel will be 'source * srcFact + destination * dstFact' - * Use result of this function as 'material_type_param'. - Sounds ------ Only Ogg Vorbis files are supported. @@ -3763,7 +3650,7 @@ Definition tables ### Tile definition * `"image.png"` -* `{name="image.png", animation={Animation definition}}` +* `{name="image.png", animation={Tile Animation definition}}` * `{name="image.png", backface_culling=bool, tileable_vertical=bool, tileable_horizontal=bool}` * backface culling enabled by default for most nodes @@ -3774,50 +3661,8 @@ Definition tables * deprecated, yet still supported field names: * `image` (name) -### Animation definition - -#### Node animation, particle and particle spawners -* `{ type="vertical_frames", - aspect_w=16, - -- ^ specify width of a picture in pixels. - aspect_h=16, - -- ^ specify height of a frame in pixels. - length=3.0 - -- ^ specify full loop length. - first_frame = 0, -- <- only for particles, use - min_first_frame = 0, -- <- for particle spawners - max_first_frame = 0, - loop_animation = true, -- <- only for particles and particle spawners - -- specify if animation should start from beginning after last frame. -}` - -#### Particle and particle spawners only -* `{ - type="2d_animation_sheet", -- <- only for particles and particle spawners - vertical_frame_num = 1, - horizontal_frame_num = 1, - -- ^ specify amount of frames in texture. - -- Can be used both for animation or for texture transform - -- together with first_frame variable. - -- A animation texture separated on equal parts of frames, - -- by horizontal and vertical numbers. For example with - -- vertical_frame_num = 4 and horizontal_frame_num = 3 we got - -- 4*3 = 12 frames in total. Animation sequence start from - -- left top frame and go on to the right until reach end of - -- row. Next row also start from left frame. - first_frame = 0, -- <- only for particles, use - min_first_frame = 0, -- <- for particle spawners - max_first_frame = 0, - -- ^ specify first frame to start animation. - frame_length = -1, - -- ^ specify length of a frame in seconds. Negative and zero values - -- disable animation. A sequence with vertical_frame_num = 4 and - -- horizontal_frame_num = 3, first_frame = 4 and frame_length = 0.1 - -- will end in (4*3-4)*0.1 = 0.8 seconds. - loop_animation = true, - -- specify if animation should start from beginning after last frame. -}` - * All settings are optional. Default values is located in this example. +### Tile animation definition +* `{type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}` ### Node definition (`register_node`) @@ -4272,20 +4117,6 @@ The Biome API is still in an experimental phase and subject to change. -- ^ Uses texture (string) playername = "singleplayer" -- ^ optional, if specified spawns particle only on the player's client - material_type_param = 12641, - -- ^ optional, if specified spawns particle with - -- specified material type param and disable z-buffer. - -- Some examples: - -- Default value: 0, - -- Additive blend: 12641, - -- Substractive blend: 12548, - -- Invert blend: 12597, - -- See also "Particle blend". - animation = {Animation definition}, - -- ^ see above. Note, that particle and particle spawners have differences. - glow = 15, - -- ^ optional, specify particle self-luminescence in darkness. - values may vary from 0 (no glow) to 15 (bright glow). } ### `ParticleSpawner` definition (`add_particlespawner`) @@ -4320,20 +4151,6 @@ The Biome API is still in an experimental phase and subject to change. -- ^ Uses texture (string) playername = "singleplayer" -- ^ Playername is optional, if specified spawns particle only on the player's client - material_type_param = 12641, - -- ^ optional, if specified spawns particle with specified material type - -- param and disable z-buffer. - -- Some examples: - -- Default value: 0, - -- Additive blend: 12641, - -- Substractive blend: 12548, - -- Invert blend: 12597, - -- See also "Particle blend". - animation = {Animation definition}, - -- ^ see above. Note, that particle and particle spawners have differences. - glow = 15, - -- ^ optional, specify particle self-luminescence in darkness. - values may vary from 0 (no glow) to 15 (bright glow). } ### `HTTPRequest` definition (`HTTPApiTable.fetch_async`, `HTTPApiTable.fetch_async`) diff --git a/src/client.h b/src/client.h index c51daf7bc..9f5bda059 100644 --- a/src/client.h +++ b/src/client.h @@ -35,7 +35,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "hud.h" #include "particles.h" #include "network/networkpacket.h" -#include "nodedef.h" // AnimationType struct MeshMakeData; class MapBlockMesh; @@ -186,14 +185,6 @@ struct ClientEvent bool collision_removal; bool vertical; std::string *texture; - u32 material_type_param; - AnimationType animation_type; - u16 vertical_frame_num; - u16 horizontal_frame_num; - u16 first_frame; - float frame_length; - bool loop_animation; - u8 glow; } spawn_particle; struct{ u16 amount; @@ -214,15 +205,6 @@ struct ClientEvent bool vertical; std::string *texture; u32 id; - u32 material_type_param; - AnimationType animation_type; - u16 vertical_frame_num; - u16 horizontal_frame_num; - u16 min_first_frame; - u16 max_first_frame; - float frame_length; - bool loop_animation; - u8 glow; } add_particlespawner; struct{ u32 id; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 03baf078a..411982f69 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -896,46 +896,23 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt) std::string texture = deSerializeLongString(is); bool vertical = false; bool collision_removal = false; - u32 material_type_param = 0; - AnimationType animation_type = AT_NONE; - u16 vertical_frame_num = 1; - u16 horizontal_frame_num = 1; - u16 first_frame = 0; - float frame_length = -1; - bool loop_animation = true; - u8 glow = 0; try { vertical = readU8(is); collision_removal = readU8(is); - material_type_param = readU32(is); - animation_type = (AnimationType)readU8(is); - vertical_frame_num = readU16(is); - horizontal_frame_num = readU16(is); - first_frame = readU16(is); - frame_length = readF1000(is); - loop_animation = readU8(is); - glow = readU8(is); } catch (...) {} ClientEvent event; - event.type = CE_SPAWN_PARTICLE; - event.spawn_particle.pos = new v3f (pos); - event.spawn_particle.vel = new v3f (vel); - event.spawn_particle.acc = new v3f (acc); - event.spawn_particle.expirationtime = expirationtime; - event.spawn_particle.size = size; - event.spawn_particle.collisiondetection = collisiondetection; - event.spawn_particle.collision_removal = collision_removal; - event.spawn_particle.vertical = vertical; - event.spawn_particle.texture = new std::string(texture); - event.spawn_particle.material_type_param = material_type_param; - event.spawn_particle.animation_type = animation_type; - event.spawn_particle.vertical_frame_num = vertical_frame_num; - event.spawn_particle.horizontal_frame_num = horizontal_frame_num; - event.spawn_particle.first_frame = first_frame; - event.spawn_particle.frame_length = frame_length; - event.spawn_particle.loop_animation = loop_animation; - event.spawn_particle.glow = glow; + event.type = CE_SPAWN_PARTICLE; + event.spawn_particle.pos = new v3f (pos); + event.spawn_particle.vel = new v3f (vel); + event.spawn_particle.acc = new v3f (acc); + event.spawn_particle.expirationtime = expirationtime; + event.spawn_particle.size = size; + event.spawn_particle.collisiondetection = collisiondetection; + event.spawn_particle.collision_removal = collision_removal; + event.spawn_particle.vertical = vertical; + event.spawn_particle.texture = new std::string(texture); + m_client_event_queue.push(event); } @@ -955,15 +932,6 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) float maxsize; bool collisiondetection; u32 id; - u32 material_type_param = 0; - u8 animation_type = (u8)AT_NONE; - u16 vertical_frame_num = 1; - u16 horizontal_frame_num = 1; - u16 min_first_frame = 0; - u16 max_first_frame = 0; - float frame_length = -1; - bool loop_animation = true; - u8 glow = 0; *pkt >> amount >> spawntime >> minpos >> maxpos >> minvel >> maxvel >> minacc >> maxacc >> minexptime >> maxexptime >> minsize @@ -980,46 +948,29 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) *pkt >> vertical; *pkt >> collision_removal; *pkt >> attached_id; - *pkt >> material_type_param; - *pkt >> animation_type; - *pkt >> vertical_frame_num; - *pkt >> horizontal_frame_num; - *pkt >> min_first_frame; - *pkt >> max_first_frame; - *pkt >> frame_length; - *pkt >> loop_animation; - *pkt >> glow; + } catch (...) {} ClientEvent event; - event.type = CE_ADD_PARTICLESPAWNER; - event.add_particlespawner.amount = amount; - event.add_particlespawner.spawntime = spawntime; - event.add_particlespawner.minpos = new v3f (minpos); - event.add_particlespawner.maxpos = new v3f (maxpos); - event.add_particlespawner.minvel = new v3f (minvel); - event.add_particlespawner.maxvel = new v3f (maxvel); - event.add_particlespawner.minacc = new v3f (minacc); - event.add_particlespawner.maxacc = new v3f (maxacc); - event.add_particlespawner.minexptime = minexptime; - event.add_particlespawner.maxexptime = maxexptime; - event.add_particlespawner.minsize = minsize; - event.add_particlespawner.maxsize = maxsize; - event.add_particlespawner.collisiondetection = collisiondetection; - event.add_particlespawner.collision_removal = collision_removal; - event.add_particlespawner.attached_id = attached_id; - event.add_particlespawner.vertical = vertical; - event.add_particlespawner.texture = new std::string(texture); - event.add_particlespawner.id = id; - event.add_particlespawner.material_type_param = material_type_param; - event.add_particlespawner.animation_type = (AnimationType)animation_type; - event.add_particlespawner.vertical_frame_num = vertical_frame_num; - event.add_particlespawner.horizontal_frame_num = horizontal_frame_num; - event.add_particlespawner.min_first_frame = min_first_frame; - event.add_particlespawner.max_first_frame = max_first_frame; - event.add_particlespawner.frame_length = frame_length; - event.add_particlespawner.loop_animation = loop_animation; - event.add_particlespawner.glow = glow; + event.type = CE_ADD_PARTICLESPAWNER; + event.add_particlespawner.amount = amount; + event.add_particlespawner.spawntime = spawntime; + event.add_particlespawner.minpos = new v3f (minpos); + event.add_particlespawner.maxpos = new v3f (maxpos); + event.add_particlespawner.minvel = new v3f (minvel); + event.add_particlespawner.maxvel = new v3f (maxvel); + event.add_particlespawner.minacc = new v3f (minacc); + event.add_particlespawner.maxacc = new v3f (maxacc); + event.add_particlespawner.minexptime = minexptime; + event.add_particlespawner.maxexptime = maxexptime; + event.add_particlespawner.minsize = minsize; + event.add_particlespawner.maxsize = maxsize; + event.add_particlespawner.collisiondetection = collisiondetection; + event.add_particlespawner.collision_removal = collision_removal; + event.add_particlespawner.attached_id = attached_id; + event.add_particlespawner.vertical = vertical; + event.add_particlespawner.texture = new std::string(texture); + event.add_particlespawner.id = id; m_client_event_queue.push(event); } diff --git a/src/nodedef.cpp b/src/nodedef.cpp index c690e6720..39ea1a60e 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -211,7 +211,7 @@ void TileDef::deSerialize(std::istream &is, const u8 contenfeatures_version, con { int version = readU8(is); name = deSerializeString(is); - animation.type = (AnimationType)readU8(is); + animation.type = (TileAnimationType)readU8(is); animation.aspect_w = readU16(is); animation.aspect_h = readU16(is); animation.length = readF1000(is); @@ -531,7 +531,7 @@ void ContentFeatures::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, tile->material_flags = 0; if (backface_culling) tile->material_flags |= MATERIAL_FLAG_BACKFACE_CULLING; - if (tiledef->animation.type == AT_VERTICAL_FRAMES) + if (tiledef->animation.type == TAT_VERTICAL_FRAMES) tile->material_flags |= MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES; if (tiledef->tileable_horizontal) tile->material_flags |= MATERIAL_FLAG_TILEABLE_HORIZONTAL; diff --git a/src/nodedef.h b/src/nodedef.h index f47517c4a..80396f992 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -161,10 +161,9 @@ enum NodeDrawType /* Stand-alone definition of a TileSpec (basically a server-side TileSpec) */ -enum AnimationType{ - AT_NONE = 0, - AT_VERTICAL_FRAMES = 1, - AT_2D_ANIMATION_SHEET = 2, +enum TileAnimationType{ + TAT_NONE=0, + TAT_VERTICAL_FRAMES=1, }; struct TileDef { @@ -173,7 +172,7 @@ struct TileDef bool tileable_horizontal; bool tileable_vertical; struct{ - enum AnimationType type; + enum TileAnimationType type; int aspect_w; // width for aspect ratio int aspect_h; // height for aspect ratio float length; // seconds @@ -185,7 +184,7 @@ struct TileDef backface_culling = true; tileable_horizontal = true; tileable_vertical = true; - animation.type = AT_NONE; + animation.type = TAT_NONE; animation.aspect_w = 1; animation.aspect_h = 1; animation.length = 1.0; diff --git a/src/particles.cpp b/src/particles.cpp index 538487028..f20fb4083 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -43,22 +43,6 @@ v3f random_v3f(v3f min, v3f max) rand()/(float)RAND_MAX*(max.Z-min.Z)+min.Z); } -u32 check_material_type_param(u32 material_type_param) -{ - u32 alphaSource = (material_type_param & 0x0000F000) >> 12; - u32 modulo = (material_type_param & 0x00000F00) >> 8; - u32 srcFact = (material_type_param & 0x000000F0) >> 4; - u32 dstFact = material_type_param & 0x0000000F; - if (alphaSource <= 3 && modulo <= 4 && srcFact <= 10 && dstFact <= 10) { - return material_type_param; - } else { - errorstream << "Server send incorrect "; - errorstream << "material_type_param value for particle."; - errorstream << std::endl; - return 0; - } -} - Particle::Particle( IGameDef *gamedef, scene::ISceneManager* smgr, @@ -74,14 +58,7 @@ Particle::Particle( bool vertical, video::ITexture *texture, v2f texpos, - v2f texsize, - u32 material_type_param, - u16 vertical_frame_num, - u16 horizontal_frame_num, - u16 first_frame, - float frame_length, - bool loop_animation, - u8 glow + v2f texsize ): scene::ISceneNode(smgr->getRootSceneNode(), smgr) { @@ -94,26 +71,11 @@ Particle::Particle( m_material.setFlag(video::EMF_BACK_FACE_CULLING, false); m_material.setFlag(video::EMF_BILINEAR_FILTER, false); m_material.setFlag(video::EMF_FOG_ENABLE, true); - if (material_type_param != 0) { - m_material.MaterialType = video::EMT_ONETEXTURE_BLEND; - m_material.MaterialTypeParam = irr::core::FR(material_type_param); - // We must disable z-buffer if we want to avoid transparent pixels - // to overlap pixels with lower z-value. - m_material.setFlag(video::EMF_ZWRITE_ENABLE, false); - } else { - m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; - } + m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; m_material.setTexture(0, texture); - m_texpos = texpos; m_texsize = texsize; - m_vertical_frame_num = vertical_frame_num; - m_horizontal_frame_num = horizontal_frame_num; - m_first_frame = first_frame; - m_frame_length = frame_length; - m_loop_animation = loop_animation; - m_texsize.Y /= m_vertical_frame_num; - m_texsize.X /= m_horizontal_frame_num; + // Particle related m_pos = pos; @@ -126,7 +88,6 @@ Particle::Particle( m_collisiondetection = collisiondetection; m_collision_removal = collision_removal; m_vertical = vertical; - m_glow = glow; // Irrlicht stuff m_collisionbox = aabb3f @@ -209,29 +170,16 @@ void Particle::updateLight() else light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0); - m_light = decode_light(light + m_glow); + m_light = decode_light(light); } void Particle::updateVertices() { video::SColor c(255, m_light, m_light, m_light); - u16 frame = m_first_frame; - if (m_frame_length > 0) { - if (m_loop_animation) - frame = m_first_frame + (u32)(m_time / m_frame_length) - % (m_vertical_frame_num * - m_horizontal_frame_num - m_first_frame); - else if (m_time >= - (m_vertical_frame_num * m_horizontal_frame_num - - m_first_frame) * m_frame_length) - frame = m_vertical_frame_num * m_horizontal_frame_num - 1; - else - frame = m_first_frame + (u16)(m_time / m_frame_length); - } - f32 tx0 = m_texpos.X + m_texsize.X * (frame % m_horizontal_frame_num); - f32 tx1 = m_texpos.X + m_texsize.X * (frame % m_horizontal_frame_num + 1); - f32 ty0 = m_texpos.Y + m_texsize.Y * (frame / m_horizontal_frame_num); - f32 ty1 = m_texpos.Y + m_texsize.Y * (frame / m_horizontal_frame_num + 1); + f32 tx0 = m_texpos.X; + f32 tx1 = m_texpos.X + m_texsize.X; + f32 ty0 = m_texpos.Y; + f32 ty1 = m_texpos.Y + m_texsize.Y; m_vertices[0] = video::S3DVertex(-m_size/2,-m_size/2,0, 0,0,0, c, tx0, ty1); @@ -266,16 +214,7 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, u16 attached_id, bool vertical, - video::ITexture *texture, u32 id, - u32 material_type_param, - u16 vertical_frame_num, - u16 horizontal_frame_num, - u16 min_first_frame, - u16 max_first_frame, - float frame_length, - bool loop_animation, - u8 glow, - ParticleManager *p_manager) : + video::ITexture *texture, u32 id, ParticleManager *p_manager) : m_particlemanager(p_manager) { m_gamedef = gamedef; @@ -299,14 +238,6 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr, m_vertical = vertical; m_texture = texture; m_time = 0; - m_vertical_frame_num = vertical_frame_num; - m_horizontal_frame_num = horizontal_frame_num; - m_min_first_frame = min_first_frame; - m_max_first_frame = max_first_frame; - m_frame_length = frame_length; - m_loop_animation = loop_animation; - m_material_type_param = material_type_param; - m_glow = glow; for (u16 i = 0; i<=m_amount; i++) { @@ -320,6 +251,7 @@ ParticleSpawner::~ParticleSpawner() {} void ParticleSpawner::step(float dtime, ClientEnvironment* env) { m_time += dtime; + bool unloaded = false; v3f attached_offset = v3f(0,0,0); if (m_attached_id != 0) { @@ -353,10 +285,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) float size = rand()/(float)RAND_MAX *(m_maxsize-m_minsize) +m_minsize; - u16 first_frame = m_min_first_frame + - rand() % - (m_max_first_frame - - m_min_first_frame + 1); + Particle* toadd = new Particle( m_gamedef, m_smgr, @@ -372,14 +301,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) m_vertical, m_texture, v2f(0.0, 0.0), - v2f(1.0, 1.0), - m_material_type_param, - m_vertical_frame_num, - m_horizontal_frame_num, - first_frame, - m_frame_length, - m_loop_animation, - m_glow); + v2f(1.0, 1.0)); m_particlemanager->addParticle(toadd); } i = m_spawntimes.erase(i); @@ -409,10 +331,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) float size = rand()/(float)RAND_MAX *(m_maxsize-m_minsize) +m_minsize; - u16 first_frame = m_min_first_frame + - rand() % - (m_max_first_frame - - m_min_first_frame + 1); + Particle* toadd = new Particle( m_gamedef, m_smgr, @@ -428,14 +347,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env) m_vertical, m_texture, v2f(0.0, 0.0), - v2f(1.0, 1.0), - m_material_type_param, - m_vertical_frame_num, - m_horizontal_frame_num, - first_frame, - m_frame_length, - m_loop_animation, - m_glow); + v2f(1.0, 1.0)); m_particlemanager->addParticle(toadd); } } @@ -547,39 +459,6 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, video::ITexture *texture = gamedef->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture)); - float frame_length = -1; - u16 vertical_frame_num = 1; - u16 horizontal_frame_num = 1; - u32 material_type_param = - check_material_type_param(event->add_particlespawner.material_type_param); - - switch (event->add_particlespawner.animation_type) { - case AT_NONE: - break; - case AT_VERTICAL_FRAMES: { - v2u32 size = texture->getOriginalSize(); - int frame_height = (float)size.X / - (float)event->add_particlespawner.vertical_frame_num * - (float)event->add_particlespawner.horizontal_frame_num; - vertical_frame_num = size.Y / frame_height; - frame_length = - event->add_particlespawner.frame_length / - vertical_frame_num; - break; - } - case AT_2D_ANIMATION_SHEET: { - vertical_frame_num = - event->add_particlespawner.vertical_frame_num; - horizontal_frame_num = - event->add_particlespawner.horizontal_frame_num; - frame_length = - event->add_particlespawner.frame_length; - break; - } - default: - break; - } - ParticleSpawner* toadd = new ParticleSpawner(gamedef, smgr, player, event->add_particlespawner.amount, event->add_particlespawner.spawntime, @@ -599,14 +478,6 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, event->add_particlespawner.vertical, texture, event->add_particlespawner.id, - material_type_param, - vertical_frame_num, - horizontal_frame_num, - event->add_particlespawner.min_first_frame, - event->add_particlespawner.max_first_frame, - frame_length, - event->add_particlespawner.loop_animation, - event->add_particlespawner.glow, this); /* delete allocated content of event */ @@ -631,39 +502,6 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, video::ITexture *texture = gamedef->tsrc()->getTextureForMesh(*(event->spawn_particle.texture)); - float frame_length = -1; - u16 vertical_frame_num = 1; - u16 horizontal_frame_num = 1; - u32 material_type_param = - check_material_type_param(event->spawn_particle.material_type_param); - - switch (event->spawn_particle.animation_type) { - case AT_NONE: - break; - case AT_VERTICAL_FRAMES: { - v2u32 size = texture->getOriginalSize(); - int frame_height = (float)size.X / - (float)event->spawn_particle.vertical_frame_num * - (float)event->spawn_particle.horizontal_frame_num; - vertical_frame_num = size.Y / frame_height; - frame_length = - event->spawn_particle.frame_length / - vertical_frame_num; - break; - } - case AT_2D_ANIMATION_SHEET: { - vertical_frame_num = - event->spawn_particle.vertical_frame_num; - horizontal_frame_num = - event->spawn_particle.horizontal_frame_num; - frame_length = - event->spawn_particle.frame_length; - break; - } - default: - break; - } - Particle* toadd = new Particle(gamedef, smgr, player, m_env, *event->spawn_particle.pos, *event->spawn_particle.vel, @@ -675,21 +513,13 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef, event->spawn_particle.vertical, texture, v2f(0.0, 0.0), - v2f(1.0, 1.0), - material_type_param, - vertical_frame_num, - horizontal_frame_num, - event->spawn_particle.first_frame, - frame_length, - event->spawn_particle.loop_animation, - event->spawn_particle.glow); + v2f(1.0, 1.0)); addParticle(toadd); delete event->spawn_particle.pos; delete event->spawn_particle.vel; delete event->spawn_particle.acc; - delete event->spawn_particle.texture; break; } @@ -758,8 +588,7 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* s false, texture, texpos, - texsize, - 0, 1, 1, 0, -1, true, 0); + texsize); addParticle(toadd); } diff --git a/src/particles.h b/src/particles.h index 6d8c6139f..eb8c6665d 100644 --- a/src/particles.h +++ b/src/particles.h @@ -50,14 +50,7 @@ class Particle : public scene::ISceneNode bool vertical, video::ITexture *texture, v2f texpos, - v2f texsize, - u32 material_type_param, - u16 vertical_frame_num, - u16 horizontal_frame_num, - u16 first_frame, - float frame_length, - bool loop_animation, - u8 glow + v2f texsize ); ~Particle(); @@ -109,12 +102,6 @@ private: bool m_collision_removal; bool m_vertical; v3s16 m_camera_offset; - u16 m_vertical_frame_num; - u16 m_horizontal_frame_num; - u16 m_first_frame; - float m_frame_length; - bool m_loop_animation; - u8 m_glow; }; class ParticleSpawner @@ -136,15 +123,8 @@ class ParticleSpawner bool vertical, video::ITexture *texture, u32 id, - u32 material_type_param, - u16 vertical_frame_num, - u16 horizontal_frame_num, - u16 min_first_frame, - u16 max_first_frame, - float frame_length, - bool loop_animation, - u8 glow, ParticleManager* p_manager); + ~ParticleSpawner(); void step(float dtime, ClientEnvironment *env); @@ -176,14 +156,6 @@ class ParticleSpawner bool m_collision_removal; bool m_vertical; u16 m_attached_id; - u32 m_material_type_param; - u16 m_vertical_frame_num; - u16 m_horizontal_frame_num; - u16 m_min_first_frame; - u16 m_max_first_frame; - float m_frame_length; - bool m_loop_animation; - u8 m_glow; }; /** diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index d4a25b68b..f20a65903 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -35,11 +35,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "noise.h" #include -struct EnumString es_AnimationType[] = +struct EnumString es_TileAnimationType[] = { - {AT_NONE, "none"}, - {AT_VERTICAL_FRAMES, "vertical_frames"}, - {AT_2D_ANIMATION_SHEET, "2d_animation_sheet"}, + {TAT_NONE, "none"}, + {TAT_VERTICAL_FRAMES, "vertical_frames"}, {0, NULL}, }; @@ -336,9 +335,9 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype) lua_getfield(L, index, "animation"); if(lua_istable(L, -1)){ // {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0} - tiledef.animation.type = (AnimationType) - getenumfield(L, -1, "type", es_AnimationType, - AT_NONE); + tiledef.animation.type = (TileAnimationType) + getenumfield(L, -1, "type", es_TileAnimationType, + TAT_NONE); tiledef.animation.aspect_w = getintfield_default(L, -1, "aspect_w", 16); tiledef.animation.aspect_h = diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 32fdb4f04..2a2228b6d 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -159,6 +159,6 @@ bool push_json_value (lua_State *L, void read_json_value (lua_State *L, Json::Value &root, int index, u8 recursion = 0); -extern struct EnumString es_AnimationType[]; +extern struct EnumString es_TileAnimationType[]; #endif /* C_CONTENT_H_ */ diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index cfb5e26db..f36298915 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -513,28 +513,6 @@ int getintfield_default(lua_State *L, int table, return result; } -int check_material_type_param(lua_State *L, int table, - const char *fieldname, int default_) -{ - int material_type_param = - getintfield_default(L, table, fieldname, default_); - u32 alphaSource = (material_type_param & 0x0000F000) >> 12; - u32 modulo = (material_type_param & 0x00000F00) >> 8; - u32 srcFact = (material_type_param & 0x000000F0) >> 4; - u32 dstFact = material_type_param & 0x0000000F; - if (alphaSource <= 3 && modulo <= 4 && srcFact <= 10 && dstFact <= 10) { - return material_type_param; - } else { - std::ostringstream error_text; - error_text << "Incorrect material_type_param value "; - error_text << "for particle or particle spawner."; - error_text << std::endl; - throw LuaError(error_text.str()); - return 0; - } -} - - float getfloatfield_default(lua_State *L, int table, const char *fieldname, float default_) { diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 71ac735c1..a5fbee765 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -45,8 +45,6 @@ float getfloatfield_default(lua_State *L, int table, const char *fieldname, float default_); int getintfield_default (lua_State *L, int table, const char *fieldname, int default_); -int check_material_type_param(lua_State *L, int table, - const char *fieldname, int default_); bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result); diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index b0a57ce6d..667ac7272 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_object.h" #include "lua_api/l_internal.h" #include "common/c_converter.h" -#include "common/c_content.h" #include "server.h" #include "particles.h" @@ -35,9 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc., // collision_removal = bool // vertical = bool // texture = e.g."default_wood.png" -// material_type_param = num -// animation = animation definition -// glow = indexed color or color string int ModApiParticles::l_add_particle(lua_State *L) { MAP_LOCK_REQUIRED; @@ -48,24 +44,13 @@ int ModApiParticles::l_add_particle(lua_State *L) float expirationtime, size; expirationtime = size = 1; - float frame_or_loop_length = -1; - - AnimationType animation_type = AT_NONE; - - u16 vertical_frame_num_or_aspect = 1; - u16 horizontal_frame_num_or_aspect = 1; - u16 first_frame = 0; bool collisiondetection, vertical, collision_removal; collisiondetection = vertical = collision_removal = false; - bool loop_animation = true; std::string texture = ""; std::string playername = ""; - u32 material_type_param = 0; - u8 glow = 0; - if (lua_gettop(L) > 1) // deprecated { log_deprecated(L, "Deprecated add_particle call with individual parameters instead of definition"); @@ -109,61 +94,8 @@ int ModApiParticles::l_add_particle(lua_State *L) acc = lua_istable(L, -1) ? check_v3f(L, -1) : acc; lua_pop(L, 1); - expirationtime = getfloatfield_default(L, 1, "expirationtime", 1); + expirationtime = getfloatfield_default(L, 1, "expirationtime", 1); size = getfloatfield_default(L, 1, "size", 1); - - lua_getfield(L, 1, "animation"); - if (lua_istable(L, -1)) { - animation_type = (AnimationType) - getenumfield(L, -1, "type", es_AnimationType, - AT_NONE); - } - switch (animation_type) { - case AT_NONE: - break; - case AT_2D_ANIMATION_SHEET: - frame_or_loop_length = - getfloatfield_default(L, -1, "frame_length", -1); - vertical_frame_num_or_aspect = - getintfield_default(L, -1, "vertical_frame_num", 1); - horizontal_frame_num_or_aspect = - getintfield_default(L, -1, "horizontal_frame_num", 1); - first_frame = - getintfield_default(L, -1, "first_frame", 0); - loop_animation = - getboolfield_default(L, -1, "loop_animation", true); - break; - case AT_VERTICAL_FRAMES: - frame_or_loop_length = - getfloatfield_default(L, -1, "length", -1); - vertical_frame_num_or_aspect = - getintfield_default(L, -1, "aspect_w", 1); - horizontal_frame_num_or_aspect = - getintfield_default(L, -1, "aspect_h", 1); - first_frame = - getintfield_default(L, -1, "first_frame", 0); - loop_animation = - getboolfield_default(L, -1, "loop_animation", true); - break; - default: - break; - } - lua_pop(L, 1); - - if (animation_type == AT_2D_ANIMATION_SHEET && - first_frame >= vertical_frame_num_or_aspect * - horizontal_frame_num_or_aspect) { - std::ostringstream error_text; - error_text << "first_frame should be lower, than " - << "vertical_frame_num * horizontal_frame_num. " - << "Got first_frame=" << first_frame - << ", vertical_frame_num=" - << vertical_frame_num_or_aspect - << " and horizontal_frame_num=" - << horizontal_frame_num_or_aspect << std::endl; - throw LuaError(error_text.str()); - } - collisiondetection = getboolfield_default(L, 1, "collisiondetection", collisiondetection); collision_removal = getboolfield_default(L, 1, @@ -171,16 +103,9 @@ int ModApiParticles::l_add_particle(lua_State *L) vertical = getboolfield_default(L, 1, "vertical", vertical); texture = getstringfield_default(L, 1, "texture", ""); playername = getstringfield_default(L, 1, "playername", ""); - material_type_param = check_material_type_param(L, 1, "material_type_param", 0); - glow = getintfield_default (L, 1, "glow", 0); } - getServer(L)->spawnParticle(playername, pos, vel, acc, expirationtime, - size, collisiondetection, collision_removal, vertical, - texture, material_type_param, - animation_type, - vertical_frame_num_or_aspect, - horizontal_frame_num_or_aspect, - first_frame, frame_or_loop_length, loop_animation, glow); + getServer(L)->spawnParticle(playername, pos, vel, acc, expirationtime, size, + collisiondetection, collision_removal, vertical, texture); return 1; } @@ -202,33 +127,21 @@ int ModApiParticles::l_add_particle(lua_State *L) // collision_removal = bool // vertical = bool // texture = e.g."default_wood.png" -// material_type_param = num -// animation = animation definition -// glow = indexed color or color string int ModApiParticles::l_add_particlespawner(lua_State *L) { MAP_LOCK_REQUIRED; // Get parameters u16 amount = 1; - u16 vertical_frame_num_or_aspect = 1; - u16 horizontal_frame_num_or_aspect = 1; - u16 min_first_frame = 0; - u16 max_first_frame = 0; v3f minpos, maxpos, minvel, maxvel, minacc, maxacc; minpos= maxpos= minvel= maxvel= minacc= maxacc= v3f(0, 0, 0); float time, minexptime, maxexptime, minsize, maxsize; time= minexptime= maxexptime= minsize= maxsize= 1; - AnimationType animation_type = AT_NONE; - float frame_or_loop_length = -1; bool collisiondetection, vertical, collision_removal; collisiondetection = vertical = collision_removal = false; - bool loop_animation = true; ServerActiveObject *attached = NULL; std::string texture = ""; std::string playername = ""; - u32 material_type_param = 0; - u8 glow = 0; if (lua_gettop(L) > 1) //deprecated { @@ -283,65 +196,6 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) maxexptime = getfloatfield_default(L, 1, "maxexptime", maxexptime); minsize = getfloatfield_default(L, 1, "minsize", minsize); maxsize = getfloatfield_default(L, 1, "maxsize", maxsize); - - - lua_getfield(L, 1, "animation"); - if (lua_istable(L, -1)) { - animation_type = (AnimationType) - getenumfield(L, -1, "type", es_AnimationType, - AT_NONE); - } - switch (animation_type) { - case AT_NONE: - break; - case AT_2D_ANIMATION_SHEET: - frame_or_loop_length = - getfloatfield_default(L, -1, "frame_length", -1); - vertical_frame_num_or_aspect = - getintfield_default(L, -1, "vertical_frame_num", 1); - horizontal_frame_num_or_aspect = - getintfield_default(L, -1, "horizontal_frame_num", 1); - min_first_frame = - getintfield_default(L, -1, "min_first_frame", 0); - max_first_frame = - getintfield_default(L, -1, "max_first_frame", 0); - loop_animation = - getboolfield_default(L, -1, "loop_animation", true); - break; - case AT_VERTICAL_FRAMES: - frame_or_loop_length = - getfloatfield_default(L, -1, "length", -1); - vertical_frame_num_or_aspect = - getintfield_default(L, -1, "aspect_w", 1); - horizontal_frame_num_or_aspect = - getintfield_default(L, -1, "aspect_h", 1); - min_first_frame = - getintfield_default(L, -1, "min_first_frame", 0); - max_first_frame = - getintfield_default(L, -1, "max_first_frame", 0); - loop_animation = - getboolfield_default(L, -1, "loop_animation", true); - break; - default: - break; - } - lua_pop(L, 1); - - if (animation_type == AT_2D_ANIMATION_SHEET && - max_first_frame >= vertical_frame_num_or_aspect * - horizontal_frame_num_or_aspect) { - std::ostringstream error_text; - error_text << "max_first_frame should be lower, than " - << "vertical_frame_num * horizontal_frame_num. " - << "Got max_first_frame=" - << max_first_frame - << ", vertical_frame_num=" - << vertical_frame_num_or_aspect - << " and horizontal_frame_num=" - << horizontal_frame_num_or_aspect << std::endl; - throw LuaError(error_text.str()); - } - collisiondetection = getboolfield_default(L, 1, "collisiondetection", collisiondetection); collision_removal = getboolfield_default(L, 1, @@ -357,8 +211,6 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) vertical = getboolfield_default(L, 1, "vertical", vertical); texture = getstringfield_default(L, 1, "texture", ""); playername = getstringfield_default(L, 1, "playername", ""); - material_type_param = check_material_type_param(L, 1, "material_type_param", 0); - glow = getintfield_default(L, 1, "glow", 0); } u32 id = getServer(L)->addParticleSpawner(amount, time, @@ -371,17 +223,9 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) collision_removal, attached, vertical, - texture, - playername, - material_type_param, - animation_type, - vertical_frame_num_or_aspect, - horizontal_frame_num_or_aspect, - min_first_frame, max_first_frame, - frame_or_loop_length, - loop_animation, - glow); + texture, playername); lua_pushnumber(L, id); + return 1; } diff --git a/src/server.cpp b/src/server.cpp index cef57be88..48331e4f8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1658,11 +1658,7 @@ void Server::SendShowFormspecMessage(u16 peer_id, const std::string &formspec, void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture, - u32 material_type_param, AnimationType animation_type, - u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, - float frame_length, bool loop_animation, - u8 glow) + bool vertical, const std::string &texture) { DSTACK(FUNCTION_NAME); @@ -1674,12 +1670,6 @@ void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f accelerat pkt << vertical; pkt << collision_removal; - pkt << material_type_param - << (u8)animation_type - << vertical_frame_num - << horizontal_frame_num << first_frame - << frame_length << loop_animation << glow; - if (peer_id != PEER_ID_INEXISTENT) { Send(&pkt); } @@ -1692,10 +1682,7 @@ void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f accelerat void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, - u16 attached_id, bool vertical, const std::string &texture, u32 id, - u32 material_type_param, AnimationType animation_type, u16 vertical_frame_num, u16 horizontal_frame_num, - u16 min_first_frame, u16 max_first_frame, float frame_length, - bool loop_animation, u8 glow) + u16 attached_id, bool vertical, const std::string &texture, u32 id) { DSTACK(FUNCTION_NAME); @@ -1711,12 +1698,6 @@ void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3 pkt << collision_removal; pkt << attached_id; - pkt << material_type_param - << (u8)animation_type - << vertical_frame_num << horizontal_frame_num - << min_first_frame << max_first_frame - << frame_length << loop_animation << glow; - if (peer_id != PEER_ID_INEXISTENT) { Send(&pkt); } @@ -3166,11 +3147,7 @@ void Server::spawnParticle(const std::string &playername, v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture, - u32 material_type_param, AnimationType animation_type, - u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, - float frame_length, bool loop_animation, - u8 glow) + bool vertical, const std::string &texture) { // m_env will be NULL if the server is initializing if (!m_env) @@ -3186,11 +3163,7 @@ void Server::spawnParticle(const std::string &playername, v3f pos, SendSpawnParticle(peer_id, pos, velocity, acceleration, expirationtime, size, collisiondetection, - collision_removal, vertical, texture, - material_type_param, animation_type, - vertical_frame_num, horizontal_frame_num, - first_frame, frame_length, loop_animation, - glow); + collision_removal, vertical, texture); } u32 Server::addParticleSpawner(u16 amount, float spawntime, @@ -3198,9 +3171,7 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, float minexptime, float maxexptime, float minsize, float maxsize, bool collisiondetection, bool collision_removal, ServerActiveObject *attached, bool vertical, const std::string &texture, - const std::string &playername, u32 material_type_param, AnimationType animation_type, - u16 vertical_frame_num, u16 horizontal_frame_num, u16 min_first_frame, u16 max_first_frame, - float frame_length, bool loop_animation, u8 glow) + const std::string &playername) { // m_env will be NULL if the server is initializing if (!m_env) @@ -3226,10 +3197,7 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, minpos, maxpos, minvel, maxvel, minacc, maxacc, minexptime, maxexptime, minsize, maxsize, collisiondetection, collision_removal, attached_id, vertical, - texture, id, material_type_param, animation_type, - vertical_frame_num, horizontal_frame_num, - min_first_frame, max_first_frame, frame_length, loop_animation, - glow); + texture, id); return id; } diff --git a/src/server.h b/src/server.h index 9a8d22b2e..9e844e36c 100644 --- a/src/server.h +++ b/src/server.h @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "hud.h" #include "gamedef.h" #include "serialization.h" // For SER_FMT_VER_INVALID -#include "nodedef.h" // AnimationType #include "mods.h" #include "inventorymanager.h" #include "subgame.h" @@ -255,11 +254,7 @@ public: v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture, - u32 material_type_param, AnimationType animation_type, - u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, - float frame_length, bool loop_animation, - u8 glow); + bool vertical, const std::string &texture); u32 addParticleSpawner(u16 amount, float spawntime, v3f minpos, v3f maxpos, @@ -270,12 +265,7 @@ public: bool collisiondetection, bool collision_removal, ServerActiveObject *attached, bool vertical, const std::string &texture, - const std::string &playername, - u32 material_type_param, AnimationType animation_type, - u16 vertical_frame_num, u16 horizontal_frame_num, - u16 min_first_frame, u16 max_first_frame, - float frame_length, bool loop_animation, - u8 glow); + const std::string &playername); void deleteParticleSpawner(const std::string &playername, u32 id); @@ -451,12 +441,7 @@ private: float minsize, float maxsize, bool collisiondetection, bool collision_removal, u16 attached_id, - bool vertical, const std::string &texture, u32 id, - u32 material_type_param, AnimationType animation_type, - u16 vertical_frame_num, u16 horizontal_frame_num, - u16 min_first_frame, u16 max_first_frame, - float frame_length, bool loop_animation, - u8 glow); + bool vertical, const std::string &texture, u32 id); void SendDeleteParticleSpawner(u16 peer_id, u32 id); @@ -465,11 +450,7 @@ private: v3f pos, v3f velocity, v3f acceleration, float expirationtime, float size, bool collisiondetection, bool collision_removal, - bool vertical, const std::string &texture, - u32 material_type_param, AnimationType animation_type, - u16 vertical_frame_num, u16 horizontal_frame_num, u16 first_frame, - float frame_length, bool loop_animation, - u8 glow); + bool vertical, const std::string &texture); u32 SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas); void SendActiveObjectMessages(u16 peer_id, const std::string &datas, bool reliable = true); -- cgit v1.2.3