diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 17:00:11 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 17:00:11 +0200 |
commit | b34d3b09e7fc9d796d56157ca5f9adb864a31c76 (patch) | |
tree | 4cbfc46f3e824394520a409cff5667dba5e24ff1 | |
parent | 3d9a47f0f6dcb6e6e33bf2d2bd34fa903422ac62 (diff) |
more shuffling
-rw-r--r-- | Museum.cpp | 10 | ||||
-rw-r--r-- | Museum.h | 11 | ||||
-rw-r--r-- | TimeTravelCommand.cpp | 9 | ||||
-rw-r--r-- | TimeTravelCommand.h | 4 | ||||
-rw-r--r-- | docs/class-diag.puml | 39 |
5 files changed, 49 insertions, 24 deletions
@@ -18,14 +18,14 @@ Museum::~Museum() { void Museum::update() { this->people.update(); this->canvas.update(); + this->tick++; } -void Museum::time_jump(long offset) { - if (offset >= 0) { - this->jump = offset; - return; - } +void Museum::skip_forward() { + this->jump += this->snapshot_ticks; +} +void Museum::skip_backward() { } @@ -21,16 +21,21 @@ public: void set_pause(bool paused); bool get_pause() { return this->paused; } void update(); - void time_jump(long offset); + void skip_forward(); + void skip_backward(); private: bool paused = false; + unsigned long jump = 0; private: - static constexpr std::chrono::milliseconds tick_interval = 15ms; - unsigned long jump = 0; bool working = true; std::thread * worker = nullptr; void work(); + +private: + unsigned long long tick = 0; + static constexpr unsigned snapshot_ticks = 50; + static constexpr std::chrono::milliseconds tick_interval = 15ms; }; diff --git a/TimeTravelCommand.cpp b/TimeTravelCommand.cpp index 8a24234..34468c0 100644 --- a/TimeTravelCommand.cpp +++ b/TimeTravelCommand.cpp @@ -2,15 +2,10 @@ #include "Museum.h" void TimeTravelCommand::forwards() { - return this->execute(+this->default_offset); + this->get_museum().skip_forward(); } void TimeTravelCommand::backwards() { - return this->execute(-this->default_offset); -} - -void TimeTravelCommand::execute(long offset) { - Museum & museum = this->get_museum(); - museum.time_jump(offset); + this->get_museum().skip_backward(); } diff --git a/TimeTravelCommand.h b/TimeTravelCommand.h index 0a2de46..7803134 100644 --- a/TimeTravelCommand.h +++ b/TimeTravelCommand.h @@ -6,11 +6,7 @@ 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/docs/class-diag.puml b/docs/class-diag.puml index cfa954d..389395a 100644 --- a/docs/class-diag.puml +++ b/docs/class-diag.puml @@ -129,10 +129,24 @@ rectangle Group_Model as "Model" <<group>> { + remove_artist(Artist &) + get_artists() : forward_list<Artist *> -- - - artists : forward_list<Artist> + - artists : forward_list<Artist *> + - artist_count : size_t + - museum : Museum & + -- + - deleted_artists : forward_list<Artist *> + - cleanup() } class Tile { + data : TileData + + color : Color + + behavior : uniq<TileBehaviorStrategy> + + set_data(TileData &) + + set_type(type : const string &) + + update() + + step(Artist *) + + get_neighbor(dx, dy) : Tile * + -- + - museum : Museum & } struct TileData { + x : unsigned int @@ -141,8 +155,12 @@ rectangle Group_Model as "Model" <<group>> { } class Artist { + update() + + step : bool + + color : Color + + data : ArtistData -- - data : ArtistData + - museum : Museum & } struct ArtistData { + x : float @@ -288,10 +306,10 @@ rectangle Group_Visualization as "Visualization" <<group>> { width : unsigned int height : unsigned int } - enum Scancode { - } - + enum MouseCode { } + enum KeyboardCode { } package SDL3 { } + class View { + window_size(width, height) + dialog_file(callback : fn(files : vec<string>, data), data) @@ -306,11 +324,21 @@ rectangle Group_Visualization as "Visualization" <<group>> { } class ViewController { + update() + + ev_keydown(KeyboardCode); + + ev_mousedown(MouseCode); + + ev_mousemove(x, y); + -- + - draw_artists : bool <<+get>> <<+set>> + - cmd_base : const Command * } ViewController ..> View ViewController <-- View - View -> SDL3 + View --> SDL3 + + View .> Rectangle + ViewController .> KeyboardCode + ViewController .> MouseCode } } /' LAYOUT '/ @@ -327,6 +355,7 @@ main -d-> Museum main -u-> LoadFilesCommand main -[norank]> Deserializer main -[norank]> View +main .l> Exception ' LAYOUT Group_TileBehavior -r[hidden] Group_TileAppearance |