diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 16 | ||||
-rw-r--r-- | src/mapgen_v6.cpp | 36 | ||||
-rw-r--r-- | src/nodedef.cpp | 37 | ||||
-rw-r--r-- | src/nodedef.h | 3 | ||||
-rw-r--r-- | src/scriptapi.cpp | 2 |
5 files changed, 69 insertions, 25 deletions
diff --git a/src/main.cpp b/src/main.cpp index 2e57a8c20..08af6a37d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -618,7 +618,7 @@ void drawMenuBackground(video::IVideoDriver* driver) { std::string path = getTexturePath("menubg.png"); if (path[0]) { - video::ITexture *bgtexture = + static const video::ITexture *bgtexture = driver->getTexture(path.c_str()); if (bgtexture) { @@ -646,7 +646,7 @@ void drawMenuFooter(video::IVideoDriver* driver, bool clouds) { std::string path = getTexturePath(clouds ? "menufooter_clouds.png" : "menufooter.png"); if (path[0]) { - video::ITexture *footertexture = + static const video::ITexture *footertexture = driver->getTexture(path.c_str()); if (footertexture) { @@ -678,13 +678,10 @@ void drawMenuHeader(video::IVideoDriver* driver) { std::string path = getTexturePath("menuheader.png"); if (path[0]) { - video::ITexture *splashtexture = + static const video::ITexture *splashtexture = driver->getTexture(path.c_str()); if(splashtexture) { - //v2s32 splashsize((splashtexture->getOriginalSize().Width*100)/ - // splashtexture->getOriginalSize().Height, 80); - f32 mult = (((f32)screensize.Width / 2)) / ((f32)splashtexture->getOriginalSize().Width); @@ -712,9 +709,10 @@ void drawMenuHeader(video::IVideoDriver* driver) { // Draw the Splash over the clouds and under the main menu void drawMenuSplash(video::IVideoDriver* driver) { core::dimension2d<u32> screensize = driver->getScreenSize(); - if (getTexturePath("menusplash.png") != "") { - video::ITexture *splashtexture = - driver->getTexture(getTexturePath("menusplash.png").c_str()); + std::string path = getTexturePath("menusplash.png"); + if (path[0]) { + static const video::ITexture *splashtexture = + driver->getTexture(path.c_str()); if(splashtexture) { core::rect<s32> splashrect(0, 0, screensize.Width, screensize.Height); diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 0b419617d..275d4b78f 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -928,20 +928,20 @@ void MapgenV6::growGrass() { void MapgenV6::defineCave(Cave &cave, PseudoRandom ps, v3s16 node_min, bool large_cave) { - cave.min_tunnel_diameter = 2; - cave.max_tunnel_diameter = ps.range(2,6); - cave.dswitchint = ps.range(1,14); - cave.flooded = true; //large_cave && ps.range(0,4); - if(large_cave){ - cave.part_max_length_rs = ps.range(2,4); - cave.tunnel_routepoints = ps.range(5, ps.range(15,30)); - cave.min_tunnel_diameter = 5; - cave.max_tunnel_diameter = ps.range(7, ps.range(8,24)); - } else { - cave.part_max_length_rs = ps.range(2,9); - cave.tunnel_routepoints = ps.range(10, ps.range(15,30)); - } - cave.large_cave_is_flat = (ps.range(0,1) == 0); + cave.min_tunnel_diameter = 2; + cave.max_tunnel_diameter = ps.range(2,6); + cave.dswitchint = ps.range(1,14); + cave.flooded = true; //large_cave && ps.range(0,4); + if (large_cave){ + cave.part_max_length_rs = ps.range(2,4); + cave.tunnel_routepoints = ps.range(5, ps.range(15,30)); + cave.min_tunnel_diameter = 5; + cave.max_tunnel_diameter = ps.range(7, ps.range(8,24)); + } else { + cave.part_max_length_rs = ps.range(2,9); + cave.tunnel_routepoints = ps.range(10, ps.range(15,30)); + } + cave.large_cave_is_flat = (ps.range(0,1) == 0); } @@ -1120,7 +1120,13 @@ void MapgenV6::generateCaves(int max_stone_y) { rp.Z = ar.Z-1; vec = rp - orp; - for(float f=0; f<1.0; f+=1.0/vec.getLength()) + float veclen = vec.getLength(); + // As odd as it sounds, veclen is *exactly* + // 0.0 sometimes, causing a FPE + if (veclen == 0.0) + veclen = 1.0; + + for(float f=0; f<1.0; f+=1.0/veclen) { v3f fp = orp + vec * f; fp.X += 0.1*ps.range(-10,10); diff --git a/src/nodedef.cpp b/src/nodedef.cpp index d41df5c3b..ca8898907 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include "nameidmapping.h" #include "util/serialize.h" +//#include "profiler.h" // For TimeTaker /* NodeBox @@ -452,6 +453,7 @@ public: virtual void getIds(const std::string &name, std::set<content_t> &result) const { + //TimeTaker t("getIds", NULL, PRECISION_MICRO); if(name.substr(0,6) != "group:"){ content_t id = CONTENT_IGNORE; if(getId(name, id)) @@ -459,6 +461,20 @@ public: return; } std::string group = name.substr(6); + +#if 1 // Optimized version, takes less than 1 microsecond at -O1 + std::map<std::string, GroupItems>::const_iterator + i = m_group_to_items.find(group); + if (i == m_group_to_items.end()) + return; + + const GroupItems &items = i->second; + for (GroupItems::const_iterator j = items.begin(); + j != items.end(); ++j) { + if ((*j).second != 0) + result.insert((*j).first); + } +#else // Old version, takes about ~150-200us at -O1 for(u16 id=0; id<=MAX_CONTENT; id++) { const ContentFeatures &f = m_content_features[id]; @@ -467,6 +483,8 @@ public: if(itemgroup_get(f.groups, group) != 0) result.insert(id); } +#endif + //printf("getIds: %dus\n", t.stop()); } virtual const ContentFeatures& get(const std::string &name) const { @@ -498,6 +516,21 @@ public: m_content_features[c] = def; if(def.name != "") addNameIdMapping(c, def.name); + + // Add this content to the list of all groups it belongs to + for (ItemGroupList::const_iterator i = def.groups.begin(); + i != def.groups.end(); ++i) { + std::string group_name = i->first; + + std::map<std::string, GroupItems>::iterator + j = m_group_to_items.find(group_name); + if (j == m_group_to_items.end()) { + m_group_to_items[group_name].push_back(std::make_pair(c, i->second)); + } else { + GroupItems &items = j->second; + items.push_back(std::make_pair(c, i->second)); + } + } } virtual content_t set(const std::string &name, const ContentFeatures &def) @@ -787,6 +820,10 @@ private: // item aliases too. Updated by updateAliases() // Note: Not serialized. std::map<std::string, content_t> m_name_id_mapping_with_aliases; + // A mapping from groups to a list of content_ts (and their levels) + // that belong to it. Necessary for a direct lookup in getIds(). + // Note: Not serialized. + std::map<std::string, GroupItems> m_group_to_items; }; IWritableNodeDefManager* createNodeDefManager() diff --git a/src/nodedef.h b/src/nodedef.h index 4f07565d1..d846489ae 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <string> #include <iostream> #include <map> +#include <list> #include "mapnode.h" #ifndef SERVER #include "tile.h" @@ -36,6 +37,8 @@ class IItemDefManager; class ITextureSource; class IGameDef; +typedef std::list<std::pair<content_t, int> > GroupItems; + enum ContentParamType { CPT_NONE, diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 80abffa2b..81fcc08d3 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -727,7 +727,7 @@ static int l_register_ore(lua_State *L) if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) { errorstream << "register_ore: clust_scarcity and clust_num_ores" - "must be greater than 0"; + " must be greater than 0" << std::endl; delete ore; return 0; } |