// store void handle_key_0(s32 val) { if(val == 0) { return; } if(check_key(0)) { region_fill(headRegion, 0x0); font_string_region_clip(headRegion, "writing scene to card...", 0, 0, 0xa, 0); headRegion->dirty = 1; render_update(); region_fill(headRegion, 0x0); // files_store_scene_name(sceneData->desc.sceneName, 1); files_store_scene_name(sceneData->desc.sceneName); print_dbg("\r\n stored scene, back to handler"); font_string_region_clip(headRegion, "done writing.", 0, 0, 0xa, 0); headRegion->dirty = 1; render_update(); // refresh // redraw_lines(); redraw_scenes(); } show_foot(); }
// function keys void handle_key_0(s32 val) { // load module if(val == 0) { return; } if(check_key(0)) { region_fill(headRegion, 0x0); font_string_region_clip(headRegion, "loading DSP module...", 0, 0, 0xa, 0); headRegion->dirty = 1; render_update(); net_clear_user_ops(); files_load_dsp(*pageSelect); bfin_wait_ready(); net_report_params(); bfin_enable(); // render status to head region region_fill(headRegion, 0x0); font_string_region_clip(headRegion, "finished loading.", 0, 0, 0xa, 0); headRegion->dirty = 1; render_update(); } show_foot(); }
void display_error_message(Interface *interface) { Area box, text_box_top, text_box_bottom; char align_message_top[ERROR_TEXTBOX], align_message_bottom[ERROR_TEXTBOX]; read_write_error(align_message_top, align_message_bottom); SDL_Event event; do { make_rect(&interface->window, &box, 0, 200, interface->text_editor_panel.rect.w, 100, 255,255,255); make_rect(&interface->window, &text_box_top, 0, box.rect.y + (box.rect.h / 4), interface->text_editor_panel.rect.w, CHALLENGE_FONT_SIZE*1.45, 255,255,255); make_text(&interface->window, &text_box_top.rect, interface->challenge_font, align_message_top, 241, 35, 65); make_rect(&interface->window, &text_box_bottom, 0, text_box_top.rect.y + text_box_top.rect.h, interface->text_editor_panel.rect.w, CHALLENGE_FONT_SIZE*1.45, 255,255,255); make_text(&interface->window, &text_box_bottom.rect, interface->challenge_font, align_message_bottom, 241, 35, 65); render_update(interface->window); SDL_PollEvent(&event); } while(event.type != SDL_MOUSEBUTTONDOWN && event.type != SDL_KEYDOWN); }
/** * The game loop, this function is called periodically to update the game. */ void game_loop() { static int last_time = -1; int delta, now; /* Update the game */ now = GET_CURRENT_TIME(); if( last_time == -1 ) { last_time = now; return; } // Get the time since the last update (minimum of one millisecond) delta = 1 + now - last_time; // TODO: remove the 1 update_world(delta); /* Update the render module */ render_update(delta); /* Render the game */ render(); last_time = now; }
void trace_clear(void) { if (trace_state != 0) { trace_state = 0; trace_unknown = 0xFFFF; render_update(trace_win_x,trace_win_y,trace_win_w,trace_win_h); } }
/* Main Menu */ void display_main_menu(Menu* main_menu) { int win_width, win_height; render_update(main_menu->window); SDL_GetWindowSize(main_menu->window.win, &win_width, &win_height); display_menu_background(win_width, win_height, main_menu); display_logo(win_width, win_height, main_menu); display_canvas_button(win_width, win_height, main_menu); display_challenges_button(win_width, win_height, main_menu); display_menu_help_button(win_width, win_height, main_menu); display_quit_button(win_width, win_height, main_menu); }
/* Challenges Menu */ void display_challenges_menu(Menu* challenges) { int win_width, win_height; render_update(challenges->window); SDL_GetWindowSize(challenges->window.win, &win_width, &win_height); display_challenges_background(win_width, win_height, challenges); display_header(win_width, win_height, challenges); display_beginner_button(win_width, win_height, challenges); display_intermediate_button(win_width, win_height, challenges); display_expert_button(win_width, win_height, challenges); display_main_menu_button(win_width, win_height, challenges); }
void GLWindow::paintGL() { static unsigned int fps_time_ms = 0, fps_ticks = 0; static unsigned long last_time = 0L; unsigned long current_time = 0; current_time = get_current_time_ms(); frame_time_ms = current_time - last_time; update_options(); render_update(frame_time_ms / 1000.0); render_draw(); fps_ticks++; last_time = current_time; fps_time_ms += frame_time_ms; if(fps_time_ms >= 1000) { current_fps = fps_ticks; fps_ticks = 0; fps_time_ms = 0; } }
int main_leveleditor() { SDL_Event e; SDL_ShowCursor(SDL_ENABLE); entity_initialize_list(1024); tank_initialize_list(15); //im a fuckboi editorclicked = 0; ui_initialize_leveleditor(rtn_renderer()); do { render_update(1); render_clear(); while(SDL_PollEvent(&e)) { if(e.type == SDL_KEYDOWN) { if(e.type == SDL_QUIT) exit(0); if(e.key.keysym.sym == SDLK_ESCAPE) { editorclicked = 0; currentstate = MAINMENU; } } if(e.type == SDL_MOUSEBUTTONDOWN) { if(e.button.button == SDL_BUTTON_LEFT) { click = 1; } } if(e.type == SDL_MOUSEBUTTONUP) { if(e.button.button == SDL_BUTTON_LEFT) { click = 0; } } if(saveclicked == 1) { saveclicked = 0; slog("save clicked"); } else if(loadclicked == 1) { loadclicked = 0; slog("load clicked"); } else if(backclicked == 1) { backclicked = 0; currentstate = MAINMENU; } } } while(currentstate == LEVELEDITOR); }
// this is called from the event queue to start the app // return >0 if there is an error doing firstrun init u8 app_launch(u8 firstrun) { u32 waitForCard; print_dbg("\r\n app launch"); print_dbg("\r\n firstrun: "); print_dbg_ulong(firstrun); if(firstrun) { // it is the first run. // need to copy audio module binary from sdcard to internal flash. render_boot("first run. waiting for SDcard..."); render_update(); print_dbg("\r\n SD check... "); while (!sd_mmc_spi_mem_check()) { waitForCard++; } print_dbg("\r\nfound SD card. "); render_boot("found sdcard.. reading DSP..."); render_update(); // search for our dsp and load it // return success (0 == fail) if( files_search_dsp() ) { ;; } else { screen_clear(); return 0; } } else { // firstrun pattern was set, so there should be a blackfin executable in flash. // read from flash to RAM render_boot("loading flash to RAM..."); render_update(); flash_read_ldr(); render_boot( "booting DSP from flash..."); render_update(); // reboot DSP from RAM bfin_load_buf(); } render_boot("waiting for bfin init... "); render_update(); bfin_wait_ready(); // set encoder sensitivity set_enc_thresh(3, 16); delay_ms(20); // enable audio render_boot("run "); render_update(); bfin_enable(); // enable timers init_app_timers(); render_startup(); render_update(); // set app event handlers mix_assign_event_handlers(); return 1; }
int render_init(void) { IF_FAILED0(!init); if(!init_opengl) { ERROR_MSG("OpenGL not initialised\n"); return 0; } log_init(); TRACE_MSG("init base render system\n"); TRACE_MSG("init noise\n"); noise_init(); glViewport(0, 0, window_width, window_height); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glClearDepth(1.0f); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_CLAMP); DEBUG_MSG("OpenGL version: %s\n", glGetString(GL_VERSION)); DEBUG_MSG("GLSL version: %s\n", (char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); // настраиваем основную камеру TRACE_MSG("init main camera\n"); camera_init(&camera, vec3f(0.0f, 0.0f, 0.5f), vec3f(0.0f, 1.0f, 0.0f), vec3f(0.0f, 0.0f, -1.0f)); camera_set_limit(&camera, -95.0f, 95.0f, -360.0f, 360.0f); camera_set_fov(&camera, camera_fov); camera_set_move_velocity(&camera, camera_move_speed); camera_set_rotate_velocity(&camera, camera_rotate_speed); camera_set_aspect(&camera, (float) window_width / (float) window_height); camera_set_zplanes(&camera, 0.001f, 1000.0f); camera_update(&camera, 0.0); isolevel = 30.0f; isolevel_animate = 0; // устанавливаем функцию по-умолчанию parser_create(&parser); const char *default_func = "d = y;"; str_function = (char*) malloc(sizeof(char) * (strlen(default_func) + 1)); strcpy(str_function, default_func); // настраиваем и создаем скалярное поле render_set_volume_size(vec3ui(128, 128, 128), 1); render_set_grid_size(vec3ui(64, 64, 64)); render_update_volume_tex(); CHECK_GL_ERRORS(); // инициализируем шейдер if(!init_shader()) return 0; // инициализируем буферы с данными init_buffers(); // устанавливаем параметры по-умолчанию new_light_position = light_position = vec3f(1.0f, 1.0f, 1.0f); rot_axis = vec3f(0.0f, 1.0f, 0.0f); num_threads = 1; rot_angle = 0.0f; light_animate = 0; light_rot_angle = 0.0f; mat4(rotmat, 1.0f); mat4(modelmat, 1.0f); material_front_color = vec3f(0.5f, 0.5f, 0.5f); material_back_color = vec3f(0.5f, 0.0f, 0.0f); light_color = vec3f(1.0f, 1.0f, 1.0f); light_spec_color = vec3f(1.0f, 1.0f, 1.0f); input_set_wheel_limits(20, 150); init = 1; // полигонизируем ск. п. render_update_mc(); // обновляем рендер render_update(0.0f); return 1; }
void GLWindow::resizeGL(int w, int h) { render_change_window(w, h); render_update(frame_time_ms / 1000.0); }
// draw to the head region void notify(const char* str) { region_fill(headRegion, 0x0); font_string_region_clip(headRegion, str, 0, 0, 0xa, 0); headRegion->dirty = 1; render_update(); }
// screen refresh callback static void screen_timer_callback(void* obj) { render_update(); }
int main_deathmatch() { SDL_Event e; SDL_ShowCursor(SDL_DISABLE); entity_initialize_list(1024); tank_initialize_list(15); g_current_level = level_load("leveloneconfig"); render_set_background(g_current_level->background->image); g_music = audio_load_music("sounds/music/backgroundmusic.wav"); g_sound = audio_load_sound("sounds/digital/digital.wav"); if(g_music->file.music != NULL) { slog("Playing Music"); //audio_play_music(g_music->file.music); } else slog("Could not load music file"); player = player_spawn("Player", PLAYER); v2d_set(player->tank->tracks->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2); v2d_set(player->tank->turret->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2); g_now = SDL_GetTicks(); ui_initialize_deathmatch(rtn_renderer()); do { //calculate deltatime g_last = g_now; g_now = SDL_GetTicks(); g_deltatime = g_now - g_last; render_update(1); render_clear(); entity_all_think(); entity_all_update(); player_move(player); while(SDL_PollEvent(&e)) { if(e.type == SDL_KEYDOWN) { if(e.type == SDL_QUIT) SDL_Quit(); if(e.key.keysym.sym == SDLK_w) player->keysHeld.W = 1; if(e.key.keysym.sym == SDLK_s) player->keysHeld.S = 1; if(e.key.keysym.sym == SDLK_a) player->keysHeld.A = 1; if(e.key.keysym.sym == SDLK_d) player->keysHeld.D = 1; if(e.key.keysym.sym == SDLK_e) { tank_weapon_change(player->tank); slog("Current weapon: %s", player->tank->currentweapon->name); } if(e.key.keysym.sym == SDLK_p) { audio_play_sound(g_sound->file.sound); } if(e.key.keysym.sym == SDLK_f) { Entity *sonar; sonar = sonar_new(sonar = entity_new(SONAR, NULL), 3.0, player->tank); } if(e.key.keysym.sym == SDLK_g) { tank_weapon_fire(player->tank); } if(e.key.keysym.sym == SDLK_h) player->tank->health -= 5; if(e.key.keysym.sym == SDLK_j) player->tank->armour -= 5; if(e.key.keysym.sym == SDLK_SPACE) { if(player->tank->is_hidden) player->tank->is_hidden = 0; else player->tank->is_hidden = 1; tank_sprite_change(player->tank); } if(e.key.keysym.sym == SDLK_ESCAPE) { playclicked = 0; entity_close_list(); tank_close_list(); player_close_list(); currentstate = MAINMENU; } } if(e.type == SDL_KEYUP) { if(e.key.keysym.sym == SDLK_w) player->keysHeld.W = 0; if(e.key.keysym.sym == SDLK_s) player->keysHeld.S = 0; if(e.key.keysym.sym == SDLK_a) player->keysHeld.A = 0; if(e.key.keysym.sym == SDLK_d) player->keysHeld.D = 0; } } if(g_deltatime < 32) SDL_Delay(32-g_deltatime); } while(currentstate == DEATHMATCH); return 0; }
int main_mainmenu() { SDL_Event e; SDL_ShowCursor(SDL_ENABLE); g_current_level = level_load("mainmenuconfig"); render_set_background(g_current_level->background->image); player_initialize_list(); ui_initialize_mainmenu(rtn_renderer()); do { render_update(0); render_clear(); while(SDL_PollEvent(&e)) { if(e.type == SDL_KEYDOWN) { if(e.type == SDL_QUIT) exit(0); if(e.key.keysym.sym == SDLK_ESCAPE) { currentstate = EXIT; exit(0); } } if(e.type == SDL_MOUSEBUTTONDOWN) { if(e.button.button == SDL_BUTTON_LEFT) { click = 1; } } if(e.type == SDL_MOUSEBUTTONUP) { if(e.button.button == SDL_BUTTON_LEFT) { click = 0; } } if(playclicked == 1) { slog("Changed to Deathmatch"); currentstate = DEATHMATCH; } else if(editorclicked == 1) { slog("Changed to LevelEditor"); currentstate = LEVELEDITOR; } else if(quitclicked == 1) { exit(0); } } } while(currentstate == MAINMENU); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; HWND hwnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_OWNDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = "GLSample"; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if (!RegisterClassEx(&wcex)) { return 0; } // 224 x 320 is the sacred resolution of Gunbird const int window_width = 224 * 2; const int window_height = 320 * 2; hwnd = CreateWindowEx(0, "GLSample", "OpenGL Sample", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, window_width, window_height, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nCmdShow); EnableOpenGL(hwnd, &hDC, &hRC); static t_game_state game_state; game_init(&game_state); render_init(window_width, window_height); sprite_system_init(); while (!bQuit) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { bQuit = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { game_update(&game_state); render_update(&game_state); SwapBuffers(hDC); //Sleep (1); } } DisableOpenGL(hwnd, hDC, hRC); DestroyWindow(hwnd); return msg.wParam; }