SVG Game Engine – Restructuring

Tonight after it cools off some, I’m going to start restructuring the code to be quite a bit cleaner.  Currently I have only built a few classes, namely the ShivaVG related classes, and a set of other game related classes.

The ShivaVG classes:

  • VGPath – A class that holds ShivaVG handles and necessary path data.
  • VGRect – A child class of VGPath which has rect specific data.
  • VGObject – A moveable object that holds a list of VGPaths.

The game classes (so far not many):

  • Bone – A single bone, which holds a 2D point where the bone starts, an angle in radians, a length for the bone, and a list of keyframes.
  • Skeleton – A collection of Bones that animate a single object.
  • Player – The player object, which will hold a VGObject and a Skeleton (and probably other things as well but I’ve not got that far).

I think the first thing I need to work on is writing a manager for drawable objects that will handle loading and setting up all of the VGObjects.  The reason I want to go this route is that I know at some point it will get too expensive to draw the static objects using vgDrawPath each frame.  Instead I’m going to set up the VGObject class to have a flag defining whether the object is static or not.  If it’s not static, it will be handled like it is currently – no change.  If it is static, however, I’m going to render it and read it back into a VGImage (which in C# is really just an IntPtr) which will be used for subsequent rendering.

Another issue requiring me to set up this manager class is gradients and how Inkscape saves them in the SVG file.  When you set up a gradient in Inkscape, it creates a child element under the svg:defs element, and the child elements of that element are the stops with the information needed to define the gradient to ShivaVG.  The actual path that uses the gradient merely holds its ID.  So to get gradient parsing working I’m going to have to parse all the gradient definitions into a list of some sort of gradient structure, then when parsing path attributes, request-by-ID the gradient defined in the style attribute of the paths.

I’m not sure how this will all be laid out or if I may end up with multiple managers (probably), but I know I also need other manager-level functionality for keeping tracking of drawing and other things.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s