Page 1 of 1

Converting AnimSprite to PB4

Posted: Wed Feb 08, 2006 9:02 am
by Truth_Seeker
I am trying to convert the PBOSL lib: AnimSprite to PB4 because I wanted to be able to modify it. I was wanting to add the ability to use DisplaySprite3d. Anyways I ran into a problem I have no idea how to solve. I do not know if it is a syntax error or something else.

The following code is a mixture of C and PB, the C functions are first and then the PB functions that I created from the C, the code looks larger then it is so dont be afriad to look through it :wink:.:

Code: Select all

Structure AnimSprite
  SpriteNumber.l
  Transparent.l
  Xsize.l
  Ysize.l
  AnimCount.l
  DirectionCount.l
  currentAnim.l
  currentDirection.l
  XclipStart.l
  YclipStart.l
  AutoFrameTime.l
  AutoFrameDirection.l
  AutoFrameLastTime.l
EndStructure

Declare NextAnimFrame(*anim.AnimSprite)
Declare PrevAnimFrame(*anim.AnimSprite)
Declare CreateAnimSprite(*anim.AnimSprite, sprite.l, xsize.l, ysize.l)
Declare CollisionAnimSprite2(*anim.AnimSprite, x1.l, y1.l, sprite.l, x2.l, y2.l, collisionmode.l)
Declare CollisionSpriteAnim2(sprite.l, x1.l, y1.l, *anim.AnimSprite, x2.l, y2.l, collisionmode.l)
Declare CollisionAnimAnim2(*anim1.AnimSprite, x1.l, y1.l, *anim2.AnimSprite, x2.l, y2.l, collisionmode.l)
Declare CalcClipStart(*anim.AnimSprite)
Declare CalcAnimSpriteDisplay(*anim.AnimSprite)

; PBFUNCTION(unsigned long) PB_AnimDirectionCount(AnimSprite *anim) {
;    // Return the animsprite direction count (Y-direction)
;    If(anim) Return anim->DirectionCount;
;    Return 0;
; }
Procedure AnimDirectionCount(*anim.AnimSprite)
  ; Return the animsprite direction count (Y-direction)
  If *anim
    ProcedureReturn *anim\DirectionCount
  EndIf
  ProcedureReturn 0
EndProcedure

; PBFUNCTION(unsigned long) PB_AnimFrameCount(AnimSprite *anim) {
;    // Return animsprite frame count
;    If(anim) Return anim->AnimCount;
;    Return 0;
; }
Procedure AnimFrameCount(*anim.AnimSprite)
  ;Return animsprite frame count
  If *anim
    ProcedureReturn *anim\AnimCount
  EndIf
  ProcedureReturn 0
EndProcedure

