Re: Rethinking my approach; rather overwhelmed.
Re: Rethinking my approach; rather overwhelmed.
- Subject: Re: Rethinking my approach; rather overwhelmed.
- From: "Louis Gerbarg" <email@hidden>
- Date: Tue, 17 Jun 2008 16:22:02 -0700
On Tue, Jun 17, 2008 at 2:42 PM, Josh de Lioncourt
<email@hidden> wrote:
>> 2. Complex keyboard control. We need to be able to intercept keystrokes,
>> be able to determine when keys are pressed or released, held in combination,
>> etc. This includes the pressing of modifier keys alone. We need to let
>> these keys pass through to the OS unless the game has need of them. Many
>> games do this sort of keyboard control. Under Windows we used DirectInput,
>> a component of DirectX to accomplish this.
>>
It sounds like what you want to do is here is subclass NSApplication,
with a replacement implementation of sendEvent that decodes the
incoming events, marshals the NSEvent's parameters, then sends them to
your C++ code for processing. If your C++ code uses them you swallow
the event, if not you pass it onto the superclasses implementation and
the app code will handle them just like any other Cocoa application.
Depending on exactly how complicated your internal event
representation is this might be anywhere from a couple dozen to a
couple hundred lines of objc, but it should be identical from project
to project once you get it done. This kind of thing can be a bit on
the tricky side, but since it should be short and reusable for
basically all of your projects that is probably acceptable.
>> 3. Obviously, timing is everything in most computer games. Timing down to
>> milliseconds is essential. Nanoseconds is overkill. I understand the
>> concepts for getting the timing working with mach_absolute_time() on the Mac
>> using Duration objects to measure the time in milli/micro seconds, but have
>> yet to actually come up with working code. I suspect this is because I am
>> far from adept in Objective C at this point. I don't believe I can write
>> such code in C++ to take advantage of mach_absolute_time(), but if would
>> love to be proven wrong.
There is nothing preventing you from directly calling
mach_absolute_time from C++ if you want, it is a pure C function.. I
would recommend using gettimeofday() instead. It has millisecond
precision, and is a standard POSIX API that tons of OSes support (so
there is lots of sample code out there).
Louis
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden