Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Game fps severely drops
Started by Blex Jan 20 2018 12:40 PM

39 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Hi everyone! I had a question about fps in my game.

 

So, when I would play about a minute of it, the fps would start dropping immensely going from 60 to around 30. I changed the game to 30 fps wondering what would happen, but now it drops to 15. 

 

If anybody has any tips as to how I should go about fixing this, that would be great. Please ask for any more information if need be.

 

Thank you.

 

PS I am using PonyWolf's Visual Monitor to see my FPS, Texture and System Memory, and # of Stage Objects on screen. So I could provide these values if necessary.

 

 



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

sounds like you're creating too many objects w/ or w/o bodies.

 

can you reduce the number of objects in your game/level as a test to see what happens?

 

Yes, provide the values you mentioned

 

 

Simulator (Win or OS X) or device (which specific device)



[TOPIC: post.html]
#3

happymongoose

[GLOBAL: userInfoPane.html]
happymongoose
  • Contributor

  • 349 posts
  • Corona SDK

Are you deleting any objects that are no longer needed when they're off screen?

 

Or - for some reason - are you running two instances of your scene at the same time?  It would explain why the frame rate halves.



[TOPIC: post.html]
#4

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

sounds like you're creating too many objects w/ or w/o bodies.

 

can you reduce the number of objects in your game/level as a test to see what happens?

 

Yes, provide the values you mentioned

 

 

Simulator (Win or OS X) or device (which specific device)

OS X Simulator

Also, here are the logs containing all of the above values:

Jan 21 01:11:08.299 FPS: 60	 Texture Memory: 4.56mb  System Memory: 1.89mb 	 Stage Objects: 167
Jan 21 01:11:08.795 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.25mb 	 Stage Objects: 239
Jan 21 01:11:09.290 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.59mb 	 Stage Objects: 287
Jan 21 01:11:09.786 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.99mb 	 Stage Objects: 287
Jan 21 01:11:10.282 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.38mb 	 Stage Objects: 287
Jan 21 01:11:10.778 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.75mb 	 Stage Objects: 287
Jan 21 01:11:11.274 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 3.09mb 	 Stage Objects: 287
Jan 21 01:11:11.771 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.75mb 	 Stage Objects: 287
Jan 21 01:11:12.267 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.16mb 	 Stage Objects: 287
Jan 21 01:11:12.763 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.5mb 	 Stage Objects: 287
Jan 21 01:11:13.260 FPS: 57	 Texture Memory: 4.7mb 	 System Memory: 2.91mb 	 Stage Objects: 287
Jan 21 01:11:13.755 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.44mb 	 Stage Objects: 285
Jan 21 01:11:14.250 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.83mb 	 Stage Objects: 287
Jan 21 01:11:14.747 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.21mb 	 Stage Objects: 287
Jan 21 01:11:15.243 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.49mb 	 Stage Objects: 285
Jan 21 01:11:15.738 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 3.02mb 	 Stage Objects: 287
Jan 21 01:11:16.235 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.58mb 	 Stage Objects: 287
Jan 21 01:11:16.731 FPS: 58	 Texture Memory: 4.7mb 	 System Memory: 1.94mb 	 Stage Objects: 287
Jan 21 01:11:17.226 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.22mb 	 Stage Objects: 287
Jan 21 01:11:17.723 FPS: 58	 Texture Memory: 4.7mb 	 System Memory: 2.59mb 	 Stage Objects: 287
Jan 21 01:11:18.219 FPS: 59	 Texture Memory: 4.7mb 	 System Memory: 3.03mb 	 Stage Objects: 287
Jan 21 01:11:18.714 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.58mb 	 Stage Objects: 287
Jan 21 01:11:19.210 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.95mb 	 Stage Objects: 289
Jan 21 01:11:19.707 FPS: 59	 Texture Memory: 4.7mb 	 System Memory: 2.22mb 	 Stage Objects: 287
Jan 21 01:11:20.203 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.73mb 	 Stage Objects: 289
Jan 21 01:11:20.699 FPS: 59	 Texture Memory: 4.7mb 	 System Memory: 3.04mb 	 Stage Objects: 287
Jan 21 01:11:21.195 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.59mb 	 Stage Objects: 287
Jan 21 01:11:21.690 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.06mb 	 Stage Objects: 287
Jan 21 01:11:22.186 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.42mb 	 Stage Objects: 287
Jan 21 01:11:22.684 FPS: 59	 Texture Memory: 4.7mb 	 System Memory: 2.79mb 	 Stage Objects: 285
Jan 21 01:11:23.179 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.47mb 	 Stage Objects: 287
Jan 21 01:11:23.674 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 1.9mb 	 Stage Objects: 289
Jan 21 01:11:24.171 FPS: 59	 Texture Memory: 4.68mb  System Memory: 2.26mb 	 Stage Objects: 289
Jan 21 01:11:24.667 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.58mb 	 Stage Objects: 287
Jan 21 01:11:25.163 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.83mb 	 Stage Objects: 287
Jan 21 01:11:25.659 FPS: 59	 Texture Memory: 4.68mb  System Memory: 3.16mb 	 Stage Objects: 287
Jan 21 01:11:26.155 FPS: 60	 Texture Memory: 4.68mb  System Memory: 1.83mb 	 Stage Objects: 287
Jan 21 01:11:26.651 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.17mb 	 Stage Objects: 287
Jan 21 01:11:27.148 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.56mb 	 Stage Objects: 287
Jan 21 01:11:27.643 FPS: 60	 Texture Memory: 4.68mb  System Memory: 3.03mb 	 Stage Objects: 289
Jan 21 01:11:28.138 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.02mb 	 Stage Objects: 275
Jan 21 01:11:28.636 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.67mb 	 Stage Objects: 287
Jan 21 01:11:29.132 FPS: 60	 Texture Memory: 4.68mb  System Memory: 1.89mb 	 Stage Objects: 287
Jan 21 01:11:29.628 FPS: 60	 Texture Memory: 4.68mb  System Memory: 2.74mb 	 Stage Objects: 287
Jan 21 01:11:30.125 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 3.73mb 	 Stage Objects: 283
Jan 21 01:11:30.623 FPS: 59	 Texture Memory: 4.7mb 	 System Memory: 2.8mb 	 Stage Objects: 271
Jan 21 01:11:31.119 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 3.87mb 	 Stage Objects: 283
Jan 21 01:11:31.614 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.9mb 	 Stage Objects: 289
Jan 21 01:11:32.110 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 4.55mb 	 Stage Objects: 289
Jan 21 01:11:32.608 FPS: 57	 Texture Memory: 4.7mb 	 System Memory: 3.52mb 	 Stage Objects: 287
Jan 21 01:11:33.104 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 5.22mb 	 Stage Objects: 287
Jan 21 01:11:33.599 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 4.11mb 	 Stage Objects: 287
Jan 21 01:11:34.094 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 2.85mb 	 Stage Objects: 287
Jan 21 01:11:34.591 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 4.88mb 	 Stage Objects: 287
Jan 21 01:11:35.089 FPS: 58	 Texture Memory: 4.7mb 	 System Memory: 3.59mb 	 Stage Objects: 287
Jan 21 01:11:35.585 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 5.85mb 	 Stage Objects: 287
Jan 21 01:11:36.082 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 4.67mb 	 Stage Objects: 287
Jan 21 01:11:36.575 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 3.37mb 	 Stage Objects: 287
Jan 21 01:11:37.073 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 6mb 	 Stage Objects: 287
Jan 21 01:11:37.571 FPS: 60	 Texture Memory: 4.68mb  System Memory: 4.7mb 	 Stage Objects: 283
Jan 21 01:11:38.065 FPS: 60	 Texture Memory: 4.68mb  System Memory: 7.53mb 	 Stage Objects: 287
Jan 21 01:11:38.563 FPS: 53	 Texture Memory: 4.68mb  System Memory: 6.28mb 	 Stage Objects: 287
Jan 21 01:11:39.057 FPS: 60	 Texture Memory: 4.68mb  System Memory: 4.98mb 	 Stage Objects: 287
Jan 21 01:11:39.556 FPS: 60	 Texture Memory: 4.68mb  System Memory: 8.24mb 	 Stage Objects: 287
Jan 21 01:11:40.081 FPS: 60	 Texture Memory: 4.68mb  System Memory: 6.81mb 	 Stage Objects: 287
Jan 21 01:11:40.593 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 5.42mb 	 Stage Objects: 287
Jan 21 01:11:41.091 FPS: 60	 Texture Memory: 4.64mb  System Memory: 8.71mb 	 Stage Objects: 289
Jan 21 01:11:41.590 FPS: 46	 Texture Memory: 4.64mb  System Memory: 7.53mb 	 Stage Objects: 289
Jan 21 01:11:42.097 FPS: 60	 Texture Memory: 4.64mb  System Memory: 5.99mb 	 Stage Objects: 287
Jan 21 01:11:42.634 FPS: 30	 Texture Memory: 4.7mb 	 System Memory: 4.62mb 	 Stage Objects: 287
Jan 21 01:11:43.159 FPS: 48	 Texture Memory: 4.7mb 	 System Memory: 8.42mb 	 Stage Objects: 283
Jan 21 01:11:43.670 FPS: 59	 Texture Memory: 4.7mb 	 System Memory: 6.85mb 	 Stage Objects: 287
Jan 21 01:11:44.162 FPS: 60	 Texture Memory: 4.68mb  System Memory: 5.35mb   Stage Objects: 279
Jan 21 01:11:44.740 FPS: 36	 Texture Memory: 4.7mb 	 System Memory: 9.77mb 	 Stage Objects: 289
Jan 21 01:11:45.283 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 8.3mb 	 Stage Objects: 287
Jan 21 01:11:45.890 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 6.62mb 	 Stage Objects: 289
Jan 21 01:11:46.428 FPS: 40	 Texture Memory: 4.7mb 	 System Memory: 11.23mb  Stage Objects: 287
Jan 21 01:11:47.029 FPS: 56	 Texture Memory: 4.7mb 	 System Memory: 9.54mb 	 Stage Objects: 291
Jan 21 01:11:47.604 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 7.79mb 	 Stage Objects: 287
Jan 21 01:11:48.167 FPS: 33	 Texture Memory: 4.7mb 	 System Memory: 6.06mb 	 Stage Objects: 275
Jan 21 01:11:48.967 FPS: 32	 Texture Memory: 4.7mb 	 System Memory: 11.14mb  Stage Objects: 287
Jan 21 01:11:49.460 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 9.45mb 	 Stage Objects: 289
Jan 21 01:11:49.956 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 7.73mb 	 Stage Objects: 287
Jan 21 01:11:50.569 FPS: 55	 Texture Memory: 4.58mb  System Memory: 6.34mb 	 Stage Objects: 287
Jan 21 01:11:51.124 FPS: 60	 Texture Memory: 4.58mb  System Memory: 11.57mb  Stage Objects: 287
Jan 21 01:11:51.672 FPS: 51	 Texture Memory: 4.58mb  System Memory: 9.73mb 	 Stage Objects: 287
Jan 21 01:11:52.196 FPS: 60	 Texture Memory: 4.58mb  System Memory: 7.86mb 	 Stage Objects: 287
Jan 21 01:11:52.695 FPS: 56	 Texture Memory: 4.58mb  System Memory: 12.78mb  Stage Objects: 287
Jan 21 01:11:53.238 FPS: 60	 Texture Memory: 4.58mb  System Memory: 12.11mb  Stage Objects: 287
Jan 21 01:11:53.765 FPS: 59	 Texture Memory: 4.58mb  System Memory: 10.36mb  Stage Objects: 287
Jan 21 01:11:54.358 FPS: 56	 Texture Memory: 4.58mb  System Memory: 8.51mb 	 Stage Objects: 287
Jan 21 01:11:54.949 FPS: 23	 Texture Memory: 4.58mb  System Memory: 9.24mb 	 Stage Objects: 289
Jan 21 01:11:55.478 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 13.09mb  Stage Objects: 287
Jan 21 01:11:56.101 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 11.21mb  Stage Objects: 289
Jan 21 01:11:56.702 FPS: 33	 Texture Memory: 4.7mb 	 System Memory: 9.24mb 	 Stage Objects: 287
Jan 21 01:11:57.401 FPS: 38	 Texture Memory: 4.7mb 	 System Memory: 7.29mb 	 Stage Objects: 283
Jan 21 01:11:58.061 FPS: 30	 Texture Memory: 4.7mb 	 System Memory: 14.28mb  Stage Objects: 283
Jan 21 01:11:58.791 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 12.24mb  Stage Objects: 287
Jan 21 01:11:59.531 FPS: 54	 Texture Memory: 4.7mb 	 System Memory: 10.21mb  Stage Objects: 287
Jan 21 01:12:00.521 FPS: 38	 Texture Memory: 4.7mb 	 System Memory: 8.06mb 	 Stage Objects: 287
Jan 21 01:12:01.368 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 15.53mb  Stage Objects: 287
Jan 21 01:12:02.185 FPS: 60	 Texture Memory: 4.7mb 	 System Memory: 13.5mb 	 Stage Objects: 287
Jan 21 01:12:03.043 FPS: 28	 Texture Memory: 4.7mb 	 System Memory: 11.43mb  Stage Objects: 289
Jan 21 01:12:03.865 FPS: 57	 Texture Memory: 4.7mb 	 System Memory: 9.27mb 	 Stage Objects: 287
Jan 21 01:12:04.734 FPS: 30	 Texture Memory: 4.7mb 	 System Memory: 16.94mb  Stage Objects: 287
Jan 21 01:12:05.723 FPS: 34	 Texture Memory: 4.7mb 	 System Memory: 14.63mb  Stage Objects: 287

