source: trunk/src/ps3app.cpp @ 840

Last change on this file since 840 was 840, checked in by sam, 10 years ago

ps3: add a build-ps3 script that uses autoconf and automake.

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, vec2i 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 = vec2i(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#endif
106}
107
108void Ps3App::Run()
109{
110    while (!Ticker::Finished())
111    {
112        /* Tick the game */
113        Ticker::TickGame();
114
115        /* Tick the renderer, show the frame and clamp to desired framerate. */
116        Ticker::TickDraw();
117
118#if defined __CELLOS_LV2__
119        psglSwap();
120
121        /* Check if exit callback was called */
122        cellSysutilCheckCallback();
123#endif
124
125        Ticker::ClampFps();
126    }
127}
128
129Ps3App::~Ps3App()
130{
131#if defined __CELLOS_LV2__
132    glFinish();
133#endif
134    delete data;
135}
136
137} /* namespace lol */
138
Note: See TracBrowser for help on using the repository browser.