cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

SDL_nacl_main.c (3072B)


      1/*
      2  Simple DirectMedia Layer
      3  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
      4
      5  This software is provided 'as-is', without any express or implied
      6  warranty.  In no event will the authors be held liable for any damages
      7  arising from the use of this software.
      8
      9  Permission is granted to anyone to use this software for any purpose,
     10  including commercial applications, and to alter it and redistribute it
     11  freely, subject to the following restrictions:
     12
     13  1. The origin of this software must not be misrepresented; you must not
     14     claim that you wrote the original software. If you use this software
     15     in a product, an acknowledgment in the product documentation would be
     16     appreciated but is not required.
     17  2. Altered source versions must be plainly marked as such, and must not be
     18     misrepresented as being the original software.
     19  3. This notice may not be removed or altered from any source distribution.
     20*/
     21#include "../../SDL_internal.h"
     22
     23#if SDL_VIDEO_DRIVER_NACL
     24
     25/* Include the SDL main definition header */
     26#include "SDL_main.h"
     27
     28#include "ppapi_simple/ps_main.h"
     29#include "ppapi_simple/ps_event.h"
     30#include "ppapi_simple/ps_interface.h"
     31#include "nacl_io/nacl_io.h"
     32#include "sys/mount.h"
     33
     34extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
     35
     36int
     37nacl_main(int argc, char *argv[])
     38{
     39    int status;
     40    PSEvent* ps_event;
     41    PP_Resource event;  
     42    struct PP_Rect rect;
     43    int ready = 0;
     44    const PPB_View *ppb_view = PSInterfaceView();
     45    
     46    /* This is started in a worker thread by ppapi_simple! */
     47    
     48    /* Wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before starting the app */
     49    
     50    PSEventSetFilter(PSE_INSTANCE_DIDCHANGEVIEW);
     51    while (!ready) {
     52        /* Process all waiting events without blocking */
     53        while (!ready && (ps_event = PSEventWaitAcquire()) != NULL) {
     54            event = ps_event->as_resource;
     55            switch(ps_event->type) {
     56                /* From DidChangeView, contains a view resource */
     57                case PSE_INSTANCE_DIDCHANGEVIEW:
     58                    ppb_view->GetRect(event, &rect);
     59                    NACL_SetScreenResolution(rect.size.width, rect.size.height, 0);
     60                    ready = 1;
     61                    break;
     62                default:
     63                    break;
     64            }
     65            PSEventRelease(ps_event);
     66        }
     67    }
     68    
     69    /* Do a default httpfs mount on /, 
     70     * apps can override this by unmounting / 
     71     * and remounting with the desired configuration
     72     */
     73    nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
     74    
     75    umount("/");
     76    mount(
     77        "",  /* source */
     78        "/",  /* target */
     79        "httpfs",  /* filesystemtype */
     80        0,  /* mountflags */
     81        "");  /* data specific to the html5fs type */
     82    
     83    /* Everything is ready, start the user main function */
     84    SDL_SetMainReady();
     85    status = SDL_main(argc, argv);
     86
     87    return 0;
     88}
     89
     90/* ppapi_simple will start nacl_main in a worker thread */
     91PPAPI_SIMPLE_REGISTER_MAIN(nacl_main);
     92
     93#endif /* SDL_VIDEO_DRIVER_NACL */