Bruh, 2023 has gone and we didn’t received any decent update in workshop with QOL changes and improvements.
We din’t received even actions/conditions to track newer gamemodes.
Complex pathfinding systems, eg A* uses many arrays with nested array values containing all possible paths.
Also some specific context where i should reserve an array of arrays that contains specific state. Eg: Zeny discord orb, now you cannot attach orb to same target within 7 seconds, you cannot do this in a 1D Array, instead you must split into two variables (lastOrbEntities
and lastOrbEntitiesTime
)
Do a for loop decreasing time every fixed time eg:
// rule conditions:
// - player is alive
// - count of (lastOrbEntities) > 0
// 30 tickrate = 0.033
// 60 tickrate = 0.016
const timeRate = 0.033;
// we copy the array to ensure thread-safety
// basically we modify a copy of values, and after iteration
// we commit the changes, instead of commiting directly
// to referenced variable
// this will ensure daraArray must have same length during for iteration:
var dataLen = min of(count of(lastOrbEntitiesTime), count of(lastOrbEntities));
// this is reason multi dimentional array & custom data types MUST be implemented,
// so we don't need split two arrays to store values.
var dataTimes = array slice(lastOrbEntitiesTime, 0, dataLen); // ensure same size
var dataEntities = array slice(lastOrbEntities, 0, dataLen); // ensure same size
for(var i = 0; i < dataLen; i++)
dataTimes[i] -= timeRate;
if (data[i] <= 0) { // time out, so we remove directly to reference array.
remove from array by index(lastOrbEntities, lastOrbiteratorIndex);
remove from array by index(lastOrbEntitiesTime, lastOrbiteratorIndex);
}
delay(timeRate)
loop if condition is true;
In other words if we use a real programming language example (i will show in C#, as my main working language now) we can reduce alot code to do this and even a efficient way to handle this:
readonly struct EntityId {
// ...implementation...
}
enum OrbType {
Good,
Bad
}
class OrbState {
public EntityId owner;
public EntityId target;
public OrbType type;
public bool active;
public float time;
public void Update(float dt, Player targetPlayer){
time -= dt;
if(time <= 0.f) {
time = 0f;
active = false;
}
// add heal/ defub status to target player
}
}
class OrbManager {
public List<OrbState> states = new(Lobby.GetMaxPlayers(Team.All));
public OrbState FindOrb(EntityId target, OrbType type) {
foreach(var orb in states){
if(orb.target == target && orb.type == type) {
return orb;
}
}
return null;
}
// ensure thread-safety
OrbState[] GetOrbs(){
lock(orbs){
return orbs.ToArray();
}
}
public void Update(float dt){
foreach(var orb in GetOrbs()){
// orb is not active, skip ticking
if(!orb.active)
continue;
if(!Match.TryGetPlayer(orb.target, out var targetPlayer)){
// player is not in the match or refs was removed.
orb.target = default;
orb.active = false;
orb.time = 0;
continue;
}
orb.Update(dt, targetPlayer);
}
}
public void AddBadOrb(EntityId owner, EntityId target, float timeout = 5f)
{
lock(orbs) {
orbs.Add(new OrbState() {
owner = owner,
target = target,
time = timeout
});
}
}
}
void Update(float dt){
// use ECS based example, because overwatch is ECS based too.
var orbManager = RemotePlayer.GetComponent<OrbManager>();
orbManager.Update(dt);
}
The problem is: If you know the size of array, multidimentional arrays is a quite simple task. Just use syntax array[x * y * z] = value;
But when you should add/remove items from multidimentional array this will not help.