]> git.localhorst.tv Git - l2e.git/commitdiff
reordered type description creation to avoid reallocation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 9 Sep 2012 13:41:28 +0000 (15:41 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 9 Sep 2012 13:41:28 +0000 (15:41 +0200)
17 files changed:
src/battle/Hero.cpp
src/battle/Monster.cpp
src/battle/PartyLayout.cpp
src/battle/Resources.cpp
src/battle/Stats.cpp
src/common/Ikari.cpp
src/common/Item.cpp
src/common/Spell.cpp
src/common/TargetingMode.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
src/loader/Interpreter.cpp

index d117da078ed072bc8dfa9a00d8f70519ccc91325..fdf8125872c1df23a57c3f8187837d96da125d2f 100644 (file)
@@ -156,9 +156,6 @@ void Hero::UpdateIkariMenu(const Resources *res) {
 
 void Hero::CreateTypeDescription() {
        Hero h;
-       TypeDescription &td(TypeDescription::CreateOrGet("Hero"));
-
-       td.SetSize(sizeof(Hero));
 
        int animationId(TypeDescription::GetTypeId("Animation"));
        int numberId(TypeDescription::GetTypeId("Number"));
@@ -166,6 +163,9 @@ void Hero::CreateTypeDescription() {
        int statsId(TypeDescription::GetTypeId("Stats"));
        int stringId(TypeDescription::GetTypeId("String"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Hero"));
+       td.SetSize(sizeof(Hero));
+
        td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true));
        td.AddField("sprite", FieldDescription(((char *)&h.sprite) - ((char *)&h), spriteId, true));
        td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId, false));
index 7408eeea09939685e186f0018cfe6fcee20235a6..dd653383a5151132777e1f6ef6ddb6fb568e680f 100644 (file)
@@ -54,9 +54,6 @@ void Monster::SubtractHealth(int amount) {
 
 void Monster::CreateTypeDescription() {
        Monster m;
-       TypeDescription &td(TypeDescription::CreateOrGet("Monster"));
-
-       td.SetSize(sizeof(Monster));
 
        int animationId(TypeDescription::GetTypeId("Animation"));
        int numberId(TypeDescription::GetTypeId("Number"));
@@ -64,6 +61,9 @@ void Monster::CreateTypeDescription() {
        int statsId(TypeDescription::GetTypeId("Stats"));
        int stringId(TypeDescription::GetTypeId("String"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Monster"));
+       td.SetSize(sizeof(Monster));
+
        td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), stringId, true));
        td.AddField("sprite", FieldDescription(((char *)&m.sprite) - ((char *)&m), spriteId, true));
        td.AddField("level", FieldDescription(((char *)&m.level) - ((char *)&m), numberId, false));
index ad0a54877c6b3c53e9266ea76cdeaa5c869cd2e4..78d2999eab2ed8ad0784b70451865ba82a6b68bf 100644 (file)
@@ -38,12 +38,12 @@ void PartyLayout::CalculatePositions(int width, int height, vector<Vector<int> >
 
 void PartyLayout::CreateTypeDescription() {
        PartyLayout p;
-       TypeDescription &td(TypeDescription::CreateOrGet("PartyLayout"));
-
-       td.SetSize(sizeof(PartyLayout));
 
        int vectorId(TypeDescription::GetTypeId("Vector"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("PartyLayout"));
+       td.SetSize(sizeof(PartyLayout));
+
        td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), vectorId, true, true));
 }
 
index a1365d070bd05e25f35f242e488b4e548d1292e3..bd20eb091ab5c5755fce10bd2163e7ad0196f040 100644 (file)
@@ -83,9 +83,6 @@ Resources::Resources()
 
 void Resources::CreateTypeDescription() {
        Resources r;
-       TypeDescription &td(TypeDescription::CreateOrGet("BattleResources"));
-
-       td.SetSize(sizeof(Resources));
 
        int animationId(TypeDescription::GetTypeId("Animation"));
        int colorId(TypeDescription::GetTypeId("Color"));
@@ -97,6 +94,9 @@ void Resources::CreateTypeDescription() {
        int spriteId(TypeDescription::GetTypeId("Sprite"));
        int stringId(TypeDescription::GetTypeId("String"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("BattleResources"));
+       td.SetSize(sizeof(Resources));
+
        td.AddField("swapCursor", FieldDescription(((char *)&r.swapCursor) - ((char *)&r), spriteId, true));
        td.AddField("moveIcons", FieldDescription(((char *)&r.moveIcons) - ((char *)&r), spriteId, true));
        td.AddField("attackIcons", FieldDescription(((char *)&r.attackIcons) - ((char *)&r), spriteId, true));
index 7ad7aa7a841e2925091e396bf67605393af7ecf2..cdf321036db0ab7941628371858983a63041fb93 100644 (file)
@@ -39,12 +39,12 @@ Stats::Stats(Uint16 attack, Uint16 defense, Uint16 strength, Uint16 agility, Uin
 
 void Stats::CreateTypeDescription() {
        Stats s;
-       TypeDescription &td(TypeDescription::CreateOrGet("Stats"));
-
-       td.SetSize(sizeof(Stats));
 
        int numberId(TypeDescription::GetTypeId("Number"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Stats"));
+       td.SetSize(sizeof(Stats));
+
        td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), numberId, false));
        td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s), numberId, false));
        td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s), numberId, false));
index 408b0f8277f0d2aba8bbf1f1e56019429813b312..3e7c79fced415f74b76f708377f1bce280eec4a1 100644 (file)
@@ -24,15 +24,15 @@ Ikari::Ikari()
 
 void Ikari::CreateTypeDescription() {
        Ikari i;
-       TypeDescription &td(TypeDescription::CreateOrGet("Ikari"));
-
-       td.SetSize(sizeof(Ikari));
 
        int boolId(TypeDescription::GetTypeId("Boolean"));
        int numberId(TypeDescription::GetTypeId("Number")); // FIXME: need small number type
        int stringId(TypeDescription::GetTypeId("String"));
        int targetsId(TypeDescription::GetTypeId("TargetingMode"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Ikari"));
+       td.SetSize(sizeof(Ikari));
+
        td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), stringId, true));
        td.AddField("cost", FieldDescription(((char *)&i.cost) - ((char *)&i), numberId, false));
        td.AddField("targets", FieldDescription(((char *)&i.targetingMode) - ((char *)&i), targetsId, false));
index 1b54c9a2ac73eef37a0278f64e32bee9b7d72d30..f79a6e030446e6cb536a0a76e661cca2e5d9786d 100644 (file)
@@ -32,9 +32,6 @@ Item::Item()
 
 void Item::CreateTypeDescription() {
        Item i;
-       TypeDescription &td(TypeDescription::CreateOrGet("Item"));
-
-       td.SetSize(sizeof(Item));
 
        int animationId(TypeDescription::GetTypeId("Animation"));
        int ikariId(TypeDescription::GetTypeId("Ikari"));
@@ -42,6 +39,9 @@ void Item::CreateTypeDescription() {
        int stringId(TypeDescription::GetTypeId("String"));
        int targetsId(TypeDescription::GetTypeId("TargetingMode"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Item"));
+       td.SetSize(sizeof(Item));
+
        td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), stringId, true));
        td.AddField("menuicon", FieldDescription(((char *)&i.menuIcon) - ((char *)&i), spriteId, true));
        // TODO: implement flags/fields (e.g. for usability)
index 907034645b76373b3961340614b988cc6007bbbe..a0b3b9de82d514f679ff01daba8bccacd561b95f 100644 (file)
@@ -22,15 +22,15 @@ Spell::Spell()
 
 void Spell::CreateTypeDescription() {
        Spell s;
-       TypeDescription &td(TypeDescription::CreateOrGet("Spell"));
-
-       td.SetSize(sizeof(Spell));
 
        // TODO: flags
        int numberId(TypeDescription::GetTypeId("Number"));
        int stringId(TypeDescription::GetTypeId("String"));
        int targetsId(TypeDescription::GetTypeId("TargetingMode"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Spell"));
+       td.SetSize(sizeof(Spell));
+
        td.AddField("name", FieldDescription(((char *)&s.name) - ((char *)&s), stringId, true));
        td.AddField("cost", FieldDescription(((char *)&s.cost) - ((char *)&s), numberId, false));
        td.AddField("targets", FieldDescription(((char *)&s.targetingMode) - ((char *)&s), targetsId, false));
index d1627bcd0255f8281497ee40adcd8f7e336a23e8..4f365c48d931ca6e584610804783c6d12bb3d812 100644 (file)
@@ -16,8 +16,8 @@ namespace common {
 
 void TargetingMode::CreateTypeDescription() {
        TargetingMode t;
-       TypeDescription &td(TypeDescription::CreateOrGet("TargetingMode"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("TargetingMode"));
        td.SetSize(sizeof(TargetingMode));
 
        // TODO: fields
index b54baf9396aeb7e56b1c26efe3198c3571162327..e4d293cdd920297799adda7225ad5fe59e21e5e5 100644 (file)
@@ -17,24 +17,25 @@ namespace graphics {
 void ComplexAnimation::CreateTypeDescription() {
        ComplexAnimation ca;
        Animation *a(&ca);
-       TypeDescription &td(TypeDescription::CreateOrGet("ComplexAnimation"));
-
-       td.SetSize(sizeof(ComplexAnimation));
-       td.AddSupertype(TypeDescription::GetTypeId("Animation"), ((char *)a) - ((char *)&ca));
 
+       int animationId(TypeDescription::GetTypeId("Animation"));
        int frameId(TypeDescription::GetTypeId("ComplexAnimationFrame"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("ComplexAnimation"));
+       td.SetSize(sizeof(ComplexAnimation));
+       td.AddSupertype(animationId, ((char *)a) - ((char *)&ca));
+
        td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), frameId, true, true));
 
 
        FrameProp fp;
-       TypeDescription &ftd(TypeDescription::CreateOrGet("ComplexAnimationFrame"));
-
-       ftd.SetSize(sizeof(FrameProp));
 
        int numberId(TypeDescription::GetTypeId("Number"));
        int vectorId(TypeDescription::GetTypeId("Vector"));
 
+       TypeDescription &ftd(TypeDescription::CreateOrGet("ComplexAnimationFrame"));
+       ftd.SetSize(sizeof(FrameProp));
+
        ftd.AddField("column", FieldDescription(((char *)&fp.col) - ((char *)&fp), numberId, false));
        ftd.AddField("row", FieldDescription(((char *)&fp.row) - ((char *)&fp), numberId, false));
        ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), vectorId, false));
index c68031065b717486f55d06bb589d124b84d0228a..d151f2559e2ac0da0831dcfdefd5e3ac7aeaff57 100644 (file)
@@ -77,13 +77,13 @@ void Font::DrawNumber(int numberIn, SDL_Surface *dest, const Vector<int> &positi
 
 void Font::CreateTypeDescription() {
        Font f;
-       TypeDescription &td(TypeDescription::CreateOrGet("Font"));
-
-       td.SetSize(sizeof(Font));
 
        int numberId(TypeDescription::GetTypeId("Number"));
        int spriteId(TypeDescription::GetTypeId("Sprite"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Font"));
+       td.SetSize(sizeof(Font));
+
        td.AddField("sprite", FieldDescription(((char *)&f.sprite) - ((char *)&f), spriteId, true));
        td.AddField("columnoffset", FieldDescription(((char *)&f.colOffset) - ((char *)&f), numberId, false));
        td.AddField("rowoffset", FieldDescription(((char *)&f.rowOffset) - ((char *)&f), numberId, false));
index 34767f53f0cd170185723e2a0806f4cd87ab14bf..b51f093f6ad4b94b486e547e6f79d764aa42cc53 100644 (file)
@@ -121,13 +121,13 @@ void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int
 
 void Frame::CreateTypeDescription() {
        Frame f;
-       TypeDescription &td(TypeDescription::CreateOrGet("Frame"));
-
-       td.SetSize(sizeof(Frame));
 
        int imageId(TypeDescription::GetTypeId("Image"));
        int vectorId(TypeDescription::GetTypeId("Vector"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Frame"));
+       td.SetSize(sizeof(Frame));
+
        td.AddField("surface", FieldDescription(((char *)&f.surface) - ((char *)&f), imageId, true));
        td.AddField("borderSize", FieldDescription(((char *)&f.borderSize) - ((char *)&f), vectorId, false));
        td.AddField("repeatSize", FieldDescription(((char *)&f.repeatSize) - ((char *)&f), vectorId, false));
index 7407ba77c2f087f57b69a8af84f51a0f1cde4d9c..6925c2ff2482ae1a302d60a8d9f3bc77add64a7c 100644 (file)
@@ -85,14 +85,14 @@ void Gauge::Draw(SDL_Surface *dest, const Vector<int> &position, int width, Uint
 
 void Gauge::CreateTypeDescription() {
        Gauge g;
-       TypeDescription &td(TypeDescription::CreateOrGet("Gauge"));
-
-       td.SetSize(sizeof(Gauge));
 
        int imageId(TypeDescription::GetTypeId("Image"));
        int numberId(TypeDescription::GetTypeId("Number"));
        int vectorId(TypeDescription::GetTypeId("Vector"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Gauge"));
+       td.SetSize(sizeof(Gauge));
+
        td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), imageId, true));
        td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), vectorId, false));
        td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), vectorId, false));
index b70697e43a1fa71fda57483051dd60d278687590..ebb76ff412a818352656dfbbfacdb39b1202c599 100644 (file)
@@ -16,15 +16,15 @@ namespace graphics {
 
 void MenuProperties::CreateTypeDescription() {
        MenuProperties p;
-       TypeDescription &td(TypeDescription::CreateOrGet("MenuProperties"));
-
-       td.SetSize(sizeof(MenuProperties));
 
        int fontId(TypeDescription::GetTypeId("Font"));
        int numberId(TypeDescription::GetTypeId("Number"));
        int spriteId(TypeDescription::GetTypeId("Sprite"));
        int stringId(TypeDescription::GetTypeId("String"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("MenuProperties"));
+       td.SetSize(sizeof(MenuProperties));
+
        td.AddField("font", FieldDescription(((char *)&p.font) - ((char *)&p), fontId, true));
        td.AddField("disabledFont", FieldDescription(((char *)&p.disabledFont) - ((char *)&p), fontId, true));
        td.AddField("cursor", FieldDescription(((char *)&p.cursor) - ((char *)&p), spriteId, true));
index 4e16b81658ec4a6dee2eec4a0eaeaffd7a7c2e01..17a0857832ce8dcfbe75b297f9113515aad4f8a3 100644 (file)
@@ -17,13 +17,14 @@ namespace graphics {
 void SimpleAnimation::CreateTypeDescription() {
        SimpleAnimation sa;
        Animation *a(&sa);
-       TypeDescription &td(TypeDescription::CreateOrGet("SimpleAnimation"));
-
-       td.SetSize(sizeof(SimpleAnimation));
-       td.AddSupertype(TypeDescription::GetTypeId("Animation"), ((char *)a) - ((char *)&sa));
 
+       int animationId(TypeDescription::GetTypeId("Animation"));
        int numberId(TypeDescription::GetTypeId("Number"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("SimpleAnimation"));
+       td.SetSize(sizeof(SimpleAnimation));
+       td.AddSupertype(animationId, ((char *)a) - ((char *)&sa));
+
        td.AddField("framecount", FieldDescription(((char *)&sa.numFrames) - ((char *)&sa), numberId, false));
        td.AddField("col", FieldDescription(((char *)&sa.col) - ((char *)&sa), numberId, false));
        td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), numberId, false));
index e83486e9fe2d4d17baa1b1d53c0f88be322e3d69..28d3b5c215c33a0459ad0963fe3f6393a0d3f9cb 100644 (file)
@@ -43,13 +43,13 @@ void Sprite::Draw(SDL_Surface *dest, const Vector<int> &position, int col, int r
 
 void Sprite::CreateTypeDescription() {
        Sprite s;
-       TypeDescription &td(TypeDescription::CreateOrGet("Sprite"));
-
-       td.SetSize(sizeof(Sprite));
 
        int imageId(TypeDescription::GetTypeId("Image"));
        int vectorId(TypeDescription::GetTypeId("Vector"));
 
+       TypeDescription &td(TypeDescription::CreateOrGet("Sprite"));
+       td.SetSize(sizeof(Sprite));
+
        td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), imageId, true));
        td.AddField("size", FieldDescription(((char *)&s.size) - ((char *)&s), vectorId, false));
        td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), vectorId, false));
index ddcc8528b95183e33bc25c8ca4e822cc9316ca19..42fb1216d18e207d4e20c843fd2856a0dde15bc4 100644 (file)
@@ -344,9 +344,10 @@ void Interpreter::CreateTypeDescriptions() {
                td.SetSize(sizeof(int));
        }
        {
+               int stringId(TypeDescription::GetTypeId("String"));
                TypeDescription &td(TypeDescription::CreateOrGet("Path"));
                td.SetSize(1);
-               td.AddSupertype(TypeDescription::GetTypeId("String"), 0);
+               td.AddSupertype(stringId, 0);
        }
        {
                TypeDescription &td(TypeDescription::CreateOrGet("String"));