Compare commits

..

No commits in common. "6081575eae9fafe16663b7515cd180aed27a2201" and "dc25a6f23b80f6abc06194ca30da17d0e8b27f11" have entirely different histories.

25 changed files with 49 additions and 244 deletions

View File

@ -154,20 +154,6 @@ std::shared_ptr<assets::Item> assets::Item::LoadFromFile(const std::string& path
{ {
iss >> item->damage; iss >> item->damage;
} }
else if (command == "aimtype")
{
std::string aimtype_str;
iss >> aimtype_str;
if (aimtype_str == "none")
item->aim_type = AIMTYPE_NONE;
else if (aimtype_str == "crosshair")
item->aim_type = AIMTYPE_CROSSHAIR;
else if (aimtype_str == "scope")
item->aim_type = AIMTYPE_SCOPE;
else
throw std::runtime_error("Invalid aim type: " + aimtype_str);
}
else else
{ {
throw std::runtime_error("Unknown item command: " + command); throw std::runtime_error("Unknown item command: " + command);

View File

@ -17,7 +17,7 @@ enum ItemType
enum ItemAimType enum ItemAimType
{ {
AIMTYPE_NONE, AIMTYPE_NONE,
AIMTYPE_CROSSHAIR, AIMTYPE_AIM,
AIMTYPE_SCOPE, AIMTYPE_SCOPE,
}; };
@ -59,8 +59,6 @@ struct Item
std::string idle_anim; std::string idle_anim;
std::string use_anim; // use or fire std::string use_anim; // use or fire
ItemAimType aim_type = AIMTYPE_NONE;
// consumable // consumable
std::string action; std::string action;

View File

@ -50,18 +50,6 @@ std::shared_ptr<const audio::Sound> audio::Sound::LoadFromFile(const std::string
{ {
iss >> sound->pitch_; iss >> sound->pitch_;
} }
else if (cmd == "refdistance")
{
iss >> sound->ref_distance_;
}
else if (cmd == "rolloff")
{
iss >> sound->rolloff_ractor_;
}
else if (cmd == "maxdistance")
{
iss >> sound->max_distance_;
}
}); });
if (sound->category_name_.empty()) if (sound->category_name_.empty())

View File

@ -20,10 +20,6 @@ public:
float GetVolume() const { return volume_; } float GetVolume() const { return volume_; }
float GetPitch() const { return pitch_; } float GetPitch() const { return pitch_; }
float GetRefDistance() const { return ref_distance_; }
float GetRolloffFactor() const { return rolloff_ractor_; }
float GetMaxDistance() const { return max_distance_; }
~Sound(); ~Sound();
private: private:
@ -33,10 +29,6 @@ private:
float volume_ = 1.0f; float volume_ = 1.0f;
float pitch_ = 1.0f; float pitch_ = 1.0f;
float ref_distance_ = 1.0f;
float rolloff_ractor_= 1.0f;
float max_distance_ = 200.0f;
}; };
} // namespace audio } // namespace audio

View File

@ -12,11 +12,6 @@ audio::SoundSource::SoundSource(Player* player, std::shared_ptr<const Sound> sou
SetPitch(1.0f); SetPitch(1.0f);
alSourcei(source_, AL_BUFFER, sound_->GetBufferId()); alSourcei(source_, AL_BUFFER, sound_->GetBufferId());
// params
alSourcef(source_, AL_REFERENCE_DISTANCE, sound_->GetRefDistance());
alSourcef(source_, AL_ROLLOFF_FACTOR, sound_->GetRolloffFactor());
alSourcef(source_, AL_MAX_DISTANCE, sound_->GetMaxDistance());
} }
void audio::SoundSource::SetLooping(bool looping) void audio::SoundSource::SetLooping(bool looping)

View File

