Skip to content

Commit f941e36

Browse files
Add is_valid functions to entity, mesh and texture in public API (#262)
* Add is_valid functions to entity, mesh and texture in public API * Update src/api/apiCore.cpp with suggested change Co-authored-by: Piotr Rybicki <[email protected]> * Add is_alive naming convention and check input argument * Add an is_alive function for node --------- Co-authored-by: Josef <[email protected]> Co-authored-by: Piotr Rybicki <[email protected]>
1 parent a3d0845 commit f941e36

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

include/rgl/api/core.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ RGL_API rgl_status_t rgl_mesh_destroy(rgl_mesh_t mesh);
474474
*/
475475
RGL_API rgl_status_t rgl_mesh_update_vertices(rgl_mesh_t mesh, const rgl_vec3f* vertices, int32_t vertex_count);
476476

477+
/**
478+
* Assigns value true to out_alive if the given mesh is known and has not been destroyed,
479+
* assigns value false otherwise.
480+
* @param mesh Mesh to check if alive
481+
* @param out_alive Boolean set to indicate if alive
482+
*/
483+
RGL_API rgl_status_t rgl_mesh_is_alive(rgl_mesh_t mesh, bool* out_alive);
484+
477485
/******************************** ENTITY ********************************/
478486

479487
/**
@@ -510,10 +518,18 @@ RGL_API rgl_status_t rgl_entity_set_id(rgl_entity_t entity, int32_t id);
510518
/**
511519
* Assign intensity texture to the given Entity. The assumption is that the Entity can hold only one intensity texture.
512520
* @param entity Entity to modify.
513-
* @apram texture Texture to assign.
521+
* @param texture Texture to assign.
514522
*/
515523
RGL_API rgl_status_t rgl_entity_set_intensity_texture(rgl_entity_t entity, rgl_texture_t texture);
516524

525+
/**
526+
* Assigns value true to out_alive if the given entity is known and has not been destroyed,
527+
* assigns value false otherwise.
528+
* @param entity Entity to check if alive
529+
* @param out_alive Boolean set to indicate if alive
530+
*/
531+
RGL_API rgl_status_t rgl_entity_is_alive(rgl_entity_t entity, bool* out_alive);
532+
517533
/******************************* TEXTURE *******************************/
518534

519535
/**
@@ -529,10 +545,18 @@ RGL_API rgl_status_t rgl_texture_create(rgl_texture_t* out_texture, const void*
529545
/**
530546
* Informs that the given texture will be no longer used.
531547
* The texture will be destroyed after all referring Entities are destroyed.
532-
* @param mesh Texture to be marked as no longer needed
548+
* @param texture Texture to be marked as no longer needed
533549
*/
534550
RGL_API rgl_status_t rgl_texture_destroy(rgl_texture_t texture);
535551

552+
/**
553+
* Assigns value true to out_alive if the given texture is known and has not been destroyed,
554+
* assigns value false otherwise.
555+
* @param texture Texture to check if alive
556+
* @param out_alive Boolean set to indicate if alive
557+
*/
558+
RGL_API rgl_status_t rgl_texture_is_alive(rgl_texture_t texture, bool* out_alive);
559+
536560
/******************************** SCENE ********************************/
537561

538562
/**
@@ -851,6 +875,14 @@ RGL_API rgl_status_t rgl_node_gaussian_noise_angular_hitpoint(rgl_node_t* node,
851875
RGL_API rgl_status_t rgl_node_gaussian_noise_distance(rgl_node_t* node, float mean, float st_dev_base,
852876
float st_dev_rise_per_meter);
853877

878+
/**
879+
* Assigns value true to out_alive if the given node is known and has not been destroyed,
880+
* assigns value false otherwise.
881+
* @param node Node to check if alive
882+
* @param out_alive Boolean set to indicate if alive
883+
*/
884+
RGL_API rgl_status_t rgl_node_is_alive(rgl_node_t node, bool* out_alive);
885+
854886
/******************************** GRAPH ********************************/
855887

856888
/**

src/api/apiCore.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ void TapeCore::tape_mesh_update_vertices(const YAML::Node& yamlNode, PlaybackSta
256256
yamlNode[2].as<int32_t>());
257257
}
258258

259+
rgl_status_t rgl_mesh_is_alive(rgl_mesh_t mesh, bool* out_alive)
260+
{
261+
auto status = rglSafeCall([&]() {
262+
CHECK_ARG(out_alive != nullptr);
263+
*out_alive = Mesh::instances.contains(mesh);
264+
});
265+
TAPE_HOOK(mesh, out_alive);
266+
return status;
267+
}
268+
259269
RGL_API rgl_status_t rgl_entity_create(rgl_entity_t* out_entity, rgl_scene_t scene, rgl_mesh_t mesh)
260270
{
261271
auto status = rglSafeCall([&]() {
@@ -355,6 +365,16 @@ void TapeCore::tape_entity_set_intensity_texture(const YAML::Node& yamlNode, Pla
355365
state.textures.at(yamlNode[1].as<TapeAPIObjectID>()));
356366
}
357367

368+
rgl_status_t rgl_entity_is_alive(rgl_entity_t entity, bool* out_alive)
369+
{
370+
auto status = rglSafeCall([&]() {
371+
CHECK_ARG(out_alive != nullptr);
372+
*out_alive = Entity::instances.contains(entity);
373+
});
374+
TAPE_HOOK(entity, out_alive);
375+
return status;
376+
}
377+
358378
RGL_API rgl_status_t rgl_texture_create(rgl_texture_t* out_texture, const void* texels, int32_t width, int32_t height)
359379
{
360380
auto status = rglSafeCall([&]() {
@@ -398,6 +418,16 @@ void TapeCore::tape_texture_destroy(const YAML::Node& yamlNode, PlaybackState& s
398418
state.textures.erase(textureId);
399419
}
400420

421+
rgl_status_t rgl_texture_is_alive(rgl_texture_t texture, bool* out_alive)
422+
{
423+
auto status = rglSafeCall([&]() {
424+
CHECK_ARG(out_alive != nullptr);
425+
*out_alive = Texture::instances.contains(texture);
426+
});
427+
TAPE_HOOK(texture, out_alive);
428+
return status;
429+
}
430+
401431
RGL_API rgl_status_t rgl_scene_set_time(rgl_scene_t scene, uint64_t nanoseconds)
402432
{
403433
auto status = rglSafeCall([&]() {
@@ -1200,6 +1230,16 @@ void TapeCore::tape_node_gaussian_noise_distance(const YAML::Node& yamlNode, Pla
12001230
state.nodes.insert({nodeId, node});
12011231
}
12021232

1233+
rgl_status_t rgl_node_is_alive(rgl_node_t node, bool* out_alive)
1234+
{
1235+
auto status = rglSafeCall([&]() {
1236+
CHECK_ARG(out_alive != nullptr);
1237+
*out_alive = Node::instances.contains(node);
1238+
});
1239+
TAPE_HOOK(node, out_alive);
1240+
return status;
1241+
}
1242+
12031243
RGL_API rgl_status_t rgl_tape_record_begin(const char* path)
12041244
{
12051245
/**

0 commit comments

Comments
 (0)