Porting non-Mac OS X app to Cocoa
Porting non-Mac OS X app to Cocoa
- Subject: Porting non-Mac OS X app to Cocoa
- From: Kevin Brandon <email@hidden>
- Date: Fri, 6 Nov 2009 00:56:38 +0100
Hi,
I have been working on a somewhat game engine (not really, but acts
like one) and currently involved in porting this to different
platforms. The engine works perfectly fine on Linux, FreeBSD and
Windows so far.
It is comprised of following parts:
1. Entry point (e.g. main or WinMain)
2. It then explicitly loads platform run-time library, depending on
the platform (in our case, it could be libCocoaAPI.dylib)
3. Then it creates windows and it should handle messages (input
messages, such as mouse and keyboard, and it should post frame events
when it's idle). All localization and/or platform-specific resource
handling is done within this shared library.
4. It may then quit.
This library is shared among different projects (which may serve for
different purposes).
Loading a library, creating windows and handling messages are fine on
Win32, Linux and FreeBSD (and on Carbon, IIRC), but we couldn't find
out a proper way to do it under Cocoa.
We need something very similar to that of SDL:
while (true)
{
if (PollEvents())
{
switch (GetEvent())
{
case MouseEvent: HandleMouseEvent(); break;
case WindowResizeEvent: HandleWindowResize(); break;
default: break;
}
}
else
HandleFrameEvent();
}
This function, however, must be implemented within a Cocoa dynamic library.
Is there a sample code doing this already? We already have different
Xcode projects for UI and this windowing framework. But we do not know
what to add into Xcode shared library (windowing framework) to work
with the application. Application's entry point is in C++, no
different than following:
typedef int (*Platform_Run)(int, char**);
int main(int argc, char* argv[])
{
void* pPlatformRuntime = dlopen("libMacRuntime.dylib", RTLD_NOW);
Platform_Runtime = (int(*)(int, char**))dlsym(pPlatformRuntime,
"Platform_Run");
int nRet = Platform_Run(argc, argv);
dlclose(pPlatformRuntime);
return nRet;
}
My questions are:
1. whether it's possible to implement entire message loop within a
shared object?
2. whether it's possible to access those messages from another shared object?
2. if so, what kind of Xcode project setup should we prepare (i.e.
should we add an Application XIB, or Empty XIB, or Window XIB)
I'd be very happy, if you could give us an idea.
Regards.
Jason
_______________________________________________
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