@ -36,42 +36,28 @@ void game::CameraController::Recalculate(collision::DynamicsWorld* world)
glm::vec3 start_noaim(0.0f); glm::vec3 start_noaim(0.0f);
glm::vec3 start_aim(0.0f); glm::vec3 start_aim(0.0f);
bool scope = ShouldDrawScope();
float distance_noaim = 5.0f; float distance_noaim = 5.0f;
glm::vec3 aim_end_offset = right * 0.4f - forward_ * 1.8f; auto aim_end_offset = right * 0.4f - forward_ * 1.8f;
if (character_transform_) if (character_transform_)
{ {
auto up = UpFromMatrix(*character_transform_); auto up = UpFromMatrix(*character_transform_);
start_noaim = TranslationFromMatrix(*character_transform_) + up * (scope ? 1.8f : 2.0f); start_noaim = TranslationFromMatrix(*character_transform_) + up * 2.0f;
start_aim = start_noaim - up * 0.3f;
if (!scope)
{
start_aim = start_noaim - up * 0.3f;
}
else
{
start_aim = start_noaim;
aim_end_offset = glm::vec3(0.0f);
}
} }
if (rideable_transform_) if (rideable_transform_)
{ {
start_noaim = TranslationFromMatrix(*rideable_transform_) + glm::vec3(0.0f, 0.0f, 2.0f); start_noaim = TranslationFromMatrix(*rideable_transform_) + glm::vec3(0.0f, 0.0f, 2.0f);
distance_noaim = 8.0f; distance_noaim = 8.0f;
aim_end_offset = right * 0.3f - forward_ * 4.5f + glm::vec3(0.0f, 0.0f, 0.8f);
if (!scope)
{
aim_end_offset = right * 0.3f - forward_ * 4.5f + glm::vec3(0.0f, 0.0f, 0.8f);
}
} }
glm::vec3 end_noaim = start_noaim - forward_ * distance_noaim; glm::vec3 end_noaim = start_noaim - forward_ * distance_noaim;
glm::vec3 end_aim = start_aim + aim_end_offset; glm::vec3 end_aim = start_aim + aim_end_offset;
auto aim_factor_smooth = scope ? 1.0f : glm::smoothstep(0.0f, 1.0f, aim_factor_); auto aim_factor_smooth = glm::smoothstep(0.0f, 1.0f, aim_factor_);
auto start = glm::mix(start_noaim, start_aim, aim_factor_smooth); auto start = glm::mix(start_noaim, start_aim, aim_factor_smooth);
auto end = glm::mix(end_noaim, end_aim, aim_factor_smooth); auto end = glm::mix(end_noaim, end_aim, aim_factor_smooth);
@ -88,24 +74,3 @@ glm::mat4 game::CameraController::GetViewMatrix() const
{ {
return glm::lookAt(eye_, eye_ + forward_, glm::vec3(0.0f, 0.0f, 1.0f)); return glm::lookAt(eye_, eye_ + forward_, glm::vec3(0.0f, 0.0f, 1.0f));
} }
bool game::CameraController::ShouldDrawCrosshair() const
{
return aim_crosshair_ && !aim_scope_ && aim_factor_ > 0.5f;
}
bool game::CameraController::ShouldDrawScope() const
{
return aim_crosshair_ && aim_scope_ && aim_factor_ > 0.7f;
}
float game::CameraController::GetFov() const
{
if (ShouldDrawScope())
{
return glm::mix(25.0f, 20.0f, glm::smoothstep(0.0f, 1.0f, (aim_factor_ - 0.7f) / 0.3f));
}
// return glm::mix(90.0f, 80.0f, aim_factor_);
return 90.0f;
}

View File

@ -18,7 +18,6 @@ public:
float GetPitch() const { return pitch_; } float GetPitch() const { return pitch_; }
void SetAiming(bool aiming) { aiming_ = aiming; } void SetAiming(bool aiming) { aiming_ = aiming; }
void SetAimType(bool crosshair, bool scope) { aim_crosshair_ = crosshair; aim_scope_ = scope; }
void Update(float time); void Update(float time);
void Recalculate(collision::DynamicsWorld* world); void Recalculate(collision::DynamicsWorld* world);
@ -28,11 +27,6 @@ public:
glm::mat4 GetViewMatrix() const; glm::mat4 GetViewMatrix() const;
float GetAimFactor() const { return aim_factor_; } float GetAimFactor() const { return aim_factor_; }
bool ShouldDrawCrosshair() const;
bool ShouldDrawScope() const;
float GetFov() const;
private: private:
const glm::mat4* character_transform_ = nullptr; const glm::mat4* character_transform_ = nullptr;
const glm::mat4* rideable_transform_ = nullptr; const glm::mat4* rideable_transform_ = nullptr;
@ -43,9 +37,6 @@ private:
bool aiming_ = false; bool aiming_ = false;
float aim_factor_ = 0.0f; float aim_factor_ = 0.0f;
bool aim_crosshair_ = false;
bool aim_scope_ = false;
glm::vec3 eye_; glm::vec3 eye_;
glm::vec3 forward_; glm::vec3 forward_;

View File

