La simu multi-agents qui repeint une image, mais en c++ Boilerplate pompé ici : https://github.com/andrew-r-king/sfml-vscode-boilerplate
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #!/bin/bash
  2. CMD=$1
  3. BUILD=$2
  4. VSCODE=$3
  5. OPTIONS=$4
  6. cwd=${PWD##*/}
  7. export GCC_COLORS="error=01;31:warning=01;33:note=01;36:locus=00;34"
  8. #==============================================================================
  9. # Function declarations
  10. display_styled_symbol() {
  11. printf "\033[1;$1m$2 $3\033[0m\n"
  12. }
  13. build_success() {
  14. printf '\n'
  15. display_styled_symbol 32 "✔" "Succeeded!"
  16. printf '\n'
  17. }
  18. launch() {
  19. display_styled_symbol 32 " " "Launching bin/$BUILD/$NAME"
  20. printf '\n'
  21. }
  22. build_success_launch() {
  23. printf '\n'
  24. display_styled_symbol 32 "✔" "Succeeded!"
  25. launch
  26. }
  27. build_fail() {
  28. printf '\n'
  29. display_styled_symbol 31 "✘" "Failed!"
  30. display_styled_symbol 31 " " "Review the compile errors above."
  31. printf '\n'
  32. printf '\033[0m'
  33. exit 1
  34. }
  35. build_prod_error() {
  36. printf '\n'
  37. display_styled_symbol 31 "⭙" "Error: buildprod must be run on Release build."
  38. printf '\033[0m'
  39. exit 1
  40. }
  41. profiler_done() {
  42. printf '\n'
  43. display_styled_symbol 35 "⯌" "Profiler Completed: View $PROF_ANALYSIS_FILE for details"
  44. printf '\n'
  45. }
  46. profiler_error() {
  47. printf '\n'
  48. display_styled_symbol 31 "⭙" "Error: Profiler must be run on Debug build."
  49. printf '\033[0m'
  50. exit 1
  51. }
  52. profiler_osx() {
  53. display_styled_symbol 31 "⭙" "Error: Profiling (with gprof) is not supported on Mac OSX."
  54. printf '\033[0m'
  55. exit 1
  56. }
  57. cmd_buildrun() {
  58. display_styled_symbol 33 "⬤" "Build & Run: $BUILD (target: $NAME)"
  59. printf '\n'
  60. BLD=$BUILD
  61. if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
  62. BLD=Release
  63. fi
  64. if $MAKE_EXEC BUILD=$BLD; then
  65. build_success_launch
  66. if [[ $BUILD == 'Tests' ]]; then
  67. bin/Release/$NAME $OPTIONS
  68. else
  69. bin/$BUILD/$NAME $OPTIONS
  70. fi
  71. else
  72. build_fail
  73. fi
  74. }
  75. cmd_build() {
  76. display_styled_symbol 33 "⬤" "Build: $BUILD (target: $NAME)"
  77. printf '\n'
  78. BLD=$BUILD
  79. if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
  80. BLD=Release
  81. fi
  82. if $MAKE_EXEC BUILD=$BLD; then
  83. build_success
  84. else
  85. build_fail
  86. fi
  87. }
  88. cmd_rebuild() {
  89. display_styled_symbol 33 "⬤" "Rebuild: $BUILD (target: $NAME)"
  90. printf '\n'
  91. BLD=$BUILD
  92. if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
  93. BLD=Release
  94. fi
  95. if $MAKE_EXEC BUILD=$BLD rebuild; then
  96. build_success
  97. else
  98. build_fail
  99. fi
  100. }
  101. cmd_run() {
  102. display_styled_symbol 33 "⬤" "Run: $BUILD (target: $NAME)"
  103. printf '\n'
  104. launch
  105. if [[ $BUILD == 'Tests' ]]; then
  106. bin/Release/$NAME $OPTIONS
  107. else
  108. bin/$BUILD/$NAME $OPTIONS
  109. fi
  110. }
  111. cmd_buildprod() {
  112. display_styled_symbol 33 "⬤" "Production Build: $BUILD (target: $NAME)"
  113. printf '\n'
  114. if [[ $BUILD == 'Release' ]]; then
  115. RECIPE=buildprod
  116. if [[ $1 != 'main' ]]; then
  117. RECIPE=
  118. fi
  119. if $MAKE_EXEC BUILD=$BUILD $RECIPE; then
  120. build_success
  121. else
  122. build_fail
  123. fi
  124. else
  125. build_prod_error
  126. fi
  127. }
  128. cmd_profile() {
  129. display_styled_symbol 33 "⬤" "Profile: $BUILD (target: $NAME)"
  130. printf '\n'
  131. if [[ $PLATFORM == 'osx' ]]; then
  132. profiler_osx
  133. elif [[ $BUILD == 'Debug' ]]; then
  134. if $MAKE_EXEC BUILD=$BUILD; then
  135. build_success_launch
  136. printf '\033[0m'
  137. bin/$BUILD/$NAME
  138. printf '\033[0;34m'
  139. gprof bin/Debug/$NAME gmon.out > $PROF_ANALYSIS_FILE 2> /dev/null
  140. profiler_done
  141. else
  142. build_fail
  143. fi
  144. else
  145. profiler_error
  146. fi
  147. }
  148. #==============================================================================
  149. # Environment
  150. if [[ $CMD == '' ]]; then
  151. CMD=buildprod
  152. fi
  153. if [[ $BUILD == '' ]]; then
  154. BUILD=Release
  155. fi
  156. if [[ $OSTYPE == 'linux-gnu'* || $OSTYPE == 'cygwin'* ]]; then
  157. if [[ $OSTYPE == 'linux-gnueabihf' ]]; then
  158. export PLATFORM=rpi
  159. else
  160. export PLATFORM=linux
  161. fi
  162. elif [[ $OSTYPE == 'darwin'* ]]; then
  163. export PLATFORM=osx
  164. elif [[ $OSTYPE == 'msys' || $OSTYPE == 'win32' ]]; then
  165. export PLATFORM=windows
  166. fi
  167. if [[ $VSCODE != 'vscode' ]]; then
  168. export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
  169. if [[ $PLATFORM == 'windows' ]]; then
  170. export PATH="/c/SFML-2.5.1/bin:/c/mingw32/bin:$PATH"
  171. else
  172. if [[ $PLATFORM == 'rpi' ]]; then
  173. export PATH="/usr/local/gcc-8.1.0/bin:$PATH"
  174. fi
  175. fi
  176. printf "\nbuild.sh PATH=$PATH\n"
  177. fi
  178. export MAKE_EXEC=make
  179. if [[ $PLATFORM == 'windows' ]]; then
  180. if [ $(type -P "mingw32-make.exe") ]; then
  181. export MAKE_EXEC=mingw32-make.exe
  182. elif [ $(type -P "make.exe") ]; then
  183. export MAKE_EXEC=make.exe
  184. fi
  185. fi
  186. if [[ $BUILD != "Release" && $BUILD != 'Debug' && $BUILD != 'Tests' ]]; then
  187. BUILD=Release
  188. fi
  189. PROF_EXEC=gprof
  190. PROF_ANALYSIS_FILE=profiler_analysis.stats
  191. #==============================================================================
  192. # Main script
  193. if [[ $BUILD_TARGETS == '' ]]; then
  194. BUILD_TARGETS=main
  195. NO_SRC_TARGET=1
  196. fi
  197. for target in $BUILD_TARGETS; do
  198. if [[ $PLATFORM == 'windows' ]]; then
  199. if [[ $target == 'main' ]]; then
  200. export NAME=$cwd.exe
  201. if [[ $BUILD == 'Tests' ]]; then
  202. NAME=tests_$NAME
  203. fi
  204. else
  205. if [[ $BUILD == 'Debug' ]]; then
  206. export NAME=lib$target-d.dll
  207. else
  208. export NAME=lib$target.dll
  209. fi
  210. fi
  211. else
  212. if [[ $PLATFORM == 'osx' ]]; then
  213. if [[ $target == 'main' ]]; then
  214. export NAME=$cwd
  215. if [[ $BUILD == 'Tests' ]]; then
  216. NAME=tests_$NAME
  217. fi
  218. else
  219. if [[ $BUILD == 'Debug' ]]; then
  220. export NAME=lib$target-d.dylib
  221. else
  222. export NAME=lib$target.dylib
  223. fi
  224. fi
  225. else
  226. if [[ $target == 'main' ]]; then
  227. export NAME=$cwd
  228. if [[ $BUILD == 'Tests' ]]; then
  229. NAME=tests_$NAME
  230. fi
  231. else
  232. if [[ $BUILD == 'Debug' ]]; then
  233. export NAME=lib$target-d.so
  234. else
  235. export NAME=lib$target.so
  236. fi
  237. fi
  238. fi
  239. fi
  240. if [[ $NO_SRC_TARGET != 1 ]]; then
  241. export SRC_TARGET=$target
  242. fi
  243. if [[ ($CMD == 'run' || $CMD == 'profile') && $target != 'main' ]]; then
  244. continue
  245. fi
  246. CHILD_CMD="cmd_$CMD $target"
  247. if [[ $CMD == 'buildrun' && $target != 'main' ]]; then
  248. CHILD_CMD="cmd_build"
  249. fi
  250. printf '\033[0;34m'
  251. if $CHILD_CMD ; then
  252. printf '\033[0m'
  253. else
  254. printf "\033[1;31mError: Command \"$CHILD_CMD\" not recognized.\033[0m"
  255. exit 1
  256. fi
  257. RESULT=$?
  258. if [[ $RESULT != 0 ]]; then
  259. break
  260. fi
  261. done
  262. printf '\033[0m\n'
  263. exit 0