-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframeFactory.h
64 lines (56 loc) · 2.59 KB
/
frameFactory.h
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
#include <string>
#include <vector>
#include <map>
#include "frame.h"
#include "gamedata.h"
// The FrameFactory makes frames and reads the corresponding SDL_Surface,
// storing the frames and their corresponding SDL_Surface (es) in maps.
// The FrameFactory treats the Frame class as a Flyweight in the sense
// that if you use the FrameFactory to make a frame you are assuming
// that you will also reuse both the Frame and the corresponding
// SDL_Surface. The intent of this FrameFactory is to facilitate
// efficient management of resources (i.e., both construction and
// deletion) and that both the Frame and the SDL_Surface will be
// available until the end of the animation.
class FrameFactory {
public:
static FrameFactory& getInstance();
~FrameFactory();
// The next constructor s/ only be used when the Frames's surface
// starts at (0, 0) in the sprite sheet, and the frame uses the
// entire sheet. For example, a Frame containing an orb or background.
// The original surface is read from a file and stored in surfaces,
// and ExtractSurface is not used. This surface is passed to Frame.
Frame* getFrame(const std::string&);
// The next constructor is for a MultiSprite, a multi-frame sprite.
// The sprite sheet surface is saved in the surfaces map, and
// individual surfaces will be extracted, using ExtractSurface, from
// the sprite sheet surface and these individual surfaces will
// be stored in the vector of Frames in multiframes.
// Therefore, this constructor should be used when an individual
// Frame's surface is found on only a part of sprite sheet.
// src_x and src_y are passed will be computed in getFrames and
// passed as parameters to the Frame constructor, but the Frame
// width and height will be obtained from the XML:
std::vector<Frame*> getFrames(const std::string&);
private:
const Gamedata& gdata;
// The next map stores surfaces for single frame sprites:
std::map<std::string, SDL_Surface*> surfaces;
// The next map stores surfaces for Multi-frame sprites. The frames
// will be extracted from the sprite sheet and stored in multiSurfaces:
std::map<std::string, std::vector<SDL_Surface*> > multiSurfaces;
// The next map stores Frames for single frame sprites:
std::map<std::string, Frame*> frames;
// The next map stores Frames for Multi-frame sprites:
std::map<std::string, std::vector<Frame*> > multiFrames;
FrameFactory() :
gdata( Gamedata::getInstance() ),
surfaces(),
multiSurfaces(),
frames(),
multiFrames()
{}
FrameFactory(const FrameFactory&);
FrameFactory& operator=(const FrameFactory&);
};