Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File naming #4

Open
coccor opened this issue Oct 24, 2012 · 2 comments
Open

File naming #4

coccor opened this issue Oct 24, 2012 · 2 comments

Comments

@coccor
Copy link

coccor commented Oct 24, 2012

If you have a TexturePack and want to change its texture the asset filename must not be the same or it won't change the texture.
For example:
I have a texture pack ( myTexturePack ) and I want to change it for different chapters.

myTexturePack = texturepackLoader.loadFromAsset("gfx/chapter1/myGFX.xml", "gfx/chapter1/");
//we load it
myTexturePack.load();

//then we want to change it (*forget unloading stuff)
myTexturePack = texturePackLoader.loadFromAsset("gfx/chapter2/myGFX.xml", "gfx/chapter2/");
myTexturePack.load();

At this point we would aspect to have the graphics from chapter 2 loaded, but this doesn't happen because of the check made in the parser.

final String file = SAXUtils.getAttributeOrThrow(pAttributes, TexturePackParser.TAG_TEXTURE_ATTRIBUTE_FILE);

if(this.mTextureManager.hasMappedTexture(file)) {
    return this.mTextureManager.getMappedTexture(file);
}

The string should contain the whole path not just the filename or there should be a reference somewhere saying that the names of the files must be different.

~korn3l

@ptekchand
Copy link

Hello
Do you mean "the [image] file name must not be the same" for what you draw/see on screen to change? Or perhaps there is a confusion, here's how I understand it after running into a similar issue:

file in TexturePackParser.java:151 is the name of the texture image (PNG/BMP/PVR/etc) file referenced inside the XML file in the texture tag - myGFX.xml in your example.

When you create the TexturePackLoader, you pass it a TextureManager (quite likely the one from your BaseActivity). This TextureManager instance is what checks a hash map whether a particular image has already been loaded as a texture. The hash map uses the texture file name as the key (without the base path - "gfx/chapter1/" and "gfx/chapter2/" - that you provide TexturePackLoader which is passed on further to TexturePackParser). This hasMappedTexture plus getMappedTexture optimization will lead to quicker loading and saved memory in case multiple assets (XMLs) reference the same image file.

If one does not wish to use unique names for their image files, a possible "fix", may be to start including the base path in the key part of the TextureManager's mTexturesMapped hash map. This would mean appending the base path to the pID parameter of all calls to TextureManager's hasMappedTexture, getMappedTexture and addMappedTexture (Calls made in TextureManager and TexturePackParser in the parts of the project I used).

Call stack:
  TexturePackParser.parseTexture (Adds loaded Texture image into TextureManager or returns previously loaded asset. Also adds it to the TexturePack which will be accessed later)
  TexturePackParser.startElement
  XMLReader.parse
  TexturePackLoader.load    (Returns TexturePack)
  TexturePackLoader.loadFromAsset (Asset (XML) path, base path and TextureManager available/set up here.)

@coccor
Copy link
Author

coccor commented Mar 25, 2013

Yeah you are right. I meant that the images should not have the same name. Obviously the solution is changing the way the texture get's mapped. Mapping the texture by it's texture file name could lead to issues in case you have textures with the same file names, but stored in different locations.

Sorry for the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants