aboutsummaryrefslogtreecommitdiff
path: root/docs/class-diag.puml
blob: 58ed9502e0ddba36683adf35683b44c6cd612ba0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
@startuml

!include style.ipuml

' !include hide-groups.ipuml
' !include hide-details.ipuml

class main as "main()"
hide main circle
hide main members

exception Exception {
	+ Exception(const char* fmt, ...)
	+ what() : const char*
	--
	# error : char*
	# va_format(va_list args, const char* fmt)
}

rectangle Group_FileReading as "File reading" <<group>> {
	class FileReaderFactory <<factory>> {
		+ create(url : const string &) : uniq<FileReader>
	}
	interface FileReader {
		# FileReader(url : const string &)
		+ ~FileReader()
		--
		# open()
		+ read() : const string
		+ close()
		--
		# url : const string
	}
	class LocalFileReader {
		+ ~LocalFileReader()
	}
	class HTTPFileReader {
	}
	package CPR { }

	FileReader <|.d. LocalFileReader
	FileReader <|.d. HTTPFileReader

	FileReaderFactory -u-> LocalFileReader
	FileReaderFactory -u-> HTTPFileReader

	HTTPFileReader -l> CPR

	' LAYOUT
	HTTPFileReader -r[hidden] LocalFileReader
}
rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>> {
	class ParserFactory <<factory>> {
		+ ParserFactory()
		+ get_parser(FileReader &) : Parser &
		--
		- parsers : vec<uniq<Parser>>
	}
	interface Parser {
		+ parse(FileReader &, MuseumDeserializer &)
		+ heuristic(FileReader &) : unsigned int
		--
		# set_file(FileReader &)
		# get_file() : FileReader &
		--
		file : FileReader *
	}

	class XMLParser
	class TXTParser
	class CSVParser

	package pugixml { }

	Parser <|.d. XMLParser
	Parser <|.d. TXTParser
	Parser <|.d. CSVParser

	ParserFactory -u-> XMLParser
	ParserFactory -u-> TXTParser
	ParserFactory -u-> CSVParser

	XMLParser -r> pugixml

	class MuseumDeserializer {
		+ MuseumDeserializer(Museum &)
		--
		+ set_canvas(CanvasData)
		+ set_tile(TileData)
		+ add_artist(ArtistData)
		+ add_type(type : string, Color, weight : unsigned int)
	}

	Parser .> MuseumDeserializer

	' LAYOUT
	CSVParser -r[hidden] TXTParser
	TXTParser -r[hidden] XMLParser
}

rectangle Group_Algorithms as "Algorithms" <<group>> {
	class PathfindingContext {
		+ PathfindingContext(Museum &)
	}
	together {
	class CollisionContext {
		+ CollisionContext(Museum &)
	}
	class CollisionChecker <<abstract>> {
		+ CollisionChecker(Museum &)
		+ compare(Artist & a, Artist & b)
		+ check() <<pure virtual>>
	}
	class QuadTreeCollisionChecker {
		+ QuadTree(Museum &)
		+ QuadTree(parent : QuadTree *, boundary : Rectangle &)
	}
	class NaiveCollisionChecker {
	}

	CollisionChecker <|-- QuadTreeCollisionChecker
	CollisionChecker <|-- NaiveCollisionChecker
	CollisionContext -> CollisionChecker
	}

}
rectangle Group_Model as "Model" <<group>> {
	class Museum {
		+ people : People
		+ canvas : Canvas
		+ collision : CollisionContext
		+ pathfinding : PathfindingContext
		--
		+ paused : bool
		+ update()
		+ skip_forward()
		+ skip_backward()
		--
		- jump : unsigned long
		--
		- working : bool
		- worker : thread *
		- work()
	}
	together {
	class Canvas {
		+ Canvas(Museum &)
		--
		+ get_tile(x, y) : Tile &
		+ set_tile(TileData)
		--
		+ update()
		+ data : CanvasData
		+ set_data(CanvasData)
		--
		- tiles : vector<Tile *>
		- museum : Museum &
	}
	struct CanvasData {
		+ rows : unsigned int
		+ columns : unsigned int
	}
	class People {
		+ People(Museum &)
		--
		+ add_artist(ArtistData)
		+ remove_artist(Artist &)
		+ get_artists() : forward_list<Artist *>
		--
		- artists : forward_list<Artist *>
		- artist_count : size_t
		- museum : Museum &
	}
	}
	together {
	class Tile {
		+ data : TileData
		+ color : Color
		+ behavior : uniq<TileBehavior>
		+ set_data(TileData &)
		+ set_type(type : const string &)
		+ update()
		+ get_neighbor(dx, dy) : Tile *
		--
		- museum : Museum &
	}
	struct TileData {
		+ x : unsigned int
		+ y : unsigned int
		+ type : string
	}
	class Artist {
		+ update()
		+ step : bool
		+ color : Color
		+ data : ArtistData
		--
		- data : ArtistData
		- museum : Museum &
	}
	struct ArtistData {
		+ x : float
		+ y : float
		+ vx : float
		+ vy : float
	}
	}

	together {
	struct Color {
		red : unsigned int
		green : unsigned int
		blue : unsigned int
	}
	class TileColorFactory <<factory>> <<singleton>> {
		+ get_color(string) : Color <<static>>
		+ register_color(string, Color) <<static>>
	}
	}

	together {
	interface TileBehavior {
		+ step(Artist *)
		+ update(Tile &)
		--
		# TileBehavior(Museum &)
		--
		# interactions : unsigned int
		# museum : Museum &
	}
	class TileBehaviorFactory <<factory>> {
		+ TileBehaviorFactory(Museum &)
		+ create(string) : uniq<TileBehavior>
		--
		- museum : Museum &
	}
	}

	together {
		class NullTileBehavior {
			- type = "" <<static constexpr>>
		}
		class StepTileBehavior {
			- type = "G" : <<static constexpr>>
		}
		class DeleteArtistTileBehavior {
			- type = "R" : <<static constexpr>>
		}
		class SetNeighborTileBehavior {
			- type = "B" : <<static constexpr>>
			--
			- dx : int
			- dy : int
		}
		class CreateArtistTileBehavior {
			- type = "Y" : <<static constexpr>>
			--
			- last_interactions : unsigned int
		}

		NullTileBehavior -d[hidden]- StepTileBehavior
		StepTileBehavior -d[hidden]- DeleteArtistTileBehavior
		DeleteArtistTileBehavior -d[hidden]- SetNeighborTileBehavior
		SetNeighborTileBehavior -d[hidden]- CreateArtistTileBehavior
	}

	Canvas -l[hidden] People

	Museum --> People
	Museum --> Canvas

	Canvas --> Tile
	People --> Artist

	Tile   -> TileData
	Artist -l> ArtistData
	Canvas -> CanvasData

	Tile --> "state" Color
	Tile .[norank].> TileColorFactory

	TileColorFactory -> Color

	TileBehavior <|.. NullTileBehavior
	TileBehavior <|.. StepTileBehavior
	TileBehavior <|.. DeleteArtistTileBehavior
	TileBehavior <|.. SetNeighborTileBehavior
	TileBehavior <|.. CreateArtistTileBehavior

	TileBehaviorFactory --> NullTileBehavior
	TileBehaviorFactory --> StepTileBehavior
	TileBehaviorFactory --> DeleteArtistTileBehavior
	TileBehaviorFactory --> SetNeighborTileBehavior
	TileBehaviorFactory --> CreateArtistTileBehavior

	Tile --> "state" TileBehavior
	Tile .[norank].> TileBehaviorFactory

	' LAYOUT
	Artist -r[hidden] Tile
}

