Tile-Game Water Physics

Get help using Construct 2

Post » Sun Nov 17, 2013 2:26 am

Hi! Okay, so I made physics to allow water to flow in my tile digging game. The problem, is it's REALLY laggy. It checks the entire 325x125 array every few seconds, and of course that hurts the performance.
So, my question is, is there a better way to do it? Is there a way to make it so it doesn't lag?
This is what I currently have:


Thanks in advance!
B
30
S
8
G
3
Posts: 366
Reputation: 6,302

Post » Sun Nov 17, 2013 3:26 am

it's not entirely clear what you're doing, so it could be a number of things.

Although OR blocks have been changed quite a bit recently, sometimes being slow or not triggering properly. I've stopped using them for the time being.. it wouldn't hurt to see if that's what causing it.

if there's a lot of actions that I don't want to be duplicated you can put them in a function, or just do this in place of the OR block:

+local var: OR = 0
+condition 1:   >set OR to 1
+condition 2:   >set OR to 1
+OR = 1        >actionskeepee2013-11-17 03:28:11
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Sun Nov 17, 2013 3:47 am

@keepee Seems like a good way to replace the OR blocks, i'll try it.
Also, what i'm trying to do is that if a water tile is next to an empty tile or a certain tile, it'll change it to a water tile. I thought it might be the large array being checked but it could also be the OR blocks, i'll give it a go.
B
30
S
8
G
3
Posts: 366
Reputation: 6,302

Post » Sun Nov 17, 2013 5:27 pm

Okay, it seems to have worked, just some small lag spikes here and there, Thanks!
B
30
S
8
G
3
Posts: 366
Reputation: 6,302

Post » Sat Dec 28, 2013 4:56 pm

Well the problem is back, and it doesn't seem to be the OR blocks. I was able to pinpoint the problem to the reading of the large array. Is there any way I can reduce the lag from this? Because every time it goes through the array, the FPS goes from 50 to 18.
B
30
S
8
G
3
Posts: 366
Reputation: 6,302

Post » Sat Dec 28, 2013 5:44 pm

Instead of looping over the entire array maybe you could loop over only part of it at a time? Another idea would to reduce the number of times you read array positions by saving the values of the adjacent cells to variables.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Sat Dec 28, 2013 9:46 pm

@R0J0hound How would you be able to loop over only part of an array?
B
30
S
8
G
3
Posts: 366
Reputation: 6,302

Post » Sun Dec 29, 2013 6:19 am

As a simple case instead of doing this.
[code]Array: for each xy
--- do stuff[/code]

You can instead do your event like this for the same effect. Except you would have to use loopindex("x") and loopindex("y") instead of Array.CurX and Array.CurY.
[code]System: for "x" from 0 to 325-1
System: for "y" from 0 to 125-1
--- do stuff[/code]

Now it can be time consuming to loop over each cell as might be your case since it has elaborate logic that is run per cell. But if you do half the array one frame and the other half the next you can reduce the stall by half.

One such implementation would be:
[code]Global number distribute=0

Every tick:
--- add 1 to distribute

System: distribute = 1
System: for "x" from 0 to 325-1
System: for "y" from 0 to 62
--- do stuff

System: distribute = 2
System: for "x" from 0 to 325-1
System: for "y" from 63 to 125-1
--- do stuff

System: distribute = 2
--- set distribute to 0[/code]

Alternately you could do every other column with something like this:
[code]Global number distribute=0

Array: for each xy
System: compare Array.CurY%2 = distribute
--- do stuff

Every tick:
--- set distribute to (distribute+1)%2[/code]R0J0hound2013-12-29 06:20:04
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Dec 30, 2013 2:39 am

@R0J0hound
Okay so I did this:

and I think it works, but the FPS has dropped to 13-19. Am I doing something wrong? Thanks fr the help!InvaderX2013-12-30 02:42:28
B
30
S
8
G
3
Posts: 366
Reputation: 6,302

Post » Sat Jan 04, 2014 1:43 am

@R0J0hound So, in event 3, I changed wait 0.1 to wait 0, and it became that the FPS is 60 but drops to 25 every 2 seconds. Er, what do I do? Thanks!
B
30
S
8
G
3
Posts: 366
Reputation: 6,302

Next

Return to How do I....?

Who is online

Users browsing this forum: Fenix18, Lancifer and 48 guests