Experimental NETCODE Makefile variable, enabled by default.

Disabling netcode compilation can be interesting on memory-constrained
systems, or those that have no means of accessing the network anyway.
Note: I'm OK with maintaining this myself, i.e. it's fine if netcode dev
breaks compilation with NETCODE=0.

git-svn-id: https://svn.eduke32.com/eduke32@3260 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-12-09 13:24:44 +00:00
parent 1588a80442
commit fc048658dc
8 changed files with 134 additions and 23 deletions

View file

@ -55,6 +55,12 @@ JAUDIOLIB=libjfaudiolib.a
ENETDIR=$(SRC)/enet
ENETLIB=libenet.a
ifeq ($(NETCODE),0)
ENET_TARGET=
else
ENET_TARGET=$(ENETDIR)/$(ENETLIB)
endif
include $(EROOT)/Makefile.shared
@ -353,7 +359,7 @@ finish:
$(BUILD_FINISHED)
$(EDUKE32): $(GAMEOBJS) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(ENETDIR)/$(ENETLIB) $(MISCGAMEDEPS)
$(EDUKE32): $(GAMEOBJS) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(ENET_TARGET) $(MISCGAMEDEPS)
$(LINK_STATUS)
if $(LINKER) -o $@ $^ $(OURLDFLAGS) $(GAMELDFLAGS) $(OURLIBS) $(STATICSTDCPP) $(STDCPPLIB); then $(LINK_OK); else $(LINK_FAILED); fi
ifeq (1,$(RELEASE))

View file

@ -99,7 +99,7 @@ BUILD32_ON_64 ?= 0
# DO NOT SET THIS TO 1 AND COMMIT IT.
USE_LIBPNG ?= 1
USE_LIBVPX ?= 1
NETCODE ?= 1
ifeq (0,$(USE_OPENGL))
POLYMER = 0
@ -310,6 +310,10 @@ ifneq (0,$(CLANG))
BASECOMMONFLAGS+= -Wno-unused-value -Wno-parentheses
endif
ifeq (0,$(NETCODE))
BASECOMMONFLAGS+= -DNETCODE_DISABLE
endif
#### Lunatic development, do not touch!
LUNATIC=0

View file

@ -7754,6 +7754,7 @@ void G_HandleLocalKeys(void)
G_AddUserQuote(ud.ridecule[i-1]);
#ifndef NETCODE_DISABLE
ch = 0;
tempbuf[ch] = PACKET_MESSAGE;
@ -7769,7 +7770,7 @@ void G_HandleLocalKeys(void)
enet_peer_send(g_netClientPeer, CHAN_CHAT, enet_packet_create(tempbuf, i, 0));
else if (g_netServer)
enet_host_broadcast(g_netServer, CHAN_CHAT, enet_packet_create(tempbuf, i, 0));
#endif
pus = NUMPAGES;
pub = NUMPAGES;
@ -7783,7 +7784,7 @@ void G_HandleLocalKeys(void)
FX_PlayAuto3D((char *)RTS_GetSound(i-1),RTS_SoundLength(i-1),0,0,0,255,-i);
g_RTSPlaying = 7;
#ifndef NETCODE_DISABLE
if ((g_netServer || ud.multimode > 1))
{
tempbuf[0] = PACKET_RTS;
@ -7795,7 +7796,7 @@ void G_HandleLocalKeys(void)
else if (g_netServer)
enet_host_broadcast(g_netServer, CHAN_CHAT, enet_packet_create(tempbuf, 3, 0));
}
#endif
pus = NUMPAGES;
pub = NUMPAGES;
@ -9960,9 +9961,11 @@ int32_t app_main(int32_t argc, const char **argv)
}
#endif
#ifndef NETCODE_DISABLE
if (enet_initialize_with_callbacks(ENET_VERSION, &callbacks) != 0)
initprintf("An error occurred while initializing ENet.\n");
else atexit(enet_deinitialize);
#endif
#ifdef _WIN32
backgroundidle = 0;
@ -10331,6 +10334,7 @@ int32_t app_main(int32_t argc, const char **argv)
if (g_scriptDebug)
initprintf("CON debugging activated (level %d).\n",g_scriptDebug);
#ifndef NETCODE_DISABLE
if (g_networkMode == NET_SERVER || g_networkMode == NET_DEDICATED_SERVER)
{
ENetAddress address = { ENET_HOST_ANY, g_netPort };
@ -10340,7 +10344,7 @@ int32_t app_main(int32_t argc, const char **argv)
initprintf("An error occurred while trying to create an ENet server host.\n");
else initprintf("Multiplayer server initialized\n");
}
#endif
numplayers = 1;
if (!g_fakeMultiMode)

