Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 831 vs 832 for /trunk/Source Code/AI/PathFinding/NavMeshes/NavMeshLoader.cpp

Diff revisions: vs.
  @@ -6,8 +6,6 @@
6 6 #include "Environment/Terrain/Headers/Terrain.h"
7 7 #include "Environment/Water/Headers/Water.h"
8 8
9 - #include <fstream>
10 -
11 9 namespace Divide {
12 10 namespace AI {
13 11 namespace Navigation {
  @@ -85,27 +83,23 @@
85 83 }
86 84
87 85 bool loadMeshFile(NavModelData& outData, const char* filename) {
88 - FILE* fp = fopen(filename, "rb");
89 - if (!fp)
90 - return false;
91 -
92 - outData.setName(filename);
93 - fseek(fp, 0, SEEK_END);
94 -
95 - I32 bufSize = ftell(fp);
96 - fseek(fp, 0, SEEK_SET);
86 + STUBBED("ToDo: Rework load/save to properly use a ByteBuffer instead of this const char* hackery. -Ionut");
87 + char* buf = nullptr;
88 + char* srcEnd = nullptr;
89 +
90 + {
91 + ByteBuffer tempBuffer;
92 + if (!tempBuffer.loadFromFile(filename)) {
93 + return false;
94 + }
97 95
98 - char* buf = MemoryManager_NEW char[bufSize];
99 - if (!buf) {
100 - fclose(fp);
101 - return false;
96 + MemoryManager_NEW char[tempBuffer.size()];
97 + std::memcpy(buf, reinterpret_cast<const char*>(tempBuffer.contents()), tempBuffer.size());
98 + srcEnd = buf + tempBuffer.size();
102 99 }
103 100
104 - fread(buf, bufSize, 1, fp);
105 - fclose(fp);
106 -
107 101 char* src = buf;
108 - char* srcEnd = buf + bufSize;
102 +
109 103 char row[512];
110 104 I32 face[32];
111 105 F32 x, y, z;
  @@ -179,28 +173,21 @@
179 173 if (!inData.getVertCount() || !inData.getTriCount())
180 174 return false;
181 175
182 - // Create the file if it doesn't exists
183 - std::ofstream myfile;
184 - myfile.open(filename, std::fstream::out);
185 - if (!myfile.is_open()) {
186 - return false;
187 - }
188 -
176 + ByteBuffer tempBuffer;
189 177 F32* vstart = inData._vertices;
190 178 I32* tstart = inData._triangles;
191 179 for (U32 i = 0; i < inData.getVertCount(); i++) {
192 180 F32* vp = vstart + i * 3;
193 - myfile << "v " << (*(vp)) << " " << *(vp + 1) << " " << (*(vp + 2))
194 - << "\n";
181 + tempBuffer << "v " << (*(vp)) << " " << *(vp + 1) << " " << (*(vp + 2))
182 + << "\n";
195 183 }
196 184 for (U32 i = 0; i < inData.getTriCount(); i++) {
197 185 I32* tp = tstart + i * 3;
198 - myfile << "f " << (*(tp) + 1) << " " << (*(tp + 1) + 1) << " "
199 - << (*(tp + 2) + 1) << "\n";
186 + tempBuffer << "f " << (*(tp) + 1) << " " << (*(tp + 1) + 1) << " "
187 + << (*(tp + 2) + 1) << "\n";
200 188 }
201 189
202 - myfile.close();
203 - return true;
190 + return tempBuffer.dumpToFile(filename);
204 191 }
205 192
206 193 NavModelData mergeModels(NavModelData& a,