Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔡 Unsigned integer 4,8,12,16,20,24 to hexadecimal #2153

Merged
merged 9 commits into from
Oct 12, 2021
10 changes: 10 additions & 0 deletions A3-Antistasi/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class A3A
class initFuncs {};
class initGarrisons {};
class initParams {};
class initPreJIP { preInit = 1; };
class initSpawnPlaces {};

class initVar {};
Expand Down Expand Up @@ -684,6 +685,15 @@ class A3A
class updateInfoBarShown {};
class disableInfoBar {};
};
class uintToHex
{
file = "functions\Utility\uintToHex";
class uint12ToHex {};
class uint16ToHex {};
class uint20ToHex {};
class uint24ToHex {};
class uintToHexGenTables {};
};

class Undercover
{
Expand Down
27 changes: 27 additions & 0 deletions A3-Antistasi/functions/Utility/uintToHex/doc_uintToHex.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Maintainer: Caleb Serafin
Formats a scalar as the specified length hexadecimal string.
These lengths are divided into multiple functions for 4, 8, 12, 16, 20, 24 bits.
4 and 8 bits are single lookup table selects.

Argument: <SCALAR> A numberic value to format as a hexadecimal string. Input must be integral.
Return Value: <STRING> 1,2,3,4,5,6 wide hexadecimal string.
Public: Yes
Dependency:
fn_uintToHexGenTables must initialise:
<ARRAY<STRING>> A3A_base16LookupTable
<ARRAY<STRING>> A3A_base16e2LookupTable
*/

// Example:
floor random 0x1000000 call A3A_fnc_uint24ToHex;
16777215 call A3A_fnc_uint24ToHex;
// Tests:
[
A3A_base16LookupTable # 0x0 isEqualTo "0",
A3A_base16e2LookupTable # 0xb4 isEqualTo "b4",
0xaaf call A3A_fnc_uint12ToHex isEqualTo "aaf",
0xdead call A3A_fnc_uint16ToHex isEqualTo "dead",
0xca1eb call A3A_fnc_uint20ToHex isEqualTo "ca1eb",
0xffffff call A3A_fnc_uint24ToHex isEqualTo "ffffff"
];
2 changes: 2 additions & 0 deletions A3-Antistasi/functions/Utility/uintToHex/fn_uint12ToHex.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A3A_base16e2LookupTable # floor (_this / 16) +
A3A_base16LookupTable # (_this mod 16);
2 changes: 2 additions & 0 deletions A3-Antistasi/functions/Utility/uintToHex/fn_uint16ToHex.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A3A_base16e2LookupTable # floor (_this / 256) +
A3A_base16e2LookupTable # (_this mod 256);
3 changes: 3 additions & 0 deletions A3-Antistasi/functions/Utility/uintToHex/fn_uint20ToHex.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A3A_base16e2LookupTable # floor (_this / 4096) +
A3A_base16e2LookupTable # floor (_this / 256 mod 256) +
A3A_base16LookupTable # (_this mod 16);
3 changes: 3 additions & 0 deletions A3-Antistasi/functions/Utility/uintToHex/fn_uint24ToHex.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A3A_base16e2LookupTable # floor (_this / 4096) +
A3A_base16e2LookupTable # floor (_this / 256 mod 256) +
A3A_base16e2LookupTable # (_this mod 256);
15 changes: 15 additions & 0 deletions A3-Antistasi/functions/Utility/uintToHex/fn_uintToHexGenTables.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Maintainer: Caleb Serafin
Generates the lookup tables for uintToHex.
Only needs to run once per machine.
Public: No.
Example:
call A3A_fnc_uintToHexGenTables;
*/
A3A_base16LookupTable = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];

A3A_base16e2LookupTable = [];
{
private _prefix = _x;
A3A_base16e2LookupTable append (A3A_base16LookupTable apply {_prefix + _x});
} forEach A3A_base16LookupTable;
26 changes: 26 additions & 0 deletions A3-Antistasi/functions/init/fn_initPreJIP.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Maintainer: Caleb Serafin
First code run upon machine joining/starting the mission.
This is run before Join-In-Progress.
Mission objects have not initialised.
Player object is not available.
https://community.bistudio.com/wiki/Initialization_Order

This file is best suited for calling initialisers for variables and lookup tables.
This file ensures that a dependency order can be maintained.
Do not vomit your initialiser code in here, place it in the relevant folder for your module and call it.
Code is allowed to take a while to execute (multiple milliseconds).
Because if it started later in scheduled init code, the player would still need to wait, and for much longer.

Scope: All
Environment: Unscheduled
Public: Yes
*/
#include "..\..\Includes\common.inc"
FIX_LINE_NUMBERS()
Debug("fn_initPreJIP Started");

call A3A_fnc_uintToHexGenTables;


Debug("fn_initPreJIP Finished");