-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
64 lines (57 loc) · 1.53 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <sys/time.h>
#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>
#include "life.h"
#include "draw.h"
#include "ui.h"
#include "bench.h"
int main(int argc, char *argv[])
{
int rows = 800;
int cols = 800;
int pixsize = 1;
// Initialize everything
Life *game = Life_MakeLife(cols, rows);
Draw *draw = Draw_MakeDraw(cols, rows, pixsize);
UI *ui = UI_MakeUI(game, draw);
Bench *bench = Bench_MakeBench();
// Draw initial cells
Life_DrawAllCells(game, draw);
Draw_UpdateDisplay(draw);
// Setup the UI object for action
ui->run = 1;
// Run the main game loop
Bench_Start(bench);
while(ui->run) {
if(!ui->paused && !ui->mouse_paused) {
Life_Iterate(game, ui);
//Life_DrawAllCells(game, draw);
UI_UpdateStatus(ui);
Draw_UpdateDisplay(draw);
SDL_Delay(ui->delay);
} else {
UI_UpdateStatus(ui);
Draw_UpdateDisplay(draw);
SDL_Delay(10);
}
while(UI_HandleEvents(ui)) {
// Main event handling
}
if(game->generations % 100 == 0) {
Bench_End(bench);
Bench_CalcElapsed(bench);
ui->gps = 100.0 / (bench->elapsed / 1000.0);
Bench_Start(bench);
}
}
// Always clean up after yourself
Life_DestroyLife(game);
Draw_DestroyDraw(draw);
UI_DestroyUI(ui);
}