; PBFUNCTION(unsigned long) PB_AnimLoopDelay(AnimSprite *anim) {
;    // Return automatic loop delay, 0ms - 60000ms
;    If(anim) {
;       If ( anim->AutoFrameTime > 60000 ) Return 60000;
;       Else                               Return anim->AutoFrameTime;
;    }
;    Return 0;
; }
Procedure AnimLoopDelay(*anim.AnimSprite)
  ; Return automatic loop delay, 0ms - 60000ms
  If *anim
    If *anim\AutoFrameTime > 60000
      ProcedureReturn 60000
    Else
      ProcedureReturn *anim\AutoFrameTime
    EndIf
  EndIf
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_AnimLoopDirection(AnimSprite *anim) {
;    // Return automatic loop direction
;    If(anim) {
;       If (anim->AutoFrameDirection) Return 1;
;    }
;    Return 0;
; }
Procedure AnimLoopDirection(*anim.AnimSprite)
  ; Return automatic loop direction
  If *anim
    If *anim\AutoFrameDirection
      ProcedureReturn 1
    EndIf
  EndIf
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_CollisionAnimAnim2(AnimSprite *anim1,
;                                                 long x1,
;                                                 long y1,
;                                                 AnimSprite *anim2,
;                                                 long x2,
;                                                 long y2,
;                                                 unsigned long collisionmode ) {
;    // check collision animsprite vs. animsprite
;    //
;    // collisonmode:
;    //    0 = exact pixel collision (Default)
;    //    1 = block collision
;    If (anim1 && anim2) {
;       PB_ClipSprite( anim1->SpriteNumber,
;                      anim1->XclipStart,
;                      anim1->YclipStart,
;                      anim1->Xsize,
;                      anim1->Ysize );
; 
;       PB_ClipSprite( anim2->SpriteNumber,
;                      anim2->XclipStart,
;                      anim2->YclipStart,
;                      anim2->Xsize,
;                      anim2->Ysize );
; 
;       If(!collisionmode)
;          Return PB_SpritePixelCollision(anim1->SpriteNumber, x1, y1,
;                                         anim2->SpriteNumber, x2, y2 );
;       Else
;          Return PB_SpriteCollision(anim1->SpriteNumber, x1, y1,
;                                    anim2->SpriteNumber, x2, y2 );
;    }
;    Return 0;
; }
Procedure CollisionAnimAnim2(*anim1.AnimSprite, x1.l, y1.l, *anim2.AnimSprite, x2.l, y2.l, collisionmode.l)
  ; check collision animsprite vs. animsprite
  ;
  ; collisionmode:
  ;   0 = exact pixel collision (Default)
  ;   1 = block collision
  If *anim1 And *anim2
    ClipSprite(*anim1\SpriteNumber, *anim1\XclipStart, *anim1\YclipStart, *anim1\Xsize, *anim1\Ysize)
    ClipSprite(*anim2\SpriteNumber, *anim2\XclipStart, *anim2\YclipStart, *anim2\Xsize, *anim2\Ysize)
    
    If collisionmode <> 1
      ProcedureReturn SpritePixelCollision(*anim1\SpriteNumber, x1, y1, *anim2\SpriteNumber, x2, y2)
    Else
      ProcedureReturn SpriteCollision(*anim1\SpriteNumber, x1, y1, *anim2\SpriteNumber, x2, y2)
    EndIf
    
  EndIf
  
  ProcedureReturn 0
EndProcedure
    
; 
; PBFUNCTION(unsigned long) PB_CollisionAnimAnim(AnimSprite *anim1,
;                                                long x1,
;                                                long y1,
;                                                AnimSprite *anim2,
;                                                long x2,
;                                                long y2 ) {
;    // check collision animsprite vs. animsprite
;    Return PB_CollisionAnimAnim2(anim1,x1,y1,anim2,x2,y2,0);
; }
Procedure CollisionAnimAnim(*anim1.AnimSprite, x1.l, y1.l, *anim2.AnimSprite, x2.l, y2.l)
  ; check collision animsprite vs. animsprite
  ProcedureReturn CollisionAnimAnim2(*anim1, x1, y1, *anim2, x2, y2, 0)
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_CollisionAnimSprite2(AnimSprite *anim,
;                                                   long x1,
;                                                   long y1,
;                                                   long sprite,
;                                                   long x2,
;                                                   long y2,
;                                                   unsigned long collisionmode ) {
;    // check collision animsprite vs. sprite
;    //
;    // collisonmode:
;    //    0 = exact pixel collision (Default)
;    //    1 = block collision
;    If(anim) {
;       PB_ClipSprite( anim->SpriteNumber,
;                      anim->XclipStart,
;                      anim->YclipStart,
;                      anim->Xsize,
;                      anim->Ysize );
; 
;       If(!collisionmode)
;          Return PB_SpritePixelCollision(anim->SpriteNumber,x1,y1,sprite,x2,y2);
;       Else
;          Return PB_SpriteCollision(anim->SpriteNumber,x1,y1,sprite,x2,y2);
;    }
;    Return 0;
; }
Procedure CollisionAnimSprite2(*anim.AnimSprite, x1.l, y1.l, sprite.l, x2.l, y2.l, collisionmode.l)
  ; check collision animsprite vs. sprite
  ;
  ; collisionmode:
  ;   0 = exact pixel collision (Default)
  ;   1 = block collision
  If *anim
    ClipSprite(*anim\SpriteNumber, *anim\XclipStart, *anim\YclipStart, *anim\Xsize, *anim\Ysize)
    
    If collisionmode <> 1
      ProcedureReturn SpritePixelCollision(*anim\SpriteNumber, x1, y1, sprite, x2, y2)
    Else
      ProcedureReturn SpriteCollision(*anim\SpriteNumber, x1, y1, sprite, x2, y2)
    EndIf
  
  EndIf
  
  ProcedureReturn 0
