- everything compiles again.

Still needs testing.
This commit is contained in:
Christoph Oelckers 2020-07-07 20:27:21 +02:00
parent 915b566612
commit 01fce31f43
21 changed files with 511 additions and 447 deletions

View file

@ -34,6 +34,7 @@
*/
#include "mapinfo.h"
#include "raze_music.h"
MapRecord mapList[512]; // Due to how this gets used it needs to be static. EDuke defines 7 episode plus one spare episode with 64 potential levels each and relies on the static array which is freely accessible by scripts.
MapRecord *currentLevel; // level that is currently played. (The real level, not what script hacks modfifying the current level index can pretend.)
@ -70,11 +71,11 @@ MapRecord *FindMapByLevelNum(int num)
MapRecord *FindNextMap(MapRecord *thismap)
{
if (thismap->nextLevel != -1) return mapList[thismap->nextlevel];
if (thismap->nextLevel != -1) return &mapList[thismap->nextLevel];
return FindMapByLevelNum(thismap->levelNumber+1);
}
bool SetMusicForMap(const char* mapname, const char* music, bool namehack = false)
bool SetMusicForMap(const char* mapname, const char* music, bool namehack)
{
static const char* specials[] = { "intro", "briefing", "loading" };
for (int i = 0; i < 3; i++)
@ -86,10 +87,10 @@ bool SetMusicForMap(const char* mapname, const char* music, bool namehack = fals
}
}
int index = FindMapByName(mapname);
auto index = FindMapByName(mapname);
// This is for the DEFS parser's MUSIC command which never bothered to check for the real map name.
if (index < 0 && namehack)
if (index == nullptr && namehack)
{
int lev, ep;
signed char b1, b2;
@ -102,21 +103,21 @@ bool SetMusicForMap(const char* mapname, const char* music, bool namehack = fals
index = FindMapByLevelNum(ep*100 + lev);
}
if (index >= 0)
if (index != nullptr)
{
mapList[index].music = music;
index->music = music;
return true;
}
return false;
}
MapRecord *AlloocateMap()
MapRecord *AllocateMap()
{
return &mapList[numUsedSlots++];
}
MapRecord* SetupUserMap(const char* boardfilename)
MapRecord* SetupUserMap(const char* boardfilename, const char *defaultmusic)
{
for (unsigned i = 0; i < numUsedSlots; i++)
{
@ -126,11 +127,11 @@ MapRecord* SetupUserMap(const char* boardfilename)
return &map;
}
}
auto map = AllocateMap()
auto map = AllocateMap();
map->name = "";
map->SetFileName(boardfilename);
map->flags = MI_USERMAP|MI_FORCEEOG;
map->music = G_SetupFilenameBasedMusic(boardfilename, !isRR() ? "dethtoll.mid" : nullptr);
map->music = G_SetupFilenameBasedMusic(boardfilename, defaultmusic);
return map;
}

View file

@ -78,6 +78,8 @@ void InitRREndMap();
MapRecord *FindMapByName(const char *nm);
MapRecord *FindMapByLevelNum(int num);
MapRecord *FindNextMap(MapRecord *thismap);
MapRecord* SetupUserMap(const char* boardfilename, const char *defaultmusic = nullptr);
MapRecord* AllocateMap();
enum
{

View file

@ -305,13 +305,14 @@ int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu)
}
int savever;
FString engine, gamegrp, mapgrp, title, filename;
FString engine, gamegrp, mapgrp, title, filename, label;
arc("Save Version", savever)
("Engine", engine)
("Game Resource", gamegrp)
("Map Resource", mapgrp)
("Title", title)
("Nap Label", label)
("Map File", filename);
auto savesig = gi->GetSaveSig();
@ -324,25 +325,16 @@ int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu)
return 0;
}
MapRecord *curLevel = nullptr;
MapRecord *curLevel = FindMapByName(label);
if (strncmp(filename, "file://", 7) != 0)
// If the map does not exist, check if it's a user map.
if (!curLevel)
{
for (auto& mr : mapList)
{
if (mr.fileName.Compare(filename) == 0)
{
curLevel = &mr;
}
}
}
else
{
curLevel = &userMapRecord;
curLevel = AllocateMap();
if (!formenu)
{
userMapRecord.name = "";
userMapRecord.SetFileName(filename);
curLevel->name = "";
curLevel->SetFileName(filename);
}
}
if (!curLevel) return 0;

View file

@ -1744,7 +1744,6 @@ int G_EnterLevel(int gameMode)
auto &p0 = *g_player[0].ps;
int16_t playerAngle;
char levelName[BMAX_PATH];
NET_75_CHECK++; // a major problem with how STAT_NETALLOC works, is that loadboard loads sprites directly into the arrays and does not take from
// STAT_NETALLOC, even though the loaded sprites are very, very likely to be relevant to the netcode.

View file

@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_EDUKE_NS
extern MapRecord userMapRecord;
class DukeSoundEngine : public SoundEngine
{

View file

@ -600,7 +600,6 @@ void dobonus_r(bool bonusonly, CompletionFunc completion)
class DRRLoadScreen : public DScreenJob
{
std::function<int(void)> callback;
std::function<int(void)> callback;
MapRecord* rec;

View file

@ -2139,7 +2139,7 @@ static void rrra_specialstats()
{
ps[screenpeek].gm = MODE_EOL;
ud.eog = 1;
ud.nextLevel = FindNextMap(currentLevel);
ud.nextLevel = nullptr;
}
}

View file

@ -43,7 +43,7 @@ bool cheatStuff(cheatseq_t* s);
bool cheatKeys(cheatseq_t* s);
bool cheatInventory(cheatseq_t* s);
static void dowarp(int volume, int level)
static void dowarp(MapRecord *map)
{
ud.m_monsters_off = ud.monsters_off = 0;
@ -54,10 +54,10 @@ static void dowarp(int volume, int level)
if (ps[myconnectindex].gm & MODE_GAME)
{
G_NewGame(volume, level, ud.m_player_skill);
G_NewGame(map, ud.m_player_skill);
ps[myconnectindex].gm = MODE_RESTART;
}
else G_NewGame_EnterLevel(volume, level, ud.m_player_skill);
else G_NewGame_EnterLevel(map, ud.m_player_skill);
}
static int ccmd_levelwarp(CCmdFuncPtr parm)
@ -71,7 +71,13 @@ static int ccmd_levelwarp(CCmdFuncPtr parm)
Printf(TEXTCOLOR_RED "Invalid level!: E%sL%s\n", parm->parms[0], parm->parms[1]);
return CCMD_OK;
}
dowarp(e - 1, m - 1);
auto map = FindMapByLevelNum(levelnum(e - 1, m - 1));
if (!map)
{
Printf(TEXTCOLOR_RED "Level not found!: E%sL%s\n", parm->parms[0], parm->parms[1]);
return CCMD_OK;
}
dowarp(map);
return CCMD_OK;
}
@ -89,36 +95,26 @@ static int ccmd_map(CCmdFuncPtr parm)
Printf(TEXTCOLOR_RED "map: file \"%s\" not found.\n", mapname.GetChars());
return CCMD_OK;
}
int volume, level;
// Check if the map is already defined.
for (int i = 0; i < 512; i++)
auto map = FindMapByName(mapname);
if (map == nullptr)
{
if (mapList[i].labelName.CompareNoCase(mapname) == 0)
{
volume = i / MAXLEVELS;
level = i % MAXLEVELS;
goto foundone;
}
}
// got a user map
if (VOLUMEONE)
{
Printf(TEXTCOLOR_RED "Cannot use user maps in shareware.\n");
return CCMD_OK;
}
// Treat as user map if not found in the list of regular maps.
boardfilename[0] = '/';
boardfilename[1] = 0;
volume = 0;
level = 7;
DefaultExtension(mapname, ".map");
strcat(boardfilename, mapname);
foundone:
if (mapname[0] != '/') mapname.Insert(0, "/");
map = SetupUserMap(mapname, !isRR() ? "dethtoll.mid" : nullptr);
}
if (numplayers > 1)
{
return CCMD_OK;
}
dowarp(volume, level);
dowarp(map);
return CCMD_OK;
}

View file

