Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

game LAGS on physics collision
Started by whammy Jun 30 2014 03:59 AM

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

whammy

[GLOBAL: userInfoPane.html]
whammy
  • Contributor

  • 202 posts
  • Corona SDK

Whoa, that would be great! Thanks a ton!

Apart from the physics slow downs everything else works well. I'm really happy with the audio performance. There are just two other minor glitches that I noticed:

- sometimes transitions stop a little bit earlier than they should - without completing the whole animation. I think it might have something to do with the timer adjustments issue that you were mentioning. Maybe they are deployed later, but stop on time?

- when I hit the middle start (windows) hardware button, sometimes I don't get a lua applicationSuspend event, although sometimes I do. Also - this button (in contradiction to the closing back button) should suspend an application (I get a native deactivate application event) but when I open the app again - but it loads up again from the beginning

When you have the communication bridge ready, could you also guide me then in a few steps on how to use it? Thanks,

[TOPIC: post.html]
#27

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

>> I'm really happy with the audio performance.

 

Oh good.  We wrote our own OpenAL library for WinRT from scratch and I'm glad this initial version is working out so well.  We even threw in AL_PITCH support, which is a hidden API in Corona, but some Corona developers are actively using it.  We just don't support the hidden positional audio feature on WP8.

   http://coronalabs.com/blog/2011/07/27/the-secretundocumented-audio-apis-in-corona-sdk/

 

The only issue with audio that I've noticed is that if you suspend/resume several times with streaming audio running (like music), then sometimes the streaming audio stops running upon resume.  You might want to give it a quick try on your end to see if you can reproduce it too.

 

>> sometimes transitions stop a little bit earlier than they should

 

Right, that's the timer issue I was telling you about last week.  The next version I'm going to give you will resolve this.

 

>> sometimes I don't get a lua applicationSuspend event

 

Yeah, this is a loose-end I haven't had time to figure out yet.  I got it working reliably when pressing the Search button and backing out of the app, but I've noticed the Home button always force quits the app, which appears to be WP8's default behavior.  That is, the Home button does not work like how it does on Android.  I think Microsoft is changing his behavior in 8.1 to make it work more like Android, but I don't yet know if that Home button behavior change is for both 8.0 and 8.1 built apps or just for 8.1 *.AppX apps.

 

>> When you have the communication bridge ready, could you also guide me then in a few steps on how to use it?

 

Absolutely!



[TOPIC: post.html]
#28

whammy

[GLOBAL: userInfoPane.html]
whammy
  • Contributor

  • 202 posts
  • Corona SDK

I'm using AL_PITCH as well and so I was happy that it was implemented.

 

I tested the music pausing - yep, when I paused my game 10 times, there was one time when the music didn't resume, but on the next pause/resume it started playing again.

 

Regarding the home (start) button functionality - according to MS documentation it shouldn't close the app (like the back button), but should push it to the background:

 

http://msdn.microsoft.com/en-us/library/windowsphone/develop/dn148258(v=vs.105).aspx



[TOPIC: post.html]
#29

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

>> I'm using AL_PITCH as well and so I was happy that it was implemented.

 

I'm glad AL_PITCH is working for you.

 

>> I tested the music pausing - yep, when I paused my game 10 times, there was one time when the music didn't resume, but on the next pause/resume it started playing again.

 

I'm starting to think that this might be a core Corona issue that might happen on other platforms based on what I'm seeing in our code.  I've seen a similar bug report on iOS and Android in the past.  If you suspend/resume several times on iOS or Android, does the streaming music sometimes stop too?

 

>> according to MS documentation it shouldn't close the app (like the back button), but should push it to the background:

 

But it will.  Microsoft does not guarantee that the app will be resumed when returning to your app after pressing the Start button.  They threaten that the device might decide to "tombstone" it.  To prove it, put break points in your "App.xaml.cs" file's Constructor, Deactivated, and Closing event handlers and launch your app.  Notice that when you press the Start/Home button, it'll Deactivate as expected, but when you go back into your app, it'll break in your App class' constructor.  This proves that the Application was terminated and being re-created when re-launched.  The same behavior can be observed with a WP8 app made with Microsoft's project templates.  It's not caused by our Corona library.

 

