From: Javier Sancho Date: Sat, 11 Apr 2020 10:49:02 +0000 (+0200) Subject: Some macros X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=a1fe598c49e7222ec5a01ad62b49026825f595d9;p=guile-irrlicht.git Some macros --- diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index f0ed9c7..1d7636a 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -176,17 +176,19 @@ extern "C" { irr_setVisible (SCM wrapped_obj, SCM visible) { +#define SET_VISIBLE(OBJ) OBJ->setVisible (scm_to_bool (visible)); + if (cursor_control_p (wrapped_obj)) { - unwrap_cursor_control (wrapped_obj)->setVisible (scm_to_bool (visible)); + SET_VISIBLE (unwrap_cursor_control (wrapped_obj)); } else if (gui_element_p (wrapped_obj)) { - unwrap_gui_element (wrapped_obj)->setVisible (scm_to_bool (visible)); + SET_VISIBLE (unwrap_gui_element (wrapped_obj)); } else if (scene_node_p (wrapped_obj)) { - unwrap_scene_node (wrapped_obj)->setVisible (scm_to_bool (visible)); + SET_VISIBLE (unwrap_scene_node (wrapped_obj)); } else { diff --git a/src/scene-node.cpp b/src/scene-node.cpp index cdad641..31109ea 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -52,19 +52,19 @@ extern "C" { irr_scene_addAnimator (SCM wrapped_scene_node, SCM animator) { - irr::scene::ISceneNode* node; +#define ADD_ANIMATOR(NODE) NODE->addAnimator (unwrap_scene_node_animator (animator)); if (animated_mesh_scene_node_p (wrapped_scene_node)) { - node = (irr::scene::ISceneNode*)unwrap_animated_mesh_scene_node (wrapped_scene_node); + ADD_ANIMATOR (unwrap_animated_mesh_scene_node (wrapped_scene_node)); } else if (mesh_scene_node_p (wrapped_scene_node)) { - node = (irr::scene::ISceneNode*)unwrap_mesh_scene_node (wrapped_scene_node); + ADD_ANIMATOR (unwrap_mesh_scene_node (wrapped_scene_node)); } else if (scene_node_p (wrapped_scene_node)) { - node = unwrap_scene_node (wrapped_scene_node); + ADD_ANIMATOR (unwrap_scene_node (wrapped_scene_node)); } else { @@ -72,7 +72,6 @@ extern "C" { scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); } - node->addAnimator (unwrap_scene_node_animator (animator)); return SCM_UNSPECIFIED; } @@ -88,19 +87,20 @@ extern "C" { SCM flag, SCM newvalue) { - irr::scene::ISceneNode* node; +#define SET_MATERIAL_FLAG(NODE) NODE->setMaterialFlag (scm_to_material_flag (flag), \ + scm_to_bool (newvalue)); if (animated_mesh_scene_node_p (wrapped_scene_node)) { - node = (irr::scene::ISceneNode*)unwrap_animated_mesh_scene_node (wrapped_scene_node); + SET_MATERIAL_FLAG (unwrap_animated_mesh_scene_node (wrapped_scene_node)); } else if (mesh_scene_node_p (wrapped_scene_node)) { - node = (irr::scene::ISceneNode*)unwrap_mesh_scene_node (wrapped_scene_node); + SET_MATERIAL_FLAG (unwrap_mesh_scene_node (wrapped_scene_node)); } else if (scene_node_p (wrapped_scene_node)) { - node = unwrap_scene_node (wrapped_scene_node); + SET_MATERIAL_FLAG (unwrap_scene_node (wrapped_scene_node)); } else { @@ -108,8 +108,6 @@ extern "C" { scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); } - node->setMaterialFlag (scm_to_material_flag (flag), - scm_to_bool (newvalue)); return SCM_UNSPECIFIED; } @@ -118,19 +116,20 @@ extern "C" { SCM texture_layer, SCM texture) { - irr::scene::ISceneNode* node; +#define SET_MATERIAL_TEXTURE(NODE) NODE->setMaterialTexture (scm_to_uint32 (texture_layer), \ + unwrap_texture (texture)); if (animated_mesh_scene_node_p (wrapped_scene_node)) { - node = (irr::scene::ISceneNode*)unwrap_animated_mesh_scene_node (wrapped_scene_node); + SET_MATERIAL_TEXTURE (unwrap_animated_mesh_scene_node (wrapped_scene_node)); } else if (mesh_scene_node_p (wrapped_scene_node)) { - node = (irr::scene::ISceneNode*)unwrap_mesh_scene_node (wrapped_scene_node); + SET_MATERIAL_TEXTURE (unwrap_mesh_scene_node (wrapped_scene_node)); } else if (scene_node_p (wrapped_scene_node)) { - node = unwrap_scene_node (wrapped_scene_node); + SET_MATERIAL_TEXTURE (unwrap_scene_node (wrapped_scene_node)); } else { @@ -138,8 +137,6 @@ extern "C" { scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); } - node->setMaterialTexture (scm_to_uint32 (texture_layer), - unwrap_texture (texture)); return SCM_UNSPECIFIED; } @@ -147,21 +144,22 @@ extern "C" { irr_scene_setPosition (SCM wrapped_scene_node, SCM position) { +#define SET_POSITION(NODE) NODE->setPosition (scm_to_vector3df (position)); + if (scene_node_p (wrapped_scene_node)) { - unwrap_scene_node (wrapped_scene_node)-> - setPosition (scm_to_vector3df (position)); + SET_POSITION (unwrap_scene_node (wrapped_scene_node)); } else if (mesh_scene_node_p (wrapped_scene_node)) { - unwrap_mesh_scene_node (wrapped_scene_node)-> - setPosition (scm_to_vector3df (position)); + SET_POSITION (unwrap_mesh_scene_node (wrapped_scene_node)); } else { scm_error (scm_arg_type_key, NULL, "Cannot set position to object: ~S", scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); } + return SCM_UNSPECIFIED; }