recommended ways of storing game entities and state game structure

Started by
14 comments, last by mickd 12 years, 1 month ago

Something like ArrayList is typical. This will work well provided you don't have TOO many things.


I prefer LinkedList for this type of Collection, but you have to use it correctly to get the performance benefits it would offer. Granted the performance benefits would really only exist when inserting or removing elements.
Advertisement

Oh, I should have probably been more specific about this but the keyHandler and mouseHandler classes just hold a hashmap of which keys were pressed (for the keyHandler) and which location on the screen was clicked (for the mouseHandler). They don't handle the events (the JPanel uses key bindings and a mouse listener to do this), more so just store what event was triggered. Every game state would need access to these since I have to be able to processEvents in each game state. Same with each component of the screen (inventory, etc).


Ah ok, that makes more sense.

One of the things I've learnt in the last 15 months working on my current project is that I only ever come up with the "right" design for something at first attempt about 1% of the time. Sometimes it's not bad but needs tweaks. Other times it's awful. My current game engine has evolved a lot as I've added new functionality and decided some part of the design was flawed. I've actually spent a fair bit of time rewriting existing code, but each iteration the system becomes better and more logical in my opinion. So I've learnt to not stress too much about having a perfect design from day one.

Generally speaking though, one of the metrics I use to tell if something isn't "right" in my code is that there are ALOT of interdependencies going on, ie many references to other classes that are passed through into other classes. There's not always an obvious elegant solution however. Sometimes you just have to live with it. :)
[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
Thanks for the replies!

I've already change my design slightly (still feels a bit off, but it's slowly getting better). I'll definitely just keep working on it to help discover more design flaws that I can work into fixing in the next iteration of the engine. It's been a great learning experience already.

Did you guys have any comments specific to storing textures? How would your draw functions in your various game entity classes access the textures? Should each class be storing a reference to it's own texture for binding and rendering? Should they be centralized in any specific way? Is it a bad idea to have a single class with static variables and functions to hold the texture files and control binding?
I would definitely cache your textures. Creating and destroying Texture objects all the time is a great way to kill your frame rate. I like the idea of having a centralised Texture Cache that's responsible for creating and destroying Texture objects because I use an "on-demand" resource allocation strategy. Ie, on render, I'm checking if the resource is allocated or not, and creating it as required, rather than allocating everything on load. This also allows texture re-use if objects are using the same texture.

You can then get a bit more advanced with reference counts to deallocate textures that you haven't used in a while to manage your video memory a bit better.
[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler

Also, I would love some extra input on the second question ;)

You may find this useful: General Game/Engine Structure


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

@YogurtEmperor Not only did I find that useful, I read it when I found it on google from an old post you made! Thanks!

@Postie Yep, sometimes I feel as if I just need a confirmation from others that what I'm doing is within reason. Thanks as well!

This topic is closed to new replies.

Advertisement