Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is any way to hack emscripten_set_main_loop() and return back into main() after quiting of a loop? #6227

Closed
Wohlstand opened this issue Feb 11, 2018 · 9 comments

Comments

@Wohlstand
Copy link

Wohlstand commented Feb 11, 2018

As I see, using of emscripten_set_main_loop() I have no way to return back into main() function to change scene into another and start emscripten_set_main_loop() again, but on another function/class.

I thinking how to hack this as Emterpreter even looks good, but result works VERY slow and I have no idea how to correctly selectively interpret loop calls are in most of cases are members of scene classes (or I getting an error of linking, or result doesn't works properly).

I thinking about a way to hack emscripten_set_main_loop() and return back to main, as idea I have:

  • By any ASM or other way completely save a current state of a stack
  • Then begin emscripten_set_main_loop() which will kill the current state of a stack
  • On calcelling of main loop, restore the saved stack state and jump into it. But, skip the emscripten_set_main_loop() call as it is not needed.
    Then, in any next time, repeat same operation when beginning a process of a next scene.

Are you think it is possible to solve this?

P.S. As my game engine has sub-loops (as example, a message or other dialog box requested from a middle of code that does own control listening and a render of parent scene's state), I would think is to use Emterpreter or even disable support of child-boxes for Emscripten builds until I'll find a proper way to selectively interpret class-membered loop calls. I can't just use a regular function callbacks as there are must be friends and there are can't be "extern 'C'" without loss of private access.

@tbfleming
Copy link

restore the saved stack state

This is impossible in asm.js and in wasm without a system like emterpreter or asyncify.

can't just use a regular function callbacks as there are must be friends and there are can't be "extern 'C'" without loss of private access.

C++ lambda functions can act as callbacks, and can safely access private data.

@Wohlstand
Copy link
Author

Wohlstand commented Feb 11, 2018

This is impossible in asm.js and in wasm without a system like emterpreter or asyncify.

To use Empterpreter or Asyncify I need to correctly refere functions are has sleeps and loops, but to make that easier I need use extern "C", or try to guess it from object files generated by the compiler, etc.

can't just use a regular function callbacks as there are must be friends and there are can't be "extern 'C'" without loss of private access.

C++ lambda functions can act as callbacks, and can safely access private data.

I meant that I need to refer a function which a class member or friend independent C++ function in the EMPTERPRITY_WHITELIST to compile everything except of those functions to don't cause a lag of entire game. I have tried to refer some of functions, but result won't work correct...

@stale
Copy link

stale bot commented Sep 19, 2019

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Sep 19, 2019
@Wohlstand
Copy link
Author

About "Asyncify", I have missed that up... I have checked it out more and looks that what I needed, I need to check this in action... I should be able to run this:

int exec()
{
    struct State xxx;
    int running = 0, ret = 0;
    while(running)
    {
        doAnything1(xxx)
        doAnything2(xxx)
        ...
        renderEverything(xxx)
        waitSome(&ret);
        if(xxx.quit)
            running = 0;
    }
    return ret;
}

and I don't want to be forced use this:

static struct State xxx;
void runStep()
{
    doAnything1(xxx)
    doAnything2(xxx)
    ...
    renderEverything(xxx)
}

As in my engine, there are many cases of sub-loops are will cause stuck of the entire engine, for example, spawned message boxes are will run own loop inside self and will render parent scene's content and self above.

@stale stale bot removed the wontfix label Sep 19, 2019
@sbc100
Copy link
Collaborator

sbc100 commented Sep 19, 2019

I think Asyncify is the way to go if you want to keep you stack while yielding to the event loop.

Can you verify and close this issue if that works for you?

@Wohlstand
Copy link
Author

Wohlstand commented Sep 19, 2019

Yes, I'll close this issue once I'll solve my problem.

P.S. Thanks that bot who reminded me about this question, I forgot about this unsolved task, so, it's a time to finally solve it! 😁

@Wohlstand
Copy link
Author

Okay, right now I can't test the build because I have met this error #9317 , will re-try tomorrow...

@Wohlstand
Copy link
Author

Have found just now that #9317 is looking like has been fixed! 🦊 😄
Gonna re-test the thing today in the evening in my time zone...

@Wohlstand
Copy link
Author

Hello! Today I finally did a test, and I did some own side works to fix up my project to work with Emscripten WohlSoft/Moondust-Project@3c5acff
So, the problem has been finally solved! Thank you all for any given help and tips! 🦊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants