ray 0.0.0.pre2 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +3 -0
  3. data/README.md +62 -0
  4. data/Rakefile +33 -23
  5. data/VERSION +1 -1
  6. data/ext/audio.c +473 -0
  7. data/ext/color.c +4 -4
  8. data/ext/event.c +25 -3
  9. data/ext/extconf.rb +35 -22
  10. data/ext/font.c +287 -0
  11. data/ext/image.c +682 -33
  12. data/ext/joystick.c +9 -9
  13. data/ext/ray.c +166 -55
  14. data/ext/ray.h +120 -9
  15. data/ext/ray_osx.m +161 -0
  16. data/ext/rect.c +31 -4
  17. data/lib/ray/audio.rb +52 -0
  18. data/lib/ray/color.rb +16 -0
  19. data/lib/ray/dsl.rb +1 -3
  20. data/lib/ray/dsl/event.rb +1 -39
  21. data/lib/ray/dsl/event_listener.rb +38 -0
  22. data/lib/ray/dsl/event_runner.rb +3 -1
  23. data/lib/ray/dsl/event_translator.rb +74 -8
  24. data/lib/ray/dsl/handler.rb +3 -33
  25. data/lib/ray/dsl/matcher.rb +129 -23
  26. data/lib/ray/font.rb +108 -0
  27. data/lib/ray/font_set.rb +37 -0
  28. data/lib/ray/game.rb +171 -34
  29. data/lib/ray/helper.rb +43 -5
  30. data/lib/ray/image.rb +90 -3
  31. data/lib/ray/image_set.rb +35 -0
  32. data/lib/ray/joystick.rb +30 -0
  33. data/lib/ray/music_set.rb +35 -0
  34. data/lib/ray/ray.rb +17 -9
  35. data/lib/ray/rect.rb +51 -0
  36. data/lib/ray/resource_set.rb +92 -0
  37. data/lib/ray/scene.rb +220 -51
  38. data/lib/ray/sound_set.rb +35 -0
  39. data/lib/ray/sprite.rb +184 -0
  40. data/psp/ext.c +4 -0
  41. data/samples/hello_world/hello.rb +35 -0
  42. data/samples/hello_world/hello_dsl.rb +24 -0
  43. data/samples/pong/pong.rb +128 -0
  44. data/samples/sokoban/level_1 +7 -0
  45. data/samples/sokoban/sokoban.rb +370 -0
  46. data/spec/ray/audio_spec.rb +146 -0
  47. data/spec/ray/color_spec.rb +13 -0
  48. data/spec/ray/event_spec.rb +57 -168
  49. data/spec/ray/font_spec.rb +93 -0
  50. data/spec/ray/image_set_spec.rb +48 -0
  51. data/spec/ray/image_spec.rb +130 -44
  52. data/spec/ray/joystick_spec.rb +13 -9
  53. data/spec/ray/matcher_spec.rb +32 -55
  54. data/spec/ray/ray_spec.rb +33 -31
  55. data/spec/ray/rect_spec.rb +80 -0
  56. data/spec/ray/resource_set_spec.rb +105 -0
  57. data/spec/ray/sprite_spec.rb +163 -0
  58. data/spec/res/VeraMono.ttf +0 -0
  59. data/spec/res/aqua2.bmp +0 -0
  60. data/spec/res/pop.wav +0 -0
  61. data/spec/spec.opts +4 -0
  62. data/spec/spec_helper.rb +8 -0
  63. data/yard_ext.rb +91 -0
  64. metadata +104 -38
  65. data/bin/ray +0 -5
  66. data/bin/ray_irb +0 -4
  67. data/ext/SDLMain.h +0 -17
  68. data/ext/SDLMain.m +0 -381
  69. data/lib/ray/config.rb +0 -84
  70. data/lib/ray/dsl/converter.rb +0 -65
  71. data/lib/ray/dsl/listener.rb +0 -30
  72. data/lib/ray/dsl/type.rb +0 -58
  73. data/spec/ray/config_spec.rb +0 -90
  74. data/spec/ray/conversion_spec.rb +0 -43
  75. data/spec/ray/type_spec.rb +0 -17
  76. data/spec_runner.rb +0 -27
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ray
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- - pre2
10
- version: 0.0.0.pre2
8
+ - 1
9
+ version: 0.0.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - "Mon ou\xC3\xAFe"
@@ -15,58 +14,112 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-25 00:00:00 +02:00
17
+ date: 2010-10-17 00:00:00 +02:00
19
18
  default_executable:
