Browse Source

le projet

master
DemiSel 3 years ago
parent
commit
72118c63fc
60 changed files with 19262 additions and 0 deletions
  1. 62
    0
      .clang-format
  2. 57
    0
      .vscode/_keybindings.json
  3. 69
    0
      .vscode/c_cpp_properties.json
  4. 46
    0
      .vscode/launch.json
  5. 109
    0
      .vscode/settings.json
  6. 204
    0
      .vscode/tasks.json
  7. 479
    0
      Makefile
  8. 7
    0
      README.md
  9. 302
    0
      build.sh
  10. 3
    0
      content/stub.txt
  11. 30
    0
      env/.all.mk
  12. 7
    0
      env/.debug.mk
  13. 1
    0
      env/.release.mk
  14. 22
    0
      env/linux.all.mk
  15. 10
    0
      env/linux/exec.desktop
  16. BIN
      env/linux/sfml.png
  17. 39
    0
      env/osx.all.mk
  18. 3
    0
      env/osx.debug.mk
  19. 13
    0
      env/osx/Info.plist.json
  20. BIN
      env/osx/dmg-background.png
  21. BIN
      env/osx/dmg-background@2x.png
  22. 23
    0
      env/osx/dmg.applescript
  23. BIN
      env/osx/sfml.png
  24. 20
    0
      env/rpi.release.mk
  25. 31
    0
      env/windows.all.mk
  26. 8
    0
      env/windows.debug.mk
  27. 2
    0
      env/windows.release.mk
  28. BIN
      env/windows/app.ico
  29. 40
    0
      env/windows/app.manifest
  30. BIN
      env/windows/icon_128.png
  31. BIN
      env/windows/icon_16.png
  32. BIN
      env/windows/icon_256.png
  33. BIN
      env/windows/icon_32.png
  34. BIN
      env/windows/icon_48.png
  35. BIN
      env/windows/icon_64.png
  36. 28
    0
      env/windows/win-make_icon_from256.sh
  37. 28
    0
      env/windows/win-make_icon_from_all.sh
  38. 18
    0
      lib/Agents/Agent.hpp
  39. 15
    0
      lib/Agents/Perception/Perception.hpp
  40. 24
    0
      lib/Environment/PictureEnvironment.hpp
  41. 16865
    0
      lib/catch2/catch.hpp
  42. 11
    0
      src/Agents/Agent.cpp
  43. 12
    0
      src/Agents/Perception/Perception.cpp
  44. 67
    0
      src/Environment/PictureEnvironment.cpp
  45. 29
    0
      src/Main.cpp
  46. 72
    0
      src/PCH.hpp
  47. 16
    0
      src/Platform/IPlatform.hpp
  48. 69
    0
      src/Platform/MacOS/MacOSPlatform.cpp
  49. 19
    0
      src/Platform/MacOS/MacOSPlatform.hpp
  50. 22
    0
      src/Platform/Platform.hpp
  51. 55
    0
      src/Platform/Unix/LinuxPlatform.cpp
  52. 19
    0
      src/Platform/Unix/LinuxPlatform.hpp
  53. 9
    0
      src/Platform/Win32/Resource.h
  54. 7
    0
      src/Platform/Win32/Resource.rc
  55. 188
    0
      src/Platform/Win32/WindowsPlatform.cpp
  56. 29
    0
      src/Platform/Win32/WindowsPlatform.hpp
  57. 20
    0
      src/Utility/FileSystem.hpp
  58. 13
    0
      src/Utility/Types.hpp
  59. 7
    0
      test/Main.cpp
  60. 33
    0
      test/test_RenderWindow.cpp

+ 62
- 0
.clang-format View File

@@ -0,0 +1,62 @@
1
+# Clang version 9.0.0
2
+Language: Cpp
3
+AccessModifierOffset: -4
4
+AllowShortBlocksOnASingleLine: false
5
+AlwaysBreakTemplateDeclarations: Yes
6
+AlignConsecutiveAssignments: false
7
+AlignConsecutiveDeclarations: false
8
+AlignOperands: false
9
+AlignTrailingComments: true
10
+AlignAfterOpenBracket: DontAlign
11
+AllowAllConstructorInitializersOnNextLine: false
12
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
13
+AllowShortCaseLabelsOnASingleLine: true
14
+AllowShortIfStatementsOnASingleLine: false
15
+AllowShortFunctionsOnASingleLine: false
16
+BinPackArguments: false
17
+BreakBeforeBinaryOperators: NonAssignment
18
+BreakBeforeTernaryOperators: false
19
+BreakConstructorInitializers: AfterColon
20
+BreakInheritanceList: AfterColon
21
+BreakStringLiterals: false
22
+ColumnLimit: 0
23
+CompactNamespaces: false
24
+FixNamespaceComments: false
25
+ContinuationIndentWidth: 4
26
+Cpp11BracedListStyle: false
27
+ExperimentalAutoDetectBinPacking: false
28
+IndentCaseLabels: true
29
+IndentPPDirectives: BeforeHash
30
+IndentWidth: 4
31
+MaxEmptyLinesToKeep: 1
32
+NamespaceIndentation: None
33
+PointerAlignment: Left
34
+ReflowComments: false
35
+SpaceAfterCStyleCast: false
36
+SpaceAfterTemplateKeyword: true
37
+SpaceBeforeCpp11BracedList: true
38
+SpacesInAngles: false
39
+SpacesInContainerLiterals: false
40
+SpacesInParentheses: false
41
+SpacesInSquareBrackets: false
42
+Standard: Cpp11
43
+TabWidth: 4
44
+UseTab: Always
45
+
46
+BreakBeforeBraces: Custom
47
+BraceWrapping:
48
+  AfterCaseLabel: false
49
+  AfterClass: true
50
+  AfterControlStatement: true
51
+  AfterEnum: true
52
+  AfterFunction: true
53
+  AfterNamespace: true
54
+  AfterStruct: true
55
+  AfterUnion: true
56
+  AfterExternBlock: true
57
+  BeforeCatch: true
58
+  BeforeElse: true
59
+  IndentBraces: false
60
+  SplitEmptyFunction: false
61
+  SplitEmptyRecord: false
62
+  SplitEmptyNamespace: true

+ 57
- 0
.vscode/_keybindings.json View File

@@ -0,0 +1,57 @@
1
+// Place your key bindings in this file to overwrite the defaults
2
+[
3
+	{
4
+		"key": "f8",
5
+		"command": "-editor.action.marker.next",
6
+		"when": "editorFocus && !editorReadonly"
7
+	},
8
+	{
9
+		"key": "f9",
10
+		"command": "-editor.debug.action.toggleBreakpoint",
11
+		"when": "editorTextFocus"
12
+	},
13
+	{
14
+		"key": "f10",
15
+		"command": "-workbench.action.debug.stepOver",
16
+		"when": "inDebugMode"
17
+	},
18
+	{
19
+		"key": "shift+f8",
20
+		"command": "-editor.action.marker.prev",
21
+		"when": "editorFocus && !editorReadonly"
22
+	},
23
+	{
24
+		"key": "shift+f9",
25
+		"command": "-editor.debug.action.toggleInlineBreakpoint",
26
+		"when": "editorTextFocus"
27
+	},
28
+	{
29
+		"key": "shift+f10",
30
+		"command": "-editor.action.showContextMenu",
31
+		"when": "editorTextFocus"
32
+	},
33
+	{
34
+		"key": "f8",
35
+		"command": "workbench.action.debug.selectandstart"
36
+	},
37
+	{
38
+		"key": "f9",
39
+		"command": "workbench.action.tasks.runTask",
40
+		"args": "Build & Run: Release"
41
+	},
42
+	{
43
+		"key": "shift+f9",
44
+		"command": "workbench.action.tasks.runTask",
45
+		"args": "Run: Release"
46
+	},
47
+	{
48
+		"key": "f10",
49
+		"command": "workbench.action.tasks.runTask",
50
+		"args": "Build & Run: Debug"
51
+	},
52
+	{
53
+		"key": "shift+f10",
54
+		"command": "workbench.action.tasks.runTask",
55
+		"args": "Run: Debug"
56
+	},
57
+]

+ 69
- 0
.vscode/c_cpp_properties.json View File

@@ -0,0 +1,69 @@
1
+{
2
+	"configurations": [
3
+		{
4
+			"name": "Linux",
5
+			"intelliSenseMode": "gcc-x64",
6
+			"includePath": [
7
+				"${workspaceFolder}/src",
8
+				"${workspaceFolder}/lib",
9
+				"${workspaceFolder}/test",
10
+				"~/SFML-2.5.1/include",
11
+				"/usr/local/include/**",
12
+				"/usr/include/**"
13
+			],
14
+			"defines": [
15
+				"_DEBUG"
16
+			],
17
+			"cStandard": "c11",
18
+			"cppStandard": "c++17",
19
+			"forcedInclude": [
20
+				"${workspaceFolder}/src/PCH.hpp"
21
+			]
22
+		},
23
+		{
24
+			"name": "Mac",
25
+			"intelliSenseMode": "clang-x64",
26
+			"compilerPath": "/usr/bin/clang",
27
+			"macFrameworkPath": [
28
+				"/Library/Frameworks",
29
+				"/System/Library/Frameworks"
30
+			],
31
+			"includePath": [
32
+				"${workspaceFolder}/src",
33
+				"${workspaceFolder}/lib",
34
+				"${workspaceFolder}/test",
35
+				"/usr/local/include/**"
36
+			],
37
+			"defines": [
38
+				"_DEBUG"
39
+			],
40
+			"cStandard": "c11",
41
+			"cppStandard": "c++17",
42
+			"forcedInclude": [
43
+				"${workspaceFolder}/src/PCH.hpp"
44
+			]
45
+		},
46
+		{
47
+			"name": "Win32",
48
+			"intelliSenseMode": "gcc-x86",
49
+			"compilerPath": "C:/mingw32/bin/gcc.exe",
50
+			"includePath": [
51
+				"${workspaceFolder}/src",
52
+				"${workspaceFolder}/lib",
53
+				"${workspaceFolder}/test",
54
+				"C:/SFML-2.5.1/include"
55
+			],
56
+			"defines": [
57
+				"_DEBUG",
58
+				"UNICODE",
59
+				"_UNICODE"
60
+			],
61
+			"cStandard": "c11",
62
+			"cppStandard": "c++17",
63
+			"forcedInclude": [
64
+				"${workspaceFolder}/src/PCH.hpp"
65
+			]
66
+		}
67
+	],
68
+	"version": 4
69
+}

+ 46
- 0
.vscode/launch.json View File

@@ -0,0 +1,46 @@
1
+{
2
+	"version": "0.2.0",
3
+	"configurations": [
4
+		{
5
+			"name": "GDB/LLDB",
6
+			"type": "cppdbg",
7
+			"request": "launch",
8
+			"program": "${workspaceFolder}/bin/Debug/${workspaceRootFolderName}.exe",
9
+			"args": [],
10
+			"stopAtEntry": false,
11
+			"cwd": "${workspaceFolder}",
12
+			"preLaunchTask": "Build: Debug",
13
+			"externalConsole": false,
14
+			"internalConsoleOptions": "neverOpen",
15
+			"setupCommands": [
16
+				{
17
+					"description": "Enable pretty-printing for gdb",
18
+					"text": "-enable-pretty-printing",
19
+					"ignoreFailures": true
20
+				}
21
+			],
22
+			"windows": {
23
+				"MIMode": "gdb",
24
+				"miDebuggerPath": "C:/mingw32/bin/gdb.exe",
25
+				"env": {
26
+					"Path": "${config:terminal.integrated.env.windows.Path}"
27
+				}
28
+			},
29
+			"linux": {
30
+				"program": "${workspaceFolder}/bin/Debug/${workspaceRootFolderName}",
31
+				"MIMode": "gdb",
32
+				"miDebuggerPath": "/usr/bin/gdb",
33
+				"env": {
34
+					"PATH": "${config:terminal.integrated.env.linux.PATH}",
35
+				}
36
+			},
37
+			"osx": {
38
+				"program": "${workspaceFolder}/bin/Debug/${workspaceRootFolderName}",
39
+				"MIMode": "lldb",
40
+				"env": {
41
+					"PATH": "${config:terminal.integrated.env.osx.PATH}",
42
+				}
43
+			},
44
+		}
45
+	]
46
+}

+ 109
- 0
.vscode/settings.json View File

