]> git.lizzy.rs Git - minetest.git/commitdiff
Move get_schematic and read_schematic to l_mapgen.cpp
authorkwolekr <kwolekr@minetest.net>
Wed, 10 Dec 2014 06:49:57 +0000 (01:49 -0500)
committerkwolekr <kwolekr@minetest.net>
Wed, 10 Dec 2014 06:49:57 +0000 (01:49 -0500)
src/script/common/c_content.cpp
src/script/common/c_content.h
src/script/lua_api/l_mapgen.cpp
src/script/lua_api/l_mapgen.h

index cab346caebc66a3c639fd3a652ba2e3ab5056cf3..4eba280e075e6b5e7d3143100ac9eeee4bf2332a 100644 (file)
@@ -1001,105 +1001,6 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np)
        return true;
 }
 
-/******************************************************************************/
-
-bool get_schematic(lua_State *L, int index, Schematic *schem,
-       INodeDefManager *ndef, std::map<std::string, std::string> &replace_names)
-{
-       if (index < 0)
-               index = lua_gettop(L) + 1 + index;
-
-       if (lua_istable(L, index)) {
-               return read_schematic(L, index, schem, ndef, replace_names);
-       } else if (lua_isstring(L, index)) {
-               NodeResolver *resolver = ndef->getResolver();
-               const char *filename = lua_tostring(L, index);
-               return schem->loadSchematicFromFile(filename, resolver, replace_names);
-       } else {
-               return false;
-       }
-}
-
-bool read_schematic(lua_State *L, int index, Schematic *schem,
-       INodeDefManager *ndef, std::map<std::string, std::string> &replace_names)
-{
-       //// Get schematic size
-       lua_getfield(L, index, "size");
-       v3s16 size = read_v3s16(L, -1);
-       lua_pop(L, 1);
-
-       //// Get schematic data
-       lua_getfield(L, index, "data");
-       luaL_checktype(L, -1, LUA_TTABLE);
-
-       int numnodes = size.X * size.Y * size.Z;
-       MapNode *schemdata = new MapNode[numnodes];
-       int i = 0;
-
-       lua_pushnil(L);
-       while (lua_next(L, -2)) {
-               if (i < numnodes) {
-                       // same as readnode, except param1 default is MTSCHEM_PROB_CONST
-                       lua_getfield(L, -1, "name");
-                       std::string name = luaL_checkstring(L, -1);
-                       lua_pop(L, 1);
-
-                       u8 param1;
-                       lua_getfield(L, -1, "param1");
-                       param1 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : MTSCHEM_PROB_ALWAYS;
-                       lua_pop(L, 1);
-
-                       u8 param2;
-                       lua_getfield(L, -1, "param2");
-                       param2 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : 0;
-                       lua_pop(L, 1);
-
-                       std::map<std::string, std::string>::iterator it;
-                       it = replace_names.find(name);
-                       if (it != replace_names.end())
-                               name = it->second;
-
-                       schemdata[i] = MapNode(ndef, name, param1, param2);
-               }
-
-               i++;
-               lua_pop(L, 1);
-       }
-
-       if (i != numnodes) {
-               errorstream << "read_schematic: incorrect number of "
-                       "nodes provided in raw schematic data (got " << i <<
-                       ", expected " << numnodes << ")." << std::endl;
-               return false;
-       }
-
-       //// Get Y-slice probability values (if present)
-       u8 *slice_probs = new u8[size.Y];
-       for (i = 0; i != size.Y; i++)
-               slice_probs[i] = MTSCHEM_PROB_ALWAYS;
-
-       lua_getfield(L, index, "yslice_prob");
-       if (lua_istable(L, -1)) {
-               lua_pushnil(L);
-               while (lua_next(L, -2)) {
-                       if (getintfield(L, -1, "ypos", i) && i >= 0 && i < size.Y) {
-                               slice_probs[i] = getintfield_default(L, -1,
-                                       "prob", MTSCHEM_PROB_ALWAYS);
-                       }
-                       lua_pop(L, 1);
-               }
-       }
-
-       // Here, we read the nodes directly from the INodeDefManager - there is no
-       // need for pending node resolutions so we'll mark this schematic as updated
-       schem->flags       = SCHEM_CIDS_UPDATED;
-
-       schem->size        = size;
-       schem->schemdata   = schemdata;
-       schem->slice_probs = slice_probs;
-       return true;
-}
-
 /******************************************************************************/
 // Returns depth of json value tree
 static int push_json_value_getdepth(const Json::Value &value)
