-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframefactory.cpp
53 lines (47 loc) · 2.05 KB
/
framefactory.cpp
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
#include "framefactory.h"
FrameFactory::FrameFactory():frame(),surface(){
}
FrameFactory::~FrameFactory(){
std::cout<<"framefactory destructor"<<std::endl;
while(!frame.empty()){
std::map<std::string, std::vector<Frame*> >::iterator it=frame.begin();
for(unsigned int i = 0; i < it->second.size(); i++){
delete it->second[i];
}
it->second.clear();
std::cout<<"framefactory delete frame "<<it->first<<std::endl;
frame.erase(it);
}
while(!surface.empty()){
std::map<std::string, SDL_Surface* >::iterator it=surface.begin();
std::cout<<"framefactory delete surface "<<it->first<<std::endl;
SDL_FreeSurface(it->second);
surface.erase(it);
}
}
std::vector<Frame*> FrameFactory::getFrame(std::string key, std::string action = ""){
std::vector<Frame*> f;
if (frame.find(key+action) != frame.end()){
f = frame[key+action];
}
else{
SDL_Surface* surf = NULL;
if (surface.find(key) != surface.end())
surf = surface[key];
else{
surf = IOManager::getInstance().loadAndSet(Gamedata::getInstance()->getXmlStr(key+"File"),Gamedata::getInstance()->getXmlBool(key+"Transparency"));
surface[key] = surf;
}
for(int j = 0; j < Gamedata::getInstance()->getXmlInt(key + action + "NumberOfFramesY"); j++){
for(int i = 0; i < Gamedata::getInstance()->getXmlInt(key + action + "NumberOfFrames"); i++){
f.push_back(new Frame(surf,
Gamedata::getInstance()->getXmlInt(key + action + "Width")/Gamedata::getInstance()->getXmlInt(key + action + "NumberOfFrames"),
Gamedata::getInstance()->getXmlInt(key + action + "Height")/Gamedata::getInstance()->getXmlInt(key + action + "NumberOfFramesY"),
Gamedata::getInstance()->getXmlInt(key + action + "Width")*i/Gamedata::getInstance()->getXmlInt(key + action + "NumberOfFrames") + Gamedata::getInstance()->getXmlInt(key + action + "SrcX"),
Gamedata::getInstance()->getXmlInt(key + action + "Height")*j/Gamedata::getInstance()->getXmlInt(key + action + "NumberOfFramesY") + Gamedata::getInstance()->getXmlInt(key + action + "SrcY")));
}
}
frame[key + action] = f;
}
return f;
}