From 44e43987d774b65dffbeae7692606eb2f82de531 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 11 Sep 2012 21:45:15 +0200 Subject: [PATCH] handle special case of Image type objects --- src/loader/Interpreter.cpp | 15 +++++++++++++++ src/loader/Interpreter.h | 2 ++ 2 files changed, 17 insertions(+) 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 { -- 2.39.2