xoreos  0.0.5
txi.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <cstdio>
26 
27 #include "src/common/error.h"
28 #include "src/common/strutil.h"
29 #include "src/common/readstream.h"
30 #include "src/common/encoding.h"
31 
34 
35 static const char * const kBlendings[] = { "default", "additive", "punchthrough" };
36 
37 namespace Graphics {
38 
40  alphaMean = 0.0f;
41  arturoHeight = 0;
42  arturoWidth = 0;
43  baselineHeight = 0.0f;
45  bumpMapScaling = 0.0f;
46  canDownsample = true;
47  caretIndent = 0.0f;
48  channelScale = 0;
49  channelTranslate = 0;
50  clamp = 0;
51  codepage = 0;
52  cols = 0;
53  compressTexture = false;
54  cube = false;
55  dbMapping = 0;
56  decal = false;
57  defaultBPP = 0;
58  defaultHeight = 0;
59  defaultWidth = 0;
60  distort = 0;
61  distortAngle = 0;
63  downsampleFactor = 0;
64  downsampleMax = 0;
65  downsampleMin = 0;
66  fileRange = 0;
67  filter = true;
68  fontHeight = 0.0f;
69  fontWidth = 0.0f;
70  fps = 0;
71  isBumpMap = false;
72  isDoubleByte = false;
73  isLightMap = false;
74  maxSizeHQ = 0;
75  maxSizeLQ = 0;
76  minSizeHQ = 0;
77  minSizeLQ = 0;
78  mipMap = true;
79  numChars = 0;
80  numCharsPerSheet = 0;
81  numX = 0;
82  numY = 0;
83  onDemand = false;
84  priority = 0.0f;
85  rows = 0;
86  spacingB = 0.0f;
87  spacingR = 0.0f;
88  speed = 0;
89  temporary = false;
90  textureWidth = 0.0f;
91  unique = false;
92  waterHeight = 0;
93  waterWidth = 0;
94  xBoxDownsample = 0;
95 }
96 
97 
99 }
100 
101 TXI::TXI(Common::SeekableReadStream &stream) : _empty(false), _mode(kModeNormal), _curCoords(0) {
102  load(stream);
103 }
104 
106 }
107 
108 bool TXI::empty() const {
109  return _empty;
110 }
111 
113  _empty = false;
114 
115  while (!stream.eos()) {
117 
118  if (line.empty())
119  break;
120 
121  if (_mode == kModeUpperLeftCoords) {
122  std::sscanf(line.c_str(), "%f %f %f",
126 
127  if (++_curCoords >= _features.upperLeftCoords.size())
128  _mode = kModeNormal;
129  continue;
130  }
131  if (_mode == kModeLowerRightCoords) {
132  std::sscanf(line.c_str(), "%f %f %f",
136 
137  if (++_curCoords >= _features.lowerRightCoords.size())
138  _mode = kModeNormal;
139  continue;
140  }
141 
142  Common::UString args;
143  TXICommand command = parseTXICommand(line, args);
144 
145  if (command == TXICommandAlphaMean)
147  else if (command == TXICommandArturoHeight)
149  else if (command == TXICommandArturoWidth)
151  else if (command == TXICommandBaselineHeight)
153  else if (command == TXICommandBlending)
155  else if (command == TXICommandBumpMapScaling)
157  else if (command == TXICommandBumpMapTexture)
158  _features.bumpMapTexture = args;
159  else if (command == TXICommandBumpyShinyTexture)
161  else if (command == TXICommandCanDownsample)
163  else if (command == TXICommandCaretIndent)
165  else if (command == TXICommandChannelScale)
167  else if (command == TXICommandChannelTranslate)
169  else if (command == TXICommandClamp)
171  else if (command == TXICommandCodepage)
173  else if (command == TXICommandCols)
175  else if (command == TXICommandCompressTexture)
177  else if (command == TXICommandControllerScript)
179  else if (command == TXICommandCube)
181  else if (command == TXICommandDBMapping)
183  else if (command == TXICommandDecal)
185  else if (command == TXICommandDefaultBPP)
187  else if (command == TXICommandDefaultHeight)
189  else if (command == TXICommandDefaultWidth)
191  else if (command == TXICommandDistort)
193  else if (command == TXICommandDistortAngle)
195  else if (command == TXICommandDistortionAmplitude)
197  else if (command == TXICommandDownsampleFactor)
199  else if (command == TXICommandDownsampleMax)
201  else if (command == TXICommandDownsampleMin)
203  else if (command == TXICommandEnvMapTexture)
204  _features.envMapTexture = args;
205  else if (command == TXICommandFileRange)
207  else if (command == TXICommandFilter)
209  else if (command == TXICommandFontHeight)
211  else if (command == TXICommandFontWidth)
213  else if (command == TXICommandFPS)
215  else if (command == TXICommandIsBumpMap)
217  else if (command == TXICommandIsDoubleByte)
219  else if (command == TXICommandIsLightMap)
221  else if (command == TXICommandLowerRightCoords) {
222  int count;
223  Common::parseString(args, count);
224 
226  _curCoords = 0;
227  _features.lowerRightCoords.resize(count);
228  } else if (command == TXICommandMaxSizeHQ)
230  else if (command == TXICommandMaxSizeLQ)
232  else if (command == TXICommandMinSizeHQ)
234  else if (command == TXICommandMinSizeLQ)
236  else if (command == TXICommandMipMap)
238  else if (command == TXICommandNumChars)
240  else if (command == TXICommandNumCharsPerSheet)
242  else if (command == TXICommandNumX)
244  else if (command == TXICommandNumY)
246  else if (command == TXICommandOnDemand)
248  else if (command == TXICommandPriority)
250  else if (command == TXICommandProcedureType)
251  _features.procedureType = args;
252  else if (command == TXICommandRows)
254  else if (command == TXICommandSpacingB)
256  else if (command == TXICommandSpacingR)
258  else if (command == TXICommandSpeed)
260  else if (command == TXICommandTemporary)
262  else if (command == TXICommandTextureWidth)
264  else if (command == TXICommandUnique)
266  else if (command == TXICommandUpperLeftCoords) {
267  int count;
268  Common::parseString(args, count);
269 
271  _curCoords = 0;
272  _features.upperLeftCoords.resize(count);
273  } else if (command == TXICommandWaterHeight)
275  else if (command == TXICommandWaterWidth)
277  else if (command == TXICommandXBoxDownsample)
279  }
280 
281 }
282 
284  return _features;
285 }
286 
288  return _features;
289 }
290 
292  for (size_t i = 0; i < ARRAYSIZE(kBlendings); i++)
293  if (!strcmp(str, kBlendings[i]))
294  return (Blending) i;
295 
296  return kBlendingDefault;
297 }
298 
299 } // End of namespace Graphics
float bumpMapScaling
Definition: txi.h:61
Blending parseBlending(const char *str)
Definition: txi.cpp:291
A class holding an UTF-8 string.
Definition: ustring.h:48
Common::UString bumpMapTexture
Definition: txi.h:62
virtual bool eos() const =0
Returns true if a read failed because the stream has been reached.
std::vector< Coords > upperLeftCoords
Definition: txi.h:117
bool empty() const
Definition: txi.cpp:108
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
void load(Common::SeekableReadStream &stream)
Definition: txi.cpp:112
Utility templates and functions for working with strings and streams.
Blending blending
Definition: txi.h:60
TXICommand
All supported commands in a TXI.
Definition: txitypes.h:37
Basic exceptions to throw.
uint8 downsampleFactor
Definition: txi.h:82
UString readStringLine(SeekableReadStream &stream, Encoding encoding)
Read a line with the given encoding out of a stream.
Definition: encoding.cpp:310
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
uint8 distortAngle
Definition: txi.h:80
Common::UString procedureType
Definition: txi.h:105
static const char *const kBlendings[]
Definition: txi.cpp:35
bool compressTexture
Definition: txi.h:71
uint16 defaultWidth
Definition: txi.h:78
Utility functions for working with differing string encodings.
uint8 distortionAmplitude
Definition: txi.h:81
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
Texture information.
std::vector< Coords > lowerRightCoords
Definition: txi.h:118
bool _empty
Definition: txi.h:141
uint16 defaultHeight
Definition: txi.h:77
uint32 _curCoords
Definition: txi.h:147
Basic reading stream interfaces.
Texture information types.
Plain, unextended ASCII (7bit clean).
Definition: encoding.h:40
uint8 channelTranslate
Definition: txi.h:67
uint16 xBoxDownsample
Definition: txi.h:115
Texture features.
Definition: txi.h:55
Common::UString controllerScript
Definition: txi.h:72
uint8 arturoHeight
Definition: txi.h:57
TXICommand parseTXICommand(const Common::UString &str, Common::UString &args)
Parse a TXI command from a string.
Definition: txitypes.cpp:99
Common::UString envMapTexture
Definition: txi.h:85
uint8 channelScale
Definition: txi.h:66
uint8 downsampleMin
Definition: txi.h:84
uint32 dbMapping
Definition: txi.h:74
float baselineHeight
Definition: txi.h:59
const Features & getFeatures() const
Definition: txi.cpp:283
Common::UString bumpyShinyTexture
Definition: txi.h:63
Blending
Blending type.
Definition: txi.h:43
uint16 numCharsPerSheet
Definition: txi.h:100
Features _features
Definition: txi.h:145
Interface for a seekable & readable data stream.
Definition: readstream.h:265
void parseString(const UString &str, T &value, bool allowEmpty)
Parse a string into any POD integer, float/double or bool type.
Definition: strutil.cpp:215
Mode _mode
Definition: txi.h:143
uint8 downsampleMax
Definition: txi.h:83