-
Notifications
You must be signed in to change notification settings - Fork 2
/
SpriteLoadTask.h
38 lines (34 loc) · 1.16 KB
/
SpriteLoadTask.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
#ifndef TRIPPIN_SPRITELOADTASK_H
#define TRIPPIN_SPRITELOADTASK_H
#include <unordered_map>
#include <vector>
#include <string>
#include <memory>
#include <thread>
#include "SDL.h"
#include "Scale.h"
#include "SpriteLoader.h"
namespace trippin {
// A background task for loading surfaces into an unordered map for a predetermined set of sprites.
// The call sequence from the main thread is: (1) start -> (2) join -> (3) take
class SpriteLoadTask {
public:
SpriteLoadTask(const SpriteLoader &spriteLoader, std::vector<std::string> names);
~SpriteLoadTask();
void start();
void join();
void load();
bool joined() const;
bool started() const;
std::unique_ptr<std::unordered_map<std::string, std::vector<SDL_Surface *>>> take();
private:
std::unique_ptr<std::unordered_map<std::string, std::vector<SDL_Surface *>>> surfaces;
std::vector<std::string> names;
std::thread thread;
const SpriteLoader &spriteLoader;
bool threadStarted{};
bool threadJoined{};
std::unordered_map<std::string, std::vector<SDL_Surface *>> loadSurfaces() const;
};
}
#endif