forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW3DDisplayStringManager.cpp
More file actions
234 lines (189 loc) · 7.56 KB
/
W3DDisplayStringManager.cpp
File metadata and controls
234 lines (189 loc) · 7.56 KB
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
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: W3DDisplayStringManager.cpp //////////////////////////////////////////////////////////////
// Created: Colin Day, July 2001
// Desc: Display string Manager for W3D
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include "Common/Debug.h"
#include "GameClient/GameClient.h"
#include "GameClient/GameText.h"
#include "GameClient/DisplayString.h"
#include "GameClient/DrawGroupInfo.h"
#include "GameClient/GlobalLanguage.h"
#include "W3DDevice/GameClient/W3DDisplayStringManager.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
W3DDisplayStringManager::W3DDisplayStringManager()
{
for (Int i = 0; i < MAX_GROUPS; ++i)
{
m_groupNumeralStrings[i] = nullptr;
}
m_formationLetterDisplayString = nullptr;
}
//-------------------------------------------------------------------------------------------------
W3DDisplayStringManager::~W3DDisplayStringManager()
{
for (Int i = 0; i < MAX_GROUPS; ++i)
{
if (m_groupNumeralStrings[i])
freeDisplayString(m_groupNumeralStrings[i]);
m_groupNumeralStrings[i] = nullptr;
}
if (m_formationLetterDisplayString)
freeDisplayString( m_formationLetterDisplayString );
m_formationLetterDisplayString = nullptr;
}
//-------------------------------------------------------------------------------------------------
void W3DDisplayStringManager::postProcessLoad()
{
// Get the font.
GameFont *font = TheFontLibrary->getFont(
TheDrawGroupInfo->m_fontName,
TheDrawGroupInfo->m_fontSize,
TheDrawGroupInfo->m_fontIsBold );
for (Int i = 0; i < MAX_GROUPS; ++i)
{
m_groupNumeralStrings[i] = newDisplayString();
m_groupNumeralStrings[i]->setFont(font);
AsciiString displayNumber;
displayNumber.format("NUMBER:%d", i);
m_groupNumeralStrings[i]->setText(TheGameText->fetch(displayNumber));
}
m_formationLetterDisplayString = newDisplayString();
m_formationLetterDisplayString->setFont(font);
AsciiString displayLetter;
displayLetter.format("LABEL:FORMATION");
m_formationLetterDisplayString->setText(TheGameText->fetch(displayLetter));
}
//-------------------------------------------------------------------------------------------------
/** Allocate a new display string and tie it to the master list so we
* can keep track of it */
//-------------------------------------------------------------------------------------------------
DisplayString *W3DDisplayStringManager::newDisplayString()
{
DisplayString *newString = newInstance(W3DDisplayString);
// sanity
if( newString == nullptr )
{
DEBUG_LOG(( "newDisplayString: Could not allocate new W3D display string" ));
assert( 0 );
return nullptr;
}
// assign a default font
if (TheGlobalLanguageData && TheGlobalLanguageData->m_defaultDisplayStringFont.name.isNotEmpty())
{
newString->setFont(TheFontLibrary->getFont(
TheGlobalLanguageData->m_defaultDisplayStringFont.name,
TheGlobalLanguageData->m_defaultDisplayStringFont.size,
TheGlobalLanguageData->m_defaultDisplayStringFont.bold) );
}
else
newString->setFont( TheFontLibrary->getFont( "Times New Roman", 12, FALSE ) );
// link string to list
link( newString );
// return our new string
return newString;
}
//-------------------------------------------------------------------------------------------------
/** Remove a display string from the master list and delete the data */
//-------------------------------------------------------------------------------------------------
void W3DDisplayStringManager::freeDisplayString( DisplayString *string )
{
// sanity
if( string == nullptr )
return;
// unlink
unLink( string );
// if the string happens to fall where our current checkpoint was, set the checkpoint to null
if ( m_currentCheckpoint == string) {
m_currentCheckpoint = nullptr;
}
// free data
deleteInstance(string);
}
//-------------------------------------------------------------------------------------------------
/** Update method for our display string Manager ... if it's been too
* long since the last time a string has been rendered, we will free
* the rendering resources of the string, if it needs to render again
* the DisplayString will have to rebuild the rendering data before
* the draw will work */
//-------------------------------------------------------------------------------------------------
void W3DDisplayStringManager::update()
{
// call base in case we add something later
DisplayStringManager::update();
W3DDisplayString *string = static_cast<W3DDisplayString *>(m_stringList);
// if the m_currentCheckpoint is valid, use it for the starting point for the search
if (m_currentCheckpoint) {
string = static_cast<W3DDisplayString *>(m_currentCheckpoint);
}
UnsignedInt currFrame = TheGameClient->getFrame();
const UnsignedInt w3dCleanupTime = 60; /** any string not rendered after
this many frames will have its
render resources freed */
int numStrings = 10;
// looping through all the strings eats up a lot of ambient time. Instead,
// loop through 10 (arbitrarily chosen) or till the end is hit.
while ( numStrings-- && string)
{
//
// has this string "expired" in terms of using resources, a string
// with a resource frame of zero isn't using any resources at all
//
if( string->m_lastResourceFrame != 0 &&
currFrame - string->m_lastResourceFrame > w3dCleanupTime )
{
// free the resources
string->m_textRenderer.Reset();
string->m_textRendererHotKey.Reset();
//
// mark data in the string as changed so that if it needs to
// be drawn again it will know to reconstruct the render data
//
string->m_textChanged = TRUE;
//
// set the last resource frame to zero, this allows us to ignore it
// in future cleanup passes of this update routine
//
string->m_lastResourceFrame = 0;
}
// move to next string
string = static_cast<W3DDisplayString *>(string->next());
}
// reset the starting point for our next search
m_currentCheckpoint = string;
}
//-------------------------------------------------------------------------------------------------
DisplayString *W3DDisplayStringManager::getGroupNumeralString( Int numeral )
{
if (numeral < 0 || numeral > MAX_GROUPS - 1 )
{
DEBUG_CRASH(("Numeral '%d' out of range.", numeral));
return m_groupNumeralStrings[0];
}
return m_groupNumeralStrings[numeral];
}