static void handle_cache_load_done(void) { if (!are_all_pages_loaded()) { return; } DEBUGPRINT("initial_cache_load: entire cache loaded done\n"); cache_loading_phase = false; /* FIXME: stop the trace. */ #if ENABLE_WEB_TRACING trace_event(TRACE_SUBSYS_NET, TRACE_EVENT_NET_STOP, 0); char *buf = malloc(4096*4096); trace_dump(buf, 4096*4096, NULL); printf("%s\n", buf); #endif // ENABLE_WEB_TRACING // lwip_benchmark_control(1, BMS_STOP_REQUEST, 0, 0); // Report the cache loading time printf("Cache loading time %"PU"\n", in_seconds(rdtsc() - last_ts)); // lwip_print_interesting_stats(); /* continue with the web-server initialization. */ init_callback(); /* do remaining initialization! */ }
void physics_system::step_and_set_new_transforms(logic_step& step) { auto& cosmos = step.cosm; const auto delta = step.get_delta(); int32 velocityIterations = 8; int32 positionIterations = 3; ray_casts_since_last_step = 0; b2world->Step(static_cast<float32>(delta.in_seconds()), velocityIterations, positionIterations); post_and_clear_accumulated_collision_messages(step); for (b2Body* b = b2world->GetBodyList(); b != nullptr; b = b->GetNext()) { if (b->GetType() == b2_staticBody) continue; entity_handle entity = cosmos[b->GetUserData()]; auto& physics = entity.get<components::physics>(); recurential_friction_handler(step, b, b->m_ownerFrictionGround); physics.component.transform = b->m_xf; physics.component.sweep = b->m_sweep; physics.component.velocity = b->GetLinearVelocity(); physics.component.angular_velocity = b->GetAngularVelocity(); } }
int run(Object& m, const std::size_t count, const std::size_t tries) { m.add("construction"); m.add("search"); std::printf("%s\n", m.name.c_str()); auto result = 0; Collection list; { std::printf("* construction... "); std::fflush(stdout); auto c = scoped_timer<Timer>(m["construction"]); generate(count, list); std::printf("%.3fs\n", c.in_seconds()); } std::printf("* search... ["); std::fflush(stdout); for (std::size_t i=0; i < tries; i++) { auto c = scoped_timer<Timer>(m["search"]); result += find_all(count, list); std::putchar('.'); std::fflush(stdout); } std::printf("] min=%.3f, max=%.3f, avg=%.3fs\n", m["search"].min(), m["search"].max(), m["search"].avg()); return result; }
static void udp_receiver_done(void) { // Record the stop timer recv_stop_c = rdtsc(); uint64_t delta = recv_stop_c - recv_start_c; lwip_benchmark_control(connection_type, BMS_STOP_REQUEST, 0, 0); lwip_print_interesting_stats(); // print the statistics printf("U: Time taken %"PU" to recv %"PRIu64" data" "(%"PRIu64" packets)\n", in_seconds(delta), rx_data_size, pkt_count); printf("U: RX speed = data(%"PRIu64") / time(%"PU") = [%f] KB \n", rx_data_size, in_seconds(delta), ((rx_data_size/in_seconds(delta))/1024)); udp_recv_bm_shown = true; } // end function: udp_receiver_done
static void stop_benchmark(uint64_t stop, uint64_t driver_runtime, uint64_t drv_pkt_count) { // FIXME: Make sure that all data is gone // uint64_t stop = rdtsc(); uint64_t delta = stop - start_tx; // sending debug message marking the stop of benchmark // lwip_benchmark_control(connection_type, BMS_STOP_REQUEST, 0, 0); printf("U: Test [%s], PBUF type %s\n", TEST_TYPE, connection_type?"PBUF_RAM":"PBUF_POOL"); lwip_print_interesting_stats(); printf("U: Time taken by APP %"PU" to send %"PRIu64" packets" "(%"PRIu64" failed)\n", in_seconds(delta), iter, failed); if (driver_runtime > 0) { printf("U: Time taken by DRV %"PU" to send %"PRIu64" packets\n", in_seconds(driver_runtime), drv_pkt_count); } uint64_t data_size = iter * MAX_DATA; printf("U: TX speed (app view) = data(%"PRIu64") / time(%"PU") = [%f] KB \n", data_size, in_seconds(delta), ((data_size/in_seconds(delta))/1024)); if (driver_runtime > 0) { data_size = drv_pkt_count * MAX_DATA; printf("U: TX speed (DRV view) = data(%"PRIu64") / time(%"PU") = [%f] KB \n", data_size, in_seconds(driver_runtime), ((data_size/in_seconds(driver_runtime))/1024)); } for (int j = 0; j < 6; ++j) { printf("U: Stats %d: [%"PRIu64"] \n", j, stats[j]); } loop_forever(); }
void light_system::render_all_lights(augs::renderer& output, const std::array<float, 16> projection_matrix, const viewing_step step, std::function<void()> neon_callback) { const auto& cosmos = step.cosm; const auto dt = step.get_delta(); const float global_time_seconds = static_cast<float>(step.get_interpolated_total_time_passed_in_seconds()); ensure_eq(0, output.get_triangle_count()); output.light_fbo.use(); glClearColor(0.1f, 0.2f, 0.2f, 1.0f); output.clear_current_fbo(); glClearColor(0.f, 0.f, 0.f, 0.f); auto& light_program = *get_resource_manager().find(assets::program_id::LIGHT); auto& default_program = *get_resource_manager().find(assets::program_id::DEFAULT); light_program.use(); const auto light_pos_uniform = glGetUniformLocation(light_program.id, "light_pos"); const auto light_max_distance_uniform = glGetUniformLocation(light_program.id, "max_distance"); const auto light_attenuation_uniform = glGetUniformLocation(light_program.id, "light_attenuation"); const auto light_multiply_color_uniform = glGetUniformLocation(light_program.id, "multiply_color"); const auto projection_matrix_uniform = glGetUniformLocation(light_program.id, "projection_matrix"); const auto& interp = step.session.systems_audiovisual.get<interpolation_system>(); const auto& particles = step.session.systems_audiovisual.get<particles_simulation_system>(); const auto& visible_per_layer = step.visible.per_layer; std::vector<messages::visibility_information_request> requests; std::vector<messages::visibility_information_response> responses; glUniformMatrix4fv(projection_matrix_uniform, 1, GL_FALSE, projection_matrix.data()); for (const auto it : cosmos.get(processing_subjects::WITH_LIGHT)) { messages::visibility_information_request request; request.eye_transform = it.viewing_transform(interp); request.filter = filters::line_of_sight_query(); request.square_side = it.get<components::light>().max_distance.base_value; request.subject = it; requests.push_back(request); } { std::vector<messages::line_of_sight_response> dummy; visibility_system().respond_to_visibility_information_requests(cosmos, {}, requests, dummy, responses); } const auto camera_transform = step.camera.transform; const auto camera_size = step.camera.visible_world_area; const auto camera_offset = -camera_transform.pos + camera_size / 2; glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE); glerr; for (size_t i = 0; i < responses.size(); ++i) { const auto& r = responses[i]; const auto& light_entity = cosmos[requests[i].subject]; const auto& light = light_entity.get<components::light>(); auto& cache = per_entity_cache[light_entity.get_id().pool.indirection_index]; const float delta = dt.in_seconds(); light.constant.variation.update_value(rng, cache.all_variation_values[0], delta); light.linear.variation.update_value(rng, cache.all_variation_values[1], delta); light.quadratic.variation.update_value(rng, cache.all_variation_values[2], delta); light.wall_constant.variation.update_value(rng, cache.all_variation_values[3], delta); light.wall_linear.variation.update_value(rng, cache.all_variation_values[4], delta); light.wall_quadratic.variation.update_value(rng, cache.all_variation_values[5], delta); light.position_variations[0].update_value(rng, cache.all_variation_values[6], delta); light.position_variations[1].update_value(rng, cache.all_variation_values[7], delta); for (size_t t = 0; t < r.get_num_triangles(); ++t) { const auto world_light_tri = r.get_world_triangle(t, requests[i].eye_transform.pos); augs::vertex_triangle renderable_light_tri; renderable_light_tri.vertices[0].pos = world_light_tri.points[0] + camera_offset; renderable_light_tri.vertices[1].pos = world_light_tri.points[1] + camera_offset; renderable_light_tri.vertices[2].pos = world_light_tri.points[2] + camera_offset; auto considered_color = light.color; if (considered_color == black) { considered_color.set_hsv({ fmod(global_time_seconds / 16.f, 1.f), 1.0, 1.0 }); } renderable_light_tri.vertices[0].color = considered_color; renderable_light_tri.vertices[1].color = considered_color; renderable_light_tri.vertices[2].color = considered_color; output.push_triangle(renderable_light_tri); } //for (size_t d = 0; d < r.get_num_discontinuities(); ++d) { // const auto world_discontinuity = *r.get_discontinuity(d); // // if (!world_discontinuity.is_boundary) { // vertex_triangle renderable_light_tri; // // const float distance_from_light = (requests[i].eye_transform.pos - world_discontinuity.points.first).length(); // const float angle = 80.f / ((distance_from_light+0.1f)/50.f); // // //(requests[i].eye_transform.pos - world_discontinuity.points.first).length(); // // if (world_discontinuity.winding == world_discontinuity.RIGHT) { // renderable_light_tri.vertices[0].pos = world_discontinuity.points.first + camera_offset; // renderable_light_tri.vertices[1].pos = world_discontinuity.points.second + camera_offset; // renderable_light_tri.vertices[2].pos = vec2(world_discontinuity.points.second).rotate(-angle, world_discontinuity.points.first) + camera_offset; // } // else { // renderable_light_tri.vertices[0].pos = world_discontinuity.points.first + camera_offset; // renderable_light_tri.vertices[1].pos = world_discontinuity.points.second + camera_offset; // renderable_light_tri.vertices[2].pos = vec2(world_discontinuity.points.second).rotate(angle, world_discontinuity.points.first) + camera_offset; // } // // renderable_light_tri.vertices[0].color = light.color; // renderable_light_tri.vertices[1].color = light.color; // renderable_light_tri.vertices[2].color = light.color; // // output.push_triangle(renderable_light_tri); // } //} vec2 light_displacement = vec2(cache.all_variation_values[6], cache.all_variation_values[7]); auto screen_pos = requests[i].eye_transform - camera_transform; screen_pos.pos.x += camera_size.x * 0.5f; screen_pos.pos.y = camera_size.y - (screen_pos.pos.y + camera_size.y * 0.5f); screen_pos += light_displacement; glUniform2f(light_pos_uniform, screen_pos.pos.x, screen_pos.pos.y); glUniform1f(light_max_distance_uniform, light.max_distance.base_value); glUniform3f(light_attenuation_uniform, cache.all_variation_values[0] + light.constant.base_value, cache.all_variation_values[1] + light.linear.base_value, cache.all_variation_values[2] + light.quadratic.base_value ); glUniform3f(light_multiply_color_uniform, 1.f, 1.f, 1.f); output.call_triangles(); output.clear_triangles(); light_program.use(); glUniform1f(light_max_distance_uniform, light.wall_max_distance.base_value); glUniform3f(light_attenuation_uniform, cache.all_variation_values[3] + light.wall_constant.base_value, cache.all_variation_values[4] + light.wall_linear.base_value, cache.all_variation_values[5] + light.wall_quadratic.base_value ); glUniform3f(light_multiply_color_uniform, light.color.r/255.f, light.color.g/255.f, light.color.b/255.f); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::DYNAMIC_BODY], step.camera, renderable_drawing_type::NORMAL); output.call_triangles(); output.clear_triangles(); glUniform3f(light_multiply_color_uniform, 1.f, 1.f, 1.f); } default_program.use(); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::DYNAMIC_BODY], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::SMALL_DYNAMIC_BODY], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::FLYING_BULLETS], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::CAR_INTERIOR], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::CAR_WHEEL], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::EFFECTS], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::ON_GROUND], step.camera, renderable_drawing_type::NEON_MAPS); render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::ON_TILED_FLOOR], step.camera, renderable_drawing_type::NEON_MAPS); { particles_simulation_system::drawing_input in(output.triangles); in.camera = step.camera; in.drawing_type = renderable_drawing_type::NEON_MAPS; particles.draw(render_layer::EFFECTS, in); } neon_callback(); output.call_triangles(); output.clear_triangles(); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); glerr; augs::graphics::fbo::use_default(); output.set_active_texture(2); output.bind_texture(output.light_fbo); output.set_active_texture(0); }
void force_joint_system::apply_forces_towards_target_entities(logic_step& step) { auto& cosmos = step.cosm; const auto delta = step.get_delta(); for (const auto& it : cosmos.get(processing_subjects::WITH_FORCE_JOINT)) { if (!it.has<components::physics>()) continue; const auto& physics = it.get<components::physics>(); if (!physics.is_constructed()) continue; const auto& force_joint = it.get<components::force_joint>(); const auto& chased_entity = cosmos[force_joint.chased_entity]; if (chased_entity.dead()) continue; const auto& chased_entity_transform = chased_entity.logic_transform(); const auto& chased_transform = chased_entity_transform + force_joint.chased_entity_offset; auto direction = chased_transform.pos - physics.get_position(); const auto& distance = direction.length(); direction.normalize_hint(distance); if (force_joint.divide_transform_mode) { const auto current_transform = it.logic_transform(); const auto interpolated = augs::interp(current_transform, chased_transform, 1.0 - 1.0 / (1.0 + delta.in_seconds() * (60.0))); //LOG("Cur: %x,%x, Chas: %x,%x, Inter: %x,%x", current_transform.pos, current_transform.rotation, chased_entity_transform.pos, chased_entity_transform.rotation, interpolated.pos, interpolated.rotation); physics.set_transform(interpolated); } else { float force_length = force_joint.force_towards_chased_entity; if (distance < force_joint.distance_when_force_easing_starts) { auto mult = distance / force_joint.distance_when_force_easing_starts; force_length *= pow(mult, force_joint.power_of_force_easing_multiplier); } const auto& force_for_chaser = vec2(direction).set_length(force_length * 1.f - force_joint.percent_applied_to_chased_entity); const auto& force_for_chased = -force_for_chaser * force_joint.percent_applied_to_chased_entity; const bool is_force_epsilon = force_for_chaser.length() < 500; const auto& offsets = force_joint.force_offsets; const int& offsets_count = static_cast<int>(offsets.size()); //if (!is_force_epsilon) { for (const auto& offset : offsets) physics.apply_force(force_for_chaser * physics.get_mass() / offsets_count, offset); //LOG("F: %x, %x, %x", force_for_chaser, physics.velocity(), AS_INTV physics.get_position()); } //else if (is_force_epsilon && physics.velocity().is_epsilon(1.f)) { // physics.set_velocity(vec2(0, 0)); // //physics.set_transform(components::transform(chased_transform.pos, physics.get_angle())); // LOG("Zeroed"); //} if (force_for_chased.length() > 5) { const auto& chased_physics = cosmos[force_joint.chased_entity].get<components::physics>(); chased_physics.apply_force(force_for_chaser * chased_physics.get_mass()); } //if (force_joint.consider_rotation) // it.get<components::rotation_copying>().target_angle = chased_transform.rotation; //LOG("F: %x", physics.body->GetLinearDamping()); } } }