EndProcedure
  
; 
; PBFUNCTION(unsigned long) PB_CollisionAnimSprite(AnimSprite *anim,
;                                                  long x1,
;                                                  long y1,
;                                                  long sprite,
;                                                  long x2,
;                                                  long y2 ) {
;    // check collision animsprite vs. sprite
;    Return PB_CollisionAnimSprite2(anim,x1,y1,sprite,x2,y2,0);
; }
Procedure CollisionAnimSprite(*anim.AnimSprite, x1.l, y1.l, sprite.l, x2.l, y2.l)
  ; check collision animsprite vs. sprite
  ProcedureReturn CollisionAnimSprite2(*anim, x1, y1, sprite, x2, y2, 0)
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_CollisionSpriteAnim2(long sprite,
;                                                   long x1,
;                                                   long y1,
;                                                   AnimSprite *anim,
;                                                   long x2,
;                                                   long y2,
;                                                   unsigned long collisionmode ) {
;    // check collision sprite vs. animsprite
;    //
;    // collisonmode:
;    //    0 = exact pixel collision (Default)
;    //    1 = block collision
;    If(anim) {
;       PB_ClipSprite( anim->SpriteNumber,
;                      anim->XclipStart,
;                      anim->YclipStart,
;                      anim->Xsize,
;                      anim->Ysize );
; 
;       If(!collisionmode)
;          Return PB_SpritePixelCollision(sprite,x1,y1,anim->SpriteNumber,x2,y2);
;       Else
;          Return PB_SpriteCollision(sprite,x1,y1,anim->SpriteNumber,x2,y2);
;    }
;    Return 0;
; }
Procedure CollisionSpriteAnim2(sprite.l, x1.l, y1.l, *anim.AnimSprite, x2.l, y2.l, collisionmode.l)
  ; check collision sprite vs. animsprite
  ;
  ; collisionmode:
  ;   0 = exact pixel collision (Default)
  ;   1 = block collision
  If *anim
    ClipSprite(*anim\SpriteNumber, *anim\XclipStart, *anim\YclipStart, *anim\Xsize, *anim\Ysize)
    
    If collisionmode <> 1
      ProcedureReturn SpritePixelCollision(sprite, x1, y1, *anim\SpriteNumber, x2, y2)
    Else
      ProcedureReturn SpriteCollision(sprite, x1, y1, *anim\SpriteNumber, x2, y2)
    EndIf
    
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_CollisionSpriteAnim(long sprite,
;                                                  long x1,
;                                                  long y1,
;                                                  AnimSprite *anim,
;                                                  long x2,
;                                                  long y2 ) {
;    // check collision sprite vs. animsprite
;    Return PB_CollisionSpriteAnim2(sprite,x1,y1,anim,x2,y2,0);
; }
Procedure CollisionSpriteAnim(sprite.l, x1.l, y1.l, *anim.AnimSprite, x2.l, y2.l)
  ; check collision sprite vs. animsprite
  ProcedureReturn CollisionSpriteAnim2(sprite, x1, y1, *anim, x2, y2, 0)
