mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-08 17:30:39 +00:00
83936bf5eb
This reverts commite878c5bab8
. Revert "SW: Use Q16.16 for horiz." This reverts commitf07a0ae01e
. Revert "SW: Use Q16.16 for angle." This reverts commit1ecc74c2ec
. Revert "SW: Minor repairs for Q16.16 implementation." This reverts commitd78d046bad
. Revert "SW: Process input at frame rate." This reverts commitc162014dab
. Revert "SW: Amendments to accommodate changes in master." This reverts commiteaa51138ad
. Revert "SW: Fix incorrectly declared function input type." This reverts commit1cdd5b08d8
. Revert "SW: Amend scaleAdjustmentToInterval() with correct value for SW." This reverts commitd4dd737cd5
. Revert "SW: Refinements to new input code." This reverts commit5ebc65a1fb
. Revert "SW: Adjust look and snap up/down keys and slightly tune PLAYER_TURN_AMOUNT." This reverts commit2852536dbf
. Revert "SW: Get PLAYER_TURN_SCALE to be just right." This reverts commit4630c8a0b7
. Revert "SW: Make map follow mode work better." This reverts commit8e94c48eff
. Revert "SW: Remove line accidentally left from 'MoveScrollMode2D()'." This reverts commit5db8047b41
. Revert "Fix multiplayer desync after the change to q16 angle and horiz." This reverts commit3bc46078b8
. Revert "SW: Revert commented out horiz->q16horiz renames in DSPRINTF strings" This reverts commit537313f620
. Revert "sw/src/draw.cpp:drawscreen: We can set the pp->si* fields just once," This reverts commitd2e9595980
. Revert "sw/src/game.cpp:LoadLevel: Rename q16ang -> ang" This reverts commita178961a3e
. Revert "SW: Minor tweaks." This reverts commit377ba68344
. Revert "SW: Further refine turning and optimise horizon adjustment." This reverts commit039022d9ac
. Revert "SW: Don't process input at frame rate if ScrollMode2D is true." This reverts commit1aa1e62c4d
. Revert "SW: Use a bit more Q16.16 in places." This reverts commit40ca656f38
. Revert "SW: Use the old interpolation path in drawscreen if player is dead" This reverts commit2d73466425
. Revert "SW: Smooth out 180 degree turn landing and replace some fix16_min/max with fix16_clamp." This reverts commit0996e87f79
. Revert "Change Next/Previous Weapon button handling for Shadow Warrior." This reverts commitf6b8ca6a22
. Revert "SW: Make "Center_View" key return smoothly." This reverts commit23c401fbc2
. Revert "SW: Use the old interpolation path in drawscreen if player is dead" This reverts commit43ec16eb55
. Revert "Interpolation fixes for SW:" This reverts commitac8a7ecfbd
. Revert "SW: Reset the number of interpolations on level load" This reverts commit04bf8499e7
. Revert "Another change modifying saved game format in SW:" This reverts commite80888523e
. Revert "SW: Interpolate sector objects in non-demo, single player games." This reverts commit996ab77cf4
. Revert "- fixed merge errors in SW." This reverts commitb8cfa94568
. Revert "- fix interpolation stutters when opening console for SW." This reverts commit99fdbfb6cb
. Revert "- reset buttonMap button states after returning from pause for SW (stops keys acting stuck down if down prior to pausing)." This reverts commit693b6955da
. Revert "SW: fix stupid input scaling bug" This reverts commit1c79e6e17c
. Revert "SW: Make vehicle input better." This reverts commit670a53c402
. Revert "SW: Change fix16_from_float() to fix16_from_int() that was changed in4630c8a0b7
but should have been reverted in 377ba68344e34495638c6fa7685ff78c9a0ed6f8." This reverts commit423c9da071
. Revert "SW: Remove ScrollMode2D extern boolean and move into PLAYERp struct." This reverts commit31eb55c1fa
.
561 lines
12 KiB
C++
561 lines
12 KiB
C++
//-------------------------------------------------------------------------
|
|
/*
|
|
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
|
|
*/
|
|
//-------------------------------------------------------------------------
|
|
#include "ns.h"
|
|
#include "build.h"
|
|
|
|
#include "keys.h"
|
|
#include "game.h"
|
|
#include "tags.h"
|
|
#include "names2.h"
|
|
#include "network.h"
|
|
#include "menus.h"
|
|
|
|
BEGIN_SW_NS
|
|
|
|
SWBOOL SyncPrintMode = TRUE;
|
|
short NumSyncBytes = 1;
|
|
char sync_first[MAXSYNCBYTES][60];
|
|
int sync_found = FALSE;
|
|
|
|
static int crctable[256];
|
|
#define updatecrc(dcrc,xz) (dcrc = (crctable[((dcrc)>>8)^((xz)&255)]^((dcrc)<<8)))
|
|
|
|
void initsynccrc(void)
|
|
{
|
|
int i, j, k, a;
|
|
|
|
for (j=0; j<256; j++) //Calculate CRC table
|
|
{
|
|
k = (j<<8); a = 0;
|
|
for (i=7; i>=0; i--)
|
|
{
|
|
if (((k^a)&0x8000) > 0)
|
|
a = ((a<<1)&65535) ^ 0x1021; //0x1021 = genpoly
|
|
else
|
|
a = ((a<<1)&65535);
|
|
k = ((k<<1)&65535);
|
|
}
|
|
crctable[j] = (a&65535);
|
|
}
|
|
}
|
|
|
|
#if SYNC_TEST
|
|
uint8_t
|
|
PlayerSync(void)
|
|
{
|
|
short i;
|
|
unsigned short crc = 0;
|
|
PLAYERp pp;
|
|
|
|
for (i = connecthead; i >= 0; i = connectpoint2[i])
|
|
{
|
|
pp = Player + i;
|
|
updatecrc(crc, pp->posx & 255);
|
|
updatecrc(crc, pp->posy & 255);
|
|
updatecrc(crc, pp->posz & 255);
|
|
updatecrc(crc, pp->pang & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
uint8_t
|
|
PlayerSync2(void)
|
|
{
|
|
short i;
|
|
unsigned short crc = 0;
|
|
PLAYERp pp;
|
|
|
|
for (i = connecthead; i >= 0; i = connectpoint2[i])
|
|
{
|
|
pp = Player + i;
|
|
|
|
updatecrc(crc, pp->horiz & 255);
|
|
updatecrc(crc, User[pp->PlayerSprite]->Health & 255);
|
|
updatecrc(crc, pp->bcnt & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
uint8_t
|
|
SOSync(void)
|
|
{
|
|
unsigned short crc = 0;
|
|
SECTOR_OBJECTp sop;
|
|
|
|
for (sop = SectorObject; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++)
|
|
{
|
|
// if (sop->xmid == INT32_MAX)
|
|
// continue;
|
|
|
|
updatecrc(crc, (sop->xmid) & 255);
|
|
updatecrc(crc, (sop->ymid) & 255);
|
|
updatecrc(crc, (sop->zmid) & 255);
|
|
updatecrc(crc, (sop->vel) & 255);
|
|
updatecrc(crc, (sop->ang) & 255);
|
|
updatecrc(crc, (sop->ang_moving) & 255);
|
|
updatecrc(crc, (sop->spin_ang) & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
|
|
uint8_t
|
|
EnemySync(void)
|
|
{
|
|
unsigned short crc = 0;
|
|
short j, nextj;
|
|
SPRITEp spr;
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_ENEMY], j, nextj)
|
|
{
|
|
spr = &sprite[j];
|
|
updatecrc(crc, (spr->x) & 255);
|
|
updatecrc(crc, (spr->y) & 255);
|
|
updatecrc(crc, (spr->z) & 255);
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
}
|
|
|
|
#if 0
|
|
extern char DemoTmpName[];
|
|
//DSPRINTF(ds, "Demo Tmp Name %s", DemoTmpName);
|
|
MONO_PRINT(ds);
|
|
|
|
{
|
|
if (Once < 1 && DemoTmpName[0] != '\0')
|
|
{
|
|
FILE *fout;
|
|
|
|
Once++;
|
|
fout = fopen(DemoTmpName, "wb");
|
|
|
|
//DSPRINTF(ds, "Demo Tmp Name %s", DemoTmpName);
|
|
MONO_PRINT(ds);
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_ENEMY], j, nextj)
|
|
{
|
|
spr = &sprite[j];
|
|
|
|
fprintf(fout, "num %d, spr->x %d, spr->y %d, spr->z %d, spr->ang %d, spr->picnum %d\n", j, spr->x, spr->y, spr->z, spr->ang, spr->picnum);
|
|
}
|
|
fclose(fout);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
uint8_t
|
|
MissileSync(void)
|
|
{
|
|
unsigned short crc = 0;
|
|
short j, nextj;
|
|
SPRITEp spr;
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_MISSILE], j, nextj)
|
|
{
|
|
spr = &sprite[j];
|
|
updatecrc(crc, (spr->x) & 255);
|
|
updatecrc(crc, (spr->y) & 255);
|
|
updatecrc(crc, (spr->z) & 255);
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
uint8_t
|
|
MissileSkip4Sync(void)
|
|
{
|
|
unsigned short crc = 0;
|
|
short j, nextj;
|
|
SPRITEp spr;
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_MISSILE_SKIP4], j, nextj)
|
|
{
|
|
spr = &sprite[j];
|
|
updatecrc(crc, (spr->x) & 255);
|
|
updatecrc(crc, (spr->y) & 255);
|
|
updatecrc(crc, (spr->z) & 255);
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
uint8_t
|
|
ShrapSync(void)
|
|
{
|
|
unsigned short crc = 0;
|
|
short j, nextj;
|
|
SPRITEp spr;
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_SHRAP], j, nextj)
|
|
{
|
|
spr = &sprite[j];
|
|
updatecrc(crc, (spr->x) & 255);
|
|
updatecrc(crc, (spr->y) & 255);
|
|
updatecrc(crc, (spr->z) & 255);
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
uint8_t
|
|
MiscSync(void)
|
|
{
|
|
unsigned short crc = 0;
|
|
short j, nextj;
|
|
SPRITEp spr;
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_MISC], j, nextj)
|
|
{
|
|
spr = &sprite[j];
|
|
updatecrc(crc, (spr->x) & 255);
|
|
updatecrc(crc, (spr->y) & 255);
|
|
updatecrc(crc, (spr->z) & 255);
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
uint8_t
|
|
RandomSync(void)
|
|
{
|
|
unsigned short crc = 0;
|
|
|
|
updatecrc(crc, randomseed & 255);
|
|
updatecrc(crc, (randomseed >> 8) & 255);
|
|
|
|
if (NumSyncBytes == 1)
|
|
{
|
|
updatecrc(crc,PlayerSync() & 255);
|
|
updatecrc(crc,PlayerSync2() & 255);
|
|
updatecrc(crc,MissileSync() & 255);
|
|
}
|
|
|
|
return (uint8_t) crc & 255;
|
|
}
|
|
|
|
/*
|
|
#define STAT_SKIP2_START 2
|
|
#define STAT_ENEMY 2
|
|
#define STAT_DEAD_ACTOR 3 //misc actor stuff - dead guys etc
|
|
#define STAT_MISSILE 4
|
|
#define STAT_SKIP2_END 4
|
|
|
|
#define STAT_SKIP4_START 5
|
|
#define STAT_ITEM 5
|
|
#define STAT_SKIP4 6
|
|
#define STAT_MISSILE_SKIP4 7
|
|
#define STAT_ENEMY_SKIP4 8
|
|
#define STAT_SKIP4_END 8
|
|
*/
|
|
|
|
const char *SyncNames[] =
|
|
{
|
|
"RandomSync",
|
|
"PlayerSync",
|
|
"PlayerSync2",
|
|
"SOSync",
|
|
"EnemySync",
|
|
"MissileSync",
|
|
"ShrapSync",
|
|
"MiscSync",
|
|
"MissileSkip4Sync",
|
|
NULL
|
|
};
|
|
|
|
static uint8_t(*SyncFunc[MAXSYNCBYTES + 1]) (void) =
|
|
{
|
|
RandomSync,
|
|
PlayerSync,
|
|
PlayerSync2,
|
|
SOSync,
|
|
EnemySync,
|
|
MissileSync,
|
|
ShrapSync,
|
|
MiscSync,
|
|
MissileSkip4Sync,
|
|
NULL
|
|
};
|
|
|
|
void
|
|
getsyncstat(void)
|
|
{
|
|
int i;
|
|
PLAYERp pp = Player + myconnectindex;
|
|
unsigned int val;
|
|
static unsigned int count;
|
|
|
|
if (!CommEnabled)
|
|
return;
|
|
|
|
if (numplayers < 2)
|
|
return;
|
|
|
|
for (i = 0; SyncFunc[i]; i++)
|
|
{
|
|
pp->syncval[pp->syncvalhead & (SYNCFIFOSIZ - 1)][i] = (*SyncFunc[i])();
|
|
}
|
|
|
|
val = pp->syncval[pp->syncvalhead & (SYNCFIFOSIZ - 1)][0];
|
|
count += val;
|
|
|
|
pp->syncvalhead++;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Sync Message print
|
|
//
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
void
|
|
SyncStatMessage(void)
|
|
{
|
|
int i, j;
|
|
static unsigned int MoveCount = 0;
|
|
extern unsigned int MoveThingsCount;
|
|
|
|
if (!CommEnabled)
|
|
return;
|
|
|
|
if (!SyncPrintMode)
|
|
return;
|
|
|
|
if (numplayers <= 1)
|
|
return;
|
|
|
|
for (i = 0; i < NumSyncBytes; i++)
|
|
{
|
|
// syncstat is NON 0 - out of sync
|
|
if (syncstat[i] != 0)
|
|
{
|
|
if (NumSyncBytes > 1)
|
|
{
|
|
Printf(PRINT_NOTIFY, "GAME OUT OF SYNC - %s", SyncNames[i]);
|
|
}
|
|
|
|
if (!sync_found && sync_first[i][0] == '\0')
|
|
{
|
|
// sync_found one so test all of them and then never test again
|
|
sync_found = TRUE;
|
|
|
|
// save off loop count
|
|
MoveCount = MoveThingsCount;
|
|
|
|
for (j = 0; j < NumSyncBytes; j++)
|
|
{
|
|
if (syncstat[j] != 0 && sync_first[j][0] == '\0')
|
|
{
|
|
sprintf(ds, "OUT OF SYNC - %s", SyncNames[j]);
|
|
strcpy(sync_first[j], ds);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// print out the sync_first message you got
|
|
for (i = 0; i < NumSyncBytes; i++)
|
|
{
|
|
if (sync_first[i][0] != '\0')
|
|
{
|
|
if (NumSyncBytes > 1)
|
|
{
|
|
Printf(PRINT_NOTIFY, "FIRST %s\n", sync_first[i]);
|
|
Printf(PRINT_NOTIFY, "MoveCount %u\n",MoveCount);
|
|
}
|
|
else
|
|
{
|
|
short w,h;
|
|
// production out of sync error
|
|
|
|
sprintf(ds,"GAME OUT OF SYNC!");
|
|
MNU_MeasureString(ds, &w, &h);
|
|
MNU_DrawString(TEXT_TEST_COL(w), 20, ds, 0, 19);
|
|
|
|
sprintf(ds,"Restart the game.");
|
|
MNU_MeasureString(ds, &w, &h);
|
|
MNU_DrawString(TEXT_TEST_COL(w), 30, ds, 0, 19);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
GetSyncInfoFromPacket(uint8_t *packbuf, int packbufleng, int *j, int otherconnectindex)
|
|
{
|
|
int sb, i;
|
|
extern int syncvaltottail;
|
|
PLAYERp ppo = &Player[otherconnectindex];
|
|
SWBOOL found = FALSE;
|
|
|
|
// have had problems with this routine crashing when players quit
|
|
// games.
|
|
|
|
// if ready2send is not set then don't try to get sync info
|
|
|
|
if (!ready2send)
|
|
return;
|
|
|
|
// Suspect that its trying to traverse the connect list
|
|
// for a player that does not exist. This tries to take care of that
|
|
|
|
TRAVERSE_CONNECT(i)
|
|
{
|
|
if (otherconnectindex == i)
|
|
found = TRUE;
|
|
}
|
|
|
|
if (!found)
|
|
return;
|
|
|
|
// sync testing
|
|
//while ((*j) != packbufleng) // changed this on Kens suggestion
|
|
while ((*j) < packbufleng)
|
|
{
|
|
for (sb = 0; sb < NumSyncBytes; sb++)
|
|
{
|
|
ppo->syncval[ppo->syncvalhead & (SYNCFIFOSIZ - 1)][sb] = packbuf[(*j)++];
|
|
}
|
|
ppo->syncvalhead++;
|
|
}
|
|
|
|
// update syncstat
|
|
// if any of the syncstat vars is non-0 then there is a problem
|
|
TRAVERSE_CONNECT(i)
|
|
{
|
|
if (Player[i].syncvalhead == syncvaltottail)
|
|
return;
|
|
}
|
|
|
|
//for (sb = 0; sb < NumSyncBytes; sb++)
|
|
// syncstat[sb] = 0;
|
|
|
|
while (TRUE)
|
|
{
|
|
for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i])
|
|
{
|
|
for (sb = 0; sb < NumSyncBytes; sb++)
|
|
{
|
|
if (Player[i].syncval[syncvaltottail & (SYNCFIFOSIZ - 1)][sb] != Player[connecthead].syncval[syncvaltottail & (SYNCFIFOSIZ - 1)][sb])
|
|
{
|
|
syncstat[sb] = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
syncvaltottail++;
|
|
|
|
TRAVERSE_CONNECT(i)
|
|
{
|
|
if (Player[i].syncvalhead == syncvaltottail)
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Demo Sync recording and testing
|
|
//
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
extern FILE *DemoSyncFile;
|
|
|
|
void
|
|
demosync_record(void)
|
|
{
|
|
int i;
|
|
uint8_t sync_val;
|
|
|
|
for (i = 0; SyncFunc[i]; i++)
|
|
{
|
|
sync_val = (*SyncFunc[i])();
|
|
fwrite(&sync_val, sizeof(sync_val), 1, DemoSyncFile);
|
|
}
|
|
}
|
|
|
|
void
|
|
demosync_test(int cnt)
|
|
{
|
|
int i;
|
|
uint8_t sync_val;
|
|
|
|
for (i = 0; SyncFunc[i]; i++)
|
|
{
|
|
fread(&sync_val, sizeof(sync_val), 1, DemoSyncFile);
|
|
|
|
if (sync_val != (*SyncFunc[i])())
|
|
{
|
|
TerminateLevel();
|
|
I_Error("Demo out of sync - Sync Byte Number %d - Iteration %d.", i, cnt);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
getsyncbyte()
|
|
{
|
|
int i, j;
|
|
char ch;
|
|
SPRITEp spr;
|
|
PLAYERp pp;
|
|
USERp u;
|
|
|
|
ch = (char) (randomseed & 255);
|
|
|
|
for (i = connecthead; i >= 0; i = connectpoint2[i])
|
|
{
|
|
pp = Player + i;
|
|
u = User[pp->SpriteP - sprite];
|
|
ch ^= (pp->posx ^ pp->posy ^ pp->posz ^ pp->pang ^ pp->horiz ^ u->Health);
|
|
}
|
|
|
|
for (j = headspritestat[STAT_ENEMY]; j >= 0; j = nextspritestat[j])
|
|
{
|
|
spr = &sprite[j];
|
|
ch ^= spr->x ^ spr->y ^ spr->z ^ spr->ang;
|
|
}
|
|
|
|
return (ch);
|
|
}
|
|
*/
|
|
#endif
|
|
|
|
END_SW_NS
|