@@ -0,0 +1,109 @@
1
+{
2
+	"C_Cpp.autocomplete": "Default",
3
+	"C_Cpp.intelliSenseEngine": "Default",
4
+	"C_Cpp.preferredPathSeparator": "Forward Slash",
5
+	"C_Cpp.workspaceParsingPriority": "highest",
6
+	"C_Cpp.enhancedColorization": "Disabled",
7
+	"debug.toolBarLocation": "docked",
8
+	"editor.tabSize": 4,
9
+	"editor.insertSpaces": false,
10
+	"editor.formatOnSave": true,
11
+	"files.encoding": "utf8",
12
+	"files.trimTrailingWhitespace": true,
13
+	"files.eol": "\n",
14
+	"files.exclude": {
15
+		// "Makefile": true,
16
+		// "build.sh": true,
17
+		"gmon.out": true,
18
+		// "bin/": true,
19
+		// "build/": true,
20
+		"**/*.7z": true,
21
+		"**/*.rar": true,
22
+		"**/Thumbs.db": true
23
+	},
24
+	"files.associations": {
25
+		"*.json": "jsonc",
26
+		"*.stats": "cpp",
27
+		"*.desktop": "properties",
28
+		".clang-format": "yaml",
29
+		"array": "cpp",
30
+		"atomic": "cpp",
31
+		"*.tcc": "cpp",
32
+		"bitset": "cpp",
33
+		"cctype": "cpp",
34
+		"chrono": "cpp",
35
+		"clocale": "cpp",
36
+		"cmath": "cpp",
37
+		"codecvt": "cpp",
38
+		"condition_variable": "cpp",
39
+		"cstdarg": "cpp",
40
+		"cstddef": "cpp",
41
+		"cstdint": "cpp",
42
+		"cstdio": "cpp",
43
+		"cstdlib": "cpp",
44
+		"cstring": "cpp",
45
+		"ctime": "cpp",
46
+		"cwchar": "cpp",
47
+		"cwctype": "cpp",
48
+		"deque": "cpp",
49
+		"list": "cpp",
50
+		"unordered_map": "cpp",
51
+		"vector": "cpp",
52
+		"exception": "cpp",
53
+		"algorithm": "cpp",
54
+		"filesystem": "cpp",
55
+		"functional": "cpp",
56
+		"iterator": "cpp",
57
+		"map": "cpp",
58
+		"memory": "cpp",
59
+		"memory_resource": "cpp",
60
+		"numeric": "cpp",
61
+		"optional": "cpp",
62
+		"random": "cpp",
63
+		"ratio": "cpp",
64
+		"regex": "cpp",
65
+		"set": "cpp",
66
+		"string": "cpp",
67
+		"string_view": "cpp",
68
+		"system_error": "cpp",
69
+		"tuple": "cpp",
70
+		"type_traits": "cpp",
71
+		"utility": "cpp",
72
+		"fstream": "cpp",
73
+		"future": "cpp",
74
+		"initializer_list": "cpp",
75
+		"iomanip": "cpp",
76
+		"iosfwd": "cpp",
77
+		"iostream": "cpp",
78
+		"istream": "cpp",
79
+		"limits": "cpp",
80
+		"mutex": "cpp",
81
+		"new": "cpp",
82
+		"ostream": "cpp",
83
+		"sstream": "cpp",
84
+		"stdexcept": "cpp",
85
+		"streambuf": "cpp",
86
+		"thread": "cpp",
87
+		"typeinfo": "cpp",
88
+		"variant": "cpp"
89
+	},
90
+	"terminal.integrated.shell.windows": "C:/Program Files/Git/bin/bash.exe",
91
+	"terminal.integrated.env.windows": {
92
+		"Path": "C:/mingw32/bin;C:/SFML-2.5.1/bin"
93
+	},
94
+	"terminal.integrated.env.linux": {
95
+		"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
96
+	},
97
+	"terminal.integrated.env.osx": {
98
+		"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
99
+	},
100
+	"workbench.colorCustomizations": {
101
+		"statusBar.background": "#8ac242",
102
+		"statusBar.foreground": "#ffffff",
103
+		"statusBar.debuggingBackground": "#5e9517",
104
+		"statusBar.debuggingForeground": "#ffffff",
105
+	},
106
+	"[applescript]": {
107
+		"files.encoding": "utf8"
108
+	}
109
+}

+ 204
- 0
.vscode/tasks.json View File

@@ -0,0 +1,204 @@
1
+{
2
+	// See https://go.microsoft.com/fwlink/?LinkId=733558
3
+	// for the documentation about the tasks.json format
4
+	"version": "2.0.0",
5
+	"windows": {
6
+		"options": {
7
+			"env": {
8
+				"Path": "${config:terminal.integrated.env.windows.Path}"
9
+			}
10
+		}
11
+	},
12
+	"linux": {
13
+		"options": {
14
+			"env": {
15
+				"PATH": "${config:terminal.integrated.env.linux.PATH}"
16
+			}
17
+		}
18
+	},
19
+	"osx": {
20
+		"options": {
21
+			"env": {
22
+				"PATH": "${config:terminal.integrated.env.osx.PATH}"
23
+			}
24
+		}
25
+	},
26
+	"presentation": {
27
+		"echo": false,
28
+		"reveal": "always",
29
+		"focus": true,
30
+		"panel": "shared",
31
+		"clear": false,
32
+		"showReuseMessage": true
33
+	},
34
+	"tasks": [
35
+		{
36
+			"label": "Build & Run: Release",
37
+			"command": "bash ./build.sh buildrun Release vscode",
38
+			"type": "shell",
39
+			"group": {
40
+				"kind": "build",
41
+				"isDefault": true
42
+			},
43
+			"problemMatcher": [
44
+				"$gcc"
45
+			],
46
+		},
47
+		{
48
+			"label": "Build: Release",
49
+			"command": "bash ./build.sh build Release vscode",
50
+			"type": "shell",
51
+			"group": {
52
+				"kind": "build",
53
+				"isDefault": true
54
+			},
55
+			"problemMatcher": [
56
+				"$gcc"
57
+			]
58
+		},
59
+		{
60
+			"label": "Run: Release",
61
+			"command": "bash ./build.sh run Release vscode",
62
+			"type": "shell",
63
+			"group": {
64
+				"kind": "build",
65
+				"isDefault": true
66
+			},
67
+			"problemMatcher": [
68
+				"$gcc"
69
+			]
70
+		},
71
+		{
72
+			"label": "Rebuild: Release",
73
+			"command": "bash ./build.sh rebuild Release vscode",
74
+			"type": "shell",
75
+			"group": {
76
+				"kind": "build",
77
+				"isDefault": true
78
+			},
79
+			"problemMatcher": [
80
+				"$gcc"
81
+			]
82
+		},
83
+		{
84
+			"label": "Build & Run: Debug",
85
+			"command": "bash ./build.sh buildrun Debug vscode",
86
+			"type": "shell",
87
+			"group": {
88
+				"kind": "build",
89
+				"isDefault": true
90
+			},
91
+			"problemMatcher": [
92
+				"$gcc"
93
+			]
94
+		},
95
+		{
96
+			"label": "Build: Debug",
97
+			"command": "bash ./build.sh build Debug vscode",
98
+			"type": "shell",
99
+			"group": {
100
+				"kind": "build",
101
+				"isDefault": true
102
+			},
103
+			"problemMatcher": [
104
+				"$gcc"
105
+			]
106
+		},
107
+		{
108
+			"label": "Run: Debug",
109
+			"command": "bash ./build.sh run Debug vscode",
110
+			"type": "shell",
111
+			"group": {
112
+				"kind": "build",
113
+				"isDefault": true
114
+			},
115
+			"problemMatcher": [
116
+				"$gcc"
117
+			]
118
+		},
119
+		{
120
+			"label": "Rebuild: Debug",
121
+			"command": "bash ./build.sh rebuild Debug vscode",
122
+			"type": "shell",
123
+			"group": {
124
+				"kind": "build",
125
+				"isDefault": true
126
+			},
127
+			"problemMatcher": [
128
+				"$gcc"
129
+			]
130
+		},
131
+		{
132
+			"label": "Profile: Debug",
133
+			"command": "bash ./build.sh profile Debug vscode",
134
+			"type": "shell",
135
+			"group": {
136
+				"kind": "build",
137
+				"isDefault": true
138
+			},
139
+			"problemMatcher": [
140
+				"$gcc"
141
+			]
142
+		},
143
+		{
144
+			"label": "Build & Run: Tests",
145
+			"command": "bash ./build.sh buildrun Tests vscode '-w NoTests -s'",
146
+			"type": "shell",
147
+			"group": {
148
+				"kind": "build",
149
+				"isDefault": true
150
+			},
151
+			"problemMatcher": [
152
+				"$gcc"
153
+			]
154
+		},
155
+		{
156
+			"label": "Build: Tests",
157
+			"command": "bash ./build.sh build Tests vscode",
158
+			"type": "shell",
159
+			"group": {
160
+				"kind": "build",
161
+				"isDefault": true
162
+			},
163
+			"problemMatcher": [
164
+				"$gcc"
165
+			]
166
+		},
167
+		{
168
+			"label": "Run: Tests",
169
+			"command": "bash ./build.sh run Tests vscode '-w NoTests -s'",
170
+			"type": "shell",
171
+			"group": {
172
+				"kind": "build",
173
+				"isDefault": true
174
+			},
175
+			"problemMatcher": [
176
+				"$gcc"
177
+			]
178
+		},
179
+		{
180
+			"label": "Rebuild: Tests",
181
+			"command": "bash ./build.sh rebuild Tests vscode",
182
+			"type": "shell",
183
+			"group": {
184
+				"kind": "build",
185
+				"isDefault": true
186
+			},
187
+			"problemMatcher": [
188
+				"$gcc"
189
+			]
190
+		},
191
+		{
192
+			"label": "Build: Production",
193
+			"command": "bash ./build.sh buildprod Release vscode",
194
+			"type": "shell",
195
+			"group": {
196
+				"kind": "build",
197
+				"isDefault": true
198
+			},
199
+			"problemMatcher": [
200
+				"$gcc"
201
+			]
202
+		}
203
+	]
204
+}

+ 479
- 0
Makefile View File

@@ -0,0 +1,479 @@
1
+.SUFFIXES:
2
+SUFFIXES =
3
+.SUFFIXES: .c .cpp .h .hpp .rc .res .inl .o .d .asm
4
+
5
+
6
+#==============================================================================
7
+MAKEFLAGS += --no-print-directory
8
+#==============================================================================
9
+
10
+SHELL := /bin/sh
11
+
12
+# Build platform
13
+PLATFORM?=linux
14
+# Build description (Primarily uses Debug/Release)
15
+BUILD?=Release
16
+_BUILDL := $(shell echo $(BUILD) | tr A-Z a-z)
17
+ifeq ($(BUILD),Tests)
18
+	_BUILDL := release
19
+endif
20
+
21
+# The sub-folder containing the target source files
22
+SRC_TARGET?=
23
+ifneq ($(SRC_TARGET),)
24
+	_SRC_TARGET := /$(SRC_TARGET)
25
+endif
26
+
27
+# Maximum parallel jobs during build process
28
+MAX_PARALLEL_JOBS?=8
29
+
30
+# Dump assembly?
31
+DUMP_ASSEMBLY?=false
32
+
33
+# Clean output?
34
+CLEAN_OUTPUT?=true
35
+
36
+# If dll, build as a static library?
37
+BUILD_STATIC?=false
38
+
39
+# Platform specific environment variables
40
+-include env/.all.mk
41
+-include env/.$(_BUILDL).mk
42
+-include env/$(PLATFORM).all.mk
43
+-include env/$(PLATFORM).$(_BUILDL).mk
44
+
45
+# Target specific variables
46
+ifneq ($(SRC_TARGET),)
47
+-include env/$(SRC_TARGET)/.all.mk
48
+-include env/$(SRC_TARGET)/.$(_BUILDL).mk
49
+-include env/$(SRC_TARGET)/$(PLATFORM).all.mk
50
+-include env/$(SRC_TARGET)/$(PLATFORM).$(_BUILDL).mk
51
+endif
52
+
53
+#==============================================================================
54
+# File/Folder dependencies for the production build recipe (makeproduction)
55
+PRODUCTION_DEPENDENCIES?=
56
+# Extensions to exclude from production builds
57
+PRODUCTION_EXCLUDE?=
58
+# Folder location (relative or absolute) to place the production build into
59
+PRODUCTION_FOLDER?=build
60
+PRODUCTION_FOLDER_RESOURCES := $(PRODUCTION_FOLDER)
61
+
62
+#==============================================================================
63
+# Library directories (separated by spaces)
64
+LIB_DIRS := \
65
+    $(LIB_DIRS ) \
66
+    $(_SFML)/lib
67
+
68
+INCLUDE_DIRS := \
69
+	$(INCLUDE_DIRS) \
70
+	lib/Environment
71
+
72
+# Link libraries (separated by spaces)
73
+LINK_LIBRARIES?=
74
+
75
+# Precompiled header filename (no extension)
76
+# This file will be excluded from Rebuild, but if the bin/(build) directory is removed, it will be as well.
77
+PRECOMPILED_HEADER?=
78
+
79
+# Build-specific preprocessor macros
80
+BUILD_MACROS?=
81
+# Build-specific compiler flags to be appended to the final build step (with prefix)
82
+BUILD_FLAGS?=
83
+
84
+# Build dependencies to copy into the bin/(build) folder - example: openal32.dll
85
+BUILD_DEPENDENCIES?=
86
+
87
+# NAME should always be passed as an argument from tasks.json as the root folder name, but uses a fallback of "game.exe"
88
+# This is used for the output filename (game.exe)
89
+NAME?=game.exe
90
+
91
+#==============================================================================
92
+# The source file directory
93
+SRC_DIR := src$(_SRC_TARGET)
94
+LIB_DIR := lib
95
+
96
+# Project .cpp or .rc files (relative to $(SRC_DIR) directory)
97
+SOURCE_FILES := $(patsubst $(SRC_DIR)/%,%,$(shell find $(SRC_DIR) -name '*.cpp' -o -name '*.c' -o -name '*.cc' -o -name '*.rc'))
98
+# Project subdirectories within $(SRC_DIR)/ that contain source files
99
+PROJECT_DIRS := $(patsubst $(SRC_DIR)/%,%,$(shell find $(SRC_DIR) -mindepth 1 -maxdepth 99 -type d))
100
+
101
+# Add prefixes to the above variables
102
+_INCLUDE_DIRS := $(patsubst %,-I%,$(SRC_DIR)/ $(LIB_DIR)/ $(INCLUDE_DIRS))
103
+
104
+_BUILD_MACROS := $(BUILD_MACROS:%=-D%)
105
+_LINK_LIBRARIES := $(LINK_LIBRARIES:%=-l%)
106
+
107
+#==============================================================================
108
+# Unit Testing
109
+TEST_DIR :=
110
+ifeq ($(BUILD),Tests)
111
+	TEST_DIR := test
112
+	SOURCE_FILES := $(SOURCE_FILES:Main.cpp=)
113
+	SOURCE_FILES := $(patsubst $(TEST_DIR)/%,.$(TEST_DIR)/%,$(shell find $(TEST_DIR) -name '*.cpp' -o -name '*.c' -o -name '*.cc' -o -name '*.rc')) $(SOURCE_FILES)
114
+	_INCLUDE_DIRS := $(patsubst %,-I%,$(TEST_DIR)/) $(_INCLUDE_DIRS)
115
+	PROJECT_DIRS := .$(TEST_DIR) $(PROJECT_DIRS)
116
+	BUILD_FLAGS := $(BUILD_FLAGS:-mwindows=)
117
+endif
118
+
119
+#==============================================================================
120
+# Linux Specific
121
+PRODUCTION_LINUX_ICON?=icon
122
+
123
+# The full working directory
124
+ifeq ($(PLATFORM),linux)
125
+	_LINUX_GREP_CWD := $(shell echo $(CURDIR) | sed 's/\//\\\//g')
126
+endif
127
+
128
+#==============================================================================
129
+# MacOS Specific
130
+PRODUCTION_MACOS_ICON?=icon
131
+PRODUCTION_MACOS_BUNDLE_COMPANY?=developer
132
+PRODUCTION_MACOS_BUNDLE_DISPLAY_NAME?=App
133
+PRODUCTION_MACOS_BUNDLE_NAME?=App
134
+PRODUCTION_MACOS_MAKE_DMG?=true
135
+PRODUCTION_MACOS_BACKGROUND?=dmg-background
136
+
137
+ifeq ($(PLATFORM),osx)
138
+	PRODUCTION_MACOS_BUNDLE_COMPANY := '$(PRODUCTION_MACOS_BUNDLE_COMPANY)'
139
+	PRODUCTION_MACOS_BUNDLE_DISPLAY_NAME := '$(PRODUCTION_MACOS_BUNDLE_DISPLAY_NAME)'
140
+	PRODUCTION_MACOS_BUNDLE_NAME := '$(PRODUCTION_MACOS_BUNDLE_NAME)'
141
+	PRODUCTION_FOLDER_MACOS := $(PRODUCTION_FOLDER)
142
+	PRODUCTION_FOLDER := $(PRODUCTION_FOLDER)/$(PRODUCTION_MACOS_BUNDLE_NAME).app/Contents
143
+	PRODUCTION_FOLDER_RESOURCES := $(PRODUCTION_FOLDER)/Resources
144
+	PRODUCTION_DEPENDENCIES := $(PRODUCTION_DEPENDENCIES)
145
+	PRODUCTION_MACOS_DYLIBS := $(PRODUCTION_MACOS_DYLIBS:%=%.dylib)
146
+	MACOS_FRAMEWORKS?=CoreFoundation
147
+	PRODUCTION_MACOS_FRAMEWORKS := $(PRODUCTION_MACOS_FRAMEWORKS:%=%.framework)
148
+	PRODUCTION_MACOS_BACKGROUND := env/osx/$(PRODUCTION_MACOS_BACKGROUND)
149
+	MACOS_FRAMEWORK_PATHS := $(MACOS_FRAMEWORK_PATHS:%=-F%)
150
+	BUILD_FLAGS := $(BUILD_FLAGS) $(MACOS_FRAMEWORK_PATHS) $(MACOS_FRAMEWORKS:%=-framework %)
151
+endif
152
+
153
+#==============================================================================
154
+# Directories & Dependencies
155
+BLD_DIR := bin/$(BUILD)
156
+ifeq ($(BUILD),Tests)
157
+	BLD_DIR := bin/Release
158
+endif
159
+BLD_DIR := $(BLD_DIR:%/=%)
160
+_BASENAME := $(basename $(NAME))
161
+ifeq ($(BUILD_STATIC),true)
162
+ifeq ($(suffix $(NAME)),$(filter $(suffix $(NAME)),.dll .dylib .so))
163
+ifneq ($(suffix $(NAME)),)
164
+	NAME := $(_BASENAME)-s.a
165
+endif
166
+endif
167
+endif
168
+TARGET := $(BLD_DIR)/$(NAME)
169
+
170
+ifneq ($(SRC_TARGET),)
171
+	LIB_DIRS := $(LIB_DIRS) $(BLD_DIR)
172
+endif
173
+_LIB_DIRS := $(LIB_DIR:%=-L%/) $(LIB_DIRS:%=-L%)
174
+
175
+_SOURCES_IF_RC := $(if $(filter windows,$(PLATFORM)),$(SOURCE_FILES),$(SOURCE_FILES:%.rc=))
176
+
177
+OBJ_DIR := $(BLD_DIR)/obj$(_SRC_TARGET)
178
+_OBJS := $(_SOURCES_IF_RC:.c=.c.o)
179
+_OBJS := $(_OBJS:.cpp=.cpp.o)
180
+_OBJS := $(_OBJS:.cc=.cc.o)
181
+_OBJS := $(_OBJS:.rc=.res)
182
+OBJS := $(_OBJS:%=$(OBJ_DIR)/%)
183
+OBJ_SUBDIRS := $(PROJECT_DIRS:%=$(OBJ_DIR)/%)
184
+
185
+DEP_DIR := $(BLD_DIR)/dep$(_SRC_TARGET)
186
+_DEPS := $(_SOURCES_IF_RC:%=%.d)
187
+DEPS := $(_DEPS:%=$(DEP_DIR)/%) $(DEP_DIR)/$(PRECOMPILED_HEADER).d
188
+DEP_SUBDIRS := $(PROJECT_DIRS:%=$(DEP_DIR)/%)
189
+
190
+_PCH_HFILE := $(shell find $(SRC_DIR) -name '$(PRECOMPILED_HEADER).hpp' -o -name '$(PRECOMPILED_HEADER).h' -o -name '$(PRECOMPILED_HEADER).hh')
191
+_PCH_HFILE := $(_PCH_HFILE:$(SRC_DIR)/%=%)
192
+_PCH_EXT := $(_PCH_HFILE:$(PRECOMPILED_HEADER).%=%)
193
+_PCH_COMPILER_EXT := $(if $(filter osx,$(PLATFORM)),p,g)ch
194
+
195
+_SYMBOLS := $(if $(filter osx,$(PLATFORM)),,$(if $(filter Release,$(BUILD)),-s,))
196
+
197
+
198
+_PCH := $(_PCH_HFILE:%=$(OBJ_DIR)/%)
199
+ifneq ($(_PCH),)
200
+	_PCH_GCH := $(_PCH).$(_PCH_COMPILER_EXT)
201
+endif
202
+
203
+ifeq ($(DUMP_ASSEMBLY),true)
204
+	ASM_DIR := $(BLD_DIR)/asm$(_SRC_TARGET)
205
+	_ASMS := $(_OBJS:%.res=)
206
+	_ASMS := $(_ASMS:.o=.o.asm)
207
+	ASMS := $(_ASMS:%=$(ASM_DIR)/%)
208
+	ASM_SUBDIRS := $(PROJECT_DIRS:%=$(ASM_DIR)/%)
209
+endif
210
+
211
+_DIRECTORIES := $(sort bin $(BLD_DIR) $(OBJ_DIR) $(OBJ_SUBDIRS) $(DEP_DIR) $(DEP_SUBDIRS) $(ASM_DIR) $(ASM_SUBDIRS))
212
+
213
+_CLEAN := $(filter true,$(CLEAN_OUTPUT))
214
+
215
+_TARGET_DEPS := $(_PCH_GCH) $(OBJS) $(ASMS) $(TEST_DIR)
216
+
217
+# Quiet flag
218
+_Q := $(if $(_CLEAN),@)
219
+
220
+#==============================================================================
221
+# Compiler & flags
222
+CC?=g++
223
+RC?=windres.exe
224
+CFLAGS?=-O2 -Wall -fdiagnostics-color=always
225
+
226
+CFLAGS_DEPS = -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.Td
227
+CFLAGS_DEPS_T = -MT $@ -MMD -MP -MF $(DEP_DIR)/.$(TEST_DIR)/$*.Td
228
+PCH_COMPILE = $(CC) $(CFLAGS_DEPS) $(_BUILD_MACROS) $(CFLAGS) $(_INCLUDE_DIRS) -o $@ -c $<
229
+ifneq ($(_PCH),)
230
+	_INCLUDE_PCH := -include $(_PCH)
231
+endif
232
+
233
+OBJ_COMPILE = $(CC) $(CFLAGS_DEPS) $(_BUILD_MACROS) $(_INCLUDE_DIRS) $(_INCLUDE_PCH) $(CFLAGS) -o $@ -c $<
234
+OBJ_COMPILE_T = $(CC) $(CFLAGS_DEPS_T) $(_BUILD_MACROS) $(_INCLUDE_DIRS) $(_INCLUDE_PCH) $(CFLAGS) -o $@ -c $<
235
+
236
+RC_COMPILE = -$(RC) -J rc -O coff --preprocessor-arg=-MT --preprocessor-arg=$@ --preprocessor-arg=-MMD --preprocessor-arg=-MP --preprocessor-arg=-MF --preprocessor-arg=$(DEP_DIR)/$*.rc.Td $(_BUILD_MACROS) $(_INCLUDE_DIRS) -i $< -o $@
237
+ifeq ($(PLATFORM),osx)
238
+	ASM_COMPILE = otool -tvV $< | c++filt > $@
239
+else
240
+	ASM_COMPILE = objdump -d -C -Mintel $< > $@
241
+endif
242
+POST_COMPILE = mv -f $(DEP_DIR)/$*.Td $(DEP_DIR)/$*.d && touch $@
243
+POST_COMPILE_T = mv -f $(DEP_DIR)/.$(TEST_DIR)/$*.Td $(DEP_DIR)/.$(TEST_DIR)/$*.d && touch $@
244
+POST_COMPILE_RC = mv -f $(DEP_DIR)/$*.rc.Td $(DEP_DIR)/$*.rc.d && touch $@
245
+
246
+#==============================================================================
247
+# Unicode
248
+UNI_COPY := ➦
249
+UNI_LINK := ⇛
250
+ifeq ($(PLATFORM),osx)
251
+	UNI_COPY := ➦
252
+	UNI_LINK := ⇛
253
+endif
254
+ifeq ($(PLATFORM),windows)
255
+	UNI_COPY := \xE2\x9E\xA6
256
+	UNI_LINK := \xE2\x87\x9B
257
+endif
258
+
259
+# Misc
260
+ORIGIN_FLAG := '-Wl,-R$$ORIGIN'
261
+ifeq ($(PLATFORM),osx)
262
+	ORIGIN_FLAG :=
263
+endif
264
+
265
+#==============================================================================
266
+# Build Scripts
267
+all:
268
+	@$(MAKE) makepch
269
+	@$(MAKE) -j$(MAX_PARALLEL_JOBS) makebuild
270
+.DELETE_ON_ERROR: all
271
+
272
+rebuild: clean all
273
+.PHONY: rebuild
274
+
275
+buildprod: all makeproduction
276
+.PHONY: buildprod
277
+
278
+#==============================================================================
279
+# Functions
280
+color_blue := \033[0;34m
281
+color_purple := \033[0;35m
282
+
283
+define compile_with
284
+	$(if $(_CLEAN),@printf '   $(color_blue)$($(2):$(OBJ_DIR)/%=%)\n')
285
+	$(_Q)$(3) && $(4)
286
+endef
287
+
288
+define linking_with
289
+	$(if $(_CLEAN),@printf '\n$(color_blue)$(UNI_LINK)  Linking: $(1)')
290
+endef
291
+
292
+define build_deps
293
+	$(foreach dep,$(BUILD_DEPENDENCIES),$(call copy_to,$(dep),$(BLD_DIR)))
294
+endef
295
+
296
+MKDIR := $(_Q)mkdir -p
297
+
298
+makepch: $(_PCH_GCH)
299
+	@printf ''
300
+.PHONY: makepch
301
+
302
+makebuild: $(TARGET)
303
+ifeq ($(SRC_TARGET),)
304
+	@printf '   $(color_blue)Target is up to date.\n'
305
+else
306
+	@printf '   $(color_blue)$(NAME): Target is up to date.\n'
307
+endif
308
+.PHONY: makebuild
309
+
310
+#==============================================================================
311
+# Build Recipes
312
+$(OBJ_DIR)/%.o: $(SRC_DIR)/%
313
+$(OBJ_DIR)/%.o: $(SRC_DIR)/% $(_PCH_GCH) $(DEP_DIR)/%.d | $(_DIRECTORIES)
314
+	$(call compile_with,@,<,$(OBJ_COMPILE),$(POST_COMPILE))
315
+
316
+$(OBJ_DIR)/.$(TEST_DIR)/%.o: $(TEST_DIR)/%
317
+$(OBJ_DIR)/.$(TEST_DIR)/%.o: $(TEST_DIR)/% $(_PCH_GCH) $(DEP_DIR)/.$(TEST_DIR)/%.d | $(_DIRECTORIES)
318
+	$(call compile_with,@,<,$(OBJ_COMPILE_T),$(POST_COMPILE_T))
319
+
320
+$(OBJ_DIR)/%.$(_PCH_EXT).$(_PCH_COMPILER_EXT) : $(SRC_DIR)/%.$(_PCH_EXT)
321
+$(OBJ_DIR)/%.$(_PCH_EXT).$(_PCH_COMPILER_EXT) : $(SRC_DIR)/%.$(_PCH_EXT) $(DEP_DIR)/%.d | $(_DIRECTORIES)
322
+	$(call compile_with,@,<,$(PCH_COMPILE),$(POST_COMPILE))
323
+
324
+$(OBJ_DIR)/%.res: $(SRC_DIR)/%.rc
325
+$(OBJ_DIR)/%.res: $(SRC_DIR)/%.rc $(DEP_DIR)/%.rc.d | $(_DIRECTORIES)
326
+	$(call compile_with,@,<,$(RC_COMPILE),$(POST_COMPILE_RC))
327
+
328
+$(ASM_DIR)/%.o.asm: $(OBJ_DIR)/%.o
329
+	$(if $(_CLEAN),@printf '   $(color_purple)$@\n')
330
+	$(_Q)$(ASM_COMPILE)
331
+
332
+$(BLD_DIR)/lib%-s.a: $(_TARGET_DEPS)
333
+	$(call linking_with,$@)
334
+	-$(_Q)rm -rf $@
335
+	$(_Q)ar -c -r -s $@ $(OBJS)
336
+	@printf '\n'
337
+
338
+$(BLD_DIR)/$(_BASENAME).dll: $(_TARGET_DEPS)
339
+	$(call linking_with,$@)
340
+	-$(_Q)rm -rf $(BLD_DIR)/$(_BASENAME).def $(BLD_DIR)/$(_BASENAME).a
341
+	$(_Q)$(CC) -shared -Wl,--output-def="$(BLD_DIR)/$(_BASENAME).def" -Wl,--out-implib="$(BLD_DIR)/$(_BASENAME).a" -Wl,--dll $(_LIB_DIRS) $(OBJS) -o $@ $(_SYMBOLS) $(_LINK_LIBRARIES) $(BUILD_FLAGS)
342
+	@printf '\n'
343
+
344
+$(BLD_DIR)/$(_BASENAME).so: $(_TARGET_DEPS)
345
+	$(call linking_with,$@)
346
+	$(_Q)$(CC) -shared $(_LIB_DIRS) $(OBJS) -o $@ $(_SYMBOLS) $(_LINK_LIBRARIES) $(BUILD_FLAGS)
347
+	@printf '\n'
348
+
349
+$(BLD_DIR)/$(_BASENAME).dylib: $(_TARGET_DEPS)
350
+	$(call linking_with,$(BLD_DIR)/$(_BASENAME).dylib)
351
+	$(_Q)$(CC) -dynamiclib -undefined suppress -flat_namespace $(_LIB_DIRS) $(OBJS) -o $@ $(_SYMBOLS) $(_LINK_LIBRARIES) $(BUILD_FLAGS)
352
+	@printf '\n'
353
+
354
+$(BLD_DIR)/$(_BASENAME).exe: $(_TARGET_DEPS)
355
+	$(call linking_with,$@)
356
+	$(_Q)$(CC) $(_LIB_DIRS) $(_SYMBOLS) -o $@ $(ORIGIN_FLAG) $(OBJS) $(_LINK_LIBRARIES) $(BUILD_FLAGS)
357
+	@printf '\n'
358
+	$(call build_deps)
359
+
360
+$(BLD_DIR)/$(_BASENAME): $(_TARGET_DEPS)
361
+	$(call linking_with,$@)
362
+	$(_Q)$(CC) $(_LIB_DIRS) $(_SYMBOLS) -o $@ $(ORIGIN_FLAG) $(OBJS) $(_LINK_LIBRARIES) $(BUILD_FLAGS)
363
+	@printf '\n'
364
+	$(call build_deps)
365
+
366
+$(_DIRECTORIES):
367
+	$(if $(_CLEAN),,@printf '\$(color_blue)')
368
+	$(MKDIR) $@
369
+
370
+clean:
371
+	$(if $(_CLEAN),@prtinf '   $(color_blue)Cleaning old build files & folders...\n\n')
372
+	$(_Q)$(RM) $(TARGET) $(DEPS) $(OBJS)
373
+.PHONY: clean
374
+
375
+#==============================================================================
376
+# Production recipes
377
+
378
+rmprod:
379
+	@printf '\n'
380
+	-$(_Q)rm -rf $(if $(filter osx,$(PLATFORM)),$(PRODUCTION_FOLDER_MACOS),$(PRODUCTION_FOLDER))
381
+ifeq ($(PLATFORM),linux)
382
+	-$(_Q)rm -rf ~/.local/share/applications/$(NAME).desktop
383
+endif
384
+.PHONY: rmprod
385
+
386
+mkdirprod:
387
+	$(MKDIR) $(PRODUCTION_FOLDER)
388
+.PHONY: mkdirprod
389
+
390
+define do_copy_to_clean
391
+	@printf  '$(color_blue)$(UNI_COPY)  Copying \"$(1)\" to \"$(CURDIR)/$(2)\"\n'
392
+	$(shell cp -r $(1) $(2))
393
+endef
394
+
395
+define do_copy_to
396
+	@printf  '$(color_blue)cp -r $(1) $(2)\n'
397
+	$(shell cp -r $(1) $(2))
398
+endef
399
+
400
+define copy_to
401
+	$(if $(wildcard $(2)/$(notdir $(1))),,$(if $(_CLEAN),$(call do_copy_to_clean,$(1),$(2)),$(call do_copy_to,$(1),$(2))))
402
+endef
403
+
404
+releasetoprod: $(TARGET)
405
+ifeq ($(PLATFORM),osx)
406
+	@printf '   $(color_blue)Creating the MacOS application bundle...\n'
407
+	@printf '\n'
408
+	$(MKDIR) $(PRODUCTION_FOLDER)/Resources $(PRODUCTION_FOLDER)/Frameworks $(PRODUCTION_FOLDER)/MacOS
409
+	$(_Q)sips -s format icns env/osx/$(PRODUCTION_MACOS_ICON).png --out $(PRODUCTION_FOLDER)/Resources/$(PRODUCTION_MACOS_ICON).icns
410
+	@printf '\n'
411
+	$(_Q)plutil -convert binary1 env/osx/Info.plist.json -o $(PRODUCTION_FOLDER)/Info.plist
412
+	$(_Q)plutil -replace CFBundleExecutable -string $(NAME) $(PRODUCTION_FOLDER)/Info.plist
413
+	$(_Q)plutil -replace CFBundleName -string $(PRODUCTION_MACOS_BUNDLE_NAME) $(PRODUCTION_FOLDER)/Info.plist
414
+	$(_Q)plutil -replace CFBundleIconFile -string $(PRODUCTION_MACOS_ICON) $(PRODUCTION_FOLDER)/Info.plist
415
+	$(_Q)plutil -replace CFBundleDisplayName -string "$(PRODUCTION_MACOS_BUNDLE_DISPLAY_NAME)" $(PRODUCTION_FOLDER)/Info.plist
416
+	$(_Q)plutil -replace CFBundleIdentifier -string com.$(PRODUCTION_MACOS_BUNDLE_DEVELOPER).$(PRODUCTION_MACOS_BUNDLE_NAME) $(PRODUCTION_FOLDER)/Info.plist
417
+	$(_Q)cp $(TARGET) $(PRODUCTION_FOLDER)/MacOS
418
+	$(_Q)chmod +x $(PRODUCTION_FOLDER)/MacOS/$(NAME)
419
+else ifeq ($(PLATFORM),linux)
420
+	$(_Q)cp $(TARGET) $(PRODUCTION_FOLDER)
421
+	$(_Q)cp env/linux/$(PRODUCTION_LINUX_ICON).png $(PRODUCTION_FOLDER)/$(PRODUCTION_LINUX_ICON).png
422
+	$(_Q)cp env/linux/exec.desktop $(PRODUCTION_FOLDER)/$(NAME).desktop
423
+	$(_Q)sed -i 's/^Exec=.*/Exec=$(_LINUX_GREP_CWD)\/$(PRODUCTION_FOLDER)\/$(NAME)/' $(PRODUCTION_FOLDER)/$(NAME).desktop
424
+	$(_Q)sed -i 's/^Path=.*/Path=$(_LINUX_GREP_CWD)\/$(PRODUCTION_FOLDER)/' $(PRODUCTION_FOLDER)/$(NAME).desktop
425
+	$(_Q)sed -i 's/^Name=.*/Name=$(PRODUCTION_LINUX_APP_NAME)/' $(PRODUCTION_FOLDER)/$(NAME).desktop
426
+	$(_Q)sed -i 's/^Comment=.*/Comment=$(PRODUCTION_LINUX_APP_COMMENT)/' $(PRODUCTION_FOLDER)/$(NAME).desktop
427
+	$(_Q)sed -i 's/^Icon=.*/Icon=$(_LINUX_GREP_CWD)\/$(PRODUCTION_FOLDER)\/$(PRODUCTION_LINUX_ICON).png/' $(PRODUCTION_FOLDER)/$(NAME).desktop
428
+	$(_Q)chmod +x $(PRODUCTION_FOLDER)/$(NAME)
429
+	$(_Q)chmod +x $(PRODUCTION_FOLDER)/$(NAME).desktop
430
+	$(_Q)cp $(PRODUCTION_FOLDER)/$(NAME).desktop ~/.local/share/applications
431
+else
432
+	$(_Q)cp $(TARGET) $(PRODUCTION_FOLDER)
433
+	$(if $(_CLEAN),,@printf '\n')
434
+endif
435
+.PHONY: releasetoprod
436
+
437
+makeproduction: rmprod mkdirprod releasetoprod
438
+ifneq ($(PRODUCTION_DEPENDENCIES),)
439
+	@printf '   $(color_blue)Adding dynamic libraries & project dependencies...\n'
440
+	@printf '\n'
441
+	$(foreach dep,$(PRODUCTION_DEPENDENCIES),$(call copy_to,$(dep),$(PRODUCTION_FOLDER_RESOURCES)))
442
+	$(foreach excl,$(PRODUCTION_EXCLUDE),$(shell find $(PRODUCTION_FOLDER_RESOURCES) -name '$(excl)' -delete))
443
+endif
444
+ifeq ($(PLATFORM),osx)
445
+	$(foreach dylib,$(PRODUCTION_MACOS_DYLIBS),$(call copy_to,$(dylib),$(PRODUCTION_FOLDER)/MacOS))
446
+	$(_Q)install_name_tool -add_rpath @executable_path/../Frameworks $(PRODUCTION_FOLDER)/MacOS/$(NAME)
447
+	$(_Q)install_name_tool -add_rpath @loader_path/.. $(PRODUCTION_FOLDER)/MacOS/$(NAME)
448
+	$(foreach dylib,$(PRODUCTION_MACOS_DYLIBS),$(shell install_name_tool -change @rpath/$(notdir $(dylib)) @rpath/MacOS/$(notdir $(dylib)) $(PRODUCTION_FOLDER)/MacOS/$(NAME)))
449
+	$(foreach dylib,$(PRODUCTION_MACOS_DYLIBS),$(shell install_name_tool -change $(notdir $(dylib)) @rpath/MacOS/$(notdir $(dylib)) $(PRODUCTION_FOLDER)/MacOS/$(NAME)))
450
+	$(foreach dylib,$(PRODUCTION_MACOS_DYLIBS),$(shell install_name_tool -change $(dylib) @rpath/MacOS/$(notdir $(dylib)) $(PRODUCTION_FOLDER)/MacOS/$(NAME)))
451
+	$(foreach framework,$(PRODUCTION_MACOS_FRAMEWORKS),$(call copy_to,$(framework),$(PRODUCTION_FOLDER)/Frameworks))
452
+ifeq ($(PRODUCTION_MACOS_MAKE_DMG),true)
453
+	$(shell hdiutil detach /Volumes/$(PRODUCTION_MACOS_BUNDLE_NAME)/ &> /dev/null)
454
+	@printf '\n'
455
+	@printf '   $(color_blue)Creating the dmg image for the application...\n'
456
+	@printf '\n'
457
+	$(_Q)hdiutil create -megabytes 54 -fs HFS+ -volname $(PRODUCTION_MACOS_BUNDLE_NAME) $(PRODUCTION_FOLDER_MACOS)/.tmp.dmg > /dev/null
458
+	$(_Q)hdiutil attach $(PRODUCTION_FOLDER_MACOS)/.tmp.dmg > /dev/null
459
+	$(_Q)cp -r $(PRODUCTION_FOLDER_MACOS)/$(PRODUCTION_MACOS_BUNDLE_NAME).app /Volumes/$(PRODUCTION_MACOS_BUNDLE_NAME)/
460
+	-$(_Q)rm -rf /Volumes/$(PRODUCTION_MACOS_BUNDLE_NAME)/.fseventsd
461
+	$(MKDIR) /Volumes/$(PRODUCTION_MACOS_BUNDLE_NAME)/.background
462
+	$(_Q)tiffutil -cathidpicheck $(PRODUCTION_MACOS_BACKGROUND).png $(PRODUCTION_MACOS_BACKGROUND)@2x.png -out /Volumes/$(PRODUCTION_MACOS_BUNDLE_NAME)/.background/background.tiff
463
+	$(_Q)ln -s /Applications /Volumes/$(PRODUCTION_MACOS_BUNDLE_NAME)/Applications
464
+	$(_Q)appName=$(PRODUCTION_MACOS_BUNDLE_NAME) osascript env/osx/dmg.applescript
465
+	$(_Q)hdiutil detach /Volumes/$(PRODUCTION_MACOS_BUNDLE_NAME)/ > /dev/null
466
+	$(_Q)hdiutil convert $(PRODUCTION_FOLDER_MACOS)/.tmp.dmg -format UDZO -o $(PRODUCTION_FOLDER_MACOS)/$(PRODUCTION_MACOS_BUNDLE_NAME).dmg > /dev/null
467
+	$(_Q)rm -f $(PRODUCTION_FOLDER_MACOS)/.tmp.dmg
468
+	@printf '\n'
469
+	@printf '   $(color_blue)Created $(PRODUCTION_FOLDER_MACOS)/$(PRODUCTION_MACOS_BUNDLE_NAME).dmg\n'
470
+endif
471
+endif
472
+.PHONY: makeproduction
473
+
474
+#==============================================================================
475
+# Dependency recipes
476
+$(DEP_DIR)/%.d: ;
477
+.PRECIOUS: $(DEP_DIR)/%.d
478
+
479
+include $(wildcard $(DEPS))

+ 7
- 0
README.md View File

@@ -0,0 +1,7 @@
1
+# CppPaintingAgents
2
+
3
+La simu multi-agents qui repeint une image, mais en c++
4
+
5
+
6
+Boilerplate pompé ici : https://github.com/andrew-r-king/sfml-vscode-boilerplate
7
+

+ 302
- 0
build.sh View File

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

+ 3
- 0
content/stub.txt View File

@@ -0,0 +1,3 @@
1
+Note:
2
+
3
+Run the 'Build: Production' command to see me get copied into the build folder, since 'content' is defined in env/windows.release.mk!

+ 30
- 0
env/.all.mk View File

@@ -0,0 +1,30 @@
1
+MAX_PARALLEL_JOBS := 8
2
+CLEAN_OUTPUT := true
3
+DUMP_ASSEMBLY := false
4
+
5
+_CFLAGS_STD := -std=c++17
6
+_CFLAGS_WARNINGS := -Wall -Werror -Wextra -Wpedantic -Wunreachable-code -Wunused -Wignored-qualifiers -Wcast-align -Wformat-nonliteral -Wformat=2 -Winvalid-pch -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wredundant-decls -Wswitch-default -Wodr
7
+_CFLAGS_OTHER := -fdiagnostics-color=always
8
+CFLAGS := $(_CFLAGS_STD) $(_CFLAGS_WARNINGS) $(_CFLAGS_OTHER)
9
+
10
+LINK_LIBRARIES := \
11
+	sfml-graphics \
12
+	sfml-audio \
13
+	sfml-network \
14
+	sfml-window \
15
+	sfml-system
16
+
17
+PRECOMPILED_HEADER := PCH
18
+
19
+PRODUCTION_FOLDER := build
20
+
21
+PRODUCTION_EXCLUDE := \
22
+	*.psd \
23
+	*.rar \
24
+	*.7z \
25
+	Thumbs.db \
26
+	.DS_Store
27
+
28
+PRODUCTION_DEPENDENCIES := \
29
+	content
30
+

+ 7
- 0
env/.debug.mk View File

@@ -0,0 +1,7 @@
1
+CFLAGS := -g $(CFLAGS) -pg
2
+
3
+BUILD_FLAGS := \
4
+	-pg
5
+
6
+BUILD_MACROS := \
7
+	_DEBUG

+ 1
- 0
env/.release.mk View File

@@ -0,0 +1 @@
1
+CFLAGS := -O2 $(CFLAGS)

+ 22
- 0
env/linux.all.mk View File

@@ -0,0 +1,22 @@
1
+CC := g++
2
+CFLAGS := $(CFLAGS) -fpic
3
+
4
+LIB_DIRS := \
5
+	/usr/local/lib
6
+
7
+INCLUDE_DIRS := \
8
+	/usr/local/include
9
+
10
+BUILD_FLAGS := \
11
+	$(BUILD_FLAGS) \
12
+	-pthread
13
+
14
+LINK_LIBRARIES := \
15
+	$(LINK_LIBRARIES) \
16
+	stdc++fs \
17
+	X11
18
+
19
+PRODUCTION_LINUX_ICON := sfml
20
+
21
+PRODUCTION_LINUX_APP_NAME := SFML Boilerplate
22
+PRODUCTION_LINUX_APP_COMMENT := My SFML Game

+ 10
- 0
env/linux/exec.desktop View File

@@ -0,0 +1,10 @@
1
+[Desktop Entry]
2
+Version=1.0
3
+Type=Application
4
+Categories=Game;Application;
5
+Terminal=false
6
+Exec=${NAME}
7
+Path=${Path}
8
+Name=${PRODUCTION_LINUX_APP_NAME}
9
+Comment=${PRODUCTION_LINUX_APP_COMMENT}
10
+Icon=${PRODUCTION_LINUX_ICON}

BIN
env/linux/sfml.png View File


+ 39
- 0
env/osx.all.mk View File

@@ -0,0 +1,39 @@
1
+CC := clang++
2
+CFLAGS := $(CFLAGS:-s=)
3
+
4
+LIB_DIRS := \
5
+	/usr/local/lib
6
+
7
+INCLUDE_DIRS := \
8
+	/usr/local/include
9
+
10
+BUILD_FLAGS :=
11
+
12
+MACOS_FRAMEWORK_PATHS := \
13
+	/Library/Frameworks
14
+
15
+# Name, no extension (eg. CoreFoundation, ogg)
16
+MACOS_FRAMEWORKS := \
17
+	CoreFoundation
18
+
19
+# Icon .png
20
+PRODUCTION_MACOS_ICON := sfml
21
+
22
+PRODUCTION_DEPENDENCIES := \
23
+	$(PRODUCTION_DEPENDENCIES)
24
+
25
+PRODUCTION_MACOS_BUNDLE_DEVELOPER := developer
26
+PRODUCTION_MACOS_BUNDLE_DISPLAY_NAME := SFML Boilerplate
27
+PRODUCTION_MACOS_BUNDLE_NAME := SFML Boilerplate
28
+PRODUCTION_MACOS_MAKE_DMG := true
29
+PRODUCTION_MACOS_BACKGROUND := dmg-background
30
+
31
+PRODUCTION_MACOS_DYLIBS := \
32
+	/usr/local/lib/libsfml-graphics.2.5 \
33
+	/usr/local/lib/libsfml-audio.2.5 \
34
+	/usr/local/lib/libsfml-network.2.5 \
35
+	/usr/local/lib/libsfml-window.2.5 \
36
+	/usr/local/lib/libsfml-system.2.5
37
+
38
+# Path, no extension (eg. /Library/Frameworks/ogg)
39
+PRODUCTION_MACOS_FRAMEWORKS :=

+ 3
- 0
env/osx.debug.mk View File

@@ -0,0 +1,3 @@
1
+CFLAGS := -g $(_CFLAGS_STD) $(_CFLAGS_WARNINGS) $(_CFLAGS_OTHER)
2
+
3
+BUILD_FLAGS := $(BUILD_FLAGS:-pg=)

+ 13
- 0
env/osx/Info.plist.json View File

@@ -0,0 +1,13 @@
1
+{
2
+	"CFBundleName": "${PRODUCTION_MACOS_BUNDLE_NAME}",
3
+	"CFBundleDisplayName": "${PRODUCTION_MACOS_BUNDLE_DISPLAY_NAME}",
4
+	"CFBundleIdentifier": "com.${PRODUCTION_MACOS_BUNDLE_DEVELOPER}.${PRODUCTION_MACOS_BUNDLE_NAME}",
5
+	"CFBundleVersion": "0.0.1.1",
6
+	"CFBundleDevelopmentRegion": "en",
7
+	"CFBundleInfoDictionaryVersion": "6.0",
8
+	"CFBundlePackageType": "APPL",
9
+	"CFBundleSignature": "????",
10
+	"CFBundleExecutable": "${NAME}",
11
+	"CFBundleIconFile": "${MACOS_ICON}",
12
+	"NSHighResolutionCapable": true
13
+}

BIN
env/osx/dmg-background.png View File


BIN
env/osx/dmg-background@2x.png View File


+ 23
- 0
env/osx/dmg.applescript View File

@@ -0,0 +1,23 @@
1
+set appName to system attribute "appName"
2
+set appNameExt to appName & ".app"
3
+
4
+tell application "Finder"
5
+	tell disk appName
6
+		open
7
+		set current view of container window to icon view
8
+		set toolbar visible of container window to false
9
+		set statusbar visible of container window to false
10
+		set the bounds of container window to {400, 100, 1060, 500}
11
+		set viewOptions to the icon view options of container window
12
+		set arrangement of viewOptions to not arranged
13
+		set icon size of viewOptions to 168
14
+		set background picture of viewOptions to file ".background:background.tiff"
15
+		set position of item appNameExt of container window to {180, 182}
16
+		set position of item "Applications" of container window to {480, 182}
17
+		set position of item ".background" of container window to {180, 582}
18
+		-- set position of item ".fseventsd" of container window to {480, 582}
19
+		close
20
+		update without registering applications
21
+		delay 2
22
+	end tell
23
+end tell

BIN
env/osx/sfml.png View File


+ 20
- 0
env/rpi.release.mk View File

@@ -0,0 +1,20 @@
1
+CC := g++-8.1.0
2
+CFLAGS := $(CFLAGS) -fpic
3
+MAX_PARALLEL_JOBS := 4
4
+
5
+LIB_DIRS := \
6
+	/usr/local/gcc-8.1.0/lib \
7
+	/usr/local/lib
8
+
9
+INCLUDE_DIRS := \
10
+	/usr/local/gcc-8.1.0/include \
11
+	/usr/local/include
12
+
13
+BUILD_DEPENDENCIES :=
14
+
15
+LINK_LIBRARIES := \
16
+	$(LINK_LIBRARIES) \
17
+	X11
18
+
19
+BUILD_FLAGS := \
20
+	-pthread

+ 31
- 0
env/windows.all.mk View File

@@ -0,0 +1,31 @@
1
+CC := g++.exe
2
+
3
+_MINGW := C:/mingw32/bin
4
+_SFML := C:/SFML-2.5.1
5
+_SFML_BIN := $(_SFML)/bin
6
+
7
+LIB_DIRS := \
8
+	$(_SFML)/lib
9
+
10
+INCLUDE_DIRS := \
11
+	$(_SFML)/include
12
+
13
+BUILD_DEPENDENCIES := \
14
+	$(_SFML_BIN)/openal32.dll
15
+
16
+LINK_LIBRARIES := \
17
+	$(LINK_LIBRARIES) \
18
+	stdc++fs \
19
+	gdi32
20
+
21
+PRODUCTION_DEPENDENCIES := \
22
+	$(PRODUCTION_DEPENDENCIES) \
23
+	$(_MINGW)/libgcc_s_dw2-1.dll \
24
+	$(_MINGW)/libstdc++-6.dll \
25
+	$(_MINGW)/libwinpthread-1.dll \
26
+	$(_SFML_BIN)/openal32.dll \
27
+	$(_SFML_BIN)/sfml-audio-2.dll \
28
+	$(_SFML_BIN)/sfml-graphics-2.dll \
29
+	$(_SFML_BIN)/sfml-network-2.dll \
30
+	$(_SFML_BIN)/sfml-system-2.dll \
31
+	$(_SFML_BIN)/sfml-window-2.dll

+ 8
- 0
env/windows.debug.mk View File

@@ -0,0 +1,8 @@
1
+LINK_LIBRARIES := \
2
+	sfml-graphics-d \
3
+	sfml-audio-d \
4
+	sfml-network-d \
5
+	sfml-window-d \
6
+	sfml-system-d \
7
+	stdc++fs \
8
+	gdi32

+ 2
- 0
env/windows.release.mk View File

@@ -0,0 +1,2 @@
1
+BUILD_FLAGS := \
2
+	-mwindows

BIN
env/windows/app.ico View File


+ 40
- 0
env/windows/app.manifest View File

@@ -0,0 +1,40 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3
+	<assemblyIdentity
4
+		name="SFML Boilerplate"
5
+		processorArchitecture="ia64"
6
+		version="1.0.0.0"
7
+		type="win32" />
8
+	<description>My SFML Game</description>
9
+	<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
10
+		<security>
11
+			<requestedPrivileges>
12
+				<requestedExecutionLevel level="asInvoker" uiAccess="false" />
13
+			</requestedPrivileges>
14
+		</security>
15
+	</trustInfo>
16
+	<application xmlns="urn:schemas-microsoft-com:asm.v3">
17
+		<windowsSettings xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">
18
+			<disableWindowFiltering>true</disableWindowFiltering>
19
+		</windowsSettings>
20
+		<windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
21
+			<dpiAwareness>permonitorv2, permonitor, unaware</dpiAwareness>
22
+      		<longPathAware>true</longPathAware>
23
+		</windowsSettings>
24
+		<windowsSettings xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">
25
+			<gdiScaling>false</gdiScaling>
26
+		</windowsSettings>
27
+		<windowsSettings xmlns="http://schemas.microsoft.com/SMI/2020/WindowsSettings">
28
+			<heapType>SegmentHeap</heapType>
29
+		</windowsSettings>
30
+	</application>
31
+	<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
32
+		<application>
33
+			<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" /> <!-- Windows Vista/Server 2008 -->
34
+			<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /> <!-- Windows 7/Server 2008 R2 -->
35
+			<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /> <!-- Windows 8/Server 2012 -->
36
+			<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /> <!-- Windows 8.1/Server 2012 R2 -->
37
+			<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> <!-- Windows 10 -->
38
+		</application>
39
+	</compatibility>
40
+</assembly>

BIN
env/windows/icon_128.png View File


BIN
env/windows/icon_16.png View File


BIN
env/windows/icon_256.png View File


BIN
env/windows/icon_32.png View File


BIN
env/windows/icon_48.png View File


BIN
env/windows/icon_64.png View File


+ 28
- 0
env/windows/win-make_icon_from256.sh View File

@@ -0,0 +1,28 @@
1
+#!/bin/bash
2
+echo
3
+
4
+if [[ $OSTYPE == 'msys' || $OSTYPE == 'win32' ]]; then
5
+	if hash magick 2>/dev/null; then
6
+		read -p "Icon Prefix (\"icon_256\"): "  icon_prefix
7
+		if [[ $icon_prefix == '' ]]; then
8
+			icon_prefix='icon_256'
9
+		fi
10
+
11
+		output_file=app
12
+		cmd="magick convert ${icon_prefix}.png -define icon:auto-resize=256,128,64,48,32,16 app.ico"
13
+		echo "$cmd"
14
+		$cmd
15
+
16
+		echo
17
+		echo "Successfully created $output_file.ico!"
18
+	else
19
+		echo 'This script requires the "ImageMagick" command-line utility'
20
+		echo 'Download from: https://www.imagemagick.org/script/download.php#windows'
21
+		echo '(Install to default location)'
22
+	fi
23
+else
24
+	echo 'This script should only run in win32'
25
+fi
26
+
27
+echo
28
+read -rsn1 -p"Press any key to continue";echo

+ 28
- 0
env/windows/win-make_icon_from_all.sh View File

@@ -0,0 +1,28 @@
1
+#!/bin/bash
2
+echo
3
+
4
+if [[ $OSTYPE == 'msys' || $OSTYPE == 'win32' ]]; then
5
+	if hash magick 2>/dev/null; then
6
+		read -p "Icon Prefix (\"icon\"): "  icon_prefix
7
+		if [[ $icon_prefix == '' ]]; then
8
+			icon_prefix='icon'
9
+		fi
10
+
11
+		output_file=app
12
+		cmd="magick convert ${icon_prefix}_256.png ${icon_prefix}_128.png ${icon_prefix}_64.png ${icon_prefix}_48.png ${icon_prefix}_32.png ${icon_prefix}_16.png $output_file.ico"
13
+		echo "$cmd"
14
+		$cmd
15
+
16
+		echo
17
+		echo "Successfully created $output_file.ico!"
18
+	else
19
+		echo 'This script requires the "ImageMagick" command-line utility'
20
+		echo 'Download from: https://www.imagemagick.org/script/download.php#windows'
21
+		echo '(Install to default location)'
22
+	fi
23
+else
24
+	echo 'This script should only run in win32'
25
+fi
26
+
27
+echo
28
+read -rsn1 -p"Press any key to continue";echo

+ 18
- 0
lib/Agents/Agent.hpp View File

@@ -0,0 +1,18 @@
1
+#ifndef AGENT_H
2
+#define AGENT_H
3
+#include <Agents/Perception/Perception.hpp>
4
+#include <Environment/PictureEnvironment.hpp>
5
+
6
+class Agent
7
+{
8
+public:
9
+	Perception fCurrentPerception;
10
+	PictureEnvironment* fEnvironment;
11
+	int fXPos;
12
+	int fYPos;
13
+
14
+	Agent(PictureEnvironment* iEnvironment);
15
+	void loop();
16
+};
17
+
18
+#endif // AGENT_H

+ 15
- 0
lib/Agents/Perception/Perception.hpp View File

@@ -0,0 +1,15 @@
1
+#ifndef PERCEPTION_H
2
+#define PERCEPTION_H
3
+
4
+class Perception
5
+{				 // The class
6
+public:			 // Access specifier
7
+	int fWidth;	 // Attribute (int variable)
8
+	int fHeight; // Attribute
9
+	std::vector<bool> fPercept;
10
+
11
+	Perception();
12
+	Perception(int iWidth, int iHeight);
13
+};
14
+
15
+#endif // PERCEPTION_H

+ 24
- 0
lib/Environment/PictureEnvironment.hpp View File

@@ -0,0 +1,24 @@
1
+#ifndef PICTURE_ENVIRONMENT_H
2
+#define PICTURE_ENVIRONMENT_H
3
+#include <Agents/Perception/Perception.hpp>
4
+
5
+class PictureEnvironment
6
+{				 // The class
7
+public:			 // Access specifier
8
+	int fWidth;	 // Attribute (int variable)
9
+	int fHeight; // Attribute
10
+	std::string fFilePath;
11
+	sf::RenderWindow* fWindow;
12
+	sf::Event fEvent;
13
+	sf::CircleShape fShape;
14
+
15
+	PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow);
16
+	Perception getPerception(int iX, int iY);
17
+
18
+	bool loop();
19
+
20
+private:
21
+	PictureEnvironment();
22
+};
23
+
24
+#endif // PICTURE_ENVIRONMENT_H

+ 16865
- 0
lib/catch2/catch.hpp
File diff suppressed because it is too large
View File


+ 11
- 0
src/Agents/Agent.cpp View File

@@ -0,0 +1,11 @@
1
+#include <Agents/Agent.hpp>
2
+#include <Environment/PictureEnvironment.hpp>
3
+
4
+Agent::Agent(PictureEnvironment* iEnvironment)
5
+{
6
+	fEnvironment = iEnvironment;
7
+}
8
+
9
+void Agent::loop()
10
+{
11
+}

+ 12
- 0
src/Agents/Perception/Perception.cpp View File

@@ -0,0 +1,12 @@
1
+#include <Agents/Perception/Perception.hpp>
2
+
3
+Perception::Perception()
4
+{
5
+}
6
+
7
+Perception::Perception(int iX, int iY)
8
+{
9
+	fPercept = std::vector<bool>(iX * iY);
10
+	fWidth = iX;
11
+	fHeight = iY;
12
+}

+ 67
- 0
src/Environment/PictureEnvironment.cpp View File

@@ -0,0 +1,67 @@
1
+#include <Agents/Perception/Perception.hpp>
2
+#include <Environment/PictureEnvironment.hpp>
3
+
4
+int PERCEPTION_SIZE = 4;
5
+
6
+PictureEnvironment::PictureEnvironment()
7
+{
8
+}
9
+
10
+PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow)
11
+{
12
+	fFilePath = iFilePath;
13
+
14
+	//memccpy(&fFilePath, &iFilePath, *iFilePath., 10);
15
+	std::cout << "Environement pour " << fFilePath;
16
+
17
+	fWindow = iWindow;
18
+
19
+	fShape = sf::CircleShape(fWindow->getSize().x / 2);
20
+	fShape.setFillColor(sf::Color::White);
21
+
22
+	sf::Texture shapeTexture;
23
+	if (!shapeTexture.loadFromFile(fFilePath))
24
+	{
25
+		std::cout << "\n COULDNT LOAD PICTURE\n";
26
+	}
27
+	fShape.setTexture(&shapeTexture);
28
+}
29
+
30
+Perception PictureEnvironment::getPerception(int iX, int iY)
31
+{
32
+	Perception vPerception = Perception(PERCEPTION_SIZE, PERCEPTION_SIZE);
33
+	iX++;
34
+	iY++;
35
+	return vPerception;
36
+}
37
+
38
+bool PictureEnvironment::loop()
39
+{
40
+	if (fWindow->isOpen())
41
+	{
42
+		while (fWindow->pollEvent(fEvent))
43
+		{
44
+			if (fEvent.type == sf::Event::Closed)
45
+				fWindow->close();
46
+		}
47
+		fShape = sf::CircleShape(fWindow->getSize().x / 2);
48
+		fShape.setFillColor(sf::Color::White);
49
+
50
+		sf::Texture shapeTexture;
51
+		if (!shapeTexture.loadFromFile(fFilePath))
52
+		{
53
+			std::cout << "\n COULDNT LOAD PICTURE\n";
54
+		}
55
+		fShape.setTexture(&shapeTexture);
56
+
57
+		fWindow->clear();
58
+		fWindow->draw(fShape);
59
+		fWindow->display();
60
+	}
61
+	else
62
+	{
63
+		std::cout << "\nBah on ferme";
64
+		return false;
65
+	}
66
+	return true;
67
+}

