My main issue right now is creation of a new ArrayShuffler instance each second. I'm trying to streamline my code and couldn't really find much info on the new() method. Will this be safe to use in such a context? Will the object created with new() be destroyed and cleaned up after EachSecond()? I don't want to clog the memory or waste resources, and rewriting the array shuffling code in multiple places just feels wrong. If there's anything else you'd change in the code you see below - please let me know! Thank you for your time and effort.
Code: Select all
class ExampleClass : Actor
{
int internalTick;
override void Tick()
{
Super.Tick();
internalTick += 1;
if (internalTick >= 35)
{
internalTick = 0;
EachSecond();
}
}
void EachSecond()
{
Array<int> intArray = {0, 1, 2, 3};
ArrayShuffler aShuffler = new("ArrayShuffler");
aShuffler.intArray.Copy(intArray);
aShuffler.ShuffleInt();
intArray.Copy(aShuffler.intArray);
}
}
class ArrayShuffler
{
// WHAT IS MY PURPOSE?
// YOU SHUFFLE ARRAYS.
// OH MY GOD.
Array<int> intArray;
void ShuffleInt()
{
if (intArray.Size() > 1)
{
for (int i = 0; i < intArray.Size(); i++)
{
int rID = random(i, intArray.Size() - 1);
int rOrg = intArray[i];
intArray[i] = intArray[rID];
intArray[rID] = rOrg;
}
}
}
}