Browse Source

somewhat synchronize light server stuff

feature/replace-renderer
Martin Dørum 3 years ago
parent
commit
9eeb30960f

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

@@ -66,7 +66,7 @@ public:

std::unique_ptr<World> world_ = NULL;
Cygnet::Renderer renderer_;
Cygnet::RenderCamera cam_{.zoom = 0.25};
Cygnet::RenderCamera cam_{.zoom = 0.125};

private:
std::bitset<SDL_NUM_SCANCODES> pressedKeys_;

+ 4
- 5
libswan/include/swan/LightServer.h View File

@@ -50,6 +50,7 @@ public:
void onLightRemoved(TilePos pos, float level);
void onChunkAdded(ChunkPos pos, NewLightChunk &&chunk);
void onChunkRemoved(ChunkPos pos);
void flip();

private:
static constexpr int LIGHT_CUTOFF_DIST = 64;
@@ -101,25 +102,21 @@ private:
inline void LightServer::onSolidBlockAdded(TilePos pos) {
std::lock_guard<std::mutex> lock(mut_);
buffers_[buffer_].push_back({ Event::Tag::BLOCK_ADDED, pos, { .i = 0 } });
cond_.notify_one();
}

inline void LightServer::onSolidBlockRemoved(TilePos pos) {
std::lock_guard<std::mutex> lock(mut_);
buffers_[buffer_].push_back({ Event::Tag::BLOCK_REMOVED, pos, { .i = 0 } });
cond_.notify_one();
}

inline void LightServer::onLightAdded(TilePos pos, float level) {
std::lock_guard<std::mutex> lock(mut_);
buffers_[buffer_].push_back({ Event::Tag::LIGHT_ADDED, pos, { .f = level } });
cond_.notify_one();
}

inline void LightServer::onLightRemoved(TilePos pos, float level) {
std::lock_guard<std::mutex> lock(mut_);
buffers_[buffer_].push_back({ Event::Tag::LIGHT_REMOVED, pos, { .f = level } });
cond_.notify_one();
}

inline void LightServer::onChunkAdded(Vec2i pos, NewLightChunk &&chunk) {
@@ -127,12 +124,14 @@ inline void LightServer::onChunkAdded(Vec2i pos, NewLightChunk &&chunk) {
buffers_[buffer_].push_back({ Event::Tag::CHUNK_ADDED, pos,
{ .i = (int)newChunkBuffers_[buffer_].size() } });
newChunkBuffers_[buffer_].push_back(std::move(chunk));
cond_.notify_one();
}

inline void LightServer::onChunkRemoved(Vec2i pos) {
std::lock_guard<std::mutex> lock(mut_);
buffers_[buffer_].push_back({ Event::Tag::CHUNK_REMOVED, pos, { .i = 0 } });
}

inline void LightServer::flip() {
cond_.notify_one();
}


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

@@ -37,8 +37,8 @@ void Game::update(float dt) {
cam_.zoom += (float)wasWheelScrolled() * 0.1f * cam_.zoom;
if (cam_.zoom > 1)
cam_.zoom = 1;
else if (cam_.zoom < 0.05)
cam_.zoom = 0.05;
else if (cam_.zoom < 0.025)
cam_.zoom = 0.025;

world_->update(dt);


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

@@ -229,8 +229,11 @@ void WorldPlane::draw(Cygnet::Renderer &rnd) {
}
}

for (auto &coll: entColls_)
for (auto &coll: entColls_) {
coll->draw(ctx, rnd);
}

lighting_->flip();

/*
if (debugBoxes_.size() > 0) {

Loading…
Cancel
Save