aboutsummaryrefslogtreecommitdiff
path: root/docs/class-diag.puml
blob: 32b70182b4dd6bdacd0c61a89d4e883cdcddbad9 (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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
@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_Collisions as "Collisions" <<group>> {
	class CollisionContext {
		+ CollisionContext(Museum &)
		+ update()
		+ get_checker() : shared<CollisionChecker>
		+ cycle_method()
		--
		- museum : Museum &
		- checker : shared<CollisionChecker>
		- checker_index : size_t
		- create_checker() : shared<CollisionChecker>
	}
	class CollisionChecker <<abstract>> {
		+ CollisionChecker(Museum &)
		+ compare(Artist & a, Artist & b)
		+ check() <<pure virtual>>
		--
		# museum : Museum &
	}
	class QuadTreeCollisionChecker {
		+ constructor(Museum &)
		- constructor(parent : this, boundary : const Rectangle &)
		--
		+ get_boundary() : const Rectangle &
		+ subtree : uniq<QuadTreeCollisionChecker>[4]
		+ check()
		--
		- capacity : const int
		- artists : forward_list<Artist *>
		- artists_size : size_t
		- boundary : Rectangle <<+get>>
		--
		- subdivide()
		- cull()
	}
	class NaiveCollisionChecker {
		+ check()
	}
	class NullCollisionChecker {
		+ check()
	}

	CollisionChecker <|-- QuadTreeCollisionChecker
	CollisionChecker <|-- NaiveCollisionChecker
	CollisionChecker <|-- NullCollisionChecker
	CollisionContext -> CollisionChecker
}
rectangle Group_Pathfinding as "Pathfinding" <<group>> {
	class PathfindingContext {
		+ PathfindingContext(Museum &)
		--
		- start_point : XY <<+get>> <<+set>>
		- end_point : XY <<+get>> <<+set>>
		+ valid_point(const XY &) : bool
		+ update()
		--
		+ get_solver() : Pathfinder &
		+ cycle_solver()
		--
		- solvers : vec<uniq<Pathfinder>>
		- solver_index : size_t
		- museum : Museum &
	}
  class Pathfinder <<abstract>> {
		+ Pathfinder(Museum &)
		+ find_between(const XY &, const XY &) <<pure virtual>
		+ get_path() : const forward_list<XY> & <<pure virtual>>
		--
		+ is_visited(const XY &) : bool
		# set_visited(const XY &)
		--
		# clear()
		- visited : vec<bool>
		--
		# museum : Museum &
	}
  class BreadthFirstPathfinder {
		+ find_between(const XY &, const XY &)
		+ get_path() : const forward_list<XY> &
		--
		- find_step(const vec<forward_list<XY>> &) : vec<forward_list<XY>>
		- solution : forward_list<XY>
		- end : XY
		--
		# clear()
	}
  class DijkstraPathfinder {
	}

  Pathfinder <|-- BreadthFirstPathfinder
  Pathfinder <|-- DijkstraPathfinder
  PathfindingContext -> Pathfinder
}
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(XY) : Tile &
		+ set_tile(TileData)
		--
		+ update()
		+ data : CanvasData
		+ set_data(CanvasData)
		--
    + tile_color : TileColorFactory
    + tile_behavior : TileBehaviorFactory
		--
		- 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(XY) : 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
	}
	class TileColorFactory <<factory>> {
		+ get_color(string) : Color <<static>>
		+ register_color(string, Color) <<static>>
	}
	class TileBehaviorFactory <<factory>> {
		+ TileBehaviorFactory(Museum &)
		+ create(string) : uniq<TileBehavior>
		--
		- museum : Museum &
	}
	}

	struct Color {
		red : unsigned int
		green : unsigned int
		blue : unsigned int
	}

	together {
	interface TileBehavior {
		+ step(Artist *)
		+ update(Tile &)
		--
		# TileBehavior(Museum &)
		--
		# interactions : unsigned int
		# museum : Museum &
	}

  class NullTileBehavior {
    - type = "" <<constexpr>>
  }
  class StepTileBehavior {
    - type = "G" : <<constexpr>>
  }
  class DeleteArtistTileBehavior {
    - type = "R" : <<constexpr>>
  }
  class SetNeighborTileBehavior {
    - type = "B" : <<constexpr>>
    --
    - dx : int
    - dy : int
  }
  class CreateArtistTileBehavior {
    - type = "Y" : <<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
  Canvas --> TileColorFactory
  Canvas --> TileBehaviorFactory
	People --> Artist

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

	Tile --> "state" Color
  Tile .> 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 &, const XY &)
		--
		- canvas : Canvas &
		- tile_pos : XY
	}
	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 &
	}
	class CycleCollisionMethodCommand {
		+ constructor(Museum &)
	}

	Command <|-d- ToggleMuseumPauseCommand
	Command <|-u- OpenFileGUICommand
	Command <|-u- ControlBooleanCommand
	Command <|-d- StepTileCommand
	Command <|-d- LoadFilesCommand
	Command <|-d- TimeTravelCommand
	Command <|-u- CycleCollisionMethodCommand
}
} /' 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