Skip to content

Commit

Permalink
25.1.26
Browse files Browse the repository at this point in the history
[Engine]
* Move all joystick related code to a new 'joystick.hpp' module and tidy up names and clean out redundant code.
* Increase supported buttons from GLFW_BUTTON_LAST+1 to 128 and protect from potential overflow.
* Increase supported axes from GLFW_AXIS_LAST+1 to 8 and protect from overflow.
* Show more information with 'input' console command.
* Fix 'Input.GetJoyButton()' returning raw button data and not translated data.

[Assets]
* Update API documentation.
  • Loading branch information
Mhatxotic committed Jan 26, 2025
1 parent 35b98d0 commit 609628d
Show file tree
Hide file tree
Showing 11 changed files with 705 additions and 558 deletions.
22 changes: 11 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<!-- Reference for the Mhatxotic Engine API version 25.1.22.118 -->
<!-- Automatically built at Thu Jan 23 01:39:36 2025 +0000 -->
<!-- With Mhatxotic Engine Project Management Utility version 25.1.22.118 -->
<!-- Reference for the Mhatxotic Engine API version 25.1.26.24 -->
<!-- Automatically built at Sun Jan 26 00:32:39 2025 +0000 -->
<!-- With Mhatxotic Engine Project Management Utility version 25.1.26.24 -->
<!-- Copyright (c) 2006-2025 Mhatxotic Design, All Rights Reserved Worldwide -->
<HTML lang="en-GB">
<HEAD>
Expand All @@ -11,18 +11,18 @@
<META name="apple-mobile-web-app-title" content="Mhatxotic Engine API">
<META name="author" content="Mhatxotic Design">
<META name="copyright" content="Copyright © 2006-2025 Mhatxotic Design, All Rights Reserved">
<META name="description" content="Reference for the Mhatxotic Engine API version 25.1.22.118">
<META name="description" content="Reference for the Mhatxotic Engine API version 25.1.26.24">
<META name="format-detection" content="telephone=no">
<META name="generator" content="Mhatxotic Engine Project Management Utility version 25.1.22.118">
<META name="generator" content="Mhatxotic Engine Project Management Utility version 25.1.26.24">
<META name="google-site-verification" content="BvWxrqmgaIxqe_W8AW3OGK0fdCI_JfB_-gcOOxCF9_4">
<META name="googlebot" content="index,follow">
<META name="og:description" content="Reference for the Mhatxotic Engine API version 25.1.22.118">
<META name="og:description" content="Reference for the Mhatxotic Engine API version 25.1.26.24">
<META name="og:image" content="https://repository-images.githubusercontent.com/611875607/ee7aa468-9797-4763-9a2d-ea3d782ef413">
<META name="og:title" content="Mhatxotic Engine 25.1.22.118 API reference">
<META name="og:title" content="Mhatxotic Engine 25.1.26.24 API reference">
<META name="og:url" content="https://mhatxotic.github.io/Engine/">
<META name="robots" content="index,follow">
<META name="viewport" content="width=device-width, initial-scale=1">
<TITLE>Mhatxotic Engine 25.1.22.118 API reference</TITLE>
<TITLE>Mhatxotic Engine 25.1.26.24 API reference</TITLE>
<STYLE media="screen">
* { margin:0; padding:0 }
BODY { background-color:#111; border:0; font-family:sans-serif; overflow-x:hidden; text-shadow: 1px 1px #111 }
Expand Down Expand Up @@ -60,7 +60,7 @@
</STYLE>
</HEAD>
<BODY id="idx.top">
<H1>Mhatxotic Engine 25.1.22.118 API reference</H1>
<H1>Mhatxotic Engine 25.1.26.24 API reference</H1>
<NOSCRIPT>
<H2>JavaScript is required to show and hide elements.</H2>
</NOSCRIPT>
Expand Down Expand Up @@ -5736,7 +5736,7 @@ <H4>Function Parameters:-</H4>
<H4>Return Parameters:-</H4>
<PRE><U>Result</U> <I>(integer)</I> = Number of ticks the button has been held down.<BR></PRE>
<H4>Synopsis:-</H4>
<PRE>Returns the state of the specified joystick button&#x2e;<BR><BR>Result can be&#x3a; &#x3d;0&#x3a; The button is not held down&#x2e;<BR>&#x3e;0&#x3a; The button was held down for this many game ticks&#x2e;<BR></PRE>
<PRE>Returns the state of the specified joystick button&#x2e;<BR><BR>Result can be&#x3a; &#x3d;0&#x3a; The button is not held down&#x2e;<BR>&#x3d;1&#x3a; The button was pressed&#x2e;<BR>&#x3e;1&#x3a; The button is being held&#x2e;<BR></PRE>
<H4><A href="#idx:Input">&#x25B2; Return to table of contents</A></H4>
</DIV>
<DIV id="Input.GetJoyName" style="display:none">
Expand Down Expand Up @@ -12306,6 +12306,6 @@ <H3>win_widthmin</H3>
<H4><A href="#idx.cv">&#x25B2; Return to table of contents</A></H4>
</DIV>
<ADDRESS>Copyright &copy; 2025 Mhatxotic Design, All Rights Reserved.<BR>
This document was generated at Thu Jan 23 01:39:36 2025 +0000</ADDRESS>
This document was generated at Sun Jan 26 00:32:39 2025 +0000</ADDRESS>
</BODY>
</HTML>
88 changes: 47 additions & 41 deletions src/conlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,71 +889,77 @@ cConsole->AddLineA(sTable.Finish(),
/* ========================================================================= */
{ "input", 1, 2, CFL_VIDEO, [](const Args &aArgs){
/* ------------------------------------------------------------------------- */
// Get joysticks data
const JoyList &jlList = cInput->GetConstJoyList();
// Required joystick namespace
using namespace IJoystick::P;
// If argument specified
if(aArgs.size() > 1)
{ // Convert parmeter to number
const size_t stArg = StrToNum<size_t>(aArgs[1]);
if(stArg >= jlList.size())
if(stArg >= cInput->JoyGetCount())
return cConsole->AddLine("Joystick index argument invalid!");
// Get joystick information and return if not connected
const JoyInfo &jiRef = jlList[stArg];
if(jiRef.IsDisconnected())
const JoyInfo &jiRef = cInput->JoyGetConst(stArg);
if(jiRef.JoyIsDisconnected())
return cConsole->AddLine("Joystick is not being polled right now!");
// Build axis state data
Statistic sAxes;
sAxes.Header();
for(size_t stIndex = 0; stIndex < jiRef.GetAxisCount(); ++stIndex)
sAxes.Header(StrFormat("A$$$$", setw(2), right, setfill('0'), stIndex));
// Buffered
sAxes.Data("BUF");
for(size_t stIndex = 0; stIndex < jiRef.GetAxisCount(); ++stIndex)
sAxes.DataN(jiRef.GetAxisState(stIndex));
// Unbuffered
sAxes.Data("RAW");
for(size_t stIndex = 0; stIndex < jiRef.GetAxisCount(); ++stIndex)
sAxes.DataN(jiRef.GetUnbufferedAxisState(stIndex), 1);
// Buffered headers
StdForEach(seq, jiRef.JoyAxisListBegin(), jiRef.JoyAxisListEnd(),
[&sAxes](const JoyAxisInfo &jaiRef) { sAxes.Header(StrFormat("BA$$$$",
setw(2), right, setfill('0'), jaiRef.AxisGetId()), true); });
// Unbuffered headers
StdForEach(seq, jiRef.JoyAxisListBegin(), jiRef.JoyAxisListEnd(),
[&sAxes](const JoyAxisInfo &jaiRef) { sAxes.Header(StrFormat("UA$$$$",
setw(2), right, setfill('0'), jaiRef.AxisGetId()), true); });
// Reserve memory for data entries
sAxes.Reserve(jiRef.JoyAxisListCount() * 2);
// Buffered state
StdForEach(seq, jiRef.JoyAxisListBegin(), jiRef.JoyAxisListEnd(),
[&sAxes](const JoyAxisInfo &jaiRef)
{ sAxes.DataN(jaiRef.AxisGetBufferedState()); });
// Unbuffered state
StdForEach(seq, jiRef.JoyAxisListBegin(), jiRef.JoyAxisListEnd(),
[&sAxes](const JoyAxisInfo &jaiRef)
{ sAxes.DataN(jaiRef.AxisGetUnbufferedState(), 1); });
// Build button state data
Statistic sButtons;
sButtons.Header();
for(size_t stIndex = 0; stIndex < jiRef.GetButtonCount(); ++stIndex)
sButtons.Header(StrFormat("B$$$$", setw(2), right, setfill('0'), stIndex));
// Buffered
sButtons.Data("BUF");
for(size_t stIndex = 0; stIndex < jiRef.GetButtonCount(); ++stIndex)
sButtons.DataN(jiRef.GetButtonState(stIndex));
// Unbuffered
sButtons.Data("RAW");
for(size_t stIndex = 0; stIndex < jiRef.GetButtonCount(); ++stIndex)
sButtons.DataN(jiRef.GetUnbufferedButtonState(stIndex));
// Buffered headers
StdForEach(seq, jiRef.JoyButtonListBegin(), jiRef.JoyButtonListEnd(),
[&sButtons](const JoyButtonInfo &jbiRef)
{ sButtons.Header(StrFormat("B$$$$",
setw(2), right, setfill('0'), jbiRef.ButtonGetId()), true); });
// Reserve memory for data entries
sButtons.Reserve(jiRef.JoyButtonListCount());
// Buffered state
StdForEach(seq, jiRef.JoyButtonListBegin(), jiRef.JoyButtonListEnd(),
[&sButtons](const JoyButtonInfo &jbiRef)
{ sButtons.DataN(jbiRef.ButtonGetState()); });
// Dump to console output and return
return cConsole->AddLineF("$$Data for $ '$' at index $.", sAxes.Finish(),
sButtons.Finish(), jiRef.GetGamepadOrJoystickString(), jiRef.IdentGet(),
sButtons.Finish(), jiRef.JoyGetGamepadOrJoystickString(), jiRef.IdentGet(),
stArg);
} // Joysticks connected
size_t stConnected = 0;
// Make a table to automatically format our data neatly
} // Make a table to automatically format our data neatly
Statistic sTable;
sTable.Header("ID").Header("FL").Header("AX").Header("BT")
.Header("NAME", false).Reserve(jlList.size());
.Header("GUID", false).Header("NAME", false)
.Header("IDENT", false).Reserve(cInput->JoyGetCount());
// For each joystick
const JoyList &jlList = cInput->JoyListGetConst();
for(const JoyInfo &jiRef : jlList)
{ // If joystick is connected
if(jiRef.IsDisconnected())
if(jiRef.JoyIsDisconnected())
{ // If joystick name was empty then ignore it. Still show disconnected ones
if(jiRef.IdentGet().empty()) continue;
} // Connected
else ++stConnected;
// Store data
sTable.DataN(jiRef.GetId()).Data(StrFromEvalTokens({
{ jiRef.FlagIsSet(JF_GAMEPAD), 'G' },
{ jiRef.FlagIsSet(JF_CONNECTED), 'C' }
})).DataN(jiRef.GetAxisCount()).DataN(jiRef.GetButtonCount())
} // Store data
sTable.DataN(jiRef.JoyGetId()).Data(StrFromEvalTokens({
{ jiRef.JoyIsGamepad(), 'G' }, { jiRef.JoyIsConnected(), 'C' }
})).DataN(jiRef.JoyAxisListCount()).DataN(jiRef.JoyButtonListCount())
.Data(jiRef.JoyGUID()).Data(jiRef.JoyGamePadName())
.Data(jiRef.IdentGet());
} // Print totals
cConsole->AddLineF("$$ connected ($ supported).", sTable.Finish(),
StrCPluraliseNum(stConnected, "input", "inputs"), jlList.size());
StrCPluraliseNum(cInput->JoyGetConnected(), "input", "inputs"),
jlList.size());
/* ------------------------------------------------------------------------- */
} }, // End of 'input' function
/* ========================================================================= */
Expand Down
2 changes: 1 addition & 1 deletion src/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Core final : // Members initially private
{ // Set main fbo by default on each frame
cFboCore->ActivateMain();
// Poll joysticks
cInput->PollJoysticks();
cInput->JoyPoll();
// Execute a tick for each frame missed
cLua->ExecuteMain();
// Break if we've caught up
Expand Down
1 change: 1 addition & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace E { // Start of engine namespace
#include "file.hpp" // FStream+FileMap class header
#include "clip.hpp" // Clipboard class header
#include "congraph.hpp" // Console rendering class header
#include "joystick.hpp" // Joystick structure class header
#include "input.hpp" // Input handling class header
#include "display.hpp" // Window handling class header
#include "mask.hpp" // BitMask system header
Expand Down
10 changes: 5 additions & 5 deletions src/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#define VER_AUTHOR "Mhatxotic Design" // Author of engine
#define VER_MAJOR 25 // Version major (year)
#define VER_MINOR 1 // Version minor (month)
#define VER_BUILD 25 // Version build (day)
#define VER_REV 1 // Version rev (build#)
#define VER_STR_NQ 25,1,25,1 // Version as literal
#define VER_STR "25.1.25.1" // Version as string
#define VER_DATE "Sat Jan 25 00:32:33 2025 +0000" // Compilation date
#define VER_BUILD 26 // Version build (day)
#define VER_REV 27 // Version rev (build#)
#define VER_STR_NQ 25,1,26,27 // Version as literal
#define VER_STR "25.1.26.27" // Version as string
#define VER_DATE "Sun Jan 26 01:08:13 2025 +0000" // Compilation date
/* == EoF =========================================================== EoF == */
12 changes: 12 additions & 0 deletions src/glfwutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ static const unsigned char *GlFWGetJoystickButtons(int iJ, int &iJAB)
/* -- Joystick other ------------------------------------------------------- */
static const char *GlFWGetJoystickName(const int iJ)
{ return glfwGetJoystickName(iJ); }
/* -- Joystick is actually a game controller ------------------------------- */
static bool GlFWJoystickIsGamepad(const int iJ)
{ return glfwJoystickIsGamepad(iJ); }
/* -- Get gamepad name ----------------------------------------------------- */
static const char *GlFWGetGamepadName(const int iJ)
{ return glfwGetGamepadName(iJ); }
/* -- Get joystick unique identification number ---------------------------- */
static const char *GlFWGetJoystickGUID(const int iJ)
{ return glfwGetJoystickGUID(iJ); }
/* -- Return if joystick is present ---------------------------------------- */
static bool GlFWJoystickPresent(const int iJ)
{ return glfwJoystickPresent(iJ); }
/* -- Set swap interval ---------------------------------------------------- */
static void GlFWSetVSync(const int iI) { glfwSwapInterval(iI); }
/* -- Wait for window event ------------------------------------------------ */
Expand Down
Loading

0 comments on commit 609628d

Please sign in to comment.