EndProcedure
; 
; PBFUNCTION(AnimSprite*) PB_CreateAnimSprite2(AnimSprite *anim,
;                                              long sprite,
;                                              unsigned long xsize,
;                                              unsigned long ysize,
;                                              unsigned long FrameTime) {
;    // create new anim sprite
;    // And set automatic update time
;    If(anim) {
;       If( PB_CreateAnimSprite(anim,sprite,xsize,ysize) ) {
;          If(FrameTime > 60000) FrameTime = 0;
;          anim->AutoFrameTime = FrameTime;
;          Return anim;
;       }
;    }
;    Return 0;
; }
Procedure CreateAnimSprite2(*anim.AnimSprite, sprite.l, xsize.l, ysize.l, FrameTime.l)
  ; create new anim sprite
  ; And set automatic update time
  If *anim
    
    If CreateAnimSprite(*anim, sprite, xsize, ysize)

      If FrameTime > 60000
        FrameTime = 0
      EndIf
      
      *anim\AutoFrameTime = FrameTime
      
      ProcedureReturn *anim
    EndIf
    
  EndIf
  
  ProcedureReturn 0
EndProcedure 
; 
; PBFUNCTION(AnimSprite*) PB_CreateAnimSprite(AnimSprite *anim,
;                                             long sprite,
;                                             unsigned long xsize,
;                                             unsigned long ysize ) {
;    If(!anim) Return 0; // check 0-pointer
; 
;    anim->SpriteNumber       = sprite;                           // Sprite-Number
;    anim->Xsize              = xsize;                            // X-Size of 1 Frame
;    anim->Ysize              = ysize;                            // Y-Size of 1 Frame
;    anim->currentAnim        = 1;                                // current Anim
;    anim->currentDirection   = 1;                                // current Direction
;    anim->AutoFrameTime      = 0;                                // time between frames
;    anim->AutoFrameDirection = 0;                                // Direction - default: right -->
;    anim->AutoFrameLastTime  = 0;                                // last time in ms
;    
;    anim->AnimCount          = PB_SpriteWidth(sprite)  / xsize;  // Anim-Count
;    anim->DirectionCount     = PB_SpriteHeight(sprite) / ysize;  // Direction-Count
; 
;    Return anim;
; }
Procedure CreateAnimSprite(*anim.AnimSprite, sprite.l, xsize.l, ysize.l)
  If *anim <> 1
    ProcedureReturn 0 ; check 0-pointer
  EndIf
  
  *anim\SpriteNumber        = sprite                            ; Sprite-Number
  *anim\Xsize               = xsize                             ; X-Size of 1 Frame
  *anim\Ysize               = ysize                             ; Y-Size of 1 Frame
  *anim\currentAnim         = 1                                 ; current Anim
  *anim\currentDirection    = 1                                 ; current Direction
  *anim\AutoFrameTime       = 0                                 ; time between frames
  *anim\AutoFrameDirection  = 0                                 ; Direction - default: right -->
  *anim\AutoFrameLastTime   = 0                                 ; last time in ms
  
  *anim\AnimCount           = SpriteWidth(sprite) / xsize       ; Anim-Count
  *anim\DirectionCount      = SpriteHeight(sprite) / ysize      ; Direction-Count
  
  ProcedureReturn *anim
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_CurrentAnimDirection(AnimSprite *anim) {
;    // Return current animation direction
;    If(anim) Return anim->currentDirection;
;    Return 0;
; }
Procedure CurrentAnimDirection(*anim.AnimSprite)
  ; Return current animation direction
  If *anim
    ProcedureReturn *anim\currentDirection
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_CurrentAnimFrame(AnimSprite *anim) {
;    // returns the current animation frame
;    If(anim) Return anim->currentAnim;
;    Return 0;
; }
Procedure CurrentAnimFrame(*anim.AnimSprite)
  ; returns the current animation frame
  If *anim
    ProcedureReturn *anim\currentAnim
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_DisplayAnimSprite(AnimSprite *anim,
;                                                long x,
;                                                long y ) {
;    // display current anim frame using PB_DisplayTransparentSprite
;    If(anim) {
;       AnimSprite_CalcAnimSpriteDisplay(anim);
;       PB_DisplayTransparentSprite( anim->SpriteNumber, x, y );
;       Return 1;
;    }
;    Return 0;
; }
Procedure DisplayAnimSprite(*anim.AnimSprite, x.l, y.l)
  ; display current anim frame using DisplayTransparentSprite
  If *anim
    CalcAnimSpriteDisplay(*anim)
    DisplayTransparentSprite(*anim\SpriteNumber, x, y)
    ProcedureReturn 1
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_NextAnimDirection(AnimSprite *anim) {
;    // set Next anim direction
;    // last direction goes To 1 (loop)
;    If(anim) {
;       If (anim->currentDirection == anim->DirectionCount)
;          anim->currentDirection = 1;
;       Else
;          anim->currentDirection++;
; 
;       AnimSprite_CalcClipStart(anim);
;       Return 1;
;    }
;    Return 0;
; }
Procedure NextAnimDirection(*anim.AnimSprite)
  ; set Next anim direction
  ; last direction goes To 1 (loop)
  If *anim
  
    If *anim\currentDirection = *anim\DirectionCount
      *anim\currentDirection = 1
    Else
      *anim\currentDirection + 1
    EndIf
      
      CalcClipStart(*anim)
      ProcedureReturn 1
  EndIf
    
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_NextAnimFrame(AnimSprite *anim) {
;    // set Next anim frame
;    // last frame goes To frame 1 (loop)
;    If(anim) {
;       If (anim->currentAnim == anim->AnimCount) anim->currentAnim = 1;
;       Else                                      anim->currentAnim++;
; 
;       AnimSprite_CalcClipStart(anim);
;       Return 1;
;    }
;    Return 0;
; }
Procedure NextAnimFrame(*anim.AnimSprite)
  ; set Next anim frame
  ; last frame goes To frame 1 (loop)
  If *anim
  
    If *anim\currentAnim = *anim\AnimCount
      *anim\currentAnim = 1
    Else
      *anim\currentAnim + 1
    EndIf
    
    CalcClipStart(*anim)
    ProcedureReturn 1
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_PrevAnimDirection(AnimSprite *anim) {
;    If(anim) {
;       If ( anim->currentDirection == 1 ) anim->currentDirection = anim->DirectionCount;
;       Else                               anim->currentDirection--;
; 
;       AnimSprite_CalcClipStart(anim);
;       Return 1;
;    }
;    Return 0;
; }
Procedure PrevAnimDirection(*anim.AnimSprite)
  If *anim
  
    If *anim\currentDirection = 1
      *anim\currentDirection = *anim\DirectionCount
    Else
      *anim\currentDirection - 1
    EndIf
    
    CalcClipStart(*anim)
    ProcedureReturn 1
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_PrevAnimFrame(AnimSprite *anim) {
;    // set previous anim frame
;    // frame 1 goes To last frame (loop)
;    If(anim) {
;       If ( anim->currentAnim == 1 ) anim->currentAnim = anim->AnimCount;
;       Else                          anim->currentAnim--;
; 
;       AnimSprite_CalcClipStart(anim);
;       Return 1;
;    }
;    Return 0;
; }
Procedure PrevAnimFrame(*anim.AnimSprite)
  ; set previous anim frame
  ; frame 1 goes To last frame (loop)
  If *anim
  
    If *anim\currentAnim = 1
      *anim\currentAnim = *anim\AnimCount
    Else
      *anim\currentAnim - 1
    EndIf
    
    CalcClipStart(*anim)
    ProcedureReturn 1
    
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_SetAnimDirection(AnimSprite *anim,
;                                               long direction ) {
;    // set new anim direction (Y-direction)
;    If(anim) {
;       If (direction < 1)
;          anim->currentDirection = 1;
;       Else If ((unsigned long)direction > anim->DirectionCount)
;          anim->currentDirection = anim->DirectionCount;
;       Else
;          anim->currentDirection = (unsigned long)direction;
; 
;       AnimSprite_CalcClipStart(anim);
;       Return 1;
;    }
;    Return 0;
; }
Procedure SetAnimDirection(*anim.AnimSprite, direction.l)
  ; set new anim direction (Y-direction)
  If *anim
  
    If direction < 1
      *anim\currentDirection = 1
    ElseIf direction > *anim\DirectionCount
      *anim\currentDirection = *anim\DirectionCount
    Else
      *anim\currentDirection = direction
    EndIf
    
    CalcClipStart(*anim)
    ProcedureReturn 1
    
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_SetAnimFrame(AnimSprite *anim, long frame) {
;    // set new anim frame (X-direction)
;    If(anim) {
;       If (frame < 1)
;          anim->currentAnim = 1;
;       Else If ((unsigned long)frame > anim->AnimCount)
;          anim->currentAnim = anim->AnimCount;
;       Else
;          anim->currentAnim = (unsigned long)frame;
; 
;       AnimSprite_CalcClipStart(anim);
;       Return 1;
;    }
;    Return 0;
; }
Procedure SetAnimFrame(*anim.AnimSprite, frame.l)
  ; set new anim frame (X-direction)
  If *anim
  
    If frame < 1
      *anim\currentAnim = 1
    ElseIf frame > *anim\AnimCount
      *anim\currentAnim = *anim\AnimCount
    Else
      *anim\currentAnim = frame
    EndIf
    
    CalcClipStart(*anim)
    ProcedureReturn 1
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_SetAnimLoopDelay(AnimSprite *anim, long delay) {
;    // set new animation delay between 0ms - 60000ms
;    If(anim) {
;       If      (delay > 60000) anim->AutoFrameTime = 60000;
;       Else If (delay < 0)     anim->AutoFrameTime = 0;
;       Else                    anim->AutoFrameTime = (unsigned long)delay;
;       Return 1;
;    }
;    Return 0;
; }
Procedure SetAnimLoopDelay(*anim.AnimSprite, delay.l)
  ; set new animation delay between 0ms - 60000ms
  If *anim
  
    If delay > 60000
      *anim\AutoFrameTime = 60000
    ElseIf delay < 0
      *anim\AutoFrameTime = 0
    Else
      *anim\AutoFrameTime = delay
    EndIf
    
    ProcedureReturn 1
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(unsigned long) PB_SetAnimLoopDirection(AnimSprite *anim,
;                                                   unsigned long direction) {
;    // set new loop direction (X-direction)
;    // 0 = loop ->
;    // 1 = loop <-
;    If(anim) {
;       If (direction) anim->AutoFrameDirection = 1;
;       Else           anim->AutoFrameDirection = 0;
;       Return 1;
;    }
;    Return 0;
; }
Procedure SetAnimLoopDirection(*anim.AnimSprite, direction.l)
  ; set new loop direction (X-direction)
  ; 0 loop ->
  ; 1 = loop <-
  If *anim
  
    If direction
      *anim\AutoFrameDirection = 1
    Else
      *anim\AutoFrameDirection = 0
    EndIf
    
    ProcedureReturn 1
  EndIf
  
  ProcedureReturn 0
