diff --git a/src/game/character.cpp b/src/game/character.cpp index cab38ef..e0d1426 100644 --- a/src/game/character.cpp +++ b/src/game/character.cpp @@ -4,10 +4,10 @@ #include "utils/math.hpp" #include "world.hpp" -game::Character::Character(World& world, const CharacterInfo& info) - : Super(world, net::ET_CHARACTER), shape_(info.shape), bt_shape_(shape_.radius, shape_.height) +game::Character::Character(World& world, const CharacterTuning& tuning) + : Super(world, net::ET_CHARACTER), tuning_(tuning), bt_shape_(tuning_.shape.radius, tuning_.shape.height) { - z_offset_ = shape_.height * 0.5f + shape_.radius - 0.05f; + z_offset_ = tuning_.shape.height * 0.5f + tuning_.shape.radius - 0.05f; sk_ = SkeletonInstance(assets::CacheManager::GetSkeleton("data/human.sk"), &root_); animstate_.idle_anim_idx = GetAnim("idle"); @@ -53,8 +53,8 @@ void game::Character::SendInitData(Player& player, net::OutMessage& msg) const Super::SendInitData(player, msg); // write clothes - msg.Write(clothes_.size()); - for (const auto& clothes : clothes_) + msg.Write(tuning_.clothes.size()); + for (const auto& clothes : tuning_.clothes) { msg.Write(net::ClothesName(clothes.name)); net::WriteRGB(msg, clothes.color); @@ -120,11 +120,6 @@ void game::Character::SetPosition(const glm::vec3& position) SyncControllerTransform(); } -void game::Character::AddClothes(std::string name, const glm::vec3& color) -{ - clothes_.emplace_back(std::move(name), color); -} - void game::Character::SetMainAnim(const std::string& anim_name) { animstate_.idle_anim_idx = GetAnim(anim_name); diff --git a/src/game/character.hpp b/src/game/character.hpp index 660d535..4e7fc83 100644 --- a/src/game/character.hpp +++ b/src/game/character.hpp @@ -6,6 +6,7 @@ #include "character_anim_state.hpp" #include "character_sync.hpp" #include "entity.hpp" +#include "character_tuning.hpp" namespace game { @@ -22,25 +23,6 @@ enum CharacterInputType CIN_SPRINT, }; -struct CapsuleShape -{ - float radius; - float height; - - CapsuleShape(float radius, float height) : radius(radius), height(height) {} -}; - -struct CharacterInfo -{ - CapsuleShape shape = CapsuleShape(0.3f, 0.75f); -}; - -struct CharacterClothes -{ - std::string name; - glm::vec3 color; -}; - class CharacterPhysicsController { public: @@ -65,11 +47,13 @@ class Character : public Entity public: using Super = Entity; - Character(World& world, const CharacterInfo& info); + Character(World& world, const CharacterTuning& tuning); virtual void Update() override; virtual void SendInitData(Player& player, net::OutMessage& msg) const override; + const CharacterTuning& GetTuning() const { return tuning_; } + void EnablePhysics(bool enable); void SetInput(CharacterInputType type, bool enable); @@ -80,8 +64,6 @@ public: void SetPosition(const glm::vec3& position); - void AddClothes(std::string name, const glm::vec3& color); - void SetMainAnim(const std::string& anim_name); ~Character() override = default; @@ -100,7 +82,7 @@ private: assets::AnimIdx GetAnim(const std::string& name) const; private: - CapsuleShape shape_; + CharacterTuning tuning_; // glm::vec3 position_ = glm::vec3(0.0f); // glm::vec3 velocity_ = glm::vec3(0.0f); @@ -121,8 +103,6 @@ private: CharacterSyncState sync_[2]; size_t sync_current_ = 0; - - std::vector clothes_; }; } // namespace game \ No newline at end of file diff --git a/src/game/character_tuning.hpp b/src/game/character_tuning.hpp new file mode 100644 index 0000000..6d7f569 --- /dev/null +++ b/src/game/character_tuning.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +namespace game +{ + +struct CharacterShape +{ + float radius; + float height; + + CharacterShape(float radius, float height) : radius(radius), height(height) {} +}; + +struct CharacterConfigClothes +{ + std::string name; + uint32_t color = 0xFFFFFF; +}; + +struct CharacterTuning +{ + CharacterShape shape = CharacterShape(0.3f, 0.75f); + std::vector clothes; +}; + + +} \ No newline at end of file diff --git a/src/game/controllable_character.cpp b/src/game/controllable_character.cpp index 7217284..70a63e8 100644 --- a/src/game/controllable_character.cpp +++ b/src/game/controllable_character.cpp @@ -1,7 +1,7 @@ #include "controllable_character.hpp" #include "drivable_vehicle.hpp" -game::ControllableCharacter::ControllableCharacter(World& world) : Character(world, CharacterInfo{}) {} +game::ControllableCharacter::ControllableCharacter(World& world, const CharacterTuning& tuning) : Character(world, tuning) {} void game::ControllableCharacter::SetVehicle(DrivableVehicle* vehicle, uint32_t seat) { diff --git a/src/game/controllable_character.hpp b/src/game/controllable_character.hpp index 17de9e4..e7304e0 100644 --- a/src/game/controllable_character.hpp +++ b/src/game/controllable_character.hpp @@ -12,7 +12,7 @@ class ControllableCharacter : public Character public: using Super = Character; - ControllableCharacter(World& world); + ControllableCharacter(World& world, const CharacterTuning& tuning); void SetVehicle(DrivableVehicle* vehicle, uint32_t seat); diff --git a/src/game/enterable_world.cpp b/src/game/enterable_world.cpp index 4de45d8..5a52124 100644 --- a/src/game/enterable_world.cpp +++ b/src/game/enterable_world.cpp @@ -1,18 +1,13 @@ #include "enterable_world.hpp" #include "player_character.hpp" -static glm::vec3 GetRandomColor() +static uint32_t GetRandomColor24() { - glm::vec3 color; - // shittiest way to do it - for (int i = 0; i < 3; ++i) - { - net::ColorQ qcol; - qcol.value = rand() % 256; - color[i] = qcol.Decode(); - } - - return color; + uint8_t r,g,b; + r = rand() % 256; + g = rand() % 256; + b = rand() % 256; + return (b << 16) | (g << 8) | r; } game::EnterableWorld::EnterableWorld(std::string mapname) : World(std::move(mapname)) {} @@ -74,11 +69,11 @@ game::PlayerCharacter& game::EnterableWorld::CreatePlayerCharacter(Player& playe { RemovePlayerCharacter(player); - auto& character = Spawn(player); - character.AddClothes("tshirt", GetRandomColor()); - character.AddClothes("shorts", GetRandomColor()); + CharacterTuning tuning{}; + tuning.clothes.push_back({ "tshirt", GetRandomColor24() }); + tuning.clothes.push_back({ "shorts", GetRandomColor24() }); - // character.SetNametag("player (" + std::to_string(character.GetEntNum()) + ")"); + auto& character = Spawn(player, tuning); character.SetPosition(position); character.SetYaw(yaw); diff --git a/src/game/npc_character.cpp b/src/game/npc_character.cpp index 90301d4..795935b 100644 --- a/src/game/npc_character.cpp +++ b/src/game/npc_character.cpp @@ -5,7 +5,7 @@ #include #include -game::NpcCharacter::NpcCharacter(World& world) : Super(world) { +game::NpcCharacter::NpcCharacter(World& world, const CharacterTuning& tuning) : Super(world, tuning) { VehicleChanged(); } diff --git a/src/game/npc_character.hpp b/src/game/npc_character.hpp index d0b8b35..8bf05a5 100644 --- a/src/game/npc_character.hpp +++ b/src/game/npc_character.hpp @@ -13,7 +13,7 @@ class NpcCharacter : public ControllableCharacter public: using Super = ControllableCharacter; - NpcCharacter(World& world); + NpcCharacter(World& world, const CharacterTuning& tuning); virtual void VehicleChanged() override; diff --git a/src/game/openworld.cpp b/src/game/openworld.cpp index b8dcd65..61ba342 100644 --- a/src/game/openworld.cpp +++ b/src/game/openworld.cpp @@ -79,18 +79,6 @@ game::OpenWorld::OpenWorld() : EnterableWorld("openworld") } -template -static T& SpawnRandomCharacter(game::OpenWorld& world, TArgs&&... args) -{ - auto& character = world.Spawn(std::forward(args)...); - - // add clothes - character.AddClothes("tshirt", GetRandomColor()); - character.AddClothes("shorts", GetRandomColor()); - - return character; -} - game::DrivableVehicle& game::OpenWorld::SpawnRandomVehicle() { game::VehicleTuning tuning; @@ -117,6 +105,10 @@ void game::OpenWorld::SpawnBot() auto& vehicle = SpawnRandomVehicle(); vehicle.SetPosition(roads->nodes[start_node].position + glm::vec3{0.0f, 0.0f, 5.0f}); - auto& driver = SpawnRandomCharacter(*this); + CharacterTuning npc_tuning; + npc_tuning.clothes.push_back({ "tshirt", GetRandomColor24() }); + npc_tuning.clothes.push_back({ "shorts", GetRandomColor24() }); + + auto& driver = Spawn(npc_tuning); driver.SetVehicle(&vehicle, 0); } diff --git a/src/game/player_character.cpp b/src/game/player_character.cpp index 6eb25b3..eb9b3a4 100644 --- a/src/game/player_character.cpp +++ b/src/game/player_character.cpp @@ -1,7 +1,7 @@ #include "player_character.hpp" #include "world.hpp" -game::PlayerCharacter::PlayerCharacter(World& world, Player& player) : Super(world), player_(player) +game::PlayerCharacter::PlayerCharacter(World& world, Player& player, const CharacterTuning& tuning) : Super(world, tuning), player_(player) { EnablePhysics(true); VehicleChanged(); diff --git a/src/game/player_character.hpp b/src/game/player_character.hpp index 85aa003..0257f6b 100644 --- a/src/game/player_character.hpp +++ b/src/game/player_character.hpp @@ -12,7 +12,7 @@ class PlayerCharacter : public ControllableCharacter public: using Super = ControllableCharacter; - PlayerCharacter(World& world, Player& player); + PlayerCharacter(World& world, Player& player, const CharacterTuning& tuning); virtual void Update() override;