Merge branch 'master' into new_level_refactor

# Conflicts:
#	src/c_dispatch.cpp
This commit is contained in:
Christoph Oelckers 2019-01-27 10:26:23 +01:00
commit 22939aade7
9 changed files with 133 additions and 138 deletions

View file

@ -70,7 +70,7 @@ const char *KeyNames[NUM_KEYS] =
NULL, NULL, NULL, NULL, "F13", "F14", "F15", "F16", //60 NULL, NULL, NULL, NULL, "F13", "F14", "F15", "F16", //60
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, //68 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, //68
"Kana", NULL, NULL, "Abnt_C1", NULL, NULL, NULL, NULL, //70 "Kana", NULL, NULL, "Abnt_C1", NULL, NULL, NULL, NULL, //70
NULL, "Convert", NULL, "NoConvert",NULL, "Yen", "abnt_c2", NULL, //78 NULL, "Convert", NULL, "NoConvert",NULL, "Yen", "Abnt_C2", NULL, //78
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, //80 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, //80
NULL, NULL, NULL, NULL, NULL, "KP=", NULL, NULL, //88 NULL, NULL, NULL, NULL, NULL, "KP=", NULL, NULL, //88
"Circumflex","@", ":", "_", "Kanji", "Stop", "Ax", "Unlabeled",//90 "Circumflex","@", ":", "_", "Kanji", "Stop", "Ax", "Unlabeled",//90
@ -148,7 +148,7 @@ const char *KeyNames[NUM_KEYS] =
"DPadUp","DPadDown","DPadLeft","DPadRight", // Gamepad buttons "DPadUp","DPadDown","DPadLeft","DPadRight", // Gamepad buttons
"Pad_Start","Pad_Back","LThumb","RThumb", "Pad_Start","Pad_Back","LThumb","RThumb",
"LShoulder","RShoulder","LTrigger","RTrigger", "LShoulder","RShoulder","LTrigger","RTrigger",
"Pad_A", "Pad_B", "Pad_X", "Pad_Y" "Pad_A", "Pad_B", "Pad_X", "Pad_Y"
}; };
FKeyBindings Bindings; FKeyBindings Bindings;

View file

