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

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

core: write a generic application class.

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