mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 14:51:40 +00:00
- moved i_net into 'common' to bring it in line with Raze.
This commit is contained in:
parent
228dfb5b8d
commit
348f9ae68c
8 changed files with 125 additions and 84 deletions
|
@ -844,7 +844,6 @@ set (PCH_SOURCES
|
|||
gameconfigfile.cpp
|
||||
gitinfo.cpp
|
||||
hu_scores.cpp
|
||||
i_net.cpp
|
||||
m_cheat.cpp
|
||||
m_misc.cpp
|
||||
playsim/p_acs.cpp
|
||||
|
@ -1115,6 +1114,7 @@ set (PCH_SOURCES
|
|||
common/engine/sc_man.cpp
|
||||
common/engine/palettecontainer.cpp
|
||||
common/engine/stringtable.cpp
|
||||
common/engine/i_net.cpp
|
||||
common/engine/i_interface.cpp
|
||||
common/engine/renderstyle.cpp
|
||||
common/engine/v_colortables.cpp
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// Emacs style mode select -*- C++ -*-
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright 1993-1996 id Software
|
||||
// Copyright 1999-2016 Randy Heit
|
||||
// $Id: i_net.c,v 1.2 1997/12/29 19:50:54 pekangas Exp $
|
||||
//
|
||||
// Copyright (C) 1993-1996 by id Software, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,7 +18,19 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Alternatively the following applies:
|
||||
//
|
||||
// This source is available for distribution and/or modification
|
||||
// only under the terms of the DOOM Source Code License as
|
||||
// published by id Software. All rights reserved.
|
||||
//
|
||||
// The source is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
||||
// for more details.
|
||||
//
|
||||
//
|
||||
// DESCRIPTION:
|
||||
// Low-level networking code. Uses BSD sockets for UDP networking.
|
||||
|
@ -53,16 +67,15 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "i_system.h"
|
||||
#include "d_net.h"
|
||||
#include "m_argv.h"
|
||||
#include "m_crc32.h"
|
||||
#include "d_player.h"
|
||||
#include "st_start.h"
|
||||
#include "m_misc.h"
|
||||
#include "engineerrors.h"
|
||||
#include "cmdlib.h"
|
||||
#include "printf.h"
|
||||
#include "i_interface.h"
|
||||
#include "templates.h"
|
||||
|
||||
#include "i_net.h"
|
||||
|
||||
|
@ -91,6 +104,10 @@ typedef int SOCKET;
|
|||
typedef int socklen_t;
|
||||
#endif
|
||||
|
||||
bool netgame, multiplayer;
|
||||
int consoleplayer; // i.e. myconnectindex in Build.
|
||||
doomcom_t doomcom;
|
||||
|
||||
//
|
||||
// NETWORKING
|
||||
//
|
||||
|
@ -143,6 +160,12 @@ struct PreGamePacket
|
|||
|
||||
uint8_t TransmitBuffer[TRANSMIT_SIZE];
|
||||
|
||||
FString GetPlayerName(int num)
|
||||
{
|
||||
if (sysCallbacks && sysCallbacks->GetPlayerName) return sysCallbacks->GetPlayerName(sendplayer[num]);
|
||||
else return FStringf("Player %d", num + 1);
|
||||
}
|
||||
|
||||
//
|
||||
// UDPsocket
|
||||
//
|
||||
|
@ -272,12 +295,12 @@ void PacketGet (void)
|
|||
if (StartScreen != NULL)
|
||||
{
|
||||
StartScreen->NetMessage ("The connection from %s was dropped.\n",
|
||||
players[sendplayer[node]].userinfo.GetName());
|
||||
GetPlayerName(node).GetChars());
|
||||
}
|
||||
else
|
||||
{
|
||||
Printf("The connection from %s was dropped.\n",
|
||||
players[sendplayer[node]].userinfo.GetName());
|
||||
GetPlayerName(node).GetChars());
|
||||
}
|
||||
|
||||
doomcom.data[0] = 0x80; // NCMD_EXIT
|
||||
|
@ -945,7 +968,7 @@ int I_InitNetwork (void)
|
|||
v = Args->CheckValue ("-dup");
|
||||
if (v)
|
||||
{
|
||||
doomcom.ticdup = clamp (atoi (v), 1, MAXTICDUP);
|
||||
doomcom.ticdup = clamp<int> (atoi (v), 1, MAXTICDUP);
|
||||
}
|
||||
else
|
||||
{
|
85
src/common/engine/i_net.h
Normal file
85
src/common/engine/i_net.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
#ifndef __I_NET_H__
|
||||
#define __I_NET_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Called by D_DoomMain.
|
||||
int I_InitNetwork (void);
|
||||
void I_NetCmd (void);
|
||||
|
||||
enum ENetConstants
|
||||
{
|
||||
MAXNETNODES = 8, // max computers in a game
|
||||
DOOMCOM_ID = 0x12345678,
|
||||
BACKUPTICS = 36, // number of tics to remember
|
||||
MAXTICDUP = 5,
|
||||
LOCALCMDTICS =(BACKUPTICS*MAXTICDUP),
|
||||
MAX_MSGLEN = 14000,
|
||||
|
||||
CMD_SEND = 1,
|
||||
CMD_GET = 2,
|
||||
};
|
||||
|
||||
// [RH]
|
||||
// New generic packet structure:
|
||||
//
|
||||
// Header:
|
||||
// One byte with following flags.
|
||||
// One byte with starttic
|
||||
// One byte with master's maketic (master -> slave only!)
|
||||
// If NCMD_RETRANSMIT set, one byte with retransmitfrom
|
||||
// If NCMD_XTICS set, one byte with number of tics (minus 3, so theoretically up to 258 tics in one packet)
|
||||
// If NCMD_QUITTERS, one byte with number of players followed by one byte with each player's consolenum
|
||||
// If NCMD_MULTI, one byte with number of players followed by one byte with each player's consolenum
|
||||
// - The first player's consolenum is not included in this list, because it always matches the sender
|
||||
//
|
||||
// For each tic:
|
||||
// Two bytes with consistancy check, followed by tic data
|
||||
//
|
||||
// Setup packets are different, and are described just before D_ArbitrateNetStart().
|
||||
|
||||
enum ENCMD
|
||||
{
|
||||
NCMD_EXIT = 0x80,
|
||||
NCMD_RETRANSMIT = 0x40,
|
||||
NCMD_SETUP = 0x20,
|
||||
NCMD_MULTI = 0x10, // multiple players in this packet
|
||||
NCMD_QUITTERS = 0x08, // one or more players just quit (packet server only)
|
||||
NCMD_COMPRESSED = 0x04, // remainder of packet is compressed
|
||||
|
||||
NCMD_XTICS = 0x03, // packet contains >2 tics
|
||||
NCMD_2TICS = 0x02, // packet contains 2 tics
|
||||
NCMD_1TICS = 0x01, // packet contains 1 tic
|
||||
NCMD_0TICS = 0x00, // packet contains 0 tics
|
||||
};
|
||||
|
||||
//
|
||||
// Network packet data.
|
||||
//
|
||||
struct doomcom_t
|
||||
{
|
||||
uint32_t id; // should be DOOMCOM_ID
|
||||
int16_t intnum; // DOOM executes an int to execute commands
|
||||
|
||||
// communication between DOOM and the driver
|
||||
int16_t command; // CMD_SEND or CMD_GET
|
||||
int16_t remotenode; // dest for send, set by get (-1 = no packet).
|
||||
int16_t datalength; // bytes in data to be sent
|
||||
|
||||
// info common to all nodes
|
||||
int16_t numnodes; // console is always node 0.
|
||||
int16_t ticdup; // 1 = no duplication, 2-5 = dup for slow nets
|
||||
|
||||
// info specific to this node
|
||||
int16_t consoleplayer;
|
||||
int16_t numplayers;
|
||||
|
||||
// packet data to be sent
|
||||
uint8_t data[MAX_MSGLEN];
|
||||
|
||||
};
|
||||
|
||||
extern doomcom_t doomcom;
|
||||
extern bool netgame, multiplayer;
|
||||
|
||||
#endif
|
|
@ -2830,6 +2830,10 @@ FString System_GetLocationDescription()
|
|||
|
||||
}
|
||||
|
||||
FString System_GetPlayerName(int node)
|
||||
{
|
||||
return players[node].userinfo.GetName();
|
||||
}
|
||||
//==========================================================================
|
||||
//
|
||||
// DoomSpecificInfo
|
||||
|
@ -3071,6 +3075,7 @@ static int D_DoomMain_Internal (void)
|
|||
System_GetSceneRect,
|
||||
System_GetLocationDescription,
|
||||
System_M_Dim,
|
||||
System_GetPlayerName,
|
||||
};
|
||||
sysCallbacks = &syscb;
|
||||
|
||||
|
|
|
@ -82,7 +82,6 @@ extern FString savegamefile;
|
|||
|
||||
extern short consistancy[MAXPLAYERS][BACKUPTICS];
|
||||
|
||||
doomcom_t doomcom;
|
||||
#define netbuffer (doomcom.data)
|
||||
|
||||
enum { NET_PeerToPeer, NET_PacketServer };
|
||||
|
|
62
src/d_net.h
62
src/d_net.h
|
@ -31,67 +31,7 @@
|
|||
#include "doomtype.h"
|
||||
#include "doomdef.h"
|
||||
#include "d_protocol.h"
|
||||
|
||||
|
||||
//
|
||||
// Network play related stuff.
|
||||
// There is a data struct that stores network
|
||||
// communication related stuff, and another
|
||||
// one that defines the actual packets to
|
||||
// be transmitted.
|
||||
//
|
||||
|
||||
#define DOOMCOM_ID 0x12345678l
|
||||
#define MAXNETNODES 8 // max computers in a game
|
||||
#define BACKUPTICS 36 // number of tics to remember
|
||||
#define MAXTICDUP 5
|
||||
#define LOCALCMDTICS (BACKUPTICS*MAXTICDUP)
|
||||
|
||||
|
||||
#ifdef DJGPP
|
||||
// The DOS drivers provide a pretty skimpy buffer.
|
||||
// Probably not enough.
|
||||
#define MAX_MSGLEN (BACKUPTICS*10)
|
||||
#else
|
||||
#define MAX_MSGLEN 14000
|
||||
#endif
|
||||
|
||||
#define CMD_SEND 1
|
||||
#define CMD_GET 2
|
||||
|
||||
//
|
||||
// Network packet data.
|
||||
//
|
||||
struct doomcom_t
|
||||
{
|
||||
uint32_t id; // should be DOOMCOM_ID
|
||||
int16_t intnum; // DOOM executes an int to execute commands
|
||||
|
||||
// communication between DOOM and the driver
|
||||
int16_t command; // CMD_SEND or CMD_GET
|
||||
int16_t remotenode; // dest for send, set by get (-1 = no packet).
|
||||
int16_t datalength; // bytes in doomdata to be sent
|
||||
|
||||
// info common to all nodes
|
||||
int16_t numnodes; // console is always node 0.
|
||||
int16_t ticdup; // 1 = no duplication, 2-5 = dup for slow nets
|
||||
#ifdef DJGPP
|
||||
int16_t pad[5]; // keep things aligned for DOS drivers
|
||||
#endif
|
||||
|
||||
// info specific to this node
|
||||
int16_t consoleplayer;
|
||||
int16_t numplayers;
|
||||
#ifdef DJGPP
|
||||
int16_t angleoffset; // does not work, but needed to preserve
|
||||
int16_t drone; // alignment for DOS drivers
|
||||
#endif
|
||||
|
||||
// packet data to be sent
|
||||
uint8_t data[MAX_MSGLEN];
|
||||
|
||||
};
|
||||
|
||||
#include "i_net.h"
|
||||
|
||||
class FDynamicBuffer
|
||||
{
|
||||
|
|
|
@ -155,13 +155,10 @@ bool noblit; // for comparative timing purposes
|
|||
|
||||
bool viewactive;
|
||||
|
||||
bool netgame; // only true if packets are broadcast
|
||||
bool multiplayer;
|
||||
bool multiplayernext = false; // [SP] Map coop/dm implementation
|
||||
player_t players[MAXPLAYERS];
|
||||
bool playeringame[MAXPLAYERS];
|
||||
|
||||
int consoleplayer; // player taking events
|
||||
int gametic;
|
||||
|
||||
time_t epochoffset = 0; // epoch start in seconds (0 = January 1st, 1970)
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef __I_NET_H__
|
||||
#define __I_NET_H__
|
||||
|
||||
// Called by D_DoomMain.
|
||||
int I_InitNetwork (void);
|
||||
void I_NetCmd (void);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue