Use Urho3D's upstream ResourceRouter

This commit is contained in:
Perttu Ahola 2014-10-05 12:55:08 +03:00
parent ac3ba3384b
commit e3a47e954c
2 changed files with 18 additions and 16 deletions

View File

@ -52,8 +52,10 @@ void GraphicsOptions::apply(magic::Graphics *magic_graphics)
vsync, triple_buffer, multisampling);
}
struct BuildatResourceRouter : public magic::ResourceRouter
class BuildatResourceRouter : public magic::ResourceRouter
{
OBJECT(BuildatResourceRouter);
sp_<client::State> m_client;
public:
BuildatResourceRouter(magic::Context *context):
@ -63,30 +65,31 @@ public:
{
m_client = client;
}
magic::String Route(const magic::String &name)
void Route(magic::String& name, magic::ResourceRequest requestType)
{
if(!m_client){
log_w(MODULE, "Resource route access: %s (no client)",
log_w(MODULE, "Resource route access: %s (client not initialized)",
name.CString());
return name;
return;
}
ss_ path = m_client->get_file_path(name.CString());
if(path == ""){
log_v(MODULE, "Resource route access: %s (assuming local file)",
name.CString());
// TODO: Check that it is in a safe path
return name;
return;
}
log_v(MODULE, "Resource route access: %s -> %s",
name.CString(), cs(path));
return path.c_str();
name = path.c_str();
}
};
struct CApp: public App, public magic::Application
{
sp_<client::State> m_state;
magic::SharedPtr<BuildatResourceRouter> m_router;
BuildatResourceRouter *m_router;
magic::LuaScript *m_script;
lua_State *L;
int64_t m_last_script_tick_us;
@ -169,8 +172,7 @@ struct CApp: public App, public magic::Application
magic::ResourceCache *magic_cache = GetSubsystem<magic::ResourceCache>();
magic_cache->SetAutoReloadResources(true);
m_router = new BuildatResourceRouter(context_);
magic_cache->SetResourceRouter(
magic::SharedPtr<magic::ResourceRouter>(m_router));
magic_cache->SetResourceRouter(m_router);
}
~CApp()

View File

@ -105,25 +105,27 @@ static ss_ hash_files(const sv_<ss_> &paths)
return interface::sha1::calculate(os.str());
}
struct BuildatResourceRouter : public magic::ResourceRouter
class BuildatResourceRouter : public magic::ResourceRouter
{
OBJECT(BuildatResourceRouter);
server::State *m_server;
public:
BuildatResourceRouter(magic::Context *context, server::State *server):
magic::ResourceRouter(context),
m_server(server)
{}
magic::String Route(const magic::String &name)
void Route(magic::String& name, magic::ResourceRequest requestType)
{
ss_ path = m_server->get_file_path(name.CString());
if(path == ""){
log_v(MODULE, "Resource route access: %s (assuming local file)",
name.CString());
return name;
return;
}
log_v(MODULE, "Resource route access: %s -> %s",
name.CString(), cs(path));
return path.c_str();
name = path.c_str();
}
};
@ -207,7 +209,6 @@ struct CState: public State, public interface::Server
magic::SharedPtr<magic::Context> m_magic_context;
magic::SharedPtr<magic::Engine> m_magic_engine;
magic::SharedPtr<BuildatResourceRouter> m_router;
magic::SharedPtr<magic::Scene> m_magic_scene;
sm_<Event::Type, magic::SharedPtr<MagicEventHandler>> m_magic_event_handlers;
// NOTE: m_magic_mutex must be locked when constructing or destructing
@ -310,9 +311,8 @@ struct CState: public State, public interface::Server
magic::ResourceCache *magic_cache =
m_magic_context->GetSubsystem<magic::ResourceCache>();
//magic_cache->SetAutoReloadResources(true);
m_router = new BuildatResourceRouter(m_magic_context, this);
magic_cache->SetResourceRouter(
magic::SharedPtr<magic::ResourceRouter>(m_router));
new BuildatResourceRouter(m_magic_context, this));
}
~CState()
{