QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

oslAnimLib - Animation Class for OSlib Users

This is a discussion on oslAnimLib - Animation Class for OSlib Users within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; oslAnimLib Here's a class for you OSlib users, capable of handling multiple image and spritesheet animations - any size, your ...

Reply
 
LinkBack Thread Tools
Old 03-26-2008, 07:52 PM   #1

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Exclamation oslAnimLib - Animation Class for OSlib Users

oslAnimLib

Here's a class for you OSlib users, capable of handling multiple image and spritesheet animations - any size, your only limit is the RAM and OSlib's PNG-format-only restriction. As a benchmark for you - about 175 160x172 PNG images is where it'll fill up either completely or be very close to.

The documentation and example usage is in the header itself (on the important stuff, some of the stuff is a given) so no need for some online documenation, however it would be nice. (i may do it later) The sample should also aid in your understanding (not really that hard though)

It's a C++ class so for you C users out there do the following to use it, note this information is also in the header file so you don't need to reference back here each time:

Add -lstdc++ to your LIBS makefile line
Change your source file's extension to .cpp INSTEAD of .c

That should do it (you may find using a C/C++ combo better then just C).

Didn't take long at all to write, but debugging took some time

The sample is straightforward and easy to follow. You'll find using this for animations gives you just as amount of control as an image does - rotation, scaling, etc. and then some.

Credits:
Inspired by Grimfate's animLib in Lua
yaustar for his help with a troubling vector situation
Brunni (@ ps2dev) for Oslib

If you do use this, I only ask you state that you used this, by me (sg57), to handle animations.

thanks and I hope this comes in handy

