Changes between Version 10 and Version 11 of UsingResources


Ignore:
Timestamp:
05/24/13 11:41:04 (6 years ago)
Author:
welberge
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsingResources

    v10 v11  
    2929BufferedInputStream ips = res.getInputStream("config.xml"); 
    3030}}} 
     31 
     32== hmi.util.Resources == 
     33The Resources class is used for more easily loading resources from some resource directory. To make this more clear, you should understand how the Java 
     34methods like getResourceAsStream search for resource files: 
     35 * First, you have a number of directories that are present on the Java runtime classpath. For instance, our ant build files ensure that (by default) the project’s resource subdirectory is always on the classpath. A second ant property called resource.path, which is usually set in the build.properties file when necessary, includes more directories on the runtime classpath. For example, a line like: resource.path=\${shared.repository}/Humanoids will include the Humanoids directory from the HMI shared repository on the classpath. 
     36 * The directories on the runtime classpath do not usually contain resource files themselves; rather, one defines subdirectories where the real resource reside. This is often necessary to avoid confusion: if some file like “config.xml” occurs at several places, that happen to be all on the classpath, it becomes unclear which one will actually be used. 
     37 * Therefore, the preferred method is to create a separate hmi.util.Resources object for every single resource directory by specifying the local directory name within one of the classpath directories. Of course, that directory name should not occur twice within the classpath directories. For example, with the resource directory and the \${shared.repository}/Humanoids on the classpath we might have a local resource directories called “icons” and “shaders” within the project’s resource directory, and resource directories like “armandia/dae” and “armandia/shaders” within ${shared.repository}/Humanoids. For each of these four directories, we then define a Resource object, for example: 
     38{{{ 
     39Resources icons = new Resources("icons"); //referring to the project’s resource/icons directory. 
     40Resources projectshaders = new Resources("shaders"); //referring to the project’s resource/shaders directory. 
     41Resources model = new Resources("armandia/dae"); //referring to the armandia/dae directory within the ${shared.repository}/Humanoids/directory. 
     42}}} 
     43 
     44== Resource caching: hmi.util.ResourcePool == 
     45The hmi.util.Resource class is fine for loading resources from a resource directory, but does not take care of resource caching. That is, when you load, for instance, some texture image via a Resource object, you might easily load the same texture image several times. Even worse, you might create several different GLTexture objects, all based on the same texture image, resulting in wasting texture memory space of your graphics card. The ResourcePool class has been designed to handle such situations. A ResourcePool object requires you to create a so called “ResourceLoader” object, to be used when some resource has to be actually loaded from a resource file. The ResourcePool will then cache the result, and deliver the cached object the next time that the same 
     46resource is asked for. 
     47 
     48 
    3149= Outdated: resource setup in Elckerlyc = 
    32 For now, see `Hmi\HmiUtil\docs\report\HmiUtilReport.tex` for an explanation. 
    33  
    3450Elckerlyc depends on a large number of resources, such as the graphical embodiments of avatars, the collections of gestures and face expressions, etcetera. There are basically two ways to include these resources into your project. Note that if a specific resource is included in more than one way at the same time, the system will get confused about which version to use :) 
    3551