1 | |
---|
2 | #include "resource_md2.h" |
---|
3 | #include "substring.h" |
---|
4 | #include "multi_type.h" |
---|
5 | #include "debug.h" |
---|
6 | |
---|
7 | |
---|
8 | ResourceMD2::ResourceMD2(const std::string& modelName, const std::string& skinName, float scale, const Resources::KeepLevel& keepLevel) |
---|
9 | : Resource(&ResourceMD2::type) |
---|
10 | { |
---|
11 | Resources::StorePointer* ptr = this->acquireResource(loadString(modelName, skinName, scale)); |
---|
12 | |
---|
13 | if (ptr) |
---|
14 | { |
---|
15 | PRINTF(0)("FOUND MD2: %s\n", modelName.c_str()); |
---|
16 | this->acquireData(static_cast<ResourceMD2::MD2ResourcePointer*>(ptr)->ptr()); |
---|
17 | } |
---|
18 | else |
---|
19 | { |
---|
20 | PRINTF(0)("NOT FOUND MD2: %s\n", modelName.c_str()); |
---|
21 | std::string modelFileName = this->Resource::locateFile(modelName); |
---|
22 | //std::string skinFileName = this->Resource::locateFile(skinName); |
---|
23 | this->MD2Model::load(modelFileName, skinName, scale); |
---|
24 | this->Resource::addResource(new ResourceMD2::MD2ResourcePointer(loadString(modelName, skinName, scale), keepLevel, this->MD2Model::dataPointer())); |
---|
25 | } |
---|
26 | |
---|
27 | } |
---|
28 | |
---|
29 | ResourceMD2 ResourceMD2::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel) |
---|
30 | { |
---|
31 | SubString loadValues(loadString, ','); |
---|
32 | std::string modelName; |
---|
33 | std::string skinName; |
---|
34 | float scale = 1.0f; |
---|
35 | if (loadValues.size() > 0) |
---|
36 | modelName = loadValues[0]; |
---|
37 | if (loadValues.size() > 1) |
---|
38 | skinName = loadValues[1]; |
---|
39 | if (loadValues.size() > 2) |
---|
40 | scale = MultiType(loadValues[2]).getFloat(); |
---|
41 | |
---|
42 | return ResourceMD2(modelName, skinName, scale, keepLevel); |
---|
43 | } |
---|
44 | |
---|
45 | std::string ResourceMD2::loadString(const std::string& modelName, const std::string& skinName, float scale) |
---|
46 | { |
---|
47 | return modelName + ',' + skinName + ',' + MultiType(scale).getString(); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | Resources::tType<ResourceMD2> ResourceMD2::type("MD2"); |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | ResourceMD2::MD2ResourcePointer::MD2ResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const MD2Data::Pointer& data) |
---|
58 | : Resources::StorePointer(loadString, keepLevel) , pointer(data) |
---|
59 | {} |
---|
60 | |
---|
61 | |
---|