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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a1bb0c0c18c89737 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-11 12:33:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!wn12feed!worldnet.att.net!207.217.77.102!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3DA72766.2010907@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: On-Screen Elapsed Time Display? References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 11 Oct 2002 19:32:20 GMT NNTP-Posting-Host: 63.184.8.76 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1034364740 63.184.8.76 (Fri, 11 Oct 2002 12:32:20 PDT) NNTP-Posting-Date: Fri, 11 Oct 2002 12:32:20 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:29728 Date: 2002-10-11T19:32:20+00:00 List-Id: Dr Nancy's Sweetie wrote: > I searched Google a few times for this, and didn't seem to find it, > but maybe I just couldn't think of the Right Magic Keywords. So > this is probably a stupid newbie question that's been answered 100 > times. (Maybe the next person to search on the keywords I came up > with will find this article and the helpful replies.) > > I have written a game, and thought it might be more interesting with > "best times" file, so people can compete with each other. It's > easy enough to add in something like this: > > type Time_T is new Long_Integer; > Start_Time, Win_Time: Time_T; > procedure Time ( Time : in out Time_T); > pragma Import (C, Time); You could also use Ada.Calendar (or Ada.Real_Time if that's not accurate enough :). > > and then set Win_Time when the player wins, subtract, and figure out > how long it took. > > What I don't see easily (and maybe I'm just blind) is a good way to > get a display on the screen (the game uses ncurses) during play. > I can update the clock every time someone pushes a key, of course, > but that's kinda lame. > > What I probably need is some Ada version setitimer(). Then it's > just a matter of set up a function that displays the clock, hook the > function to SIGALRM, and set the timer to 900ms. I found the pragma > "Attach_Handler", and also found SIGALRM in Ada.Interrupts.Names. > But what's the Ada equivalent of "setitimer();"? > > I can import setitimer(), and make Ada versions of struct timerval > and itimerval, but that's starting to feel like I'm overusing C, > and depending on Unixisms (which is bad for portability). > > What is the Right Thing to do? I'm using GNAT, if that makes any > difference. Maybe you want another task that updates the time display every so often using "delay until". Then, of course, you have 2 tasks writing to the display, so you need to protect it, but that's simple enough. Create a protected queue on which tasks can put Strings to be displayed and the position at which to display them, then have a 3rd task that takes things off this queue and does the display. Have the queue block the display task if the queue is empty. When dealing with an inherently concurrent problem, things are usually simpler if you use high-level concurrency constructs. -- Jeff Carter "Death awaits you all, with nasty, big, pointy teeth!" Monty Python & the Holy Grail