EndProcedure
; 
; PBFUNCTION(void) AnimSprite_CalcAnimSpriteDisplay(AnimSprite *anim) {
;    // If automatic animation is used,
;    // it calculates the current frame
; 
;    // If automatic animation, update frames
;    If (anim->AutoFrameTime) {
;       If ( anim->AutoFrameLastTime == 0 ) {
;          // set start time For the first time
;          anim->AutoFrameLastTime = PB_ElapsedMilliseconds();
;       }
;       Else {
;          int temp, temp2;
;          temp  = PB_ElapsedMilliseconds();
;          temp2 = anim->AutoFrameLastTime + anim->AutoFrameTime;
; 
;          // time To update
;          If (temp2 == temp) {
;             anim->AutoFrameLastTime = temp;
; 
;             If ( anim->AutoFrameDirection ) PB_PrevAnimFrame(anim);
;             Else                            PB_NextAnimFrame(anim);
;          }
;          // catch up frames
;          Else If (temp2 < temp) {
;             unsigned long difference;
;             difference = (temp - temp2) / anim->AutoFrameTime;
;             difference++;
; 
;             While (difference) { // loop To update frames
;                If ( anim->AutoFrameDirection ) PB_PrevAnimFrame(anim);
;                Else                            PB_NextAnimFrame(anim);
;                difference--;
;             }
; 
;             // exactly update last frame time
;             difference = anim->AutoFrameTime % (temp - temp2);
;             anim->AutoFrameLastTime = temp + difference;
;          }
;       }
;    }
; 
;    // set sprite clipping
;    PB_ClipSprite( anim->SpriteNumber,
;                   anim->XclipStart,
;                   anim->YclipStart,
;                   anim->Xsize,
;                   anim->Ysize );
; }
Procedure CalcAnimSpriteDisplay(*anim.AnimSprite)
  ; If automatic animation is used,
  ; it calculates the current anim
  
  ; If automatic animation, update frames
  If *anim\AutoFrameTime
    
    If *anim\AutoFrameLastTime = 0
      ; set start time For the first time
      *anim\AutoFrameLastTime = ElapsedMilliseconds()
    EndIf
    
  Else
    temp.l = ElapsedMilliseconds()
    temp2.l = *anim\AutoFrameLastTime + *anim\AutoFrameTime
    
    ; time To update
    If temp2 = temp
      *anim\AutoFrameLastTime = temp
      
      If *anim\AutoFrameDirection
        PrevAnimFrame(*anim)
      Else
        NextAnimFrame(*anim)
      EndIf
    
    EndIf
    
  ; catch up frames
  ;ElseIf temp2 < temp ;<--- the C code had this but this is illegal in PB, I am might have misread the C code
    If temp2 < temp ;<--- I have a feeling this is the problem but I dont know
      difference.l = (temp - temp2) / *anim\AutoFrameTime ;<--- I get the "Division by Zero is forbidden" error at this line so this is where the program halts
      difference + 1
    
      While difference ; loop To update frames
        If *anim\AutoFrameDirection
          PrevAnimFrame(*anim)
        Else
          NextAnimFrame(*anim)
          difference - 1
        EndIf
      Wend
    
      ; exactly update the last frame time
      difference = *anim\AutoFrameTime % (temp - temp2)
      *anim\AutoFrameLastTime = temp + difference
    EndIf
    
  EndIf
  
  ClipSprite(*anim\SpriteNumber, *anim\XclipStart, *anim\YclipStart, *anim\xsize, *anim\ysize)
  
