0
\$\begingroup\$

I'm now managing the Loading of my Resources and I got a Question in my mind.

How does my Resource Manager know which Sprites,Sounds, etc. are used by the Map I want to load? First I thought of files which contain a list of used Sprites, Sounds etc. for every Map. E.g. like this

Map0001.map //Map Data Map0001.sfx //List of Sounds Map0001.gfx //List of Sprites Map0001.tle //Tileset 

This makes x4 more files than maps and I'm not sure if this is efficient, since every File has to be loaded and it's content read separately.

Any Idea on how to do this properly?

\$\endgroup\$
2
  • \$\begingroup\$ You can do the separate files as individual chunks in a packed level file. It won't really gain you much, as you still need to maintain the data. Pick any, it won't be much of a bottleneck. \$\endgroup\$ Commented Feb 23, 2015 at 9:41
  • \$\begingroup\$ It sounds like you're optimising too early. Loading 4 files instead of 1 is next to no perceptible difference on a modern machine. \$\endgroup\$ Commented Feb 26, 2015 at 22:09

1 Answer 1

1
\$\begingroup\$

I personally just pack them into an archive file format.

Something as simple as the Quake .PAK file should be enough for this case. It's pretty simple to load and has tools that make packing files into them easier.

Here is documentation on the format, along with a C example (which is pretty simple to convert to Java).

If you want to compress the files, look into zlib Java bindings, and you could either append onto the .PAK file format to allow for compression or you could just use the .zip file format instead.

EDIT:

Apparently I misinterpreted the original post.

I expressed myself wrong. Let's say my Map contains an enemy. How exactly does my Asset Manager know which file this Sprite uses, when it does not have access to the single Sprites within the Map?

You just store what's needed directly in the map file itself. When the AssetManager class loads the map, it should read in the portion of the file that contains a list of what's required. It's pretty efficient since everything is packed together in contiguous memory and can be read from pretty quickly. It's also really simple.

/* Pseudocode... */ struct map_asset_section_t { uint32_t num_entites; uint32_t num_animations; uint32_t num_tilesets; hash32_t entities[num_entities]; //... etc }; 
\$\endgroup\$
2
  • \$\begingroup\$ I expressed myself wrong. Let's say my Map contains an enemy. How exactly does my Asset Manager know which file this Sprite uses, when it does not have access to the single Sprites within the Map? \$\endgroup\$ Commented Feb 23, 2015 at 19:31
  • \$\begingroup\$ This is my first time posting on this site so I'm not exactly familiar with what's allowed, so I hope I'm doing this correctly. Anyways, I updated my answer in response to your clarification. \$\endgroup\$ Commented Feb 23, 2015 at 22:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.