X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.cpp;h=0b81323b03b39fc4800ae64cc38317e5e21ddc15;hb=e02068d51f5e7f82d4d3195e9a9ce5c9d76f727d;hp=550be2678f7e75f175b9a187a50080079d911a70;hpb=401785f03e9d56fb28d9e29cdb74dbbf5664c342;p=l2e.git diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 550be26..0b81323 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -69,6 +69,15 @@ Interpreter::~Interpreter() { } +const Interpreter::ParsedDefinition &Interpreter::GetDefinition(const string &identifier) const { + try { + return parsedDefinitions.at(identifier); + } catch (...) { + throw std::runtime_error("cannot find definition for " + identifier); + } +} + + void *Interpreter::GetObject(int typeId, const std::string &name) { map::const_iterator i(parsedDefinitions.find(name)); if (i != parsedDefinitions.end()) { @@ -301,6 +310,9 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis } } else { char *src(reinterpret_cast(GetObject(fd.TypeId(), *i->second))); + if (fd.TypeId() == TypeDescription::GetTypeId("Image")) { + src = reinterpret_cast(GetImage(src)); + } if (fd.IsReferenced()) { std::memcpy(dest, &src, sizeof(char *)); } else { @@ -308,21 +320,33 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis } } } else { - Postpone(typeId, id, fd.Offset(), i->second->GetIdentifier(), fd.TypeId()); + Postpone(typeId, id, fd.Offset(), i->second->GetIdentifier(), fd.TypeId(), !fd.IsReferenced()); } } } +SDL_Surface *Interpreter::GetImage(const string &path) { + map::const_iterator result(imageCache.find(path)); + if (result != imageCache.end()) { + return result->second; + } else { + SDL_Surface *image(IMG_Load(path.c_str())); + imageCache.insert(make_pair(path, image)); + return image; + } +} + + bool Interpreter::CanLink(const Value &v) const { return v.IsLiteral() || source.IsDefined(v.GetIdentifier()); } -void Interpreter::Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType) { +void Interpreter::Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined) { char *str(new char[identifier.size() + 1]); std::memcpy(str, identifier.c_str(), identifier.size()); str[identifier.size()] = '\0'; - postponedDefinitions.push_back(PostponedDefinition(type, id, offset, str, linkedType)); + postponedDefinitions.push_back(PostponedDefinition(type, id, offset, str, linkedType, inlined)); }