Restructure the waiting screen code. Establish our own separate event
loop while waiting for the game to start, to avoid affecting the original code too much. Move some _gui variables to net_client.c. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 252
This commit is contained in:
parent
dd2339bca5
commit
fba617a6b4
4 changed files with 144 additions and 35 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// Emacs style mode select -*- C++ -*-
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Id: net_client.c 246 2006-01-02 20:14:07Z fraggle $
|
||||
// $Id: net_client.c 252 2006-01-02 21:50:26Z fraggle $
|
||||
//
|
||||
// Copyright(C) 2005 Simon Howard
|
||||
//
|
||||
|
|
@ -21,6 +21,11 @@
|
|||
// 02111-1307, USA.
|
||||
//
|
||||
// $Log$
|
||||
// Revision 1.8 2006/01/02 21:50:26 fraggle
|
||||
// Restructure the waiting screen code. Establish our own separate event
|
||||
// loop while waiting for the game to start, to avoid affecting the original
|
||||
// code too much. Move some _gui variables to net_client.c.
|
||||
//
|
||||
// Revision 1.7 2006/01/02 20:14:07 fraggle
|
||||
// Fix connect timeout and shutdown client properly if we fail to connect.
|
||||
//
|
||||
|
|
@ -83,13 +88,38 @@ typedef enum
|
|||
CLIENT_STATE_DISCONNECTED,
|
||||
} net_clientstate_t;
|
||||
|
||||
static boolean client_initialised = false;
|
||||
|
||||
static net_clientstate_t client_state;
|
||||
static net_addr_t *server_addr;
|
||||
static net_context_t *client_context;
|
||||
static int last_send_time;
|
||||
|
||||
// if TRUE, we are connected to a server
|
||||
|
||||
boolean net_client_connected = false;
|
||||
|
||||
// if TRUE, this client is the controller of the game
|
||||
|
||||
boolean net_client_controller = false;
|
||||
|
||||
// Number of clients currently connected to the server
|
||||
|
||||
int net_clients_in_game;
|
||||
|
||||
// Waiting for the game to start?
|
||||
|
||||
boolean net_waiting_for_start = false;
|
||||
|
||||
// Shut down the client code, etc. Invoked after a disconnect.
|
||||
|
||||
static void NET_CL_Shutdown(void)
|
||||
{
|
||||
net_client_connected = false;
|
||||
|
||||
NET_FreeAddress(server_addr);
|
||||
|
||||
// Shut down network module, etc. To do.
|
||||
}
|
||||
|
||||
// data received while we are waiting for the game to start
|
||||
|
||||
static void NET_CL_ParseWaitingData(net_packet_t *packet)
|
||||
|
|
@ -154,6 +184,8 @@ static void NET_CL_ParseDisconnect(net_packet_t *packet)
|
|||
fprintf(stderr, "Disconnected from server.\n");
|
||||
|
||||
// Now what?
|
||||
|
||||
NET_CL_Disconnect();
|
||||
}
|
||||
|
||||
// parse a DISCONNECT_ACK packet
|
||||
|
|
@ -283,7 +315,7 @@ void NET_CL_Run(void)
|
|||
net_addr_t *addr;
|
||||
net_packet_t *packet;
|
||||
|
||||
if (!client_initialised)
|
||||
if (!net_client_connected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -315,15 +347,6 @@ void NET_CL_Run(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void NET_CL_Shutdown(void)
|
||||
{
|
||||
client_initialised = false;
|
||||
|
||||
NET_FreeAddress(server_addr);
|
||||
|
||||
// Shut down network module, etc. To do.
|
||||
}
|
||||
|
||||
// connect to a server
|
||||
|
||||
boolean NET_CL_Connect(net_addr_t *addr)
|
||||
|
|
@ -346,7 +369,8 @@ boolean NET_CL_Connect(net_addr_t *addr)
|
|||
|
||||
NET_AddModule(client_context, addr->module);
|
||||
|
||||
client_initialised = true;
|
||||
net_client_connected = true;
|
||||
net_waiting_for_start = true;
|
||||
|
||||
// try to connect
|
||||
|
||||
|
|
@ -400,7 +424,7 @@ void NET_CL_Disconnect(void)
|
|||
{
|
||||
int start_time;
|
||||
|
||||
if (!client_initialised)
|
||||
if (!net_client_connected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Emacs style mode select -*- C++ -*-
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Id: net_client.h 239 2006-01-02 00:00:08Z fraggle $
|
||||
// $Id: net_client.h 252 2006-01-02 21:50:26Z fraggle $
|
||||
//
|
||||
// Copyright(C) 2005 Simon Howard
|
||||
//
|
||||
|
|
@ -21,6 +21,11 @@
|
|||
// 02111-1307, USA.
|
||||
//
|
||||
// $Log$
|
||||
// Revision 1.6 2006/01/02 21:50:26 fraggle
|
||||
// Restructure the waiting screen code. Establish our own separate event
|
||||
// loop while waiting for the game to start, to avoid affecting the original
|
||||
// code too much. Move some _gui variables to net_client.c.
|
||||
//
|
||||
// Revision 1.5 2006/01/02 00:00:08 fraggle
|
||||
// Neater prefixes: NET_Client -> NET_CL_. NET_Server -> NET_SV_.
|
||||
//
|
||||
|
|
@ -46,11 +51,17 @@
|
|||
#ifndef NET_CLIENT_H
|
||||
#define NET_CLIENT_H
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "net_defs.h"
|
||||
|
||||
boolean NET_CL_Connect(net_addr_t *addr);
|
||||
void NET_CL_Disconnect(void);
|
||||
void NET_CL_Run(void);
|
||||
|
||||
extern boolean net_client_connected;
|
||||
extern boolean net_client_controller;
|
||||
extern int net_clients_in_game;
|
||||
extern boolean net_waiting_for_start;
|
||||
|
||||
#endif /* #ifndef NET_CLIENT_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Emacs style mode select -*- C++ -*-
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Id: net_gui.c 235 2005-12-30 18:58:22Z fraggle $
|
||||
// $Id: net_gui.c 252 2006-01-02 21:50:26Z fraggle $
|
||||
//
|
||||
// Copyright(C) 2005 Simon Howard
|
||||
//
|
||||
|
|
@ -21,6 +21,11 @@
|
|||
// 02111-1307, USA.
|
||||
//
|
||||
// $Log$
|
||||
// Revision 1.2 2006/01/02 21:50:26 fraggle
|
||||
// Restructure the waiting screen code. Establish our own separate event
|
||||
// loop while waiting for the game to start, to avoid affecting the original
|
||||
// code too much. Move some _gui variables to net_client.c.
|
||||
//
|
||||
// Revision 1.1 2005/12/30 18:58:22 fraggle
|
||||
// Fix client code to correctly send reply to server on connection.
|
||||
// Add "waiting screen" while waiting for the game to start.
|
||||
|
|
@ -33,8 +38,15 @@
|
|||
// start the game.
|
||||
//
|
||||
|
||||
#include "net_client.h"
|
||||
#include "net_gui.h"
|
||||
#include "net_server.h"
|
||||
|
||||
#include "d_event.h"
|
||||
#include "d_main.h"
|
||||
#include "i_system.h"
|
||||
#include "i_video.h"
|
||||
#include "m_menu.h"
|
||||
#include "r_defs.h"
|
||||
#include "v_video.h"
|
||||
#include "w_wad.h"
|
||||
|
|
@ -42,15 +54,7 @@
|
|||
|
||||
extern void M_WriteText(int x, int y, char *string);
|
||||
|
||||
// if TRUE, this client is the controller of the game
|
||||
|
||||
boolean net_client_controller = false;
|
||||
|
||||
// Number of clients currently connected to the server
|
||||
|
||||
int net_clients_in_game;
|
||||
|
||||
void NET_Drawer(void)
|
||||
static void Drawer(void)
|
||||
{
|
||||
patch_t *backdrop;
|
||||
int backdrop_lumpnum;
|
||||
|
|
@ -85,8 +89,78 @@ void NET_Drawer(void)
|
|||
}
|
||||
}
|
||||
|
||||
boolean NET_Responder(event_t *event)
|
||||
static void ProcessEvents(void)
|
||||
{
|
||||
return true;
|
||||
event_t *ev;
|
||||
|
||||
while ((ev = D_PopEvent()) != NULL)
|
||||
{
|
||||
if (M_Responder(ev))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// process event ...
|
||||
}
|
||||
}
|
||||
|
||||
// Displays a graphical screen while waiting for the game to start.
|
||||
|
||||
void NET_WaitForStart(void)
|
||||
{
|
||||
int last_tic_time;
|
||||
int nowtime;
|
||||
int runtics;
|
||||
int i;
|
||||
|
||||
if (!net_client_connected || !net_waiting_for_start)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
last_tic_time = I_GetTime();
|
||||
|
||||
while (net_waiting_for_start)
|
||||
{
|
||||
// Keyboard/mouse events, etc.
|
||||
|
||||
I_StartTic();
|
||||
ProcessEvents();
|
||||
|
||||
// Run the menu, etc.
|
||||
|
||||
nowtime = I_GetTime();
|
||||
runtics = nowtime - last_tic_time;
|
||||
|
||||
if (runtics > 0)
|
||||
{
|
||||
for (i=0; i<runtics; ++i)
|
||||
{
|
||||
M_Ticker();
|
||||
}
|
||||
|
||||
last_tic_time = nowtime;
|
||||
|
||||
// Draw the screen
|
||||
|
||||
Drawer();
|
||||
M_Drawer();
|
||||
I_FinishUpdate();
|
||||
}
|
||||
|
||||
// Network stuff
|
||||
|
||||
NET_CL_Run();
|
||||
NET_SV_Run();
|
||||
|
||||
if (!net_client_connected)
|
||||
{
|
||||
I_Error("Disconnected from server");
|
||||
}
|
||||
|
||||
// Don't hog the CPU
|
||||
|
||||
I_Sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Emacs style mode select -*- C++ -*-
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Id: net_gui.h 235 2005-12-30 18:58:22Z fraggle $
|
||||
// $Id: net_gui.h 252 2006-01-02 21:50:26Z fraggle $
|
||||
//
|
||||
// Copyright(C) 2005 Simon Howard
|
||||
//
|
||||
|
|
@ -21,6 +21,11 @@
|
|||
// 02111-1307, USA.
|
||||
//
|
||||
// $Log$
|
||||
// Revision 1.2 2006/01/02 21:50:26 fraggle
|
||||
// Restructure the waiting screen code. Establish our own separate event
|
||||
// loop while waiting for the game to start, to avoid affecting the original
|
||||
// code too much. Move some _gui variables to net_client.c.
|
||||
//
|
||||
// Revision 1.1 2005/12/30 18:58:22 fraggle
|
||||
// Fix client code to correctly send reply to server on connection.
|
||||
// Add "waiting screen" while waiting for the game to start.
|
||||
|
|
@ -38,13 +43,8 @@
|
|||
#define NET_GUI_H
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "d_event.h"
|
||||
|
||||
extern void NET_Drawer(void);
|
||||
extern boolean NET_Responder(event_t *event);
|
||||
|
||||
extern boolean net_client_controller;
|
||||
extern int net_clients_in_game;
|
||||
extern void NET_WaitForStart();
|
||||
|
||||
#endif /* #ifndef NET_GUI_H */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue