-
Notifications
You must be signed in to change notification settings - Fork 1
/
platform.c
executable file
·144 lines (123 loc) · 3.01 KB
/
platform.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
136
137
138
139
140
141
142
143
#include "platform.h"
#include "config.h"
#include "location.h"
#include "media.h"
#include "sdl_ogl.h"
#include <stdlib.h>
struct platform *platform_start;
static int count = 0;
static int has_unknown = 0;
static struct platform platform_unknown = { NULL, NULL, "???" };
int platform_count( void ) {
return count;
}
void platform_add( struct platform *platform, struct platform *after ) {
if( after == NULL ) {
platform->prev = platform;
platform->next = platform;
}
else {
after->next->prev = platform;
platform->next = after->next;
after->next = platform;
platform->prev = after;
}
}
void platform_add_unknown( void ) {
if( has_unknown == 0 ) {
if( platform_start ) {
platform_unknown.next = platform_start;
platform_unknown.prev = platform_start->prev;
platform_start->prev->next = &platform_unknown;
platform_start->prev = &platform_unknown;
}
else {
platform_start = &platform_unknown;
platform_start->next = platform_start;
platform_start->prev = platform_start;
}
count++;
has_unknown = 1;
}
}
void platform_free_textures( void ) {
struct platform *p = platform_start;
if( p ) {
do {
if( p->texture ) {
ogl_free_texture( p->texture );
p->texture = NULL;
}
p = p->next;
} while( p != platform_start );
}
}
int platform_load_textures( void ) {
struct platform *p = platform_start;
if( p ) {
do {
if( p->image_file && p->image_file[0] ) {
p->texture = sdl_create_texture( p->image_file );
}
p = p->next;
} while( p != platform_start );
}
return 0;
}
int platform_init( void ) {
struct config_platform *c = config_get()->platforms;
struct platform *platform = NULL;
struct platform *prev = NULL;
while( c ) {
platform = malloc( sizeof(struct platform) );
if( platform ) {
memset( platform, 0, sizeof(struct platform) );
platform->name = c->name;
location_get_match( image_type_name(IMAGE_PLATFORM), platform->name, platform->image_file );
prev = platform_start;
if( platform_start ) {
prev = platform_start->prev;
while( strcasecmp( prev->name, platform->name ) > 0 ) {
prev = prev->prev;
if( prev == platform_start->prev ) break;
}
}
platform_add( platform, prev );
if( !platform_start || strcasecmp( platform->name, platform_start->name ) < 0 ) {
platform_start = platform;
}
count++;
}
else {
fprintf( stderr, "Error: Couldn't allocate memeory for platform object\n" );
return -1;
}
c = c->next;
}
platform_load_textures();
return 0;
}
void platform_free( void ) {
platform_free_textures();
}
void platform_pause( void ) {
platform_free_textures();
}
int platform_resume( void ) {
return platform_load_textures();
}
struct platform *platform_first( void ) {
return platform_start;
}
struct platform *platform_get( const char *name ) {
struct platform *g = platform_start;
if( name && *name ) {
while( g ) {
if( strcasecmp( g->name, name ) == 0 )
return g;
if( g == platform_start->prev ) break;
g = g->next;
}
}
return &platform_unknown;
}