Microsoft documents this here under the "Deactivated" section...

   http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff817008(v=vs.105).aspx

 

In my experience, this tombstoning behavior always happens when pressing the Start button.  I've yet to see a WP8 device resume an app afterwards, but I wonder if it might have something to do with how much RAM is available on the device.  The Lumia 920 that I typically test with is considered a low memory device.

 

I'll work on this later.  The XAML events we're currently depending on to raise system events in Lua work in all cases *except* for the Start/Home button.  So, we'll just have to hook into other events to get it working right.  Just another to-do item on the list.  We'll get to it.  ;-)



[TOPIC: post.html]
#30

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

One more thing app pressing the Start/Home button.  I figured out what's going on.  If you press the Start/Home button and then tap on your app from the app listing, it will *always* restart your app.  However, if you hold down the Back button to bring up the "Fast App Switcher" and tap on your app from there, then it will resume.

   http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj735579(v=vs.105).aspx

 

I remember figuring that out a while ago and I guess I forgot how it works again because I'm used to Android's behavior.  :)

I remember other WP8 app developers complaining to Microsoft about this, asking them to change the behavior to be more like Android on 8.1.



[TOPIC: post.html]
#31

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Pressing the Back button after pressing the Start/Home button will resume your app too.



[TOPIC: post.html]
#32

whammy

[GLOBAL: userInfoPane.html]
whammy
  • Contributor

  • 202 posts
  • Corona SDK

Oh! I didn't even know about the "fast app switcher" to be honest :-) Yep - it works like you say. It's resuming the app instead of relaunching it. Thanks for the info.

 

Regarding the music pause/resume on iOS - I haven't noticed this behaviour, but maybe it's just not as frequent as on WP8. Can't say.



[TOPIC: post.html]
#33

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

>> Yep - it works like you say. It's resuming the app instead of relaunching it. Thanks for the info.

 

No problem!  Honestly, I keeping forgetting that this is how WP8 works too because I'm so used to Android's behavior.  :)

 

 

>> Regarding the music pause/resume on iOS - I haven't noticed this behavior

 

Okay.  Fair enough.  I do know that we have some old closed out bugs on this on Android and iOS.  I'll dig into how this issue was resolved on those platforms later.

 