@ -179,8 +179,10 @@ static bool cheatLevel(cheatseq_t *s)
levnume = (s->Args[1] - '0')*10+(s->Args[2]-'0') - 1;
// Instead of hard coded range checks on volume and level, let's just check if the level is defined.
if (mapList[volnume*MAXLEVELS + levnume].fileName.IsNotEmpty())
auto map = FindMapByLevelNum(levelnum(volnume, levnume));
if (map)
{
ud.nextLevel = map;
FX_StopAllSounds();
FX_SetReverb(0);
ps[myconnectindex].gm |= MODE_RESTART;

View file

@ -40,6 +40,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
#include "gstrings.h"
#include "version.h"
#include "names.h"
#include "mapinfo.h"
#include "../../glbackend/glbackend.h"
@ -317,7 +318,11 @@ void GameInterface::StartGame(FNewGameStartup& gs)
ud.m_respawn_items = 0;
ud.m_respawn_inventory = 0;
ud.multimode = 1;
G_NewGame_EnterLevel(gs.Episode, gs.Level, ud.m_player_skill);
auto map = FindMapByLevelNum(levelnum(gs.Episode, gs.Level));
if (map)
{
G_NewGame_EnterLevel(map, ud.m_player_skill);
}
}

View file

@ -220,5 +220,6 @@ void prelevel_d(int g);
void prelevel_r(int g);
void e4intro(CompletionFunc completion);
void clearfrags(void);
int exitlevel();
END_DUKE_NS

View file

@ -45,8 +45,6 @@ extern int rtsplaying;
#ifndef ONLY_USERDEFS
extern char boardfilename[BMAX_PATH];
#define USERMAPMUSICFAKEVOLUME MAXVOLUMES
#define USERMAPMUSICFAKELEVEL (MAXLEVELS-1)
extern int32_t g_Shareware;
extern int32_t cameraclock;
@ -90,11 +88,11 @@ static inline int32_t calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk
}
static inline void G_NewGame_EnterLevel(int volume, int level, int skill)
static inline void G_NewGame_EnterLevel(MapRecord *map, int skill)
{
G_NewGame(volume, level, skill);
G_NewGame(map, skill);
if (G_EnterLevel(MODE_GAME))
if (enterlevel(map, MODE_GAME))
G_BackToMenu();
}

View file

@ -42,6 +42,7 @@ into many sub-files.
#include "menu.h"
#include "global.h"
#include "m_argv.h"
#include "sounds.h"
BEGIN_DUKE_NS
@ -63,6 +64,16 @@ extern int* labelcode;
TArray<int> ScriptCode;
struct TempMusic
{
int levnum;
FString music;
};
// This is for situations where the music gets defined before the map. Since the map records do not exist yet, we need a temporary buffer.
static TArray<TempMusic> tempMusic;
//---------------------------------------------------------------------------
//
// synthesize the instruction list
@ -752,11 +763,8 @@ int parsecommand()
popscriptvalue();
transnum(); // Volume Number (0/4)
k = popscriptvalue() - 1;
if (k < 0) specialmusic.Clear();
if (k == -1) k = MAXVOLUMES;
if (k >= 0) // if it's background music
{
i = 0;
// get the file name...
while (keyword() == -1)
@ -775,12 +783,20 @@ int parsecommand()
j++;
}
parsebuffer.Push(0);
mapList[(MAXLEVELS * k) + i].music = parsebuffer.Data();
if (k >= 0)
{
tempMusic.Reserve(1);
tempMusic.Last().levnum = levelnum(k, i);
tempMusic.Last().music = parsebuffer.Data();
textptr += j;
if (i > MAXLEVELS) break;
}
else
{
specialmusic.Push(parsebuffer.Data());
}
i++;
}
}
return 0;
}
case concmd_include:
@ -1395,6 +1411,7 @@ int parsecommand()
return 0;
case concmd_definelevelname:
{
popscriptvalue();
transnum();
j = popscriptvalue();
@ -1410,22 +1427,25 @@ int parsecommand()
textptr++, i++;
}
parsebuffer.Push(0);
mapList[j * MAXLEVELS + k].SetFileName(parsebuffer.Data());
auto levnum = levelnum(j, k);
auto map = FindMapByLevelNum(levnum);
if (!map) map = AllocateMap();
map->SetFileName(parsebuffer.Data());
while (*textptr == ' ') textptr++;
mapList[j * MAXLEVELS + k].parTime =
map->parTime =
(((*(textptr + 0) - '0') * 10 + (*(textptr + 1) - '0')) * 26 * 60) +
(((*(textptr + 3) - '0') * 10 + (*(textptr + 4) - '0')) * 26);
textptr += 5;
while (*textptr == ' ') textptr++;
mapList[j * MAXLEVELS + k].designerTime =
map->designerTime =
(((*(textptr + 0) - '0') * 10 + (*(textptr + 1) - '0')) * 26 * 60) +
(((*(textptr + 3) - '0') * 10 + (*(textptr + 4) - '0')) * 26);
mapList[j * MAXLEVELS + k].levelNumber = k + j * 100;
map->levelNumber = levnum;
textptr += 5;
while (*textptr == ' ') textptr++;
@ -1439,9 +1459,9 @@ int parsecommand()
textptr++, i++;
}
parsebuffer.Push(0);
mapList[j * MAXLEVELS + k].name = parsebuffer.Data();
map->name = parsebuffer.Data();
return 0;
}
case concmd_definequote:
popscriptvalue();
transnum();
@ -1703,6 +1723,12 @@ void loadcons(const char* filenam)
// These can only be retrieved AFTER loading the scripts.
InitGameVarPointers();
ResetSystemDefaults();
for (auto& tm : tempMusic)
{
auto map = FindMapByLevelNum(tm.levnum);
if (map) map->music = tm.music;
}
tempMusic.Clear();
}