+ 29
- 0
src/Main.cpp View File

@@ -0,0 +1,29 @@
1
+
2
+#include "Platform/Platform.hpp"
3
+#include <Environment/PictureEnvironment.hpp>
4
+
5
+int main()
6
+{
7
+	util::Platform platform;
8
+#if defined(_DEBUG)
9
+	std::cout << "Hello World!" << std::endl;
10
+#endif
11
+	std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\dickbutt.jpg";
12
+	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\caisseenre.png";
13
+	//std::string filepath = "content/sfml.png";
14
+	sf::RenderWindow window;
15
+
16
+	// in Windows at least, this must be called before creating the window
17
+	float screenScalingFactor = platform.getScreenScalingFactor(window.getSystemHandle());
18
+	// Use the screenScalingFactor
19
+	window.create(sf::VideoMode(800.0f * screenScalingFactor, 600.0f * screenScalingFactor), "SFML works!");
20
+	platform.setIcon(window.getSystemHandle());
21
+
22
+	PictureEnvironment vEnvironment(filepath, &window);
23
+
24
+	while (vEnvironment.loop())
25
+	{
26
+	}
27
+
28
+	return 0;
29
+}

+ 72
- 0
src/PCH.hpp View File

@@ -0,0 +1,72 @@
1
+#ifndef PRECOMPILED_HEADER_HPP
2
+#define PRECOMPILED_HEADER_HPP
3
+
4
+#ifndef _DEBUG
5
+	#ifndef NDEBUG
6
+		#define NDEBUG
7
+	#endif
8
+#endif // _DEBUG
9
+
10
+// SFML
11
+#include <SFML/Audio.hpp>
12
+#include <SFML/Graphics.hpp>
13
+#include <SFML/Network.hpp>
14
+#include <SFML/System.hpp>
15
+#include <SFML/Window.hpp>
16
+
17
+// Raspberry Pi
18
+#ifdef SFML_SYSTEM_LINUX
19
+	#ifdef __arm__
20
+		#define SFML_SYSTEM_PI
21
+	#endif
22
+#endif // SFML SYSTEM_LINUX
23
+
24
+// Typical stdafx.h
25
+#include <algorithm>
26
+#include <cstdio>
27
+#include <deque>
28
+#include <fstream>
29
+#include <iostream>
30
+#include <list>
31
+#include <map>
32
+#include <memory>
33
+#include <set>
34
+#include <string>
35
+#include <vector>
36
+
37
+// Additional C/C++ libs
38
+#include <atomic>
39
+#include <cassert>
40
+#include <cmath>
41
+#include <cstdlib>
42
+#include <exception>
43
+#include <functional>
44
+#include <iomanip>
45
+#include <mutex>
46
+#include <random>
47
+#include <sstream>
48
+#include <thread>
49
+#include <type_traits>
50
+
51
+// Windows
52
+#ifdef _WIN32
53
+	#ifndef UNICODE
54
+		#define UNICODE
55
+	#endif
56
+
57
+	#ifndef _UNICODE
58
+		#define _UNICODE
59
+	#endif
60
+
61
+	#define WIN32_LEAN_AND_MEAN
62
+	#include <windows.h>
63
+#endif // _WIN32
64
+
65
+// Utils
66
+#include "Utility/FileSystem.hpp"
67
+#include "Utility/Types.hpp"
68
+
69
+// Macros
70
+#define UNUSED(x) (void)(x)
71
+
72
+#endif // PRECOMPILED_HEADER_HPP