@ -74,6 +74,7 @@ extern bool insave;
CVAR (Bool, sv_cheats, false, CVAR_SERVERINFO | CVAR_LATCH) CVAR (Bool, sv_cheats, false, CVAR_SERVERINFO | CVAR_LATCH)
CVAR (Bool, sv_unlimited_pickup, false, CVAR_SERVERINFO) CVAR (Bool, sv_unlimited_pickup, false, CVAR_SERVERINFO)
CVAR (Bool, cl_blockcheats, false, 0)
CCMD (toggleconsole) CCMD (toggleconsole)
{ {
@ -87,6 +88,11 @@ bool CheckCheatmode (bool printmsg)
if (printmsg) Printf ("sv_cheats must be true to enable this command.\n"); if (printmsg) Printf ("sv_cheats must be true to enable this command.\n");
return true; return true;
} }
else if (cl_blockcheats)
{
if (printmsg) Printf ("cl_blockcheats is turned on and disabled this command.\n");
return true;
}
else else
{ {
return false; return false;

View file

@ -629,7 +629,7 @@ void C_DeinitConsole ()
while (cmd != NULL) while (cmd != NULL)
{ {
GameAtExit *next = cmd->Next; GameAtExit *next = cmd->Next;
AddCommandString (cmd->Command.LockBuffer()); AddCommandString (cmd->Command);
delete cmd; delete cmd;
cmd = next; cmd = next;
} }
@ -1559,17 +1559,9 @@ static bool C_HandleKey (event_t *ev, FCommandBuffer &buffer)
{ {
// Work with a copy of command to avoid side effects caused by // Work with a copy of command to avoid side effects caused by
// exception raised during execution, like with 'error' CCMD. // exception raised during execution, like with 'error' CCMD.
// It's problematic to maintain FString's lock symmetry. FString copy = buffer.Text;
static TArray<char> command;
const size_t length = buffer.Text.Len();
command.Resize(unsigned(length + 1));
memcpy(&command[0], buffer.Text.GetChars(), length);
command[length] = '\0';
buffer.SetString(""); buffer.SetString("");
AddCommandString(copy);
AddCommandString(&command[0]);
} }
TabbedLast = false; TabbedLast = false;
TabbedList = false; TabbedList = false;

View file

@ -60,38 +60,119 @@
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
class DWaitingCommand : public DThinker class UnsafeExecutionScope
{ {
DECLARE_CLASS (DWaitingCommand, DThinker) const bool wasEnabled;
public: public:
DWaitingCommand (const char *cmd, int tics, bool unsafe); explicit UnsafeExecutionScope(const bool enable = true)
~DWaitingCommand (); : wasEnabled(UnsafeExecutionContext)
void Serialize(FSerializer &arc); {
void Tick (); UnsafeExecutionContext = enable;
}
private: ~UnsafeExecutionScope()
DWaitingCommand (); {
UnsafeExecutionContext = wasEnabled;
}
};
char *Command; class FDelayedCommand
{
protected:
virtual bool Tick() = 0;
friend class FDelayedCommandQueue;
};
class FWaitingCommand : public FDelayedCommand
{
public:
FWaitingCommand(const char *cmd, int tics, bool unsafe)
: Command(cmd), TicsLeft(tics+1), IsUnsafe(unsafe)
{}
bool Tick() override
{
if (--TicsLeft == 0)
{
UnsafeExecutionScope scope(IsUnsafe);
AddCommandString(Command);
return true;
}
return false;
}
FString Command;
int TicsLeft; int TicsLeft;
bool IsUnsafe; bool IsUnsafe;
}; };
class DStoredCommand : public DThinker class FStoredCommand : public FDelayedCommand
{ {
DECLARE_CLASS (DStoredCommand, DThinker)
public: public:
DStoredCommand (FConsoleCommand *com, const char *cmd); FStoredCommand(FConsoleCommand *com, const char *cmd)
~DStoredCommand (); : Command(com), Text(cmd)
void Tick (); {}
bool Tick() override
{
if (Text.IsNotEmpty() && Command != nullptr)
{
FCommandLine args(Text);
Command->Run(args, players[consoleplayer].mo, 0);
}
return true;
}
private: private:
DStoredCommand ();
FConsoleCommand *Command; FConsoleCommand *Command;
char *Text; FString Text;
}; };
class FDelayedCommandQueue
{
TDeletingArray<FDelayedCommand *> delayedCommands;
public:
void Run()
{
for (unsigned i = 0; i < delayedCommands.Size(); i++)
{
if (delayedCommands[i]->Tick())
{
delete delayedCommands[i];
delayedCommands.Delete(i);
i--;
}
}
}
void Clear()
{
delayedCommands.DeleteAndClear();
}
void AddCommand(FDelayedCommand * cmd)
{
delayedCommands.Push(cmd);
}
};
static FDelayedCommandQueue delayedCommandQueue;
void C_RunDelayedCommands()
{
delayedCommandQueue.Run();
}
void C_ClearDelayedCommands()
{
delayedCommandQueue.Clear();
}
struct FActionMap struct FActionMap
{ {
FButtonStatus *Button; FButtonStatus *Button;
@ -128,22 +209,6 @@ FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
bool ParsingKeyConf, UnsafeExecutionContext; bool ParsingKeyConf, UnsafeExecutionContext;
class UnsafeExecutionScope
{
const bool wasEnabled;
public:
explicit UnsafeExecutionScope(const bool enable = true)
: wasEnabled(UnsafeExecutionContext)
{
UnsafeExecutionContext = enable;
}
~UnsafeExecutionScope()
{
UnsafeExecutionContext = wasEnabled;
}
};
// To add new actions, go to the console and type "key <action name>". // To add new actions, go to the console and type "key <action name>".
// This will give you the key value to use in the first column. Then // This will give you the key value to use in the first column. Then
@ -206,79 +271,6 @@ static const char *KeyConfCommands[] =
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
IMPLEMENT_CLASS(DWaitingCommand, false, false)
void DWaitingCommand::Serialize(FSerializer &arc)
{
Super::Serialize (arc);
arc("command", Command)
("ticsleft", TicsLeft)
("unsafe", IsUnsafe);
}
DWaitingCommand::DWaitingCommand ()
{
Command = NULL;
TicsLeft = 1;
IsUnsafe = false;
}
DWaitingCommand::DWaitingCommand (const char *cmd, int tics, bool unsafe)
{
Command = copystring (cmd);
TicsLeft = tics+1;
IsUnsafe = unsafe;
}
DWaitingCommand::~DWaitingCommand ()
{
if (Command != NULL)
{
delete[] Command;
}
}
void DWaitingCommand::Tick ()
{
if (--TicsLeft == 0)
{
UnsafeExecutionScope scope(IsUnsafe);
AddCommandString (Command);
Destroy ();
}
}
IMPLEMENT_CLASS(DStoredCommand, false, false)
DStoredCommand::DStoredCommand ()
{
Text = NULL;
Destroy ();
}
DStoredCommand::DStoredCommand (FConsoleCommand *command, const char *args)
{
Command = command;
Text = copystring (args);
}
DStoredCommand::~DStoredCommand ()
{
if (Text != NULL)
{
delete[] Text;
}
}
void DStoredCommand::Tick ()
{
if (Text != NULL && Command != NULL)
{
FCommandLine args (Text);
Command->Run (args, players[consoleplayer].mo, 0);
}
Destroy ();
}
static int ListActionCommands (const char *pattern) static int ListActionCommands (const char *pattern)
{ {
@ -657,7 +649,8 @@ void C_DoCommand (const char *cmd, int keynum)
} }
else else
{ {
currentUILevel->CreateThinker<DStoredCommand> (com, beg); auto cmd = new FStoredCommand(com, beg);
delayedCommandQueue.AddCommand(cmd);
} }
} }
} }
@ -697,8 +690,12 @@ DEFINE_ACTION_FUNCTION(DOptionMenuItemCommand, DoCommand)
return 0; return 0;
} }
void AddCommandString (char *cmd, int keynum) void AddCommandString (const char *text, int keynum)
{ {
// Operate on a local copy instead of messing around with the data that's being passed in here.
TArray<char> buffer(strlen(text) + 1, true);
memcpy(buffer.Data(), text, buffer.Size());
char *cmd = buffer.Data();
char *brkpt; char *brkpt;
int more; int more;
@ -753,7 +750,8 @@ void AddCommandString (char *cmd, int keynum)
// Note that deferred commands lose track of which key // Note that deferred commands lose track of which key
// (if any) they were pressed from. // (if any) they were pressed from.
*brkpt = ';'; *brkpt = ';';
currentUILevel->CreateThinker<DWaitingCommand> (brkpt, tics, UnsafeExecutionContext); auto cmd = new FWaitingCommand(brkpt, tics, UnsafeExecutionContext);
delayedCommandQueue.AddCommand(cmd);
} }
return; return;
} }
@ -1478,8 +1476,7 @@ void FConsoleAlias::Run (FCommandLine &args, AActor *who, int key)
} }
bRunning = true; bRunning = true;
AddCommandString (mycommand.LockBuffer(), key); AddCommandString (mycommand, key);
mycommand.UnlockBuffer();
bRunning = false; bRunning = false;
if (m_Command[index].IsEmpty()) if (m_Command[index].IsEmpty())
{ // The alias is unchanged, so put the command back so it can be used again. { // The alias is unchanged, so put the command back so it can be used again.
@ -1555,8 +1552,7 @@ void FExecList::ExecCommands() const
{ {
for (unsigned i = 0; i < Commands.Size(); ++i) for (unsigned i = 0; i < Commands.Size(); ++i)
{ {
AddCommandString(Commands[i].LockBuffer()); AddCommandString(Commands[i]);
Commands[i].UnlockBuffer();
} }
} }

View file

@ -77,7 +77,10 @@ FExecList *C_ParseCmdLineParams(FExecList *exec);
// and semicolon-separated commands. This function may modify the source // and semicolon-separated commands. This function may modify the source
// string, but the string will be restored to its original state before // string, but the string will be restored to its original state before
// returning. Therefore, commands passed must not be in read-only memory. // returning. Therefore, commands passed must not be in read-only memory.
void AddCommandString (char *text, int keynum=0); void AddCommandString (const char *text, int keynum=0);
void C_RunDelayedCommands();
void C_ClearDelayedCommands();
// Process a single console command. Does not handle wait. // Process a single console command. Does not handle wait.
void C_DoCommand (const char *cmd, int keynum=0); void C_DoCommand (const char *cmd, int keynum=0);

View file

@ -2579,7 +2579,7 @@ void D_DoomMain (void)
// [RH] Run any saved commands from the command line or autoexec.cfg now. // [RH] Run any saved commands from the command line or autoexec.cfg now.
gamestate = GS_FULLCONSOLE; gamestate = GS_FULLCONSOLE;
Net_NewMakeTic (); Net_NewMakeTic ();
DThinker::RunThinkers (); C_RunDelayedCommands();
gamestate = GS_STARTUP; gamestate = GS_STARTUP;
if (!restart) if (!restart)
@ -2646,7 +2646,7 @@ void D_DoomMain (void)
G_InitNew(startmap, false); G_InitNew(startmap, false);
if (StoredWarp.IsNotEmpty()) if (StoredWarp.IsNotEmpty())
{ {
AddCommandString(StoredWarp.LockBuffer()); AddCommandString(StoredWarp);
StoredWarp = NULL; StoredWarp = NULL;
} }
} }

