Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

LWJGL Cahce Textures in a Hashmap

4: Adsense

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   

129
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.



#2 Aldacron   GDNet+   

4490
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   Members   

9328
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   

129
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.