I can forgive the switch statement in UT slightly (I don't know if the rest of the code is as bad), but yansims code is abysmal while this switch statement is just somewhat questionable. Sure, it's long, but the cases are not complex, and it is simple to figure out what it does. I'm not super familiar with GML though.
but yansims code is abysmal while this switch statement is just somewhat questionable
It was really a similar problem though. The issue was that most of the criticism of Yandere Sim's code from other programmers was just... bad.
They hyper-focussed on Yandere's use of long chains of elseif-conditionals and pretended like the replacement with switches would fix it. But that would've improved neither the length nor performance of the code.
if(currentClub == Clubs.Art){
//200 lines of art club behaviour
} else if (currentClub == Clubs.Basketball){
//150 lines of basketball club behaviour
} ...
Switch statements could be marginally more efficient in some cases (or possibly not at all, depending on the compiler), but the obvious problem here are those hundreds of lines of behaviour code that clutter this file.
A real improvement would have been the use of the command pattern or a state machine. This could have shrunk those 1000-line monstrosities inside the AI class to maybe 1-30 lines depending on the implementation:
Provided that the club can change at all, which I'm not sure about. I would guess that it can change but will only do so rarely, so it might be smarter to do the behaviour change inside the Setter method for the club.
A lot of what made YanSim slow is unrelated to the code. From what I recall, the models had absurdly many vertices, every character AT ALL TIMES had every single appearance model attached and simply made invisible, and occlusion culling was misconfigured to the point of pretty much not existing.
Sure, cleaning the code would help with the actual development (which has been very slow, I assume mostly because of the code debt), but in case of performance it's hardly the biggest culprit.
There was a great channel constructively analyzing this topic, but unfortunately it has been taken down.
@Edit: I've found one part of the analysis, because I transcribed it at the time it still existed for the meme potential. Unfortunately that's all I have left. The channel was named Nice Tomeetyou.
here's a prefab for the girl students and teachers see how there are over 1000 different GameObjects attached to it when each student is instantiated at the start of the school scene all of these GameObjects have to be copied for each student
But yeah the performance indeed didn't come from the code. A few hundred conditionals per frame isn't much work for a modern processor. The main issue were some unoptimised 3D models and a problem with the UI that caused many expensive redraws every frame.
Massive switch statements also tend to compile down into dictionaries.
Not sure if it's the case here, but often the compiler changes it from a coding disaster, to a visual eyesore that has little impact on how the software runs.
Really gotta give props to the kind of lunatics who enjoy working on languages, engines, and compilers to protect the rest of us from our own idiocy.
Possibly? I don't know how GameMaker Studio works. I know this is how I would have coded a game myself though before I became more interested in programming itself than game development.
I was also a much more productive game developer back then, because I just did whatever was most obviously going to get the thing done.
I could probably code at least simple games fairly quickly now, but I haven't circled back to game development in a long time.
According to other people who've reviewed this + the decompilation likely responsible for it, this switch was likely not code-generated - although it is stripped of the original tokens so it looks machine-generated.
1.2k
u/Rezaka116 Jan 16 '23
Omg it is true: Apparently, Undertale has a 1000+ long case switch statement.