How do I solve perf issues (real time tilemap grid update) ?

Get help using Construct 2

Post » Fri Oct 07, 2016 10:54 pm

Hi everyone !

I have big performance issues with my current game project (a real time tactical game, with terrain invasion (like Splatoon or Starcraft's Zerg creep !)).
100% CPU usage and 4~10 FPS. :?

The game area is a 40x40 grid, made of 32x32 pixels Tiles (1280px wide)
There is a 3D Array to save Race (humans, aliens,...), Type (hill, river, building,...) and Discovery Status (yes or no).
And there is a Fog of War function : units explore to reveal the map, and all the tiles = PlayerRace are auto-discovered (on layout start if any, or at anytime).
The goal : units move on a yet undiscovered and neutral map, and they can explore and invade tiles (=> the tile image changes according to the race it belongs).

I first created the grid with sprites (using several animations and frames to display the various informations but there should be 5 races, with a lot of tiles each. One tilemap per race seems the best deal, for me). For now, I work with a single TileMap containing the 6 Race Color Tile Sprites and Fog Tile Sprite.
But as I'm learning more and more about C2, I want to improve my event sheet with less events, and more complicated stuff (loop). I thought it'd be a good idea to use tilemap and For Each (already used and approved for my training game JumpLin Game (check my profile)).
Now I don't know what to do to make this system work.


The current code :
(on start of layout, the array is filled with a "0" value. In 1D, it's for neutral ownership. In 2D for the basic environnement. In 3D for "undiscovered" status. And after that, the grid is filled with tiles, all neutral for now).

Screenshots :
The CPU killer code :
Image

Few adjustments. No more 100% CPU, 15FPS... but no tiles displayed X)
Image

For Each XYZ element :

___ check Z = 2 ||||||||||||||||||| Set Fog of War Tile Sprite
___ check value = undiscovered

___ check Z=2 |||||||||||||||| Set Race Tile Sprite (according to Z=0)
___ check value = discovered

___ check "Race on Tile = Player Race" ||||| Set Tile to discovered (in Z=2)

___ For Each FamilyUnits
________ -3 < X > +3 ||||||||||||||| Set Tile to discovered (in Z=2)
________ -3 < Y > +3


All the planned functionalities are not yet added and it already doesn't work ! X)
What can I do please ?

Go back to Sprites, animations and frames ? (I don't think the problem is here...)
Improve my usage of "For Each" loop ?
Don't use a single Array ?
Functions ?


Thank you for your help ! I hope i've been clear (sorry for my bad english).
;)
B
6
S
2
Posts: 3
Reputation: 410

Post » Sat Oct 08, 2016 11:14 am

Not a 'functional' capx. Just demonstrating how to pick tiles, change tiles, pair an array with a tilemap, avoiding huge loops each tick ....

https://www.dropbox.com/s/0pxbwb6i5q4x7 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Oct 08, 2016 1:24 pm

Thank you !!!! That's exactly what I was looking for :D

Using local variables and loopindex to apply changes only on the concerned tiles, and apply tiles on an *area*.... I didn't know these techniques yet. Brilliant ideas !
Thanks again. Go back to work :)

However, I have few questions left :

- The "For Each [Family]" pick all objects of the family and apply the action every tick. No need to add a "Every tick" condition. That's right ?

- therefore, there's no need to set the same events on start of layout, as soon as there are active for every tick ?

- Is it normal that the game runs slower in debug ? Moreover, I have 10fps with "inspect" window opened, and when i switch to "profile" window, 120fps are back. Usual too ?
B
6
S
2
Posts: 3
Reputation: 410

Post » Sat Oct 08, 2016 4:34 pm

More optimised trail. Now there is not 1 huge array iterating, max 12 tiles change in 1 tick.

https://www.dropbox.com/s/m4aeqgbc28si3 ... .capx?dl=0

'For Each' runs every tick. And that is a loop each tick.
In my capx, things got prepared in the 'start of layout'. The situation how it is before the player starts moving. That is essential. It also cages things that have to be done only once, effectively to only once.

You will never ever see a good representation of the fps on the inspect page in the debugger. That is actual (Heisenberg principle) very normal. The debugger is a program that runs in the same time and in the same browser as the game. If the debugger has to calculate a lot, like representing an array each tick, the tick (containing games actions + debugger actions) gets longer, leading to a smaller fps.

Use 'watch' or 'profile' to measure speed.
Use 'inspect' (or things added to watch) to inspect values.

I also have to add that when the debugger (in inspect mode) drops the fps to much, collisions, frame independed actions and frame independed behaviors will actual break.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Oct 08, 2016 6:30 pm

Wow, this second file is more complicated... X) I didn't understand what you're doing... But anyway, the 1st one helped a lot and unlock my dev process ^_^
It looks more complicated for almost the same result... What are the differences please ? And how could it help me in my game ?

On start of layout, you place buildings, and unlock fog of war around friendly building. But after that, all the things with wallclocktime and Array... Didn't get it X)
Are you adjusting the array size and values according to the tiles (type and position) around the player ? If so, that's clever. But it didn't suit to my game, where there are several units (like any tactical/RTS game, like Men of War, Company of Heroes, Starcraft,...)

And thank you for your answer about For Each and Debug. I understand better now :)
This project is very important to me. So... if I become popular with it, I will not forget your help ! ^_^
B
6
S
2
Posts: 3
Reputation: 410


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests