Skyscraper 2.0
textures.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - Script Processor - Textures Section
3 Copyright (C)2003-2024 Ryan Thoryk
4 https://www.skyscrapersim.net
5 https://sourceforge.net/projects/skyscraper/
6 Contact - ryan@skyscrapersim.net
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*/
22
23#include "globals.h"
24#include "sbs.h"
25#include "enginecontext.h"
26#include "texture.h"
27#include "scriptproc.h"
28#include "section.h"
29
30using namespace SBS;
31
32namespace Skyscraper {
33
38
40{
41 //Process Textures
42
43 TextureManager *texturemanager = Simcore->GetTextureManager();
44
45 //Load command
46 if (StartsWithNoCase(LineData, "load "))
47 {
48 //get data
49 int params = SplitData(LineData, 5, false);
50
51 if (params != 4 && params != 5)
52 return ScriptError("Incorrect number of )parameters");
53
54 //check numeric values
55 for (int i = 2; i <= 3; i++)
56 {
57 if (!IsNumeric(tempdata[i]))
58 return ScriptError("Invalid value: " + tempdata[i]);
59 }
60 parent->CheckFile(tempdata[0]);
61 if (params == 4)
62 texturemanager->LoadTexture(tempdata[0], tempdata[1], ToFloat(tempdata[2]), ToFloat(tempdata[3]));
63 else
64 texturemanager->LoadTexture(tempdata[0], tempdata[1], ToFloat(tempdata[2]), ToFloat(tempdata[3]), true, ToBool(tempdata[4]));
65 return sNextLine;
66 }
67
68 //LoadAnimated command
69 if (StartsWithNoCase(LineData, "loadanimated"))
70 {
71 //get data
72 int params = SplitData(LineData, 12, false);
73
74 if (params < 6)
75 return ScriptError("Incorrect number of parameters");
76
77 bool force;
78 if (IsNumeric(tempdata[params - 1]) == true && IsNumeric(tempdata[params - 2]) == true)
79 force = false;
80 else
81 force = true;
82
83 //check numeric values
84 if (force == true)
85 {
86 for (int i = (params - 4); i <= (params - 2); i++)
87 {
88 if (!IsNumeric(tempdata[i]))
89 return ScriptError("Invalid value: " + tempdata[i]);
90 }
91 }
92 else
93 {
94 for (int i = (params - 3); i <= (params - 1); i++)
95 {
96 if (!IsNumeric(tempdata[i]))
97 return ScriptError("Invalid value: " + tempdata[i]);
98 }
99 }
100
101 std::vector<std::string> filenames;
102 if (force == true)
103 {
104 for (int i = 0; i < params - 5; i++)
105 filenames.emplace_back(tempdata[i]);
106 }
107 else
108 {
109 for (int i = 0; i < params - 4; i++)
110 filenames.emplace_back(tempdata[i]);
111 }
112
113 //check existence of files
114 for (size_t i = 0; i < filenames.size(); i++)
115 parent->CheckFile(filenames[i]);
116
117 if (force == false)
118 texturemanager->LoadAnimatedTexture(filenames, tempdata[params - 4], ToFloat(tempdata[params - 3]), ToFloat(tempdata[params - 2]), ToFloat(tempdata[params - 1]));
119 else
120 texturemanager->LoadAnimatedTexture(filenames, tempdata[params - 5], ToFloat(tempdata[params - 4]), ToFloat(tempdata[params - 3]), ToFloat(tempdata[params - 2]), true, ToBool(tempdata[params - 1]));
121 return sNextLine;
122 }
123
124 //LoadAlphaBlend command
125 if (StartsWithNoCase(LineData, "loadalphablend"))
126 {
127 //get data
128 int params = SplitData(LineData, 14, false);
129
130 if (params != 7 && params != 8)
131 return ScriptError("Incorrect number of parameters");
132
133 //check numeric values
134 for (int i = 5; i <= 6; i++)
135 {
136 if (!IsNumeric(tempdata[i]))
137 return ScriptError("Invalid value: " + tempdata[i]);
138 }
139
140 //check existence of files
141 parent->CheckFile(tempdata[0]);
142 parent->CheckFile(tempdata[1]);
143 parent->CheckFile(tempdata[2]);
144
145 if (params == 7)
146 texturemanager->LoadAlphaBlendTexture(tempdata[0], tempdata[1], tempdata[2], tempdata[3], ToBool(tempdata[4]), ToFloat(tempdata[5]), ToFloat(tempdata[6]));
147 else
148 texturemanager->LoadAlphaBlendTexture(tempdata[0], tempdata[1], tempdata[2], tempdata[3], ToBool(tempdata[4]), ToFloat(tempdata[5]), ToFloat(tempdata[6]), true, ToBool(tempdata[7]));
149 return sNextLine;
150 }
151
152 //LoadMaterial command
153 if (StartsWithNoCase(LineData, "loadmaterial"))
154 {
155 //get data
156 int params = SplitData(LineData, 12, false);
157
158 if (params != 4 && params != 5)
159 return ScriptError("Incorrect number of parameters");
160
161 //check numeric values
162 for (int i = 2; i <= 3; i++)
163 {
164 if (!IsNumeric(tempdata[i]))
165 return ScriptError("Invalid value: " + tempdata[i]);
166 }
167 if (params == 4)
168 texturemanager->LoadMaterial(tempdata[0], tempdata[1], ToFloat(tempdata[2]), ToFloat(tempdata[3]));
169 else
170 texturemanager->LoadMaterial(tempdata[0], tempdata[1], ToFloat(tempdata[2]), ToFloat(tempdata[3]), true, ToBool(tempdata[4]));
171 return sNextLine;
172 }
173
174 //LoadRange command
175 if (StartsWithNoCase(LineData, "loadrange"))
176 {
177 //get data
178 int params = SplitData(LineData, 9, false);
179
180 if (params != 6 && params != 7)
181 return ScriptError("Incorrect number of parameters");
182
183 //check numeric values
184 for (int i = 0; i <= 5; i++)
185 {
186 if (i == 2)
187 i = 4;
188 if (!IsNumeric(tempdata[i]))
189 return ScriptError("Invalid value: " + tempdata[i]);
190 }
191 int RangeL = ToInt(tempdata[0]);
192 int RangeH = ToInt(tempdata[1]);
193 std::string filename, buffer, name;
194 for (int Current = RangeL; Current <= RangeH; Current++)
195 {
196 filename = tempdata[2];
197 buffer = ToString(Current);
198 TrimString(buffer);
199 ReplaceAll(filename, "%number%", buffer);
200 name = tempdata[3];
201 ReplaceAll(name, "%number%", buffer);
202 parent->CheckFile(filename);
203 if (params == 6)
204 texturemanager->LoadTexture(filename, name, ToFloat(tempdata[4]), ToFloat(tempdata[5]));
205 else
206 texturemanager->LoadTexture(filename, name, ToFloat(tempdata[4]), ToFloat(tempdata[5]), true, ToBool(tempdata[6]));
207 }
208 return sNextLine;
209 }
210
211 //AddText command
212 if (StartsWithNoCase(LineData, "addtext "))
213 {
214 //get data
215 int params = SplitData(LineData, 8, false);
216
217 if (params != 14 && params != 15)
218 return ScriptError("Incorrect number of parameters");
219
220 //check numeric values
221 for (int i = 3; i <= 13; i++)
222 {
223 if (i == 4)
224 i = 5;
225 if (i == 9)
226 i = 11;
227
228 if (!IsNumeric(tempdata[i]))
229 return ScriptError("Invalid value: " + tempdata[i]);
230 }
231 std::string filename = tempdata[2];
232 TrimString(filename);
233 filename.insert(0, "data/fonts/");
234 parent->CheckFile(filename);
235 if (params == 14)
236 texturemanager->AddTextToTexture(tempdata[0], tempdata[1], filename, ToFloat(tempdata[3]), tempdata[4], ToInt(tempdata[5]), ToInt(tempdata[6]), ToInt(tempdata[7]), ToInt(tempdata[8]), tempdata[9], tempdata[10], ToInt(tempdata[11]), ToInt(tempdata[12]), ToInt(tempdata[13]));
237 else
238 texturemanager->AddTextToTexture(tempdata[0], tempdata[1], filename, ToFloat(tempdata[3]), tempdata[4], ToInt(tempdata[5]), ToInt(tempdata[6]), ToInt(tempdata[7]), ToInt(tempdata[8]), tempdata[9], tempdata[10], ToInt(tempdata[11]), ToInt(tempdata[12]), ToInt(tempdata[13]), true, ToBool(tempdata[14]));
239 return sNextLine;
240 }
241
242 //AddTextRange command
243 if (StartsWithNoCase(LineData, "addtextrange"))
244 {
245 //get data
246 int params = SplitData(LineData, 13, false);
247
248 if (params != 16 && params != 17)
249 return ScriptError("Incorrect number of parameters");
250
251 //check numeric values
252 for (int i = 0; i <= 15; i++)
253 {
254 if (i == 2)
255 i = 5;
256 if (i == 6)
257 i = 7;
258 if (i == 11)
259 i = 13;
260
261 if (!IsNumeric(tempdata[i]))
262 return ScriptError("Invalid value: " + tempdata[i]);
263 }
264 int RangeL = ToInt(tempdata[0]);
265 int RangeH = ToInt(tempdata[1]);
266 std::string orig_line = LineData;
267 for (int Current = RangeL; Current <= RangeH; Current++)
268 {
269 std::string num = ToString(Current);
270 TrimString(num);
271 LineData = orig_line;
272 ReplaceAll(LineData, "%number%", num);
273
274 //get data
275 int params = SplitData(LineData, 13, false);
276
277 std::string filename = tempdata[4];
278 TrimString(filename);
279 filename.insert(0, "data/fonts/");
280 parent->CheckFile(filename);
281 if (params == 16)
282 texturemanager->AddTextToTexture(tempdata[2], tempdata[3], filename, ToFloat(tempdata[5]), tempdata[6], ToInt(tempdata[7]), ToInt(tempdata[8]), ToInt(tempdata[9]), ToInt(tempdata[10]), tempdata[11], tempdata[12], ToInt(tempdata[13]), ToInt(tempdata[14]), ToInt(tempdata[15]));
283 else
284 texturemanager->AddTextToTexture(tempdata[2], tempdata[3], filename, ToFloat(tempdata[5]), tempdata[6], ToInt(tempdata[7]), ToInt(tempdata[8]), ToInt(tempdata[9]), ToInt(tempdata[10]), tempdata[11], tempdata[12], ToInt(tempdata[13]), ToInt(tempdata[14]), ToInt(tempdata[15]), true, ToBool(tempdata[16]));
285 }
286 return sNextLine;
287 }
288
289 //LoadCropped command
290 if (StartsWithNoCase(LineData, "loadcropped"))
291 {
292 //get data
293 int params = SplitData(LineData, 12, false);
294
295 if (params != 8 && params != 9)
296 return ScriptError("Incorrect number of parameters");
297
298 //check numeric values
299 for (int i = 2; i <= 7; i++)
300 {
301 if (!IsNumeric(tempdata[i]))
302 return ScriptError("Invalid value: " + tempdata[i]);
303 }
304 parent->CheckFile(tempdata[0]);
305 if (params == 8)
306 texturemanager->LoadTextureCropped(tempdata[0], tempdata[1], ToInt(tempdata[2]), ToInt(tempdata[3]), ToInt(tempdata[4]), ToInt(tempdata[5]), ToFloat(tempdata[6]), ToFloat(tempdata[7]));
307 else
308 texturemanager->LoadTextureCropped(tempdata[0], tempdata[1], ToInt(tempdata[2]), ToInt(tempdata[3]), ToInt(tempdata[4]), ToInt(tempdata[5]), ToFloat(tempdata[6]), ToFloat(tempdata[7]), ToBool(tempdata[8]));
309 return sNextLine;
310 }
311
312 //AddOverlay command
313 if (StartsWithNoCase(LineData, "addoverlay"))
314 {
315 //get data
316 int params = SplitData(LineData, 11, false);
317
318 if (params != 9 && params != 10)
319 return ScriptError("Incorrect number of parameters");
320
321 //check numeric values
322 for (int i = 3; i <= 8; i++)
323 {
324 if (!IsNumeric(tempdata[i]))
325 return ScriptError("Invalid value: " + tempdata[i]);
326 }
327 if (params == 9)
328 texturemanager->AddTextureOverlay(tempdata[0], tempdata[1], tempdata[2], ToInt(tempdata[3]), ToInt(tempdata[4]), ToInt(tempdata[5]), ToInt(tempdata[6]), ToFloat(tempdata[7]), ToFloat(tempdata[8]));
329 else
330 texturemanager->AddTextureOverlay(tempdata[0], tempdata[1], tempdata[2], ToInt(tempdata[3]), ToInt(tempdata[4]), ToInt(tempdata[5]), ToInt(tempdata[6]), ToFloat(tempdata[7]), ToFloat(tempdata[8]), true, ToBool(tempdata[9]));
331 return sNextLine;
332 }
333
334 //SetLighting command
335 if (StartsWithNoCase(LineData, "setlighting"))
336 {
337 //get data
338 int params = SplitData(LineData, 12, false);
339
340 if (params != 3)
341 return ScriptError("Incorrect number of parameters");
342
343 //check numeric values
344 for (int i = 0; i <= 2; i++)
345 {
346 if (!IsNumeric(tempdata[i]))
347 return ScriptError("Invalid value: " + tempdata[i]);
348 }
349
350 //stop here if in Check mode
351 if (config->CheckScript == true)
352 return sNextLine;
353
354 Simcore->SetLighting(ToFloat(tempdata[0]), ToFloat(tempdata[1]), ToFloat(tempdata[2]));
355 return sNextLine;
356 }
357
358 //Rotate command
359 if (StartsWithNoCase(LineData, "rotate "))
360 {
361 //get data
362 int params = SplitData(LineData, 7, false);
363
364 if (params != 2)
365 return ScriptError("Incorrect number of parameters");
366
367 //check numeric value
368 if (!IsNumeric(tempdata[1]))
369 return ScriptError("Invalid value: " + tempdata[1]);
370
371 //stop here if in Check mode
372 if (config->CheckScript == true)
373 return sNextLine;
374
375 texturemanager->RotateTexture(tempdata[0], ToFloat(tempdata[1]));
376 return sNextLine;
377 }
378
379 //RotateAnim command
380 if (StartsWithNoCase(LineData, "rotateanim"))
381 {
382 //get data
383 int params = SplitData(LineData, 10, false);
384
385 if (params != 2)
386 return ScriptError("Incorrect number of parameters");
387
388 //check numeric value
389 if (!IsNumeric(tempdata[1]))
390 return ScriptError("Invalid value: " + tempdata[1]);
391
392 //stop here if in Check mode
393 if (config->CheckScript == true)
394 return sNextLine;
395
396 texturemanager->RotateAnimTexture(tempdata[0], ToFloat(tempdata[1]));
397 return sNextLine;
398 }
399
400 //Scroll command
401 if (StartsWithNoCase(LineData, "scroll "))
402 {
403 //get data
404 int params = SplitData(LineData, 7, false);
405
406 if (params != 3)
407 return ScriptError("Incorrect number of parameters");
408
409 //check numeric values
410 for (int i = 1; i <= 2; i++)
411 {
412 if (!IsNumeric(tempdata[i]))
413 return ScriptError("Invalid value: " + tempdata[i]);
414 }
415
416 //stop here if in Check mode
417 if (config->CheckScript == true)
418 return sNextLine;
419
420 texturemanager->ScrollTexture(tempdata[0], ToFloat(tempdata[1]), ToFloat(tempdata[2]));
421 return sNextLine;
422 }
423
424 //ScrollAnim command
425 if (StartsWithNoCase(LineData, "scrollanim"))
426 {
427 //get data
428 int params = SplitData(LineData, 10, false);
429
430 if (params != 3)
431 return ScriptError("Incorrect number of parameters");
432
433 //check numeric values
434 for (int i = 1; i <= 2; i++)
435 {
436 if (!IsNumeric(tempdata[i]))
437 return ScriptError("Invalid value: " + tempdata[i]);
438 }
439
440 //stop here if in Check mode
441 if (config->CheckScript == true)
442 return sNextLine;
443
444 texturemanager->ScrollAnimTexture(tempdata[0], ToFloat(tempdata[1]), ToFloat(tempdata[2]));
445 return sNextLine;
446 }
447
448 //Scale command
449 if (StartsWithNoCase(LineData, "scale"))
450 {
451 //get data
452 int params = SplitData(LineData, 5, false);
453
454 if (params != 3)
455 return ScriptError("Incorrect number of parameters");
456
457 //check numeric values
458 for (int i = 1; i <= 2; i++)
459 {
460 if (!IsNumeric(tempdata[i]))
461 return ScriptError("Invalid value: " + tempdata[i]);
462 }
463
464 //stop here if in Check mode
465 if (config->CheckScript == true)
466 return sNextLine;
467
468 texturemanager->ScaleTexture(tempdata[0], ToFloat(tempdata[1]), ToFloat(tempdata[2]));
469 return sNextLine;
470 }
471
472 //Transform command
473 if (StartsWithNoCase(LineData, "transform"))
474 {
475 //get data
476 int params = SplitData(LineData, 9, false);
477
478 if (params != 7)
479 return ScriptError("Incorrect number of parameters");
480
481 //check numeric values
482 for (int i = 3; i <= 6; i++)
483 {
484 if (!IsNumeric(tempdata[i]))
485 return ScriptError("Invalid value: " + tempdata[i]);
486 }
487
488 //stop here if in Check mode
489 if (config->CheckScript == true)
490 return sNextLine;
491
492 texturemanager->TransformTexture(tempdata[0], tempdata[1], tempdata[2], ToFloat(tempdata[3]), ToFloat(tempdata[4]), ToFloat(tempdata[5]), ToFloat(tempdata[6]));
493 return sNextLine;
494 }
495
496 //SetCulling command
497 if (StartsWithNoCase(LineData, "setculling"))
498 {
499 //get data
500 int params = SplitData(LineData, 11, false);
501
502 if (params != 2)
503 return ScriptError("Incorrect number of parameters");
504
505 //check numeric values
506 if (!IsNumeric(tempdata[1]))
507 return ScriptError("Invalid value: " + tempdata[1]);
508
509 //stop here if in Check mode
510 if (config->CheckScript == true)
511 return sNextLine;
512
513 texturemanager->SetCulling(tempdata[0], ToInt(tempdata[1]));
514 return sNextLine;
515 }
516
517 //handle end of textures section
518 if (StartsWithNoCase(LineData, "<endtextures>"))
519 {
521 config->SectionNum = 0;
522 config->Context = "None";
523 engine->Report("Finished textures");
524 return sNextLine;
525 }
526
527 return sContinue;
528}
529
530}
TextureManager * GetTextureManager()
Definition sbs.cpp:4558
void SetLighting(Real red=1.0, Real green=1.0, Real blue=1.0)
Definition sbs.cpp:3378
void Report(const std::string &message)
TexturesSection(ScriptProcessor *parent)
Definition textures.cpp:34
static const int sNextLine
Definition scriptproc.h:70
static const int sContinue
Definition scriptproc.h:69
bool StartsWithNoCase(const std::string &string, const std::string &check_string)
Definition globals.cpp:237
void ReplaceAll(std::string &string, const std::string &original, const std::string &replacement)
Definition globals.cpp:201
int ToInt(const std::string &string)
Definition globals.cpp:402
std::string ToString(int number)
Definition globals.cpp:279
Real ToFloat(const std::string &string)
Definition globals.cpp:397
void TrimString(std::string &string)
Definition globals.cpp:188
bool ToBool(std::string string)
Definition globals.cpp:407
bool IsNumeric(const wxString &string)