+ 16
- 0
src/Platform/IPlatform.hpp View File

@@ -0,0 +1,16 @@
1
+#ifndef UTIL_IPLATFORM_HELPER_HPP
2
+#define UTIL_IPLATFORM_HELPER_HPP
3
+
4
+namespace util
5
+{
6
+struct IPlatform
7
+{
8
+	virtual ~IPlatform() = default;
9
+	virtual void setIcon(const sf::WindowHandle& inHandle) = 0;
10
+	virtual void toggleFullscreen(const sf::WindowHandle& inHandle, const sf::Uint32 inStyle, const bool inWindowed, const sf::Vector2u& inResolution) = 0;
11
+	virtual int getRefreshRate(const sf::WindowHandle& inHandle) = 0;
12
+	virtual float getScreenScalingFactor(const sf::WindowHandle& inHandle) = 0;
13
+};
14
+}
15
+
16
+#endif // UTIL_IPLATFORM_HELPER_HPP

+ 69
- 0
src/Platform/MacOS/MacOSPlatform.cpp View File

@@ -0,0 +1,69 @@
1
+#ifdef __APPLE__
2
+	#include "Platform/MacOS/MacOSPlatform.hpp"
3
+
4
+	#include <CoreFoundation/CoreFoundation.h>
5
+
6
+namespace util
7
+{
8
+/******************************************************************************
9
+ *
10
+ *****************************************************************************/
11
+MacOSPlatform::MacOSPlatform()
12
+{
13
+	// This function ensures the working directory is set inside of the bundle if in production mode
14
+	CFBundleRef mainBundle = CFBundleGetMainBundle();
15
+	CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
16
+	char path[PATH_MAX];
17
+	bool pathSet = CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8*)path, PATH_MAX);
18
+
19
+	// This is a copy, so we release it here
20
+	CFRelease(resourcesURL);
21
+
22
+	// Actually do the check here
23
+	if (pathSet)
24
+	{
25
+		std::string pathStr = path;
26
+		if (pathStr.find(".app") != std::string::npos)
27
+			chdir(path);
28
+	}
29
+}
30
+
31
+/******************************************************************************
32
+ *
33
+ *****************************************************************************/
34
+void MacOSPlatform::setIcon(const sf::WindowHandle& inHandle)
35
+{
36
+	UNUSED(inHandle);
37
+}
38
+
39
+/******************************************************************************
40
+ *
41
+ *****************************************************************************/
42
+void MacOSPlatform::toggleFullscreen(const sf::WindowHandle& inHandle, const sf::Uint32 inStyle, const bool inWindowed, const sf::Vector2u& inResolution)
43
+{
44
+	UNUSED(inHandle);
45
+	UNUSED(inStyle);
46
+	UNUSED(inWindowed);
47
+	UNUSED(inResolution);
48
+}
49
+
50
+/******************************************************************************
51
+ *
52
+ *****************************************************************************/
53
+float MacOSPlatform::getScreenScalingFactor(const sf::WindowHandle& inHandle)
54
+{
55
+	UNUSED(inHandle);
56
+	return 1.0f;
57
+}
58
+
59
+/******************************************************************************
60
+ *
61
+ *****************************************************************************/
62
+int MacOSPlatform::getRefreshRate(const sf::WindowHandle& inHandle)
63
+{
64
+	UNUSED(inHandle);
65
+	return 59;
66
+}
67
+}
68
+
69
+#endif // __APPLE__

