]> git.localhorst.tv Git - l2e.git/commitdiff
handle special case of Image type objects
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 11 Sep 2012 19:45:15 +0000 (21:45 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 11 Sep 2012 19:45:15 +0000 (21:45 +0200)
src/loader/Interpreter.cpp
src/loader/Interpreter.h

index 550be2678f7e75f175b9a187a50080079d911a70..1005c64db76e5bbbbe7f3aa800e9868e646a30cd 100644 (file)
@@ -301,6 +301,9 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis
                                }
                        } else {
                                char *src(reinterpret_cast<char *>(GetObject(fd.TypeId(), *i->second)));
+                               if (fd.TypeId() == TypeDescription::GetTypeId("Image")) {
+                                       src = reinterpret_cast<char *>(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<string, SDL_Surface *>::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());
 }
index 8d5c1e31aadf7ca70ad042501baa2317d074fbd3..3202482d3d9a1e28e2a8c67ddb9a3ea181938356 100644 (file)
@@ -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 {