Browse Source

add operator<< to Vector2 and SRF

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
5d9c63b36d

+ 2
- 0
libswan/include/swan/SRF.h View File

@@ -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 {

+ 12
- 1
libswan/include/swan/Vector2.h View File

@@ -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>;

+ 3
- 3
libswan/src/Chunk.cc View File

@@ -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;

+ 5
- 0
libswan/src/SRF.cc View File

@@ -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);

+ 1
- 2
libswan/src/WorldPlane.cc View File

@@ -43,8 +43,7 @@ Entity &WorldPlane::spawnEntity(const std::string &name, const SRF &params) {
}

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;
}


Loading…
Cancel
Save