MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / loadVoxelSlice

Method loadVoxelSlice

framework/data.cpp:184–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184sp<VoxelSlice> DataImpl::loadVoxelSlice(const UString &path)
185{
186 std::lock_guard<std::recursive_mutex> l(this->voxelCacheLock);
187 if (path == "")
188 return nullptr;
189
190 auto alias = this->voxelAliases.find(path);
191 if (alias != this->voxelAliases.end())
192 {
193 LogInfo("Using alias \"%s\" for \"%s\"", path, alias->second);
194 return this->loadVoxelSlice(alias->second);
195 }
196
197 sp<VoxelSlice> slice;
198 if (path.substr(0, 9) == "LOFTEMPS:")
199 {
200 auto splitString = split(path, ":");
201 // "LOFTEMPS:DATFILE:TABFILE:INDEX"
202 // or
203 // "LOFTEMPS:DATFILE:TABFILE:INDEX:X:Y"
204 if (splitString.size() != 4)
205 {
206 LogError("Invalid LOFTEMPS string \"%s\"", path);
207 return nullptr;
208 }
209 // Cut off the index to get the LOFTemps file
210 UString cacheKey = splitString[0] + splitString[1] + splitString[2];
211 cacheKey = to_upper(cacheKey);
212 sp<LOFTemps> lofTemps = this->LOFVoxelCache[cacheKey].lock();
213 if (!lofTemps)
214 {
215 auto datFile = this->fs.open(splitString[1]);
216 if (!datFile)
217 {
218 LogError("Failed to open LOFTemps dat file \"%s\"", splitString[1]);
219 return nullptr;
220 }
221 auto tabFile = this->fs.open(splitString[2]);
222 if (!tabFile)
223 {
224 LogError("Failed to open LOFTemps tab file \"%s\"", splitString[2]);
225 return nullptr;
226 }
227 lofTemps = mksp<LOFTemps>(datFile, tabFile);
228 this->LOFVoxelCache[cacheKey] = lofTemps;
229 this->pinnedLOFVoxels.push(lofTemps);
230 this->pinnedLOFVoxels.pop();
231 }
232 int idx = Strings::toInteger(splitString[3]);
233 slice = lofTemps->getSlice(idx);
234 if (!slice)
235 {
236 LogError("Invalid idx %d", idx);
237 }
238 }
239 else
240 {
241 auto img = loadImage(path);

Callers 7

loadImageMethod · 0.95
serializeInFunction · 0.80
extractAgentBodyTypesMethod · 0.80
extractVehiclesMethod · 0.80
extractCitySceneryMethod · 0.80
readBattleMapPartsMethod · 0.80

Calls 10

splitFunction · 0.85
to_upperFunction · 0.85
endMethod · 0.80
openMethod · 0.80
pushMethod · 0.80
popMethod · 0.80
getSliceMethod · 0.80
setBitMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected