migrate to new c djstdlib
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include <cstring>
|
||||
#include "string.h"
|
||||
#include "scene.h"
|
||||
|
||||
Entity *getEntity(Scene *s, uint32 id) {
|
||||
@@ -14,26 +14,26 @@ SceneGraphNode *getSceneGraphNode(Scene *s, uint32 sceneGraphNodeHandle) {
|
||||
}
|
||||
|
||||
uint32 createSceneGraphNode(Arena *arena, Scene *s) {
|
||||
appendList(&s->graphNodes, (SceneGraphNode){0});
|
||||
s->graphNodes.data[s->graphNodes.head - 1].children = PushList(arena, uint32, 64);
|
||||
return (uint32)s->graphNodes.head;
|
||||
AppendList(&s->graphNodes, (SceneGraphNode){0});
|
||||
s->graphNodes.data[s->graphNodes.length - 1].children = PushList(arena, HandleList, 64);
|
||||
return (uint32)s->graphNodes.length;
|
||||
}
|
||||
|
||||
uint32 createEntity(Arena *arena, Scene *s) {
|
||||
appendList(&s->entities, (Entity){0});
|
||||
AppendList(&s->entities, (Entity){0});
|
||||
uint32 graphNodeId = createSceneGraphNode(arena, s);
|
||||
s->entities.data[s->entities.head - 1].graphNodeHandle = graphNodeId;
|
||||
getSceneGraphNode(s, graphNodeId)->entityHandle = (uint32)s->entities.head;
|
||||
uint32 handle = (uint32)s->entities.head;
|
||||
uint32 graphNodeHandle = (uint32)s->graphNodes.head;
|
||||
s->entities.data[s->entities.length - 1].graphNodeHandle = graphNodeId;
|
||||
getSceneGraphNode(s, graphNodeId)->entityHandle = (uint32)s->entities.length;
|
||||
uint32 handle = (uint32)s->entities.length;
|
||||
uint32 graphNodeHandle = (uint32)s->graphNodes.length;
|
||||
initGraphNode(getSceneGraphNode(s, graphNodeHandle));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void initGraphNode(SceneGraphNode *n) {
|
||||
n->scale = RLVector3{1.0f, 1.0f, 1.0f};
|
||||
n->translation = RLVector3{0.0f, 0.0f, 0.0f};
|
||||
n->rotation = Quaternion{1.0f, 0.0f, 0.0f, 0.0f};
|
||||
n->scale = (RLVector3){1.0f, 1.0f, 1.0f};
|
||||
n->translation = (RLVector3){0.0f, 0.0f, 0.0f};
|
||||
n->rotation = (Quaternion){1.0f, 0.0f, 0.0f, 0.0f};
|
||||
n->local = MatrixIdentity();
|
||||
n->world = n->local;
|
||||
}
|
||||
@@ -44,8 +44,8 @@ void recalcGraphNode(SceneGraphNode *n) {
|
||||
|
||||
Scene createScene(Arena *arena) {
|
||||
Scene result = {};
|
||||
result.entities = PushList(arena, Entity, 1024);
|
||||
result.graphNodes = PushList(arena, SceneGraphNode, 1024);
|
||||
result.entities = PushList(arena, EntityList, 1024);
|
||||
result.graphNodes = PushList(arena, SceneGraphNodeList, 1024);
|
||||
result.sceneRoot = createSceneGraphNode(arena, &result);
|
||||
return result;
|
||||
}
|
||||
@@ -75,10 +75,10 @@ void removeEntity(Scene *s, uint32 entityHandle) {
|
||||
SceneGraphNode *graphNode = getSceneGraphNode(s, entity->graphNodeHandle);
|
||||
if (graphNode->parentHandle) {
|
||||
SceneGraphNode *parentNode = getSceneGraphNode(s, graphNode->parentHandle);
|
||||
for (int i = 0; i < parentNode->children.head; i++) {
|
||||
for (int i = 0; i < parentNode->children.length; i++) {
|
||||
if (parentNode->children.data[i] == entity->graphNodeHandle) {
|
||||
memcpy(&parentNode->children.data[i], &parentNode->children.data[i + 1], parentNode->children.head - i);
|
||||
parentNode->children.head -= 1;
|
||||
memcpy(&parentNode->children.data[i], &parentNode->children.data[i + 1], parentNode->children.length - i);
|
||||
parentNode->children.length -= 1;
|
||||
graphNode->parentHandle = 0;
|
||||
break;
|
||||
}
|
||||
@@ -87,7 +87,6 @@ void removeEntity(Scene *s, uint32 entityHandle) {
|
||||
}
|
||||
|
||||
void sceneNodeAddEntity(Scene *s, uint32 graphNodeHandle, uint32 entityHandle) {
|
||||
list<uint32> *childList = &getSceneGraphNode(s, graphNodeHandle)->children;
|
||||
appendList(childList, getEntity(s, entityHandle)->graphNodeHandle);
|
||||
print("%zu HI\n", childList->length);
|
||||
HandleList *childList = &getSceneGraphNode(s, graphNodeHandle)->children;
|
||||
AppendList(childList, getEntity(s, entityHandle)->graphNodeHandle);
|
||||
}
|
||||
|
||||
@@ -1,42 +1,46 @@
|
||||
#include "../gfx/gfx.h"
|
||||
#include "../lib/raymath.h"
|
||||
|
||||
DefineList(uint32, Handle);
|
||||
|
||||
enum EntityFlags {
|
||||
EntityFlags_Visible=1<<0,
|
||||
EntityFlags_Dead=1<<1,
|
||||
EntityFlags_Render=1<<2,
|
||||
};
|
||||
};
|
||||
|
||||
struct Entity {
|
||||
typedef struct {
|
||||
Mesh *mesh;
|
||||
Texture *tex;
|
||||
uint32 graphNodeHandle;
|
||||
uint64 flags;
|
||||
};
|
||||
} Entity;
|
||||
DefineList(Entity, Entity);
|
||||
|
||||
struct SceneGraphNode {
|
||||
typedef struct {
|
||||
Matrix local;
|
||||
Matrix world;
|
||||
RLVector3 translation;
|
||||
Quaternion rotation;
|
||||
RLVector3 scale;
|
||||
list<uint32> children;
|
||||
HandleList children;
|
||||
uint32 entityHandle;
|
||||
uint32 parentHandle;
|
||||
};
|
||||
} SceneGraphNode;
|
||||
DefineList(SceneGraphNode, SceneGraphNode);
|
||||
|
||||
struct Scene {
|
||||
typedef struct {
|
||||
uint32 sceneRoot;
|
||||
list<Entity> entities;
|
||||
list<SceneGraphNode> graphNodes;
|
||||
};
|
||||
EntityList entities;
|
||||
SceneGraphNodeList graphNodes;
|
||||
} Scene;
|
||||
|
||||
uint32 createEntity(Arena *arena, Scene *s);
|
||||
Entity *getEntity(Scene *s);
|
||||
SceneGraphNode *getSceneGraphNode(Scene *s, int id);
|
||||
Entity *getEntity(Scene *s, uint32 id);
|
||||
SceneGraphNode *getSceneGraphNode(Scene *s, uint32 id);
|
||||
uint32 createSceneGraphNode(Arena *arena, Scene *s);
|
||||
Scene createScene(Arena *arena);
|
||||
void initGraphNode(SceneGraphNode *n);
|
||||
void initGraphNode(SceneGraphNode *n);
|
||||
void recalcGraphNode(SceneGraphNode *n);
|
||||
void recalcSceneGraphNode(Scene *s, uint32 parentHandle);
|
||||
void recalcScene(Scene *s);
|
||||
|
||||
Reference in New Issue
Block a user