aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


client/runtime/browser_loop.c (1651B)


      1 #include "browser_loop.h"
      2 #include "recomp_types.h"
      3 #include <assert.h>
      4 #include <emscripten.h>
      5 #include <emscripten/html5.h>
      6 
      7 int browser_client_stopping;
      8 static uint32_t client_object, loop_stack, loop_frame;
      9 void ao_frame_complete(void);
     10 void ao_frame_begin(double timestamp);
     11 void ao_game_closed(void);
     12 void browser_test_frame(void);
     13 void browser_touch_frame_complete(void);
     14 void browser_select_character(unsigned character_id);
     15 int browser_graphics_ready(void);
     16 void sub_28002DA0(void);
     17 void sub_28001000(void);
     18 void sub_28005684(void);
     19 
     20 static bool browser_frame(double timestamp, void *argument)
     21 {
     22     (void)argument;
     23     if (!browser_graphics_ready()) return true;
     24     ao_frame_begin(timestamp);
     25     g_esp = loop_stack;
     26     g_ebp = loop_frame;
     27     g_ebx = client_object;
     28     g_esi = client_object + 0x1c;
     29 
     30     /* The original message loop returns after one frame, or completes its quit epilogue. */
     31     sub_28002DA0();
     32     if (browser_client_stopping) {
     33         sub_28001000();
     34         ao_game_closed();
     35         sub_28005684();
     36         return false;
     37     }
     38     assert(g_esp == loop_stack);
     39     /* FFR s_nCharID changes when the creator accepts the server's new identity. */
     40     browser_select_character(MEM32(0x2f01f008));
     41     browser_test_frame();
     42     browser_touch_frame_complete();
     43     ao_frame_complete();
     44     return true;
     45 }
     46 
     47 void browser_start_frame_loop(void)
     48 {
     49     /* Guest startup locals remain in linear memory; no host call frame survives a tick. */
     50     client_object = g_ebx;
     51     loop_stack = g_esp;
     52     loop_frame = g_ebp;
     53     emscripten_request_animation_frame_loop(browser_frame, NULL);
     54     emscripten_exit_with_live_runtime();
     55 }