Skip to content

Commit

Permalink
renderer programmierung vereinfacht
Browse files Browse the repository at this point in the history
git-svn-id: http://infon.googlecode.com/svn/branches/renderer@109 8171fb75-e542-0410-96e4-03d5dd800671
  • Loading branch information
dividuum committed Nov 27, 2006
1 parent 5cdb787 commit 8933f13
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 119 deletions.
26 changes: 9 additions & 17 deletions aa_gui.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@


#define SCALE 4 #define SCALE 4


#include "client_world.h"
#include "client_creature.h"
#include "client_player.h"
#include "renderer.h" #include "renderer.h"


#include "aalib.h" #include "aalib.h"


static const infon_api_t *infon;

static aa_context *context; static aa_context *context;
static unsigned char *bitmap; static unsigned char *bitmap;
static aa_palette palette; static aa_palette palette;
Expand Down Expand Up @@ -68,7 +63,7 @@ __AA_CONST static int pal[] =
63, 63, 49, 63, 63, 50, 63, 63, 51, 63, 63, 52, 63, 63, 52, 63, 63, 53, 63, 63, 54, 63, 63, 55, 63, 63, 49, 63, 63, 50, 63, 63, 51, 63, 63, 52, 63, 63, 52, 63, 63, 53, 63, 63, 54, 63, 63, 55,
63, 63, 56, 63, 63, 57, 63, 63, 58, 63, 63, 59, 63, 63, 60, 63, 63, 61, 63, 63, 62, 63, 63, 63}; 63, 63, 56, 63, 63, 57, 63, 63, 58, 63, 63, 59, 63, 63, 60, 63, 63, 61, 63, 63, 62, 63, 63, 63};


static int null_open(int w, int h, int fs) { static int aarenderer_open(int w, int h, int fs) {
int argc = 1; int argc = 1;
char *argv[] = { "foo", NULL }; char *argv[] = { "foo", NULL };
int i; int i;
Expand All @@ -87,10 +82,10 @@ static int null_open(int w, int h, int fs) {
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
aa_setpalette(palette, i, pal[i * 3] * 4, pal[i * 3 + 1] * 4, pal[i * 3 + 2] * 4); aa_setpalette(palette, i, pal[i * 3] * 4, pal[i * 3 + 1] * 4, pal[i * 3 + 2] * 4);
aa_hidecursor(context); aa_hidecursor(context);
return 1; return 1;
} }


static void null_close() { static void aarenderer_close() {
aa_close(context); aa_close(context);
} }


Expand All @@ -106,7 +101,7 @@ static void draw_creature(const client_creature_t *creature, void *opaque) {
bitmap[y * aa_imgwidth(context) + x] = 0xFF; bitmap[y * aa_imgwidth(context) + x] = 0xFF;
} }


static void null_tick(int gt, int delta) { static void aarenderer_tick(int gt, int delta) {
const client_world_info_t *worldsize = infon->get_world_info(); const client_world_info_t *worldsize = infon->get_world_info();
if (!worldsize) return; if (!worldsize) return;
const client_maptile_t *world = infon->get_world(); const client_maptile_t *world = infon->get_world();
Expand Down Expand Up @@ -143,14 +138,11 @@ static void null_tick(int gt, int delta) {
aa_flush(context); aa_flush(context);
} }


const static renderer_api_t null_api = { const static renderer_api_t aa_api = {
.version = RENDERER_API_VERSION, .version = RENDERER_API_VERSION,
.open = null_open, .open = aarenderer_open,
.close = null_close, .close = aarenderer_close,
.tick = null_tick, .tick = aarenderer_tick,
}; };


const renderer_api_t *load(const infon_api_t *api) { RENDERER_EXPORT(aa_api);
infon = api;
return &null_api;
}
4 changes: 2 additions & 2 deletions client_creature.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ void client_creature_move(int delta) {
if (dw > 16) dw -= 32; if (dw > 16) dw -= 32;


if (dw < -1) { if (dw < -1) {
creature->dir += 2; creature->dir += dw < -5 ? 2 : 1;
} else if (dw > 1) { } else if (dw > 1) {
creature->dir -= 2; creature->dir -= dw > 5 ? 2 : 1;
} else { } else {
creature->dir = winkel_to_waypoint; creature->dir = winkel_to_waypoint;
} }
Expand Down
18 changes: 2 additions & 16 deletions gl_gui.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,18 +30,11 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>


#include "global.h"
#include "map.h"
#include "misc.h"
#include "renderer.h" #include "renderer.h"
#include "gl_video.h"
#include "common_player.h"
#include "client_world.h"


#include "gl_video.h"
#include "gl_mdl.h" #include "gl_mdl.h"


static const infon_api_t *infon;

static Uint32 real_time; static Uint32 real_time;


typedef struct { typedef struct {
Expand Down Expand Up @@ -680,11 +673,4 @@ static const renderer_api_t gl_api = {
.scroll_message = NULL, .scroll_message = NULL,
}; };


#ifdef WIN32 RENDERER_EXPORT(gl_api);
__declspec(dllexport)
#endif
const renderer_api_t *load(const infon_api_t *api) {
infon = api;
printf("Renderer loaded\n");
return &gl_api;
}
49 changes: 17 additions & 32 deletions lilith_gui.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,20 +30,11 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>


extern "C" {
#include "global.h"
#include "map.h"
#include "misc.h"
#include "renderer.h" #include "renderer.h"
#include "common_player.h"
#include "client_world.h"
}


using namespace grinliz; using namespace grinliz;
using namespace lilith3d; using namespace lilith3d;


static const infon_api_t *infon;

static SDL_Surface *surface = 0; static SDL_Surface *surface = 0;
static TextureManager *texman = 0; static TextureManager *texman = 0;
static MeshResManager *meshman = 0; static MeshResManager *meshman = 0;
Expand Down Expand Up @@ -374,27 +365,21 @@ static void lilith_close() {
delete texman; delete texman;
SDL_Quit(); SDL_Quit();
} }

static const renderer_api_t lilith_api = {
RENDERER_API_VERSION,
lilith_open,
lilith_close,
lilith_tick,
lilith_world_info_changed,
lilith_world_changed,
NULL,
NULL,
NULL,
lilith_creature_spawned,
lilith_creature_changed,
lilith_creature_died,
NULL
};


extern "C" { RENDERER_EXPORT(lilith_api);
renderer_api_t lilith_api = {0};

#ifdef WIN32
__declspec(dllexport)
#endif
const renderer_api_t *load(const infon_api_t *api) {
infon = api;
printf("Renderer loaded\n");

lilith_api.version = RENDERER_API_VERSION;
lilith_api.open = lilith_open;
lilith_api.close = lilith_close;
lilith_api.tick = lilith_tick;
lilith_api.world_info_changed = lilith_world_info_changed;
lilith_api.world_changed = lilith_world_changed;
lilith_api.creature_spawned = lilith_creature_spawned;
lilith_api.creature_changed = lilith_creature_changed;
lilith_api.creature_died = lilith_creature_died;

return &lilith_api;
}
}
3 changes: 3 additions & 0 deletions misc.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ int yesno(const char *fmt, ...);
#define max(a,b) ((a)>(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b))
#endif #endif


#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#define save_lua_stack(L, diff) \ #define save_lua_stack(L, diff) \
lua_State *check_L = L; \ lua_State *check_L = L; \
int lua_stack = lua_gettop(check_L) - diff;\ int lua_stack = lua_gettop(check_L) - diff;\
Expand Down
41 changes: 16 additions & 25 deletions null_gui.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,62 +20,57 @@


#include <stdio.h> #include <stdio.h>


#include "client_world.h"
#include "client_creature.h"
#include "client_player.h"
#include "renderer.h" #include "renderer.h"


static const infon_api_t *infon;

static int null_open(int w, int h, int fs) { static int null_open(int w, int h, int fs) {
printf("open\n"); printf("open\n");
return 1; return 1;
} }


static void null_close() { static void null_close() {
printf("close\n"); printf("close\n");
} }


static void null_tick(int gt, int delta) { static void null_tick(int gt, int delta) {
printf("tick %d\n", delta); printf("tick %d\n", delta);
} }


static void null_world_info_changed(const client_world_info_t *info) { static void null_world_info_changed(const client_world_info_t *info) {
printf("new world\n"); printf("new world\n");
} }


static void null_world_changed(int x, int y) { static void null_world_changed(int x, int y) {
printf("change at %d,%d\n", x, y); printf("change at %d,%d\n", x, y);
} }


static void *null_player_joined(const client_player_t *player) { static void *null_player_joined(const client_player_t *player) {
printf("new player %d\n", player->num); printf("new player %d\n", player->num);
return NULL; return NULL;
} }


static void null_player_changed(const client_player_t *player, int changed) { static void null_player_changed(const client_player_t *player, int changed) {
printf("player %d changed: %d\n", player->num, changed); printf("player %d changed: %d\n", player->num, changed);
} }


static void null_player_left(const client_player_t *player) { static void null_player_left(const client_player_t *player) {
printf("player %d left\n", player->num); printf("player %d left\n", player->num);
} }


static void *null_creature_spawned(const client_creature_t *creature) { static void *null_creature_spawned(const client_creature_t *creature) {
printf("creature spawned %d\n", creature->num); printf("creature spawned %d\n", creature->num);
return NULL; return NULL;
} }


static void null_creature_changed(const client_creature_t *creature, int changed) { static void null_creature_changed(const client_creature_t *creature, int changed) {
printf("creature %d changed: %d\n", creature->num, changed); printf("creature %d changed: %d\n", creature->num, changed);
} }


static void null_creature_died(const client_creature_t *creature) { static void null_creature_died(const client_creature_t *creature) {
printf("creature %d died\n", creature->num); printf("creature %d died\n", creature->num);
} }


static void null_scroll_message(const char *message) { static void null_scroll_message(const char *message) {
printf("scroll: %s\n", message); printf("scroll: %s\n", message);
} }


const static renderer_api_t null_api = { const static renderer_api_t null_api = {
Expand All @@ -94,8 +89,4 @@ const static renderer_api_t null_api = {
.scroll_message = null_scroll_message, .scroll_message = null_scroll_message,
}; };


const renderer_api_t *load(const infon_api_t *api) { RENDERER_EXPORT(null_api);
infon = api;
printf("null renderer loaded\n");
return &null_api;
}
19 changes: 11 additions & 8 deletions renderer.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <assert.h> #include <assert.h>


#include "misc.h" #include "misc.h"
#include "global.h"
#include "renderer.h" #include "renderer.h"


#include "client.h" #include "client.h"
Expand All @@ -51,7 +52,9 @@ static void renderer_set_shutdown() {
render_shutdown = 1; render_shutdown = 1;
} }


static const infon_api_t infon = { static const infon_api_t infon_api = {
.version = GAME_NAME,

.max_players = MAXPLAYERS, .max_players = MAXPLAYERS,
.max_creatures = MAXCREATURES, .max_creatures = MAXCREATURES,


Expand All @@ -71,7 +74,7 @@ static const infon_api_t infon = {
}; };


void renderer_init_from_pointer(render_loader loader) { void renderer_init_from_pointer(render_loader loader) {
renderer = loader(&infon); renderer = loader(&infon_api);


if (renderer->version != RENDERER_API_VERSION) if (renderer->version != RENDERER_API_VERSION)
die("version mismatch between renderer and engine:\n" die("version mismatch between renderer and engine:\n"
Expand All @@ -87,22 +90,22 @@ void renderer_init_from_file(const char *shared) {
dlhandle = LoadLibrary(shared); dlhandle = LoadLibrary(shared);


if (!dlhandle) if (!dlhandle)
die("dlopen(\"%s\") failed: %d", shared, GetLastError()); die("opening renderer failed: dlopen(\"%s\") failed: %d", shared, GetLastError());


render_loader loader = (render_loader)GetProcAddress(dlhandle, "load"); render_loader loader = (render_loader)GetProcAddress(dlhandle, TOSTRING(RENDERER_SYM));


if (!loader) if (!loader)
die("cannot find symbol 'load'"); die("cannot find symbol '" TOSTRING(RENDERER_SYM) "' in renderer %s", shared);
#else #else
dlhandle = dlopen(shared, RTLD_NOW); dlhandle = dlopen(shared, RTLD_NOW);


if (!dlhandle) if (!dlhandle)
die("dlopen(\"%s\") failed: %s", shared, dlerror()); die("opening renderer failed: dlopen(\"%s\") failed: %s", shared, dlerror());


render_loader loader = (render_loader)dlsym(dlhandle, "load"); render_loader loader = (render_loader)dlsym(dlhandle, TOSTRING(RENDERER_SYM));


if (!loader) if (!loader)
die("cannot find symbol 'load'"); die("cannot find symbol '" TOSTRING(RENDERER_SYM) "' in renderer %s", shared);
#endif #endif
renderer_init_from_pointer(loader); renderer_init_from_pointer(loader);
} }
Expand Down
Loading

0 comments on commit 8933f13

Please sign in to comment.