PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/src/lipsofsuna/extension/sound/ext-script.c

https://github.com/deldiablo/GodheadLips
C | 214 lines | 163 code | 26 blank | 25 comment | 21 complexity | c6d8a00daf60f890b7e35234ebecf777 MD5 | raw file
  1. /* Lips of Suna
  2. * Copyright© 2007-2011 Lips of Suna development team.
  3. *
  4. * Lips of Suna is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as
  6. * published by the Free Software Foundation, either version 3 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * Lips of Suna is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with Lips of Suna. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \addtogroup LIExt Extension
  19. * @{
  20. * \addtogroup LIExtSound Sound
  21. * @{
  22. */
  23. #include "ext-module.h"
  24. static void Sound_effect (LIScrArgs* args)
  25. {
  26. #ifndef LI_DISABLE_SOUND
  27. int tmp;
  28. int flags = 0;
  29. float pitch;
  30. float volume;
  31. const char* effect;
  32. LIEngObject* object;
  33. LIExtModule* module;
  34. LIMatVector velocity;
  35. LIScrData* data;
  36. LISndSource* source;
  37. if (liscr_args_gets_string (args, "effect", &effect) &&
  38. liscr_args_gets_data (args, "object", LISCR_SCRIPT_OBJECT, &data))
  39. {
  40. if (liscr_args_gets_bool (args, "positional", &tmp) && !tmp)
  41. flags |= LIEXT_SOUND_FLAG_NONPOSITIONAL;
  42. if (liscr_args_gets_bool (args, "repeating", &tmp) && tmp)
  43. flags |= LIEXT_SOUND_FLAG_REPEAT;
  44. object = liscr_data_get_data (data);
  45. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  46. source = liext_sound_set_effect (module, object->id, effect, flags);
  47. if (source != NULL)
  48. {
  49. if (liscr_args_gets_float (args, "pitch", &pitch))
  50. lisnd_source_set_pitch (source, pitch);
  51. if (liscr_args_gets_float (args, "volume", &volume))
  52. lisnd_source_set_volume (source, volume);
  53. if (liscr_args_gets_vector (args, "velocity", &velocity))
  54. lisnd_source_set_velocity (source, &velocity);
  55. }
  56. }
  57. #endif
  58. }
  59. static void Sound_get_listener_position (LIScrArgs* args)
  60. {
  61. LIExtModule* module;
  62. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  63. liscr_args_seti_vector (args, &module->listener_position);
  64. }
  65. static void Sound_set_listener_position (LIScrArgs* args)
  66. {
  67. LIExtModule* module;
  68. LIMatVector value;
  69. if (liscr_args_geti_vector (args, 0, &value))
  70. {
  71. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  72. module->listener_position = value;
  73. }
  74. }
  75. static void Sound_get_listener_rotation (LIScrArgs* args)
  76. {
  77. LIExtModule* module;
  78. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  79. liscr_args_seti_quaternion (args, &module->listener_rotation);
  80. }
  81. static void Sound_set_listener_rotation (LIScrArgs* args)
  82. {
  83. LIExtModule* module;
  84. LIMatQuaternion value;
  85. if (liscr_args_geti_quaternion (args, 0, &value))
  86. {
  87. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  88. module->listener_rotation = value;
  89. }
  90. }
  91. static void Sound_get_listener_velocity (LIScrArgs* args)
  92. {
  93. LIExtModule* module;
  94. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  95. liscr_args_seti_vector (args, &module->listener_velocity);
  96. }
  97. static void Sound_set_listener_velocity (LIScrArgs* args)
  98. {
  99. LIExtModule* module;
  100. LIMatVector value;
  101. if (liscr_args_geti_vector (args, 0, &value))
  102. {
  103. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  104. module->listener_velocity = value;
  105. }
  106. }
  107. static void Sound_set_music (LIScrArgs* args)
  108. {
  109. #ifndef LI_DISABLE_SOUND
  110. const char* value;
  111. LIExtModule* module;
  112. if (liscr_args_geti_string (args, 0, &value))
  113. {
  114. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  115. liext_sound_set_music (module, value);
  116. }
  117. #endif
  118. }
  119. static void Sound_set_music_fading (LIScrArgs* args)
  120. {
  121. #ifndef LI_DISABLE_SOUND
  122. float value;
  123. LIExtModule* module;
  124. if (liscr_args_geti_float (args, 0, &value))
  125. {
  126. value = LIMAT_MAX (0.0f, value);
  127. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  128. liext_sound_set_music_fading (module, value);
  129. }
  130. #endif
  131. }
  132. static void Sound_get_music_offset (LIScrArgs* args)
  133. {
  134. #ifndef LI_DISABLE_SOUND
  135. LIExtModule* module;
  136. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  137. if (module->music != NULL)
  138. liscr_args_seti_float (args, lisnd_source_get_offset (module->music));
  139. else
  140. liscr_args_seti_float (args, 0.0f);
  141. #else
  142. liscr_args_seti_float (args, 0.0f);
  143. #endif
  144. }
  145. static void Sound_set_music_offset (LIScrArgs* args)
  146. {
  147. #ifndef LI_DISABLE_SOUND
  148. float value;
  149. LIExtModule* module;
  150. if (liscr_args_geti_float (args, 0, &value))
  151. {
  152. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  153. if (module->music != NULL)
  154. lisnd_source_set_offset (module->music, value);
  155. }
  156. #endif
  157. }
  158. static void Sound_set_music_volume (LIScrArgs* args)
  159. {
  160. #ifndef LI_DISABLE_SOUND
  161. float value;
  162. LIExtModule* module;
  163. if (liscr_args_geti_float (args, 0, &value))
  164. {
  165. module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
  166. liext_sound_set_music_volume (module, value);
  167. }
  168. #endif
  169. }
  170. /*****************************************************************************/
  171. void liext_script_sound (
  172. LIScrScript* self)
  173. {
  174. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_effect", Sound_effect);
  175. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_get_listener_position", Sound_get_listener_position);
  176. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_set_listener_position", Sound_set_listener_position);
  177. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_get_listener_rotation", Sound_get_listener_rotation);
  178. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_set_listener_rotation", Sound_set_listener_rotation);
  179. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_get_listener_velocity", Sound_get_listener_velocity);
  180. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_set_listener_velocity", Sound_set_listener_velocity);
  181. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_set_music", Sound_set_music);
  182. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_set_music_fading", Sound_set_music_fading);
  183. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_get_music_offset", Sound_get_music_offset);
  184. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_set_music_offset", Sound_set_music_offset);
  185. liscr_script_insert_cfunc (self, LIEXT_SCRIPT_SOUND, "sound_set_music_volume", Sound_set_music_volume);
  186. }
  187. /** @} */
  188. /** @} */