inline void expand(int add_size = 100){ // size unit is byte int new_size = buffer_size + add_size; int cs_snap = content_size(); start = (byte *) realloc(start, new_size); // may change the value of start current = start + cs_snap; memset(current, 0, add_size); buffer_size = new_size; }
void EngineView::paint_ui(CmdBufferRecorder& recorder, const FrameToken& token) { y_profile(); update(); TextureView* output = nullptr; { FrameGraph graph(context()->resource_pool()); auto gbuffer = render_gbuffer(graph, &_scene_view, content_size()); auto lighting = render_lighting(graph, gbuffer, _ibl_data); auto tone_mapping = render_tone_mapping(graph, lighting); FrameGraphImageId output_image = tone_mapping.tone_mapped; { FrameGraphPassBuilder builder = graph.add_pass("ImGui texture pass"); builder.add_texture_input(output_image, PipelineStage::FragmentBit); builder.set_render_func([&output, output_image](CmdBufferRecorder& rec, const FrameGraphPass* pass) { auto out = std::make_unique<TextureView>(pass->resources()->image<ImageUsage::TextureBit>(output_image)); output = out.get(); rec.keep_alive(std::move(out)); }); } std::move(graph).render(recorder); recorder.keep_alive(_ibl_data); } // ImGui { if(output) { ImGui::GetWindowDrawList()->AddImage(output, position() + math::Vec2(ImGui::GetWindowContentRegionMin()), position() + math::Vec2(ImGui::GetWindowContentRegionMax())); } /*if(&context()->scene().scene_view() == &_scene_view)*/ { _gizmo.paint(recorder, token); if(!_gizmo.is_dragging()) { update_selection(); } } } }
/* ** Load the record identify by rid. Make sure we can reproduce it ** without error. ** ** Panic if anything goes wrong. If this procedure returns it means ** that everything is OK. */ static void verify_rid(int rid){ Blob uuid, hash, content; if( content_size(rid, 0)<0 ){ return; /* No way to verify phantoms */ } blob_zero(&uuid); db_blob(&uuid, "SELECT uuid FROM blob WHERE rid=%d", rid); if( blob_size(&uuid)!=UUID_SIZE ){ fossil_fatal("not a valid rid: %d", rid); } if( content_get(rid, &content) ){ sha1sum_blob(&content, &hash); blob_reset(&content); if( blob_compare(&uuid, &hash) ){ fossil_fatal("hash of rid %d (%b) does not match its uuid (%b)", rid, &hash, &uuid); } blob_reset(&hash); } blob_reset(&uuid); }
/* ** Check to see if content is available for artifact "rid". Return ** true if it is. Return false if rid is a phantom or depends on ** a phantom. */ int content_is_available(int rid){ int srcid; int depth = 0; /* Limit to recursion depth */ while( depth++ < 10000000 ){ if( bag_find(&contentCache.missing, rid) ){ return 0; } if( bag_find(&contentCache.available, rid) ){ return 1; } if( content_size(rid, -1)<0 ){ bag_insert(&contentCache.missing, rid); return 0; } srcid = findSrcid(rid); if( srcid==0 ){ bag_insert(&contentCache.available, rid); return 1; } rid = srcid; } fossil_panic("delta-loop in repository"); return 0; }
Message receive( web::socket const & s , std::chrono::seconds timeout_in ) { static_assert( elib::aux::is_same<Message, request>::value || elib::aux::is_same<Message, response>::value , "The only two choices" ); Message msg; data_type buff(10024); data_type remaining; const auto timeout_at = std::chrono::system_clock::now() + timeout_in; auto timeout_receive = [&]() { std::error_code ec; while (std::chrono::system_clock::now() < timeout_at) { ec.clear(); ::ssize_t ret = web::receive(s, buff, ec); if (ec.value() == EAGAIN || ec.value() == EWOULDBLOCK) continue; if (ec) { ELIB_THROW_EXCEPTION(socket_error( elib::fmt( "http::receive failed with error %s" , ec.message() ) , ec )); } ELIB_ASSERT(ret >= 0); std::copy_n( buff.begin() , static_cast<std::size_t>(ret) , std::back_inserter(remaining) ); return ret; } ELIB_THROW_EXCEPTION(web_error( "http::receive timed out" )); }; // get header while (true) { timeout_receive(); auto pos = parse(remaining.begin(), remaining.end(), msg.header); if (pos == remaining.begin()) continue; remaining.erase(remaining.begin(), pos); break; } // get fields and newline while (true) { auto field_end = parse(remaining.begin(), remaining.end(), msg.fields); remaining.erase(remaining.begin(), field_end); auto newl_end = parse_newl(remaining.begin(), remaining.end()); bool have_newl = newl_end != remaining.begin(); remaining.erase(remaining.begin(), newl_end); if (have_newl) break; // receive must only happen if we fail to parse till the // newline break. othewise we could be waiting on a message // we already have timeout_receive(); } std::size_t const con_size = content_size(msg); ELIB_ASSERT(con_size >= remaining.size()); // get remaining data if needed while (remaining.size() != con_size) { timeout_receive(); } msg.data.insert(msg.data.end(), remaining.begin(), remaining.end()); return msg; }
void EngineView::update_camera() { auto size = content_size(); auto& camera = _scene_view.camera(); math::Vec3 cam_pos = camera.position(); math::Vec3 cam_fwd = camera.forward(); math::Vec3 cam_lft = camera.left(); if(ImGui::IsWindowFocused()) { float cam_speed = 500.0f; float dt = cam_speed / ImGui::GetIO().Framerate; if(ImGui::IsKeyDown(int(context()->settings().camera().move_forward))) { cam_pos += cam_fwd * dt; } if(ImGui::IsKeyDown(int(context()->settings().camera().move_backward))) { cam_pos -= cam_fwd * dt; } if(ImGui::IsKeyDown(int(context()->settings().camera().move_left))) { cam_pos += cam_lft * dt; } if(ImGui::IsKeyDown(int(context()->settings().camera().move_right))) { cam_pos -= cam_lft * dt; } if(ImGui::IsMouseDown(1)) { auto delta = math::Vec2(ImGui::GetIO().MouseDelta) / math::Vec2(ImGui::GetWindowSize()); delta *= context()->settings().camera().sensitivity; { auto pitch = math::Quaternion<>::from_axis_angle(cam_lft, delta.y()); cam_fwd = pitch(cam_fwd); } { auto yaw = math::Quaternion<>::from_axis_angle(cam_fwd.cross(cam_lft), -delta.x()); cam_fwd = yaw(cam_fwd); cam_lft = yaw(cam_lft); } auto euler = math::Quaternion<>::from_base(cam_fwd, cam_lft, cam_fwd.cross(cam_lft)).to_euler(); bool upside_down = cam_fwd.cross(cam_lft).z() < 0.0f; euler[math::Quaternion<>::RollIndex] = upside_down ? -math::pi<float> : 0.0f; auto rotation = math::Quaternion<>::from_euler(euler); cam_fwd = rotation({1.0f, 0.0f, 0.0f}); cam_lft = rotation({0.0f, 1.0f, 0.0f}); } if(ImGui::IsMouseDown(2)) { auto delta = ImGui::GetIO().MouseDelta; cam_pos -= (delta.y * cam_fwd.cross(cam_lft) + delta.x * cam_lft); } } float fov = math::to_rad(60.0f); auto proj = math::perspective(fov, float(size.x()) / float(size.y()), 1.0f); auto view = math::look_at(cam_pos, cam_pos + cam_fwd, cam_fwd.cross(cam_lft)); camera.set_proj(proj); camera.set_view(view); /*auto& camera = _scene_view.camera(); math::Vec3 cam_pos = camera.position(); math::Vec3 cam_fwd = camera.forward(); math::Vec3 cam_lft = camera.left(); math::Vec3 cam_up = camera.up(); if(ImGui::IsWindowFocused()) { float cam_speed = 500.0f; float dt = cam_speed / ImGui::GetIO().Framerate; if(ImGui::IsKeyDown(int(context()->settings().camera().move_forward))) { cam_pos += cam_fwd * dt; } if(ImGui::IsKeyDown(int(context()->settings().camera().move_backward))) { cam_pos -= cam_fwd * dt; } if(ImGui::IsKeyDown(int(context()->settings().camera().move_left))) { cam_pos += cam_lft * dt; } if(ImGui::IsKeyDown(int(context()->settings().camera().move_right))) { cam_pos -= cam_lft * dt; } } if(ImGui::IsMouseDown(1)) { math::Vec3 view_vec = cam_pos - _picked_pos; // trackball auto delta = math::Vec2(ImGui::GetIO().MouseDelta) / math::Vec2(ImGui::GetWindowSize()); delta *= context()->settings().camera().sensitivity; { auto pitch = math::Quaternion<>::from_axis_angle(cam_lft, delta.y()); view_vec = pitch(view_vec); } { auto yaw = math::Quaternion<>::from_axis_angle(cam_up, delta.x()); view_vec = yaw(view_vec); } cam_pos = view_vec + _picked_pos; } auto view = math::look_at(cam_pos, cam_pos + cam_fwd, cam_fwd.cross(cam_lft)); camera.set_view(view);*/ }
// Using memory copy method to append a C array to buffer, inline void append(const void * c, int size){ // size unit is byte expand_to(content_size() + size) ; memcpy(current, c, size); current = current + size; }