View file

@ -931,7 +931,7 @@ static void VM_ResetPlayer(void)
if (g_fakeMultiMode)
P_ResetPlayer(vm.g_p);
#ifndef NETCODE_DISABLE
if (g_netServer)
{
int32_t jj = 0;
@ -949,6 +949,7 @@ static void VM_ResetPlayer(void)
enet_host_broadcast(g_netServer, CHAN_GAMESTATE, enet_packet_create(
packbuf, jj, ENET_PACKET_FLAG_RELIABLE));
}
#endif
}
P_UpdateScreenPal(g_player[vm.g_p].ps);
//AddLog("EOF: resetplayer");

View file

@ -50,6 +50,10 @@ char g_netPassword[32];
int32_t g_netPlayersWaiting = 0;
int32_t g_networkMode = NET_CLIENT;
#ifdef NETCODE_DISABLE
void faketimerhandler(void) {}
#else
static char recbuf[180];
static int32_t g_chatPlayer = -1;
@ -627,6 +631,8 @@ void Net_ReceiveDisconnect(ENetEvent *event)
////////////////////////////////////////////////////////////////////////////////
// Packet Handlers
#endif
void Net_GetPackets(void)
{
sampletimer();
@ -656,6 +662,8 @@ void Net_GetPackets(void)
}
}
#ifndef NETCODE_DISABLE
void Net_HandleClientPackets(void)
{
ENetEvent event;
@ -2316,3 +2324,4 @@ void Net_RecieveMapVoteCancel(uint8_t *pbuf)
voting = -1;
}
#endif // !defined NETCODE_DISABLE

View file

