From: Daniel Karbach Date: Sun, 9 Sep 2012 13:32:16 +0000 (+0200) Subject: fixed some issues to get it to compile again X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=ac3755adc509404528ef7de58695bf8e3bfb7dcd;hp=f821f7bf3d3faa6aa27eec278350b861badfa03d;p=l2e.git fixed some issues to get it to compile again --- diff --git a/Debug/src/battle/subdir.mk b/Debug/src/battle/subdir.mk index 703adbf..7d95878 100644 --- a/Debug/src/battle/subdir.mk +++ b/Debug/src/battle/subdir.mk @@ -13,6 +13,7 @@ CPP_SRCS += \ ../src/battle/MoveMenu.cpp \ ../src/battle/NumberAnimation.cpp \ ../src/battle/PartyLayout.cpp \ +../src/battle/Resources.cpp \ ../src/battle/SmallHeroTag.cpp \ ../src/battle/Stats.cpp \ ../src/battle/TargetSelection.cpp @@ -27,6 +28,7 @@ OBJS += \ ./src/battle/MoveMenu.o \ ./src/battle/NumberAnimation.o \ ./src/battle/PartyLayout.o \ +./src/battle/Resources.o \ ./src/battle/SmallHeroTag.o \ ./src/battle/Stats.o \ ./src/battle/TargetSelection.o @@ -41,6 +43,7 @@ CPP_DEPS += \ ./src/battle/MoveMenu.d \ ./src/battle/NumberAnimation.d \ ./src/battle/PartyLayout.d \ +./src/battle/Resources.d \ ./src/battle/SmallHeroTag.d \ ./src/battle/Stats.d \ ./src/battle/TargetSelection.d diff --git a/Debug/src/common/subdir.mk b/Debug/src/common/subdir.mk index f253180..8072d36 100644 --- a/Debug/src/common/subdir.mk +++ b/Debug/src/common/subdir.mk @@ -7,19 +7,22 @@ CPP_SRCS += \ ../src/common/Ikari.cpp \ ../src/common/Inventory.cpp \ ../src/common/Item.cpp \ -../src/common/Spell.cpp +../src/common/Spell.cpp \ +../src/common/TargetingMode.cpp OBJS += \ ./src/common/Ikari.o \ ./src/common/Inventory.o \ ./src/common/Item.o \ -./src/common/Spell.o +./src/common/Spell.o \ +./src/common/TargetingMode.o CPP_DEPS += \ ./src/common/Ikari.d \ ./src/common/Inventory.d \ ./src/common/Item.d \ -./src/common/Spell.d +./src/common/Spell.d \ +./src/common/TargetingMode.d # Each subdirectory must supply rules for building sources it contributes diff --git a/Debug/src/graphics/subdir.mk b/Debug/src/graphics/subdir.mk index 53d19d5..c755a65 100644 --- a/Debug/src/graphics/subdir.mk +++ b/Debug/src/graphics/subdir.mk @@ -4,21 +4,33 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/graphics/Animation.cpp \ +../src/graphics/ComplexAnimation.cpp \ ../src/graphics/Font.cpp \ ../src/graphics/Frame.cpp \ ../src/graphics/Gauge.cpp \ +../src/graphics/Menu.cpp \ +../src/graphics/SimpleAnimation.cpp \ ../src/graphics/Sprite.cpp OBJS += \ +./src/graphics/Animation.o \ +./src/graphics/ComplexAnimation.o \ ./src/graphics/Font.o \ ./src/graphics/Frame.o \ ./src/graphics/Gauge.o \ +./src/graphics/Menu.o \ +./src/graphics/SimpleAnimation.o \ ./src/graphics/Sprite.o CPP_DEPS += \ +./src/graphics/Animation.d \ +./src/graphics/ComplexAnimation.d \ ./src/graphics/Font.d \ ./src/graphics/Frame.d \ ./src/graphics/Gauge.d \ +./src/graphics/Menu.d \ +./src/graphics/SimpleAnimation.d \ ./src/graphics/Sprite.d diff --git a/Debug/src/loader/subdir.mk b/Debug/src/loader/subdir.mk index bebb9ab..bedbb88 100644 --- a/Debug/src/loader/subdir.mk +++ b/Debug/src/loader/subdir.mk @@ -8,6 +8,7 @@ CPP_SRCS += \ ../src/loader/ParsedSource.cpp \ ../src/loader/Parser.cpp \ ../src/loader/Tokenizer.cpp \ +../src/loader/TypeDescription.cpp \ ../src/loader/utility.cpp OBJS += \ @@ -15,6 +16,7 @@ OBJS += \ ./src/loader/ParsedSource.o \ ./src/loader/Parser.o \ ./src/loader/Tokenizer.o \ +./src/loader/TypeDescription.o \ ./src/loader/utility.o CPP_DEPS += \ @@ -22,6 +24,7 @@ CPP_DEPS += \ ./src/loader/ParsedSource.d \ ./src/loader/Parser.d \ ./src/loader/Tokenizer.d \ +./src/loader/TypeDescription.d \ ./src/loader/utility.d diff --git a/Release/src/battle/subdir.mk b/Release/src/battle/subdir.mk index 70d865d..ba4653e 100644 --- a/Release/src/battle/subdir.mk +++ b/Release/src/battle/subdir.mk @@ -13,6 +13,7 @@ CPP_SRCS += \ ../src/battle/MoveMenu.cpp \ ../src/battle/NumberAnimation.cpp \ ../src/battle/PartyLayout.cpp \ +../src/battle/Resources.cpp \ ../src/battle/SmallHeroTag.cpp \ ../src/battle/Stats.cpp \ ../src/battle/TargetSelection.cpp @@ -27,6 +28,7 @@ OBJS += \ ./src/battle/MoveMenu.o \ ./src/battle/NumberAnimation.o \ ./src/battle/PartyLayout.o \ +./src/battle/Resources.o \ ./src/battle/SmallHeroTag.o \ ./src/battle/Stats.o \ ./src/battle/TargetSelection.o @@ -41,6 +43,7 @@ CPP_DEPS += \ ./src/battle/MoveMenu.d \ ./src/battle/NumberAnimation.d \ ./src/battle/PartyLayout.d \ +./src/battle/Resources.d \ ./src/battle/SmallHeroTag.d \ ./src/battle/Stats.d \ ./src/battle/TargetSelection.d diff --git a/Release/src/common/subdir.mk b/Release/src/common/subdir.mk index c471112..d86dbcd 100644 --- a/Release/src/common/subdir.mk +++ b/Release/src/common/subdir.mk @@ -7,19 +7,22 @@ CPP_SRCS += \ ../src/common/Ikari.cpp \ ../src/common/Inventory.cpp \ ../src/common/Item.cpp \ -../src/common/Spell.cpp +../src/common/Spell.cpp \ +../src/common/TargetingMode.cpp OBJS += \ ./src/common/Ikari.o \ ./src/common/Inventory.o \ ./src/common/Item.o \ -./src/common/Spell.o +./src/common/Spell.o \ +./src/common/TargetingMode.o CPP_DEPS += \ ./src/common/Ikari.d \ ./src/common/Inventory.d \ ./src/common/Item.d \ -./src/common/Spell.d +./src/common/Spell.d \ +./src/common/TargetingMode.d # Each subdirectory must supply rules for building sources it contributes diff --git a/Release/src/graphics/subdir.mk b/Release/src/graphics/subdir.mk index fa52cf2..1b53d99 100644 --- a/Release/src/graphics/subdir.mk +++ b/Release/src/graphics/subdir.mk @@ -4,21 +4,33 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/graphics/Animation.cpp \ +../src/graphics/ComplexAnimation.cpp \ ../src/graphics/Font.cpp \ ../src/graphics/Frame.cpp \ ../src/graphics/Gauge.cpp \ +../src/graphics/Menu.cpp \ +../src/graphics/SimpleAnimation.cpp \ ../src/graphics/Sprite.cpp OBJS += \ +./src/graphics/Animation.o \ +./src/graphics/ComplexAnimation.o \ ./src/graphics/Font.o \ ./src/graphics/Frame.o \ ./src/graphics/Gauge.o \ +./src/graphics/Menu.o \ +./src/graphics/SimpleAnimation.o \ ./src/graphics/Sprite.o CPP_DEPS += \ +./src/graphics/Animation.d \ +./src/graphics/ComplexAnimation.d \ ./src/graphics/Font.d \ ./src/graphics/Frame.d \ ./src/graphics/Gauge.d \ +./src/graphics/Menu.d \ +./src/graphics/SimpleAnimation.d \ ./src/graphics/Sprite.d diff --git a/Release/src/loader/subdir.mk b/Release/src/loader/subdir.mk index d4a6685..8b5366f 100644 --- a/Release/src/loader/subdir.mk +++ b/Release/src/loader/subdir.mk @@ -8,6 +8,7 @@ CPP_SRCS += \ ../src/loader/ParsedSource.cpp \ ../src/loader/Parser.cpp \ ../src/loader/Tokenizer.cpp \ +../src/loader/TypeDescription.cpp \ ../src/loader/utility.cpp OBJS += \ @@ -15,6 +16,7 @@ OBJS += \ ./src/loader/ParsedSource.o \ ./src/loader/Parser.o \ ./src/loader/Tokenizer.o \ +./src/loader/TypeDescription.o \ ./src/loader/utility.o CPP_DEPS += \ @@ -22,6 +24,7 @@ CPP_DEPS += \ ./src/loader/ParsedSource.d \ ./src/loader/Parser.d \ ./src/loader/Tokenizer.d \ +./src/loader/TypeDescription.d \ ./src/loader/utility.d diff --git a/src/battle/Resources.h b/src/battle/Resources.h index 64fc8e7..7286e0d 100644 --- a/src/battle/Resources.h +++ b/src/battle/Resources.h @@ -9,6 +9,7 @@ #define BATTLE_RESOURCES_H_ #include "../graphics/Color.h" +#include "../graphics/Menu.h" #include diff --git a/src/common/Item.cpp b/src/common/Item.cpp index e695e8d..1b54c9a 100644 --- a/src/common/Item.cpp +++ b/src/common/Item.cpp @@ -38,7 +38,6 @@ void Item::CreateTypeDescription() { int animationId(TypeDescription::GetTypeId("Animation")); int ikariId(TypeDescription::GetTypeId("Ikari")); - int numberId(TypeDescription::GetTypeId("Number")); int spriteId(TypeDescription::GetTypeId("Sprite")); int stringId(TypeDescription::GetTypeId("String")); int targetsId(TypeDescription::GetTypeId("TargetingMode")); diff --git a/src/common/TargetingMode.cpp b/src/common/TargetingMode.cpp new file mode 100644 index 0000000..d1627bc --- /dev/null +++ b/src/common/TargetingMode.cpp @@ -0,0 +1,26 @@ +/* + * TargetingMode.cpp + * + * Created on: Sep 9, 2012 + * Author: holy + */ + +#include "TargetingMode.h" + +#include "../loader/TypeDescription.h" + +using loader::FieldDescription; +using loader::TypeDescription; + +namespace common { + +void TargetingMode::CreateTypeDescription() { + TargetingMode t; + TypeDescription &td(TypeDescription::CreateOrGet("TargetingMode")); + + td.SetSize(sizeof(TargetingMode)); + + // TODO: fields +} + +} diff --git a/src/common/TargetingMode.h b/src/common/TargetingMode.h index 9041448..08829de 100644 --- a/src/common/TargetingMode.h +++ b/src/common/TargetingMode.h @@ -37,6 +37,8 @@ public: void TargetMultipleAllies() { mode = ALLY | MULTIPLE; } void TargetSingleAlly() { mode = ALLY | SINGLE; } + static void CreateTypeDescription(); + private: enum { ALL = 0, diff --git a/src/graphics/Animation.cpp b/src/graphics/Animation.cpp index caffb50..c1ba637 100644 --- a/src/graphics/Animation.cpp +++ b/src/graphics/Animation.cpp @@ -14,7 +14,7 @@ using loader::TypeDescription; namespace graphics { -void AddFields(TypeDescription &td, const Animation &a, std::ptrdiff_t offset) { +void Animation::AddFields(TypeDescription &td, const Animation &a, std::ptrdiff_t offset) { int boolId(TypeDescription::GetTypeId("Boolean")); int numberId(TypeDescription::GetTypeId("Number")); int spriteId(TypeDescription::GetTypeId("Sprite")); diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index fcfe473..ddcc852 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -54,320 +54,37 @@ using std::vector; namespace loader { Interpreter::~Interpreter() { - for (vector::const_iterator i(battleResources.begin()), end(battleResources.end()); i != end; ++i) { - delete *i; + for (vector::const_iterator i(postponedDefinitions.begin()), end(postponedDefinitions.end()); i != end; ++i) { + delete i->identifier; } - for (vector::const_iterator i(complexAnimations.begin()), end(complexAnimations.end()); i != end; ++i) { - delete *i; + for (map::const_iterator i(imageCache.begin()), end(imageCache.end()); i != end; ++i) { + SDL_FreeSurface(i->second); } - for (vector::const_iterator i(fonts.begin()), end(fonts.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(frames.begin()), end(frames.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(gauges.begin()), end(gauges.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(ikaris.begin()), end(ikaris.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(images.begin()), end(images.end()); i != end; ++i) { - SDL_FreeSurface(*i); - } - for (vector::const_iterator i(items.begin()), end(items.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(menuProperties.begin()), end(menuProperties.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(monsters.begin()), end(monsters.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(partyLayouts.begin()), end(partyLayouts.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(simpleAnimations.begin()), end(simpleAnimations.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(spells.begin()), end(spells.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(sprites.begin()), end(sprites.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(strings.begin()), end(strings.end()); i != end; ++i) { - delete *i; - } - for (vector::const_iterator i(targetingModes.begin()), end(targetingModes.end()); i != end; ++i) { - delete *i; - } -} - - -Animation *Interpreter::GetAnimation(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == COMPLEX_ANIMATION) { - return complexAnimations[i->second.index]; - } else if (i->second.type == SIMPLE_ANIMATION) { - return simpleAnimations[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Animation"); - } - } else { - throw Error("access to undefined Animation " + name); - } -} - -battle::Resources *Interpreter::GetBattleResources(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == BATTLE_RESOURCES) { - return battleResources[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to BattleResources"); - } - } else { - throw Error("access to undefined BattleResources " + name); - } -} - -bool Interpreter::GetBoolean(const std::string &name) const { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == BOOLEAN) { - return booleans[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Boolean"); - } - } else { - throw Error("access to undefined Boolean " + name); - } -} - -const Color &Interpreter::GetColor(const std::string &name) const { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == COLOR) { - return colors[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Color"); - } - } else { - throw Error("access to undefined Color " + name); - } -} - -Font *Interpreter::GetFont(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == FONT) { - return fonts[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Font"); + // TODO: maybe need to reverse the array deletion check if most objects turn out to be arrays (of char) + for (map >::const_iterator i(values.begin()), end(values.end()); i != end; ++i) { + for (vector::const_iterator j(i->second.begin()), end(i->second.end()); j != end; ++j) { + delete[] reinterpret_cast(*j); } - } else { - throw Error("access to undefined Font " + name); } } -Frame *Interpreter::GetFrame(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == FRAME) { - return frames[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Frame"); - } - } else { - throw Error("access to undefined Frame " + name); - } -} - -Gauge *Interpreter::GetGauge(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == GAUGE) { - return gauges[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Gauge"); - } - } else { - throw Error("access to undefined Gauge " + name); - } -} -Hero *Interpreter::GetHero(const std::string &name) { +void *Interpreter::GetObject(int typeId, const std::string &name) { map::const_iterator i(parsedDefinitions.find(name)); if (i != parsedDefinitions.end()) { - if (i->second.type == HERO) { - return heroes[i->second.index]; + const TypeDescription &requested(TypeDescription::Get(typeId)); + const TypeDescription &actual(TypeDescription::Get(i->second.type)); + if (requested.TypeId() == actual.TypeId()) { + return values[actual.TypeId()][i->second.id]; + } else if (actual.IsSubtypeOf(requested)) { + char *sub(reinterpret_cast(values[actual.TypeId()][i->second.id])); + std::ptrdiff_t offset(actual.SupertypeOffset(requested)); + return sub - offset; } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Hero"); + throw Error("cannot cast " + actual.TypeName() + " to " + requested.TypeName()); } } else { - throw Error("access to undefined Hero " + name); - } -} - -Ikari *Interpreter::GetIkari(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == IKARI) { - return ikaris[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Ikari"); - } - } else { - throw Error("access to undefined Ikari " + name); - } -} - -Item *Interpreter::GetItem(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == ITEM) { - return items[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Item"); - } - } else { - throw Error("access to undefined Item " + name); - } -} - -graphics::MenuProperties *Interpreter::GetMenuProperties(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == MENU_PROPERTIES) { - return menuProperties[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to MenuProperties"); - } - } else { - throw Error("access to undefined MenuProperties " + name); - } -} - -Monster *Interpreter::GetMonster(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == MONSTER) { - return monsters[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Monster"); - } - } else { - throw Error("access to undefined Monster " + name); - } -} - -int Interpreter::GetNumber(const std::string &name) const { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == NUMBER) { - return numbers[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Number"); - } - } else { - throw Error("access to undefined Number " + name); - } -} - -PartyLayout *Interpreter::GetPartyLayout(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == PARTY_LAYOUT) { - return partyLayouts[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to PartyLayout"); - } - } else { - throw Error("access to undefined PartyLayout " + name); - } -} - -const char *Interpreter::GetPath(const std::string &name) const { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == PATH) { - return strings[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Path"); - } - } else { - throw Error("access to undefined Path " + name); - } -} - -Spell *Interpreter::GetSpell(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == SPELL) { - return spells[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Spell"); - } - } else { - throw Error("access to undefined Spell " + name); - } -} - -Sprite *Interpreter::GetSprite(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == SPRITE) { - return sprites[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Sprite"); - } - } else { - throw Error("access to undefined Sprite " + name); - } -} - -const char *Interpreter::GetString(const std::string &name) const { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - // TODO: enable path to string casting some time - if (i->second.type == STRING /* || i->second.type == PATH */) { - return strings[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to String"); - } - } else { - throw Error("access to undefined String " + name); - } -} - -TargetingMode *Interpreter::GetTargetingMode(const std::string &name) { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == TARGETING_MODE) { - return targetingModes[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to TargetingMode"); - } - } else { - throw Error("access to undefined TargetingMode " + name); - } -} - -Vector Interpreter::GetVector(const std::string &name) const { - map::const_iterator i(parsedDefinitions.find(name)); - if (i != parsedDefinitions.end()) { - if (i->second.type == VECTOR) { - return vectors[i->second.index]; - } else { - throw Error("cannot cast " + i->second.dfn->TypeName() + " to Vector"); - } - } else { - throw Error("access to undefined Vector " + name); + throw Error("access to undefined object " + name); } } @@ -392,46 +109,58 @@ void Interpreter::ReadDefinition(const Definition &dfn) { void Interpreter::ReadLiteral(const Definition &dfn) { switch (dfn.GetLiteral()->GetType()) { case Literal::ARRAY_VALUES: - valueArrays.push_back(dfn.GetLiteral()->GetValues()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VALUE_ARRAY, valueArrays.size() - 1))); + throw Error("named value arrays are not supported, sorry"); break; case Literal::ARRAY_PROPS: - propertyListArrays.push_back(dfn.GetLiteral()->GetPropertyLists()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PROPERTY_LIST_ARRAY, propertyListArrays.size() - 1))); + throw Error("named property list arrays are not supported, sorry"); break; case Literal::BOOLEAN: - booleans.push_back(dfn.GetLiteral()->GetBoolean()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, BOOLEAN, booleans.size() - 1))); + { + int typeId(TypeDescription::GetTypeId("Boolean")); + values[typeId].push_back(new bool(dfn.GetLiteral()->GetBoolean())); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, values[typeId].size() - 1))); + } break; case Literal::COLOR: - colors.push_back(Color(dfn.GetLiteral()->GetRed(), dfn.GetLiteral()->GetGreen(), dfn.GetLiteral()->GetBlue(), dfn.GetLiteral()->GetAlpha())); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COLOR, colors.size() - 1))); + { + int typeId(TypeDescription::GetTypeId("Color")); + values[typeId].push_back(new Color(dfn.GetLiteral()->GetRed(), dfn.GetLiteral()->GetGreen(), dfn.GetLiteral()->GetBlue(), dfn.GetLiteral()->GetAlpha())); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, values[typeId].size() - 1))); + } break; case Literal::NUMBER: - numbers.push_back(dfn.GetLiteral()->GetNumber()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, NUMBER, numbers.size() - 1))); + { + int typeId(TypeDescription::GetTypeId("Number")); + values[typeId].push_back(new int(dfn.GetLiteral()->GetNumber())); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, values[typeId].size() - 1))); + } break; case Literal::PATH: { + int typeId(TypeDescription::GetTypeId("Path")); char *str(new char[dfn.GetLiteral()->GetString().size() + 1]); std::memcpy(str, dfn.GetLiteral()->GetString().c_str(), dfn.GetLiteral()->GetString().size()); str[dfn.GetLiteral()->GetString().size()] = '\0'; - strings.push_back(str); + values[typeId].push_back(str); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, values[typeId].size() - 1))); } - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PATH, strings.size() - 1))); break; case Literal::STRING: { + int typeId(TypeDescription::GetTypeId("String")); char *str(new char[dfn.GetLiteral()->GetString().size() + 1]); std::memcpy(str, dfn.GetLiteral()->GetString().c_str(), dfn.GetLiteral()->GetString().size()); str[dfn.GetLiteral()->GetString().size()] = '\0'; - strings.push_back(str); + values[typeId].push_back(str); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, values[typeId].size() - 1))); } - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, STRING, strings.size() - 1))); break; case Literal::VECTOR: - vectors.push_back(Vector(dfn.GetLiteral()->GetX(), dfn.GetLiteral()->GetY())); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VECTOR, vectors.size() - 1))); + { + int typeId(TypeDescription::GetTypeId("Vector")); + values[typeId].push_back(new Vector(dfn.GetLiteral()->GetX(), dfn.GetLiteral()->GetY())); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, values[typeId].size() - 1))); + } break; case Literal::OBJECT: ReadObject(dfn); @@ -439,810 +168,193 @@ void Interpreter::ReadLiteral(const Definition &dfn) { } } -Animation *Interpreter::GetAnimation(const Value &v) { - if (v.IsLiteral()) { - if (v.GetLiteral().GetTypeName() == "ComplexAnimation") { - ComplexAnimation *a(new ComplexAnimation); - ReadComplexAnimation(*a, *v.GetLiteral().GetProperties()); - complexAnimations.push_back(a); - return a; - } else { - SimpleAnimation *a(new SimpleAnimation); - ReadSimpleAnimation(*a, *v.GetLiteral().GetProperties()); - simpleAnimations.push_back(a); - return a; - } - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetAnimation(v.GetIdentifier()); - } -} - -battle::Resources *Interpreter::GetBattleResources(const Value &v) { - if (v.IsLiteral()) { - battle::Resources *r(new battle::Resources); - ReadBattleResources(*r, *v.GetLiteral().GetProperties()); - return r; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetBattleResources(v.GetIdentifier()); - } -} -bool Interpreter::GetBoolean(const Value &v) { +void *Interpreter::GetObject(int typeId, const Value &v) { if (v.IsLiteral()) { - return v.GetLiteral().GetBoolean(); - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetBoolean(v.GetIdentifier()); - } -} - -Color Interpreter::GetColor(const Value &v) { - if (v.IsLiteral()) { - return Color(v.GetLiteral().GetRed(), v.GetLiteral().GetGreen(), v.GetLiteral().GetBlue(), v.GetLiteral().GetAlpha()); - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetColor(v.GetIdentifier()); - } -} - -Font *Interpreter::GetFont(const Value &v) { - if (v.IsLiteral()) { - Font *f(new Font); - ReadFont(*f, *v.GetLiteral().GetProperties()); - return f; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetFont(v.GetIdentifier()); - } -} - -Frame *Interpreter::GetFrame(const Value &v) { - if (v.IsLiteral()) { - Frame *f(new Frame); - ReadFrame(*f, *v.GetLiteral().GetProperties()); - return f; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetFrame(v.GetIdentifier()); - } -} - -Gauge *Interpreter::GetGauge(const Value &v) { - if (v.IsLiteral()) { - Gauge *g(new Gauge); - ReadGauge(*g, *v.GetLiteral().GetProperties()); - return g; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetGauge(v.GetIdentifier()); - } -} - -Hero *Interpreter::GetHero(const Value &v) { - if (v.IsLiteral()) { - Hero *h(new Hero); - ReadHero(*h, *v.GetLiteral().GetProperties()); - return h; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetHero(v.GetIdentifier()); - } -} - -Ikari *Interpreter::GetIkari(const Value &v) { - if (v.IsLiteral()) { - Ikari *i(new Ikari); - ReadIkari(*i, *v.GetLiteral().GetProperties()); - return i; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetIkari(v.GetIdentifier()); - } -} - -SDL_Surface *Interpreter::GetImage(const Value &v) { - string path(GetPath(v)); - map::const_iterator i(imageCache.find(path)); - if (i == imageCache.end()) { - SDL_Surface *image(IMG_Load(path.c_str())); - images.push_back(image); - imageCache.insert(make_pair(path, image)); - return image; - } else { - return i->second; - } -} - -Item *Interpreter::GetItem(const Value &v) { - if (v.IsLiteral()) { - Item *i(new Item); - ReadItem(*i, *v.GetLiteral().GetProperties()); - return i; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetItem(v.GetIdentifier()); - } -} - -graphics::MenuProperties *Interpreter::GetMenuProperties(const Value &v) { - if (v.IsLiteral()) { - graphics::MenuProperties *m(new graphics::MenuProperties); - ReadMenuProperties(*m, *v.GetLiteral().GetProperties()); - return m; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetMenuProperties(v.GetIdentifier()); - } -} - -Monster *Interpreter::GetMonster(const Value &v) { - if (v.IsLiteral()) { - Monster *m(new Monster); - ReadMonster(*m, *v.GetLiteral().GetProperties()); - return m; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetMonster(v.GetIdentifier()); - } -} - -int Interpreter::GetNumber(const Value &v) { - if (v.IsLiteral()) { - return v.GetLiteral().GetNumber(); - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetNumber(v.GetIdentifier()); - } -} - -PartyLayout *Interpreter::GetPartyLayout(const Value &v) { - if (v.IsLiteral()) { - PartyLayout *l(new PartyLayout); - ReadPartyLayout(*l, *v.GetLiteral().GetProperties()); - return l; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetPartyLayout(v.GetIdentifier()); - } -} - -const char *Interpreter::GetPath(const Value &v) { - if (v.IsLiteral()) { - return v.GetLiteral().GetString().c_str(); - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetPath(v.GetIdentifier()); - } -} - -const PropertyList *Interpreter::GetPropertyList(const Value &v) { - if (v.IsLiteral()) { - return v.GetLiteral().GetProperties(); - } else { - throw Error("cannot reference property lists"); - } -} - -const vector &Interpreter::GetPropertyListArray(const Value &v) { - if (v.IsLiteral()) { - return v.GetLiteral().GetPropertyLists(); - } else { - throw Error("cannot reference property list arrays"); - } -} - -Spell *Interpreter::GetSpell(const Value &v) { - if (v.IsLiteral()) { - Spell *s(new Spell); - ReadSpell(*s, *v.GetLiteral().GetProperties()); - return s; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetSpell(v.GetIdentifier()); - } -} - -Sprite *Interpreter::GetSprite(const Value &v) { - if (v.IsLiteral()) { - Sprite *s(new Sprite); - ReadSprite(*s, *v.GetLiteral().GetProperties()); - return s; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetSprite(v.GetIdentifier()); - } -} - -const char *Interpreter::GetString(const Value &v) { - if (v.IsLiteral()) { - return v.GetLiteral().GetString().c_str(); - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetString(v.GetIdentifier()); - } -} - -TargetingMode *Interpreter::GetTargetingMode(const Value &v) { - if (v.IsLiteral()) { - TargetingMode *t(new TargetingMode); - ReadTargetingMode(*t, *v.GetLiteral().GetProperties()); - return t; - } else { - ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetTargetingMode(v.GetIdentifier()); - } -} - -Vector Interpreter::GetVector(const Value &v) { - if (v.IsLiteral()) { - return Vector(v.GetLiteral().GetX(), v.GetLiteral().GetY()); + if (v.GetLiteral().IsObject()) { + int typeId(TypeDescription::GetTypeId(v.GetLiteral().GetTypeName())); + const TypeDescription &td(TypeDescription::Get(typeId)); + char *object(new char[td.Size()]); + int id(values[typeId].size()); + values[typeId].push_back(object); + ReadObject(typeId, id, object, *v.GetLiteral().GetProperties()); + return object; + } else { + int typeId(0), id(0); + switch (v.GetLiteral().GetType()) { + case Literal::ARRAY_VALUES: + throw Error("cannot copy value arrays, sorry"); + break; + case Literal::ARRAY_PROPS: + throw Error("cannot copy property list arrays, sorry"); + break; + case Literal::BOOLEAN: + { + typeId = TypeDescription::GetTypeId("Boolean"); + id = values[typeId].size(); + const TypeDescription &td(TypeDescription::Get(typeId)); + char *object(new char[td.Size()]); + values[typeId].push_back(new (object) bool(v.GetLiteral().GetBoolean())); + } + break; + case Literal::COLOR: + { + typeId = TypeDescription::GetTypeId("Color"); + id = values[typeId].size(); + const TypeDescription &td(TypeDescription::Get(typeId)); + char *object(new char[td.Size()]); + values[typeId].push_back(new (object) Color(v.GetLiteral().GetRed(), v.GetLiteral().GetGreen(), v.GetLiteral().GetBlue(), v.GetLiteral().GetAlpha())); + } + break; + case Literal::NUMBER: + { + typeId = TypeDescription::GetTypeId("Number"); + id = values[typeId].size(); + const TypeDescription &td(TypeDescription::Get(typeId)); + char *object(new char[td.Size()]); + values[typeId].push_back(new (object) int(v.GetLiteral().GetNumber())); + } + break; + case Literal::PATH: + { + typeId = TypeDescription::GetTypeId("Path"); + id = values[typeId].size(); + char *str(new char[v.GetLiteral().GetString().size() + 1]); + std::memcpy(str, v.GetLiteral().GetString().c_str(), v.GetLiteral().GetString().size()); + str[v.GetLiteral().GetString().size()] = '\0'; + values[typeId].push_back(str); + } + break; + case Literal::STRING: + { + typeId = TypeDescription::GetTypeId("String"); + id = values[typeId].size(); + char *str(new char[v.GetLiteral().GetString().size() + 1]); + std::memcpy(str, v.GetLiteral().GetString().c_str(), v.GetLiteral().GetString().size()); + str[v.GetLiteral().GetString().size()] = '\0'; + values[typeId].push_back(str); + } + break; + case Literal::VECTOR: + { + typeId = TypeDescription::GetTypeId("Vector"); + id = values[typeId].size(); + const TypeDescription &td(TypeDescription::Get(typeId)); + char *object(new char[td.Size()]); + values[typeId].push_back(new (object) Vector(v.GetLiteral().GetX(), v.GetLiteral().GetY())); + } + break; + case Literal::OBJECT: + { + typeId = TypeDescription::GetTypeId(v.GetLiteral().GetTypeName()); + const TypeDescription &td(TypeDescription::Get(typeId)); + id = values[typeId].size(); + char *object(new char[td.Size()]); + ReadObject(typeId, id, object, *v.GetLiteral().GetProperties()); + } + break; + } + return values[typeId][id]; + } } else { ReadDefinition(source.GetDefinition(v.GetIdentifier())); - return GetVector(v.GetIdentifier()); - } -} - -const vector &Interpreter::GetValueArray(const Value &v) { - if (v.IsLiteral()) { - return v.GetLiteral().GetValues(); - } else { - throw Error("cannot reference value arrays"); + return GetObject(typeId, v.GetIdentifier()); } } void Interpreter::ReadObject(const Definition &dfn) { - if (dfn.TypeName() == "BattleResources") { - battle::Resources *res(new battle::Resources); - int index(battleResources.size()); - battleResources.push_back(res); - ReadBattleResources(*res, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, BATTLE_RESOURCES, index))); - } else if (dfn.TypeName() == "ComplexAnimation") { - ComplexAnimation *animation(new ComplexAnimation); - int index(complexAnimations.size()); - complexAnimations.push_back(animation); - ReadComplexAnimation(*animation, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COMPLEX_ANIMATION, index))); - } else if (dfn.TypeName() == "Font") { - Font *font(new Font); - int index(fonts.size()); - fonts.push_back(font); - ReadFont(*font, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FONT, index))); - } else if (dfn.TypeName() == "Frame") { - Frame *frame(new Frame); - int index(frames.size()); - frames.push_back(frame); - ReadFrame(*frame, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FRAME, index))); - } else if (dfn.TypeName() == "Gauge") { - Gauge *gauge(new Gauge); - int index(gauges.size()); - gauges.push_back(gauge); - ReadGauge(*gauge, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, GAUGE, index))); - } else if (dfn.TypeName() == "Hero") { - Hero *hero(new Hero); - int index(heroes.size()); - heroes.push_back(hero); - ReadHero(*hero, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, HERO, index))); - } else if (dfn.TypeName() == "Ikari") { - Ikari *ikari(new Ikari); - int index(ikaris.size()); - ikaris.push_back(ikari); - ReadIkari(*ikari, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, IKARI, index))); - } else if (dfn.TypeName() == "Item") { - Item *item(new Item); - int index(items.size()); - items.push_back(item); - ReadItem(*item, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, ITEM, index))); - } else if (dfn.TypeName() == "MenuProperties") { - graphics::MenuProperties *mprops(new graphics::MenuProperties); - int index(menuProperties.size()); - menuProperties.push_back(mprops); - ReadMenuProperties(*mprops, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MENU_PROPERTIES, index))); - } else if (dfn.TypeName() == "Monster") { - Monster *monster(new Monster); - int index(monsters.size()); - monsters.push_back(monster); - ReadMonster(*monster, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MONSTER, index))); - } else if (dfn.TypeName() == "PartyLayout") { - PartyLayout *layout(new PartyLayout); - int index(partyLayouts.size()); - partyLayouts.push_back(layout); - ReadPartyLayout(*layout, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PARTY_LAYOUT, index))); - } else if (dfn.TypeName() == "SimpleAnimation") { - SimpleAnimation *animation(new SimpleAnimation); - int index(simpleAnimations.size()); - simpleAnimations.push_back(animation); - ReadSimpleAnimation(*animation, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SIMPLE_ANIMATION, index))); - } else if (dfn.TypeName() == "Spell") { - Spell *spell(new Spell); - int index(spells.size()); - spells.push_back(spell); - ReadSpell(*spell, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPELL, index))); - } else if (dfn.TypeName() == "Sprite") { - Sprite *sprite(new Sprite); - int index(sprites.size()); - sprites.push_back(sprite); - ReadSprite(*sprite, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPRITE, index))); - } else if (dfn.TypeName() == "TargetingMode") { - TargetingMode *mode(new TargetingMode); - int index(targetingModes.size()); - targetingModes.push_back(mode); - ReadTargetingMode(*mode, *dfn.GetProperties()); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, TARGETING_MODE, index))); - } else { - throw Error("unhandled object type: " + dfn.TypeName()); - } + int typeId(TypeDescription::GetTypeId(dfn.TypeName())); + const TypeDescription &td(TypeDescription::Get(typeId)); + int id(values[typeId].size()); + char *object(new char[td.Size()]); + values[typeId].push_back(object); + ReadObject(typeId, id, object, *dfn.GetProperties()); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, id))); } -void Interpreter::ReadBattleResources(battle::Resources &res, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "swapCursor") { - res.swapCursor = GetSprite(*i->second); - } else if (i->first == "moveIcons") { - res.moveIcons = GetSprite(*i->second); - } else if (i->first == "attackIcons") { - res.attackIcons = GetSprite(*i->second); - } else if (i->first == "attackChoiceIcons") { - res.attackChoiceIcons = GetSprite(*i->second); - } else if (i->first == "titleFrame") { - res.titleFrame = GetFrame(*i->second); - } else if (i->first == "titleFont") { - res.titleFont = GetFont(*i->second); - } else if (i->first == "heroTagFrame") { - res.heroTagFrame = GetFrame(*i->second); - } else if (i->first == "activeHeroTagFrame") { - res.activeHeroTagFrame = GetFrame(*i->second); - } else if (i->first == "smallHeroTagFrame") { - res.smallHeroTagFrame = GetFrame(*i->second); - } else if (i->first == "lastSmallHeroTagFrame") { - res.lastSmallHeroTagFrame = GetFrame(*i->second); - } else if (i->first == "heroTagFont") { - res.heroTagFont = GetFont(*i->second); - } else if (i->first == "heroTagLabels") { - res.heroTagLabels = GetSprite(*i->second); - } else if (i->first == "healthGauge") { - res.healthGauge = GetGauge(*i->second); - } else if (i->first == "manaGauge") { - res.manaGauge = GetGauge(*i->second); - } else if (i->first == "ikariGauge") { - res.ikariGauge = GetGauge(*i->second); - } else if (i->first == "selectFrame") { - res.selectFrame = GetFrame(*i->second); - } else if (i->first == "normalFont") { - res.normalFont = GetFont(*i->second); - } else if (i->first == "disabledFont") { - res.disabledFont = GetFont(*i->second); - } else if (i->first == "menuCursor") { - res.menuCursor = GetSprite(*i->second); - } else if (i->first == "weaponTargetCursor") { - res.weaponTargetCursor = GetSprite(*i->second); - } else if (i->first == "magicTargetCursor") { - res.magicTargetCursor = GetSprite(*i->second); - } else if (i->first == "itemTargetCursor") { - res.itemTargetCursor = GetSprite(*i->second); - } else if (i->first == "spellMenuHeadline") { - res.spellMenuHeadline = GetString(*i->second); - } else if (i->first == "spellMenuProperties") { - res.spellMenuProperties = GetMenuProperties(*i->second); - } else if (i->first == "itemMenuHeadline") { - res.itemMenuHeadline = GetString(*i->second); - } else if (i->first == "itemMenuProperties") { - res.itemMenuProperties = GetMenuProperties(*i->second); - } else if (i->first == "ikariMenuHeadline") { - res.ikariMenuHeadline = GetString(*i->second); - } else if (i->first == "ikariMenuProperties") { - res.ikariMenuProperties = GetMenuProperties(*i->second); - } else if (i->first == "noEquipmentText") { - res.noEquipmentText = GetString(*i->second); - } else if (i->first == "escapeText") { - res.escapeText = GetString(*i->second); - } else if (i->first == "numberAnimationPrototype") { - res.numberAnimationPrototype = GetAnimation(*i->second); - } else if (i->first == "bigNumberSprite") { - res.bigNumberSprite = GetSprite(*i->second); - } else if (i->first == "greenNumberSprite") { - res.greenNumberSprite = GetSprite(*i->second); - } else if (i->first == "weaponMenuIcon") { - res.weaponMenuIcon = GetSprite(*i->second); - } else if (i->first == "armorMenuIcon") { - res.armorMenuIcon = GetSprite(*i->second); - } else if (i->first == "shieldMenuIcon") { - res.shieldMenuIcon = GetSprite(*i->second); - } else if (i->first == "helmetMenuIcon") { - res.helmetMenuIcon = GetSprite(*i->second); - } else if (i->first == "ringMenuIcon") { - res.ringMenuIcon = GetSprite(*i->second); - } else if (i->first == "jewelMenuIcon") { - res.jewelMenuIcon = GetSprite(*i->second); - } else if (i->first == "levelLabelCol") { - res.levelLabelCol = GetNumber(*i->second); - } else if (i->first == "levelLabelRow") { - res.levelLabelRow = GetNumber(*i->second); - } else if (i->first == "healthLabelCol") { - res.healthLabelCol = GetNumber(*i->second); - } else if (i->first == "healthLabelRow") { - res.healthLabelRow = GetNumber(*i->second); - } else if (i->first == "manaLabelCol") { - res.manaLabelCol = GetNumber(*i->second); - } else if (i->first == "manaLabelRow") { - res.manaLabelRow = GetNumber(*i->second); - } else if (i->first == "moveLabelCol") { - res.moveLabelCol = GetNumber(*i->second); - } else if (i->first == "moveLabelRow") { - res.moveLabelRow = GetNumber(*i->second); - } else if (i->first == "ikariLabelCol") { - res.ikariLabelCol = GetNumber(*i->second); - } else if (i->first == "ikariLabelRow") { - res.ikariLabelRow = GetNumber(*i->second); - } else if (i->first == "heroesBgColor") { - res.heroesBgColor = GetColor(*i->second); - } else { - throw Error("unknown BattleResources property: " + i->first); - } - } -} - -void Interpreter::ReadComplexAnimation(ComplexAnimation &a, const PropertyList &props) { +void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyList &props) { + const TypeDescription &td(TypeDescription::Get(typeId)); for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "sprite") { - a.SetSprite(GetSprite(*i->second)); - } else if (i->first == "frametime") { - a.SetFrameTime(GetNumber(*i->second)); - } else if (i->first == "repeat") { - a.SetRepeat(GetBoolean(*i->second)); - } else if (i->first == "frames") { - const vector &values(GetPropertyListArray(*i->second)); - for (vector::const_iterator i(values.begin()), end(values.end()); i != end; ++i) { - ComplexAnimation::FrameProp frame; - ReadComplexAnimationFrame(frame, **i); - a.AddFrame(frame); + const FieldDescription &fd(td.GetField(i->first)); + const TypeDescription &fieldType(TypeDescription::Get(fd.TypeId())); + if (CanLink(*i->second)) { + char *dest(object + fd.Offset()); + if (fd.IsAggregate()) { + if (i->second->GetLiteral().GetType() != Literal::ARRAY_PROPS) { + throw Error("unsupported aggregate type"); + } + int arraySize(i->second->GetLiteral().ArraySize()); + char *aggregate(new char[fieldType.Size() * arraySize]); + char *iter(aggregate); + vector list(i->second->GetLiteral().GetPropertyLists()); + for (vector::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) { + ReadObject(fieldType.TypeId(), -1, iter, **j); + } + if (fd.IsReferenced()) { + std::memcpy(dest, &aggregate, sizeof(char *)); + dest += sizeof(char *); + std::memcpy(dest, &arraySize, sizeof(int)); + } else { + throw Error("aggregate type fields must be referenced"); + } + } else { + char *src(reinterpret_cast(GetObject(fd.TypeId(), *i->second))); + if (fd.IsReferenced()) { + std::memcpy(dest, &src, sizeof(char *)); + } else { + std::memcpy(dest, src, fieldType.Size()); + } } } else { - throw Error("unknown ComplexAnimation property: " + i->first); + Postpone(typeId, id, fd.Offset(), i->second->GetIdentifier(), fd.TypeId()); } } } -void Interpreter::ReadComplexAnimationFrame(ComplexAnimation::FrameProp &f, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "column") { - f.col = GetNumber(*i->second); - } else if (i->first == "row") { - f.row = GetNumber(*i->second); - } else if (i->first == "disposition") { - f.disposition = GetVector(*i->second); - } else { - throw Error("unknown ComplexAnimationFrame property: " + i->first); - } - } -} -void Interpreter::ReadFont(Font &f, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "sprite") { - f.SetSprite(GetSprite(*i->second)); - } else if (i->first == "columnoffset") { - f.SetColOffset(GetNumber(*i->second)); - } else if (i->first == "rowoffset") { - f.SetRowOffset(GetNumber(*i->second)); - } else { - throw Error("unknown Font property: " + i->first); - } - } +bool Interpreter::CanLink(const Value &v) const { + return v.IsLiteral() || source.IsDefined(v.GetIdentifier()); } -void Interpreter::ReadFrame(Frame &f, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "image") { - f.SetSurface(GetImage(*i->second)); - } else if (i->first == "border") { - f.SetBorderSize(GetVector(*i->second)); - } else if (i->first == "repeat") { - f.SetRepeatSize(GetVector(*i->second)); - } else if (i->first == "offset") { - f.SetOffset(GetVector(*i->second)); - } else { - throw Error("unknown Frame property: " + i->first); - } - } +void Interpreter::Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType) { + char *str(new char[identifier.size() + 1]); + std::memcpy(str, identifier.c_str(), identifier.size()); + str[identifier.size()] = '\0'; + postponedDefinitions.push_back(PostponedDefinition(type, id, offset, str, linkedType)); } -void Interpreter::ReadGauge(Gauge &g, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "image") { - g.SetSurface(GetImage(*i->second)); - } else if (i->first == "full") { - g.SetFullOffset(GetVector(*i->second)); - } else if (i->first == "empty") { - g.SetEmptyOffset(GetVector(*i->second)); - } else if (i->first == "height") { - g.SetHeight(GetNumber(*i->second)); - } else if (i->first == "start") { - g.SetStartWidth(GetNumber(*i->second)); - } else if (i->first == "repeat") { - g.SetRepeatWidth(GetNumber(*i->second)); - } else if (i->first == "end") { - g.SetEndWidth(GetNumber(*i->second)); - } else { - throw Error("unknown Gauge property: " + i->first); - } - } -} -void Interpreter::ReadIkari(Ikari &ikari, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "name") { - ikari.SetName(GetString(*i->second)); - } else if (i->first == "cost") { - ikari.SetCost(GetNumber(*i->second)); - } else if (i->first == "targets") { - ikari.GetTargetingMode() = *GetTargetingMode(*i->second); - } else if (i->first == "magical") { - if (GetBoolean(*i->second)) { - ikari.SetMagical(); - } - } else if (i->first == "physical") { - if (GetBoolean(*i->second)) { - ikari.SetPhysical(); - } - } else { - throw Error("unknown Ikari property: " + i->first); - } +void Interpreter::CreateTypeDescriptions() { + { + TypeDescription &td(TypeDescription::CreateOrGet("Boolean")); + td.SetSize(sizeof(bool)); } -} - -void Interpreter::ReadItem(Item &item, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "name") { - item.SetName(GetString(*i->second)); - } else if (i->first == "menuicon") { - item.SetMenuIcon(GetSprite(*i->second)); - } else if (i->first == "battle") { - if (GetBoolean(*i->second)) { - item.SetUsableInBattle(); - } - } else if (i->first == "targets") { - item.GetTargetingMode() = *GetTargetingMode(*i->second); - } else if (i->first == "ikari") { - item.SetIkari(GetIkari(*i->second)); - } else if (i->first == "attackanimation") { - item.SetAttackAnimation(GetAnimation(*i->second)); - } else { - throw Error("unknown Item property: " + i->first); - } + { + TypeDescription &td(TypeDescription::CreateOrGet("Color")); + td.SetSize(sizeof(Color)); } -} - -void Interpreter::ReadHero(Hero &h, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "name") { - h.SetName(GetString(*i->second)); - } else if (i->first == "sprite") { - h.SetSprite(GetSprite(*i->second)); - } else if (i->first == "level") { - h.SetLevel(GetNumber(*i->second)); - } else if (i->first == "maxHealth") { - h.SetMaxHealth(GetNumber(*i->second)); - } else if (i->first == "health") { - h.SetHealth(GetNumber(*i->second)); - } else if (i->first == "maxMana") { - h.SetMaxMana(GetNumber(*i->second)); - } else if (i->first == "mana") { - h.SetMana(GetNumber(*i->second)); - } else if (i->first == "ip") { - h.SetIP(GetNumber(*i->second)); - } else if (i->first == "stats") { - battle::Stats stats; - ReadStats(stats, *GetPropertyList(*i->second)); - h.SetStats(stats); - } else if (i->first == "attackAnimation") { - h.SetAttackAnimation(GetAnimation(*i->second)); - } else if (i->first == "spellAnimation") { - h.SetSpellAnimation(GetAnimation(*i->second)); - } else if (i->first == "meleeAnimation") { - h.SetMeleeAnimation(GetAnimation(*i->second)); - } else { - throw Error("unknown Hero property: " + i->first); - } + { + TypeDescription &td(TypeDescription::CreateOrGet("Image")); + td.SetSize(sizeof(SDL_Surface)); } -} - -void Interpreter::ReadMenuProperties(graphics::MenuProperties &mprops, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "font") { - mprops.font = GetFont(*i->second); - } else if (i->first == "disabledFont") { - mprops.disabledFont = GetFont(*i->second); - } else if (i->first == "cursor") { - mprops.cursor = GetSprite(*i->second); - } else if (i->first == "charsPerEntry") { - mprops.charsPerEntry = GetNumber(*i->second); - } else if (i->first == "rows") { - mprops.rows = GetNumber(*i->second); - } else if (i->first == "rowGap") { - mprops.rowGap = GetNumber(*i->second); - } else if (i->first == "iconSpace") { - mprops.iconSpace = GetNumber(*i->second); - } else if (i->first == "cols") { - mprops.cols = GetNumber(*i->second); - } else if (i->first == "colGap") { - mprops.colGap = GetNumber(*i->second); - } else if (i->first == "delimiter") { - mprops.delimiter = *GetString(*i->second); - } else if (i->first == "charsPerNumber") { - mprops.charsPerNumber = GetNumber(*i->second); - } else if (i->first == "charsPerAdditionalText") { - mprops.charsPerAdditionalText = GetNumber(*i->second); - } else if (i->first == "additionalTextGap") { - mprops.additionalTextGap = GetNumber(*i->second); - } else { - throw Error("unknown MenuProperties property: " + i->first); - } - } -} - -void Interpreter::ReadMonster(Monster &m, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "name") { - m.SetName(GetString(*i->second)); - } else if (i->first == "sprite") { - m.SetSprite(GetSprite(*i->second)); - } else if (i->first == "level") { - m.SetLevel(GetNumber(*i->second)); - } else if (i->first == "maxHealth") { - m.SetMaxHealth(GetNumber(*i->second)); - } else if (i->first == "health") { - m.SetHealth(GetNumber(*i->second)); - } else if (i->first == "maxMana") { - m.SetMaxMana(GetNumber(*i->second)); - } else if (i->first == "mana") { - m.SetMana(GetNumber(*i->second)); - } else if (i->first == "stats") { - battle::Stats stats; - ReadStats(stats, *GetPropertyList(*i->second)); - m.SetStats(stats); - } else if (i->first == "attackAnimation") { - m.SetAttackAnimation(GetAnimation(*i->second)); - } else if (i->first == "meleeAnimation") { - m.SetMeleeAnimation(GetAnimation(*i->second)); - } else { - throw Error("unknown Monster property: " + i->first); - } - } -} - -void Interpreter::ReadPartyLayout(PartyLayout &p, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "positions") { - const vector &positions(GetValueArray(*i->second)); - for (vector::const_iterator j(positions.begin()), end(positions.end()); j != end; ++j) { - p.AddPosition(GetVector(**j)); - } - } else { - throw Error("unknown PartyLayout property: " + i->first); - } - } -} - -void Interpreter::ReadSimpleAnimation(SimpleAnimation &a, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "sprite") { - a.SetSprite(GetSprite(*i->second)); - } else if (i->first == "frametime") { - a.SetFrameTime(GetNumber(*i->second)); - } else if (i->first == "repeat") { - a.SetRepeat(GetBoolean(*i->second)); - } else if (i->first == "framecount") { - a.SetNumFrames(GetNumber(*i->second)); - } else if (i->first == "col") { - a.SetCol(GetNumber(*i->second)); - } else if (i->first == "row") { - a.SetRow(GetNumber(*i->second)); - } else { - throw Error("unknown SimpleAnimation property: " + i->first); - } - } -} - -void Interpreter::ReadSpell(Spell &s, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "name") { - s.SetName(GetString(*i->second)); - } else if (i->first == "cost") { - s.SetCost(GetNumber(*i->second)); - } else if (i->first == "battle") { - if (GetBoolean(*i->second)) { - s.SetUsableInBattle(); - } - } else if (i->first == "targets") { - s.GetTargetingMode() = *GetTargetingMode(*i->second); - } else { - throw Error("unknown Spell property: " + i->first); - } + { + TypeDescription &td(TypeDescription::CreateOrGet("Number")); + td.SetSize(sizeof(int)); } -} - -void Interpreter::ReadSprite(Sprite &s, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "image") { - s.SetSurface(GetImage(*i->second)); - } else if (i->first == "size") { - s.SetSize(GetVector(*i->second)); - } else if (i->first == "offset") { - s.SetOffset(GetVector(*i->second)); - } else { - throw Error("unknown Sprite property: " + i->first); - } + { + TypeDescription &td(TypeDescription::CreateOrGet("Path")); + td.SetSize(1); + td.AddSupertype(TypeDescription::GetTypeId("String"), 0); } -} - -void Interpreter::ReadStats(Stats &s, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "atp") { - s.SetAttack(GetNumber(*i->second)); - } else if (i->first == "dfp") { - s.SetDefense(GetNumber(*i->second)); - } else if (i->first == "str") { - s.SetStrength(GetNumber(*i->second)); - } else if (i->first == "agl") { - s.SetAgility(GetNumber(*i->second)); - } else if (i->first == "int") { - s.SetIntelligence(GetNumber(*i->second)); - } else if (i->first == "gut") { - s.SetGut(GetNumber(*i->second)); - } else if (i->first == "mgr") { - s.SetMagicResistance(GetNumber(*i->second)); - } else { - throw Error("unknown Stats property: " + i->first); - } + { + TypeDescription &td(TypeDescription::CreateOrGet("String")); + td.SetSize(1); } -} - -void Interpreter::ReadTargetingMode(TargetingMode &t, const PropertyList &props) { - for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { - if (i->first == "ally") { - if (GetBoolean(*i->second)) { - t.TargetAlly(); - } else { - t.TargetEnemy(); - } - } else if (i->first == "enemy") { - if (GetBoolean(*i->second)) { - t.TargetEnemy(); - } else { - t.TargetAlly(); - } - } else if (i->first == "all") { - if (GetBoolean(*i->second)) { - t.TargetAll(); - } - } else if (i->first == "multiple") { - if (GetBoolean(*i->second)) { - t.TargetMultiple(); - } - } else if (i->first == "single") { - if (GetBoolean(*i->second)) { - t.TargetSingle(); - } - } else { - throw Error("unknown TargetingMode property: " + i->first); - } + { + TypeDescription &td(TypeDescription::CreateOrGet("Vector")); + td.SetSize(sizeof(Vector)); } } diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 044a3c0..b826d2c 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -8,6 +8,7 @@ #ifndef LOADER_INTERPRETER_H_ #define LOADER_INTERPRETER_H_ +#include "TypeDescription.h" #include "../geometry/Vector.h" #include "../graphics/Color.h" #include "../graphics/ComplexAnimation.h" @@ -67,163 +68,47 @@ private: public: void ReadSource(); + void *GetObject(int typeId, const std::string &name); + + static void CreateTypeDescriptions(); + struct PostponedDefinition { + PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType) + : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType) { } + int type; + int id; + std::ptrdiff_t offset; + const char *identifier; + int linkedType; + }; -public: - graphics::Animation *GetAnimation(const std::string &name); - battle::Resources *GetBattleResources(const std::string &name); - bool GetBoolean(const std::string &name) const; - const graphics::Color &GetColor(const std::string &name) const; - graphics::Font *GetFont(const std::string &name); - graphics::Frame *GetFrame(const std::string &name); - graphics::Gauge *GetGauge(const std::string &name); - battle::Hero *GetHero(const std::string &name); - common::Ikari *GetIkari(const std::string &name); - common::Item *GetItem(const std::string &name); - graphics::MenuProperties *GetMenuProperties(const std::string &name); - battle::Monster *GetMonster(const std::string &name); - int GetNumber(const std::string &name) const; - battle::PartyLayout *GetPartyLayout(const std::string &name); - const char *GetPath(const std::string &name) const; - common::Spell *GetSpell(const std::string &name); - graphics::Sprite *GetSprite(const std::string &name); - const char *GetString(const std::string &name) const; - common::TargetingMode *GetTargetingMode(const std::string &name); - geometry::Vector GetVector(const std::string &name) const; - -public: - const std::vector &BattleResources() const { return battleResources; } - const std::vector &Booleans() const { return booleans; } - const std::vector &Colors() const { return colors; } - const std::vector &ComplexAnimations() const { return complexAnimations; } - const std::vector &Fonts() const { return fonts; } - const std::vector &Frames() const { return frames; } - const std::vector &Gauges() const { return gauges; } - const std::vector &Heroes() const { return heroes; } - const std::vector &Ikaris() const { return ikaris; } - const std::vector &Images() const { return images; } - const std::vector &Items() const { return items; } - const std::vector &MenuProperties() const { return menuProperties; } - const std::vector &Monsters() const { return monsters; } - const std::vector &Numbers() const { return numbers; } - const std::vector &PartyLayouts() const { return partyLayouts; } - const std::vector &SimpleAnimations() const { return simpleAnimations; } - const std::vector &Spells() const { return spells; } - const std::vector &Sprites() const { return sprites; } - const std::vector &Strings() const { return strings; } - const std::vector &TargetingModes() const { return targetingModes; } - const std::vector > &Vectors() const { return vectors; } + const std::vector &PostponedDefinitions() { return postponedDefinitions; } private: void ReadDefinition(const Definition &); void ReadLiteral(const Definition &); void ReadObject(const Definition &); - graphics::Animation *GetAnimation(const Value &); - battle::Resources *GetBattleResources(const Value &); - graphics::Color GetColor(const Value &); - bool GetBoolean(const Value &); - graphics::Font *GetFont(const Value &); - graphics::Frame *GetFrame(const Value &); - graphics::Gauge *GetGauge(const Value &); - battle::Hero *GetHero(const Value &); - common::Ikari *GetIkari(const Value &); - SDL_Surface *GetImage(const Value &); - common::Item *GetItem(const Value &); - graphics::MenuProperties *GetMenuProperties(const Value &); - battle::Monster *GetMonster(const Value &); - int GetNumber(const Value &); - battle::PartyLayout *GetPartyLayout(const Value &); - const PropertyList *GetPropertyList(const Value &); - const std::vector &GetPropertyListArray(const Value &); - const char *GetPath(const Value &); - common::Spell *GetSpell(const Value &); - graphics::Sprite *GetSprite(const Value &); - const char *GetString(const Value &); - common::TargetingMode *GetTargetingMode(const Value &); - const std::vector &GetValueArray(const Value &); - geometry::Vector GetVector(const Value &); - - void ReadBattleResources(battle::Resources &, const PropertyList &); - void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &); - void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &); - void ReadFont(graphics::Font &, const PropertyList &); - void ReadFrame(graphics::Frame &, const PropertyList &); - void ReadGauge(graphics::Gauge &, const PropertyList &); - void ReadHero(battle::Hero &, const PropertyList &); - void ReadIkari(common::Ikari &, const PropertyList &); - void ReadItem(common::Item &, const PropertyList &); - void ReadMenuProperties(graphics::MenuProperties &, const PropertyList &); - void ReadMonster(battle::Monster &, const PropertyList &); - void ReadPartyLayout(battle::PartyLayout &, const PropertyList &); - void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &); - void ReadSpell(common::Spell &, const PropertyList &); - void ReadSprite(graphics::Sprite &, const PropertyList &); - void ReadStats(battle::Stats &, const PropertyList &); - void ReadTargetingMode(common::TargetingMode &, const PropertyList &); + void *GetObject(int typeId, const Value &value); + void ReadObject(int typeId, int id, char *dest, const PropertyList &); private: const ParsedSource &source; - enum Type { - BATTLE_RESOURCES, - BOOLEAN, - COLOR, - COMPLEX_ANIMATION, - FONT, - FRAME, - GAUGE, - HERO, - IKARI, - IMAGE, - ITEM, - MENU_PROPERTIES, - MONSTER, - NUMBER, - PARTY_LAYOUT, - PATH, - PROPERTY_LIST_ARRAY, - SIMPLE_ANIMATION, - SPELL, - SPRITE, - STRING, - TARGETING_MODE, - VECTOR, - VALUE_ARRAY, - }; struct ParsedDefinition { - ParsedDefinition(const Definition *dfn, Type type, int index) - : dfn(dfn), type(type), index(index) { } + ParsedDefinition(const Definition *dfn, int type, int id) + : dfn(dfn), type(type), id(id) { } const Definition *dfn; - Type type; - int index; + int type; + int id; }; std::map parsedDefinitions; + bool CanLink(const Value &) const; + void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType); + std::vector postponedDefinitions; + std::map imageCache; - std::vector battleResources; - std::vector booleans; - std::vector colors; - std::vector complexAnimations; - std::vector fonts; - std::vector frames; - std::vector gauges; - std::vector heroes; - std::vector ikaris; - std::vector images; - std::vector items; - std::vector menuProperties; - std::vector monsters; - std::vector numbers; - std::vector partyLayouts; - std::vector propertyLists; - std::vector > propertyListArrays; - std::vector simpleAnimations; - std::vector spells; - std::vector sprites; - std::vector strings; - std::vector targetingModes; - std::vector > valueArrays; - std::vector > vectors; + std::map > values; }; diff --git a/src/loader/ParsedSource.h b/src/loader/ParsedSource.h index 98ecd84..e10b287 100644 --- a/src/loader/ParsedSource.h +++ b/src/loader/ParsedSource.h @@ -51,6 +51,9 @@ private: public: Type GetType() const { return type; } + bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS; } + bool IsObject() const { return GetType() == OBJECT; } + int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size() : GetPropertyLists().size(); } const std::vector &GetValues() const; const std::vector &GetPropertyLists() const; diff --git a/src/loader/TypeDescription.cpp b/src/loader/TypeDescription.cpp index c69efbe..07be7b2 100644 --- a/src/loader/TypeDescription.cpp +++ b/src/loader/TypeDescription.cpp @@ -51,10 +51,10 @@ std::ptrdiff_t TypeDescription::SupertypeOffset(int id) const { } -vector Interpreter::typeDescriptions; +vector TypeDescription::typeDescriptions; TypeDescription &TypeDescription::CreateOrGet(const std::string &name) { - for (vector::const_iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) { + for (vector::iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) { if (i->name == name) { return *i; } @@ -74,7 +74,7 @@ int TypeDescription::GetTypeId(const std::string &name) { } const TypeDescription &TypeDescription::Get(int id) { - assert(id >= 0 && id < typeDescriptions.size()); + assert(id >= 0 && id < int(typeDescriptions.size())); return typeDescriptions[id]; } diff --git a/src/main.cpp b/src/main.cpp index 4280985..2117a02 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,7 @@ #include "loader/Interpreter.h" #include "loader/ParsedSource.h" #include "loader/Parser.h" +#include "loader/TypeDescription.h" #include "sdl/InitImage.h" #include "sdl/InitScreen.h" #include "sdl/InitSDL.h" @@ -61,6 +62,7 @@ using graphics::Sprite; using loader::Interpreter; using loader::ParsedSource; using loader::Parser; +using loader::TypeDescription; using sdl::InitImage; using sdl::InitScreen; using sdl::InitSDL; @@ -80,6 +82,22 @@ int main(int argc, char **argv) { InitSDL sdl; InitImage image(IMG_INIT_PNG); + battle::Resources::CreateTypeDescription(); + ComplexAnimation::CreateTypeDescription(); + Font::CreateTypeDescription(); + Frame::CreateTypeDescription(); + Gauge::CreateTypeDescription(); + Hero::CreateTypeDescription(); + Ikari::CreateTypeDescription(); + Item::CreateTypeDescription(); + graphics::MenuProperties::CreateTypeDescription(); + PartyLayout::CreateTypeDescription(); + SimpleAnimation::CreateTypeDescription(); + Spell::CreateTypeDescription(); + Sprite::CreateTypeDescription(); + Stats::CreateTypeDescription(); + common::TargetingMode::CreateTypeDescription(); + ParsedSource source; Parser("test-data/test.l2s", source).Parse(); Parser("test-data/ikaris.l2s", source).Parse(); @@ -88,76 +106,83 @@ int main(int argc, char **argv) { Interpreter intp(source); intp.ReadSource(); - InitScreen screen(width, height); + int battleResId(TypeDescription::GetTypeId("BattleResources")); + int heroId(TypeDescription::GetTypeId("Hero")); + int itemId(TypeDescription::GetTypeId("Item")); + int monsterId(TypeDescription::GetTypeId("Monster")); + int partyLayoutId(TypeDescription::GetTypeId("PartyLayout")); + int spellId(TypeDescription::GetTypeId("Spell")); // temporary test data SDL_Surface *bg(IMG_Load("test-data/battle-bg.png")); - PartyLayout monstersLayout(*intp.GetPartyLayout("monstersLayout")); - PartyLayout heroesLayout(*intp.GetPartyLayout("heroesLayout")); + PartyLayout monstersLayout(*reinterpret_cast(intp.GetObject(partyLayoutId, "monstersLayout"))); + PartyLayout heroesLayout(*reinterpret_cast(intp.GetObject(partyLayoutId, "heroesLayout"))); - Monster monster(*intp.GetMonster("lizard")); - Hero maxim(*intp.GetHero("maxim")); - Hero selan(*intp.GetHero("selan")); - Hero guy(*intp.GetHero("guy")); - Hero dekar(*intp.GetHero("dekar")); + Monster monster(*reinterpret_cast(intp.GetObject(monsterId, "lizard"))); + Hero maxim(*reinterpret_cast(intp.GetObject(heroId, "maxim"))); + Hero selan(*reinterpret_cast(intp.GetObject(heroId, "selan"))); + Hero guy(*reinterpret_cast(intp.GetObject(heroId, "guy"))); + Hero dekar(*reinterpret_cast(intp.GetObject(heroId, "dekar"))); - battle::Resources *battleRes(intp.GetBattleResources("battleResources")); + battle::Resources *battleRes(reinterpret_cast(intp.GetObject(battleResId, "battleResources"))); - maxim.AddSpell(intp.GetSpell("resetSpell")); - Spell *strongSpell(intp.GetSpell("strongSpell")); + maxim.AddSpell(reinterpret_cast(intp.GetObject(spellId, "resetSpell"))); + Spell *strongSpell(reinterpret_cast(intp.GetObject(spellId, "strongSpell"))); maxim.AddSpell(strongSpell); selan.AddSpell(strongSpell); - Spell *strongerSpell(intp.GetSpell("strongerSpell")); + Spell *strongerSpell(reinterpret_cast(intp.GetObject(spellId, "strongerSpell"))); maxim.AddSpell(strongerSpell); selan.AddSpell(strongerSpell); - Spell *championSpell(intp.GetSpell("championSpell")); + Spell *championSpell(reinterpret_cast(intp.GetObject(spellId, "championSpell"))); maxim.AddSpell(championSpell); selan.AddSpell(championSpell); - Spell *rallySpell(intp.GetSpell("rallySpell")); + Spell *rallySpell(reinterpret_cast(intp.GetObject(spellId, "rallySpell"))); maxim.AddSpell(rallySpell); selan.AddSpell(rallySpell); - selan.AddSpell(intp.GetSpell("escapeSpell")); - Spell *valorSpell(intp.GetSpell("valorSpell")); + selan.AddSpell(reinterpret_cast(intp.GetObject(spellId, "escapeSpell"))); + Spell *valorSpell(reinterpret_cast(intp.GetObject(spellId, "valorSpell"))); maxim.AddSpell(valorSpell); selan.AddSpell(valorSpell); Inventory inventory; - inventory.Add(intp.GetItem("antidoteItem"), 9); - inventory.Add(intp.GetItem("magicJarItem"), 4); - inventory.Add(intp.GetItem("hiPotionItem"), 4); - inventory.Add(intp.GetItem("powerPotionItem"), 4); - inventory.Add(intp.GetItem("escapeItem"), 2); - inventory.Add(intp.GetItem("sleepBallItem"), 1); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "antidoteItem")), 9); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "magicJarItem")), 4); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "hiPotionItem")), 4); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "powerPotionItem")), 4); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "escapeItem")), 2); + inventory.Add(reinterpret_cast(intp.GetObject(itemId, "sleepBallItem")), 1); battleRes->inventory = &inventory; - maxim.SetWeapon(intp.GetItem("zircoSwordItem")); - maxim.SetArmor(intp.GetItem("zirconArmorItem")); - maxim.SetShield(intp.GetItem("holyShieldItem")); - maxim.SetHelmet(intp.GetItem("legendHelmItem")); - maxim.SetRing(intp.GetItem("sProRingItem")); - maxim.SetJewel(intp.GetItem("evilJewelItem")); - -// selan.SetWeapon(intp.GetItem("zircoWhipItem")); - selan.SetArmor(intp.GetItem("zirconPlateItem")); - selan.SetShield(intp.GetItem("zircoGlovesItem")); - selan.SetHelmet(intp.GetItem("holyCapItem")); - selan.SetRing(intp.GetItem("ghostRingItem")); - selan.SetJewel(intp.GetItem("eagleRockItem")); - -// guy.SetWeapon(intp.GetItem("zircoAxItem")); - guy.SetArmor(intp.GetItem("zirconArmorItem")); - guy.SetShield(intp.GetItem("megaShieldItem")); - guy.SetHelmet(intp.GetItem("zircoHelmetItem")); - guy.SetRing(intp.GetItem("powerRingItem")); - guy.SetJewel(intp.GetItem("evilJewelItem")); + maxim.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "zircoSwordItem"))); + maxim.SetArmor(reinterpret_cast(intp.GetObject(itemId, "zirconArmorItem"))); + maxim.SetShield(reinterpret_cast(intp.GetObject(itemId, "holyShieldItem"))); + maxim.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "legendHelmItem"))); + maxim.SetRing(reinterpret_cast(intp.GetObject(itemId, "sProRingItem"))); + maxim.SetJewel(reinterpret_cast(intp.GetObject(itemId, "evilJewelItem"))); + +// selan.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "zircoWhipItem"))); + selan.SetArmor(reinterpret_cast(intp.GetObject(itemId, "zirconPlateItem"))); + selan.SetShield(reinterpret_cast(intp.GetObject(itemId, "zircoGlovesItem"))); + selan.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "holyCapItem"))); + selan.SetRing(reinterpret_cast(intp.GetObject(itemId, "ghostRingItem"))); + selan.SetJewel(reinterpret_cast(intp.GetObject(itemId, "eagleRockItem"))); + +// guy.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "zircoAxItem"))); + guy.SetArmor(reinterpret_cast(intp.GetObject(itemId, "zirconArmorItem"))); + guy.SetShield(reinterpret_cast(intp.GetObject(itemId, "megaShieldItem"))); + guy.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "zircoHelmetItem"))); + guy.SetRing(reinterpret_cast(intp.GetObject(itemId, "powerRingItem"))); + guy.SetJewel(reinterpret_cast(intp.GetObject(itemId, "evilJewelItem"))); // NOTE: this is actually Artea equipment -// dekar.SetWeapon(intp.GetItem("lizardBlowItem")); - dekar.SetArmor(intp.GetItem("holyRobeItem")); - dekar.SetShield(intp.GetItem("zircoGlovesItem")); - dekar.SetHelmet(intp.GetItem("holyCapItem")); - dekar.SetRing(intp.GetItem("rocketRingItem")); - dekar.SetJewel(intp.GetItem("krakenRockItem")); +// dekar.SetWeapon(reinterpret_cast(intp.GetObject(itemId, "lizardBlowItem"))); + dekar.SetArmor(reinterpret_cast(intp.GetObject(itemId, "holyRobeItem"))); + dekar.SetShield(reinterpret_cast(intp.GetObject(itemId, "zircoGlovesItem"))); + dekar.SetHelmet(reinterpret_cast(intp.GetObject(itemId, "holyCapItem"))); + dekar.SetRing(reinterpret_cast(intp.GetObject(itemId, "rocketRingItem"))); + dekar.SetJewel(reinterpret_cast(intp.GetObject(itemId, "krakenRockItem"))); + + InitScreen screen(width, height); BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes)); battleState->AddMonster(monster);