X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.cpp;h=a1fdc8250639ec81ee3e9613e06dcf37ddb401d5;hb=04e4e8797a63c0a89aae9882982cd864213d05ab;hp=fc428cd8365e998ea37128ef23adf2ede9dbb716;hpb=8c8061a4f8b88410d6d93c039afe6affc4b69cf2;p=l2e.git diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index fc428cd..a1fdc82 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -332,10 +332,12 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis int arraySize(i->second->GetLiteral().ArraySize()); size_t memberSize = fd.IsReferenced() ? sizeof(char *) : fieldType.Size(); Array array; + array.typeId = fd.TypeId(); array.size = arraySize * memberSize; array.data = alloc.Alloc(array.size); array.ref = fd.IsReferenced(); arrays.push_back(array); + std::memset(array.data, 0, array.size); char *iter = reinterpret_cast(array.data); if (i->second->GetLiteral().GetType() == Literal::ARRAY_PROPS) { const vector &list(i->second->GetLiteral().GetPropertyLists()); @@ -383,7 +385,8 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis } } } - std::memcpy(dest, &array.data, sizeof(char *)); + size_t pLen = sizeof(char *); + std::memcpy(dest, &array.data, pLen); dest += sizeof(char *); std::memcpy(dest, &arraySize, sizeof(int)); } else if (i->second->IsLiteral() && !fd.IsReferenced()) { @@ -905,6 +908,17 @@ SDL_Surface *Interpreter::GetImage(const string &path) { } } +const string &Interpreter::FindImage(SDL_Surface *img) const { + for (std::map::const_iterator + i(imageCache.begin()), end(imageCache.end()); + i != end; ++i) { + if (i->second == img) { + return i->first; + } + } + throw Error("unable to locate image"); +} + bool Interpreter::CanLink(const Value &v) const { return v.IsLiteral() || source.IsDefined(v.GetIdentifier()); @@ -946,16 +960,18 @@ void Interpreter::CreateTypeDescriptions() { td.SetDescription("A signed integer."); td.SetSize(sizeof(int)); } - {; + { TypeDescription &td(TypeDescription::Create(PATH_ID, "Path")); td.SetDescription("A path in the filesystem which is interpreted relative to the source file's location."); td.SetSize(1); td.AddSupertype(STRING_ID, 0); } { + Script s; TypeDescription &td(TypeDescription::Create(SCRIPT_ID, "Script")); td.SetDescription("Collection of commands that define a behaviour."); td.SetSize(sizeof(Script)); + td.AddField("text", FieldDescription(((char *)&s.text) - ((char *)&s), STRING_ID).SetAggregate()); } { TypeDescription &td(TypeDescription::Create(STRING_ID, "String"));