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();
Delay(10);
}
}
+#endif
+
+
if (game_status == EXITGAME)
return;
HandleSetupScreen(mx,my,0,0,button);
break;
case PLAYING:
+
+ /* --> NoXEvent() will follow */
+
+ /*
HandleGameActions(0);
+ */
+
break;
default:
break;
{
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;
if (tape.pausing || AllPlayersGone)
joy = 0;
- /*
- if (!network_player_action_stored)
- SendToServer_MovePlayer(joy, 0);
- */
-
HandleGameActions((byte)joy);
break;
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);
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);
(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();
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;
}
}
else
recorded_player_action = NULL;
-
- SendToServer_MovePlayer(player_action, FrameCounter);
-
+ if (!standalone)
+ SendToServer_MovePlayer(player_action);
for(i=0; i<MAX_PLAYERS; i++)
{
+ int actual_player_action =
+ (standalone ? player_action : network_player_action[i]);
+
+ /*
int actual_player_action = network_player_action[i];
+ */
/*
int actual_player_action = player_action;
actual_player_action = 0;
*/
+ if (standalone && i != TestPlayer)
+ actual_player_action = 0;
+
/* TEST TEST TEST */
if (recorded_player_action)
network_player_action[i] = 0;
}
- network_player_action_stored = FALSE;
+ network_player_action_received = FALSE;
ScrollScreen(NULL, SCROLL_GO_ON);
FrameCounter++;
TimeFrames++;
+
/*
- printf("advancing FrameCounter to %d\n",
- FrameCounter);
+ printf("FrameCounter == %d, RND(100) == %d\n", FrameCounter, RND(100));
*/
+
for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
{
Stop[x][y] = FALSE;
{
int nr_wanted;
- standalone = FALSE;
-
if (standalone)
return;
int MampferNr, SiebAktiv;
byte network_player_action[MAX_PLAYERS];
-BOOL network_player_action_stored = FALSE;
+BOOL network_player_action_received = FALSE;
int TestPlayer = 0;
struct LevelDirInfo leveldir[MAX_LEVDIR_ENTRIES];
struct RecordingInfo
{
int level_nr;
- unsigned int random_seed;
+ unsigned long random_seed;
unsigned long date;
unsigned long counter;
unsigned long length;
extern int MampferNr, SiebAktiv;
extern byte network_player_action[];
-extern BOOL network_player_action_stored;
+extern BOOL network_player_action_received;
extern int TestPlayer;
extern struct LevelDirInfo leveldir[];
printf("--levels == '%s'\n", level_directory);
}
+ else if (strncmp(option, "-network", option_len) == 0)
+ {
+ printf("--network\n");
+
+ standalone = FALSE;
+ }
else if (strncmp(option, "-verbose", option_len) == 0)
{
printf("--verbose\n");
fatal("Internal error: send buffer overflow");
memcpy(writbuf + nwrite, realbuf, 4 + len);
nwrite += 4 + len;
+
+
+ flushbuf();
+
+
}
}
buf[2] = PROT_VERS_1;
buf[3] = PROT_VERS_2;
buf[4] = PROT_VERS_3;
+
sendbuf(5);
}
{
buf[1] = OP_NRWANTED;
buf[2] = nr_wanted;
+
sendbuf(3);
}
void SendToServer_StartPlaying()
{
+ unsigned long new_random_seed = InitRND(NEW_RANDOMIZE);
+
buf[1] = OP_PLAY;
buf[2] = (byte)(level_nr >> 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()
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:
{
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; i<MAX_PLAYERS; i++)
{
if (stored_player[i].active)
network_player_action[i] = buf[6 + i];
}
- network_player_action_stored = TRUE;
-
- /*
- printf("FrameCounter == %d, frame_nr = %d\n",
- FrameCounter, frame_nr);
- */
-
- /*
- if (buf[2])
- */
-
-
- /*
- printf("OP_MOVE: %d\n", buf[0]);
- */
+ network_player_action_received = TRUE;
sprintf(msgbuf, "frame %d: client %d moves player [0x%02x]",
FrameCounter, buf[0], buf[2]);
void SendToServer_ProtocolVersion(void);
void SendToServer_NrWanted(int);
void SendToServer_StartPlaying(void);
-void SendToServer_MovePlayer(byte, unsigned long);
+void SendToServer_MovePlayer(byte);
void HandleNetworking(void);
#endif
{
int old_handicap = local_player->handicap;
+#if 0
if (!strcmp(local_player->alias_name,"Artsoft"))
+#endif
local_player->handicap = leveldir[leveldir_nr].levels-1;
if (local_player->handicap != old_handicap)
#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;
}