This project is read-only.

When Xen support XNA 3.1?

Jun 12, 2009 at 4:09 PM

I tried to upgrade to XNA 3.1, but an error occured in my project.


Assembly Xen.Ex.ParticlesSystemImporter was built with a reference to MicrosfotXna.Framework with an incorrect version when version was expected.



Jun 12, 2009 at 5:42 PM

Xen works fine with 3.1, and the next update will probably be 3.1. However you need to upgrade all the projects.
In order to do this, the best option is to open the two prebuild solutions and run the XNA project upgrader on each (This will upgrade all the various projects, including the content projects such as the particle system importer). These are found in ./xen/prebuild/sln.

Jun 13, 2009 at 3:40 AM

Thanks! It's works perfectly.

and... there are more questions.


I tried to make loading Screen with sample source It's works  almost but didn't work Loading Animation.

This sample used Draw method in other thread on loading state.

That, I tried to that

1. Get DrawState before Start loading. (In first call Draw, save DrawState to other variable)

2.Make new thread include DrawMethod, start Draw with Drawstate from 1. (using System.Threading.Thread Class)

3.New Thread of 2. has timer to using animation.

4.Start Loading
The timer was normally count. but Game Screen is not animated.
How to call Draw Method in other Thread?

Always appreciate.

Jun 13, 2009 at 1:22 PM
Edited Jun 13, 2009 at 3:12 PM

Short answer: You don't.

Drawing should always occur on the main thread, starting from the Application Draw() method. Internally, this is what is expected to happen, and if you do something different you will almost certainly get unexpected results. DraeState code internally is doing *loads* of state tracking and optimizations, and if suddenly calls are being made in unexpected context, then things will go wrong.

You should use the background thread to do your background loading (or whatever the processing it is you wish to be doing).
In such a case, you should use a Xen thread pool. The application has a thread pool, it can be accessed through a state object (state.Application.ThreadPool).

With the thread pool, you can create as many thread tasks as you want using QueueTask. For example async animation uses this system. Each call will return a WaitCallback structure, which can tell you if the task is complete (or let you wait for it to complete). Xen ThreadPool will manage the threads for you, and make sure to clean things up as well.
Also you shouldn't be keeping a reference to the DrawState. DrawState is intended to be used only when a method gives access to it (ie, in a Draw() method). Because of the way state and stacks are kept internally, if you use it outside of the Draw method, then things could possibly go wrong.

So, I assume you are trying to load game content on a thread - and show a loading progress bar.
The general pattern to do this would be something like this:


Create an object that loads the assets for the level, have this object implement IAction (thread action interface) and also IContentOwner.
Inside the PerformAction() method, create a new ContentRegister(Application) - and store it. Add the class to the content register to call LoadContent().
Inside this method, load all the game content.

In the main application, (on the primary thread), create an instance of the loader and store it. Add it to the thread pool with QueueTask. Store the WaitCallback.
Each frame, in the Update() method, poll the WaitCallback to see if it's done. Once it's done, carry on with your game.
In the Draw() method, draw your loading display as normal.
Once done with the level, call a method on the loader to tell it to dispose it's ContentRegister.

Granted, it's not a simple thing to do. But it should be quite robust.


 How about I make it even simpler, :-)

here is *example* code for a threaded content loader:


	public class ThreadLevelLoader : Xen.Threading.IAction, IContentOwner, IDisposable
		private ContentRegister levelContent;
		private readonly Application application;
		private bool loadingComplete;

		public ThreadLevelLoader(Application application)
			//store a ref to the application for later..
			this.application = application;

			//queue this object into the thread pool.
			this.application.ThreadPool.QueueTask(this, null);

		//use this property to check if the load is done.
		public bool LoadingComplete
			get { return loadingComplete; }

		//don't call this directly, the ThreadPool will call it for you from a task thread.
		public void PerformAction(object data)
			//here is where the loading is initalised.
			//this is on another thread

			//creating a content register requires an application.
			//it should be created on the thread it will be used on...
			this.levelContent = new ContentRegister(application);

			//add this class to the content register

		//don't call this directly, the ContentRegister will call it for you.
		public void LoadContent(ContentRegister content, DrawState state, Microsoft.Xna.Framework.Content.ContentManager manager)
			//load your content (this will be on another thread)

// when you load something here with manager.Load<..>(), how you get it back to your game is entirely up to you

loadingComplete = true; } public void UnloadContent(ContentRegister content, DrawState state) { //usually don't need to do anything here... } public void Dispose() { //call this when you are done with the level, and want to clean it's content up. //it's important to dispose the content register this.levelContent.Dispose(); } }
Jun 13, 2009 at 3:11 PM

Cool! It's works perfectly!

Your ThreadLevelLoader so cool! I edited sample's ScreenManager for Xen, and use this Loader to Show Loading Screen. It's perfectly work!.


Jul 5, 2009 at 5:19 AM

sorry i am newer to xen.i don't understand HOW to use the *ThreadLevelLoader* class in my owner project and where to put my game codes with this.

i beg you show a sample plz...

Jul 5, 2009 at 12:09 PM
Edited Jul 5, 2009 at 11:23 PM

I will be including an example built around it in the next update. It's not complete yet, as I've had what seems like a month long head cold - so I have been doing very little work on xen.

Here is an early version: (It's quite big, so I suggest copying it to a file)


I just realised there are changes in the core which will mean that code won't compile and possibly do some odd things :-)