]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Interpreter.cpp
moved Hero and Stats to common
[l2e.git] / src / loader / Interpreter.cpp
index 550be2678f7e75f175b9a187a50080079d911a70..28e9b39335d2f13c13ecc7c0226d1ecf69589c6e 100644 (file)
@@ -15,6 +15,7 @@
 #include "../common/Ikari.h"
 #include "../common/Item.h"
 #include "../common/Spell.h"
+#include "../common/Stats.h"
 #include "../common/TargetingMode.h"
 #include "../graphics/ComplexAnimation.h"
 #include "../graphics/Font.h"
 using battle::Hero;
 using battle::Monster;
 using battle::PartyLayout;
-using battle::Stats;
 using common::Ikari;
 using common::Item;
 using common::Spell;
+using common::Stats;
 using common::TargetingMode;
 using graphics::Animation;
 using graphics::Color;
@@ -69,6 +70,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<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
        if (i != parsedDefinitions.end()) {
@@ -301,6 +311,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 {
@@ -308,21 +321,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<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());
 }
 
-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));
 }