-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathUpdateUnitEntities.cpp
More file actions
654 lines (560 loc) · 32.5 KB
/
UpdateUnitEntities.cpp
File metadata and controls
654 lines (560 loc) · 32.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#include "UpdateUnitEntities.h"
#include "Game-Lib/ECS/Components/AnimationData.h"
#include "Game-Lib/ECS/Components/AttachmentData.h"
#include "Game-Lib/ECS/Components/DisplayInfo.h"
#include "Game-Lib/ECS/Components/Events.h"
#include "Game-Lib/ECS/Components/Model.h"
#include "Game-Lib/ECS/Components/MovementInfo.h"
#include "Game-Lib/ECS/Components/Name.h"
#include "Game-Lib/ECS/Components/Tags.h"
#include "Game-Lib/ECS/Components/Unit.h"
#include "Game-Lib/ECS/Components/UnitCustomization.h"
#include "Game-Lib/ECS/Components/UnitEquipment.h"
#include "Game-Lib/ECS/Components/UnitMovementOverTime.h"
#include "Game-Lib/ECS/Components/UnitPowersComponent.h"
#include "Game-Lib/ECS/Components/UnitResistancesComponent.h"
#include "Game-Lib/ECS/Components/UnitStatsComponent.h"
#include "Game-Lib/ECS/Singletons/CharacterSingleton.h"
#include "Game-Lib/ECS/Singletons/JoltState.h"
#include "Game-Lib/ECS/Singletons/NetworkState.h"
#include "Game-Lib/ECS/Singletons/Database/ClientDBSingleton.h"
#include "Game-Lib/ECS/Singletons/Database/UnitCustomizationSingleton.h"
#include "Game-Lib/ECS/Singletons/Database/TextureSingleton.h"
#include "Game-Lib/ECS/Util/Transforms.h"
#include "Game-Lib/ECS/Util/Database/TextureUtil.h"
#include "Game-Lib/ECS/Util/Database/UnitCustomizationUtil.h"
#include "Game-Lib/Gameplay/Animation/Defines.h"
#include "Game-Lib/Gameplay/Database/Unit.h"
#include "Game-Lib/Rendering/GameRenderer.h"
#include "Game-Lib/Rendering/Model/ModelLoader.h"
#include "Game-Lib/Rendering/Texture/TextureRenderer.h"
#include "Game-Lib/Util/AnimationUtil.h"
#include "Game-Lib/Util/AttachmentUtil.h"
#include "Game-Lib/Util/ServiceLocator.h"
#include "Game-Lib/Util/UnitUtil.h"
#include <MetaGen/Shared/ClientDB/ClientDB.h>
#include <entt/entt.hpp>
#include <Jolt/Jolt.h>
#include <Jolt/Physics/Collision/CastResult.h>
#include <Jolt/Physics/Collision/RayCast.h>
#include <tracy/Tracy.hpp>
namespace ECS::Systems
{
class NetworkedEntityFilter : public JPH::BodyFilter
{
public:
NetworkedEntityFilter(u32 bodyID) : _bodyID(bodyID) { }
bool ShouldCollide(const JPH::BodyID& inBodyID) const override
{
return _bodyID != inBodyID;
}
bool ShouldCollideLocked(const JPH::Body& inBody) const override
{
return _bodyID != inBody.GetID();
}
private:
JPH::BodyID _bodyID;
};
void UpdateUnitEntities::Init(entt::registry& registry)
{
}
void SetOrientation(vec4& settings, f32 orientation, f32 timeToChange = 0.15f)
{
f32 currentOrientation = settings.x;
if (orientation == currentOrientation)
return;
settings.y = orientation;
settings.z = timeToChange;
settings.w = 0.0f;
};
bool HandleUpdateOrientation(vec4& settings, f32 deltaTime)
{
if (settings.x == settings.y)
return false;
settings.w += deltaTime;
settings.w = glm::clamp(settings.w, 0.0f, settings.z);
f32 progress = settings.w / settings.z;
settings.x = glm::mix(settings.x, settings.y, progress);
return true;
};
void UpdateUnitEntities::Update(entt::registry& registry, f32 deltaTime)
{
ZoneScopedN("ECS::UpdateUnitEntities");
TransformSystem& transformSystem = TransformSystem::Get(registry);
auto& characterSingleton = registry.ctx().get<Singletons::CharacterSingleton>();
auto& joltState = registry.ctx().get<Singletons::JoltState>();
auto& networkState = registry.ctx().get<Singletons::NetworkState>();
entt::registry* dbRegistry = ServiceLocator::GetEnttRegistries()->dbRegistry;
auto& clientDBSingleton = dbRegistry->ctx().get<Singletons::ClientDBSingleton>();
auto& unitCustomizationSingleton = dbRegistry->ctx().get<Singletons::UnitCustomizationSingleton>();
auto& textureSingleton = dbRegistry->ctx().get<Singletons::TextureSingleton>();
GameRenderer* gameRenderer = ServiceLocator::GetGameRenderer();
ModelLoader* modelLoader = gameRenderer->GetModelLoader();
auto modelLoadedEventView = registry.view<Components::ModelLoadedEvent>();
if (modelLoadedEventView.size() > 0)
{
auto* unitRaceStorage = clientDBSingleton.Get(ClientDBHash::UnitRace);
auto* creatureDisplayInfoStorage = clientDBSingleton.Get(ClientDBHash::CreatureDisplayInfo);
auto* creatureDisplayInfoExtraStorage = clientDBSingleton.Get(ClientDBHash::CreatureDisplayInfoExtra);
auto* unitTextureSectionStorage = clientDBSingleton.Get(ClientDBHash::UnitTextureSection);
auto* unitCustomizationOptionStorage = clientDBSingleton.Get(ClientDBHash::UnitCustomizationOption);
auto* unitCustomizationGeosetStorage = clientDBSingleton.Get(ClientDBHash::UnitCustomizationGeoset);
auto* unitCustomizationMaterialStorage = clientDBSingleton.Get(ClientDBHash::UnitCustomizationMaterial);
auto* unitRaceCustomizationChoiceStorage = clientDBSingleton.Get(ClientDBHash::UnitRaceCustomizationChoice);
modelLoadedEventView.each([&](entt::entity entity, Components::ModelLoadedEvent& modelLoadedEvent)
{
if (modelLoadedEvent.flags.staticModel)
return;
auto& model = registry.get<Components::Model>(entity);
auto* name = registry.try_get<Components::Name>(entity);
if (modelLoadedEvent.flags.loaded)
{
if (model.modelHash == std::numeric_limits<u32>().max())
{
NC_LOG_INFO("Entity \"{0}\" Loaded Model with Invalid ModelHash", name ? name->name : "Unknown");
return;
}
auto& discoveredModel = modelLoader->GetDiscoveredModel(model.modelHash);
modelLoader->DisableAllGroupsForModel(model);
if (auto* unitCustomization = registry.try_get<Components::UnitCustomization>(entity))
{
unitCustomization->flags = { 0 };
unitCustomization->componentSectionsInUse = { 0 };
auto& displayInfo = registry.get<Components::DisplayInfo>(entity);
if (auto* displayInfoRow = creatureDisplayInfoStorage->TryGet<MetaGen::Shared::ClientDB::CreatureDisplayInfoRecord>(displayInfo.displayID))
{
if (auto* displayInfoExtraRow = creatureDisplayInfoExtraStorage->TryGet<MetaGen::Shared::ClientDB::CreatureDisplayInfoExtraRecord>(displayInfoRow->extendedDisplayInfoID))
{
u32 bakedTextureHash = creatureDisplayInfoExtraStorage->GetStringHash(displayInfoExtraRow->bakedTexture);
unitCustomization->flags.useCustomSkin = !textureSingleton.textureHashToPath.contains(bakedTextureHash);
displayInfo.race = static_cast<GameDefine::UnitRace>(displayInfoExtraRow->raceID);
displayInfo.gender = static_cast<GameDefine::UnitGender>(displayInfoExtraRow->gender);
unitCustomization->skinID = displayInfoExtraRow->skinID;
unitCustomization->faceID = displayInfoExtraRow->faceID;
unitCustomization->facialHairID = displayInfoExtraRow->facialHairID;
unitCustomization->hairStyleID = displayInfoExtraRow->hairStyleID;
unitCustomization->hairColorID = displayInfoExtraRow->hairColorID;
}
else
{
if (unitCustomizationSingleton.modelIDToUnitModelInfo.contains(displayInfoRow->modelID))
{
auto& unitModelInfo = unitCustomizationSingleton.modelIDToUnitModelInfo[displayInfoRow->modelID];
displayInfo.race = unitModelInfo.race;
displayInfo.gender = unitModelInfo.gender;
unitCustomization->flags.useCustomSkin = true;
}
}
}
if (unitCustomization->flags.useCustomSkin)
{
unitCustomization->flags.forceRefresh = true;
registry.emplace_or_replace<ECS::Components::UnitRebuildSkinTexture>(entity);
}
}
if (auto* modelQueuedGeometryGroups = registry.try_get<Components::ModelQueuedGeometryGroups>(entity))
{
for (u32 groupID : modelQueuedGeometryGroups->enabledGroupIDs)
{
modelLoader->EnableGroupForModel(model, groupID);
}
registry.erase<Components::ModelQueuedGeometryGroups>(entity);
}
else
{
registry.emplace_or_replace<ECS::Components::UnitRebuildGeosets>(entity);
}
if (auto* unitEquipment = registry.try_get<Components::UnitEquipment>(entity))
{
bool isEquipmentDirty = false;
bool isVisualEquipmentDirty = false;
for (u32 i = (u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::EquipmentStart; i <= (u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::EquipmentEnd; i++)
{
u32 equipSlotIndex = i;
u32 equippedItemID = unitEquipment->equipmentSlotToItemID[equipSlotIndex];
if (equippedItemID != 0)
{
unitEquipment->dirtyItemIDSlots.insert((MetaGen::Shared::Unit::ItemEquipSlotEnum)equipSlotIndex);
isEquipmentDirty = true;
}
u32 visualItemID = unitEquipment->equipmentSlotToVisualItemID[equipSlotIndex];
if (visualItemID != 0)
{
unitEquipment->dirtyVisualItemIDSlots.insert((MetaGen::Shared::Unit::ItemEquipSlotEnum)equipSlotIndex);
isVisualEquipmentDirty = true;
}
}
if (isEquipmentDirty)
registry.get_or_emplace<Components::UnitEquipmentDirty>(entity);
if (isVisualEquipmentDirty)
registry.get_or_emplace<Components::UnitVisualEquipmentDirty>(entity);
}
if (auto* unit = registry.try_get<Components::Unit>(entity))
{
auto& transform = registry.get<Components::Transform>(entity);
vec3 position = transform.GetWorldPosition();
vec3 scale = transform.GetLocalScale();
vec3 min = position - (scale * 0.5f);
vec3 max = position + (scale * 0.5f);
if (auto* aabb = registry.try_get<Components::AABB>(entity))
{
min = position + (aabb->centerPos - aabb->extents);
max = position + (aabb->centerPos + aabb->extents);
}
networkState.networkVisTree->Insert(&min.x, &max.x, unit->networkID);
}
}
else
{
if (registry.all_of<Components::ModelQueuedGeometryGroups>(entity))
registry.erase<Components::ModelQueuedGeometryGroups>(entity);
}
});
registry.clear<Components::ModelLoadedEvent>();
}
auto unitMovementOverTimeView = registry.view<Components::Transform, Components::Unit, Components::UnitMovementOverTime>();
unitMovementOverTimeView.each([&](entt::entity entity, Components::Transform& transform, Components::Unit& unit, Components::UnitMovementOverTime& unitMovementOverTime)
{
if (unitMovementOverTime.time == 1.0f)
return;
unitMovementOverTime.time += 10.0f * deltaTime;
unitMovementOverTime.time = glm::min(unitMovementOverTime.time, 1.0f);
f32 progress = unitMovementOverTime.time;
vec3 startPos = unitMovementOverTime.startPos;
vec3 endPos = unitMovementOverTime.endPos;
vec3 newPosition = glm::mix(startPos, endPos, progress);
transformSystem.SetWorldPosition(entity, newPosition);
f32 scale = transform.GetLocalScale().x;
vec3 min = newPosition - (scale * 0.5f);
vec3 max = newPosition + (scale * 0.5f);
if (auto* aabb = registry.try_get<Components::AABB>(entity))
{
min = newPosition + (aabb->centerPos - aabb->extents);
max = newPosition + (aabb->centerPos + aabb->extents);
}
networkState.networkVisTree->Remove(unit.networkID);
networkState.networkVisTree->Insert(&min.x, &max.x, unit.networkID);
if (unit.bodyID == std::numeric_limits<u32>().max())
return;
JPH::BodyID bodyID = JPH::BodyID(unit.bodyID);
quat rotation = transform.GetWorldRotation();
joltState.physicsSystem.GetBodyInterface().SetPositionAndRotation(bodyID, JPH::Vec3(newPosition.x, newPosition.y, newPosition.z), JPH::Quat(rotation.x, rotation.y, rotation.z, rotation.w), JPH::EActivation::DontActivate);
});
auto unitView = registry.view<Components::Unit, Components::Model, Components::AnimationData, Components::MovementInfo>();
unitView.each([&](entt::entity entity, Components::Unit& unit, Components::Model& model, Components::AnimationData& animationData, Components::MovementInfo& movementInfo)
{
if (!registry.all_of<>(entity))
return;
if (unit.overrideAnimation == ::Animation::Defines::Type::Invalid)
::Util::Unit::UpdateAnimationState(registry, entity, model, deltaTime);
const auto* modelInfo = modelLoader->GetModelInfo(model.modelHash);
if (auto* attachmentData = registry.try_get<Components::AttachmentData>(entity))
{
if (modelInfo)
{
for (auto& pair : attachmentData->attachmentToInstance)
{
Util::Attachment::CalculateAttachmentMatrix(modelInfo, animationData, pair.first, pair.second, model.scale);
}
}
}
auto& unitPowersComponent = registry.get<Components::UnitPowersComponent>(entity);
auto& healthPower = ::Util::Unit::GetPower(unitPowersComponent, MetaGen::Shared::Unit::PowerTypeEnum::Health);
bool isAlive = healthPower.current > 0.0f;
if (!isAlive)
return;
bool isMovingForward = movementInfo.movementFlags.forward;
bool isMovingBackward = movementInfo.movementFlags.backward;
bool isMovingLeft = movementInfo.movementFlags.left;
bool isMovingRight = movementInfo.movementFlags.right;
bool isGrounded = movementInfo.movementFlags.grounded;
bool isFlying = !isGrounded && movementInfo.movementFlags.flying;
if (isAlive && modelInfo && (isGrounded || isFlying /* || (canControlInAir && isMoving))*/))
{
f32 spineOrientation = 0.0f;
f32 headOrientation = 0.0f;
f32 waistOrientation = 0.0f;
if (!isFlying)
{
if (isMovingForward)
{
if (isMovingRight)
{
spineOrientation = -30.0f;
headOrientation = -30.0f;
waistOrientation = 45.0f;
}
else if (isMovingLeft)
{
spineOrientation = 30.0f;
headOrientation = 30.0f;
waistOrientation = -45.0f;
}
}
else if (isMovingBackward)
{
if (isMovingRight)
{
spineOrientation = 30.0f;
headOrientation = 15.0f;
waistOrientation = -45.0f;
}
else if (isMovingLeft)
{
spineOrientation = -30.0f;
headOrientation = -15.0f;
waistOrientation = 45.0f;
}
}
else if (isMovingRight)
{
spineOrientation = -45.0f;
headOrientation = -30.0f;
waistOrientation = 90.0f;
}
else if (isMovingLeft)
{
spineOrientation = 45.0f;
headOrientation = 30.0f;
waistOrientation = -90.0f;
}
}
f32 timeToChange = 0.1f;
if (!isMovingForward && !isMovingBackward && spineOrientation == 0.0f && headOrientation == 0.0f && waistOrientation == 0.0f)
timeToChange = 0.35f;
SetOrientation(movementInfo.spineRotationSettings, spineOrientation, timeToChange);
SetOrientation(movementInfo.headRotationSettings, headOrientation, timeToChange);
SetOrientation(movementInfo.rootRotationSettings, waistOrientation, timeToChange);
}
if (HandleUpdateOrientation(movementInfo.spineRotationSettings, deltaTime))
{
quat rotation = glm::quat(glm::vec3(0.0f, glm::radians(movementInfo.spineRotationSettings.x), 0.0f));
::Util::Animation::SetBoneRotation(modelInfo, animationData, ::Animation::Defines::Bone::SpineLow, rotation);
}
if (HandleUpdateOrientation(movementInfo.headRotationSettings, deltaTime))
{
quat rotation = glm::quat(glm::vec3(0.0f, glm::radians(movementInfo.headRotationSettings.x), 0.0f));
::Util::Animation::SetBoneRotation(modelInfo, animationData, ::Animation::Defines::Bone::Head, rotation);
}
if (HandleUpdateOrientation(movementInfo.rootRotationSettings, deltaTime))
{
quat rotation = glm::quat(glm::vec3(0.0f, glm::radians(movementInfo.rootRotationSettings.x), 0.0f));
::Util::Animation::SetBoneRotation(modelInfo, animationData, ::Animation::Defines::Bone::Default, rotation);
}
});
auto* itemStorage = clientDBSingleton.Get(ClientDBHash::Item);
auto unitVisualEquipmentView = registry.view<const Components::Unit, const Components::DisplayInfo, const Components::Model, const Components::UnitCustomization, Components::UnitEquipment, Components::UnitVisualEquipmentDirty>();
unitVisualEquipmentView.each([&](entt::entity entity, const Components::Unit& unit, const Components::DisplayInfo& displayInfo, const Components::Model& model, const Components::UnitCustomization& unitCustomization, Components::UnitEquipment& unitEquipment)
{
if (!model.flags.loaded)
return;
bool needToRefreshGeometry = false;
bool needToRefreshSkin = false;
for (const MetaGen::Shared::Unit::ItemEquipSlotEnum equipSlot : unitEquipment.dirtyVisualItemIDSlots)
{
u32 itemID = unitEquipment.equipmentSlotToVisualItemID[(u32)equipSlot];
needToRefreshGeometry |= equipSlot != ::MetaGen::Shared::Unit::ItemEquipSlotEnum::MainHand && equipSlot != ::MetaGen::Shared::Unit::ItemEquipSlotEnum::OffHand && equipSlot != ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Ranged;
needToRefreshSkin |= equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Chest || equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Shirt || equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Tabard ||
equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Bracers || equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Gloves || equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Belt ||
equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Pants || equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Boots;
if (itemID == 0)
{
if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::MainHand)
{
::Util::Unit::OpenHand(registry, entity, false);
::Util::Unit::RemoveItemFromAttachment(registry, entity, ::Attachment::Defines::Type::HandRight);
}
else if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::OffHand)
{
::Util::Unit::OpenHand(registry, entity, true);
::Util::Unit::RemoveItemFromAttachment(registry, entity, ::Attachment::Defines::Type::HandLeft);
::Util::Unit::RemoveItemFromAttachment(registry, entity, ::Attachment::Defines::Type::Shield);
}
else if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Helm)
{
::Util::Unit::RemoveItemFromAttachment(registry, entity, ::Attachment::Defines::Type::Helm);
}
else if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Shoulders)
{
::Util::Unit::RemoveItemFromAttachment(registry, entity, ::Attachment::Defines::Type::ShoulderLeft);
::Util::Unit::RemoveItemFromAttachment(registry, entity, ::Attachment::Defines::Type::ShoulderRight);
}
}
else
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(itemID);
if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::MainHand)
{
entt::entity itemEntity = entt::null;
if (::Util::Unit::AddWeaponToHand(registry, entity, item, false, itemEntity))
::Util::Unit::CloseHand(registry, entity, false);
}
else if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::OffHand)
{
entt::entity itemEntity = entt::null;
if (::Util::Unit::AddWeaponToHand(registry, entity, item, true, itemEntity))
::Util::Unit::CloseHand(registry, entity, true);
}
else if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Helm)
{
entt::entity itemEntity = entt::null;
::Util::Unit::AddHelm(registry, entity, item, displayInfo.race, displayInfo.gender, itemEntity);
}
else if (equipSlot == ::MetaGen::Shared::Unit::ItemEquipSlotEnum::Shoulders)
{
entt::entity shoulderLeftEntity = entt::null;
entt::entity shoulderRightEntity = entt::null;
::Util::Unit::AddShoulders(registry, entity, item, shoulderLeftEntity, shoulderRightEntity);
}
}
}
if (unitCustomization.flags.useCustomSkin)
{
if (needToRefreshGeometry)
registry.emplace_or_replace<ECS::Components::UnitRebuildGeosets>(entity);
if (needToRefreshSkin)
registry.emplace_or_replace<ECS::Components::UnitRebuildSkinTexture>(entity);
}
unitEquipment.dirtyVisualItemIDSlots.clear();
});
registry.clear<Components::UnitVisualEquipmentDirty>();
// TODO : Handle Equipped Item Changes (Client Side Calculation of stats?)
registry.clear<Components::UnitEquipmentDirty>();
auto unitRebuildGeosetsView = registry.view<const Components::Unit, const Components::Model, ECS::Components::UnitRebuildGeosets>();
unitRebuildGeosetsView.each([&](entt::entity entity, const Components::Unit& unit, const Components::Model& model)
{
if (!model.flags.loaded)
return;
::Util::Unit::DisableAllGeometryGroups(registry, entity, model);
::Util::Unit::RefreshGeometryGroups(registry, entity, clientDBSingleton, unitCustomizationSingleton, model);
});
registry.clear<Components::UnitRebuildGeosets>();
TextureRenderer* textureRenderer = ServiceLocator::GetGameRenderer()->GetTextureRenderer();
auto& itemSingleton = dbRegistry->ctx().get<Singletons::ItemSingleton>();
auto UnitRebuildSkinTextureView = registry.view<const Components::Unit, Components::UnitCustomization, const Components::Model, Components::DisplayInfo, ECS::Components::UnitRebuildSkinTexture>();
UnitRebuildSkinTextureView.each([&](entt::entity entity, const Components::Unit& unit, Components::UnitCustomization& unitCustomization, const Components::Model& model, Components::DisplayInfo& displayInfo)
{
if (!model.flags.loaded)
return;
::Util::Unit::RefreshSkinTexture(*dbRegistry, entity, clientDBSingleton, unitCustomizationSingleton, displayInfo, unitCustomization, model);
if (auto* unitEquipment = registry.try_get<Components::UnitEquipment>(entity))
{
if (!unitCustomization.flags.hasGloveModel)
{
u32 glovesID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Gloves];
if (glovesID > 0)
{
if (itemStorage->Has(glovesID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(glovesID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
}
u32 shirtID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Shirt];
if (shirtID > 0)
{
if (itemStorage->Has(shirtID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(shirtID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
u32 bracersID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Bracers];
if (bracersID > 0)
{
if (itemStorage->Has(bracersID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(bracersID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
u32 bootsID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Boots];
if (bootsID > 0)
{
if (itemStorage->Has(bootsID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(bootsID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
u32 pantsID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Pants];
if (pantsID > 0)
{
if (itemStorage->Has(pantsID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(pantsID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
u32 chestID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Chest];
if (chestID > 0)
{
if (itemStorage->Has(chestID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(chestID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
if (unitCustomization.flags.hasGloveModel)
{
u32 glovesID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Gloves];
if (glovesID > 0)
{
if (itemStorage->Has(glovesID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(glovesID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
}
u32 beltID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Belt];
if (beltID > 0)
{
if (itemStorage->Has(beltID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(beltID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
u32 tabardID = unitEquipment->equipmentSlotToVisualItemID[(u32)MetaGen::Shared::Unit::ItemEquipSlotEnum::Tabard];
if (tabardID > 0)
{
if (itemStorage->Has(tabardID))
{
auto& item = itemStorage->Get<MetaGen::Shared::ClientDB::ItemRecord>(tabardID);
if (item.displayID > 0)
{
ECSUtil::UnitCustomization::WriteItemToSkin(textureSingleton, clientDBSingleton, itemSingleton, unitCustomizationSingleton, unitCustomization, item.displayID);
}
}
}
}
});
registry.clear<Components::UnitRebuildSkinTexture>();
}
}