From: Daniel Karbach Date: Sun, 9 Sep 2012 13:41:28 +0000 (+0200) Subject: reordered type description creation to avoid reallocation X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=46d158b25b842d2ec4b9734af09ca6006c934498;p=l2e.git reordered type description creation to avoid reallocation --- diff --git a/src/battle/Hero.cpp b/src/battle/Hero.cpp index d117da0..fdf8125 100644 --- a/src/battle/Hero.cpp +++ b/src/battle/Hero.cpp @@ -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)); diff --git a/src/battle/Monster.cpp b/src/battle/Monster.cpp index 7408eee..dd65338 100644 --- a/src/battle/Monster.cpp +++ b/src/battle/Monster.cpp @@ -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)); diff --git a/src/battle/PartyLayout.cpp b/src/battle/PartyLayout.cpp index ad0a548..78d2999 100644 --- a/src/battle/PartyLayout.cpp +++ b/src/battle/PartyLayout.cpp @@ -38,12 +38,12 @@ void PartyLayout::CalculatePositions(int width, int height, vector > 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)); } diff --git a/src/battle/Resources.cpp b/src/battle/Resources.cpp index a1365d0..bd20eb0 100644 --- a/src/battle/Resources.cpp +++ b/src/battle/Resources.cpp @@ -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)); diff --git a/src/battle/Stats.cpp b/src/battle/Stats.cpp index 7ad7aa7..cdf3210 100644 --- a/src/battle/Stats.cpp +++ b/src/battle/Stats.cpp @@ -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)); diff --git a/src/common/Ikari.cpp b/src/common/Ikari.cpp index 408b0f8..3e7c79f 100644 --- a/src/common/Ikari.cpp +++ b/src/common/Ikari.cpp @@ -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)); diff --git a/src/common/Item.cpp b/src/common/Item.cpp index 1b54c9a..f79a6e0 100644 --- a/src/common/Item.cpp +++ b/src/common/Item.cpp @@ -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) diff --git a/src/common/Spell.cpp b/src/common/Spell.cpp index 9070346..a0b3b9d 100644 --- a/src/common/Spell.cpp +++ b/src/common/Spell.cpp @@ -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)); diff --git a/src/common/TargetingMode.cpp b/src/common/TargetingMode.cpp index d1627bc..4f365c4 100644 --- a/src/common/TargetingMode.cpp +++ b/src/common/TargetingMode.cpp @@ -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 diff --git a/src/graphics/ComplexAnimation.cpp b/src/graphics/ComplexAnimation.cpp index b54baf9..e4d293c 100644 --- a/src/graphics/ComplexAnimation.cpp +++ b/src/graphics/ComplexAnimation.cpp @@ -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)); diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index c680310..d151f25 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -77,13 +77,13 @@ void Font::DrawNumber(int numberIn, SDL_Surface *dest, const Vector &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)); diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index 34767f5..b51f093 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -121,13 +121,13 @@ void Frame::Draw(SDL_Surface *dest, const Vector &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)); diff --git a/src/graphics/Gauge.cpp b/src/graphics/Gauge.cpp index 7407ba7..6925c2f 100644 --- a/src/graphics/Gauge.cpp +++ b/src/graphics/Gauge.cpp @@ -85,14 +85,14 @@ void Gauge::Draw(SDL_Surface *dest, const Vector &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)); diff --git a/src/graphics/Menu.cpp b/src/graphics/Menu.cpp index b70697e..ebb76ff 100644 --- a/src/graphics/Menu.cpp +++ b/src/graphics/Menu.cpp @@ -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)); diff --git a/src/graphics/SimpleAnimation.cpp b/src/graphics/SimpleAnimation.cpp index 4e16b81..17a0857 100644 --- a/src/graphics/SimpleAnimation.cpp +++ b/src/graphics/SimpleAnimation.cpp @@ -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)); diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index e83486e..28d3b5c 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -43,13 +43,13 @@ void Sprite::Draw(SDL_Surface *dest, const Vector &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)); diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index ddcc852..42fb121 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -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"));