+ 19
- 0
src/Platform/MacOS/MacOSPlatform.hpp View File

@@ -0,0 +1,19 @@
1
+#ifndef UTIL_MACOS_PLATFORM_HPP
2
+#define UTIL_MACOS_PLATFORM_HPP
3
+
4
+#include "Platform/IPlatform.hpp"
5
+
6
+namespace util
7
+{
8
+struct MacOSPlatform : IPlatform
9
+{
10
+	MacOSPlatform();
11
+
12
+	void setIcon(const sf::WindowHandle& inHandle) final;
13
+	void toggleFullscreen(const sf::WindowHandle& inHandle, const sf::Uint32 inStyle, const bool inWindowed, const sf::Vector2u& inResolution) final;
14
+	float getScreenScalingFactor(const sf::WindowHandle& inHandle) final;
15
+	int getRefreshRate(const sf::WindowHandle& inHandle) final;
16
+};
17
+}
18
+
19
+#endif // UTIL_MACOS_PLATFORM_HPP

+ 22
- 0
src/Platform/Platform.hpp View File

@@ -0,0 +1,22 @@
1
+#ifndef UTIL_PLATFORM_HPP
2
+#define UTIL_PLATFORM_HPP
3
+
4
+#if defined(__APPLE__)
5
+	#include "Platform/MacOS/MacOSPlatform.hpp"
6
+#elif defined(__linux__)
7
+	#include "Platform/Unix/LinuxPlatform.hpp"
8
+#elif defined(_WIN32)
9
+	#include "Platform/Win32/WindowsPlatform.hpp"
10
+#endif
11
+
12
+namespace util
13
+{
14
+#if defined(__APPLE__)
15
+using Platform = MacOSPlatform;
16
+#elif defined(__linux__)
17
+using Platform = LinuxPlatform;
18
+#elif defined(_WIN32)
19
+using Platform = WindowsPlatform;
20
+#endif
21
+}
22
+#endif // UTIL_PLATFORM_HPP

