Exemplo n.º 1
0
    Resource* Resources::get(const std::string& id_, error_policy ep) const
    {
        std::string id = lower(id_);

        resources::const_iterator it = std::lower_bound(_fastAccessResources.begin(), _fastAccessResources.end(),
                                       id.c_str(), ObjectBasePredicate());

        if (it != _fastAccessResources.end())
        {
            if ((*it)->getName() == id)
                return (*it).get();
        }

        handleErrorPolicy(ep, "can't find resource: '%s' in '%s'", id.c_str(), _name.c_str());
        return 0;
    }
Exemplo n.º 2
0
 void Resources::sort()
 {
     std::sort(_fastAccessResources.begin(), _fastAccessResources.end(), ObjectBasePredicate());
 }
Exemplo n.º 3
0
	void Resources::loadXML(const string &xml_name, 
		LoadResourcesContext *load_context, 
		bool load_completely, bool use_load_counter, 
		const string &prebuilt_folder_)
	{


		_name = xml_name;
		_loadCounter = load_completely ? 1 : 0;


		FS_LOG("step0");
		file::buffer fb;
		file::read(xml_name.c_str(), fb);

		FS_LOG("step1");
		

        updateName(xml_name);

        char destHead[255];
        char destTail[255];
        path::split(xml_name.c_str(), destHead, destTail);

        string prebuilt_folder = prebuilt_folder_ + "/" + destTail + ".ox/";
		if (prebuilt_folder[0] == '/')
		{
			prebuilt_folder.erase(prebuilt_folder.begin());
		}

		file::buffer fb_meta;
		pugi::xml_document doc_meta;
		string ox = prebuilt_folder + "meta.xml";
		const char *ox_file = ox.c_str();

		
		FS_LOG("step2");

		if (file::exists(ox_file))
		{
			file::read(ox_file, fb_meta, ep_ignore_error);
			if (fb_meta.getSize())
				doc_meta.load_buffer_inplace(&fb_meta.data[0], fb_meta.data.size());
		}

		if (!fb.data.size())
		{
			OX_ASSERT(fb.data.size()  && "can't find xml file");
			return;
		}

		pugi::xml_document *doc = new pugi::xml_document();
		_docs.push_back(doc);

		bool loaded = doc->load_buffer(&fb.data[0], fb.data.size());
		OX_ASSERT(loaded);

		pugi::xml_node resources = doc->first_child();
		pugi::xml_node resources_meta = doc_meta.first_child();


		int i = 0;

		string id;
		//string file;
		string rect_str;

		FS_LOG("loading xml resources");

		XmlWalker walker(destHead, 1.0f, load_completely, resources, resources_meta);

		while(true)
		{
			CreateResourceContext context;
			context.walker = walker.next();
			if (context.walker.empty())
				break;


			const char *type = context.walker.getType();

			registeredResources::iterator i = lower_bound(_registeredResources.begin(), _registeredResources.end(), type);
			if (i == _registeredResources.end() || strcmp(i->id, type))
			{
				log::error("unknown resource. type: '%s' id: '%s'", type, Resource::extractID(context.walker.getNode(), "", "").c_str());
				OX_ASSERT(!"unknown resource type");
				continue;
			}

			registeredResource &r = *i;

			
			context.xml_name = &xml_name;
			context.resources = this;

			string prebuilt_xml_folder = prebuilt_folder + "/" + type + "/";
			context.prebuilt_folder = &prebuilt_xml_folder;


			FS_LOG("resource: %s ", name);
			Resource *res = r.cb(context);
			OX_ASSERT(res);
			res->setUseLoadCounter(use_load_counter);

			if (res)
			{	
				bool load = context.walker.getLoad();

				//res-> = child;
				if (load)
					res->load(load_context);
                res->setParent(this);
				_resources.push_back(res);
				_owned.push_back(res);
			}
		}

		sort(_fastAccessResources.begin(), _fastAccessResources.end(), ObjectBasePredicate());
		FS_LOG("xml loaded");
	}