Quote:
I don't know if it is more or less effective to do so on the NES, but a state setup is just naturally how you do programming. It's organized, efficient, and emphasizes code reusability.
It's fun because I'd almost say the exact opposite. Working with gamestate method would be a huge mess because all code would be merged at the same place and doing lots of indirect jumps. This would be hard to modify and unorganized. Plus, the programm have to read a variable, do an indirect jump in function of it, read another, re-do an indirect jump, etc... It's unefficient when you could just jsr to the desired routine straight away. Code reusability ? Well, as long as you use subroutines instead of just in-linging code, there is nothing to worry about that (no matter if you jump to them directly or indirectly).
Quote:
¨
If everything is just a lot of loops in a straight line, what if you want to display the title screen again for some reason? Yes you could jump to the title screen code, but after that the game starts over at level one automatically, right? With a state you can change a variable and go right back into gameplay again.
Don't worry, my loops are *not* in a straight line. If I wanted to show the title screen again during gameplay, I would just make the code that draw the title screen in a routine, and do "jsr DrawTitle" again. I don't see the problem here.
Quote:
I'm not entirely sure I understand the setup Bregalad is talking about...it sounds a lot like there are states anyway, just without a single variable.
Well, I guess there *is* gamestates anyway no matter if you want them or not... but it's just I don't worry about that, and just keep things separed if they must be separed.
Quote:
Of course what is most important is that your game runs quickly and smoothly. Smile
Yes you're right. Konami used the "state" method and does a lot of indirect jumps all the time, yet most of their games runs quickly and smoothly.
Quote:
You can blame bunnyboy, since I jumped into writing my own game after finishing his tutorials. Smile His pong game uses the gamestate method:
http://www.nintendoage.com/forum/messag ... eadid=8747. I'm a newbie so I don't really know if this gamestate method has any advantages over your own.
Well, I don't know what will work the best for you. I think the state method worked because a pong clone is extremely simple to code, and so the negative effect of the game state method didn't show up.
I don't remember if I mentionned it yet, but I originally wanted to make a RPG on the NES based on a "Game State" variable, where 0 = Title Screen, 1 = Menu sub-screen, 2 = Field screen and 3 = Battle. In the NMI I just did an indirect jump (altough I only implemented 0 and 1 before giving up that programm).
It worked very well for 0, as nothing very spectacular had to be done. However, for 1, I had a long hard time to figure how to draw text-boxes with this engine. I made a "sub-game state" variable to get more entry points in my routines, but that was still too limited. In the end I ended up using an indirect jump pointer, and whenever a frame was complete, I set this pointer so that on next frame it would do an indirect jump to it. But even that was a headache to handle, so I gave up and made another project
That was long ago tough so I don't really remember the details. Maybe what I wrote above isn't exactly correct also. I think I thrown away the source so I can't even look back to see why that was such a pain. I was a newbie to programming back then, so how painfull this was could also be done to my lack of programming skills.
However, more recently I found myself having headache with enemy AI because I had only one entry point, and needed to do lot of switch and if/else branches in function of enemy's state variable. I hated it because while it worked fine, each time I wanted to modify the code to add something to enemy's AI, it was a headache. Now I found a way to trick the stak in order to have a variable entry point, and everything fixes up
There is sill the inconvenient that if I wanted to call a routine in all cases no matter the enemy's state, I had to do it only once before the indirect jump with the old system, and I have to do it a lot of times with the new. However, again a simple use of the jsr opcode can fix that.
Quote:
What if you have some side scroller levels and some racing levels, with different drawing and input routines?
Well, you'd probably have only one routine reading the controller, but a different engine reading it and interfacing with it.
As for drawing routines, they don't really need to be different. I have a routine that allows me to draw up to 2 name table rows + 1 attribute table rows in NMI (or less if I need less), and another that allows me to draw a metatile without changing the rest. That does all the drawing for me and I never felt any limited with that (other than what the hardware limits you). If I were to do completely disconnected engine where more special screen updates would be needed, I guess I'd still opt for different NMI routines.