-
Notifications
You must be signed in to change notification settings - Fork 0
/
Process.c
135 lines (112 loc) · 2.9 KB
/
Process.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
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
/*
Aside from windows message processing, this module is
the highest level of abstraction. The function
process_control(...) is called every frame. It's
responsible for handing control to the active scene and
telling that scene how long it's been running. It
manages fading between scenes and framerate profiling.
*/
#include <windows.h>
#include "graphics.h"
#include "common.h"
#include "process.h"
#include "credits.h"
#include "rohan.h"
#include "demo.h"
//#include "moria.h" Wasn't finished in time.
#include "intro.h"
#include "fps.h"
#define FADE_DURATION 2000
#define NUM_SCENES 4
/*
All scenes are time based. Everything is updated
and drawn given the amount of time that has passed
since that scene started.
*/
typedef struct
{
void (*update) (unsigned long); // Update function. Draw objects based on current time.
void (*setup) (void); // Startup function. Allocated data etc.
void (*end) (void); // Shut down function. Free data etc.
unsigned long duration;
} scene_t;
static scene_t scene_index[NUM_SCENES] = {
{ // The opening LOTR graphic scene.
intro_process,
intro_setup,
intro_end,
7000
},
{ // The spinning rings scene.
ring_poem_process,
ring_poem_setup,
ring_poem_end,
58000
},
{ // The hilly terrain scene.
rohan_terrain_process,
rohan_terrain_setup,
rohan_terrain_end,
35000
},
// { // Wasn't finished in time. Moria tunnels.
// moria_process,
// moria_setup,
// moria_end,
// 35000
// },
{ // A brief credits list.
credits_process,
credits_setup,
credits_end,
67000
}
};
static unsigned long process_timer;
static int scene_running = 0;
static int scene = 0;
static void process_timer_reset(void)
{
process_timer = timeGetTime();
}
static unsigned long process_timer_get(void)
{
return (unsigned long) (timeGetTime() - process_timer);
}
int process_control(void)
{
unsigned long elapsed;
if(!scene_running) {
// A scene needs to be initialized.
scene_index[scene].setup();
process_timer_reset();
scene_running = 1;
}
elapsed = process_timer_get();
scene_index[scene].update(elapsed);
// Fade between the scenes.
if(elapsed >= scene_index[scene].duration - FADE_DURATION)
graphics_fade(1.0F / FADE_DURATION * (elapsed
- (scene_index[scene].duration - FADE_DURATION)));
else if(elapsed < FADE_DURATION)
graphics_fade(1.0F / FADE_DURATION * (FADE_DURATION - elapsed));
#ifdef BUILD_DEBUG
fps_update(elapsed);
#endif
if(process_timer_get() >= scene_index[scene].duration) {
// This scene has ended. Move on to the next one.
scene_index[scene].end();
scene_running = 0;
scene++;
}
// Exit when all scenes are finished.
if(scene == NUM_SCENES || GetAsyncKeyState(VK_ESCAPE)) {
if(scene_running) {
scene_index[scene].end();
if(scene != 3)
scene_index[3].end();
}
return 1;
}
return 0;
}