together { /' LAYOUT '/
rectangle Group_Visualization as "Visualization" <<group>> {
	struct Rectangle {
		x : unsigned int
		y : unsigned int
		width : unsigned int
		height : unsigned int
	}
	enum MouseCode { }
	enum KeyboardCode { }
	package SDL3 { }

	class View {
		+ window_size(width, height)
		+ dialog_file(callback : fn(files : vec<string>, data), data)
		+ draw_rect(Rectangle, Color)
		--
		- window : SDL_Window *
		- renderer : SDL_Renderer *
		--
		+ open : bool
		- worker : thread *
		- work()
	}
	class ViewController {
		+ update()
		+ ev_keydown(KeyboardCode)
		+ ev_mousedown(MouseCode)
		+ ev_mousemove(x, y)
		--
		- draw_artists : bool <<+get>> <<+set>>
	}

	ViewController ..> View
	ViewController <-- View
	View --> SDL3

	View .l> Rectangle
	ViewController .l> KeyboardCode
	ViewController .l> MouseCode
}
rectangle Group_Commands as "Commands" <<group>> {
	interface Command {
		+ execute()
	}

	class ToggleMuseumPauseCommand {
		+ constructor(Museum &)
		+ constructor(Museum &, set : bool)
		--
		toggle : bool
		value : bool
	}
	class OpenFileGUICommand {
		+ constructor(Museum &, View &)
		--
		- museum : Museum &
		- view : View &
	}
	class LoadFilesCommand {
		+ constructor(Museum &, files : vec<string>)
		+ constructor(Museum &, argc, argv)
		--
		- load_files()
		- museum : Museum &
		- files : vec<string>
	}
	class StepTileCommand {
		+ constructor(Canvas &, pair<x, y>)
		--
		- canvas : Canvas &
		- x : unsigned int
		- y : unsigned int
	}
	class TimeTravelCommand {
		+ constructor(Museum &, forwards : bool)
		--
		- museum : Museum &
		- forwards : bool
	}
	class ControlBooleanCommand {
		+ constructor(target : bool &)
		+ constructor(target : bool &, set : bool)
		--
		- toggle : bool
		- value : bool
		- target : bool &
	}

	Command <|-d- ToggleMuseumPauseCommand
	Command <|-u- OpenFileGUICommand
	Command <|-u- ControlBooleanCommand
	Command <|-d- StepTileCommand
	Command <|-d- LoadFilesCommand
	Command <|-d- TimeTravelCommand
}
} /' LAYOUT '/

Parser .l> FileReader
' Parser -l> FileReaderFactory
MuseumDeserializer .l> Museum

Museum --> PathfindingContext
Museum --> CollisionContext

ViewController -[norank]> Command

main -d-> Museum
main -u-> LoadFilesCommand
' main -[norank]> MuseumDeserializer
main -[norank]> View
main .r> Exception

@enduml