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.
 
 
 

99 rivejä
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. using namespace std;
  23. namespace lol
  24. {
  25. /*
  26. * Sample implementation class
  27. */
  28. class SampleData
  29. {
  30. friend class Sample;
  31. private:
  32. char *name, *path;
  33. #if defined USE_SDL
  34. Mix_Chunk *chunk;
  35. #endif
  36. };
  37. /*
  38. * Public Sample class
  39. */
  40. Sample::Sample(char const *path)
  41. : data(new SampleData())
  42. {
  43. data->name = (char *)malloc(9 + strlen(path) + 1);
  44. data->path = data->name + 9;
  45. sprintf(data->name, "<sample> %s", path);
  46. #if defined USE_SDL
  47. data->chunk = Mix_LoadWAV(path);
  48. if (!data->chunk)
  49. {
  50. #if !LOL_RELEASE
  51. Log::Error("could not load %s\n", path);
  52. #endif
  53. SDL_Quit();
  54. exit(1);
  55. }
  56. #endif
  57. }
  58. Sample::~Sample()
  59. {
  60. #if defined USE_SDL
  61. Mix_FreeChunk(data->chunk);
  62. #endif
  63. free(data->name);
  64. delete data;
  65. }
  66. void Sample::TickGame(float deltams)
  67. {
  68. Entity::TickGame(deltams);
  69. }
  70. char const *Sample::GetName()
  71. {
  72. return data->name;
  73. }
  74. void Sample::Play()
  75. {
  76. #if defined USE_SDL
  77. Mix_PlayChannel(-1, data->chunk, 0);
  78. #endif
  79. }
  80. } /* namespace lol */