EndProcedure
        
    
  
; 
; PBFUNCTION(void) AnimSprite_CalcClipStart(AnimSprite *anim) {
;    // calculate the new clipping offsets X & Y
;    anim->XclipStart = ( anim->currentAnim      - 1 ) * anim->Xsize;
;    anim->YclipStart = ( anim->currentDirection - 1 ) * anim->Ysize;
; }
Procedure CalcClipStart(*anim.AnimSprite)
  ; calculate the new clipping offsets X & Y
  *anim\XclipStart = (*anim\currentAnim - 1) * *anim\Xsize
  *anim\YclipStart = (*anim\currentDirection - 1) * *anim\Ysize
EndProcedure
I would rather not have had to do this but I want to add more functions to this lib. I hope I was not breaking the LGPL license by doing this. I really need the extra features in my game engine which will be released to the PB community in open source. I am hoping by writing this engine people can have a easier time creating game with PB. Help is greatly appreciated!

By the way, I know that the AnimSprite has already been converted to PB4 but I still would like to be able to add support for DisplaySprite3d (with the alphablending) and maybe other things.

Posted: Wed Feb 08, 2006 8:07 pm
by Truth_Seeker
I might have not explained the problem enough so here I go again.

Here is the problem I think is causing it, I am having a hard time with the coding of the if statements in the C code. If some one could help me with determining when the IF statements close and what IF the ELSEIF is supposed to be under.

