This may cut down a little on unnecessary strings / mallocs:

* Only create the self.[xywh] aliases and its variables if prefixedname has no
  periods in it, e.g. MusicText.x, but not MusicText.align.x

* Set the .r, .g and .b variables directly, rather than aliasing them through
  .x, .y and .w

svn-id: r23000
This commit is contained in:
Torbjörn Andersson 2006-06-10 10:09:40 +00:00
parent c78409da15
commit 8ef6ff1765
2 changed files with 35 additions and 28 deletions

View File

@ -413,30 +413,36 @@ void Theme::processSingleLine(const String &section, const String &prefix, const
uint i;
int value;
const char *selfpostfixes[] = {"self.x", "self.y", "self.w", "self.h"};
const char *postfixes[] = {".x", ".y", ".w", ".h"};
const char *postfixesXYWH[] = {".x", ".y", ".w", ".h"};
const char *postfixesRGB[] = {".r", ".g", ".b"};
int npostfix = 0;
const String prefixedname(prefix + name);
// Make self.BLAH work
for (i = 0; i < ARRAYSIZE(postfixes); i++) {
String to(prefixedname);
// Make self.BLAH work, but not self.ANYTHING.BLAH
if (!strchr(prefixedname.c_str(), '.')) {
for (i = 0; i < ARRAYSIZE(postfixesXYWH); i++) {
String to(prefixedname);
to += postfixes[i];
to += postfixesXYWH[i];
_evaluator->setAlias(selfpostfixes[i], to);
_evaluator->setVar(to, EVAL_UNDEF_VAR);
_evaluator->setAlias(selfpostfixes[i], to);
_evaluator->setVar(to, EVAL_UNDEF_VAR);
}
}
// Count the number of parameters, so that we know if they're meant to
// be XY[WH] or RGB.
int ntmppostfix = 0;
for (i = 0; i < str.size(); i++) {
if (isspace(str[i]) && level == 0) {
value = _evaluator->eval(String(&(str.c_str()[start]), i - start), section, name + postfixes[npostfix], start);
_evaluator->setVar(prefixedname + postfixes[npostfix++], value);
start = i + 1;
ntmppostfix++;
}
if (str[i] == '(')
level++;
if (str[i] == ')') {
else if (str[i] == ')') {
if (level == 0) {
error("Extra ')' in section: [%s] expression: \"%s\" start is at: %d",
section.c_str(), name.c_str(), start);
@ -449,6 +455,23 @@ void Theme::processSingleLine(const String &section, const String &prefix, const
error("Missing ')' in section: [%s] expression: \"%s\" start is at: %d",
section.c_str(), name.c_str(), start);
const char **postfixes = (ntmppostfix == 2) ? postfixesRGB : postfixesXYWH;
// Now do it for real, only this time we already know the parantheses
// are balanced.
for (i = 0; i < str.size(); i++) {
if (isspace(str[i]) && level == 0) {
value = _evaluator->eval(String(&(str.c_str()[start]), i - start), section, name + postfixes[npostfix], start);
_evaluator->setVar(prefixedname + postfixes[npostfix++], value);
start = i + 1;
}
if (str[i] == '(')
level++;
else if (str[i] == ')')
level--;
}
value = _evaluator->eval(String(&(str.c_str()[start]), i - start), section, name + postfixes[npostfix], start);
if (value == EVAL_STRING_VAR)
@ -466,8 +489,6 @@ void Theme::processSingleLine(const String &section, const String &prefix, const
_evaluator->getVar(prefixedname + ".x") + _evaluator->getVar(prefixedname + ".w"));
_evaluator->setVar(prefixedname + ".y2",
_evaluator->getVar(prefixedname + ".y") + _evaluator->getVar(prefixedname + ".h"));
} else if (npostfix == 2) { // Specify shortcuts for R G B
setRGBAlias(prefixedname);
}
if (npostfix != 0)
@ -544,19 +565,6 @@ void Theme::setSpecialAlias(const String &alias, const String &name) {
}
}
void Theme::setRGBAlias(const String &name) {
const char *frompostfixes[] = {".x", ".y", ".w"};
const char *topostfixes[] = {".r", ".g", ".b"};
int i;
for (i = 0; i < ARRAYSIZE(frompostfixes); i++) {
String from(name + frompostfixes[i]);
String to(name + topostfixes[i]);
_evaluator->setAlias(to.c_str(), from);
}
}
bool Theme::isThemeLoadingRequired() {
int x = g_system->getOverlayWidth(), y = g_system->getOverlayHeight();

View File

@ -195,7 +195,6 @@ public:
void processResSection(Common::ConfigFile &config, const String &name, bool skipDefs = false, const String &prefix = "");
void processSingleLine(const String &section, const String &prefix, const String &name, const String &str);
void setSpecialAlias(const String &alias, const String &name);
void setRGBAlias(const String &name);
bool isThemeLoadingRequired();
bool sectionIsSkipped(Common::ConfigFile &config, const char *name, int w, int h);