source: trunk/src/platform/ps3/ps3app.cpp @ 1063

Last change on this file since 1063 was 1063, checked in by sam, 12 years ago

core: implement Application::ShowPointer() so that applications can choose
whether to use the system mouse pointer or not.

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