2020-06-30 18:59:24 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 1996, 2003 - 3D Realms Entertainment
|
|
|
|
Copyright (C) 2020 - Christoph Oelckers
|
|
|
|
|
|
|
|
This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
|
|
|
|
|
|
|
|
Duke Nukem 3D 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
|
|
|
|
aint with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
Original Source: 1996 - Todd Replogle
|
|
|
|
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
|
|
|
|
Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2020-07-18 21:50:46 +00:00
|
|
|
#include "gamestate.h"
|
2020-06-30 18:59:24 +00:00
|
|
|
#include "duke3d.h"
|
2020-07-06 01:00:52 +00:00
|
|
|
#include "sbar.h"
|
2020-06-30 18:59:24 +00:00
|
|
|
#include "m_argv.h"
|
|
|
|
#include "mapinfo.h"
|
|
|
|
#include "texturemanager.h"
|
2020-08-28 07:06:49 +00:00
|
|
|
#include "glbackend/glbackend.h"
|
2020-06-30 18:59:24 +00:00
|
|
|
|
|
|
|
BEGIN_DUKE_NS
|
|
|
|
|
2020-07-06 06:55:56 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-07-06 08:34:31 +00:00
|
|
|
// abstract the queue's implementation
|
|
|
|
// All access to the input queues should go through this function interface.
|
2020-07-06 06:55:56 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2020-08-26 15:12:48 +00:00
|
|
|
static InputPacket inputfifo[MOVEFIFOSIZ][MAXPLAYERS];
|
2020-07-06 08:34:31 +00:00
|
|
|
static int movefifoend[MAXPLAYERS];
|
|
|
|
static int movefifoplc;
|
2020-07-06 09:39:39 +00:00
|
|
|
static int bufferjitter;
|
2020-07-06 08:34:31 +00:00
|
|
|
|
|
|
|
void clearfifo(void)
|
2020-07-06 06:55:56 +00:00
|
|
|
{
|
2020-07-06 08:34:31 +00:00
|
|
|
memset(&inputfifo, 0, sizeof(inputfifo));
|
2020-07-15 11:10:18 +00:00
|
|
|
memset(sync, 0, sizeof(sync));
|
2020-07-06 06:55:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 08:34:31 +00:00
|
|
|
|
|
|
|
static inline void GetNextInput()
|
|
|
|
{
|
|
|
|
for (int i = connecthead; i >= 0; i = connectpoint2[i])
|
2020-08-26 15:12:48 +00:00
|
|
|
memcpy(&sync[i], &inputfifo[movefifoplc & (MOVEFIFOSIZ - 1)][i], sizeof(InputPacket));
|
2020-07-06 08:34:31 +00:00
|
|
|
|
|
|
|
movefifoplc++;
|
|
|
|
}
|
|
|
|
|
2020-07-18 09:56:49 +00:00
|
|
|
static void advancequeue(int myconnectindex)
|
2020-07-06 08:34:31 +00:00
|
|
|
{
|
|
|
|
movefifoend[myconnectindex]++;
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:12:48 +00:00
|
|
|
static InputPacket& nextinput(int myconnectindex)
|
2020-07-06 08:34:31 +00:00
|
|
|
{
|
|
|
|
return inputfifo[movefifoend[myconnectindex] & (MOVEFIFOSIZ - 1)][myconnectindex];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldprocessinput(int myconnectindex)
|
|
|
|
{
|
|
|
|
if (movefifoend[myconnectindex] - movefifoplc > bufferjitter)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = connecthead; i >= 0; i = connectpoint2[i])
|
|
|
|
if (movefifoplc == movefifoend[i]) return false;
|
|
|
|
if (i >= 0) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-06 06:55:56 +00:00
|
|
|
|
2020-06-30 18:59:24 +00:00
|
|
|
static void fakedomovethings()
|
|
|
|
{
|
|
|
|
// prediction
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fakedomovethingscorrect()
|
|
|
|
{
|
|
|
|
// unprediction
|
|
|
|
}
|
|
|
|
|
2020-07-06 08:34:31 +00:00
|
|
|
void prediction()
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
// We currently have no net code driving this.
|
|
|
|
if (numplayers > 1)
|
|
|
|
while (fakemovefifoplc < movefifoend[myconnectindex]) fakedomovethings();
|
|
|
|
getpackets();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-06-30 18:59:24 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2020-07-06 01:00:52 +00:00
|
|
|
/*
|
|
|
|
void mploadsave()
|
2020-06-30 18:59:24 +00:00
|
|
|
{
|
2020-07-06 01:00:52 +00:00
|
|
|
for(int i=connecthead;i>=0;i=connectpoint2[i])
|
|
|
|
if( sync[i].bits&(1<<17) )
|
|
|
|
{
|
|
|
|
multiflag = 2;
|
|
|
|
multiwhat = (sync[i].bits>>18)&1;
|
|
|
|
multipos = (unsigned) (sync[i].bits>>19)&15;
|
|
|
|
multiwho = i;
|
|
|
|
|
|
|
|
if( multiwhat )
|
|
|
|
{
|
|
|
|
saveplayer( multipos );
|
|
|
|
multiflag = 0;
|
|
|
|
|
|
|
|
if(multiwho != myconnectindex)
|
|
|
|
{
|
|
|
|
strcpy(&fta_quotes[122],&ud.user_name[multiwho][0]);
|
|
|
|
strcat(&fta_quotes[122]," SAVED A MULTIPLAYER GAME");
|
|
|
|
FTA(122,&ps[myconnectindex]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(&fta_quotes[122],"MULTIPLAYER GAME SAVED");
|
|
|
|
FTA(122,&ps[myconnectindex]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// waitforeverybody();
|
|
|
|
|
|
|
|
j = loadplayer( multipos );
|
|
|
|
|
|
|
|
multiflag = 0;
|
|
|
|
|
2020-07-06 11:26:26 +00:00
|
|
|
if(j == 0 && !isRR())
|
2020-07-06 01:00:52 +00:00
|
|
|
{
|
|
|
|
if(multiwho != myconnectindex)
|
|
|
|
{
|
|
|
|
strcpy(&fta_quotes[122],&ud.user_name[multiwho][0]);
|
|
|
|
strcat(&fta_quotes[122]," LOADED A MULTIPLAYER GAME");
|
|
|
|
FTA(122,&ps[myconnectindex]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(&fta_quotes[122],"MULTIPLAYER GAME LOADED");
|
|
|
|
FTA(122,&ps[myconnectindex]);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-30 18:59:24 +00:00
|
|
|
}
|
2020-07-06 01:00:52 +00:00
|
|
|
*/
|
2020-06-30 18:59:24 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int domovethings()
|
|
|
|
{
|
2020-08-28 20:51:05 +00:00
|
|
|
int i;
|
2020-06-30 18:59:24 +00:00
|
|
|
|
|
|
|
// mplpadsave();
|
|
|
|
|
2020-07-06 01:00:52 +00:00
|
|
|
ud.camerasprite = -1;
|
|
|
|
|
|
|
|
if (earthquaketime > 0) earthquaketime--;
|
|
|
|
if (rtsplaying > 0) rtsplaying--;
|
|
|
|
|
|
|
|
if (show_shareware > 0)
|
|
|
|
{
|
|
|
|
show_shareware--;
|
|
|
|
}
|
|
|
|
|
|
|
|
everyothertime++;
|
|
|
|
GetNextInput();
|
|
|
|
updateinterpolations();
|
|
|
|
|
2020-08-27 22:03:35 +00:00
|
|
|
#if 0
|
2020-07-06 01:00:52 +00:00
|
|
|
j = -1;
|
|
|
|
for (i = connecthead; i >= 0; i = connectpoint2[i])
|
|
|
|
{
|
2020-07-06 11:26:26 +00:00
|
|
|
if (PlayerInput(i, SKB_GAMEQUIT))
|
2020-07-06 01:00:52 +00:00
|
|
|
{
|
|
|
|
if (i == myconnectindex) gameexitfrommenu();
|
|
|
|
if (screenpeek == i)
|
|
|
|
{
|
|
|
|
screenpeek = connectpoint2[i];
|
|
|
|
if (screenpeek < 0) screenpeek = connecthead;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == connecthead) connecthead = connectpoint2[connecthead];
|
|
|
|
else connectpoint2[j] = connectpoint2[i];
|
|
|
|
|
|
|
|
numplayers--;
|
|
|
|
ud.multimode--;
|
|
|
|
|
|
|
|
//closedemowrite();
|
|
|
|
|
|
|
|
if (numplayers < 2 && !isRR())
|
|
|
|
S_PlaySound(GENERIC_AMBIENCE17, CHAN_AUTO, CHANF_UI);
|
|
|
|
|
2020-07-15 16:10:31 +00:00
|
|
|
Printf(PRINT_NOTIFY, "%s is history!", ud.user_name[i]);
|
2020-07-06 01:00:52 +00:00
|
|
|
|
|
|
|
quickkill(&ps[i]);
|
|
|
|
deletesprite(ps[i].i);
|
|
|
|
}
|
|
|
|
else j = i;
|
|
|
|
}
|
2020-08-27 22:03:35 +00:00
|
|
|
#endif
|
2020-07-06 01:00:52 +00:00
|
|
|
|
|
|
|
//if(ud.recstat == 1) record();
|
|
|
|
|
2020-07-21 20:46:26 +00:00
|
|
|
if (playrunning())
|
2020-07-06 01:00:52 +00:00
|
|
|
{
|
|
|
|
global_random = krand();
|
|
|
|
movedummyplayers();//ST 13
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = connecthead; i >= 0; i = connectpoint2[i])
|
|
|
|
{
|
2020-07-21 20:46:26 +00:00
|
|
|
if (playrunning())
|
2020-07-06 01:00:52 +00:00
|
|
|
{
|
|
|
|
auto p = &ps[i];
|
2020-07-06 19:57:38 +00:00
|
|
|
if (p->pals.a > 0)
|
|
|
|
p->pals.a--;
|
2020-07-06 01:00:52 +00:00
|
|
|
|
2020-07-17 19:09:07 +00:00
|
|
|
hud_input(i);
|
2020-07-06 01:00:52 +00:00
|
|
|
fi.processinput(i);
|
|
|
|
fi.checksectors(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 20:46:26 +00:00
|
|
|
if (playrunning())
|
2020-07-06 01:00:52 +00:00
|
|
|
{
|
|
|
|
if (levelTextTime > 0)
|
|
|
|
levelTextTime--;
|
2020-06-30 18:59:24 +00:00
|
|
|
|
|
|
|
fi.think();
|
2020-07-06 01:00:52 +00:00
|
|
|
}
|
2020-06-30 18:59:24 +00:00
|
|
|
|
2020-07-06 01:00:52 +00:00
|
|
|
fakedomovethingscorrect();
|
2020-06-30 18:59:24 +00:00
|
|
|
|
2020-07-06 01:00:52 +00:00
|
|
|
if ((everyothertime & 1) == 0)
|
|
|
|
{
|
|
|
|
fi.animatewalls();
|
|
|
|
movecyclers();
|
|
|
|
}
|
2020-06-30 18:59:24 +00:00
|
|
|
|
2020-07-06 01:00:52 +00:00
|
|
|
if (isRR() && ud.recstat == 0 && ud.multimode < 2)
|
|
|
|
dotorch();
|
2020-06-30 18:59:24 +00:00
|
|
|
|
2020-07-06 01:00:52 +00:00
|
|
|
return 0;
|
2020-06-30 18:59:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 01:00:52 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-08-29 19:20:10 +00:00
|
|
|
void GameTicker()
|
2020-07-18 09:56:49 +00:00
|
|
|
{
|
|
|
|
if (ps[myconnectindex].gm == MODE_DEMO)
|
|
|
|
{
|
|
|
|
M_ClearMenus();
|
2020-08-29 19:20:10 +00:00
|
|
|
gamestate = GS_STARTUP;
|
|
|
|
return;
|
2020-07-18 09:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Net_GetPackets();
|
|
|
|
|
2020-08-09 06:39:15 +00:00
|
|
|
|
2020-07-18 09:56:49 +00:00
|
|
|
gameupdatetime.Reset();
|
|
|
|
gameupdatetime.Clock();
|
|
|
|
|
2020-08-25 06:47:50 +00:00
|
|
|
int const currentTic = I_GetTime();
|
2020-08-30 06:04:33 +00:00
|
|
|
gameclock = I_GetBuildTime() - gameclockstart;
|
2020-08-25 05:06:29 +00:00
|
|
|
|
2020-08-28 05:29:41 +00:00
|
|
|
while (playrunning() && currentTic - lastTic >= 1)
|
2020-07-18 09:56:49 +00:00
|
|
|
{
|
2020-08-25 05:06:29 +00:00
|
|
|
lastTic = currentTic;
|
2020-07-18 09:56:49 +00:00
|
|
|
auto& input = nextinput(myconnectindex);
|
|
|
|
|
2020-08-29 19:20:10 +00:00
|
|
|
gi->GetInput(&input);
|
2020-07-18 09:56:49 +00:00
|
|
|
|
|
|
|
advancequeue(myconnectindex);
|
|
|
|
|
2020-07-21 20:46:26 +00:00
|
|
|
if (playrunning())
|
2020-07-18 09:56:49 +00:00
|
|
|
{
|
2020-08-29 19:20:10 +00:00
|
|
|
prediction();
|
|
|
|
|
|
|
|
if (numplayers < 2) bufferjitter = 0;
|
|
|
|
while (shouldprocessinput(myconnectindex))
|
|
|
|
{
|
|
|
|
if (domovethings()) break;
|
|
|
|
}
|
2020-07-18 09:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-25 06:47:50 +00:00
|
|
|
|
2020-07-18 09:56:49 +00:00
|
|
|
gameupdatetime.Unclock();
|
|
|
|
|
|
|
|
if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART))
|
|
|
|
{
|
2020-07-18 22:53:13 +00:00
|
|
|
exitlevel();
|
2020-07-18 09:56:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 12:12:09 +00:00
|
|
|
if (!cl_syncinput)
|
|
|
|
{
|
2020-08-29 19:20:10 +00:00
|
|
|
gi->GetInput(nullptr);
|
2020-07-28 12:12:09 +00:00
|
|
|
}
|
2020-07-18 09:56:49 +00:00
|
|
|
|
2020-08-29 19:20:10 +00:00
|
|
|
nonsharedkeys();
|
2020-08-29 22:55:49 +00:00
|
|
|
gi->UpdateSounds();
|
2020-07-18 09:56:49 +00:00
|
|
|
drawtime.Reset();
|
|
|
|
drawtime.Clock();
|
2020-08-29 19:20:10 +00:00
|
|
|
videoSetBrightness(thunder_brightness);
|
|
|
|
double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
|
2020-07-18 09:56:49 +00:00
|
|
|
displayrooms(screenpeek, smoothRatio);
|
2020-08-29 19:20:10 +00:00
|
|
|
drawoverlays(smoothRatio);
|
2020-07-18 09:56:49 +00:00
|
|
|
drawtime.Unclock();
|
|
|
|
|
2020-08-29 19:20:10 +00:00
|
|
|
if (ps[myconnectindex].gm == MODE_DEMO)
|
|
|
|
{
|
|
|
|
gamestate = GS_STARTUP;
|
|
|
|
}
|
2020-07-18 09:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-07-18 21:50:46 +00:00
|
|
|
void startmainmenu()
|
|
|
|
{
|
2020-08-10 22:46:27 +00:00
|
|
|
gamestate = GS_MENUSCREEN;
|
2020-07-18 21:50:46 +00:00
|
|
|
M_StartControlPanel(false);
|
|
|
|
M_SetMenu(NAME_Mainmenu);
|
|
|
|
FX_StopAllSounds();
|
|
|
|
}
|
|
|
|
|
2020-08-30 05:53:20 +00:00
|
|
|
void resetGameClock()
|
|
|
|
{
|
2020-08-30 06:04:33 +00:00
|
|
|
I_SetFrameTime();
|
2020-08-30 06:13:34 +00:00
|
|
|
gameclockstart = I_GetBuildTime();
|
2020-08-30 05:53:20 +00:00
|
|
|
gameclock = 0;
|
|
|
|
cloudclock = 0;
|
|
|
|
}
|
2020-07-18 21:50:46 +00:00
|
|
|
|
2020-08-29 19:20:10 +00:00
|
|
|
static void Startup()
|
2020-07-18 09:56:49 +00:00
|
|
|
{
|
2020-08-30 05:53:20 +00:00
|
|
|
resetGameClock();
|
2020-08-23 15:47:05 +00:00
|
|
|
ps[myconnectindex].ftq = 0;
|
|
|
|
|
|
|
|
if (userConfig.CommandMap.IsNotEmpty())
|
2020-07-18 21:50:46 +00:00
|
|
|
{
|
2020-08-23 15:47:05 +00:00
|
|
|
auto maprecord = FindMapByName(userConfig.CommandMap);
|
|
|
|
userConfig.CommandMap = "";
|
|
|
|
if (maprecord)
|
2020-07-21 22:42:50 +00:00
|
|
|
{
|
2020-08-23 15:47:05 +00:00
|
|
|
ud.m_respawn_monsters = ud.m_player_skill == 4;
|
2020-07-18 09:56:49 +00:00
|
|
|
|
2020-08-23 15:47:05 +00:00
|
|
|
for (int i = 0; i != -1; i = connectpoint2[i])
|
2020-07-18 09:56:49 +00:00
|
|
|
{
|
2020-08-23 15:47:05 +00:00
|
|
|
resetweapons(i);
|
|
|
|
resetinventory(i);
|
2020-07-18 09:56:49 +00:00
|
|
|
}
|
2020-08-23 15:47:05 +00:00
|
|
|
startnewgame(maprecord, /*userConfig.skill*/2);
|
2020-07-21 22:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-23 15:47:05 +00:00
|
|
|
else
|
2020-07-21 22:42:50 +00:00
|
|
|
{
|
2020-08-23 15:47:05 +00:00
|
|
|
fi.ShowLogo([](bool) { startmainmenu(); });
|
2020-07-18 21:50:46 +00:00
|
|
|
}
|
2020-08-29 19:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GameInterface::RunGameFrame()
|
|
|
|
{
|
|
|
|
switch (gamestate)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case GS_STARTUP:
|
|
|
|
Startup();
|
2020-08-23 15:47:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GS_MENUSCREEN:
|
|
|
|
case GS_FULLCONSOLE:
|
|
|
|
drawbackground();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GS_LEVEL:
|
2020-08-29 19:20:10 +00:00
|
|
|
GameTicker();
|
2020-08-23 15:47:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GS_INTERMISSION:
|
|
|
|
case GS_INTRO:
|
2020-08-29 19:20:10 +00:00
|
|
|
RunScreenJobFrame();
|
2020-08-23 15:47:05 +00:00
|
|
|
break;
|
|
|
|
|
2020-07-18 09:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-30 18:59:24 +00:00
|
|
|
END_DUKE_NS
|
|
|
|
|