Jump to content
  • Advertisement
Sign in to follow this  
JasonWelch

Resource loading

This topic is 2763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font="'Comic Sans MS"]I've been working on my current project for about 2 months or so now but recently, I decided that loading resources on the fly was a poor choice I made. It works fine when there aren't many resources being loaded at once, but in various peaks, the frame rate crawls to a stop (on my android phone). Not only that, I realized also that the texture manager I was using, didn't offer any sort of actual resource management, only creation of textures. To solve this, I created a singleton Resource Manager class in which contains several HashMaps for the various types of resources. [/font]
[font="'Comic Sans MS"]
[/font]
[font="'Comic Sans MS"]What needs to happen now is, during the initial scene / resource load call, ALL resources need to be loaded at once. I've already ported my code so that it requests textures and such from the resource manager based upon filename, but the problem is, I have some objects such as monsters, which get spawned much, much later. Until they get spawned, all the engine knows about them is the string name contained within the level data. Of course, these string names correspond to actual class's, however, HOW do I tell the resource manager to load their associated textures/sounds/etc before the objects are even created??[/font]
[font="'Comic Sans MS"]
[/font]
[font="'Comic Sans MS"]Preloading all resources is out of the question. The game we're working on is going to have 50 hand custom (non tile based) maps. Monsters and such maybe okay to preload (for the entire course of the game) but the solution I'd rather use is to simply preload all monsters, characters and scene data at load time on a per level basis. What I'm tied up with though is, How do I tell the resource manager what data to load for each type of entity? The only solution I have right now is to have a "model" for each entity AND OR have the data stored in the level file. A model would be an xml file in which would describe each monster for example. This data would only get loaded once, then all of the resources it contains would be pre loaded. Once the entity then gets created, it requests all of this data from the resource manager.[/font]
[font="'Comic Sans MS"]
[/font]
[font="'Comic Sans MS"]What do you think of this design and do you have any better ideas/solutions?[/font]

Share this post


Link to post
Share on other sites
Advertisement
I'm using a concept that is based on the following fundamental idea: Resource is the base class of resources. There is an instance of one of its concrete sub-classes for each resource known in a loaded level. I.e. the list of resource instances is part of a level. Now, such an instance doesn't contain the actual resource data but a pointer to it. Hence having the resource object loaded doesn't mean that the resource data is also loaded.

Each resource may refer to a Supply object, which may be of a ResourceImport class. (For the purpose of this thread is would be sufficient if the functionality of this import is incorporated into the Resource class directly.) An import consists (at least) of the following data: The name of the source file and the import policy. The import policy is an enum denoting the event that should cause loading of the resource data. E.g. ON_LEVEL_LOAD and ON_DEMAND and possibilities. After loading the level (and hence all Resource instances) the onLevelLoad event occurred. The list of loaded Resource instances is iterated and its supplyLoad() method is invoked if (and only if) its policy is ON_LEVEL_LOAD. When the scene later requests a resource, the belonging Resource instance is asked to return its belonging resource data. If the data is loaded the all is fine. If not, then the data is loaded right now.

Several events can be thought of that may cause loading of resources: onGameStart, onMenuShow, onLevelLoad, onLocaleSwitch, .... each used one encodable in the policy. Similarly is it possible to control unloading of resource data on several possible events.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!