MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / SaveCollisionNormals

Function SaveCollisionNormals

Source/Main/engine.cpp:4213–4270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4211static const char* kCollisionNormalIdentifier = "overgrowth_level_collision_normals";
4212
4213void SaveCollisionNormals(const SceneGraph* scenegraph) {
4214 std::string path = scenegraph->level_path_.GetOriginalPathStr() + ".col_norm";
4215 if (scenegraph->level_path_.source != kAbsPath) {
4216 if (!config["allow_game_dir_save"].toBool()) {
4217 path = GetWritePath(scenegraph->level_path_.mod_source) + path;
4218 }
4219 }
4220 std::string temp_path = GetWritePath(CoreGameModID).c_str();
4221 temp_path += "temp_collision_normals";
4222 FILE* file = my_fopen(temp_path.c_str(), "wb");
4223 if (file) {
4224 fwrite(kCollisionNormalIdentifier, strlen(kCollisionNormalIdentifier), 1, file);
4225 fwrite(&kCollisionNormalVersion, sizeof(int), 1, file);
4226 int num_objects = 0;
4227 for (auto eo : scenegraph->visible_static_meshes_) {
4228 if (eo->GetCollisionModelID() != -1) {
4229 ++num_objects;
4230 }
4231 }
4232 fwrite(&num_objects, sizeof(int), 1, file);
4233 for (auto eo : scenegraph->visible_static_meshes_) {
4234 if (eo->GetCollisionModelID() != -1) {
4235 int id = eo->GetID();
4236 fwrite(&id, sizeof(int), 1, file);
4237 int num_normals = (int)eo->normal_override_custom.size();
4238 fwrite(&num_normals, sizeof(int), 1, file);
4239 if (num_normals > 0) {
4240 fwrite(&eo->normal_override_custom[0], sizeof(vec4) * num_normals, 1, file);
4241 }
4242 int num_ledge_lines = (int)eo->ledge_lines.size();
4243 fwrite(&num_ledge_lines, sizeof(int), 1, file);
4244 if (num_ledge_lines > 0) {
4245 fwrite(&eo->ledge_lines[0], sizeof(int) * num_ledge_lines, 1, file);
4246 }
4247 }
4248 }
4249 fclose(file);
4250
4251 Zip(temp_path, temp_path + ".zip", "data", _YES_OVERWRITE);
4252 // void UnZip(const std::string &zip_file_path, ExpandedZipFile &expanded_zip_file);
4253
4254 std::string src = temp_path + ".zip";
4255 std::string dst = path + ".zip";
4256 if (movefile(src.c_str(), dst.c_str())) {
4257 LOGI << "Creating parent dirs before trying to move file again" << std::endl;
4258 CreateParentDirs(dst);
4259 if (movefile(src.c_str(), dst.c_str())) {
4260#ifndef NO_ERR
4261 DisplayError("Error",
4262 (std::string("Problem moving file \"") + strerror(errno) + "\". From " +
4263 src +
4264 " to " + dst)
4265 .c_str());
4266#endif
4267 }
4268 }
4269 }
4270}

Callers 1

DrawImGuiFunction · 0.85

Calls 12

GetWritePathFunction · 0.85
my_fopenFunction · 0.85
ZipFunction · 0.85
movefileFunction · 0.85
CreateParentDirsFunction · 0.85
GetOriginalPathStrMethod · 0.80
toBoolMethod · 0.80
GetCollisionModelIDMethod · 0.80
DisplayErrorFunction · 0.50
c_strMethod · 0.45
GetIDMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected