-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored SDL & message code (SDL1)
Added sys.c Renamed sys_sdl2.c to sys_sdl2.h Moved message code to message.h
- Loading branch information
Showing
7 changed files
with
110 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
#ifndef MESSAGE_H__ | ||
#define MESSAGE_H__ | ||
|
||
#include <string.h> | ||
|
||
#define MESSAGE_MAX 30 | ||
#define MESSAGE_TIMELIMIT 1000 | ||
#define MAX_MESSAGES 5 | ||
|
||
char *_queue[MAX_MESSAGES]; | ||
|
||
struct message_t { | ||
void (*add)(char *m, ...); | ||
char* (*get)(); | ||
void (*clear)(const char *m); | ||
void (*clear_all)(); | ||
}; | ||
|
||
static void add(char *m, ...) { | ||
int j; | ||
for (int i = 0; i < MAX_MESSAGES; i++) | ||
if (_queue[i] && strcmp(m, _queue[i]) == 0) | ||
return; | ||
for (int i = 0; i < MAX_MESSAGES; i++) | ||
if (!_queue[i]) | ||
j = i; | ||
_queue[ 0 + j ] = m; | ||
} | ||
|
||
static char* get() { | ||
for (int i = 0; i < MAX_MESSAGES; i++) | ||
if (_queue[i]) | ||
return _queue[i]; | ||
return 0; | ||
} | ||
|
||
static void clear(const char *m) { | ||
for (int i = 0; i < MAX_MESSAGES; i++) | ||
if (_queue[i] && strcmp(m, _queue[i]) == 0) | ||
_queue[i] = 0; | ||
} | ||
|
||
static void clear_all() { | ||
for (int i = 0; i < MAX_MESSAGES; i++) | ||
_queue[i] = 0; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
#include "message.h" | ||
|
||
struct message_t g_message = { | ||
.add = add, | ||
.get = get, | ||
.clear = clear, | ||
.clear_all = clear_all | ||
}; | ||
|
||
#include "sys_sdl2.h" | ||
|
||
struct sys_t g_sys = { | ||
.init = sdl2_init, | ||
.fini = sdl2_fini, | ||
.set_screen_size = sdl2_set_screen_size, | ||
.set_screen_palette = sdl2_set_screen_palette, | ||
.set_palette_amiga = sdl2_set_palette_amiga, | ||
.set_copper_bars = sdl2_set_copper_bars, | ||
.set_palette_color = sdl2_set_palette_color, | ||
.fade_in_palette = sdl2_fade_in_palette, | ||
.fade_out_palette = sdl2_fade_out_palette, | ||
.clear_slide = clear_slide, | ||
.resize_screen = sdl2_resize_screen, | ||
.update_screen = sdl2_update_screen, | ||
.update_screen_cached = sdl2_update_screen_cached, | ||
.shake_screen = sdl2_shake_screen, | ||
.transition_screen = sdl2_transition_screen, | ||
.process_events = sdl2_process_events, | ||
.sleep = sdl2_sleep, | ||
.get_timestamp = sdl2_get_timestamp, | ||
.start_audio = sdl2_start_audio, | ||
.stop_audio = sdl2_stop_audio, | ||
.lock_audio = sdl2_lock_audio, | ||
.unlock_audio = sdl2_unlock_audio, | ||
.render_load_sprites = render_load_sprites, | ||
.render_unload_sprites = render_unload_sprites, | ||
.render_add_sprite = render_add_sprite, | ||
.render_clear_sprites = render_clear_sprites, | ||
.render_set_sprites_clipping_rect = render_set_sprites_clipping_rect | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters