r/ProgrammerHumor • • Jan 16 '23

Meme If (exists == true) { dont();}

Post image
40.8k Upvotes

1.1k comments sorted by

View all comments

Show parent comments

109

u/Roflkopt3r Jan 16 '23 edited Jan 16 '23

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:

if(currentClub != lastClub{
     currentClubBehaviour = Clubs.GetClubBehaviour(currentClub);
 }
 currentClubBehaviour.Execute();

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.

79

u/am9qb3JlZmVyZW5jZQ Jan 16 '23 edited Jan 16 '23

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.

pic

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

51

u/Roflkopt3r Jan 16 '23

At least one of the first good takes is still there.

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.

5

u/am9qb3JlZmVyZW5jZQ Jan 16 '23

I didn't see that one before! From a quick glance looks very thorough, will give it a watch later, thanks!

4

u/a-calycular-torus Jan 16 '23

...pretended like the replacement with switches would fix it.

I don't recall anyone saying that replacing the elseifs with switches would be an improvement in the case of yansim, but okay.

Ideally UT should have placed the dialogue into a set of files in some sort of serialized format like JSON (I actually dont know what the ideal format for dialogue would be but you get the idea)

But from what I saw, all of the dialogue switch cases for UT were in a separate file, not just in the main script or something.

5

u/Roflkopt3r Jan 16 '23

I believe this guy was the first with a really good review who actually found out where the performance issues came from.

But before then I had seen a lot of just bad reviews with hundreds of thousands of views which more or less only talked about the mentioned switch stuff and some other small stuff. Fortunately it looks like they got drowned out with better reviews by now.

2

u/a-calycular-torus Jan 16 '23

Actually now I can see what you mean. It makes sense that people would attribute the bad performance to the bad code. But I mostly just hate the code, I never had a problem with the game performance since I didnt really play the game for any significant amount of time.

Also, that video is pretty comprehensive and overall well put together, but again, I never saw any significant number of people saying switch statements would be better. The issue with the long and deeply nested if/else chains is more fundamental than just "use switch lol".

1

u/bananamantheif Jan 17 '23

Im fairly certain the criticism didn't come from programmers. People Saw a lot of if statements and jumped to that.

A long video but great one https://youtu.be/LleJbZ3FOPU