11#include <glm/gtc/matrix_transform.hpp>
12#include <glm/gtc/quaternion.hpp>
19 m = glm::translate(
m, glm::vec3(
n.x,
n.y,
n.z));
20 if (
n.space ==
"2d") {
21 m = glm::rotate(
m,
n.roll, glm::vec3(0.f, 0.f, 1.f));
23 m = glm::rotate(
m,
n.yaw, glm::vec3(0.f, 1.f, 0.f));
24 m = glm::rotate(
m,
n.pitch, glm::vec3(1.f, 0.f, 0.f));
25 m = glm::rotate(
m,
n.roll, glm::vec3(0.f, 0.f, 1.f));
27 m = glm::scale(
m, glm::vec3(
n.sx,
n.sy,
n.sz));
34void updateNode(SceneHost::Tree &tree,
int nodeIndex,
const glm::mat4 &parentWorld) {
38 for (
int c =
n.firstChild;
c >= 0;
c = tree.nodes[size_t(
c)].nextSibling) {
39 updateNode(tree,
c,
n.world);
44void pullTargets(SceneHost *
host) {
46 auto t =
host->tree();
47 for (
size_t i = 0; i <
t->nodes.size(); ++i) {
48 SceneNode &
n =
t->nodes[i];
49 for (
auto &l :
n.links) {
50 if (l.syncMode != 1 || !l.target)
continue;
54 host->markSubtreeDirty(
int(i));
60void pushTarget(
const SceneNode &
n,
const SceneLink &l);
61void updateNodeIncremental(SceneHost::Tree &tree,
int nodeIndex,
62 const glm::mat4 &parentWorld,
bool force) {
64 const bool need =
force ||
n.subtreeDirty;
68 n.subtreeDirty =
false;
69 for (
auto &l :
n.links) {
70 if (l.syncMode == 0) pushTarget(
n, l);
73 for (
int c =
n.firstChild;
c >= 0;
c = tree.nodes[size_t(
c)].nextSibling) {
74 updateNodeIncremental(tree,
c,
n.world, need);
79void pushTarget(
const SceneNode &
n,
const SceneLink &l) {
80 if (!l.target)
return;
85void syncLinks(SceneHost *
host) {
87 auto t =
host->tree();
89 for (
auto &l :
n.links) {
90 if (l.syncMode == 0) pushTarget(
n, l);
100bool linkTargetAlive(
const SceneLink &l) {
101 if (!l.target)
return false;
108void purgeDeadLinks(SceneHost::Tree &tree) {
109 for (
auto &
n : tree.
nodes) {
110 for (
auto it =
n.links.begin(); it !=
n.links.end();) {
111 if (linkTargetAlive(*it)) {
114 it =
n.links.erase(it);
124 auto t =
host->tree();
125 if (
t->root < 0 ||
t->nodes.empty()) {
126 t->transformDirty =
false;
136 bool legacy =
t->transformDirty;
137 bool anySubtree =
false;
139 for (
const auto &
n :
t->nodes) {
140 if (
n.localDirty && !
n.subtreeDirty) {
144 anySubtree = anySubtree ||
n.subtreeDirty;
149 if (
t->nodes[
index].parent < 0) updateNode(*
t,
static_cast<int>(
index), glm::mat4(1.f));
151 for (
auto &
n :
t->nodes) {
152 n.localDirty =
false;
153 n.subtreeDirty =
false;
155 t->transformDirty =
false;
161 t->transformDirty =
false;
165 if (
t->nodes[
index].parent < 0) updateNodeIncremental(*
t,
static_cast<int>(
index), glm::mat4(1.f),
false);
166 t->transformDirty =
false;
172 if (ecs::current()->getManager<SceneHost>() ==
nullptr)
return;
173 auto view = ecs::View<SceneHost, SceneHost::Meta, SceneHost::Tree>();
174 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
175 auto [meta, tree] = *it;
177 if (!meta->entity)
continue;
#define EV_PROFILE_MODULE(module, name)
Profile the enclosing scope, tagged with a module for grouping.
ECS mount point for one scene graph (full scene or nested subtree root). Isomorphic to eve::ui::UIHos...
glm::mat4 localMatrix(const SceneNode &node)
void flushPendingComponents()
Flush one batch of live dirty components before host traversal. @thread Owner thread; newly queued ed...
const LinkOps * linkOps(int kindId)
Link ops.
void(* pushWorld)(const SceneNode &node, void *target)
Void.
void(* pullWorld)(SceneNode &node, void *target)
Void.
bool(* alive)(const void *target)
Bool.
Retained scene node (arena). Conceptual GameObject; isomorphic to eve::ui::UINode.