Skip to content
  • English
  • Polski
Digital Karabela
Digital Karabela
Primary Navigation Menu
Menu
  • Home
  • Products
  • DevBlog
  • Castle Engine
  • About

Measuring the passage of time on Android

Castle Game Engine Logo

While testing the game I’m working on, I came across a strange error. Sometimes, every 10-20 minutes, the game freezes for a moment. First, I noticed that the engine shows many debug lines:

Time: Detected gettimeofday() going backwards on Unix, workarounding. This is known to happen on some Android devices

So I limited the debug to one line, that significantly reduced downtime, but it still occurred. Like Michalis, I assumed it was a defect in my phone. But I was wondering why other games run smoothly.

Clocks on Android

After a short investigation, it turned out that time on Android can be obtained in several ways. The default clock, called the “wall” clock, synchronizes with the network quite often what can cause forward and backward jumps. This clock is used by the function fpgettimeofday(), which was used by CGE and the Kraft physics engine.

A monotonic clock on Android

To use a clock that guarantees monotonic continuity, use the clock_gettime(CLOCK_MONOTONIC) function from the Linux module. After making these changes, the game began to work perfectly without any temporary freezing.

Castle Game Engine and Kraft fixes

If you’re planning to create a game for Android, remember that in Castle Game Engine the problem was resolved on August 18, 2019.

The Kraft was repaired on August 21, 2019, in official repository.

2019-09-02
Previous Post: Streaming music in Castle Game Engine
Next Post: Running Castle Game Engine games on Raspberry Pi

Try my new game! Free to play!

Logo Bricks Color Pick

Bricks Color Pick is a completely new approach to classic Arkanoid! No paddle! Now your goal is to switch the color of the ball to the color of the brick.

Get it from Google Play

Level 37/40 5-6 Colors Screenshot

You can also change ball movement direction by the button in top left corner.

QR Code Google Play Bricks Color Pick

Level 62/80 (RelaxMode) Screenshot

Recent Posts

  • How to compile OpenAL library for Android with Oboe library.
  • Lazarus 2.0.12 Released
  • How to Fix LMMS GUI Freezing on Linux?
  • How to update wine to 5.0.0 on Linux Mint 19 or Ubuntu 18?
  • Agile Commander 1.2.3 Released!

Categories

  • DevBlog
  • GameDev
    • Castle Game Engine
    • Godot Engine
  • Linux
  • Programming
    • Dlang
      • DlangUI
    • Object Pascal
      • Lazarus
  • Promotion

Products:
Agile Commander
Bricks Color Pick

 

 

Digital Karabela – Andrzej Kilijański
76-015 Wyszebórz 32, Poland
https://digitalkarabela.com
Contact
Privacy Policy