Compare commits

..

No commits in common. "627beffc65a76c8d5222809c4d07b67216fb4d93" and "6341db8ff0a7c602a170839f8cc9b6213c2d1652" have entirely different histories.

23 changed files with 46 additions and 251 deletions

View File

@ -18,8 +18,6 @@ set(COMMON_SOURCES
"src/assets/model.cpp"
"src/assets/skeleton.hpp"
"src/assets/skeleton.cpp"
"src/assets/vehicle_tuning_list.hpp"
"src/assets/vehicle_tuning_list.cpp"
"src/assets/vehiclemdl.hpp"
"src/assets/vehiclemdl.cpp"
"src/collision/dynamicsworld.hpp"

View File

@ -23,30 +23,3 @@ void assets::LoadCMDFile(const std::string& filename,
}
}
std::string assets::ParseString(std::istringstream& iss)
{
std::string str;
iss >> str;
if (!str.starts_with('"'))
return str;
str = str.substr(1);
while (iss)
{
std::string tmp;
iss >> tmp;
str += ' ';
str += tmp;
if (str.ends_with('"'))
{
str.pop_back();
break;
}
}
return str;
}

View File

@ -21,6 +21,4 @@ inline void ParseTransform(std::istringstream& iss, Transform& trans)
iss >> trans.scale;
}
std::string ParseString(std::istringstream& iss);
} // namespace assets

View File

@ -1,24 +0,0 @@
#include "vehicle_tuning_list.hpp"
#include "cmdfile.hpp"
std::unique_ptr<const assets::VehicleTuningList> assets::VehicleTuningList::LoadFromFile(const std::string& filename)
{
auto tuninglist = std::make_unique<VehicleTuningList>();
if (!fs::FileExists(filename))
return tuninglist; // empty
LoadCMDFile(filename, [&](const std::string& command, std::istringstream& iss) {
if (command == "wheel")
{
VehicleWheelPreset wheel{};
wheel.displayname = ParseString(iss);
iss >> wheel.price >> wheel.model;
tuninglist->wheels.emplace_back(wheel);
}
});
return tuninglist;
}

View File

@ -1,27 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <cstdint>
#include <memory>
namespace assets
{
struct VehicleWheelPreset
{
uint32_t price;
std::string displayname;
std::string model;
};
struct VehicleTuningList
{
std::vector<VehicleWheelPreset> wheels;
static std::unique_ptr<const VehicleTuningList> LoadFromFile(const std::string& filename);
};
}

View File

@ -48,9 +48,6 @@ std::shared_ptr<const assets::VehicleModel> assets::VehicleModel::LoadFromFile(c
}
});
// tuning list
veh->tuninglist_ = VehicleTuningList::LoadFromFile(filename + ".tun");
return veh;
}

View File

@ -2,7 +2,6 @@
#include "model.hpp"
#include "utils/transform.hpp"
#include "vehicle_tuning_list.hpp"
namespace assets
{
@ -36,13 +35,11 @@ public:
const std::shared_ptr<const Model>& GetModel() const { return basemodel_; }
const std::vector<VehicleWheel>& GetWheels() const { return wheels_; }
const Transform* GetLocation(const std::string& name) const;
const VehicleTuningList& GetTuningList() const { return *tuninglist_; }
private:
std::shared_ptr<const Model> basemodel_;
std::vector<VehicleWheel> wheels_;
std::map<std::string, Transform> locations_;
std::unique_ptr<const VehicleTuningList> tuninglist_;
};

View File

@ -2,7 +2,8 @@
#include "player_character.hpp"
#include "utils/random.hpp"
game::DrivableVehicle::DrivableVehicle(World& world, const VehicleTuning& tuning) : Vehicle(world, tuning)
game::DrivableVehicle::DrivableVehicle(World& world, std::string model_name, const glm::vec3& color)
: Vehicle(world, std::move(model_name), color)
{
InitSeats();
}

View File

