LamptonWorm

Hi,

My primary platform at the moment is Windows, but I want to ensure I don't code anything that is going to cause alot of pain when I eventually get around to subscribing to the creators club and deploying to the 360.

I've read a couple of articles on GC and other performance related stuff, but I wondered if anyone has any advice generally on what to avoid or if there are preferences in how ceratin things are coded (e.g. there are many types of storage, is one better than another for XNA specifically) that will mean the transition to 360 is as smooth as possible.

Any thoughts or comments welcome!

Cheers :)


Re: XNA Game Studio Express 360 Dev do's and don'ts

Jendrik

Im not very long working with XNA but you should not draw any important UI-Elements at the borders of the screen because not every TV draws the complete screen.

An other important thing is the input. You should build up your input-class so that you can switch the input device easy without changing a lot of code.





Re: XNA Game Studio Express 360 Dev do's and don'ts

Arek Bal

If you would first look for infos by yourself, then you would know that there are just few main rules:
-minimize GC calls by making objects live... watch out, when operating on collections as some could generate short living garbage(most known "foreach problem").
-And, as already said, sometimes not everything would be drawed, so you should oversee it - let user adjust screen size, or draw UI in safe screen.
-He, I hope I don't have to say - xboxs usually don't have keyboards and mouses.





Re: XNA Game Studio Express 360 Dev do's and don'ts

Joel Martinez

This one bit me. If you're doing audio programming, make sure you call the dispose method on any Cue that you retrieve with GetCue() after it's done playing. If you don't need to stop or pause the cue, you can simply use the PlayCue() method.





Re: XNA Game Studio Express 360 Dev do's and don'ts

Ska Software

I think I've run into significant trouble with GC; I get lockups of nearly 1 second every minute or so. When I figure out what I've done wrong and how to fix it I'll tell everyone! :)





Re: XNA Game Studio Express 360 Dev do's and don'ts

Arek Bal

Ska Software wrote:
I think I've run into significant trouble with GC; I get lockups of nearly 1 second every minute or so. When I figure out what I've done wrong and how to fix it I'll tell everyone! :)


Try to call GC.Collect()...each second. Just for profiling purposes. See how much of what and when is collected in profiler.




Re: XNA Game Studio Express 360 Dev do's and don'ts

Ska Software

I did; it turns the game into a slideshow :)

I'm not sure why it's gotten so bad. I'm assuming that when you have

Rectangle rect = new Rectangle();

called in each sprite's render function, you end up with lots of rectangles lying around. Things like this I'm going to go in and change so that each sprite has rect declared at instantiation and reused. Hopefully I'm on the right idea...

:edit:

The math may add up--if I have an average of 500 sprites, rendered at 60 fps, in a minute I'll have 1.8 million rectangles.  If 100,000 live objects takes 14ms, 2 million should be about 300ms.  Does it really work like that   I've always taken GC for granted without really knowing any of the fundamentals behind it while still being able to be a somewhat accomplished game programmer! ;-)





Re: XNA Game Studio Express 360 Dev do's and don'ts

Arek Bal

Heh, have you playing Heroes of Might &Magic IV This game was slowly creating more and more objects.until crash(time depending on your memory). Garbage collector teoretically prevents this by devouring useless objects. It's a li'l of C in our life to know when objects are useless or created and minimize that.

I like your count.
But remember, smaller objects are collecting faster, while bigger slower. It's hard to predict(I wonder if anybody was "really" countin that) how long any "GCollect" will take.




Re: XNA Game Studio Express 360 Dev do's and don'ts

dagfari

My biggest concern aside from 'safety' zones, was making the game look decent on a standard definition TV.





Re: XNA Game Studio Express 360 Dev do's and don'ts

Ska Software

Yeah, with the advent of HD (but not the funds to make the move) I am mourning the death of the *readable font.* Tried Dead Rising Squint City. Crackdown is pretty bad too.

I got VGA cable but don't use it regularly because I'd have to have a setup alongside the TV, complete with some sort of sound system.





Re: XNA Game Studio Express 360 Dev do's and don'ts

Shawn Hargreaves - MSFT

Ska Software wrote:
I did; it turns the game into a slideshow :)

I'm not sure why it's gotten so bad. I'm assuming that when you have

Rectangle rect = new Rectangle();

called in each sprite's render function, you end up with lots of rectangles lying around.



That would normally be true, but Rectangle is a value type so it doesn't ever go on the heap or create any garbage.

Garbage collection is only an issue for reference types, ie. classes, or if you are doing anything that causes value types to get boxed.





Re: XNA Game Studio Express 360 Dev do's and don'ts

Ska Software

I guess that puts me back at square one again, in terms of solving this garbage problem...

What about 1 call per sprite per render of

tColor = new Color(new Vector4(r, g, b, a));









Re: XNA Game Studio Express 360 Dev do's and don'ts

Joel Martinez

again, those are both value types. A good way of finding out whether something is a value or ref type is to right click on the type name, and choose "Go To Definition". That will bring up a stub of the type ... if you see "public class", it's a reference type, if you see "public struct" it's a value type.

If you are able to run the project on windows ... run it through the CLR Profiler and see what types are getting created where. Although the collection profile will change on the 360's GC, the allocation profile will be exactly the same, so you can use that to find problem areas





Re: XNA Game Studio Express 360 Dev do's and don'ts

Arek Bal

nope color is a struct...vector also.
Still no GC.
In profiler you should see any sick performance.

http://msdn2.microsoft.com/en-us/netframework/aa569269.aspx
CLR Profiler > "Histogram by Age" from report...You can see what was collected...and how many. If thats GC...you will know what and how much...in easy way.

Edit: Heheh, Late post... "Big minds are thinking similarly"




Re: XNA Game Studio Express 360 Dev do's and don'ts

Ska Software

I think I found the culprit (or one of them at least)--lots of string.toLower() nonsense. I have an 2D animation structure where animations have names, and frames in animations can have script commands, like "setanim idle," which will make it look through the animations for one named "idle." Anyway, I took out a bunch of toLowers() and have everything set toLower() at load time (shoulda done that anyway) and I shaved 3000ms off the latency...