ruby2d 0.9.4 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/SDL2/SDL.h +4 -1
  3. data/assets/include/SDL2/SDL_assert.h +3 -1
  4. data/assets/include/SDL2/SDL_atomic.h +1 -1
  5. data/assets/include/SDL2/SDL_audio.h +1 -1
  6. data/assets/include/SDL2/SDL_bits.h +1 -1
  7. data/assets/include/SDL2/SDL_blendmode.h +4 -1
  8. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  9. data/assets/include/SDL2/SDL_config.h +1 -1
  10. data/assets/include/SDL2/SDL_config_android.h +7 -3
  11. data/assets/include/SDL2/SDL_config_iphoneos.h +16 -10
  12. data/assets/include/SDL2/SDL_config_macosx.h +40 -14
  13. data/assets/include/SDL2/SDL_config_minimal.h +1 -1
  14. data/assets/include/SDL2/SDL_config_os2.h +26 -8
  15. data/assets/include/SDL2/SDL_config_pandora.h +4 -2
  16. data/assets/include/SDL2/SDL_config_psp.h +2 -1
  17. data/assets/include/SDL2/SDL_config_windows.h +40 -9
  18. data/assets/include/SDL2/SDL_config_winrt.h +5 -2
  19. data/assets/include/SDL2/SDL_config_wiz.h +5 -2
  20. data/assets/include/SDL2/SDL_copying.h +1 -1
  21. data/assets/include/SDL2/SDL_cpuinfo.h +32 -3
  22. data/assets/include/SDL2/SDL_egl.h +4 -1
  23. data/assets/include/SDL2/SDL_endian.h +6 -3
  24. data/assets/include/SDL2/SDL_error.h +38 -2
  25. data/assets/include/SDL2/SDL_events.h +64 -28
  26. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  27. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  28. data/assets/include/SDL2/SDL_gesture.h +1 -1
  29. data/assets/include/SDL2/SDL_haptic.h +10 -1
  30. data/assets/include/SDL2/SDL_hints.h +316 -4
  31. data/assets/include/SDL2/SDL_joystick.h +115 -24
  32. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  33. data/assets/include/SDL2/SDL_keycode.h +11 -9
  34. data/assets/include/SDL2/SDL_loadso.h +1 -1
  35. data/assets/include/SDL2/SDL_locale.h +101 -0
  36. data/assets/include/SDL2/SDL_log.h +3 -3
  37. data/assets/include/SDL2/SDL_main.h +1 -1
  38. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  39. data/assets/include/SDL2/SDL_metal.h +117 -0
  40. data/assets/include/SDL2/SDL_misc.h +75 -0
  41. data/assets/include/SDL2/SDL_mouse.h +1 -1
  42. data/assets/include/SDL2/SDL_mutex.h +1 -1
  43. data/assets/include/SDL2/SDL_name.h +1 -1
  44. data/assets/include/SDL2/SDL_opengl.h +1 -1
  45. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  46. data/assets/include/SDL2/SDL_opengles.h +1 -1
  47. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  48. data/assets/include/SDL2/SDL_pixels.h +25 -16
  49. data/assets/include/SDL2/SDL_platform.h +1 -1
  50. data/assets/include/SDL2/SDL_power.h +1 -1
  51. data/assets/include/SDL2/SDL_quit.h +1 -1
  52. data/assets/include/SDL2/SDL_rect.h +1 -1
  53. data/assets/include/SDL2/SDL_render.h +63 -3
  54. data/assets/include/SDL2/SDL_revision.h +2 -2
  55. data/assets/include/SDL2/SDL_rwops.h +2 -10
  56. data/assets/include/SDL2/SDL_scancode.h +1 -1
  57. data/assets/include/SDL2/SDL_sensor.h +25 -9
  58. data/assets/include/SDL2/SDL_shape.h +1 -1
  59. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  60. data/assets/include/SDL2/SDL_surface.h +11 -2
  61. data/assets/include/SDL2/SDL_system.h +50 -4
  62. data/assets/include/SDL2/SDL_syswm.h +29 -2
  63. data/assets/include/SDL2/SDL_test.h +1 -1
  64. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  65. data/assets/include/SDL2/SDL_test_common.h +14 -1
  66. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  67. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  68. data/assets/include/SDL2/SDL_test_font.h +1 -1
  69. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  70. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  71. data/assets/include/SDL2/SDL_test_images.h +1 -1
  72. data/assets/include/SDL2/SDL_test_log.h +1 -1
  73. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  74. data/assets/include/SDL2/SDL_test_memory.h +1 -1
  75. data/assets/include/SDL2/SDL_test_random.h +1 -1
  76. data/assets/include/SDL2/SDL_thread.h +34 -11
  77. data/assets/include/SDL2/SDL_timer.h +1 -1
  78. data/assets/include/SDL2/SDL_touch.h +1 -1
  79. data/assets/include/SDL2/SDL_types.h +1 -1
  80. data/assets/include/SDL2/SDL_version.h +2 -2
  81. data/assets/include/SDL2/SDL_video.h +11 -5
  82. data/assets/include/SDL2/SDL_vulkan.h +6 -8
  83. data/assets/include/SDL2/begin_code.h +5 -9
  84. data/assets/include/SDL2/close_code.h +1 -1
  85. data/assets/macos/lib/libFLAC.a +0 -0
  86. data/assets/macos/lib/libSDL2.a +0 -0
  87. data/assets/macos/lib/libSDL2_image.a +0 -0
  88. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  89. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  90. data/assets/macos/lib/libfreetype.a +0 -0
  91. data/assets/macos/lib/libjpeg.a +0 -0
  92. data/assets/macos/lib/libmodplug.a +0 -0
  93. data/assets/macos/lib/libmpg123.a +0 -0
  94. data/assets/macos/lib/libogg.a +0 -0
  95. data/assets/macos/lib/libpng16.a +0 -0
  96. data/assets/macos/lib/libtiff.a +0 -0
  97. data/assets/macos/lib/libvorbis.a +0 -0
  98. data/assets/macos/lib/libvorbisfile.a +0 -0
  99. data/assets/macos/lib/libwebp.a +0 -0
  100. data/assets/mingw/bin/SDL2.dll +0 -0
  101. data/assets/mingw/lib/libSDL2.a +0 -0
  102. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  103. data/assets/mingw/lib/libSDL2_test.a +0 -0
  104. data/assets/mingw/lib/libSDL2main.a +0 -0
  105. data/bin/ruby2d +1 -0
  106. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  107. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  108. data/ext/ruby2d/extconf.rb +37 -59
  109. data/ext/ruby2d/font.c +35 -0
  110. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +66 -98
  111. data/ext/ruby2d/gl2.c +86 -0
  112. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +69 -112
  113. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
  114. data/ext/ruby2d/image.c +58 -0
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  116. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  117. data/ext/ruby2d/ruby2d.c +449 -439
  118. data/ext/ruby2d/ruby2d.h +652 -0
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/sound.c +39 -14
  121. data/ext/ruby2d/text.c +22 -0
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +63 -63
  123. data/lib/ruby2d/circle.rb +21 -3
  124. data/lib/ruby2d/cli/build.rb +4 -7
  125. data/lib/ruby2d/dsl.rb +16 -9
  126. data/lib/ruby2d/entity.rb +17 -0
  127. data/lib/ruby2d/font.rb +23 -3
  128. data/lib/ruby2d/image.rb +35 -7
  129. data/lib/ruby2d/line.rb +23 -1
  130. data/lib/ruby2d/music.rb +5 -0
  131. data/lib/ruby2d/pixel.rb +17 -0
  132. data/lib/ruby2d/quad.rb +21 -1
  133. data/lib/ruby2d/rectangle.rb +12 -3
  134. data/lib/ruby2d/renderable.rb +4 -20
  135. data/lib/ruby2d/sound.rb +30 -0
  136. data/lib/ruby2d/sprite.rb +57 -75
  137. data/lib/ruby2d/square.rb +10 -1
  138. data/lib/ruby2d/text.rb +55 -12
  139. data/lib/ruby2d/texture.rb +28 -0
  140. data/lib/ruby2d/tileset.rb +87 -0
  141. data/lib/ruby2d/triangle.rb +19 -1
  142. data/lib/ruby2d/version.rb +1 -1
  143. data/lib/ruby2d/vertices.rb +84 -0
  144. data/lib/ruby2d/window.rb +259 -22
  145. data/lib/ruby2d.rb +6 -1
  146. metadata +30 -26
  147. data/assets/include/simple2d.h +0 -757
  148. data/assets/linux/simple2d/Makefile +0 -260
  149. data/assets/linux/simple2d/bin/simple2d.sh +0 -1318
  150. data/assets/linux/simple2d/include/simple2d.h +0 -757
  151. data/assets/linux/simple2d/src/gl2.c +0 -146
  152. data/assets/linux/simple2d/src/image.c +0 -138
  153. data/assets/linux/simple2d/src/sprite.c +0 -147
  154. data/assets/linux/simple2d/src/text.c +0 -129
  155. data/assets/macos/lib/libsimple2d.a +0 -0
  156. data/assets/mingw/lib/libsimple2d.a +0 -0
