Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
4 registered members (NewbieZorro, Grant, TipmyPip, AndrewAMD), 13,346 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with timing problem for music rhythm game #326690
06/02/10 13:49
06/02/10 13:49
Joined: May 2010
Posts: 8
Singapore
C
CaedLucin Offline OP
Newbie
CaedLucin  Offline OP
Newbie
C

Joined: May 2010
Posts: 8
Singapore
Hello guys,
I am pretty new to Lite C or rather programming and is having some issue with timing.

You see, i am doing a simple music rhythm game that requires high precision timing. So basically my game will read a .txt file and extract certain information from it, such as the noteTime (the time when the note bars should be hit) and trackNum (The 4 columns where the note bars are supposed to drop vertically down on) for ALL the beats in each music play.

So basically my program will read the .txt file and place the note timing value in the noteTime array, and the track number on the trackNum array. The totalbeatcount will count the total number of beats in the game.

Then my program's logic will run through the 2 array in order to know when to create the beats and on which track.

The problem now is that because i am using total_sec, sometimes the game doesn't create the beat bars and i suspect it has to do with this if loop below..

if((int)total_secs == (noteTime[i] - (int)playtime))

Because sometimes the total_sec may have overshot the needed initial timing for the first beat, thus the first beat note and the remaining beats will not be created.

Code:
var playtime = total_secs;
int valid = 0;
var filehandle = file_open_read(filename);
read_file();
file_close(filehandle);

for(i = 0; i < totalbeatCount-1; i++)
{
     while(valid == 0)
     {
          if((int)total_secs == (noteTime[i] - (int)playtime))
          {
               if(trackNum[i] == 1)
                    //create red beat bar 1
               else if(trackNum[i] == 2)
                    //create yellow beat bar 2
               else if(trackNum[i] == 3)
                    //create green beat bar 3
               else if(trackNum[i] == 4)
                    //create blue beat bar 4
          }
          wait(-0.1);
     }
}



Could anyone help me on this? Thank you very much! laugh

Last edited by CaedLucin; 06/02/10 14:36.
Re: Help with timing problem for music rhythm game [Re: CaedLucin] #326702
06/02/10 14:25
06/02/10 14:25
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
only thing I can imagine is;

typecasting of (int) whent wrong (in which case you can try converting it using: integer(varName); ).
or, noteTime[i] is not an integer, and thus you're trying to equal a integer value vs a floating value.

Keep in mind a frame only contains 16 updates, so timing it with total_secs might be a bit off at times...

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Help with timing problem for music rhythm game [Re: Helghast] #326703
06/02/10 14:30
06/02/10 14:30
Joined: May 2010
Posts: 8
Singapore
C
CaedLucin Offline OP
Newbie
CaedLucin  Offline OP
Newbie
C

Joined: May 2010
Posts: 8
Singapore
Hmmm ok, so basically the file has the following contents

Quote:
<Note time="2.0" duration="0.0" track="3" >
</Note>
<Note time="3.0" duration="0.0" track="1" >
</Note>
<Note time="5.5" duration="0.0" track="2" >
</Note>
<Note time="6.5" duration="0.0" track="4" >
</Note>


But funny thing is, sometimes it does read the file, and is able to load up the beat bars. But anyway the values for noteTime is not of an integer value. But is it even possible to cast total_secs into integer?

Last edited by CaedLucin; 06/02/10 14:35.
Re: Help with timing problem for music rhythm game [Re: CaedLucin] #326796
06/02/10 21:57
06/02/10 21:57
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

Would it be faster if you used : case

as in
Code:
switch (choice)
{  
case 0:   
  //create red beat bar 1
   
 break; 
 case 1:   
 ......;    
break;  
case 2:
 //create yellow beat bar 2
    
 .....;
 break;  
default:    
.......;
}




Hope this helps!
Ottawa laugh

Ver 7.86.2 Pro and Lite-C
Re: Help with timing problem for music rhythm game [Re: CaedLucin] #326856
06/03/10 12:31
06/03/10 12:31
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Originally Posted By: CaedLucin
Hmmm ok, so basically the file has the following contents

Quote:
<Note time="2.0" duration="0.0" track="3" >
</Note>
<Note time="3.0" duration="0.0" track="1" >
</Note>
<Note time="5.5" duration="0.0" track="2" >
</Note>
<Note time="6.5" duration="0.0" track="4" >
</Note>


But funny thing is, sometimes it does read the file, and is able to load up the beat bars. But anyway the values for noteTime is not of an integer value. But is it even possible to cast total_secs into integer?


You're typecasting it into an integer, so if the note time is something 2.0, 3.0 etc, it will load the bar, but when it's end with something different then x.0 it will fail.

Your best bet is to work with something else then seconds.
as miliseconds ingame will never be the same (because of the 16 frames per second loop).

What i would do, is track seconds by adding a variable with +1 every frame, and dividing that by 16.
Then base the timing on seconds.framenumber(1-16).

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1