]> Dogcows Code - chaz/yoink/blobdiff - src/moof/resource.cc
resource loading bugs and new sound class
[chaz/yoink] / src / moof / resource.cc
index 359d1b4dcdfc35fcb3b2bb8d8a3394ecbee60925..314f80b5db81707e73b4cb3d91300f6d5b5a8ea0 100644 (file)
 
 namespace moof {
        
+void resource::print_types()
+{
+}
+
+void resource::manage_loader(const std::string& extension, loader_ptr& loader, bool set)
+{
+       static type_lookup lookup;
+
+       if (loader || set)
+       {
+               lookup[extension] = loader;
+       }
+       else
+       {
+               std::map<std::string,loader_ptr>::iterator it;
+               it = lookup.find(extension);
+               if (it != lookup.end()) loader = (*it).second;
+       }
+}
 
 static std::string search_paths_;
 
@@ -40,7 +59,8 @@ typedef boost::weak_ptr<resource> resource_weakptr;
 static hash<std::string,resource_weakptr,hash_function> resource_table_;
 
 // static member
-resource::type_lookup_ptr resource::type_lookup_;
+//resource::type_lookup_ptr resource::type_lookup_;
+//resource::type_lookup resource::type_lookup_;
 
 
 #ifdef USE_HOTLOADING
@@ -107,14 +127,15 @@ resource_ptr resource::load(const std::string& path)
 {
        std::string extension = stlplus::extension_part(path);
 
-       if (!find(path))
+       std::string path1 = find_file(path);
+       if (!find(path1))
        {
-               log_error("trying to load missing resource:", path);
+               log_error("trying to load missing resource:", path1);
                return resource_ptr();
        }
 
        hash<std::string,resource_weakptr,hash_function>::iterator it;
-       it = resource_table_.find(path);
+       it = resource_table_.find(path1);
        if (it != resource_table_.end())
        {
                resource_weakptr rsrc = (*it).second;
@@ -122,18 +143,18 @@ resource_ptr resource::load(const std::string& path)
                if (locked) return locked;
        }
 
-       std::map<std::string,loader_ptr>::iterator jt;
-       jt = type_lookup_->find(extension);
-       if (jt != type_lookup_->end())
+       loader_ptr loader;
+       manage_loader(extension, loader);
+       if (loader)
        {
-               resource_ptr rsrc((*jt).second->load(path));
-               rsrc->set_loader(path, (*jt).second);
-               resource_table_[path] = rsrc;
+               resource_ptr rsrc(loader->load(path1));
+               rsrc->set_loader(path1, loader);
+               resource_table_[path1] = rsrc;
 
 #ifdef USE_HOTLOADING
-               int wd = inotify_add_watch(monitor_fd_, path.c_str(), IN_MODIFY);
+               int wd = inotify_add_watch(monitor_fd_, path1.c_str(), IN_MODIFY);
                rsrc->set_watch_descriptor(wd);
-               monitor_lookup_[wd] = path;
+               monitor_lookup_[wd] = path1;
 #endif
 
                log_info("loaded", rsrc.get());
This page took 0.018403 seconds and 4 git commands to generate.