Skip to content
Permalink
Browse files
Reworked a joysticks processing
Use a part of PGE Engine's code to process joysticks better
  • Loading branch information
Wohlstand committed Apr 28, 2020
1 parent 17dabac commit 93abda538392ab5d2ddc4b14052409508e7a8791
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 311 deletions.
@@ -1,5 +1,9 @@
TheXTech Changelog.

Changes for 1.3.2.1
-Reworked joysticks support


Changes for 1.3.2
-Added an own timeout sound-92 for P-Switch timer (will be played with 3 seconds before the end)
-Added a level testing interprocess interface to work with PGE Editor
@@ -1214,12 +1214,42 @@ void InitControls()
{
{
auto &j = conJoystick[A];
j.Run = 2;
j.AltRun = 3;
j.Jump = 0;
j.AltJump = 1;
j.Drop = 6;
j.Start = 7;
j.Up.val = SDL_HAT_UP;
j.Up.type = ConJoystick_t::JoyHat;
j.Up.id = 0;
j.Down.val = SDL_HAT_DOWN;
j.Down.type = ConJoystick_t::JoyHat;
j.Down.id = 0;
j.Left.val = SDL_HAT_LEFT;
j.Left.id = 0;
j.Left.type = ConJoystick_t::JoyHat;
j.Right.val = SDL_HAT_RIGHT;
j.Right.type = ConJoystick_t::JoyHat;
j.Right.id = 0;

j.Run.id = 2;
j.Run.val = 1;
j.Run.type = ConJoystick_t::JoyButton;

j.AltRun.id = 3;
j.AltRun.val = 1;
j.AltRun.type = ConJoystick_t::JoyButton;

j.Jump.id = 0;
j.Jump.val = 1;
j.Jump.type = ConJoystick_t::JoyButton;

j.AltJump.id = 1;
j.AltJump.val = 1;
j.AltJump.type = ConJoystick_t::JoyButton;

j.Drop.id = 6;
j.Drop.val = 1;
j.Drop.type = ConJoystick_t::JoyButton;

j.Start.id = 7;
j.Start.val = 1;
j.Start.type = ConJoystick_t::JoyButton;
}
}

@@ -24,6 +24,7 @@
*/

#include "globals.h"
#include <fmt_format_ne.h>

FrmMain frmMain;
GFX_t GFX;
@@ -59,7 +60,7 @@ bool resChanged = false;
int inputKey = 0;
bool getNewKeyboard = false;
bool getNewJoystick = false;
int lastJoyButton = 0;
KM_Key lastJoyButton;
bool GamePaused = false;
std::string MessageText;
int NumSelectWorld = 0;
@@ -324,7 +325,7 @@ Uint32 RenderMode = 1;
RangeArr<std::string, 1, maxWorldCredits> WorldCredits;
int Score = 0;
RangeArrI<int, 1, 13, 0> Points;
int oldJumpJoy = 0;
KM_Key oldJumpJoy;
int MaxWorldStars = 0;
bool Debugger = false;
RangeArr<Player_t, 0, 10> SavedChar;
@@ -502,6 +503,13 @@ const char *getKeyName(int key)
return SDL_GetScancodeName(k);
}

std::string getJoyKeyName(const KM_Key &key)
{
if(key.type < 0)
return "_";
return fmt::format_ne("K={0} ID={1} T={2}", key.val, key.id, key.type);
}


void initAll()
{
@@ -544,3 +552,4 @@ void initAll()
Background.fill(Background_t());
NPC.fill(NPC_t());
}

@@ -103,6 +103,9 @@ const int KEY_PRESSED = 1;
*/
const char *getKeyName(int key);

struct KM_Key;
std::string getJoyKeyName(const KM_Key &key);


//'Saved Events
//Public numSavedEvents As Integer
@@ -243,21 +246,43 @@ struct ConKeyboard_t
//End Type
};

struct KM_Key
{
int val = -1;
int id = -1;
int type = -1;
};

//Public Type conJoystick 'Input settings for the joystick
struct ConJoystick_t
{
// EXTRA
enum CtrlTypes
{
NoControl=-1,
JoyAxis=0,
JoyBallX,
JoyBallY,
JoyHat,
JoyButton
};
KM_Key Up;
KM_Key Down;
KM_Key Left;
KM_Key Right;

// Jump As Integer
int Jump = 0;
KM_Key Jump;
// Run As Integer
int Run = 0;
KM_Key Run;
// Drop As Integer
int Drop = 0;
KM_Key Drop;
// Start As Integer
int Start = 0;
KM_Key Start;
// AltJump As Integer
int AltJump = 0;
KM_Key AltJump;
// AltRun As Integer
int AltRun = 0;
KM_Key AltRun;
//End Type
};