In the meantime (and if you don't mind), you should be able to work-around this issue by calling audio.pause() on your streaming music upon "applicationSuspend" and then upon "applicationResume" call audio.play().  That's how Corona developers used to worked-around this on iOS and Android in the past.

 

Other than that, how is everything else working out for you on WP8?



[TOPIC: post.html]
#34

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Oh and in regards to 60 FPS.  I'm still struggling to achieve this.  It's proving to be quite difficult to do this on WP8.  Every solution I've tried has had some kind of negative impact on something else.

 

At this point, I'm thinking that if I can't come up with a reasonable solution by the end of today, then I should punt on this issue and starting working on that Native/Lua bridge instead and the other nagging issues (like timers elapsing too soon, audio not resuming, etc.).  That way I'm not blocking you from implementing in-app purchase and other tasks.  Does that sound reasonable at the moment?



[TOPIC: post.html]
#35

whammy

[GLOBAL: userInfoPane.html]
whammy
  • Contributor

  • 202 posts
  • Corona SDK

I agree, I think it would be the best decision for now. But could you include the improvement you already achieved in the next update?

 

But there's sth more - I've just tried to upload a test xap package made with CoronaCards to my MS dev center but the package didn't pass the validation:

 

1028: The native API api-ms-win-core-debug-l1-1-1.dll:OutputDebugStringA() isn’t allowed in assembly CoronaLabs.Corona.Component.dll. Update it and then try again.

1028: The native API api-ms-win-core-localization-l1-2-0.dll:FormatMessageA() isn’t allowed in assembly lua.dll. Update it and then try again.
1028: The native API api-ms-win-core-synch-l1-2-0.dll:CreateMutexExA() isn’t allowed in assembly almixer.dll. Update it and then try again.

 

Should I make a build in a specific way to skip these APIs, or it's on your side to remove it?



[TOPIC: post.html]
#36

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

It's on my side to remove.  I didn't realize ASCII version of those functions were not allowed on the app store.  Interesting since those functions are publicly available.  Anyways, I'll change them over to Unicode wide character version next week.  Thanks for bringing this up.



[TOPIC: post.html]
#37

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Oh and yes, I'll add the other timer improvements I talked about before.

 

Here's a current update on the 60 FPS issue so far.  I can only get it to render at 60 FPS if I do absolutely nothing on the main UI thread.  As soon as I do anything interesting on the main UI thread (or perhaps any thread?), even if only by a 3-4 milliseconds, it seems to have a negative impact on the Direct3D rendering thread and I can only get about 40-45 FPS.  Even if I happen to do everything with the 16 millisecond timeframe needed for 60 FPS, the rendering thread still skips a frame on every few frames.  That's incredibly frustrating and it makes it sound like 60 FPS might be impossible with a XAML based app... at least on the phone I'm testing with.

 

The alternative solution that I was talking to you about before was to update Corona and its physics on-time 60 times a second and render when I can (because the rendering thread appears to be lazy and is out of my control).  With this approach, I can update Corona on-time 60 times a second, but only render 40 times a second.  So, from a Lua and physics standpoint everything appears to be running at 60 FPS, but the display will only render at 40 FPS.  Still better than 30 FPS, but it's still not truly 60 FPS.



[TOPIC: post.html]
#38

Lerg

[GLOBAL: userInfoPane.html]
Lerg
  • Contributor

  • 533 posts
  • Corona Staff

Is it better if you don't use physics at all?



[TOPIC: post.html]
#39

whammy

[GLOBAL: userInfoPane.html]
whammy
  • Contributor

  • 202 posts
  • Corona SDK

@Joshua, I meant the improvements to fps that you made. If there are no visible slow downs now then maybe 40fps would appear smooth enough for our needs, at least for now. I'd be happy to test it.

 

The main issue in my game is that the physics frame-rate slow downs are getting bigger after time. It looks that after every following level load I have worse physics performance.

 

I though that it might be caused by a memory leak, but I checked and I have only 2-5kb leaks so it shouldn't be an issue. When I load the first level, physics response is decent, some slow downs appear, but nothing serious. But after I load the level several times - the slow downs are getting more and more visible. I even tried to call physics.stop() and remove all scenes before loading the next level but it doesn't help the performance.

 

I don't have this issue with the same code on iOS, only on WP8, and I'm curious if the changes that you already made to the physic speed calculations would help to solve that issue. 



[TOPIC: post.html]
#40

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Without physics, such as our "Graphics\Fishies" sample app, I'm seeing about 5-10 frame improvement.  So, it renders at about 45-50 FPS.  Interesting since the other app I was testing only adds about 1-2 millisecond overhead with physics, well within the 16 millisecond time period needed for 60 FPS.



[TOPIC: post.html]
#41

Lerg

[GLOBAL: userInfoPane.html]
Lerg
  • Contributor

  • 533 posts
  • Corona Staff

45..50 is really good!



[TOPIC: post.html]
#42

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Yeah, it's 45-50 rendered and I'm updating Corona/physics 60 times a second.  Seems to be the best compromise.  Especially if your physics system is framerate based, which it is by default.  It just kind of irks me that I can't get this phone I'm testing with to render faster.  Especially since I'm easily updating/rendering everything within 16 milliseconds.



[TOPIC: post.html]
#43

Lerg

[GLOBAL: userInfoPane.html]
Lerg
  • Contributor

  • 533 posts
  • Corona Staff

Can you send me your binary somehow so I can test it and measure FPS on my Lumia 625?

I don't know if it's possible.



[TOPIC: post.html]
#44

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

>> The main issue in my game is that the physics frame-rate slow downs are getting bigger after time.

 

Olaf, that definitely sounds like a memory leak.  I don't think the framerate improvements that I'm making will help with that.

 

I'm not seeing any leaks with the apps I'm running at the moment... or Visual Studio isn't detecting the ones you are seeing.  Would you be willing to send  your project to us so that we can try it for ourselves?

 

Also, I do know that tomorrow's daily build will contain some memory leak fixes for all platforms.  There were some minor memory leaks involving rendering geometry via display.newLine(), newCircle(), newRect(), newRoundedRect(), and newPolygon().  It was a minor leak, but they would accumulate over time if you create/destroy these often.  I'll get a hold of those fixes and include them in our next WP8 build for you guys next week.



[TOPIC: post.html]
#45

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Lerg, would you mind waiting until next week?

I don't a nice means of packaging everything up right now.

Plus, I'll see about finishing implementing what since it *is* an improvement.



[TOPIC: post.html]
#46

Lerg

[GLOBAL: userInfoPane.html]
Lerg
  • Contributor

  • 533 posts
  • Corona Staff

Sure, no hurry.



[TOPIC: post.html]
#47

whammy

[GLOBAL: userInfoPane.html]
whammy
  • Contributor

  • 202 posts
  • Corona SDK

Joshua,

 

OK, you were right - I had one particle update enterFrame listener that I didn't remove before exiting scene. Oops.. :-)

Now everything runs fast after several level updates. My bad. There still are frame-rate slow downs, but they don't increase in time.

 

Anyway, thanks for your help.



[TOPIC: post.html]
#48

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Olaf,

 

We'll be sending everyone a new WP8 update today which provides the framerate and timer improvements that you need.  It's a pretty huge improvement and I'd be interested to know how well it works for you.  Just note that if you have native XAML UI on top (like a TextBox), then that can cause a huge framerate issue if you're rendering at 60 FPS.  I can't do much about that because Corona and Microsoft's UI are heavily competing for the rendering thread's time.  If you frequently display native UI on top (I don't think you do), then you'll have to switch to 30 FPS... which by the way is much smoother and improved as well.  Kind of a bummer that I can't make 60 FPS play nice with XAML, but this is the best compromise that I could come up with.

 

