-
Notifications
You must be signed in to change notification settings - Fork 6
/
BspManager.cpp
234 lines (192 loc) · 5.03 KB
/
BspManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// BspManager.cpp: implementation of the CBspManager class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "sparkedit.h"
#include "BspManager.h"
#include "TagManager.h"
extern CTagManager gTagManager;
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
/*-------------------------------------------------------------------
* Name: CBspManager()
* Description:
*
*-----------------------------------------------------------------*/
CBspManager::CBspManager()
{
m_pMapFile = NULL;
m_Magic = 0;
m_pBspInfo = NULL;
m_pBsp = NULL;
m_ActiveBsp = 0;
m_BspCount = 0;
m_Version = 0;
}
/*-------------------------------------------------------------------
* Name: ~CBspManager()
* Description:
*
*-----------------------------------------------------------------*/
CBspManager::~CBspManager()
{
Cleanup();
}
/*-------------------------------------------------------------------
* Name: Initialize()
* Description:
*
*-----------------------------------------------------------------*/
void CBspManager::Initialize(CFile *pMapFile, UINT magic)
{
m_pMapFile = pMapFile;
m_Magic = magic;
}
/*-------------------------------------------------------------------
* Name: ActivateBsp()
* Description:
*
*-----------------------------------------------------------------*/
void CBspManager::ActivateBsp(int bsp_index)
{
ASSERT(bsp_index < m_BspCount);
m_ActiveBsp = bsp_index;
}
/*-------------------------------------------------------------------
* Name: LoadVisibleBspInfo()
* Description:
*
*-----------------------------------------------------------------*/
void CBspManager::LoadVisibleBspInfo(REFLEXIVE BspChunk, UINT version)
{
CString temp;
UINT hdr;
int i = 0;
m_Version = version;
if(BspChunk.Count > 0)
{
m_pBspInfo = new SCENARIO_BSP_INFO[BspChunk.Count];
m_pBsp = new CVisibleBspEx[BspChunk.Count];
m_pMapFile->Seek(BspChunk.Offset, 0);
m_pMapFile->Read(m_pBspInfo, sizeof(SCENARIO_BSP_INFO)*BspChunk.Count);
m_BspCount = BspChunk.Count;
for(int i=0; i<BspChunk.Count; i++)
{
m_pBspInfo[i].Magic -= m_pBspInfo[i].BspStart;
m_pBsp[i].Initialize(m_pMapFile, m_Magic, m_pBspInfo[i].Magic);
temp = CheckForReference(m_pMapFile, m_pBspInfo[i].BspTag.NamePtr, m_Magic);
m_BspNames.Add(temp);
m_pMapFile->Seek(m_pBspInfo[i].BspStart, 0);
m_pMapFile->Read(&hdr, sizeof(hdr));
hdr -= m_pBspInfo[i].Magic;
m_pBsp[i].LoadVisibleBsp(hdr, version);
m_pBsp[i].SampleConversionGlobals();
}
// m_pBsp[0].ConvertBsp();
}
/*
UINT *pBuf = NULL;
int bsp_index = 0;
UINT BufSize = m_pBspInfo[bsp_index].BspSize/4;
//AnalyzeFileSection(m_pMapFile, m_pBspInfo[0].BspStart, m_pBspInfo[0].BspSize, m_Magic);
pBuf = new UINT[BufSize];
m_pMapFile->Seek(m_pBspInfo[bsp_index].BspStart,0);
m_pMapFile->Read(pBuf, BufSize*4);
printf("\nAnalyzing BSP %d-------------------------------\n", bsp_index);
gTagManager.FindMatchingSubTags(0, pBuf, BufSize);
*/
}
void CBspManager::Cleanup()
{
for(int i=0; i<m_BspCount; i++)
{
m_pBsp[i].Cleanup();
}
if(m_pBspInfo)
delete [] m_pBspInfo;
m_pBspInfo = NULL;
if(m_pBsp)
delete [] m_pBsp;
m_pBsp = NULL;
m_BspNames.RemoveAll();
m_ActiveBsp = 0;
m_BspCount = 0;
m_Version = 0;
}
void CBspManager::LoadBspSections()
{
int i;
for(i=0; i<m_BspCount; i++)
{
}
}
void CBspManager::GetActiveBspCentroid(float *x, float *y, float *z)
{
*x = 0;
*y = 0;
*z = 0;
if(m_pBsp)
m_pBsp[m_ActiveBsp].GetMapCentroid(x, y, z);
}
SUBMESH_INFO* CBspManager::GetActiveBspSubmesh(UINT mesh_index)
{
SUBMESH_INFO *pMesh = NULL;
pMesh = &(m_pBsp[m_ActiveBsp].m_pMesh[mesh_index]);
return(pMesh);
}
UINT CBspManager::GetActiveBspSubmeshCount()
{
UINT mesh_count;
if(m_pBsp)
mesh_count = m_pBsp[m_ActiveBsp].m_SubMeshCount;
else
mesh_count = 0;
return(mesh_count);
}
void CBspManager::ExportActiveBspToObj(CString path)
{
if(m_pBsp)
{
if(m_Version == 5)
{
m_pBsp[m_ActiveBsp].ExportXboxMeshToObj(path);
}
else if(m_Version == 7)
{
m_pBsp[m_ActiveBsp].ExportPcMeshToObj(path);
}
}
}
CString CBspManager::GetActiveBspName()
{
return(m_BspNames[m_ActiveBsp]);
}
CString CBspManager::GetMeshInfo(int mesh_index)
{
CString info;
if(m_pBsp)
info = m_pBsp[m_ActiveBsp].GetMeshInfo(mesh_index);
else
info = "No BSP loaded";
return(info);
}
void CBspManager::ReportBspInfo(CStdioFile *pFile)
{
CString str;
str = "\n-------BSP info-------\n";
pFile->WriteString(str);
for(int i=0; i<m_BspCount; i++)
{
str.Format("BSP %d Name: %s\n", i, m_BspNames[i]);
pFile->WriteString(str);
str.Format("BSP %d Offset: 0x%08X\n", i, m_pBspInfo[i].BspStart);
pFile->WriteString(str);
str.Format("BSP %d Size: 0x%08X\n", i, m_pBspInfo[i].BspSize);
pFile->WriteString(str);
str.Format("BSP %d Magic: 0x%08X\n\n", i, m_pBspInfo[i].Magic);
pFile->WriteString(str);
}
}