2015-05-19 21:54:34 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 1997, 2005 - 3D Realms Entertainment
|
|
|
|
|
|
|
|
This file is part of Shadow Warrior version 1.2
|
|
|
|
|
|
|
|
Shadow Warrior is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
Original Source: 1997 - Frank Maddin and Jim Norwood
|
|
|
|
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-10-09 16:09:05 +00:00
|
|
|
#include "ns.h"
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "build.h"
|
|
|
|
#include "baselayer.h"
|
|
|
|
#include "mmulti.h"
|
|
|
|
|
2020-05-29 00:32:53 +00:00
|
|
|
#include "gamecontrol.h"
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "game.h"
|
|
|
|
#include "tags.h"
|
|
|
|
#include "names2.h"
|
2019-03-21 02:24:19 +00:00
|
|
|
#include "network.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "pal.h"
|
|
|
|
|
|
|
|
#include "weapon.h"
|
|
|
|
#include "menus.h"
|
2020-01-07 00:11:19 +00:00
|
|
|
#include "printf.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
BEGIN_SW_NS
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-05-19 13:14:15 +00:00
|
|
|
void getinput(SW_PACKET *, SWBOOL);
|
2019-10-09 17:58:09 +00:00
|
|
|
|
2019-04-08 06:26:08 +00:00
|
|
|
static uint8_t tempbuf[576], packbuf[576];
|
2015-05-19 21:54:34 +00:00
|
|
|
int PlayClock;
|
|
|
|
|
|
|
|
gNET gNet;
|
|
|
|
|
|
|
|
#define TIMERUPDATESIZ 32
|
|
|
|
|
|
|
|
//SW_PACKET fsync;
|
|
|
|
|
|
|
|
//Local multiplayer variables
|
|
|
|
// should move this to a local scope of faketimerhandler - do it when able to test
|
|
|
|
SW_PACKET loc;
|
|
|
|
|
|
|
|
//SW_PACKET oloc;
|
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
SWBOOL ready2send = 0;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
SWBOOL CommEnabled = FALSE;
|
|
|
|
uint8_t CommPlayers = 0;
|
2015-05-19 21:54:34 +00:00
|
|
|
int movefifoplc, movefifosendplc; //, movefifoend[MAX_SW_PLAYERS];
|
|
|
|
unsigned int MoveThingsCount;
|
|
|
|
|
|
|
|
//int myminlag[MAX_SW_PLAYERS];
|
|
|
|
int mymaxlag, otherminlag, bufferjitter = 1;
|
2015-05-19 22:10:03 +00:00
|
|
|
extern char sync_first[MAXSYNCBYTES][60];
|
2015-05-19 21:54:34 +00:00
|
|
|
extern int sync_found;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tic Duplication - so you can move multiple times per packet
|
|
|
|
//
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-05-19 21:58:29 +00:00
|
|
|
int32_t vel;
|
|
|
|
int32_t svel;
|
2020-04-12 20:28:32 +00:00
|
|
|
fix16_t q16angvel;
|
|
|
|
fix16_t q16aimvel;
|
2020-04-10 21:23:42 +00:00
|
|
|
fix16_t q16ang;
|
|
|
|
fix16_t q16horiz;
|
2015-05-19 21:58:29 +00:00
|
|
|
int32_t bits;
|
2015-05-19 21:54:34 +00:00
|
|
|
} SW_AVERAGE_PACKET;
|
|
|
|
|
|
|
|
int MovesPerPacket = 1;
|
|
|
|
SW_AVERAGE_PACKET AveragePacket;
|
|
|
|
|
|
|
|
// GAME.C sync state variables
|
2015-05-19 21:58:29 +00:00
|
|
|
uint8_t syncstat[MAXSYNCBYTES];
|
2015-05-19 21:54:34 +00:00
|
|
|
//int syncvalhead[MAX_SW_PLAYERS];
|
|
|
|
int syncvaltail, syncvaltottail;
|
2019-04-08 06:27:12 +00:00
|
|
|
void GetSyncInfoFromPacket(uint8_t *packbuf, int packbufleng, int *j, int otherconnectindex);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// when you set totalclock to 0 also set this one
|
|
|
|
int ototalclock;
|
|
|
|
int smoothratio;
|
|
|
|
int save_totalclock;
|
|
|
|
|
|
|
|
// must start out as 0
|
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
void
|
|
|
|
InitNetPlayerOptions(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-03-06 15:49:55 +00:00
|
|
|
// short pnum;
|
2015-05-19 21:54:34 +00:00
|
|
|
PLAYERp pp = Player + myconnectindex;
|
|
|
|
|
2019-10-27 13:09:56 +00:00
|
|
|
strncpy(pp->PlayerName, playername, 32);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// myconnectindex palette
|
|
|
|
pp->TeamColor = gs.NetColor;
|
2020-08-16 17:11:04 +00:00
|
|
|
if (pp->SpriteP)
|
|
|
|
{
|
|
|
|
pp->SpriteP->pal = PALETTE_PLAYER0 + pp->TeamColor;
|
|
|
|
User[pp->SpriteP - sprite]->spal = pp->SpriteP->pal;
|
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
waitforeverybody(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
void
|
|
|
|
InitNetVars(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
short pnum;
|
|
|
|
PLAYERp pp;
|
|
|
|
|
|
|
|
memset(&loc, 0, sizeof(loc));
|
|
|
|
|
|
|
|
TRAVERSE_CONNECT(pnum)
|
|
|
|
{
|
|
|
|
pp = Player + pnum;
|
|
|
|
pp->movefifoend = 0;
|
|
|
|
Player[pnum].syncvalhead = 0;
|
|
|
|
memset(pp->inputfifo,0,sizeof(pp->inputfifo));
|
|
|
|
}
|
|
|
|
movefifoplc = 0;
|
|
|
|
movefifosendplc = 0;
|
|
|
|
syncvaltail = 0;
|
|
|
|
syncvaltottail = 0;
|
|
|
|
predictmovefifoplc = 0;
|
|
|
|
|
|
|
|
memset(&syncstat, 0, sizeof(syncstat));
|
|
|
|
memset(sync_first, 0, sizeof(sync_first));
|
|
|
|
sync_found = FALSE;
|
|
|
|
|
|
|
|
TRAVERSE_CONNECT(pnum)
|
|
|
|
{
|
|
|
|
Player[pnum].myminlag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
otherminlag = mymaxlag = 0;
|
|
|
|
}
|
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
void
|
|
|
|
InitTimingVars(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
PlayClock = 0;
|
|
|
|
|
|
|
|
// resettiming();
|
|
|
|
totalsynctics = 0;
|
|
|
|
totalclock = 0;
|
|
|
|
ototalclock = 0;
|
|
|
|
randomseed = 17L;
|
|
|
|
|
|
|
|
MoveSkip8 = 2;
|
|
|
|
MoveSkip2 = 0;
|
|
|
|
MoveSkip4 = 1; // start slightly offset so these
|
|
|
|
// don't move the same
|
|
|
|
// as the Skip2's
|
|
|
|
MoveThingsCount = 0;
|
|
|
|
|
|
|
|
// CTW REMOVED
|
|
|
|
//if (gTenActivated)
|
|
|
|
// tenResetClock();
|
|
|
|
// CTW REMOVED END
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2020-05-21 23:23:39 +00:00
|
|
|
UpdateInputs(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-03-06 15:49:49 +00:00
|
|
|
int i, j, k;
|
2015-05-19 21:54:34 +00:00
|
|
|
PLAYERp pp;
|
|
|
|
|
|
|
|
ototalclock += synctics;
|
|
|
|
|
2020-08-16 08:40:20 +00:00
|
|
|
//getpackets();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (Player[myconnectindex].movefifoend - movefifoplc >= 100)
|
|
|
|
return;
|
|
|
|
|
2020-04-11 07:17:59 +00:00
|
|
|
getinput(&loc, FALSE);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
AveragePacket.vel += loc.vel;
|
|
|
|
AveragePacket.svel += loc.svel;
|
2020-04-12 20:28:32 +00:00
|
|
|
AveragePacket.q16angvel += loc.q16angvel;
|
|
|
|
AveragePacket.q16aimvel += loc.q16aimvel;
|
2020-04-10 21:23:42 +00:00
|
|
|
AveragePacket.q16ang = Player[myconnectindex].camq16ang;
|
|
|
|
AveragePacket.q16horiz = Player[myconnectindex].camq16horiz;
|
2015-05-19 21:54:34 +00:00
|
|
|
SET(AveragePacket.bits, loc.bits);
|
|
|
|
|
2020-04-11 07:17:59 +00:00
|
|
|
Bmemset(&loc, 0, sizeof(loc));
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
pp = Player + myconnectindex;
|
|
|
|
|
|
|
|
if (pp->movefifoend & (MovesPerPacket-1))
|
|
|
|
{
|
|
|
|
memcpy(&pp->inputfifo[pp->movefifoend & (MOVEFIFOSIZ - 1)],
|
|
|
|
&pp->inputfifo[(pp->movefifoend-1) & (MOVEFIFOSIZ - 1)],
|
|
|
|
sizeof(SW_PACKET));
|
|
|
|
|
|
|
|
pp->movefifoend++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loc.vel = AveragePacket.vel / MovesPerPacket;
|
|
|
|
loc.svel = AveragePacket.svel / MovesPerPacket;
|
2020-04-12 20:28:32 +00:00
|
|
|
loc.q16angvel = fix16_div(AveragePacket.q16angvel, fix16_from_int(MovesPerPacket));
|
|
|
|
loc.q16aimvel = fix16_div(AveragePacket.q16aimvel, fix16_from_int(MovesPerPacket));
|
2020-04-10 21:23:42 +00:00
|
|
|
loc.q16ang = AveragePacket.q16ang;
|
|
|
|
loc.q16horiz = AveragePacket.q16horiz;
|
2015-05-19 21:54:34 +00:00
|
|
|
loc.bits = AveragePacket.bits;
|
|
|
|
|
|
|
|
memset(&AveragePacket, 0, sizeof(AveragePacket));
|
|
|
|
|
|
|
|
pp->inputfifo[Player[myconnectindex].movefifoend & (MOVEFIFOSIZ - 1)] = loc;
|
|
|
|
pp->movefifoend++;
|
2020-04-11 07:17:59 +00:00
|
|
|
Bmemset(&loc, 0, sizeof(loc));
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (!CommEnabled)
|
|
|
|
{
|
|
|
|
TRAVERSE_CONNECT(i)
|
|
|
|
{
|
|
|
|
if (i != myconnectindex)
|
|
|
|
{
|
2020-08-12 22:45:50 +00:00
|
|
|
memset(&Player[i].inputfifo[Player[i].movefifoend & (MOVEFIFOSIZ - 1)], 0, sizeof(Player[i].inputfifo[0]));
|
2015-05-19 21:54:34 +00:00
|
|
|
Player[i].movefifoend++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|