Include and link physfs properly.
[tuxanci.git] / src / client / screen.c
blob476cf3e1a9eaea7f39fdbb5e767ab05d33b1d884
1 #include <stdlib.h>
2 #include <assert.h>
4 #include "main.h"
5 #include "list.h"
7 #include "interface.h"
8 #include "screen.h"
9 #include "layer.h"
10 #include "myTimer.h"
12 /*#define DEBUG_TIME_DRAW*/
14 static screen_t *currentScreen;
15 static screen_t *futureScreen;
17 static list_t *listScreen;
19 static bool_t isScreenInit = FALSE;
21 bool_t screen_is_inicialized()
23 return isScreenInit;
26 screen_t *screen_new(char *name, void (*fce_start) (), void (*fce_event) (),
27 void (*fce_draw) (), void (*fce_stop) ())
29 screen_t *new;
31 assert(name != NULL);
32 assert(fce_start != NULL);
33 assert(fce_event != NULL);
34 assert(fce_draw != NULL);
35 assert(fce_stop != NULL);
37 new = malloc(sizeof(screen_t));
38 new->name = strdup(name);
39 new->fce_start = fce_start;
40 new->fce_event = fce_event;
41 new->fce_draw = fce_draw;
42 new->fce_stop = fce_stop;
44 return new;
47 void screen_destroy(screen_t *p)
49 assert(p != NULL);
51 free(p->name);
52 free(p);
55 void screen_register(screen_t *p)
57 assert(p != NULL);
59 debug("Registering screen [%s]", p->name);
61 list_add(listScreen, p);
64 void screen_init()
66 listScreen = list_new();
68 currentScreen = NULL;
69 futureScreen = NULL;
71 isScreenInit = TRUE;
74 static screen_t *findScreen(char *name)
76 screen_t *this;
77 int i;
79 for (i = 0; i < listScreen->count; i++) {
80 this = (screen_t *) listScreen->list[i];
81 assert(this != NULL);
83 if (strcmp(name, this->name) == 0) {
84 return this;
88 return NULL;
91 void screen_set(char *name)
93 futureScreen = findScreen(name);
94 assert(futureScreen != NULL);
97 void screen_switch()
99 if (futureScreen == NULL) {
100 return;
103 layer_flush();
105 if (currentScreen != NULL) {
106 debug("Stopping screen [%s]", currentScreen->name);
107 currentScreen->fce_stop();
110 currentScreen = futureScreen;
111 futureScreen = NULL;
113 debug("Starting screen [%s]", currentScreen->name);
115 currentScreen->fce_start();
118 void screen_start(char *name)
120 screen_set(name);
121 screen_switch();
124 char *screen_get()
126 assert(currentScreen != NULL);
127 return currentScreen->name;
130 void screen_draw()
132 static int count = 0;
134 count++;
136 if (count == 1) {
137 count = 0;
139 assert(currentScreen != NULL);
141 #ifdef DEBUG_TIME_DRAW
142 my_time_t prev;
144 prev = timer_get_current_timeMicro();
145 #endif /* DEBUG_TIME_DRAW */
147 currentScreen->fce_draw();
149 interface_refresh();
151 #ifdef DEBUG_TIME_DRAW
152 printf("c draw time = %d\n", timer_get_current_timeMicro() - prev);
153 #endif /* DEBUG_TIME_DRAW */
158 void screen_event()
160 assert(currentScreen != NULL);
162 currentScreen->fce_event();
164 #ifdef DEBUG_TIME_EVENT
165 printf("c event time = %d\n", timer_get_current_timeMicro() - prev);
166 #endif /* DEBUG_TIME_EVENT */
169 void screen_quit()
171 assert(listScreen != NULL);
173 list_destroy_item(listScreen, screen_destroy);
174 isScreenInit = FALSE;