@ -16,7 +16,7 @@ struct VehicleSeat
class DrivableVehicle : public Vehicle, public Usable
{
public:
DrivableVehicle(World& world, const VehicleTuning& tuning);
DrivableVehicle(World& world, std::string model_name, const glm::vec3& color);
virtual void Use(PlayerCharacter& character, uint32_t target_id) override;

View File

@ -36,14 +36,6 @@ static glm::vec3 GetRandomColor()
return color;
}
static uint32_t GetRandomColor24()
{
uint8_t r,g,b;
r = rand() % 256;
g = rand() % 256;
b = rand() % 256;
return (b << 16) | (g << 8) | r;
}
game::OpenWorld::OpenWorld() : World("openworld")
{
@ -55,14 +47,7 @@ game::OpenWorld::OpenWorld() : World("openworld")
SpawnBot();
}
// initial twingo
VehicleTuning twingo_tuning;
twingo_tuning.model = "twingo";
twingo_tuning.primary_color = 0x0077FF;
twingo_tuning.wheels_idx = 1; // enkei
twingo_tuning.wheel_color = 0x00FF00;
auto& veh = Spawn<game::DrivableVehicle>(twingo_tuning);
auto& veh = Spawn<game::DrivableVehicle>("twingo", glm::vec3{1.0f, 0.8f, 0.1f});
veh.SetPosition({110.0f, 100.0f, 5.0f});
constexpr size_t in_row = 20;
@ -74,7 +59,7 @@ game::OpenWorld::OpenWorld() : World("openworld")
size_t row = i / in_row;
glm::vec3 pos(62.0f + static_cast<float>(col) * 4.0f, 165.0f + static_cast<float>(row) * 7.0f, 7.0f);
auto& veh = SpawnRandomVehicle();
auto& veh = Spawn<game::DrivableVehicle>(GetRandomCarModel(), GetRandomColor());
veh.SetPosition(pos);
});
}
@ -172,32 +157,29 @@ void game::OpenWorld::RemovePlayerCharacter(Player& player)
}
}
game::DrivableVehicle& game::OpenWorld::SpawnRandomVehicle()
static game::DrivableVehicle& SpawnRandomVehicle(game::World& world)
{
game::VehicleTuning tuning;
tuning.model = GetRandomCarModel();
tuning.primary_color = GetRandomColor24();
auto roads = world.GetMap().GetGraph("roads");
auto& vehicle = Spawn<game::DrivableVehicle>(tuning);
if (!roads)
{
throw std::runtime_error("SpawnRandomVehicle: no roads graph in map");
}
size_t start_node = rand() % roads->nodes.size();
// auto color = glm::vec3{0.3f, 0.3f, 0.3f};
auto color = GetRandomColor();
auto& vehicle = world.Spawn<game::DrivableVehicle>(GetRandomCarModel(), color);
// vehicle.SetNametag("bot (" + std::to_string(vehicle.GetEntNum()) + ")");
vehicle.SetPosition(roads->nodes[start_node].position + glm::vec3{0.0f, 0.0f, 5.0f});
return vehicle;
}
void game::OpenWorld::SpawnBot()
{
auto roads = GetMap().GetGraph("roads");
if (!roads)
{
throw std::runtime_error("SpawnBot: no roads graph in map");
}
size_t start_node = rand() % roads->nodes.size();
auto& vehicle = SpawnRandomVehicle();
vehicle.SetPosition(roads->nodes[start_node].position + glm::vec3{0.0f, 0.0f, 5.0f});
auto& vehicle = SpawnRandomVehicle(*this);
auto& driver = SpawnRandomCharacter<NpcCharacter>(*this);
driver.SetVehicle(&vehicle, 0);
}

View File

@ -4,7 +4,6 @@
#include "vehicle.hpp"
#include "character.hpp"
#include "usable.hpp"
#include "drivable_vehicle.hpp"
#include <optional>
@ -32,7 +31,6 @@ private:
void CreatePlayerCharacter(Player& player);
void RemovePlayerCharacter(Player& player);
game::DrivableVehicle& SpawnRandomVehicle();
void SpawnBot();
private:

View File

@ -13,9 +13,10 @@ static std::shared_ptr<const assets::VehicleModel> LoadVehicleModelByName(const
return assets::CacheManager::GetVehicleModel("data/" + model_name + ".veh");
}
game::Vehicle::Vehicle(World& world, const VehicleTuning& tuning)
: Entity(world, net::ET_VEHICLE), tuning_(tuning), model_(LoadVehicleModelByName(tuning.model)),
motion_(root_.local)
game::Vehicle::Vehicle(World& world, std::string model_name, const glm::vec3& color)
: Entity(world, net::ET_VEHICLE), model_name_(model_name), model_(LoadVehicleModelByName(model_name)),
motion_(root_.local),
color_(color)
{
root_.local.position.z = 10.0f;
@ -36,8 +37,8 @@ game::Vehicle::Vehicle(World& world, const VehicleTuning& tuning)
collision::SetObjectInfo(body_.get(), collision::OT_ENTITY, collision::OF_NOTIFY_CONTACT, this);
// setup vehicle
btRaycastVehicle::btVehicleTuning bt_tuning;
vehicle_ = std::make_unique<collision::RaycastVehicle>(bt_tuning, body_.get(), &world_.GetVehicleRaycaster());
btRaycastVehicle::btVehicleTuning tuning;
vehicle_ = std::make_unique<collision::RaycastVehicle>(tuning, body_.get(), &world_.GetVehicleRaycaster());
vehicle_->setCoordinateSystem(0, 2, 1);
// setup wheels
@ -75,7 +76,7 @@ game::Vehicle::Vehicle(World& world, const VehicleTuning& tuning)
btVector3 wheel_pos(wheeldef.position.x, wheeldef.position.y, wheeldef.position.z + wheel_z_offset_);
auto& wi = vehicle_->addWheel(wheel_pos, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius,
bt_tuning, is_front);
tuning, is_front);
wi.m_suspensionStiffness = suspensionStiffness;
@ -125,8 +126,9 @@ void game::Vehicle::SendInitData(Player& player, net::OutMessage& msg) const
{
Super::SendInitData(player, msg);
msg.Write(net::ModelName(tuning_.model));
WriteTuning(msg);
net::ModelName name(model_name_);
msg.Write(name);
net::WriteRGB(msg, color_); // primary color
// write state against default
static const VehicleSyncState default_state;
@ -551,12 +553,3 @@ void game::Vehicle::SendDeformMsg(const net::PositionQ& pos, const net::Position
net::WritePositionQ(msg, pos);
net::WritePositionQ(msg, deform);
}
void game::Vehicle::WriteTuning(net::OutMessage& msg) const
{
net::WriteRGB(msg, tuning_.primary_color);
// wheels
msg.Write<net::TuningPartIdx>(tuning_.wheels_idx);
net::WriteRGB(msg, tuning_.wheel_color);
}

View File

@ -10,7 +10,6 @@
#include "world.hpp"
#include "vehicle_sync.hpp"
#include "deform_grid.hpp"
#include "vehicle_tuning.hpp"
namespace game
{
@ -38,7 +37,7 @@ class Vehicle : public Entity
public:
using Super = Entity;
Vehicle(World& world, const VehicleTuning& tuning);
Vehicle(World& world, std::string model_name, const glm::vec3& color);
virtual void Update() override;
virtual void SendInitData(Player& player, net::OutMessage& msg) const override;
@ -56,8 +55,9 @@ public:
void SetSteering(bool analog, float value = 0.0f);
const std::string& GetModelName() const { return tuning_.model; }
const std::string& GetModelName() const { return model_name_; }
const std::shared_ptr<const assets::VehicleModel>& GetModel() const { return model_; }
const glm::vec3& GetColor() const { return color_; }
virtual ~Vehicle();
@ -74,11 +74,10 @@ private:
void Deform(const glm::vec3& pos, const glm::vec3& deform, float radius);
void SendDeformMsg(const net::PositionQ& pos, const net::PositionQ& deform);
void WriteTuning(net::OutMessage& msg) const;
private:
VehicleTuning tuning_;
std::string model_name_;
std::shared_ptr<const assets::VehicleModel> model_;
glm::vec3 color_;
collision::MotionState motion_;
std::unique_ptr<btRigidBody> body_;

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
namespace game
{
struct VehicleTuning
{
std::string model;
uint32_t primary_color = 0xFFFFFFFF;
size_t wheels_idx = 0;
uint32_t wheel_color = 0xFFFFFFFF;
};
}

View File

@ -12,7 +12,8 @@ game::view::VehicleView::VehicleView(WorldView& world, net::InMessage& msg)
: EntityView(world, msg)
{
net::ModelName modelname;
if (!msg.Read(modelname))
glm::vec3 color;
if (!msg.Read(modelname) || !net::ReadRGB(msg, color))
throw EntityInitError();
model_ = assets::CacheManager::GetVehicleModel("data/" + std::string(modelname) + ".veh");
@ -27,7 +28,12 @@ game::view::VehicleView::VehicleView(WorldView& world, net::InMessage& msg)
wheels_[i].node.parent = &root_;
}
if (!ReadTuning(msg) || !ReadState(&msg) || !ReadDeformSync(msg))
color_ = glm::vec4(color, 1.0f);
if (!ReadState(&msg))
throw EntityInitError();
if (!ReadDeformSync(msg))
throw EntityInitError();
// init the other transform to identical
@ -133,14 +139,13 @@ void game::view::VehicleView::Draw(const DrawArgs& args)
const auto& wheels = model_->GetWheels();
for (size_t i = 0; i < wheels.size(); ++i)
{
const auto& mesh = *wheels_[i].model->GetMesh();
const auto& mesh = *wheels[i].model->GetMesh();
for (const auto& surface : mesh.surfaces)
{
gfx::DrawSurfaceCmd cmd;
cmd.surface = &surface;
cmd.matrices = &wheels_[i].node.matrix;
cmd.color = &wheels_[i].color;
args.dlist.AddSurface(cmd);
}
}
@ -184,35 +189,6 @@ void game::view::VehicleView::InitMesh()
deform_->tex->SetData(deform_->grid.GetData());
}
bool game::view::VehicleView::ReadTuning(net::InMessage& msg)
{
uint32_t color, wheel_color;
net::TuningPartIdx wheel_idx;
const auto& tuninglist = model_->GetTuningList();
if (!net::ReadRGB(msg, color))
return false;
color_ = glm::unpackUnorm4x8(color);
// wheels
if (!msg.Read(wheel_idx) || !net::ReadRGB(msg, wheel_color))
return false;
auto wheelmodel = wheel_idx < tuninglist.wheels.size() ? assets::CacheManager::GetModel("data/" + tuninglist.wheels[wheel_idx].model + ".mdl") : nullptr;
glm::vec3 wheelcolor = glm::unpackUnorm4x8(wheel_color);
for (size_t i = 0; i < wheels_.size(); ++i)
{
auto& wheel = wheels_[i];
wheel.model = wheelmodel ? wheelmodel : model_->GetWheels()[i].model;
wheel.color = glm::vec4(wheelcolor, 1.0f);
}
return true;
}
bool game::view::VehicleView::ReadState(net::InMessage* msg)
{
root_trans_[0] = root_.local;

View File

@ -13,9 +13,6 @@ namespace game::view
struct VehicleWheelViewInfo
{
std::shared_ptr<const assets::Model> model;
glm::vec4 color;
TransformNode node;
float steering = 0.0f;
float z_offset = 0.0f;
@ -46,7 +43,6 @@ public:
private:
void InitMesh();
bool ReadTuning(net::InMessage& msg);
bool ReadState(net::InMessage* msg);
bool ReadDeformSync(net::InMessage& msg);

View File

@ -183,9 +183,6 @@ bool game::view::WorldView::ProcessUpdateEntsMsg(net::InMessage& msg)
if (!msg.Read(count))
return false;
if (count > ents_.size())
return false; // wanna update more than we have
net::EntNum current = 0;
auto it = ents_.begin();

View File

@ -135,8 +135,4 @@ using NumTexels = uint16_t;
using Version = uint32_t;
// tuning
using TuningPartIdx = uint8_t;
} // namespace net

View File

@ -126,25 +126,6 @@ inline bool ReadRGB(InMessage& msg, glm::vec3& color)
return msg.Read<ColorQ>(color.r) && msg.Read<ColorQ>(color.g) && msg.Read<ColorQ>(color.b);
}
// COLOR 24bit
inline void WriteRGB(OutMessage& msg, uint32_t color)
{
msg.Write<uint8_t>(color & 0xFF);
msg.Write<uint8_t>((color >> 8) & 0xFF);
msg.Write<uint8_t>((color >> 16) & 0xFF);
}
inline bool ReadRGB(InMessage& msg, uint32_t& color)
{
uint8_t r, g, b;
if (!msg.Read(r) || !msg.Read(g) || !msg.Read(b))
return false;
color = (b << 16) | (g << 8) | r;
return true;
}
// DELTA
template <std::unsigned_integral T> requires (sizeof(T) == 1)
inline void WriteDelta(OutMessage& msg, T previous, T current)

View File

@ -31,13 +31,3 @@ std::istringstream fs::ReadFileAsStream(const std::string& path)
std::string content = ReadFileAsString(path);
return std::istringstream(content);
}
bool fs::FileExists(const std::string& path)
{
SDL_RWops *rw = SDL_RWFromFile(path.c_str(), "rb");
if (!rw)
return false;
SDL_RWclose(rw);
return true;
}

View File

@ -4,7 +4,6 @@
namespace fs
{
bool FileExists(const std::string& path);
std::string ReadFileAsString(const std::string& path);
std::istringstream ReadFileAsStream(const std::string& path);
}

View File

@ -1,7 +1,6 @@
#include "files.hpp"
#include <fstream>
#include <filesystem>
std::string fs::ReadFileAsString(const std::string& path)
{
@ -23,8 +22,3 @@ std::istringstream fs::ReadFileAsStream(const std::string& path)
std::string content = ReadFileAsString(path);
return std::istringstream(content);
}
bool fs::FileExists(const std::string& path)
{
return std::filesystem::exists(path);
}

View File

@ -1,3 +1,3 @@
#pragma once
#define FEKAL_VERSION 2026032001
#define FEKAL_VERSION 2026031401