aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Museum.cpp10
-rw-r--r--Museum.h11
-rw-r--r--TimeTravelCommand.cpp9
-rw-r--r--TimeTravelCommand.h4
-rw-r--r--docs/class-diag.puml39
5 files changed, 49 insertions, 24 deletions
diff --git a/Museum.cpp b/Museum.cpp
index df9144a..f6b8977 100644
--- a/Museum.cpp
+++ b/Museum.cpp
@@ -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() {
}
diff --git a/Museum.h b/Museum.h
index 73183c3..0792ec3 100644
--- a/Museum.h
+++ b/Museum.h
@@ -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