} | } | ||||
void onMouseMove(Sint32 x, Sint32 y) { | void onMouseMove(Sint32 x, Sint32 y) { | ||||
mousePos_ = { x, y }; | |||||
mousePos_ = {x, y}; | |||||
} | } | ||||
void onMouseDown(Sint32 x, Sint32 y, Uint8 button) { | void onMouseDown(Sint32 x, Sint32 y, Uint8 button) { | ||||
mousePos_ = { x, y }; | |||||
mousePos_ = {x, y}; | |||||
pressedButtons_[button] = true; | pressedButtons_[button] = true; | ||||
didPressButtons_[button] = true; | didPressButtons_[button] = true; | ||||
} | |||||
} | |||||
void onMouseUp(Sint32 x, Sint32 y, Uint8 button) { | void onMouseUp(Sint32 x, Sint32 y, Uint8 button) { | ||||
mousePos_ = { x, y }; | |||||
mousePos_ = {x, y}; | |||||
pressedButtons_[button] = false; | pressedButtons_[button] = false; | ||||
didReleaseButtons_[button] = true; | didReleaseButtons_[button] = true; | ||||
} | } | ||||
std::unique_ptr<World> world_ = NULL; | std::unique_ptr<World> world_ = NULL; | ||||
Cygnet::Renderer renderer_; | Cygnet::Renderer renderer_; | ||||
Cygnet::RenderCamera cam_; | |||||
Cygnet::RenderCamera cam_{ .zoom = 0.25 }; | |||||
private: | private: | ||||
std::bitset<SDL_NUM_SCANCODES> pressedKeys_; | std::bitset<SDL_NUM_SCANCODES> pressedKeys_; |
break; | break; | ||||
case Event::Tag::LIGHT_ADDED: | case Event::Tag::LIGHT_ADDED: | ||||
info << cpos << ": Add " << evt.f << " light to " << rpos; | |||||
ch->lightSources[rpos] += evt.f; | ch->lightSources[rpos] += evt.f; | ||||
markChunksModified(cpos, rpos, ch->lightSources[rpos]); | markChunksModified(cpos, rpos, ch->lightSources[rpos]); | ||||
break; | break; | ||||
case Event::Tag::LIGHT_REMOVED: | case Event::Tag::LIGHT_REMOVED: | ||||
info << cpos << ": Remove " << evt.f << " light to " << rpos; | |||||
markChunksModified(cpos, rpos, ch->lightSources[rpos]); | markChunksModified(cpos, rpos, ch->lightSources[rpos]); | ||||
ch->lightSources[rpos] -= evt.f; | ch->lightSources[rpos] -= evt.f; | ||||
if (ch->lightSources[rpos] < LIGHT_CUTOFF) { | if (ch->lightSources[rpos] < LIGHT_CUTOFF) { | ||||
buf.clear(); | buf.clear(); | ||||
newChunks.clear(); | newChunks.clear(); | ||||
auto start = std::chrono::steady_clock::now(); | |||||
for (auto &pos: updatedChunks_) { | for (auto &pos: updatedChunks_) { | ||||
auto ch = chunks_.find(pos); | auto ch = chunks_.find(pos); | ||||
if (ch != chunks_.end()) { | if (ch != chunks_.end()) { | ||||
} | } | ||||
} | } | ||||
auto end = std::chrono::steady_clock::now(); | |||||
auto dur = std::chrono::duration<double, std::milli>(end - start); | |||||
info << "Generating light for " << updatedChunks_.size() | |||||
<< " chunks took " << dur.count() << "ms"; | |||||
for (auto &pos: updatedChunks_) { | for (auto &pos: updatedChunks_) { | ||||
auto ch = chunks_.find(pos); | auto ch = chunks_.find(pos); | ||||
if (ch != chunks_.end()) { | if (ch != chunks_.end()) { |
// Create a world | // Create a world | ||||
Game game; | Game game; | ||||
game.cam_.size = window.size(); | |||||
std::vector<std::string> mods{ "core.mod" }; | std::vector<std::string> mods{ "core.mod" }; | ||||
game.createWorld("core::default", mods); | game.createWorld("core::default", mods); | ||||
} | } | ||||
} | } | ||||
game.cam_.size = window.size(); | |||||
auto now = std::chrono::steady_clock::now(); | auto now = std::chrono::steady_clock::now(); | ||||
std::chrono::duration<float> dur(now - prevTime); | std::chrono::duration<float> dur(now - prevTime); | ||||
prevTime = now; | prevTime = now; | ||||
{ | { | ||||
ZoneScopedN("game draw"); | ZoneScopedN("game draw"); | ||||
game.cam_.size = window.size(); | |||||
game.draw(); | game.draw(); | ||||
} | } | ||||