From 3f375a193d0f10a8121d568a745a7903c075c568 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 15 Oct 2024 15:36:00 +0200 Subject: update class diagram + add empty time travel command --- CMakeLists.txt | 1 + TimeTravelCommand.cpp | 16 ++++ TimeTravelCommand.h | 16 ++++ ViewController.cpp | 3 + docs/class-diag.puml | 250 ++++++++++++++++++++++++++++++++------------------ 5 files changed, 199 insertions(+), 87 deletions(-) create mode 100644 TimeTravelCommand.cpp create mode 100644 TimeTravelCommand.h diff --git a/CMakeLists.txt b/CMakeLists.txt index aa0ef49..a74a6b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ add_executable(main MuseumPauseCommand.cpp ArtistVisibilityCommand.cpp TileDecayCommand.cpp + TimeTravelCommand.cpp ) target_link_libraries(main diff --git a/TimeTravelCommand.cpp b/TimeTravelCommand.cpp new file mode 100644 index 0000000..c7dfc82 --- /dev/null +++ b/TimeTravelCommand.cpp @@ -0,0 +1,16 @@ +#include "TimeTravelCommand.h" +#include "Museum.h" + +void TimeTravelCommand::forwards() { + return this->execute(+this->default_offset); +} + +void TimeTravelCommand::backwards() { + return this->execute(-this->default_offset); +} + +void TimeTravelCommand::execute(long offset) { + Museum & museum = this->get_museum(); + // TODO +} + diff --git a/TimeTravelCommand.h b/TimeTravelCommand.h new file mode 100644 index 0000000..0a2de46 --- /dev/null +++ b/TimeTravelCommand.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Command.h" + +class TimeTravelCommand : public Command { + using Command::Command; + +public: + virtual void execute(long offset); + virtual void forwards(); + virtual void backwards(); + +private: + static constexpr long default_offset = 50; +}; + diff --git a/ViewController.cpp b/ViewController.cpp index 303d5b9..52cdefc 100644 --- a/ViewController.cpp +++ b/ViewController.cpp @@ -6,6 +6,7 @@ #include "MuseumPauseCommand.h" #include "OpenFileGUICommand.h" #include "TileDecayCommand.h" +#include "TimeTravelCommand.h" #include "View.h" #include "Museum.h" @@ -79,9 +80,11 @@ void ViewController::ev_keydown(KeyboardCode key) { break; } case KEY_LEFT: { + TimeTravelCommand(this->cmd_base).backwards(); break; } case KEY_RIGHT: { + TimeTravelCommand(this->cmd_base).forwards(); break; } default: break; diff --git a/docs/class-diag.puml b/docs/class-diag.puml index 8526346..a502503 100644 --- a/docs/class-diag.puml +++ b/docs/class-diag.puml @@ -17,6 +17,7 @@ exception Exception { # va_format(va_list args, const char* fmt) } +together { /' LAYOUT '/ rectangle Group_FileReading as "File reading" <> { class FileReader <> { +open(url) : FileStrategy& @@ -34,10 +35,7 @@ rectangle Group_FileReading as "File reading" <> { class HTTPFile { - instance : HTTPFile <> } - package CPR { - class Response <> - class Url <> - } + package CPR { } FileStrategy <|.. LocalFile FileStrategy <|.. HTTPFile @@ -45,17 +43,21 @@ rectangle Group_FileReading as "File reading" <> { FileStrategy <. FileReader FileStrategy .> FileReader - HTTPFile --> CPR.Response - CPR.Response - CPR.Url + HTTPFile -> CPR + + ' LAYOUT + LocalFile -r[hidden] HTTPFile } rectangle Group_ParsingDeserialization as "Parsing & deserialization" <> { class Parser { - + parse(File, Deserializer) <> - + register_strategy(ParserStrategy) <> + + parse(FileStrategy &, Deserializer &) <> + + register_strategy(ParserStrategy *) <> + -- + - get_collection() : ParserCollection <> } interface ParserStrategy { - + parse(File, Deserializer) <> - + heuristic(File) : unsigned int <> + + parse(FileStrategy &, Deserializer &) <> + + heuristic(FileStrategy &) : unsigned int <> } ParserStrategy .> Parser @@ -65,45 +67,76 @@ rectangle Group_ParsingDeserialization as "Parsing & deserialization" <> class XMLParser class TXTParser + package pugixml { } + CSVParser ..|> ParserStrategy TXTParser ..|> ParserStrategy XMLParser ..|> ParserStrategy + XMLParser -> pugixml + class Deserializer { - + set_target(Museum &) - + add_artist(uniq) - + set_rows(unsigned int) - + set_cols(unsigned int) - + add_type(string, Color, unsigned int) - + add_tile(unsigned int x, unsigned int y, uniq) + + Deserializer(Museum &) + -- + + set_canvas(CanvasData) + + set_tile(TileData) + + add_artist(ArtistData) + + add_type(type : string, Color, weight : unsigned int) } CSVParser -up-> Deserializer XMLParser -up-> Deserializer TXTParser -up-> Deserializer - ' ParserStrategy ..> Deserializer + ' LAYOUT + CSVParser -r[hidden] TXTParser + TXTParser -r[hidden] XMLParser } +} /' LAYOUT '/ +together { /' LAYOUT '/ rectangle Group_Model as "Model" <> { + class Museum { + + people : People + + canvas : Canvas + -- + + update() + -- + - paused : bool <<+get>> <<+set>> + - tick : unsigned long long + -- + - working : bool + - worker : thread * + - work() + } class Canvas { - + get_tile(x, y) - + set_tile(x, y, TileData) - - data : CanvasData - - tiles : Tile[] + + Canvas(Museum &) + -- + + get_tile(x, y) : Tile & + + set_tile(TileData) + -- + + update() + + data : CanvasData + + set_data(CanvasData) + -- + - tiles : vector + - museum : Museum & } class People { - + add_artist(uniq) - - artists : Artist[] - } - class Museum { - - people : People - - canvas : Canvas + + People(Museum &) + -- + + add_artist(ArtistData) + + remove_artist(Artist &) + + get_artists() : forward_list + -- + - artists : forward_list } class Tile { + data : TileData } struct TileData { + + x : unsigned int + + y : unsigned int + type : string } class Artist { @@ -135,7 +168,6 @@ rectangle Group_Model as "Model" <> { ' LAYOUT Artist -r[hidden] Tile } - rectangle Group_TileAppearance as "Tile appearance" <> { struct Color { red : unsigned int @@ -152,36 +184,104 @@ rectangle Group_TileAppearance as "Tile appearance" <> { Color <.. TileAppearance } rectangle Group_TileBehavior as "Tile behavior" <> { - interface TileBehaviorStrategy + interface TileBehaviorStrategy { + + step(Artist *) + + update(Tile &) + + clone(Museum &) : uniq + -- + # TileBehaviorStrategy(type : string) + # TileBehaviorStrategy() + -- + # interactions : unsigned int + # museum : Museum * + } - class TileBehavior + class TileBehavior { + + get_strategy(string) : TileBehaviorStrategy & <> + + register_strategy(string, TileBehaviorStrategy *) <> + -- + - get_collection() : TileBehaviorCollection & <> + } together { - class NullTileBehavior - - class GrayTileBehavior - class RedTileBehavior - class BlueTileBehavior - class YellowTileBehavior - + class NullTileBehavior { + - type = "" <> + } + class GrayTileBehavior { + - type = "G" : <> + } + class RedTileBehavior { + - type = "R" : <> + } + class BlueTileBehavior { + - type = "B" : <> + -- + - update_neighbor(here : Tile &, dx, dy) + - dx : int + - dy : int + } + class YellowTileBehavior { + - type = "Y" : <> + -- + - last_interactions : unsigned int + } + + ' LAYOUT + TileBehavior -d[hidden]- NullTileBehavior NullTileBehavior -d[hidden]- GrayTileBehavior GrayTileBehavior -d[hidden]- RedTileBehavior RedTileBehavior -d[hidden]- BlueTileBehavior BlueTileBehavior -d[hidden]- YellowTileBehavior } - TileBehaviorStrategy <|.. NullTileBehavior - TileBehaviorStrategy <|.. GrayTileBehavior - TileBehaviorStrategy <|.. RedTileBehavior - TileBehaviorStrategy <|.. BlueTileBehavior - TileBehaviorStrategy <|.. YellowTileBehavior + TileBehaviorStrategy <|.[norank]. NullTileBehavior + TileBehaviorStrategy <|.[norank]. GrayTileBehavior + TileBehaviorStrategy <|.[norank]. RedTileBehavior + TileBehaviorStrategy <|.[norank]. BlueTileBehavior + TileBehaviorStrategy <|.[norank]. YellowTileBehavior Tile --> "state" TileBehavior TileBehavior .l> TileBehaviorStrategy TileBehavior <. TileBehaviorStrategy } +} /' LAYOUT '/ +together { /' LAYOUT '/ +rectangle Group_Commands as "Commands" <> { + class Command { + # museum : Museum& + # view : View& + # controller : ViewController& + -- + + Command(command : const Command *) + + Command(museum, view, controller) + } + + class MuseumPauseCommand { + + toggle() + + set(paused : bool) + } + class OpenFileGUICommand { + + execute() + } + class ArtistVisibilityCommand { + + toggle() + + set(paused : bool) + } + class LoadFilesCommand { + + execute(files) + } + class TileDecayCommand { + + execute(x, y) + } + + Command <|-u- MuseumPauseCommand + Command <|-u- OpenFileGUICommand + Command <|-u- ArtistVisibilityCommand + Command <|-u- TileDecayCommand + Command <|-d- LoadFilesCommand +} rectangle Group_Visualization as "Visualization" <> { struct Rectangle { x : unsigned int @@ -192,8 +292,18 @@ rectangle Group_Visualization as "Visualization" <> { enum Scancode { } - package SDL2 { } + package SDL3 { } class View { + + window_size(width, height) + + dialog_file(callback : fn(files : vec, data), data) + + draw_rect(Rectangle, Color) + -- + - window : SDL_Window * + - renderer : SDL_Renderer * + -- + + open : bool + - worker : thread * + - work() } class ViewController { + update() @@ -201,62 +311,28 @@ rectangle Group_Visualization as "Visualization" <> { ViewController ..> View ViewController <-- View - View -> SDL2 -} - -rectangle Group_Commands as "Commands" <> { - class Command { - #museum : Museum& - #view : View& - #controller : ViewController& - +Command(museum, view, controller) - +Command(command : const Command *) - } - - class MuseumPauseCommand { - +toggle() - +set(paused : bool) - } - class OpenFileGUICommand { - +execute() - } - class ArtistVisibilityCommand { - +toggle() - +set(paused : bool) - } - - Command <|-u- MuseumPauseCommand - Command <|-u- OpenFileGUICommand - Command <|-u- ArtistVisibilityCommand - - Command .d..> Museum - Command ...d[norank]> View - Command ...d[norank]> ViewController + View -> SDL3 } +} /' LAYOUT '/ -' PeopleDeserializer <... People -' CanvasDeserializer <... Canvas -' Deserializer <... Museum +Command .[norank]> Museum +Command .[norank]> View +Command .[norank]> ViewController ParserStrategy ..> FileStrategy -' Museum .> Deserializer : friend Deserializer .> Museum ViewController -[norank]> Command -main --> Museum -main --[norank]> Deserializer -main --[norank]> View -' DETAIL: main ..[norank]> FileReader -' DETAIL: main ..[norank]> Parser +main -d-> Museum +main -u-> LoadFilesCommand +main -[norank]> Deserializer +main -[norank]> View ' LAYOUT -Group_ParsingDeserialization -d[hidden] Group_FileReading Group_TileBehavior -r[hidden] Group_TileAppearance Group_Model -r[hidden] Group_ParsingDeserialization -Group_Model -l[hidden] main -' Group_Model -d[hidden] Group_TileBehavior -' Group_Model -d[hidden] Group_TileAppearance +Group_Commands -r[hidden] Group_Visualization @enduml -- cgit v1.2.3