This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPick4.cpp
97 lines (77 loc) · 2.32 KB
/
Pick4.cpp
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
#include <chrono>
#include <thread>
#include "Pick4.hpp"
#include "DisplayScene.hpp"
#include "ConsoleScene.hpp"
#include "P4Memory.hpp"
using std::string;
Pick4::Pick4(): console_(ConsoleScene::instance()), display_(DisplayScene::instance()), mem(P4Memory()) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return;
}
window_ = SDL_CreateWindow("Pick-4", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, screen_width << 2,
screen_height << 2, SDL_WINDOW_SHOWN);
if (!window_) {
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
return;
}
SDL_SetWindowResizable(window_, SDL_TRUE);
renderer_ = SDL_CreateRenderer(window_, -1, 0);
SDL_RenderSetLogicalSize(renderer_, screen_width, screen_height);
if (!console_.init(renderer_)) {
printf("ConsoleScene could not be created! SDL_Error: %s\n", SDL_GetError());
return;
}
if (!display_.init(renderer_)) {
printf("DisplayScene not be created! SDL_Error: %s\n", SDL_GetError());
return;
}
FileSystem::init();
lua.set_function("cls", []() { DisplayScene::instance().cls(); });
lua.set_function("pixel", [](int x,int y,int c) { DisplayScene::instance().pixel(x, y, c); });
lua.set_function(
"line", [](int x0,int y0,int x1, int y1, int c) { DisplayScene::instance().line(x0, y0, x1, y1, c); });
lua_script_ = FileSystem::load("hello").code;
}
Pick4& Pick4::instance() {
static Pick4 instance;
return instance;
}
void Pick4::create_window() {}
void Pick4::run() {
scene_type next = scene_display;
while (next != scene_exit) {
switch (next) {
case scene_console: next = console_.run();
break;
case scene_display: next = display_.run();
break;
case scene_editor:
default:
next = display_.run();
break;
}
}
close();
}
long Pick4::time() { return SDL_GetTicks(); }
void Pick4::set_script(const std::string& script) { lua_script_ = script; }
bool Pick4::load_script() {
lua.script(lua_script_);
return true;
}
bool Pick4::run_draw_script() {
lua.script("_draw()");
return true;
}
bool Pick4::run_update_script() {
lua.script("_update()");
return true;
}
void Pick4::close() {
SDL_DestroyWindow(window_);
window_ = nullptr;
SDL_Quit();
}