7

I'm making an XNA game, where I often test things that cannot be edited without rebuilding the whole game application (edit and continue doesn't work). Getting to the point where I actually test things can take quite some time, because the game needs to load its resources.

What I'd like to do is to be able to load resources to some backing application and access them from the game app somehow, eliminating the need to reload game assets most of the time. Is it possible in .Net applications, or is there some other approach I should know about?

My XNA game relies heavily on Texture2D instances, specifically a library class with several Dictionary<string, Texture2D> objects.

I think what I'd like to be able to do is to have direct access to those dictionaries in the backing app from within the game app. XNA games can only be targeted at 32-bit platforms, and I would like the backing app to be 64-bit, so it could hold more than 1(.5) Gigabyte of resource data (if that's possible).


Unit testing approach (or whatever implies not using some of the resources) won't work for me in this case, since I'm developing visual effects, and it involves every texture I have.

user1306322
  • 8,561
  • 18
  • 61
  • 122
  • Maybe you can design better unit tests which do not load the huge resources and use mock data instead of large amounts of data needed for the production version. http://stackoverflow.com/questions/14087/automated-testing-a-game#14136. http://stackoverflow.com/questions/32835/xna-unit-testing – Despertar Mar 17 '13 at 18:34

4 Answers4

2

If you want to unload an reload compiled dlls full of resources then you may want to look at Application Domains. i.e. you can unload and reload assemblies with it. But you have to access their contents via a "proxy". You cannot unload assemblies directly, which is why you need domains.

The idea would be to load up a master application that never closes. Then you have a seperate Game.dll that you load up in its own Application Domain. You then load all your resources in your master application. So you would need to make a "proxy" interface for the game to get hold of the resources, but that should be doable.

The good thing about this is that you stop your game.dll, recompile it, reload the assembly and give it the still loaded resources.

One possible route.

Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
  • Sounds like what I had in mind, but how do I do that exactly? – user1306322 Mar 17 '13 at 18:44
  • Well you need to ask/answer another question: _Can you share XNA resources cross domain via proxies_. If you want to go down this route you need to ask this first. I can't help you with that one. – Meirion Hughes Mar 17 '13 at 18:46
  • I think *XNA resources* falls into *.Net resources* category, at least I don't think there should be any more problems with sharing `Texture2D` instances than `System.Drawing.Bitmap`s. – user1306322 Mar 17 '13 at 18:48
  • Well actually I don't know. Are XNA resources on GPU, page-locked, or paged memory? Can you proxy-share it if its GPU? :/ – Meirion Hughes Mar 17 '13 at 18:50
  • How do I find the kind of memory those instances are from within VS2010? – user1306322 Mar 17 '13 at 18:51
0

If you would like to have a dynamic provider/server for your resources you have a whole bunch of possibilities. With C# you could use f.e. WCF to provide your Resources. But as mentioned before maybe you should try to decouple your design so that you can actually use unit testing instead of starting the whole game.

http://en.wikipedia.org/wiki/Unit_testing

Daniel Bişar
  • 2,663
  • 7
  • 32
  • 54
  • Unfortunately, most of the new functionality is closely related to all of the game aspects, so I need pretty much everything to be loaded so I could see with my own eyes the changes, which requires all textures too. – user1306322 Mar 17 '13 at 18:46
  • What stuff you're changing? – Daniel Bişar Mar 17 '13 at 18:52
  • Menus that have buttons which run methods that do all kinds of game mechanics related things, like create a bunch of projectiles, run some animations, modify particle properties, and that means I need to see them, which in turn means loaded textures. – user1306322 Mar 17 '13 at 18:54
  • Another way could be to use dynamic code compilation. Like this you could inject 'functions' in your game and test it. I am just not sure if it is worth the effort. – Daniel Bişar Mar 17 '13 at 18:57
  • I think that may not be allowed by "edit and continue" functionality, or I may be wrong. It just doesn't sound like a good option, my code is a mess as it is, don't want to get it messier :p – user1306322 Mar 17 '13 at 18:59
  • Maybe this can help: http://stackoverflow.com/questions/826398/is-it-possible-to-dynamically-compile-and-execute-c-sharp-code-fragments i would use it just to test small functionalities. – Daniel Bişar Mar 17 '13 at 19:00
0

why not use WCF Named pipe?

just make your application as WCF server using named pip and provide Set(string spriteName,Texture2D texture)

that will change the textures..

Nahum
  • 6,959
  • 12
  • 48
  • 69
-1

It all comes down to what type of resources you want to load at run-time. If you just want to test texture / sound assets, then this can be tackled with use of the Texture2D.FromFile and SoundEffect.FromStream (MUST be PCM wave file) methods. However, if you want to load models dynamically, that requires a little extra effort. Adaptation of this sample should be able to accomplish what you need.

Sir Digby Chicken Caesar
  • 3,063
  • 1
  • 23
  • 31
  • There is no significant difference between loading compiled resources or raw image files, either way it takes an awful lot of time to load them all before the application gets to the first screen. I'd like to avoid doing it all the time, and instead load resources only once and keep them available to newly compiled game apps. – user1306322 Mar 17 '13 at 18:28
  • Well, if this is a speed / blocking issue you could try containing all content management in a separate thread (with a Cell mutex wrapper) and poll to check if assets are fully loaded. This blog post gives a pretty good overview of thread-safe content loading in XNA: http://konaju.com/?p=27. However, XNA imposes a critical section over any use of a GraphicsDevice, so if you are trying to do a great deal of animation / asset loading this could make your project MUCH slower. In that case, this might work beter: http://theinstructionlimit.com/a-shared-content-manager-for-xna. – Sir Digby Chicken Caesar Mar 17 '13 at 18:35
  • That's 2688 separate image files, nothing can be done to speed *that* up enough. Unless they're already loaded and available at any moment. – user1306322 Mar 17 '13 at 18:39