You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

97 lines
1.5 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdlib>
  14. #include <cstdio>
  15. #include <cmath>
  16. #include <cstring>
  17. #if defined USE_SDL
  18. # include <SDL.h>
  19. # include <SDL_mixer.h>
  20. #endif
  21. #include "core.h"
  22. namespace lol
  23. {
  24. /*
  25. * Sample implementation class
  26. */
  27. class SampleData
  28. {
  29. friend class Sample;
  30. private:
  31. char *name, *path;
  32. #if defined USE_SDL
  33. Mix_Chunk *chunk;
  34. #endif
  35. };
  36. /*
  37. * Public Sample class
  38. */
  39. Sample::Sample(char const *path)
  40. : data(new SampleData())
  41. {
  42. data->name = (char *)malloc(9 + strlen(path) + 1);
  43. data->path = data->name + 9;
  44. sprintf(data->name, "<sample> %s", path);
  45. #if defined USE_SDL
  46. data->chunk = Mix_LoadWAV(path);
  47. if (!data->chunk)
  48. {
  49. #if !LOL_RELEASE
  50. Log::Error("could not load %s\n", path);
  51. #endif
  52. SDL_Quit();
  53. exit(1);
  54. }
  55. #endif
  56. }
  57. Sample::~Sample()
  58. {
  59. #if defined USE_SDL
  60. Mix_FreeChunk(data->chunk);
  61. #endif
  62. free(data->name);
  63. delete data;
  64. }
  65. void Sample::TickGame(float deltams)
  66. {
  67. Entity::TickGame(deltams);
  68. }
  69. char const *Sample::GetName()
  70. {
  71. return data->name;
  72. }
  73. void Sample::Play()
  74. {
  75. #if defined USE_SDL
  76. Mix_PlayChannel(-1, data->chunk, 0);
  77. #endif
  78. }
  79. } /* namespace lol */