-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.cpp
More file actions
103 lines (71 loc) · 1.95 KB
/
App.cpp
File metadata and controls
103 lines (71 loc) · 1.95 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Created by shawn on 7/26/2025.
//
#include "App.h"
#include <cstdio>
#include <SDL_ttf.h>
#include <SDL2/SDL_image.h>
#include "Draw.h"
#include "Audio/SoundManager.h"
App* App::applicationInstance;
SDL_Renderer *App::getRenderer() const {
return renderer;
}
SDL_Window *App::getWindow() const {
return window;
}
void App::setRenderer(SDL_Renderer *renderer) {
this->renderer = renderer;
}
void App::setWindow(SDL_Window *window) {
this->window = window;
}
App *App::getInstance() {
return applicationInstance;
}
const char* App::initialize(App::Settings* settings) {
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
return SDL_GetError();
}
if(name.length() == 0) {
return SDL_GetError();
}
auto* window =
SDL_CreateWindow(name.c_str(),
settings->windowPosition.x,
settings->windowPosition.y,
settings->windowDimensions.x,
settings->windowDimensions.y, settings->windowFlags);
if(!window) {
return SDL_GetError();
}
setWindow(window);
for(auto& hint : settings->sdlHints) {
if(SDL_SetHint(hint.name.c_str(), hint.value.c_str()) != SDL_TRUE) {
hint.failed = true;
}
}
if(IMG_Init(settings->imageFlags) == -1) {
return SDL_GetError();
}
if(TTF_Init() == -1) {
return SDL_GetError();
}
auto* renderer = SDL_CreateRenderer(window, settings->index, settings->renderFlags);
if(!renderer) {
return SDL_GetError();
}
setRenderer(renderer);
this->settings = settings;
createTools();
return nullptr;
}
void App::createTools() const {
//create a new Draw tool instance, uses singleton type behaviour
new Draw();
//create a new sound manager instance, uses singleton type behaviour.
new SoundManager(settings->audioRenderingSettings, settings->audioRenderingDevice);
}
App::Settings *App::getSettings() const {
return settings;
}