Browse Source

stuff

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
9750fb49fa

+ 8
- 1
libswan/include/swan/Chunk.h View File

@@ -43,7 +43,14 @@ public:
drawBlock(pos, tmap.get(id));
}

void redraw(TileMap &tmap);
void redraw(TileMap &tmap) {
for (int x = 0; x < CHUNK_WIDTH; ++x) {
for (int y = 0; y < CHUNK_HEIGHT; ++y) {
drawBlock(tmap, ChunkPos(x, y), tiles_[x][y]);
}
}
}

void draw(Win &win);
};


+ 0
- 6
libswan/include/swan/Vector2.h View File

@@ -73,12 +73,6 @@ public:
y_ /= num;
return *this;
}

bool operator<(const Vector2<T> &vec) const {
if (x_ < vec.x_) return true;
if (vec.x_ < x_) return false;
return y_ < vec.y_;
}
};

using Vec2 = Vector2<float>;

+ 1
- 1
libswan/include/swan/WorldPlane.h View File

@@ -18,7 +18,7 @@ class WorldPlane {
public:
using ID = uint16_t;

std::map<Chunk::ChunkPos, Chunk> chunks_;
std::map<std::pair<int, int>, Chunk> chunks_;
ID id_;
World *world_;
std::shared_ptr<WorldGen> gen_;

+ 2
- 1
libswan/include/swan/common.h View File

@@ -16,11 +16,12 @@ struct Win {
public:
sf::RenderWindow *window_;
sf::Transform transform_;
Vec2 cam_;

Win(sf::RenderWindow *win): window_(win) {}

void setPos(const Vec2 &pos) {
transform_ = sf::Transform().translate(pos);
transform_ = sf::Transform().translate(pos - cam_);
}

void draw(const sf::Drawable &drawable) {

+ 1
- 9
libswan/src/Chunk.cc View File

@@ -2,21 +2,13 @@

namespace Swan {

void Chunk::redraw(TileMap &tmap) {
for (int x = 0; x < CHUNK_WIDTH; ++x) {
for (int y = 0; y < CHUNK_HEIGHT; ++y) {
drawBlock(tmap, x, y, tiles_[x][y]);
}
}
}

void Chunk::draw(Win &win) {
if (dirty_) {
sprite_.setTexture(texture_);
dirty_ = false;
}

win.setPos(Vec2(x_ * CHUNK_WIDTH, y_ * CHUNK_HEIGHT));
win.setPos(Vec2(pos_.x_ * CHUNK_WIDTH, pos_.y_ * CHUNK_HEIGHT));
win.draw(sprite_);
}


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

@@ -18,10 +18,10 @@ static Chunk::RelPos relPos(int x, int y) {

Chunk &WorldPlane::getChunk(int x, int y) {
Chunk::ChunkPos pos = chunkPos(x, y);
auto it = chunks_.find(pos);
auto it = chunks_.find(std::pair<int, int>(pos.x_, pos.y_));

if (it == chunks_.end()) {
it = chunks_.emplace(pos, Chunk(pos)).first;
it = chunks_.emplace(std::pair<int, int>(pos.x_, pos.y_), Chunk(pos)).first;
gen_->genChunk(it->second, pos.x_, pos.y_);
it->second.redraw(world_->tile_map_);
}

Loading…
Cancel
Save