From: Daniel Karbach Date: Sun, 9 Sep 2012 12:31:07 +0000 (+0200) Subject: added type description of PartyLayout X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;ds=sidebyside;h=06cdcf42d8f86955419bcf8ca3457f1d59a14707;p=l2e.git added type description of PartyLayout --- diff --git a/src/battle/PartyLayout.cpp b/src/battle/PartyLayout.cpp index 6389327..ad0a548 100644 --- a/src/battle/PartyLayout.cpp +++ b/src/battle/PartyLayout.cpp @@ -7,6 +7,44 @@ #include "PartyLayout.h" +#include "../loader/TypeDescription.h" + +using geometry::Vector; +using loader::FieldDescription; +using loader::TypeDescription; +using std::vector; + namespace battle { +Vector PartyLayout::CalculatePosition(int index, int width, int height) const { + assert(index >= 0 && index < numPositions); + return Vector( + positions[index].X() * width / 255, + positions[index].Y() * height / 223 + ); +} + +void PartyLayout::CalculatePositions(int width, int height, vector > &dest) const { + dest.clear(); + dest.reserve(numPositions); + for (int i(0); i < numPositions; ++i) { + dest.push_back(Vector( + positions[i].X() * width / 255, + positions[i].Y() * height / 223 + )); + } +} + + +void PartyLayout::CreateTypeDescription() { + PartyLayout p; + TypeDescription &td(TypeDescription::CreateOrGet("PartyLayout")); + + td.SetSize(sizeof(PartyLayout)); + + int vectorId(TypeDescription::GetTypeId("Vector")); + + td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), vectorId, true, true)); +} + } diff --git a/src/battle/PartyLayout.h b/src/battle/PartyLayout.h index 1d72aa8..b2454f2 100644 --- a/src/battle/PartyLayout.h +++ b/src/battle/PartyLayout.h @@ -19,37 +19,24 @@ namespace battle { class PartyLayout { public: - PartyLayout() { } + PartyLayout() : positions(0), numPositions(0) { } public: - std::vector >::size_type NumPositions() const { return positions.size(); } - template - void CalculatePositions(U width, U height, std::vector > &dest) const { - dest.clear(); - dest.reserve(positions.size()); - for (std::vector >::const_iterator i(positions.begin()), end(positions.end()); i != end; ++i) { - dest.push_back(geometry::Vector( - i->X() * width / 255, - i->Y() * height / 223 - )); - } - } - template - geometry::Vector CalculatePosition(std::vector >::size_type index, U width, U height) const { - assert(index >= 0 && index < positions.size()); - return geometry::Vector( - positions[index].X() * width / 255, - positions[index].Y() * height / 223 - ); - } + std::vector >::size_type NumPositions() const { return numPositions; } + void CalculatePositions(int width, int height, std::vector > &dest) const; + geometry::Vector CalculatePosition(int index, int width, int height) const; public: - void AddPosition(const geometry::Vector &p) { - positions.push_back(p); + void SetPositions(const geometry::Vector *p, int num) { + positions = p; + numPositions = num; } + static void CreateTypeDescription(); + private: - std::vector > positions; + const geometry::Vector *positions; + int numPositions; };