/* Step the game simulation by handling events, and drawing: */ int game_step(void *input) { GameData *gd = input; ASSERT_ACTIVE(); EventType temp; /* Handle all queued events: */ while( (temp=gamelib_event_get_type()) != GAME_EVENT_NONE ) { /* Trying to resize the window? */ if(temp == GAME_EVENT_RESIZE) { Rect r = gamelib_event_resize_get_size(); screen_resize(gd->data.active.s, r.w, r.h); /* Trying to toggle fullscreen? */ } else if(temp == GAME_EVENT_TOGGLE_FULLSCREEN) { screen_set_fullscreen(gd->data.active.s, -1); /* Trying to exit? */ } else if(temp == GAME_EVENT_EXIT) { return 1; } /* Done with this event: */ gamelib_event_done(); } /* Clear everything: */ tanklist_map(gd->data.active.tl, tank_clear(t, gd->data.active.b)); plist_clear (gd->data.active.pl, gd->data.active.b); /* Charge a small bit of energy for life: */ tanklist_map(gd->data.active.tl, tank_alter_energy(t, TANK_IDLE_COST)); /* See if we need to be healed: */ tanklist_map(gd->data.active.tl, tank_try_base_heal(t)); /* Move everything: */ plist_step (gd->data.active.pl, gd->data.active.lvl, gd->data.active.tl); tanklist_map(gd->data.active.tl, tank_move(t, gd->data.active.tl)); /* Draw everything: */ plist_draw (gd->data.active.pl, gd->data.active.b); tanklist_map(gd->data.active.tl, tank_draw(t, gd->data.active.b)); screen_draw (gd->data.active.s); return 0; }
int main (int argc, char *argv[]) { const char *snapshot; atexit(shutdown_sdl); if (SDL_Init( #ifdef __EMSCRIPTEN__ // It seems there is an issue with emscripten SDL2: SDL_Init does not work if TIMER and/or HAPTIC is tried to be intialized or just "EVERYTHING" is used!! SDL_INIT_EVERYTHING & ~(SDL_INIT_TIMER | SDL_INIT_HAPTIC) #else SDL_INIT_EVERYTHING #endif ) != 0) { ERROR_WINDOW("Fatal SDL initialization problem: %s", SDL_GetError()); return 1; } if (config_init(argc, argv)) { #ifdef __EMSCRIPTEN__ ERROR_WINDOW("Error with config parsing. Please check the (javascript) console of your browser to learn about the error."); #endif return 1; } guarded_exit = 1; // turn on guarded exit, with custom de-init stuffs DEBUGPRINT("EMU: sleeping = \"%s\", timing = \"%s\"" NL, __SLEEP_METHOD_DESC, __TIMING_METHOD_DESC ); fileio_init( #ifdef __EMSCRIPTEN__ "/", #else app_pref_path, #endif "files"); if (screen_init()) return 1; if (xepgui_init()) return 1; audio_init(config_getopt_int("audio")); z80ex_init(); set_ep_cpu(CPU_Z80); ep_pixels = nick_init(); if (ep_pixels == NULL) return 1; snapshot = config_getopt_str("snapshot"); if (strcmp(snapshot, "none")) { if (ep128snap_load(snapshot)) snapshot = NULL; } else snapshot = NULL; if (!snapshot) { if (roms_load()) return 1; primo_rom_seg = primo_search_rom(); ep_set_ram_config(config_getopt_str("ram")); } mouse_setup(config_getopt_int("mousemode")); ep_reset(); kbd_matrix_reset(); joy_sdl_event(NULL); // this simply inits joy layer ... #ifdef CONFIG_SDEXT_SUPPORT if (!snapshot) sdext_init(); #endif #ifdef CONFIG_EXDOS_SUPPORT wd_exdos_reset(); wd_attach_disk_image(config_getopt_str("wdimg")); #endif #ifdef CONFIG_W5300_SUPPORT w5300_init(NULL); #endif ticks = SDL_GetTicks(); balancer = 0; set_cpu_clock(DEFAULT_CPU_CLOCK); emu_timekeeping_start(); audio_start(); if (config_getopt_int("fullscreen")) screen_set_fullscreen(1); DEBUGPRINT(NL "EMU: entering into main emulation loop" NL); sram_ready = 1; if (strcmp(config_getopt_str("primo"), "none") && !snapshot) { // TODO: da stuff ... primo_emulator_execute(); OSD("Primo Emulator Mode"); } if (snapshot) ep128snap_set_cpu_and_io(); console_monitor_ready(); // OK to run monitor on console now! #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(xep128_emulation, 50, 1); #else for (;;) xep128_emulation(); #endif printf("EXITING FROM main()?!" NL); return 0; }
static void __emu_one_frame(int rasters, int frameskip) { SDL_Event e; while (SDL_PollEvent(&e) != 0) switch (e.type) { case SDL_WINDOWEVENT: if (!is_fullscreen && e.window.event == SDL_WINDOWEVENT_RESIZED) { DEBUG("UI: Window is resized to %d x %d" NL, e.window.data1, e.window.data2 ); screen_window_resized(e.window.data1, e.window.data2); } break; case SDL_QUIT: if (QUESTION_WINDOW("?No|!Yes", "Are you sure to exit?") == 1) XEMUEXIT(0); return; case SDL_KEYDOWN: case SDL_KEYUP: if (e.key.repeat == 0 && (e.key.windowID == sdl_winid || e.key.windowID == 0)) { int code = emu_kbd(e.key.keysym, e.key.state == SDL_PRESSED); if (code == 0xF9) // // OSD REPLAY, default key GRAVE osd_replay(e.key.state == SDL_PRESSED ? 0 : OSD_FADE_START); else if (code && e.key.state == SDL_PRESSED) switch(code) { #ifndef __EMSCRIPTEN__ case 0xFF: // FULLSCREEN toogle, default key F11 screen_set_fullscreen(!is_fullscreen); break; case 0xFE: // EXIT, default key F9 if (QUESTION_WINDOW("?No|!Yes", "Are you sure to exit?") == 1) XEMUEXIT(0); break; case 0xFD: // SCREENSHOT, default key F10 screen_shot(ep_pixels, current_directory, "screenshot-*.png"); break; #endif case 0xFC: // RESET, default key PAUSE if (e.key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) { zxemu_on = 0; (void)ep_init_ram(); } ep_reset(); break; case 0xFB: // DOWNGRADE CPU SPEED, default key PAGE DOWN if (_cpu_speed_index) set_cpu_clock_with_osd(_cpu_speeds[-- _cpu_speed_index]); break; case 0xFA: // UPGRADE CPU SPEED, default key PAGE UP if (_cpu_speed_index < 3) set_cpu_clock_with_osd(_cpu_speeds[++ _cpu_speed_index]); break; case 0xF8: // CONSOLE, key pad minus if (!console_is_open) console_open_window(); break; } } else if (e.key.repeat == 0) DEBUG("UI: NOT HANDLED KEY EVENT: repeat = %d windowid = %d [our win = %d]" NL, e.key.repeat, e.key.windowID, sdl_winid); break; case SDL_MOUSEMOTION: if (e.motion.windowID == sdl_winid) emu_mouse_motion(e.motion.xrel, e.motion.yrel); break; case SDL_MOUSEWHEEL: if (e.wheel.windowID == sdl_winid) emu_mouse_wheel( e.wheel.x, e.wheel.y, e.wheel.direction == SDL_MOUSEWHEEL_FLIPPED ); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (e.button.windowID == sdl_winid) emu_mouse_button(e.button.button, e.button.state == SDL_PRESSED); break; default: joy_sdl_event(&e); break; } if (!frameskip) screen_present_frame(ep_pixels); // this should be after the event handler, as eg screenshot function needs locked texture state if this feature is used at all xepgui_iteration(); monitor_process_queued(); emu_timekeeping_delay((1000000.0 * rasters * 57.0) / (double)NICK_SLOTS_PER_SEC); }