index 834db319b3b6404cbc8d434bfb1baf36e9edf4a2..241b1ca7651a9008c8d73c472ebb39f3c7c4aecb 100644 (file)
@@ -149,14 +149,6 @@ bool               string_to_enum            (const EnumString *spec,
 
 bool               read_noiseparams          (lua_State *L, int index,
                                               NoiseParams *np);
-bool               get_schematic             (lua_State *L, int index,
-                                              Schematic *schem,
-                                              INodeDefManager *ndef,
-                             std::map<std::string, std::string> &replace_names);
-bool               read_schematic            (lua_State *L, int index,
-                                              Schematic *dschem,
-                                              INodeDefManager *ndef,
-                             std::map<std::string, std::string> &replace_names);
 
 void               luaentity_get             (lua_State *L,u16 id);
 
index 03a2ee0d5f53fdaf64afb0661caa58a936b087e7..3fe6fb99124919e52449051e95a46859a5585b56 100644 (file)
@@ -85,7 +85,114 @@ struct EnumString ModApiMapgen::es_Rotation[] =
 };
 
 
-static void read_schematic_replacements(lua_State *L,
+///////////////////////////////////////////////////////////////////////////////
+
+
+bool read_schematic(lua_State *L, int index, Schematic *schem,
+       INodeDefManager *ndef, std::map<std::string, std::string> &replace_names)
+{
+       //// Get schematic size
+       lua_getfield(L, index, "size");
+       v3s16 size = read_v3s16(L, -1);
+       lua_pop(L, 1);
+
+       //// Get schematic data
+       lua_getfield(L, index, "data");
+       luaL_checktype(L, -1, LUA_TTABLE);
+
+       int numnodes = size.X * size.Y * size.Z;
+       MapNode *schemdata = new MapNode[numnodes];
+       int i = 0;
+
+       lua_pushnil(L);
+       while (lua_next(L, -2)) {
+               if (i >= numnodes) {
+                       i++;
+                       lua_pop(L, 1);
+                       continue;
+               }
+
+               // same as readnode, except param1 default is MTSCHEM_PROB_CONST
+               lua_getfield(L, -1, "name");
+               std::string name = luaL_checkstring(L, -1);
+               lua_pop(L, 1);
+
+               u8 param1;
+               lua_getfield(L, -1, "param1");
+               param1 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : MTSCHEM_PROB_ALWAYS;
+               lua_pop(L, 1);
+
+               u8 param2;
+               lua_getfield(L, -1, "param2");
+               param2 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : 0;
+               lua_pop(L, 1);
+
+               std::map<std::string, std::string>::iterator it;
+               it = replace_names.find(name);
+               if (it != replace_names.end())
+                       name = it->second;
+
+               schemdata[i] = MapNode(ndef, name, param1, param2);
+
+               i++;
+               lua_pop(L, 1);
+       }
+
+       if (i != numnodes) {
+               errorstream << "read_schematic: incorrect number of "
+                       "nodes provided in raw schematic data (got " << i <<
+                       ", expected " << numnodes << ")." << std::endl;
+               delete schemdata;
+               return false;
+       }
+
+       //// Get Y-slice probability values (if present)
+       u8 *slice_probs = new u8[size.Y];
+       for (i = 0; i != size.Y; i++)
+               slice_probs[i] = MTSCHEM_PROB_ALWAYS;
+
+       lua_getfield(L, index, "yslice_prob");
+       if (lua_istable(L, -1)) {
+               lua_pushnil(L);
+               while (lua_next(L, -2)) {
+                       if (getintfield(L, -1, "ypos", i) && i >= 0 && i < size.Y) {
+                               slice_probs[i] = getintfield_default(L, -1,
+                                       "prob", MTSCHEM_PROB_ALWAYS);
+                       }
+                       lua_pop(L, 1);
+               }
+       }
+
+       // Here, we read the nodes directly from the INodeDefManager - there is no
+       // need for pending node resolutions so we'll mark this schematic as updated
+       schem->flags       = SCHEM_CIDS_UPDATED;
+
+       schem->size        = size;
+       schem->schemdata   = schemdata;
+       schem->slice_probs = slice_probs;
+       return true;
+}
+
+
+bool get_schematic(lua_State *L, int index, Schematic *schem,
+       INodeDefManager *ndef, std::map<std::string, std::string> &replace_names)
+{
+       if (index < 0)
+               index = lua_gettop(L) + 1 + index;
+
+       if (lua_istable(L, index)) {
+               return read_schematic(L, index, schem, ndef, replace_names);
+       } else if (lua_isstring(L, index)) {
+               NodeResolver *resolver = ndef->getResolver();
+               const char *filename = lua_tostring(L, index);
+               return schem->loadSchematicFromFile(filename, resolver, replace_names);
+       } else {
+               return false;
+       }
+}
+
+
+void read_schematic_replacements(lua_State *L,
        std::map<std::string, std::string> &replace_names, int index)
 {
        lua_pushnil(L);
index 72bf1f59b265c1e55c07bf3617b0e5b7923ea383..76f60a2d7b20b8ac82667d50277c39c1c54fdbea 100644 (file)
@@ -76,6 +76,4 @@ class ModApiMapgen : public ModApiBase {
        static void Initialize(lua_State *L, int top);
 };
 
-
-
 #endif /* L_MAPGEN_H_ */