Code: Select all

; PBFUNCTION(void) AnimSprite_CalcAnimSpriteDisplay(AnimSprite *anim) {
;    // If automatic animation is used,
;    // it calculates the current frame
;
;    // If automatic animation, update frames
;    If (anim->AutoFrameTime) {
;       If ( anim->AutoFrameLastTime == 0 ) {
;          // set start time For the first time
;          anim->AutoFrameLastTime = PB_ElapsedMilliseconds();
;       }
;       Else {
;          int temp, temp2;
;          temp  = PB_ElapsedMilliseconds();
;          temp2 = anim->AutoFrameLastTime + anim->AutoFrameTime;
;
;          // time To update
;          If (temp2 == temp) {
;             anim->AutoFrameLastTime = temp;
;
;             If ( anim->AutoFrameDirection ) PB_PrevAnimFrame(anim);
;             Else                            PB_NextAnimFrame(anim);
;          }
;          // catch up frames
;          Else If (temp2 < temp) {
;             unsigned long difference;
;             difference = (temp - temp2) / anim->AutoFrameTime;
;             difference++;
;
;             While (difference) { // loop To update frames
;                If ( anim->AutoFrameDirection ) PB_PrevAnimFrame(anim);
;                Else                            PB_NextAnimFrame(anim);
;                difference--;
;             }
;
;             // exactly update last frame time
;             difference = anim->AutoFrameTime % (temp - temp2);
;             anim->AutoFrameLastTime = temp + difference;
;          }
;       }
;    }
;
;    // set sprite clipping
;    PB_ClipSprite( anim->SpriteNumber,
;                   anim->XclipStart,
;                   anim->YclipStart,
;                   anim->Xsize,
;                   anim->Ysize );
; }
Procedure CalcAnimSpriteDisplay(*anim.AnimSprite)
  ; If automatic animation is used,
  ; it calculates the current anim
 
  ; If automatic animation, update frames
  If *anim\AutoFrameTime
   
    If *anim\AutoFrameLastTime = 0
      ; set start time For the first time
      *anim\AutoFrameLastTime = ElapsedMilliseconds()
    EndIf
   
  Else
    temp.l = ElapsedMilliseconds()
    temp2.l = *anim\AutoFrameLastTime + *anim\AutoFrameTime
   
    ; time To update
    If temp2 = temp
      *anim\AutoFrameLastTime = temp
     
      If *anim\AutoFrameDirection
        PrevAnimFrame(*anim)
      Else
        NextAnimFrame(*anim)
      EndIf
   
    EndIf
   
  ; catch up frames
  ;ElseIf temp2 < temp ;<--- the C code had this but this is illegal in PB, I am might have misread the C code
    If temp2 < temp ;<--- I have a feeling this is the problem but I dont know
      difference.l = (temp - temp2) / *anim\AutoFrameTime ;<--- I get the "Division by Zero is forbidden" error at this line so this is where the program halts
      difference + 1
   
      While difference ; loop To update frames
        If *anim\AutoFrameDirection
          PrevAnimFrame(*anim)
        Else
          NextAnimFrame(*anim)
          difference - 1
        EndIf
      Wend
   
      ; exactly update the last frame time
      difference = *anim\AutoFrameTime % (temp - temp2)
      *anim\AutoFrameLastTime = temp + difference
    EndIf
   
  EndIf
 
  ClipSprite(*anim\SpriteNumber, *anim\XclipStart, *anim\YclipStart, *anim\xsize, *anim\ysize)
 
EndProcedure 
Other problem which you can see in my previous post is the C code requires that some of the procedures return a pointer that has a structure as a type. I do not know if thats possible to do in PB and if it is, I might have done it wrong.

Anyone have any ideas?

Re: Converting AnimSprite to PB4

Posted: Thu Feb 09, 2006 12:05 am
by ts-soft
Truth_Seeker wrote: I would rather not have had to do this but I want to add more functions to this lib. I hope I was not breaking the LGPL license by doing this.
Changing the Lib doesn't break the LGPL! You must only make the changes available! Done :wink:

I will see change the PBOSL Lib to PureBasic, when no way to implement some features in c version.

In this time, we wait for TailBite 4 :wink:

Posted: Thu Feb 09, 2006 7:04 am
by Truth_Seeker
I still would like to know why my conversion to PB is not working, anyone have some ideas on what I can do?