@ -9,8 +9,6 @@ using CameraFlags = uint8_t;
enum CameraFlag : CameraFlags enum CameraFlag : CameraFlags
{ {
CAM_AIMING = 1, CAM_AIMING = 1,
CAM_AIM_CROSSHAIR = 2,
CAM_AIM_SCOPE = 4,
}; };
struct CameraInfo struct CameraInfo

View File

@ -486,6 +486,5 @@ void game::Player::SendMenuMsgs()
void game::Player::UpdateCamera() void game::Player::UpdateCamera()
{ {
camera_controller_.SetAiming(camera_info_.flags & CAM_AIMING); camera_controller_.SetAiming(camera_info_.flags & CAM_AIMING);
camera_controller_.SetAimType(camera_info_.flags & CAM_AIM_CROSSHAIR, camera_info_.flags & CAM_AIM_SCOPE);
camera_controller_.Update(1.0f / 25.0f); camera_controller_.Update(1.0f / 25.0f);
} }

View File

@ -171,8 +171,6 @@ void game::PlayerCharacter::OnHeldItemChanged()
{ {
const auto& item = GetHeldItem(); const auto& item = GetHeldItem();
hud_data_.held_item = item ? item->def->name : ""; hud_data_.held_item = item ? item->def->name : "";
// UpdatePlayerCamera(); // might be required?
} }
bool game::PlayerCharacter::HaveAmmo(const std::string& ammo_name) bool game::PlayerCharacter::HaveAmmo(const std::string& ammo_name)
@ -232,22 +230,6 @@ void game::PlayerCharacter::UpdatePlayerCamera()
if (GetAiming()) if (GetAiming())
camera_info.flags |= CAM_AIMING; camera_info.flags |= CAM_AIMING;
assets::ItemAimType aim_type = assets::AIMTYPE_NONE;
const auto& held_item = GetHeldItem();
if (held_item)
{
aim_type = held_item->def->aim_type;
}
if (aim_type != assets::AIMTYPE_NONE)
{
camera_info.flags |= CAM_AIM_CROSSHAIR;
if (aim_type == assets::AIMTYPE_SCOPE)
{
camera_info.flags |= CAM_AIM_SCOPE;
}
}
player_->SetCamera(camera_info); player_->SetCamera(camera_info);
} }

View File

@ -128,9 +128,6 @@ void game::TuningWorld::OpenGroupMenu(const VehicleTuningGroup& group)
btn.SetSelection(state_text); btn.SetSelection(state_text);
mounted_part_menu_item_ = &btn; mounted_part_menu_item_ = &btn;
// play vrtačka sound
vehicle_->PlaySound("tuning");
}); });
if (GetPartState(group.id, part_id, &state_text)) if (GetPartState(group.id, part_id, &state_text))

View File

@ -189,7 +189,7 @@ void game::Vehicle::ProcessInput()
float steeringClamp = std::max(minsc, (1.f - (std::abs(speed) / sl)) * maxsc); float steeringClamp = std::max(minsc, (1.f - (std::abs(speed) / sl)) * maxsc);
// steeringClamp = .5f; // steeringClamp = .5f;
float steeringSpeed = steeringClamp * steering_speed_; float steeringSpeed = steeringClamp * 5.0f;
if (steering_analog_) if (steering_analog_)
steeringSpeed *= 3.0f; steeringSpeed *= 3.0f;
@ -641,7 +641,6 @@ void game::Vehicle::ApplyTuning(const VehicleTuning& tuning)
} }
health_ = tuning_ctx_.health; health_ = tuning_ctx_.health;
steering_speed_ = tuning_ctx_.steering;
// (re)create physics // (re)create physics
physics_.reset(); physics_.reset();

View File

@ -136,7 +136,6 @@ private:
float steering_ = 0.0f; float steering_ = 0.0f;
bool steering_analog_ = false; bool steering_analog_ = false;
float target_steering_ = 0.0f; float target_steering_ = 0.0f;
float steering_speed_ = 5.0f;
std::vector<VehicleWheelState> wheels_; std::vector<VehicleWheelState> wheels_;

View File

@ -14,8 +14,6 @@ static float game::VehicleTuningContext::* GetCtxVariablePointer(const std::stri
return &game::VehicleTuningContext::braking_force; return &game::VehicleTuningContext::braking_force;
if (name == "health") if (name == "health")
return &game::VehicleTuningContext::health; return &game::VehicleTuningContext::health;
if (name == "steering")
return &game::VehicleTuningContext::steering;
throw std::runtime_error("tuning list: invalid variable " + name); throw std::runtime_error("tuning list: invalid variable " + name);
} }