DOWNLOAD
(like 500kb - the animations in the sample give it it's size)

Screens of the sample (hopefully my bandwidth is ok from the neoflash competition :S):


__________________

Last edited by SG57; 03-27-2008 at 04:46 AM..
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-26-2008, 08:53 PM   #2

Developer
 
snowymydog's Avatar
 
Join Date: Jun 2006
Posts: 82
Trader Feedback: 0
Default

I'm using OSLIB all the time. Like you do, I have my self written extension to OSLIB. Maybe I'll share it too.

At the moment, I cannot dl your work but I'll check it later today. Just a simple question. OSLIB itself has it own rotate, zoom ability and it's simple to deal with. What benefits does your class provide? Thx.
snowymydog is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-26-2008, 10:04 PM   #3

Developer in Making...
 
BlackShark's Avatar
 
Join Date: Oct 2006
Location: Pimp'en in the US F#cking A!!!
Posts: 1,254
Trader Feedback: 0
Default

um, animations?
__________________
The Wentire Worls in two Sectors....
When did I get dev statz?
Spoiler for my PSP homebrewReleases:
Ace of Space V1|PvP Pong Online|PvP Pong v3 | 3.03 BlackShark Custom Firmware
(PvP Pong DL'ed well over 2403 times combined! get yours now!)
Spoiler for Great Quotes:

"No Snowflake in an Avalanche ever feels responsible....." - Fortune Cookie.
BlackShark is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-26-2008, 10:39 PM   #4

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

Quote:
Originally Posted by snowymydog
I'm using OSLIB all the time. Like you do, I have my self written extension to OSLIB. Maybe I'll share it too.

At the moment, I cannot dl your work but I'll check it later today. Just a simple question. OSLIB itself has it own rotate, zoom ability and it's simple to deal with. What benefits does your class provide? Thx.
Animations aren't natively supported by OSlib. You'd usually declare an image with the OSL_IMAGE structure, with this you use the OSL_ANIMATION class. You can load sprite sheets and/or multiple images for an animation and use it much like you would an image in OSlib.

ex
Code:
OSL_ANIMATION myAnimation;

...

myAnimation.Load(...pass stuff here...);

...

myAnimation.Initialize(...pass stuff here...);

...

myAnimation.Update();
..
myAnimation.Draw();
That's really all you need to do. Then there are more things you can do to adjust the animation - scale, rotate, reverse animation, slow down animation, speed up animation, loop animation, etc.

The sample code demonstrates it's ease of use compared to hard coding the animations in, using this class will take a load off your mind ^^ I'm currently using this in my project and it works great - it's optimized nearly as much as it can (inlined, no memory leaks - next best thing would be to reference everything instead of pass direct values in the setXX() functions).

Hope that helps
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-26-2008, 11:36 PM   #5

Developer
 
snowymydog's Avatar
 
Join Date: Jun 2006
Posts: 82
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
Animations aren't natively supported by OSlib. You'd usually declare an image with the OSL_IMAGE structure, with this you use the OSL_ANIMATION class. You can load sprite sheets and/or multiple images for an animation and use it much like you would an image in OSlib.

ex
Code:
OSL_ANIMATION myAnimation;

...

myAnimation.Load(...pass stuff here...);

...

myAnimation.Initialize(...pass stuff here...);

...

myAnimation.Update();
..
myAnimation.Draw();
That's really all you need to do. Then there are more things you can do to adjust the animation - scale, rotate, reverse animation, slow down animation, speed up animation, loop animation, etc.

The sample code demonstrates it's ease of use compared to hard coding the animations in, using this class will take a load off your mind ^^ I'm currently using this in my project and it works great - it's optimized nearly as much as it can (inlined, no memory leaks - next best thing would be to reference everything instead of pass direct values in the setXX() functions).

Hope that helps
ic, that's something similar to my stuff. However, I didn't do anything on zoom and rotation, cause my project doesn't need zoom and rotation.

My lib uses definition file(s) to load the sprite sheets. You can have many sprite sheets within a definition file and many definition file within your program. Load the definition and all the animation are ready to go. If you need to fine tune the animation, just edit the definition file(plain text format), no need to recompile. Your program don't need to know what png need to load, all declared by the definition file.

I did upload to some web free space and share in an old thread, but it seems the dl link has expired. Anyway I'll upload again and let's discuss again.
snowymydog is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 03:16 AM   #6

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

I had a quick look and fixed a memory leak and places where you were needlessly copying by value. I don't understand why you put everything in the header and not some in a separate source file.

I look over the actual design later.

Code:
#ifndef OSL_ANIMLIB_H
#define OSL_ANIMLIB_H

/*
               oslAnimLib
     
   This is a library to aid in animating
  multiple images or a sprite sheet in the
  advanced 2D graphics library 'OSlib' for
 the PSP.  Inspired by animLib, same concept
    but for, and in, Lua by Grimfate126.
     
     My only request is that if you
    use this in your project, you give
some credit to myself for this particular
         mechanic (animations)
     
 Let me know if this has been of use to you
       and possibly request another
      useful class you'd like to see
     
                                    ~ SG57
*/


// Check out the sample for correct usage of this library
//
// If your using C, add -lstdc++ to your LIBS makefile line
// and change your source file's extension to .cpp INSTEAD of .c - that's it!
class OSL_ANIMATION
{
  private:
    OSL_IMAGE *sSpriteSheet;   // since oslCreateImageTile references the image, we can't delete it afterwards or have it temporary
    std::vector<OSL_IMAGE*> vFrames; // dynamic array of OSL_IMAGE's
    std::string sFilename;          // file path and name for the images
    int iX, iY;                // coordintes of the animation
    int iWidth, iHeight;       // dimensions of the animation
    int iCenterX, iCenterY;    // the 'pole' the image is rotated around
    int iNumFrames;            // number of frames
    int iCurrentFrame;         // current frame in the animation were on
    int iStartFrame;           // frame that the animation starts on
    int iEndFrame;             // frame that the animation ends on
    int iDelay;                // delay count until we go to the next frame in the animation
    int iDelayCount;           // internally used - this value is incremented til' it reaches iDelay then resets
    float fAngle;              // angle in degrees the animation is rotated
    bool bPlay;                // flag to tell if we should play the animation
    bool bLoop;                // flag to tell if we should loop the animation
    bool bReverse;             // flag to tell if we should play animation reversed
    
  public:
    // Constructor
    OSL_ANIMATION() : sFilename("/"), iX(0), iY(0), iWidth(0), iHeight(0), iCenterX(0), iCenterY(0), iNumFrames(0), iCurrentFrame(0), iEndFrame(0), iDelay(0),
                      iDelayCount(0), fAngle(0.0f), bPlay(false), bLoop(false), bReverse(false)
    {
      sSpriteSheet = NULL;
      vFrames.clear();
    }
    // Destructor
    ~OSL_ANIMATION()
    {
      Unload();
    }

    /*
                               DO
      These functions actually do stuff, not set/get values
    */
    
    /* Description: This loads the animation's frames using a sprite sheet           */
    /* Usage: Call this before any other OSL_ANIMATION call - uses interval + offset */
    /* Example:                                                                      */
    /*       animWalkingLeft.Load("Images/Resources/Huge Explosion",6,0,0,32,32,true)*/
    /*   This will load 6 frames, starting at 0,0 each with the dimensions 32x32     */
    /*                            going across horizontally                          */
    void Load(const std::string & filename, const int numframes, const int startx, const int starty, const int width, const int height, const bool horizontal)
    {
      Unload();

      sSpriteSheet = oslLoadImageFile( (filename + ".png").c_str(), OSL_IN_RAM, OSL_PF_8888); // load it
      oslAssert(sSpriteSheet); // verify it loaded correctly

      int StartX = startx; // these are used for if the sprite sheet row/coloumn end is reached
      int StartY = starty;
      int tmp = 0;   // temporary var used for the rows and coloumns in the animation
      iWidth = width;
      iHeight = height;
      iNumFrames = numframes;

      for (int i = 0; i < numframes; i++)
      {
        vFrames.push_back(oslCreateImageTileSize(sSpriteSheet, StartX + (horizontal ? (tmp * width) : 0), StartY + (horizontal ? 0 : (tmp * height)),
                                                 width, height));
        oslAssert(vFrames[i]);

        tmp++;

        // now we check and fix any sprite sheet sprite row/coloumn endings
        if (horizontal)
        {
          if (StartX + ((tmp) * width) >= sSpriteSheet->stretchX)
          {
            StartY += height; // go down a row
            StartX = startx;
            tmp = 0;
          }
        }
        else
        {
          if (StartY + ((tmp) * height) >= sSpriteSheet->stretchY)
          {
            StartX += width; // move over a coloumn
            StartY = starty;
            tmp = 0;
          }
        }
      }

      sFilename = filename;
    }
    
    /* Description: This loads the animation's frames using a multiple images        */
    /* Usage: Call this before any other OSL_ANIMATION call                          */
    /* Example:                                                                      */
    /*       animWalkingLeft.Load("Images/Resources/Huge Explosion",6)               */
    /*   This will load 6 frames named consecutively located at                      */
    /*              ImagesResources/Huge Explosion[0 - 6 here].png                   */
    void Load(std::string filename, const int numframes)
    {      
      Unload();
      
      iNumFrames = numframes;
      
      char tempFilename[500];

      for (int i = 0; i < iNumFrames; i++)
      {
        snprintf(tempFilename, 500, "%s%i.png",filename.c_str(),i+1);
        
        vFrames.push_back(oslLoadImageFile(tempFilename, OSL_IN_RAM, OSL_PF_8888)); // add it
        oslAssert(vFrames[i]);
      }
      
      iWidth = vFrames[0]->stretchX;
      iHeight = vFrames[0]->stretchY;
      sFilename = filename; // just set it back to how it was...
    }
    
    /* Description: This unloads the animation's frames                              */
    /* Usage: Call this when leaving a state, exiting the game, etc.                 */
    void Unload()
    {
      for (int i = 0; i < (int)vFrames.size(); i++)
      {
        if (vFrames[i])
          oslDeleteImage(vFrames[i]);

        vFrames[i] = NULL;
      }
      vFrames.clear();

      if (sSpriteSheet)
        oslDeleteImage(sSpriteSheet);
        
      sSpriteSheet = NULL;
    }
    
    /* Description: This initializes alot of members                                 */
    /* Usage: Call this after you load the animation or to reset the animation       */
    /* Example:                                                                      */
    /*         animWalkingLeft.Initialize(0,0,32,32,0,10,20,false,true,false)        */
    /*                                                                               */
    /* This makes animWalkingLeft X and Y at (0,0).  It's width and height 32, it's  */
    /* starting frame at 0, ending frame at 10. The animation delay at 20, it's angle*/
    /* at 0 degrees, it won't play after being initialized, it will loop when played */
    /* and it won't play reversed.                                                   */
    void Initialize(const int x, const int y, const int width, const int height, const int startFrame, const int endFrame,
                    const int delay, const bool play, const bool loop, const bool reverse)
    {
      iX = x;
      iY = y;

      if (width != -1) iWidth = width;
      if (height != -1) iHeight = height;

      iCenterX = iWidth/2; // middle of image
      iCenterY = iHeight/2;// "

      iStartFrame = startFrame;
      iEndFrame = endFrame;

      iDelay = delay;
      iDelayCount = 0;

      fAngle = 0.0f;

      bPlay = play;
      bLoop = loop;
      bReverse = reverse;

      if (bReverse)
        iCurrentFrame = iEndFrame - 1;
      else
        iCurrentFrame = iStartFrame;
    }
    
    /* Description: This does all the drawing for the animationn                     */
    /* Usage: Call this in your main loop for when you want the animation to be drawn*/
    /* Example:                                                                      */
    /*            if ((bool) bWalkingLeft)                                           */
    /*            {                                                                  */
    /*              animWalkingLeft.Draw();                                          */
    /*            }                                                                  */
    void Draw()
    {
      if (bPlay)
      {
        if (!vFrames[iCurrentFrame])
          oslDebug("%s\nvFrames[%i] not loaded!",sFilename.c_str(),iCurrentFrame);

        oslDrawImage(vFrames[iCurrentFrame]);
      }
    }
    
    /* Description: This does all the thinking for the animation                     */
    /* Usage: Call this in your main loop for when you want the animation to update  */
    /* Example:                                                                      */
    /*            if ((bool) bWalkingLeft)                                           */
    /*            {                                                                  */
    /*              animWalkingLeft.Update();                                        */
    /*            }                                                                  */
    void Update()
    {
      if (bPlay)
      {
        // if the frames are out of whack :S
        if (iEndFrame < iStartFrame)
          oslDebug("When updating an animation, it appears it's end frame (%i) is LESS THEN it's start frame (%i)\n\nwtf is wrong with you?", iEndFrame, iStartFrame);

        for (int i = iStartFrame; i < iEndFrame; i++)
        {
          if (!vFrames[i])
            oslDebug("%s\nvFrames[%i] not loaded!",sFilename.c_str(),i);

          // update animation frames' value's
          vFrames[i]->x = iX;
          vFrames[i]->y = iY;
          vFrames[i]->stretchX = iWidth;
          vFrames[i]->stretchY = iHeight;
          vFrames[i]->centerX = iCenterX;
          vFrames[i]->centerY = iCenterY;
          vFrames[i]->angle = fAngle;
        }

        // delay stuff
        iDelayCount++;

        if (iDelayCount >= iDelay)
        {
          if (bReverse)
          {
            iCurrentFrame--;

            if (iCurrentFrame < iStartFrame)
            {
              iCurrentFrame = iEndFrame - 1;

              if (!bLoop)
              {
                bPlay = false;
              }
            }
          }
          else
          {
            iCurrentFrame++;

            if (iCurrentFrame >= iEndFrame)
            {
              iCurrentFrame = iStartFrame;

              if (!bLoop)
              {
                bPlay = false;
              }
            }
          }

          iDelayCount = 0;
        }
      }
    }

    /*
                          SET
      These functions set private members' values
    */
    
    /* Description: This sets the bPlay boolean to true meaning play the animation   */
    /* Usage: Pass this when an event occurs and you want to play the animation      */
    /* Example: myAnimation.setFilename("Resources/Animations/Huge Explosion")       */
    inline void Play()
    {
      bPlay = true;
    }

    /* Description: This sets the file path and base file name, doesn't reload though*/
    /*                                               use Unload() and Load() for that*/
    /* Usage: Pass this a string containing the path to the animation (no extension) */
    /* Example: myAnimation.setFilename("Resources/Animations/Huge Explosion")       */
    inline void setFilename(const std::string & filename)
    {
      sFilename = filename;
    }
    
    /* Description: This sets y-coordinate as to where to draw the animation         */
    /* Usage: Pass this an integer for where to draw the animation on the y-axis     */
    /* Example: myAnimation.setY(272)                                                */
    inline void setY(const int y)
    {
      iY = y;
    }

    /* Description: This sets x-coordinate as to where to draw the animation         */
    /* Usage: Pass this an integer for where to draw the animation on the x-axis     */
    /* Example: myAnimation.setY(480)                                                */
    inline void setX(const int x)
    {
      iX = x;
    }

    /* Description: This sets the width of the animation                             */
    /* Usage: Pass this an integer that the animation's width will be stretched to   */
    /* Example: myAnimation.setWidth(256)                                            */
    inline void setWidth(const int width)
    {
      iWidth = width;
    }
    
    /* Description: This sets the height of the animation                            */
    /* Usage: Pass this an integer that the animation's height will be stretched to  */
    /* Example: myAnimation.setHeight(256)                                           */
    inline void setHeight(const int height)
    {
      iHeight = height;
    }
    
    /* Description: This sets the center X of rotation of the animation              */
    /* Usage: Pass this an integer that the animation's rotation center X will be    */
    /* Example: myAnimation.setCenterX(128)                                          */
    inline void setCenterX(const int x)
    {
      iCenterX = x;
    }
    
    /* Description: This sets the center Y of rotation of the animation              */
    /* Usage: Pass this an integer that the animation's rotation center Y will be    */
    /* Example: myAnimation.setCenterY(128)                                          */
    inline void setCenterY(const int y)
    {
      iCenterY = y;
    }
    
    /* Description: This sets the angle of the animation                             */
    /* Usage: Pass this an integer that the animation will be rotated to (degrees)   */
    /* Example: myAnimation.setRotationAngle(180)                                    */
    inline void setRotationAngle(const float angle)
    {
      fAngle = angle;
    }
    
    /* Description: This sets the delay of the animation                             */
    /* Usage: Pass this an integer that the animation will delay for before going to */
    /*        the next frame in the animation (tweak this til it's right)            */
    /* Example: myAnimation.setDelay(100)                                            */
    inline void setDelay(const int delay)
    {
      iDelay = delay;
    }
    
    /* Description: This sets the current frame of the animation                     */
    /* Usage: Pass this an integer that the current animation frame will be displaed */
    /* Example: myAnimation.setCurrentFrame(2)                                       */
    inline void setCurrentFrame(const int frame)
    {
      if (vFrames[frame])
        iCurrentFrame = frame;
      else
        oslDebug("problem when setting the current frame to %i - it isn't loaded?", frame);
    }
    
    /* Description: This sets the starting frame of the animation                    */
    /* Usage: Pass this an integer that the animation will start on                  */
    /* Example: myAnimation.setStartFrame(3)                                         */
    inline void setStartFrame(const int frame)
    {
      iStartFrame = frame;
    }

    /* Description: This sets the ending frame of the animation                      */
    /* Usage: Pass this an integer that the animation will end on                    */
    /* Example: myAnimation.setEndFrame(7)                                           */
    inline void setEndFrame(const int frame)
    {
      iEndFrame = frame;
    }

    /* Description: This sets whether or not to loop the animation                   */
    /* Usage: Pass this a boolean for if the animation should loop when finished     */
    /* Example: myAnimation.setLoop(true)                                            */
    inline void setLoop(const bool loop)
    {
      bLoop = loop;
    }
    
    
    /* Description: This sets whether or not to play the animation backwards         */
    /* Usage: Pass this a boolean for if the animation should play reversedished     */
    /* Example: myAnimation.setReverse(true)                                         */
    inline void setReverse(const bool reverse)
    {
      bReverse = reverse;
    }

    /*
                     GET
      These functions get private members
      
      Won't demonstrate usage of the obvious ones ;)
    */
    inline const std::vector<OSL_IMAGE*> & getFrames()
    {
      return vFrames;
    }
    
    inline const std::string & getFilename()
    {
      return sFilename;
    }

    inline const int getY()
    {
      return iY;
    }
    inline const int getX()
    {
      return iX;
    }
    inline const int getWidth()
    {
      return iWidth;
    }
    inline const int getHeight()
    {
      return iHeight;
    }
    inline const int getCenterX()
    {
      return iCenterX;
    }
    inline const int getCenterY()
    {
      return iCenterY;
    }
    inline const float getRotationAngle()
    {
      return fAngle;
    }
    inline const int getDelay()
    {
      return iDelay;
    }
    inline const int getStartFrame()
    {
      return iStartFrame;
    }
    inline const int getEndFrame()
    {
      return iEndFrame;
    }
    inline const int getCurrentFrame()
    {
      return iCurrentFrame;
    }
    inline const int getFrameCount()
    {
      return iNumFrames;
    }
    
    inline const bool isPlaying()
    {
      return bPlay;
    }
    inline const bool isLooped()
    {
      return bLoop;
    }
    inline const bool isReversed()
    {
      return bReverse;
    }
};

#endif
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 03:22 AM   #7

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

Seems like a step above what I've done (except for the rotation and scaling). Mine could be easily adapted to do that but hey not my cup of tea - the less external file requirements my games need the better

yaustar - I did so many things to the source to fix that darn bug with the sprite sheets and my sorta less-then-perfect C++ skills I'm not surprised. I didn't think to call Unload like that - helps readability to say the least

I kept it all in one header file to remove the need to link the object file - I always seem to forget to until I get the implicit declarations. I could always copy over the non-inlined if it's better that way - what do you think? I've updated the file with that by the way - thanks

EDIT

OH I forgot to reference gahhh.... I asked you earlier so when I did fix that spritesheet bug I would reference anything I could but I forgottt Thanks again yaustar one more mess up on my part... By the way is that type of formatting 'acceptable' to you? And thanks for your time, again, yaustar - I'm sure eventually I'll be able to make something similar to how you would've without a problem.

One more thing - it seems oslLoadImageFile doesn't like taking a const char* as it's file name
Code:
oslAnimLib.h:78: error: invalid conversion from 'const char*' to 'char*'
oslAnimLib.h:78: error:   initializing argument 1 of 'OSL_IMAGE* oslLoadImageFil
e(char*, int, int)'
That explains why I was copying it to a char*
__________________

Last edited by SG57; 03-27-2008 at 04:01 AM..
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:04 AM   #8

Developer
 
jsharrad's Avatar
 
Join Date: Oct 2005
Real First Name: Justin
Location: Dubuque
Just Played: ..
Posts: 414
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
Credits:
.....
PSdonkey (@ psphacks) for Oslib
I think PSdonkey and Brunni (the author of OSLib) are two different people.
__________________
PSP Demo Videos (updated 11/29/08)
MinerPSP Coder
jsharrad is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:10 AM   #9

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

It should definitely not be all in the header. This means that when you change the behaviour of a function, you are forced to recompile all the source files that include it.

As for the const char, that's really bad on OSL's part. I be tempted to const_cast it if I was sure that the function doesn't modify it.
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:10 AM   #10

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

jsharrad - Ah ya I see now. However PSdonkey released multiple versions of OSlib with functions for showing say the neoflash logo or psphacks logo. They are one and the same I believe

yaustar - I thought the same when I passed it the filename string as well a few days ago.

I didn't know about the header file -> recompile everything that includes it. It makes sense just never thought of that. I'm updating it now to reflect that. Thanks yaustar

k it's edited to reflect the change
__________________

Last edited by SG57; 03-27-2008 at 04:23 AM..
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:11 AM   #11

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Quote:
Originally Posted by jsharrad
I think PSdonkey and Brunni (the author of OSLib) are two different people.
They are. PSDonkey modified some of the source for his competition.
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:26 AM   #12

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

Is the source released or are Brunni and PSDonkey close friends or what?

In any case I'm updating the first post to say Brunni. (also the class now has it's non-inlined functions in it's own source file - recompiled and updated sample and whatnot)
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:38 AM   #13

Developer
 
jsharrad's Avatar
 
Join Date: Oct 2005
Real First Name: Justin
Location: Dubuque
Just Played: ..
Posts: 414
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
Is the source released or are Brunni and PSDonkey close friends or what?
Just the older version, you can pick it up from his website, http://brunni.dev-fr.org/
__________________
PSP Demo Videos (updated 11/29/08)
MinerPSP Coder
jsharrad is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:55 AM   #14

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

Whoa there's a new version?

Didn't know that Mp3 support is nice By the way - there's a problem with that install batch file. It tries to copy lib/libmikmod.a when it should jsut be libmikmod.a (that or he forgot to make a lib folder and put libmikmod.a in it XD)
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 08:48 AM   #15


Developer
 
daaa57150's Avatar
 
Join Date: Sep 2006
Location: france
Posts: 167
Trader Feedback: 0
Default

Quote:
Originally Posted by yaustar
As for the const char, that's really bad on OSL's part. I be tempted to const_cast it if I was sure that the function doesn't modify it.
That's what I do, never had a problem.

Also SG, what all animation libraries lack is the ability to not load many times the same image. Like if you have 10 same enemies on screen, they all use the same images right? So every image used should be loaded only once, and animations should use pointers to those. Haven't looked at your lib, but if it doesn't do that and you want to know how to do it, I can help because I myself wrote an animation class with this ability (c++ too, using stdlib too).
__________________
Try my latest game:
MEGA DROPS 2

daaa57150 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 02:36 PM   #16

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

daaa - I see what you mean. one method that might work is to load all frames ever loaded using that class into a global vector where every image/frame loaded is ran through that vector for any reoccurances and if there is any, point to that image's location in the vector. I'm sure I can get something working by tonight but it'll probably need some tweaks by yaustar to make it better.

EDIT

Actually - I'm going to store the filepath's and run them through a vector and find any reoccurances - will make loads much faster and makes sense - can't have 2 images in the same spot unless that split second it's loading you somehow rename, copy over, rename again.
__________________

Last edited by SG57; 03-27-2008 at 02:46 PM..
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 03:25 PM   #17

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Don't use vectors, use a std::map. It has a much faster lookup operation (almost O(1)). If you can, use a hashed filename for the key rather then the actual string.
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 04:08 PM   #18

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

I've never heard of nor used map's... I'll need to read up on them for abit.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 05:52 PM   #19
 
Join Date: Mar 2007
Posts: 26
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
Is the source released or are Brunni and PSDonkey close friends or what?

In any case I'm updating the first post to say Brunni. (also the class now has it's non-inlined functions in it's own source file - recompiled and updated sample and whatnot)
This is PSdonkey from psp-hacks.com

Brunni and I are good friends and he is the one that created OSlib. I am the one who made several lessons on how to use and implement OSlib into programming for the PSP. I also added new features and functions into the previous version of OSlib(not the new one that supports mp3 playback). I was actually going to implement mp3 playback and streaming video capabilities into the new version with Brunni but I never had the chance to do it.

Also, SG57, I saw your post on not knowing how to use maps. I wrote a detail tutorial on how to use and create maps using OSlib. I also wrote several other tutorials for using OSlib for animations and collision detection if you care to read them.

You can find everything here:
http://www.psp-hacks.com/forums/viewtopic.php?id=66708
PSPHacks is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-27-2008, 06:53 PM   #20

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

How long ago are we talking here PSPHacks? I haven't asked a question there in a very long time.

And ya I know all about your lessons and examples. I haven't really used them, other then as a reference for basic usage of a few functions. But i will use the map example cause something I'm making will be better with maps then make my own little map format :S

This class handles animations for you, the sample included shows how easy they are to work with
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-28-2008, 01:09 AM   #21


Developer
 
daaa57150's Avatar
 
Join Date: Sep 2006
Location: france
Posts: 167
Trader Feedback: 0
Default

Yep SG, it's exactly what I did, except I did it with a std::list (std::vector are bad when adding stuff they reallocate everything) but as yaustar said, I also should have done it with a std::map, much faster lookup.
I also keep a number associated with every image, to count how many references I have on that particular image, and when there is no reference anymore it's time to deallocate it, depending on the mode the user set up the Anim class (auto or manual deallocation). That's just some ideas for you.
__________________
Try my latest game:
MEGA DROPS 2

daaa57150 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-28-2008, 03:19 AM   #22

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Quote:
Originally Posted by PSPHacks
Also, SG57, I saw your post on not knowing how to use maps. I wrote a detail tutorial on how to use and create maps using OSlib. I also wrote several other tutorials for using OSlib for animations and collision detection if you care to read them.
std::maps not oslibs's maps.
-= Double Post =-
Quote:
Originally Posted by daaa57150
(std::vector are bad when adding stuff they reallocate everything)
Not always. It depends on how much you reserve via the reserve function. As long as it is big enough, it won't deallocate, reallocate and copy. std::lists are slower to transverse then std::vectors.

Last edited by yaustar; 03-28-2008 at 03:22 AM.. Reason: Automerged Doublepost
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-28-2008, 03:49 AM   #23


Developer
 
daaa57150's Avatar
 
Join Date: Sep 2006
Location: france
Posts: 167
Trader Feedback: 0
Default

Quote:
Originally Posted by yaustar
Not always. It depends on how much you reserve via the reserve function. As long as it is big enough, it won't deallocate, reallocate and copy. std::lists are slower to transverse then std::vectors.
Yeah I know that, also even if you don't reserve yourself, vectors can reserve a bit more by themselves so the reallocation doesn't happen at every pushback.
as for transversing (is that a word?) I don't know the speeds so I'll just believe you. all I know is lists are good when adding/removing a lot on the front and back and when you only need to access elements from there or in a successive way and vectors have fast access to inside elements ([] operator) as their elements are contiguous in memory.
__________________
Try my latest game:
MEGA DROPS 2

daaa57150 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-28-2008, 05:14 AM   #24

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Quote:
Originally Posted by daaa57150
Yeah I know that, also even if you don't reserve yourself, vectors can reserve a bit more by themselves so the reallocation doesn't happen at every pushback.
as for transversing (is that a word?) I don't know the speeds so I'll just believe you. all I know is lists are good when adding/removing a lot on the front and back and when you only need to access elements from there or in a successive way and vectors have fast access to inside elements ([] operator) as their elements are contiguous in memory.
Vectors double their reserved allocated memory every time they run out.

Lists are faster then vectors for inserting elements except for the back. push_back on a vector is at least as fast as a list if not faster.

Vectors have random element access where lists can only immediately access the front and end elements.

Vectors are faster then lists for transversing through the elements and just as fast as arrays.

Lists are faster then vectors for removing elements expect for the back. pop_back on a vector is at least as fast as a list if not faster. A common idiom for vectors is to swap the element you want to remove with the last element in the vector and call pop_back.

Last edited by yaustar; 03-28-2008 at 05:26 AM..
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-28-2008, 02:04 PM   #25
 
Join Date: Mar 2007
Posts: 26
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
How long ago are we talking here PSPHacks? I haven't asked a question there in a very long time.

And ya I know all about your lessons and examples. I haven't really used them, other then as a reference for basic usage of a few functions. But i will use the map example cause something I'm making will be better with maps then make my own little map format :S

This class handles animations for you, the sample included shows how easy they are to work with
Yes i saw your animation class and it looks great
This should help a lot of OSlib users over at my PSP Programming section at www.psp-hacks.com

I also made some new lessons on OSlib besides just using and converting maps for OSlib for the PSP. You can check them all out over in my PSP Programming section over there.

I also plan to implement .gif images usage and pmp streaming video usage for OSlib very soon so look for another OSlib update in the near future.

I hope to see you more often in our forums over at www.psp-hacks.com
PSPHacks is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-28-2008, 02:48 PM   #26

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Now that I have some time to look at this again:

PSPHacks, can you fix the oslib so that oslLoadImageFile takes a const char* rather then char*? This is so that it is const correct and works with the C++ string library .c_str().

SG57:
Do you really need to store the filename? I honestly can't think of any use for it after the image has loaded. If it is only for internal debug then you don't need any getter or setter functions.

Why do you have two Load functions named the same when they perform different actions? Call one LoadFromTileSheet and the other LoadFromMultipleFiles.

Do you really need all the getter functions outside of this object? I can't see why outside this object would need access to the frame data, start frame, end frame, delay, center x/y, etc needs to be accessed. You could remove most of them it not all.

Considering you have setters for nearly everything, do you really need a initialise function?

You have a play function but no stop, reset or pause?
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-03-2008, 01:09 AM   #27

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

yaustar - Being an animation class, it's sole purpose is to animate. When making a game, I thought of all that could be wanted access to. Rather then create multiple animation classes using the same spreadsheet, you can set the start and end frames of just 1 animation class instead. I forgot to add a Stop() function (bPlay = false) lol. For reseting, use setCurrentFrame(getStartF rame()). but ill add a reset function to make it easier.

And ya with OSL_IMAGE's you can rotate, scale, etc. and need to set the center of rotation and do all that jazz. Removing them is a huge mistake yaustar :X (i demonstrated how they could be used in a game in the sample - rather then have a sprite sheet with left and right animations, just have left and scale it 2x it's width and you have 'right' animations -- this is just an example, heck in my kitten cannon game i had to rotate the explosion relative to the barrel of the cannon). The setFilename i was thinking of having a Reload(), no parameters, that would basically reload everything given what's already set, but that's unneeded considering you can Unload then Load again and just use get* functions.

As for all the getXXX functions, why not? You never know when they may be needed and I for one would rather have them added for when that time comes then have to manually add it for a specific game, i'm thinking of the end user of this yaustar and if I cover all the areas possible to cover there's no need to update this or get PMs asking how to get the filename used to load the animation for whatever reason, even if it's for debug...

And sorry I didn't respond sooner, was at my Dad's for like 5 days 5 states away X(

And yeah I'll look into the std::maps, something I plan on making will have a class with this animation class in it and I'd hate to load 100 of the same spread sheet

I did a small search on std::map's and I'm curious as to whether anything else is available. Speed is a non issue, well sorta - just don't have the next option be crazy processor intensive and slow lol. I'm going to use std::map's regardless but for future reference i'd like to know what there is that could accomplish this that just isn't right for this situation.

And hey if it isn't too much trouble, your examples work great yaustar - should I hope for a 'correct usage of std::map's' out of you

PSPHacks - yeah I will, I forgot about after my long absence from the scene :X Nice features comin' If there's anything I can do to contribute that isn't beyond my abilities I'm up for it.
__________________

Last edited by SG57; 04-03-2008 at 01:25 AM..
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-03-2008, 02:23 AM   #28
 
Fzero's Avatar
 
Join Date: Apr 2007
Posts: 2,097
Trader Feedback: 0
Default

I'm learning OSlib now.
Fzero is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-03-2008, 03:39 AM   #29

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Quote:
Originally Posted by SG57
And ya with OSL_IMAGE's you can rotate, scale, etc. and need to set the center of rotation and do all that jazz. Removing them is a huge mistake yaustar :X
Don't remove the variables (that WOULD be insane), just remove the accessors.

Quote:
As for all the getXXX functions, why not? You never know when they may be needed and I for one would rather have them added for when that time comes then have to manually add it for a specific game, i'm thinking of the end user of this yaustar and if I cover all the areas possible to cover there's no need to update this or get PMs asking how to get the filename used to load the animation for whatever reason, even if it's for debug...
It is the case where this is supposed to be an OO object and the internals should not be exposed otherwise it is little more then a struct.

It isn't 'wrong' but it can increase coupling between objects.
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-03-2008, 04:21 AM   #30

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

yaustar - Well tbh I'm trying to make this resemble the rest of the OSlib structures (OSL_IMAGE --> OSL_ANIMATION) but this has a lot more then a structure can offer so keeping all those structure-accessible goodies in a more readable (imo) way while doing what it's main purpose is, is ideal. You'll notice how I gave instructions for using a C/C++ combo since not everyone uses OO but would like some of the other goodies C++ has to offer. In any case I don't think the extra stuff that someone may want to have access to hinders performance at all (noticeably) so my main, and possibly last, thing to do is manage already loaded animation frames/sprites.
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
animation , class , oslanimlib , oslib , users

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 07:01 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us