@@ -1,1318 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # ------------------------------------------------------------------------------
4
- # The Simple 2D Command-Line Utility for Unix-like Systems
5
- #
6
- # Run from the web using:
7
- # bash <(curl -fsSL https://script_url_here)
8
- # or...
9
- # bash <(wget -qO - https://script_url_here)
10
- # ------------------------------------------------------------------------------
11
-
12
- # Set Constants ################################################################
13
-
14
- # The installed version
15
- VERSION='1.2.0'
16
-
17
- # URL to this script in the repo
18
- SCRIPT_URL="https://raw.githubusercontent.com/simple2d/simple2d/master/bin/simple2d.sh"
19
-
20
- # MinGW Simple 2D installer
21
- s2d_mingw_installer_fname="simple2d-windows-mingw-${VERSION}.zip"
22
- s2d_mingw_installer_url="https://github.com/simple2d/simple2d/releases/download/v${VERSION}/${s2d_mingw_installer_fname}"
23
-
24
- # SDL minimum version
25
- SDL_MIN_VERSION='2.0.4'
26
-
27
- # SDL download paths
28
- libsdl_url="https://www.libsdl.org"
29
-
30
- sdl_fname="SDL2-2.0.10"
31
- sdl_url="${libsdl_url}/release/${sdl_fname}.tar.gz"
32
-
33
- image_fname="SDL2_image-2.0.5"
34
- image_url="${libsdl_url}/projects/SDL_image/release/${image_fname}.tar.gz"
35
-
36
- mixer_fname="SDL2_mixer-2.0.4"
37
- mixer_url="${libsdl_url}/projects/SDL_mixer/release/${mixer_fname}.tar.gz"
38
-
39
- ttf_fname="SDL2_ttf-2.0.15"
40
- ttf_url="${libsdl_url}/projects/SDL_ttf/release/${ttf_fname}.tar.gz"
41
-
42
- # SDL config
43
- sdl_arm_config_flags="\
44
- --disable-video-opengl --disable-video-x11 \
45
- --disable-pulseaudio --disable-esd \
46
- --disable-video-mir --disable-video-wayland"
47
-
48
- # Colors
49
- BOLD='\033[1;39m' # default, bold
50
- UNDERLINE='\033[4m' # underline
51
- TASK='\033[1;34m' # blue, bold
52
- BLUE=$TASK
53
- INFO='\033[1;36m' # cyan, underline
54
- WARN='\033[1;33m' # yellow, underline
55
- ERROR='\033[1;31m' # red, underline
56
- SUCCESS='\033[1;32m' # green, bold
57
- NORMAL='\033[0m' # reset
58
-
59
- # Set Variables ################################################################
60
-
61
- platform='unknown'
62
- platform_display='unknown'
63
- platform_rpi=false
64
- ret='' # for storing function return values
65
- confirmed=false # to skip confirmation prompts
66
-
67
- # Use xcpretty for nicer output: gem install xcpretty
68
- if xcpretty -v &>/dev/null; then
69
- XCPRETTY=xcpretty
70
- else
71
- XCPRETTY=cat
72
- fi
73
-
74
- # Helper Functions #############################################################
75
-
76
-
77
- # Prints an information messages
78
- # params:
79
- # $1 String Message text
80
- info_msg() {
81
- echo -e "${INFO}Info:${NORMAL} $1\n"
82
- }
83
- warning_msg() {
84
- echo -e "${WARN}Warning:${NORMAL} $1\n"
85
- }
86
- error_msg() {
87
- echo -e "${ERROR}Error:${NORMAL} $1\n"
88
- }
89
- success_msg() {
90
- echo -e "${SUCCESS}$1${NORMAL}\n"
91
- }
92
-
93
-
94
- # Prompts to continue, or exits
95
- # params:
96
- # $1 String Message before y/n prompt
97
- prompt_to_continue() {
98
- if ! $confirmed; then
99
- printf "${BOLD}$1${NORMAL} "
100
- read -p "(y/n) " ans
101
- if [[ $ans != "y" ]]; then
102
- echo -e "\nQuitting...\n"
103
- exit
104
- fi
105
- echo
106
- fi
107
- }
108
-
109
-
110
- # Prints the task in progress
111
- # params:
112
- # $1 String Name of task
113
- # $2 String Optional white space, e.g. "\n\n"
114
- print_task() {
115
- printf "${TASK}==>${BOLD} $1${NORMAL}$2"
116
- }
117
-
118
-
119
- # Prints and runs a command
120
- # params:
121
- # $1 String The command
122
- print_and_run() {
123
- echo "==> $1"; $1
124
- }
125
-
126
-
127
- # Checks if a library is installed
128
- # params:
129
- # $1 String Name of the library, e.g. SDL2, without the "-l"
130
- have_lib?() {
131
- print_task "Checking for $1... "
132
-
133
- if $(ld -o /dev/null -l$1 2>&1 | grep -qE '(library not found|ld: cannot find -l)'); then
134
- echo "no"
135
- return 1
136
- else
137
- echo "yes"
138
- return 0
139
- fi
140
- }
141
-
142
-
143
- # Gets the text from a remote resource
144
- # params:
145
- # $1 String URL of the resource
146
- get_remote_str() {
147
- which curl &>/dev/null && cmd='curl -fsSL' || cmd='wget -qO -';
148
- ret=$($cmd $1)
149
- }
150
-
151
-
152
- # Compares version numbers in the form `#.#.#`
153
- # Adapted from:
154
- # stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format
155
- # params:
156
- # $1 String First version number to compare
157
- # $2 String Second version number to compare
158
- # returns:
159
- # 0 If $1 is equal to $2
160
- # 1 If $1 is newer than $2
161
- # 2 If $1 is older than $2
162
- compare_versions() {
163
- if [[ $1 == $2 ]]
164
- then
165
- return 0
166
- fi
167
- local IFS=.
168
- local i ver1=($1) ver2=($2)
169
- # fill empty fields in ver1 with zeros
170
- for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
171
- do
172
- ver1[i]=0
173
- done
174
- for ((i=0; i<${#ver1[@]}; i++))
175
- do
176
- if [[ -z ${ver2[i]} ]]
177
- then
178
- # fill empty fields in ver2 with zeros
179
- ver2[i]=0
180
- fi
181
- if ((10#${ver1[i]} > 10#${ver2[i]}))
182
- then
183
- return 1
184
- fi
185
- if ((10#${ver1[i]} < 10#${ver2[i]}))
186
- then
187
- return 2
188
- fi
189
- done
190
- return 0
191
- }
192
-
193
-
194
- # Build #######################################################################
195
-
196
-
197
- # Builds a Simple 2D program
198
- # If directory contains an Xcode project, it will call `xcodebuild`.
199
- # If $1 is a C or C++ source file, it will attempt to compile using `gcc`.
200
- build() {
201
-
202
- # If no input, print build usage
203
- if [[ $1 == '' ]]; then print_usage_build; exit; fi
204
-
205
- # If C source file given, e.g.: build app.c
206
- if [[ ${1: -2} == '.c' ]]; then
207
- # Compile
208
- gcc -std=c11 $1 `simple2d --libs` -o ${1%.*}
209
- exit
210
- fi
211
-
212
- # If C++ source file given, e.g.: build app.cpp
213
- if [[ ${1: -4} == '.cpp' ]]; then
214
- # Compile
215
- g++ -std=c++11 $1 `simple2d --libs` -o ${1%.*}
216
- exit
217
- fi
218
-
219
- # Check if current directory has an Xcode project
220
- has_xcodeproj?() {
221
- if [[ $(ls *.xcodeproj 2>/dev/null) ]]; then
222
- return 0
223
- else
224
- return 1
225
- fi
226
- }
227
-
228
- # Build an Xcode project
229
- build_with_xcodebuild() {
230
- if [[ $XCPRETTY != 'xcpretty' ]]; then
231
- echo -e "xcpretty not found: Run \`gem install xcpretty\` for nicer xcodebuild output.\n"
232
- fi
233
- case $1 in
234
- --ios)
235
- xcodebuild -sdk iphonesimulator | $XCPRETTY; exit;;
236
- --ios-device)
237
- xcodebuild -sdk iphoneos | $XCPRETTY; exit;;
238
- --tvos)
239
- xcodebuild -sdk appletvsimulator | $XCPRETTY; exit;;
240
- --tvos-device)
241
- xcodebuild -sdk appletvos | $XCPRETTY; exit;;
242
- esac
243
- }
244
-
245
- # If bad SDK flag, print build usage
246
- if ! [[ $1 =~ ^(--ios|--ios-device|--tvos|--tvos-device)$ ]]; then
247
- print_usage_build; exit 1
248
- fi
249
-
250
- # If current directory has an Xcode project, e.g.:
251
- # build --[ios|tvos][-device]
252
- if has_xcodeproj?; then
253
- build_with_xcodebuild $1
254
- fi
255
-
256
- # If an Xcode project path and options are provided, e.g.:
257
- # build --ios[-device] build/ios
258
- # build --tvos[-device] build/tvos
259
- # build --ios[-device] build/ios/MyApp.xcodeproj
260
- # build --tvos[-device] build/tvos/MyApp.xcodeproj
261
- if [[ ${2: -10} == '.xcodeproj' ]]; then
262
- cd $(dirname $2)
263
- elif [[ -d $2 ]]; then
264
- cd $2
265
- else
266
- error_msg "\"$2\" is not a directory or Xcode project"; exit 1
267
- fi
268
-
269
- if ! has_xcodeproj?; then
270
- error_msg "The directory does not contain an Xcode project"; exit 1
271
- fi
272
-
273
- build_with_xcodebuild $1
274
- }
275
-
276
-
277
- # Installation #################################################################
278
-
279
-
280
- # Checks installed versions of SDL
281
- check_sdl_versions() {
282
-
283
- print_task "Checking SDL2 version... "
284
-
285
- # Check SDL version installed
286
- SDL_INSTALLED_VERSION=$(sdl2-config --version)
287
- compare_versions $SDL_MIN_VERSION $SDL_INSTALLED_VERSION
288
-
289
- if [[ $? == 1 ]]; then
290
- echo $SDL_INSTALLED_VERSION
291
- error_msg "Installed version of SDL2 is too old (must be at least $SDL_MIN_VERSION)"
292
- return 1
293
- else
294
- echo "$SDL_INSTALLED_VERSION"
295
- return 0
296
- fi
297
- }
298
-
299
-
300
- # Checks if SDL libraries are installed
301
- have_sdl_libs?() {
302
-
303
- have_all_libs=true
304
- have_sdl2_lib=true
305
- have_image_lib=true
306
- have_mixer_lib=true
307
- have_ttf_lib=true
308
-
309
- if ! have_lib? 'SDL2'; then
310
- have_sdl2_lib=false
311
- have_all_libs=false
312
- else
313
- if ! check_sdl_versions; then
314
- have_sdl2_lib=false
315
- have_all_libs=false
316
- fi
317
- fi
318
-
319
- if ! have_lib? 'SDL2_image'; then
320
- have_image_lib=false
321
- have_all_libs=false
322
- fi
323
-
324
- if ! have_lib? 'SDL2_mixer'; then
325
- have_mixer_lib=false
326
- have_all_libs=false
327
- fi
328
-
329
- if ! have_lib? 'SDL2_ttf'; then
330
- have_ttf_lib=false
331
- have_all_libs=false
332
- fi
333
-
334
- if $have_all_libs; then
335
- return 0
336
- else
337
- return 1
338
- fi
339
- }
340
-
341
-
342
- # Installs SDL on BSD
343
- install_sdl_bsd() {
344
-
345
- echo "The following packages will be installed:"
346
- echo " sdl2"
347
- echo " sdl2_image"
348
- echo " sdl2_mixer"
349
- echo " sdl2_ttf"
350
-
351
- prompt_to_continue "Install SDL now?"
352
-
353
- print_task "Updating packages" "\n\n"
354
- print_and_run "sudo pkg update"
355
-
356
- echo; print_task "Installing packages" "\n\n"
357
- print_and_run "sudo pkg install sdl2 sdl2_image sdl2_mixer sdl2_ttf"
358
- echo
359
-
360
- if ! have_sdl_libs?; then
361
- echo; error_msg "SDL libraries did not install correctly"; exit 1
362
- else
363
- echo; info_msg "SDL was installed successfully"
364
- fi
365
- }
366
-
367
-
368
- # Installs SDL on Linux
369
- install_sdl_linux() {
370
-
371
- echo "The following packages will be installed:"
372
- # Fedora and CentOS
373
- if which yum &>/dev/null; then
374
- echo " SDL2-devel"
375
- echo " SDL2_image-devel"
376
- echo " SDL2_mixer-devel"
377
- echo " SDL2_ttf-devel"
378
- # Arch
379
- elif which pacman &>/dev/null; then
380
- echo " sdl2"
381
- echo " sdl2_image"
382
- echo " sdl2_mixer"
383
- echo " sdl2_ttf"
384
- # openSUSE
385
- elif which zypper &>/dev/null; then
386
- echo " libSDL2-devel"
387
- echo " libSDL2_image-devel"
388
- echo " libSDL2_mixer-devel"
389
- echo " libSDL2_ttf-devel"
390
- # Ubuntu, Debian, and Mint
391
- # `apt` must be last because openSUSE has it aliased to `zypper`
392
- elif which apt &>/dev/null; then
393
- echo " libsdl2-dev"
394
- echo " libsdl2-image-dev"
395
- echo " libsdl2-mixer-dev"
396
- echo " libsdl2-ttf-dev"
397
- else
398
- error_msg "Could not find a package manager to install SDL"; exit 1
399
- fi
400
- echo
401
-
402
- prompt_to_continue "Install SDL now?"
403
-
404
- print_task "Updating packages" "\n\n"
405
-
406
- if which yum &>/dev/null; then
407
- print_and_run "yum check-update"
408
- elif which pacman &>/dev/null; then
409
- print_and_run "sudo pacman -Syy"
410
- elif which zypper &>/dev/null; then
411
- print_and_run "sudo zypper refresh"
412
- elif which apt &>/dev/null; then
413
- print_and_run "sudo apt update"
414
- fi
415
-
416
- echo; print_task "Installing packages" "\n\n"
417
-
418
- if which yum &>/dev/null; then
419
- print_and_run "sudo yum install -y SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel"
420
- elif which pacman &>/dev/null; then
421
- print_and_run "sudo pacman -S --noconfirm sdl2 sdl2_image sdl2_mixer sdl2_ttf"
422
- elif which zypper &>/dev/null; then
423
- print_and_run "sudo zypper install -y libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel"
424
- elif which apt &>/dev/null; then
425
- print_and_run "sudo apt install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
426
- fi
427
- echo
428
-
429
- if ! have_sdl_libs?; then
430
- echo; error_msg "SDL libraries did not install correctly"; exit 1
431
- else
432
- echo; info_msg "SDL was installed successfully"
433
- fi
434
- }
435
-
436
-
437
- # Installs SDL from source
438
- # Takes about 30 min on RPI 2
439
- install_sdl_source() {
440
-
441
- echo "SDL will be compiled and installed from source."; echo
442
-
443
- prompt_to_continue "Install SDL now?"
444
-
445
- # Install SDL dependencies
446
- print_task "Installing SDL2 dependencies" "\n\n"
447
- sudo apt update
448
-
449
- libs=(
450
- build-essential # This may be missing on some ARM platforms
451
-
452
- # SDL2
453
- libudev-dev
454
- libdbus-1-dev
455
- libasound2-dev
456
-
457
- # SDL2_image
458
- libjpeg9-dev
459
- libpng-dev
460
-
461
- # SDL2_mixer
462
- libmpg123-dev
463
- libvorbis-dev
464
- libflac-dev
465
-
466
- # SDL2_ttf
467
- libgl1-mesa-dev # Solves error missing -lGL
468
- libfreetype6-dev
469
- )
470
-
471
- sudo apt install -y ${libs[*]}
472
-
473
- # Downloads, compiles, and installs an SDL library from source
474
- # params:
475
- # $1 String URL of the tar archive
476
- # $2 String Name of the tar file
477
- # $3 String ./configure flags
478
- install_sdl_lib () {
479
- cd /tmp
480
- wget -N $1
481
- tar -xzf $2.tar.gz
482
- cd $2
483
- print_task "Configuring" "\n\n"
484
- print_and_run "./configure $3"
485
- echo; print_task "Compiling" "\n\n"
486
- make
487
- echo; print_task "Installing" "\n\n"
488
- sudo make install
489
- rm /tmp/$2.tar.gz
490
- rm -rf /tmp/$2
491
- }
492
-
493
- # Note that `$have_*_lib` variables are set by `have_sdl_libs?()`
494
-
495
- if [[ $have_sdl2_lib == 'false' ]]; then
496
- echo; print_task "Downloading SDL2" "\n\n"
497
- if [[ $platform == 'arm' ]]; then
498
- if $platform_rpi; then
499
- config="--host=arm-raspberry-linux-gnueabihf $sdl_arm_config_flags"
500
- else
501
- config=$sdl_arm_config_flags
502
- fi
503
- install_sdl_lib $sdl_url $sdl_fname "$config"
504
- else
505
- install_sdl_lib $sdl_url $sdl_fname
506
- fi
507
- fi
508
-
509
- if [[ $have_image_lib == 'false' ]]; then
510
- echo; print_task "Downloading SDL2_image" "\n\n"
511
- install_sdl_lib $image_url $image_fname
512
- fi
513
-
514
- if [[ $have_mixer_lib == 'false' ]]; then
515
- echo; print_task "Downloading SDL2_mixer" "\n\n"
516
- install_sdl_lib $mixer_url $mixer_fname
517
- fi
518
-
519
- if [[ $have_ttf_lib == 'false' ]]; then
520
- echo; print_task "Downloading SDL2_ttf" "\n\n"
521
- install_sdl_lib $ttf_url $ttf_fname
522
- fi
523
-
524
- echo
525
- if ! have_sdl_libs?; then
526
- error_msg "SDL libraries did not install correctly"; exit 1
527
- else
528
- echo; info_msg "SDL was installed successfully"
529
- fi
530
- }
531
-
532
-
533
- # Installs SDL
534
- install_sdl() {
535
- if [[ $platform == 'linux' ]]; then
536
- install_sdl_linux
537
- elif [[ $platform == 'bsd' ]]; then
538
- install_sdl_bsd
539
- elif [[ $platform == 'arm' ]]; then
540
- install_sdl_source
541
- fi
542
- }
543
-
544
-
545
- # Installs Simple 2D for MinGW environments
546
- install_s2d_mingw() {
547
- tmp_dir="/tmp/simple2d"
548
- mkdir -p $tmp_dir
549
- print_and_run "wget -NP $tmp_dir $s2d_mingw_installer_url"
550
- print_and_run "pacman -S unzip --needed --noconfirm"
551
- print_and_run "unzip -q $tmp_dir/$s2d_mingw_installer_fname -d $tmp_dir"
552
- print_and_run "cd $tmp_dir"
553
- print_and_run "bash install.sh -y"
554
- print_and_run "rm -rf $tmp_dir"
555
- }
556
-
557
-
558
- # Installs Simple 2D
559
- # params:
560
- # $1 String Version to install, either 'master' or $VERSION
561
- install_s2d() {
562
-
563
- tmp_dir="/tmp/simple2d"
564
-
565
- mkdir $tmp_dir
566
-
567
- if [[ $1 == 'master' ]]; then
568
- f_name=$1
569
- else
570
- f_name="v$1"
571
- fi
572
-
573
- url="https://github.com/simple2d/simple2d/archive/$f_name.zip"
574
-
575
- print_task "Downloading Simple 2D" "\n\n"
576
- # Linux and Raspberry Pi may not have curl installed by default
577
- if which curl &>/dev/null; then
578
- print_and_run "curl -L $url -o $tmp_dir/$f_name.zip"
579
- else
580
- print_and_run "wget -NP $tmp_dir $url"
581
- fi
582
-
583
- # Check if archive was downloaded properly
584
- if [[ ! -f "$tmp_dir/$f_name.zip" ]]; then
585
- echo; error_msg "Simple 2D could not be downloaded"; exit 1
586
- fi
587
-
588
- echo; print_task "Unpacking" "\n\n"
589
- print_and_run "unzip -q $tmp_dir/$f_name.zip -d $tmp_dir"
590
-
591
- # Check if archive was unpacked properly
592
- if [[ $? != 0 ]]; then
593
- echo; error_msg "Could not unpack. The downloaded Simple 2D package may be damaged."; exit 1
594
- fi
595
-
596
- print_and_run "cd $tmp_dir/simple2d-$1"
597
-
598
- if [[ $platform == 'bsd' ]]; then
599
- echo; print_and_run "gmake"
600
- echo; print_and_run "sudo gmake install"
601
- else
602
- echo; print_and_run "make"
603
- echo; print_and_run "sudo make install"
604
- fi
605
-
606
- echo; print_task "Cleaning up" "\n"; echo
607
- print_and_run "rm -rf $tmp_dir"; echo
608
-
609
- # Check if S2D installed correctly
610
- if ! have_lib? 'simple2d'; then
611
- echo; error_msg "Simple 2D did not install correctly"; exit 1
612
- fi
613
- echo
614
- }
615
-
616
-
617
- # Main entry point to install Simple 2D and SDL
618
- # params:
619
- # $1 String Flags used, e.g. `--sdl`
620
- install() {
621
-
622
- # If macOS, print message and quit
623
- if [[ $platform == 'macos' ]]; then
624
- macos_homebrew_message $1
625
- fi
626
-
627
- # If SDL flag, install only SDL and quit
628
- if [[ $1 == '--sdl' ]]; then
629
- echo
630
- if have_sdl_libs?; then
631
- echo; info_msg "SDL is already installed"
632
- else
633
- echo; install_sdl
634
- fi
635
- exit
636
- fi
637
-
638
- # Welcome message
639
- echo -e "\n${BOLD}Welcome to Simple 2D!${NORMAL}"
640
- echo -e "${BLUE}---------------------${NORMAL}\n"
641
-
642
- echo -e "Platform detected: ${BOLD}${platform_display}${NORMAL}\n"
643
-
644
- # If MinGW, install Simple 2D release and quit
645
- if [[ $platform == 'mingw' ]]; then
646
- prompt_to_continue "Continue to install?"
647
- install_s2d_mingw
648
- exit
649
- fi
650
-
651
- if have_lib? 'simple2d' > /dev/null; then
652
- warning_msg "Simple 2D is already installed. Proceeding will reinstall."
653
- fi
654
-
655
- echo -e "Simple 2D will be installed to the following locations:
656
- /usr/local/include/simple2d.h
657
- /usr/local/lib/libsimple2d.a
658
- /usr/local/bin/simple2d"
659
- echo
660
-
661
- if [[ $1 == '--HEAD' ]]; then
662
- echo -e "This will install Simple 2D from the \`master\` development branch.\n"
663
- fi
664
-
665
- prompt_to_continue "Continue?"
666
-
667
- if have_sdl_libs?; then
668
- echo
669
- else
670
- echo; install_sdl
671
- fi
672
-
673
- if [[ $1 == '--HEAD' ]]; then
674
- install_s2d 'master'
675
- else
676
- install_s2d $VERSION
677
- fi
678
-
679
- success_msg "Simple 2D installed successfully!"
680
- }
681
-
682
-
683
- # Uninstall ####################################################################
684
-
685
-
686
- # Uninstalls SDL on BSD
687
- uninstall_sdl_bsd() {
688
-
689
- echo "The following packages will be removed:"
690
- echo " sdl2"
691
- echo " sdl2_image"
692
- echo " sdl2_mixer"
693
- echo " sdl2_ttf"
694
-
695
- prompt_to_continue "Uninstall SDL now?"
696
-
697
- echo; print_task "Uninstalling packages" "\n\n"
698
- print_and_run "sudo pkg remove sdl2 sdl2_image sdl2_mixer sdl2_ttf"
699
- echo
700
-
701
- if have_sdl_libs?; then
702
- echo; error_msg "SDL libraries did not uninstall correctly"
703
- else
704
- echo; info_msg "SDL was uninstalled successfully"
705
- fi
706
- }
707
-
708
-
709
- # Uninstalls SDL on Linux
710
- uninstall_sdl_linux() {
711
-
712
- echo "The following packages will be removed:"
713
- # Fedora and CentOS
714
- if which yum &>/dev/null; then
715
- echo " SDL2-devel"
716
- echo " SDL2_image-devel"
717
- echo " SDL2_mixer-devel"
718
- echo " SDL2_ttf-devel"
719
- # Arch
720
- elif which pacman &>/dev/null; then
721
- echo " sdl2"
722
- echo " sdl2_image"
723
- echo " sdl2_mixer"
724
- echo " sdl2_ttf"
725
- # openSUSE
726
- elif which zypper &>/dev/null; then
727
- echo " libSDL2-devel"
728
- echo " libSDL2_image-devel"
729
- echo " libSDL2_mixer-devel"
730
- echo " libSDL2_ttf-devel"
731
- # Ubuntu, Debian, and Mint
732
- # `apt` must be last because openSUSE has it aliased to `zypper`
733
- elif which apt &>/dev/null; then
734
- echo " libsdl2-dev"
735
- echo " libsdl2-image-dev"
736
- echo " libsdl2-mixer-dev"
737
- echo " libsdl2-ttf-dev"
738
- else
739
- error_msg "Could not find a package manager to uninstall SDL"; exit 1
740
- fi
741
- echo
742
-
743
- prompt_to_continue "Uninstall SDL now?"
744
-
745
- print_task "Uninstalling packages" "\n\n"
746
-
747
- if which yum &>/dev/null; then
748
- print_and_run "sudo yum remove -y SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel"
749
- elif which pacman &>/dev/null; then
750
- print_and_run "sudo pacman -Rs --noconfirm sdl2 sdl2_image sdl2_mixer sdl2_ttf"
751
- elif which zypper &>/dev/null; then
752
- print_and_run "sudo zypper remove -y libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel"
753
- elif which apt &>/dev/null; then
754
- print_and_run "sudo apt remove -y --purge libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
755
- fi
756
- echo
757
-
758
- if have_sdl_libs?; then
759
- echo; error_msg "SDL libraries did not uninstall correctly"
760
- else
761
- echo; info_msg "SDL was uninstalled successfully"
762
- fi
763
- }
764
-
765
-
766
- # Uninstalls SDL from source
767
- uninstall_sdl_source() {
768
-
769
- prompt_to_continue "Uninstall SDL now?"
770
-
771
- # Uninstall packages in case they were used
772
- print_and_run "sudo apt remove -y --purge libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev"
773
-
774
- uninstall_sdl_lib () {
775
- cd /tmp
776
- wget -N $1
777
- tar -xzf $2.tar.gz
778
- cd $2
779
- ./configure $3
780
- sudo make uninstall
781
- rm /tmp/$2.tar.gz
782
- rm -rf /tmp/$2
783
- }
784
-
785
- echo; print_task "Uninstalling SDL2_image" "\n\n"
786
- uninstall_sdl_lib $image_url $image_fname
787
-
788
- echo; print_task "Uninstalling SDL2_mixer" "\n\n"
789
- uninstall_sdl_lib $mixer_url $mixer_fname
790
-
791
- echo; print_task "Uninstalling SDL2_ttf" "\n\n"
792
- uninstall_sdl_lib $ttf_url $ttf_fname
793
-
794
- echo; print_task "Uninstalling SDL2" "\n\n"
795
- if [[ $platform == 'arm' ]]; then
796
- uninstall_sdl_lib $sdl_url $sdl_fname "$sdl_arm_config_flags"
797
- else
798
- uninstall_sdl_lib $sdl_url $sdl_fname
799
- fi
800
-
801
- echo
802
- if have_sdl_libs?; then
803
- echo; error_msg "SDL libraries did not uninstall correctly"; exit 1
804
- else
805
- echo; info_msg "SDL was uninstalled successfully"
806
- fi
807
- }
808
-
809
-
810
- # Uninstalls SDL
811
- uninstall_sdl() {
812
-
813
- if have_sdl_libs?; then
814
- echo
815
- else
816
- echo; info_msg "SDL appears to be already uninstalled"
817
- prompt_to_continue "Try uninstalling SDL anyways?"
818
- fi
819
-
820
- if [[ $platform == 'linux' ]]; then
821
- uninstall_sdl_linux
822
- elif [[ $platform == 'bsd' ]]; then
823
- uninstall_sdl_bsd
824
- elif [[ $platform == 'arm' ]]; then
825
- uninstall_sdl_source
826
- fi
827
- }
828
-
829
-
830
- # Uninstalls Simple 2D
831
- # params:
832
- # $1 String Flags used, e.g. `--sdl`
833
- uninstall() {
834
-
835
- if [[ $platform == 'macos' ]]; then
836
- macos_homebrew_message $1
837
- fi
838
-
839
- # If MinGW, print message and quit
840
- if [[ $platform == 'mingw' ]]; then
841
- mingw_not_implemented_message
842
- fi
843
-
844
- if [[ $1 == '--sdl' ]]; then
845
- echo; uninstall_sdl
846
- exit
847
- fi
848
-
849
- echo; echo -e "The following files will be removed:
850
- /usr/local/include/simple2d.h
851
- /usr/local/lib/libsimple2d.a
852
- /usr/local/bin/simple2d"
853
-
854
- echo; prompt_to_continue "Uninstall Simple 2D?"
855
-
856
- # Use hard-coded, absolute paths for safety
857
- print_and_run "rm -f /usr/local/include/simple2d.h"
858
- print_and_run "rm -f /usr/local/lib/libsimple2d.a"
859
- print_and_run "rm -f /usr/local/bin/simple2d"
860
-
861
- # Check if files were actually deleted
862
- files=(/usr/local/include/simple2d.h
863
- /usr/local/lib/libsimple2d.a
864
- /usr/local/bin/simple2d)
865
-
866
- if [ -f ${files[0]} -o -f ${files[1]} -o -f ${files[2]} ]; then
867
- echo; error_msg "Simple 2D files could not be removed. Try using \`sudo\`?"
868
- else
869
- echo; success_msg "Simple 2D uninstalled!"
870
- fi
871
- }
872
-
873
-
874
- # Update #######################################################################
875
-
876
-
877
- # Updates Simple 2D to latest version or commit
878
- # params:
879
- # $1 String Flags used, e.g. `--HEAD`
880
- update() {
881
-
882
- if [[ $platform == 'macos' ]]; then
883
- macos_homebrew_message
884
- fi
885
-
886
- # If MinGW, print message and quit
887
- if [[ $platform == 'mingw' ]]; then
888
- mingw_not_implemented_message
889
- fi
890
-
891
- # Check if Simple 2D is installed
892
- if ! have_lib? 'simple2d' > /dev/null; then
893
- error_msg "Simple 2D isn't currently installed"
894
- echo -e "Use the \`install\` command to install Simple 2D.\n"
895
- exit 1
896
- fi
897
-
898
- # Check if SDL is installed
899
- update_check_sdl() {
900
- if have_sdl_libs?; then
901
- echo
902
- else
903
- echo; error_msg "SDL libraries missing"
904
- echo -e "Run \`simple2d install --sdl\` to install SDL.\n"
905
- exit 1
906
- fi
907
- }
908
-
909
- # Read this script from repo, get the version number
910
- get_remote_str $SCRIPT_URL
911
- LATEST_VERSION=$(bash -c "$ret" -- -v)
912
-
913
- compare_versions $LATEST_VERSION $VERSION
914
-
915
- # $LATEST_VERSION is newer $VERSION (the version installed)
916
- if [[ $? == 1 ]]; then
917
- echo -e "A new version of Simple 2D is available.\n"
918
- prompt_to_continue "Upgrade from v$VERSION to v$LATEST_VERSION?"
919
- update_check_sdl
920
- install_s2d $LATEST_VERSION
921
- success_msg "Simple 2D has been updated to $LATEST_VERSION!"
922
- echo -e "View the release notes:
923
- ${UNDERLINE}https://github.com/simple2d/simple2d/releases/latest${NORMAL}"; echo
924
-
925
- # $LATEST_VERSION is the same as installed version
926
- else
927
- echo "Simple 2D is already up to date!"
928
- fi
929
- }
930
-
931
-
932
- # Doctor #######################################################################
933
-
934
-
935
- # Runs the diagnostics
936
- doctor() {
937
-
938
- echo; echo -e "Running diagnostics...\n"
939
-
940
- errors=false
941
-
942
- if ! have_sdl_libs?; then
943
- errors=true
944
- echo; error_msg "SDL libraries missing"
945
- fi
946
-
947
- if have_lib? 'simple2d'; then
948
- echo
949
- else
950
- errors=true
951
- echo; error_msg "Simple 2D library missing"
952
- fi
953
-
954
- if $errors; then
955
- echo -e "Issues were found.\n"
956
- else
957
- success_msg "No issues found!"
958
- fi
959
- }
960
-
961
-
962
- # Simulator ####################################################################
963
-
964
-
965
- # Get list of booted iOS or tvOS simulators, store in $booted
966
- # $1 Equals 'cmd' if called from command line
967
- simulator_booted() {
968
- booted=`xcrun simctl list devices | grep Booted`
969
- if [[ $1 == 'cmd' ]]; then
970
- if [[ $booted == '' ]]; then
971
- echo "No devices are booted."
972
- else
973
- echo $booted
974
- fi
975
- fi
976
- }
977
-
978
-
979
- # List all iOS and tvOS simulator devices available
980
- simulator_list() {
981
- xcrun simctl list devices | grep -iv unavailable
982
- }
983
-
984
-
985
- # Open an iOS or tvOS simulator
986
- # $1 The device name, e.g. iPhone X
987
- # See `simulator_list` function for available names
988
- simulator_open() {
989
- device=$1
990
-
991
- # Check if device name exists
992
- if ! xcrun simctl list devices | grep -q "$device"; then
993
- error_msg "\"$device\" does not match any simulator device names"
994
- echo -e "Choose a device name from the following:\n"
995
- simulator_list
996
- exit 1
997
- fi
998
-
999
- # Get the device UDID
1000
- device_udid=`xcrun simctl list devices | grep "$device" | head -n1 | egrep -wo '\([-0-9A-F]+\)' | tr -d '\(\)'`
1001
- echo "Requested device: $device with UDID $device_udid"
1002
- simulator_booted
1003
-
1004
- # If the current simulator running is not the requested device, then quit
1005
- if [[ $booted != '' && $booted != *$device* ]]; then
1006
- echo "Quitting current device simulator..."
1007
- osascript -e 'quit app "Simulator"'
1008
- fi
1009
-
1010
- # Open the requsted simulator
1011
- echo "Opening $device simulator..."
1012
- open -a Simulator --args -CurrentDeviceUDID $device_udid
1013
-
1014
- # Wait for device to boot
1015
- not_booted=true
1016
- while $not_booted; do
1017
- simulator_booted
1018
- if [[ $booted == *$device* ]]; then
1019
- not_booted=false
1020
- else
1021
- sleep 2
1022
- fi
1023
- done
1024
- }
1025
-
1026
-
1027
- # Install an app on the booted iOS or tvOS simulator
1028
- # $1 The path to the `.app` file, e.g. Release-iphonesimulator/MyApp.app
1029
- simulator_install() {
1030
- echo "Installing app..."
1031
- xcrun simctl install booted $1
1032
- }
1033
-
1034
-
1035
- # Launch an installed app on the booted iOS or tvOS simulator
1036
- # $1 The bundle identifier, e.g. "Simple2D.MyApp"
1037
- simulator_launch() {
1038
- echo "Launching app..."
1039
- xcrun simctl launch booted $1
1040
- }
1041
-
1042
-
1043
- # Stream log of currently running iOS or tvOS simulator
1044
- # $1 Optional app name to filter by
1045
- simulator_log() {
1046
- if [[ $1 == '' ]]; then
1047
- xcrun simctl spawn booted log stream --level=debug
1048
- else
1049
- xcrun simctl spawn booted log stream --predicate "processImagePath endswith \"$1\""
1050
- fi
1051
- }
1052
-
1053
-
1054
- # Stream log of currently running iOS or tvOS simulator, error messages only
1055
- simulator_log_errors() {
1056
- xcrun simctl spawn booted log stream --predicate 'eventMessage contains "error" or messageType == error'
1057
- }
1058
-
1059
-
1060
- # Platform Specifics ###########################################################
1061
-
1062
-
1063
- # Prints homebrew message and quit
1064
- # params:
1065
- # $1 String The message to show, e.g. '--sdl'
1066
- macos_homebrew_message() {
1067
-
1068
- if [[ $1 == '--sdl' ]]; then
1069
- echo -e "
1070
- We recommend using ${BOLD}Homebrew${NORMAL} to install, update, and uninstall
1071
- SDL on macOS. If you installed Simple 2D using Homebrew, the
1072
- following SDL packages were installed:
1073
-
1074
- sdl2
1075
- sdl2_image
1076
- sdl2_mixer
1077
- sdl2_ttf
1078
-
1079
- Run \`brew info <formula>\` to see information about each and
1080
- their dependencies, which were also installed.
1081
-
1082
- Learn more at ${UNDERLINE}http://brew.sh${NORMAL}
1083
- "
1084
- elif [[ $1 == '--HEAD' ]]; then
1085
- echo -e "
1086
- Use ${BOLD}Homebrew${NORMAL} to install, update, and uninstall Simple 2D on macOS.
1087
-
1088
- To install the latest changes from the \`master\` development branch, use:
1089
- brew install --HEAD simple2d
1090
-
1091
- Note \`brew update\` will not update formulas installed with \`--HEAD\`,
1092
- but you can use \`brew reinstall --HEAD simple2d\` to manually grab
1093
- the latest changes.
1094
- "
1095
- else
1096
- echo -e "
1097
- Use ${BOLD}Homebrew${NORMAL} to install, update, and uninstall Simple 2D on macOS.
1098
-
1099
- First, use \`brew tap\` to get Simple 2D formulas:
1100
- brew tap simple2d/tap
1101
-
1102
- Then, the following \`brew\` commands will be available:
1103
- brew install simple2d
1104
- brew upgrade simple2d
1105
- brew uninstall simple2d
1106
-
1107
- Learn more at ${UNDERLINE}http://brew.sh${NORMAL}
1108
- "
1109
- fi
1110
-
1111
- exit
1112
- }
1113
-
1114
-
1115
- # Commands only available on macOS
1116
- macos_only_command() {
1117
- echo -e "This command is only available on macOS"; exit 1
1118
- }
1119
-
1120
-
1121
- # For stuff not yet implemented in MinGW
1122
- mingw_not_implemented_message() {
1123
- echo -e "This isn't implemented in MinGW yet :("; exit 1
1124
- }
1125
-
1126
-
1127
- # Detect Platform ##############################################################
1128
-
1129
-
1130
- unamestr=$(uname)
1131
-
1132
- # macOS
1133
- if [[ $unamestr == 'Darwin' ]]; then
1134
- platform_display='macOS'
1135
- platform='macos'
1136
-
1137
- # ARM
1138
- elif [[ $(uname -m) =~ 'arm' && $unamestr == 'Linux' ]]; then
1139
- platform_display='ARM / Linux'
1140
- platform='arm'
1141
-
1142
- # Raspberry Pi
1143
- if [[ $(cat /etc/os-release | grep -i raspbian) ]]; then
1144
- platform_display='ARM / Linux (Raspberry Pi)'
1145
- platform_rpi=true
1146
- fi
1147
-
1148
- # Linux
1149
- elif [[ $unamestr == 'Linux' ]]; then
1150
- platform_display='Linux'
1151
- platform='linux'
1152
-
1153
- # Windows / MinGW
1154
- elif [[ $unamestr =~ 'MINGW' ]]; then
1155
- platform_display='Windows / MinGW'
1156
- platform='mingw'
1157
-
1158
- # BSD
1159
- elif [[ $unamestr =~ 'BSD' ]]; then
1160
- platform_display='BSD'
1161
- platform='bsd'
1162
- fi
1163
-
1164
- # Unsupported platform
1165
- if [[ $platform == 'unknown' ]]; then
1166
- echo; error_msg "Not a supported system (macOS, Linux, or ARM platform)"; exit 1
1167
- fi
1168
-
1169
-
1170
- # Check Command-line Arguments #################################################
1171
-
1172
-
1173
- print_usage() {
1174
- echo -e "${BOLD}Simple 2D is a simple, open-source 2D graphics engine for everyone.${NORMAL}
1175
-
1176
- Usage: simple2d [--libs] [-v|--version]
1177
- <command> <options>
1178
-
1179
- Summary of commands and options:
1180
- build Build a C/C++ source file or Xcode project; run for options
1181
- install Installs the latest release
1182
- --HEAD Installs from the development branch
1183
- --sdl Installs SDL only
1184
- uninstall Removes Simple 2D files
1185
- --sdl Removes SDL only
1186
- update Updates to latest release
1187
- doctor Runs diagnostics, checks installation, reports issues
1188
- simulator Interact with iOS and tvOS simulators; run for options
1189
- --libs Outputs libraries needed to compile Simple 2D apps
1190
- -v|--version Prints the installed version
1191
- "
1192
- }
1193
-
1194
-
1195
- print_usage_build() {
1196
- echo -e "
1197
- Use the ${BOLD}build${NORMAL} command to compile or build Simple 2D apps.
1198
-
1199
- For compiling C/C++ source files, use:
1200
- build <c_or_cpp_file>
1201
-
1202
- To build an Xcode project, use:
1203
- build <sdk_option> <optional_path_to_xcode_project>
1204
-
1205
- For <sdk_option> above, use one of the following:
1206
- --ios iOS simulator SDK
1207
- --ios-device iOS device SDK (requires signing)
1208
- --tvos tvOS simulator SDK
1209
- --tvos-device tvOS device SDK (requires signing)
1210
- "
1211
- }
1212
-
1213
-
1214
- print_usage_simulator() {
1215
- echo -e "
1216
- Choose an option with the ${BOLD}simulator${NORMAL} command:
1217
-
1218
- --list List available devices
1219
- --booted Show currently booted devices
1220
-
1221
- --open <device_name> Open a simulator device with a given device name
1222
-
1223
- --install <app_file> Install an app on the booted simulator given the path
1224
- to the app e.g. \"Release-iphonesimulator/MyApp.app\"
1225
-
1226
- --launch <bundle_id> Launch an app given the app bundle's identifier,
1227
- e.g. \"Simple2D.MyApp\"
1228
-
1229
- --log Stream log of the booted simulator
1230
- --log <app> Stream log for the app only, given the app name
1231
- --log-errors Stream log containing only error messages
1232
- "
1233
- }
1234
-
1235
-
1236
- case $1 in
1237
- build)
1238
- build $2 $3;;
1239
- install)
1240
- case $2 in
1241
- '')
1242
- install;;
1243
- -y)
1244
- confirmed=true
1245
- install;;
1246
- --HEAD)
1247
- install '--HEAD';;
1248
- --sdl)
1249
- install '--sdl';;
1250
- *)
1251
- print_usage;;
1252
- esac;;
1253
- uninstall)
1254
- case $2 in
1255
- '')
1256
- uninstall;;
1257
- --sdl)
1258
- uninstall '--sdl';;
1259
- *)
1260
- print_usage;;
1261
- esac;;
1262
- update)
1263
- case $2 in
1264
- '')
1265
- update;;
1266
- --HEAD)
1267
- update '--HEAD';;
1268
- *)
1269
- print_usage;;
1270
- esac;;
1271
- doctor)
1272
- doctor;;
1273
- simulator)
1274
- if [[ $platform != 'macos' ]]; then macos_only_command; fi
1275
- case $2 in
1276
- '')
1277
- print_usage_simulator;;
1278
- --list)
1279
- simulator_list;;
1280
- --booted)
1281
- simulator_booted 'cmd';;
1282
- --open)
1283
- simulator_open "$3";;
1284
- --install)
1285
- simulator_install "$3";;
1286
- --launch)
1287
- simulator_launch "$3";;
1288
- --log)
1289
- simulator_log "$3";;
1290
- --log-errors)
1291
- simulator_log_errors;;
1292
- *)
1293
- print_usage_simulator;;
1294
- esac;;
1295
- --libs)
1296
- if [[ $platform == 'macos' ]]; then
1297
- FLAGS='-Wl,-framework,OpenGL'
1298
- elif [[ $platform == 'linux' || $platform == 'bsd' ]]; then
1299
- FLAGS='-lGL -lm'
1300
- elif [[ $platform == 'arm' ]]; then
1301
- FLAGS='-lm -I/opt/vc/include/ -L/opt/vc/lib'
1302
- if $platform_rpi; then
1303
- FLAGS+=' -lbrcmGLESv2'
1304
- else
1305
- FLAGS+=' -lGLESv2'
1306
- fi
1307
- fi
1308
- if [[ $platform == 'mingw' ]]; then
1309
- echo "-I/usr/local/include/ -L/usr/local/lib -lmingw32 -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lopengl32 -lglew32"
1310
- else
1311
- echo "-lsimple2d `sdl2-config --cflags --libs`"\
1312
- "${FLAGS} -lSDL2_image -lSDL2_mixer -lSDL2_ttf"
1313
- fi;;
1314
- -v|--version)
1315
- echo $VERSION;;
1316
- *)
1317
- print_usage;;
1318
- esac