From: Javier Sancho Date: Wed, 8 Apr 2020 07:16:55 +0000 (+0200) Subject: set-material-flag! refactor X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=789237bc01f8b2172725b51dbc7ae72b9a30be7a;p=guile-irrlicht.git set-material-flag! refactor --- diff --git a/src/animated-mesh-scene-node.cpp b/src/animated-mesh-scene-node.cpp index ceb5ec2..dc46e80 100644 --- a/src/animated-mesh-scene-node.cpp +++ b/src/animated-mesh-scene-node.cpp @@ -21,6 +21,7 @@ #include #include + #include "animated-mesh-md2.h" #include "animated-mesh-scene-node.h" #include "wrapped.h" @@ -40,11 +41,11 @@ extern "C" { wrap_animated_mesh_scene_node, unwrap_animated_mesh_scene_node); SCM - irr_scene_setMD2Animation (SCM wrappedAnimatedMeshSceneNode, + irr_scene_setMD2Animation (SCM wrapped_animated_mesh_scene_node, SCM anim) { irr::scene::IAnimatedMeshSceneNode* node = - unwrap_animated_mesh_scene_node (wrappedAnimatedMeshSceneNode); + unwrap_animated_mesh_scene_node (wrapped_animated_mesh_scene_node); bool result = node->setMD2Animation (scm_to_md2_animation_type (anim)); return scm_from_bool (result); } diff --git a/src/animated-mesh-scene-node.h b/src/animated-mesh-scene-node.h index c84aab9..04c484b 100644 --- a/src/animated-mesh-scene-node.h +++ b/src/animated-mesh-scene-node.h @@ -36,7 +36,7 @@ extern "C" { wrap_animated_mesh_scene_node, unwrap_animated_mesh_scene_node); SCM - irr_scene_setMD2Animation (SCM wrappedAnimatedMeshSceneNode, + irr_scene_setMD2Animation (SCM wrapped_animated_mesh_scene_node, SCM anim); } diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index f81cff7..a1e8411 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -36,7 +36,6 @@ #include "guile-irrlicht.h" #include "keymap.h" #include "material.h" -#include "material-flags.h" #include "mesh.h" #include "mesh-scene-node.h" #include "reference-counted.h" @@ -68,7 +67,6 @@ extern "C" { init_gui_static_text (); init_keymap (); init_material (); - init_material_flag (); init_mesh (); init_mesh_scene_node (); init_reference_counted (); @@ -83,10 +81,11 @@ extern "C" { scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_drawAll); scm_c_define_gsubr ("get-name", 1, 0, 0, (scm_t_subr)irr_getName); scm_c_define_gsubr ("set-material!", 2, 0, 0, (scm_t_subr)irr_setMaterial); + scm_c_define_gsubr ("set-material-flag!", 3, 0, 0, (scm_t_subr)irr_setMaterialFlag); scm_c_define_gsubr ("set-position!", 2, 0, 0, (scm_t_subr)irr_setPosition); scm_c_define_gsubr ("set-visible!", 2, 0, 0, (scm_t_subr)irr_setVisible); - scm_c_export ("draw-all", "get-name", "set-material!", "set-position!", - "set-visible!", NULL); + scm_c_export ("draw-all", "get-name", "set-material!", "set-material-flag!", + "set-position!", "set-visible!", NULL); } SCM @@ -137,6 +136,22 @@ extern "C" { } } + SCM + irr_setMaterialFlag (SCM wrapped_obj, + SCM flag, + SCM newvalue) + { + if (mesh_scene_node_p (wrapped_obj) || scene_node_p (wrapped_obj)) + { + return irr_scene_ISceneNode_setMaterialFlag (wrapped_obj, flag, newvalue); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set material flag to object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + SCM irr_setPosition (SCM wrapped_obj, SCM position) @@ -151,7 +166,7 @@ extern "C" { } else { - scm_error (scm_arg_type_key, NULL, "Cannot set position for object: ~S", + scm_error (scm_arg_type_key, NULL, "Cannot set position to object: ~S", scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); } } @@ -174,7 +189,7 @@ extern "C" { } else { - scm_error (scm_arg_type_key, NULL, "Cannot set visibility for object: ~S", + scm_error (scm_arg_type_key, NULL, "Cannot set visibility to object: ~S", scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); } return SCM_UNSPECIFIED; diff --git a/src/guile-irrlicht.h b/src/guile-irrlicht.h index 52026d7..5f42bac 100644 --- a/src/guile-irrlicht.h +++ b/src/guile-irrlicht.h @@ -40,6 +40,11 @@ extern "C" { irr_setMaterial (SCM wrapped_obj, SCM material); + SCM + irr_setMaterialFlag (SCM wrapped_obj, + SCM flag, + SCM newvalue); + SCM irr_setPosition (SCM wrapped_obj, SCM position); diff --git a/src/material-flags.cpp b/src/material-flags.cpp index 90aa64e..0957af6 100644 --- a/src/material-flags.cpp +++ b/src/material-flags.cpp @@ -21,42 +21,9 @@ #include #include -#include "animated-mesh-scene-node.h" -#include "material-flags.h" -#include "scene-node.h" extern "C" { - void - init_material_flag (void) - { - scm_c_define_gsubr ("set-material-flag!", 3, 0, 0, (scm_t_subr)irr_scene_setMaterialFlag); - scm_c_export ("set-material-flag!", NULL); - } - - SCM - irr_scene_setMaterialFlag (SCM wrapped_obj, - SCM flag, - SCM newvalue) - { - if (animated_mesh_scene_node_p (wrapped_obj)) - { - unwrap_animated_mesh_scene_node (wrapped_obj)->setMaterialFlag (scm_to_material_flag (flag), - scm_to_bool (newvalue)); - } - else if (scene_node_p (wrapped_obj)) - { - unwrap_scene_node (wrapped_obj)->setMaterialFlag (scm_to_material_flag (flag), - scm_to_bool (newvalue)); - } - else - { - scm_error (scm_arg_type_key, NULL, "Cannot set material flag for object: ~S", - scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); - } - return SCM_UNSPECIFIED; - } - irr::video::E_MATERIAL_FLAG scm_to_material_flag (SCM material_flag) { diff --git a/src/material-flags.h b/src/material-flags.h index 77aa62b..1b1f053 100644 --- a/src/material-flags.h +++ b/src/material-flags.h @@ -27,14 +27,6 @@ extern "C" { - void - init_material_flag (void); - - SCM - irr_scene_setMaterialFlag (SCM wrapped_obj, - SCM flag, - SCM newvalue); - irr::video::E_MATERIAL_FLAG scm_to_material_flag (SCM material_flag); diff --git a/src/scene-node.cpp b/src/scene-node.cpp index 684ad3f..f587c05 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -23,6 +23,7 @@ #include #include "animated-mesh-scene-node.h" +#include "material-flags.h" #include "matrix4.h" #include "mesh-scene-node.h" #include "scene-node.h" @@ -65,28 +66,63 @@ extern "C" { return scm_from_matrix4 (node->getAbsoluteTransformation ()); } + SCM + irr_scene_ISceneNode_setMaterialFlag (SCM wrapped_scene_node, + SCM flag, + SCM newvalue) + { + irr::scene::ISceneNode* node; + + if (animated_mesh_scene_node_p (wrapped_scene_node)) + { + node = (irr::scene::ISceneNode*)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); + } + else if (scene_node_p (wrapped_scene_node)) + { + node = unwrap_scene_node (wrapped_scene_node); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set material flag to object: ~S", + 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; + } + SCM irr_scene_setMaterialTexture (SCM wrapped_scene_node, SCM texture_layer, SCM texture) { + irr::scene::ISceneNode* node; + if (animated_mesh_scene_node_p (wrapped_scene_node)) { - unwrap_animated_mesh_scene_node (wrapped_scene_node)-> - setMaterialTexture (scm_to_uint32 (texture_layer), - unwrap_texture (texture)); + node = (irr::scene::ISceneNode*)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); } else if (scene_node_p (wrapped_scene_node)) { - unwrap_scene_node (wrapped_scene_node)-> - setMaterialTexture (scm_to_uint32 (texture_layer), - unwrap_texture (texture)); + node = unwrap_scene_node (wrapped_scene_node); } else { scm_error (scm_arg_type_key, NULL, "Cannot set material texture to object: ~S", 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; } diff --git a/src/scene-node.h b/src/scene-node.h index 660cc86..3246b8b 100644 --- a/src/scene-node.h +++ b/src/scene-node.h @@ -41,6 +41,11 @@ extern "C" { SCM irr_scene_getAbsoluteTransformation (SCM wrapped_scene_node); + SCM + irr_scene_ISceneNode_setMaterialFlag (SCM wrapped_scene_node, + SCM flag, + SCM newvalue); + SCM irr_scene_setMaterialTexture (SCM wrapped_scene_node, SCM texture_layer,