Towards the end as you can see there are brief moments where the FPS drops to about half.

 

I am not sure why it says there are 287 Stage Objects, because there are only 60 asteroids, one player with a health bar and two thrusters, two buttons, and a radar system with blips for some of the asteroids. This should only account for about half of the # of stage objects that is being printed out.

 

Do physics bodies count as stage objects?



[TOPIC: post.html]
#5

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Are you deleting any objects that are no longer needed when they're off screen?

 

Or - for some reason - are you running two instances of your scene at the same time?  It would explain why the frame rate halves.

Objects that are no longer within a certain range of the player are removed and only a maximum of 60 objects are allowed besides the player. 

 

I made sure I am running one instance of the level. I only called the creation function for the level once in main.lua:

level.createLevel(10, 60)


[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

1. I'm not sure about this, but based on the name (current stage is the top group that owns all other groups and objects) I'm assuming stage objects are any display object (not physics bodies) that have been created and still exist somewhere. 

 

This is ALL display objects that have been created till that point and not deleted, regardless of whether you are showing them in the visible area of the screen or not.

 

One way you could have MORE stage objects than you think should be counted:

  • create a scene with objects
  • change scenes to a new scene and create more objects w/o destroying last scene

 

 

2. I think your removal code is not working as expected.  Furthermore, if those objects all have bodies... then they are slowing down your game.



[TOPIC: post.html]
#7

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

1. I'm not sure about this, but based on the name (current stage is the top group that owns all other groups and objects) I'm assuming stage objects are any display object (not physics bodies) that have been created and still exist somewhere. 

 

This is ALL display objects that have been created till that point and not deleted, regardless of whether you are showing them in the visible area of the screen or not.

 

One way you could have MORE stage objects than you think should be counted:

  • create a scene with objects
  • change scenes to a new scene and create more objects w/o destroying last scene

 

 

2. I think your removal code is not working as expected.  Furthermore, if those objects all have bodies... then they are slowing down your game.

 

1. I am not switching between scenes, there is currently only one scene so far in this game. However, one thing I did notice was that when I moved the max limit for asteroids from 60 to 59 as a test, the number of stage objects went down by 4, from 287 to 283. 

 

I am not sure why, though. This means that the asteroids account for 240 of the display objects. 

 

2. I will put together a test to see if the code is actually removing the asteroids.



[TOPIC: post.html]
#8

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

That tells me, for every asteroid you think you're making you're making 4.  So I think you've got a code bug.

 

I'm curious what your test will be as  you may run into issues.  By the fact that you're trying to measure the state of the system you are affecting it.  Specifically you need a way to count objects.  Counting them requires a reference.  Having a reference keeps them from garbage collecting.

 

 

You may very well need a mentor/experienced coder to look at your code for you if you stay stuck.



[TOPIC: post.html]
#9

DGuy

[GLOBAL: userInfoPane.html]
DGuy
  • Observer

  • 9 posts
  • Corona SDK

Hi,

 

I can't speak to the frame-rate-drop issue, but I believe a bug in Visual Monitor is what's causing a too-high object count to be reported.

 

See below for fix:

local function deepNumChildren(group)
  local function countChildren(agroup)
    local count = 0    <== 'count' was originally being initialized to '1'
    if agroup.numChildren and not agroup.isMonitor then
      count = count + agroup.numChildren
      for i = agroup.numChildren, 1, -1 do
        count = count + countChildren(agroup[i])
      end
    end
    return count
  end
  return countChildren(group)
end

Btw, 'deepNumChildren' is a function within the VisualMonitor source code.

 

After initializing 'count' to '0' instead of '1', it began working as expected (i.e. When I create one display object, the object count reported increases by only one).

 

Hope this helps :)



