-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
98 lines (77 loc) · 2.78 KB
/
main.cpp
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 <cstdlib>
#include <cstring>
#ifdef MACOSX
#include <CoreFoundation/CoreFoundation.h>
#endif
#include "PuyoCommander.h"
#ifndef DATADIR
const char *DATADIR = "data";
#endif
const 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(const char *path)
{
FILE *f;
f = fopen(path, "r");
if (f == NULL)
return false;
fclose(f);
return true;
}
#include <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;
}