View File

@ -35,7 +35,6 @@ struct VehicleTuningContext
float engine_force; float engine_force;
float braking_force; float braking_force;
float health; float health;
float steering;
std::vector<VehicleWheelTuningContext> wheels; std::vector<VehicleWheelTuningContext> wheels;
}; };

View File

@ -112,7 +112,6 @@ void game::view::CharacterView::Update(const UpdateInfo& info)
if (item_) if (item_)
{ {
item_node_.UpdateMatrix(); item_node_.UpdateMatrix();
fire_snd_node_.UpdateMatrix();
} }
} }
@ -374,9 +373,6 @@ void game::view::CharacterView::SetItem(const std::string& item_name)
item_node_.parent = bone_node ? bone_node : &root_; item_node_.parent = bone_node ? bone_node : &root_;
item_node_.local = item_->bone_offset; item_node_.local = item_->bone_offset;
fire_snd_node_.parent = &item_node_;
fire_snd_node_.local.position = glm::vec3(0.0f, 0.1f, 0.0f);
// snd // snd
if (!item_->fire_snd.empty()) if (!item_->fire_snd.empty())
{ {
@ -390,6 +386,7 @@ void game::view::CharacterView::SetItem(const std::string& item_name)
auto loc = item_->model->GetLocation(item_->fire_fx_loc); auto loc = item_->model->GetLocation(item_->fire_fx_loc);
fire_fx_offset_ = loc ? loc->position : glm::vec3(0.0f); fire_fx_offset_ = loc ? loc->position : glm::vec3(0.0f);
} }
} }
void game::view::CharacterView::DrawItem(const DrawArgs& args) void game::view::CharacterView::DrawItem(const DrawArgs& args)
@ -414,7 +411,7 @@ void game::view::CharacterView::FireItem()
if (fire_snd_) if (fire_snd_)
{ {
auto snd = audioplayer_.PlaySound(fire_snd_, &fire_snd_node_); auto snd = audioplayer_.PlaySound(fire_snd_, &item_node_);
// snd->SetPosition(item_node_.GetGlobalPosition()); // snd->SetPosition(item_node_.GetGlobalPosition());
} }

View File

@ -84,7 +84,6 @@ private:
std::string item_name_; std::string item_name_;
TransformNode item_node_; TransformNode item_node_;
TransformNode fire_snd_node_;
std::shared_ptr<const assets::Item> item_; std::shared_ptr<const assets::Item> item_;
std::shared_ptr<const audio::Sound> fire_snd_; std::shared_ptr<const audio::Sound> fire_snd_;
std::shared_ptr<const assets::Effect> fire_fx_; std::shared_ptr<const assets::Effect> fire_fx_;

View File

