Skip to content

Commit

Permalink
GRAPHICS: Implement loading of texture properties from TXI
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 28, 2014
1 parent 3a507e7 commit 608733f
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/graphics/textureman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,84 @@ TextureProperties::TextureProperties() {
TextureProperties::~TextureProperties() {
}

bool TextureProperties::loadFromTXI(Common::SeekableReadStream &stream) {
std::vector<Coords> *coords = 0;
uint currentCoord = 0;

while (!stream.eos()) {
Common::UString line;

line.readLineASCII(stream);
if (line.empty())
continue;

if (coords) {
std::sscanf(line.c_str(), "%f %f %f",
&(*coords)[currentCoord].x,
&(*coords)[currentCoord].y,
&(*coords)[currentCoord].z);

if (++currentCoord >= coords->size())
coords = 0;

continue;
}

Common::UString::iterator s = line.findFirst(' ');
if (s == line.end())
continue;

Common::UString key(line.begin(), s);
Common::UString val(++s, line.end());

if (key.equalsIgnoreCase("upperleftcoords")) {
coords = &_coordsUpperLeft;
currentCoord = 0;

int count = 0;
val.parse(count);

coords->resize(count);
} else if (key.equalsIgnoreCase("lowerrightcoords")) {
coords = &_coordsLowerRight;
currentCoord = 0;

int count = 0;
val.parse(count);

coords->resize(count);
}

setString(key, val);
}

return true;
}

bool TextureProperties::loadFromTXI(const ImageDecoder &img) {
Common::SeekableReadStream *txi = img.getTXI();
if (!txi)
return false;

bool result = loadFromTXI(*txi);

delete txi;

return result;
}

bool TextureProperties::loadFromTXI(const Common::UString &file) {
Common::SeekableReadStream *txi = ResMan.getResource(file, ::Aurora::kFileTypeTXI);
if (!txi)
return false;

bool result = loadFromTXI(*txi);

delete txi;

return result;
}

Common::UString TextureProperties::getString(const Common::UString &key, const Common::UString &def) const {
Common::StringIMap::const_iterator it = _properties.find(key);
if (it == _properties.end())
Expand All @@ -73,6 +151,9 @@ Common::UString TextureProperties::getString(const Common::UString &key, const C

void TextureProperties::setString(const Common::UString &key, const Common::UString &value) {
_properties[key] = value;

_properties[key].trim();
_properties[key].tolower();
}

bool TextureProperties::getBool(const Common::UString &key, bool def) const {
Expand Down Expand Up @@ -134,6 +215,14 @@ void TextureProperties::setDouble(const Common::UString &key, double value) {
_properties[key] = Common::UString::sprintf("%lf", value);
}

const std::vector<TextureProperties::Coords> &TextureProperties::getUpperLeftCoords() const {
return _coordsUpperLeft;
}

const std::vector<TextureProperties::Coords> &TextureProperties::getLowerRightCoords() const {
return _coordsLowerRight;
}


TextureManager::TextureManager() {
}
Expand Down Expand Up @@ -198,6 +287,8 @@ ImageDecoder *TextureManager::createImage(const Common::UString &name) {

p.first->second = new TextureProperties;

p.first->second->loadFromTXI(name);

ImageDecoder *image = 0;
WinIconImage *cursor = 0;

Expand Down Expand Up @@ -240,6 +331,8 @@ ImageDecoder *TextureManager::createImage(const Common::UString &name) {
throw;
}

p.first->second->loadFromTXI(*image);

delete img;
delete cursor;

Expand Down
15 changes: 15 additions & 0 deletions src/graphics/textureman.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ class ImageDecoder;
*/
class TextureProperties {
public:
/** Coordinates. */
struct Coords {
float x, y, z;
};

TextureProperties();
~TextureProperties();

Common::UString getString(const Common::UString &key, const Common::UString &def = "") const;
void setString(const Common::UString &key, const Common::UString &value);

bool loadFromTXI(Common::SeekableReadStream &stream);
bool loadFromTXI(const ImageDecoder &img);
bool loadFromTXI(const Common::UString &file);

bool getBool (const Common::UString &key, bool def = false) const;
int getInt (const Common::UString &key, int def = 0 ) const;
uint getUInt (const Common::UString &key, uint def = 0 ) const;
Expand All @@ -64,8 +73,14 @@ class TextureProperties {
void setUInt (const Common::UString &key, uint value);
void setDouble(const Common::UString &key, double value);

const std::vector<Coords> &getUpperLeftCoords() const;
const std::vector<Coords> &getLowerRightCoords() const;

private:
Common::StringIMap _properties;

std::vector<Coords> _coordsUpperLeft;
std::vector<Coords> _coordsLowerRight;
};

/** The global texture manager.
Expand Down

0 comments on commit 608733f

Please sign in to comment.