1#include "LocationComponent.h"
3#include "EntityStore.h"
6#include "Components/Core/MeshComponent.h"
7#include "Components/Core/TransformComponent.h"
8#include "Components/Appearance/MaterialComponent.h"
10#include "Resources/MeshManager.h"
12#include "../Components/DataSetComponent.h"
13#include "../Components/DataRefComponent.h"
15#include "Foundation/Logging/Logger.h"
26using namespace Cogs::Core::EchoSounder;
28void LocationComponent::registerType()
32 Field(
Name(
"time"), &LocationComponent::time),
33 Field(
Name(
"updateTransform"), &LocationComponent::updateTransform)
36 Method(
Name(
"initialize"), &LocationComponent::initialize),
37 Method(
Name(
"update"), &LocationComponent::update),
39 DynamicComponent::registerDerivedType<LocationComponent>()
44void LocationComponent::initialize(
Context * context)
46 this->context = context;
47 this->dataSystem = ExtensionRegistry::getExtensionSystem<DataSetSystem>(context);
50void LocationComponent::update()
52 if (!this->dataSystem)
return;
54 auto dataRefComp = getComponent<DataRefComponent>();
55 if (dataRefComp->data) {
57 auto & dataData = dataSystem->getData(dataComp);
60 dataRefComp->hasChanged() ||
61 dataComp->hasChanged() ||
62 dataGen != dataData.dataGen)
64 const auto & config = dataData.persistent->config;
65 const auto & buffer = dataData.persistent->buffer;
67 dataGen = dataData.dataGen;
68 if (buffer.sliceCount) {
70 index = locateContainingInterval((
int)buffer.sliceBegin,
71 (
int)(buffer.sliceBegin + buffer.sliceCount) - 1,
72 config.capacity, buffer.timestamps, time);
74 catch (std::runtime_error e) {
75 index = buffer.sliceBegin;
77 index = index % config.capacity;
79 if (updateTransform) {
80 auto * trComp = getComponent<TransformComponent>();
81 trComp->position = buffer.metaPings[index].vesselPositionGlobal;
82 trComp->rotation = buffer.metaPings[index].vesselOrientationGlobal;
bool hasFieldChanged(const Reflection::FieldId fieldId) const
Gets if the field with the given id on this component instance has changed.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Log implementation class.
Field definition describing a single data member of a data structure.
Simple method definition.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains reflection support.
Represents an unique name.