mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-18 01:21:32 +00:00
- separated the button code from c_dispatch.
Two separate features justify two separate files.
This commit is contained in:
parent
4a50f78bfe
commit
603ad755ab
14 changed files with 339 additions and 275 deletions
|
@ -829,6 +829,7 @@ set (PCH_SOURCES
|
||||||
playsim/bots/b_think.cpp
|
playsim/bots/b_think.cpp
|
||||||
bbannouncer.cpp
|
bbannouncer.cpp
|
||||||
console/c_commandline.cpp
|
console/c_commandline.cpp
|
||||||
|
console/c_buttons.cpp
|
||||||
console/c_bind.cpp
|
console/c_bind.cpp
|
||||||
console/c_cmds.cpp
|
console/c_cmds.cpp
|
||||||
console/c_console.cpp
|
console/c_console.cpp
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
#include "g_levellocals.h"
|
#include "g_levellocals.h"
|
||||||
#include "actorinlines.h"
|
#include "actorinlines.h"
|
||||||
#include "earcut.hpp"
|
#include "earcut.hpp"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
256
src/console/c_buttons.cpp
Normal file
256
src/console/c_buttons.cpp
Normal file
|
@ -0,0 +1,256 @@
|
||||||
|
/*
|
||||||
|
** c_dispatch.cpp
|
||||||
|
** Functions for executing console commands and aliases
|
||||||
|
**
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
** Copyright 1998-2007 Randy Heit
|
||||||
|
** All rights reserved.
|
||||||
|
**
|
||||||
|
** Redistribution and use in source and binary forms, with or without
|
||||||
|
** modification, are permitted provided that the following conditions
|
||||||
|
** are met:
|
||||||
|
**
|
||||||
|
** 1. Redistributions of source code must retain the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer.
|
||||||
|
** 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
|
** documentation and/or other materials provided with the distribution.
|
||||||
|
** 3. The name of the author may not be used to endorse or promote products
|
||||||
|
** derived from this software without specific prior written permission.
|
||||||
|
**
|
||||||
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "c_buttons.h"
|
||||||
|
#include "templates.h"
|
||||||
|
#include "c_dispatch.h"
|
||||||
|
#include "printf.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
#include "c_console.h"
|
||||||
|
|
||||||
|
|
||||||
|
FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
|
||||||
|
Button_Attack, Button_Speed, Button_MoveRight, Button_MoveLeft,
|
||||||
|
Button_Strafe, Button_LookDown, Button_LookUp, Button_Back,
|
||||||
|
Button_Forward, Button_Right, Button_Left, Button_MoveDown,
|
||||||
|
Button_MoveUp, Button_Jump, Button_ShowScores, Button_Crouch,
|
||||||
|
Button_Zoom, Button_Reload,
|
||||||
|
Button_User1, Button_User2, Button_User3, Button_User4,
|
||||||
|
Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp,
|
||||||
|
Button_AM_ZoomIn, Button_AM_ZoomOut;
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// insert your new action into this list so that the keys remain sorted
|
||||||
|
// in ascending order. No two keys can be identical. If yours matches
|
||||||
|
// an existing key, change the name of your action.
|
||||||
|
|
||||||
|
FActionMap ActionMaps[] =
|
||||||
|
{
|
||||||
|
{ &Button_AM_PanLeft, 0x0d52d67b, "am_panleft"},
|
||||||
|
{ &Button_User2, 0x125f5226, "user2" },
|
||||||
|
{ &Button_Jump, 0x1eefa611, "jump" },
|
||||||
|
{ &Button_Right, 0x201f1c55, "right" },
|
||||||
|
{ &Button_Zoom, 0x20ccc4d5, "zoom" },
|
||||||
|
{ &Button_Back, 0x23a99cd7, "back" },
|
||||||
|
{ &Button_AM_ZoomIn, 0x41df90c2, "am_zoomin"},
|
||||||
|
{ &Button_Reload, 0x426b69e7, "reload" },
|
||||||
|
{ &Button_LookDown, 0x4463f43a, "lookdown" },
|
||||||
|
{ &Button_AM_ZoomOut, 0x51f7a334, "am_zoomout"},
|
||||||
|
{ &Button_User4, 0x534c30ee, "user4" },
|
||||||
|
{ &Button_Attack, 0x5622bf42, "attack" },
|
||||||
|
{ &Button_User1, 0x577712d0, "user1" },
|
||||||
|
{ &Button_Klook, 0x57c25cb2, "klook" },
|
||||||
|
{ &Button_Forward, 0x59f3e907, "forward" },
|
||||||
|
{ &Button_MoveDown, 0x6167ce99, "movedown" },
|
||||||
|
{ &Button_AltAttack, 0x676885b8, "altattack" },
|
||||||
|
{ &Button_MoveLeft, 0x6fa41b84, "moveleft" },
|
||||||
|
{ &Button_MoveRight, 0x818f08e6, "moveright" },
|
||||||
|
{ &Button_AM_PanRight, 0x8197097b, "am_panright"},
|
||||||
|
{ &Button_AM_PanUp, 0x8d89955e, "am_panup"} ,
|
||||||
|
{ &Button_Mlook, 0xa2b62d8b, "mlook" },
|
||||||
|
{ &Button_Crouch, 0xab2c3e71, "crouch" },
|
||||||
|
{ &Button_Left, 0xb000b483, "left" },
|
||||||
|
{ &Button_LookUp, 0xb62b1e49, "lookup" },
|
||||||
|
{ &Button_User3, 0xb6f8fe92, "user3" },
|
||||||
|
{ &Button_Strafe, 0xb7e6a54b, "strafe" },
|
||||||
|
{ &Button_AM_PanDown, 0xce301c81, "am_pandown"},
|
||||||
|
{ &Button_ShowScores, 0xd5897c73, "showscores" },
|
||||||
|
{ &Button_Speed, 0xe0ccb317, "speed" },
|
||||||
|
{ &Button_Use, 0xe0cfc260, "use" },
|
||||||
|
{ &Button_MoveUp, 0xfdd701c7, "moveup" },
|
||||||
|
};
|
||||||
|
#define NUM_ACTIONS countof(ActionMaps)
|
||||||
|
|
||||||
|
|
||||||
|
// FindButton scans through the actionbits[] array
|
||||||
|
// for a matching key and returns an index or -1 if
|
||||||
|
// the key could not be found. This uses binary search,
|
||||||
|
// so actionbits[] must be sorted in ascending order.
|
||||||
|
|
||||||
|
FButtonStatus *FindButton (unsigned int key)
|
||||||
|
{
|
||||||
|
const FActionMap *bit;
|
||||||
|
|
||||||
|
bit = BinarySearch<FActionMap, unsigned int>
|
||||||
|
(ActionMaps, NUM_ACTIONS, &FActionMap::Key, key);
|
||||||
|
return bit ? bit->Button : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FButtonStatus::PressKey (int keynum)
|
||||||
|
{
|
||||||
|
int i, open;
|
||||||
|
|
||||||
|
keynum &= KEY_DBLCLICKED-1;
|
||||||
|
|
||||||
|
if (keynum == 0)
|
||||||
|
{ // Issued from console instead of a key, so force on
|
||||||
|
Keys[0] = 0xffff;
|
||||||
|
for (i = MAX_KEYS-1; i > 0; --i)
|
||||||
|
{
|
||||||
|
Keys[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = MAX_KEYS-1, open = -1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (Keys[i] == 0)
|
||||||
|
{
|
||||||
|
open = i;
|
||||||
|
}
|
||||||
|
else if (Keys[i] == keynum)
|
||||||
|
{ // Key is already down; do nothing
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (open < 0)
|
||||||
|
{ // No free key slots, so do nothing
|
||||||
|
Printf ("More than %u keys pressed for a single action!\n", MAX_KEYS);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Keys[open] = keynum;
|
||||||
|
}
|
||||||
|
uint8_t wasdown = bDown;
|
||||||
|
bDown = bWentDown = true;
|
||||||
|
// Returns true if this key caused the button to go down.
|
||||||
|
return !wasdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FButtonStatus::ReleaseKey (int keynum)
|
||||||
|
{
|
||||||
|
int i, numdown, match;
|
||||||
|
uint8_t wasdown = bDown;
|
||||||
|
|
||||||
|
keynum &= KEY_DBLCLICKED-1;
|
||||||
|
|
||||||
|
if (keynum == 0)
|
||||||
|
{ // Issued from console instead of a key, so force off
|
||||||
|
for (i = MAX_KEYS-1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
Keys[i] = 0;
|
||||||
|
}
|
||||||
|
bWentUp = true;
|
||||||
|
bDown = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = MAX_KEYS-1, numdown = 0, match = -1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (Keys[i] != 0)
|
||||||
|
{
|
||||||
|
++numdown;
|
||||||
|
if (Keys[i] == keynum)
|
||||||
|
{
|
||||||
|
match = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (match < 0)
|
||||||
|
{ // Key was not down; do nothing
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Keys[match] = 0;
|
||||||
|
bWentUp = true;
|
||||||
|
if (--numdown == 0)
|
||||||
|
{
|
||||||
|
bDown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Returns true if releasing this key caused the button to go up.
|
||||||
|
return wasdown && !bDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetButtonTriggers ()
|
||||||
|
{
|
||||||
|
for (int i = NUM_ACTIONS-1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
ActionMaps[i].Button->ResetTriggers ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetButtonStates ()
|
||||||
|
{
|
||||||
|
for (int i = NUM_ACTIONS-1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
FButtonStatus *button = ActionMaps[i].Button;
|
||||||
|
|
||||||
|
if (button != &Button_Mlook && button != &Button_Klook)
|
||||||
|
{
|
||||||
|
button->ReleaseKey (0);
|
||||||
|
}
|
||||||
|
button->ResetTriggers ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int ListActionCommands (const char *pattern)
|
||||||
|
{
|
||||||
|
char matcher[16];
|
||||||
|
unsigned int i;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < NUM_ACTIONS; ++i)
|
||||||
|
{
|
||||||
|
if (pattern == NULL || CheckWildcards (pattern,
|
||||||
|
(mysnprintf (matcher, countof(matcher), "+%s", ActionMaps[i].Name), matcher)))
|
||||||
|
{
|
||||||
|
Printf ("+%s\n", ActionMaps[i].Name);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (pattern == NULL || CheckWildcards (pattern,
|
||||||
|
(mysnprintf (matcher, countof(matcher), "-%s", ActionMaps[i].Name), matcher)))
|
||||||
|
{
|
||||||
|
Printf ("-%s\n", ActionMaps[i].Name);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddButtonTabCommands()
|
||||||
|
{
|
||||||
|
// Add all the action commands for tab completion
|
||||||
|
for (int i = 0; i < NUM_ACTIONS; i++)
|
||||||
|
{
|
||||||
|
char tname[16];
|
||||||
|
strcpy (&tname[1], ActionMaps[i].Name);
|
||||||
|
tname[0] = '+';
|
||||||
|
C_AddTabCommand (tname);
|
||||||
|
tname[0] = '-';
|
||||||
|
C_AddTabCommand (tname);
|
||||||
|
}
|
||||||
|
}
|
43
src/console/c_buttons.h
Normal file
43
src/console/c_buttons.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
struct FButtonStatus
|
||||||
|
{
|
||||||
|
enum { MAX_KEYS = 6 }; // Maximum number of keys that can press this button
|
||||||
|
|
||||||
|
uint16_t Keys[MAX_KEYS];
|
||||||
|
uint8_t bDown; // Button is down right now
|
||||||
|
uint8_t bWentDown; // Button went down this tic
|
||||||
|
uint8_t bWentUp; // Button went up this tic
|
||||||
|
uint8_t padTo16Bytes;
|
||||||
|
|
||||||
|
bool PressKey (int keynum); // Returns true if this key caused the button to be pressed.
|
||||||
|
bool ReleaseKey (int keynum); // Returns true if this key is no longer pressed.
|
||||||
|
void ResetTriggers () { bWentDown = bWentUp = false; }
|
||||||
|
void Reset () { bDown = bWentDown = bWentUp = false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FActionMap
|
||||||
|
{
|
||||||
|
FButtonStatus* Button;
|
||||||
|
unsigned int Key; // value from passing Name to MakeKey()
|
||||||
|
char Name[12];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extern FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
|
||||||
|
Button_Attack, Button_Speed, Button_MoveRight, Button_MoveLeft,
|
||||||
|
Button_Strafe, Button_LookDown, Button_LookUp, Button_Back,
|
||||||
|
Button_Forward, Button_Right, Button_Left, Button_MoveDown,
|
||||||
|
Button_MoveUp, Button_Jump, Button_ShowScores, Button_Crouch,
|
||||||
|
Button_Zoom, Button_Reload,
|
||||||
|
Button_User1, Button_User2, Button_User3, Button_User4,
|
||||||
|
Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp,
|
||||||
|
Button_AM_ZoomIn, Button_AM_ZoomOut;
|
||||||
|
extern bool ParsingKeyConf, UnsafeExecutionContext;
|
||||||
|
|
||||||
|
void ResetButtonTriggers (); // Call ResetTriggers for all buttons
|
||||||
|
void ResetButtonStates (); // Same as above, but also clear bDown
|
||||||
|
FButtonStatus *FindButton (unsigned int key);
|
||||||
|
void AddButtonTabCommands();
|
||||||
|
extern FActionMap ActionMaps[];
|
|
@ -360,7 +360,8 @@ CCMD (changemap)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!players[who->player - players].settings_controller && netgame)
|
AActor* user = (AActor*)who;
|
||||||
|
if (!players[user->player - players].settings_controller && netgame)
|
||||||
{
|
{
|
||||||
Printf ("Only setting controllers can change the map.\n");
|
Printf ("Only setting controllers can change the map.\n");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -55,9 +55,9 @@
|
||||||
#include "menu/menu.h"
|
#include "menu/menu.h"
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
#include "g_levellocals.h"
|
#include "g_levellocals.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
// TYPES -------------------------------------------------------------------
|
// TYPES -------------------------------------------------------------------
|
||||||
|
|
||||||
class UnsafeExecutionScope
|
class UnsafeExecutionScope
|
||||||
|
@ -176,13 +176,6 @@ void C_ClearDelayedCommands()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct FActionMap
|
|
||||||
{
|
|
||||||
FButtonStatus *Button;
|
|
||||||
unsigned int Key; // value from passing Name to MakeKey()
|
|
||||||
char Name[12];
|
|
||||||
};
|
|
||||||
|
|
||||||
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
||||||
|
|
||||||
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
||||||
|
@ -196,66 +189,11 @@ static FConsoleCommand *ScanChainForName (FConsoleCommand *start, const char *na
|
||||||
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
||||||
|
|
||||||
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
||||||
|
|
||||||
CVAR (Bool, lookspring, true, CVAR_ARCHIVE); // Generate centerview when -mlook encountered?
|
|
||||||
|
|
||||||
FConsoleCommand *Commands[FConsoleCommand::HASH_SIZE];
|
|
||||||
FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
|
|
||||||
Button_Attack, Button_Speed, Button_MoveRight, Button_MoveLeft,
|
|
||||||
Button_Strafe, Button_LookDown, Button_LookUp, Button_Back,
|
|
||||||
Button_Forward, Button_Right, Button_Left, Button_MoveDown,
|
|
||||||
Button_MoveUp, Button_Jump, Button_ShowScores, Button_Crouch,
|
|
||||||
Button_Zoom, Button_Reload,
|
|
||||||
Button_User1, Button_User2, Button_User3, Button_User4,
|
|
||||||
Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp,
|
|
||||||
Button_AM_ZoomIn, Button_AM_ZoomOut;
|
|
||||||
|
|
||||||
bool ParsingKeyConf, UnsafeExecutionContext;
|
bool ParsingKeyConf, UnsafeExecutionContext;
|
||||||
|
|
||||||
|
FConsoleCommand* Commands[FConsoleCommand::HASH_SIZE];
|
||||||
|
|
||||||
// To add new actions, go to the console and type "key <action name>".
|
CVAR (Bool, lookspring, true, CVAR_ARCHIVE); // Generate centerview when -mlook encountered?
|
||||||
// This will give you the key value to use in the first column. Then
|
|
||||||
// insert your new action into this list so that the keys remain sorted
|
|
||||||
// in ascending order. No two keys can be identical. If yours matches
|
|
||||||
// an existing key, change the name of your action.
|
|
||||||
|
|
||||||
FActionMap ActionMaps[] =
|
|
||||||
{
|
|
||||||
{ &Button_AM_PanLeft, 0x0d52d67b, "am_panleft"},
|
|
||||||
{ &Button_User2, 0x125f5226, "user2" },
|
|
||||||
{ &Button_Jump, 0x1eefa611, "jump" },
|
|
||||||
{ &Button_Right, 0x201f1c55, "right" },
|
|
||||||
{ &Button_Zoom, 0x20ccc4d5, "zoom" },
|
|
||||||
{ &Button_Back, 0x23a99cd7, "back" },
|
|
||||||
{ &Button_AM_ZoomIn, 0x41df90c2, "am_zoomin"},
|
|
||||||
{ &Button_Reload, 0x426b69e7, "reload" },
|
|
||||||
{ &Button_LookDown, 0x4463f43a, "lookdown" },
|
|
||||||
{ &Button_AM_ZoomOut, 0x51f7a334, "am_zoomout"},
|
|
||||||
{ &Button_User4, 0x534c30ee, "user4" },
|
|
||||||
{ &Button_Attack, 0x5622bf42, "attack" },
|
|
||||||
{ &Button_User1, 0x577712d0, "user1" },
|
|
||||||
{ &Button_Klook, 0x57c25cb2, "klook" },
|
|
||||||
{ &Button_Forward, 0x59f3e907, "forward" },
|
|
||||||
{ &Button_MoveDown, 0x6167ce99, "movedown" },
|
|
||||||
{ &Button_AltAttack, 0x676885b8, "altattack" },
|
|
||||||
{ &Button_MoveLeft, 0x6fa41b84, "moveleft" },
|
|
||||||
{ &Button_MoveRight, 0x818f08e6, "moveright" },
|
|
||||||
{ &Button_AM_PanRight, 0x8197097b, "am_panright"},
|
|
||||||
{ &Button_AM_PanUp, 0x8d89955e, "am_panup"} ,
|
|
||||||
{ &Button_Mlook, 0xa2b62d8b, "mlook" },
|
|
||||||
{ &Button_Crouch, 0xab2c3e71, "crouch" },
|
|
||||||
{ &Button_Left, 0xb000b483, "left" },
|
|
||||||
{ &Button_LookUp, 0xb62b1e49, "lookup" },
|
|
||||||
{ &Button_User3, 0xb6f8fe92, "user3" },
|
|
||||||
{ &Button_Strafe, 0xb7e6a54b, "strafe" },
|
|
||||||
{ &Button_AM_PanDown, 0xce301c81, "am_pandown"},
|
|
||||||
{ &Button_ShowScores, 0xd5897c73, "showscores" },
|
|
||||||
{ &Button_Speed, 0xe0ccb317, "speed" },
|
|
||||||
{ &Button_Use, 0xe0cfc260, "use" },
|
|
||||||
{ &Button_MoveUp, 0xfdd701c7, "moveup" },
|
|
||||||
};
|
|
||||||
#define NUM_ACTIONS countof(ActionMaps)
|
|
||||||
|
|
||||||
|
|
||||||
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
||||||
|
|
||||||
|
@ -274,152 +212,6 @@ static const char *KeyConfCommands[] =
|
||||||
|
|
||||||
// CODE --------------------------------------------------------------------
|
// CODE --------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static int ListActionCommands (const char *pattern)
|
|
||||||
{
|
|
||||||
char matcher[16];
|
|
||||||
unsigned int i;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_ACTIONS; ++i)
|
|
||||||
{
|
|
||||||
if (pattern == NULL || CheckWildcards (pattern,
|
|
||||||
(mysnprintf (matcher, countof(matcher), "+%s", ActionMaps[i].Name), matcher)))
|
|
||||||
{
|
|
||||||
Printf ("+%s\n", ActionMaps[i].Name);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (pattern == NULL || CheckWildcards (pattern,
|
|
||||||
(mysnprintf (matcher, countof(matcher), "-%s", ActionMaps[i].Name), matcher)))
|
|
||||||
{
|
|
||||||
Printf ("-%s\n", ActionMaps[i].Name);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// FindButton scans through the actionbits[] array
|
|
||||||
// for a matching key and returns an index or -1 if
|
|
||||||
// the key could not be found. This uses binary search,
|
|
||||||
// so actionbits[] must be sorted in ascending order.
|
|
||||||
|
|
||||||
FButtonStatus *FindButton (unsigned int key)
|
|
||||||
{
|
|
||||||
const FActionMap *bit;
|
|
||||||
|
|
||||||
bit = BinarySearch<FActionMap, unsigned int>
|
|
||||||
(ActionMaps, NUM_ACTIONS, &FActionMap::Key, key);
|
|
||||||
return bit ? bit->Button : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FButtonStatus::PressKey (int keynum)
|
|
||||||
{
|
|
||||||
int i, open;
|
|
||||||
|
|
||||||
keynum &= KEY_DBLCLICKED-1;
|
|
||||||
|
|
||||||
if (keynum == 0)
|
|
||||||
{ // Issued from console instead of a key, so force on
|
|
||||||
Keys[0] = 0xffff;
|
|
||||||
for (i = MAX_KEYS-1; i > 0; --i)
|
|
||||||
{
|
|
||||||
Keys[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (i = MAX_KEYS-1, open = -1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
if (Keys[i] == 0)
|
|
||||||
{
|
|
||||||
open = i;
|
|
||||||
}
|
|
||||||
else if (Keys[i] == keynum)
|
|
||||||
{ // Key is already down; do nothing
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (open < 0)
|
|
||||||
{ // No free key slots, so do nothing
|
|
||||||
Printf ("More than %u keys pressed for a single action!\n", MAX_KEYS);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Keys[open] = keynum;
|
|
||||||
}
|
|
||||||
uint8_t wasdown = bDown;
|
|
||||||
bDown = bWentDown = true;
|
|
||||||
// Returns true if this key caused the button to go down.
|
|
||||||
return !wasdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FButtonStatus::ReleaseKey (int keynum)
|
|
||||||
{
|
|
||||||
int i, numdown, match;
|
|
||||||
uint8_t wasdown = bDown;
|
|
||||||
|
|
||||||
keynum &= KEY_DBLCLICKED-1;
|
|
||||||
|
|
||||||
if (keynum == 0)
|
|
||||||
{ // Issued from console instead of a key, so force off
|
|
||||||
for (i = MAX_KEYS-1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
Keys[i] = 0;
|
|
||||||
}
|
|
||||||
bWentUp = true;
|
|
||||||
bDown = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (i = MAX_KEYS-1, numdown = 0, match = -1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
if (Keys[i] != 0)
|
|
||||||
{
|
|
||||||
++numdown;
|
|
||||||
if (Keys[i] == keynum)
|
|
||||||
{
|
|
||||||
match = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (match < 0)
|
|
||||||
{ // Key was not down; do nothing
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Keys[match] = 0;
|
|
||||||
bWentUp = true;
|
|
||||||
if (--numdown == 0)
|
|
||||||
{
|
|
||||||
bDown = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Returns true if releasing this key caused the button to go up.
|
|
||||||
return wasdown && !bDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResetButtonTriggers ()
|
|
||||||
{
|
|
||||||
for (int i = NUM_ACTIONS-1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
ActionMaps[i].Button->ResetTriggers ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResetButtonStates ()
|
|
||||||
{
|
|
||||||
for (int i = NUM_ACTIONS-1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
FButtonStatus *button = ActionMaps[i].Button;
|
|
||||||
|
|
||||||
if (button != &Button_Mlook && button != &Button_Klook)
|
|
||||||
{
|
|
||||||
button->ReleaseKey (0);
|
|
||||||
}
|
|
||||||
button->ResetTriggers ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void C_DoCommand (const char *cmd, int keynum)
|
void C_DoCommand (const char *cmd, int keynum)
|
||||||
{
|
{
|
||||||
FConsoleCommand *com;
|
FConsoleCommand *com;
|
||||||
|
@ -709,20 +501,8 @@ FConsoleCommand::FConsoleCommand (const char *name, CCmdRun runFunc)
|
||||||
|
|
||||||
if (firstTime)
|
if (firstTime)
|
||||||
{
|
{
|
||||||
char tname[16];
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
|
AddButtonTabCommands();
|
||||||
// Add all the action commands for tab completion
|
|
||||||
for (i = 0; i < NUM_ACTIONS; i++)
|
|
||||||
{
|
|
||||||
strcpy (&tname[1], ActionMaps[i].Name);
|
|
||||||
tname[0] = '+';
|
|
||||||
C_AddTabCommand (tname);
|
|
||||||
tname[0] = '-';
|
|
||||||
C_AddTabCommand (tname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ag = strcmp (name, "kill");
|
int ag = strcmp (name, "kill");
|
||||||
|
@ -731,7 +511,7 @@ FConsoleCommand::FConsoleCommand (const char *name, CCmdRun runFunc)
|
||||||
m_Name = copystring (name);
|
m_Name = copystring (name);
|
||||||
|
|
||||||
if (!AddToHash (Commands))
|
if (!AddToHash (Commands))
|
||||||
Printf ("FConsoleCommand c'tor: %s exists\n", name);
|
Printf ("Adding CCMD %s twice.\n", name);
|
||||||
else
|
else
|
||||||
C_AddTabCommand (name);
|
C_AddTabCommand (name);
|
||||||
}
|
}
|
||||||
|
@ -745,12 +525,12 @@ FConsoleCommand::~FConsoleCommand ()
|
||||||
delete[] m_Name;
|
delete[] m_Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FConsoleCommand::Run (FCommandLine &argv, AActor *who, int key)
|
void FConsoleCommand::Run (FCommandLine &argv, void *who, int key)
|
||||||
{
|
{
|
||||||
m_RunFunc (argv, who, key);
|
m_RunFunc (argv, who, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FUnsafeConsoleCommand::Run (FCommandLine &args, AActor *instigator, int key)
|
void FUnsafeConsoleCommand::Run (FCommandLine &args, void *instigator, int key)
|
||||||
{
|
{
|
||||||
if (UnsafeExecutionContext)
|
if (UnsafeExecutionContext)
|
||||||
{
|
{
|
||||||
|
@ -1098,6 +878,8 @@ CCMD (alias)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ListActionCommands(const char* pattern);
|
||||||
|
|
||||||
CCMD (cmdlist)
|
CCMD (cmdlist)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
|
@ -1166,7 +948,7 @@ bool FConsoleAlias::IsAlias ()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FConsoleAlias::Run (FCommandLine &args, AActor *who, int key)
|
void FConsoleAlias::Run (FCommandLine &args, void *who, int key)
|
||||||
{
|
{
|
||||||
if (bRunning)
|
if (bRunning)
|
||||||
{
|
{
|
||||||
|
@ -1229,7 +1011,7 @@ void FConsoleAlias::SafeDelete ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FUnsafeConsoleAlias::Run (FCommandLine &args, AActor *instigator, int key)
|
void FUnsafeConsoleAlias::Run (FCommandLine &args, void *instigator, int key)
|
||||||
{
|
{
|
||||||
UnsafeExecutionScope scope;
|
UnsafeExecutionScope scope;
|
||||||
FConsoleAlias::Run(args, instigator, key);
|
FConsoleAlias::Run(args, instigator, key);
|
||||||
|
|
|
@ -53,6 +53,8 @@ struct FExecList
|
||||||
void AddPullins(TArray<FString> &wads) const;
|
void AddPullins(TArray<FString> &wads) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern bool ParsingKeyConf, UnsafeExecutionContext;
|
||||||
|
|
||||||
|
|
||||||
extern bool CheckCheatmode (bool printmsg = true);
|
extern bool CheckCheatmode (bool printmsg = true);
|
||||||
|
|
||||||
|
@ -84,7 +86,7 @@ void C_ClearAliases ();
|
||||||
FString BuildString (int argc, FString *argv);
|
FString BuildString (int argc, FString *argv);
|
||||||
|
|
||||||
class AActor;
|
class AActor;
|
||||||
typedef void (*CCmdRun) (FCommandLine &argv, AActor *instigator, int key);
|
typedef void (*CCmdRun) (FCommandLine &argv, void *instigator, int key);
|
||||||
|
|
||||||
class FConsoleCommand
|
class FConsoleCommand
|
||||||
{
|
{
|
||||||
|
@ -94,7 +96,7 @@ public:
|
||||||
virtual bool IsAlias ();
|
virtual bool IsAlias ();
|
||||||
void PrintCommand();
|
void PrintCommand();
|
||||||
|
|
||||||
virtual void Run (FCommandLine &args, AActor *instigator, int key);
|
virtual void Run (FCommandLine &args, void *instigator, int key);
|
||||||
static FConsoleCommand* FindByName (const char* name);
|
static FConsoleCommand* FindByName (const char* name);
|
||||||
|
|
||||||
FConsoleCommand *m_Next, **m_Prev;
|
FConsoleCommand *m_Next, **m_Prev;
|
||||||
|
@ -111,9 +113,9 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CCMD(n) \
|
#define CCMD(n) \
|
||||||
void Cmd_##n (FCommandLine &, AActor *, int key); \
|
void Cmd_##n (FCommandLine &, void *, int key); \
|
||||||
FConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \
|
FConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \
|
||||||
void Cmd_##n (FCommandLine &argv, AActor *who, int key)
|
void Cmd_##n (FCommandLine &argv, void *who, int key)
|
||||||
|
|
||||||
class FUnsafeConsoleCommand : public FConsoleCommand
|
class FUnsafeConsoleCommand : public FConsoleCommand
|
||||||
{
|
{
|
||||||
|
@ -123,13 +125,13 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Run (FCommandLine &args, AActor *instigator, int key) override;
|
virtual void Run (FCommandLine &args, void *instigator, int key) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UNSAFE_CCMD(n) \
|
#define UNSAFE_CCMD(n) \
|
||||||
static void Cmd_##n (FCommandLine &, AActor *, int key); \
|
static void Cmd_##n (FCommandLine &, void *, int key); \
|
||||||
static FUnsafeConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \
|
static FUnsafeConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \
|
||||||
void Cmd_##n (FCommandLine &argv, AActor *who, int key)
|
void Cmd_##n (FCommandLine &argv, void *who, int key)
|
||||||
|
|
||||||
const int KEY_DBLCLICKED = 0x8000;
|
const int KEY_DBLCLICKED = 0x8000;
|
||||||
|
|
||||||
|
@ -138,7 +140,7 @@ class FConsoleAlias : public FConsoleCommand
|
||||||
public:
|
public:
|
||||||
FConsoleAlias (const char *name, const char *command, bool noSave);
|
FConsoleAlias (const char *name, const char *command, bool noSave);
|
||||||
~FConsoleAlias ();
|
~FConsoleAlias ();
|
||||||
void Run (FCommandLine &args, AActor *instigator, int key);
|
void Run (FCommandLine &args, void *instigator, int key);
|
||||||
bool IsAlias ();
|
bool IsAlias ();
|
||||||
void PrintAlias ();
|
void PrintAlias ();
|
||||||
void Archive (FConfigFile *f);
|
void Archive (FConfigFile *f);
|
||||||
|
@ -159,39 +161,9 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Run (FCommandLine &args, AActor *instigator, int key) override;
|
virtual void Run (FCommandLine &args, void *instigator, int key) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Actions
|
|
||||||
struct FButtonStatus
|
|
||||||
{
|
|
||||||
enum { MAX_KEYS = 6 }; // Maximum number of keys that can press this button
|
|
||||||
|
|
||||||
uint16_t Keys[MAX_KEYS];
|
|
||||||
uint8_t bDown; // Button is down right now
|
|
||||||
uint8_t bWentDown; // Button went down this tic
|
|
||||||
uint8_t bWentUp; // Button went up this tic
|
|
||||||
uint8_t padTo16Bytes;
|
|
||||||
|
|
||||||
bool PressKey (int keynum); // Returns true if this key caused the button to be pressed.
|
|
||||||
bool ReleaseKey (int keynum); // Returns true if this key is no longer pressed.
|
|
||||||
void ResetTriggers () { bWentDown = bWentUp = false; }
|
|
||||||
void Reset () { bDown = bWentDown = bWentUp = false; }
|
|
||||||
};
|
|
||||||
|
|
||||||
extern FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
|
|
||||||
Button_Attack, Button_Speed, Button_MoveRight, Button_MoveLeft,
|
|
||||||
Button_Strafe, Button_LookDown, Button_LookUp, Button_Back,
|
|
||||||
Button_Forward, Button_Right, Button_Left, Button_MoveDown,
|
|
||||||
Button_MoveUp, Button_Jump, Button_ShowScores, Button_Crouch,
|
|
||||||
Button_Zoom, Button_Reload,
|
|
||||||
Button_User1, Button_User2, Button_User3, Button_User4,
|
|
||||||
Button_AM_PanLeft, Button_AM_PanRight, Button_AM_PanDown, Button_AM_PanUp,
|
|
||||||
Button_AM_ZoomIn, Button_AM_ZoomOut;
|
|
||||||
extern bool ParsingKeyConf, UnsafeExecutionContext;
|
|
||||||
|
|
||||||
void ResetButtonTriggers (); // Call ResetTriggers for all buttons
|
|
||||||
void ResetButtonStates (); // Same as above, but also clear bDown
|
|
||||||
|
|
||||||
#include "superfasthash.h"
|
#include "superfasthash.h"
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
#include "gstrings.h"
|
#include "gstrings.h"
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,6 +104,7 @@
|
||||||
#include "swrenderer/r_swcolormaps.h"
|
#include "swrenderer/r_swcolormaps.h"
|
||||||
#include "findfile.h"
|
#include "findfile.h"
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
EXTERN_CVAR(Bool, hud_althud)
|
EXTERN_CVAR(Bool, hud_althud)
|
||||||
EXTERN_CVAR(Int, vr_mode)
|
EXTERN_CVAR(Int, vr_mode)
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
#include "g_hub.h"
|
#include "g_hub.h"
|
||||||
#include "g_levellocals.h"
|
#include "g_levellocals.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
|
|
||||||
static FRandom pr_dmspawn ("DMSpawn");
|
static FRandom pr_dmspawn ("DMSpawn");
|
||||||
|
@ -471,7 +472,7 @@ CCMD (use)
|
||||||
{
|
{
|
||||||
if (argv.argc() > 1 && who != NULL)
|
if (argv.argc() > 1 && who != NULL)
|
||||||
{
|
{
|
||||||
SendItemUse = who->FindInventory(argv[1]);
|
SendItemUse = ((AActor*)who)->FindInventory(argv[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +495,7 @@ CCMD (drop)
|
||||||
{
|
{
|
||||||
if (argv.argc() > 1 && who != NULL)
|
if (argv.argc() > 1 && who != NULL)
|
||||||
{
|
{
|
||||||
SendItemDrop = who->FindInventory(argv[1]);
|
SendItemDrop = ((AActor*)who)->FindInventory(argv[1]);
|
||||||
SendItemDropAmount = argv.argc() > 2 ? atoi(argv[2]) : -1;
|
SendItemDropAmount = argv.argc() > 2 ? atoi(argv[2]) : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,7 +503,7 @@ CCMD (drop)
|
||||||
CCMD (useflechette)
|
CCMD (useflechette)
|
||||||
{
|
{
|
||||||
if (who == nullptr) return;
|
if (who == nullptr) return;
|
||||||
IFVIRTUALPTRNAME(who, NAME_PlayerPawn, GetFlechetteItem)
|
IFVIRTUALPTRNAME(((AActor*)who), NAME_PlayerPawn, GetFlechetteItem)
|
||||||
{
|
{
|
||||||
VMValue params[] = { who };
|
VMValue params[] = { who };
|
||||||
AActor *cls;
|
AActor *cls;
|
||||||
|
@ -515,15 +516,16 @@ CCMD (useflechette)
|
||||||
|
|
||||||
CCMD (select)
|
CCMD (select)
|
||||||
{
|
{
|
||||||
|
auto user = ((AActor*)who);
|
||||||
if (argv.argc() > 1)
|
if (argv.argc() > 1)
|
||||||
{
|
{
|
||||||
auto item = who->FindInventory(argv[1]);
|
auto item = user->FindInventory(argv[1]);
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
{
|
{
|
||||||
who->PointerVar<AActor>(NAME_InvSel) = item;
|
user->PointerVar<AActor>(NAME_InvSel) = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
who->player->inventorytics = 5*TICRATE;
|
user->player->inventorytics = 5*TICRATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int joyint(double val)
|
static inline int joyint(double val)
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
#include "p_conversation.h"
|
#include "p_conversation.h"
|
||||||
#include "p_effect.h"
|
#include "p_effect.h"
|
||||||
#include "stringtable.h"
|
#include "stringtable.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
#include "gi.h"
|
#include "gi.h"
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
#include "scripting/types.h"
|
#include "scripting/types.h"
|
||||||
|
|
||||||
int DMenu::InMenu;
|
int DMenu::InMenu;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
#include "g_levellocals.h"
|
#include "g_levellocals.h"
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
EXTERN_CVAR(Float, transsouls)
|
EXTERN_CVAR(Float, transsouls)
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@
|
||||||
#include "engineerrors.h"
|
#include "engineerrors.h"
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
#include "g_levellocals.h"
|
#include "g_levellocals.h"
|
||||||
|
#include "c_buttons.h"
|
||||||
|
|
||||||
int32_t refreshfreq = -1;
|
int32_t refreshfreq = -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue