-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.cpp
More file actions
67 lines (53 loc) · 1.43 KB
/
scene.cpp
File metadata and controls
67 lines (53 loc) · 1.43 KB
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
65
66
67
#include "scene.h"
namespace gamecore {
gamecore::Scene::Scene(sf::RenderWindow* window)
: window_(window)
{
}
void Scene::Draw()
{
for (auto&[priority, items] : userInterfaceDraw_)
{
for (std::unique_ptr<sf::Drawable>& draw : *items.get())
{
window_->draw(*draw.get());
}
}
}
void Scene::AddTexture(const std::filesystem::path& file, const int texture, const bool isRepeated)
{
std::unique_ptr<sf::Texture> newTexture = std::unique_ptr<sf::Texture>(LoadFromFile<sf::Texture>(file));
newTexture->setRepeated(isRepeated);
texturePool_.insert({ texture, std::move(newTexture) });
}
void Scene::AddFont(const std::filesystem::path& file, const int font)
{
std::unique_ptr<sf::Font> newFont = std::unique_ptr<sf::Font>(LoadFromFile<sf::Font>(file));
fontPool_.insert({ font, std::move(newFont) });
}
sf::Texture* Scene::GetTexture(const int id) const
{
return texturePool_.find(id)->second.get();
}
sf::Font* Scene::GetFont(const int id) const
{
return fontPool_.find(id)->second.get();
}
ExitSceneCode Scene::GetExitCode() const
{
return exitCode_;
}
Scene::~Scene()
{
if (camera_) {
delete camera_;
}
if (eventsGame_) {
delete eventsGame_;
}
}
int RandomGenerate(std::mt19937& generator, int min, int max) {
generator.seed(std::chrono::steady_clock::now().time_since_epoch().count());
return std::uniform_int_distribution(min, max)(generator);
}
} // namespace gamecore