Ignore:
Timestamp:
Jun 4, 2012, 7:18:45 PM (11 years ago)
Author:
sam
Message:

nacl: preliminary gamepad support in the NaCl backend.

Location:
trunk/src/platform/nacl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/platform/nacl/nacl_instance.cpp

    r1435 r1439  
    5252static double const DELTA_MS = 1000.0 / 60.0;
    5353
    54 void TickCallback(void* data, int32_t result)
     54void NaClInstance::TickCallback(void* data, int32_t result)
    5555{
    5656    NaClInstance *instance = (NaClInstance *)data;
     
    6060    pp::Module::Get()->core()->CallOnMainThread(
    6161            DELTA_MS, pp::CompletionCallback(&TickCallback, data), PP_OK);
     62
     63    /* Propagate gamepad information */
     64    PP_GamepadsSampleData all_pads_data;
     65    instance->m_pad_interface->Sample(instance->pp_instance(), &all_pads_data);
     66
     67    for (int i = 0; i < all_pads_data.length; i++)
     68    {
     69        PP_GamepadSampleData const& pad_data = all_pads_data.items[i];
     70
     71        if (i >= instance->m_sticks.Count())
     72        {
     73            Stick *stick = Input::CreateStick();
     74            instance->m_sticks.Push(stick);
     75        }
     76
     77        instance->m_sticks[i]->SetAxisCount(pad_data.axes_length);
     78        for (int j = 0; j < pad_data.axes_length; j++)
     79            instance->m_sticks[i]->SetAxis(j, pad_data.axes[j]);
     80
     81        instance->m_sticks[i]->SetButtonCount(pad_data.buttons_length);
     82        for (int j = 0; j < pad_data.buttons_length; j++)
     83            instance->m_sticks[i]->SetButton(j, pad_data.buttons[j] > 0.5f);
     84    }
    6285}
    6386
     
    6689                        const char* argv[])
    6790{
    68     // My timer callback
    69     pp::Module::Get()->core()->CallOnMainThread(
    70             DELTA_MS, pp::CompletionCallback(&TickCallback, this), PP_OK);
     91    Ticker::Setup(60.0f);
    7192
    7293    /* Call the user's main() function. FIXME: run it in a thread */
     
    7697    lol_nacl_main(argc, const_cast<char **>(argv), (char **)env);
    7798
     99    // My timer callback
     100    pp::Module::Get()->core()->CallOnMainThread(
     101            DELTA_MS, pp::CompletionCallback(&TickCallback, this), PP_OK);
     102
     103    /* The gamepad interface */
     104    m_pad_interface = static_cast<PPB_Gamepad const *>(
     105            pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_INTERFACE));
     106
    78107    return true;
     108}
     109
     110void NaClInstance::RunMain(uint32_t argc,
     111                           const char* /* argn */[],
     112                           const char* argv[])
     113{
     114
    79115}
    80116
  • trunk/src/platform/nacl/nacl_instance.h

    r1435 r1439  
    66#define EXAMPLES_TUMBLER_TUMBLER_H_
    77
    8 #include <pthread.h>
    9 #include <map>
    10 #include <vector>
    11 
    128#include <ppapi/cpp/instance.h>
     9#include <ppapi/c/ppb_gamepad.h>
    1310
    1411#include "platform/nacl/opengl_context.h"
    1512#include "platform/nacl/opengl_context_ptrs.h"
     13
     14#include "input/input.h"
    1615
    1716namespace lol {
     
    4847
    4948private:
     49    static void TickCallback(void* data, int32_t result);
     50
    5051    static void CallIntMainWrappers(int argc, char const* argn[]);
    5152    static void CallVoidMainWrappers(int argc, char const* argn[]);
     53
     54    static void RunMain(uint32_t argc, const char* argn[], const char* argv[]);
     55
     56    /* Gamepad support */
     57    PPB_Gamepad const *m_pad_interface;
     58    Array<Stick *> m_sticks;
    5259};
    5360
Note: See TracChangeset for help on using the changeset viewer.