October 19, 2021, 08:29:45

Author Topic: when to create game objects  (Read 2044 times)

Offline Ashmoor

  • Full Member
  • ***
  • Posts: 112
when to create game objects
« on: March 26, 2018, 19:13:52 »
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?

Offline Derron

  • Hero Member
  • *****
  • Posts: 3664
Re: when to create game objects
« Reply #1 on: March 26, 2018, 20:56:53 »
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

Offline Matty

  • Hero Member
  • *****
  • Posts: 1369
    • MattiesGames
Re: when to create game objects
« Reply #2 on: March 27, 2018, 02:07:56 »
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.

I eat cheese in the trees when its eight degrees

Offline Ashmoor

  • Full Member
  • ***
  • Posts: 112
Re: when to create game objects
« Reply #3 on: March 28, 2018, 02:29:34 »
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?






Offline Matty

  • Hero Member
  • *****
  • Posts: 1369
    • MattiesGames
Re: when to create game objects
« Reply #4 on: March 28, 2018, 04:05:36 »
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.
I eat cheese in the trees when its eight degrees

Offline IanMartin

  • Full Member
  • ***
  • Posts: 122
Re: when to create game objects
« Reply #5 on: March 29, 2018, 12:00:37 »
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/

Offline Ashmoor

  • Full Member
  • ***
  • Posts: 112
Re: when to create game objects
« Reply #6 on: March 30, 2018, 01:24:21 »
I'll try to load everything at the start of the game and I guess I'll optimize if I run into trouble.

Offline Yellownakji

  • Sr. Member
  • ****
  • Posts: 253
  • No.
Re: when to create game objects
« Reply #7 on: March 30, 2018, 14:43:55 »
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.

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1290
Re: when to create game objects
« Reply #8 on: March 30, 2018, 16:49:52 »
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 ?!
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline IanMartin

  • Full Member
  • ***
  • Posts: 122
Re: when to create game objects
« Reply #9 on: March 30, 2018, 23:42:54 »
Quote
What ? 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/

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1290
Re: when to create game objects
« Reply #10 on: March 31, 2018, 07:47:14 »
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.
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal