Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync to latest fw flecs #105

Merged
merged 9 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions code/client/src/core/modules/human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ namespace MafiaMP::Core::Modules {

void Human::Create(flecs::entity e, uint64_t spawnProfile) {
auto info = Core::gApplication->GetEntityFactory()->RequestHuman(spawnProfile);
auto trackingData = e.get_mut<Core::Modules::Human::Tracking>();
trackingData->info = info;
trackingData->human = nullptr;
auto &trackingData = e.ensure<Core::Modules::Human::Tracking>();
trackingData.info = info;
trackingData.human = nullptr;

auto interp = e.get_mut<Interpolated>();
interp->interpolator.GetPosition()->SetCompensationFactor(1.5f);
auto &interp = e.ensure<Interpolated>();
interp.interpolator.GetPosition()->SetCompensationFactor(1.5f);

e.add<HumanData>();
e.add<Shared::Modules::Mod::EntityKind>();
e.set<Shared::Modules::Mod::EntityKind>({Shared::Modules::Mod::MOD_PLAYER});
e.add<Shared::Modules::HumanSync::UpdateData>();

const auto OnHumanRequestFinish = [](Game::Streaming::EntityTrackingInfo *info, bool success) {
CreateNetCharacterController = false;
Expand Down Expand Up @@ -227,16 +229,18 @@ namespace MafiaMP::Core::Modules {
}

void Human::SetupLocalPlayer(Application *, flecs::entity e) {
auto trackingData = e.get_mut<Core::Modules::Human::Tracking>();
trackingData->human = Game::Helpers::Controls::GetLocalPlayer();
trackingData->info = nullptr;
auto &trackingData = e.ensure<Core::Modules::Human::Tracking>();
trackingData.human = Game::Helpers::Controls::GetLocalPlayer();
trackingData.info = nullptr;

e.add<Shared::Modules::HumanSync::UpdateData>();
e.add<Core::Modules::Human::LocalPlayer>();
e.add<HumanData>();
e.add<Shared::Modules::Mod::EntityKind>();
e.set<Shared::Modules::Mod::EntityKind>({Shared::Modules::Mod::MOD_PLAYER});
e.add<Framework::World::Modules::Base::Frame>();

const auto es = e.get_mut<Framework::World::Modules::Base::Streamable>();
auto es = e.get_mut<Framework::World::Modules::Base::Streamable>();
es->modEvents.updateProc = [](Framework::Networking::NetworkPeer *peer, uint64_t guid, flecs::entity e) {
const auto updateData = e.get<Shared::Modules::HumanSync::UpdateData>();

Expand Down
12 changes: 7 additions & 5 deletions code/client/src/core/modules/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ namespace MafiaMP::Core::Modules {

void Vehicle::Create(flecs::entity e, std::string modelName) {
auto info = Core::gApplication->GetEntityFactory()->RequestVehicle(std::move(modelName));
auto trackingData = e.get_mut<Core::Modules::Vehicle::Tracking>();
trackingData->info = info;
trackingData->car = nullptr;
auto &trackingData = e.ensure<Core::Modules::Vehicle::Tracking>();
trackingData.info = info;
trackingData.car = nullptr;

auto interp = e.get_mut<Interpolated>();
interp->interpolator.GetPosition()->SetCompensationFactor(1.5f);
auto &interp = e.ensure<Interpolated>();
interp.interpolator.GetPosition()->SetCompensationFactor(1.5f);

e.add<Shared::Modules::Mod::EntityKind>();
e.set<Shared::Modules::Mod::EntityKind>({Shared::Modules::Mod::MOD_VEHICLE});
e.add<Shared::Modules::VehicleSync::UpdateData>();

const auto OnVehicleRequestFinish = [](Game::Streaming::EntityTrackingInfo *info, bool success) {
if (success) {
Expand Down
4 changes: 2 additions & 2 deletions code/server/src/core/builtins/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace MafiaMP::Scripting {
static Vehicle CreateVehicle(std::string modelName) {
auto e = MafiaMP::Core::Modules::Vehicle::Create(Server::_serverRef);

auto frame = e.get_mut<Framework::World::Modules::Base::Frame>();
frame->modelName = modelName;
auto &frame = e.ensure<Framework::World::Modules::Base::Frame>();
frame.modelName = modelName;

return Vehicle(e);
}
Expand Down
4 changes: 2 additions & 2 deletions code/server/src/core/modules/human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace MafiaMP::Core::Modules {
}

void Human::Create(Framework::Networking::NetworkServer *net, flecs::entity e) {
auto frame = e.get_mut<Framework::World::Modules::Base::Frame>();
frame->modelHash = 335218123840277515; /* TODO */
auto &frame = e.ensure<Framework::World::Modules::Base::Frame>();
frame.modelHash = 335218123840277515; /* TODO */

e.add<Shared::Modules::HumanSync::UpdateData>();

Expand Down
10 changes: 5 additions & 5 deletions code/server/src/core/modules/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ namespace MafiaMP::Core::Modules {
const auto net = server->GetNetworkingEngine()->GetNetworkServer();
auto e = server->GetWorldEngine()->CreateEntity();
server->GetStreamingFactory()->SetupServer(e, SLNet::UNASSIGNED_RAKNET_GUID.g);
auto frame = e.get_mut<Framework::World::Modules::Base::Frame>();
frame->modelName = "berkley_810"; /* TODO */
auto& frame = e.ensure<Framework::World::Modules::Base::Frame>();
frame.modelName = "berkley_810"; /* TODO */

auto updateData = e.get_mut<Shared::Modules::VehicleSync::UpdateData>();
auto updateData = e.ensure<Shared::Modules::VehicleSync::UpdateData>();

// generate a random license plate
{
constexpr char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
constexpr char numbers[] = "0123456789";
for (int i = 0; i < 2; i++) {
updateData->licensePlate[i] = letters[::rand() % (sizeof(letters) - 1)];
updateData.licensePlate[i] = letters[::rand() % (sizeof(letters) - 1)];
}
for (int i = 3; i < 6; i++) {
updateData->licensePlate[i] = numbers[::rand() % (sizeof(numbers) - 1)];
updateData.licensePlate[i] = numbers[::rand() % (sizeof(numbers) - 1)];
}
}

Expand Down
6 changes: 3 additions & 3 deletions code/server/src/core/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace MafiaMP {
GetWorldEngine()->GetWorld()->import <Core::Modules::Vehicle>();

// Setup specific components - default values
auto weather = GetWorldEngine()->GetWorld()->get_mut<Core::Modules::Environment::Weather>();
weather->_weatherSetName = "_default_game";
weather->_dayTimeHours = 11.0f;
auto weather = GetWorldEngine()->GetWorld()->ensure<Core::Modules::Environment::Weather>();
weather._weatherSetName = "_default_game";
weather._dayTimeHours = 11.0f;
}

void Server::PostUpdate() {}
Expand Down