20
- dependencies: []
21
-
22
- description:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: jeweler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: yard
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: psp_task
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :development
71
+ version_requirements: *id004
72
+ description: Written to play with Ruby
23
73
  email: mon.ouie@gmail.com
24
- executables:
25
- - ray
26
- - ray_irb
27
- - ray
28
- - ray_irb
74
+ executables: []
75
+
29
76
  extensions:
30
77
  - ext/extconf.rb
31
- - ext/extconf.rb
32
- extra_rdoc_files: []
33
-
78
+ extra_rdoc_files:
79
+ - README.md
34
80
  files:
35
81
  - .gitignore
36
82
  - .gitmodules
83
+ - .rspec
84
+ - README.md
37
85
  - Rakefile
38
86
  - VERSION
39
- - bin/ray
40
- - bin/ray_irb
41
- - ext/SDLMain.h
42
- - ext/SDLMain.m
87
+ - ext/audio.c
43
88
  - ext/color.c
44
89
  - ext/event.c
45
90
  - ext/extconf.rb
91
+ - ext/font.c
46
92
  - ext/image.c
47
93
  - ext/joystick.c
48
94
  - ext/ray.c
49
95
  - ext/ray.h
96
+ - ext/ray_osx.m
50
97
  - ext/rect.c
51
98
  - lib/ray.rb
99
+ - lib/ray/audio.rb
52
100
  - lib/ray/color.rb
53
- - lib/ray/config.rb
54
101
  - lib/ray/dsl.rb
55
- - lib/ray/dsl/converter.rb
56
102
  - lib/ray/dsl/event.rb
103
+ - lib/ray/dsl/event_listener.rb
57
104
  - lib/ray/dsl/event_raiser.rb
58
105
  - lib/ray/dsl/event_runner.rb
59
106
  - lib/ray/dsl/event_translator.rb
60
107
  - lib/ray/dsl/handler.rb
61
- - lib/ray/dsl/listener.rb
62
108
  - lib/ray/dsl/matcher.rb
63
- - lib/ray/dsl/type.rb
109
+ - lib/ray/font.rb
110
+ - lib/ray/font_set.rb
64
111
  - lib/ray/game.rb
65
112
  - lib/ray/helper.rb
66
113
  - lib/ray/image.rb
114
+ - lib/ray/image_set.rb
115
+ - lib/ray/joystick.rb
116
+ - lib/ray/music_set.rb
67
117
  - lib/ray/ray.rb
68
118
  - lib/ray/rect.rb
119
+ - lib/ray/resource_set.rb
69
120
  - lib/ray/scene.rb
121
+ - lib/ray/sound_set.rb
122
+ - lib/ray/sprite.rb
70
123
  - psp/SDL_psp_main.c
71
124
  - psp/bigdecimal/README
72
125
  - psp/bigdecimal/bigdecimal.c
@@ -131,22 +184,34 @@ files:
131
184
  - psp/syck/yamlbyte.h
132
185
  - psp/thread/thread.c
133
186
  - psp/zlib/zlib.c
187
+ - samples/hello_world/hello.rb
188
+ - samples/hello_world/hello_dsl.rb
189
+ - samples/pong/pong.rb
190
+ - samples/sokoban/level_1
191
+ - samples/sokoban/sokoban.rb
134
192
  - script.rb
193
+ - spec/ray/audio_spec.rb
135
194
  - spec/ray/color_spec.rb
136
- - spec/ray/config_spec.rb
137
- - spec/ray/conversion_spec.rb
138
195
  - spec/ray/event_spec.rb
196
+ - spec/ray/font_spec.rb
197
+ - spec/ray/image_set_spec.rb
139
198
  - spec/ray/image_spec.rb
140
199
  - spec/ray/joystick_spec.rb
141
200
  - spec/ray/matcher_spec.rb
142
201
  - spec/ray/ray_spec.rb
143
202
  - spec/ray/rect_spec.rb
144
- - spec/ray/type_spec.rb
203
+ - spec/ray/resource_set_spec.rb
204
+ - spec/ray/sprite_spec.rb
205
+ - spec/res/VeraMono.ttf
145
206
  - spec/res/aqua.bmp
146
207
  - spec/res/aqua.png
208
+ - spec/res/aqua2.bmp
147
209
  - spec/res/not_a_jpeg.jpeg
148
- - spec_runner.rb
149
- has_rdoc: true
210
+ - spec/res/pop.wav
211
+ - spec/spec.opts
212
+ - spec/spec_helper.rb
213
+ - yard_ext.rb
214
+ has_rdoc: yard
150
215
  homepage: http://github.com/Mon-Ouie/ray
151
216
  licenses: []
152
217
 
@@ -166,28 +231,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
231
  required_rubygems_version: !ruby/object:Gem::Requirement
167
232
  none: false
168
233
  requirements:
169
- - - ">"
234
+ - - ">="
170
235
  - !ruby/object:Gem::Version
171
236
  segments:
172
- - 1
173
- - 3
174
- - 1
175
- version: 1.3.1
237
+ - 0
238
+ version: "0"
176
239
  requirements: []
177
240
 
178
241
  rubyforge_project:
179
242
  rubygems_version: 1.3.7
180
243
  signing_key:
181
244
  specification_version: 3
182
- summary: ""
245
+ summary: A library to write games (or to play with) in Ruby
183
246
  test_files:
247
+ - spec/ray/audio_spec.rb
184
248
  - spec/ray/color_spec.rb
185
- - spec/ray/config_spec.rb
186
- - spec/ray/conversion_spec.rb
187
249
  - spec/ray/event_spec.rb
250
+ - spec/ray/font_spec.rb
251
+ - spec/ray/image_set_spec.rb
188
252
  - spec/ray/image_spec.rb
189
253
  - spec/ray/joystick_spec.rb
190
254
  - spec/ray/matcher_spec.rb
191
255
  - spec/ray/ray_spec.rb
192
256
  - spec/ray/rect_spec.rb
