when to create game objects

Started by Ashmoor, March 26, 2018, 19:13:52

Previous topic - Next topic

Ashmoor

When do you guys create game objects? For example an options dialog window, do you create it when it's needed or at the start of the game and only display it when it's needed? What is considered good practice?

Derron

I create once it is needed and keep it if it is needed very often.


The option dialogue is eg. only needed during ... setting up things. So I would create it when the user clicks on the "settings button" (aka before calling "settingsdialogue.open()").
As soon as the settings get applied - the window get closed and you can get rid of the dialogue. If the user clicks it again, then create it again.
This is a rarely used thing so no need to keep it "in memory".


in general: if things can get out of scope (get "no longer needed") you can get rid of them. BUT if things are used every x minutes and creation time is 10 seconds, then keep it.
If things need a reset every "restart" (level started again or so) you might consider not initializing/resetting them each time but just creating them "afresh". This keeps maintenance more easy as you do not need to take care of "have I reset everything" ?


bye
Ron

Matty

Depends on the hardware.

With a PC / Desktop - many things can be created on the fly and deleted on the fly (characters, bullets, particles etc - that sort of thing)

With an Android Device - because of the garbage collector causing stutters you may need to create all objects, even temporary ones like bullets and so on, put them in a pool and re-use them and simply hide them from view when they are not in use.


Ashmoor

Thanks guys. I am currently developing for PC.

Now I have more questions. What happens if I load lots of images for a 2d game and run out of memory, are older images erased from the memory to make room for new ones or the new ones will not load until there is space available?






Matty

Depends on the software...

I imagine it is technically impossible to run out of memory as if you do you will start using the hard drive for memory access, which is dead slow....this is just a guess - but I believe the actual memory will be full and the system will start using hard drive access for paging files and memory and so on which will slow your whole system to a crawl...other things may happen first though before you get to that point.

IanMartin

I load everything at the beginning of the program (Windows). 
I hate it when I'm playing a game and I shoot or swing a sword and there's a noticeable delay and stutter the first time as it loads the sound from the disk.  This is not very professional and I see it even in AAA games.   
I think people are more tolerant of a bit of a load at the beginning of the game.  You can disguise load times by showing titles, logos, etc.  Don't make people watch 30 seconds of logos with nothing happening in the background, and then wait 30 seconds with a dumb "Loading...please wait" screen.  Again, I see this all the time in AAA games.  You can load for 5 seconds during an epilepsy warning, for instance.
Platfinity (made with BlitzMax) on Steam:
http://store.steampowered.com/app/365440/Platfinity/

Ashmoor

I'll try to load everything at the start of the game and I guess I'll optimize if I run into trouble.

Yellownakji

Most people, even budget-budget PCs, have at least 4gb of ram.   So, it's perfectly acceptable, especially for 2D, to load everything at once.

I assume your target-audience is modern hardware in terms of support so it should be perfectly fine.     All my images are very beefy and i only take up around 80mb ram, which is nothing in this day and age.  Even if you were to not load everything at the bootstrap of your software, you can still get away with it.   My old PentiumD loads huge crap in a blink.

I've been trying to figure out myself on how to "unload" something since i am targeting older hardware as a minimum.   but i haven't gotten to the point where i absolutely need a function like that.  I think you'll be fine tho.

RemiD

Quote
I hate it when I'm playing a game and I shoot or swing a sword and there's a noticeable delay and stutter the first time as it loads the sound from the disk
What ? Once you have loaded a sound and have an handle / reference to use it, normaly it should be in the ram ?!

IanMartin

QuoteWhat ? Once you have loaded a sound and have an handle / reference to use it, normaly it should be in the ram ?!

Yeah, there should be no stutter if you load everything before having the character running around doing things.  I don't know why you'd want to load in the middle of gameplay, but I've seen it done over and over.  Mostly in AAA, for some reason.  Action RPG games mostly.
Platfinity (made with BlitzMax) on Steam:
http://store.steampowered.com/app/365440/Platfinity/

RemiD

It could be a "big" unique image / texture / surface going from the ram to the vram, this could definitely increase render time and cause noticeable slowdowns.