@@ -1070,7 +1095,7 @@ extern bool getNewKeyboard;
//Public getNewJoystick As Boolean
extern bool getNewJoystick;
//Public lastJoyButton As Integer
extern int lastJoyButton;
extern KM_Key lastJoyButton;
//Public GamePaused As Boolean 'true if the game is paused
extern bool GamePaused;
//Public MessageText As String 'when talking to an npc
@@ -1776,7 +1801,7 @@ extern int Score;
//Public Points(1 To 13) As Integer
extern RangeArrI<int, 1, 13, 0> Points;
//Public oldJumpJoy As Integer
extern int oldJumpJoy;
extern KM_Key oldJumpJoy;
//Public MaxWorldStars As Integer 'maximum number of world stars
extern int MaxWorldStars;
//Public Debugger As Boolean 'if the debugger window is open
@@ -2042,35 +2042,46 @@ void UpdateGraphics(bool skipRepaint)
{
SuperPrint("INPUT......JOYSTICK " + std::to_string(useJoystick[MenuMode - 30]), 3, 300, 260 + menuFix);

if(conJoystick[MenuMode - 30].Run >= 0)
SuperPrint(fmt::format_ne("RUN........{0}", conJoystick[MenuMode - 30].Run), 3, 300, 290 + menuFix);
else
SuperPrint("RUN........_", 3, 300, 290 + menuFix);

if(conJoystick[MenuMode - 30].AltRun >= 0)
SuperPrint(fmt::format_ne("ALT RUN....{0}", conJoystick[MenuMode - 30].AltRun), 3, 300, 320 + menuFix);
else
SuperPrint("ALT RUN...._", 3, 300, 320 + menuFix);

if(conJoystick[MenuMode - 30].Jump >= 0)
SuperPrint(fmt::format_ne("JUMP.......{0}", conJoystick[MenuMode - 30].Jump), 3, 300, 350 + menuFix);
else
SuperPrint("JUMP......._", 3, 300, 350 + menuFix);

if(conJoystick[MenuMode - 30].AltJump >= 0)
SuperPrint(fmt::format_ne("ALT JUMP...{0}", conJoystick[MenuMode - 30].AltJump), 3, 300, 380 + menuFix);
else
SuperPrint("ALT JUMP..._", 3, 300, 380 + menuFix);

if(conJoystick[MenuMode - 30].Drop >= 0)
SuperPrint(fmt::format_ne("DROP ITEM..{0}", conJoystick[MenuMode - 30].Drop), 3, 300, 410 + menuFix);
else
SuperPrint("DROP ITEM.._", 3, 300, 410 + menuFix);

if(conJoystick[MenuMode - 30].Start >= 0)
SuperPrint(fmt::format_ne("PAUSE......{0}", conJoystick[MenuMode - 30].Start), 3, 300, 440 + menuFix);
else
SuperPrint("PAUSE......_", 3, 300, 440 + menuFix);
SuperPrint(fmt::format_ne("UP.........{0}", getJoyKeyName(conJoystick[MenuMode - 30].Up)), 3, 300, 290 + menuFix);
SuperPrint(fmt::format_ne("DOWN.......{0}", getJoyKeyName(conJoystick[MenuMode - 30].Down)), 3, 300, 320 + menuFix);
SuperPrint(fmt::format_ne("LEFT.......{0}", getJoyKeyName(conJoystick[MenuMode - 30].Left)), 3, 300, 350 + menuFix);
SuperPrint(fmt::format_ne("RIGHT......{0}", getJoyKeyName(conJoystick[MenuMode - 30].Right)), 3, 300, 380 + menuFix);
SuperPrint(fmt::format_ne("RUN........{0}", getJoyKeyName(conJoystick[MenuMode - 30].Run)), 3, 300, 410 + menuFix);
SuperPrint(fmt::format_ne("ALT RUN....{0}", getJoyKeyName(conJoystick[MenuMode - 30].AltRun)), 3, 300, 440 + menuFix);
SuperPrint(fmt::format_ne("JUMP.......{0}", getJoyKeyName(conJoystick[MenuMode - 30].Jump)), 3, 300, 470 + menuFix);
SuperPrint(fmt::format_ne("ALT JUMP...{0}", getJoyKeyName(conJoystick[MenuMode - 30].AltJump)), 3, 300, 500 + menuFix);
SuperPrint(fmt::format_ne("DROP ITEM..{0}", getJoyKeyName(conJoystick[MenuMode - 30].Drop)), 3, 300, 530 + menuFix);
SuperPrint(fmt::format_ne("PAUSE......{0}", getJoyKeyName(conJoystick[MenuMode - 30].Start)), 3, 300, 560 + menuFix);

// if(conJoystick[MenuMode - 30].Run >= 0)
// SuperPrint(fmt::format_ne("RUN........{0}", conJoystick[MenuMode - 30].Run), 3, 300, 290 + menuFix);
// else
// SuperPrint("RUN........_", 3, 300, 290 + menuFix);

// if(conJoystick[MenuMode - 30].AltRun >= 0)
// SuperPrint(fmt::format_ne("ALT RUN....{0}", conJoystick[MenuMode - 30].AltRun), 3, 300, 320 + menuFix);
// else
// SuperPrint("ALT RUN...._", 3, 300, 320 + menuFix);

// if(conJoystick[MenuMode - 30].Jump >= 0)
// SuperPrint(fmt::format_ne("JUMP.......{0}", conJoystick[MenuMode - 30].Jump), 3, 300, 350 + menuFix);
// else
// SuperPrint("JUMP......._", 3, 300, 350 + menuFix);

// if(conJoystick[MenuMode - 30].AltJump >= 0)
// SuperPrint(fmt::format_ne("ALT JUMP...{0}", conJoystick[MenuMode - 30].AltJump), 3, 300, 380 + menuFix);
// else
// SuperPrint("ALT JUMP..._", 3, 300, 380 + menuFix);

// if(conJoystick[MenuMode - 30].Drop >= 0)
// SuperPrint(fmt::format_ne("DROP ITEM..{0}", conJoystick[MenuMode - 30].Drop), 3, 300, 410 + menuFix);
// else
// SuperPrint("DROP ITEM.._", 3, 300, 410 + menuFix);

// if(conJoystick[MenuMode - 30].Start >= 0)
// SuperPrint(fmt::format_ne("PAUSE......{0}", conJoystick[MenuMode - 30].Start), 3, 300, 440 + menuFix);
// else
// SuperPrint("PAUSE......_", 3, 300, 440 + menuFix);
}

frmMain.renderTexture(300 - 20, 260 + (MenuCursor * 30) + menuFix,

0 comments on commit 93abda5

Please sign in to comment.