So I found out there was a decompilation project for Harvest Moon 64 and whoever programmed the original game loved nested if/switch statements because there is a ton. Granted, the game is programmed in C, and I'm used to OOP, but I don't understand why they couldn't just use data tables and function pointers. It's almost as if YandereDev wrote this.

github.com/harvestwhisperer/hm

@xianc78 i used way too many in my game lol, could have lessened it by a lot if i knew more about general coding practices instead of just making things work in rpg maker. no way am i going back and changing all of it now lol but some of the systems are a bit of a mess xD

@beardalaxy When you have a bunch of if-statements like this, it's probably better to have an array or dictionary of function pointers because the CPU can just go to the address of the first value of the array + the offset and then call the function based on the address of the function in the table. On the other hand, if-statements require the CPU to repeatedly calculate conditions which is much less efficient.

@xianc78 @beardalaxy Calculation is what CPUs do best. Jumping across code memory in a way that makes it hard for the compiler, the cache, and CPU to optimise around however isn't

Follow

@xianc78 @beardalaxy Knowing what is going to be faster with todays hypercomplex hardware is a guessing game at best

In either case, it's the wrong point to make. Write sane, readable, maintainable code first. Optimise then only later if it is clear there is a reason to. The compiler will usually do a better job of it anyway

· · Web · 0 · 0 · 1
Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.