aorecomp

Anarchy Online classic in the browser

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


client/tests/browser_loop.c (1921B)


      1 #include "browser_loop.h"
      2 #include "recomp_types.h"
      3 #include "guest_memory.h"
      4 #include <assert.h>
      5 #include <math.h>
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 #include <emscripten/threading.h>
      9 
     10 static unsigned ticks, frames, completed, closed;
     11 
     12 int browser_graphics_ready(void)
     13 {
     14     ++ticks;
     15     return ticks != 2;
     16 }
     17 
     18 void ao_frame_begin(double timestamp)
     19 {
     20     static double previous;
     21     assert(isfinite(timestamp) && (ticks == 1 || timestamp >= previous));
     22     previous = timestamp;
     23 }
     24 void ao_frame_complete(void) { ++completed; }
     25 void browser_test_frame(void) { assert(frames == completed + 1); }
     26 void browser_touch_frame_complete(void) { assert(frames == completed + 1); }
     27 void ao_game_closed(void) { ++closed; }
     28 void browser_select_character(unsigned character_id)
     29 {
     30     assert(character_id == (frames < 2 ? 0 : 42));
     31 }
     32 
     33 void sub_28002DA0(void)
     34 {
     35     assert(g_ebx == 0x50001000 && g_ebp == 0x5000fe00 && g_esp == 0x5000fd00);
     36     assert(g_esi == 0x5000101c);
     37     if (frames == 3) {
     38         browser_client_stopping = 1;
     39         g_esp = 0x5000ff00;
     40         g_ebp = 0x12345678;
     41         return;
     42     }
     43     assert(ticks == 1 || ticks == 3 || ticks == 4);
     44     ++frames;
     45     if (frames == 2) MEM32(0x2f01f008) = 42;
     46 }
     47 
     48 void sub_28001000(void)
     49 {
     50     assert(browser_client_stopping && g_esp == 0x5000ff00 && g_ebp == 0x12345678);
     51     g_ebp = 0x23456789;
     52 }
     53 
     54 void sub_28005684(void)
     55 {
     56     assert(g_ebp == 0x23456789);
     57     assert(frames == 3 && completed == 3 && ticks == 5 && closed == 1);
     58     puts("PASS: browser callbacks preserve guest frames, skip lost graphics and resume shutdown without JSPI");
     59     exit(0);
     60 }
     61 
     62 int main(void)
     63 {
     64     assert(!emscripten_is_main_browser_thread());
     65     assert(guest_map("browser loop fixture", 0x50000000, 0x10000));
     66     assert(guest_map("FFR character identity", 0x2f010000, 0x10000));
     67     g_ebx = 0x50001000;
     68     g_esp = 0x5000fd00;
     69     g_ebp = 0x5000fe00;
     70 
     71     browser_start_frame_loop();
     72 }