From 458e0005690ea9d579588a0a12368fc2c2c9a93a Mon Sep 17 00:00:00 2001 From: untodesu Date: Tue, 1 Jul 2025 03:08:39 +0500 Subject: I hyper-focued on refactoring again - I put a cool-sounding "we are number one" remix on repeat and straight up grinded the entire repository to a better state until 03:09 AM. I guess I have something wrong in my brain that makes me do this shit --- game/client/world/player_target.cc | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 game/client/world/player_target.cc (limited to 'game/client/world/player_target.cc') diff --git a/game/client/world/player_target.cc b/game/client/world/player_target.cc new file mode 100644 index 0000000..6da8129 --- /dev/null +++ b/game/client/world/player_target.cc @@ -0,0 +1,68 @@ +#include "client/pch.hh" + +#include "client/world/player_target.hh" + +#include "shared/world/dimension.hh" +#include "shared/world/ray_dda.hh" + +#include "shared/coord.hh" + +#include "client/entity/camera.hh" +#include "client/world/outline.hh" + +#include "client/game.hh" +#include "client/globals.hh" +#include "client/session.hh" + +constexpr static float MAX_REACH = 16.0f; + +voxel_id world::player_target::voxel; +voxel_pos world::player_target::coord; +voxel_pos world::player_target::normal; +const world::VoxelInfo* world::player_target::info; + +void world::player_target::init(void) +{ + world::player_target::voxel = NULL_VOXEL_ID; + world::player_target::coord = voxel_pos(); + world::player_target::normal = voxel_pos(); + world::player_target::info = nullptr; +} + +void world::player_target::update(void) +{ + if(session::is_ingame()) { + RayDDA ray(globals::dimension, entity::camera::position_chunk, entity::camera::position_local, entity::camera::direction); + + do { + world::player_target::voxel = ray.step(); + + if(world::player_target::voxel != NULL_VOXEL_ID) { + world::player_target::coord = ray.vpos; + world::player_target::normal = ray.vnormal; + world::player_target::info = world::voxel_registry::find(world::player_target::voxel); + break; + } + + world::player_target::coord = voxel_pos(); + world::player_target::normal = voxel_pos(); + world::player_target::info = nullptr; + } while(ray.distance < MAX_REACH); + } else { + world::player_target::voxel = NULL_VOXEL_ID; + world::player_target::coord = voxel_pos(); + world::player_target::normal = voxel_pos(); + world::player_target::info = nullptr; + } +} + +void world::player_target::render(void) +{ + if((world::player_target::voxel != NULL_VOXEL_ID) && !client_game::hide_hud) { + auto cpos = coord::to_chunk(world::player_target::coord); + auto fpos = coord::to_local(world::player_target::coord); + + world::outline::prepare(); + world::outline::cube(cpos, glm::fvec3(fpos), glm::fvec3(1.0f), 2.0f, glm::fvec4(0.0f, 0.0f, 0.0f, 1.0f)); + } +} -- cgit