Spyrrho

I'm wondering if the content manager uses caching... I have noticed quite a few people build objects like texture caches and so forth. Is this really necessary

Previous to XNA I would create a texture 1 time and share it across multiple sprite classes... rendering the same texture at many different locations (1 for each sprite) during a single pass.

Is it safe to just use the ContentManager inside of the sprite class with XNA

Example

//constructor
public
Sprite(string asset)
{this.texture = game.ContentManager.Load<Texture2D>(asset);}

I've built my classes like this because I made the assumption that the content manager would only load a particular asset in memory once. But since it's an assumption I'm now posing the question.

...or should I go back to my old paradigm of loading it once and just redrawing it at multiple positions.



Re: XNA Framework Does Content Manager use Caching?

Jim.Welch

The help doc says:

"Repeated calls to load the same asset will return the same object instance."

So I understand that to believe that it is cached, otherwise, it would be a different instance of the asset. (that was found on the ContentManager.Load Generic Method page)





Re: XNA Framework Does Content Manager use Caching?

Spyrrho

Is there a benefit to building objects like texture caches then, since content manager is already do this I'm wondering why I see so many of them in released source.

Thanks for the reply.





Re: XNA Framework Does Content Manager use Caching?

Jim.Welch

Are you looking at source code down with beta 1 Back then, everyone was doing that because there wasn't a content pipeline. Otherwise, some people might do it because they are doing other things within the cache (maybe ) or because its code that they ported from another system (like MDX).




Re: XNA Framework Does Content Manager use Caching?

Spyrrho

A bit of both... v1 code i have is not doing it as often as the beta stuff. Ported code sounds logical as I don't see much else happening besides caching.

Thanks for the info.