View file

@ -560,6 +560,7 @@ void InitGameVarPointers(void)
//
//---------------------------------------------------------------------------
// These are deliberately not stored in accessible variables anymore
int getmap() { return mapfromlevelnum(currentLevel->levelNumber); }
int getvol() { return volfromlevelnum(currentLevel->levelNumber); }

View file

@ -40,15 +40,12 @@ BEGIN_DUKE_NS
#define MOVEFIFOSIZ 256
#define MAXLEVELS 64
#define MAXGAMETYPES 16
enum {
MUS_FIRST_SPECIAL = MAXVOLUMES * MAXLEVELS,
MUS_INTRO = MUS_FIRST_SPECIAL,
MUS_BRIEFING = MUS_FIRST_SPECIAL + 1,
MUS_LOADING = MUS_FIRST_SPECIAL + 2,
MUS_INTRO = 0,
MUS_BRIEFING = 1,
MUS_LOADING = 2,
};
@ -127,8 +124,7 @@ G_EXTERN int32_t g_earthquakeTime;
G_EXTERN int32_t g_freezerSelfDamage;
#define freezerhurtowner g_freezerSelfDamage
G_EXTERN int32_t g_gameQuit;
G_EXTERN int32_t g_globalRandom;
#define global_random g_globalRandom
G_EXTERN int32_t global_random;
G_EXTERN int32_t impact_damage;
extern int32_t labelcnt;
G_EXTERN int32_t g_maxPlayerHealth;
@ -220,7 +216,7 @@ G_EXTERN int16_t fakebubba_spawn, mamaspawn_count, banjosound, g_bellTime, BellS
#define BellTime g_bellTime
#define word_119BE0 BellSprite
G_EXTERN uint8_t g_spriteExtra[MAXSPRITES], g_sectorExtra[MAXSECTORS]; // move these back into the base structs!
G_EXTERN uint8_t enemysizecheat, ufospawnsminion, pistonsound, chickenphase, RRRA_ExitedLevel, RRRA_EndEpisode, fogactive;
G_EXTERN uint8_t enemysizecheat, ufospawnsminion, pistonsound, chickenphase, RRRA_ExitedLevel, fogactive;
G_EXTERN int32_t g_cdTrack;
#define raat607 enemysizecheat // only as a reminder
#define raat605 chickenphase
@ -241,7 +237,6 @@ G_EXTERN player_orig po[MAXPLAYERS];
#pragma pack(pop)
G_EXTERN uint32_t everyothertime;
G_EXTERN uint32_t g_moveThingsCount;
G_EXTERN double g_gameUpdateTime;
G_EXTERN double g_gameUpdateAndDrawTime;
#define GAMEUPDATEAVGTIMENUMSAMPLES 100

