forked from ScatteredRay/SurfaceTension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoresystems.cpp
151 lines (121 loc) · 3.04 KB
/
coresystems.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "coresystems.h"
#include "systemmanager.h"
#include "ploy/symbol.h"
#include <SDL.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include "glrender.h"
#include <assert.h>
struct sdl_system
{
};
void* init_sdl_system(SystemManager* SM)
{
SDL_Init(SDL_INIT_JOYSTICK);
return new sdl_system();
}
void destroy_sdl_system(void* System)
{
SDL_Quit();
delete (sdl_system*)System;
}
void declare_sdl_system(SystemManager* SM)
{
declare_system(SM, system_manager_symbol(SM, "SDL"), init_sdl_system, destroy_sdl_system);
}
struct tick_system
{
unsigned int TickCount;
unsigned int TickAccum;
};
void* init_tick_system(SystemManager* SM)
{
system_manager_require(SM, "SDL");
tick_system* Ticker = new tick_system();
Ticker->TickCount = SDL_GetTicks();
Ticker->TickAccum = 0;
return Ticker;
}
void destroy_tick_system(void* System)
{
delete (tick_system*)System;
}
void tick_system_tick(tick_system* System)
{
int NewTick = SDL_GetTicks();
System->TickAccum += NewTick - System->TickCount;
System->TickCount = NewTick;
float DeltaTime = 0.0f; // Box2D assumes fixed timestep, lock it?
if(System->TickAccum >= 20)
DeltaTime = 0.02f;
while(System->TickAccum >= 20)
{
// Run All Ticks
//UpdateInput(LocalPlayerInput);
//UpdatePlayerInput(MainPlayer, LocalPlayerInput);
//UpdatePlayer(DeltaTime, MainPlayer);
//PhysicsWorld->Step(DeltaTime, 10);
System->TickAccum -= 20;
}
if(DeltaTime == 0.0f)
{
// Run Needed Ticks (Should only be Box2d's debug rendering, should be able to remove.
//PhysicsWorld->Step(DeltaTime, 10);
}
}
void declare_tick_system(SystemManager* SM)
{
declare_system(SM, system_manager_symbol(SM, "ticker"), init_tick_system, destroy_tick_system);
}
struct glut_system
{
tick_system* Ticker;
gl_render* renderer;
};
// GLUT doesn't want us to pass a user pointer into the draw func, so we use a global
glut_system* GLUT_sys;
void* init_glut_system(SystemManager* SM)
{
GLUT_sys = new glut_system;
GLUT_sys->Ticker = (tick_system*)system_manager_require(SM, "ticker");
GLUT_sys->renderer = NULL;
// Need way to get these in.
int argc = 0;
char** argv = NULL;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1280, 720);
glutInitWindowPosition(100, 100);
glutCreateWindow("Surface Tension\n");
return GLUT_sys;
}
void destroy_glut_system(void* System)
{
delete (glut_system*)System;
}
void glut_system_set_renderer(glut_system* glut, gl_render* renderer)
{
glut->renderer = renderer;
}
GLvoid glut_system_draw_func()
{
assert(GLUT_sys->renderer);
assert(GLUT_sys->Ticker);
tick_system_tick(GLUT_sys->Ticker);
gl_render_do_render(GLUT_sys->renderer);
glutSwapBuffers();
glutPostRedisplay();
}
void glut_system_run(void* System)
{
glutDisplayFunc(glut_system_draw_func);
glutMainLoop();
}
void declare_glut_system(SystemManager* SM)
{
declare_system(SM, system_manager_symbol(SM, "GLUT"), init_glut_system, destroy_glut_system);
}
void set_glut_system_run(SystemManager* SM)
{
set_run_system(SM, system_manager_symbol(SM, "GLUT"), glut_system_run);
}