void obj_sort_and_collide() { if (Cmdline_dis_collisions) return; if ( !(Game_detail_flags & DETAIL_FLAG_COLLISION) ) return; SCP_vector<int> sort_list_y; SCP_vector<int> sort_list_z; sort_list_y.clear(); { TRACE_SCOPE(tracing::SortColliders); obj_quicksort_colliders(&Collision_sort_list, 0, (int)(Collision_sort_list.size() - 1), 0); } obj_find_overlap_colliders(&sort_list_y, &Collision_sort_list, 0, false); sort_list_z.clear(); { TRACE_SCOPE(tracing::SortColliders); obj_quicksort_colliders(&sort_list_y, 0, (int)(sort_list_y.size() - 1), 1); } obj_find_overlap_colliders(&sort_list_z, &sort_list_y, 1, false); sort_list_y.clear(); { TRACE_SCOPE(tracing::SortColliders); obj_quicksort_colliders(&sort_list_z, 0, (int)(sort_list_z.size() - 1), 2); } obj_find_overlap_colliders(&sort_list_y, &sort_list_z, 2, true); }
// Pages in all the texutures for the currently // loaded mission. Call game_busy() occasionally... void level_page_in() { TRACE_SCOPE(tracing::LevelPageIn); // Most important ones first game_busy( NOX("*** paging in ships ***") ); ship_page_in(); //Must be called after paging in ships game_busy( NOX("*** paging in weapons ***") ); weapons_page_in(); game_busy( NOX("*** paging in various effects ***") ); fireballs_page_in(); particle::page_in(); debris_page_in(); hud_page_in(); stars_page_in(); shockwave_page_in(); shield_hit_page_in(); asteroid_page_in(); neb2_page_in(); mflash_page_in(false); // just so long as it happens after weapons_page_in() // preload mission messages if NOT running low-memory (greater than 48MB) if (game_using_low_mem() == false) { message_pagein_mission_messages(); } if(!(Game_mode & GM_STANDALONE_SERVER)){ model_page_in_stop(); // free any loaded models that aren't used bm_page_in_stop(); } mprintf(( "Ending level bitmap paging...\n" )); }
void gr_opengl_flip() { if ( !GL_initted ) return; TRACE_SCOPE(tracing::PageFlip); gr_reset_clip(); mouse_reset_deltas(); if (Cmdline_gl_finish) glFinish(); current_viewport->swapBuffers(); opengl_tcache_frame(); #ifndef NDEBUG int ic = opengl_check_for_errors(); if (ic) { mprintf(("!!DEBUG!! OpenGL Errors this frame: %i\n", ic)); } #endif }
void obj_find_overlap_colliders(SCP_vector<int> *overlap_list_out, SCP_vector<int> *list, int axis, bool collide) { TRACE_SCOPE(tracing::FindOverlapColliders); size_t i, j; bool overlapped; bool first_not_added = true; SCP_vector<int> overlappers; float min; float overlap_max; overlappers.clear(); for ( i = 0; i < (*list).size(); ++i ) { overlapped = false; min = obj_get_collider_endpoint((*list)[i], axis, true); for ( j = 0; j < overlappers.size(); ) { overlap_max = obj_get_collider_endpoint(overlappers[j], axis, false); if ( min <= overlap_max ) { overlapped = true; if ( overlappers.size() == 1 && first_not_added ) { first_not_added = false; overlap_list_out->push_back(overlappers[j]); } if ( collide ) { obj_collide_pair(&Objects[(*list)[i]], &Objects[overlappers[j]]); } } else { overlappers[j] = overlappers.back(); overlappers.pop_back(); continue; } ++j; } if ( overlappers.empty() ) { first_not_added = true; } if ( overlapped ) { overlap_list_out->push_back((*list)[i]); } overlappers.push_back((*list)[i]); } overlapped = true; }
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; } }
void * thread_func ( void * ) #endif { TRACE_SCOPE(trace::e_Info, trace::CTX_Default); while (!g_Quit) { static int i = 0; ++i; TRACE_MSG(trace::e_Info, trace::CTX_Default, "Thread tick i=%u", i); sleep_ms(100); } return 0; }
void batching_render_all(bool render_distortions) { GR_DEBUG_SCOPE("Batching render all"); TRACE_SCOPE(tracing::DrawEffects); batching_load_buffers(render_distortions); SCP_map<batch_buffer_key, primitive_batch_buffer>::iterator bi; for ( bi = Batching_buffers.begin(); bi != Batching_buffers.end(); ++bi ) { batching_render_buffer(&bi->second); } gr_clear_states(); }
void decal_draw_list::render() { GR_DEBUG_SCOPE("Render decals"); TRACE_SCOPE(tracing::RenderDecals); _buffer->submitData(); std::sort(_draws.begin(), _draws.end(), decal_draw_list::sort_draws); vertex_layout layout; layout.add_vertex_component(vertex_format_data::POSITION3, sizeof(vec3d), 0); indexed_vertex_source source; source.Vbuffer_handle = box_vertex_buffer; source.Ibuffer_handle = box_index_buffer; // Bind the global data only once gr_bind_uniform_buffer(uniform_block_type::DecalGlobals, 0, sizeof(graphics::decal_globals), _buffer->bufferHandle()); gr_screen.gf_start_decal_pass(); for (auto& draw : _draws) { GR_DEBUG_SCOPE("Draw single decal"); TRACE_SCOPE(tracing::RenderSingleDecal); gr_bind_uniform_buffer(uniform_block_type::DecalInfo, draw.uniform_offset, sizeof(graphics::decal_info), _buffer->bufferHandle()); gr_screen.gf_render_decals(&draw.draw_mat, PRIM_TYPE_TRIS, &layout, BOX_NUM_FACES, source); } gr_screen.gf_stop_decal_pass(); }
int main () #endif { #if defined WIN32 setvbuf(stdout, 0, _IONBF, 0); #endif TRACE_APPNAME("Simple Client"); TRACE_CONNECT(); TRACE_SCOPE(trace::e_Error, trace::CTX_Default); TRACE_MSG(trace::e_Info, trace::CTX_Default, "Text with Error inside"); { for (int i = 0; i < 64; ++i) { float x = 3.1415926535f * 2.0f / 128.0f * static_cast<float>(i); TRACE_PLOT_XY(trace::e_Info, trace::CTX_Default, x, sinf(x), "sample_plot/sin(x)"); } TRACE_MSG(trace::e_Warning, trace::CTX_Default, "first message\nsecond line"); // not sure if this is a valid case! TRACE_MSG(trace::e_Warning, trace::CTX_Game, "first game message\nsecond line"); // not sure if this is a valid case TRACE_MSG(trace::e_Error, trace::CTX_Game, "first game error\nsecond line"); TRACE_MSG(trace::e_Error, trace::CTX_Game, "second game error\nsecond line of that"); TRACE_MSG(trace::e_Warning, trace::CTX_Default, "First warning, errno=0x%08x", 0xFEEDDEAD); TRACE_MSG(trace::e_Warning, trace::CTX_Default, "Second warning, errno=0x%08x", 0xFEEDDEAD); foo(); Bar bar; ThreadPool<2> thr_pool; thr_pool.Create(thread_func, 0); for (;;) { static int i = 0; sleep_ms(200); TRACE_MSG(trace::e_Info, trace::CTX_Default, "Some message i=%u from main thread", i); TRACE_MSG(trace::e_Debug, trace::CTX_Default, "Some detailed message i=%u from main thread", i); ++i; if (i == 1000) break; } g_Quit = 1; thr_pool.WaitForTerminate(); } TRACE_DISCONNECT(); }
void batching_load_buffers(bool distortion) { GR_DEBUG_SCOPE("Batching load buffers"); TRACE_SCOPE(tracing::LoadBatchingBuffers); SCP_map<batch_info, primitive_batch>::iterator bi; SCP_map<batch_buffer_key, primitive_batch_buffer>::iterator buffer_iter; for ( buffer_iter = Batching_buffers.begin(); buffer_iter != Batching_buffers.end(); ++buffer_iter ) { // zero out the buffers buffer_iter->second.desired_buffer_size = 0; } // assign primitive batch items for ( bi = Batching_primitives.begin(); bi != Batching_primitives.end(); ++bi ) { if ( bi->first.mat_type == batch_info::DISTORTION ) { if ( !distortion ) { continue; } } else { if ( distortion ) { continue; } } size_t num_verts = bi->second.num_verts(); if ( num_verts > 0 ) { batch_info render_info = bi->second.get_render_info(); uint vertex_mask = batching_determine_vertex_layout(&render_info); primitive_batch_buffer *buffer = batching_find_buffer(vertex_mask, render_info.prim_type); primitive_batch_item draw_item; draw_item.batch_item_info = render_info; draw_item.offset = 0; draw_item.n_verts = num_verts; draw_item.batch = &bi->second; buffer->desired_buffer_size += num_verts * sizeof(batch_vertex); buffer->items.push_back(draw_item); } } for ( buffer_iter = Batching_buffers.begin(); buffer_iter != Batching_buffers.end(); ++buffer_iter ) { batching_allocate_and_load_buffer(&buffer_iter->second); } }
std::shared_ptr<TraceCollection> CreateTrace(int N, int R) { std::unique_ptr<TraceReporterDataSourceCollector> dataSrc = TraceReporterDataSourceCollector::New(); TraceCollector::GetInstance().SetEnabled(true); TRACE_SCOPE("Test Outer"); for (int i = 0; i < N/R; i++) { Recursion(R); } TraceCollector::GetInstance().SetEnabled(false); std::shared_ptr<TraceCollection> collection = dataSrc->ConsumeData()[0]; TraceReporter::GetGlobalReporter()->ClearTree(); return collection; }
void batching_render_buffer(primitive_batch_buffer *buffer) { TRACE_SCOPE(tracing::RenderBatchBuffer); size_t num_batches = buffer->items.size(); for ( int j = 0; j < batch_info::NUM_RENDER_TYPES; ++j ) { for ( size_t i = 0; i < num_batches; ++i ) { if ( buffer->items[i].batch_item_info.mat_type != j ) { continue; } batching_render_batch_item(&buffer->items[i], &buffer->layout, buffer->prim_type, buffer->buffer_num); } } buffer->items.clear(); }
void VideoDecoder::decodePacket(AVPacket* packet) { TRACE_SCOPE(tracing::CutsceneFFmpegVideoDecoder); #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255) int send_result; do { send_result = avcodec_send_packet(m_status->videoCodecCtx, packet); while(avcodec_receive_frame(m_status->videoCodecCtx, m_decodeFrame) == 0) { convertAndPushPicture(m_decodeFrame); } } while (send_result == AVERROR(EAGAIN)); #else int finishedFrame = 0; auto result = avcodec_decode_video2(m_status->videoCodecCtx, m_decodeFrame, &finishedFrame, packet); if (result >= 0 && finishedFrame) { convertAndPushPicture(m_decodeFrame); } #endif }
void AudioDecoder::decodePacket(AVPacket* packet) { TRACE_SCOPE(tracing::CutsceneFFmpegAudioDecoder); #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255) int send_result; do { send_result = avcodec_send_packet(m_status->audioCodecCtx, packet); while (avcodec_receive_frame(m_status->audioCodecCtx, m_decodeFrame) == 0) { handleDecodedFrame(m_decodeFrame); } } while (send_result == AVERROR(EAGAIN)); #else int finishedFrame = 0; auto err = avcodec_decode_audio4(m_status->audioCodecCtx, m_decodeFrame, &finishedFrame, packet); if (err >= 0 && finishedFrame) { handleDecodedFrame(m_decodeFrame); } #endif }
void batching_render_batch_item(primitive_batch_item *item, vertex_layout *layout, primitive_type prim_type, int buffer_num) { TRACE_SCOPE(tracing::RenderBatchItem); if ( item->batch_item_info.mat_type == batch_info::VOLUME_EMISSIVE ) { // Cmdline_softparticles particle_material material_def; material_set_unlit_volume(&material_def, item->batch_item_info.texture, prim_type == PRIM_TYPE_POINTS); gr_render_primitives_particle(&material_def, prim_type, layout, (int)item->offset, (int)item->n_verts, buffer_num); } else if ( item->batch_item_info.mat_type == batch_info::DISTORTION ) { distortion_material material_def; material_set_distortion(&material_def, item->batch_item_info.texture, item->batch_item_info.thruster); gr_render_primitives_distortion(&material_def, PRIM_TYPE_TRIS, layout, (int)item->offset, (int)item->n_verts, buffer_num); } else { material material_def; material_set_unlit_emissive(&material_def, item->batch_item_info.texture, 1.0f, 2.0f); gr_render_primitives(&material_def, PRIM_TYPE_TRIS, layout, (int)item->offset, (int)item->n_verts, buffer_num); } }
void AudioDecoder::finishDecoding() { TRACE_SCOPE(tracing::CutsceneFFmpegAudioDecoder); #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255) // Send flush packet avcodec_send_packet(m_status->audioCodecCtx, nullptr); // Handle those decoders that have a delay while (true) { auto ret = avcodec_receive_frame(m_status->audioCodecCtx, m_decodeFrame); if (ret == 0) { handleDecodedFrame(m_decodeFrame); } else { // Everything consumed or error break; } } #else // Handle those decoders that have a delay AVPacket nullPacket; memset(&nullPacket, 0, sizeof(nullPacket)); nullPacket.data = nullptr; nullPacket.size = 0; while (true) { int finishedFrame = 1; auto err = avcodec_decode_audio4(m_status->audioCodecCtx, m_decodeFrame, &finishedFrame, &nullPacket); if (err < 0 || !finishedFrame) { break; } handleDecodedFrame(m_decodeFrame); } #endif // Push the last bits of audio data into the queue flushAudioBuffer(); }
void VideoDecoder::finishDecoding() { TRACE_SCOPE(tracing::CutsceneFFmpegVideoDecoder); #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255) // Send flush packet avcodec_send_packet(m_status->videoCodecCtx, nullptr); // Handle those decoders that have a delay while (true) { auto ret = avcodec_receive_frame(m_status->videoCodecCtx, m_decodeFrame); if (ret == 0) { convertAndPushPicture(m_decodeFrame); } else { // Everything consumed or error break; } } #else // Handle those decoders that have a delay AVPacket nullPacket; memset(&nullPacket, 0, sizeof(nullPacket)); nullPacket.data = nullptr; nullPacket.size = 0; while (true) { int finishedFrame = 1; auto err = avcodec_decode_video2(m_status->videoCodecCtx, m_decodeFrame, &finishedFrame, &nullPacket); if (err < 0 || !finishedFrame) { break; } convertAndPushPicture(m_decodeFrame); } #endif }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); MSG msg = {}; HACCEL hAccelTable = NULL; auto result = function_contract_hresult( [&] () -> unique_hresult { WPP_INIT_TRACING(SCANNER_TRACING_ID); ON_UNWIND_AUTO([&]{ WPP_CLEANUP(); }); TRACE_SCOPE("commandline: %ls", lpCmdLine); unique_winerror winerror; unique_hresult hr; hr.reset(CoInitialize(NULL)).throw_if(); ON_UNWIND_AUTO([&]{CoUninitialize();}); std::wstring title; std::wstring className; lib::wr::unique_close_window window; #if 1 typedef lib::wr::unique_cotask_factory<WCHAR[]>::type unique_cotask_wstr; auto helloRange = lib::rng::make_range(L"hello"); unique_cotask_wstr output; std::tie(winerror, output) = unique_cotask_wstr::make(helloRange.size()); winerror.throw_if(); stdext::checked_array_iterator< WCHAR* > checked_begin(output->begin(), output->size()); std::copy(helloRange.begin(), helloRange.end(), checked_begin); typedef lib::wr::unique_local_factory<std::wstring[]>::type unique_local_strings; unique_local_strings strings; std::tie(winerror, strings) = unique_local_strings::make(2); winerror.throw_if(); unique_cotask_wstr cotaskTitle; std::tie(winerror, cotaskTitle) = lib::wr::LoadStdString<unique_cotask_wstr>(hInstance, IDS_APP_TITLE); winerror.throw_if(); auto string = lib::rng::copy<UNICODE_STRING>(helloRange); auto stringRange = lib::rng::make_range(string); auto unicodeTitle = lib::rng::copy<UNICODE_STRING>(lib::rng::make_range_raw(title)); stringRange = lib::rng::make_range(unicodeTitle); #endif title = lib::wr::LoadStdString(hInstance, IDS_APP_TITLE); className = lib::wr::LoadStdString(hInstance, IDC_SCANNER); // Perform application initialization: std::tie(winerror, window) = CreateMainWindow(hInstance, className.c_str(), title.c_str(), nCmdShow); winerror.throw_if(); if (!window) { return hresult_cast(E_UNEXPECTED); } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SCANNER)); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return hr; } ); return SUCCEEDED(result) ? (int) msg.wParam : FALSE; }
void foo () { TRACE_SCOPE(trace::e_Info, trace::CTX_Default); TRACE_MSG(trace::e_Info, trace::CTX_Default, "%s %s", "\'llo world froom foo().", "and from bar!"); }
~Bar () { TRACE_SCOPE(trace::e_Info, trace::CTX_Default); }
void model_collide_parse_bsp(bsp_collision_tree *tree, void *model_ptr, int version) { TRACE_SCOPE(tracing::ModelParseBSPTree); ubyte *p = (ubyte *)model_ptr; ubyte *next_p; int chunk_type = w(p); int chunk_size = w(p+4); int next_chunk_type; int next_chunk_size; Assert(chunk_type == OP_DEFPOINTS); int n_verts = model_collide_parse_bsp_defpoints(p); if ( n_verts <= 0) { tree->point_list = NULL; tree->n_verts = 0; tree->n_nodes = 0; tree->node_list = NULL; tree->n_leaves = 0; tree->leaf_list = NULL; // finally copy the vert list. tree->vert_list = NULL; return; } p += chunk_size; bsp_collision_node new_node; bsp_collision_leaf new_leaf; SCP_vector<bsp_collision_node> node_buffer; SCP_vector<bsp_collision_leaf> leaf_buffer; SCP_vector<model_tmap_vert> vert_buffer; SCP_map<size_t, ubyte*> bsp_datap; node_buffer.push_back(new_node); size_t i = 0; vec3d *min; vec3d *max; bsp_datap[i] = p; while ( i < node_buffer.size() ) { p = bsp_datap[i]; chunk_type = w(p); chunk_size = w(p+4); switch ( chunk_type ) { case OP_SORTNORM: if ( version >= 2000 ) { min = vp(p+56); max = vp(p+68); node_buffer[i].min = *min; node_buffer[i].max = *max; } node_buffer[i].leaf = -1; node_buffer[i].front = -1; node_buffer[i].back = -1; if ( w(p+36) ) { next_chunk_type = w(p+w(p+36)); if ( next_chunk_type != OP_EOF ) { node_buffer.push_back(new_node); node_buffer[i].front = (int)(node_buffer.size() - 1); bsp_datap[node_buffer[i].front] = p+w(p+36); } } if ( w(p+40) ) { next_chunk_type = w(p+w(p+40)); if ( next_chunk_type != OP_EOF ) { node_buffer.push_back(new_node); node_buffer[i].back = (int)(node_buffer.size() - 1); bsp_datap[node_buffer[i].back] = p+w(p+40); } } next_p = p + chunk_size; next_chunk_type = w(next_p); Assert( next_chunk_type == OP_EOF ); ++i; break; case OP_BOUNDBOX: min = vp(p+8); max = vp(p+20); node_buffer[i].min = *min; node_buffer[i].max = *max; node_buffer[i].front = -1; node_buffer[i].back = -1; node_buffer[i].leaf = -1; next_p = p + chunk_size; next_chunk_type = w(next_p); next_chunk_size = w(next_p+4); if ( next_chunk_type != OP_EOF && (next_chunk_type == OP_TMAPPOLY || next_chunk_type == OP_FLATPOLY ) ) { new_leaf.next = -1; node_buffer[i].leaf = (int)leaf_buffer.size(); // get index of where our poly list starts in the leaf buffer while ( next_chunk_type != OP_EOF ) { if ( next_chunk_type == OP_TMAPPOLY ) { model_collide_parse_bsp_tmappoly(&new_leaf, &vert_buffer, next_p); leaf_buffer.push_back(new_leaf); leaf_buffer.back().next = (int)leaf_buffer.size(); } else if ( next_chunk_type == OP_FLATPOLY ) { model_collide_parse_bsp_flatpoly(&new_leaf, &vert_buffer, next_p); leaf_buffer.push_back(new_leaf); leaf_buffer.back().next = (int)leaf_buffer.size(); } else { Int3(); } next_p += next_chunk_size; next_chunk_type = w(next_p); next_chunk_size = w(next_p+4); } leaf_buffer.back().next = -1; } Assert(next_chunk_type == OP_EOF); ++i; break; } } // copy point list Assert(n_verts != -1); tree->point_list = (vec3d*)vm_malloc(sizeof(vec3d) * n_verts); for ( i = 0; i < (size_t)n_verts; ++i ) { tree->point_list[i] = *Mc_point_list[i]; } tree->n_verts = n_verts; // copy node info. this might be a good time to organize the nodes into a cache efficient tree layout. tree->n_nodes = (int)node_buffer.size(); tree->node_list = (bsp_collision_node*)vm_malloc(sizeof(bsp_collision_node) * node_buffer.size()); memcpy(tree->node_list, &node_buffer[0], sizeof(bsp_collision_node) * node_buffer.size()); node_buffer.clear(); // copy leaves. tree->n_leaves = (int)leaf_buffer.size(); tree->leaf_list = (bsp_collision_leaf*)vm_malloc(sizeof(bsp_collision_leaf) * leaf_buffer.size()); memcpy(tree->leaf_list, &leaf_buffer[0], sizeof(bsp_collision_leaf) * leaf_buffer.size()); leaf_buffer.clear(); // finally copy the vert list. tree->vert_list = (model_tmap_vert*)vm_malloc(sizeof(model_tmap_vert) * vert_buffer.size()); memcpy(tree->vert_list, &vert_buffer[0], sizeof(model_tmap_vert) * vert_buffer.size()); vert_buffer.clear(); }
void gr_opengl_update_distortion() { if (Distortion_framebuffer == 0) { // distortion is disabled return; } GR_DEBUG_SCOPE("Update distortion"); TRACE_SCOPE(tracing::UpdateDistortion); GLboolean depth = GL_state.DepthTest(GL_FALSE); GLboolean depth_mask = GL_state.DepthMask(GL_FALSE); GLboolean blend = GL_state.Blend(GL_FALSE); GLboolean cull = GL_state.CullFace(GL_FALSE); opengl_shader_set_passthrough(true); GL_state.PushFramebufferState(); GL_state.BindFrameBuffer(Distortion_framebuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Distortion_texture[!Distortion_switch], 0); glDrawBuffer(GL_COLOR_ATTACHMENT0); glViewport(0,0,32,32); GL_state.Texture.Enable(0, GL_TEXTURE_2D, Distortion_texture[Distortion_switch]); glClearColor(0.5f, 0.5f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); vertex vertices[4]; vertices[0].texture_position.u = 0.0f; vertices[0].texture_position.v = 0.0f; vertices[1].texture_position.u = 0.96875f; vertices[1].texture_position.v = 0.0f; vertices[2].texture_position.u = 0.0f; vertices[2].texture_position.v = 1.0f; vertices[3].texture_position.u = 0.96875f; vertices[3].texture_position.v = 1.0f; vertices[0].screen.xyw.x = 0.03f*(float)gr_screen.max_w; vertices[0].screen.xyw.y = (float)gr_screen.max_h; vertices[1].screen.xyw.x = (float)gr_screen.max_w; vertices[1].screen.xyw.y = (float)gr_screen.max_h; vertices[2].screen.xyw.x = 0.03f*(float)gr_screen.max_w; vertices[2].screen.xyw.y = 0.0f; vertices[3].screen.xyw.x = (float)gr_screen.max_w; vertices[3].screen.xyw.y = 0.0f; vertex_layout vert_def; vert_def.add_vertex_component(vertex_format_data::POSITION2, sizeof(vertex), offsetof(vertex, screen)); vert_def.add_vertex_component(vertex_format_data::TEX_COORD2, sizeof(vertex), offsetof(vertex, texture_position)); opengl_render_primitives_immediate(PRIM_TYPE_TRISTRIP, &vert_def, 4, vertices, sizeof(vertex) * 4); opengl_shader_set_passthrough(false); vertex distortion_verts[33]; for(int i = 0; i < 33; i++) { distortion_verts[i].r = (ubyte)rand() % 256; distortion_verts[i].g = (ubyte)rand() % 256; distortion_verts[i].b = 255; distortion_verts[i].a = 255; distortion_verts[i].screen.xyw.x = 1.f; distortion_verts[i].screen.xyw.y = (float)gr_screen.max_h*0.03125f*i; } vert_def = vertex_layout(); vert_def.add_vertex_component(vertex_format_data::POSITION2, sizeof(vertex), offsetof(vertex, screen)); vert_def.add_vertex_component(vertex_format_data::COLOR4, sizeof(vertex), offsetof(vertex, r)); opengl_render_primitives_immediate(PRIM_TYPE_POINTS, &vert_def, 33, distortion_verts, 33 * sizeof(vertex)); Distortion_switch = !Distortion_switch; // reset state GL_state.PopFramebufferState(); glViewport(0,0,gr_screen.max_w,gr_screen.max_h); GL_state.DepthTest(depth); GL_state.DepthMask(depth_mask); GL_state.Blend(blend); GL_state.CullFace(cull); }
void gr_opengl_scene_texture_end() { if ( !Scene_framebuffer_in_frame ) { return; } GR_DEBUG_SCOPE("End scene texture"); TRACE_SCOPE(tracing::SceneTextureEnd); time_buffer+=flFrametime; if(time_buffer>0.03f) { gr_opengl_update_distortion(); time_buffer = 0.0f; } if ( Gr_post_processing_enabled && !PostProcessing_override ) { gr_post_process_end(); } else { GR_DEBUG_SCOPE("Draw scene texture"); TRACE_SCOPE(tracing::DrawSceneTexture); GLboolean depth = GL_state.DepthTest(GL_FALSE); GLboolean depth_mask = GL_state.DepthMask(GL_FALSE); GLboolean blend = GL_state.Blend(GL_FALSE); GLboolean cull = GL_state.CullFace(GL_FALSE); GL_state.PopFramebufferState(); GL_state.Texture.Enable(0, GL_TEXTURE_2D, Scene_color_texture); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); opengl_shader_set_passthrough(true); GL_state.Array.BindArrayBuffer(0); if (GL_rendering_to_texture) { opengl_draw_textured_quad(0.0f, 0.0f, 0.0f, 0.0f, (float)gr_screen.max_w, (float)gr_screen.max_h, Scene_texture_u_scale, Scene_texture_v_scale); } else { opengl_draw_textured_quad(0.0f, 0.0f, 0.0f, Scene_texture_v_scale, (float)gr_screen.max_w, (float)gr_screen.max_h, Scene_texture_u_scale, 0.0f); } // reset state GL_state.DepthTest(depth); GL_state.DepthMask(depth_mask); GL_state.Blend(blend); GL_state.CullFace(cull); } // Reset the UV scale values Scene_texture_u_scale = 1.0f; Scene_texture_v_scale = 1.0f; Scene_framebuffer_in_frame = false; High_dynamic_range = false; }
void obj_collide_pair(object *A, object *B) { TRACE_SCOPE(tracing::CollidePair); uint ctype; int (*check_collision)( obj_pair *pair ); int swapped = 0; check_collision = NULL; if ( A==B ) return; // Don't check collisions with yourself if ( !(A->flags[Object::Object_Flags::Collides]) ) return; // This object doesn't collide with anything if ( !(B->flags[Object::Object_Flags::Collides]) ) return; // This object doesn't collide with anything if ((A->flags[Object::Object_Flags::Immobile]) && (B->flags[Object::Object_Flags::Immobile])) return; // Two immobile objects will never collide with each other // Make sure you're not checking a parent with it's kid or vicy-versy // if ( A->parent_sig == B->signature && !(A->type == OBJ_SHIP && B->type == OBJ_DEBRIS) ) return; // if ( B->parent_sig == A->signature && !(A->type == OBJ_DEBRIS && B->type == OBJ_SHIP) ) return; if ( reject_obj_pair_on_parent(A,B) ) { return; } Assert( A->type < 127 ); Assert( B->type < 127 ); ctype = COLLISION_OF(A->type,B->type); switch( ctype ) { case COLLISION_OF(OBJ_WEAPON,OBJ_SHIP): swapped = 1; check_collision = collide_ship_weapon; break; case COLLISION_OF(OBJ_SHIP, OBJ_WEAPON): check_collision = collide_ship_weapon; break; case COLLISION_OF(OBJ_DEBRIS, OBJ_WEAPON): check_collision = collide_debris_weapon; break; case COLLISION_OF(OBJ_WEAPON, OBJ_DEBRIS): swapped = 1; check_collision = collide_debris_weapon; break; case COLLISION_OF(OBJ_DEBRIS, OBJ_SHIP): check_collision = collide_debris_ship; break; case COLLISION_OF(OBJ_SHIP, OBJ_DEBRIS): check_collision = collide_debris_ship; swapped = 1; break; case COLLISION_OF(OBJ_ASTEROID, OBJ_WEAPON): // Only check collision's with player weapons // if ( Objects[B->parent].flags[Object::Object_Flags::Player_ship] ) { check_collision = collide_asteroid_weapon; // } break; case COLLISION_OF(OBJ_WEAPON, OBJ_ASTEROID): swapped = 1; // Only check collision's with player weapons // if ( Objects[A->parent].flags[Object::Object_Flags::Player_ship] ) { check_collision = collide_asteroid_weapon; // } break; case COLLISION_OF(OBJ_ASTEROID, OBJ_SHIP): // Only check collisions with player ships // if ( B->flags[Object::Object_Flags::Player_ship] ) { check_collision = collide_asteroid_ship; // } break; case COLLISION_OF(OBJ_SHIP, OBJ_ASTEROID): // Only check collisions with player ships // if ( A->flags[Object::Object_Flags::Player_ship] ) { check_collision = collide_asteroid_ship; // } swapped = 1; break; case COLLISION_OF(OBJ_SHIP,OBJ_SHIP): check_collision = collide_ship_ship; break; case COLLISION_OF(OBJ_SHIP, OBJ_BEAM): if(beam_collide_early_out(B, A)){ return; } swapped = 1; check_collision = beam_collide_ship; break; case COLLISION_OF(OBJ_BEAM, OBJ_SHIP): if(beam_collide_early_out(A, B)){ return; } check_collision = beam_collide_ship; break; case COLLISION_OF(OBJ_ASTEROID, OBJ_BEAM): if(beam_collide_early_out(B, A)) { return; } swapped = 1; check_collision = beam_collide_asteroid; break; case COLLISION_OF(OBJ_BEAM, OBJ_ASTEROID): if(beam_collide_early_out(A, B)){ return; } check_collision = beam_collide_asteroid; break; case COLLISION_OF(OBJ_DEBRIS, OBJ_BEAM): if(beam_collide_early_out(B, A)) { return; } swapped = 1; check_collision = beam_collide_debris; break; case COLLISION_OF(OBJ_BEAM, OBJ_DEBRIS): if(beam_collide_early_out(A, B)){ return; } check_collision = beam_collide_debris; break; case COLLISION_OF(OBJ_WEAPON, OBJ_BEAM): if(beam_collide_early_out(B, A)) { return; } swapped = 1; check_collision = beam_collide_missile; break; case COLLISION_OF(OBJ_BEAM, OBJ_WEAPON): if(beam_collide_early_out(A, B)){ return; } check_collision = beam_collide_missile; break; case COLLISION_OF(OBJ_WEAPON, OBJ_WEAPON): { weapon_info *awip, *bwip; awip = &Weapon_info[Weapons[A->instance].weapon_info_index]; bwip = &Weapon_info[Weapons[B->instance].weapon_info_index]; if ((awip->weapon_hitpoints > 0) || (bwip->weapon_hitpoints > 0)) { if (bwip->weapon_hitpoints == 0) { check_collision = collide_weapon_weapon; swapped=1; } else { check_collision = collide_weapon_weapon; } } break; } default: return; } if ( !check_collision ) return; // Swap them if needed if ( swapped ) { object *tmp = A; A = B; B = tmp; } collider_pair *collision_info = NULL; bool valid = false; uint key = (OBJ_INDEX(A) << 12) + OBJ_INDEX(B); collision_info = &Collision_cached_pairs[key]; if ( collision_info->initialized ) { // make sure we're referring to the correct objects in case the original pair was deleted if ( collision_info->signature_a == collision_info->a->signature && collision_info->signature_b == collision_info->b->signature ) { valid = true; } else { collision_info->a = A; collision_info->b = B; collision_info->signature_a = A->signature; collision_info->signature_b = B->signature; collision_info->next_check_time = timestamp(0); } } else { collision_info->a = A; collision_info->b = B; collision_info->signature_a = A->signature; collision_info->signature_b = B->signature; collision_info->initialized = true; collision_info->next_check_time = timestamp(0); } if ( valid && A->type != OBJ_BEAM ) { // if this signature is valid, make the necessary checks to see if we need to collide check if ( collision_info->next_check_time == -1 ) { return; } else { if ( !timestamp_elapsed(collision_info->next_check_time) ) { return; } } } else { //if ( A->type == OBJ_BEAM ) { //if(beam_collide_early_out(A, B)){ //collision_info->next_check_time = -1; //return; //} //} // only check debris:weapon collisions for player if (check_collision == collide_debris_weapon) { // weapon is B if ( !(Weapon_info[Weapons[B->instance].weapon_info_index].wi_flags[Weapon::Info_Flags::Turns]) ) { // check for dumbfire weapon // check if debris is behind laser float vdot; if (Weapon_info[Weapons[B->instance].weapon_info_index].subtype == WP_LASER) { vec3d velocity_rel_weapon; vm_vec_sub(&velocity_rel_weapon, &B->phys_info.vel, &A->phys_info.vel); vdot = -vm_vec_dot(&velocity_rel_weapon, &B->orient.vec.fvec); } else { vdot = vm_vec_dot( &A->phys_info.vel, &B->phys_info.vel); } if ( vdot <= 0.0f ) { // They're heading in opposite directions... // check their positions vec3d weapon2other; vm_vec_sub( &weapon2other, &A->pos, &B->pos ); float pdot = vm_vec_dot( &B->orient.vec.fvec, &weapon2other ); if ( pdot <= -A->radius ) { // The other object is behind the weapon by more than // its radius, so it will never hit... collision_info->next_check_time = -1; return; } } // check dist vs. dist moved during weapon lifetime vec3d delta_v; vm_vec_sub(&delta_v, &B->phys_info.vel, &A->phys_info.vel); if (vm_vec_dist_squared(&A->pos, &B->pos) > (vm_vec_mag_squared(&delta_v)*Weapons[B->instance].lifeleft*Weapons[B->instance].lifeleft)) { collision_info->next_check_time = -1; return; } // for nonplayer ships, only create collision pair if close enough if ( (B->parent >= 0) && !((Objects[B->parent].signature == B->parent_sig) && (Objects[B->parent].flags[Object::Object_Flags::Player_ship])) && (vm_vec_dist(&B->pos, &A->pos) < (4.0f*A->radius + 200.0f)) ) { collision_info->next_check_time = -1; return; } } } // don't check same team laser:ship collisions on small ships if not player if (check_collision == collide_ship_weapon) { // weapon is B if ( (B->parent >= 0) && (Objects[B->parent].signature == B->parent_sig) && !(Objects[B->parent].flags[Object::Object_Flags::Player_ship]) && (Ships[Objects[B->parent].instance].team == Ships[A->instance].team) && (Ship_info[Ships[A->instance].ship_info_index].is_small_ship()) && (Weapon_info[Weapons[B->instance].weapon_info_index].subtype == WP_LASER) ) { collision_info->next_check_time = -1; return; } } } obj_pair new_pair; new_pair.a = A; new_pair.b = B; new_pair.check_collision = check_collision; new_pair.next_check_time = collision_info->next_check_time; if ( check_collision(&new_pair) ) { // don't have to check ever again collision_info->next_check_time = -1; } else { collision_info->next_check_time = new_pair.next_check_time; } }
double MathFuncs_1::Add(double a, double b) { TRACE_SCOPE(trace::e_Info, trace::CTX_Default); TRACE_MSG(trace::e_Info, trace::CTX_Default, "Adding: %f + %f = ", a, b, a + b); return a + b; }
double MathFuncs_1::Subtract(double a, double b) { TRACE_SCOPE(trace::e_Info, trace::CTX_Default); TRACE_MSG(trace::e_Info, trace::CTX_Default, "Adding: %f + -%f = ", a, b, a - b); return a - b; }