⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3controller.m

📁 quakeIII源码这个不用我多说吧
💻 M
📖 第 1 页 / 共 2 页
字号:
        
        arg = [arguments objectAtIndex:argumentIndex];
        // Don't pass the Process Serial Number command line arg that the Window Server/Finder invokes us with
        if ([arg hasPrefix: @"-psn_"])
            continue;
            
        argv[argc++] = strdup([arg cString]);
    }
    
    // Figure out where the level data is stored.
    installationPathKey = @"RetailInstallationPath";

    installationPath = [[NSUserDefaults standardUserDefaults] objectForKey:installationPathKey];
    if (!installationPath) {
        // Default to the directory containing the executable (which is where most users will want to put it
        installationPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
    }

#if !defined(DEDICATED)    
    appName = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleName"];
#else
	// We are hard coding the app name here since the dedicated server is a tool, not a app bundle and does not have access to the Info.plist that the client app does.  Suck.
    appName = @"Quake3";
#endif
    demoAppName = appName;

    while (YES) {
        NSString *dataPath;
        NSOpenPanel *openPanel;
        int result;
        
        foundDirectory = NO;
        defaultManager = [NSFileManager defaultManager];
        //NSLog(@"Candidate installation path = %@", installationPath);
        dataPath = [installationPath stringByAppendingPathComponent: @"baseq3"];
        
        if ([defaultManager fileExistsAtPath: dataPath]) {
            // Check that the data directory contains at least one .pk3 file.  We don't know what it will be named, so don't hard code a name (for example it might be named 'french.pk3' for a French release
            NSArray *files;
            unsigned int fileIndex;
            
            files = [defaultManager directoryContentsAtPath: dataPath];
            fileIndex = [files count];
            while (fileIndex--) {
                if ([[files objectAtIndex: fileIndex] hasSuffix: @"pk3"]) {
                    //NSLog(@"Found %@.", [files objectAtIndex: fileIndex]);
                    foundDirectory = YES;
                    break;
                }
            }
        }
        
        if (foundDirectory)
            break;

#ifdef DEDICATED
            break;
#warning TJW: We are hard coding the app name and default domain here since the dedicated server is a tool, not a app bundle and does not have access to the Info.plist that the client app does.  Suck.
        NSLog(@"Unable to determine installation directory.  Please move the executable into the '%@' installation directory or add a '%@' key in the 'Q3DedicatedServer' defaults domain.", appName, installationPathKey, [[NSBundle mainBundle] bundleIdentifier]);
        Sys_Quit();
        exit(1);
#else
        selectButton = @"Select Retail Installation...";

        result = NSRunAlertPanel(demoAppName, @"You need to select the installation directory for %@ (not any directory inside of it -- the installation directory itself).", selectButton, @"Quit", nil, appName);
        switch (result) {
            case NSAlertDefaultReturn:
                break;
            default:
                Sys_Quit();
                break;
        }
        
        openPanel = [NSOpenPanel openPanel];
        [openPanel setAllowsMultipleSelection:NO];
        [openPanel setCanChooseDirectories:YES];
        [openPanel setCanChooseFiles:NO];
        result = [openPanel runModalForDirectory:nil file:nil];
        if (result == NSOKButton) {
            NSArray *filenames;

            filenames = [openPanel filenames];
            if ([filenames count] == 1) {
                installationPath = [filenames objectAtIndex:0];
                [[NSUserDefaults standardUserDefaults] setObject:installationPath forKey:installationPathKey];
                [[NSUserDefaults standardUserDefaults] synchronize];
            }
        }
#endif
    }
    
    // Create the application support directory if it doesn't exist already
    do {
        NSArray *results;
        NSString *libraryPath, *homePath, *filePath;
        NSDictionary *attributes;
        
        results = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
        if (![results count])
            break;
        
        libraryPath = [results objectAtIndex: 0];
        homePath = [libraryPath stringByAppendingPathComponent: @"Application Support"];
        homePath = [homePath stringByAppendingPathComponent: appName];
        filePath = [homePath stringByAppendingPathComponent: @"foo"];
        
        attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithUnsignedInt: 0750], NSFilePosixPermissions, nil];
        NS_DURING {
            Sys_CreatePathToFile(filePath, attributes);
            Sys_SetDefaultHomePath([homePath fileSystemRepresentation]);
        } NS_HANDLER {
            NSLog(@"Exception: %@", localException);
#ifndef DEDICATED
            NSRunAlertPanel(nil, @"Unable to create '%@'.  Please make sure that you have permission to write to this folder and re-run the game.", @"OK", nil, nil, homePath);
#endif
            Sys_Quit();
        } NS_ENDHANDLER;
    } while(0);
    
    // Provoke the CD scanning code into looking up the CD.
    Sys_CheckCD();
    
    // Let the filesystem know where our local install is
    Sys_SetDefaultInstallPath([installationPath cString]);

    cmdline = NULL;