[TOPIC: post.html]
#10

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,896 posts
  • Corona SDK

I checked the code on the monitor and it is not very accurate/useful for FPS monitoring.

 

A much better solution is to time each frame and return an average of those rather than what it is doing which is returning a snapshot frame rate based on the current frame every <game fps>/10.



[TOPIC: post.html]
#11

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Oh, so would I add the values of each FPS snapshot add them up and then divide them by 10?



[TOPIC: post.html]
#12

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,896 posts
  • Corona SDK

yes - that will give a average FPS and is more representative of how fast your game is actually running.



[TOPIC: post.html]
#13

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Hi,

 

I can't speak to the frame-rate-drop issue, but I believe a bug in Visual Monitor is what's causing a too-high object count to be reported.

 

See below for fix:

local function deepNumChildren(group)
  local function countChildren(agroup)
    local count = 0    <== 'count' was originally being initialized to '1'
    if agroup.numChildren and not agroup.isMonitor then
      count = count + agroup.numChildren
      for i = agroup.numChildren, 1, -1 do
        count = count + countChildren(agroup[i])
      end
    end
    return count
  end
  return countChildren(group)
end

Btw, 'deepNumChildren' is a function within the VisualMonitor source code.

 

After initializing 'count' to '0' instead of '1', it began working as expected (i.e. When I create one display object, the object count reported increases by only one).

 

