forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sceRtcGetCurrentTick u64 and u32 chaos :(

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Feb 06, 2006 2:52 am    Post subject: sceRtcGetCurrentTick u64 and u32 chaos :( Reply with quote

Hi folks,

I try to get the current tickcount to display the time you have played the current game. the problem is that it works with u64 and u32 variables. How can i convert them into an int which i can use for the sprintf (or a function i will create to display the seconds as a time.) What can i do?

Code:
int iResult;
int iResultTime;
iResult = sceRtcGetCurrentTick(&iTimeNow);
      iResultTime = (iTimeNow - iTimeStart) / sceRtcGetTickResolution();
      sprintf(sCurrentTime, "%i", iResultTime);

_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Feb 06, 2006 3:02 am    Post subject: Reply with quote

The strangest thing happens

Code:
int GameMain(void) {
   int iResult;
   int iResultTime;

   //Load everything
   GameLoad();
   iResult = sceRtcGetCurrentTick(&iTimeStart);
   while(1) {
      

      iResult = sceRtcGetCurrentTick(&iTimeNow);
      iResultTime = (iTimeNow - iTimeStart) / sceRtcGetTickResolution();
      sprintf(sCurrentTime, "%i", iResultTime);
      // read controls
      GameControls();
      // if pause then don't do anything.
      if (iPause == 0){
         // Handle the quad
         GameHandleQuad();
         // Handle Game events
         GameEvents();
         // Handle the Line
         GameHandleLine();
      }
      // draw game
      GameRender();
return 0;
}
      //


If i don't put in the gettickcount codes to get the the time everything works fine but when i do as the code above there goes alot wrong with the game. Like that instead of 4 critters there are 5 critters. and with this the game crashes at a certain time. why is this code wrong?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Danny769



Joined: 01 Feb 2006
Posts: 55

PostPosted: Mon Feb 06, 2006 4:30 am    Post subject: Reply with quote

That is odd, i dont see any error, unless im missing some thing small.
could it have some thing to do with any other part of your code?
Back to top
View user's profile Send private message
Saotome



Joined: 03 Apr 2004
Posts: 182

PostPosted: Mon Feb 06, 2006 4:48 am    Post subject: Reply with quote

That code snippet doesn't help at all.
Is the type of iTimeStart and iTimeNow even u64 (like it should)?

From the SDK (svn):
Code:

int sceRtcGetCurrentTick(u64 *tick);

_________________
infj
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Feb 06, 2006 5:53 am    Post subject: Reply with quote

Hi,

well the two vars are declared as u64 and i don't get any compile error's with this but when i use the gettickcount(the two before the sprintf
Code:
//iResult = sceRtcGetCurrentTick(&iTimeNow);
      //iResultTime = (iTimeNow - iTimeStart) / sceRtcGetTickResolution();
then when the following code runs it creates another critter:
Code:
int GameEvents(void){
   if (iQuadPosY == 11){
      if (BlockStatus[1] == 0) {
         iField[iQuadPosX][iQuadPosY] = iCurrentQuad[1];
         BlockStatus[1] = 1;
      }
      if (BlockStatus[2] == 0) {
         iField[iQuadPosX + 1][iQuadPosY] = iCurrentQuad[2];
         BlockStatus[2] = 1;
      }
      if (BlockStatus[3] == 0) {
         iField[iQuadPosX + 1][iQuadPosY + 1] = iCurrentQuad[3];
         BlockStatus[3] = 1;
      }
      if (BlockStatus[4] == 0) {
         iField[iQuadPosX][iQuadPosY + 1] = iCurrentQuad[4];
         BlockStatus[4] = 1;
      }
      CheckSurroundingField(iQuadPosX, iQuadPosY + 1, iCurrentQuad[4]);
      CheckSurroundingField(iQuadPosX, iQuadPosY, iCurrentQuad[1]);
      CheckSurroundingField(iQuadPosX + 1, iQuadPosY + 1, iCurrentQuad[3]);
      CheckSurroundingField(iQuadPosX + 1, iQuadPosY, iCurrentQuad[2]);   
      iControllable = 1;
   }
   else {
   //if (iQuadPosYold + 1 == iQuadPosY){
      if (iControllable == 0) {
         if (iDropSpeed == 40){
            iQuadPosY += 1;
            iDropSpeed = 0;

         }
         else { iDropSpeed += 1;}
      }
      else {
         //if (iDropSpeed == 5){
            iQuadPosY += 1;
         //   iDropSpeed = 0;
            //iTest +=1;

         //}
         //else { iDropSpeed += 1;}
      }
   }



   return 0;
}


the above code checks if the position is 11 and when it is then the code save the temporary blocks and saves them in the field. The problem that occurs only when the tickcount code is added is that instead of 4 blocks that are saved in the field, 5 are saved in the field. When this occurs then in the following function:

Code:
int GameHandleQuad(void){
   
   int iCheck = 0;
   // check block 4 en 1
   if (BlockStatus[4] != 1){
      if (iField[iQuadPosX][iQuadPosY + 1] > 0){
         if (iQuadPosY <= 2){ GameOver(); }
         iField[iQuadPosX][iQuadPosY] = iCurrentQuad[4];
         iField[iQuadPosX][iQuadPosY - 1] = iCurrentQuad[1];
         BlockStatus[1] = 1;
         BlockStatus[4] = 1;
         iControllable = 1;
         iCheck += 1;
         CheckSurroundingField(iQuadPosX, iQuadPosY, iCurrentQuad[4]);
         CheckSurroundingField(iQuadPosX, iQuadPosY - 1, iCurrentQuad[1]);   
      }   
      else {BlockStatus[4] = 0; BlockStatus[1] = 0;}
   }
   

   // check block 3 en 2
   if (BlockStatus[3] != 1){
      if (iField[iQuadPosX + 1][iQuadPosY + 1] > 0){
         if (iQuadPosY <= 2){ GameOver(); }
         iField[iQuadPosX + 1][iQuadPosY] = iCurrentQuad[3];
         iField[iQuadPosX + 1][iQuadPosY - 1] = iCurrentQuad[2];
         BlockStatus[3] = 1;
         BlockStatus[2] = 1;
         iControllable = 1;
         iCheck += 2;
         CheckSurroundingField(iQuadPosX + 1, iQuadPosY, iCurrentQuad[3]);
         CheckSurroundingField(iQuadPosX + 1, iQuadPosY - 1, iCurrentQuad[2]);
         
      }
      else {BlockStatus[2] = 0; BlockStatus[3] = 0;}
   }

   if (iCheck != 3 && iCheck != 0){
      iQuadPosY -= 1;
   }

   if (BlockStatus[3] == 1) {
      if (BlockStatus[2] == 1) {
         if (BlockStatus[1] == 1) {
            if (BlockStatus[4] == 1) {
               BlockStatus[1] = 0;
               BlockStatus[2] = 0;
               BlockStatus[3] = 0;
               BlockStatus[4] = 0;
               GameCreateQuad();
            }
         }
      }
   }

   return 0;


}


then not every BlockStatus = 1 however it should be and without the code it is, so it should be the code with the ticks that cause the errors but i do not know why and what. Maybe it is because i calculate with u64 and u32 but save it into a integer?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
charliex



Joined: 26 Jan 2006
Posts: 16

PostPosted: Mon Feb 06, 2006 6:57 am    Post subject: Reply with quote

is sCurrentTime big enough to receive the whole string ?

you can leave it all as u64 if needed then cast as (int) at the sprintf.
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Feb 06, 2006 7:56 am    Post subject: Reply with quote

hi well i declared my sCurrentTime as:

Code:
char sCurrentTime[100];


i tried (int) also but the same result. The strangest thing is that i don't see any double vars or so, so i don't know why my gettickcount interferes with my other code. It's a mysterie for me? don't know C very well but can it be something with declaring to much info so my memory fills up and saves over other info? or something in that way?

greets ghoti
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Mon Feb 06, 2006 9:48 am    Post subject: Reply with quote

Well, my compiler always tells me not to use sprintf but only use snprintf for security reasons. You could try that with snprintf(sCurrentTime, 100, "%i", iResultTime);
My guess there is that the 64bit division gives an overflow. You should also try to typecast everything in place, rather than to depend on the automatic typecasting, ie. use
iResultTime = (int)(iTimeNow - iTimeStart) / (int)sceRtcGetTickResolution();
Back to top
View user's profile Send private message Visit poster's website
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Feb 06, 2006 7:35 pm    Post subject: Reply with quote

:( that doesn't work also :(

isn't there a other way of calculating how many seconds have passed since you started the game?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
charliex



Joined: 26 Jan 2006
Posts: 16

PostPosted: Tue Feb 07, 2006 4:19 am    Post subject: Reply with quote

i've just been using clock() but that may just call the same functions internally.
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Feb 07, 2006 11:46 pm    Post subject: Reply with quote

hi back again.

Well i tried a bit around and i have used another function now which uses seconds (what i need)

the syntax =
Code:
time_t sceKernelLibcTime  (  time_t *  t   )


i use
Code:
time_t iTimeNow;
sceKernelLibcTime(&iTimeNow);


this works for the getting the seconds but i get the same errors but now i know which line makes the error. It is the function call. When I // it then the code runs fine without strange things but as soon as i put it back in then my blocks come out all wrong. So maybe i use the function incorrect ( i hope)?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group