Recent Posts

Pages: [1] 2 3 ... 10
For Linux and other Unix platforms, a slightly different approach should be used. QueryPerformanceFrequency and QueryPerformanceCounter do not exist on these platforms, so you need to use e.g. other functions. The class of this clock was taken from the Deep Platformer project — in this project the clock class is adapted to Linux. These functions look like this:

Code: Pascal  [Select][+][-]
  1. function TClock.GetCounterFrequency(): Int64;
  2. begin
  4.   Result := 0;
  5.   QueryPerformanceFrequency(Result);
  6.   {$ELSE}
  7.   Result := 1000000000;
  8.   {$ENDIF}
  9. end;
  11. function TClock.GetCounterValue(): Int64;
  12. {$IFDEF UNIX}
  13. var
  14.   Counter: TTimeVal;
  15. {$ENDIF}
  16. begin
  17.   {$IFDEF WINDOWS}
  18.   Result := 0;
  19.   QueryPerformanceCounter(Result);
  20.   {$ELSE}
  21.   FPGetTimeOfDay(@Counter, nil);
  22.   Result := Int64(Counter.tv_sec) * 1000000000 + Int64(Counter.tv_usec) * 1000;
  23.   {$ENDIF}
  24. end;

In the thread hold method, the number of nanoseconds is calculated and the thread is frozen using the FPNanoSleep function. In the case of Unix, busy waiting is not needed, because FPNanoSleep supports precision down to a nanosecond (actually a microsecond, but that's enough), while under Windows, Sleep has only a millisecond precision, which is not enough — that's why busy waiting is used additionally:

Code: Pascal  [Select][+][-]
  1. procedure TClock.WaitForNMI();
  2. var
  4.   SleepTime: Single;
  5.   {$ELSE}
  6.   SleepTime: Int64;
  7.   RequestedTime, RemainingTime: TTimeSpec;
  8.   {$ENDIF}
  9. begin
  10.   if not Machine.Stopped then
  11.   begin
  12.     {$IFDEF WINDOWS}
  13.     if not FPrecise then
  14.     begin
  15.       SleepTime := 1000 / FFrameRateLimit * (1 - (FFrameTicksEnd - FFrameTicksBegin) / FTicksPerFrame) - 1;
  16.       SleepTime -= Ord(Round(SleepTime) > SleepTime);
  17.       SleepTime := Max(SleepTime, 0);
  19.       Sleep(Round(SleepTime));
  20.     end;
  22.     while GetCounterValue() < FFrameTicksNext do ;
  23.     {$ELSE}
  24.     SleepTime := FFrameTicksBegin + FTicksPerFrame - FFrameTicksEnd;
  26.     if SleepTime > 0 then
  27.     begin
  28.       RemainingTime.tv_sec := SleepTime div 1000000000;
  29.       RemainingTime.tv_nsec := SleepTime mod 1000000000;
  31.       repeat
  32.         RequestedTime := RemainingTime;
  34.         if FPNanoSleep(@RequestedTime, @RemainingTime) = 0 then Exit;
  35.         if FPGetErrNo() <> ESysEINTR then Exit;
  36.       until False;
  37.     end;
  38.     {$ENDIF}
  39.   end
  40.   else
  41.     Sleep(50);
  42. end;

When using SDL under Windows, the Sleep function does not suspend the thread's work (I don't know why), so the specified number of milliseconds is frozen by the SDL_Delay function, which also has millisecond precision. The remainder is waited with busy waiting, calling the assembly pause instruction in loop.

So, to make the clock compatible with Linux, you just need to use the fixed value 1,000,000,000 as the number of ticks of the clock (ticks per one second) and find the current time with high precision using the FPGetTimeOfDay function and simple calculations as I showed in the first code snippet.

However, to suspend the work of the thread for a given amount of time (a few or several milliseconds and the microsecond part), use the above code, i.e. simple calculations and the FPNanoSleep function in a loop. If the FPNanoSleep function will not stop the thread (like Sleep in Windows), then do the same as in Windows — calculate the millisecond part and freeze the thread with SDL_Delay, and eat the remaining (microsecond) part with busy waiting (loop checking the current number of ticks and the pause command).

So, probably the only thing that needs to be changed in the Fairtris code is the contents of the GetCounterFrequency and GetCounterValue methods, using the code taken from the clock in the Deep Platformer game. The UpdateFrameAlign method will most likely not need to be changed.
Third party / Re: Online Package Manager
« Last post by GetMem on Today at 06:04:44 pm »
Hi jmpessoa,

Unfortunately trunk/main versions may contain bugs and the bug tracker will be flooded with issues about third party packages. Actually this already happened in the past, so it was decided(not by me), that OPM should only target stable version of a particular package. Package maintainers however, can push a newer versions via the "external update" feature(see image1). There is a catch though, in order for the external update to work, you have to enable it from options(see image2). It's disabled by default because some users did not like the fact the OPM connects to various sites. So even if you create a target release and an update json, novice users most likely wouldn't be able to update, because they are not familiar with the procedure. The situation is far from ideal, but until a new update method is developed we have to cope with the current system.
In my opinion the best solution is(for now) to update the packages manually, it only takes about 3-5 minutes for me. All you have to do is to leave a message here and I will update the package in 24 hours, except weekends.
LCL / Re: ListView Selected change color
« Last post by Pe3s on Today at 04:23:16 pm »
I will read
General / Re: Do you want video tutorials?
« Last post by jamie on Today at 03:32:49 pm »
Video works for me :D
General / Re: Do you want video tutorials?
« Last post by sysrpl on Today at 03:12:41 pm »
This video is either unavailable or not supported in this browser. (Error #4000)
Linux x64, Firefox.
If your system cannot play the video, then this is the correct message. Apparently, you are missing some video codecs that you need to install if you expect to view this video and others like it. At a guess, I'd say that you do not have the AVC (Advanced Video Codec) installed. Use ffprobe to verify.

     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv,bt709), 1920x1080 [SAR 1:1 DAR 16:9], 5955 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
       handler_name    : VideoHandler
     Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
       handler_name    : SoundHandler


And allready, does anyone have example code for FPC-AVR for the UART, that compiles?


  in the wiki exists a section regarding AVR Embedded programming and more.

  Here it is a UART Example.

General / Re: Do you want video tutorials?
« Last post by Alextp on Today at 03:02:41 pm »
This video is either unavailable or not supported in this browser. (Error #4000)
Linux x64, Firefox.
LCL / Re: ListView Selected change color
« Last post by jamie on Today at 02:42:14 pm »
Have you looked at all the various custom Draw events you can use ?

You can change the brush color of the canvas depending on the state.
General / Do you want video tutorials?
« Last post by sysrpl on Today at 02:25:23 pm »
I am getting ready to start recording some of my projects running on Raspberry Pi computers and have my video capture environement ready, as the Raspberry Pi isn't powerful enough to both run my Pascal demos and record itself with ffmpeg.

This had me thinking, do you guys have any interest in Lazarus development related videos? I made a test video located below. If you're interested let me know and I may record some tutorials on specific topics and up the productions values. Let me know and I might move forward on this.

Here is an example:

Of course I could also self host this content, ensuring t never expires.
Embedded - AVR / Re: FPC-AVR hex file does not make LED blink
« Last post by pascalbythree on Today at 01:39:17 pm »
And allready, does anyone have example code for FPC-AVR for the UART, that compiles?

Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018