![]() |
![]() |
#1 |
Registered User
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,452
|
Getting millisecond elapsed time using Bebbo's Amiga GCC toolchain
Hi,
Wonder if anyone can help. I need a fast way to tack how much time has passed in my main loop. I normally use https://www.tutorialspoint.com/c_sta...tion_clock.htm which has a high frequency on the old GCC 3.4 (milliseconds) but in my Bebbo build it seems to be limited to 50fps. I've hacked together the following code but I'm not really sure it's the best way to do it. Code:
gettimeofday(&lastFrameTime, NULL); while (true) { gettimeofday(¤tFrameTime, NULL); double elapsedtime = (currentFrameTime.tv_sec - lastFrameTime.tv_sec) * 1000.0; // sec to ms elapsedtime += (currentFrameTime.tv_usec - lastFrameTime.tv_usec) / 1000.0; // us to ms // Capture user input and update object positions. g_world->updateWorld(elapsedtime / 1000); g_world->updateFrame(); memcpy(&lastFrameTime, ¤tFrameTime, sizeof(struct timeval)); } Thanks ![]() |
![]() |
![]() |
#2 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 323
|
I don't have a lot of context, but if you're limited to 50 fps, maybe you're using the wrong CIA timer in your gettimeofday?
Anyway, in case it helps, this is how I do it, having taken over the system: Code:
ULONG GetCurrentTime(void) { ULONG hi = ciab->ciatodhi; // latch activated ULONG mid = ciab->ciatodmid; ULONG low = ciab->ciatodlow; // latch deactivated return ((hi << 8 | mid) << 8 | low) << 8; } Code:
Display_Show(); game.isPaused = FALSE; ULONG previousTime = GetCurrentTime(); ULONG lag = 0; Game_UpdateDisplay(); for (;;) { ULONG currentTime = GetCurrentTime(); ULONG elapsedTime = currentTime - previousTime; ULONG fps = (256 * CLOCK_CONSTANT) / (227 * elapsedTime); previousTime = currentTime; lag += elapsedTime; ULONG ticks = 0; while (lag >= TIMER_INCREMENT_PER_SIMULATION_STEP) { Game_ProcessUserInput(); if (game.exitRequested) break; Game_UpdateState(); lag -= TIMER_INCREMENT_PER_SIMULATION_STEP; ticks++; } if (game.exitRequested) break; Game_UpdateDisplay(); TinyText_MoveTo(80 - 8, 0); TinyText_PrintFormatted("%4ld fps", fps); TinyText_MoveTo(80 - 8, 1); TinyText_PrintFormatted("%4ld ipf", ticks); } game.isPaused = TRUE; PrintStatistics(); Code:
ciab->ciacrb &= ~CIACRBF_ALARM; |
![]() |
![]() |
#3 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,447
|
Quote:
No, I do not recommend accessing the hardware. Reading the E-clock has certain quirks the Os takes care of. |
|
![]() |
Currently Active Users Viewing This Thread: 3 (2 members and 1 guests) | |
Thomas Richter, peceha |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Setting up a debugging environment for Bebbo's Amiga GCC toolchain | Nightfox | Coders. C/C++ | 3 | 12 July 2024 19:48 |
GCC 6.2 toolchain for AmigaOS 3 | Samurai_Crow | Coders. C/C++ | 1555 | 01 May 2024 19:56 |
Can't make bebbo's amiga-gcc work | Bren McGuire | Coders. General | 18 | 12 June 2023 01:09 |
bebbo gcc+eclipse problem | Raislin77it | Coders. C/C++ | 1 | 15 February 2022 08:37 |
gcc-bebbo: argc is always 0 | sparhawk | Coders. C/C++ | 8 | 31 January 2021 18:42 |
|
|