diff --git a/src/platform/nacl/nacl_instance.cpp b/src/platform/nacl/nacl_instance.cpp index de801733..fceb5670 100644 --- a/src/platform/nacl/nacl_instance.cpp +++ b/src/platform/nacl/nacl_instance.cpp @@ -51,7 +51,7 @@ NaClInstance::~NaClInstance() static double const DELTA_MS = 1000.0 / 60.0; -void TickCallback(void* data, int32_t result) +void NaClInstance::TickCallback(void* data, int32_t result) { NaClInstance *instance = (NaClInstance *)data; instance->DrawSelf(); @@ -59,15 +59,36 @@ void TickCallback(void* data, int32_t result) /* FIXME: only set if if Ticker isn't finished */ pp::Module::Get()->core()->CallOnMainThread( DELTA_MS, pp::CompletionCallback(&TickCallback, data), PP_OK); + + /* Propagate gamepad information */ + PP_GamepadsSampleData all_pads_data; + instance->m_pad_interface->Sample(instance->pp_instance(), &all_pads_data); + + for (int i = 0; i < all_pads_data.length; i++) + { + PP_GamepadSampleData const& pad_data = all_pads_data.items[i]; + + if (i >= instance->m_sticks.Count()) + { + Stick *stick = Input::CreateStick(); + instance->m_sticks.Push(stick); + } + + instance->m_sticks[i]->SetAxisCount(pad_data.axes_length); + for (int j = 0; j < pad_data.axes_length; j++) + instance->m_sticks[i]->SetAxis(j, pad_data.axes[j]); + + instance->m_sticks[i]->SetButtonCount(pad_data.buttons_length); + for (int j = 0; j < pad_data.buttons_length; j++) + instance->m_sticks[i]->SetButton(j, pad_data.buttons[j] > 0.5f); + } } bool NaClInstance::Init(uint32_t argc, const char* /* argn */[], const char* argv[]) { - // My timer callback - pp::Module::Get()->core()->CallOnMainThread( - DELTA_MS, pp::CompletionCallback(&TickCallback, this), PP_OK); + Ticker::Setup(60.0f); /* Call the user's main() function. FIXME: run it in a thread */ char *env[] = { NULL }; @@ -75,9 +96,24 @@ bool NaClInstance::Init(uint32_t argc, lol_nacl_main(argc, const_cast(argv)); lol_nacl_main(argc, const_cast(argv), (char **)env); + // My timer callback + pp::Module::Get()->core()->CallOnMainThread( + DELTA_MS, pp::CompletionCallback(&TickCallback, this), PP_OK); + + /* The gamepad interface */ + m_pad_interface = static_cast( + pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_INTERFACE)); + return true; } +void NaClInstance::RunMain(uint32_t argc, + const char* /* argn */[], + const char* argv[]) +{ + +} + void NaClInstance::HandleMessage(const pp::Var& message) { if (!message.is_string()) diff --git a/src/platform/nacl/nacl_instance.h b/src/platform/nacl/nacl_instance.h index 0d1a3f20..420138d2 100644 --- a/src/platform/nacl/nacl_instance.h +++ b/src/platform/nacl/nacl_instance.h @@ -5,15 +5,14 @@ #ifndef EXAMPLES_TUMBLER_TUMBLER_H_ #define EXAMPLES_TUMBLER_TUMBLER_H_ -#include -#include -#include - #include +#include #include "platform/nacl/opengl_context.h" #include "platform/nacl/opengl_context_ptrs.h" +#include "input/input.h" + namespace lol { class NaClInstance : public pp::Instance { @@ -47,8 +46,16 @@ class NaClInstance : public pp::Instance { ivec2 m_size; private: + static void TickCallback(void* data, int32_t result); + static void CallIntMainWrappers(int argc, char const* argn[]); static void CallVoidMainWrappers(int argc, char const* argn[]); + + static void RunMain(uint32_t argc, const char* argn[], const char* argv[]); + + /* Gamepad support */ + PPB_Gamepad const *m_pad_interface; + Array m_sticks; }; } // namespace lol