Mulitple Game Loops?

Started by
5 comments, last by macmanmatty 5 years, 11 months ago

I'm still working on large RPG top down   game  that has  very large maps 500 x500 32 x 32 px  tiles  and there 5 of  these "land maps" each with three large buildings  of a   "200*200" tiled  map some with more than one map for each floor.  and shops taverns/ blacksmiths/ stables  / houses  with 20 x 20 or so tile maps.  Since you can have / control  more than one unit to optimize  the game  I was thinking  each map  ( land map, shop, tavern,  budiling ect.)  should have it's own game  loop. There would be a button created for each map you have units on to switch to that map   and when you switch them  one loop is paused  and the other one is activated? Is this a good idea?

Advertisement
31 minutes ago, macmanmatty said:

when you switch them  one loop is paused  and the other one is activated? Is this a good idea?

Pausing all the game loops and keeping only one active is nothing different than having a single loop handling it all so I don't see what you would gain from doing this. "Multiple" game loops are more commonly used in editors such as 3dsmax to display multiple viewport and still, it's usually just one loop that dispatch the work evenly accross all the viewports.

 

Your efforts would be much better invested in looking for something like a cache and level of detail system. For example you could initially load a very low resolution version of your textures / 3d models and display it first while the full detailed version is loading.

 

You could also cache some levels that have been previously loaded. When switching between your characters, don't automatically release all the level resources unless it is really necessary to free some resources. That way everything remain loaded if you switch back to that character.

 

We could give you a better direction to look at if you can tell us exactly what part of your level loading need to be optimized.

Is it resource loading from disk? Is it a procedural level generation and the logic of building the level is the bottleneck?

Each map should have it's own update / render logic, but not necessarily a game loop (that consists of physics, object updates, player input, etc.). In your main game loop just call activeMap->Update() / activeMap->Render() as an example. Also, only render what you can see and nothing more. You shouldn't be looping through all of those tiles every frame.

yes but if you can have multiple  units  how do only render what you can see? I envisioned having maps like  age of empires or Ceaser III where you could see the whole map and use a scroll pane  to  move around it and select units and zoom in and out of course.  Of course only one map would  be active at time. This is a 2d  orthogonal  tiled game with low quality graphics already.  I don't need to optimize code yet just wondering if each map having it's own game loop object  that can be paused  and started (they way I'm currently doing it )  is better  or having single game loop  would be better?

 

The previous  bottleneck  neck was the drawing of 400 * 400 tiles but  I was using JavaFX (not the best for games I have come to find out )  and a grid of stack panes with crappy game art   but I'm now switching  to  libGDX  and 2d tiled map with better game art  which is supposed to be  Faster and better for games.

The units can still be updated, but if they're out of view then there is no reason to draw them. You could create a 2x2 buffer around the area you're drawing to account for the panning, zooming, etc. I don't consider this a premature optimization since the number of tiles x number of layers can quickly add up and degrade performance (see below for an example of this). Like ChuckNovice mentioned, you are essentially doing one game loop either way. I think the way you are managing how the updates/rendering is done needs addressed. Can you give some pseudo code on how you are currently doing this? I can give better advice once I see that.

libGDX is good, but drawing every tile is going to bring any system to it's knees. Think about it this way, you have a map that is 500x500 tiles with each tile being 32x32. That's about 250,000 tiles being drawn per loop. Now if we do the optimized method then for a 1920x1080 resolution you would only draw 2,232 tiles (62 x 36) per loop - (1920 / 32) x (1080 / 32) resolution with the 2x2 bleed area.

 

Here is an example as well as the article:

https://github.com/mozdevs/gamedev-js-tiles/blob/gh-pages/performance/offcanvas.js

https://developer.mozilla.org/en-US/docs/Games/Techniques/Tilemaps (see the performance part)

 

Either way, show the pseudo code of what you're thinking.

two questions since units require food  and water to live  should  I even allow   the  player to have units off the map? and If if I do  what about the enemies  that may find them and attack them? I was going  pause the non viewed maps paused but that makes little sense either.

 

I realize drawing the whole map  at once will not work.  But is there any way  to link  orthogonal camera view to  the sliders on a  scroll pane? Otherwise I will just go with click and drag

 

 

 

 

 

This topic is closed to new replies.

Advertisement