VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /usr/share/emscripten/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/emscripten/tests/emscripten_api_browser.cpp
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<SDL.h>
#include<emscripten.h>
#include<assert.h>

int last = 0;

extern "C" {

bool pre1ed = false;
bool pre2ed = false;
void pre1(void *arg) {
  assert(!pre1ed);
  assert(!pre2ed);
  assert((int)arg == 123);
  pre1ed = true;
}
void pre2(void *arg) {
  assert(pre1ed);
  assert(!pre2ed);
  assert((int)arg == 98);
  pre2ed = true;
}

bool fived = false;
void five(void *arg) {
  assert((int)arg == 55);
  fived = true;
  emscripten_resume_main_loop();
}

void argey(void* arg) {
  static int counter = 0;
  assert((int)arg == 17);
  counter++;
  printf("argey: %d\n", counter);
  if (counter == 5) {
    emscripten_cancel_main_loop();
    int result = 1;
    REPORT_RESULT();
  }
}

void mainey() {
  static int counter = 0;
  printf("mainey: %d\n", counter++);
  if (counter == 20) {
    emscripten_pause_main_loop();
    emscripten_async_call(five, (void*)55, 1000);
  } else if (counter == 22) { // very soon after 20, so without pausing we fail
    assert(fived);
    emscripten_push_main_loop_blocker(pre1, (void*)123);
    emscripten_push_main_loop_blocker(pre2, (void*)98);
  } else if (counter == 23) {
    assert(pre1ed);
    assert(pre2ed);
    printf("Good!\n");
    emscripten_cancel_main_loop();
    emscripten_set_main_loop_arg(argey, (void*)17, 0, 0);
  }
}

void four(void *arg) {
  assert((int)arg == 43);
  printf("four!\n");
  emscripten_set_main_loop(mainey, 0, 0);
}

void __attribute__((used)) third() {
  int now = SDL_GetTicks();
  printf("thard! %d\n", now);
  assert(fabs(now - last - 1000) < 500);
  emscripten_async_call(four, (void*)43, -1); // triggers requestAnimationFrame
}

void second(void *arg) {
  int now = SDL_GetTicks();
  printf("sacond! %d\n", now);
  assert(fabs(now - last - 500) < 250);
  last = now;
  emscripten_async_run_script("Module._third()", 1000);
}

}

void never() {
  int result = 0;
  REPORT_RESULT();
}

int main() {
  SDL_Init(0);
  last = SDL_GetTicks();
  printf("frist! %d\n", last);

  atexit(never); // should never be called - it is wrong to exit the runtime orderly if we have async calls!

  emscripten_async_call(second, (void*)0, 500);

  return 1;
}


VaKeR 2022