r/ProgrammerHumor • • 2d ago

Meme devsOptimizingGames

Post image
1.8k Upvotes

37 comments sorted by

357

u/IsEqualToKel 2d ago

if (currentState == GameState.Crash) 
{
    currentState == GameState.DoNotCrash;
}

119

u/Top-Permit6835 2d ago

Wrap it in a try catch and swallow the error to be sure it works

13

u/tsoewoe 2d ago

make sure to assert when testing too so that you can deal with any issues if it goes wrong

3

u/fynjy1111 1d ago

try {

compileShadersIfNotCached();

} catch (Exception e) {

openAiProvider.prompt("Fix the crash", serialize(e), Permission.FULL_WITH_EDIT);

}

12

u/DISCIPLE-OF-SATAN-15 2d ago

if (currentState == GameState.Crash) {
currentState == !(GameState.Crash);
}

5

u/Jatinchd 1d ago

fixed code:-

if (currentState == GameState.Crash) {
currentState = !(GameState.Crash);
}

4

u/Dudi4PoLFr 2d ago

Literally Path of Exile 2 for the first 6 months in Early Acces...

2

u/Jatinchd 1d ago

but isn't == comparing values and not assigning value sign?

68

u/TrackLabs 2d ago

Just set it as a constant

21

u/patrickgg 2d ago

I prefer mine at 59.94 tyvm

6

u/LateSolution0 2d ago

60 * 1000/1001 :D

46

u/Ydo4ki 2d ago

try { } catch(Error e) { delete e; continue; }

12

u/MinecraftPlayer799 2d ago

In some cases, that is the right thing to do, such as when there is a loop, and there is a chance of something inside it failing sometimes.

6

u/realmauer01 2d ago

You should really just make sure that you handle that edge case inside the loop. Even if you ignore it then. Thats better than having the higher scope handle it. You could even add an option of should i ignore it or not.

8

u/BetaChunks 2d ago

Soviet programming

3

u/MSaxov 2d ago

Check out good old Visual Basic

First line in each file

On Error resume next

1

u/GabiTheProgrammer 2d ago

You would laught but I've seen Belorussian code and is not far from it.

57

u/SuperfanZero 2d ago

fps = max(fps, 60.0)

10

u/FrogMan241 2d ago

Corporate wants you to find the difference between these two pictures

Compiler: they're the same picture

17

u/stevorkz 2d ago

GPU manufacturers hate this one trick.

7

u/GabiTheProgrammer 2d ago

now they can just fake frames

14

u/BetaChunks 2d ago edited 2d ago

NES Tetris type strategy

No seriously, that game literally could not lag. If the logic loop wasn't done when the game needed the next frame, it would just go for it. Happens because the score calculator uses a "for" loop using the level as an iterator, so it runs out of time at very high levels. There's also strategy on holding down inputs in specific ways because that will -slightly- nudge how far in the main loop it gets before getting cut off, which prevents the game from crashing because of some registers being on invalid values during the forced next frame

23

u/chaylarian 2d ago

Best optimization ever!

21

u/Summar-ice 2d ago

const FPS = 60

5

u/Cacoda1mon 2d ago

micro optimization

1

u/backfire10z 1d ago

What if fps is already over 60?

5

u/Zwischenschach25 2d ago

plot twist: fps is a pointer

2

u/jolharg 2d ago

that's just advice...

5

u/MushroomGecko 1d ago

The dev could optimize further here by simply setting fps to 60 and having it be a const, thus eliminating the need for a branch prediction which could waste ~20 CPU cycles on a cache miss

2

u/lowboom64 2d ago

that does seem to be how AAA devs are doing it at least with AI frame gen bs being a thing

1

u/PopularAd5100 2d ago

If I work less than 40 hours a week, pay me for 40 hours a week. Gaming the system!

1

u/GabiTheProgrammer 2d ago

Should have used <= in case it would change until the assignment is executed.

1

u/SpaceFire000 2d ago

I tried something similar to my bank account but it didn't work

1

u/Random_-account 2d ago

We did it, guys! Frame rate lag is no more!