-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathempty_project.cpp
More file actions
72 lines (60 loc) · 1.75 KB
/
empty_project.cpp
File metadata and controls
72 lines (60 loc) · 1.75 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
#include "console.h"
#include "file_system.h"
#include "pen.h"
#include "threads.h"
namespace
{
void* user_setup(void* params);
loop_t user_update();
void user_shutdown();
} // namespace
// entry function, where we can configure low level details, like window or renderer in pen_creation_params
namespace pen
{
pen_creation_params pen_entry(int argc, char** argv)
{
pen::pen_creation_params p;
p.window_width = 1280;
p.window_height = 720;
p.window_title = "empty_project";
p.window_sample_count = 4;
p.user_thread_function = user_setup;
p.flags = pen::e_pen_create_flags::console_app;
return p;
}
} // namespace pen
// web friendly main loop
namespace
{
pen::job_thread_params* job_params;
pen::job* p_thread_info;
void* user_setup(void* params)
{
PEN_LOG("User Setup");
// unpack the params passed to the thread and signal to the engine it ok to proceed
job_params = (pen::job_thread_params*)params;
p_thread_info = job_params->job_info;
pen::semaphore_post(p_thread_info->p_sem_continue, 1);
// we call user_update once per frame
pen_main_loop(user_update);
return PEN_THREAD_OK;
}
void user_shutdown()
{
PEN_LOG("User Shutdown");
pen::semaphore_post(p_thread_info->p_sem_terminated, 1);
}
loop_t user_update()
{
PEN_LOG("User Thread Update");
pen::thread_sleep_ms(16);
// msg from the engine we want to terminate
if (pen::semaphore_try_wait(p_thread_info->p_sem_exit))
{
user_shutdown();
pen_main_loop_exit();
}
exit(0);
pen_main_loop_continue();
}
} // namespace