+ 55
- 0
src/Platform/Unix/LinuxPlatform.cpp View File

@@ -0,0 +1,55 @@
1
+#ifdef __linux__
2
+	#include "Platform/Unix/LinuxPlatform.hpp"
3
+
4
+	#include <X11/Xlib.h>
5
+
6
+namespace util
7
+{
8
+/******************************************************************************
9
+ *
10
+ *****************************************************************************/
11
+LinuxPlatform::LinuxPlatform()
12
+{
13
+	// TODO: Investigate further
14
+	XInitThreads();
15
+}
16
+
17
+/******************************************************************************
18
+ *
19
+ *****************************************************************************/
20
+void LinuxPlatform::setIcon(const sf::WindowHandle& inHandle)
21
+{
22
+	UNUSED(inHandle);
23
+}
24
+
25
+/******************************************************************************
26
+ *
27
+ *****************************************************************************/
28
+void LinuxPlatform::toggleFullscreen(const sf::WindowHandle& inHandle, const sf::Uint32 inStyle, const bool inWindowed, const sf::Vector2u& inResolution)
29
+{
30
+	UNUSED(inHandle);
31
+	UNUSED(inStyle);
32
+	UNUSED(inWindowed);
33
+	UNUSED(inResolution);
34
+}
35
+
36
+/******************************************************************************
37
+ *
38
+ *****************************************************************************/
39
+float LinuxPlatform::getScreenScalingFactor(const sf::WindowHandle& inHandle)
40
+{
41
+	UNUSED(inHandle);
42
+	return 1.0f;
43
+}
44
+
45
+/******************************************************************************
46
+ *
47
+ *****************************************************************************/
48
+int LinuxPlatform::getRefreshRate(const sf::WindowHandle& inHandle)
49
+{
50
+	UNUSED(inHandle);
51
+	return 59;
52
+}
53
+}
54
+
55
+#endif // __linux__

+ 19
- 0
src/Platform/Unix/LinuxPlatform.hpp View File

@@ -0,0 +1,19 @@
1
+#ifndef UTIL_LINUX_PLATFORM_HPP
2
+#define UTIL_LINUX_PLATFORM_HPP
3
+
4
+#include "Platform/IPlatform.hpp"
5
+
6
+namespace util
7
+{
8
+struct LinuxPlatform : IPlatform
9
+{
10
+	LinuxPlatform();
11
+
12
+	void setIcon(const sf::WindowHandle& inHandle) final;
13
+	void toggleFullscreen(const sf::WindowHandle& inHandle, const sf::Uint32 inStyle, const bool inWindowed, const sf::Vector2u& inResolution) final;
14
+	float getScreenScalingFactor(const sf::WindowHandle& inHandle) final;
15
+	int getRefreshRate(const sf::WindowHandle& inHandle) final;
16
+};
17
+}
18
+
19
+#endif // UTIL_LINUX_PLATFORM_HPP

+ 9
- 0
src/Platform/Win32/Resource.h View File

@@ -0,0 +1,9 @@
1
+#ifndef RESOURCE_H
2
+#define RESOURCE_H
3
+
4
+#include <winuser.h>
5
+
6
+#define WIN32_ICON_MAIN 1
7
+#define MANIFEST_RESOURCE_ID 1
8
+
9
+#endif // RESOURCE_H

+ 7
- 0
src/Platform/Win32/Resource.rc View File

@@ -0,0 +1,7 @@
1
+#ifdef _WIN32
2
+#include "Resource.h"
3
+
4
+MANIFEST_RESOURCE_ID RT_MANIFEST "env/windows/app.manifest"
5
+WIN32_ICON_MAIN ICON "env/windows/app.ico"
6
+
7
+#endif

+ 188
- 0
src/Platform/Win32/WindowsPlatform.cpp View File

