-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinigin.cpp
More file actions
94 lines (78 loc) · 2.2 KB
/
Copy pathMinigin.cpp
File metadata and controls
94 lines (78 loc) · 2.2 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
#include <stdexcept>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include "Minigin.h"
#include "InputManager.h"
#include "SceneManager.h"
#include "Renderer.h"
#include "ResourceManager.h"
SDL_Window* g_window{};
void PrintSDLVersion()
{
SDL_version version{};
SDL_VERSION(&version);
printf("We compiled against SDL version %u.%u.%u ...\n",
version.major, version.minor, version.patch);
SDL_GetVersion(&version);
printf("We are linking against SDL version %u.%u.%u.\n",
version.major, version.minor, version.patch);
SDL_IMAGE_VERSION(&version);
printf("We compiled against SDL_image version %u.%u.%u ...\n",
version.major, version.minor, version.patch);
version = *IMG_Linked_Version();
printf("We are linking against SDL_image version %u.%u.%u.\n",
version.major, version.minor, version.patch);
SDL_TTF_VERSION(&version)
printf("We compiled against SDL_ttf version %u.%u.%u ...\n",
version.major, version.minor, version.patch);
version = *TTF_Linked_Version();
printf("We are linking against SDL_ttf version %u.%u.%u.\n",
version.major, version.minor, version.patch);
}
dae::Minigin::Minigin(const std::string &dataPath)
{
PrintSDLVersion();
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
throw std::runtime_error(std::string("SDL_Init Error: ") + SDL_GetError());
}
g_window = SDL_CreateWindow(
"Programming 4 assignment",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640,
480,
SDL_WINDOW_OPENGL
);
if (g_window == nullptr)
{
throw std::runtime_error(std::string("SDL_CreateWindow Error: ") + SDL_GetError());
}
Renderer::GetInstance().Init(g_window);
ResourceManager::GetInstance().Init(dataPath);
}
dae::Minigin::~Minigin()
{
Renderer::GetInstance().Destroy();
SDL_DestroyWindow(g_window);
g_window = nullptr;
SDL_Quit();
}
void dae::Minigin::Run(const std::function<void()>& load)
{
load();
auto& renderer = Renderer::GetInstance();
auto& sceneManager = SceneManager::GetInstance();
auto& input = InputManager::GetInstance();
// todo: this update loop could use some work.
bool doContinue = true;
while (doContinue)
{
doContinue = input.ProcessInput();
sceneManager.Update();
renderer.Render();
}
}