Compare commits
3 Commits
4b2446a5f4
...
2ee6d61231
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ee6d61231 | ||
|
|
9bc8984a21 | ||
|
|
e0951c39a7 |
@ -12,12 +12,7 @@ App::App() :
|
|||||||
{
|
{
|
||||||
std::cout << "Initializing App..." << std::endl;
|
std::cout << "Initializing App..." << std::endl;
|
||||||
|
|
||||||
#ifndef EMSCRIPTEN
|
ApplySettings();
|
||||||
audiomaster_.SetMasterVolume(1.0f);
|
|
||||||
#else
|
|
||||||
audiomaster_.SetMasterVolume(2.0f);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
AddChatMessage("Test!");
|
AddChatMessage("Test!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +136,11 @@ void App::Input(game::PlayerInputType in, bool pressed, bool repeated)
|
|||||||
{
|
{
|
||||||
if (in == game::IN_MENU && pressed)
|
if (in == game::IN_MENU && pressed)
|
||||||
{
|
{
|
||||||
|
if (!menu_)
|
||||||
OpenSettings();
|
OpenSettings();
|
||||||
|
else
|
||||||
|
menu_.reset();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,10 +158,8 @@ void App::Input(game::PlayerInputType in, bool pressed, bool repeated)
|
|||||||
|
|
||||||
void App::MouseMove(const glm::vec2& delta)
|
void App::MouseMove(const glm::vec2& delta)
|
||||||
{
|
{
|
||||||
float sensitivity = 0.002f; // Sensitivity factor for mouse movement
|
float delta_yaw = -delta.x * sensitivity_;
|
||||||
|
float delta_pitch = -delta.y * sensitivity_;
|
||||||
float delta_yaw = -delta.x * sensitivity;
|
|
||||||
float delta_pitch = -delta.y * sensitivity;
|
|
||||||
|
|
||||||
if (session_)
|
if (session_)
|
||||||
session_->ProcessMouseMove(delta_yaw, delta_pitch);
|
session_->ProcessMouseMove(delta_yaw, delta_pitch);
|
||||||
@ -210,10 +207,10 @@ void App::DrawChat()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddSlider(gui::Menu& menu, std::string text, int& value, int min, int max)
|
static void AddSlider(gui::Menu& menu, std::string text, int& value, int min, int max, std::function<void()> changed)
|
||||||
{
|
{
|
||||||
auto& slider = menu.Add<gui::SelectMenuItem>(std::move(text));
|
auto& slider = menu.Add<gui::SelectMenuItem>(std::move(text));
|
||||||
auto on_switch = [&slider, &value, min, max] (int v) {
|
auto on_switch = [&slider, &value, min, max, changed] (int v) {
|
||||||
value += v;
|
value += v;
|
||||||
|
|
||||||
// clamp
|
// clamp
|
||||||
@ -223,6 +220,7 @@ static void AddSlider(gui::Menu& menu, std::string text, int& value, int min, in
|
|||||||
value = max;
|
value = max;
|
||||||
|
|
||||||
slider.SetSelectionText(std::to_string(value));
|
slider.SetSelectionText(std::to_string(value));
|
||||||
|
changed();
|
||||||
};
|
};
|
||||||
|
|
||||||
slider.SetSwitchCallback(on_switch);
|
slider.SetSwitchCallback(on_switch);
|
||||||
@ -233,12 +231,41 @@ void App::OpenSettings()
|
|||||||
{
|
{
|
||||||
menu_ = std::make_unique<gui::Menu>();
|
menu_ = std::make_unique<gui::Menu>();
|
||||||
|
|
||||||
AddSlider(*menu_, "jak moc to řve", volume_, 0, 100);
|
AddSlider(*menu_, "jak moc to řve", volume_, 0, 100, [this]{
|
||||||
|
ApplyVolume();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddSlider(*menu_, "agresivita krysy", sens_, 0, 100, [this]{
|
||||||
|
ApplySensitivity();
|
||||||
|
});
|
||||||
|
|
||||||
auto& ok = menu_->Add<gui::ButtonMenuItem>("0k");
|
auto& ok = menu_->Add<gui::ButtonMenuItem>("0k");
|
||||||
ok.SetClickCallback([this] { menu_.reset(); });
|
ok.SetClickCallback([this] { menu_.reset(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::ApplySettings()
|
||||||
|
{
|
||||||
|
ApplyVolume();
|
||||||
|
ApplySensitivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::ApplyVolume()
|
||||||
|
{
|
||||||
|
float vol_f = static_cast<float>(volume_) / 50.0f;
|
||||||
|
|
||||||
|
#ifndef EMSCRIPTEN
|
||||||
|
audiomaster_.SetMasterVolume(vol_f);
|
||||||
|
#else
|
||||||
|
audiomaster_.SetMasterVolume(2.0f * vol_f);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::ApplySensitivity()
|
||||||
|
{
|
||||||
|
float f = static_cast<float>(sens_) / 100.0f;
|
||||||
|
sensitivity_ = glm::mix(0.0005f, 0.0035f, f);
|
||||||
|
}
|
||||||
|
|
||||||
#define COL_LABEL "^ccc"
|
#define COL_LABEL "^ccc"
|
||||||
#define COL_VALUE "^5ff"
|
#define COL_VALUE "^5ff"
|
||||||
|
|
||||||
|
|||||||
@ -57,6 +57,9 @@ private:
|
|||||||
void DrawChat();
|
void DrawChat();
|
||||||
|
|
||||||
void OpenSettings();
|
void OpenSettings();
|
||||||
|
void ApplySettings();
|
||||||
|
void ApplyVolume();
|
||||||
|
void ApplySensitivity();
|
||||||
|
|
||||||
void UpdateStats();
|
void UpdateStats();
|
||||||
void DrawStats();
|
void DrawStats();
|
||||||
@ -83,6 +86,8 @@ private:
|
|||||||
|
|
||||||
// settings
|
// settings
|
||||||
int volume_ = 50;
|
int volume_ = 50;
|
||||||
|
int sens_ = 50;
|
||||||
|
float sensitivity_ = 0.0f;
|
||||||
|
|
||||||
// stats
|
// stats
|
||||||
float stats_time_ = 0.0f;
|
float stats_time_ = 0.0f;
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#include "game.hpp"
|
#include "game.hpp"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "openworld.hpp"
|
#include "openworld.hpp"
|
||||||
|
|
||||||
@ -22,13 +24,26 @@ void game::Game::FinishFrame()
|
|||||||
void game::Game::PlayerJoined(Player& player)
|
void game::Game::PlayerJoined(Player& player)
|
||||||
{
|
{
|
||||||
player.SetWorld(default_world_);
|
player.SetWorld(default_world_);
|
||||||
|
|
||||||
|
players_.insert(&player);
|
||||||
|
BroadcastChat(std::format("{}^r se připoojil jupí jupí jupííí", player.GetName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void game::Game::PlayerLeft(Player& player)
|
void game::Game::PlayerLeft(Player& player)
|
||||||
{
|
{
|
||||||
|
players_.erase(&player);
|
||||||
|
BroadcastChat(std::format("{}^r se vodpojil zmrd", player.GetName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool game::Game::PlayerInput(Player& player, PlayerInputType type, bool enabled)
|
bool game::Game::PlayerInput(Player& player, PlayerInputType type, bool enabled)
|
||||||
{
|
{
|
||||||
return false; // not handled here
|
return false; // not handled here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game::Game::BroadcastChat(const std::string& text)
|
||||||
|
{
|
||||||
|
for (auto player : players_)
|
||||||
|
{
|
||||||
|
player->SendChat(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
|
||||||
@ -21,9 +22,12 @@ public:
|
|||||||
void PlayerLeft(Player& player);
|
void PlayerLeft(Player& player);
|
||||||
bool PlayerInput(Player& player, PlayerInputType type, bool enabled);
|
bool PlayerInput(Player& player, PlayerInputType type, bool enabled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void BroadcastChat(const std::string& text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<World> default_world_;
|
std::shared_ptr<World> default_world_;
|
||||||
|
std::set<Player*> players_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -119,7 +119,7 @@ void game::OpenWorld::DestructibleDestroyed(net::ObjNum num, std::unique_ptr<Map
|
|||||||
{
|
{
|
||||||
auto& destroyed_obj = Spawn<DestroyedObject>(std::move(col));
|
auto& destroyed_obj = Spawn<DestroyedObject>(std::move(col));
|
||||||
|
|
||||||
Schedule(10000, [this, num] {
|
Schedule(120000, [this, num] {
|
||||||
RespawnObj(num);
|
RespawnObj(num);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,7 @@ bool sv::Client::ProcessLoginMsg(net::InMessage& msg)
|
|||||||
// check ver
|
// check ver
|
||||||
if (ver != FEKAL_VERSION)
|
if (ver != FEKAL_VERSION)
|
||||||
{
|
{
|
||||||
SendChat(std::format("^f55špatná verze {}, server je na verzi {}", ver, FEKAL_VERSION));
|
SendChat(std::format("^f55máš nahovno verzi {}, server je na {}", ver, FEKAL_VERSION));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user