-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
83 lines (61 loc) · 1.47 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL2/SDL.h>
#include "c_video.h"
#include "def.h"
#include "log.h"
#include "c_mem.h"
#include "w_wad.h"
#include "p_level.h"
#include "am_map.h"
int init() {
log_init();
log_set_level(LOGLEVEL_TRACE);
LOG_INFO("Logging initialized");
char* files[3];
files[0] = "wads/doom.wad";
files[1] = NULL;
files[2] = NULL;
w_init_files(files);
//w_log_lumpinfo();
p_load_level(1, 1);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
LOG_ERROR("SDL_Init error: %s", SDL_GetError());
return 0;
}
c_video_init(1280, 720);
return 1;
}
void main_loop() {
am_init();
int running = 1;
SDL_Event event;
while (running) {
am_update();
// clear buffer
memset(framebuffers[0], 0, SCREENWIDTH * SCREENHEIGHT * sizeof(uint8_t));
am_draw();
// display
c_video_display_frame();
while (SDL_PollEvent(&event)) {
if ((event.type == SDL_QUIT) ||
(event.type == SDL_KEYDOWN &&
event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)) {
running = 0;
break;
}
am_handle_event(&event);
}
usleep(30000); // TODO: proper fixed timestep
}
}
int main()
{
if (!init())
return EXIT_FAILURE;
main_loop();
c_free_all();
c_video_shutdown();
return EXIT_SUCCESS;
}