Kaynağa Gözat

only draw chunks around the player

opengl-renderer-broken
Martin Dørum 4 yıl önce
ebeveyn
işleme
14f2c39cd2
1 değiştirilmiş dosya ile 17 ekleme ve 2 silme
  1. 17
    2
      libswan/src/WorldPlane.cc

+ 17
- 2
libswan/src/WorldPlane.cc Dosyayı Görüntüle

@@ -1,5 +1,7 @@
#include "WorldPlane.h"

#include <math.h>

#include "World.h"
#include "Timer.h"

@@ -67,8 +69,21 @@ Entity &WorldPlane::spawnPlayer() {
}

void WorldPlane::draw(Win &win) {
for (auto &ch: chunks_)
ch.second->draw(win);
const Vec2 &ppos = world_->player_->getPos();
ChunkPos pcpos = ChunkPos(
(int)floor(ppos.x_ / CHUNK_WIDTH),
(int)floor(ppos.y_ / CHUNK_HEIGHT));

for (int x = -1; x <= 1; ++x) {
for (int y = -1; y <= 1; ++y) {
auto chunk = chunks_.find(pcpos + ChunkPos(x, y));
if (chunk != chunks_.end())
chunk->second->draw(win);
}
}

//for (auto &ch: chunks_)
// ch.second->draw(win);
for (auto &ent: entities_)
ent->draw(win);


Loading…
İptal
Kaydet