@ -25,6 +25,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "enet/enet.h"
extern uint32_t g_netMapRevision;
extern ENetHost *g_netClient;
extern ENetHost *g_netServer;
extern ENetPeer *g_netClientPeer;
extern char g_netPassword[32];
extern int32_t g_netDisconnect;
extern int32_t g_netPlayersWaiting;
extern enet_uint16 g_netPort;
extern int32_t g_networkMode;
extern int32_t lastsectupdate[MAXSECTORS];
extern int32_t lastupdate[MAXSPRITES];
extern int32_t lastwallupdate[MAXWALLS];
extern int16_t g_netStatnums[10];
#define NET_REVISIONS 64
enum netchan_t
@ -128,20 +142,6 @@ extern netmapstate_t *g_multiMapState[MAXPLAYERS];
extern netmapstate_t *g_multiMapRevisions[NET_REVISIONS];
#pragma pack(pop)
extern uint32_t g_netMapRevision;
extern ENetHost *g_netClient;
extern ENetHost *g_netServer;
extern ENetPeer *g_netClientPeer;
extern char g_netPassword[32];
extern int32_t g_netDisconnect;
extern int32_t g_netPlayersWaiting;
extern enet_uint16 g_netPort;
extern int32_t g_networkMode;
extern int32_t lastsectupdate[MAXSECTORS];
extern int32_t lastupdate[MAXSPRITES];
extern int32_t lastwallupdate[MAXWALLS];
extern int16_t g_netStatnums[10];
#pragma pack(push,1)
typedef struct {
vec3_t pos;
@ -177,13 +177,17 @@ typedef struct {
extern newgame_t pendingnewgame;
#ifndef NETCODE_DISABLE
// Connect/Disconnect
void Net_Connect(const char *srvaddr);
void Net_Disconnect(void);
void Net_ReceiveDisconnect(ENetEvent *event);
// Packet Handlers
#endif
void Net_GetPackets(void);
#ifndef NETCODE_DISABLE
void Net_HandleServerPackets(void);
void Net_HandleClientPackets(void);
void Net_ParseClientPacket(ENetEvent *event);
@ -251,4 +255,81 @@ void Net_SyncPlayer(ENetEvent *event);
void Net_WaitForServer(void);
void faketimerhandler(void);
#else
/* NETCODE_ENABLE is not defined */
// Connect/Disconnect
#define Net_Connect(...) ((void)0)
#define Net_Disconnect(...) ((void)0)
#define Net_ReceiveDisconnect(...) ((void)0)
// Packet Handlers
#define Net_HandleServerPackets(...) ((void)0)
#define Net_HandleClientPackets(...) ((void)0)
#define Net_ParseClientPacket(...) ((void)0)
#define Net_ParseServerPacket(...) ((void)0)
#define Net_ParsePacketCommon(...) ((void)0)
#define Net_SendVersion(...) ((void)0)
#define Net_RecieveVersion(...) ((void)0)
#define Net_SendChallenge(...) ((void)0)
#define Net_RecieveChallenge(...) ((void)0)
#define Net_SendNewPlayer(...) ((void)0)
#define Net_RecieveNewPlayer(...) ((void)0)
#define Net_SendPlayerIndex(...) ((void)0)
#define Net_RecievePlayerIndex(...) ((void)0)
#define Net_SendClientInfo(...) ((void)0)
#define Net_ReceiveClientInfo(...) ((void)0)
#define Net_SendUserMapName(...) ((void)0)
#define Net_ReceiveUserMapName(...) ((void)0)
#define Net_SendClientSync(...) ((void)0)
#define Net_ReceiveClientSync(...) ((void)0)
#define Net_SendMapUpdate(...) ((void)0)
#define Net_ReceiveMapUpdate(...) ((void)0)
#define Net_FillPlayerUpdate(...) ((void)0)
#define Net_ExtractPlayerUpdate(...) ((void)0)
#define Net_SendServerUpdates(...) ((void)0)
#define Net_ReceiveServerUpdate(...) ((void)0)
#define Net_SendClientUpdate(...) ((void)0)
#define Net_ReceiveClientUpdate(...) ((void)0)
#define Net_SendMessage(...) ((void)0)
#define Net_ReceiveMessage(...) ((void)0)
#define Net_StartNewGame(...) ((void)0)
#define Net_SendNewGame(...) ((void)0)
#define Net_ReceiveNewGame(...) ((void)0)
#define Net_FillNewGame(...) ((void)0)
#define Net_ExtractNewGame(...) ((void)0)
#define Net_SendMapVoteInitiate(...) ((void)0)
#define Net_RecieveMapVoteInitiate(...) ((void)0)
#define Net_SendMapVote(...) ((void)0)
#define Net_RecieveMapVote(...) ((void)0)
#define Net_CheckForEnoughVotes(...) ((void)0)
#define Net_SendMapVoteCancel(...) ((void)0)
#define Net_RecieveMapVoteCancel(...) ((void)0)
//////////
#define Net_ResetPrediction(...) ((void)0)
#define Net_RestoreMapState(...) ((void)0)
#define Net_SyncPlayer(...) ((void)0)
#define Net_WaitForServer(...) ((void)0)
#endif
#endif // __netplay_h__

View file

@ -1206,6 +1206,7 @@ static int32_t osdcmd_password(const osdfuncparm_t *parm)
static int32_t osdcmd_listplayers(const osdfuncparm_t *parm)
{
#ifndef NETCODE_DISABLE
ENetPeer *currentPeer;
char ipaddr[32];
@ -1231,12 +1232,13 @@ static int32_t osdcmd_listplayers(const osdfuncparm_t *parm)
initprintf("%x %s %s\n", currentPeer->address.host, ipaddr,
g_player[(intptr_t)currentPeer->data].user_name);
}
#endif
return OSDCMD_OK;
}
static int32_t osdcmd_kick(const osdfuncparm_t *parm)
{
#ifndef NETCODE_DISABLE
ENetPeer *currentPeer;
uint32_t hexaddr;
@ -1269,11 +1271,13 @@ static int32_t osdcmd_kick(const osdfuncparm_t *parm)
initprintf("Player %s not found!\n", parm->parms[0]);
osdcmd_listplayers(NULL);
#endif
return OSDCMD_OK;
}
static int32_t osdcmd_kickban(const osdfuncparm_t *parm)
{
#ifndef NETCODE_DISABLE
ENetPeer *currentPeer;
uint32_t hexaddr;
@ -1312,6 +1316,7 @@ static int32_t osdcmd_kickban(const osdfuncparm_t *parm)
initprintf("Player %s not found!\n", parm->parms[0]);
osdcmd_listplayers(NULL);
#endif
return OSDCMD_OK;
}

View file

@ -3667,7 +3667,7 @@ void P_FragPlayer(int32_t snum)
p->dead_flag = (512-((krand()&1)<<10)+(krand()&255)-512)&2047;
if (p->dead_flag == 0)
p->dead_flag++;
#ifndef NETCODE_DISABLE
if (g_netServer)
{
packbuf[0] = PACKET_FRAG;
@ -3679,6 +3679,7 @@ void P_FragPlayer(int32_t snum)
enet_host_broadcast(g_netServer, CHAN_GAMESTATE, enet_packet_create(packbuf, 9, ENET_PACKET_FLAG_RELIABLE));
}
#endif
}
p->jetpack_on = 0;