I also had the Win32 functions removed that caused your app to be rejected from the Windows Store.  Just note that I haven't tested uploading it to the Windows Store myself.  Not set up for this yet and haven't had time.  So, if you can confirm if this resolves the app rejection issue then that would be great.  Thanks!



[TOPIC: post.html]
#49

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I've also whipped together the following Lua code which you can use to measure the framerate...
 

local lastEnterFrameTime = nil
local durationCollectionSize = 60
local durationCollectionIndex = 1
local durationCollection = {}
for index = 1, durationCollectionSize do
	durationCollection[index] = 0
end
local function onEnterFrame(event)
	local currentTime = system.getTimer()

	-- If this is the first frame, then fetch the current time and exit out.
	if (lastEnterFrameTime == nil) then
		lastEnterFrameTime = currentTime
		return
	end

	-- Store the duration since the last frame.
	durationCollection[durationCollectionIndex] = currentTime - lastEnterFrameTime
	lastEnterFrameTime = currentTime

	-- Do not continue if we have more durations to collection before averaging below.
	if (durationCollectionIndex < durationCollectionSize) then
		durationCollectionIndex = durationCollectionIndex + 1
		return
	end

	-- Average the collected durations and print it to the log.
	local averageDuration = 0
	for index = 1, durationCollectionSize do
		averageDuration = averageDuration + durationCollection[index]
	end
	averageDuration = averageDuration / durationCollectionSize
	local averageFps = 1000 / averageDuration
	print("Average FPS = " .. tostring(averageFps) .. ", Average Duration = " .. tostring(averageDuration))

	-- Reset data collection.
	durationCollectionIndex = 1
end
Runtime:addEventListener("enterFrame", onEnterFrame)

The above will print the average framerate once every 60 frames to Visual Studio's Output panel.  Just remember that you don't want to print() on every frame since that function has a huge performance penalty on WP8.  I measures about 3-4 milliseconds per print!  But once every 60 times isn't so bad.



