com.triangularpixels.rebirth.resources
Class ResourcePool

java.lang.Object
  extended by com.triangularpixels.rebirth.resources.ResourcePool

public class ResourcePool
extends Object

A pool of resource objects. Parses and creates resources from xml as well as managing their lifetimes. Resources may be loaded either immediately or in a background thread. Remember to call update() at least once a frame to keep things ticking over, and call destroy() when you're finished with it.

Author:
John Campbell

Constructor Summary
ResourcePool(ResourceIO io, FileMonitor monitor, ResourceParser parser)
           
 
Method Summary
 boolean areAllCreated()
           
 void backgroundParse(String resourcePath)
          Starts a background parse of the specified resource file.
<T extends Resource>
ResourceHandle<T>
forceCreate(Class<T> type, String resourceName)
           
 boolean isIdle()
          Returns true if no background parsing is taking place.
 boolean isInCreateQueue(ResourceHandle<? extends Resource> handle)
           
 void parse(String resourcePath)
          Opens the file specified and parses the contents.
<T extends Resource>
ResourceHandle<T>
peek(Class<T> type, String resourceName)
           
 void processCreateQueue()
           
<T extends Resource>
ResourceHandle<T>
requestCreate(Class<T> type, String resourceName)
          Adds a resource onto the create queue so that it will be fully created in a background thread.
 void requestCreateAll()
           
 void update()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourcePool

public ResourcePool(ResourceIO io,
                    FileMonitor monitor,
                    ResourceParser parser)
Method Detail

parse

public void parse(String resourcePath)
Opens the file specified and parses the contents. This is a blocking call and all parsing is done immediately in the main thread.


backgroundParse

public void backgroundParse(String resourcePath)
Starts a background parse of the specified resource file. Parsing is done in a low priority thread and resources pushed into the pool when created.

Parameters:
resourcePath -

isIdle

public boolean isIdle()
Returns true if no background parsing is taking place.


peek

public <T extends Resource> ResourceHandle<T> peek(Class<T> type,
                                                   String resourceName)

forceCreate

public <T extends Resource> ResourceHandle<T> forceCreate(Class<T> type,
                                                          String resourceName)

requestCreate

public <T extends Resource> ResourceHandle<T> requestCreate(Class<T> type,
                                                            String resourceName)
Adds a resource onto the create queue so that it will be fully created in a background thread.

Type Parameters:
T -
Parameters:
type - the type of the resource to create
resourceName - the name of the resource
Returns:
a handle to the resource which will be created, or null if not found

requestCreateAll

public void requestCreateAll()

areAllCreated

public boolean areAllCreated()

isInCreateQueue

public boolean isInCreateQueue(ResourceHandle<? extends Resource> handle)

processCreateQueue

public void processCreateQueue()

update

public void update()


Copyright © 2009 TriangularPixels.com. All Rights Reserved.