@@ -20,6 +20,8 @@ struct SRF { | |||
virtual std::ostream &pretty(std::ostream &os) const = 0; | |||
static SRF *read(std::istream &is); | |||
friend std::ostream &operator<<(std::ostream &os, const SRF &srf); | |||
}; | |||
struct SRFObject: SRF { |
@@ -1,6 +1,7 @@ | |||
#pragma once | |||
#include <utility> | |||
#include <ostream> | |||
namespace Swan { | |||
@@ -92,9 +93,19 @@ struct Vector2 { | |||
} | |||
static const Vector2<T> ZERO; | |||
template<typename U> | |||
friend std::ostream &operator<<(std::ostream &os, const Vector2<U> &vec); | |||
}; | |||
template<typename T> const Vector2<T> Vector2<T>::ZERO = Vector2<T>(0, 0); | |||
template<typename T> | |||
const Vector2<T> Vector2<T>::ZERO = Vector2<T>(0, 0); | |||
template<typename T> | |||
std::ostream &operator<<(std::ostream &os, const Vector2<T> &vec) { | |||
os << '(' << vec.x << ", " << vec.y << ')'; | |||
return os; | |||
} | |||
using Vec2 = Vector2<float>; | |||
using Vec2i = Vector2<int>; |
@@ -54,12 +54,12 @@ void Chunk::compress() { | |||
compressed_size_ = destlen; | |||
info | |||
<< "Compressed chunk " << pos_.x << "," << pos_.y << " " | |||
<< "Compressed chunk " << pos_ << " " | |||
<< "from " << CHUNK_WIDTH * CHUNK_HEIGHT * sizeof(Tile::ID) << "bytes " | |||
<< "to " << destlen << " bytes."; | |||
} else if (ret == Z_BUF_ERROR) { | |||
info | |||
<< "Didn't compress chunk " << pos_.x << "," << pos_.y << " " | |||
<< "Didn't compress chunk " << pos_ << " " | |||
<< "because compressing it would've made it bigger."; | |||
} else { | |||
warn << "Chunk compression error: " << ret << " (Out of memory?)"; | |||
@@ -88,7 +88,7 @@ void Chunk::decompress() { | |||
need_render_ = true; | |||
info | |||
<< "Decompressed chunk " << pos_.x << "," << pos_.y << " from " | |||
<< "Decompressed chunk " << pos_ << " from " | |||
<< compressed_size_ << " bytes to " | |||
<< CHUNK_WIDTH * CHUNK_HEIGHT * sizeof(Tile::ID) << " bytes."; | |||
compressed_size_ = -1; |
@@ -153,6 +153,11 @@ SRF *SRF::read(std::istream &is) { | |||
return srf; | |||
} | |||
std::ostream &operator<<(std::ostream &os, const SRF &srf) { | |||
srf.pretty(os); | |||
return os; | |||
} | |||
SRFObject::SRFObject(std::initializer_list<std::pair<std::string, SRF *>> lst) { | |||
for (auto &[k, v]: lst) | |||
val[k] = std::unique_ptr<SRF>(v); |
@@ -43,8 +43,7 @@ Entity &WorldPlane::spawnEntity(const std::string &name, const SRF ¶ms) { | |||
} | |||
spawn_list_.push_back(std::unique_ptr<Entity>(ent)); | |||
info << "Spawned " << name << ". SRF:"; | |||
params.pretty(std::clog) << '\n'; | |||
info << "Spawned " << name << ". SRF: " << params; | |||
return *ent; | |||
} | |||