File: main.cpp

package info (click to toggle)
flobopuyo 0.20-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,052 kB
  • sloc: cpp: 6,209; ansic: 3,743; yacc: 179; makefile: 176; lex: 42
file content (98 lines) | stat: -rw-r--r-- 2,859 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdlib.h>
#include <string.h>
#ifdef MACOSX
#include <CoreFoundation/CoreFoundation.h>
#endif

#include "PuyoCommander.h"

#ifndef DATADIR
char *DATADIR = "/usr/share/games/flobopuyo";
#endif

char *dataFolder = "data";

#ifdef MACOSX
const char *bundleDataPath = "/Contents/Resources/data";
void show(CFStringRef formatString, ...) {
    CFStringRef resultString;
    CFDataRef data;
    va_list argList;
    
    va_start(argList, formatString);
    resultString = CFStringCreateWithFormatAndArguments(NULL, NULL, formatString, argList);
    va_end(argList);
    
    data = CFStringCreateExternalRepresentation(NULL, resultString, CFStringGetSystemEncoding(), '?');
    
    if (data != NULL) {
        printf ("%.*s\n\n", (int)CFDataGetLength(data), CFDataGetBytePtr(data));
        CFRelease(data);
    }
    
    CFRelease(resultString);
}
#endif

bool fileExists(char *path)
{
    FILE *f;
    f = fopen(path, "r");
    if (f == NULL)
        return false;
    fclose(f);
    return true;
}

#include <SDL/SDL_main.h>

int main(int argc, char *argv[])
{
    int i;
    
  if (!strcmp(argv[argc-1],"-h")) {
      printf("-win for windowed mode.\n");
      printf("-quiet to remove music.\n");
      printf("-nofx to remove sound FX.\n");
    return 0;
  }
    
#ifdef MACOSX

#ifndef DATADIR
    CFStringRef bundlePath = CFURLCopyFileSystemPath(CFBundleCopyBundleURL(CFBundleGetMainBundle()), kCFURLPOSIXPathStyle);
    int pathSize = (int)CFStringGetMaximumSizeForEncoding(CFStringGetLength(bundlePath), CFStringGetSystemEncoding()) + 1;
    DATADIR = (char *)malloc(pathSize + strlen(bundleDataPath));
    CFStringGetCString (bundlePath, DATADIR, pathSize, CFStringGetSystemEncoding());
    strcat(DATADIR, bundleDataPath);
    
    //show(CFSTR("test   : %@"), CFURLCopyFileSystemPath(CFBundleCopyBundleURL(CFBundleGetMainBundle()), kCFURLPOSIXPathStyle));
    //fprintf(stderr, "bundle=%d path=%s\n", CFBundleGetMainBundle(), DATADIR);
    //fprintf(stderr, "Attention ça va planter2\n");
    //CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle(),kCFStringEncodingUnicode);
    //DATADIR = strdup(CFStringGetCStringPtr(CFURLGetString( CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle())), kCFStringEncodingUnicode));
    //fprintf(stderr, "Resource path: %s\n", DATADIR);
#endif
#endif
 
    bool fs = true;
    bool snd = true;
    bool fx = true;
    
    for (i=1; i<argc; i++)
    {
        if (strcmp(argv[i],"-win") == 0) fs = false;
        if (strcmp(argv[i],"-quiet") == 0) snd = false;
        if (strcmp(argv[i],"-nofx") == 0) fx = false;
    }
    
    if (!fileExists("data/gfx/v0.png")) {
        dataFolder = DATADIR;
    }
    
    PuyoCommander commander( fs, snd, fx );

    
  commander.run();
  return 0;
}