diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-05-12 20:39:34 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-05-12 20:39:34 +0000 |
| commit | 7055882c93022da3a6a1cf74cebf3d17c44ce6c4 (patch) | |
| tree | bacb905bbfb33a5ee5a203c4e327495fcbd85ef7 /src | |
| parent | 46958f55432bcbb6f4e90f4dd937d8de355e5785 (diff) | |
- podpora modulov
- hra sa musi kompilovat s GUI ako
v config.h _zakomenotvane_ #define PUBLIC_SERVER
make clean
make
make mod
su
make install
- hra sa musi ako server kompilovat
v config.h _odkomentovane__ #define PUBLIC_SERVER
make clean
make
make mod
- pozor, urcite tam je este vela bugov //je to nedoladene
zatial to ani nedavajte na server
git-svn-id: http://opensvn.csie.org/tuxanci_ng@52 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src')
| -rwxr-xr-x | src/Makefile | 15 | ||||
| -rwxr-xr-x | src/Makefile-publicServer | 19 | ||||
| -rw-r--r-- | src/arena.c | 17 | ||||
| -rw-r--r-- | src/arenaFile.c | 51 | ||||
| -rwxr-xr-x | src/modules.c | 220 | ||||
| -rw-r--r-- | src/pipe.c | 3 | ||||
| -rw-r--r-- | src/proto.c | 3 | ||||
| -rw-r--r-- | src/publicServer.c | 4 | ||||
| -rw-r--r-- | src/screen_world.c | 6 | ||||
| -rw-r--r-- | src/shot.c | 9 | ||||
| -rw-r--r-- | src/tux.c | 9 |
11 files changed, 288 insertions, 68 deletions
diff --git a/src/Makefile b/src/Makefile index 0db4928..ab243b6 100755 --- a/src/Makefile +++ b/src/Makefile @@ -9,12 +9,12 @@ CFLAGS = -g -O0 -std=c99 -I../include -Wall `sdl-config --cflags` BUILD_DIR = . LIBS = `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL_net -FILES = interface.o font.o list.o image.o layer.o director.o configFile.o tux.o main.o \ +FILES = interface.o font.o list.o modules.o image.o layer.o director.o configFile.o tux.o main.o \ screen.o screen_world.o wall.o shot.o myTimer.o panel.o net_multiplayer.o \ buffer.o dynamicInt.o arena.o arenaFile.o textFile.o audio.o sound.o music.o gun.o \ item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \ widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \ - widget_buttonimage.o screen_credits.o teleport.o pipe.o homeDirector.o screen_table.o \ + widget_buttonimage.o screen_credits.o homeDirector.o screen_table.o \ sdl_udp.o proto.o server.o client.o term.o keytable.o language.o game.o tuxanci-ng: $(FILES) @@ -26,6 +26,9 @@ main.o: main.c interface.o: interface.c ../include/interface.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/interface.o -c interface.c +modules.o: modules.c ../include/modules.h + $(CC) $(CFLAGS) -o $(BUILD_DIR)/modules.o -c modules.c + font.o: font.c ../include/font.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/font.o -c font.c @@ -155,11 +158,11 @@ widget_check.o: widget_check.c ../include/widget_check.h widget_image.o: widget_image.c ../include/widget_image.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/widget_image.o -c widget_image.c -teleport.o: teleport.c ../include/teleport.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c +#teleport.o: teleport.c ../include/teleport.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c -pipe.o: pipe.c ../include/pipe.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c +#pipe.o: pipe.c ../include/pipe.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c homeDirector.o: homeDirector.c ../include/homeDirector.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/homeDirector.o -c homeDirector.c diff --git a/src/Makefile-publicServer b/src/Makefile-publicServer index 39537ee..d6956bf 100755 --- a/src/Makefile-publicServer +++ b/src/Makefile-publicServer @@ -4,14 +4,14 @@ CC = gcc DESTDIR:=/usr/local -CFLAGS = -g -O0 -DPUBLIC_SERVER -DSUPPORT_NET_UNIX_UDP -I../include -Wall +CFLAGS = -g -O0 -I../include -Wall #CFLAGS = -O2 -DDESTDIR=\"$(DESTDIR)\" `sdl-config --cflags` -I../include -Wall BUILD_DIR = ../build-server -LIBS = +LIBS = -ldl -FILES = list.o director.o configFile.o tux.o wall.o shot.o myTimer.o \ - buffer.o dynamicInt.o arena.o arenaFile.o textFile.o gun.o item.o teleport.o pipe.o \ +FILES = list.o modules.o director.o configFile.o tux.o wall.o shot.o myTimer.o \ + buffer.o dynamicInt.o arena.o arenaFile.o textFile.o gun.o item.o\ udp.o proto.o server.o publicServer.o net_multiplayer.o serverConfigFile.o main.o $(BUILD_DIR)/publicserver: mkdir_build $(FILES) @@ -23,6 +23,9 @@ mkdir_build: main.o: main.c $(CC) $(CFLAGS) -o $(BUILD_DIR)/main.o -c main.c +modules.o: modules.c + $(CC) $(CFLAGS) -o $(BUILD_DIR)/modules.o -c modules.c + publicServer.o: publicServer.c $(CC) $(CFLAGS) -o $(BUILD_DIR)/publicServer.o -c publicServer.c @@ -83,11 +86,11 @@ gun.o: gun.c ../include/gun.h item.o: item.c ../include/item.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/item.o -c item.c -teleport.o: teleport.c ../include/teleport.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c +#teleport.o: teleport.c ../include/teleport.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c -pipe.o: pipe.c ../include/pipe.h - $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c +#pipe.o: pipe.c ../include/pipe.h +# $(CC) $(CFLAGS) -o $(BUILD_DIR)/pipe.o -c pipe.c serverConfigFile.o: serverConfigFile.c ../include/serverConfigFile.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/serverConfigFile.o -c serverConfigFile.c diff --git a/src/arena.c b/src/arena.c index b762937..05749d6 100644 --- a/src/arena.c +++ b/src/arena.c @@ -13,6 +13,7 @@ #include "teleport.h" #include "pipe.h" #include "myTimer.h" +#include "modules.h" #ifndef PUBLIC_SERVER #include "layer.h" @@ -62,8 +63,8 @@ int isFreeSpace(arena_t *arena, int x, int y, int w, int h) if ( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0; if ( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0; if ( isConflictWithListItem(arena->listItem, x, y, w, h) )return 0; - if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; - if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; + //if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; + //if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; return 1; } @@ -95,8 +96,8 @@ void drawArena(arena_t *arena) drawListTux(arena->listTux); drawListWall(arena->listWall); - drawListTeleport(arena->listTeleport); - drawListPipe(arena->listPipe); + //drawListTeleport(arena->listTeleport); + //drawListPipe(arena->listPipe); drawListShot(arena->listShot); drawListItem(arena->listItem); @@ -120,15 +121,15 @@ void eventArena(arena_t *arena) { int i; - eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport); + //eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport); eventConflictTuxWithShot(arena->listTux, arena->listShot); for( i = 0 ; i < 4 ; i++) { eventMoveListShot(arena->listShot); eventConflictShotWithWall(arena->listWall, arena->listShot); - eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); - eventConflictShotWithPipe(arena->listPipe, arena->listShot); + //eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); + //eventConflictShotWithPipe(arena->listPipe, arena->listShot); eventConflictShotWithItem(arena->listItem, arena->listShot); } @@ -142,7 +143,7 @@ void eventArena(arena_t *arena) int isConflictWithObjectInArena(arena_t *arena, int x, int y, int w, int h) { if( isConflictWithListWall(arena->listWall, x, y, w, h) || - isConflictWithListPipe(arena->listPipe, x, y, w, h) ) + isConflictModule(x, y, w, h) ) { return 1; } diff --git a/src/arenaFile.c b/src/arenaFile.c index b30c231..90ae231 100644 --- a/src/arenaFile.c +++ b/src/arenaFile.c @@ -18,6 +18,7 @@ #include "item.h" #include "director.h" #include "path.h" +#include "modules.h" #include "string_length.h" #ifndef PUBLIC_SERVER @@ -35,6 +36,15 @@ bool_t isAreaFileInicialized() return isArenaFileInit; } +static void cmd_loadModule(char *line) +{ + char str_file[STR_SIZE]; + + if( getValue(line, "file", str_file, STR_SIZE) != 0 )return; + + loadModule(str_file); +} + #ifndef PUBLIC_SERVER static void cmd_loadImage(char *line) @@ -119,38 +129,7 @@ static void cmd_wall(arena_t *arena, char *line) addList(arena->listWall, new); } -static void cmd_teleport(arena_t *arena, char *line) -{ - char str_x[STR_NUM_SIZE]; - char str_y[STR_NUM_SIZE]; - char str_w[STR_NUM_SIZE]; - char str_h[STR_NUM_SIZE]; - char str_layer[STR_NUM_SIZE]; - char str_image[STR_SIZE]; - teleport_t *new; - - if( getValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; - if( getValue(line, "image", str_image, STR_SIZE) != 0 )return; - -#ifndef PUBLIC_SERVER - new = newTeleport(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_layer), getImage(IMAGE_GROUP_USER, str_image) ); -#endif - -#ifdef PUBLIC_SERVER - new = newTeleport(atoi(str_x), atoi(str_y), - atoi(str_w), atoi(str_h), - atoi(str_layer) ); -#endif - - addList(arena->listTeleport, new); -} - +/* static void cmd_pipe(arena_t *arena, char *line) { char str_x[STR_NUM_SIZE]; @@ -189,6 +168,7 @@ static void cmd_pipe(arena_t *arena, char *line) addList(arena->listPipe, new); } +*/ int getArenaCount() { @@ -270,6 +250,8 @@ arena_t* getArena(int id) char *line; line = (char *) (ts->text->list[i]); + cmdModule(line); + #ifndef PUBLIC_SERVER if( strncmp(line, "loadImage", 9) == 0 )cmd_loadImage(line); if( strncmp(line, "loadMusic", 9) == 0 )cmd_loadMusic(line); @@ -277,9 +259,10 @@ arena_t* getArena(int id) if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line); #endif + if( strncmp(line, "loadModule", 10) == 0 )cmd_loadModule(line); if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); - if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); - if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); + //if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); + //if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); } return arena; diff --git a/src/modules.c b/src/modules.c new file mode 100755 index 0000000..7a8f3cd --- /dev/null +++ b/src/modules.c @@ -0,0 +1,220 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <assert.h> + +#include "main.h" +#include "configFile.h" +#include "list.h" +#include "path.h" +#include "tux.h" +#include "shot.h" +#include "modules.h" +#include "tux.h" +#include "arena.h" +#include "proto.h" + +#ifndef PUBLIC_SERVER +#include "interface.h" +#include "image.h" +#include "layer.h" +#endif + +int pokus(char *s) +{ + printf("s = %s\n", s); + return 0; +} + +static export_fce_t export_fce = + { +#ifndef PUBLIC_SERVER + .fce_addLayer = addLayer, + .fce_getImage = getImage, +#endif + .fce_getValue = getValue, + .fce_getNetTypeGame = getNetTypeGame, + .fce_getTuxProportion = getTuxProportion, + .fce_setTuxProportion = setTuxProportion, + .fce_getTuxID = getTuxID, + + .fce_getCurrentArena = getCurrentArena, + .fce_conflictSpace = conflictSpace, + .fce_isFreeSpace = isFreeSpace, + .fce_findFreeSpace = findFreeSpace, + .fce_proto_send_newtux_server = proto_send_newtux_server, + .fce_proto_send_shot_server = proto_send_shot_server, + .fce_destroyShot = destroyShot, + .fce_boundBombBall = boundBombBall + }; + +static list_t *listModule; + +static void* getFce(module_t *p, char *s) +{ + void *ret; + char *error; + + assert( p != NULL ); + assert( s != NULL ); + + ret = dlsym(p->image, s); + + if( ( error = dlerror() ) != NULL) + { + fprintf (stderr, "error = %s\n", error); + return NULL; + } + + return (void *)ret; +} + +static module_t* newModule(char *name) +{ + module_t *ret; + + assert( name != NULL ); + + ret = malloc( sizeof(module_t) ); + + ret->image = dlopen (name, RTLD_LAZY); + + if(!ret->image) + { + fputs (dlerror(), stderr); + free(ret); + return NULL; + } + + ret->file = strdup(name); + + ret->fce_init = getFce(ret, "init"); +#ifndef PUBLIC_SERVER + ret->fce_draw = getFce(ret, "draw"); +#endif + ret->fce_event = getFce(ret, "event"); + ret->fce_destroy = getFce(ret, "destroy"); + ret->fce_isConflict = getFce(ret, "isConflict"); + ret->fce_cmd = getFce(ret, "cmd"); + + printf("load module.. (%s)\n", name); + + if( ret->fce_init(&export_fce) != 0 ) + { + fprintf(stderr, "init module failed !\n"); + + dlclose(ret->image); + free(ret->file); + free(ret); + return NULL; + } + + return ret; +} + +static int destroyModule(module_t *p) +{ + assert( p != NULL ); + + p->fce_destroy(); + + free(p->file); + dlclose(p->image); + free(p); + + + printf("destroy module..\n"); + + return 0; +} + +void initModule() +{ + listModule = newList(); +} + +int loadModule(char *name) +{ + char str[STR_PATH_SIZE]; + module_t *module; + + sprintf(str, PATH_MODULES "%s", name); + accessExistFile(str); + + module = newModule(str); + + if( module == NULL ) + { + fprintf(stderr, "load module %s failed !\n", name); + return -1; + } + + addList(listModule, module); + + return 0; +} + +void cmdModule(char *s) +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + this->fce_cmd(s); + } +} + +#ifndef PUBLIC_SERVER + +void drawModule() +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + this->fce_draw(); + } +} + +#endif + +void eventModule() +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + this->fce_event(); + } +} + +int isConflictModule(int x, int y, int w, int h) +{ + int i; + + for( i = 0 ; i < listModule->count ; i++ ) + { + module_t *this; + this = (module_t *)listModule->list[i]; + + if( this->fce_isConflict(x, y, w, h) == 1 ) + { + return 1; + } + } + + return 0; +} + +void quitModule() +{ + destroyListItem(listModule, destroyModule); +} @@ -149,9 +149,10 @@ static void moveShotFromPipe(shot_t *shot, pipe_t *pipe, list_t *listPipe) fprintf(stderr, "Pipe %d ID not found\n", pipe->id); return; } - +/* moveShot(shot, distPipe->position, pipe->x, pipe->y, distPipe->x, distPipe->y, distPipe->w, distPipe->h); +*/ } void eventConflictShotWithPipe(list_t *listPipe, list_t *listShot) diff --git a/src/proto.c b/src/proto.c index db45109..0441371 100644 --- a/src/proto.c +++ b/src/proto.c @@ -610,11 +610,12 @@ void proto_recv_shot_client(char *msg) shot->isCanKillAuthor = isCanKillAuthor; shot->position = position; +/* if( shot->gun == GUN_LASSER ) { transformOnlyLasser(shot); } - +*/ addList(getCurrentArena()->listShot, shot); } diff --git a/src/publicServer.c b/src/publicServer.c index 4b7774b..66d530f 100644 --- a/src/publicServer.c +++ b/src/publicServer.c @@ -21,6 +21,7 @@ #include "publicServer.h" #include "net_multiplayer.h" #include "serverConfigFile.h" +#include "modules.h" static int arenaId; static arena_t *arena; @@ -37,6 +38,7 @@ static char *getSetting(char *env, char *param, char *default_val) int initPublicServer() { + initModule(); initArenaFile(); initTux(); initItem(); @@ -97,6 +99,7 @@ void eventPublicServer() lastActive = getMyTime(); eventArena(arena); + eventModule(); } void my_handler_quit(int n) @@ -112,6 +115,7 @@ void quitPublicServer() destroyArena(arena); quitArenaFile(); quitServerConfigFile(); + quitModule(); exit(0); } diff --git a/src/screen_world.c b/src/screen_world.c index 9858a8b..671a858 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -35,6 +35,8 @@ #include "proto.h" #include "term.h" #include "font.h" +#include "music.h" +#include "modules.h" static arena_t *arena; static int count; @@ -193,6 +195,7 @@ void drawWorld() drawPanel(arena->listTux); } + drawModule(); drawTerm(); } @@ -358,6 +361,7 @@ void eventWorld() eventNetMultiplayer(); eventArena(arena); + eventModule(); eventTerm(); eventEnd(); @@ -372,6 +376,7 @@ void startWorld() count = 0; lastServerLag = LAG_SERVER_UNKNOWN; + initModule(); setGameType(); initTerm(); prepareArena(); @@ -435,6 +440,7 @@ void stoptWorld() stopMusic(); delAllImageInGroup(IMAGE_GROUP_USER); delAllMusicInGroup(MUSIC_GROUP_USER); + quitModule(); } void initWorld() @@ -201,12 +201,6 @@ int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h) return 0; } -static int myAbs(int n) -{ - return ( n > 0 ? n : -n ); -} - - static int getRandomCourse(int x, int y) { int ret; @@ -287,6 +281,7 @@ void eventMoveListShot(list_t *listShot) } } +/* static int getSppedShot(shot_t *shot) { return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); @@ -405,7 +400,7 @@ void moveShot(shot_t *shot, int position, int src_x, int src_y, } } - +*/ void destroyShot(shot_t *p) { assert( p != NULL ); @@ -18,6 +18,7 @@ #include "net_multiplayer.h" #include "dynamicInt.h" #include "proto.h" +#include "modules.h" #ifndef PUBLIC_SERVER #include "image.h" @@ -526,6 +527,7 @@ void eventConflictTuxWithShot(list_t *listTux, list_t *listShot) } } +/* void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport) { teleport_t *thisTeleport; @@ -551,6 +553,7 @@ void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport) } } } +*/ void moveTux(tux_t *tux, int n) { @@ -623,8 +626,8 @@ void moveTux(tux_t *tux, int n) if( tux->bonus != BONUS_GHOST && ( isConflictTuxWithListTux(tux, arena->listTux) || - isConflictWithListWall(arena->listWall, x, y, w, h) || - isConflictWithListPipe(arena->listPipe, x, y, w, h) ) ) + isConflictWithListWall(arena->listWall, x, y, w, h) || + isConflictModule(x, y, w, h) ) ) { tux->x = zal_x; tux->y = zal_y; @@ -795,7 +798,7 @@ static void eventBonus(tux_t *tux) tux->bonus = BONUS_NONE; if ( isConflictWithListWall(getCurrentArena()->listWall, x, y, w, h) || - isConflictWithListPipe(getCurrentArena()->listPipe, x, y, w, h) || + isConflictModule(x, y, w, h) || isConflictTuxWithListTux(tux, getCurrentArena()->listTux) ) { tux->bonus = BONUS_GHOST; |