Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
278 строк · 9.7 Кб
1
/*
2
 * Copyright (C) 2011-2016 Project SkyFire <http://www.projectskyfire.org/>
3
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
4
 * Copyright (C) 2005-2016 MaNGOS <http://getmangos.com/>
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License as published by the
8
 * Free Software Foundation; either version 3 of the License, or (at your
9
 * option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
 * more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along
17
 * with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "IntermediateValues.h"
21

22
namespace MMAP
23
{
24
    IntermediateValues::~IntermediateValues()
25
    {
26
        rcFreeCompactHeightfield(compactHeightfield);
27
        rcFreeHeightField(heightfield);
28
        rcFreeContourSet(contours);
29
        rcFreePolyMesh(polyMesh);
30
        rcFreePolyMeshDetail(polyMeshDetail);
31
    }
32

33
    void IntermediateValues::writeIV(uint32 mapID, uint32 tileX, uint32 tileY)
34
    {
35
        char fileName[255];
36
        char tileString[25];
37
        sprintf(tileString, "[%02u,%02u]: ", tileX, tileY);
38

39
        printf("%sWriting debug output...                       \r", tileString);
40

41
        std::string name("meshes/%04u_%02i_%02i.");
42

43
#define DEBUG_WRITE(fileExtension,data) \
44
    do { \
45
    sprintf(fileName, (name + fileExtension).c_str(), mapID, tileY, tileX); \
46
    FILE* file = fopen(fileName, "wb"); \
47
    if (!file) \
48
        { \
49
        char message[1024]; \
50
        sprintf(message, "%sFailed to open %s for writing!\n",  tileString, fileName); \
51
        perror(message); \
52
        } \
53
            else \
54
            debugWrite(file, data); \
55
            if (file) fclose(file); \
56
            printf("%sWriting debug output...                       \r", tileString); \
57
    } while (false)
58

59
        if (heightfield)
60
            DEBUG_WRITE("hf", heightfield);
61
        if (compactHeightfield)
62
            DEBUG_WRITE("chf", compactHeightfield);
63
        if (contours)
64
            DEBUG_WRITE("cs", contours);
65
        if (polyMesh)
66
            DEBUG_WRITE("pmesh", polyMesh);
67
        if (polyMeshDetail)
68
            DEBUG_WRITE("dmesh", polyMeshDetail);
69

70
#undef DEBUG_WRITE
71
    }
72

73
    void IntermediateValues::debugWrite(FILE* file, const rcHeightfield* mesh)
74
    {
75
        if (!file || !mesh)
76
            return;
77

78
        fwrite(&(mesh->cs), sizeof(float), 1, file);
79
        fwrite(&(mesh->ch), sizeof(float), 1, file);
80
        fwrite(&(mesh->width), sizeof(int), 1, file);
81
        fwrite(&(mesh->height), sizeof(int), 1, file);
82
        fwrite(mesh->bmin, sizeof(float), 3, file);
83
        fwrite(mesh->bmax, sizeof(float), 3, file);
84

85
        for (int y = 0; y < mesh->height; ++y)
86
            for (int x = 0; x < mesh->width; ++x)
87
            {
88
                rcSpan* span = mesh->spans[x+y*mesh->width];
89

90
                // first, count the number of spans
91
                int spanCount = 0;
92
                while (span)
93
                {
94
                    spanCount++;
95
                    span = span->next;
96
                }
97

98
                // write the span count
99
                fwrite(&spanCount, sizeof(int), 1, file);
100

101
                // write the spans
102
                span = mesh->spans[x+y*mesh->width];
103
                while (span)
104
                {
105
                    fwrite(span, sizeof(rcSpan), 1, file);
106
                    span = span->next;
107
                }
108
            }
109
    }
110

111
    void IntermediateValues::debugWrite(FILE* file, const rcCompactHeightfield* chf)
112
    {
113
        if (!file | !chf)
114
            return;
115

116
        fwrite(&(chf->width), sizeof(chf->width), 1, file);
117
        fwrite(&(chf->height), sizeof(chf->height), 1, file);
118
        fwrite(&(chf->spanCount), sizeof(chf->spanCount), 1, file);
119

120
        fwrite(&(chf->walkableHeight), sizeof(chf->walkableHeight), 1, file);
121
        fwrite(&(chf->walkableClimb), sizeof(chf->walkableClimb), 1, file);
122

123
        fwrite(&(chf->maxDistance), sizeof(chf->maxDistance), 1, file);
124
        fwrite(&(chf->maxRegions), sizeof(chf->maxRegions), 1, file);
125

126
        fwrite(chf->bmin, sizeof(chf->bmin), 1, file);
127
        fwrite(chf->bmax, sizeof(chf->bmax), 1, file);
128

129
        fwrite(&(chf->cs), sizeof(chf->cs), 1, file);
130
        fwrite(&(chf->ch), sizeof(chf->ch), 1, file);
131

132
        int tmp = 0;
133
        if (chf->cells) tmp |= 1;
134
        if (chf->spans) tmp |= 2;
135
        if (chf->dist) tmp |= 4;
136
        if (chf->areas) tmp |= 8;
137

138
        fwrite(&tmp, sizeof(tmp), 1, file);
139

140
        if (chf->cells)
141
            fwrite(chf->cells, sizeof(rcCompactCell), chf->width*chf->height, file);
142
        if (chf->spans)
143
            fwrite(chf->spans, sizeof(rcCompactSpan), chf->spanCount, file);
144
        if (chf->dist)
145
            fwrite(chf->dist, sizeof(unsigned short), chf->spanCount, file);
146
        if (chf->areas)
147
            fwrite(chf->areas, sizeof(unsigned char), chf->spanCount, file);
148
    }
149

150
    void IntermediateValues::debugWrite(FILE* file, const rcContourSet* cs)
151
    {
152
        if (!file || !cs)
153
            return;
154

155
        fwrite(&(cs->cs), sizeof(float), 1, file);
156
        fwrite(&(cs->ch), sizeof(float), 1, file);
157
        fwrite(cs->bmin, sizeof(float), 3, file);
158
        fwrite(cs->bmax, sizeof(float), 3, file);
159
        fwrite(&(cs->nconts), sizeof(int), 1, file);
160
        for (int i = 0; i < cs->nconts; ++i)
161
        {
162
            fwrite(&cs->conts[i].area, sizeof(unsigned char), 1, file);
163
            fwrite(&cs->conts[i].reg, sizeof(unsigned short), 1, file);
164
            fwrite(&cs->conts[i].nverts, sizeof(int), 1, file);
165
            fwrite(cs->conts[i].verts, sizeof(int), cs->conts[i].nverts*4, file);
166
            fwrite(&cs->conts[i].nrverts, sizeof(int), 1, file);
167
            fwrite(cs->conts[i].rverts, sizeof(int), cs->conts[i].nrverts*4, file);
168
        }
169
    }
170

171
    void IntermediateValues::debugWrite(FILE* file, const rcPolyMesh* mesh)
172
    {
173
        if (!file || !mesh)
174
            return;
175

176
        fwrite(&(mesh->cs), sizeof(float), 1, file);
177
        fwrite(&(mesh->ch), sizeof(float), 1, file);
178
        fwrite(&(mesh->nvp), sizeof(int), 1, file);
179
        fwrite(mesh->bmin, sizeof(float), 3, file);
180
        fwrite(mesh->bmax, sizeof(float), 3, file);
181
        fwrite(&(mesh->nverts), sizeof(int), 1, file);
182
        fwrite(mesh->verts, sizeof(unsigned short), mesh->nverts*3, file);
183
        fwrite(&(mesh->npolys), sizeof(int), 1, file);
184
        fwrite(mesh->polys, sizeof(unsigned short), mesh->npolys*mesh->nvp*2, file);
185
        fwrite(mesh->flags, sizeof(unsigned short), mesh->npolys, file);
186
        fwrite(mesh->areas, sizeof(unsigned char), mesh->npolys, file);
187
        fwrite(mesh->regs, sizeof(unsigned short), mesh->npolys, file);
188
    }
189

190
    void IntermediateValues::debugWrite(FILE* file, const rcPolyMeshDetail* mesh)
191
    {
192
        if (!file || !mesh)
193
            return;
194

195
        fwrite(&(mesh->nverts), sizeof(int), 1, file);
196
        fwrite(mesh->verts, sizeof(float), mesh->nverts*3, file);
197
        fwrite(&(mesh->ntris), sizeof(int), 1, file);
198
        fwrite(mesh->tris, sizeof(char), mesh->ntris*4, file);
199
        fwrite(&(mesh->nmeshes), sizeof(int), 1, file);
200
        fwrite(mesh->meshes, sizeof(int), mesh->nmeshes*4, file);
201
    }
202

203
    void IntermediateValues::generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
204
    {
205
        char objFileName[255];
206
        sprintf(objFileName, "meshes/map%04u_%02u_%02u.obj", mapID, tileY, tileX);
207

208
        FILE* objFile = fopen(objFileName, "wb");
209
        if (!objFile)
210
        {
211
            char message[1024];
212
            sprintf(message, "Failed to open %s for writing!\n", objFileName);
213
            perror(message);
214
            return;
215
        }
216

217
        G3D::Array<float> allVerts;
218
        G3D::Array<int> allTris;
219

220
        allTris.append(meshData.liquidTris);
221
        allVerts.append(meshData.liquidVerts);
222
        TerrainBuilder::copyIndices(meshData.solidTris, allTris, allVerts.size() / 3);
223
        allVerts.append(meshData.solidVerts);
224

225
        float* verts = allVerts.getCArray();
226
        int vertCount = allVerts.size() / 3;
227
        int* tris = allTris.getCArray();
228
        int triCount = allTris.size() / 3;
229

230
        for (int i = 0; i < allVerts.size() / 3; i++)
231
            fprintf(objFile, "v %f %f %f\n", verts[i*3], verts[i*3 + 1], verts[i*3 + 2]);
232

233
        for (int i = 0; i < allTris.size() / 3; i++)
234
            fprintf(objFile, "f %i %i %i\n", tris[i*3] + 1, tris[i*3 + 1] + 1, tris[i*3 + 2] + 1);
235

236
        fclose(objFile);
237

238

239
        char tileString[25];
240
        sprintf(tileString, "[%02u,%02u]: ", tileY, tileX);
241
        printf("%sWriting debug output...                       \r", tileString);
242

243
        sprintf(objFileName, "meshes/%04u.map", mapID);
244

245
        objFile = fopen(objFileName, "wb");
246
        if (!objFile)
247
        {
248
            char message[1024];
249
            sprintf(message, "Failed to open %s for writing!\n", objFileName);
250
            perror(message);
251
            return;
252
        }
253

254
        char b = '\0';
255
        fwrite(&b, sizeof(char), 1, objFile);
256
        fclose(objFile);
257

258
        sprintf(objFileName, "meshes/%04u_%02u_%02u.mesh", mapID, tileY, tileX);
259
        objFile = fopen(objFileName, "wb");
260
        if (!objFile)
261
        {
262
            char message[1024];
263
            sprintf(message, "Failed to open %s for writing!\n", objFileName);
264
            perror(message);
265
            return;
266
        }
267

268
        fwrite(&vertCount, sizeof(int), 1, objFile);
269
        fwrite(verts, sizeof(float), vertCount*3, objFile);
270
        fflush(objFile);
271

272
        fwrite(&triCount, sizeof(int), 1, objFile);
273
        fwrite(tris, sizeof(int), triCount*3, objFile);
274
        fflush(objFile);
275

276
        fclose(objFile);
277
    }
278
}
279

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.