193
- - spec/ray/type_spec.rb
257
+ - spec/ray/resource_set_spec.rb
258
+ - spec/ray/sprite_spec.rb
259
+ - spec/spec_helper.rb
data/bin/ray DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- path = File.expand_path(File.join(File.dirname(__FILE__), "../ext/ray"))
4
- args = ARGV.map { |i| '"' + i.gsub('"', "\\\"") + '"' }.join(' ')
5
- system "#{path} #{args}"
data/bin/ray_irb DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- system <<-COMMAND
3
- ray -e "require 'irb'; IRB.start"
4
- COMMAND
data/ext/SDLMain.h DELETED
@@ -1,17 +0,0 @@
1
- /* SDLMain.m - main entry point for our Cocoa-ized SDL app
2
- Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
3
- Non-NIB-Code & other changes: Max Horn <max@quendi.de>
4
-
5
- Feel free to customize this file to suit your needs
6
- */
7
-
8
- #ifndef _SDLMain_h_
9
- #define _SDLMain_h_
10
-
11
- #import <Cocoa/Cocoa.h>
12
-
13
- @interface SDLMain : NSObject {
14
- }
15
- @end
16
-
17
- #endif /* _SDLMain_h_ */
data/ext/SDLMain.m DELETED
@@ -1,381 +0,0 @@
1
- /* SDLMain.m - main entry point for our Cocoa-ized SDL app
2
- Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
3
- Non-NIB-Code & other changes: Max Horn <max@quendi.de>
4
-
5
- Feel free to customize this file to suit your needs
6
- */
7
-
8
- #include "SDL.h"
9
- #include "SDLMain.h"
10
- #include <sys/param.h> /* for MAXPATHLEN */
11
- #include <unistd.h>
12
-
13
- /* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
14
- but the method still is there and works. To avoid warnings, we declare
15
- it ourselves here. */
16
- @interface NSApplication(SDL_Missing_Methods)
17
- - (void)setAppleMenu:(NSMenu *)menu;
18
- @end
19
-
20
- /* Use this flag to determine whether we use SDLMain.nib or not */
21
- #define SDL_USE_NIB_FILE 0
22
-
23
- /* Use this flag to determine whether we use CPS (docking) or not */
24
- #define SDL_USE_CPS 1
25
- #ifdef SDL_USE_CPS
26
- /* Portions of CPS.h */
27
- typedef struct CPSProcessSerNum
28
- {
29
- UInt32 lo;
30
- UInt32 hi;
31
- } CPSProcessSerNum;
32
-
33
- extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
34
- extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
35
- extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
36
-
37
- #endif /* SDL_USE_CPS */
38
-
39
- static int gArgc;
40
- static char **gArgv;
41
- static BOOL gFinderLaunch;
42
- static BOOL gCalledAppMainline = FALSE;
43
-
44
- static NSString *getApplicationName(void)
45
- {
46
- const NSDictionary *dict;
47
- NSString *appName = 0;
48
-
49
- /* Determine the application name */
50
- dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
51
- if (dict)
52
- appName = [dict objectForKey: @"CFBundleName"];
53
-
54
- if (![appName length])
55
- appName = [[NSProcessInfo processInfo] processName];
56
-
57
- return appName;
58
- }
59
-
60
- #if SDL_USE_NIB_FILE
61
- /* A helper category for NSString */
62
- @interface NSString (ReplaceSubString)
63
- - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
64
- @end
65
- #endif
66
-
67
- @interface NSApplication (SDLApplication)
68
- @end
69
-
70
- @implementation NSApplication (SDLApplication)
71
- /* Invoked from the Quit menu item */
72
- - (void)terminate:(id)sender
73
- {
74
- /* Post a SDL_QUIT event */
75
- SDL_Event event;
76
- event.type = SDL_QUIT;
77
- SDL_PushEvent(&event);
78
- }
79
- @end
80
-
81
- /* The main class of the application, the application's delegate */
82
- @implementation SDLMain
83
-
84
- /* Set the working directory to the .app's parent directory */
85
- - (void) setupWorkingDirectory:(BOOL)shouldChdir
86
- {
87
- if (shouldChdir)
88
- {
89
- char parentdir[MAXPATHLEN];
90
- CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
91
- CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
92
- if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
93
- chdir(parentdir); /* chdir to the binary app's parent */
94
- }
95
- CFRelease(url);
96
- CFRelease(url2);
97
- }
98
- }
99
-
100
- #if SDL_USE_NIB_FILE
101
-
102
- /* Fix menu to contain the real app name instead of "SDL App" */
103
- - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
104
- {
105
- NSRange aRange;
106
- NSEnumerator *enumerator;
107
- NSMenuItem *menuItem;
108
-
109
- aRange = [[aMenu title] rangeOfString:@"SDL App"];
110
- if (aRange.length != 0)
111
- [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
112
-
113
- enumerator = [[aMenu itemArray] objectEnumerator];
114
- while ((menuItem = [enumerator nextObject]))
115
- {
116
- aRange = [[menuItem title] rangeOfString:@"SDL App"];
117
- if (aRange.length != 0)
118
- [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
119
- if ([menuItem hasSubmenu])
120
- [self fixMenu:[menuItem submenu] withAppName:appName];
121
- }
122
- }
123
-
124
- #else
125
-
126
- static void setApplicationMenu(void)
127
- {
128
- /* warning: this code is very odd */
129
- NSMenu *appleMenu;
130
- NSMenuItem *menuItem;
131
- NSString *title;
132
- NSString *appName;
133
-
134
- appName = getApplicationName();
135
- appleMenu = [[NSMenu alloc] initWithTitle:@""];
136
-
137
- /* Add menu items */
138
- title = [@"About " stringByAppendingString:appName];
139
- [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
140
-
141
- [appleMenu addItem:[NSMenuItem separatorItem]];
142
-
143
- title = [@"Hide " stringByAppendingString:appName];
144
- [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
145
-
146
- menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
147
- [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
148
-
149
- [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
150
-
151
- [appleMenu addItem:[NSMenuItem separatorItem]];
152
-
153
- title = [@"Quit " stringByAppendingString:appName];
154
- [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
155
-
156
-
157
- /* Put menu into the menubar */
158
- menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
159
- [menuItem setSubmenu:appleMenu];
160
- [[NSApp mainMenu] addItem:menuItem];
161
-
162
- /* Tell the application object that this is now the application menu */
163
- [NSApp setAppleMenu:appleMenu];
164
-
165
- /* Finally give up our references to the objects */
166
- [appleMenu release];
167
- [menuItem release];
168
- }
169
-
170
- /* Create a window menu */
171
- static void setupWindowMenu(void)
172
- {
173
- NSMenu *windowMenu;
174
- NSMenuItem *windowMenuItem;
175
- NSMenuItem *menuItem;
176
-
177
- windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
178
-
179
- /* "Minimize" item */
180
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
181
- [windowMenu addItem:menuItem];
182
- [menuItem release];
183
-
184
- /* Put menu into the menubar */
185
- windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
186
- [windowMenuItem setSubmenu:windowMenu];
187
- [[NSApp mainMenu] addItem:windowMenuItem];
188
-
189
- /* Tell the application object that this is now the window menu */
190
- [NSApp setWindowsMenu:windowMenu];
191
-
192
- /* Finally give up our references to the objects */
193
- [windowMenu release];
194
- [windowMenuItem release];
195
- }
196
-
197
- /* Replacement for NSApplicationMain */
198
- static void CustomApplicationMain (int argc, char **argv)
199
- {
200
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
201
- SDLMain *sdlMain;
202
-
203
- /* Ensure the application object is initialised */
204
- [NSApplication sharedApplication];
205
-
206
- #ifdef SDL_USE_CPS
207
- {
208
- CPSProcessSerNum PSN;
209
- /* Tell the dock about us */
210
- if (!CPSGetCurrentProcess(&PSN))
211
- if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
212
- if (!CPSSetFrontProcess(&PSN))
213
- [NSApplication sharedApplication];
214
- }
215
- #endif /* SDL_USE_CPS */
216
-
217
- /* Set up the menubar */
218
- [NSApp setMainMenu:[[NSMenu alloc] init]];
219
- setApplicationMenu();
220
- setupWindowMenu();
221
-
222
- /* Create SDLMain and make it the app delegate */
223
- sdlMain = [[SDLMain alloc] init];
224
- [NSApp setDelegate:sdlMain];
225
-
226
- /* Start the main event loop */
227
- [NSApp run];
228
-
229
- [sdlMain release];
230
- [pool release];
231
- }
232
-
233
- #endif
234
-
235
-
236
- /*
237
- * Catch document open requests...this lets us notice files when the app
238
- * was launched by double-clicking a document, or when a document was
239
- * dragged/dropped on the app's icon. You need to have a
240
- * CFBundleDocumentsType section in your Info.plist to get this message,
241
- * apparently.
242
- *
243
- * Files are added to gArgv, so to the app, they'll look like command line
244
- * arguments. Previously, apps launched from the finder had nothing but
245
- * an argv[0].
246
- *
247
- * This message may be received multiple times to open several docs on launch.
248
- *
249
- * This message is ignored once the app's mainline has been called.
250
- */
251
- - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
252
- {
253
- const char *temparg;
254
- size_t arglen;
255
- char *arg;
256
- char **newargv;
257
-
258
- if (!gFinderLaunch) /* MacOS is passing command line args. */
259
- return FALSE;
260
-
261
- if (gCalledAppMainline) /* app has started, ignore this document. */
262
- return FALSE;
263
-
264
- temparg = [filename UTF8String];
265
- arglen = SDL_strlen(temparg) + 1;
266
- arg = (char *) SDL_malloc(arglen);
267
- if (arg == NULL)
268
- return FALSE;
269
-
270
- newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
271
- if (newargv == NULL)
272
- {
273
- SDL_free(arg);
274
- return FALSE;
275
- }
276
- gArgv = newargv;
277
-
278
- SDL_strlcpy(arg, temparg, arglen);
279
- gArgv[gArgc++] = arg;
280
- gArgv[gArgc] = NULL;
281
- return TRUE;
282
- }
283
-
284
-
285
- /* Called when the internal event loop has just started running */
286
- - (void) applicationDidFinishLaunching: (NSNotification *) note
287
- {
288
- int status;
289
-
290
- /* Set the working directory to the .app's parent directory */
291
- [self setupWorkingDirectory:gFinderLaunch];
292
-
293
- #if SDL_USE_NIB_FILE
294
- /* Set the main menu to contain the real app name instead of "SDL App" */
295
- [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
296
- #endif
297
-
298
- /* Hand off to main application code */
299
- gCalledAppMainline = TRUE;
300
- status = SDL_main (gArgc, gArgv);
301
-
302
- /* We're done, thank you for playing */
303
- exit(status);
304
- }
305
- @end
306
-
307
-
308
- @implementation NSString (ReplaceSubString)
309
-
310
- - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
311
- {
312
- unsigned int bufferSize;
313
- unsigned int selfLen = (unsigned int)[self length];
314
- unsigned int aStringLen = (unsigned int)[aString length];
315
- unichar *buffer;
316
- NSRange localRange;
317
- NSString *result;
318
-
319
- bufferSize = selfLen + aStringLen - (unsigned int)aRange.length;
320
- buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
321
-
322
- /* Get first part into buffer */
323
- localRange.location = 0;
324
- localRange.length = aRange.location;
325
- [self getCharacters:buffer range:localRange];
326
-
327
- /* Get middle part into buffer */
328
- localRange.location = 0;
329
- localRange.length = aStringLen;
330
- [aString getCharacters:(buffer+aRange.location) range:localRange];
331
-
332
- /* Get last part into buffer */
333
- localRange.location = aRange.location + aRange.length;
334
- localRange.length = selfLen - localRange.location;
335
- [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
336
-
337
- /* Build output string */
338
- result = [NSString stringWithCharacters:buffer length:bufferSize];
339
-
340
- NSDeallocateMemoryPages(buffer, bufferSize);
341
-
342
- return result;
343
- }
344
-
345
- @end
346
-
347
-
348
-
349
- #ifdef main
350
- # undef main
351
- #endif
352
-
353
-
354
- /* Main entry point to executable - should *not* be SDL_main! */
355
- int main (int argc, char **argv)
356
- {
357
- /* Copy the arguments into a global variable */
358
- /* This is passed if we are launched by double-clicking */
359
- if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
360
- gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
361
- gArgv[0] = argv[0];
362
- gArgv[1] = NULL;
363
- gArgc = 1;
364
- gFinderLaunch = YES;
365
- } else {
366
- int i;
367
- gArgc = argc;
368
- gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
369
- for (i = 0; i <= argc; i++)
370
- gArgv[i] = argv[i];
371
- gFinderLaunch = NO;
372
- }
373
-
374
- #if SDL_USE_NIB_FILE
375
- NSApplicationMain (argc, argv);
376
- #else
377
- CustomApplicationMain (argc, argv);
378
- #endif
379
- return 0;
380
- }
381
-