LynarMoon.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * author: Patrick-Christopher Mattulat
  3. * dev-tools: JetBrains CLion
  4. * created: 10.08.2018
  5. * last updated: 19.10.2018
  6. */
  7. #ifndef LYNARMOON_H
  8. #define LYNARMOON_H
  9. #define SDL_MAIN_HANDLED
  10. #include <string>
  11. #include <vector>
  12. #include <memory>
  13. #include <atomic>
  14. #include <map>
  15. #include "../tools/File/LogFileHandler.h"
  16. #include "Error/ErrorHandler.h"
  17. #include "../tools/ThreadSafety/ThreadSafeSharedPtr.h"
  18. #include "Module/Mouse/MouseModule.h"
  19. #include "../tools/Color/Color.h"
  20. #include "../tools/List/SmartList.h"
  21. #include "Module/TimeEvent/TimeEventModule.h"
  22. #include "Module/Sound/SoundModule.h"
  23. #include "Module/Music/MusicModule.h"
  24. #include "Module/Keyboard/KeyboardModule.h"
  25. #include "Module/Font/FontModule.h"
  26. #include "Module/Line/LineModule.h"
  27. #include "Zindex/Zindex.h"
  28. #include "Module/Point/PointModule.h"
  29. #include "Module/Text/TextModule.h"
  30. #include "Module/Model/ModelModule.h"
  31. #include "SetUp/SetUp.h"
  32. class LynarMoon
  33. {
  34. private:
  35. class FontLayer
  36. {
  37. private:
  38. std::shared_ptr<ErrorHandler> errorHandler;
  39. std::string objectName;
  40. LynarMoon* parent;
  41. std::shared_ptr<SmartList<FontModule>> FontList;
  42. public:
  43. explicit FontLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  44. ~FontLayer();
  45. void clear();
  46. int create(uint32_t, const std::string&, double);
  47. uint32_t getAmount();
  48. double getSize(uint32_t);
  49. int getStyle(uint32_t);
  50. int remove(uint32_t);
  51. int setStyle(uint32_t, int);
  52. };
  53. class LineLayer
  54. {
  55. private:
  56. std::shared_ptr<ErrorHandler> errorHandler;
  57. std::string objectName;
  58. LynarMoon* parent;
  59. std::shared_ptr<SmartList<LineModule>> LineList;
  60. public:
  61. explicit LineLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  62. ~LineLayer();
  63. void clear();
  64. int create(uint32_t);
  65. LynarMath::_Line_d get(uint32_t);
  66. uint32_t getAmount();
  67. _ColorValue_d getColor(uint32_t);
  68. uint32_t getZindex(uint32_t);
  69. bool isVisible(uint32_t);
  70. int makeVisible(uint32_t, bool);
  71. int remove(uint32_t);
  72. int set(uint32_t, LynarMath::_Line_d);
  73. int setColor(uint32_t, _ColorValue_d);
  74. int setZindex(uint32_t, uint32_t);
  75. };
  76. class ModelLayer
  77. {
  78. private:
  79. std::shared_ptr<ErrorHandler> errorHandler;
  80. std::string objectName;
  81. LynarMoon* parent;
  82. std::shared_ptr<SmartList<ModelModule>> ModelList;
  83. public:
  84. explicit ModelLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  85. ~ModelLayer();
  86. int addClone(uint32_t, uint32_t);
  87. int addDirection(uint32_t, uint32_t, LynarMath::_Vec2_d);
  88. int addTexture(uint32_t, uint32_t, const std::string&);
  89. int addTexture(uint32_t, uint32_t, SDL_Surface*);
  90. int addTexturePartialArea(uint32_t, uint32_t, uint32_t, LynarMath::_Rectangle_d);
  91. int changeDirection(uint32_t, uint32_t, LynarMath::_Vec2_d);
  92. int changeTexturePartialArea(uint32_t, uint32_t, uint32_t, LynarMath::_Rectangle_d);
  93. void clear();
  94. int clearDirections(uint32_t);
  95. int clearTextures(uint32_t);
  96. int colorOperation(uint32_t, uint32_t, _ColorValue_d, uint8_t);
  97. int create(uint32_t);
  98. int focusTexturePartialArea(uint32_t, uint32_t, uint32_t);
  99. uint32_t getAmount();
  100. uint32_t getAmountOfClones(uint32_t);
  101. uint32_t getAmountOfDirections(uint32_t);
  102. uint32_t getAmountOfTexturePartialAreas(uint32_t, uint32_t);
  103. uint32_t getAmountOfTextures(uint32_t);
  104. double getAngle(uint32_t);
  105. ModelCloneRendererInfo getCloneRendererInfo(uint32_t, uint32_t);
  106. LynarMath::_Vec2_d getDirection(uint32_t, uint32_t);
  107. LynarMath::_Point_d getPosition(uint32_t);
  108. LynarMath::_Point_d getSize(uint32_t);
  109. double getSizeFactor(uint32_t);
  110. LynarMath::_Rectangle_d getTexturePartialArea(uint32_t, uint32_t, uint32_t);
  111. LynarMath::_Point_d getTexturePosition(uint32_t, uint32_t);
  112. uint32_t getTextureZindex(uint32_t, uint32_t);
  113. uint32_t getZindex(uint32_t);
  114. bool isTextureVisible(uint32_t, uint32_t);
  115. bool isVisible(uint32_t);
  116. int makeTextureVisible(uint32_t, uint32_t, bool);
  117. int makeVisible(uint32_t, bool);
  118. int moveInDirection(uint32_t, uint32_t);
  119. int remove(uint32_t);
  120. int removeClone(uint32_t, uint32_t);
  121. int removeDirection(uint32_t, uint32_t);
  122. int removeTexturePartialArea(uint32_t, uint32_t, uint32_t);
  123. int removeTexture(uint32_t, uint32_t);
  124. int setAngle(uint32_t, double);
  125. int setCloneRendererInfo(uint32_t, uint32_t, ModelCloneRendererInfo);
  126. int setPosition(uint32_t, LynarMath::_Point_d);
  127. int setSize(uint32_t, LynarMath::_Point_d);
  128. int setSizeFactor(uint32_t, double);
  129. int setTexturePosition(uint32_t, uint32_t, LynarMath::_Point_d);
  130. int setTextureZindex(uint32_t, uint32_t, uint32_t);
  131. int setZindex(uint32_t, uint32_t);
  132. };
  133. class MusicLayer
  134. {
  135. private:
  136. std::shared_ptr<ErrorHandler> errorHandler;
  137. std::string objectName;
  138. LynarMoon* parent;
  139. SmartList<MusicModule> MusicList;
  140. public:
  141. explicit MusicLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  142. ~MusicLayer();
  143. void clear();
  144. int create(uint32_t);
  145. int fadeIn(uint32_t, int);
  146. int fadeOut(uint32_t, int);
  147. uint32_t getAmount();
  148. uint8_t getVolume(uint32_t);
  149. bool isLocked(uint32_t);
  150. bool isPaused(uint32_t);
  151. bool isPlaying(uint32_t);
  152. int load(uint32_t, const std::string&);
  153. int lock(uint32_t, bool);
  154. int pause(uint32_t);
  155. int play(uint32_t, int);
  156. int remove(uint32_t);
  157. int resume(uint32_t);
  158. int setVolume(uint32_t, uint8_t);
  159. };
  160. class PointLayer
  161. {
  162. private:
  163. std::shared_ptr<ErrorHandler> errorHandler;
  164. std::string objectName;
  165. LynarMoon* parent;
  166. std::shared_ptr<SmartList<PointModule>> PointList;
  167. public:
  168. explicit PointLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  169. ~PointLayer();
  170. int addDirection(uint32_t, uint32_t, LynarMath::_Vec2_d);
  171. int changeDirection(uint32_t, uint32_t, LynarMath::_Vec2_d);
  172. void clear();
  173. int clearDirections(uint32_t);
  174. int create(uint32_t);
  175. LynarMath::_Point_d get(uint32_t);
  176. uint32_t getAmount();
  177. uint32_t getAmountOfDirections(uint32_t);
  178. _ColorValue_d getColor(uint32_t);
  179. LynarMath::_Vec2_d getDirection(uint32_t, uint32_t);
  180. uint32_t getZindex(uint32_t);
  181. bool isVisible(uint32_t);
  182. int makeVisible(uint32_t, bool);
  183. int remove(uint32_t);
  184. int removeDirection(uint32_t, uint32_t);
  185. int set(uint32_t, LynarMath::_Point_d);
  186. int setColor(uint32_t, _ColorValue_d);
  187. int setZindex(uint32_t, uint32_t);
  188. };
  189. class SoundLayer
  190. {
  191. private:
  192. std::shared_ptr<ErrorHandler> errorHandler;
  193. std::string objectName;
  194. LynarMoon* parent;
  195. SmartList<SoundModule> SoundList;
  196. public:
  197. explicit SoundLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  198. ~SoundLayer();
  199. void clear();
  200. int create(uint32_t);
  201. int fadeIn(uint32_t, int);
  202. int fadeOut(uint32_t, int);
  203. uint32_t getAmount();
  204. uint8_t getVolume(uint32_t);
  205. bool isLocked(uint32_t);
  206. bool isPaused(uint32_t);
  207. bool isPlaying(uint32_t);
  208. int load(uint32_t, const std::string&);
  209. int lock(uint32_t, bool);
  210. int pause(uint32_t);
  211. int play(uint32_t, int);
  212. int remove(uint32_t);
  213. int resume(uint32_t);
  214. int setVolume(uint32_t, uint8_t);
  215. };
  216. class TextLayer
  217. {
  218. private:
  219. std::shared_ptr<ErrorHandler> errorHandler;
  220. std::string objectName;
  221. LynarMoon* parent;
  222. std::shared_ptr<SmartList<TextModule>> TextList;
  223. public:
  224. explicit TextLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  225. ~TextLayer();
  226. int addDirection(uint32_t, uint32_t, LynarMath::_Vec2_d);
  227. int changeDirection(uint32_t, uint32_t, LynarMath::_Vec2_d);
  228. void clear();
  229. int clearDirections(uint32_t);
  230. int colorOperation(uint32_t, _ColorValue_d, uint8_t);
  231. int create(uint32_t);
  232. std::string get(uint32_t);
  233. uint32_t getAmount();
  234. uint32_t getAmountOfDirections(uint32_t);
  235. _ColorValue_d getColor(uint32_t);
  236. LynarMath::_Vec2_d getDirection(uint32_t, uint32_t);
  237. LynarMath::_Point_d getPosition(uint32_t);
  238. LynarMath::_Point_d getSize(uint32_t);
  239. double getSizeFactor(uint32_t);
  240. uint32_t getZindex(uint32_t);
  241. bool isVisible(uint32_t);
  242. int makeVisible(uint32_t, bool);
  243. int relateFont(uint32_t, uint32_t);
  244. int remove(uint32_t);
  245. int removeDirection(uint32_t, uint32_t);
  246. int set(uint32_t, const std::string&);
  247. int setColor(uint32_t, _ColorValue_d);
  248. int setPosition(uint32_t, LynarMath::_Point_d);
  249. int setSizeFactor(uint32_t, double);
  250. int setZindex(uint32_t, uint32_t);
  251. };
  252. class TimeEventLayer
  253. {
  254. private:
  255. std::shared_ptr<ErrorHandler> errorHandler;
  256. std::string objectName;
  257. LynarMoon* parent;
  258. SmartList<TimeEventModule> TimeEventList;
  259. public:
  260. explicit TimeEventLayer(LynarMoon* lm, const std::string&, std::shared_ptr<ErrorHandler>&);
  261. ~TimeEventLayer();
  262. void clear();
  263. int create(uint32_t);
  264. uint32_t getAmount();
  265. uint32_t getTimestamp(uint32_t);
  266. bool reached(uint32_t);
  267. int remove(uint32_t);
  268. int set(uint32_t, uint32_t);
  269. int update(uint32_t, uint32_t);
  270. };
  271. class Window
  272. {
  273. private:
  274. std::string appName;
  275. std::atomic<SDL_DisplayMode> displayMode;
  276. std::shared_ptr<ErrorHandler> errorHandler;
  277. ThreadSafeSharedPtr<SDL_Window> window;
  278. int initDisplayMode();
  279. public:
  280. Window();
  281. explicit Window(const std::string&, std::shared_ptr<ErrorHandler>&);
  282. ~Window();
  283. int create();
  284. SDL_DisplayMode getDisplayMode();
  285. std::shared_ptr<SDL_Window> getWindowHandle();
  286. };
  287. // members
  288. std::string appName;
  289. _ColorValue_d backgroundColor;
  290. std::shared_ptr<ErrorHandler> errorHandler;
  291. SDL_Event event;
  292. std::shared_ptr<SmartList<FontModule>> fontModuleList;
  293. std::atomic<uint32_t> fps;
  294. std::atomic<bool> initialized;
  295. std::atomic<bool> initializedIMG;
  296. std::atomic<bool> initializedSound;
  297. std::atomic<bool> initializedTTF;
  298. std::shared_ptr<SmartList<LineModule>> lineModuleList;
  299. std::string logFileName;
  300. std::shared_ptr<SmartList<ModelModule>> modelModuleList;
  301. std::atomic<uint32_t> numberOfSoundChannels;
  302. std::atomic<uint8_t> operatingSystem;
  303. std::shared_ptr<SmartList<PointModule>> pointModuleList;
  304. std::string prefPath;
  305. std::shared_ptr<SDL_Renderer> renderer;
  306. SetUp setup;
  307. std::shared_ptr<SmartList<TextModule>> textModuleList;
  308. std::atomic<uint32_t> timestamp;
  309. std::atomic<double> timestep;
  310. std::shared_ptr<Window> window;
  311. Zindex zindexHandler;
  312. void createPreferencePath();
  313. int drawLineModule(std::shared_ptr<LineModule>&);
  314. int drawModelModule(std::shared_ptr<ModelModule>&);
  315. int drawModelModuleClones(std::shared_ptr<ModelModule>&);
  316. int drawModelModuleOriginal(std::shared_ptr<ModelModule>&);
  317. int drawPointModule(std::shared_ptr<PointModule>&);
  318. int drawTextModule(std::shared_ptr<TextModule>&);
  319. int drawModules();
  320. void initModules();
  321. int initRenderer();
  322. int initSDL();
  323. int writeVersion();
  324. public:
  325. LynarMoon();
  326. ~LynarMoon();
  327. void beginFrame();
  328. void delay(uint32_t);
  329. int drawFrame();
  330. void endFrame();
  331. uint32_t getAmountOfSoundChannels();
  332. const std::string getAppName();
  333. _ColorValue_d getBackgroundColor();
  334. uint32_t getFps();
  335. int getMaxFrameRate();
  336. const std::string getPrefPath();
  337. int getScreenHeight();
  338. int getScreenWidth();
  339. uint32_t getTimestamp();
  340. double getTimestep();
  341. int init(std::string);
  342. int initIMG();
  343. int initSound(uint32_t);
  344. int initTTF();
  345. int pollEvent();
  346. void setBackgroundColor(_ColorValue_d);
  347. int showCursor(bool);
  348. double step(double);
  349. // modules
  350. std::shared_ptr<FontLayer> Font;
  351. std::shared_ptr<KeyboardModule> Keyboard;
  352. std::shared_ptr<LineLayer> Line;
  353. std::shared_ptr<ModelLayer> Model;
  354. std::shared_ptr<MouseModule> Mouse;
  355. std::shared_ptr<MusicLayer> Music;
  356. std::shared_ptr<PointLayer> Point;
  357. std::shared_ptr<SoundLayer> Sound;
  358. std::shared_ptr<TextLayer> Text;
  359. std::shared_ptr<TimeEventLayer> TimeEvent;
  360. };
  361. #endif