Homebrew Calculate time with libnds

Morgawr

Well-Known Member
OP
Member
Joined
Dec 18, 2008
Messages
330
Trophies
0
Age
34
Website
Visit site
XP
158
Country
Italy
I know I've been posing many questions about libnds programming, but it's getting very frustrating since the API seems incomplete or really really bad put (I can't find half of the function I've seen used in examples) and the forums around the internet are almost all deserted... it seems like libnds is an unused, dropped, project.. wtf >_.
 

Jeremysr

Member
Newcomer
Joined
Jul 26, 2006
Messages
21
Trophies
0
Age
32
Location
Kamsack, Saskatchewan, Canada
Website
viewsourcecode.org
XP
229
Country
Canada
Oh, and to answer your question:

I have always done timings using the DS's V-blanks. A V-blank is basically the time it takes for the screen to refresh. It is almost exactly 1/60 of a second on the DS, so there are 60 V-blanks in a second. Your main game loop should look something like this:

Code:
touchPosition stylus;

while (1) {
ÂÂÂÂscanKeys();
ÂÂÂÂstylus = touchReadXY();

ÂÂÂÂ// ...
ÂÂÂÂ// (handle input, update gamestate, render to screen)
ÂÂÂÂ// ...

ÂÂÂÂswiWaitForVBlank();
}

The call to 'swiWaitForVBlank()' at the end of the loop causes the game loop to run every 1/60th of a second (resulting in a framerate of 60 frames per second unless your other code in the loop takes longer than that to execute). If you want to read input from the stylus only every X milliseconds you could keep a count of the number of frames (or V-blanks) that have passed since the beginning of the loop, and only read input from the stylus when the current V-blank count is divisible by a certain number. If that number is 30, then input will be read every 30 V-blanks (30/60 = 1/2 of a second). If the number is 5, then input will be read every 5 V-blanks (5/60 = 1/12th of a second).

So here's what it might look like after you do all this:

Code:
touchPosition stylus;
unsigned long vblank_count = 0;

while (1) {
ÂÂÂÂscanKeys();

ÂÂÂÂ// If vblank_count is divisible by 5...
ÂÂÂÂif (vblank_count % 5 == 0) {
ÂÂÂÂÂÂÂÂstylus = touchReadXY();
ÂÂÂÂ}

ÂÂÂÂ// ...
ÂÂÂÂ// (handle input, update gamestate, render to screen)
ÂÂÂÂ// ...

ÂÂÂÂswiWaitForVBlank();
ÂÂÂÂvblank_count++;
}
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BakerMan
    The snack that smiles back, Ballsack!
  • Psionic Roshambo @ Psionic Roshambo:
    What my idea is that I would be processing video on the new one while I could game on my current machine
  • Psionic Roshambo @ Psionic Roshambo:
    Sort of what I use my Pi 4 for now
  • BakerMan @ BakerMan:
    luke is a simp for kath soucie ngl
  • realtimesave @ realtimesave:
    @Psionic Roshambo don't worry my spanish is so bad, I said "quanto" on facebook instead of "cuanto"
    +1
  • SylverReZ @ SylverReZ:
    I only know little Spanish, haven't done classes in a long time.
  • Psionic Roshambo @ Psionic Roshambo:
    I used to know almost enough Spanish to have a simple conversation but not anymore lol
  • NinStar @ NinStar:
    quanto is portuguese
  • BakerMan @ BakerMan:
    guys, hear me out
  • BakerMan @ BakerMan:
    a backrooms or scp mmo would be sick
  • BakerMan @ BakerMan:
    especially if you could change perspective (first person, third person, top down)
  • NinStar @ NinStar:
    backrooms kinda lost its magic for me
  • Veho @ Veho:
    Fluffernutter sounds like a sex move but apparently it's not.
    +1
  • Sonic Angel Knight @ Sonic Angel Knight:
    Blaster Master is the name of a game. by SUNSOFT! Totally not a sex move. :creep:
    +1
  • Veho @ Veho:
    Master Blaster is the name of a Mad Max character.
    +1
  • Veho @ Veho:
    Characters to be precise.

    +1
  • SylverReZ @ SylverReZ:
    @Veho, Master Blaster sounds like an adult video game.
  • Veho @ Veho:
    His ultimate move is the Jizznado.
    +2
  • SylverReZ @ SylverReZ:
    How does that work?
  • BakerMan @ BakerMan:
    he jerks it in a circle
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Math Blaster lol
    +1
  • BakerMan @ BakerMan:
    guys, i know how minecraft can (kinda) get the fans not as focused on the damn mob vote: they should (with permission from 4j) bring back the console edition tutorial worlds, whether in their own tab, or if they have their own seeds
  • BakerMan @ BakerMan:
    wait i don't think the fans even care that much anymore
  • BakerMan @ BakerMan:
    although, i propose a losers' round for the mob vote, so we can see whether people would vote the golems or the iceologer (nah fuck that name i'm calling him the chillager)
  • SylverReZ @ SylverReZ:
    @BakerMan, I've never played MC in years.
    SylverReZ @ SylverReZ: @BakerMan, I've never played MC in years.