-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleResources.cpp
More file actions
77 lines (59 loc) · 1.65 KB
/
ModuleResources.cpp
File metadata and controls
77 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "ModuleResources.h"
#include "ResourceMesh.h"
#include "ModuleFS.h"
#include "Application.h"
#include "Globals.h"
#include <string>
#pragma comment (lib, "Assimp/libx86/assimp.lib")
#include "Assimp/include/cimport.h"
#include "Assimp/include/scene.h"
#include "Assimp/include/postprocess.h"
#include "Assimp/include/cfileio.h"
#pragma comment (lib, "Devil/libx86/DevIL.lib")
#pragma comment (lib, "Devil/libx86/ILU.lib")
#pragma comment (lib, "Devil/libx86/ILUT.lib")
#include "Devil/include/il.h"
#include "Devil/include/ilu.h"
#include "Devil/include/ilut.h"
ModuleResources::ModuleResources(Application* app, bool start_enabled) : Module(app, start_enabled)
{}
ModuleResources::~ModuleResources()
{
resources.clear();
}
Resource* ModuleResources::Get(std::string& uid)
{
std::map<std::string, Resource*>::iterator it = resources.find(uid);
if (it != resources.end())
return it->second;
return nullptr;
}
const Resource* ModuleResources::Get(std::string& uid) const
{
std::map<std::string, Resource*>::const_iterator it = resources.find(uid);
if (it != resources.end())
return it->second;
return nullptr;
}
Resource* ModuleResources::LoadResource(std::string& imported_file)
{
Resource* res = nullptr;
if (res = Get(imported_file))
{
uint instances = res->AddInstance();
if (instances == 1) // first instance of the object
res->LoadToMemory();
return res;
}
return nullptr;
}
void ModuleResources::UnLoadResource(std::string& imported_file)
{
Resource* res = nullptr;
if (res = Get(imported_file))
{
uint instances = res->RemoveInstance();
if (instances == 0) // last instance of the object
res->UnLoadToMemory();
}
}