Sign in to follow this  
MajinMusashi

Class design of an animation library

Recommended Posts

Hi! [/b]CONTEXT: [/b]I'm using C++ and OpenGL, and I'll extend an old 2D animation library (mostly used as a sprite manager) used in my little projects so that it can handle text, sound effects and streaming audio (imagine a simplified Macromedial Flash for use in games). This is the supposed class diagram: Free Image Hosting at www.ImageShack.us
// The different "Frame" classes have different member variables. Example:

class BitmapFrame {
  Vector2 pos;
  float width;
  float height;
};
class TextFrame {
  Color color;
  Rectangle box;
};

// "Sequence" classes in the same domain inherit from a base class. Example:

class BitmapSequence {
  virtual void update( unsigned int passedTime ) = 0;
};
class BitmapColorSequence : public BitmapSequence {
  // ...
};
class BitmapMotionSequence : public BitmapSequence {
  // ...
};



PROBLEM: I can't imagine a simple way of doing that without hardtyping a lot of code related to the frames and sequences. Maybe if something like a "templated namespace" existed things would be easier, but AFAIK this is not the case. QUESTION: Do you have any advice on how to best represent this hierarchy? Is there some design pattern I'm not aware of (or I'm not intelligent enough to understand and adapt) that would do the job? Thanks a lot! PS.: Object-derived classes need access to the Frame class, so I can't make the previous a nested class of Sequence (Sequence keeps only references to two consecutive frames) [Edited by - MajinMusashi on July 23, 2006 1:31:54 PM]

Share this post


Link to post
Share on other sites
Does it need to be anything more complicated than this?


template <typename T, typename U> class cSequence
{
std::vector<T> mFrames;
std::vector<U *> mSequences;
};

typedef cSequence<cBitmapFrame, cBitmapSequence> cBitmap;

class cDerivedBitmap : public cBitmap
{
};

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Does anything outside the Sequence classes need access to the Frame classes? See if you can make them inner classes or something, which may cut down on class bloat.

There is something called namespace aliasing. An example of how I (would) use it:

namespace win32 {
class Window {...};
}

namespace osx {
class Window {...};
}

#ifdef _WIN32
namespace os = win32;
#else
namespace os = osx;
#endif // OS

os::Window NewWindow;

Share this post


Link to post
Share on other sites
Quote:
Original post by JasonBlochowiak
Does it need to be anything more complicated than this?


template <typename T, typename U> class cSequence
{
std::vector<T> mFrames;
std::vector<U *> mSequences;
};

typedef cSequence<cBitmapFrame, cBitmapSequence> cBitmap;

class cDerivedBitmap : public cBitmap
{
};


Hi, Jason!
I'm a bit confused about the source code you've posted. The "frames" and "sequences" don't belong to the sequence class, neither Bitmap is a sequence, nor I need a derived bitmap.
Please, could you elaborate?

Thanks a lot!

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Does anything outside the Sequence classes need access to the Frame classes? See if you can make them inner classes or something, which may cut down on class bloat.

Yes, because the frame objects are stored inside a vector in the Object-derived classes. Sequences keep only references to frames...

Quote:

There is something called namespace aliasing. An example of how I (would) use it:

namespace win32 {
class Window {...};
}

namespace osx {
class Window {...};
}

#ifdef _WIN32
namespace os = win32;
#else
namespace os = osx;
#endif // OS

os::Window NewWindow;


Very interesting trick, but how can this be applyed to the given example?

Thanks a lot, AP!

[Edited by - MajinMusashi on July 23, 2006 6:08:56 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this