Hope this helps :)

I did this fix, and there are now 143 stage objects. I think that is a more accurate number.



[TOPIC: post.html]
#14

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,896 posts
  • Corona SDK

This will give a true figure

local function countAllDisplayObjects(group)
  local count = 0
  local function countChildren(agroup)
    if agroup.numChildren and not agroup.isMonitor then
      count = count + agroup.numChildren
      for i = agroup.numChildren, 1, -1 do
        countChildren(agroup[i])
      end
    end
  end
  countChildren(group)
  return count
end

print( countAllDisplayObjects(display.getCurrentStage()) ) 


[TOPIC: post.html]
#15

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Is this about right?

                FPSValues[#FPSValues + 1] = min( display.fps, int( 1000 / ( curTime - prevTime ) ) )
		count = count + 1
		if (count % 10 == 0) then
			for i = 1, #FPSValues do
				trueFPS = trueFPS + FPSValues[i]
			end
			trueFPS = trueFPS / (#FPSValues + 1)
			print(trueFPS)
			FPSValues = {}
		end


[TOPIC: post.html]
#16

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,896 posts
  • Corona SDK

FPSValues[#FPSValues + 1] = min( display.fps, int( 1000 / ( curTime - prevTime ) ) )
count = count + 1
local FPSValues = 0
if (count % 10 == 0) then
	for i = 1, #FPSValues do
		FPSValues = FPSValues + FPSValues[i]
	end
	local avgFPS = FPSValues / #FPSValues
	print("FPS = "..avgFPS)
	FPSValues = {}
end


[TOPIC: post.html]
#17

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Thank you. However, the problem now comes with fixing this problem.

 

When I remove an asteroid, the # of stage objects decreases by 2. Also I notice that the more I hit asteroids, the more the System Memory value increases, and the more the FPS drops. 



[TOPIC: post.html]
#18

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

So after removing a radar, I discovered that the asteroids are being created and removed properly.

 

Every time I added an asteroid, a "blip" is added to the radar, hence why the removal of an asteroid results in a loss of two stage objects.

 

However, my previous observations still stands:

 

I notice that the more I hit asteroids, the more the System Memory value increases, and the more the FPS drops. 



[TOPIC: post.html]
#19

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

My first guess is, "You're not correctly removing/clearing references to the objects and they aren't getting garbage collected."

 

Questions:

 

1. Are you tracking references to asteroids, bullets, effects, etc. in more than a single variable?

 

2. Are you perhaps using a table to track objects?

 

3. If you're using a table are you doing this:

asteroids[#asteroids+1] = new_asteroid  -- TERRIBLE and naive way; leads to issues like you're seeing.

or this:

asteroids[new_asteroid] = new_asteroid  -- BEST WAY

4. If you're doing the first one... why?  That is a bad way to track objects in a action game.

 

Note:  To anyone who says it is faster, so it is better... "You are 'Verrückt'." 

 

By the time you have enough objects in a table to notice the speed difference you'll have crushed your FPS by having too many display objects.

 

 

5. Do you do it because you need to count asteroids?  If so, are you aware that SSK provides a table count helper

local numAsteroids = table.count( asteroids )

6. Do you use a finalize event listener on your asteroids?  If you don't... you should.

local asteroid = ... your code to make an asteroid 

asteroids[asteroid] = asteroid -- put it in a tracking table.

function asteroid.finalize( self )
   asteroids[self] = nil -- stop tracking in 'asteroids' table.
end

asteroid:addEventListener("finalize")

Edited by roaminggamer, 23 January 2018 - 02:49 PM.


[TOPIC: post.html]
#20

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Thank you for that well written explanation. However, I do not use a table to track asteroids. 

 

Also, I do have a finalize listener, and I have confirmed that it runs properly (or at least runs) :

asteroidFinalize = function(self)
  local masterM = require "levels-management.moduleaccessor"
  masterM.enemyHUD.getHUD()
  masterM.enemyHUD.ignoreObject(self)
  ignoreList({"enterFrame"}, self)
end


[TOPIC: post.html]
#21

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Just in case though, I do use tables to store the width, height, and health values of different sized asteroids:

local asteroidImageSizeTableX = {133, 140, 131, 195, 201, 207, 77, 81, 84, 195, 195, 134, 144, 84, 87}
local asteroidImageSizeTableY = {114, 113, 110, 157, 170, 170, 63, 67, 63, 157, 156, 113, 116, 63, 63}
local asteroidHealthTable = {350, 325, 280, 550, 610, 615, 180, 200, 190, 550, 550, 350, 335, 190, 195}

--fragment of newAsteroid function
newAsteroid = function(group, x, y, object)
  local random = mRand(1,15)
  width = asteroidImageSizeTableX[random]
  height = asteroidImageSizeTableY[random]
  local asteroid = display.newImageRect(group, "sprite/rock/asteroid".. random ..".png", width, height)
  asteroid.health = asteroidHealthTable[random]
end


[TOPIC: post.html]
#22

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,896 posts
  • Corona SDK

You need to think about this more efficiently.... if you keep creating and destroying display objects like you are you will eventually drag.  I'm not sure if this is a GC/Corona implementation error or not but it is a thing for sure.

 

What you need to do is define a max asteroids value, say 50.  Then when your game loads you instantiate all 50 asteroids.  Have a flag on them like asteroid.isActive = true/false.  If this value is true then do work on it, if false then do not display it and do no work.

 

If you want to add a new asteroid, walk the array and find the first one that is isActive=false and activate it.  When your asteroid is hit set isActive = false and hide it.

 

This way you never have more than 50 objects and your memory allocation will stay constant, as will your FPS.

 

This is called object pooling and is totally something you need to learn.



[TOPIC: post.html]
#23

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

So, when they are reactivated, I just reposition them....

 

Ok, I will try this out.



[TOPIC: post.html]
#24

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

I found that I did not have to use a table to do this, I merely just detected when they were out of a certain range, than re-positioned them, but the problem still occurs:

--new code
manageAsteroids = function(self) --enterFrame listener for each asteroid
  if (not display.isValid(self)) then return end
  local rawX = mAbs(self.x - asteroidObject.x)
  local rawY = mAbs(self.y - asteroidObject.y)
  local rawDistance = mPow(rawX, 2) + mPow(rawY, 2)
  local trueDistance = mSqrt(rawDistance)
  if trueDistance > 2625 then
    local randomX = mRand(-2625, 2625)
    local randomY = mRand(-2625, 2625)
    if (((randomX > fullw - centerX + 150) or randomX < -(fullw - centerX + 150)) or ((randomY > fullh - centerY + 90) or (randomY < -(fullh - centerY + 90)))) then
      local rawX2 = mAbs(centerX - randomX)
      local rawY2 = mAbs(centerY - randomY)
      local trueDistance2 = mSqrt(rawX2 * rawX2 + rawY2 * rawY2)
      if trueDistance2 < 2625 then
        self.x = asteroidObject.x + randomX
        self.y = asteroidObject.y + randomY
      end
    end
  end
end
Log:

Jan 24 04:14:15.445 FPS = 60
Jan 24 04:14:16.567 FPS = 59.3
Jan 24 04:14:17.685 FPS = 59.9
Jan 24 04:14:18.804 FPS = 59.7
Jan 24 04:14:19.925 FPS = 59.9
Jan 24 04:14:21.046 FPS = 59.5
Jan 24 04:14:22.165 FPS = 59.9
Jan 24 04:14:23.284 FPS = 59.5
Jan 24 04:14:24.405 FPS = 59.7
Jan 24 04:14:25.525 FPS = 59.9
Jan 24 04:14:26.645 FPS = 60
Jan 24 04:14:27.766 FPS = 60
Jan 24 04:14:28.886 FPS = 59.7
Jan 24 04:14:30.005 FPS = 60
Jan 24 04:14:31.124 FPS = 59.7
Jan 24 04:14:32.246 FPS = 60
Jan 24 04:14:33.366 FPS = 59.9
Jan 24 04:14:34.486 FPS = 59.7
Jan 24 04:14:35.606 FPS = 59.5
Jan 24 04:14:36.727 FPS = 60
Jan 24 04:14:37.846 FPS = 59.8
Jan 24 04:14:38.967 FPS = 60
Jan 24 04:14:40.086 FPS = 59.7
Jan 24 04:14:41.207 FPS = 60
Jan 24 04:14:42.327 FPS = 59.9
Jan 24 04:14:43.446 FPS = 59.8
Jan 24 04:14:44.566 FPS = 60
Jan 24 04:14:45.686 FPS = 59.7
Jan 24 04:14:46.807 FPS = 59.5
Jan 24 04:14:47.927 FPS = 60
Jan 24 04:14:49.047 FPS = 59.8
Jan 24 04:14:50.166 FPS = 59.7
Jan 24 04:14:51.287 FPS = 60
Jan 24 04:14:52.407 FPS = 59.8
Jan 24 04:14:53.528 FPS = 60
Jan 24 04:14:54.648 FPS = 59.7
Jan 24 04:14:55.766 FPS = 59.8
Jan 24 04:14:56.888 FPS = 60
Jan 24 04:14:58.009 FPS = 59.7
Jan 24 04:14:59.131 FPS = 59.9
Jan 24 04:15:00.252 FPS = 59.9
Jan 24 04:15:01.371 FPS = 59.8
Jan 24 04:15:02.493 FPS = 59.9
Jan 24 04:15:03.614 FPS = 59.8
Jan 24 04:15:04.734 FPS = 59.7
Jan 24 04:15:05.855 FPS = 58.6
Jan 24 04:15:06.977 FPS = 59.7
Jan 24 04:15:08.110 FPS = 57.9
Jan 24 04:15:09.264 FPS = 56.3
Jan 24 04:15:10.451 FPS = 55.9
Jan 24 04:15:11.584 FPS = 54
Jan 24 04:15:12.774 FPS = 49.1
Jan 24 04:15:14.030 FPS = 47
Jan 24 04:15:15.220 FPS = 56.1
Jan 24 04:15:16.464 FPS = 55.8
Jan 24 04:15:17.957 FPS = 46.4
Jan 24 04:15:19.506 FPS = 48.2
Jan 24 04:15:20.777 FPS = 53
Jan 24 04:15:22.277 FPS = 49.2
Jan 24 04:15:23.797 FPS = 46.2
Jan 24 04:15:25.554 FPS = 38.9
Jan 24 04:15:27.387 FPS = 33.2
Jan 24 04:15:29.382 FPS = 30.8
Jan 24 04:15:31.431 FPS = 32
Jan 24 04:15:33.433 FPS = 39.2
Jan 24 04:15:35.676 FPS = 31
Jan 24 04:15:37.888 FPS = 32.1
Jan 24 04:15:40.045 FPS = 29.6
Jan 24 04:15:42.320 FPS = 30.7
Jan 24 04:15:44.545 FPS = 31.9
Jan 24 04:15:46.800 FPS = 31.3
Jan 24 04:15:49.124 FPS = 27.2
Jan 24 04:15:51.442 FPS = 27.4
Jan 24 04:15:53.713 FPS = 32.8

Currently, I have an enterFrame listener for each asteroid.

 

Would it be better to put the enterFrame, or even a timer, on one table filled with the asteroids, and just traverse the table, and then reposition them. Could this work?

 

Also, I noticed that System Memory continuously increases. 



[TOPIC: post.html]
#25

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,896 posts
  • Corona SDK

FYR: My games manage 30k+ display objects and hit a constant 30 FPS (the speed I set my games to run at) so if you can't manage 200+ then you are seriously doing something wrong.

 

Your FPS is mad.... Check for crazy coding like dropping/recreating objects per frame leaving orphaned physics bodies, etc.  Adding enterFrame() events per frame, etc.

 

With proper object pooling your memory and FPS should remain constant - have you done what I suggested?




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]