View file

@ -1021,9 +1021,8 @@ void G_Ticker ()
if (ToggleFullscreen) if (ToggleFullscreen)
{ {
static char toggle_fullscreen[] = "toggle fullscreen";
ToggleFullscreen = false; ToggleFullscreen = false;
AddCommandString (toggle_fullscreen); AddCommandString ("toggle fullscreen");
} }
// do things to change the game state // do things to change the game state
@ -1173,6 +1172,7 @@ void G_Ticker ()
// [ZZ] also tick the UI part of the events // [ZZ] also tick the UI part of the events
E_UiTick(); E_UiTick();
C_RunDelayedCommands();
// do main actions // do main actions
switch (gamestate) switch (gamestate)
@ -2058,12 +2058,12 @@ static void PutSaveWads (FSerializer &arc)
name = Wads.GetWadName (Wads.GetIwadNum()); name = Wads.GetWadName (Wads.GetIwadNum());
arc.AddString("Game WAD", name); arc.AddString("Game WAD", name);
// Name of wad the map resides in // Name of wad the map resides in
if (Wads.GetLumpFile (level.lumpnum) > Wads.GetIwadNum()) if (Wads.GetLumpFile (level.lumpnum) > Wads.GetIwadNum())
{ {
name = Wads.GetWadName (Wads.GetLumpFile (level.lumpnum)); name = Wads.GetWadName (Wads.GetLumpFile (level.lumpnum));
arc.AddString("Map WAD", name); arc.AddString("Map WAD", name);
} }
} }
static void PutSaveComment (FSerializer &arc) static void PutSaveComment (FSerializer &arc)
@ -2079,7 +2079,7 @@ static void PutSaveComment (FSerializer &arc)
arc.AddString("Creation Time", comment); arc.AddString("Creation Time", comment);
// Get level name // Get level name
//strcpy (comment, level.level_name); //strcpy (comment, level.level_name);
comment.Format("%s - %s\n", level.MapName.GetChars(), level.LevelName.GetChars()); comment.Format("%s - %s\n", level.MapName.GetChars(), level.LevelName.GetChars());

View file

@ -748,8 +748,7 @@ void P_PlaybackKeyConfWeapons(FWeaponSlots *slots)
PlayingKeyConf = slots; PlayingKeyConf = slots;
for (unsigned int i = 0; i < KeyConfWeapons.Size(); ++i) for (unsigned int i = 0; i < KeyConfWeapons.Size(); ++i)
{ {
FString cmd(KeyConfWeapons[i]); AddCommandString(KeyConfWeapons[i]);
AddCommandString(cmd.LockBuffer());
} }
PlayingKeyConf = nullptr; PlayingKeyConf = nullptr;
} }

View file

@ -2202,8 +2202,7 @@ void OpenALSoundRenderer::UpdateSounds()
if(connected == ALC_FALSE) if(connected == ALC_FALSE)
{ {
Printf("Sound device disconnected; restarting...\n"); Printf("Sound device disconnected; restarting...\n");
static char snd_reset[] = "snd_reset"; AddCommandString("snd_reset");
AddCommandString(snd_reset);
return; return;
} }
} }