[TOPIC: post.html]
#50

whammy

[GLOBAL: userInfoPane.html]
whammy
  • Contributor

  • 202 posts
  • Corona SDK

Joshua,

 

I've just tested the new CoronaCard build. It's sooo much smoother! :) I could even increase the particles number because I didn't observe lags when the particles were removed. Once I increased their number - the tiny lags appeared again but I noticed them only because I knew they occured before. Now the lags don't affect the gameplay at all! Thanks a lot, it's a great improvement!

Below this post I paste a framerate output I get on my Lumia 625 - nearly 60fps :-)

 

I have only rate&review native UI popup appearing at the beginning after every 5th game launch, so it doesn't affect my fps during the gameplay.

 

Regarding submitting the package to the Windows Store - it has passed the validation now, thanks.

 

So once you have the native/lua communication done, I'd be able to submit my release candidate to the Q&A Microsoft team with no fear :-) When do you think it might be ready?

 

Here's the fps log:

Average FPS = 40.187541862023, Average Duration = 24.883333333333
Average FPS = 50.718512256974, Average Duration = 19.716666666667
Average FPS = 59.820538384845, Average Duration = 16.716666666667
Average FPS = 60.606060606061, Average Duration = 16.5
Average FPS = 59.464816650149, Average Duration = 16.816666666667
Average FPS = 56.232427366448, Average Duration = 17.783333333333
Average FPS = 60.06006006006, Average Duration = 16.65
Average FPS = 60.240963855422, Average Duration = 16.6
Average FPS = 59.94005994006, Average Duration = 16.683333333333
Average FPS = 59.94005994006, Average Duration = 16.683333333333
Average FPS = 57.08848715509, Average Duration = 17.516666666667
Average FPS = 58.42259006816, Average Duration = 17.116666666667
Average FPS = 58.42259006816, Average Duration = 17.116666666667
Average FPS = 60.606060606061, Average Duration = 16.5
Average FPS = 59.52380952381, Average Duration = 16.8
Average FPS = 57.19733079123, Average Duration = 17.483333333333
Average FPS = 60.240963855422, Average Duration = 16.6
Average FPS = 60.180541624875, Average Duration = 16.616666666667
Average FPS = 56.127221702526, Average Duration = 17.816666666667
Average FPS = 54.347826086957, Average Duration = 18.4
Average FPS = 57.526366251198, Average Duration = 17.383333333333
Average FPS = 59.52380952381, Average Duration = 16.8
Average FPS = 60.362173038229, Average Duration = 16.566666666667
Average FPS = 59.701492537313, Average Duration = 16.75
Average FPS = 57.692307692308, Average Duration = 17.333333333333
Average FPS = 59.464816650149, Average Duration = 16.816666666667
Average FPS = 60.362173038229, Average Duration = 16.566666666667
Average FPS = 58.881256133464, Average Duration = 16.983333333333
Average FPS = 59.701492537313, Average Duration = 16.75
Average FPS = 57.034220532319, Average Duration = 17.533333333333
Average FPS = 60.728744939271, Average Duration = 16.466666666667
Average FPS = 59.171597633136, Average Duration = 16.9
Average FPS = 37.974683544304, Average Duration = 26.333333333333
Average FPS = 60.483870967742, Average Duration = 16.533333333333
Average FPS = 57.636887608069, Average Duration = 17.35
Average FPS = 57.859209257473, Average Duration = 17.283333333333
Average FPS = 58.939096267191, Average Duration = 16.966666666667
Average FPS = 59.582919563059, Average Duration = 16.783333333333
Average FPS = 60.301507537688, Average Duration = 16.583333333333
Average FPS = 57.859209257473, Average Duration = 17.283333333333
Average FPS = 59.820538384845, Average Duration = 16.716666666667
Average FPS = 60.120240480962, Average Duration = 16.633333333333
Average FPS = 58.881256133464, Average Duration = 16.983333333333



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