選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

129 行
2.8 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. #if defined __CELLOS_LV2__
  14. # include <sys/spu_initialize.h>
  15. # include <sys/paths.h> /* SYS_HOST_ROOT */
  16. # include <cell/sysmodule.h>
  17. # include <PSGL/psgl.h>
  18. #endif
  19. #include "core.h"
  20. #include "lolgl.h"
  21. #include "ps3app.h"
  22. namespace lol
  23. {
  24. /*
  25. * PS3 App implementation class
  26. */
  27. class Ps3AppData
  28. {
  29. friend class Ps3App;
  30. private:
  31. #if defined __CELLOS_LV2__
  32. static void SysCallBack(uint64_t status, uint64_t param, void *data)
  33. {
  34. if (status == CELL_SYSUTIL_REQUEST_EXITGAME)
  35. Ticker::Shutdown();
  36. }
  37. #endif
  38. };
  39. /*
  40. * Public Ps3App class
  41. */
  42. Ps3App::Ps3App(char const *title, vec2i res, float fps) :
  43. data(new Ps3AppData())
  44. {
  45. #if defined __CELLOS_LV2__
  46. sys_spu_initialize(6, 1);
  47. /* FIXME: we should check for CELL_SYSMODULE_ERROR_UNKNOWN and others,
  48. * but what could we do anyway? */
  49. cellSysmoduleLoadModule(CELL_SYSMODULE_GCM_SYS);
  50. cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
  51. cellSysmoduleLoadModule(CELL_SYSMODULE_USBD);
  52. cellSysmoduleLoadModule(CELL_SYSMODULE_IO);
  53. cellSysutilRegisterCallback(0, Ps3AppData::SysCallBack, NULL);
  54. PSGLinitOptions psglio =
  55. {
  56. enable: PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS
  57. | PSGL_INIT_HOST_MEMORY_SIZE,
  58. maxSPUs: 1,
  59. initializeSPUs: false,
  60. persistentMemorySize: 0,
  61. transientMemorySize: 0,
  62. errorConsole: 0,
  63. fifoSize: 0,
  64. hostMemorySize: 128 * 1024 * 1024,
  65. };
  66. psglInit(&psglio);
  67. PSGLdevice* psgl = psglCreateDeviceAuto(GL_ARGB_SCE, GL_DEPTH_COMPONENT24,
  68. GL_MULTISAMPLING_4X_SQUARE_ROTATED_SCE);
  69. GLuint w, h;
  70. psglGetDeviceDimensions(psgl, &w, &h);
  71. PSGLcontext *ctx = psglCreateContext();
  72. psglMakeCurrent(ctx, psgl);
  73. psglLoadShaderLibrary(REMOTE_PATH "/shaders.bin");
  74. psglResetCurrentContext();
  75. /* Initialise everything */
  76. Ticker::Setup(fps);
  77. Video::Setup(res);
  78. Audio::Setup(2);
  79. #endif
  80. }
  81. void Ps3App::Run()
  82. {
  83. while (!Ticker::Finished())
  84. {
  85. /* Tick the game */
  86. Ticker::TickGame();
  87. /* Tick the renderer, show the frame and clamp to desired framerate. */
  88. Ticker::TickDraw();
  89. #if defined __CELLOS_LV2__
  90. psglSwap();
  91. /* Check if exit callback was called */
  92. cellSysutilCheckCallback();
  93. #endif
  94. Ticker::ClampFps();
  95. }
  96. }
  97. Ps3App::~Ps3App()
  98. {
  99. #if defined __CELLOS_LV2__
  100. glFinish();
  101. #endif
  102. delete data;
  103. }
  104. } /* namespace lol */