diff options
| -rw-r--r-- | Artist.h | 4 | ||||
| -rw-r--r-- | ArtistData.h | 12 | ||||
| -rw-r--r-- | Canvas.cpp | 11 | ||||
| -rw-r--r-- | Canvas.h | 4 | ||||
| -rw-r--r-- | CanvasData.h | 8 | ||||
| -rw-r--r-- | Color.h | 10 | ||||
| -rw-r--r-- | Deserializer.cpp | 4 | ||||
| -rw-r--r-- | Deserializer.h | 3 | ||||
| -rw-r--r-- | Museum.cpp | 1 | ||||
| -rw-r--r-- | Museum.h | 1 | ||||
| -rw-r--r-- | People.cpp | 1 | ||||
| -rw-r--r-- | Tile.cpp | 4 | ||||
| -rw-r--r-- | Tile.h | 3 | ||||
| -rw-r--r-- | TileData.h | 8 | ||||
| -rw-r--r-- | XMLParser.cpp | 13 | ||||
| -rw-r--r-- | YellowTileBehavior.cpp | 4 | ||||
| -rw-r--r-- | readme.md | 7 | 
17 files changed, 51 insertions, 47 deletions
@@ -17,8 +17,8 @@ private:  	void update_edge_collision();  public: -	ArtistData data = { 0 }; -	Color color = { 0 }; +	ArtistData data; +	Color color;  	bool step = false; diff --git a/ArtistData.h b/ArtistData.h index ddee528..1c3c88c 100644 --- a/ArtistData.h +++ b/ArtistData.h @@ -1,9 +1,9 @@  #pragma once -typedef struct { -	float x; -	float y; -	float vx; -	float vy; -} ArtistData; +struct ArtistData { +	float x = 0.0; +	float y = 0.0; +	float vx = 0.0; +	float vy = 0.0; +}; @@ -13,13 +13,11 @@ Tile & Canvas::get_tile(unsigned x, unsigned y) {  	return *this->tiles[this->pos_to_index(x, y)];  } -void Canvas::set_tile(unsigned x, unsigned y, TileData data) { -	size_t index = this->pos_to_index(x, y); +void Canvas::set_tile(TileData data) { +	size_t index = this->pos_to_index(data.x, data.y);  	if (this->tiles[index] != nullptr)  		delete this->tiles[index];  	this->tiles[index] = new Tile(this->museum, data); -	this->tiles[index]->x = x; -	this->tiles[index]->y = y;  }  size_t Canvas::pos_to_index(unsigned x, unsigned y) { @@ -39,7 +37,10 @@ void Canvas::set_data(CanvasData data) {  		for (size_t x = 0; x < this->data.columns; x++) {  			if (this->tiles[this->pos_to_index(x, y)] != nullptr)  				continue; -			this->set_tile(x, y, {}); +			this->set_tile({ +				.x = static_cast<unsigned int>(x), +				.y = static_cast<unsigned int>(y), +			});  		}  	}  } @@ -16,10 +16,10 @@ public:  public:  	virtual Tile & get_tile(unsigned x, unsigned y); -	virtual void set_tile(unsigned x, unsigned y, TileData data); +	virtual void set_tile(TileData data);  public: -	CanvasData data = { 0 }; +	CanvasData data;  	void update();  	void set_data(CanvasData data); diff --git a/CanvasData.h b/CanvasData.h index 19812da..d2b0666 100644 --- a/CanvasData.h +++ b/CanvasData.h @@ -1,7 +1,7 @@  #pragma once -typedef struct { -	unsigned rows; -	unsigned columns; -} CanvasData; +struct CanvasData { +	unsigned rows = 0; +	unsigned columns = 0; +}; @@ -1,8 +1,8 @@  #pragma once -typedef struct { -	unsigned int red; -	unsigned int green; -	unsigned int blue; -} Color; +struct Color { +	unsigned int red = 0; +	unsigned int green = 0; +	unsigned int blue = 0; +}; diff --git a/Deserializer.cpp b/Deserializer.cpp index 3c1e580..7215dd4 100644 --- a/Deserializer.cpp +++ b/Deserializer.cpp @@ -11,8 +11,8 @@ void Deserializer::set_canvas(CanvasData data) {  	this->museum.canvas.set_data(data);  } -void Deserializer::add_tile(unsigned int x, unsigned int y, TileData data) { -	this->museum.canvas.set_tile(x, y, data); +void Deserializer::set_tile(TileData data) { +	this->museum.canvas.set_tile(data);  }  void Deserializer::add_type(std::string type, Color color, unsigned int weight) { diff --git a/Deserializer.h b/Deserializer.h index bdbcde0..50ae57d 100644 --- a/Deserializer.h +++ b/Deserializer.h @@ -14,8 +14,7 @@ public:  	void add_type(std::string type, Color color, unsigned int weight);  	void set_canvas(CanvasData); - -	void add_tile(unsigned int x, unsigned int y, TileData); +	void set_tile(TileData);  	void add_artist(ArtistData);  private: @@ -27,6 +27,7 @@ void Museum::work() {  		auto next = chrono::steady_clock::now() + this->tick_interval;  		this->update();  		this_thread::sleep_until(next); +		this->tick++;  	}  } @@ -23,6 +23,7 @@ public:  	void update();  private: +	unsigned long long tick = 0;  	bool paused = false;  private: @@ -40,6 +40,7 @@ string People::to_string() {  	out += stringf("%d artists\n", this->artist_count);  	for (Artist * artist : this->artists) { +		if (artist == nullptr) continue;  		out += stringf("- at (%.2f,%.2f)\n", artist->data.x, artist->data.y);  	} @@ -32,8 +32,8 @@ void Tile::step(Artist * artist) {  Tile * Tile::get_neighbor(int dx, int dy) {  	Canvas & canvas = this->museum.canvas; -	int x = this->x + dx; -	int y = this->y + dy; +	int x = this->data.x + dx; +	int y = this->data.y + dy;  	if (x < 0) return nullptr;  	if (x >= canvas.data.columns) return nullptr;  	if (y < 0) return nullptr; @@ -17,9 +17,6 @@ public:  	Color color;  	std::unique_ptr<TileBehaviorStrategy> behavior = nullptr; -	unsigned int x = 0; -	unsigned int y = 0; -  public:  	void set_data(TileData & data);  	void set_type(const std::string & type); @@ -2,7 +2,9 @@  #include <string> -typedef struct { -	std::string type; -} TileData; +struct TileData { +	unsigned int x = 0; +	unsigned int y = 0; +	std::string type = ""; +}; diff --git a/XMLParser.cpp b/XMLParser.cpp index 3d6e6cf..6be26af 100644 --- a/XMLParser.cpp +++ b/XMLParser.cpp @@ -5,6 +5,7 @@  #include "XMLParser.h"  #include "Exception.h"  #include "Parser.h" +#include "TileData.h"  using namespace std; @@ -62,13 +63,11 @@ void XMLParser::parse(FileStrategy & f, Deserializer & d) {  	if (!nodes)  		throw Exception("missing <nodes>");  	for (xml_node node : nodes) { -		d.add_tile( -			node.attribute("x").as_uint(), -			node.attribute("y").as_uint(), -			{ -				.type = node.name(), -			} -		); +		d.set_tile({ +			.x = node.attribute("x").as_uint(), +			.y = node.attribute("y").as_uint(), +			.type = node.name(), +		});  	}  } diff --git a/YellowTileBehavior.cpp b/YellowTileBehavior.cpp index 0c2ee35..4e35733 100644 --- a/YellowTileBehavior.cpp +++ b/YellowTileBehavior.cpp @@ -26,8 +26,8 @@ void YellowTileBehavior::update(Tile & tile) {  	for (unsigned int i = 0; i < new_artists; i++) {  		if (i >= 2) break;  		ArtistData new_data = { -			.x = static_cast<float>(tile.x), -			.y = static_cast<float>(tile.y), +			.x = static_cast<float>(tile.data.x), +			.y = static_cast<float>(tile.data.y),  		};  		float velocity = random_float(rng);  		random_bool(rng) ? new_data.vx = velocity : new_data.vy = velocity; @@ -1,7 +1,10 @@  # TODO +DPA: +  - state snapshots (memento) -- send commands from GUI + +ALGA: +  - artist-artist collision behavior -- artist steps on tile behavior  |