#if 0
    if (GRCheckFileForCmd()) {
	GRGetWaitingCmd();
	if (GRHasProperty( 'Exec' )) {
            NSString *cfgPath, *grCfg;
            cfgPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
            cfgPath = [cfgPath stringByAppendingPathComponent: [NSString stringWithCString: GRGetPropertyStr( 'Exec' )]];
            grCfg = [NSString stringWithContentsOfFile: cfgPath];
            cmdline = malloc(strlen([grCfg cString])+1);
            [grCfg getCString: cmdline];
	}
    }
#endif
    if (!cmdline) {
        // merge the command line, this is kinda silly	
        for (commandLineLength = 1, argumentIndex = 1; argumentIndex < argc; argumentIndex++)
            commandLineLength += strlen(argv[argumentIndex]) + 1;
        cmdline = malloc(commandLineLength);
        *cmdline = '\0';
        for (argumentIndex = 1; argumentIndex < argc; argumentIndex++) {
            if (argumentIndex > 1)
                strcat(cmdline, " ");
            strcat(cmdline, argv[argumentIndex]);
        }
    }
    Com_Printf("command line: %s\n", cmdline);
    
    Com_Init(cmdline);

#ifndef DEDICATED
    [NSApp activateIgnoringOtherApps:YES];
#endif

    while (1) {
        Com_Frame();

        if ((count & 15)==0) {
            // We should think about doing this less frequently than every frame
            [pool release];
            pool = [[NSAutoreleasePool alloc] init];
        }
    }

    [pool release];
}

@end



// Creates any directories needed to be able to create a file at the specified path.  Raises an exception on failure.
static void Sys_CreatePathToFile(NSString *path, NSDictionary *attributes)
{
    NSArray *pathComponents;
    unsigned int dirIndex, dirCount;
    unsigned int startingIndex;
    NSFileManager *manager;
    
    manager = [NSFileManager defaultManager];
    pathComponents = [path pathComponents];
    dirCount = [pathComponents count] - 1;

    startingIndex = 0;
    for (dirIndex = startingIndex; dirIndex < dirCount; dirIndex++) {
        NSString *partialPath;
        BOOL fileExists;

        partialPath = [NSString pathWithComponents:[pathComponents subarrayWithRange:NSMakeRange(0, dirIndex + 1)]];
        
        // Don't use the 'fileExistsAtPath:isDirectory:' version since it doesn't traverse symlinks
        fileExists = [manager fileExistsAtPath:partialPath];
        if (!fileExists) {
            if (![manager createDirectoryAtPath:partialPath attributes:attributes]) {
                [NSException raise:NSGenericException format:@"Unable to create a directory at path: %@", partialPath];
            }
        } else {
            NSDictionary *attributes;

            attributes = [manager fileAttributesAtPath:partialPath traverseLink:YES];
            if (![[attributes objectForKey:NSFileType] isEqualToString: NSFileTypeDirectory]) {
                [NSException raise:NSGenericException format:@"Unable to write to path \"%@\" because \"%@\" is not a directory",
                    path, partialPath];
            }
        }
    }
}

#ifdef DEDICATED
void S_ClearSoundBuffer( void ) {
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -