Hi. Inside js-dos project I have long living bug about mouse locking
that didn't work. Yesterday I tried to fix it again, and I faced
problem that emscripten pointer lock api does not work as expected.

I  used api in this way:

1) set callbacks:
    // register no-op callbacks for defered events
    emscripten_set_mousedown_callback("#canvas", NULL, false, [](int
eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) {
        return 0;
    });

    auto pointerLockChangeSet =
emscripten_set_pointerlockchange_callback("#canvas", NULL, false,
        [](int eventType, const EmscriptenPointerlockChangeEvent
*pointerlockChangeEvent, void *userData) -> EM_BOOL {
            printf("Received pointer lock change event\n");
            return true;
        }) == EMSCRIPTEN_RESULT_SUCCESS;
    printf("Pointerlock callback set\n");

2) ask for current pointer lock state:
    EmscriptenPointerlockChangeEvent lastChangeEvent;
    auto haveLockInfo =
emscripten_get_pointerlock_status(&lastChangeEvent) ==
EMSCRIPTEN_RESULT_SUCCESS;
    // use lastChangeEvent;

3) request for lock:
    auto lockRequested = emscripten_request_pointerlock("#canvas",
true) == EMSCRIPTEN_RESULT_DEFERRED;

Step 3) always return EMSCRIPTEN_RESULT_DEFERRED as expected and then
browser lock mouse
Step 2) always works correct,  every time when I asked for last state
of pointer lock then I recieve correct value (true when locked and
false when not).
In Step 1) pointerlockchange callback is set fine (I received
EMSCRIPTEN_RESULT_SUCCESS), but callback it self is never called. So I
need to ask about current status (step 2) periodically to get changes.

--
emcc (Emscripten gcc/clang-like replacement) 1.39.0 (commit
e047fe4c1ecfae6ba471ca43f2f630b79516706b)
https://github.com/caiiiycuk/js-dos/issues/63

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVFactEBzECFkWPy-YM%3Dv6yG1j9sTMSJFia65rANpCDwZw%40mail.gmail.com.

Reply via email to