From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a447112bc8b81379 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: "Luke A. Guest" Newsgroups: comp.lang.ada Subject: Re: Ada, games and frame rate calculation Date: Wed, 16 Feb 2005 23:03:20 +0000 Message-ID: References: NNTP-Posting-Host: abyss2.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.demon.co.uk 1108595000 14374 62.49.62.197 (16 Feb 2005 23:03:20 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 16 Feb 2005 23:03:20 +0000 (UTC) User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Xref: g2news1.google.com comp.lang.ada:8366 Date: 2005-02-16T23:03:20+00:00 List-Id: On Wed, 16 Feb 2005 17:16:06 -0500, Stephen Leake wrote: > "Luke A. Guest" writes: > >> Hi, >> >> I'm currently designing a game engine in Ada and was wondering about using >> the Ada.Real_Time facilities (especially the timing). > > If you are using GNAT on Windows, there is no difference between > Ada.Real_Time and Ada.Calendar. On other compilers and operating > systems, there may be a difference. It's portable, so yeah there will be a windaz build. My main development platform is Linux. I'm surprised that the win32 is identical to Calendar, well not that surprised ;-) just as long as I can get milliseconds from it then that'll be fine. Although, I would've thought they'd have used the performance counters for the Ada.Real_Time package! >> Now, normally you get the current time calculate how much time has >> passed since the last time it was called. These values are used to >> implement frame rate (FPS) display and to animated models. > > I'm a little confused by this. A typical loop should be: > > declare > use Ada.Real_Time; -- or Calendar > Next_Time : Time; > Frame_Time : Time_Span := To_Time_Span (0.0333); > begin > loop > Next_Time := Next_Time + Frame_Time; > delay until Next_Time; > -- do stuff here > end loop; > end; You don't have to delay...what's confusing? It's a game engine, you want it to run as fast as possible, but by utilising certain Ada language features, you get some extra nice functionality that's portable. >> So ultimately, I need to get access to the internals (I think). > > No, that should never be necessary. Well, not at the bit level no ;-) I have been told and I've verified it, that I can use Duration and use that to get the string value to display. >> So, as an example, I have my Ada.Real_Time.Time type which is my FPS, I >> now have to display this on screen, so I need to determine the actual >> text from the value. How do I do this? > > Use Split and To_Duration: > > declare > seconds : seconds_Count; > fraction : time_span; > begin > split (Next_time, seconds, fraction); put_Line (seconds_count'image > (Seconds) & "." & duration'image > (to_duration (fraction))); > end; > > That's not a very clean format, but you get the idea. Well, here's my current FPS calculation: procedure CalculateFPS is CurrentTime : Float := Float(SDL.Timer.GetTicks) / 1000.0; ElapsedTime : Float := CurrentTime - LastElapsedTime; FramesPerSecond : String(1 .. 10); MillisecondPerFrame : String(1 .. 10); package Float_InOut is new Text_IO.Float_IO(Float); use Float_InOut; begin FrameCount := FrameCount + 1; if ElapsedTime > 1.0 then FPS := Float(FrameCount) / ElapsedTime; Put(FramesPerSecond, FPS, Aft => 2, Exp => 0); Put(MillisecondPerFrame, 1000.0 / FPS, Aft => 2, Exp => 0); SDL.Video.WM_Set_Caption_Title(Example.GetTitle & " " & FramesPerSecond & " fps " & MillisecondPerFrame & " ms/frame"); LastElapsedTime := CurrentTime; FrameCount := 0; end if; end CalculateFPS; Now that uses SDL, but ultimately that's not portable and I won't be using SDL in the long run and cannot depend on it. Luke.