]> git.localhorst.tv Git - l2e.git/commitdiff
use referenced flag of array types
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 31 Jan 2013 06:41:28 +0000 (07:41 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 31 Jan 2013 06:41:28 +0000 (07:41 +0100)
reference arrays are pointer to pointer to value + an int while
"normal" arrays are pointer to value + an int

refs #34

src/battle/PartyLayout.cpp
src/common/Capsule.cpp
src/common/Hero.cpp
src/graphics/ComplexAnimation.cpp
src/loader/Interpreter.cpp
src/map/Area.cpp
src/map/Map.cpp

index e46b276d685b038efe2ce04bbf9f07295c40827e..00fa930f9eb711853e469e32c61bc14d456ad96d 100644 (file)
@@ -39,7 +39,7 @@ void PartyLayout::CreateTypeDescription() {
        td.SetConstructor(&Construct);
        td.SetSize(sizeof(PartyLayout));
 
-       td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), Interpreter::VECTOR_ID).SetReferenced().SetAggregate().SetDescription("the members' positions"));
+       td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), Interpreter::VECTOR_ID).SetAggregate().SetDescription("the members' positions"));
 }
 
 void PartyLayout::Construct(void *data) {
index c8a490eb0f4631d9075f00d1dda11d5baecff98a..6667068c3c8299dc11268faa889d4cba9a383a8e 100644 (file)
@@ -231,9 +231,9 @@ void Capsule::CreateTypeDescription() {
        td.AddField("level", FieldDescription(((char *)&c.level) - ((char *)&c), Interpreter::NUMBER_ID));
        td.AddField("experience", FieldDescription(((char *)&c.experience) - ((char *)&c), Interpreter::NUMBER_ID));
 
-       td.AddField("ladder", FieldDescription(((char *)&c.levelLadder) - ((char *)&c), Interpreter::NUMBER_ID).SetReferenced().SetAggregate());
+       td.AddField("ladder", FieldDescription(((char *)&c.levelLadder) - ((char *)&c), Interpreter::NUMBER_ID).SetAggregate());
 
-       td.AddField("classes", FieldDescription(((char *)&c.classes) - ((char *)&c), Class::TYPE_ID).SetReferenced().SetAggregate());
+       td.AddField("classes", FieldDescription(((char *)&c.classes) - ((char *)&c), Class::TYPE_ID).SetAggregate());
        td.AddField("class", FieldDescription(((char *)&c.curClass) - ((char *)&c), Interpreter::NUMBER_ID));
        td.AddField("maxClass", FieldDescription(((char *)&c.maxClass) - ((char *)&c), Interpreter::NUMBER_ID));
 
index dbd5aed494da7139cf4988d4ab6bd57e999a824a..cca9d43f812eba77b89c039fc10990889c97645c 100644 (file)
@@ -97,7 +97,7 @@ void Hero::CreateTypeDescription() {
        td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
 
        td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
-       td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetReferenced().SetAggregate());
+       td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetAggregate());
 
        td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID));
 
index c1b88c18d789aa2c7fb847331fb6b07a8c326be8..95f58692ed67bae11a7cb2187e332c8336b18a57 100644 (file)
@@ -55,7 +55,7 @@ void ComplexAnimation::CreateTypeDescription() {
        td.AddSupertype(Animation::TYPE_ID, ((char *)a) - ((char *)&ca));
 
        Animation::AddFields(td, ca, ((char *)a) - ((char *)&ca));
-       td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), FrameProp::TYPE_ID).SetReferenced().SetAggregate().SetDescription("a variable number of frames"));
+       td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), FrameProp::TYPE_ID).SetAggregate().SetDescription("a variable number of frames"));
 
 
        FrameProp fp;