@ -84,10 +84,6 @@ void game::view::ClientSession::Input(game::PlayerInputType in, bool pressed, bo
void game::view::ClientSession::ProcessMouseMove(float delta_yaw, float delta_pitch) void game::view::ClientSession::ProcessMouseMove(float delta_yaw, float delta_pitch)
{ {
auto sens_mult = glm::mix(1.0f, 0.3f, camera_controller_.GetAimFactor()); auto sens_mult = glm::mix(1.0f, 0.3f, camera_controller_.GetAimFactor());
if (camera_controller_.ShouldDrawScope())
{
sens_mult = 0.1f;
}
float yaw = glm::mod(camera_controller_.GetYaw() + delta_yaw * sens_mult, glm::two_pi<float>()); float yaw = glm::mod(camera_controller_.GetYaw() + delta_yaw * sens_mult, glm::two_pi<float>());
@ -307,19 +303,10 @@ void game::view::ClientSession::UpdateCamera(const UpdateInfo& info)
camera_controller_.SetRideableTransform(rideable ? &rideable->GetRoot().matrix : nullptr); camera_controller_.SetRideableTransform(rideable ? &rideable->GetRoot().matrix : nullptr);
camera_controller_.SetAiming(camera_info_.flags & CAM_AIMING); camera_controller_.SetAiming(camera_info_.flags & CAM_AIMING);
camera_controller_.SetAimType(camera_info_.flags & CAM_AIM_CROSSHAIR, camera_info_.flags & CAM_AIM_SCOPE);
camera_controller_.Update(info.delta_time); camera_controller_.Update(info.delta_time);
camera_controller_.Recalculate(world_.get()); camera_controller_.Recalculate(world_.get());
hud_.SetDisplayCrosshair(camera_controller_.ShouldDrawCrosshair()); hud_.SetDisplayCrosshair(camera_controller_.GetAimFactor() >= 0.5f);
hud_.SetDisplayScope(camera_controller_.ShouldDrawScope());
// hide character if scope
if (character)
{
character->SetVisible(!camera_controller_.ShouldDrawScope());
}
} }
void game::view::ClientSession::DrawWorld(gfx::DrawList& dlist, gfx::DrawListParams& params, gui::Context& gui) void game::view::ClientSession::DrawWorld(gfx::DrawList& dlist, gfx::DrawListParams& params, gui::Context& gui)
@ -330,7 +317,7 @@ void game::view::ClientSession::DrawWorld(gfx::DrawList& dlist, gfx::DrawListPar
const float farplane = 3000.0f; const float farplane = 3000.0f;
glm::mat4 proj = glm::perspective(glm::radians(camera_controller_.GetFov() * 0.5f), aspect, 0.1f, farplane); glm::mat4 proj = glm::perspective(glm::radians(45.0f), aspect, 0.1f, farplane);
glm::mat4 view = camera_controller_.GetViewMatrix(); glm::mat4 view = camera_controller_.GetViewMatrix();
params.view_proj = proj * view; params.view_proj = proj * view;

View File

@ -45,9 +45,6 @@ public:
Sphere GetBoundingSphere() const { return Sphere{root_.GetGlobalPosition(), radius_}; } Sphere GetBoundingSphere() const { return Sphere{root_.GetGlobalPosition(), radius_}; }
const TransformNode& GetRoot() const { return root_; } const TransformNode& GetRoot() const { return root_; }
void SetVisible(bool visible) { visible_ = visible; }
bool IsVisible() const { return visible_; }
virtual ~EntityView() = default; virtual ~EntityView() = default;
protected: protected:
@ -69,7 +66,6 @@ protected:
EntityView* parent_ = nullptr; EntityView* parent_ = nullptr;
float radius_ = 1.0f; float radius_ = 1.0f;
bool visible_ = true;
audio::Player audioplayer_; audio::Player audioplayer_;

View File

@ -22,7 +22,7 @@ static const game::view::WorldEnvKeyframe env_kfs[] = {
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // sun halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.00002f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
@ -35,7 +35,7 @@ static const game::view::WorldEnvKeyframe env_kfs[] = {
glm::vec4(1.0f, 0.8f, 0.6f, 0.2f), // sun halfsphere color glm::vec4(1.0f, 0.8f, 0.6f, 0.2f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.00001f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
@ -48,72 +48,72 @@ static const game::view::WorldEnvKeyframe env_kfs[] = {
glm::vec4(1.0f, 1.0f, 1.0f, 0.4f), // sun halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.4f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.00001f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
12.0f, // time 12.0f, // time
glm::vec3(0.6f, 0.8f, 1.0f) * 1.2f, // clear color glm::vec3(0.6f, 0.8f, 1.0f), // clear color
glm::vec3(0.5f, 0.5f, 0.45f) * 1.1f, // ambient color glm::vec3(0.5f, 0.5f, 0.5f) * 0.9f, // ambient color
glm::vec3(1.0f, 0.95f, 0.7f) * 0.9f, // sun color glm::vec3(1.0f, 0.95f, 0.7f) * 0.9f, // sun color
1.0f, // sun light source 1.0f, // sun light source
glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // sun disc color glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // sun disc color
glm::vec4(1.0f, 0.9f, 0.9f, 0.5f), // sun halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.7f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.000001f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
17.0f, // time 17.0f, // time
glm::vec3(0.6f, 0.8f, 1.0f) * 1.2f, // clear color glm::vec3(0.5f, 0.7f, 1.0f) * 0.9f, // clear color
glm::vec3(0.5f, 0.5f, 0.4f) * 1.4f, // ambient color glm::vec3(0.5f, 0.5f, 0.5f) * 1.1f, // ambient color
glm::vec3(1.0f, 0.95f, 0.7f) * 0.9f, // sun color glm::vec3(1.0f, 0.95f, 0.7f) * 0.9f, // sun color
1.0f, // sun light source 1.0f, // sun light source
glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // sun disc color glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // sun disc color
glm::vec4(1.0f, 0.85f, 0.6f, 0.7f), // sun halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.5f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.000001f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
17.5f, // time 17.5f, // time
glm::vec3(0.6f, 0.8f, 1.0f) * 1.1f, // clear color glm::vec3(0.5f, 0.7f, 1.0f) * 0.8f, // clear color
glm::vec3(0.8f, 0.6f, 0.4f) * 1.1f, // ambient color glm::vec3(0.8f, 0.6f, 0.5f) * 0.8f, // ambient color
glm::vec3(1.0f, 0.8f, 0.6f) * 0.8f, // sun color glm::vec3(1.0f, 0.8f, 0.6f) * 0.8f, // sun color
1.0f, // sun light source 1.0f, // sun light source
glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // sun disc color glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // sun disc color
glm::vec4(1.0f, 0.7f, 0.5f, 1.0f), // sun halfsphere color glm::vec4(1.0f, 0.7f, 0.5f, 1.0f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.2f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 0.2f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.000002f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
18.0f, // time 18.0f, // time
glm::vec3(0.5f, 0.7f, 1.0f) * 0.7f, // clear color glm::vec3(0.5f, 0.7f, 1.0f) * 0.7f, // clear color
glm::vec3(0.8f, 0.6f, 0.4f) * 0.8f, // ambient color glm::vec3(0.8f, 0.6f, 0.5f) * 0.8f, // ambient color
glm::vec3(1.0f, 0.7f, 0.6f) * 0.2f, // sun color glm::vec3(1.0f, 0.8f, 0.6f) * 0.8f, // sun color
1.0f, // sun light source 0.0f, // sun light source
glm::vec4(1.0f, 0.8f, 0.7f, 1.0f), // sun disc color glm::vec4(1.0f, 0.8f, 0.7f, 1.0f), // sun disc color
glm::vec4(1.0f, 0.7f, 0.5f, 1.0f), // sun halfsphere color glm::vec4(1.0f, 0.7f, 0.5f, 1.0f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.2f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 0.2f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.000005f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
19.0f, // time 19.0f, // time
glm::vec3(0.1f, 0.15f, 0.3f), // clear color glm::vec3(0.1f, 0.15f, 0.3f), // clear color
glm::vec3(0.4f, 0.4f, 0.4f), // ambient color glm::vec3(0.4f, 0.4f, 0.4f), // ambient color
glm::vec3(1.0f, 0.7f, 0.6f) * 0.2f, // sun color glm::vec3(0.5f, 0.8f, 1.0f) * 0.4f, // sun color
0.0f, // sun light source -1.0f, // sun light source
glm::vec4(1.0f, 0.5f, 0.3f, 1.0f), // sun disc color glm::vec4(1.0f, 0.5f, 0.3f, 1.0f), // sun disc color
glm::vec4(1.0f, 0.5f, 0.2f, 0.8f), // sun halfsphere color glm::vec4(1.0f, 0.5f, 0.2f, 0.8f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.00001f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
game::view::WorldEnvKeyframe{ game::view::WorldEnvKeyframe{
@ -126,7 +126,7 @@ static const game::view::WorldEnvKeyframe env_kfs[] = {
glm::vec4(1.0f, 0.5f, 0.2f, 0.0f), // sun halfsphere color glm::vec4(1.0f, 0.5f, 0.2f, 0.0f), // sun halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), // moon disc color
glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color glm::vec4(1.0f, 1.0f, 1.0f, 0.1f), // moon halfsphere color
glm::vec4(1.0f, 1.0f, 1.0f, 0.00003f), // fog glm::vec4(1.0f, 1.0f, 1.0f, 10000.0f), // fog
}, },
@ -165,7 +165,7 @@ void game::view::WorldEnv::Draw(const DrawArgs& args)
args.env.ambient_light = glm::mix(kf1->ambient_color, kf2->ambient_color, t); args.env.ambient_light = glm::mix(kf1->ambient_color, kf2->ambient_color, t);
args.env.sun_color = glm::mix(kf1->sun_color, kf2->sun_color, t); args.env.sun_color = glm::mix(kf1->sun_color, kf2->sun_color, t);
// args.env.fog = glm::mix(kf1->fog, kf2->fog, t); // args.env.fog = glm::mix(kf1->fog, kf2->fog, t);
args.env.fog = glm::vec4(args.env.clear_color, glm::mix(kf1->fog.a, kf2->fog.a, t)); args.env.fog = glm::vec4(args.env.clear_color, 0.00001f);
float dist = args.farplane * 0.5f; float dist = args.farplane * 0.5f;

View File

@ -106,13 +106,8 @@ void game::view::WorldView::Draw(const DrawArgs& args)
for (const auto& [entnum, ent] : ents_) for (const auto& [entnum, ent] : ents_)
{ {
if (!ent->IsVisible()) if (args.frustum.IsSphereVisible(ent->GetBoundingSphere()))
continue; ent->Draw(args);
if (!args.frustum.IsSphereVisible(ent->GetBoundingSphere()))
continue;
ent->Draw(args);
} }
DrawBeams(args); DrawBeams(args);

View File

@ -25,13 +25,6 @@ void gui::Context::DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t c
PushRect(p0, glm::vec2(0.0f), p1, glm::vec2(1.0f), color); PushRect(p0, glm::vec2(0.0f), p1, glm::vec2(1.0f), color);
} }
void gui::Context::DrawRectUV(const glm::vec2& p0, const glm::vec2& p1, const glm::vec2& uv0, const glm::vec2& uv1,
uint32_t color, const gfx::Texture* texture)
{
BeginTexture(texture ? texture : white_tex_.get());
PushRect(p0, uv0, p1, uv1, color);
}
static uint32_t DecodeUTF8Codepoint(const char*& p, const char* end) static uint32_t DecodeUTF8Codepoint(const char*& p, const char* end)
{ {
if (p == end) if (p == end)

View File

@ -35,7 +35,6 @@ public:
void Begin(const glm::vec2& viewport_size); void Begin(const glm::vec2& viewport_size);
void DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t color, const gfx::Texture* texture = nullptr); void DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t color, const gfx::Texture* texture = nullptr);
void DrawRectUV(const glm::vec2& p0, const glm::vec2& p1, const glm::vec2& uv0, const glm::vec2& uv1, uint32_t color, const gfx::Texture* texture);
glm::vec2 MeasureText(std::string_view text); glm::vec2 MeasureText(std::string_view text);
void DrawText(std::string_view text, const glm::vec2& pos, uint32_t color = 0xFFFFFFFF, float scale = 1.0f); void DrawText(std::string_view text, const glm::vec2& pos, uint32_t color = 0xFFFFFFFF, float scale = 1.0f);

View File

@ -23,7 +23,6 @@ static uint32_t COLOR_ERROR = 0xFF7777FF;
gui::PlayerHud::PlayerHud(const float& time) : time_(time) gui::PlayerHud::PlayerHud(const float& time) : time_(time)
{ {
crosshair_texture_ = assets::CacheManager::GetTexture("data/crosshair.png"); crosshair_texture_ = assets::CacheManager::GetTexture("data/crosshair.png");
scope_texture_ = assets::CacheManager::GetTexture("data/scope.png");
UpdateWeaponSlotsText(); UpdateWeaponSlotsText();
} }
@ -74,9 +73,8 @@ void gui::PlayerHud::Update(float delta_time)
void gui::PlayerHud::Draw(Context& ctx) const void gui::PlayerHud::Draw(Context& ctx) const
{ {
DrawCrosshair(ctx);
DrawScope(ctx);
DrawPain(ctx); DrawPain(ctx);
DrawCrosshair(ctx);
DrawHealthBar(ctx); DrawHealthBar(ctx);
DrawItemInfo(ctx); DrawItemInfo(ctx);
DrawUseTarget(ctx); DrawUseTarget(ctx);
@ -104,22 +102,6 @@ void gui::PlayerHud::UpdateWeaponSlotsText()
} }
} }
uint32_t gui::PlayerHud::GetCrosshairColor() const
{
glm::vec3 color(1.0f);
if (damage_dealt_factor_ > 0.01f)
{
color = glm::mix(color, glm::vec3(0.3f), damage_dealt_factor_);
}
if (damage_dealt_kill_factor_ > 0.01f)
{
color = glm::mix(color, glm::vec3(1.0f, 0.1f, 0.1f), damage_dealt_kill_factor_);
}
return glm::packUnorm4x8(glm::vec4(color, 1.0f));
}
void gui::PlayerHud::DrawPain(Context& ctx) const void gui::PlayerHud::DrawPain(Context& ctx) const
{ {
if (damage_received_factor_ <= 0.01f) if (damage_received_factor_ <= 0.01f)
@ -134,6 +116,17 @@ void gui::PlayerHud::DrawCrosshair(Context& ctx) const
if (!display_crosshair_) if (!display_crosshair_)
return; return;
glm::vec3 color(1.0f);
if (damage_dealt_factor_ > 0.01f)
{
color = glm::mix(color, glm::vec3(0.3f), damage_dealt_factor_);
}
if (damage_dealt_kill_factor_ > 0.01f)
{
color = glm::mix(color, glm::vec3(1.0f, 0.1f, 0.1f), damage_dealt_kill_factor_);
}
const float crosshair_size = 32.0f; const float crosshair_size = 32.0f;
auto& viewport_size = ctx.GetViewportSize(); auto& viewport_size = ctx.GetViewportSize();
@ -141,41 +134,7 @@ void gui::PlayerHud::DrawCrosshair(Context& ctx) const
auto p0 = viewport_size * 0.5f - crosshair_size * 0.5f; auto p0 = viewport_size * 0.5f - crosshair_size * 0.5f;
auto p1 = p0 + crosshair_size; auto p1 = p0 + crosshair_size;
ctx.DrawRect(p0, p1, GetCrosshairColor(), crosshair_texture_.get()); ctx.DrawRect(p0, p1, glm::packUnorm4x8(glm::vec4(color, 1.0f)), crosshair_texture_.get());
}
void gui::PlayerHud::DrawScope(Context& ctx) const
{
if (!display_scope_)
return;
glm::vec2 p0(0.0f);
glm::vec2 size = ctx.GetViewportSize();
if (size.x < size.y)
{
p0.y += (size.y - size.x) * 0.5f;
size.y = size.x;
ctx.DrawRect(glm::vec2(0.0f), glm::vec2(p0.x + size.x, p0.y + 2.0f), 0xFF000000);
ctx.DrawRect(glm::vec2(p0.x, p0.y + size.y - 2.0f), ctx.GetViewportSize(), 0xFF000000);
}
else
{
p0.x += (size.x - size.y) * 0.5f;
size.x = size.y;
ctx.DrawRect(glm::vec2(0.0f), glm::vec2(p0.x + 2.0f, p0.y + size.y), 0xFF000000);
ctx.DrawRect(glm::vec2(p0.x + size.x - 2.0f, p0.y), ctx.GetViewportSize(), 0xFF000000);
}
p0 = glm::floor(p0);
size = glm::floor(size);
// glm::vec2 p1 = p0 + size * 0.5f;
glm::vec2 p2 = p0 + size;
auto color = GetCrosshairColor();
ctx.DrawRect(p0, p2, color, scope_texture_.get());
} }
void gui::PlayerHud::DrawHealthBar(Context& ctx) const void gui::PlayerHud::DrawHealthBar(Context& ctx) const

View File

@ -21,7 +21,6 @@ public:
void SetUseTargetData(std::string text, std::string error_text, float delay); void SetUseTargetData(std::string text, std::string error_text, float delay);
void SetDisplayCrosshair(bool show) { display_crosshair_ = show; } void SetDisplayCrosshair(bool show) { display_crosshair_ = show; }
void SetDisplayScope(bool show) { display_scope_ = show; }
void ShowDamageReceived(); void ShowDamageReceived();
void ShowDamageDealt(bool kill); void ShowDamageDealt(bool kill);
@ -33,11 +32,8 @@ public:
private: private:
void UpdateWeaponSlotsText(); void UpdateWeaponSlotsText();
uint32_t GetCrosshairColor() const;
void DrawPain(Context& ctx) const; void DrawPain(Context& ctx) const;
void DrawCrosshair(Context& ctx) const; void DrawCrosshair(Context& ctx) const;
void DrawScope(Context& ctx) const;
void DrawHealthBar(Context& ctx) const; void DrawHealthBar(Context& ctx) const;
void DrawItemInfo(Context& ctx) const; void DrawItemInfo(Context& ctx) const;
void DrawUseTarget(Context& ctx) const; void DrawUseTarget(Context& ctx) const;
@ -48,7 +44,6 @@ private:
// resources // resources
std::shared_ptr<const gfx::Texture> crosshair_texture_; std::shared_ptr<const gfx::Texture> crosshair_texture_;
std::shared_ptr<const gfx::Texture> scope_texture_;
// general // general
float health_ = 0.0f; float health_ = 0.0f;
@ -72,7 +67,6 @@ private:
// crosshair & events // crosshair & events
bool display_crosshair_ = false; bool display_crosshair_ = false;
bool display_scope_ = false;
float damage_received_factor_ = 0.0f; float damage_received_factor_ = 0.0f;
float damage_dealt_factor_ = 0.0f; float damage_dealt_factor_ = 0.0f;
float damage_dealt_kill_factor_ = 0.0f; float damage_dealt_kill_factor_ = 0.0f;