Component, Manager, and Shared/Instanced Data

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Component, Manager, and Shared/Instanced Data

      Hi guys,

      I have come to the point where I need to get animations going, I have decided to start with 2D animations to keep it simple as I have never done any form of animation system coding before.

      I am having trouble visualizing my system and I would love to get some feedback to help me get things going.

      I have tried to visualize where everything should exist, for instance, the data used by animations will likely be

      - A sprite sheet
      - A custom data format for creating animation data ie

      Source Code

      1. <root>
      2. <Sprite File="Assets/Textures/SpriteSheet.png">
      3. <Running startX="0" startY="0" tileX="32" tileY="32" frameCount="10" duration="2.0"/>
      4. </Sprite>
      5. </root>


      I figured this would be all the info I really will need for animations aside from maybe event calling at certain frames. The thing that is puzzling me is, how should I have this information stored, should I
      - have an animation manager class which has a list based on actor ID which handles all the animations for that actor, and a component which controls it by calling into the manager (Similar to the Physics System/Component in GCC)
      - have all my actor animation states inside of a component and scrap the manager altogether

      I have also wondered, what should be shared and what should be instanced? I know the texture data should definitely be shared, but should I have my animation file (XML) also shared and just have my components hold onto
      a resource identifier, which it will load and grab information from each time an animation is playing? Any help is greatly appreciated, thanks.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • RE: Component, Manager, and Shared/Instanced Data

      Originally posted by mholley519
      should I
      - have an animation manager class which has a list based on actor ID which handles all the animations for that actor, and a component which controls it by calling into the manager (Similar to the Physics System/Component in GCC)
      - have all my actor animation states inside of a component and scrap the manager altogether


      If you're writing your own, you should put it all into the component, as much as possible. The main reason so much physics functionality exists outside of the physics component is because we wanted to isolate the Bullet code from our code. If you were using a 3rd party animation system, I would suggest doing something similar to what we did for Bullet.


      I have also wondered, what should be shared and what should be instanced? I know the texture data should definitely be shared, but should I have my animation file (XML) also shared and just have my components hold onto
      a resource identifier, which it will load and grab information from each time an animation is playing? Any help is greatly appreciated, thanks.

      For 2D animation, you'll want to share the texture(s) and the animation data. If you have 50 characters in the game, you can save yourself some time by making all their animations use the same format. Ultima VII is a great example of this. Most humanoid characters use the same exact animation sequences. So "walk right" would always be frames 4 - 8. That can save a bit on the tedium of building the data and also save on memory. The only instanced data should be the animation state.

      Kaykry:
      The basic idea seems okay, you just need to organize it into an animation component so that it's not tightly coupled to a bunch of other things. You could have a process that's in charge of calling Update() on all animation components. The only other system that really needs to know about animations is the render system to get the appropriate animation frame, and whatever systems you have that need to set the animation (probably gameplay scripts).

      -Rez
    • Hey, mholley519

      Funny thing. I was trying to make sprite animation as well. Unfortunately, I couldn't find any advanced sprite animation tutorials on the net (as if noone does it) and decided to make one myself. Here is what I came up with:

      Source Code

      1. <SpriteRenderComponent>
      2. <BitmapResource filename="playership.bmp" alphar="255" alphag="0" alphab="255" />
      3. <AnimationData frameWidth="27" frameHeight="21" speed="12" >
      4. <Pose name="Initial" loopAnimation="false" >
      5. <Frame index="2" />
      6. </Pose>
      7. <Pose name="SteerLeft" loopAnimation="false" return="true" >
      8. <Frame index="1" />
      9. <Frame index="0" />
      10. </Pose>
      11. <Pose name="SteerRight" loopAnimation="false" return="true" >
      12. <Frame index="3" />
      13. <Frame index="4" />
      14. </Pose>
      15. </AnimationData>
      16. </SpriteRenderComponent>
      Display All


      BitmapResource holds sprite sheet filename and transparency mask.

      AnimationData describes the frame format and speed of animation - in this case 12 FPS. It doesn't need frame count - it is calculated with sprite sheet total width and height. Frames in file are counted from left to right and from top to down.

      Next AnimationData describes the possible poses or animation runs that you call when you need to play some animation.
      For example, when my ship turns right in logic delegate I call
      SpriteRenderComponent->ChangePose("SteerRight");
      And the component runs frames 3 and 4 from the sprite sheet texture. This way the position of frames in texture file are not dependant on code, rather on XML file, which you don't need to compile. So if you want to change position of single frame in sprite sheet you dont need to change the code, just change the frame index in XML. You can even write simple editor which will handle XML stuff for you automatically.

      "loopAnimation" is what it is - should the animation loop infinitely
      "return" describes if the animation should run backwards on pose change - space ship must return to center from turning right then start turning left.

      The source code is in attachment. It somewhat messy, but it works.
      Files

      The post was edited 1 time, last by chehob ().

    • I ended up implementing my own animation system after I got the insight from Rez, wasn't really sure where the data should belong. I ended up separating my animation data from any specific sprite due to the use of being able to share an animation file with several different sprites.

      I actually ended up using shaders as well for the drawing, this allows me to pass in texture coordinates calculated for the current frame of animation, which let me also specifiy key frames in the sprite sheet so only having to specify 2 frames for any given animation clip.

      I also just used the first pixel in my pixel array, which may be a bad idea but I assume that the background colour will always be present at the top-left most pixel.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz