// set a view and projection matrix for a 2D element // TODO: this probably needs to accept values void gr_set_2d_matrix(/*int x, int y, int w, int h*/) { // don't bother with this if we aren't even going to need it if (!gr_htl_projection_matrix_set) { return; } Assert( htl_2d_matrix_set == 0 ); Assert( htl_2d_matrix_depth == 0 ); // the viewport needs to be the full screen size since glOrtho() is relative to it gr_set_viewport(0, 0, gr_screen.max_w, gr_screen.max_h); gr_last_projection_matrix = gr_projection_matrix; // the top and bottom positions are reversed on purpose, but RTT needs them the other way if (gr_screen.rendering_to_texture != -1) { create_orthographic_projection_matrix(&gr_projection_matrix, 0, i2fl(gr_screen.max_w), 0, i2fl(gr_screen.max_h), -1, 1); } else { create_orthographic_projection_matrix(&gr_projection_matrix, 0, i2fl(gr_screen.max_w), i2fl(gr_screen.max_h), 0, -1, 1); } matrix4 identity_mat; vm_matrix4_set_identity(&identity_mat); gr_model_matrix_stack.push_and_replace(identity_mat); gr_last_view_matrix = gr_view_matrix; gr_view_matrix = identity_mat; vm_matrix4_x_matrix4(&gr_model_view_matrix, &gr_view_matrix, &identity_mat); htl_2d_matrix_set = true; htl_2d_matrix_depth++; }
void HudGaugeRadarOrb::drawContactHtl(vec3d *pnt, int rad) { vec3d p; p=*pnt; vm_vec_normalize(&p); float size = fl_sqrt(vm_vec_dist(&Orb_eye_position, pnt) * 8.0f); if (size < i2fl(rad)) size = i2fl(rad); if (rad == Radar_blip_radius_target) { if (radar_target_id_flags & RTIF_PULSATE) { // use mask to make the darn thing work faster size *= 1.3f + (sinf(10 * f2fl(Missiontime)) * 0.3f); } if (radar_target_id_flags & RTIF_BLINK) { if (Missiontime & 8192) return; } g3_render_sphere(pnt,size/100.0f); } else { g3_render_sphere(pnt,size/300.0f); } //g3_draw_htl_line(&p,pnt); g3_render_line_3d(false, &p, pnt); }
void HudGaugeRadarOrb::drawContact(vec3d *pnt, int rad) { vertex verts[2]; vec3d p; p=*pnt; vm_vec_normalize(&p); g3_rotate_vertex(&verts[0], &p); g3_project_vertex(&verts[0]); g3_rotate_vertex(&verts[1], pnt); g3_project_vertex(&verts[1]); float size = fl_sqrt(vm_vec_dist(&Orb_eye_position, pnt) * 8.0f); if (size < i2fl(rad)) size = i2fl(rad); if (rad == Radar_blip_radius_target) { g3_draw_sphere(&verts[1],size/100.0f); } else { g3_draw_sphere(&verts[1],size/300.0f); } g3_draw_line(&verts[0],&verts[1]); }
/** * Builds the output text. */ void profile_dump_output() { if (Cmdline_frame_profile) { end_profile_time = timer_get_microseconds(); if (Cmdline_profile_write_file) { profiling_file << end_profile_time << ";" << (end_profile_time - start_profile_time) << std::endl; } profile_output.clear(); profile_output += " Avg : Min : Max : # : Profile Name\n"; profile_output += "----------------------------------------\n"; for(int i = 0; i < (int)samples.size(); i++) { uint64_t sample_time; float percent_time, avg_time, min_time, max_time; uint64_t avg_micro_seconds, min_micro_seconds, max_micro_seconds; Assert(samples[i].open_profiles == 0); sample_time = samples[i].accumulator - samples[i].children_sample_time; if (end_profile_time == start_profile_time) { percent_time = 0.0f; } else { percent_time = (i2fl(sample_time) / i2fl(end_profile_time - start_profile_time)) *100.0f; } avg_micro_seconds = min_micro_seconds = max_micro_seconds = sample_time; avg_time = min_time = max_time = percent_time; // add new measurement into the history and get avg, min, and max store_profile_in_history(samples[i].name, percent_time, sample_time); get_profile_from_history(samples[i].name, &avg_time, &min_time, &max_time, &avg_micro_seconds, &min_micro_seconds, &max_micro_seconds); // format the data char avg[64], min[64], max[64], num[64]; sprintf(avg, "%3.1f%% (%3.1fms)", avg_time, i2fl(avg_micro_seconds)*0.001f); sprintf(min, "%3.1f%% (%3.1fms)", min_time, i2fl(min_micro_seconds)*0.001f); sprintf(max, "%3.1f%% (%3.1fms)", max_time, i2fl(max_micro_seconds)*0.001f); sprintf(num, "%3d", samples[i].profile_instances); SCP_string indented_name(samples[i].name); for(uint indent = 0; indent < samples[i].num_parents; indent++) { indented_name = ">" + indented_name; } char line[256]; sprintf(line, "%5s : %5s : %5s : %3s : ", avg, min, max, num); profile_output += line + indented_name + "\n"; } samples.clear(); start_profile_time = timer_get_microseconds(); } }
void HudGaugeRadarDradis::setupViewHtl() { setClip(position[0], position[1], Radar_radius[0], Radar_radius[1]); gr_set_proj_matrix(.625f * PI_2, i2fl(Radar_radius[0])/i2fl(Radar_radius[1]), 0.001f, 5.0f); gr_set_view_matrix(&Orb_eye_position, &vmd_identity_matrix); gr_zbuffer_set(GR_ZBUFF_NONE); }
void gr_opengl_set_ambient_light(int red, int green, int blue) { GL_light_ambient[0] = i2fl(red)/255.0f; GL_light_ambient[1] = i2fl(green)/255.0f; GL_light_ambient[2] = i2fl(blue)/255.0f; GL_light_ambient[3] = 1.0f; opengl_calculate_ambient_factor(); }
void gr_opengl_scene_texture_begin() { if ( !Scene_texture_initialized ) { return; } if ( Scene_framebuffer_in_frame ) { return; } GR_DEBUG_SCOPE("Begin scene texture"); TRACE_SCOPE(tracing::SceneTextureBegin); GL_state.PushFramebufferState(); GL_state.BindFrameBuffer(Scene_framebuffer); //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, Scene_depth_texture, 0); if (GL_rendering_to_texture) { Scene_texture_u_scale = i2fl(gr_screen.max_w) / i2fl(Scene_texture_width); Scene_texture_v_scale = i2fl(gr_screen.max_h) / i2fl(Scene_texture_height); CLAMP(Scene_texture_u_scale, 0.0f, 1.0f); CLAMP(Scene_texture_v_scale, 0.0f, 1.0f); } else { Scene_texture_u_scale = 1.0f; Scene_texture_v_scale = 1.0f; } if ( Cmdline_no_deferred_lighting ) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } else { GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4 }; glDrawBuffers(5, buffers); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); opengl_clear_deferred_buffers(); glDrawBuffer(GL_COLOR_ATTACHMENT0); } Scene_framebuffer_in_frame = true; if ( Gr_post_processing_enabled && !PostProcessing_override ) { High_dynamic_range = true; } }
// Returns amount of time key (specified by "code") has been down since last call. // Returns float, unlike key_down_time() which returns a fix. float key_down_timef(uint scancode) { uint time_down, time; uint delta_time; if (!key_inited) { return 0.0f; } if (scancode >= NUM_KEYS) { return 0.0f; } ENTER_CRITICAL_SECTION(key_lock); time = timer_get_milliseconds(); delta_time = time - key_data.TimeKeyDownChecked[scancode]; key_data.TimeKeyDownChecked[scancode] = time; if (delta_time <= 1) { key_data.TimeKeyWentDown[scancode] = time; if (keyd_pressed[scancode]) { LEAVE_CRITICAL_SECTION(key_lock); return 1.0f; } else { LEAVE_CRITICAL_SECTION(key_lock); return 0.0f; } } if (!keyd_pressed[scancode]) { time_down = key_data.TimeKeyHeldDown[scancode]; key_data.TimeKeyHeldDown[scancode] = 0; } else { time_down = time - key_data.TimeKeyWentDown[scancode]; key_data.TimeKeyWentDown[scancode] = time; } LEAVE_CRITICAL_SECTION(key_lock); return i2fl(time_down) / i2fl(delta_time); }
void gr_end_proj_matrix() { gr_set_viewport(0, 0, gr_screen.max_w, gr_screen.max_h); gr_last_projection_matrix = gr_projection_matrix; // the top and bottom positions are reversed on purpose, but RTT needs them the other way if (gr_screen.rendering_to_texture != -1) { create_orthographic_projection_matrix(&gr_projection_matrix, 0.0f, i2fl(gr_screen.max_w), 0.0f, i2fl(gr_screen.max_h), -1.0f, 1.0f); } else { create_orthographic_projection_matrix(&gr_projection_matrix, 0.0f, i2fl(gr_screen.max_w), i2fl(gr_screen.max_h), 0.0f, -1.0f, 1.0f); } gr_htl_projection_matrix_set = false; }
void gr_opengl_zbias(int bias) { if (bias) { GL_state.PolygonOffsetFill(GL_TRUE); if(bias < 0) { GL_state.SetPolygonOffset(1.0, -i2fl(bias)); } else { GL_state.SetPolygonOffset(0.0, -i2fl(bias)); } } else { GL_state.PolygonOffsetFill(GL_FALSE); } }
/** * Renders everything for a head animation * Also checks for when new head ani's need to start playing */ void HudGaugeTalkingHead::render(float frametime) { if ( Head_frame.first_frame == -1 ) { return; } if(msg_id != -1 && head_anim != NULL) { if(!head_anim->done_playing) { // draw frame // hud_set_default_color(); setGaugeColor(); // clear setClip(position[0] + Anim_offsets[0], position[1] + Anim_offsets[1], Anim_size[0], Anim_size[1]); gr_clear(); resetClip(); renderBitmap(Head_frame.first_frame, position[0], position[1]); // head ani border float scale_x = i2fl(Anim_size[0]) / i2fl(head_anim->width); float scale_y = i2fl(Anim_size[1]) / i2fl(head_anim->height); gr_set_screen_scale(fl2ir(base_w / scale_x), fl2ir(base_h / scale_y)); setGaugeColor(); generic_anim_render(head_anim,frametime, fl2ir((position[0] + Anim_offsets[0] + HUD_offset_x) / scale_x), fl2ir((position[1] + Anim_offsets[1] + HUD_offset_y) / scale_y)); // draw title gr_set_screen_scale(base_w, base_h); renderString(position[0] + Header_offsets[0], position[1] + Header_offsets[1], XSTR("message", 217)); } else { for (int j = 0; j < Num_messages_playing; ++j) { if (Playing_messages[j].id == msg_id) { Playing_messages[j].play_anim = false; break; // only one head ani plays at a time } } msg_id = -1; // allow repeated messages to display a new head ani head_anim = NULL; // Nothing to see here anymore, move along } } // check playing messages to see if we have any messages with talking animations that need to be created. for (int i = 0; i < Num_messages_playing; i++ ) { if(Playing_messages[i].play_anim && Playing_messages[i].id != msg_id ) { msg_id = Playing_messages[i].id; if (Playing_messages[i].anim_data) head_anim = Playing_messages[i].anim_data; else head_anim = NULL; return; } } }
// Reset data used for player lock indicator void hud_lock_reset(float lock_time_scale) { weapon_info *wip; ship_weapon *swp; swp = &Player_ship->weapons; wip = &Weapon_info[swp->secondary_bank_weapons[swp->current_secondary_bank]]; Player_ai->current_target_is_locked = 0; Players[Player_num].lock_indicator_visible = 0; Player->target_in_lock_cone = 0; Player->lock_time_to_target = i2fl(wip->min_lock_time*lock_time_scale); Player->current_target_sx = -1; Player->current_target_sy = -1; Player->locking_subsys=NULL; Player->locking_on_center=0; Player->locking_subsys_parent=-1; hud_stop_looped_locking_sounds(); Lock_gauge_draw_stamp = -1; Lock_gauge_draw = 0; // reset the lock anim time elapsed Lock_anim.time_elapsed = 0.0f; }
float joy_down_time(int btn) { float rval; unsigned int now; joy_button_info *bi; if ( joy_num_sticks < 1 ) return 0.0f; if ( (btn < 0) || (btn >= JOY_TOTAL_BUTTONS)) return 0.0f; bi = &joy_buttons[btn]; now = timer_get_milliseconds(); if ( bi->down_time == 0 && joy_down(btn) ) { bi->down_time += joy_pollrate; } if ( (now - bi->last_down_check) > 0) rval = i2fl(bi->down_time) / (now - bi->last_down_check); else rval = 0.0f; bi->down_time = 0; bi->last_down_check = now; if (rval < 0) rval = 0.0f; if (rval > 1) rval = 1.0f; return rval; }
// Reset data used for player lock indicator void hud_lock_reset(float lock_time_scale) { weapon_info *wip; ship_weapon *swp; swp = &Player_ship->weapons; if ((swp->current_secondary_bank >= 0) && (swp->secondary_bank_weapons[swp->current_secondary_bank] >= 0)) { Assert(swp->current_secondary_bank < MAX_SHIP_SECONDARY_BANKS); Assert(swp->secondary_bank_weapons[swp->current_secondary_bank] < MAX_WEAPON_TYPES); wip = &Weapon_info[swp->secondary_bank_weapons[swp->current_secondary_bank]]; Player->lock_time_to_target = i2fl(wip->min_lock_time*lock_time_scale); } else { Player->lock_time_to_target = 0.0f; } Player_ai->current_target_is_locked = 0; Players[Player_num].lock_indicator_visible = 0; Player->target_in_lock_cone = 0; Player->current_target_sx = -1; Player->current_target_sy = -1; Player->locking_subsys=NULL; Player->locking_on_center=0; Player->locking_subsys_parent=-1; hud_stop_looped_locking_sounds(); }
/** * Create a new head animation object */ anim_instance* HudGaugeTalkingHead::createAnim(int anim_start_frame, anim* anim_data) { anim_play_struct aps; float scale_x = i2fl(Anim_size[0]) / i2fl(anim_data->width); float scale_y = i2fl(Anim_size[1]) / i2fl(anim_data->height); anim_play_init(&aps, anim_data, fl2ir((position[0] + Anim_offsets[0] + HUD_offset_x) / scale_x), fl2ir((position[1] + Anim_offsets[1] + HUD_offset_y) / scale_y), base_w, base_h); aps.start_at = anim_start_frame; // aps.color = &HUD_color_defaults[HUD_color_alpha]; aps.color = &HUD_config.clr[HUD_TALKING_HEAD]; // I'd much rather use gr_init_color and retrieve the colors from this object but no, aps.color just happens to be a pointer. // So, just give it the address from the player's HUD configuration. You win, aps.color. I'll take care of you next time. (Swifty) return anim_play(&aps); }
void gr_setup_viewport() { if (Gr_inited) { // This may be called by FRED before the gr system is actually initialized so we need to make sure that // this function call is actually valid at this point. gr_set_viewport(0, 0, gr_screen.max_w, gr_screen.max_h); } gr_last_projection_matrix = gr_projection_matrix; // the top and bottom positions are reversed on purpose, but RTT needs them the other way if (gr_screen.rendering_to_texture != -1) { create_orthographic_projection_matrix(&gr_projection_matrix, 0, i2fl(gr_screen.max_w), 0, i2fl(gr_screen.max_h), -1, 1); } else { create_orthographic_projection_matrix(&gr_projection_matrix, 0, i2fl(gr_screen.max_w), i2fl(gr_screen.max_h), 0, -1, 1); } }
void FrameProfiler::dump_output(SCP_stringstream& out, uint64_t /*start_profile_time*/, uint64_t /*end_profile_time*/, SCP_vector<profile_sample>& samples) { out << " Avg : Min : Max : # : Profile Name\n"; out << "----------------------------------------\n"; for (int i = 0; i < (int) samples.size(); i++) { uint64_t sample_time; uint64_t avg_micro_seconds, min_micro_seconds, max_micro_seconds; Assert(samples[i].open_profiles == 0); sample_time = samples[i].accumulator - samples[i].children_sample_time; avg_micro_seconds = min_micro_seconds = max_micro_seconds = sample_time; // add new measurement into the history and get avg, min, and max store_profile_in_history(samples[i].name, sample_time); get_profile_from_history(samples[i].name, &avg_micro_seconds, &min_micro_seconds, &max_micro_seconds); // format the data char avg[64], min[64], max[64], num[64]; sprintf(avg, "%3.1fms", i2fl(avg_micro_seconds) * 0.000001f); sprintf(min, "%3.1fms", i2fl(min_micro_seconds) * 0.000001f); sprintf(max, "%3.1fms", i2fl(max_micro_seconds) * 0.000001f); sprintf(num, "%3d", samples[i].profile_instances); SCP_string indented_name; for (uint indent = 0; indent < samples[i].num_parents; indent++) { indented_name += ">"; } indented_name += samples[i].name; char line[256]; sprintf_safe(line, "%5s : %5s : %5s : %3s : ", avg, min, max, num); out << line + indented_name + "\n"; } }
void gr_opengl_end_projection_matrix() { GL_CHECK_FOR_ERRORS("start of end_projection_matrix()"); glViewport(0, 0, gr_screen.max_w, gr_screen.max_h); GL_last_projection_matrix = GL_projection_matrix; // the top and bottom positions are reversed on purpose, but RTT needs them the other way if (GL_rendering_to_texture) { opengl_create_orthographic_projection_matrix(&GL_projection_matrix, 0, i2fl(gr_screen.max_w), 0, i2fl(gr_screen.max_h), -1.0, 1.0); } else { opengl_create_orthographic_projection_matrix(&GL_projection_matrix, 0, i2fl(gr_screen.max_w), i2fl(gr_screen.max_h), 0, -1.0, 1.0); } GL_CHECK_FOR_ERRORS("end of end_projection_matrix()"); GL_htl_projection_matrix_set = 0; }
void radar_frame_init() { radar_null_nblips(); radx = i2fl(Radar_radius[gr_screen.res][0])/2.0f; rady = i2fl(Radar_radius[gr_screen.res][1])/2.0f; int w,h; gr_set_font(FONT1); Small_blip_string[0] = ubyte(SMALL_BLIP_CHAR); Small_blip_string[1] = 0; gr_get_string_size( &w, &h, Small_blip_string ); Small_blip_offset_x = -w/2; Small_blip_offset_y = -h/2; Large_blip_string[0] = ubyte(LARGE_BLIP_CHAR); Large_blip_string[1] = 0; gr_get_string_size( &w, &h, Large_blip_string ); Large_blip_offset_x = -w/2; Large_blip_offset_y = -h/2; }
// Recharge whole shield. // Apply delta/MAX_SHIELD_SECTIONS to each shield section. void shield_add_strength(object* objp, float delta) { // if we aren't going to change anything anyway then just bail if (delta == 0.0f) return; if (!(Ai_info[Ships[objp->instance].ai_index].ai_profile_flags & AIPF_SMART_SHIELD_MANAGEMENT) || delta <= 0.0f) //SUSHI: We don't want smart shield management for negative delta { for (int i = 0; i < MAX_SHIELD_SECTIONS; i++) shield_add_quad(objp, i, delta / MAX_SHIELD_SECTIONS); } else { float section_max = shield_get_max_quad(objp); // smart shield repair while (delta > 0.0f) { //WMC - Set to INT_MAX so that this is set to something float weakest = i2fl(INT_MAX); int weakest_idx = -1; // find weakest shield quadrant for (int i = 0; i < MAX_SHIELD_SECTIONS; i++) { float quad = shield_get_quad(objp, i); if (weakest_idx < 0 || quad < weakest) { weakest = quad; weakest_idx = i; } } // all quads are at full strength if (weakest >= section_max) break; // throw all possible shield power at this quadrant // if there's any left over then apply it to the next weakest on the next pass float xfer_amount; if (weakest + delta > section_max) xfer_amount = section_max - weakest; else xfer_amount = delta; shield_add_quad(objp, weakest_idx, xfer_amount); delta -= xfer_amount; } } }
// Creates a bunch of particles. You pass a structure // rather than a bunch of parameters. void particle_emit( particle_emitter *pe, int type, int optional_data, float range ) { int i, n; if ( !Particles_enabled ) return; int n1, n2; // Account for detail int percent = get_percent(Detail.num_particles); //Particle rendering drops out too soon. Seems to be around 150 m. Is it detail level controllable? I'd like it to be 500-1000 float min_dist = 125.0f; float dist = vm_vec_dist_quick( &pe->pos, &Eye_position ) / range; if ( dist > min_dist ) { percent = fl2i( i2fl(percent)*min_dist / dist ); if ( percent < 1 ) { return; } } //mprintf(( "Dist = %.1f, percent = %d%%\n", dist, percent )); n1 = (pe->num_low*percent)/100; n2 = (pe->num_high*percent)/100; // How many to emit? n = (rand() % (n2-n1+1)) + n1; if ( n < 1 ) return; for (i=0; i<n; i++ ) { // Create a particle vec3d tmp_vel; vec3d normal; // What normal the particle emit arond float radius = (( pe->max_rad - pe->min_rad ) * frand()) + pe->min_rad; float speed = (( pe->max_vel - pe->min_vel ) * frand()) + pe->min_vel; float life = (( pe->max_life - pe->min_life ) * frand()) + pe->min_life; normal.xyz.x = pe->normal.xyz.x + (frand()*2.0f - 1.0f)*pe->normal_variance; normal.xyz.y = pe->normal.xyz.y + (frand()*2.0f - 1.0f)*pe->normal_variance; normal.xyz.z = pe->normal.xyz.z + (frand()*2.0f - 1.0f)*pe->normal_variance; vm_vec_normalize_safe( &normal ); vm_vec_scale_add( &tmp_vel, &pe->vel, &normal, speed ); particle_create( &pe->pos, &tmp_vel, life, radius, type, optional_data ); } }
void gr_opengl_reset_clip() { gr_screen.offset_x = gr_screen.offset_x_unscaled = 0; gr_screen.offset_y = gr_screen.offset_y_unscaled = 0; gr_screen.clip_left = gr_screen.clip_left_unscaled = 0; gr_screen.clip_top = gr_screen.clip_top_unscaled = 0; gr_screen.clip_right = gr_screen.clip_right_unscaled = gr_screen.max_w - 1; gr_screen.clip_bottom = gr_screen.clip_bottom_unscaled = gr_screen.max_h - 1; gr_screen.clip_width = gr_screen.clip_width_unscaled = gr_screen.max_w; gr_screen.clip_height = gr_screen.clip_height_unscaled = gr_screen.max_h; if (gr_screen.custom_size) { gr_unsize_screen_pos( &gr_screen.clip_right_unscaled, &gr_screen.clip_bottom_unscaled ); gr_unsize_screen_pos( &gr_screen.clip_width_unscaled, &gr_screen.clip_height_unscaled ); } gr_screen.clip_aspect = i2fl(gr_screen.clip_width) / i2fl(gr_screen.clip_height); gr_screen.clip_center_x = (gr_screen.clip_left + gr_screen.clip_right) * 0.5f; gr_screen.clip_center_y = (gr_screen.clip_top + gr_screen.clip_bottom) * 0.5f; GL_state.ScissorTest(GL_FALSE); }
void HudGaugeRadarStd::plotBlip(blip *b, int *x, int *y) { float zdist, rscale; vec3d *pos = &b->position; if (b->dist < pos->xyz.z) { rscale = 0.0f; } else { rscale = (float) acos(pos->xyz.z / b->dist) / PI; //2.0f; } zdist = fl_sqrt((pos->xyz.x * pos->xyz.x) + (pos->xyz.y * pos->xyz.y)); float new_x_dist, clipped_x_dist; float new_y_dist, clipped_y_dist; if (zdist < 0.01f) { new_x_dist = 0.0f; new_y_dist = 0.0f; } else { new_x_dist = (pos->xyz.x / zdist) * rscale * (Radar_radius[0]/2.0f); new_y_dist = (pos->xyz.y / zdist) * rscale * (Radar_radius[1]/2.0f); // force new_x_dist and new_y_dist to be inside the radar float hypotenuse; float max_radius; hypotenuse = (float) _hypot(new_x_dist, new_y_dist); max_radius = i2fl(Radar_radius[0] - 5); if (hypotenuse >= max_radius) { clipped_x_dist = max_radius * (new_x_dist / hypotenuse); clipped_y_dist = max_radius * (new_y_dist / hypotenuse); new_x_dist = clipped_x_dist; new_y_dist = clipped_y_dist; } } *x = fl2i(position[0] + Radar_center_offsets[0] + new_x_dist); *y = fl2i(position[1] + Radar_center_offsets[1] - new_y_dist); }
void Cursor::setCurrentFrame() { if (mAnimationFrames.size() > 1) { // We are animated, compute the current frame float diffSeconds = i2fl(timestamp() - mBeginTimeStamp) / TIMESTAMP_FREQUENCY; // Use the bmpman function for this. That also ensures that APNG cursors work correctly auto frameIndex = static_cast<size_t>(bm_get_anim_frame(mBitmapHandle, diffSeconds, 0.0f, true)); Assert(frameIndex < mAnimationFrames.size()); if (mLastFrame != frameIndex) { SDL_SetCursor(mAnimationFrames[frameIndex]); mLastFrame = frameIndex; } } }
// hud_calculate_lock_position() will determine where on the screen to draw the lock // indicator, and will determine when a lock has occurred. If the lock indicator is not // on the screen yet, hud_calculate_lock_start_pos() is called to pick a starting location void hud_calculate_lock_position(float frametime) { ship_weapon *swp; weapon_info *wip; static float pixels_moved_while_locking; static float pixels_moved_while_degrading; static int Need_new_start_pos = 0; static double accumulated_x_pixels, accumulated_y_pixels; double int_portion; static float last_dist_to_target; static int catching_up; static int maintain_lock_count = 0; static float catch_up_distance = 0.0f; double hypotenuse, delta_x, delta_y; swp = &Player_ship->weapons; wip = &Weapon_info[swp->secondary_bank_weapons[swp->current_secondary_bank]]; if (Player->target_in_lock_cone) { if (!Players[Player_num].lock_indicator_visible) { hud_calculate_lock_start_pos(); last_dist_to_target = 0.0f; Players[Player_num].lock_indicator_x = Players[Player_num].lock_indicator_start_x; Players[Player_num].lock_indicator_y = Players[Player_num].lock_indicator_start_y; Players[Player_num].lock_indicator_visible = 1; Players[Player_num].lock_time_to_target = i2fl(wip->min_lock_time); catching_up = 0; } Need_new_start_pos = 1; if (Player_ai->current_target_is_locked) { Players[Player_num].lock_indicator_x = Player->current_target_sx; Players[Player_num].lock_indicator_y = Player->current_target_sy; return; } delta_x = Players[Player_num].lock_indicator_x - Player->current_target_sx; delta_y = Players[Player_num].lock_indicator_y - Player->current_target_sy; if (!delta_y && !delta_x) { hypotenuse = 0.0f; } else { hypotenuse = _hypot(delta_y, delta_x); } Players[Player_num].lock_dist_to_target = (float)hypotenuse; if (last_dist_to_target == 0) { last_dist_to_target = Players[Player_num].lock_dist_to_target; } //nprintf(("Alan","dist to target: %.2f\n",Players[Player_num].lock_dist_to_target)); //nprintf(("Alan","last to target: %.2f\n\n",last_dist_to_target)); if (catching_up) { //nprintf(("Alan","IN CATCH UP MODE catch_up_dist is %.2f\n",catch_up_distance)); if ( Players[Player_num].lock_dist_to_target < catch_up_distance ) catching_up = 0; } else { //nprintf(("Alan","IN NORMAL MODE\n")); if ( (Players[Player_num].lock_dist_to_target - last_dist_to_target) > 2.0f ) { catching_up = 1; catch_up_distance = last_dist_to_target + wip->catchup_pixel_penalty; } } last_dist_to_target = Players[Player_num].lock_dist_to_target; if (!catching_up) { Players[Player_num].lock_time_to_target -= frametime; if (Players[Player_num].lock_time_to_target < 0.0f) Players[Player_num].lock_time_to_target = 0.0f; } float lock_pixels_per_sec; if (Players[Player_num].lock_time_to_target > 0) { lock_pixels_per_sec = Players[Player_num].lock_dist_to_target / Players[Player_num].lock_time_to_target; } else { lock_pixels_per_sec = i2fl(wip->lock_pixels_per_sec); } if (lock_pixels_per_sec > wip->lock_pixels_per_sec) { lock_pixels_per_sec = i2fl(wip->lock_pixels_per_sec); } if (catching_up) { pixels_moved_while_locking = wip->catchup_pixels_per_sec * frametime; } else { pixels_moved_while_locking = lock_pixels_per_sec * frametime; } if (delta_x != 0) { accumulated_x_pixels += pixels_moved_while_locking * delta_x/hypotenuse; } if (delta_y != 0) { accumulated_y_pixels += pixels_moved_while_locking * delta_y/hypotenuse; } if (fl_abs(accumulated_x_pixels) > 1.0f) { modf(accumulated_x_pixels, &int_portion); Players[Player_num].lock_indicator_x -= (int)int_portion; if ( fl_abs(Players[Player_num].lock_indicator_x - Player->current_target_sx) < fl_abs(int_portion) ) Players[Player_num].lock_indicator_x = Player->current_target_sx; accumulated_x_pixels -= int_portion; } if (fl_abs(accumulated_y_pixels) > 1.0f) { modf(accumulated_y_pixels, &int_portion); Players[Player_num].lock_indicator_y -= (int)int_portion; if ( fl_abs(Players[Player_num].lock_indicator_y - Player->current_target_sy) < fl_abs(int_portion) ) Players[Player_num].lock_indicator_y = Player->current_target_sy; accumulated_y_pixels -= int_portion; } if ( Missile_track_loop == -1 ) { Missile_track_loop = snd_play_looping( &Snds[SND_MISSILE_TRACKING], 0.0f , -1, -1); } if (!Players[Player_num].lock_time_to_target) { if ( (Players[Player_num].lock_indicator_x == Player->current_target_sx) && (Players[Player_num].lock_indicator_y == Player->current_target_sy) ) { if (maintain_lock_count++ > 1) { Player_ai->current_target_is_locked = 1; } } else { maintain_lock_count = 0; } } } else { if ( Missile_track_loop > -1 ) { snd_chg_loop_status(Missile_track_loop, 0); Missile_track_loop = -1; } Player_ai->current_target_is_locked = 0; if (!Players[Player_num].lock_indicator_visible) { return; } catching_up = 0; last_dist_to_target = 0.0f; if (Need_new_start_pos) { hud_calculate_lock_start_pos(); Need_new_start_pos = 0; accumulated_x_pixels = 0.0f; accumulated_y_pixels = 0.0f; } delta_x = Players[Player_num].lock_indicator_x - Players[Player_num].lock_indicator_start_x; delta_y = Players[Player_num].lock_indicator_y - Players[Player_num].lock_indicator_start_y; if (!delta_y && !delta_x) { hypotenuse = 0.0f; } else { hypotenuse = _hypot(delta_y, delta_x); } Players[Player_num].lock_time_to_target += frametime; if (Players[Player_num].lock_time_to_target > wip->min_lock_time) Players[Player_num].lock_time_to_target = i2fl(wip->min_lock_time); pixels_moved_while_degrading = 2.0f * wip->lock_pixels_per_sec * frametime; if (delta_x != 0) accumulated_x_pixels += pixels_moved_while_degrading * delta_x/hypotenuse; if (delta_y != 0) accumulated_y_pixels += pixels_moved_while_degrading * delta_y/hypotenuse; if (fl_abs(accumulated_x_pixels) > 1.0f) { modf(accumulated_x_pixels, &int_portion); Players[Player_num].lock_indicator_x -= (int)int_portion; if ( fl_abs(Players[Player_num].lock_indicator_x - Players[Player_num].lock_indicator_start_x) < fl_abs(int_portion) ) Players[Player_num].lock_indicator_x = Players[Player_num].lock_indicator_start_x; accumulated_x_pixels -= int_portion; } if (fl_abs(accumulated_y_pixels) > 1.0f) { modf(accumulated_y_pixels, &int_portion); Players[Player_num].lock_indicator_y -= (int)int_portion; if ( fl_abs(Players[Player_num].lock_indicator_y - Players[Player_num].lock_indicator_start_y) < fl_abs(int_portion) ) Players[Player_num].lock_indicator_y = Players[Player_num].lock_indicator_start_y; accumulated_y_pixels -= int_portion; } if ( (Players[Player_num].lock_indicator_x == Players[Player_num].lock_indicator_start_x) && (Players[Player_num].lock_indicator_y == Players[Player_num].lock_indicator_start_y) ) { Players[Player_num].lock_indicator_visible = 0; } } }
void credits_init() { int i; credits_screen_buttons *b; // pre-initialize Credits_num_images = DEFAULT_NUM_IMAGES; Credits_artwork_index = -1; // this is moved up here so we can override it if desired strcpy_s(Credits_music_name, "Cinema"); // parse credits early so as to set up any overrides (for music and such) Credits_parsed = false; credits_parse(); // we could conceivably have specified a number of images but not an index, // so if that's the case, set the value here if (Credits_artwork_index < 0) { Credits_artwork_index = rand() % Credits_num_images; } int credits_spooled_music_index = event_music_get_spooled_music_index(Credits_music_name); if(credits_spooled_music_index != -1){ char *credits_wavfile_name = Spooled_music[credits_spooled_music_index].filename; if(credits_wavfile_name != NULL){ credits_load_music(credits_wavfile_name); } } // Use this id to trigger the start of music playing on the briefing screen Credits_music_begin_timestamp = timestamp(Credits_music_delay); Credits_frametime = 0; Credits_last_time = timer_get_milliseconds(); if (!Credits_parsed) { Credit_text_parts.push_back(SCP_string("No credits available.\n")); } else { switch (SCP_credits_position) { case START: Credit_text_parts.insert(Credit_text_parts.begin(), fs2_open_credit_text); break; case END: Credit_text_parts.push_back(fs2_open_credit_text); break; default: Error(LOCATION, "Unimplemented credits position %d. Get a coder!", (int) SCP_credits_position); break; } } int ch; SCP_vector<SCP_string>::iterator iter; for (iter = Credit_text_parts.begin(); iter != Credit_text_parts.end(); ++iter) { for (SCP_string::iterator ii = iter->begin(); ii != iter->end(); ++ii) { ch = *ii; switch (ch) { case -4: ch = 129; break; case -28: ch = 132; break; case -10: ch = 148; break; case -23: ch = 130; break; case -30: ch = 131; break; case -25: ch = 135; break; case -21: ch = 137; break; case -24: ch = 138; break; case -17: ch = 139; break; case -18: ch = 140; break; case -60: ch = 142; break; case -55: ch = 144; break; case -12: ch = 147; break; case -14: ch = 149; break; case -5: ch = 150; break; case -7: ch = 151; break; case -42: ch = 153; break; case -36: ch = 154; break; case -31: ch = 160; break; case -19: ch = 161; break; case -13: ch = 162; break; case -6: ch = 163; break; case -32: ch = 133; break; case -22: ch = 136; break; case -20: ch = 141; break; } *ii = (char) ch; } } int temp_h; int h = 0; for (iter = Credit_text_parts.begin(); iter != Credit_text_parts.end(); ++iter) { gr_get_string_size(NULL, &temp_h, iter->c_str(), (int)iter->length()); h = h + temp_h; } Credit_start_pos = i2fl(Credits_text_coords[gr_screen.res][CREDITS_H_COORD]); Credit_stop_pos = -i2fl(h); Credit_position = Credit_start_pos; Ui_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0); Ui_window.set_mask_bmap(Credits_bitmap_mask_fname[gr_screen.res]); common_set_interface_palette("InterfacePalette"); // set the interface palette for (i=0; i<NUM_BUTTONS; i++) { b = &Buttons[i][gr_screen.res]; b->button.create(&Ui_window, "", b->x, b->y, 60, 30, (i < 2), 1); // set up callback for when a mouse first goes over a button b->button.set_highlight_action(common_play_highlight_sound); b->button.set_bmaps(b->filename); b->button.link_hotspot(b->hotspot); } // add some text Ui_window.add_XSTR("Technical Database", 1055, Buttons[TECH_DATABASE_BUTTON][gr_screen.res].xt, Buttons[TECH_DATABASE_BUTTON][gr_screen.res].yt, &Buttons[TECH_DATABASE_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN); Ui_window.add_XSTR("Mission Simulator", 1056, Buttons[SIMULATOR_BUTTON][gr_screen.res].xt, Buttons[SIMULATOR_BUTTON][gr_screen.res].yt, &Buttons[SIMULATOR_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN); Ui_window.add_XSTR("Cutscenes", 1057, Buttons[CUTSCENES_BUTTON][gr_screen.res].xt, Buttons[CUTSCENES_BUTTON][gr_screen.res].yt, &Buttons[CUTSCENES_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN); Ui_window.add_XSTR("Credits", 1058, Buttons[CREDITS_BUTTON][gr_screen.res].xt, Buttons[CREDITS_BUTTON][gr_screen.res].yt, &Buttons[CREDITS_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_GREEN); Ui_window.add_XSTR("Exit", 1420, Buttons[EXIT_BUTTON][gr_screen.res].xt, Buttons[EXIT_BUTTON][gr_screen.res].yt, &Buttons[EXIT_BUTTON][gr_screen.res].button, UI_XSTR_COLOR_PINK); if (Player->flags & PLAYER_FLAGS_IS_MULTI) { Buttons[SIMULATOR_BUTTON][gr_screen.res].button.disable(); Buttons[CUTSCENES_BUTTON][gr_screen.res].button.disable(); } Buttons[EXIT_BUTTON][gr_screen.res].button.set_hotkey(KEY_CTRLED | KEY_ENTER); Background_bitmap = bm_load(Credits_bitmap_fname[gr_screen.res]); Credits_bmps.resize(Credits_num_images); for (i=0; i<Credits_num_images; i++) { Credits_bmps[i] = -1; } }
//clips an edge against one plane. vertex *clip_edge(int plane_flag,vertex *on_pnt,vertex *off_pnt, uint flags) { float ratio; vertex *tmp; tmp = get_temp_point(); if ( plane_flag & CC_OFF_USER ) { // Clip with user-defined plane vector w, ray_direction; float num,den; vm_vec_sub(&ray_direction,(vector *)&off_pnt->x,(vector *)&on_pnt->x); vm_vec_sub(&w,(vector *)&on_pnt->x,&G3_user_clip_point); den = -vm_vec_dot(&G3_user_clip_normal,&ray_direction); if ( den == 0.0f ) { // Ray & plane are parallel, so there is no intersection Int3(); // Get John ratio = 1.0f; } else { num = vm_vec_dot(&G3_user_clip_normal,&w); ratio = num / den; } tmp->x = on_pnt->x + (off_pnt->x-on_pnt->x) * ratio; tmp->y = on_pnt->y + (off_pnt->y-on_pnt->y) * ratio; tmp->z = on_pnt->z + (off_pnt->z-on_pnt->z) * ratio; } else { float a,b,kn,kd; //compute clipping value k = (xs-zs) / (xs-xe-zs+ze) //use x or y as appropriate, and negate x/y value as appropriate if (plane_flag & (CC_OFF_RIGHT | CC_OFF_LEFT)) { a = on_pnt->x; b = off_pnt->x; } else { a = on_pnt->y; b = off_pnt->y; } if (plane_flag & (CC_OFF_LEFT | CC_OFF_BOT)) { a = -a; b = -b; } kn = a - on_pnt->z; //xs-zs kd = kn - b + off_pnt->z; //xs-zs-xe+ze ratio = kn / kd; tmp->x = on_pnt->x + (off_pnt->x-on_pnt->x) * ratio; tmp->y = on_pnt->y + (off_pnt->y-on_pnt->y) * ratio; if (plane_flag & (CC_OFF_TOP|CC_OFF_BOT)) { tmp->z = tmp->y; } else { tmp->z = tmp->x; } if (plane_flag & (CC_OFF_LEFT|CC_OFF_BOT)) tmp->z = -tmp->z; } if (flags & TMAP_FLAG_TEXTURED) { tmp->u = on_pnt->u + (off_pnt->u-on_pnt->u) * ratio; tmp->v = on_pnt->v + (off_pnt->v-on_pnt->v) * ratio; tmp->env_u = on_pnt->env_u + (off_pnt->env_u-on_pnt->env_u) * ratio; tmp->env_v = on_pnt->env_v + (off_pnt->env_v-on_pnt->env_v) * ratio; } if (flags & TMAP_FLAG_GOURAUD ) { if (flags & TMAP_FLAG_RAMP) { float on_b, off_b; on_b = i2fl(on_pnt->b); off_b = i2fl(off_pnt->b); tmp->b = ubyte(fl2i(on_b + (off_b-on_b) * ratio)); } if (flags & TMAP_FLAG_RGB) { float on_r, on_b, on_g, onspec_r, onspec_g, onspec_b; float off_r, off_b, off_g, offspec_r, offspec_g, offspec_b; on_r = i2fl(on_pnt->r); off_r = i2fl(off_pnt->r); on_g = i2fl(on_pnt->g); off_g = i2fl(off_pnt->g); on_b = i2fl(on_pnt->b); off_b = i2fl(off_pnt->b); onspec_r = i2fl(on_pnt->spec_r); offspec_r = i2fl(off_pnt->spec_r); onspec_g = i2fl(on_pnt->spec_g); offspec_g = i2fl(off_pnt->spec_g); onspec_b = i2fl(on_pnt->spec_b); offspec_b = i2fl(off_pnt->spec_b); tmp->r = ubyte(fl2i(on_r + (off_r-on_r) * ratio)); tmp->g = ubyte(fl2i(on_g + (off_g-on_g) * ratio)); tmp->b = ubyte(fl2i(on_b + (off_b-on_b) * ratio)); tmp->spec_r = ubyte(fl2i(onspec_r + (offspec_r-onspec_r) * ratio)); tmp->spec_g = ubyte(fl2i(onspec_g + (offspec_g-onspec_g) * ratio)); tmp->spec_b = ubyte(fl2i(onspec_b + (offspec_b-onspec_b) * ratio)); } } else { tmp->spec_r=tmp->spec_g=tmp->spec_b=0; } if (flags & TMAP_FLAG_ALPHA) { float on_a, off_a; on_a = i2fl(on_pnt->a); off_a = i2fl(off_pnt->a); tmp->a = ubyte(fl2i(on_a + (off_a-on_a) * ratio)); } g3_code_vertex(tmp); return tmp; }
// ------------------------------------------------------------------ // swarm_update_direction() // // Check if we want to update the direction of a swarm missile. // void swarm_update_direction(object *objp, float frametime) { weapon_info *wip; weapon *wp; object *hobjp; swarm_info *swarmp; vec3d obj_to_target; float vel, target_dist, radius, missile_speed, missile_dist; physics_info *pi; Assert(objp->instance >= 0 && objp->instance < MAX_WEAPONS); wp = &Weapons[objp->instance]; if (wp->swarm_index == -1) { return; } wip = &Weapon_info[wp->weapon_info_index]; hobjp = wp->homing_object; pi = &Objects[wp->objnum].phys_info; swarmp = &Swarm_missiles[wp->swarm_index]; // check if homing is lost.. if it is then get a new path to move swarm missile along if ( swarmp->homing_objnum != -1 && hobjp == &obj_used_list ) { swarmp->change_timestamp = 1; swarmp->path_num = -1; swarmp->homing_objnum = -1; } if ( hobjp != &obj_used_list ) { swarmp->homing_objnum = OBJ_INDEX(hobjp); } if ( timestamp_elapsed(swarmp->change_timestamp) ) { if ( swarmp->path_num == -1 ) { if ( Objects[objp->parent].type != OBJ_SHIP ) { //AL: parent ship died... so just pick some random paths swarmp->path_num = myrand()%4; } else { ship *parent_shipp; parent_shipp = &Ships[Objects[objp->parent].instance]; swarmp->path_num = (parent_shipp->next_swarm_path++)%4; if ( parent_shipp->next_swarm_path%4 == 0 ) { swarmp->flags ^= SWARM_POSITIVE_PATH; } } vm_vec_scale_add(&swarmp->original_target, &objp->pos, &objp->orient.vec.fvec, SWARM_CONE_LENGTH); swarmp->circle_rvec = objp->orient.vec.rvec; swarmp->circle_uvec = objp->orient.vec.uvec; swarmp->change_count = 1; swarmp->change_time = fl2i(SWARM_CHANGE_DIR_TIME + SWARM_TIME_VARIANCE*(frand() - 0.5f) * 2); vm_vec_zero(&swarmp->last_offset); missile_speed = pi->speed; missile_dist = missile_speed * swarmp->change_time/1000.0f; if ( missile_dist < SWARM_DIST_OFFSET ) { missile_dist=i2fl(SWARM_DIST_OFFSET); } swarmp->angle_offset = (float)(asin(SWARM_DIST_OFFSET / missile_dist)); Assert(!_isnan(swarmp->angle_offset) ); } swarmp->change_timestamp = timestamp(swarmp->change_time); // check if swarm missile is homing, if so need to calculate a new target pos to turn towards if ( hobjp != &obj_used_list && f2fl(Missiontime - wp->creation_time) > 0.5f && ( f2fl(Missiontime - wp->creation_time) > wip->free_flight_time ) ) { swarmp->original_target = wp->homing_pos; // Calculate a rvec and uvec that will determine the displacement from the // intended target. Use crossprod to generate a right vector, from the missile // up vector and the vector connecting missile to the homing object. swarmp->circle_uvec = objp->orient.vec.uvec; swarmp->circle_rvec = objp->orient.vec.rvec; missile_speed = pi->speed; missile_dist = missile_speed * swarmp->change_time/1000.0f; if ( missile_dist < SWARM_DIST_OFFSET ) { missile_dist = i2fl(SWARM_DIST_OFFSET); } swarmp->angle_offset = (float)(asin(SWARM_DIST_OFFSET / missile_dist)); Assert(!_isnan(swarmp->angle_offset) ); } vm_vec_sub(&obj_to_target, &swarmp->original_target, &objp->pos); target_dist = vm_vec_mag_quick(&obj_to_target); swarmp->last_dist = target_dist; // If homing swarm missile is close to target, let missile home in on original target if ( target_dist < SWARM_DIST_STOP_SWARMING ) { swarmp->new_target = swarmp->original_target; goto swarm_new_target_calced; } radius = (float)tan(swarmp->angle_offset) * target_dist; vec3d rvec_component, uvec_component; swarmp->change_count++; if ( swarmp->change_count > 2 ) { swarmp->flags ^= SWARM_POSITIVE_PATH; swarmp->change_count = 0; } // pick a new path number to follow once at center if ( swarmp->change_count == 1 ) { swarmp->path_num = swarmp->path_num + myrand()%3; if ( swarmp->path_num > 3 ) { swarmp->path_num = 0; } } vm_vec_zero(&rvec_component); vm_vec_zero(&uvec_component); switch ( swarmp->path_num ) { case 0: // straight up and down if ( swarmp->flags & SWARM_POSITIVE_PATH ) vm_vec_copy_scale( &uvec_component, &swarmp->circle_uvec, radius); else vm_vec_copy_scale( &uvec_component, &swarmp->circle_uvec, -radius); break; case 1: // left/right if ( swarmp->flags & SWARM_POSITIVE_PATH ) vm_vec_copy_scale( &rvec_component, &swarmp->circle_rvec, radius); else vm_vec_copy_scale( &rvec_component, &swarmp->circle_rvec, -radius); break; case 2: // top/right - bottom/left if ( swarmp->flags & SWARM_POSITIVE_PATH ) { vm_vec_copy_scale( &rvec_component, &swarmp->circle_rvec, radius); vm_vec_copy_scale( &uvec_component, &swarmp->circle_uvec, radius); } else { vm_vec_copy_scale( &rvec_component, &swarmp->circle_rvec, -radius); vm_vec_copy_scale( &uvec_component, &swarmp->circle_uvec, -radius); } break; case 3: // top-left - bottom/right if ( swarmp->flags & SWARM_POSITIVE_PATH ) { vm_vec_copy_scale( &rvec_component, &swarmp->circle_rvec, -radius); vm_vec_copy_scale( &uvec_component, &swarmp->circle_uvec, radius); } else { vm_vec_copy_scale( &rvec_component, &swarmp->circle_rvec, radius); vm_vec_copy_scale( &uvec_component, &swarmp->circle_uvec, -radius); } break; default: Int3(); break; } swarmp->new_target = swarmp->original_target; vm_vec_zero(&swarmp->last_offset); vm_vec_add(&swarmp->last_offset, &uvec_component, &rvec_component); vm_vec_add2(&swarmp->new_target, &swarmp->last_offset); } else { if ( hobjp != &obj_used_list && f2fl(Missiontime - wp->creation_time) > 0.5f ) { swarmp->new_target = swarmp->original_target; if ( swarmp->last_dist < SWARM_DIST_STOP_SWARMING ) { swarmp->new_target = wp->homing_pos; goto swarm_new_target_calced; } vm_vec_add2(&swarmp->new_target, &swarmp->last_offset); } } swarm_new_target_calced: ai_turn_towards_vector(&swarmp->new_target, objp, frametime, wip->turn_time, NULL, NULL, 0.0f, 0); vel = vm_vec_mag(&objp->phys_info.desired_vel); vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, vel); }
void credits_do_frame(float frametime) { GR_DEBUG_SCOPE("Credits do frame"); int i, k, next, percent, bm1, bm2; int bx1, by1, bw1, bh1; int bx2, by2, bw2, bh2; // Use this id to trigger the start of music playing on the credits screen if ( timestamp_elapsed(Credits_music_begin_timestamp) ) { Credits_music_begin_timestamp = 0; credits_start_music(); } k = Ui_window.process(); switch (k) { case KEY_ESC: gameseq_post_event(GS_EVENT_MAIN_MENU); key_flush(); break; case KEY_CTRLED | KEY_UP: case KEY_SHIFTED | KEY_TAB: if ( !(Player->flags & PLAYER_FLAGS_IS_MULTI) ) { credits_screen_button_pressed(CUTSCENES_BUTTON); break; } // else, react like tab key. case KEY_CTRLED | KEY_DOWN: case KEY_TAB: credits_screen_button_pressed(TECH_DATABASE_BUTTON); break; default: break; } // end switch for (i=0; i<NUM_BUTTONS; i++){ if (Buttons[i][gr_screen.res].button.pressed()){ if (credits_screen_button_pressed(i)){ return; } } } gr_reset_clip(); GR_MAYBE_CLEAR_RES(Background_bitmap); if (Background_bitmap >= 0) { gr_set_bitmap(Background_bitmap); gr_bitmap(0, 0, GR_RESIZE_MENU); } percent = (int) (100.0f - (Credits_artwork_display_time - Credits_counter) * 100.0f / Credits_artwork_fade_time); if (percent < 0){ percent = 0; } next = Credits_artwork_index + 1; if (next >= Credits_num_images){ next = 0; } if (Credits_bmps[Credits_artwork_index] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), Credits_artwork_index); } else { sprintf(buf, NOX("CrIm%.2d"), Credits_artwork_index); } Credits_bmps[Credits_artwork_index] = bm_load(buf); } if (Credits_bmps[next] < 0) { char buf[40]; if (gr_screen.res == GR_1024) { sprintf(buf, NOX("2_CrIm%.2d"), next); } else { sprintf(buf, NOX("CrIm%.2d"), next); } Credits_bmps[next] = bm_load(buf); } bm1 = Credits_bmps[Credits_artwork_index]; bm2 = Credits_bmps[next]; if((bm1 != -1) && (bm2 != -1)){ GR_DEBUG_SCOPE("Render credits bitmap"); Assert(percent >= 0 && percent <= 100); // get width and height bm_get_info(bm1, &bw1, &bh1, NULL, NULL, NULL); bm_get_info(bm2, &bw2, &bh2, NULL, NULL, NULL); // determine where to draw the coords bx1 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw1)/2); by1 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh1)/2); bx2 = Credits_image_coords[gr_screen.res][CREDITS_X_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_W_COORD] - bw2)/2); by2 = Credits_image_coords[gr_screen.res][CREDITS_Y_COORD] + ((Credits_image_coords[gr_screen.res][CREDITS_H_COORD] - bh2)/2); auto alpha = (float)percent / 100.0f; gr_set_bitmap(bm1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - alpha); gr_bitmap(bx1, by1, GR_RESIZE_MENU); gr_set_bitmap(bm2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha); gr_bitmap(bx2, by2, GR_RESIZE_MENU); } Ui_window.draw(); for (i=TECH_DATABASE_BUTTON; i<=CREDITS_BUTTON; i++){ if (Buttons[i][gr_screen.res].button.button_down()){ break; } } if (i > CREDITS_BUTTON){ Buttons[CREDITS_BUTTON][gr_screen.res].button.draw_forced(2); } gr_set_clip(Credits_text_coords[gr_screen.res][CREDITS_X_COORD], Credits_text_coords[gr_screen.res][CREDITS_Y_COORD], Credits_text_coords[gr_screen.res][CREDITS_W_COORD], Credits_text_coords[gr_screen.res][CREDITS_H_COORD], GR_RESIZE_MENU); font::set_font(font::FONT1); gr_set_color_fast(&Color_normal); int y_offset = 0; for (SCP_vector<SCP_string>::iterator iter = Credit_text_parts.begin(); iter != Credit_text_parts.end(); ++iter) { size_t currentPos = 0; size_t lineEnd; do { int height; int width; lineEnd = iter->find('\n', currentPos); auto length = lineEnd - currentPos; if (lineEnd == SCP_string::npos) { length = std::numeric_limits<size_t>::max(); } gr_get_string_size(&width, &height, iter->c_str() + currentPos, static_cast<int>(length)); // Check if the text part is actually visible if (Credit_position + y_offset + height > 0.0f) { float x = static_cast<float>((gr_screen.clip_width_unscaled - width) / 2); gr_string(x, Credit_position + y_offset, iter->c_str() + currentPos, GR_RESIZE_MENU, static_cast<int>(length)); } y_offset += height; currentPos = lineEnd + 1; } while (lineEnd < iter->length() && lineEnd != SCP_string::npos); } int temp_time; temp_time = timer_get_milliseconds(); Credits_frametime = temp_time - Credits_last_time; Credits_last_time = temp_time; timestamp_inc(i2f(Credits_frametime) / TIMESTAMP_FREQUENCY); float fl_frametime = i2fl(Credits_frametime) / 1000.f; if (keyd_pressed[KEY_LSHIFT]) { Credit_position -= fl_frametime * Credits_scroll_rate * 4.0f; } else { Credit_position -= fl_frametime * Credits_scroll_rate; } if (Credit_position < Credit_stop_pos){ Credit_position = Credit_start_pos; } Credits_counter += fl_frametime; while (Credits_counter >= Credits_artwork_display_time) { Credits_counter -= Credits_artwork_display_time; Credits_artwork_index = next; } gr_flip(); }
void radar_plot_object( object *objp ) { vector pos, tempv; float dist, rscale, zdist, max_radar_dist; int xpos, ypos, color=0; vector *world_pos = &objp->pos; float awacs_level; // don't process anything here. Somehow, a jumpnode object caused this function // to get entered on server side. if( Game_mode & GM_STANDALONE_SERVER ){ return; } // multiplayer clients ingame joining should skip this function if ( MULTIPLAYER_CLIENT && (Net_player->flags & NETINFO_FLAG_INGAME_JOIN) ){ return; } // get team-wide awacs level for the object if not ship int ship_is_visible = 0; if (objp->type == OBJ_SHIP) { if (Player_ship != NULL) { if (ship_is_visible_by_team(objp->instance, Player_ship->team)) { ship_is_visible = 1; } } } // only check awacs level if ship is not visible by team awacs_level = 1.5f; if (Player_ship != NULL && !ship_is_visible) { awacs_level = awacs_get_level(objp, Player_ship); } // if the awacs level is unviewable - bail if(awacs_level < 0.0f && !See_all){ return; } // Apply object type filters switch ( objp->type ) { case OBJ_SHIP: // Place to cull ships, such as NavBuoys break; case OBJ_JUMP_NODE: // filter jump nodes here if required break; case OBJ_WEAPON: { // if not a bomb, return if ( !(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_BOMB) ) { return; } // if bomb is on same team as player, return if ( (obj_team(objp) == Player_ship->team) && (Player_ship->team != TEAM_TRAITOR) ) { return; } break; } default: return; // if any other kind of object, don't want to show on radar break; } // end switch // JAS -- new way of getting the rotated point that doesn't require this to be // in a g3_start_frame/end_frame block. vm_vec_sub(&tempv,world_pos,&Player_obj->pos); vm_vec_rotate( &pos, &tempv, &Player_obj->orient ); // Apply range filter dist = vm_vec_dist(world_pos, &Player_obj->pos); max_radar_dist = Radar_ranges[HUD_config.rp_dist]; if ( dist > max_radar_dist ){ return; } if ( dist < pos.xyz.z ) { rscale = 0.0f; } else { rscale = (float) acos( pos.xyz.z/dist ) / 3.14159f; //2.0f; } zdist = fl_sqrt( (pos.xyz.x*pos.xyz.x)+(pos.xyz.y*pos.xyz.y) ); float new_x_dist, clipped_x_dist; float new_y_dist, clipped_y_dist; if (zdist < 0.01f ) { new_x_dist = 0.0f; new_y_dist = 0.0f; } else { new_x_dist = (pos.xyz.x/zdist) * rscale * radx; new_y_dist = (pos.xyz.y/zdist) * rscale * rady; // force new_x_dist and new_y_dist to be inside the radar float hypotenuse; float max_radius; hypotenuse = (float)_hypot(new_x_dist, new_y_dist); max_radius = i2fl(Radar_radius[gr_screen.res][0] - 5); if (hypotenuse >= (max_radius) ) { clipped_x_dist = max_radius * (new_x_dist / hypotenuse); clipped_y_dist = max_radius * (new_y_dist / hypotenuse); new_x_dist = clipped_x_dist; new_y_dist = clipped_y_dist; } } xpos = fl2i( Radar_center[gr_screen.res][0] + new_x_dist ); ypos = fl2i( Radar_center[gr_screen.res][1] - new_y_dist ); color = radar_blip_color(objp); // Determine the distance at which we will dim the radar blip if ( timestamp_elapsed(Radar_calc_dim_dist_timer) ) { Radar_calc_dim_dist_timer=timestamp(1000); Radar_dim_range = player_farthest_weapon_range(); if ( Radar_dim_range <= 0 ) { Radar_dim_range=1500.0f; } } blip *b; int blip_dim=0; if ( dist > Radar_dim_range ) { blip_dim=1; } if ( N_blips >= MAX_BLIPS ) { // out of blips, don't plot Int3(); return; } b = &Blips[N_blips]; b->flags=0; // flag the blip as a current target if it is if (OBJ_INDEX(objp) == Player_ai->target_objnum) { b->flags |= BLIP_CURRENT_TARGET; blip_dim = 0; } if ( blip_dim ) { list_append( &Blip_dim_list[color], b ); } else { list_append( &Blip_bright_list[color], b ); } b->x = xpos; b->y = ypos; // see if blip should be drawn distorted if (objp->type == OBJ_SHIP) { // ships specifically hidden from sensors if ( Ships[objp->instance].flags & SF_HIDDEN_FROM_SENSORS ) { b->flags |= BLIP_DRAW_DISTORTED; } // determine if its AWACS distorted if ( awacs_level < 1.0f ){ b->flags |= BLIP_DRAW_DISTORTED; } } N_blips++; }