Skip to content

Commit

Permalink
🔡 Unsigned integer 4,8,12,16,20,24 to hexadecimal (#2153)
Browse files Browse the repository at this point in the history
## What type of PR is this.
* Bug
* Change
3. [x] Enhancement

### What have you changed and why?
    Formats a scalar as the specified length hexadecimal string.
    These lengths are divided into multiple functions for 4, 8, 12, 16, 20, 24 bits.
    This is needed for UUID generation and output. May help other areas.

### Please verify the following and ensure all checks are completed.

1. [x] Have you loaded the mission in LAN host?
2. [ ] Have you loaded the mission on a dedicated server?

### Is further testing or are further changes required?
1. [x] No
* Yes (Please provide further detail below.)

### How can the changes be tested?
```sqf
[
    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"
] isEqualTo [true,true,true,true,true,true];
```
Notes:
* 🔡 Unsigned integer 4,8,12,16,20,24 to hexidecimal

* 〰 Spelling Fixes.

* 📄Fixed doc example to show random's exclusiveness

* ⛔16e3 lookup table removed. Files moved to utility

* 🌅 Added initPreJIP function.

* ⏪ uintToHexGenTables added to initPreJIP.

* 🔍 4 and 8 uintToHex replaced by lookup examples.

* #️⃣ Fixed include for initPreJIP.

* 🔥 Fixed broken math from 4096 lookuptable removal
  • Loading branch information
CalebSerafin authored Oct 12, 2021
1 parent 21887ed commit 0c68128
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 0 deletions.
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 / 16 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 / 65536) +
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");

0 comments on commit 0c68128

Please sign in to comment.