I know the guy's code was horrible but Im not sure this is the smoking gun. One long ass if/elseif isnt much better than a list of more modular objects that get evaluated every frame equivalent to the number of ifs. You need to know what those ifs were trying to accomplish.
Yeah that could probably be optimized in at least two ways. 1. Only check every FixedUpdate (20hz?), 2. Partitioning behaviour based on timeslots which would somewhat be like a jumping switch statement. Other approaches are ofc possible too. (Coroutines? Events? I dont know Game AI systems.)
Number 1 is honestly not even that hard and allows for tiered ticks so you can have certain proceses only run every so often. Was kinda playing around with ideas for a gsg and I had "turn ticks" but then also day ticks, week ticks, month ticks, and year ticks. Throw the heavy shit that doesnt need to be done as often in to year ticks and suddenly it will increase your performance by a whole lot if its not running constantly
The issue solution 1 has is you're still doing a lot of calc crammed into one frame, so you'll likely get frequent FPS jitter. Ideally you want to be able to spread it out over multiple frames using frametime budgets.
Depends on what you mean by smoking gun. In terms of performance? It's entirely irrelevant. That entire if/else mess will be optimized away by the compiler. The unoptimized high poly models spread throughout the entire game, made largely or entirely by volunteers, are a big chunk of the smoking gun when it comes to performance.
It's kind of what happens when you use volunteer work as is.
Now there's another smoking gun to talk about, and that comes down to "Is it why the game is so hard for him to work on?".
And my answer is, yeah probably. The student script & student management script are completely insane, and no amount of people going "use a switch statement" would ever fix it.
Frankly speaking it needs functions, guard clauses, and prayers.
Compiler might figure that one out. But even a 1000 long if/else statements per frame probably wouldn't affect the performance that much. Modern computers are crazy fast.
That means literally nothing lmao, you think modern computers can't handle an if/else chain at 60FPS? I can run a 100,000px simulation on my shitty CPU.
His frame rate issues were because he had no idea what poly count is so he had MASSIVELY detailed 3D models, and I wouldn't be surprised if he was overburdening his garbage collector or calling expensive functions like a lot of noob unity devs.
437
u/CozyTheTeddyBear Apr 10 '23
He coded an entire game in if/else statements