From 4503b5097f99d2806763650f33d8ef3b49f77ce4 Mon Sep 17 00:00:00 2001 From: Rogier-5 Date: Wed, 10 Aug 2016 12:10:00 +0200 Subject: Fixes for compiling with a newer (system) jsoncpp (#4429) * Move included json code to jsoncpp subdirectory This is needed to avoid having to specify the minetest src directory as a system include when fixing the json includes. * Fix json includes They used "", so that the compiler searches the project's directory first. The result was that when compiling with a system jsoncpp, the project's own version of json.h was still included, instead of the system version. The includes now use <>, so a system location, or one specified with '-Ilocation' is searched only. * Fix for jsoncpp deprecated function warning When compiling with a newer version of jsoncpp (and ENABLE_SYSTEM_JSONCPP=true), jsoncpp emits a warning about a deprecated function that minetest uses. --- src/script/common/c_content.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/script/common') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 06e20c2a0..c664101ea 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "porting.h" #include "mg_schematic.h" #include "noise.h" -#include "json/json.h" +#include struct EnumString es_TileAnimationType[] = { @@ -1250,8 +1250,13 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value, lua_newtable(L); for (Json::Value::const_iterator it = value.begin(); it != value.end(); ++it) { +#ifndef JSONCPP_STRING const char *str = it.memberName(); lua_pushstring(L, str ? str : ""); +#else + std::string str = it.name(); + lua_pushstring(L, str.c_str()); +#endif push_json_value_helper(L, *it, nullindex); lua_rawset(L, -3); } -- cgit v1.2.3 From c013c73f338b1c2227662458ebc650883f83271c Mon Sep 17 00:00:00 2001 From: Tomas Date: Wed, 10 Aug 2016 12:17:48 +0200 Subject: Lua->C getintfield() use lua_tointeger (#4408) previously function used tonumber which returned float this caused errors in large numbers and resulted in obj-def-handlers being invalid when retrived from lua tables in c --- src/script/common/c_converter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/script/common') diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 55c4a5f5a..857300fa5 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -391,7 +391,7 @@ bool getintfield(lua_State *L, int table, lua_getfield(L, table, fieldname); bool got = false; if(lua_isnumber(L, -1)){ - result = lua_tonumber(L, -1); + result = lua_tointeger(L, -1); got = true; } lua_pop(L, 1); @@ -404,7 +404,7 @@ bool getintfield(lua_State *L, int table, lua_getfield(L, table, fieldname); bool got = false; if(lua_isnumber(L, -1)){ - result = lua_tonumber(L, -1); + result = lua_tointeger(L, -1); got = true; } lua_pop(L, 1); @@ -417,7 +417,7 @@ bool getintfield(lua_State *L, int table, lua_getfield(L, table, fieldname); bool got = false; if(lua_isnumber(L, -1)){ - result = lua_tonumber(L, -1); + result = lua_tointeger(L, -1); got = true; } lua_pop(L, 1); @@ -430,7 +430,7 @@ bool getintfield(lua_State *L, int table, lua_getfield(L, table, fieldname); bool got = false; if(lua_isnumber(L, -1)){ - result = lua_tonumber(L, -1); + result = lua_tointeger(L, -1); got = true; } lua_pop(L, 1); -- cgit v1.2.3 From 2de8c22a9971153d594b2bb4736eb293753f1212 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Tue, 6 Sep 2016 19:13:52 +0200 Subject: Make getStackMax return the correct maximal stack size --- src/inventory.h | 5 ++--- src/itemdef.h | 2 +- src/script/common/c_content.cpp | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src/script/common') diff --git a/src/inventory.h b/src/inventory.h index a690eb5ae..7d7e58d61 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -80,15 +80,14 @@ struct ItemStack // Maximum size of a stack u16 getStackMax(IItemDefManager *itemdef) const { - s16 max = itemdef->get(name).stack_max; - return (max >= 0) ? max : 0; + return itemdef->get(name).stack_max; } // Number of items that can be added to this stack u16 freeSpace(IItemDefManager *itemdef) const { u16 max = getStackMax(itemdef); - if(count > max) + if (count >= max) return 0; return max - count; } diff --git a/src/itemdef.h b/src/itemdef.h index b14ed41f7..dcb98e8a9 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -61,7 +61,7 @@ struct ItemDefinition /* Item stack and interaction properties */ - s16 stack_max; + u16 stack_max; bool usable; bool liquids_pointable; // May be NULL. If non-NULL, deleted by destructor diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index c664101ea..19873abc5 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -65,9 +65,8 @@ ItemDefinition read_item_definition(lua_State* L,int index, } lua_pop(L, 1); - def.stack_max = getintfield_default(L, index, "stack_max", def.stack_max); - if(def.stack_max == 0) - def.stack_max = 1; + int stack_max = getintfield_default(L, index, "stack_max", def.stack_max); + def.stack_max = rangelim(stack_max, 1, U16_MAX); lua_getfield(L, index, "on_use"); def.usable = lua_isfunction(L, -1); -- cgit v1.2.3 From 5f084cd98d7b3326b51320455364337539710efd Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 5 Oct 2016 00:13:10 +0200 Subject: Make some maps unordered to improve performance * This permit to improve performance on C++11 builds * use some existing typedefs in tools maps * minor code style changes --- src/script/common/c_content.cpp | 18 ++++++++---------- src/settings.h | 4 ++-- src/sound_openal.cpp | 26 +++++++++++--------------- src/tool.cpp | 23 +++++++++++------------ src/tool.h | 15 ++++++--------- 5 files changed, 38 insertions(+), 48 deletions(-) (limited to 'src/script/common') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 19873abc5..6fb9080bc 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -829,20 +829,18 @@ void push_tool_capabilities(lua_State *L, // Create groupcaps table lua_newtable(L); // For each groupcap - for(std::map::const_iterator - i = toolcap.groupcaps.begin(); i != toolcap.groupcaps.end(); i++){ + for (ToolGCMap::const_iterator i = toolcap.groupcaps.begin(); + i != toolcap.groupcaps.end(); i++) { // Create groupcap table lua_newtable(L); const std::string &name = i->first; const ToolGroupCap &groupcap = i->second; // Create subtable "times" lua_newtable(L); - for(std::map::const_iterator - i = groupcap.times.begin(); i != groupcap.times.end(); i++){ - int rating = i->first; - float time = i->second; - lua_pushinteger(L, rating); - lua_pushnumber(L, time); + for (UNORDERED_MAP::const_iterator + i = groupcap.times.begin(); i != groupcap.times.end(); i++) { + lua_pushinteger(L, i->first); + lua_pushnumber(L, i->second); lua_settable(L, -3); } // Set subtable "times" @@ -858,8 +856,8 @@ void push_tool_capabilities(lua_State *L, //Create damage_groups table lua_newtable(L); // For each damage group - for(std::map::const_iterator - i = toolcap.damageGroups.begin(); i != toolcap.damageGroups.end(); i++){ + for (DamageGroup::const_iterator i = toolcap.damageGroups.begin(); + i != toolcap.damageGroups.end(); i++) { // Create damage group table lua_pushinteger(L, i->second); lua_setfield(L, -2, i->first.c_str()); diff --git a/src/settings.h b/src/settings.h index 0af861a58..c6c044779 100644 --- a/src/settings.h +++ b/src/settings.h @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "threading/mutex.h" #include -#include +#include "util/cpp11_container.h" #include #include @@ -45,7 +45,7 @@ typedef std::vector< > > SettingsCallbackList; -typedef std::map SettingsCallbackMap; +typedef UNORDERED_MAP SettingsCallbackMap; enum ValueType { VALUETYPE_STRING, diff --git a/src/sound_openal.cpp b/src/sound_openal.cpp index 1832a0c77..317667f52 100644 --- a/src/sound_openal.cpp +++ b/src/sound_openal.cpp @@ -41,9 +41,9 @@ with this program; ifnot, write to the Free Software Foundation, Inc., #include "log.h" #include "util/numeric.h" // myrand() #include "porting.h" -#include #include #include +#include "util/cpp11_container.h" #define BUFFER_SIZE 30000 @@ -271,8 +271,8 @@ private: ALCdevice *m_device; ALCcontext *m_context; int m_next_id; - std::map > m_buffers; - std::map m_sounds_playing; + UNORDERED_MAP > m_buffers; + UNORDERED_MAP m_sounds_playing; v3f m_listener_pos; public: bool m_is_initialized; @@ -337,7 +337,7 @@ public: alcCloseDevice(m_device); m_device = NULL; - for (std::map >::iterator i = m_buffers.begin(); + for (UNORDERED_MAP >::iterator i = m_buffers.begin(); i != m_buffers.end(); ++i) { for (std::vector::iterator iter = (*i).second.begin(); iter != (*i).second.end(); ++iter) { @@ -351,7 +351,7 @@ public: void addBuffer(const std::string &name, SoundBuffer *buf) { - std::map >::iterator i = + UNORDERED_MAP >::iterator i = m_buffers.find(name); if(i != m_buffers.end()){ i->second.push_back(buf); @@ -365,7 +365,7 @@ public: SoundBuffer* getBuffer(const std::string &name) { - std::map >::iterator i = + UNORDERED_MAP >::iterator i = m_buffers.find(name); if(i == m_buffers.end()) return NULL; @@ -443,8 +443,7 @@ public: void deleteSound(int id) { - std::map::iterator i = - m_sounds_playing.find(id); + UNORDERED_MAP::iterator i = m_sounds_playing.find(id); if(i == m_sounds_playing.end()) return; PlayingSound *sound = i->second; @@ -484,10 +483,8 @@ public: < del_list; - for(std::map::iterator - i = m_sounds_playing.begin(); - i != m_sounds_playing.end(); ++i) - { + for(UNORDERED_MAP::iterator i = m_sounds_playing.begin(); + i != m_sounds_playing.end(); ++i) { int id = i->first; PlayingSound *sound = i->second; // If not playing, remove it @@ -583,9 +580,8 @@ public: } void updateSoundPosition(int id, v3f pos) { - std::map::iterator i = - m_sounds_playing.find(id); - if(i == m_sounds_playing.end()) + UNORDERED_MAP::iterator i = m_sounds_playing.find(id); + if (i == m_sounds_playing.end()) return; PlayingSound *sound = i->second; diff --git a/src/tool.cpp b/src/tool.cpp index 54b9f15f4..20b71fb31 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -34,24 +34,23 @@ void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const writeF1000(os, full_punch_interval); writeS16(os, max_drop_level); writeU32(os, groupcaps.size()); - for(std::map::const_iterator - i = groupcaps.begin(); i != groupcaps.end(); ++i){ + for (ToolGCMap::const_iterator i = groupcaps.begin(); i != groupcaps.end(); ++i) { const std::string *name = &i->first; const ToolGroupCap *cap = &i->second; os<uses); writeS16(os, cap->maxlevel); writeU32(os, cap->times.size()); - for(std::map::const_iterator - i = cap->times.begin(); i != cap->times.end(); ++i){ + for (UNORDERED_MAP::const_iterator + i = cap->times.begin(); i != cap->times.end(); ++i) { writeS16(os, i->first); writeF1000(os, i->second); } } if(protocol_version > 17){ writeU32(os, damageGroups.size()); - for(std::map::const_iterator - i = damageGroups.begin(); i != damageGroups.end(); ++i){ + for (DamageGroup::const_iterator i = damageGroups.begin(); + i != damageGroups.end(); ++i) { os<first); writeS16(os, i->second); } @@ -106,7 +105,7 @@ DigParams getDigParams(const ItemGroupList &groups, default: break; } - + // Values to be returned (with a bit of conversion) bool result_diggable = false; float result_time = 0.0; @@ -115,8 +114,8 @@ DigParams getDigParams(const ItemGroupList &groups, int level = itemgroup_get(groups, "level"); //infostream<<"level="<::const_iterator - i = tp->groupcaps.begin(); i != tp->groupcaps.end(); ++i){ + for (ToolGCMap::const_iterator i = tp->groupcaps.begin(); + i != tp->groupcaps.end(); ++i) { const std::string &name = i->first; //infostream<<"group="<second; @@ -163,8 +162,8 @@ HitParams getHitParams(const ItemGroupList &armor_groups, s16 damage = 0; float full_punch_interval = tp->full_punch_interval; - for(std::map::const_iterator - i = tp->damageGroups.begin(); i != tp->damageGroups.end(); ++i){ + for (DamageGroup::const_iterator i = tp->damageGroups.begin(); + i != tp->damageGroups.end(); ++i) { s16 armor = itemgroup_get(armor_groups, i->first); damage += i->second * rangelim(time_from_last_punch / full_punch_interval, 0.0, 1.0) * armor / 100.0; @@ -197,7 +196,7 @@ PunchDamageResult getPunchDamage( do_hit = false; } } - + PunchDamageResult result; if(do_hit) { diff --git a/src/tool.h b/src/tool.h index 509561a16..ebba5b749 100644 --- a/src/tool.h +++ b/src/tool.h @@ -23,12 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes.h" #include #include -#include +#include "util/cpp11_container.h" #include "itemgroup.h" struct ToolGroupCap { - std::map times; + UNORDERED_MAP times; int maxlevel; int uses; @@ -39,8 +39,8 @@ struct ToolGroupCap bool getTime(int rating, float *time) const { - std::map::const_iterator i = times.find(rating); - if(i == times.end()){ + UNORDERED_MAP::const_iterator i = times.find(rating); + if (i == times.end()) { *time = 0; return false; } @@ -50,22 +50,19 @@ struct ToolGroupCap }; -// CLANG SUCKS DONKEY BALLS -typedef std::map ToolGCMap; -typedef std::map DamageGroup; +typedef UNORDERED_MAP ToolGCMap; +typedef UNORDERED_MAP DamageGroup; struct ToolCapabilities { float full_punch_interval; int max_drop_level; - // CLANG SUCKS DONKEY BALLS ToolGCMap groupcaps; DamageGroup damageGroups; ToolCapabilities( float full_punch_interval_=1.4, int max_drop_level_=1, - // CLANG SUCKS DONKEY BALLS ToolGCMap groupcaps_=ToolGCMap(), DamageGroup damageGroups_=DamageGroup() ): -- cgit v1.2.3 From 613797a3048907275ceebe29582b9fc2761b1f25 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 5 Oct 2016 09:03:55 +0200 Subject: Replace various std::map with UNORDERED_MAP + various cleanups This is part 2 for 5f084cd98d7b3326b51320455364337539710efd Other improvements: * Use the defined ItemGroupList when used * make Client::checkPrivilege const * inline some trivial functions * Add ActiveObjectMap typedef * Add SettingsEntries typedef --- src/client.cpp | 4 +-- src/client.h | 6 ++--- src/clientiface.cpp | 55 ++++++++++++++----------------------- src/clientiface.h | 7 +++-- src/content_cao.cpp | 6 ++--- src/content_cao.h | 2 +- src/emerge.cpp | 6 ++--- src/emerge.h | 2 +- src/environment.cpp | 60 ++++++++++++++--------------------------- src/environment.h | 8 +++--- src/game.cpp | 9 +++---- src/itemdef.cpp | 4 +-- src/itemgroup.h | 6 ++--- src/mapsector.cpp | 28 +++++-------------- src/mapsector.h | 4 +-- src/mg_schematic.cpp | 4 +-- src/script/common/c_content.cpp | 8 +++--- src/script/common/c_content.h | 6 ++--- src/script/common/c_converter.h | 4 +-- src/script/lua_api/l_util.cpp | 4 +-- src/server.cpp | 12 ++++----- src/settings.cpp | 26 +++++++++--------- src/settings.h | 6 +++-- 23 files changed, 110 insertions(+), 167 deletions(-) (limited to 'src/script/common') diff --git a/src/client.cpp b/src/client.cpp index 483b22caa..a599e21dc 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -303,7 +303,7 @@ Client::~Client() delete m_inventory_from_server; // Delete detached inventories - for (std::map::iterator + for (UNORDERED_MAP::iterator i = m_detached_inventories.begin(); i != m_detached_inventories.end(); ++i) { delete i->second; @@ -1437,7 +1437,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc) break; case InventoryLocation::DETACHED: { - if(m_detached_inventories.count(loc.name) == 0) + if (m_detached_inventories.count(loc.name) == 0) return NULL; return m_detached_inventories[loc.name]; } diff --git a/src/client.h b/src/client.h index b479062a0..fb479068f 100644 --- a/src/client.h +++ b/src/client.h @@ -462,7 +462,7 @@ public: u16 getHP(); u16 getBreath(); - bool checkPrivilege(const std::string &priv) + bool checkPrivilege(const std::string &priv) const { return (m_privileges.count(priv) != 0); } bool getChatMessage(std::wstring &message); @@ -670,11 +670,11 @@ private: std::map m_sounds_to_objects; // Privileges - std::set m_privileges; + UNORDERED_SET m_privileges; // Detached inventories // key = name - std::map m_detached_inventories; + UNORDERED_MAP m_detached_inventories; // Storage for mesh data for creating multiple instances of the same mesh StringMap m_mesh_data; diff --git a/src/clientiface.cpp b/src/clientiface.cpp index a3a17d435..e7ad39579 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -605,11 +605,8 @@ ClientInterface::~ClientInterface() { MutexAutoLock clientslock(m_clients_mutex); - for(std::map::iterator - i = m_clients.begin(); - i != m_clients.end(); ++i) - { - + for (UNORDERED_MAP::iterator i = m_clients.begin(); + i != m_clients.end(); ++i) { // Delete client delete i->second; } @@ -621,10 +618,8 @@ std::vector ClientInterface::getClientIDs(ClientState min_state) std::vector reply; MutexAutoLock clientslock(m_clients_mutex); - for(std::map::iterator - i = m_clients.begin(); - i != m_clients.end(); ++i) - { + for(UNORDERED_MAP::iterator i = m_clients.begin(); + i != m_clients.end(); ++i) { if (i->second->getState() >= min_state) reply.push_back(i->second->peer_id); } @@ -691,8 +686,7 @@ void ClientInterface::sendToAll(u16 channelnum, NetworkPacket* pkt, bool reliable) { MutexAutoLock clientslock(m_clients_mutex); - for(std::map::iterator - i = m_clients.begin(); + for(UNORDERED_MAP::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { RemoteClient *client = i->second; @@ -705,11 +699,10 @@ void ClientInterface::sendToAll(u16 channelnum, RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) { MutexAutoLock clientslock(m_clients_mutex); - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return NULL; if (n->second->getState() >= state_min) @@ -720,11 +713,10 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min) { - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return NULL; if (n->second->getState() >= state_min) @@ -736,11 +728,10 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat ClientState ClientInterface::getClientState(u16 peer_id) { MutexAutoLock clientslock(m_clients_mutex); - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return CS_Invalid; return n->second->getState(); @@ -749,11 +740,10 @@ ClientState ClientInterface::getClientState(u16 peer_id) void ClientInterface::setPlayerName(u16 peer_id,std::string name) { MutexAutoLock clientslock(m_clients_mutex); - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n != m_clients.end()) + if (n != m_clients.end()) n->second->setName(name); } @@ -762,11 +752,10 @@ void ClientInterface::DeleteClient(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return; /* @@ -797,10 +786,9 @@ void ClientInterface::CreateClient(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // The client shouldn't already exist - if(n != m_clients.end()) return; + if (n != m_clients.end()) return; // Create client RemoteClient *client = new RemoteClient(); @@ -814,8 +802,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event) MutexAutoLock clientlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // No client to deliver event if (n == m_clients.end()) @@ -836,8 +823,7 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // No client to get version if (n == m_clients.end()) @@ -851,8 +837,7 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch MutexAutoLock conlock(m_clients_mutex); // Error check - std::map::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP::iterator n = m_clients.find(peer_id); // No client to set versions if (n == m_clients.end()) diff --git a/src/clientiface.h b/src/clientiface.h index c09942909..8985ef71f 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -25,10 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serialization.h" // for SER_FMT_VER_INVALID #include "threading/mutex.h" #include "network/networkpacket.h" +#include "util/cpp11_container.h" #include #include -#include #include class MapBlock; @@ -502,8 +502,7 @@ protected: void lock() { m_clients_mutex.lock(); } void unlock() { m_clients_mutex.unlock(); } - std::map& getClientList() - { return m_clients; } + UNORDERED_MAP& getClientList() { return m_clients; } private: /* update internal player list */ @@ -513,7 +512,7 @@ private: con::Connection* m_con; Mutex m_clients_mutex; // Connected clients (behind the con mutex) - std::map m_clients; + UNORDERED_MAP m_clients; std::vector m_clients_names; //for announcing masterserver // Environment diff --git a/src/content_cao.cpp b/src/content_cao.cpp index f414b2b9b..609422f26 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -1505,10 +1505,8 @@ void GenericCAO::updateBonePosition() return; m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render - for(std::map >::const_iterator ii = m_bone_position.begin(); - ii != m_bone_position.end(); ++ii) - { + for(UNORDERED_MAP >::const_iterator + ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { std::string bone_name = (*ii).first; v3f bone_pos = (*ii).second.X; v3f bone_rot = (*ii).second.Y; diff --git a/src/content_cao.h b/src/content_cao.h index bf99fd3ba..cf14a1e18 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -90,7 +90,7 @@ private: int m_animation_speed; int m_animation_blend; bool m_animation_loop; - std::map > m_bone_position; // stores position and rotation for each bone name + UNORDERED_MAP > m_bone_position; // stores position and rotation for each bone name std::string m_attachment_bone; v3f m_attachment_position; v3f m_attachment_rotation; diff --git a/src/emerge.cpp b/src/emerge.cpp index daf42f5e2..bdb5e0729 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -369,12 +369,10 @@ bool EmergeManager::pushBlockEmergeData( } -bool EmergeManager::popBlockEmergeData( - v3s16 pos, - BlockEmergeData *bedata) +bool EmergeManager::popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata) { std::map::iterator it; - std::map::iterator it2; + UNORDERED_MAP::iterator it2; it = m_blocks_enqueued.find(pos); if (it == m_blocks_enqueued.end()) diff --git a/src/emerge.h b/src/emerge.h index cf0677145..71ad97da3 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -156,7 +156,7 @@ private: Mutex m_queue_mutex; std::map m_blocks_enqueued; - std::map m_peer_queue_count; + UNORDERED_MAP m_peer_queue_count; u16 m_qlimit_total; u16 m_qlimit_diskonly; diff --git a/src/environment.cpp b/src/environment.cpp index eea264699..34b3c34f4 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1124,14 +1124,12 @@ bool ServerEnvironment::swapNode(v3s16 p, const MapNode &n) void ServerEnvironment::getObjectsInsideRadius(std::vector &objects, v3f pos, float radius) { - for(std::map::iterator - i = m_active_objects.begin(); - i != m_active_objects.end(); ++i) - { + for (ActiveObjectMap::iterator i = m_active_objects.begin(); + i != m_active_objects.end(); ++i) { ServerActiveObject* obj = i->second; u16 id = i->first; v3f objectpos = obj->getBasePosition(); - if(objectpos.getDistanceFrom(pos) > radius) + if (objectpos.getDistanceFrom(pos) > radius) continue; objects.push_back(id); } @@ -1142,8 +1140,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode) infostream << "ServerEnvironment::clearObjects(): " << "Removing all active objects" << std::endl; std::vector objects_to_remove; - for (std::map::iterator - i = m_active_objects.begin(); + for (ActiveObjectMap::iterator i = m_active_objects.begin(); i != m_active_objects.end(); ++i) { ServerActiveObject* obj = i->second; if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) @@ -1518,10 +1515,8 @@ void ServerEnvironment::step(float dtime) send_recommended = true; } - for(std::map::iterator - i = m_active_objects.begin(); - i != m_active_objects.end(); ++i) - { + for(ActiveObjectMap::iterator i = m_active_objects.begin(); + i != m_active_objects.end(); ++i) { ServerActiveObject* obj = i->second; // Don't step if is to be removed or stored statically if(obj->m_removed || obj->m_pending_deactivation) @@ -1554,7 +1549,7 @@ void ServerEnvironment::step(float dtime) Manage particle spawner expiration */ if (m_particle_management_interval.step(dtime, 1.0)) { - for (std::map::iterator i = m_particle_spawners.begin(); + for (UNORDERED_MAP::iterator i = m_particle_spawners.begin(); i != m_particle_spawners.end(); ) { //non expiring spawners if (i->second == PARTICLE_SPAWNER_NO_EXPIRY) { @@ -1579,8 +1574,7 @@ u32 ServerEnvironment::addParticleSpawner(float exptime) u32 id = 0; for (;;) { // look for unused particlespawner id id++; - std::map::iterator f; - f = m_particle_spawners.find(id); + UNORDERED_MAP::iterator f = m_particle_spawners.find(id); if (f == m_particle_spawners.end()) { m_particle_spawners[id] = time; break; @@ -1589,31 +1583,21 @@ u32 ServerEnvironment::addParticleSpawner(float exptime) return id; } -void ServerEnvironment::deleteParticleSpawner(u32 id) -{ - m_particle_spawners.erase(id); -} - ServerActiveObject* ServerEnvironment::getActiveObject(u16 id) { - std::map::iterator n; - n = m_active_objects.find(id); - if(n == m_active_objects.end()) - return NULL; - return n->second; + ActiveObjectMap::iterator n = m_active_objects.find(id); + return (n != m_active_objects.end() ? n->second : NULL); } -bool isFreeServerActiveObjectId(u16 id, - std::map &objects) +bool isFreeServerActiveObjectId(u16 id, ActiveObjectMap &objects) { - if(id == 0) + if (id == 0) return false; return objects.find(id) == objects.end(); } -u16 getFreeServerActiveObjectId( - std::map &objects) +u16 getFreeServerActiveObjectId(ActiveObjectMap &objects) { //try to reuse id's as late as possible static u16 last_used_id = 0; @@ -1659,8 +1643,7 @@ void ServerEnvironment::getAddedActiveObjects(Player *player, s16 radius, - discard objects that are found in current_objects. - add remaining objects to added_objects */ - for(std::map::iterator - i = m_active_objects.begin(); + for(ActiveObjectMap::iterator i = m_active_objects.begin(); i != m_active_objects.end(); ++i) { u16 id = i->first; @@ -1756,8 +1739,7 @@ void ServerEnvironment::setStaticForActiveObjectsInBlock( so_it = block->m_static_objects.m_active.begin(); so_it != block->m_static_objects.m_active.end(); ++so_it) { // Get the ServerActiveObject counterpart to this StaticObject - std::map::iterator ao_it; - ao_it = m_active_objects.find(so_it->first); + ActiveObjectMap::iterator ao_it = m_active_objects.find(so_it->first); if (ao_it == m_active_objects.end()) { // If this ever happens, there must be some kind of nasty bug. errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): " @@ -1806,8 +1788,8 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, verbosestream<<"ServerEnvironment::addActiveObjectRaw(): " <<"supplied with id "<getId()<getId(), m_active_objects) == false) - { + + if(!isFreeServerActiveObjectId(object->getId(), m_active_objects)) { errorstream<<"ServerEnvironment::addActiveObjectRaw(): " <<"id is not free ("<getId()<<")"<environmentDeletes()) @@ -1875,8 +1857,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, void ServerEnvironment::removeRemovedObjects() { std::vector objects_to_remove; - for(std::map::iterator - i = m_active_objects.begin(); + for(ActiveObjectMap::iterator i = m_active_objects.begin(); i != m_active_objects.end(); ++i) { u16 id = i->first; ServerActiveObject* obj = i->second; @@ -1894,7 +1875,7 @@ void ServerEnvironment::removeRemovedObjects() We will delete objects that are marked as removed or thatare waiting for deletion after deactivation */ - if(obj->m_removed == false && obj->m_pending_deactivation == false) + if (!obj->m_removed && !obj->m_pending_deactivation) continue; /* @@ -2094,8 +2075,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) void ServerEnvironment::deactivateFarObjects(bool force_delete) { std::vector objects_to_remove; - for(std::map::iterator - i = m_active_objects.begin(); + for(ActiveObjectMap::iterator i = m_active_objects.begin(); i != m_active_objects.end(); ++i) { ServerActiveObject* obj = i->second; assert(obj); diff --git a/src/environment.h b/src/environment.h index c6786faed..1ba7b196f 100644 --- a/src/environment.h +++ b/src/environment.h @@ -300,6 +300,8 @@ enum ClearObjectsMode { This is not thread-safe. Server uses an environment mutex. */ +typedef UNORDERED_MAP ActiveObjectMap; + class ServerEnvironment : public Environment { public: @@ -338,7 +340,7 @@ public: void loadDefaultMeta(); u32 addParticleSpawner(float exptime); - void deleteParticleSpawner(u32 id); + void deleteParticleSpawner(u32 id) { m_particle_spawners.erase(id); } /* External ActiveObject interface @@ -491,7 +493,7 @@ private: // World path const std::string m_path_world; // Active object list - std::map m_active_objects; + ActiveObjectMap m_active_objects; // Outgoing network message buffer for active objects std::queue m_active_object_messages; // Some timers @@ -522,7 +524,7 @@ private: // Particles IntervalLimiter m_particle_management_interval; - std::map m_particle_spawners; + UNORDERED_MAP m_particle_spawners; }; #ifndef SERVER diff --git a/src/game.cpp b/src/game.cpp index 5a3b10879..22d9ffef6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -605,7 +605,7 @@ public: void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver, gui::IGUIFont *font) const { - std::map m_meta; + UNORDERED_MAP m_meta; for (std::deque::const_iterator k = m_log.begin(); k != m_log.end(); ++k) { @@ -615,8 +615,7 @@ public: i != piece.values.end(); ++i) { const std::string &id = i->first; const float &value = i->second; - std::map::iterator j = - m_meta.find(id); + UNORDERED_MAP::iterator j = m_meta.find(id); if (j == m_meta.end()) { m_meta[id] = Meta(value); @@ -643,7 +642,7 @@ public: sizeof(usable_colors) / sizeof(*usable_colors); u32 next_color_i = 0; - for (std::map::iterator i = m_meta.begin(); + for (UNORDERED_MAP::iterator i = m_meta.begin(); i != m_meta.end(); ++i) { Meta &meta = i->second; video::SColor color(255, 200, 200, 200); @@ -659,7 +658,7 @@ public: s32 textx2 = textx + 200 - 15; s32 meta_i = 0; - for (std::map::const_iterator i = m_meta.begin(); + for (UNORDERED_MAP::const_iterator i = m_meta.begin(); i != m_meta.end(); ++i) { const std::string &id = i->first; const Meta &meta = i->second; diff --git a/src/itemdef.cpp b/src/itemdef.cpp index a6c627a03..1aa6331dc 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -146,9 +146,9 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const } os<::const_iterator + for (ItemGroupList::const_iterator i = groups.begin(); i != groups.end(); ++i){ - os<first); + os << serializeString(i->first); writeS16(os, i->second); } os< -#include +#include "util/cpp11_container.h" -typedef std::map ItemGroupList; +typedef UNORDERED_MAP ItemGroupList; static inline int itemgroup_get(const ItemGroupList &groups, const std::string &name) { - std::map::const_iterator i = groups.find(name); + ItemGroupList::const_iterator i = groups.find(name); if(i == groups.end()) return 0; return i->second; diff --git a/src/mapsector.cpp b/src/mapsector.cpp index 1588a5962..410689f5e 100644 --- a/src/mapsector.cpp +++ b/src/mapsector.cpp @@ -42,9 +42,8 @@ void MapSector::deleteBlocks() m_block_cache = NULL; // Delete all - for(std::map::iterator i = m_blocks.begin(); - i != m_blocks.end(); ++i) - { + for (UNORDERED_MAP::iterator i = m_blocks.begin(); + i != m_blocks.end(); ++i) { delete i->second; } @@ -56,20 +55,13 @@ MapBlock * MapSector::getBlockBuffered(s16 y) { MapBlock *block; - if(m_block_cache != NULL && y == m_block_cache_y){ + if (m_block_cache != NULL && y == m_block_cache_y) { return m_block_cache; } // If block doesn't exist, return NULL - std::map::iterator n = m_blocks.find(y); - if(n == m_blocks.end()) - { - block = NULL; - } - // If block exists, return it - else{ - block = n->second; - } + UNORDERED_MAP::iterator n = m_blocks.find(y); + block = (n != m_blocks.end() ? n->second : NULL); // Cache the last result m_block_cache_y = y; @@ -135,18 +127,12 @@ void MapSector::deleteBlock(MapBlock *block) void MapSector::getBlocks(MapBlockVect &dest) { - for(std::map::iterator bi = m_blocks.begin(); - bi != m_blocks.end(); ++bi) - { + for (UNORDERED_MAP::iterator bi = m_blocks.begin(); + bi != m_blocks.end(); ++bi) { dest.push_back(bi->second); } } -bool MapSector::empty() -{ - return m_blocks.empty(); -} - /* ServerMapSector */ diff --git a/src/mapsector.h b/src/mapsector.h index 4c1ce86a3..c3bff3575 100644 --- a/src/mapsector.h +++ b/src/mapsector.h @@ -63,7 +63,7 @@ public: void getBlocks(MapBlockVect &dest); - bool empty(); + bool empty() const { return m_blocks.empty(); } // Always false at the moment, because sector contains no metadata. bool differs_from_disk; @@ -71,7 +71,7 @@ public: protected: // The pile of MapBlocks - std::map m_blocks; + UNORDERED_MAP m_blocks; Map *m_parent; // Position on parent (in MapBlock widths) diff --git a/src/mg_schematic.cpp b/src/mg_schematic.cpp index 0b95fa267..e028215dc 100644 --- a/src/mg_schematic.cpp +++ b/src/mg_schematic.cpp @@ -564,14 +564,14 @@ void Schematic::applyProbabilities(v3s16 p0, void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount, std::vector *usednodes, INodeDefManager *ndef) { - std::map nodeidmap; + UNORDERED_MAP nodeidmap; content_t numids = 0; for (size_t i = 0; i != nodecount; i++) { content_t id; content_t c = nodes[i].getContent(); - std::map::const_iterator it = nodeidmap.find(c); + UNORDERED_MAP::const_iterator it = nodeidmap.find(c); if (it == nodeidmap.end()) { id = numids; numids++; diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 6fb9080bc..f20a65903 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1063,8 +1063,7 @@ void push_flags_string(lua_State *L, FlagDesc *flagdesc, u32 flags, u32 flagmask /******************************************************************************/ /******************************************************************************/ -void read_groups(lua_State *L, int index, - std::map &result) +void read_groups(lua_State *L, int index, ItemGroupList &result) { if (!lua_istable(L,index)) return; @@ -1083,11 +1082,10 @@ void read_groups(lua_State *L, int index, } /******************************************************************************/ -void push_groups(lua_State *L, const std::map &groups) +void push_groups(lua_State *L, const ItemGroupList &groups) { lua_newtable(L); - std::map::const_iterator it; - for (it = groups.begin(); it != groups.end(); ++it) { + for (ItemGroupList::const_iterator it = groups.begin(); it != groups.end(); ++it) { lua_pushnumber(L, it->second); lua_setfield(L, -2, it->first.c_str()); } diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 46416ad8e..2a2228b6d 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -33,11 +33,11 @@ extern "C" { } #include -#include #include #include "irrlichttypes_bloated.h" #include "util/string.h" +#include "itemgroup.h" namespace Json { class Value; } @@ -106,10 +106,10 @@ void pushnode (lua_State *L, const MapNode &n, NodeBox read_nodebox (lua_State *L, int index); void read_groups (lua_State *L, int index, - std::map &result); + ItemGroupList &result); void push_groups (lua_State *L, - const std::map &groups); + const ItemGroupList &groups); //TODO rename to "read_enum_field" int getenumfield (lua_State *L, int table, diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index eefac0ed7..a5fbee765 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define C_CONVERTER_H_ #include -#include +#include "util/cpp11_container.h" #include "irrlichttypes_bloated.h" #include "common/c_types.h" @@ -60,7 +60,7 @@ bool getintfield(lua_State *L, int table, bool getintfield(lua_State *L, int table, const char *fieldname, u32 &result); void read_groups(lua_State *L, int index, - std::map &result); + UNORDERED_MAP &result); bool getboolfield(lua_State *L, int table, const char *fieldname, bool &result); bool getfloatfield(lua_State *L, int table, diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 13c0d702f..fa2d15b03 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -220,7 +220,7 @@ int ModApiUtil::l_write_json(lua_State *L) int ModApiUtil::l_get_dig_params(lua_State *L) { NO_MAP_LOCK_REQUIRED; - std::map groups; + ItemGroupList groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); if(lua_isnoneornil(L, 3)) @@ -235,7 +235,7 @@ int ModApiUtil::l_get_dig_params(lua_State *L) int ModApiUtil::l_get_hit_params(lua_State *L) { NO_MAP_LOCK_REQUIRED; - std::map groups; + UNORDERED_MAP groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); if(lua_isnoneornil(L, 3)) diff --git a/src/server.cpp b/src/server.cpp index c615aee13..5b67b321a 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -669,7 +669,7 @@ void Server::AsyncRunStep(bool initial_step) MutexAutoLock envlock(m_env_mutex); m_clients.lock(); - std::map clients = m_clients.getClientList(); + UNORDERED_MAP clients = m_clients.getClientList(); ScopeProfiler sp(g_profiler, "Server: checking added and deleted objs"); // Radius inside which objects are active @@ -685,8 +685,7 @@ void Server::AsyncRunStep(bool initial_step) if (player_radius == 0 && is_transfer_limited) player_radius = radius; - for (std::map::iterator - i = clients.begin(); + for (UNORDERED_MAP::iterator i = clients.begin(); i != clients.end(); ++i) { RemoteClient *client = i->second; @@ -696,7 +695,7 @@ void Server::AsyncRunStep(bool initial_step) continue; Player *player = m_env->getPlayer(client->peer_id); - if(player == NULL) { + if (player == NULL) { // This can happen if the client timeouts somehow /*warningstream<peer_id @@ -817,10 +816,9 @@ void Server::AsyncRunStep(bool initial_step) } m_clients.lock(); - std::map clients = m_clients.getClientList(); + UNORDERED_MAP clients = m_clients.getClientList(); // Route data to every client - for (std::map::iterator - i = clients.begin(); + for (UNORDERED_MAP::iterator i = clients.begin(); i != clients.end(); ++i) { RemoteClient *client = i->second; std::string reliable_data; diff --git a/src/settings.cpp b/src/settings.cpp index 91ea9c58b..c4c3c9073 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -196,9 +196,8 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const { MutexAutoLock lock(m_mutex); - for (std::map::const_iterator - it = m_settings.begin(); - it != m_settings.end(); ++it) + for (SettingEntries::const_iterator it = m_settings.begin(); + it != m_settings.end(); ++it) printEntry(os, it->first, it->second, tab_depth); } @@ -231,7 +230,7 @@ void Settings::printEntry(std::ostream &os, const std::string &name, bool Settings::updateConfigObject(std::istream &is, std::ostream &os, const std::string &end, u32 tab_depth) { - std::map::const_iterator it; + SettingEntries::const_iterator it; std::set present_entries; std::string line, name, value; bool was_modified = false; @@ -381,7 +380,7 @@ const SettingsEntry &Settings::getEntry(const std::string &name) const { MutexAutoLock lock(m_mutex); - std::map::const_iterator n; + SettingEntries::const_iterator n; if ((n = m_settings.find(name)) == m_settings.end()) { if ((n = m_defaults.find(name)) == m_defaults.end()) throw SettingNotFoundException("Setting [" + name + "] not found."); @@ -572,9 +571,8 @@ bool Settings::exists(const std::string &name) const std::vector Settings::getNames() const { std::vector names; - for (std::map::const_iterator - i = m_settings.begin(); - i != m_settings.end(); ++i) { + for (SettingEntries::const_iterator i = m_settings.begin(); + i != m_settings.end(); ++i) { names.push_back(i->first); } return names; @@ -880,7 +878,7 @@ bool Settings::remove(const std::string &name) { MutexAutoLock lock(m_mutex); - std::map::iterator it = m_settings.find(name); + SettingEntries::iterator it = m_settings.find(name); if (it != m_settings.end()) { delete it->second.group; m_settings.erase(it); @@ -912,7 +910,6 @@ void Settings::updateValue(const Settings &other, const std::string &name) try { std::string val = other.get(name); - m_settings[name] = val; } catch (SettingNotFoundException &e) { } @@ -968,8 +965,9 @@ void Settings::updateNoLock(const Settings &other) void Settings::clearNoLock() { - std::map::const_iterator it; - for (it = m_settings.begin(); it != m_settings.end(); ++it) + + for (SettingEntries::const_iterator it = m_settings.begin(); + it != m_settings.end(); ++it) delete it->second.group; m_settings.clear(); @@ -978,8 +976,8 @@ void Settings::clearNoLock() void Settings::clearDefaultsNoLock() { - std::map::const_iterator it; - for (it = m_defaults.begin(); it != m_defaults.end(); ++it) + for (SettingEntries::const_iterator it = m_defaults.begin(); + it != m_defaults.end(); ++it) delete it->second.group; m_defaults.clear(); } diff --git a/src/settings.h b/src/settings.h index c6c044779..b19733514 100644 --- a/src/settings.h +++ b/src/settings.h @@ -98,6 +98,8 @@ struct SettingsEntry { bool is_group; }; +typedef UNORDERED_MAP SettingEntries; + class Settings { public: Settings() {} @@ -231,8 +233,8 @@ private: void doCallbacks(const std::string &name) const; - std::map m_settings; - std::map m_defaults; + SettingEntries m_settings; + SettingEntries m_defaults; SettingsCallbackMap m_callbacks; -- cgit v1.2.3 From 6eb6e75fff91f86d0e59d337f12ec93fcf9dc46e Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 23 Oct 2016 20:45:25 +0300 Subject: Adding LuaError on attempt to assign vectors with values out of range --- src/script/common/c_converter.cpp | 12 ++++++++++++ src/script/lua_api/l_object.cpp | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/script/common') diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 857300fa5..f36298915 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -23,6 +23,7 @@ extern "C" { } #include "util/numeric.h" +#include "util/serialize.h" #include "util/string.h" #include "common/c_converter.h" #include "constants.h" @@ -37,6 +38,14 @@ extern "C" { } \ } while(0) #define CHECK_POS_COORD(name) CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER) +#define CHECK_FLOAT_RANGE(value, name) \ +if (value < F1000_MIN || value > F1000_MAX) { \ + std::ostringstream error_text; \ + error_text << "Invalid float vector dimension range '" name "' " << \ + "(expected " << F1000_MIN << " < " name " < " << F1000_MAX << \ + " got " << value << ")." << std::endl; \ + throw LuaError(error_text.str()); \ +} #define CHECK_POS_TAB(index) CHECK_TYPE(index, "position", LUA_TTABLE) @@ -170,14 +179,17 @@ v3f check_v3f(lua_State *L, int index) lua_getfield(L, index, "x"); CHECK_POS_COORD("x"); pos.X = lua_tonumber(L, -1); + CHECK_FLOAT_RANGE(pos.X, "x") lua_pop(L, 1); lua_getfield(L, index, "y"); CHECK_POS_COORD("y"); pos.Y = lua_tonumber(L, -1); + CHECK_FLOAT_RANGE(pos.Y, "y") lua_pop(L, 1); lua_getfield(L, index, "z"); CHECK_POS_COORD("z"); pos.Z = lua_tonumber(L, -1); + CHECK_FLOAT_RANGE(pos.Z, "z") lua_pop(L, 1); return pos; } diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index bb352e429..23994181c 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -606,10 +606,10 @@ int ObjectRef::l_set_bone_position(lua_State *L) bone = lua_tostring(L, 2); v3f position = v3f(0, 0, 0); if (!lua_isnil(L, 3)) - position = read_v3f(L, 3); + position = check_v3f(L, 3); v3f rotation = v3f(0, 0, 0); if (!lua_isnil(L, 4)) - rotation = read_v3f(L, 4); + rotation = check_v3f(L, 4); co->setBonePosition(bone, position, rotation); return 0; } -- 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/common') 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/common') 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 From 2fe3bf5a18eb9aa9f38654b3c0a0729c42408cd6 Mon Sep 17 00:00:00 2001 From: juhdanad Date: Mon, 28 Nov 2016 09:43:33 +0100 Subject: Limit light_source in the engine (#4814) Since light_source>15 causes crash, it must be limited. --- src/nodedef.cpp | 2 ++ src/script/common/c_content.cpp | 6 ++++++ src/voxelalgorithms.cpp | 1 + 3 files changed, 9 insertions(+) (limited to 'src/script/common') diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 39ea1a60e..ccbb42c66 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -482,6 +482,7 @@ void ContentFeatures::deSerialize(std::istream &is) liquid_viscosity = readU8(is); liquid_renewable = readU8(is); light_source = readU8(is); + light_source = MYMIN(light_source, LIGHT_MAX); damage_per_second = readU32(is); node_box.deSerialize(is); selection_box.deSerialize(is); @@ -1442,6 +1443,7 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) liquid_alternative_source = deSerializeString(is); liquid_viscosity = readU8(is); light_source = readU8(is); + light_source = MYMIN(light_source, LIGHT_MAX); damage_per_second = readU32(is); node_box.deSerialize(is); selection_box.deSerialize(is); diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index f20a65903..541744895 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -526,6 +526,12 @@ ContentFeatures read_content_features(lua_State *L, int index) // Amount of light the node emits f.light_source = getintfield_default(L, index, "light_source", f.light_source); + if (f.light_source > LIGHT_MAX) { + warningstream << "Node " << f.name.c_str() + << " had greater light_source than " << LIGHT_MAX + << ", it was reduced." << std::endl; + f.light_source = LIGHT_MAX; + } f.damage_per_second = getintfield_default(L, index, "damage_per_second", f.damage_per_second); diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp index 55f0d1c98..93cc33acc 100644 --- a/src/voxelalgorithms.cpp +++ b/src/voxelalgorithms.cpp @@ -264,6 +264,7 @@ struct LightQueue { const mapblock_v3 &block_pos, MapBlock *block, direction source_dir) { + assert(light <= LIGHT_SUN); lights[light].push_back( ChangingLight(rel_pos, block_pos, block, source_dir)); } -- cgit v1.2.3