// -*- mode: C++; tab-width: 4; indent-tabs-mode: t; -*- vim:ts=4:sw=4 // // Copyright (C) 2004,2005 David Lau (skunix) // Chong Kai Xiong (descender) // // This file is part of The Plains of Usata. // // The Plains of Usata is licensed under the GNU General Public // License (GPL) version 2. For details, please see the COPYING file // included in the software distribution, or visit // http://www.fsf.org/licenses/gpl.html. // // $Id: scene-loader.cpp,v 1.1 2005/02/23 16:52:07 skunix Exp $ #include #include #include #include #include #include "object.hpp" #include "log.hpp" #include "scene-loader.hpp" #include "object-registry.hpp" #include "xml/scene_parser.hpp" #include namespace usata { SceneLoader::SceneLoader(const boost::filesystem::path&p) : mScenePath(p), mTimeToDie(false) { mLoadThread.reset( new boost::thread(boost::bind(&SceneLoader::thread_main, this))); log::BufferedStream ls; ls << "Main: " << getpid() << log::commit; } SceneLoader::~SceneLoader() { } void SceneLoader::thread_load(const std::string&fn) { using namespace boost; log::BufferedStream ls; filesystem::path file = mScenePath/fn; if (!filesystem::exists(file)) { return; } ObjectVector loading; std::string native_path = file.native_file_string(); std::ifstream is(native_path.c_str()); SceneParser scene_in(is, native_path); scene_in.threaded_parse(); ObjectDescription * odp; std::auto_ptr odp_ap; ObjectRegistry *objreg = ObjectRegistry::instance(); bool success = true; while (1) { bool finished = scene_in.finished(); odp = scene_in.get_object(); if (!odp) { if (finished) break; boost::thread::yield(); continue; } Object* no = objreg->create(odp->type); if (!no) { ls << "creation of object failed (class=\"" << odp->type <<"\")" << log::commit; } GCInterface *no_gci = dynamic_cast(no); if (no_gci) { no_gci->construct(odp->props); loading.push_back(Object_sp(no)); ls << "successfully loaded and initialized " << odp->type <