1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING |
---|
17 | |
---|
18 | #include "resource.h" |
---|
19 | #include "filesys/file.h" |
---|
20 | |
---|
21 | ObjectListDefinition(Resource); |
---|
22 | |
---|
23 | |
---|
24 | std::vector<Resource::Type*> Resource::_resourceTypes; |
---|
25 | |
---|
26 | //! GLOBALS |
---|
27 | Directory Resource::_mainGlobalPath; |
---|
28 | std::vector<Directory> Resource::_globalPaths; |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * standard constructor |
---|
33 | */ |
---|
34 | Resource::Resource (Resource::Type* type) |
---|
35 | : _pointer(NULL), _type(type) |
---|
36 | { |
---|
37 | this->registerObject(this, Resource::_objectList); |
---|
38 | |
---|
39 | if(this->_type->id() == -1) |
---|
40 | { |
---|
41 | Resource::_resourceTypes.push_back(this->_type); |
---|
42 | this->_type->setID(Resource::_resourceTypes.size()-1); |
---|
43 | } |
---|
44 | |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * standard deconstructor |
---|
49 | */ |
---|
50 | Resource::~Resource () |
---|
51 | { |
---|
52 | // delete what has to be deleted here |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | std::string Resource::locateFile(const std::string& fileName) |
---|
57 | { |
---|
58 | if (File(fileName).exists()) |
---|
59 | return fileName; |
---|
60 | else if ((Resource::_mainGlobalPath+File(fileName)) . exists() ) |
---|
61 | return (Resource::_mainGlobalPath + File(fileName)).name(); |
---|
62 | |
---|
63 | |
---|
64 | return std::string("/home/bensch/svn/orxonox/data/") + fileName; |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | Resource::Pointer* Resource::acquireResource(const std::string& loadString) |
---|
70 | { |
---|
71 | //const Resource::Type* const type = Resource::_resourceTypes[this->_type->id()]; |
---|
72 | |
---|
73 | for (unsigned int i = 0; i < _type->storedResources().size(); ++i) |
---|
74 | if (_type->storedResources()[i]->_pointer->loadString() == loadString) |
---|
75 | return _type->storedResources()[i]->_pointer; |
---|
76 | |
---|
77 | return NULL; |
---|
78 | } |
---|
79 | |
---|
80 | void Resource::setMainGlobalPath(const Directory& directory) |
---|
81 | { |
---|
82 | Resource::_mainGlobalPath = directory; |
---|
83 | Resource::_mainGlobalPath.open(); |
---|
84 | } |
---|
85 | |
---|
86 | void Resource::addGlobalPath(const Directory& directory) |
---|
87 | { |
---|
88 | std::vector<Directory>::const_iterator it = std::find(Resource::_globalPaths.begin(), Resource::_globalPaths.end(), directory); |
---|
89 | if (it == Resource::_globalPaths.end()) |
---|
90 | Resource::_globalPaths.push_back(directory); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | void Resource::addResource(Resource::Pointer* pointer) |
---|
96 | {} |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | void Resource::KeepLevel::setKeepLevelName(unsigned int level, const std::string& name) |
---|
108 | { |
---|
109 | if (_keepLevelName.size() <= level) |
---|
110 | _keepLevelName.resize(level+1); |
---|
111 | _keepLevelName[level] = name; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | Resource::Pointer::Pointer(const std::string& loadString, const Resource::KeepLevel& keeplevel) |
---|
124 | { |
---|
125 | } |
---|
126 | |
---|
127 | void Resource::Type::setID(int id) |
---|
128 | { |
---|
129 | this->_id = id; |
---|
130 | } |
---|