MCPcopy Create free account
hub / github.com/cuberite/cuberite / ParseCharMap

Method ParseCharMap

src/Generating/Prefab.cpp:173–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171
172
173void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef)
174{
175 ASSERT(a_CharMapDef != NULL);
176
177 // Initialize the charmap to all-invalid values:
178 for (size_t i = 0; i < ARRAYCOUNT(a_CharMapOut); i++)
179 {
180 a_CharMapOut[i].m_BlockType = 0;
181 a_CharMapOut[i].m_BlockMeta = 16; // Mark unassigned entries with a meta that is impossible otherwise
182 }
183
184 // Process the lines in the definition:
185 AStringVector Lines = StringSplitAndTrim(a_CharMapDef, "\n");
186 for (AStringVector::const_iterator itr = Lines.begin(), end = Lines.end(); itr != end; ++itr)
187 {
188 AStringVector CharDef = StringSplitAndTrim(*itr, ":");
189 size_t NumElements = CharDef.size();
190 if ((NumElements < 2) || CharDef[0].empty() || CharDef[1].empty())
191 {
192 LOGWARNING("Bad prefab CharMap definition line: \"%s\", skipping.", itr->c_str());
193 continue;
194 }
195 unsigned char Src = (unsigned char)CharDef[0][0];
196 ASSERT(a_CharMapOut[Src].m_BlockMeta == 16); // This letter has not been assigned yet?
197 a_CharMapOut[Src].m_BlockType = (BLOCKTYPE)atoi(CharDef[1].c_str());
198 NIBBLETYPE BlockMeta = 0;
199 if ((NumElements >= 3) && !CharDef[2].empty())
200 {
201 BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str());
202 ASSERT((BlockMeta >= 0) && (BlockMeta <= 15));
203 }
204 a_CharMapOut[Src].m_BlockMeta = BlockMeta;
205 } // for itr - Lines[]
206}
207
208
209

Callers

nothing calls this directly

Calls 6

StringSplitAndTrimFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
sizeMethod · 0.80
emptyMethod · 0.80
c_strMethod · 0.80

Tested by

no test coverage detected