Skip to content

Commit

Permalink
Added 'is_queued_for_deletion' property and function to get full time…
Browse files Browse the repository at this point in the history
… dilation with physics delta for Nodes from python api (#184)
  • Loading branch information
Chukobyte authored Apr 4, 2023
1 parent 61cd789 commit e3a5865
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 3 deletions.
11 changes: 11 additions & 0 deletions crescent_py_api/crescent_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,12 @@ def add_child(self, child_node) -> None:
def queue_deletion(self) -> None:
crescent_api_internal.node_queue_deletion(entity_id=self.entity_id)

@property
def is_queued_for_deletion(self) -> bool:
return crescent_api_internal.node_is_queued_for_deletion(
entity_id=self.entity_id
)

def create_event(self, event_id: str) -> None:
crescent_api_internal.node_create_event(
entity_id=self.entity_id, event_id=event_id
Expand Down Expand Up @@ -985,6 +991,11 @@ def get_full_time_dilation(self) -> float:
entity_id=self.entity_id
)

def get_full_time_dilation_with_physics_delta(self) -> float:
return crescent_api_internal.node_get_full_time_dilation_with_physics_delta(
entity_id=self.entity_id
)


# 2D
class Node2D(Node):
Expand Down
8 changes: 8 additions & 0 deletions crescent_py_api/crescent_api_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def node_queue_deletion(entity_id: int) -> None:
pass


def node_is_queued_for_deletion(entity_id: int) -> bool:
return False


def node_add_child(parent_entity_id: int, child_entity_id: int) -> None:
pass

Expand Down Expand Up @@ -377,6 +381,10 @@ def node_get_full_time_dilation(entity_id: int) -> float:
return 1.0


def node_get_full_time_dilation_with_physics_delta(entity_id: int) -> float:
return 1.0


def node2D_set_position(entity_id: int, x: float, y: float) -> None:
pass

Expand Down
1 change: 1 addition & 0 deletions engine/src/core/ecs/component/node_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NodeComponent* node_component_create() {
NodeComponent* nodeComponent = SE_MEM_ALLOCATE(NodeComponent);
nodeComponent->name[0] = '\0';
nodeComponent->type = NodeBaseType_INVALID;
nodeComponent->queuedForDeletion = false;
nodeComponent->timeDilation = (NodeTimeDilation) {
.value = 1.0f, .cachedFullValue = 1.0f, .cacheInvalid = true
};
Expand Down
1 change: 1 addition & 0 deletions engine/src/core/ecs/component/node_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct NodeTimeDilation {
typedef struct NodeComponent {
char name[32];
NodeBaseType type;
bool queuedForDeletion;
NodeTimeDilation timeDilation;
// Called after '_start' is called on an entity
SEEvent onSceneTreeEnter; // { data = entity (unsigned int), type = 0 (not used) }
Expand Down
8 changes: 8 additions & 0 deletions engine/src/core/scene/scene_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ void cre_queue_destroy_tree_node_entity(SceneTreeNode* treeNode) {
}

void cre_queue_destroy_tree_node_entity_all(SceneTreeNode* treeNode) {
NodeComponent* nodeComp = cre_component_manager_get_component_unchecked(treeNode->entity, CreComponentDataIndex_NODE);
if (nodeComp) {
if (nodeComp->queuedForDeletion) {
se_logger_warn("Entity '%s' already queued for deletion, skipping queue deletion!", nodeComp->name);
return;
}
nodeComp->queuedForDeletion = true;
}
cre_scene_execute_on_all_tree_nodes(treeNode, cre_queue_destroy_tree_node_entity);
if (treeNode->parent != NULL) {
SE_STATIC_ARRAY_ADD(entitiesToUnlinkParent, treeNode->entity);
Expand Down
23 changes: 21 additions & 2 deletions engine/src/core/scripting/python/cre_py_api_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,7 @@ PyObject* cre_py_api_camera2D_unfollow_node(PyObject* self, PyObject* args, PyOb

// World
void py_mark_scene_nodes_time_dilation_flag_dirty(SceneTreeNode* node) {
NodeComponent* nodeComponent = (NodeComponent*) cre_component_manager_get_component_unchecked(node->entity,
CreComponentDataIndex_NODE);
NodeComponent* nodeComponent = (NodeComponent*) cre_component_manager_get_component_unchecked(node->entity, CreComponentDataIndex_NODE);
SE_ASSERT(nodeComponent != NULL);
nodeComponent->timeDilation.cacheInvalid = true;
}
Expand Down Expand Up @@ -868,6 +867,18 @@ PyObject* cre_py_api_node_queue_deletion(PyObject* self, PyObject* args, PyObjec
return NULL;
}

PyObject* cre_py_api_node_is_queued_for_deletion(PyObject* self, PyObject* args, PyObject* kwargs) {
CreEntity entity;
if (PyArg_ParseTupleAndKeywords(args, kwargs, "i", crePyApiGenericGetEntityKWList, &entity)) {
NodeComponent* nodeComponent = (NodeComponent*) cre_component_manager_get_component(entity, CreComponentDataIndex_NODE);
if (nodeComponent->queuedForDeletion) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
return NULL;
}

PyObject* cre_py_api_node_add_child(PyObject* self, PyObject* args, PyObject* kwargs) {
CreEntity parentEntity;
CreEntity entity;
Expand Down Expand Up @@ -990,6 +1001,14 @@ PyObject* cre_py_api_node_get_full_time_dilation(PyObject* self, PyObject* args,
return NULL;
}

PyObject* cre_py_api_node_get_full_time_dilation_with_physics_delta(PyObject* self, PyObject* args, PyObject* kwargs) {
CreEntity entity;
if (PyArg_ParseTupleAndKeywords(args, kwargs, "i", crePyApiGenericGetEntityKWList, &entity)) {
return Py_BuildValue("f", cre_scene_manager_get_node_full_time_dilation(entity) * CRE_GLOBAL_PHYSICS_DELTA_TIME);
}
return NULL;
}

// Event related stuff
void py_api_node_event_callback(void* observerData, NodeEventNotifyPayload* notifyPayload) {
PyObject* pyCallbackFunc = (PyObject*) observerData;
Expand Down
10 changes: 10 additions & 0 deletions engine/src/core/scripting/python/cre_py_api_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ PyObject* cre_py_api_game_properties_get(PyObject* self, PyObject* args);
// Node
PyObject* cre_py_api_node_new(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_queue_deletion(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_is_queued_for_deletion(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_add_child(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_get_child(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_get_children(PyObject* self, PyObject* args, PyObject* kwargs);
Expand All @@ -103,6 +104,7 @@ PyObject* cre_py_api_node_get_name(PyObject* self, PyObject* args, PyObject* kwa
PyObject* cre_py_api_node_set_time_dilation(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_get_time_dilation(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_get_full_time_dilation(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_get_full_time_dilation_with_physics_delta(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_create_event(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_subscribe_to_event(PyObject* self, PyObject* args, PyObject* kwargs);
PyObject* cre_py_api_node_broadcast_event(PyObject* self, PyObject* args, PyObject* kwargs);
Expand Down Expand Up @@ -473,6 +475,10 @@ static struct PyMethodDef crePyApiMethods[] = {
"node_queue_deletion", (PyCFunction) cre_py_api_node_queue_deletion,
METH_VARARGS | METH_KEYWORDS, "Queues a node for deletion."
},
{
"node_is_queued_for_deletion", (PyCFunction) cre_py_api_node_is_queued_for_deletion,
METH_VARARGS | METH_KEYWORDS, "Returns whether a node is queued for deletion."
},
{
"node_add_child", (PyCFunction) cre_py_api_node_add_child,
METH_VARARGS | METH_KEYWORDS, "Adds a node to the scene."
Expand Down Expand Up @@ -505,6 +511,10 @@ static struct PyMethodDef crePyApiMethods[] = {
"node_get_full_time_dilation", (PyCFunction) cre_py_api_node_get_full_time_dilation,
METH_VARARGS | METH_KEYWORDS, "Returns a node's total time dilation, including global world and parents."
},
{
"node_get_full_time_dilation_with_physics_delta", (PyCFunction) cre_py_api_node_get_full_time_dilation_with_physics_delta,
METH_VARARGS | METH_KEYWORDS, "Returns a node's total time dilation, including global world, parents, and physics delta time."
},
{
"node_create_event", (PyCFunction) cre_py_api_node_create_event,
METH_VARARGS | METH_KEYWORDS, "Creates an event to be observed by others."
Expand Down
11 changes: 11 additions & 0 deletions engine/src/core/scripting/python/crescent_api_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,12 @@
" def queue_deletion(self) -> None:\n"\
" crescent_api_internal.node_queue_deletion(entity_id=self.entity_id)\n"\
"\n"\
" @property\n"\
" def is_queued_for_deletion(self) -> bool:\n"\
" return crescent_api_internal.node_is_queued_for_deletion(\n"\
" entity_id=self.entity_id\n"\
" )\n"\
"\n"\
" def create_event(self, event_id: str) -> None:\n"\
" crescent_api_internal.node_create_event(\n"\
" entity_id=self.entity_id, event_id=event_id\n"\
Expand Down Expand Up @@ -1022,6 +1028,11 @@
" entity_id=self.entity_id\n"\
" )\n"\
"\n"\
" def get_full_time_dilation_with_physics_delta(self) -> float:\n"\
" return crescent_api_internal.node_get_full_time_dilation_with_physics_delta(\n"\
" entity_id=self.entity_id\n"\
" )\n"\
"\n"\
"\n"\
"# 2D\n"\
"class Node2D(Node):\n"\
Expand Down
4 changes: 3 additions & 1 deletion seika/src/rendering/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ TextureCoordinates renderer_get_texture_coordinates(const SETexture* texture, co
tMin = tMax;
tMax = tempTMin;
}
return (TextureCoordinates){ sMin, sMax, tMin, tMax };
return (TextureCoordinates) {
sMin, sMax, tMin, tMax
};
}

void renderer_set_shader_instance_params(SEShaderInstance* shaderInstance) {
Expand Down

0 comments on commit e3a5865

Please sign in to comment.