{"action":"created","issue":{"url":"https://api.github.com/repos/edsomjr/IJE/issues/27","labels_url":"https://api.github.com/repos/edsomjr/IJE/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/edsomjr/IJE/issues/27/comments","events_url":"https://api.github.com/repos/edsomjr/IJE/issues/27/events","html_url":"https://github.com/edsomjr/IJE/issues/27","id":77722310,"number":27,"title":"ENGINE: Duplicacao de codigo em ResourcesManager","user":{"login":"CaioIcy","id":4528105,"avatar_url":"https://avatars.githubusercontent.com/u/4528105?v=3","gravatar_id":"","url":"https://api.github.com/users/CaioIcy","html_url":"https://github.com/CaioIcy","followers_url":"https://api.github.com/users/CaioIcy/followers","following_url":"https://api.github.com/users/CaioIcy/following{/other_user}","gists_url":"https://api.github.com/users/CaioIcy/gists{/gist_id}","starred_url":"https://api.github.com/users/CaioIcy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaioIcy/subscriptions","organizations_url":"https://api.github.com/users/CaioIcy/orgs","repos_url":"https://api.github.com/users/CaioIcy/repos","events_url":"https://api.github.com/users/CaioIcy/events{/privacy}","received_events_url":"https://api.github.com/users/CaioIcy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-18T16:43:12Z","updated_at":"2015-05-18T18:28:05Z","closed_at":null,"body":"Tendo em vista que pra cada novo tipo de _asset_ da engine, temos que fazer um metodo __get_*__ e __acquire_*__, seria melhor generalizar o **ResourcesManager** com template?\r\n\r\nPor exemplo:\r\n```\r\nenv->resources_manager->get<Texture>(\"res/sprite.png\");\r\n```\r\n\r\nao contrario do atual:\r\n```\r\nenv->resources_manager->get_texture(\"res/sprite.png\");\r\n```\r\n\r\nO unico problema seria que a interface mudaria, entao o codigo de todos que estao usando a engine teria que ser alterado. Um exemplo de implementacao (um pouco diferente do que seria nesta engine) eh a [ResourceManager](https://github.com/CaioIcy/sdl2-engine/blob/master/src/core/ResourceManager.h) da sdl2-engine."},"comment":{"url":"https://api.github.com/repos/edsomjr/IJE/issues/comments/103162125","html_url":"https://github.com/edsomjr/IJE/issues/27#issuecomment-103162125","issue_url":"https://api.github.com/repos/edsomjr/IJE/issues/27","id":103162125,"user":{"login":"CaioIcy","id":4528105,"avatar_url":"https://avatars.githubusercontent.com/u/4528105?v=3","gravatar_id":"","url":"https://api.github.com/users/CaioIcy","html_url":"https://github.com/CaioIcy","followers_url":"https://api.github.com/users/CaioIcy/followers","following_url":"https://api.github.com/users/CaioIcy/following{/other_user}","gists_url":"https://api.github.com/users/CaioIcy/gists{/gist_id}","starred_url":"https://api.github.com/users/CaioIcy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CaioIcy/subscriptions","organizations_url":"https://api.github.com/users/CaioIcy/orgs","repos_url":"https://api.github.com/users/CaioIcy/repos","events_url":"https://api.github.com/users/CaioIcy/events{/privacy}","received_events_url":"https://api.github.com/users/CaioIcy/received_events","type":"User","site_admin":false},"created_at":"2015-05-18T18:28:05Z","updated_at":"2015-05-18T18:28:05Z","body":"Do jeito que tenho aqui:\r\n```\r\ntemplate <typename T>\r\nclass ResourcesManager\r\n{\r\n...\r\nmap < string, shared_ptr<T> > m_resources;\r\n...\r\n```\r\n\r\nresultaria em _n_ instancias diferentes de ResourcesManager<T> em Environment, onde _n_ eh o numero de assets/resources diferentes (Texture, Music, etc).\r\n\r\nE para usar, seria:\r\n```\r\nResourcesManager<Texture> texture_manager;\r\nResourcesManager<Music> music_manager;\r\n\r\n...\r\n\r\nEnvironment* env = ...;\r\nTexture* texture = env->texture_manager.get(\"...\");\r\nMusic* music = env->music_manager.get(\"...\");\r\n```\r\n\r\nMas para manter como esta a Environment, com apenas uma instancia de ResourcesManager, teria que ser abordado de outra forma. O template precisaria ir para os metodos **get** e **acquire**:\r\n```\r\nresources_manager.get<Texture>(\"...\");\r\n```\r\n\r\nE minha duvida eh como eu referencio o mapa de textures da ResourcesManager dentro desse metodo **get** como um template.\r\n```\r\nclass ResourcesManager\r\n{\r\n...\r\nmap < string, shared_ptr<Texture> > m_textures;\r\nmap < string, shared_ptr<Music> > m_musics;\r\n...\r\n};\r\n\r\ntemplate <typename T>\r\nshared_ptr<T>\r\nget(const string& path)\r\n{\r\n\tif (m_?????.find(id) != m_?????.end())\r\n    {\r\n        return m_?????[id];\r\n    }\r\n\r\n    return acquire(id);\r\n}\r\n...\r\n```\r\n\r\nCaso eu tenha que implementar um metodo **get** e **acquire** pra cada tipo de asset/resource, nao resolveria o problema da duplicacao de codigo.\r\n\r\nTem um jeito melhor?"}}