index cb15a035185512b8127d6a1206850a46b0a6fe01..8f9e9dc6eff141aa69a1d5d13ad4662293b4b329 100644 (file)
@@ -286,28 +286,45 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis
                        char *dest(object + fd.Offset());
                        if (fd.IsAggregate()) {
                                int arraySize(i->second->GetLiteral().ArraySize());
-                               char *aggregate;
+                               size_t memberSize = fd.IsReferenced() ? sizeof(char *) : fieldType.Size();
+                               char *aggregate = alloc.Alloc(arraySize * memberSize);
+                               char *iter = aggregate;
                                if (i->second->GetLiteral().GetType() == Literal::ARRAY_PROPS) {
-                                       aggregate = alloc.Alloc(fieldType.Size() * arraySize);
-                                       char *iter = aggregate;
                                        const vector<PropertyList *> &list(i->second->GetLiteral().GetPropertyLists());
-                                       for (vector<PropertyList *>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) {
-                                               fieldType.Construct(iter);
-                                               ReadObject(fieldType.TypeId(), -1, iter, **j);
+                                       for (vector<PropertyList *>::const_iterator j(list.begin()), end(list.end());
+                                                       j != end; ++j, iter += memberSize) {
+                                               char *member;
+                                               if (fd.IsReferenced()) {
+                                                       member = alloc.Alloc(fieldType.Size());
+                                                       *reinterpret_cast<char **>(iter) = member;
+                                               } else {
+                                                       member = iter;
+                                               }
+                                               fieldType.Construct(member);
+                                               ReadObject(fieldType.TypeId(), -1, member, **j);
                                        }
                                } else if (i->second->GetLiteral().GetType() == Literal::ARRAY_VALUES) {
-                                       aggregate = alloc.Alloc(fieldType.Size() * arraySize);
-                                       char *iter = aggregate;
                                        const vector<Value *> &list(i->second->GetLiteral().GetValues());
-                                       for (vector<Value *>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) {
-                                               fieldType.Construct(iter);
-                                               ReadLiteral(fieldType.TypeId(), -1, iter, (*j)->GetLiteral());
+                                       for (vector<Value *>::const_iterator j(list.begin()), end(list.end());
+                                                       j != end; ++j, iter += memberSize) {
+                                               char *member;
+                                               if (fd.IsReferenced()) {
+                                                       member = alloc.Alloc(fieldType.Size());
+                                                       *reinterpret_cast<char **>(iter) = member;
+                                               } else {
+                                                       member = iter;
+                                               }
+                                               fieldType.Construct(member);
+                                               ReadLiteral(fieldType.TypeId(), -1, member, (*j)->GetLiteral());
                                        }
                                } else {
-                                       aggregate = alloc.Alloc(sizeof(char *) * arraySize);
-                                       char *iter = aggregate;
+                                       if (!fd.IsReferenced()) {
+                                               // TODO: implement inline identifier arrays
+                                               throw std::runtime_error("inline identifier arrays not implemented (yet)");
+                                       }
                                        const vector<string> &list(i->second->GetLiteral().GetIdentifiers());
-                                       for (vector<string>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += sizeof(void *)) {
+                                       for (vector<string>::const_iterator j(list.begin()), end(list.end());
+                                                       j != end; ++j, iter += memberSize) {
                                                if (source.IsDefined(*j)) {
                                                        *reinterpret_cast<void **>(iter)
                                                                        = GetObject(fd.TypeId(), *j);
@@ -316,13 +333,9 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis
                                                }
                                        }
                                }
-                               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");
-                               }
+                               std::memcpy(dest, &aggregate, sizeof(char *));
+                               dest += sizeof(char *);
+                               std::memcpy(dest, &arraySize, sizeof(int));
                        } else if (i->second->IsLiteral() && !fd.IsReferenced()) {
                                // inline literals
                                if (i->second->GetLiteral().IsObject()) {
index 91018e5b4a82cf410f328a43d93376c532b7a0d2..6299290a6a98057dfcbb3257675fcd07bdb37324 100644 (file)
@@ -108,7 +108,7 @@ void Area::CreateTypeDescription() {
        td.SetSize(sizeof(Area));
 
        td.AddField("battlebg", FieldDescription(((char *)&a.battlebg) - ((char *)&a), Interpreter::IMAGE_ID).SetReferenced());
-       td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), Tile::TYPE_ID).SetReferenced().SetAggregate());
+       td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), Tile::TYPE_ID).SetAggregate());
        td.AddField("width", FieldDescription(((char *)&a.width) - ((char *)&a), Interpreter::NUMBER_ID));
 }
 
index 60c319d4a8d8c8fc6a4c0a974c3129ac3a4d176f..85fbd22ad01156db0ae078364d116a5454cde0c9 100644 (file)
@@ -162,9 +162,9 @@ void Map::CreateTypeDescription() {
 
        td.AddField("tileset", FieldDescription(((char *)&m.tileset) - ((char *)&m), Sprite::TYPE_ID).SetReferenced());
        td.AddField("battlebg", FieldDescription(((char *)&m.battlebg) - ((char *)&m), Interpreter::IMAGE_ID).SetReferenced());
-       td.AddField("areas", FieldDescription(((char *)&m.areas) - ((char *)&m), Area::TYPE_ID).SetReferenced().SetAggregate());
-       td.AddField("triggers", FieldDescription(((char *)&m.triggers) - ((char *)&m), Trigger::TYPE_ID).SetReferenced().SetAggregate());
-       td.AddField("entities", FieldDescription(((char *)&m.entities) - ((char *)&m), Entity::TYPE_ID).SetReferenced().SetAggregate());
+       td.AddField("areas", FieldDescription(((char *)&m.areas) - ((char *)&m), Area::TYPE_ID).SetAggregate());
+       td.AddField("triggers", FieldDescription(((char *)&m.triggers) - ((char *)&m), Trigger::TYPE_ID).SetAggregate());
+       td.AddField("entities", FieldDescription(((char *)&m.entities) - ((char *)&m), Entity::TYPE_ID).SetAggregate());
        td.AddField("width", FieldDescription(((char *)&m.width) - ((char *)&m), Interpreter::NUMBER_ID));
 }