Skip to main content
gamedev.net
🔒 Locked

Elegant design solution

Started by DeusFacticius 4 replies 800+ views
Original Post
DeusFacticius
DeusFacticius
just looking to pick some brains here for an 'elegant' solution. problem: A resource manager deals out serializable 'handles' to resources. the handles themselves only store a string to the resource they refer to, and keep track of which resource manager they're associated w/ so that it can retrieve the resource. There are two seperate resource managers for static Images, and Animated Sprites. I'm writing a tile-based map editor, for which I want tiles to be able to be represented by either Images, or Animated Sprites. However in the tile class, storing a handle of each type, and enforcing checks to make sure only one is ever valid, doesn't seem like a clean or 'elegant' solution. I believe some form of abstraction is needed here, but I do not want to violate the rules of encapsulation. I'm using Java, so any solution involving multiple inheritance will not work :( any help?
jflanglois
jflanglois
Why do you need two handles in the first place? Can't a handle reference different resource managers, or are you telling us that the image resource manager is not the same type as the animated sprite resource manager?


jfl.
OrangyTang
OrangyTang
Quote:
Original post by DeusFacticius
There are two seperate resource managers for static Images, and Animated Sprites. I'm writing a tile-based map editor, for which I want tiles to be able to be represented by either Images, or Animated Sprites. However in the tile class, storing a handle of each type, and enforcing checks to make sure only one is ever valid, doesn't seem like a clean or 'elegant' solution.

I don't see the problem - your tiles just need to hold on to a Handle, which points at either an Image or an AnimatedImage.

Possible problems:
1. You've got separate classes for ImageHandle and AnimatedImageHandle (why?)
2. You've got separate classes for ImageResourceManager and AnimatedImageResourceManager (why?)
3. You don't have a single interface for Image and AnimatedImage. (make one!)

You're going to have to clarify your actual setup and problem.
Deyja
Deyja
Consider a normal image an animated image with only one frame, and your two heirarchys will collapse into one. :)
DeusFacticius
DeusFacticius
well what made this problem even more complicted was the fact that i considered an animated sprite a set of animations, so if an object were to reference a sprite, they'd have to specify and animation from within that sprite as well.

after reviewing my design, i think it would be best to refactor my sprite class into a simple animation chain class, as well as provide a single interface for both static and animated images. thus the resource managers could be collapsed as well.

thanks for the advice, to all.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.