1#include "ComponentFunctions.h"
3#include "Foundation/Logging/Logger.h"
7#include "EntityStore.h"
9#include "Systems/Core/TransformSystem.h"
10#include "Systems/Core/SceneSystem.h"
11#include "Systems/Core/RenderSystem.h"
12#include "Systems/Core/CameraSystem.h"
13#include "Systems/Core/DynamicComponentSystem.h"
21 void entityError(
const char* method,
const EntityId entityId)
23 LOG_ERROR(logger,
"%s: Invalid entity id %zd.", method,
size_t(entityId));
27void getLocalTransform(BridgeContext* ctx, EntityId entityId,
float * data)
29 auto context =
static_cast<Context*
>(ctx);
32 entityError(
"getLocalTransform", entityId);
38 if (!transformComponent) {
39 LOG_ERROR(logger,
"Could not retrieve transform component for entity %zd.", entity->getId());
43 context->transformSystem->updateLocalTransform(*transformComponent);
45 *
reinterpret_cast<glm::mat4 *
>(data) = context->transformSystem->getLocalTransform(transformComponent);
48void getWorldTransform(BridgeContext* ctx, EntityId entityId,
float * data)
50 auto context =
static_cast<Context*
>(ctx);
53 entityError(
"getWorldTransform", entityId);
59 if (!transformComponent) {
60 LOG_ERROR(logger,
"Could not retrieve transform component for entity %zd.", entity->getId());
64 context->transformSystem->updateTransformData(*transformComponent);
66 *
reinterpret_cast<glm::mat4 *
>(data) = context->transformSystem->getLocalToWorld(transformComponent);
69void getViewMatrix(BridgeContext* ctx, EntityId entityId,
float * data)
71 auto context =
static_cast<Context*
>(ctx);
74 entityError(
"getViewMatrix", entityId);
80 if (!cameraComponent) {
81 LOG_ERROR(logger,
"Could not retrieve camera component for entity %zd.", entity->getId());
85 auto cameraData = &context->cameraSystem->getData(cameraComponent);
88 LOG_ERROR(logger,
"Could not get camera data for entity %zd.", entity->getId());
92 *
reinterpret_cast<glm::mat4 *
>(data) = cameraData->viewMatrix;
95void getProjectionMatrix(BridgeContext* ctx, EntityId entityId,
float * data)
97 auto context =
static_cast<Context*
>(ctx);
100 entityError(
"getProjectionMatrix", entityId);
106 if (!cameraComponent) {
107 LOG_ERROR(logger,
"Could not retrieve camera component for entity %zd.", entity->getId());
111 auto cameraData = &context->cameraSystem->getData(cameraComponent);
114 LOG_ERROR(logger,
"Could not get camera data for entity %zd.", entity->getId());
118 *
reinterpret_cast<glm::mat4 *
>(data) = cameraData->projectionMatrix;
121CogsBool getVisibility(BridgeContext* ctx, EntityId entityId,
const int mask)
123 auto context =
static_cast<Context*
>(ctx);
126 entityError(
"getVisibility", entityId);
132 if (!renderComponent) {
133 LOG_ERROR(logger,
"Could not retrieve render component for entity %zd.", entity->getId());
137 return renderComponent->isVisibleInLayer((
RenderLayers)mask);
140void sendMessage(BridgeContext* ctx, EntityId entityId,
const char * message,
void * arg)
142 auto context =
static_cast<Context*
>(ctx);
145 entityError(
"sendMessage", entityId);
149 auto messageId = context->dynamicComponentSystem->getMessageId(
Cogs::StringView(message));
150 context->dynamicComponentSystem->sendMessage(entity, messageId, arg);
151 context->engine->triggerUpdate();
A Context instance contains all the services, systems and runtime components needed to use Cogs.
class EntityStore * store
Entity store.
ComponentModel::Entity * getEntityPtr(const EntityId entityId)
Get a raw pointer to the entity with the given id.
Base component for all rendering content.
Log implementation class.
Provides a weakly referenced view over the contents of a string.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
RenderLayers
Contains common render layers.
constexpr Log getLogger(const char(&name)[LEN]) noexcept