@@ -0,0 +1,188 @@
1
+#ifdef _WIN32
2
+	#include "Platform/Win32/WindowsPlatform.hpp"
3
+
4
+	#include "Resource.h"
5
+
6
+namespace util
7
+{
8
+/******************************************************************************
9
+ *
10
+ *****************************************************************************/
11
+WindowsPlatform::WindowsPlatform()
12
+{
13
+	// Get the default device info
14
+	m_screenScalingFactor = getScreenScalingFactor(nullptr);
15
+	m_refreshRate = getRefreshRate(nullptr);
16
+}
17
+
18
+/******************************************************************************
19
+ * The window handle uses 32x32 (ICON_BIG) & 16x16 (ICON_SMALL) sized icons.
20
+ * This should be called any time the SFML window is create/recreated
21
+ *****************************************************************************/
22
+void WindowsPlatform::setIcon(const sf::WindowHandle& inHandle)
23
+{
24
+	// Get the icon directory
25
+	PBYTE iconDirectory = getIconDirectory(WIN32_ICON_MAIN);
26
+	std::array<int, 5> icons = { 16, 32, 48, 64, 128 };
27
+
28
+	std::size_t indexSmallIcon = static_cast<std::size_t>(std::min(std::max(std::ceil(m_screenScalingFactor - 1.0f), 0.0f), static_cast<float>(icons.size()) - 1.0f));
29
+	std::size_t indexBigIcon = static_cast<std::size_t>(std::min(std::max(std::ceil(m_screenScalingFactor - 1.0f), 0.0f) + 1.0f, static_cast<float>(icons.size()) - 1.0f));
30
+
31
+	HICON smallIcon = getIconFromIconDirectory(iconDirectory, icons[indexSmallIcon]);
32
+	HICON bigIcon = getIconFromIconDirectory(iconDirectory, icons[indexBigIcon]);
33
+
34
+	if (smallIcon)
35
+		SendMessage(inHandle, WM_SETICON, ICON_SMALL, (LPARAM)smallIcon);
36
+
37
+	if (bigIcon)
38
+		SendMessage(inHandle, WM_SETICON, ICON_BIG, (LPARAM)bigIcon);
39
+
40
+	// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-destroyicon
41
+	// It is only necessary to call DestroyIcon for icons and cursors created with the following functions:
42
+	//   CreateIconFromResourceEx (if called without the LR_SHARED flag)
43
+}
44
+
45
+/******************************************************************************
46
+ *
47
+ *****************************************************************************/
48
+void WindowsPlatform::toggleFullscreen(const sf::WindowHandle& inHandle, const sf::Uint32 inStyle, const bool inWindowed, const sf::Vector2u& inResolution)
49
+{
50
+	DWORD win32Style = sfmlWindowStyleToWin32WindowStyle(inStyle);
51
+	UINT flags = SWP_DRAWFRAME | SWP_FRAMECHANGED;
52
+
53
+	if (inWindowed)
54
+	{
55
+		// Window (centered on the focused screen)
56
+		HDC screenDC = GetDC(inHandle);
57
+		int screenWidth = GetDeviceCaps(screenDC, HORZRES);
58
+		int screenHeight = GetDeviceCaps(screenDC, VERTRES);
59
+		ReleaseDC(inHandle, screenDC);
60
+
61
+		int width = static_cast<int>(inResolution.x);
62
+		int height = static_cast<int>(inResolution.y);
63
+		int left = (screenWidth - width) / 2;
64
+		int top = (screenHeight - height) / 2;
65
+		RECT rectangle = { 0, 0, width, height };
66
+		AdjustWindowRect(&rectangle, win32Style, false);
67
+		width = rectangle.right - rectangle.left;
68
+		height = rectangle.bottom - rectangle.top;
69
+
70
+		SetWindowLongPtr(inHandle, GWL_STYLE, win32Style);
71
+		SetWindowLongPtr(inHandle, GWL_EXSTYLE, 0);
72
+		SetWindowPos(inHandle, nullptr, left, top, width, height, flags);
73
+	}
74
+	else
75
+	{
76
+		// Fullscreen
77
+		int width = static_cast<int>(inResolution.x);
78
+		int height = static_cast<int>(inResolution.y);
79
+
80
+		// first time prevents the border from showing in the corner
81
+		SetWindowPos(inHandle, HWND_TOP, 0, 0, width, height, flags);
82
+		SetWindowLongPtr(inHandle, GWL_EXSTYLE, WS_EX_APPWINDOW);
83
+		SetWindowLongPtr(inHandle, GWL_STYLE, win32Style);
84
+
85
+		// second time cleans up the rect after the border has been removed
86
+		SetWindowPos(inHandle, HWND_TOP, 0, 0, width, height, flags);
87
+
88
+		// note: double SetWindowPos call isn't very effective on slower machines anyway :/
89
+	}
90
+	ShowWindow(inHandle, SW_SHOW);
91
+}
92
+
93
+/******************************************************************************
94
+ * Gets the screen scaling factor of the device from the supplied handle
95
+ *****************************************************************************/
96
+float WindowsPlatform::getScreenScalingFactor(const sf::WindowHandle& inHandle)
97
+{
98
+	UNUSED(inHandle);
99
+
100
+	if (m_screenScalingFactor != 0.0f)
101
+		return m_screenScalingFactor;
102
+
103
+	HDC screenDC = GetDC(nullptr);
104
+	int logicalScreenHeight = GetDeviceCaps(screenDC, VERTRES);
105
+	int physicalScreenHeight = GetDeviceCaps(screenDC, DESKTOPVERTRES);
106
+	m_screenScalingFactor = static_cast<float>(physicalScreenHeight) / static_cast<float>(logicalScreenHeight);
107
+	ReleaseDC(nullptr, screenDC);
108
+
109
+	return m_screenScalingFactor;
110
+}
111
+
112
+/******************************************************************************
113
+ * Gets the refresh rate of the device from the supplied handle
114
+ *****************************************************************************/
115
+int WindowsPlatform::getRefreshRate(const sf::WindowHandle& inHandle)
116
+{
117
+	UNUSED(inHandle);
118
+
119
+	if (m_refreshRate != 0)
120
+		return m_refreshRate;
121
+
122
+	HDC screenDC = GetDC(nullptr);
123
+	m_refreshRate = GetDeviceCaps(screenDC, VREFRESH);
124
+	ReleaseDC(nullptr, screenDC);
125
+
126
+	return m_refreshRate;
127
+}
128
+
129
+/******************************************************************************
130
+ * Loads a .ico file from The application's resources, and can contain multiple
131
+ * sizes (for instance 16x16, 32x32 & 64x64). This is referred to as an
132
+ * "Icon Directory". Additionally, it can have a single icon
133
+ *****************************************************************************/
134
+PBYTE WindowsPlatform::getIconDirectory(const int inResourceId)
135
+{
136
+	HMODULE hModule = GetModuleHandle(nullptr);
137
+	HRSRC hResource = FindResource(hModule, MAKEINTRESOURCE(inResourceId), RT_GROUP_ICON);
138
+
139
+	HGLOBAL hData = LoadResource(hModule, hResource);
140
+	PBYTE data = (PBYTE)LockResource(hData);
141
+
142
+	return data;
143
+}
144
+
145
+/******************************************************************************
146
+ * This will attempt to load a single icon from an icon directory
147
+ * If the requested size isn't found, the first one is returned
148
+ *****************************************************************************/
149
+HICON WindowsPlatform::getIconFromIconDirectory(PBYTE inIconDirectory, const uint inSize)
150
+{
151
+	HMODULE hModule = GetModuleHandle(nullptr);
152
+	int resourceId = LookupIconIdFromDirectoryEx(inIconDirectory, TRUE, inSize, inSize, LR_DEFAULTCOLOR | LR_SHARED);
153
+	HRSRC hResource = FindResource(hModule, MAKEINTRESOURCE(resourceId), RT_ICON);
154
+
155
+	HGLOBAL hData = LoadResource(hModule, hResource);
156
+	PBYTE data = (PBYTE)LockResource(hData);
157
+	DWORD sizeofData = SizeofResource(hModule, hResource);
158
+
159
+	HICON icon = CreateIconFromResourceEx(data, sizeofData, TRUE, 0x00030000, inSize, inSize, LR_DEFAULTCOLOR | LR_SHARED);
160
+	return icon;
161
+}
162
+
163
+/******************************************************************************
164
+ * Takes an SFML window style and matches it back to the Win32 equivalent
165
+ *****************************************************************************/
166
+DWORD WindowsPlatform::sfmlWindowStyleToWin32WindowStyle(const sf::Uint32 inStyle)
167
+{
168
+	DWORD style = 0;
169
+	if (inStyle == sf::Style::None || inStyle == sf::Style::Fullscreen)
170
+	{
171
+		style = WS_VISIBLE | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
172
+	}
173
+	else
174
+	{
175
+		style = WS_VISIBLE;
176
+		if (inStyle & sf::Style::Titlebar)
177
+			style |= WS_CAPTION | WS_MINIMIZEBOX;
178
+		if (inStyle & sf::Style::Resize)
179
+			style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
180
+		if (inStyle & sf::Style::Close)
181
+			style |= WS_SYSMENU;
182
+	}
183
+
184
+	return style;
185
+}
186
+}
187
+
188
+#endif // _WIN32

+ 29
- 0
src/Platform/Win32/WindowsPlatform.hpp View File

@@ -0,0 +1,29 @@
1
+#ifndef UTIL_WINDOWS_PLATFORM_HPP
2
+#define UTIL_WINDOWS_PLATFORM_HPP
3
+
4
+#include "Platform/IPlatform.hpp"
5
+
6
+// TODO: WM_DISPLAYCHANGE event handling (multi-monitor support)
7
+
8
+namespace util
9
+{
10
+struct WindowsPlatform : IPlatform
11
+{
12
+	WindowsPlatform();
13
+
14
+	void setIcon(const sf::WindowHandle& inHandle) final;
15
+	void toggleFullscreen(const sf::WindowHandle& inHandle, const sf::Uint32 inStyle, const bool inWindowed, const sf::Vector2u& inResolution) final;
16
+	float getScreenScalingFactor(const sf::WindowHandle& inHandle) final;
17
+	int getRefreshRate(const sf::WindowHandle& inHandle) final;
18
+
19
+private:
20
+	PBYTE getIconDirectory(const int inResourceId);
21
+	HICON getIconFromIconDirectory(PBYTE inIconDirectory, const uint inSize);
22
+	DWORD sfmlWindowStyleToWin32WindowStyle(const sf::Uint32 inStyle);
23
+
24
+	float m_screenScalingFactor = 0.0f;
25
+	int m_refreshRate = 0;
26
+};
27
+}
28
+
29
+#endif // UTIL_WINDOWS_PLATFORM_HPP

+ 20
- 0
src/Utility/FileSystem.hpp View File

@@ -0,0 +1,20 @@
1
+#ifndef UTIL_FILE_SYSTEM_HPP
2
+#define UTIL_FILE_SYSTEM_HPP
3
+
4
+// std::filesystem
5
+#if __GNUC__ >= 8 || __clang_major__ >= 9
6
+	#include <filesystem>
7
+#else
8
+	#include <experimental/filesystem>
9
+#endif
10
+
11
+namespace util
12
+{
13
+#if __GNUC__ >= 8 || __clang_major__ >= 9
14
+namespace fs = std::filesystem;
15
+#else
16
+namespace fs = std::experimental::filesystem::v1;
17
+#endif
18
+}
19
+
20
+#endif // UTIL_FILE_SYSTEM_HPP

+ 13
- 0
src/Utility/Types.hpp View File

@@ -0,0 +1,13 @@
1
+#ifndef UTIL_TYPES_HPP
2
+#define UTIL_TYPES_HPP
3
+
4
+#include <cstdint>
5
+
6
+typedef std::uint8_t uchar;
7
+typedef std::uint16_t ushort;
8
+typedef std::uint32_t uint;
9
+typedef std::uint64_t ullong;
10
+
11
+typedef std::int64_t llong;
12
+
13
+#endif // UTIL_TYPES_HPP

+ 7
- 0
test/Main.cpp View File

@@ -0,0 +1,7 @@
1
+#define CATCH_CONFIG_RUNNER
2
+#include <catch2/catch.hpp>
3
+
4
+int main(const int argc, const char* argv[])
5
+{
6
+	return Catch::Session().run(argc, argv);
7
+}

+ 33
- 0
test/test_RenderWindow.cpp View File

@@ -0,0 +1,33 @@
1
+#include <catch2/catch.hpp>
2
+
3
+// This example is a bit silly, but you get the idea
4
+TEST_CASE("sf::RenderWindow", "[renderwindow]") {
5
+	sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
6
+
7
+	REQUIRE(window.getSize().x == 200);
8
+	REQUIRE(window.getSize().y == 200);
9
+
10
+	sf::CircleShape shape(window.getSize().x/2);
11
+	shape.setFillColor(sf::Color::White);
12
+
13
+	REQUIRE(shape.getRadius() == 100.0f);
14
+	REQUIRE(shape.getFillColor() == sf::Color::White);
15
+	REQUIRE(static_cast<int>(shape.getLocalBounds().width) == 198); // 🤔
16
+	REQUIRE(static_cast<int>(shape.getLocalBounds().height) == 200);
17
+
18
+	sf::Texture shapeTexture;
19
+	shapeTexture.loadFromFile("content/sfml.png");
20
+	shape.setTexture(&shapeTexture);
21
+
22
+	REQUIRE(shapeTexture.getSize().x == 256);
23
+	REQUIRE(shapeTexture.getSize().y == 256);
24
+	REQUIRE(shape.getTexture() == &shapeTexture);
25
+
26
+	// Show the RenderWindow once
27
+	window.clear();
28
+	window.draw(shape);
29
+	window.display();
30
+
31
+	REQUIRE(window.isOpen() == true);
32
+
33
+}

Loading…
Cancel
Save