20 #define DLL_LOADS_FILES
21 #ifdef DLL_LOADS_FILES
89 if (keepTrackOfMemory)
91 VF_DELETE[] dataFileContents;
105 bool initFromFiles(
const std::string& project_file,
const std::string& bundle_file)
107 keepTrackOfMemory =
true;
111 std::ifstream t(project_file);
115 t.seekg(0, std::ios::end);
116 propFileContents.reserve((
size_t)t.tellg());
117 t.seekg(0, std::ios::beg);
119 propFileContents.assign((std::istreambuf_iterator<char>(t)),
120 std::istreambuf_iterator<char>());
128 std::ifstream t(bundle_file, std::ios::binary);
133 t.seekg(0, std::ios::end);
134 size_t len = (size_t)t.tellg();
135 dataFileContents =
new char[len];
136 t.seekg(0, std::ios::beg);
137 t.read(dataFileContents, len);
144 extractOffsetsInBundle();
152 bool initFromData(
const std::string& project_file,
const char* bundle_file_data)
154 keepTrackOfMemory =
false;
156 propFileContents = project_file;
157 dataFileContents =
const_cast<char*
>(bundle_file_data);
159 extractOffsetsInBundle();
169 bool getBool(
const std::string& section,
const std::string& field,
const bool defaultValue)
const
171 std::string field_val;
172 if (!getSectionFieldString(section, field, field_val))
177 return (field_val.c_str()[0] ==
'T')?
true:
false;
180 int getInt(
const std::string& section,
const std::string& field,
const int defaultValue)
const
182 std::string field_val;
183 if (!getSectionFieldString(section, field, field_val))
187 return atoi(field_val.c_str());
190 double getFloat(
const std::string& section,
const std::string& field,
const double defaultValue)
const
192 std::string field_val;
193 if (!getSectionFieldString(section, field, field_val))
197 return atof(field_val.c_str());
200 std::string getString(
const std::string& section,
const std::string& field,
const std::string defaultValue)
const
202 std::string field_val;
203 if (!getSectionFieldString(section, field, field_val))
210 void getString(
const std::string& section,
const std::string& field,
const char* defaultValue,
char* str_out,
const size_t max_str_size)
const
212 std::string field_val;
213 if (!getSectionFieldString(section, field, field_val))
215 size_t len = min(strlen(defaultValue), max_str_size - 2);
216 for (
size_t i = 0; i<len; ++i)
218 str_out[i] = defaultValue[i];
224 size_t len = min(strlen(field_val.c_str()), max_str_size - 2);
225 const char* str = field_val.c_str();
226 for (
size_t i=0; i<len; ++i)
235 bool getSectionFieldString(
const std::string& section_name_in,
const std::string& field_name_in, std::string& field_str_out)
const
238 const std::size_t sectionTagPos = propFileContents.find(
"[" + section_name_in +
"]");
239 if (sectionTagPos == std::string::npos)
244 const size_t sectionStrLen = section_name_in.length() + 2;
246 const std::size_t endSectionPos = propFileContents.find(
"[", sectionTagPos + sectionStrLen);
247 const std::string fields = propFileContents.substr(sectionTagPos, endSectionPos - sectionTagPos);
249 const size_t fieldStrLen = field_name_in.length();
253 std::size_t fieldPos = fields.find(field_name_in);
255 while (fieldPos != std::string::npos)
257 const std::size_t valStartPos = fields.find(
"=", fieldPos) + 1;
259 if (fieldStrLen == valStartPos - fieldPos - 1)
261 field_str_out = fields.substr(valStartPos, fields.find(
'\n', valStartPos) - fieldPos - fieldStrLen - 1);
265 fieldPos = fields.find(field_name_in, valStartPos);
277 template<
typename T> T* loadMap(
const char*
id,
const int size,
const HWND hostHWND)
const
279 std::string clean_id(
id);
282 while (clean_id[clean_id.length() - 1] ==
'\n' || clean_id[clean_id.length() - 1] ==
'\r')
284 clean_id.erase(clean_id.length() - 1, 1);
287 T* maskColors =
new T[size*size];
289 TMap<std::string, size_t>::const_iterator offset_iter = offsetMap.find(clean_id);
291 if (offset_iter == offsetMap.end())
293 memcpy(maskColors, 0x0,
sizeof(T)*size*size);
294 MessageBox(hostHWND, clean_id.c_str(),
"Could not find the id in the bundle!", MB_ICONERROR | MB_OK);
298 size_t offset = offset_iter->second;
299 memcpy(maskColors, dataFileContents + offset,
sizeof(T)*size*size);
315 char* getDataWithOffset(
const char*
id)
const
317 std::string clean_id(
id);
319 while (clean_id[clean_id.length() - 1] ==
'\n' || clean_id[clean_id.length() - 1] ==
'\r')
321 clean_id.erase(clean_id.length() - 1, 1);
324 TMap<std::string, size_t>::const_iterator offset_iter = offsetMap.find(clean_id);
326 if (offset_iter == offsetMap.end())
330 return dataFileContents + offset_iter->second;
338 void extractOffsetsInBundle()
341 const std::size_t bundleTagPos = propFileContents.find(
"[Bundle]");
342 if (bundleTagPos == std::string::npos)
347 const std::size_t endBundlePos = propFileContents.find(
"[", bundleTagPos + 8);
348 const std::string fileOffsetsStr = propFileContents.substr(bundleTagPos + 8, endBundlePos - bundleTagPos - 8);
355 std::size_t markOfInterestPos = fileOffsetsStr.find(
".");
357 while (markOfInterestPos != std::string::npos)
359 const size_t sectionStartPos = markOfInterestPos + 1;
360 markOfInterestPos = fileOffsetsStr.find(
"=", sectionStartPos);
362 const std::string id_str = fileOffsetsStr.substr(sectionStartPos, markOfInterestPos - sectionStartPos);
365 const std::string offsetStr = fileOffsetsStr.substr(markOfInterestPos + 1, fileOffsetsStr.find(
'\n', sectionStartPos) - markOfInterestPos - 1);
367 const size_t offset = atoi(offsetStr.c_str());
369 offsetMap[id_str] = offset;
372 markOfInterestPos = fileOffsetsStr.find(
".", markOfInterestPos + 1);
377 std::string propFileContents =
"";
378 char* dataFileContents = NULL;
380 TMap<std::string, size_t> offsetMap;
383 bool keepTrackOfMemory;
387 static bool extractRawDataFromFiles(
const std::string& project_dat_filename,
const std::string& bundle_filename, std::string& priject_data_out,
388 std::string& bundle_data_out)
391 std::ifstream t(project_dat_filename);
395 priject_data_out =
"";
397 t.seekg(0, std::ios::end);
398 priject_data_out.reserve((
size_t)t.tellg());
399 t.seekg(0, std::ios::beg);
401 priject_data_out.assign((std::istreambuf_iterator<char>(t)),
402 std::istreambuf_iterator<char>());
414 std::ifstream t(bundle_filename, std::ios::binary);
418 bundle_data_out =
"";
420 t.seekg(0, std::ios::end);
421 size_t len = (size_t)t.tellg();
422 bundle_data_out.reserve(len);
424 t.seekg(0, std::ios::beg);
427 bundle_data_out.assign((std::istreambuf_iterator<char>(t)),
428 std::istreambuf_iterator<char>());
Contains all classes and functions for the VoxelFarm engine.