Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

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