void link(void) { int ret = modbus_io(&modbus); if (ret == MODBUS_SUCCESS) { // OK } update_inputs(); OS::sleep(LINK_PERIOD_MS); }
FUNCTION PUBLIC DEFINITION void POST_updateWidgetValues ( const widget* w, const sessionWidgets_t*, Buffer_t& buf, bool no_events ) { Str_t utf8; if (w->Type == INPUT || w->Type == INPUT_DATE) { update_inputs(w, buf, no_events); } else if (w->Type == BUTTON) { update_buttons(w, buf, no_events); } else if (w->Type == GRID) { update_grid(w, buf, no_events); } else if (w->Type == FILEEXPLORER) { update_fileexplorer(w, buf, no_events); } else if (w->Type == LISTBOX) { update_listbox(w, buf); } else if (w->Type == CHECKBOXGROUP) { update_checkboxGroup(w, buf); } else if (w->Type == TEXTAREA) { update_textArea(w, buf, no_events); } if (w->Visible == true) buf << utl::Stringf(cjs::set_show, w->Uuid); else if (w->Visible == false) buf << utl::Stringf(cjs::set_hide, w->Uuid); if (w->Disable == true) buf << utl::Stringf(cjs::set_disable, w->Uuid); else if (w->Disable == false) buf << utl::Stringf(cjs::set_enable, w->Uuid); }
FUNCTION PUBLIC DEFINITION void PRE_updateWidgetValues ( const widget* w, Buffer_t& buf, bool no_events ) { // Se inicializan sus valores por defecto if (w->Type == INPUT || w->Type == INPUT_DATE) { update_inputs(w, buf, no_events); } else if (w->Type == BUTTON) { update_buttons(w, buf, no_events); } else if (w->Type == FILEEXPLORER) { update_fileexplorer(w, buf, no_events); } else if (w->Type == LISTBOX) { update_listbox(w, buf); } else if (w->Type == CHECKBOXGROUP) { update_checkboxGroup(w, buf); } else if (w->Type == TEXTAREA) { update_textArea(w, buf, no_events); } if (w->Visible == true) buf << utl::Stringf(cjs::set_show, w->Uuid); else if (w->Visible == false) buf << utl::Stringf(cjs::set_hide, w->Uuid); if (w->Disable == true) buf << utl::Stringf(cjs::set_disable, w->Uuid); else if (w->Disable == false) buf << utl::Stringf(cjs::set_enable, w->Uuid); }
const netlist_time matrix_solver_t::solve() { const netlist_time now = netlist().time(); const netlist_time delta = now - m_last_step; // We are already up to date. Avoid oscillations. // FIXME: Make this a parameter! if (delta < netlist_time::quantum()) return netlist_time::zero(); /* update all terminals for new time step */ m_last_step = now; step(delta); solve_base(); const netlist_time next_time_step = compute_next_timestep(delta.as_double()); update_inputs(); return next_time_step; }
netlist_time matrix_solver_t::solve() { const netlist_time now = netlist().time(); const netlist_time delta = now - m_last_step; // We are already up to date. Avoid oscillations. // FIXME: Make this a parameter! if (delta < netlist_time::from_nsec(1)) // 20000 return netlist_time::from_nsec(0); /* update all terminals for new time step */ m_last_step = now; m_cur_ts = delta.as_double(); step(delta); const netlist_time next_time_step = solve_base(); update_inputs(); return next_time_step; }
void update_and_render(Memory *memory, GameState *game_state, FrameBuffer *frame_buffer, Keys *keys, Mouse *mouse, u64 time_us, u32 last_frame_dt, u32 fps , u32 argc, char *argv[]) { if (!game_state->init) { init_render_segments(memory, game_state, frame_buffer); init_game(memory, game_state, keys, time_us, argc, argv); load_maze(memory, game_state, argc, argv); reset_zoom(game_state); } update_inputs(keys, &game_state->inputs, time_us); if (game_state->inputs.maps[SAVE].active) { serialize_maze(&game_state->maze, &game_state->functions, game_state->filename); } if (game_state->inputs.maps[RELOAD].active) { strcpy(game_state->persistent_str, "Reload!"); load_maze(memory, game_state, argc, argv); } if (game_state->inputs.maps[RESET].active) { strcpy(game_state->persistent_str, "Reset!"); reset_zoom(game_state); } if (game_state->inputs.maps[RESTART].active) { strcpy(game_state->persistent_str, "Restart!"); delete_all_cars(&game_state->cars); reset_car_inputs(&game_state->ui); game_state->finish_sim_step_move = false; game_state->last_sim_tick = 0; game_state->sim_steps = 0; } if (game_state->inputs.maps[STEP_MODE_TOGGLE].active) { game_state->single_step = !game_state->single_step; log(L_GameLoop, "Changing stepping mode"); } // // UPDATE VIEW // update_pan_and_zoom(game_state, mouse); RenderBasis render_basis; render_basis.world_per_pixel = game_state->world_per_pixel; render_basis.scale = squared(game_state->zoom / 30.0f); render_basis.scale_focus = game_state->scale_focus; render_basis.origin = game_state->maze_pos * game_state->world_per_pixel; render_basis.clip_region = game_state->world_render_region * game_state->world_per_pixel; RenderBasis orthographic_basis; get_orthographic_basis(&orthographic_basis, game_state->screen_render_region); // // UPDATE WORLD // ui_consume_mouse_clicks(game_state, &orthographic_basis, &game_state->ui, mouse, time_us); if (game_state->inputs.maps[SIM_TICKS_INC].active) { game_state->sim_ticks_per_s += .5f; } if (game_state->inputs.maps[SIM_TICKS_DEC].active) { game_state->sim_ticks_per_s -= .5f; } game_state->sim_ticks_per_s = clamp(.5, game_state->sim_ticks_per_s, 20); update_cells_ui_state(game_state, &render_basis, mouse, time_us); b32 sim = sim_tick(game_state, time_us); if (sim && game_state->ui.car_inputs == 0 && !game_state->finish_sim_step_move) { perform_cells_sim_tick(memory, game_state, &(game_state->maze.tree), time_us); perform_cars_sim_tick(memory, game_state, time_us); } if (sim && game_state->ui.car_inputs == 0) { move_cars(game_state); game_state->finish_sim_step_move = false; ++game_state->sim_steps; } annimate_cars(game_state, last_frame_dt); step_particles(&(game_state->particles), time_us); update_ui(game_state, &orthographic_basis, &game_state->ui, mouse, &game_state->inputs, time_us); // // RENDER // // Add render operations to queue game_state->render_operations.next_free = 0; add_fast_box_to_render_list(&game_state->render_operations, &orthographic_basis, (Rectangle) { (V2) {0,0},size(game_state->screen_render_region) }, (PixelColor) { 255, 255, 255 }); draw_cells(game_state, &game_state->render_operations, &render_basis, &(game_state->maze.tree), time_us); draw_cars(game_state, &game_state->render_operations, &render_basis, &(game_state->cars), time_us); // render_particles(&(game_state->particles), &game_state->render_operations, &render_basis); r32 text_scale = 0.3; draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, size(game_state->screen_render_region) - CHAR_SIZE*text_scale*(V2) { strlen(game_state->persistent_str), 1 }, game_state->persistent_str, text_scale, (V4) { 1, 0, 0, 0 }); draw_ui(&game_state->render_operations, &orthographic_basis, &render_basis, &game_state->bitmaps.font, &game_state->cell_bitmaps, &game_state->ui, time_us); char str[4]; fmted_str(str, 4, "%d", fps); draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, (V2) { 0, 0 }, str, 0.3, (V4) { 1, 0, 0, 0 }); // Add render segments to render queue V2 ns = game_state->render_segs.n_segments; V2 s; for (s.y = 0; s.y < ns.y; ++s.y) { for (s.x = 0; s.x < ns.x; ++s.x) { RenderQueueData render_data; Rectangle *segment = game_state->render_segs.segments + (u32)s.y + (u32)ns.y*(u32)s.x; render_data.clip_region = *segment; render_data.frame_buffer = frame_buffer; render_data.render_operations = &game_state->render_operations; #ifdef THREADED_RENDERING pthread_mutex_lock(&game_state->render_queue.mut); while (game_state->render_queue.full) { log(L_RenderQueue, "producer: queue FULL."); pthread_cond_wait(&game_state->render_queue.not_full, &game_state->render_queue.mut); } log(L_RenderQueue, "producer: Adding."); queue_add(&game_state->render_queue, render_data); pthread_mutex_unlock(&game_state->render_queue.mut); pthread_cond_signal(&game_state->render_queue.not_empty); #else consume_render_operations(render_data.frame_buffer, render_data.render_operations, render_data.clip_region); #endif } } // TODO: Wait for frame rendering to finish // TODO: Get rid of this game_state->last_render_basis = render_basis; }
int joyai_config(int joy) { BOOL running = TRUE; keysym_type *keysym = (joy == 2) ? keysym_2 : keysym_1; ULONG signals; if (!amigainput_lib_loaded) { return -1; } if (CTX == NULL) { return -1; } get_cfg(joy); ai_release(); memset(&devices, 0, sizeof(devices)); memset(&inputs, 0, sizeof(inputs)); if (joy_id[joy - 1] != -1) { ai_handle[0] = AIN_ObtainDevice(CTX, joy_id[joy - 1]); if (ai_handle[0] != NULL) { AIN_ReleaseDevice(CTX, ai_handle[0]); ai_handle[0] = NULL; } else { joy_id[joy - 1] = -1; } } devices.ids[devices.count] = -1; devices.names[devices.count] = lib_stralloc("-"); devices.count++; default_id = joy_id[joy - 1]; default_count = 0; AIN_EnumDevices(CTX, enumfunc, &devices); update_inputs(joy_id[joy - 1]); { APTR label, text[NUM_KEYSYM], button, app, main_group, window, ok, cancel, Odevice, Oinput[NUM_KEYSYM]; app = ApplicationObject, MUIA_Application_Author, "Mathias Roslund & Marco van den Heuvel", MUIA_Application_Base, KEYNAME, MUIA_Application_Title, KEYNAME, MUIA_Application_Version, "$VER: " KEYNAME " v1.0", MUIA_Application_Copyright, "Mathias Roslund & Marco van den Heuvel", MUIA_Application_Description, "Versatile Commodore Emulator", SubWindow, window = WindowObject, MUIA_Window_Title, KEYNAME, MUIA_Window_ID, MAKE_ID('0', 'W', 'I', 'N'), MUIA_Window_Screen, canvaslist->os->screen, WindowContents, VGroup, Child, HGroup, Child, TextObject, MUIA_Text_PreParse, "\033r", MUIA_Text_Contents, "AI Device", MUIA_Weight, 0, MUIA_InnerLeft, 0, MUIA_InnerRight, 0, End, Child, Odevice = CycleObject, MUIA_Cycle_Entries, devices.names, MUIA_Cycle_Active, default_count, End, End, Child, main_group = ColGroup(4), End, Child, HGroup, Child, ok = TextObject, ButtonFrame, MUIA_Background, MUII_ButtonBack, MUIA_Text_Contents, "Ok", MUIA_Text_PreParse, "\033c", MUIA_InputMode, MUIV_InputMode_RelVerify, End, Child, cancel = TextObject, ButtonFrame, MUIA_Background, MUII_ButtonBack, MUIA_Text_Contents, "Cancel", MUIA_Text_PreParse, "\033c", MUIA_InputMode, MUIV_InputMode_RelVerify, End, End, End, End, End; if (app) { unsigned int i; DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit); DoMethod(Odevice, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, app, 2, MUIM_Application_ReturnID, DEV_CHANGE); DoMethod(cancel, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit); DoMethod(ok, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, BTN_OK); for (i = 0; i < NUM_KEYSYM; i++) { /* label */ label = TextObject, MUIA_Text_PreParse, "\033r", MUIA_Text_Contents, keysym[i].label, MUIA_InnerLeft, 0, MUIA_InnerRight, 0, End; Oinput[i] = CycleObject, MUIA_Cycle_Entries, inputs.names, MUIA_Cycle_Active, offset_to_active(keysym[i].type, keysym[i].offset), End, text[i] = TextObject, MUIA_Background, MUII_TextBack, MUIA_Frame, MUIV_Frame_Text, MUIA_Text_Contents, rawkey_to_name(keysym[i].rawkey), End; button = TextObject, ButtonFrame, MUIA_Background, MUII_ButtonBack, MUIA_Text_Contents, "Change", MUIA_Text_PreParse, "\033c", MUIA_InputMode, MUIV_InputMode_RelVerify, End; DoMethod(button, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, (i + 1)); /* add to window */ DoMethod(main_group, OM_ADDMEMBER, label); DoMethod(main_group, OM_ADDMEMBER, Oinput[i]); DoMethod(main_group, OM_ADDMEMBER, text[i]); DoMethod(main_group, OM_ADDMEMBER, button); } } if (app) { unsigned int i; set(window, MUIA_Window_Open, TRUE); while (running) { unsigned long retval = DoMethod(app, MUIM_Application_Input, &signals); switch (retval) { case MUIV_Application_ReturnID_Quit: running = FALSE; break; case BTN_OK: for (i = 0; i < NUM_KEYSYM; i++) { ULONG active; get(Oinput[i], MUIA_Cycle_Active, &active); keysym[i].type = inputs.types[active]; keysym[i].offset = inputs.offsets[active]; } set_cfg(joy); running = FALSE; break; case DEV_CHANGE: { ULONG active; get(Odevice, MUIA_Cycle_Active, &active); joy_id[joy - 1] = devices.ids[active]; update_inputs(joy_id[joy - 1]); for (i = 0; i < NUM_KEYSYM; i++) { set(Oinput[i], MUIA_Cycle_Entries, inputs.names); set(Oinput[i], MUIA_Cycle_Active, 0); } } break; default: if ((retval >= 1) && (retval <= (1 + NUM_KEYSYM))) { int keycode, index, result; result = get_key(joy_id[joy - 1], &keycode, &index); if (result == 1) { /* KEY */ keysym[retval - 1].rawkey = keycode; set(text[retval - 1], MUIA_Text_Contents, rawkey_to_name(keycode)); } else if (result == 2) { /* AI */ index = offset_to_index(index); if (index >= 0) { set(Oinput[retval - 1], MUIA_Cycle_Active, index); } } } break; } if (running && signals) { Wait(signals); } } MUI_DisposeObject(app); } } #undef DEV_CHANGE #undef BTN_OK ai_attach(); return 0; }