From d5ae032d2b251a1604042f68a9cd3215c233792e Mon Sep 17 00:00:00 2001 From: oroborus Date: Wed, 16 Jul 2008 19:51:46 +0000 Subject: nove funkcie : extern void actionSpace(space_t *space, void *f, void *p); extern void actionSpaceFromLocation(space_t *space, void *f, void *p, int x, int y, int w, int h); casti kodu ktore tieto funkcie potrebovali boli prepisane tak aby ich pouzivali. ( moduly tak prepisem zajtra ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@150 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/base/arena.c | 1 + src/base/item.c | 114 ++++++++++++++++++++-------------------------------- src/base/myTimer.c | 19 +++++++++ src/base/shot.c | 61 +++++++++++++--------------- src/base/space.c | 42 ++++++++++++++++++- src/base/space.h | 2 + src/base/tux.c | 85 ++++++++++++++++++--------------------- src/client/screen.c | 25 ++++++++++++ 8 files changed, 197 insertions(+), 152 deletions(-) (limited to 'src') diff --git a/src/base/arena.c b/src/base/arena.c index 2b4821c..b90c650 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -188,6 +188,7 @@ void drawArena(arena_t *arena) t = getMyTime(); */ + if( tux == NULL ) { drawLayerCenter(WINDOW_SIZE_X/2, WINDOW_SIZE_Y/2); diff --git a/src/base/item.c b/src/base/item.c index 70d6c0e..08651fd 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -367,62 +367,55 @@ static void mineExplosion(space_t *spaceItem, item_t *item) } } -void eventConflictShotWithItem(arena_t *arena) +static void action_item(space_t *space, item_t *item, int *isDel) { - shot_t *thisShot; - item_t *thisItem; - int i, j; + arena_t *arena; - if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return; - } + arena = getCurrentArena(); - for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) + switch( item->type ) { - bool_t isDelShot; + case ITEM_MINE : + if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + mineExplosion(space, item); + } + break; + + case ITEM_EXPLOSION : + case ITEM_BIG_EXPLOSION : + *isDel = 1; + break; + } +} - isDelShot = FALSE; - thisShot = (shot_t *)arena->spaceShot->list->list[i]; - assert( thisShot != NULL ); +static void action_shot(space_t *space, shot_t *shot, space_t *spaceItem) +{ + int isDel = 0; - listDoEmpty(listHelp); - getObjectFromSpace(arena->spaceItem, thisShot->x, thisShot->y, thisShot->w, thisShot->h, listHelp); + actionSpaceFromLocation(spaceItem, action_item, &isDel, shot->x, shot->y, shot->w, shot->h); - for( j = 0 ; j < listHelp->count ; j++ ) + if( isDel ) + { + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - thisItem = (item_t *)listHelp->list[j]; - assert( thisItem != NULL ); - - switch( thisItem->type ) - { - case ITEM_MINE : - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - mineExplosion(arena->spaceItem, thisItem); - } - break; - - case ITEM_EXPLOSION : - case ITEM_BIG_EXPLOSION : - isDelShot = TRUE; - break; - } + proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id); } - - if( isDelShot ) - { - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_del_server(PROTO_SEND_ALL, NULL, thisShot->id); - } - delObjectFromSpaceWithObject(arena->spaceShot, thisShot, destroyShot); - i--; - } + delObjectFromSpaceWithObject(space, shot, destroyShot); } } +void eventConflictShotWithItem(arena_t *arena) +{ + if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + return; + } + + actionSpace(arena->spaceShot, action_shot, arena->spaceItem); +} + static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item) { if( tux->bonus == BONUS_GHOST ) @@ -504,7 +497,7 @@ static void tuxGiveGun(tux_t *tux, item_t *item) } } -void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem) +static void action_giveitem(space_t *space, item_t *item, tux_t *tux) { switch( item->type ) { @@ -521,13 +514,13 @@ void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem) proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); } - delObjectFromSpaceWithObject(spaceItem, item, destroyItem); + delObjectFromSpaceWithObject(space, item, destroyItem); break; case ITEM_MINE : if( tux->bonus != BONUS_GHOST ) { - mineExplosion(spaceItem, item); + mineExplosion(space, item); } break; @@ -552,25 +545,23 @@ void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem) proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); } - delObjectFromSpaceWithObject(spaceItem, item, destroyItem); + delObjectFromSpaceWithObject(space, item, destroyItem); break; } } void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem) { - item_t *thisItem; int x, y, w, h; - int i; + + assert( spaceItem != NULL ); + assert( tux != NULL ); if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) { return; } - assert( spaceItem != NULL ); - assert( tux != NULL ); - if( tux->status == TUX_STATUS_DEAD ) { return; @@ -578,24 +569,7 @@ void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem) getTuxProportion(tux, &x, &y, &w, &h); - listDoEmpty(listHelp); - getObjectFromSpace(spaceItem, x, y, w, h, listHelp); - - for( i = 0 ; i < listHelp->count ; i++ ) - { - thisItem = (item_t *)listHelp->list[i]; - assert( thisItem != NULL ); - - eventGiveTuxItem(tux, thisItem, spaceItem); - -#ifdef PUBLIC_SERVER - addNewItem(spaceItem, ID_UNKNOWN); -#endif - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); - } - } + actionSpaceFromLocation(spaceItem, action_giveitem, tux, x, y, w, h); } void destroyItem(item_t *p) diff --git a/src/base/myTimer.c b/src/base/myTimer.c index 5e74207..7bfb91a 100644 --- a/src/base/myTimer.c +++ b/src/base/myTimer.c @@ -45,6 +45,25 @@ my_time_t getMyTime() return ticks; } +my_time_t getMyTimeMicro() +{ + static struct timeval start = { .tv_sec = 0, .tv_usec = 0 }; + struct timeval now; + my_time_t ticks; + + if( start.tv_sec == 0 && start.tv_usec == 0 ) + { + gettimeofday(&start, NULL); + } + + gettimeofday(&now, NULL); + + ticks = (now.tv_sec-start.tv_sec)*1000*1000+(now.tv_usec-start.tv_usec); + + //printf("-> %d\n", ticks); + return ticks; +} + my_timer_t* newTimerItem(int type, void (*fce)(void *p), void *arg, my_time_t my_time) { static int new_id = 0; diff --git a/src/base/shot.c b/src/base/shot.c index 6911d1a..1b657c2 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -272,33 +272,30 @@ void transformOnlyLasser(shot_t *shot) } } -void eventMoveListShot(arena_t *arena) +static void action_moveShot(space_t *space, shot_t *shot, void *p) { - shot_t *thisShot; int new_x, new_y; - int i; + arena_t *arena; - for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) - { - thisShot = (shot_t *) arena->spaceShot->list->list[i]; - assert( thisShot != NULL ); + arena = getCurrentArena(); - new_x = thisShot->x + thisShot->px; - new_y = thisShot->y + thisShot->py; + new_x = shot->x + shot->px; + new_y = shot->y + shot->py; - moveObjectInSpace(getCurrentArena()->spaceShot, thisShot, new_x, new_y); + moveObjectInSpace(space, shot, new_x, new_y); - if( thisShot->x+thisShot->w < 0 || thisShot->x > arena->w || - thisShot->y+thisShot->h < 0 || thisShot->y > arena->h ) - { - delObjectFromSpaceWithObject(arena->spaceShot, - thisShot, destroyShot); - i--; - continue; - } + if( shot->x+shot->w < 0 || shot->x > arena->w || + shot->y+shot->h < 0 || shot->y > arena->h ) + { + delObjectFromSpaceWithObject(space, shot, destroyShot); } } +void eventMoveListShot(arena_t *arena) +{ + actionSpace(arena->spaceShot, action_moveShot, NULL); +} + static int isValueInList(list_t *list, int x) { int i; @@ -314,14 +311,22 @@ static int isValueInList(list_t *list, int x) return 0; } +static void action_check(space_t *space, shot_t *shot, client_t *client) +{ + if( isValueInList(client->listSeesShot, shot->id) == 0 ) + { + addList(client->listSeesShot, newInt(shot->id) ); + proto_send_shot_server(PROTO_SEND_ONE, client, shot); + } +} + void checkShotIsInTuxScreen(arena_t *arena) { int screen_x, screen_y; - shot_t *thisShot; tux_t *thisTux; client_t *thisClient; list_t *listClient; - int i, j; + int i; if( getNetTypeGame() != NET_GAME_TYPE_SERVER ) { @@ -342,20 +347,8 @@ void checkShotIsInTuxScreen(arena_t *arena) getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y); - listDoEmpty(listHelp); - - getObjectFromSpace(arena->spaceShot, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y, listHelp); - - for( j = 0 ; j count ; j++ ) - { - thisShot = (shot_t *)listHelp->list[j]; - - if( isValueInList(thisClient->listSeesShot, thisShot->id) == 0 ) - { - addList(thisClient->listSeesShot, newInt(thisShot->id) ); - proto_send_shot_server(PROTO_SEND_ONE, thisClient, thisShot); - } - } + actionSpaceFromLocation(arena->spaceShot, action_check, + thisClient, screen_x, screen_y, WINDOW_SIZE_X, WINDOW_SIZE_Y); while( thisClient->listSeesShot->count > 100 ) { diff --git a/src/base/space.c b/src/base/space.c index fb51c40..42fce71 100644 --- a/src/base/space.c +++ b/src/base/space.c @@ -310,8 +310,48 @@ void printSpace(space_t *p) } } -void actionSpace(space_t *space) +void actionSpace(space_t *space, void *f, void *p) { + void (*fce)(space_t *space, void *f, void *p); + int len; + int i; + + fce = f; + len = space->list->count; + + for( i = 0 ; i < len ; i++ ) + { + fce(space, space->list->list[i], p); + + if( space->list->count == len-1 ) + { + len--; + i--; + } + } +} + +void actionSpaceFromLocation(space_t *space, void *f, void *p, int x, int y, int w, int h) +{ + void (*fce)(space_t *space, void *f, void *p); + list_t *list; + int len; + int i; + + fce = f; + + list = newList(); + + getObjectFromSpace(space, x, y, w, h, list); + + len = list->count; + + for( i = 0 ; i < len ; i++ ) + { + fce(space, list->list[i], p); + } + + destroyList(list); } void destroySpace(space_t *p) diff --git a/src/base/space.h b/src/base/space.h index ed46a87..868c5a9 100644 --- a/src/base/space.h +++ b/src/base/space.h @@ -41,6 +41,8 @@ extern void delObjectFromSpace(space_t *p, void *item); extern void delObjectFromSpaceWithObject(space_t *p, void *item, void *f); extern void moveObjectInSpace(space_t *p, void *item, int move_x, int move_y); extern void printSpace(space_t *p); +extern void actionSpace(space_t *space, void *f, void *p); +extern void actionSpaceFromLocation(space_t *space, void *f, void *p, int x, int y, int w, int h); extern void destroySpace(space_t *p); extern void destroySpaceWithObject(space_t *p, void *f); diff --git a/src/base/tux.c b/src/base/tux.c index 21fa7e6..94a7666 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -406,62 +406,53 @@ static void bombBallExplosion(shot_t *shot) delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); } -void eventConflictTuxWithShot(arena_t *arena) +static void action_tux(space_t *space, tux_t *tux, shot_t *shot) { - shot_t *thisShot; - tux_t *thisTux; - int i, j; - - for( i = 0 ; i < arena->spaceShot->list->count ; i++ ) - { - thisShot = (shot_t *)arena->spaceShot->list->list[i]; - assert( thisShot != NULL ); + arena_t *arena; - listDoEmpty(listHelp); - getObjectFromSpace(arena->spaceTux, thisShot->x, thisShot->y, - thisShot->w, thisShot->h, listHelp); + arena = getCurrentArena(); - for( j = 0 ; j < listHelp->count ; j++ ) + if( tux->status == TUX_STATUS_ALIVE ) + { + if( shot->author_id == tux->id && + shot->isCanKillAuthor == FALSE ) { - thisTux = listHelp->list[j]; + return; + } - if( thisTux->status == TUX_STATUS_ALIVE ) + if( tux->bonus == BONUS_TELEPORT ) + { + tuxTeleport(tux); + return; + } + + if( shot->gun == GUN_BOMBBALL ) + { + if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) { - if( thisShot->author_id == thisTux->id && - thisShot->isCanKillAuthor == FALSE ) - { - continue; - } - - if( thisTux->bonus == BONUS_TELEPORT ) - { - tuxTeleport(thisTux); - continue; - } - - if( thisShot->gun == GUN_BOMBBALL ) - { - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - bombBallExplosion(thisShot); - i--; - } - - continue; - } - - if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) - { - eventTuxIsDeadWIthShot(thisTux, thisShot); - } + bombBallExplosion(shot); } - - delObjectFromSpaceWithObject(arena->spaceShot, thisShot, destroyShot); - i--; - - continue; + + return; + } + + if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + eventTuxIsDeadWIthShot(tux, shot); } } + + delObjectFromSpaceWithObject(arena->spaceShot, shot, destroyShot); +} + +static void action_shot(space_t *space, shot_t *shot, space_t *spaceTux) +{ + actionSpaceFromLocation(spaceTux, action_tux, shot, shot->x, shot->y, shot->w, shot->h); +} + +void eventConflictTuxWithShot(arena_t *arena) +{ + actionSpace(arena->spaceShot, action_shot, arena->spaceTux); } void moveTux(tux_t *tux, int n) diff --git a/src/client/screen.c b/src/client/screen.c index 8a3c29c..a96dd9e 100644 --- a/src/client/screen.c +++ b/src/client/screen.c @@ -8,6 +8,9 @@ #include "interface.h" #include "screen.h" #include "layer.h" +#include "myTimer.h" + +//#define DEBUG_TIME_DRAW static screen_t *currentScreen; static list_t *listScreen; @@ -115,16 +118,38 @@ void drawScreen() { assert( currentScreen != NULL ); +#ifdef DEBUG_TIME_DRAW + clock_t prev; + + prev = clock(); +#endif + currentScreen->fce_draw(); interfaceRefresh(); + +#ifdef DEBUG_TIME_DRAW + printf("CLK_TCK = %d\n", CLOCKS_PER_SEC); + printf("c draw time = %d\n", clock() - prev ); +#endif } + void eventScreen() { assert( currentScreen != NULL ); +#ifdef DEBUG_TIME_EVENT + clock_t prev; + + prev = clock(); +#endif + currentScreen->fce_event(); + +#ifdef DEBUG_TIME_EVENT + printf("c event time = %d\n", clock() - prev ); +#endif } void quitScreen() -- cgit v1.2.3