25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

112 satır
1.9 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 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://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdlib>
  14. #include <cstdio>
  15. #include <cstring>
  16. #if defined USE_SDL_MIXER
  17. # if defined HAVE_SDL_SDL_H
  18. # include <SDL/SDL.h>
  19. # else
  20. # include <SDL.h>
  21. # endif
  22. # if defined HAVE_SDL_SDL_MIXER_H
  23. # include <SDL/SDL_mixer.h>
  24. # else
  25. # include <SDL_mixer.h>
  26. # endif
  27. #endif
  28. #include "core.h"
  29. using namespace std;
  30. namespace lol
  31. {
  32. /*
  33. * Sample implementation class
  34. */
  35. class SampleData
  36. {
  37. friend class Sample;
  38. private:
  39. char *name, *path;
  40. #if defined USE_SDL_MIXER
  41. Mix_Chunk *chunk;
  42. #endif
  43. };
  44. /*
  45. * Public Sample class
  46. */
  47. Sample::Sample(char const *path)
  48. : data(new SampleData())
  49. {
  50. data->name = (char *)malloc(9 + strlen(path) + 1);
  51. data->path = data->name + 9;
  52. sprintf(data->name, "<sample> %s", path);
  53. #if defined USE_SDL_MIXER
  54. Array<String> pathlist = System::GetPathList(path);
  55. for (int i = 0; i < pathlist.Count(); ++i)
  56. {
  57. data->chunk = Mix_LoadWAV(pathlist[0].C());
  58. if (data->chunk)
  59. break;
  60. }
  61. if (!data->chunk)
  62. {
  63. #if !LOL_RELEASE
  64. Log::Error("could not load sample %s\n", path);
  65. #endif
  66. SDL_Quit();
  67. exit(1);
  68. }
  69. #endif
  70. }
  71. Sample::~Sample()
  72. {
  73. #if defined USE_SDL_MIXER
  74. Mix_FreeChunk(data->chunk);
  75. #endif
  76. free(data->name);
  77. delete data;
  78. }
  79. void Sample::TickGame(float seconds)
  80. {
  81. Entity::TickGame(seconds);
  82. }
  83. char const *Sample::GetName()
  84. {
  85. return data->name;
  86. }
  87. void Sample::Play()
  88. {
  89. #if defined USE_SDL_MIXER
  90. Mix_PlayChannel(-1, data->chunk, 0);
  91. #endif
  92. }
  93. } /* namespace lol */