Skip to content

Commit

Permalink
WIP map list encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
peterekepeter committed Jul 15, 2023
1 parent 6c425b8 commit e158aa1
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,66 @@
"clear": true
}
},
{
"label": "watch test MVES",
"type": "shell",
"command": "nodemon -e uc -x \"ucx build MVES && ucx build TestMVE && ucx ucc TestMVE.TestAll\"",
"problemMatcher": [
{
"pattern": [
{
"regexp": "(Classes(?:\\\\[A-Za-z0-9.]+)+)\\((\\d+)\\)\\s*:\\s*Error,?\\s*(.*)$",
"file": 1,
"location": 2,
"message": 3
}
]
}
],
"runOptions": {
"instanceLimit": 1,
"reevaluateOnRerun": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"group": "groupA",
"showReuseMessage": true,
"clear": true
}
},
{
"label": "watch test TestMVE",
"type": "shell",
"command": "nodemon -e uc -x \"ucx build TestMVE && ucx ucc TestMVE.TestAll\"",
"problemMatcher": [
{
"pattern": [
{
"regexp": "(Classes(?:\\\\[A-Za-z0-9.]+)+)\\((\\d+)\\)\\s*:\\s*Error,?\\s*(.*)$",
"file": 1,
"location": 2,
"message": 3
}
]
}
],
"runOptions": {
"instanceLimit": 1,
"reevaluateOnRerun": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"group": "groupA",
"showReuseMessage": true,
"clear": true
}
},
{
"label": "run server",
"type": "shell",
Expand Down
1 change: 1 addition & 0 deletions TestMVE/Classes/TestAll.uc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ function TestMain()
TestChild(class'TestSort');
TestChild(class'TestMapVoteResult');
TestChild(class'TestMapTags');
TestChild(class'TestMapListEncoder');
}
167 changes: 167 additions & 0 deletions TestMVE/Classes/TestMapListEncoder.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
class TestMapListEncoder extends TestClass;

var string L[1024];
var int P;
var int RangeStart;
var int PrevIndex;
var string PrevCodes;
var string Codes;
var string NextMap;
var string NextMapEnc;
var string PrevMap;
const NA = -65536;

function TestMain()
{
Describe("Basic GameCode Encode");
AddMap("Random");
AddToGame(4);
AddToGame(7);
AssertLine(0, "Random:4:7");

Describe("Game codes are range encoded");
AddMap("DM-Deck16][");
AddToGame(1);
AddToGame(2);
AddToGame(3);
AddToGame(6);
AddToGame(7);
AddToGame(8);
AssertLine(0, "DM-Deck16][:1>3:6>8");

Describe("Game codes are ommited when identical");
AddMap("Random");
AddToGame(4);
AddToGame(7);
AddMap("CTF-Face");
AddToGame(4);
AddToGame(7);
AssertLine(0, "Random:4:7|CTF-Face");

Describe("Maps without games are discarded");
AddMap("Random");
AddToGame(1);
AddMap("CTF-Face");
AssertLine(0, "Random:1");

Describe("Map name start is reused");
AddMap("DM-Deck16][");
AddToGame(1);
AddMap("DM-Decimator");
AddToGame(1);
AssertLine(0, "DM-Deck16][:1|6>imator");

// Describe("Range start is implicitly 0");
// AddMap("DM-Deck16][");
// AddToGame(0);
// AddToGame(1);
// AddToGame(2);
// AddToGame(3);
// AssertLine(0, "DM-Deck16][:>3");
}

function AssertLine(int line, string expected)
{
Finalize();
AssertEquals(L[line], expected, "line "$line$" is correct");
}

function Describe(string str)
{
Reset();
Super.Describe(str);
}

function AddMap(string map)
{
local int i, l;
FinalizeMapEntry();
l = Len(map);
for (i = 0; i < l && Mid(PrevMap, i, 1) == Mid(map,i, 1); i+=1);
NextMap = map;
if (i > 2)
{
NextMapEnc = i$">"$Mid(map, i);
}
else
{
NextMapEnc = map;
}
}
function AddToGame(int idx)
{
if (PrevIndex >= 0)
{
if (idx - PrevIndex == 1)
{
PrevIndex = idx;
return;
}
else
{
FinalizeCodesRange();
}
}
Codes = Codes$":"$idx;
PrevIndex = idx;
RangeStart = idx;
}
function FinalizeCodesRange()
{
if (PrevIndex >= 0)
{
if (RangeStart != PrevIndex)
{
Codes = Codes$">"$PrevIndex;
}
PrevIndex = NA;
RangeStart = NA;
}
}
function FinalizeMapEntry()
{
local string s;
FinalizeCodesRange();
if (Codes != "")
{
s = NextMapEnc;
if (Codes != PrevCodes)
{
s = s$Codes;
}
if (L[P] != "")
{
L[P] = L[P]$"|"$s;
}
else
{
L[P] = L[P]$s;
}
PrevCodes = Codes;
Codes = "";
PrevMap = NextMap;
}
}
function Finalize()
{
FinalizeMapEntry();
}
function Reset()
{
local int i;
for (i = 0; i <= P; i+=1)
{
L[i] = "";
}
P = 0;
PrevIndex = NA;
RangeStart = NA;
PrevCodes = "";
Codes = "";
PrevMap = "";
}

0 comments on commit e158aa1

Please sign in to comment.