View file

@ -908,17 +908,6 @@ int enterlevel(MapRecord *mi, int gamemode)
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void setmapfog(int fogtype)
{
GLInterface.SetMapFog(fogtype != 0);
}
//---------------------------------------------------------------------------
//
// Ideally this will become the only place where map progression gets set up.
@ -964,4 +953,58 @@ bool setnextmap(bool checksecretexit)
return false;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int exitlevel(void)
{
bool endofgame = ud.eog || (currentLevel->flags & MI_FORCEEOG) || ud.nextLevel == nullptr;
STAT_Update(endofgame);
setpal(&ps[myconnectindex]);
if (ps[myconnectindex].gm & MODE_RESTART)
{
ud.nextLevel = currentLevel;
}
if (ps[myconnectindex].gm & MODE_EOL)
{
ready2send = 0;
dobonus(0);
// Clear potentially loaded per-map ART only after the bonus screens.
artClearMapArt();
if (endofgame)
{
ud.eog = 0;
if (ud.multimode < 2)
{
if (!VOLUMEALL)
doorders([](bool) {});
ps[myconnectindex].gm = 0;
return 2;
}
else
{
ud.nextLevel = FindMapByLevelNum(0);
if (!ud.nextLevel) return 2;
}
}
}
ready2send = 0;
if (numplayers > 1)
ps[myconnectindex].gm = MODE_GAME;
int res = enterlevel(ud.nextLevel, ps[myconnectindex].gm);
ud.nextLevel = nullptr;
return res ? 2 : 1;
}
END_DUKE_NS

View file

@ -29,10 +29,8 @@ BEGIN_DUKE_NS
extern int16_t ambientlotag[64];
extern int16_t ambienthitag[64];
int G_EnterLevel(MapRecord *mi, int gameMode);
int G_FindLevelByFile(const char *fileName);
void G_NewGame(int volumeNum, int levelNum, int skillNum);
void G_ResetTimers(uint8_t keepgtics);
int enterlevel(MapRecord *mi, int gameMode);
void G_NewGame(MapRecord *mi, int skillNum);
void P_ResetPlayer(int pn);
void G_ResetInterpolations(void);
void G_InitRRRASkies(void);

View file

@ -44,6 +44,8 @@ source as it is released.
BEGIN_DUKE_NS
TArray<FString> specialmusic;
class DukeSoundEngine : public SoundEngine
{
// client specific parts of the sound engine go in this class.
@ -546,7 +548,7 @@ int S_CheckSoundPlaying(int soundNum)
void S_MenuSound(void)
{
static int menunum;
int/*static const short*/ menusnds[] =
static const short menusnds[] =
{
LASERTRIP_EXPLODE,
DUKE_GRUNT,
@ -587,12 +589,11 @@ void S_PlayLevelMusic(MapRecord *mi)
void S_PlaySpecialMusic(unsigned int m)
{
if (isRR()) return; // Can only be MUS_LOADING, isRR() does not use it.
auto& musicfn = mapList[m].music;
if (isRR() || m >= specialmusic.Size()) return; // Can only be MUS_LOADING, isRR() does not use it.
auto& musicfn = specialmusic[m];
if (musicfn.IsNotEmpty())
{
Mus_Play(nullptr, musicfn, true);
}
}

View file

@ -109,6 +109,8 @@ inline bool StartCommentary(int tag, int sprnum)
return false;
}
extern TArray<FString> specialmusic;
END_DUKE_NS

View file

@ -133,13 +133,13 @@ void G_NewGame(MapRecord *map, int skillNum)
void resetpspritevars(int gameMode);
static inline void clearfrags(void)
void clearfrags(void)
{
for (int i = 0; i < ud.multimode; i++)
{
playerdata_t *const pPlayerData = &g_player[i];
pPlayerData->ps->frag = pPlayerData->ps->fraggedself = 0;
Bmemset(pPlayerData->frags, 0, sizeof(pPlayerData->frags));
memset(pPlayerData->frags, 0, sizeof(pPlayerData->frags));
}
}

View file

@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_RR_NS
extern MapRecord userMapRecord;
class DukeSoundEngine : public SoundEngine
{
// client specific parts of the sound engine go in this class.