I also have a solution to the inheritance problem that I'll be blogging about soon and is covered in the updated game chapter in my book, available soon electronically.
Man, you have a lot of good stuff coming :) Really looking forward to it. Actually I have just brought Michael Show's "Game development in Silverlight" book (not sure the name is right). Guess I will by yours when it comes out.
--------------------------
Please mark the post as answered if this answers your question
http://www.laumania.net
Okay folks, I have got some updates regarding the humungous Canvas. The outcome is good; I have created Canvas of size 20480x10240 pixels at no additional cost (both in terms of memory consumption and performance). So Ksleung was right. I am having 384 tiles
visible each of which is 64x32 pixels in size. Content Canvas hosting them moves smoothly (it is going at 58fps constantly) since I no longer have to offset these 384 tiles when the “jump” happens.
Thanks for your performance benchmark, Bill. I still use Get/SetValue methods for now as 384 tiles are much lesser than 4000 in your case, so I don’t expect that to cause too much of a problem (also I suspect creating another 384 TranslateTransform will
likely to stress .NET runtime in a way that it needs to track these objects’ lifespan).
I am not sure what is going to happen if I have more tile bitmaps in future, I hope Silverlight runtime puts all my bitmaps on one texture in hardware level (imho texture switching in video memory is costly).
While this is not the optimal solution I would personally like to see (I think WriteableBitmap is more “natural” for my purposes), it does solve the problem for now. Ultimate solution I’d like to see is the ability to access Image (in SL3 RTW, even if it
is read-only) from a background thread, then the jittery issue can be completely resolved.
I don't think the SL team will provide access to the WriteableBitmap in background thread. The reason is that SL must have full access to all UI assets whenever it is running the UI thread, so it really cannot afford to let you muck with it in the meantime.
I do hope that the SL team can provide better WriteableBitmap APIs. Currently the only pixel access is the [] operator, which I image has tons of checks (security and bound) on a per-pixel basis. This is highly inefficient especially we all want to use
WriteableBitmap in a very heavy way. Why not provide wholesale array copy API? For example,
WriteableBitmap.CopyFrom(int[] Src, int SrcWidth, int SrcHeight, Rect Region, int TranslateX, int TranslateY);
WriteableBitmap.CopyTo(int[] Dest, int DestWidth, int DestHeight, Rect Region, int TranslateX, int TranslateY);
This way, whatever check only needs to be done once.
It is still okay to require that these APIs be called from the UI thead. But at least this approach would allow us to write decent code to perform all the maths in the background thread, and make one async call to push the result to the WriteableBitmap.
I hope the SL team would consider this. Perhaps they already did, but the frustrating thing is that nobody knows!
Visit http://www.tagxedo.com, a Silverlight-based word cloud generator. If you like it, please help me spread the word!
I completely agree with you about WritableBitmap being alot better suited for this sort of task, just with the performance bottle neck its a killer...
When you said you were getting around 54 Fps constant with a massive canvas, how many tiles did you have (roughly) in it and how many tiles were on screen at once (roughly), for my game the resolution will be anything between 640x480 to 1280x1024 (or whatever
the resolution is around that size). This means i would have a few hundered on screen at once, but also they are layered, so although there may be lets say 200 flat tiles, there may be 3x this many acctually on the screen, and paired with any other moving
objects... i think im going to try and test this tonight, i got a bit carried away with writing some of the logic the other day... oh and moving house, so will see if i can bring back any numbers from my example...
At the moment the juddering on translating is killing my game, and if i could get rid of that it would probably be fine and i can do a little dance! OH also while we are on topic...
so far we have been comparing Canvas.Top/Left vs TranslateTransformation.X/Y, for a reason i cant remember off the top of my head i have had to use both. I think the static tiles dont ever change the Canvas.Top/Left but as i have lots of moving entities
they require the canvas position to move as well as the render transformations... well i think so off top of my head anyway...
In your game im guessing you will have the goomba equivalent which will be moving around a bit, how have you gone about doing his movement with a scrolling background? Same route as me or some other gem?
Well, Ksleung I am not sure if that is going to solve my problem. I was merely doing a WriteableBitmap.Render(m_SourceImage, new TranslateTransform) when the "jump" needs to happen (roughly once per second), and it already causes jittery movement. I can
of course lower my frame rate to make the "jump" transition smooth (if each frame takes longer time than what is required for the jump transition, then the jump won’t be noticeable). But I doubt I’d want to go there. I do trust SL team will be improving this
"blitting" overtime though.
Gofit, I have 384 tiles in the humungous Content Canvas at one time. Older tiles that scrolled out of view will be recycled and used in position of newer tiles, which then get scrolled into view. The only reason I use humungous canvas is because of the limitations
I stated in the original post (to avoid 384 calls to Get/SetValue on 384 Image objects, which was proven to be costly).
The tiles are the "background" actually. 384 isometric tiles made up the map that covers the entire displayable area. I have yet to put static buildings on the map, but I don’t expect that to cause much problem. The frame rate for a scrolling background
of this many tiles is quite satisfying on my single core laptop actually. [:D]
I revisited my tile system to see if there were any immediate issues i could look at updating... and it ends up that i was already translating the canvas, so im not positioning every single one of the tiles... one thing is though im using 32x32 tiles so
i would end up having more smaller elements compared to your fewer larger elements... i wont be in my actual game but as im just prototyping everything i thought i would start with them.
Anyway my framerate is awful, its perfect if you are stationary constantly > 60fps with menus and other things going on... but the scrolling kills it. It seems to be marginly slower if i just put all the tiles into the canvas and let SL deal with what to
display on the given page. However if i use a quadtree system to enable/disable children as and when are needed it is like 5fps faster.
Im not sure if the bottle neck comes from having lots of things to draw on screen or just having lots of things in the canvas... im hoping to be able to have >30fps consistantly with the scrolling and lots of stuff on screen at once and hopefully some simple
particle style effects... although im not sure if it will happen :( as im struggling to get >20 fps when scrolling with more than 1 tile layer at the moment... im still got a few optimizations up my sleave like baking the static things together ad a few other
tweaks around...
I also tried testing my app on my other laptop, which is a dedicated gaming one... and it got pretty much the same performance as my crappy little laptop which i found as odd...although it does only have a single core (its >3 years old), and im guessing
SL still hammers the CPU more than anything else...
Bill Reiss
Contributor
4973 Points
947 Posts
Re: Re: Re: Super Mario, Tile Based Game and Silverlight Performance
Jul 06, 2009 01:06 PM | LINK
I also have a solution to the inheritance problem that I'll be blogging about soon and is covered in the updated game chapter in my book, available soon electronically.
Bill Reiss, Coauthor of Hello! Silverlight
My blog
Qbus
Member
611 Points
271 Posts
Re: Re: Re: Re: Super Mario, Tile Based Game and Silverlight Performance
Jul 06, 2009 01:09 PM | LINK
Please mark the post as answered if this answers your question
http://www.laumania.net
HaywireGuy
Member
11 Points
18 Posts
Re: Super Mario, Tile Based Game and Silverlight Performance
Jul 06, 2009 02:18 PM | LINK
Okay folks, I have got some updates regarding the humungous Canvas. The outcome is good; I have created Canvas of size 20480x10240 pixels at no additional cost (both in terms of memory consumption and performance). So Ksleung was right. I am having 384 tiles visible each of which is 64x32 pixels in size. Content Canvas hosting them moves smoothly (it is going at 58fps constantly) since I no longer have to offset these 384 tiles when the “jump” happens.
Thanks for your performance benchmark, Bill. I still use Get/SetValue methods for now as 384 tiles are much lesser than 4000 in your case, so I don’t expect that to cause too much of a problem (also I suspect creating another 384 TranslateTransform will likely to stress .NET runtime in a way that it needs to track these objects’ lifespan).
I am not sure what is going to happen if I have more tile bitmaps in future, I hope Silverlight runtime puts all my bitmaps on one texture in hardware level (imho texture switching in video memory is costly).
While this is not the optimal solution I would personally like to see (I think WriteableBitmap is more “natural” for my purposes), it does solve the problem for now. Ultimate solution I’d like to see is the ability to access Image (in SL3 RTW, even if it is read-only) from a background thread, then the jittery issue can be completely resolved.
Thanks again for your help, guys!
Tile-Based Tiles Silverlight Performance
ksleung
Contributor
6680 Points
1265 Posts
Re: Super Mario, Tile Based Game and Silverlight Performance
Jul 06, 2009 05:30 PM | LINK
Good to hear that you made some progress.
One comment on WriteableBitmap.
I don't think the SL team will provide access to the WriteableBitmap in background thread. The reason is that SL must have full access to all UI assets whenever it is running the UI thread, so it really cannot afford to let you muck with it in the meantime.
I do hope that the SL team can provide better WriteableBitmap APIs. Currently the only pixel access is the [] operator, which I image has tons of checks (security and bound) on a per-pixel basis. This is highly inefficient especially we all want to use WriteableBitmap in a very heavy way. Why not provide wholesale array copy API? For example,
WriteableBitmap.CopyFrom(int[] Src, int SrcWidth, int SrcHeight, Rect Region, int TranslateX, int TranslateY);
WriteableBitmap.CopyTo(int[] Dest, int DestWidth, int DestHeight, Rect Region, int TranslateX, int TranslateY);
This way, whatever check only needs to be done once.
It is still okay to require that these APIs be called from the UI thead. But at least this approach would allow us to write decent code to perform all the maths in the background thread, and make one async call to push the result to the WriteableBitmap.
I hope the SL team would consider this. Perhaps they already did, but the frustrating thing is that nobody knows!
Grofit
Member
298 Points
342 Posts
Re: Re: Super Mario, Tile Based Game and Silverlight Performance
Jul 07, 2009 07:21 AM | LINK
I completely agree with you about WritableBitmap being alot better suited for this sort of task, just with the performance bottle neck its a killer...
When you said you were getting around 54 Fps constant with a massive canvas, how many tiles did you have (roughly) in it and how many tiles were on screen at once (roughly), for my game the resolution will be anything between 640x480 to 1280x1024 (or whatever the resolution is around that size). This means i would have a few hundered on screen at once, but also they are layered, so although there may be lets say 200 flat tiles, there may be 3x this many acctually on the screen, and paired with any other moving objects... i think im going to try and test this tonight, i got a bit carried away with writing some of the logic the other day... oh and moving house, so will see if i can bring back any numbers from my example...
At the moment the juddering on translating is killing my game, and if i could get rid of that it would probably be fine and i can do a little dance! OH also while we are on topic...
so far we have been comparing Canvas.Top/Left vs TranslateTransformation.X/Y, for a reason i cant remember off the top of my head i have had to use both. I think the static tiles dont ever change the Canvas.Top/Left but as i have lots of moving entities they require the canvas position to move as well as the render transformations... well i think so off top of my head anyway...
In your game im guessing you will have the goomba equivalent which will be moving around a bit, how have you gone about doing his movement with a scrolling background? Same route as me or some other gem?
HaywireGuy
Member
11 Points
18 Posts
Re: Super Mario, Tile Based Game and Silverlight Performance
Jul 07, 2009 02:45 PM | LINK
Well, Ksleung I am not sure if that is going to solve my problem. I was merely doing a WriteableBitmap.Render(m_SourceImage, new TranslateTransform) when the "jump" needs to happen (roughly once per second), and it already causes jittery movement. I can of course lower my frame rate to make the "jump" transition smooth (if each frame takes longer time than what is required for the jump transition, then the jump won’t be noticeable). But I doubt I’d want to go there. I do trust SL team will be improving this "blitting" overtime though.
Gofit, I have 384 tiles in the humungous Content Canvas at one time. Older tiles that scrolled out of view will be recycled and used in position of newer tiles, which then get scrolled into view. The only reason I use humungous canvas is because of the limitations I stated in the original post (to avoid 384 calls to Get/SetValue on 384 Image objects, which was proven to be costly).
The tiles are the "background" actually. 384 isometric tiles made up the map that covers the entire displayable area. I have yet to put static buildings on the map, but I don’t expect that to cause much problem. The frame rate for a scrolling background of this many tiles is quite satisfying on my single core laptop actually. [:D]
Grofit
Member
298 Points
342 Posts
Re: Super Mario, Tile Based Game and Silverlight Performance
Jul 08, 2009 11:49 AM | LINK
I revisited my tile system to see if there were any immediate issues i could look at updating... and it ends up that i was already translating the canvas, so im not positioning every single one of the tiles... one thing is though im using 32x32 tiles so i would end up having more smaller elements compared to your fewer larger elements... i wont be in my actual game but as im just prototyping everything i thought i would start with them.
Anyway my framerate is awful, its perfect if you are stationary constantly > 60fps with menus and other things going on... but the scrolling kills it. It seems to be marginly slower if i just put all the tiles into the canvas and let SL deal with what to display on the given page. However if i use a quadtree system to enable/disable children as and when are needed it is like 5fps faster.
Im not sure if the bottle neck comes from having lots of things to draw on screen or just having lots of things in the canvas... im hoping to be able to have >30fps consistantly with the scrolling and lots of stuff on screen at once and hopefully some simple particle style effects... although im not sure if it will happen :( as im struggling to get >20 fps when scrolling with more than 1 tile layer at the moment... im still got a few optimizations up my sleave like baking the static things together ad a few other tweaks around...
I also tried testing my app on my other laptop, which is a dedicated gaming one... and it got pretty much the same performance as my crappy little laptop which i found as odd...although it does only have a single core (its >3 years old), and im guessing SL still hammers the CPU more than anything else...
Jose Luis Qu...
Member
28 Points
5 Posts
Re: Super Mario, Tile Based Game and Silverlight Performance
Aug 27, 2009 07:15 AM | LINK
Example in Game RPG. http://www.elquintero.net/games/SimonTheLegacy/
Silverlight game development