SFML community forums

Bindings - other languages => DotNet => Topic started by: Kalishir on June 06, 2013, 06:20:33 pm

Title: Comparing Texture Objects
Post by: Kalishir on June 06, 2013, 06:20:33 pm
Am I correct in thinking there is no way to compare two texture objects to determine if they were constructed from the same file?

I am attempting to create a content manager that will help me minimize the number of duplicate textures by returning one from a list if it already exists. However I cannot seem to build a predicate function that returns properly.

Taking a quick look at the source files I did see that Equals and GetHashCode for Textures has not been overridden; which is what I was initially using to compare the objects. (This will, of course, return false).

Has anyone else had any luck doing something similar to what I am attempting.
Title: Re: Comparing Texture Objects
Post by: zsbzsb on June 06, 2013, 07:01:04 pm
You can use a Dictionary<TKey, TValue> to hold your textures. Make the TKey the path to the file and the TValue the texture. Then when you go to load/grab the texture you can use Dictionary<TKey, TValue>.ContainsKey(TKey) to determine of the file has already been loaded.

Here (http://msdn.microsoft.com/en-us/library/1e8ecdh9.aspx) is the MSDN reference for Dictionary<TKey, TValue>.
Title: Re: Comparing Texture Objects
Post by: Kalishir on June 06, 2013, 07:19:22 pm
Yeah, I had considered that, but I was hoping to not have the overhead of a Dictionary. Not to mention its troubles when you have a lot of inserts/deletions.

If that's the best way though, so be it.
Title: Re: Comparing Texture Objects
Post by: zsbzsb on June 06, 2013, 08:08:08 pm
Yeah, I had considered that, but I was hoping to not have the overhead of a Dictionary. Not to mention its troubles when you have a lot of inserts/deletions.

Be wary of premature optimizations  ;)

Because unless your storing a huge amount of textures you aren't going to even know about the Dictionaries overhead. And if you are storing that many textures I think you would run out of VRAM first  :D

If your concerned over the 22 or so bytes each KeyValuePair holds you probably should consider moving to C++ if your that concerned over memory. In fact for what you are trying to do is exactly what makes a Dictionary better than a List. Take a look at the following links.

http://stackoverflow.com/questions/2300859/dictionary-performance (http://stackoverflow.com/questions/2300859/dictionary-performance)
http://social.msdn.microsoft.com/Forums/en-us/csharpgeneral/thread/3fc4c78d-7cd1-47a1-a23e-ab7b0786c192 (http://social.msdn.microsoft.com/Forums/en-us/csharpgeneral/thread/3fc4c78d-7cd1-47a1-a23e-ab7b0786c192)
http://www.dotnetperls.com/dictionary-time (http://www.dotnetperls.com/dictionary-time)