@@ -92,14 +92,6 @@ struct EnumString ModApiMapgen::es_SchematicFormatType[] =
92
92
{0 , NULL },
93
93
};
94
94
95
- struct EnumString ModApiMapgen::es_NodeResolveMethod[] =
96
- {
97
- {NODE_RESOLVE_NONE, " none" },
98
- {NODE_RESOLVE_DIRECT, " direct" },
99
- {NODE_RESOLVE_DEFERRED, " deferred" },
100
- {0 , NULL },
101
- };
102
-
103
95
ObjDef *get_objdef (lua_State *L, int index, ObjDefManager *objmgr);
104
96
105
97
Biome *get_or_load_biome (lua_State *L, int index,
@@ -109,14 +101,11 @@ size_t get_biome_list(lua_State *L, int index,
109
101
BiomeManager *biomemgr, std::set<u8> *biome_id_list);
110
102
111
103
Schematic *get_or_load_schematic (lua_State *L, int index,
112
- SchematicManager *schemmgr, StringMap *replace_names,
113
- bool register_on_load=true ,
114
- NodeResolveMethod resolve_method=NODE_RESOLVE_DEFERRED);
104
+ SchematicManager *schemmgr, StringMap *replace_names);
115
105
Schematic *load_schematic (lua_State *L, int index, INodeDefManager *ndef,
116
- StringMap *replace_names, NodeResolveMethod resolve_method );
106
+ StringMap *replace_names);
117
107
Schematic *load_schematic_from_def (lua_State *L, int index,
118
- INodeDefManager *ndef, StringMap *replace_names,
119
- NodeResolveMethod resolve_method);
108
+ INodeDefManager *ndef, StringMap *replace_names);
120
109
bool read_schematic_def (lua_State *L, int index,
121
110
Schematic *schem, std::vector<std::string> *names);
122
111
@@ -145,9 +134,7 @@ ObjDef *get_objdef(lua_State *L, int index, ObjDefManager *objmgr)
145
134
// /////////////////////////////////////////////////////////////////////////////
146
135
147
136
Schematic *get_or_load_schematic (lua_State *L, int index,
148
- SchematicManager *schemmgr, StringMap *replace_names,
149
- bool register_on_load,
150
- NodeResolveMethod resolve_method)
137
+ SchematicManager *schemmgr, StringMap *replace_names)
151
138
{
152
139
if (index < 0 )
153
140
index = lua_gettop (L) + 1 + index ;
@@ -157,13 +144,10 @@ Schematic *get_or_load_schematic(lua_State *L, int index,
157
144
return schem;
158
145
159
146
schem = load_schematic (L, index , schemmgr->getNodeDef (),
160
- replace_names, resolve_method );
147
+ replace_names);
161
148
if (!schem)
162
149
return NULL ;
163
150
164
- if (!register_on_load)
165
- return schem;
166
-
167
151
if (schemmgr->add (schem) == OBJDEF_INVALID_HANDLE) {
168
152
delete schem;
169
153
return NULL ;
@@ -174,7 +158,7 @@ Schematic *get_or_load_schematic(lua_State *L, int index,
174
158
175
159
176
160
Schematic *load_schematic (lua_State *L, int index, INodeDefManager *ndef,
177
- StringMap *replace_names, NodeResolveMethod resolve_method )
161
+ StringMap *replace_names)
178
162
{
179
163
if (index < 0 )
180
164
index = lua_gettop (L) + 1 + index ;
@@ -183,7 +167,7 @@ Schematic *load_schematic(lua_State *L, int index, INodeDefManager *ndef,
183
167
184
168
if (lua_istable (L, index )) {
185
169
schem = load_schematic_from_def (L, index , ndef,
186
- replace_names, resolve_method );
170
+ replace_names);
187
171
if (!schem) {
188
172
delete schem;
189
173
return NULL ;
@@ -198,7 +182,7 @@ Schematic *load_schematic(lua_State *L, int index, INodeDefManager *ndef,
198
182
filepath = ModApiBase::getCurrentModPath (L) + DIR_DELIM + filepath;
199
183
200
184
if (!schem->loadSchematicFromFile (filepath, ndef,
201
- replace_names, resolve_method )) {
185
+ replace_names)) {
202
186
delete schem;
203
187
return NULL ;
204
188
}
@@ -208,8 +192,8 @@ Schematic *load_schematic(lua_State *L, int index, INodeDefManager *ndef,
208
192
}
209
193
210
194
211
- Schematic *load_schematic_from_def (lua_State *L, int index, INodeDefManager *ndef,
212
- StringMap *replace_names, NodeResolveMethod resolve_method )
195
+ Schematic *load_schematic_from_def (lua_State *L, int index,
196
+ INodeDefManager *ndef, StringMap *replace_names )
213
197
{
214
198
Schematic *schem = SchematicManager::create (SCHEMATIC_NORMAL);
215
199
@@ -230,7 +214,7 @@ Schematic *load_schematic_from_def(lua_State *L, int index, INodeDefManager *nde
230
214
}
231
215
}
232
216
233
- ndef->pendNodeResolve (schem, resolve_method );
217
+ ndef->pendNodeResolve (schem);
234
218
235
219
return schem;
236
220
}
@@ -406,7 +390,7 @@ Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef)
406
390
nn.push_back (getstringfield_default (L, index , " node_water" , " " ));
407
391
nn.push_back (getstringfield_default (L, index , " node_river_water" , " " ));
408
392
nn.push_back (getstringfield_default (L, index , " node_dust" , " " ));
409
- ndef->pendNodeResolve (b, NODE_RESOLVE_DEFERRED );
393
+ ndef->pendNodeResolve (b);
410
394
411
395
return b;
412
396
}
@@ -770,7 +754,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
770
754
return 0 ;
771
755
}
772
756
773
- ndef->pendNodeResolve (deco, NODE_RESOLVE_DEFERRED );
757
+ ndef->pendNodeResolve (deco);
774
758
775
759
ObjDefHandle handle = decomgr->add (deco);
776
760
if (handle == OBJDEF_INVALID_HANDLE) {
@@ -928,7 +912,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
928
912
size_t nnames = getstringlistfield (L, index , " wherein" , &ore->m_nodenames );
929
913
ore->m_nnlistsizes .push_back (nnames);
930
914
931
- ndef->pendNodeResolve (ore, NODE_RESOLVE_DEFERRED );
915
+ ndef->pendNodeResolve (ore);
932
916
933
917
lua_pushinteger (L, handle);
934
918
return 1 ;
@@ -945,7 +929,7 @@ int ModApiMapgen::l_register_schematic(lua_State *L)
945
929
read_schematic_replacements (L, 2 , &replace_names);
946
930
947
931
Schematic *schem = load_schematic (L, 1 , schemmgr->getNodeDef (),
948
- &replace_names, NODE_RESOLVE_DEFERRED );
932
+ &replace_names);
949
933
if (!schem)
950
934
return 0 ;
951
935
@@ -1138,8 +1122,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
1138
1122
return 0 ;
1139
1123
}
1140
1124
1141
- schem->placeStructure (map, p, 0 , (Rotation)rot, force_placement,
1142
- schemmgr->getNodeDef ());
1125
+ schem->placeStructure (map, p, 0 , (Rotation)rot, force_placement);
1143
1126
1144
1127
lua_pushboolean (L, true );
1145
1128
return 1 ;
@@ -1151,14 +1134,15 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L)
1151
1134
SchematicManager *schemmgr = getServer (L)->getEmergeManager ()->schemmgr ;
1152
1135
1153
1136
// // Read options
1154
- NodeResolveMethod resolve_method = (NodeResolveMethod)getenumfield (L, 3 ,
1155
- " node_resolve_method" , es_NodeResolveMethod, NODE_RESOLVE_NONE);
1156
- bool register_on_load = getboolfield_default (L, 3 , " register_on_load" , false );
1157
1137
bool use_comments = getboolfield_default (L, 3 , " use_lua_comments" , false );
1158
1138
1159
- // // Read schematic
1160
- Schematic *schem = get_or_load_schematic (L, 1 , schemmgr, NULL ,
1161
- register_on_load, resolve_method);
1139
+ // // Get schematic
1140
+ bool was_loaded = false ;
1141
+ Schematic *schem = (Schematic *)get_objdef (L, 1 , schemmgr);
1142
+ if (!schem) {
1143
+ schem = load_schematic (L, 1 , NULL , NULL );
1144
+ was_loaded = true ;
1145
+ }
1162
1146
if (!schem) {
1163
1147
errorstream << " serialize_schematic: failed to get schematic" << std::endl;
1164
1148
return 0 ;
@@ -1174,15 +1158,18 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L)
1174
1158
std::ostringstream os (std::ios_base::binary);
1175
1159
switch (schem_format) {
1176
1160
case SCHEM_FMT_MTS:
1177
- schem->serializeToMts (&os);
1161
+ schem->serializeToMts (&os, schem-> m_nodenames );
1178
1162
break ;
1179
1163
case SCHEM_FMT_LUA:
1180
- schem->serializeToLua (&os, use_comments);
1164
+ schem->serializeToLua (&os, schem-> m_nodenames , use_comments);
1181
1165
break ;
1182
1166
default :
1183
1167
return 0 ;
1184
1168
}
1185
1169
1170
+ if (was_loaded)
1171
+ delete schem;
1172
+
1186
1173
std::string ser = os.str ();
1187
1174
lua_pushlstring (L, ser.c_str (), ser.length ());
1188
1175
return 1 ;
0 commit comments