From: Daniel Karbach Date: Tue, 11 Sep 2012 19:45:15 +0000 (+0200) Subject: handle special case of Image type objects X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=44e43987d774b65dffbeae7692606eb2f82de531;hp=21539c358e849b44106b4af3f5941b4131c0f2d1;p=l2e.git handle special case of Image type objects --- diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 550be26..1005c64 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -301,6 +301,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 { @@ -314,6 +317,18 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis } +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()); } diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 8d5c1e3..3202482 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -93,6 +93,8 @@ private: void *GetObject(int typeId, const Value &value); void ReadObject(int typeId, int id, char *dest, const PropertyList &); + SDL_Surface *GetImage(const std::string &); + private: const ParsedSource &source; struct ParsedDefinition {