diff --git a/src/graphics/render/Decorator.cpp b/src/graphics/render/Decorator.cpp index f94dc20cc..fd32b56ba 100644 --- a/src/graphics/render/Decorator.cpp +++ b/src/graphics/render/Decorator.cpp @@ -83,7 +83,7 @@ void Decorator::addParticles(const Block& def, const glm::ivec3& pos) { ); blockEmitters[pos] = renderer.particles->add(std::make_unique( level, - glm::vec3{pos.x + 0.5, pos.y + 0.5, pos.z + 0.5}, + worldvec3 {pos.x + 0.5, pos.y + 0.5, pos.z + 0.5}, *def.particles, treg.texture, treg.region, @@ -205,7 +205,7 @@ void Decorator::updateRandom( ); renderer.particles->add(std::make_unique( level, - glm::vec3 { + worldvec3 { pos.x + random.randFloat(), pos.y + 1.1, pos.z + random.randFloat()}, @@ -308,11 +308,11 @@ void Decorator::updateTextNotes() { renderer.texts->remove(textsIter->second); textsIter = playerTexts.erase(textsIter); } else { - glm::vec3 position = player->getPosition(); + worldvec3 position = player->getPosition(); if (auto entity = level.entities->get(player->getEntity())) { position = entity->getInterpolatedPosition(); } - note->setPosition(position + glm::vec3(0, 1, 0)); + note->setPosition(position + worldvec3(0, 1, 0)); if (note->getText() != player->getName()) { note->setText(player->getName()); } diff --git a/src/graphics/render/Emitter.cpp b/src/graphics/render/Emitter.cpp index aa817b354..7fe636192 100644 --- a/src/graphics/render/Emitter.cpp +++ b/src/graphics/render/Emitter.cpp @@ -14,7 +14,7 @@ Emitter::Emitter( const Level& level, - std::variant origin, + EmitterOrigin origin, ParticlesPreset preset, const Texture* texture, const UVRegion& region, @@ -50,15 +50,15 @@ static inline glm::vec3 generate_coord(ParticleSpawnShape shape) { void Emitter::update( float delta, - const glm::vec3& cameraPosition, + const worldvec3& cameraPosition, std::vector& particles ) { const float spawnInterval = preset.spawnInterval; if (count == 0 || (count == -1 && spawnInterval < FLT_EPSILON)) { return; } - glm::vec3 position {}; - if (auto staticPos = std::get_if(&origin)) { + worldvec3 position {}; + if (auto staticPos = std::get_if(&origin)) { position = *staticPos; } else if (auto entityId = std::get_if(&origin)) { if (auto entity = level.entities->get(*entityId)) { @@ -105,7 +105,7 @@ void Emitter::update( spawnOffset *= preset.spawnSpread; spawnOffset += preset.spawnOffset; - particle.position = position + spawnOffset; + particle.position = position + worldvec3(spawnOffset); particle.lifetime *= 1.0f - preset.lifetimeSpread * random.randFloat(); particle.velocity += glm::ballRand(1.0f) * preset.explosion; if (preset.randomSubUV < 1.0f) { diff --git a/src/graphics/render/Emitter.hpp b/src/graphics/render/Emitter.hpp index ce1ec8f47..61b1941df 100644 --- a/src/graphics/render/Emitter.hpp +++ b/src/graphics/render/Emitter.hpp @@ -20,7 +20,7 @@ struct Particle { /// @brief Some random integer for visuals configuration. int random; /// @brief Global position - glm::vec3 position; + worldvec3 position; /// @brief Linear velocity glm::vec3 velocity; /// @brief Remaining life time @@ -35,7 +35,7 @@ struct Particle { class Texture; -using EmitterOrigin = std::variant; +using EmitterOrigin = std::variant; class Emitter { const Level& level; @@ -61,7 +61,7 @@ public: Emitter( const Level& level, - std::variant origin, + EmitterOrigin origin, ParticlesPreset preset, const Texture* texture, const UVRegion& region, @@ -79,7 +79,7 @@ public: /// @param particles destination particles vector void update( float delta, - const glm::vec3& cameraPosition, + const worldvec3& cameraPosition, std::vector& particles ); diff --git a/src/graphics/render/ParticlesRenderer.cpp b/src/graphics/render/ParticlesRenderer.cpp index d283389e0..b5cf3b63c 100644 --- a/src/graphics/render/ParticlesRenderer.cpp +++ b/src/graphics/render/ParticlesRenderer.cpp @@ -38,10 +38,10 @@ static inline void update_particle( auto& angle = particle.angle; vel += delta * preset.acceleration; - if (preset.collision && chunks.isObstacleAt(pos + vel * delta)) { + if (preset.collision && chunks.isObstacleAt(pos + worldvec3(vel * delta))) { vel *= 0.0f; } - pos += vel * delta; + pos += worldvec3(vel * delta); angle += particle.angularVelocity * delta; particle.lifetime -= delta; } @@ -114,7 +114,8 @@ static inline glm::vec4 calc_lights( light = glm::max( light, MainBatch::sampleLight( - particle.position - size * glm::vec3(x, y, z), + particle.position - + worldvec3(size * glm::vec3(x, y, z)), chunks, backlight ) diff --git a/src/graphics/render/TextNote.cpp b/src/graphics/render/TextNote.cpp index 7c4797fd3..48881196d 100644 --- a/src/graphics/render/TextNote.cpp +++ b/src/graphics/render/TextNote.cpp @@ -1,6 +1,6 @@ #include "TextNote.hpp" -TextNote::TextNote(std::wstring text, NotePreset preset, glm::vec3 position) +TextNote::TextNote(std::wstring text, NotePreset preset, worldvec3 position) : text(std::move(text)), preset(std::move(preset)), position(std::move(position)) { @@ -30,11 +30,11 @@ void TextNote::updatePreset(const dv::value& data) { preset.deserialize(data); } -void TextNote::setPosition(const glm::vec3& position) { +void TextNote::setPosition(const worldvec3& position) { this->position = position; } -const glm::vec3& TextNote::getPosition() const { +const worldvec3& TextNote::getPosition() const { return position; } diff --git a/src/graphics/render/TextNote.hpp b/src/graphics/render/TextNote.hpp index 0fc8f4afd..c05d14465 100644 --- a/src/graphics/render/TextNote.hpp +++ b/src/graphics/render/TextNote.hpp @@ -7,13 +7,13 @@ class TextNote { std::wstring text; NotePreset preset; - glm::vec3 position; + worldvec3 position; entityid_t entity = ENTITY_NONE; glm::vec3 xAxis {1, 0, 0}; glm::vec3 yAxis {0, 1, 0}; public: - TextNote(std::wstring text, NotePreset preset, glm::vec3 position); + TextNote(std::wstring text, NotePreset preset, worldvec3 position); void setText(std::wstring_view text); void setEntity(entityid_t eid); @@ -25,8 +25,8 @@ public: void updatePreset(const dv::value& data); - void setPosition(const glm::vec3& position); - const glm::vec3& getPosition() const; + void setPosition(const worldvec3& position); + const worldvec3& getPosition() const; const glm::vec3& getAxisX() const; const glm::vec3& getAxisY() const; diff --git a/src/graphics/render/TextsRenderer.cpp b/src/graphics/render/TextsRenderer.cpp index 2cd0cc575..2b9c7b027 100644 --- a/src/graphics/render/TextsRenderer.cpp +++ b/src/graphics/render/TextsRenderer.cpp @@ -35,16 +35,16 @@ void TextsRenderer::renderNote( ) { const auto& text = note.getText(); const auto& preset = note.getPreset(); - auto pos = note.getPosition(); + auto worldPos = note.getPosition(); entityid_t eid = note.getEntity(); if (eid != ENTITY_NONE) { if (auto entity = level.entities->get(eid)) { - pos += entity->getTransform().displayPos; + worldPos += entity->getTransform().displayPos; } } - pos = util::to_local(pos, camera.getOrigin()); + glm::vec3 pos = util::to_local(worldPos, camera.getOrigin()); const glm::vec3 cameraPos = camera.getLocalPosition(); if (util::distance2(pos, cameraPos) > diff --git a/src/logic/scripting/lua/libs/libblockwraps.cpp b/src/logic/scripting/lua/libs/libblockwraps.cpp index a6eba3e8f..baa4ac17c 100644 --- a/src/logic/scripting/lua/libs/libblockwraps.cpp +++ b/src/logic/scripting/lua/libs/libblockwraps.cpp @@ -7,7 +7,7 @@ using namespace scripting; static int l_wrap(lua::State* L) { - auto position = lua::tovec3(L, 1); + auto position = lua::tovec<3, double>(L, 1); std::string texture = lua::require_string(L, 2); float emission = lua::isnumber(L, 3) ? lua::tonumber(L, 3) : 1.0f; glm::vec4 tint = @@ -31,7 +31,7 @@ static int l_unwrap(lua::State* L) { static int l_set_pos(lua::State* L) { if (auto wrapper = renderer->blockWraps->get(lua::tointeger(L, 1))) { - wrapper->position = lua::tovec3(L, 2); + wrapper->position = lua::tovec<3, double>(L, 2); } return 0; } diff --git a/src/logic/scripting/lua/libs/libgeneration.cpp b/src/logic/scripting/lua/libs/libgeneration.cpp index 2e872ec7c..218788330 100644 --- a/src/logic/scripting/lua/libs/libgeneration.cpp +++ b/src/logic/scripting/lua/libs/libgeneration.cpp @@ -24,8 +24,8 @@ static int l_save_fragment(lua::State* L) { } static int l_create_fragment(lua::State* L) { - auto pointA = lua::tovec<3>(L, 1); - auto pointB = lua::tovec<3>(L, 2); + auto pointA = lua::tovec<3, double>(L, 1); + auto pointB = lua::tovec<3, double>(L, 2); bool crop = lua::toboolean(L, 3); bool saveEntities = lua::toboolean(L, 4); diff --git a/src/logic/scripting/lua/libs/libparticles.cpp b/src/logic/scripting/lua/libs/libparticles.cpp index 563f2f2e0..f7c8cf68a 100644 --- a/src/logic/scripting/lua/libs/libparticles.cpp +++ b/src/logic/scripting/lua/libs/libparticles.cpp @@ -9,7 +9,7 @@ using namespace scripting; static int l_emit(lua::State* L) { EmitterOrigin origin; if (lua::istable(L, 1)) { - origin = lua::tovec3(L, 1); + origin = lua::tovec<3, double>(L, 1); } else { origin = static_cast(lua::tointeger(L, 1)); } @@ -47,8 +47,8 @@ static int l_get_origin(lua::State* L) { u64id_t id = lua::touinteger(L, 1); if (auto emitter = renderer->particles->getEmitter(id)) { const auto& origin = emitter->getOrigin(); - if (auto pos = std::get_if(&origin)) { - return lua::pushvec3(L, *pos); + if (auto pos = std::get_if(&origin)) { + return lua::pushvec(L, *pos); } else if (auto entityid = std::get_if(&origin)) { return lua::pushinteger(L, *entityid); } @@ -60,7 +60,7 @@ static int l_set_origin(lua::State* L) { u64id_t id = lua::touinteger(L, 1); if (auto emitter = renderer->particles->getEmitter(id)) { if (lua::istable(L, 2)) { - emitter->setOrigin(lua::tovec3(L, 2)); + emitter->setOrigin(lua::tovec<3, double>(L, 2)); } else { emitter->setOrigin(static_cast(lua::tointeger(L, 2))); } diff --git a/src/logic/scripting/lua/libs/libpathfinding.cpp b/src/logic/scripting/lua/libs/libpathfinding.cpp index d702633e3..55f5a3fc3 100644 --- a/src/logic/scripting/lua/libs/libpathfinding.cpp +++ b/src/logic/scripting/lua/libs/libpathfinding.cpp @@ -46,8 +46,8 @@ static int push_route(lua::State* L, const voxels::Route& route) { static int l_make_route(lua::State* L) { if (auto agent = get_agent(L)) { - auto start = lua::tovec3(L, 2); - auto target = lua::tovec3(L, 3); + auto start = lua::tovec<3, double>(L, 2); + auto target = lua::tovec<3, double>(L, 3); agent->state = {}; agent->start = glm::floor(start); agent->target = target; @@ -62,8 +62,8 @@ static int l_make_route(lua::State* L) { static int l_make_route_async(lua::State* L) { if (auto agent = get_agent(L)) { - auto start = lua::tovec3(L, 2); - auto target = lua::tovec3(L, 3); + auto start = lua::tovec<3, double>(L, 2); + auto target = lua::tovec<3, double>(L, 3); agent->state = {}; agent->start = glm::floor(start); agent->target = target; diff --git a/src/logic/scripting/lua/libs/libtext3d.cpp b/src/logic/scripting/lua/libs/libtext3d.cpp index 0c3957cce..90be4c23e 100644 --- a/src/logic/scripting/lua/libs/libtext3d.cpp +++ b/src/logic/scripting/lua/libs/libtext3d.cpp @@ -6,7 +6,7 @@ using namespace scripting; static int l_show(lua::State* L) { - auto position = lua::tovec3(L, 1); + auto position = lua::tovec<3, double>(L, 1); auto text = lua::require_wstring(L, 2); auto preset = lua::tovalue(L, 3); auto extension = lua::tovalue(L, 4); @@ -47,7 +47,7 @@ static int l_get_pos(lua::State* L) { } static int l_set_pos(lua::State* L) { if (auto note = renderer->texts->get(lua::tointeger(L, 1))) { - note->setPosition(lua::tovec3(L, 2)); + note->setPosition(lua::tovec<3, double>(L, 2)); } return 0; } diff --git a/src/voxels/Chunks.cpp b/src/voxels/Chunks.cpp index 906aad91b..04c946c4f 100644 --- a/src/voxels/Chunks.cpp +++ b/src/voxels/Chunks.cpp @@ -52,7 +52,7 @@ voxel& Chunks::require(int32_t x, int32_t y, int32_t z) const { return blocks_agent::require(*this, x, y, z); } -const AABB* Chunks::isObstacleAt(float x, float y, float z) const { +const AABB* Chunks::isObstacleAt(double x, double y, double z) const { int ix = std::floor(x); int iy = std::floor(y); int iz = std::floor(z); diff --git a/src/voxels/Chunks.hpp b/src/voxels/Chunks.hpp index 0d3f2072f..7e4f66a7a 100644 --- a/src/voxels/Chunks.hpp +++ b/src/voxels/Chunks.hpp @@ -123,9 +123,9 @@ public: const worldvec3& start, const glm::vec3& dir, float maxDist ) const; - const AABB* isObstacleAt(float x, float y, float z) const; + const AABB* isObstacleAt(double x, double y, double z) const; - const AABB* isObstacleAt(const glm::vec3& pos) const { + const AABB* isObstacleAt(const worldvec3& pos) const { return isObstacleAt(pos.x, pos.y, pos.z); }