简体   繁体   English

构建Mac OS X App而不是控制台

[英]Building Mac OS X App instead of console

I have a port of my application, a game, running on Mac OS X. I build with make, and only added a few .mm files to access the necessities from NSApplication, NSWindow and NSOpenGLView. 我有一个应用程序端口,一个游戏,可在Mac OS X上运行。我使用make进行构建,并且仅添加了几个.mm文件来访问NSApplication,NSWindow和NSOpenGLView的必需品。

  1. How do I "convert it" into a proper App as opposed to the current console form? 如何将其“转换”为适合的应用程序,而不是当前的控制台形式? Do I bundle it with something, if so how? 我是否将其与某些东西捆绑在一起? Or is it some type of linker setting (as in Windows)? 还是某种类型的链接器设置(如Windows)? Do I have to build using XCode? 我必须使用XCode进行构建吗?
  2. Currently I just "tick" the system, ie poll it for events rather than utilizing OS X message pump properly. 当前,我只是“打勾”系统,即轮询事件,而不是正确使用OS X消息泵。 Could you point me to some basic sample or tutorial which shows me how to do it properly, while still being able to "tick" my own stuff at a fixed frame rate? 您能否指出一些基本示例或教程,向我展示如何正确执行操作,同时仍然能够以固定帧速率“标记”我自己的东西? I say "sample or tutorial", since I am blind when it comes to documentation. 我之所以说“示例或教程”,是因为我对文档一无所知。

Thanks! 谢谢!

For the creation of a proper Mac application, you'll have to create a Mac OS X bundle. 为了创建正确的Mac应用程序,您必须创建Mac OS X捆绑软件。 You can find the great documentation on the Apple site, here . 你可以找到在苹果网站上的精彩文档, 在这里 You can create them with standard tool (I did write a small python script to create a bundle from a simple .ini file that describe files to pack, and how to construct the Info.plist file). 您可以使用标准工具创建它们(我确实编写了一个小型python脚本,从一个简单的.ini文件创建一个捆绑包,该捆绑包描述了要打包的文件以及如何构造Info.plist文件)。

Basically, an application bundle is just a regular directory with a .app extension, and a fixed structure. 基本上,应用程序捆绑包只是带有.app扩展名和固定结构的常规目录。 The following file are required: 需要以下文件:

Application.app/
  + Contents/
    + MacOS/
    | + <Executable>
    + Resources/
    | + <Icon>
    + Info.plist

The Info.plist file is a standard property list file (either in XML or in the old format), that indicate what is the name of the executable file ( CFBundleExecutable ), what is the name of the icon file ( CFBundleIconFile ), the bundle type ( CFBundleType with a value of APPL ), and some other informations (file type supported, version string, development language, ...). Info.plist文件是标准属性列表文件(采用XML或旧格式),指示可执行文件的名称是什么( CFBundleExecutable ),图标文件的名称是什么( CFBundleIconFile ),该文件包类型( CFBundleType的值为APPL )和其他一些信息(支持的文件类型,版本字符串,开发语言等)。 Those file is the strict minimum required to have a basic Mac OS X application. 这些文件是具有基本Mac OS X应用程序所需的严格最低要求。

For explanation of how the Mac OS X message pump work, I recommend the reading of this article by Matt Gallagher. 有关Mac OS X消息泵工作原理的解释,建议阅读Matt Gallagher 撰写的本文 He explains how the run message of the NSApplication class is implemented. 他解释了如何实现NSApplication类的运行消息。 You can then write this method runOnce that only iterate when there are pending messages. 然后,您可以编写此runOnce方法,该方法仅在有待处理消息时进行迭代。 You'll then call this function periodically (it is really similar to the PeekMessage , TranslateMessage , and DispatchMessage sequence on Win32): 然后,您将定期调用此函数(它实际上类似于Win32上的PeekMessageTranslateMessageDispatchMessage序列):

- (void)runOnce
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    [self finishLaunching];

    for (;;)
    {
        [pool release];
        pool = [[NSAutoreleasePool alloc] init];

        NSEvent *event =
            [self
                nextEventMatchingMask:NSAnyEventMask
                untilDate:nil
                inMode:NSDefaultRunLoopMode
                dequeue:YES];

        if (sender == nil)
            break;

        [self sendEvent:event];
        [self updateWindows];
    }

    [pool release];
}

Unless you really want to learn a bunch of Mac-specific APIs and XCode, you should just use SDL . 除非您真的想学习大量Mac专用的API和XCode,否则应该只使用SDL It's a cross-platform library that abstracts things like event handling, threading, and multimedia. 它是一个跨平台的库,它抽象了诸如事件处理,线程和多媒体之类的内容。 It includes XCode templates that allow you to build a proper app bundle with minimal changes to your code. 它包含XCode模板,可让您以最小的代码更改来构建适当的应用程序包。 Using SDL would mean throwing away most of the Mac-specific code you've written, but it would vastly simplify any future ports and would make it easier to maintain your app for multiple platforms. 使用SDL意味着将丢弃您编写的大多数特定于Mac的代码,但是它将极大地简化将来的任何端口,并使在多个平台上维护应用程序变得更加容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM