From: Holger Schemel Date: Mon, 5 Oct 1998 22:50:24 +0000 (+0200) Subject: rnd-19981006-1 X-Git-Tag: 1.2.0^2~64 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d32496fdd3867910a188acba0ac132f66c99306c;p=rocksndiamonds.git rnd-19981006-1 --- diff --git a/src/events.c b/src/events.c index 71d03604..92bdeef6 100644 --- a/src/events.c +++ b/src/events.c @@ -62,6 +62,21 @@ void EventLoop(void) break; } } + + HandleNoXEvent(); + + /* don't use all CPU time when idle; the main loop while playing + has its own synchronization and is CPU friendly, too */ + + if (game_status != PLAYING) + { + XSync(display, FALSE); + Delay(10); + } + + + +#if 0 else /* got no event, but don't be lazy... */ { HandleNoXEvent(); @@ -75,6 +90,9 @@ void EventLoop(void) Delay(10); } } +#endif + + if (game_status == EXITGAME) return; @@ -314,7 +332,13 @@ void HandleButton(int mx, int my, int button) HandleSetupScreen(mx,my,0,0,button); break; case PLAYING: + + /* --> NoXEvent() will follow */ + + /* HandleGameActions(0); + */ + break; default: break; @@ -730,11 +754,6 @@ void HandleJoystick() { int joystick = Joystick(); int keyboard = key_joystick_mapping; - - /* - int joy = (tape.playing ? TapePlayAction() : (joystick | keyboard)); - */ - int joy = (joystick | keyboard); int left = joy & JOY_LEFT; int right = joy & JOY_RIGHT; @@ -788,11 +807,6 @@ void HandleJoystick() if (tape.pausing || AllPlayersGone) joy = 0; - /* - if (!network_player_action_stored) - SendToServer_MovePlayer(joy, 0); - */ - HandleGameActions((byte)joy); break; diff --git a/src/game.c b/src/game.c index c8519b39..d79e9e13 100644 --- a/src/game.c +++ b/src/game.c @@ -129,12 +129,12 @@ void InitGame() local_player->active = TRUE; local_player->local = TRUE; - network_player_action_stored = FALSE; + network_player_action_received = FALSE; /* initial null action */ - SendToServer_MovePlayer(0,0); + SendToServer_MovePlayer(MV_NO_MOVING); @@ -2874,11 +2874,9 @@ void GameActions(byte player_action) int i, x,y, element; int *recorded_player_action; - if (game_status != PLAYING) return; - #ifdef DEBUG action_delay_value = (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GameFrameDelay); @@ -2887,21 +2885,16 @@ void GameActions(byte player_action) (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY); #endif - /* - HandleNetworking(); - - if (game_status != PLAYING) - return; - */ - /* main game synchronization point */ WaitUntilDelayReached(&action_delay, action_delay_value); - if (!network_player_action_stored) + if (!standalone && !network_player_action_received) { + /* #ifdef DEBUG printf("DEBUG: try to get network player actions in time\n"); #endif + */ /* last chance to get network player actions without main loop delay */ HandleNetworking(); @@ -2909,11 +2902,13 @@ void GameActions(byte player_action) if (game_status != PLAYING) return; - if (!network_player_action_stored) + if (!network_player_action_received) { + /* #ifdef DEBUG printf("DEBUG: failed to get network player actions in time\n"); #endif + */ return; } } @@ -2923,13 +2918,17 @@ void GameActions(byte player_action) else recorded_player_action = NULL; - - SendToServer_MovePlayer(player_action, FrameCounter); - + if (!standalone) + SendToServer_MovePlayer(player_action); for(i=0; i> 8); buf[3] = (byte)(level_nr & 0xff); buf[4] = (byte)(leveldir_nr >> 8); buf[5] = (byte)(leveldir_nr & 0xff); - strcpy(&buf[6], leveldir[leveldir_nr].name); - sendbuf(strlen(leveldir[leveldir_nr].name)+1 + 6); + + buf[6] = (unsigned char)((new_random_seed >> 24) & 0xff); + buf[7] = (unsigned char)((new_random_seed >> 16) & 0xff); + buf[8] = (unsigned char)((new_random_seed >> 8) & 0xff); + buf[9] = (unsigned char)((new_random_seed >> 0) & 0xff); + + strcpy(&buf[10], leveldir[leveldir_nr].name); + + sendbuf(10 + strlen(leveldir[leveldir_nr].name)+1); } -void SendToServer_MovePlayer(byte player_action, unsigned long frame_nr) +void SendToServer_MovePlayer(byte player_action) { buf[1] = OP_MOVE; buf[2] = player_action; sendbuf(3); - - /* - buf[3] = (byte)((frame_nr >> 24) & 0xff); - buf[4] = (byte)((frame_nr >> 16) & 0xff); - buf[5] = (byte)((frame_nr >> 8) & 0xff); - buf[6] = (byte)((frame_nr >> 0) & 0xff); - - sendbuf(7); - */ - - /* - printf("%d: %x, %x, %x, %x\n", frame_nr, buf[3], buf[4], buf[5], buf[6]); - */ - - - - flushbuf(); - - - } void handlemessages() @@ -474,43 +470,59 @@ void handlemessages() break; case OP_PLAY: + { + int new_level_nr, new_leveldir_nr; + unsigned long new_random_seed; + unsigned char *new_leveldir_name; + + new_level_nr = (buf[2] << 8) + buf[3]; + new_leveldir_nr = (buf[4] << 8) + buf[5]; + new_random_seed = + (buf[6] << 24) | (buf[7] << 16) | (buf[8] << 8) | (buf[9]); + new_leveldir_name = &buf[10]; + printf("OP_PLAY: %d\n", buf[0]); sprintf(msgbuf, "client %d starts game [level %d from levedir %d (%s)]\n", buf[0], - (buf[2] << 8) + buf[3], - (buf[4] << 8) + buf[5], - &buf[6]); + new_level_nr, + new_leveldir_nr, + new_leveldir_name); sysmsg(msgbuf); - if (strcmp(leveldir[(buf[4] << 8) + buf[5]].name, &buf[6]) == 0) - { - leveldir_nr = (buf[4] << 8) + buf[5]; - local_player->leveldir_nr = leveldir_nr; - LoadPlayerInfo(PLAYER_LEVEL); - SavePlayerInfo(PLAYER_SETUP); + if (strcmp(leveldir[new_leveldir_nr].name, new_leveldir_name) != 0) + Error(ERR_RETURN, "no such level directory: '%s'",new_leveldir_name); - level_nr = (buf[2] << 8) + buf[3]; + leveldir_nr = new_leveldir_nr; - TapeErase(); - LoadLevelTape(level_nr); + local_player->leveldir_nr = leveldir_nr; + LoadPlayerInfo(PLAYER_LEVEL); + SavePlayerInfo(PLAYER_SETUP); - GetPlayerConfig(); - LoadLevel(level_nr); + level_nr = new_level_nr; - { - if (autorecord_on) - TapeStartRecording(); + TapeErase(); + LoadLevelTape(level_nr); + + GetPlayerConfig(); + LoadLevel(level_nr); + + if (autorecord_on) + TapeStartRecording(); + + tape.random_seed = new_random_seed; + + InitRND(tape.random_seed); + + /* + printf("tape.random_seed == %d\n", tape.random_seed); + */ + + game_status = PLAYING; + InitGame(); - game_status = PLAYING; - InitGame(); - } - } - else - { - Error(ERR_RETURN, "no such level directory: '%s'", &buf[6]); - } break; + } case OP_MOVE: { @@ -520,27 +532,21 @@ void handlemessages() frame_nr = (buf[2] << 24) | (buf[3] << 16) | (buf[4] << 8) | (buf[5]); + if (frame_nr != FrameCounter) + { + Error(ERR_RETURN, "client and servers frame counters out of sync"); + Error(ERR_RETURN, "frame counter of client is %d", FrameCounter); + Error(ERR_RETURN, "frame counter of server is %d", frame_nr); + Error(ERR_EXIT, "this should not happen -- please debug"); + } + for (i=0; ihandicap; +#if 0 if (!strcmp(local_player->alias_name,"Artsoft")) +#endif local_player->handicap = leveldir[leveldir_nr].levels-1; if (local_player->handicap != old_handicap) diff --git a/src/tools.c b/src/tools.c index f987d323..1327e4e5 100644 --- a/src/tools.c +++ b/src/tools.c @@ -613,7 +613,7 @@ void DrawGraphicThruMask(int x, int y, int graphic) #if DEBUG if (!IN_SCR_FIELD(x,y)) { - printf("DrawGraphicThruMask(): x = %d, y = %d\n",x,y); + printf("DrawGraphicThruMask(): x = %d,y = %d, graphic = %d\n",x,y,graphic); printf("DrawGraphicThruMask(): This should never happen!\n"); return; }