From af178ed1c2cab7fe037edc9ace5b91d8444aec2a Mon Sep 17 00:00:00 2001 From: Paul Merrill Date: Fri, 20 Apr 2012 15:34:21 -0700 Subject: [PATCH] multiple archives, call init.py from base.zip --- src/Makefile | 8 ++++++-- src/base/init.py | 0 src/config.h | 3 +++ src/resourcer.cpp | 23 ++++++++++++++++++++--- src/resourcer.h | 2 ++ src/window.cpp | 16 +++++++++++++++- src/world.cpp | 10 ++++------ src/world.h | 2 +- 8 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 src/base/init.py diff --git a/src/Makefile b/src/Makefile index 5f3126e..a82751d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,12 +19,13 @@ LDFLAGS = $(BLDLDFLAGS) -lboost_program_options -lboost_python -lgosu \ -lphysfs $(shell pkg-config --libs python-2.7) $(shell xml2-config --libs) # Name of testing world. +BASEDATA = base.zip TESTWORLD = testing.world ### --- MAIN SECTION --- ### -all: tsunagari $(TESTWORLD) +all: tsunagari $(BASEDATA) $(TESTWORLD) depend: @$(CXX) $(CXXFLAGS) -MM *.cpp | perl ../scripts/filter-depend.pl @@ -35,11 +36,14 @@ tsunagari: animation.o area.o area-tmx.o clientconf.o cmd.o entity.o log.o \ world.o xml.o $(CXX) -o tsunagari *.o $(LDFLAGS) +%.zip: + cd $(basename $@) && zip --symlinks -r -0 ../$@ * + %.world: cd $(basename $@) && zip --symlinks -r -0 ../$@ * clean: - $(RM) tsunagari *.o $(TESTWORLD) + $(RM) tsunagari *.o $(BASEDATA) $(TESTWORLD) ### --- DEPENDS SECTION --- ### diff --git a/src/base/init.py b/src/base/init.py new file mode 100644 index 0000000..e69de29 diff --git a/src/config.h b/src/config.h index 24d38e4..f7d55c9 100644 --- a/src/config.h +++ b/src/config.h @@ -10,6 +10,9 @@ #define TSUNAGARI_RELEASE_VERSION "Tsunagari Tile Engine AlphaP4 Revision 2" // === Default Configuration Settings === + /* Base data file. */ + #define BASE_ZIP "./base.zip" + /* Tsunagari config file. */ #define CLIENT_CONF_FILE "./client.ini" diff --git a/src/resourcer.cpp b/src/resourcer.cpp index 6e36389..e0dfd3f 100644 --- a/src/resourcer.cpp +++ b/src/resourcer.cpp @@ -49,12 +49,29 @@ bool Resourcer::init(char* argv0) { int err; err = PHYSFS_init(argv0); - if (!err) + return err != 0; +} + +bool Resourcer::prependPath(std::string path) +{ + int err; + + err = PHYSFS_mount(path.c_str(), NULL, 0); + if (!err) { + Log::fatal("Resourcer", path + ": could not open archive"); return false; + } + + return true; +} + +bool Resourcer::appendPath(std::string path) +{ + int err; - err = PHYSFS_mount(conf.worldFilename.c_str(), NULL, 0); + err = PHYSFS_mount(path.c_str(), NULL, 1); if (!err) { - Log::fatal("Resourcer", conf.worldFilename + ": could not open world"); + Log::fatal("Resourcer", path + ": could not open archive"); return false; } diff --git a/src/resourcer.h b/src/resourcer.h index b0df90d..3f09dfc 100644 --- a/src/resourcer.h +++ b/src/resourcer.h @@ -53,6 +53,8 @@ public: Resourcer(); ~Resourcer(); bool init(char* argv0); + bool prependPath(std::string path); + bool appendPath(std::string path); //! Returns true if the World contains a resource by that name. bool resourceExists(const std::string& name) const; diff --git a/src/window.cpp b/src/window.cpp index 2b507ed..6966163 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -58,7 +58,21 @@ bool GameWindow::init(char* argv0) { rc.reset(new Resourcer()); world.reset(new World()); - return rc->init(argv0) && world->init(); + if (!rc->init(argv0)) + return false; + + if (!rc->appendPath(BASE_ZIP)) + return false; + if (rc->resourceExists("init.py")) + rc->runPythonScript("init.py"); + else { + Log::fatal(BASE_ZIP, "couldn't find init.py"); + return false; + } + + if (!rc->appendPath(conf.worldFilename)) + return false; + return world->init(); } int GameWindow::width() const diff --git a/src/world.cpp b/src/world.cpp index 46a86c2..eb7c17f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -25,7 +25,7 @@ World* World::instance() } World::World() - : player(NULL) + : music(new Music()), player(NULL) { globalWorld = this; pythonSetGlobal("World", this); @@ -40,8 +40,6 @@ bool World::init() if (!processDescriptor()) // Try to load in descriptor. return false; - music.reset(new Music()); - if (!player.init(playerentity)) return false; player.setPhase("down"); @@ -52,7 +50,7 @@ bool World::init() rc->runPythonScript(onLoadScript); } - view = new Viewport(viewport); + view.reset(new Viewport(viewport)); view->trackEntity(&player); Area* area = getArea(entry.area); @@ -101,7 +99,7 @@ Area* World::getArea(const std::string& filename) if (entry != areas.end()) return entry->second; - Area* newArea = new AreaTMX(view, &player, music.get(), filename); + Area* newArea = new AreaTMX(view.get(), &player, music.get(), filename); if (!newArea->init()) newArea = NULL; @@ -157,7 +155,7 @@ bool World::processDescriptor() ASSERT(processInput(child)); } } - + if (conf.moveMode == TURN && (conf.persistInit == 0 || conf.persistCons == 0)) { Log::fatal("world.conf", "\"input->persist\" option required in TURN mode."); diff --git a/src/world.h b/src/world.h index 5191c7f..47e124e 100644 --- a/src/world.h +++ b/src/world.h @@ -93,7 +93,7 @@ private: //! fit on-screen. Gosu::Transform getTransform(); - Viewport* view; + boost::shared_ptr view; Area* area; boost::shared_ptr music; Player player; -- 2.11.4.GIT