Jump to content

  • Log In with Google      Sign In   
  • Create Account


LWJGL Cahce Textures in a Hashmap


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 coppyhop   Members   -  Reputation: 124

Like
0Likes
Like

Posted 07 July 2014 - 04:52 PM

In my previous question, I asked how can I stop the too many files exception, I knew what my problem was, and the solution was, Have the Texture Loader Cache the Textures In a Hashmap so that the instance can check if it exists already, and then use it if it is. How can I do that? I'm using slick-utils TextureLoader.



Sponsor:

#2 Aldacron   GDNet+   -  Reputation: 3130

Like
1Likes
Like

Posted 07 July 2014 - 11:11 PM

I haven't used slick-utils, but if you can't find any option for caching in the documentation, then it's very simple to implement it yourself.

  •  
  • Create your own TextureLoader class which contains an instance of the slick-utils loader (unless the Slick loader uses static methods, of course) and a java.util.HashMap<String,Texture>.
  • Implement a load method that accepts a file name and returns a texture.
  • Inside your load method, take the following steps:
    • Try to fetch the texture from your cache by calling 'get' on your hash map instance using the file name as a key.
    • If the 'get' call returns null, call the Slick texture loader, add the loaded texture to the hash map with the file name as the key, then return it.
    • If the 'get' call doesn't return null, then simply return the texture.
  • Profit!

Edited by Aldacron, 07 July 2014 - 11:19 PM.


#3 TheChubu   Crossbones+   -  Reputation: 4062

Like
0Likes
Like

Posted 08 July 2014 - 04:21 AM


How can I do that?
What have you tried? Did you read the HashMap docs? Do you know what a key-value store is? Do you know how to save a reference for an object and retrieve it later when you need it?

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#4 coppyhop   Members   -  Reputation: 124

Like
0Likes
Like

Posted 08 July 2014 - 02:05 PM

How I load the Textures is in the Block.java I call 

import org.newdawn.slick.Texture;

import org.newdawn.slick.TextureLoader;

 

(Or something like that)

 

Texture block = null;

try{

block = TextureLoader.loadTexture(new FileInputStream(new File (type.imageURL)));

 

I have an enumerator Type which has a (String) imageURL.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS