void serializefrom(Costume &tgt, BitStream &src,const ColorAndPartPacker *packer) { tgt.m_body_type = src.GetPackedBits(3); // 0:male normal tgt.skin_color = src.GetBits(32); // rgb tgt.m_height = src.GetFloat(); tgt.m_physique = src.GetFloat(); tgt.m_send_full_costume = src.GetBits(1); tgt.m_num_parts = src.GetPackedBits(4); try { for(int costume_part=0; costume_part<tgt.m_num_parts;costume_part++) { CostumePart part; part.m_full_part = tgt.m_send_full_costume; ::serializefrom(part,src,packer); tgt.m_parts.push_back(part); } } catch(cereal::RapidJSONException &e) { qWarning() << e.what(); } catch(std::exception &e) { qCritical() << e.what(); } }
int NetStructure::getBitsConditional( BitStream &bs,int numbits ) { if(bs.GetBits(1)) { return bs.GetBits(numbits); } return 0; }
int getBitsConditional( BitStream &bs,uint32_t numbits ) { if(bs.GetBits(1)) { return bs.GetBits(numbits); } return 0; }
// ******************************************************************************************** void Block::ReadLzMatches(BitStream &bit_stream, LzMatcher &lz_matcher) { for (uint32 i = 0; i < rec_count; ++i) { uint32 tmp(0); // remove warning... bit_stream.GetBit(tmp); lz_matches[i].length = tmp; if (!lz_matches[i].length) { bit_stream.GetBit(tmp); records[i].lz_inserted = tmp != 0; } } bit_stream.FlushInputWordBuffer(); // DNA data uint32 rec_no_bits = BitStream::BitLength(b_start_rec_no + rec_count - 1); uint32 length_bits; uint32 offset_bits = (uint32)MAX(0, (int32)global_max_sequence_length - (int32)lz_matcher.GetMinMatchLen()); if (offset_bits) { offset_bits = BitStream::BitLength(offset_bits); } for (uint32 i = 0; i < rec_count; ++i) { if (lz_matches[i].length > 0) { uint32 tmp; bit_stream.GetBits(tmp, rec_no_bits); lz_matches[i].rec_no = tmp; length_bits = (uint32)MAX(0, MIN((int32)records[i].sequence_len - (int32)lz_matcher.GetMinMatchLen(), 255)); if (length_bits) { length_bits = BitStream::BitLength(length_bits); bit_stream.GetBits(tmp, length_bits); } else { tmp = 0; } lz_matches[i].length = tmp + lz_matcher.GetMinMatchLen(); if (offset_bits) { bit_stream.GetBits(tmp, offset_bits); } else { tmp = 0; } lz_matches[i].rec_offset = tmp; } } bit_stream.FlushInputWordBuffer(); }
// ******************************************************************************************** void Block::ReadQualityRLE(BitStream &bit_stream, std::vector<uchar> &qualities, std::vector<HuffmanEncoder*> &Huffman_qua, int32 /*n_qualities*/, std::vector<HuffmanEncoder*> &Huffman_run, int32 /*max_run_len*/) { int32 max_len = 0; uint32 i = 0; for (; i < rec_count; ++i) { max_len += records[i].quality_len; } qua_stream_len = run_stream_len = max_len; qua_stream = new uchar[max_len]; run_stream = new uchar[max_len]; uint32 prev = 0; i = 0; for (uint32 j = 0; j < qua_stream_len; ++i) { int32 h_tmp; uint32 bit; // Quality data bit_stream.GetBits(bit, Huffman_qua[prev]->GetMinLen()); h_tmp = Huffman_qua[prev]->DecodeFast(bit); while (h_tmp < 0) { bit_stream.GetBit(bit); h_tmp = Huffman_qua[prev]->Decode(bit); }; my_assert(h_tmp < (int32)qualities.size()); qua_stream[i] = qualities[h_tmp]; prev = h_tmp; // Run data bit_stream.GetBits(bit, Huffman_run[prev]->GetMinLen()); h_tmp = Huffman_run[prev]->DecodeFast(bit); while (h_tmp < 0) { bit_stream.GetBit(bit); h_tmp = Huffman_run[prev]->Decode(bit); }; run_stream[i] = (uchar) h_tmp; j += h_tmp+1; } bit_stream.FlushInputWordBuffer(); }
void serializefrom_base(BitStream &bs) { field0 = bs.GetBits(32); //field_0 time_res = bs.GetBits(32); // get_time_resl timestep = bs.GetFloat(); //v7->timestep time_rel1C = timestep; if(bs.GetBits(1)) //timestep!=time_rel1C time_rel1C = bs.GetFloat(); m_perf_cntr_diff = bs.Get64Bits(); //next_state->ticks - current_state->ticks m_perf_cntr_diff = bs.Get64Bits(); //v7->perf_cntr1 }
// ******************************************************************************************** void Block::ReadQualityPlain(BitStream &bit_stream, std::vector<uchar> &qualities, std::vector<HuffmanEncoder*> &Huffman_qua, int32 /*n_qualities*/, bool trucated_hashes, bool /*uses_const_delta*/) { // Quality data for (uint32 i = 0; i < rec_count; ++i) { no_of_amb[i] = 0; uchar *cur_quality = records[i].quality; uint32 cur_quality_len = records[i].quality_len; uint32 trunc_len = 0; if (trucated_hashes) // Truncate # { uint32 is_truncated(0); // skip warning... bit_stream.GetBit(is_truncated); if (is_truncated) { bit_stream.GetBits(trunc_len, BitStream::BitLength(cur_quality_len)); } } for (uint32 j = 0; j < cur_quality_len-trunc_len; ++j) { uint32 bit; int32 h_tmp; bit_stream.GetBits(bit, Huffman_qua[j+1]->GetMinLen()); h_tmp = Huffman_qua[j+1]->DecodeFast(bit); while (h_tmp < 0) { bit_stream.GetBit(bit); h_tmp = Huffman_qua[j+1]->Decode(bit); }; if ((cur_quality[j] = qualities[h_tmp]) >= 128) { no_of_amb[i]++; } } for (uint32 j = cur_quality_len-trunc_len; j < cur_quality_len; ++j) { cur_quality[j] = '#'; } } bit_stream.FlushInputWordBuffer(); }
uint32_t NetStructure::getCached_Color( BitStream &bs ) { bool in_hash= bs.GetBits(1); if(in_hash) { uint16_t hash_idx =bs.GetBits(colorcachecount_bitlength); uint32_t *kv = WorldData::instance()->colors().key_for_idx(hash_idx); if(kv) return *kv; return 0; } else return bs.GetBits(32); return 0; }
// recover actual ControlState from network data and previous entry void serializefrom_delta(BitStream &bs,const ControlState &prev) { field0 = bs.GetPackedBits(1); // field_0 diff next-current time_res = bs.GetPackedBits(1); // time to next state ? timestep = bs.GetFloat(); // next state's timestep time_rel1C = timestep; if(bs.GetBits(1)) //timestep!=time_rel1C time_rel1C = bs.GetFloat(); m_perf_cntr_diff = bs.Get64Bits(); //next_state->ticks - current_state->ticks if(bs.GetBits(1)) { // perf freq changed between current and next m_perf_freq_diff = bs.Get64Bits(); } }
//TODO: use generic ReadableStructures here ? void RecvInputState::recv_client_opts(BitStream &bs) { ClientOptions opts; ClientOption *entry; glm::vec3 vec; int cmd_idx; while((cmd_idx = bs.GetPackedBits(1))!=0) { entry=opts.get(cmd_idx-1); if (!entry) { qWarning() << "recv_client_opts missing opt for cmd index" << cmd_idx-1; continue; } for(ClientOption::Arg &arg : entry->m_args) { switch ( arg.type ) { case ClientOption::t_int: { *((int32_t *)arg.tgt) = bs.GetPackedBits(1); break; } case ClientOption::t_float: { *((float *)arg.tgt)=bs.GetFloat(); break; } case ClientOption::t_quant_angle: { float * tgt_angle = (float *)arg.tgt; *tgt_angle = AngleDequantize(bs.GetBits(14),14); qCDebug(logInput, "Quant angle res:%f", *tgt_angle); //dequantized angle break; } case ClientOption::t_string: case ClientOption::t_sentence: { QString v; bs.GetString(v); break; } case ClientOption::t_vec3: { for (int j = 0; j < 3; ++j ) { vec[j] = bs.GetFloat(); } break; } default: continue; } } } }
void UpdateServer::serializefrom( BitStream &src ) { m_build_date = src.GetPackedBits(1); /*uint32_t t =*/ src.GetPackedBits(1); src.GetString(currentVersion); src.GetBitArray(clientInfo,sizeof(clientInfo)*8); authID = src.GetPackedBits(1); authCookie = src.GetBits(32); src.GetString(accountName); }
//TODO: use generic ReadableStructures here ? void InputState::recv_client_opts(BitStream &bs) { ClientOptions opts; ClientOption *entry; int opt_idx=0; int some_idx = bs.GetPackedBits(1); entry=opts.get(opt_idx)-1; Vector3 vec; while(some_idx!=0) { for(size_t i=0; i<entry->m_args.size(); i++) { ClientOption::Arg &arg=entry->m_args[i]; switch ( arg.type ) { case ClientOption::t_int: { *((int32_t *)arg.tgt) = bs.GetPackedBits(1); break; } case ClientOption::t_float: { *((float *)arg.tgt)=bs.GetFloat(); break; } case ClientOption::t_quant_angle: { printf("Quant:%d\n",bs.GetBits(14)); //quantized angle break; } case ClientOption::t_string: case 4: { std::string v; bs.GetString(v); break; } case ClientOption::t_vec3: { for (int j = 0; j < 3; ++j ) { vec.v[j] = bs.GetFloat(); } break; } default: continue; } } some_idx = bs.GetPackedBits(1)-1; opt_idx++; entry=opts.get(opt_idx); } }
void NewEntity::serializefrom( BitStream &bs ) { // the very first time an entity is created (character creation) m_cookie = bs.GetPackedBits(1); //m_city_of_developers = src.GetBits(1); m_new_character=bs.GetBits(1); if(m_new_character) { m_character_data.appendBitStream(bs); } }
void RecvInputState::serializefrom(BitStream &bs) { m_next_state.m_full_timeupdate = false; // possibly some kind of full_update flag that is used elsewhere also if(bs.GetBits(1)) extended_input(bs); m_next_state.m_has_target = bs.GetBits(1); m_next_state.m_target_idx = bs.GetPackedBits(14); // targeted entity server_index qCDebug(logTarget, "Has Target? %d | TargetIdx: %d", m_next_state.m_has_target, m_next_state.m_target_idx); TimeState prev_fld; int ctrl_idx = 0; while(bs.GetBits(1)) // receive control state array entries ? { TimeState fld; if(ctrl_idx) { fld.serializefrom_delta(bs, prev_fld); } else // initial values { fld.serializefrom_base(bs); } fld.dump(); prev_fld = fld; ctrl_idx++; } recv_client_opts(bs); // g_pak contents will follow if(bs.GetReadableBits()>0) { m_user_commands.ResetOffsets(); bs.ByteAlign(true,false); m_user_commands.StoreBitArray(bs.read_ptr(),bs.GetReadableBits()); // all remaining bits were moved to m_user_commands. bs.SetReadPos(bs.GetWritePos()); } }
void InputState::extended_input(BitStream &bs) { has_input_commit_guess = bs.GetBits(1); if(has_input_commit_guess) // list of partial_2 follows { m_csc_deltabits=bs.GetBits(5) + 1; // number of bits in max_time_diff_ms someOtherbits = bs.GetBits(16);//ControlStateChange::field_8 or OptRel::field_19A8 current_state_P = 0; #ifdef DEBUG_INPUT fprintf(stderr,"CSC_DELTA[%x-%x] : ",m_csc_deltabits,someOtherbits); #endif partial_2(bs); } controlBits = 0; for(int idx=0; idx<6; ++idx) controlBits |= (bs.GetBits(1))<<idx; #ifdef DEBUG_INPUT if(controlBits) fprintf(stderr,"E input %x : ",controlBits); #endif if(bs.GetBits(1))//if ( abs(s_prevTime - ms_time) < 1000 ) { m_A_ang11_probably = bs.GetBits(11);//pak->SendBits(11, control_state.field_1C[0]); m_B_ang11_probably = bs.GetBits(11);//pak->SendBits(11, control_state.field_1C[1]); #ifdef DEBUG_INPUT fprintf(stderr,"%f : %f",m_A_ang11_probably/2048.0,m_A_ang11_probably/2048.0); #endif } }
void InputState::serializefrom(BitStream &bs) { m_send_deltas=false; #ifdef DEBUG_INPUT fprintf(stderr,"\nI:"); #endif if(bs.GetBits(1)) extended_input(bs); bool has_targeted_entity = bs.GetBits(1); int tgt_idx=bs.GetPackedBits(14); // targeted entity server index int ctrl_idx=0; #ifdef DEBUG_INPUT fprintf(stderr,"T:[%d]",has_targeted_entity); if(has_targeted_entity) fprintf(stderr,"TI:[%d]",tgt_idx); #endif ControlState prev_fld; while(bs.GetBits(1)) // receive control state array entries ? { ControlState fld; if(ctrl_idx) { fld.serializefrom_delta(bs,prev_fld); } else // initial values { fld.serializefrom_base(bs); } fld.dump(); prev_fld = fld; ctrl_idx++; } recv_client_opts(bs); // g_pak contents will follow #ifdef DEBUG_INPUT fprintf(stderr,"\n"); #endif }
int NetCommand::serializefrom( BitStream &bs ) { for(size_t i=0; i<m_arguments.size(); i++) { switch(m_arguments[i].type) { case 1: { int res=bs.GetPackedBits(1); if(m_arguments[i].targetvar) *((int *)m_arguments[i].targetvar) = res; qDebug("CommRecv %s:arg%zu : %d", qPrintable(m_name),i,res); break; } case 2: case 4: { QString res; bs.GetString(res); // postprocessed qDebug("CommRecv %s:arg%zu : %s", qPrintable(m_name),i,qPrintable(res)); break; } case 3: { float res = bs.GetFloat(); qDebug("CommRecv %s:arg%zu : %f", qPrintable(m_name),i,res); break; } case 5: { float res1 = normalizedCircumferenceToFloat(bs.GetBits(14),14); qDebug("CommRecv %s:arg%zu : %f", qPrintable(m_name),i,res1); break; } case 6: break; case 7: { float res1 = bs.GetFloat(); float res2 = bs.GetFloat(); float res3 = bs.GetFloat(); qDebug("CommRecv %s:arg%zu : %f,%f,%f", qPrintable(m_name),i,res1,res2,res3); break; } } } return 1; }
std::string NetStructure::getCached_String( BitStream &bs ) { std::ostringstream strm; std::string tgt(""); bool in_cache= bs.GetBits(1); if(in_cache) { int in_cache_idx = bs.GetPackedBits(stringcachecount_bitlength); std::string *kv = WorldData::instance()->strings().key_for_idx(in_cache_idx); if(kv) tgt=*kv; return tgt; } else bs.GetString(tgt); return tgt; }
void SaveClientOptions::serializefrom(BitStream & bs) { qDebug() << "Serializing options from Client"; data.m_mouse_speed = bs.GetFloat(); data.m_turn_speed = bs.GetFloat(); data.m_mouse_invert = bs.GetBits(1); data.m_fade_chat_wnd = bs.GetBits(1); data.m_fade_nav_wnd = bs.GetBits(1); data.m_show_tooltips = bs.GetBits(1); data.m_allow_profanity = bs.GetBits(1); data.m_chat_balloons = bs.GetBits(1); data.m_show_archetype = (ReticleVisibility)bs.GetBits(3); data.m_show_supergroup = (ReticleVisibility)bs.GetBits(3); data.m_show_player_name = (ReticleVisibility)bs.GetBits(3); data.m_show_player_bars = (ReticleVisibility)bs.GetBits(3); data.m_show_enemy_name = (ReticleVisibility)bs.GetBits(3); data.m_show_enemy_bars = (ReticleVisibility)bs.GetBits(3); data.m_show_player_reticles = (ReticleVisibility)bs.GetBits(3); data.m_show_enemy_reticles = (ReticleVisibility)bs.GetBits(3); data.m_show_assist_reticles = (ReticleVisibility)bs.GetBits(3); data.m_chat_font_size = bs.GetPackedBits(5); }
void RecvInputState::extended_input(BitStream &bs) { bool keypress_state; m_next_state.m_full_input_packet = bs.GetBits(1); if(m_next_state.m_full_input_packet) // list of partial_2 follows { m_next_state.m_csc_deltabits = bs.GetBits(5) + 1; // number of bits in max_time_diff_ms m_next_state.m_send_id = bs.GetBits(16); //qCDebug(logInput, "CSC_DELTA[%x-%x-%x] : ", m_current.m_csc_deltabits, m_current.m_send_id, m_current.current_state_P); receiveControlState(bs); // formerly partial_2 } // Key Pressed/Held for(int idx=0; idx<6; ++idx) { keypress_state = bs.GetBits(1); m_next_state.m_control_bits[idx] = keypress_state; if(keypress_state==true) { m_next_state.m_keypress_start[idx] = std::chrono::steady_clock::now(); processDirectionControl(&m_next_state, idx, 0, keypress_state); qCDebug(logInput, "keypress down %d", idx); } } if (m_next_state.m_control_bits != 0) m_next_state.m_input_received = true; if(bs.GetBits(1)) //if ( abs(s_prevTime - ms_time) < 1000 ) { m_next_state.m_orientation_pyr[0] = AngleDequantize(bs.GetBits(11),11); m_next_state.m_orientation_pyr[1] = AngleDequantize(bs.GetBits(11),11); qCDebug(logOrientation, "extended pitch: %f \tyaw: %f", m_next_state.m_orientation_pyr[0], m_next_state.m_orientation_pyr[1]); } }
void getTransformMatrix(BitStream &bs, glm::mat4x3 &src ) { if(bs.GetBits(1)) assert(!"PACKED ARRAY RECEIVED!"); bs.GetBitArray((uint8_t *)glm::value_ptr(src),sizeof(glm::mat4x3)*8); }
void InputState::partial_2(BitStream &bs) { uint8_t control_id; //uint16_t v6; uint16_t time_since_prev; int v; static const char *control_name[] = {"FORWARD", "BACK", "LEFT", "RIGHT", "UP", "DOWN"}; do { if(bs.GetBits(1)) control_id = 8; else control_id = bs.GetBits(4); if(bs.GetBits(1)) // time_since_prev=bs.GetBits(2)+32; else time_since_prev=bs.GetBits(m_csc_deltabits); switch(control_id) { case 0: case 1: case 2: case 3: case 4: case 5: fprintf(stderr,"%s : %d - ",control_name[control_id],time_since_prev); processDirectionControl(control_id,time_since_prev,bs.GetBits(1)); break; case 6: case 7: { v = bs.GetBits(11); // v = (x+pi)*(2048/2pi) // x = (v*(pi/1024))-pi float recovered = (float(v)/2048.0f)*(2*M_PI) - M_PI; if(control_id==6) //TODO: use camera_pyr.v[] here ? camera_pyr.x = recovered; else camera_pyr.y = recovered; fprintf(stderr,"Pyr %f : %f \n",camera_pyr.x,camera_pyr.y); break; } case 8: v = bs.GetBits(1); fprintf(stderr," C8[%d] ",v); if ( m_send_deltas ) { m_t1=bs.GetPackedBits(8); m_t2=bs.GetPackedBits(8); } else { m_send_deltas = true; m_t1=bs.GetBits(32); m_t2=bs.GetPackedBits(10); } fprintf(stderr,"t1:t2 [%d,%d] ",m_t1,m_t2); if(bs.GetBits(1)) { v=bs.GetBits(8); fprintf(stderr,"v [%d] ",v); } break; case 9: //a2->timerel_18 //fprintf(stderr,"CtrlId %d : %d - ",control_id,time_since_prev); fprintf(stderr,"C9:%d ",bs.GetBits(8)); break; case 10: fprintf(stderr,"C10 : %d - ",time_since_prev); fprintf(stderr,"%d\n",bs.GetBits(1)); //a2->timerel_18 & 1 break; default: assert(!"Unknown control_id"); } } while(bs.GetBits(1)); }
void RecvInputState::receiveControlState(BitStream &bs) // formerly partial_2 { uint8_t control_id = 0; uint32_t ms_since_prev = 0; float angle = 0.0f; do { if(bs.GetBits(1)) control_id = 8; else control_id = bs.GetBits(4); if(bs.GetBits(1)) ms_since_prev = bs.GetBits(2)+32; // delta from prev event else ms_since_prev = bs.GetBits(m_next_state.m_csc_deltabits); if (control_id < 8) m_next_state.m_input_received = true; m_next_state.m_ms_since_prev = ms_since_prev; switch(control_id) { case FORWARD: case BACKWARD: case LEFT: case RIGHT: case UP: case DOWN: { bool keypress_state = bs.GetBits(1); // get keypress state auto now_ms = std::chrono::steady_clock::now(); m_next_state.m_svr_keypress_time[control_id] = now_ms - m_next_state.m_keypress_start[control_id]; m_next_state.m_control_bits[control_id] = keypress_state; // save control_bits state processDirectionControl(&m_next_state, control_id, ms_since_prev, keypress_state); qCDebug(logInput, "key released %d", control_id); qCDebug(logInput, "svr vs client keypress time: %f %f : %f", m_next_state.m_svr_keypress_time[control_id].count(), m_next_state.m_keypress_time[control_id], m_next_state.m_ms_since_prev); break; } case PITCH: // camera pitch (Insert/Delete keybinds) { angle = AngleDequantize(bs.GetBits(11),11); // pitch m_next_state.m_pyr_valid[0] = true; m_next_state.m_camera_pyr[0] = angle; qCDebug(logInput, "Pitch (%f): %f", m_next_state.m_orientation_pyr[0], m_next_state.m_camera_pyr.x); break; } case YAW: // camera yaw (Q or E keybinds) { angle = AngleDequantize(bs.GetBits(11),11); // yaw m_next_state.m_pyr_valid[1] = true; m_next_state.m_camera_pyr[1] = angle; qCDebug(logInput, "Yaw (%f): %f", m_next_state.m_orientation_pyr[1], m_next_state.m_camera_pyr.y); break; } case 8: { m_next_state.m_controls_disabled = bs.GetBits(1); if ( m_next_state.m_full_timeupdate ) // sent_run_physics. maybe autorun? maybe is_running? { m_next_state.m_time_diff1 = bs.GetPackedBits(8); // value - previous_value m_next_state.m_time_diff2 = bs.GetPackedBits(8); // time - previous_time } else { m_next_state.m_full_timeupdate = true; m_next_state.m_time_diff1 = bs.GetBits(32); // value m_next_state.m_time_diff2 = bs.GetPackedBits(10); // value - time } /* qCDebug(logMovement, "Controls Disabled: %d time_diff1: %d \t time_diff2: %d", m_next_state.m_controls_disabled, m_next_state.m_time_diff1, m_next_state.m_time_diff2); */ if(bs.GetBits(1)) // if true velocity scale < 255 { m_next_state.m_velocity_scale = bs.GetBits(8); qCDebug(logInput, "Velocity Scale: %d", m_next_state.m_velocity_scale); } else m_next_state.m_velocity_scale = 255; break; } case 9: { m_next_state.m_every_4_ticks = bs.GetBits(8); // value goes to 0 every 4 ticks. Some kind of send_partial flag if(m_next_state.m_every_4_ticks != 1) qCDebug(logInput, "This goes to 0 every 4 ticks: %d", m_next_state.m_every_4_ticks); break; } case 10: { m_next_state.m_no_collision = bs.GetBits(1); qCDebug(logInput, "Collision: %d", m_next_state.m_no_collision); break; } default: assert(!"Unknown control_id"); } } while(bs.GetBits(1)); //qCDebug(logInput, "recv control_id 9 %f", m_next_state.m_every_4_ticks); }
void InputState::partial_2(BitStream &bs) { uint8_t control_id; //uint16_t v6; uint16_t time_since_prev; int v; static const char *control_name[] = {"FORWARD", "BACK", "LEFT", "RIGHT", "UP", "DOWN"}; do { if(bs.GetBits(1)) control_id = 8; else control_id = bs.GetBits(4); if(bs.GetBits(1)) time_since_prev=bs.GetBits(2)+32; // delta from prev event else time_since_prev=bs.GetBits(m_data.m_csc_deltabits); switch(control_id) { case 0: case 1: case 2: case 3: case 4: case 5: #ifdef DEBUG_INPUT fprintf(stderr,"%s : %d - ",control_name[control_id],time_since_prev); #endif m_data.processDirectionControl(control_id,time_since_prev,bs.GetBits(1)); break; case 6: case 7: { v = bs.GetBits(11); // v = (x+pi)*(2048/2pi) // x = (v*(pi/1024))-pi float recovered = (float(v)/2048.0f)*(2*M_PI) - M_PI; m_data.pyr_valid[control_id==7] = true; if(control_id==6) //TODO: use camera_pyr.v[] here ? m_data.camera_pyr[0] = recovered; else m_data.camera_pyr[1] = recovered; fprintf(stderr,"Pyr %f : %f \n",m_data.camera_pyr.x,m_data.camera_pyr.y); break; } case 8: v = bs.GetBits(1); #ifdef DEBUG_INPUT fprintf(stderr," C8[%d] ",v); #endif if ( m_data.m_send_deltas ) { m_data.m_t1=bs.GetPackedBits(8); // value - previous_value m_data.m_t2=bs.GetPackedBits(8); // time - previous_time } else { m_data.m_send_deltas = true; m_data.m_t1=bs.GetBits(32); // value m_data.m_t2=bs.GetPackedBits(10); // value - time } #ifdef DEBUG_INPUT fprintf(stderr,"t1:t2 [%d,%d] ",m_data.m_t1,m_data.m_t2); #endif if(bs.GetBits(1)) { m_data.field_20=bs.GetBits(8); #ifdef DEBUG_INPUT fprintf(stderr,"v [%d] ",v); #endif } break; case 9: { //a2->timerel_18 //fprintf(stderr,"CtrlId %d : %d - ",control_id,time_since_prev); uint8_t s=bs.GetBits(8); #ifdef DEBUG_INPUT fprintf(stderr,"C9:%d ",s); #endif } break; case 10: { uint8_t s=bs.GetBits(1); #ifdef DEBUG_INPUT fprintf(stderr,"C10 : %d - ",time_since_prev); fprintf(stderr,"%d\n",s); //a2->timerel_18 & 1 #endif } break; default: assert(!"Unknown control_id"); } } while(bs.GetBits(1)); }
// ******************************************************************************************** void Block::Read(BitStream &bit_stream, LzMatcher &lz_matcher, std::vector<Field> &fields, uint32 n_fields, uint32 fastq_flags, std::vector<uchar> &symbols, HuffmanEncoder *Huffman_sym, std::vector<uchar> &qualities, std::vector<HuffmanEncoder*> &Huffman_qua, uint32 max_run_len, std::vector<HuffmanEncoder*> &Huffman_run, uint32 n_qualities, uint32 _global_max_sequence_length, uint32 max_quality_length, uint32 block_no, uint32 quality_stats_mode, bool extracting) { global_max_sequence_length = _global_max_sequence_length; #if (D_RESERVE_BYTES_PER_BLOCK) { uchar bytes[Block::RESERVED_BYTES]; bit_stream.GetBytes(bytes, Block::RESERVED_BYTES); for (uint32 i = 0; i < Block::RESERVED_BYTES; ++i) { my_assert(bytes[i] == INVALID_BYTE); } } #endif no_of_amb.resize(rec_count); for (uint32 i = 0; i < rec_count; ++i) { records[i].Reset(); no_of_amb[i] = 0; } int32 quality_len_bits = BitStream::BitLength(max_quality_length); if ((fastq_flags & FLAG_PLUS_ONLY) == 0) { for (uint32 i = 0; i < rec_count; ++i) { bit_stream.GetBit(records[i].plus_len); } } else { for (uint32 i = 0; i < rec_count; ++i) { records[i].plus_len = 1; } } if ((fastq_flags & FLAG_VARIABLE_LENGTH) != 0) { uint32 tmp; for (uint32 i = 0; i < rec_count; ++i) { FastqRecord& rec = records[i]; bit_stream.GetBits(tmp, quality_len_bits); rec.quality_len = tmp; rec.ExtendTo(rec.quality, rec.quality_size, tmp+2); rec.sequence_len = tmp; rec.ExtendTo(rec.sequence, rec.sequence_size, tmp+2); } } else { for (uint32 i = 0; i < rec_count; ++i) { FastqRecord& rec = records[i]; rec.quality_len = max_quality_length; rec.ExtendTo(rec.quality, rec.quality_size, max_quality_length+2); rec.sequence_len = global_max_sequence_length; rec.ExtendTo(rec.sequence, rec.sequence_size, global_max_sequence_length+2); } } if ((fastq_flags & FLAG_LINE_BREAKS) != 0) { uint32 line_breaks_bits; bit_stream.GetBits(line_breaks_bits, 5); uint32 tmp; for (uint32 i = 0; i < rec_count; ++i) { FastqRecord& rec = records[i]; if (rec.sequence_breaks) { delete rec.sequence_breaks; rec.sequence_breaks = NULL; } bit_stream.GetBits(tmp, line_breaks_bits); while (tmp != 0) { if (!rec.sequence_breaks) { rec.sequence_breaks = new std::vector<int>; } rec.sequence_breaks->push_back(tmp); bit_stream.GetBits(tmp, line_breaks_bits); } if (rec.quality_breaks) { delete rec.quality_breaks; rec.quality_breaks = NULL; } bit_stream.GetBits(tmp, line_breaks_bits); while (tmp != 0) { if (!rec.quality_breaks) { rec.quality_breaks = new std::vector<int>; } rec.quality_breaks->push_back(tmp); bit_stream.GetBits(tmp, line_breaks_bits); } } } bit_stream.FlushInputWordBuffer(); bool is_num_fields_constant = (fastq_flags & FLAG_CONST_NUM_FIELDS) != 0; ReadTitle(bit_stream, fields, n_fields, block_no, is_num_fields_constant); if (quality_stats_mode == QUALITY_RLE) { ReadQualityRLE(bit_stream, qualities, Huffman_qua, n_qualities, Huffman_run, max_run_len); MakeUnRLE(); } else { bool use_trunc_h = quality_stats_mode == QUALITY_PLAIN_TRUNC; bool uses_const_delta = (fastq_flags & (FLAG_USE_DELTA | FLAG_DELTA_CONSTANT)) == (FLAG_USE_DELTA | FLAG_DELTA_CONSTANT); ReadQualityPlain(bit_stream, qualities, Huffman_qua, n_qualities, use_trunc_h, uses_const_delta); } bool try_lz = (fastq_flags & FLAG_TRY_LZ) != 0; if ((fastq_flags & FLAG_DNA_PLAIN) != 0) { ReadDNAPlain(bit_stream, lz_matcher, symbols, try_lz, extracting); } else { ReadDNAHuf(bit_stream, lz_matcher, symbols, Huffman_sym, try_lz, extracting); // lz_matches not supported when Huffman encoding } #if (D_COMPUTE_RECORDS_CRC_PER_BLOCK) uint32 hash; bit_stream.GetWord(hash); my_assert(hash == ComputeRecordsCrc32()); #endif }
// ******************************************************************************************** void Block::ReadTitle(BitStream &bit_stream, std::vector<Field> &fields, uint32 n_fields, int32 block_no, bool is_num_fields_constant) { prev_value.resize(n_fields); uint32 n_fields_bits = BitStream::BitLength(n_fields); uint32 tmp = 0; for (uint32 i = 0; i < n_fields; ++i) { if (fields[i].is_constant) continue; prev_value[i] = 0; if (!fields[i].is_numeric) { bit_stream.GetBit(tmp); fields[i].block_desc[block_no].is_block_constant = tmp != 0; } else { bit_stream.GetBit(tmp); if (fields[i].is_delta_coding) { fields[i].block_desc[block_no].is_block_delta_constant = tmp != 0; } else { fields[i].block_desc[block_no].is_block_value_constant = tmp != 0; } } } for (uint32 i = 0; i < rec_count; ++i) { FastqRecord& cur_rec = records[i]; uint32 cn_fields = n_fields; if (!is_num_fields_constant) { bit_stream.GetBits(tmp, n_fields_bits); cn_fields = tmp; } for (uint32 j = 0; j < cn_fields; ++j) { Field &cur_field = fields[j]; if (cur_field.is_constant) { cur_rec.AppendTitle(cur_field.data, cur_field.len); cur_rec.AppendTitle(cur_field.sep); continue; } if (cur_field.is_numeric) { uint32 num_val = 0; if (cur_rec.title_len + 10 >= cur_rec.title_size) { cur_rec.Extend(cur_rec.title, cur_rec.title_size); } if (i == 0) { bit_stream.GetBits(num_val, cur_field.no_of_bits_per_value); num_val += cur_field.min_value; cur_rec.title_len += utils::to_string(cur_rec.title+cur_rec.title_len, num_val); prev_value[j] = num_val; } else { if ((cur_field.is_delta_coding && !cur_field.block_desc[block_no].is_block_delta_constant) || (!cur_field.is_delta_coding && !cur_field.block_desc[block_no].is_block_value_constant)) { if (cur_field.no_of_bits_per_num > 0) { if (cur_field.Huffman_global) { uint32 bit; int32 h_tmp; bit_stream.GetBits(bit, cur_field.Huffman_global->GetMinLen()); h_tmp = cur_field.Huffman_global->DecodeFast(bit); while (h_tmp < 0) { bit_stream.GetBit(bit); h_tmp = cur_field.Huffman_global->Decode(bit); }; num_val = h_tmp; } else { bit_stream.GetBits(num_val, cur_field.no_of_bits_per_num); } } else { num_val = 0; } } else { if (cur_field.is_delta_coding) { num_val = 0; } else { num_val = prev_value[j] - cur_field.min_value; } } if (cur_field.is_delta_coding) { num_val += prev_value[j] + cur_field.min_delta; } else { num_val += cur_field.min_value; } cur_rec.title_len += utils::to_string(cur_rec.title+cur_rec.title_len, num_val); prev_value[j] = num_val; } cur_rec.AppendTitle(cur_field.sep); continue; } if (i > 0 && cur_field.block_desc[block_no].is_block_constant) { cur_rec.AppendTitle(records[0].title+cur_field.block_str_start, cur_field.block_str_len); cur_rec.AppendTitle(cur_field.sep); continue; } uint32 field_len; if (!cur_field.is_len_constant) { bit_stream.GetBits(field_len, cur_field.no_of_bits_per_len); field_len += cur_field.min_len; } else { field_len = cur_field.len; } for (uint32 k = 0; k < field_len; ++k) { if (k < cur_field.len && cur_field.Ham_mask[k]) { cur_rec.AppendTitle(cur_field.data[k]); } else { uint32 bit; int32 h_tmp; HuffmanEncoder *cur_huf = cur_field.Huffman_local[MIN(k, Superblock::MAX_FIELD_STAT_LEN)]; bit_stream.GetBits(bit, cur_huf->GetMinLen()); h_tmp = cur_huf->DecodeFast(bit); while (h_tmp < 0) { bit_stream.GetBit(bit); h_tmp = cur_huf->Decode(bit); }; tmp = h_tmp; cur_rec.AppendTitle((uchar) tmp); } } if (i == 0 && cur_field.block_desc[block_no].is_block_constant) { cur_field.block_str_start = cur_rec.title_len - field_len; cur_field.block_str_len = field_len; } cur_rec.AppendTitle(cur_field.sep); } cur_rec.title_len--; // do not count last '\0' symbols cur_rec.plus[0] = '+'; if (cur_rec.plus_len == 1) { cur_rec.plus[1] = '\0'; } else { cur_rec.plus_len = cur_rec.title_len; cur_rec.ExtendTo(cur_rec.plus, cur_rec.plus_size, cur_rec.title_len+2); std::copy(cur_rec.title+1, cur_rec.title+cur_rec.title_len, cur_rec.plus+1); } } bit_stream.FlushInputWordBuffer(); }
// ******************************************************************************************** void Block::ReadDNAHuf(BitStream &bit_stream, LzMatcher &lz_matcher, std::vector<uchar> &symbols, HuffmanEncoder *Huffman_sym, bool try_lz, bool extracting) { // Info about LZ matches lz_matches.resize(rec_count); for (uint32 i = 0; i < rec_count; ++i) { records[i].sequence_len = records[i].quality_len - no_of_amb[i]; } if (try_lz) { ReadLzMatches(bit_stream, lz_matcher); for (uint32 i = 0; i < rec_count; ++i) { if (!extracting) DecodeLzMatches(lz_matcher, i); uint32 cur_sequence_len = records[i].sequence_len; uchar *cur_sequence = records[i].sequence; for (uint32 j = lz_matches[i].length; j < cur_sequence_len; ++j) { // Symbols uint32 bit; bit_stream.GetBits(bit, Huffman_sym->GetMinLen()); int32 h_tmp = Huffman_sym->DecodeFast(bit); while (h_tmp < 0) { bit_stream.GetBit(bit); h_tmp = Huffman_sym->Decode(bit); }; cur_sequence[j] = symbols[h_tmp]; } cur_sequence[cur_sequence_len] = '\0'; if (!extracting) DecodeLzMatches_Insert(lz_matcher, i); } } else { for (uint32 i = 0; i < rec_count; ++i) { lz_matches[i].length = 0; uint32 cur_sequence_len = records[i].sequence_len; uchar *cur_sequence = records[i].sequence; for (uint32 j = lz_matches[i].length; j < cur_sequence_len; ++j) { // Symbols uint32 bit; bit_stream.GetBits(bit, Huffman_sym->GetMinLen()); int32 h_tmp = Huffman_sym->DecodeFast(bit); while (h_tmp < 0) { bit_stream.GetBit(bit); h_tmp = Huffman_sym->Decode(bit); }; cur_sequence[j] = symbols[h_tmp]; } cur_sequence[cur_sequence_len] = '\0'; } } bit_stream.FlushInputWordBuffer(); }
void NetStructure::getTransformMatrix( BitStream &bs,Matrix4x3 &src ) { if(bs.GetBits(1)) assert(!"PACKED ARRAY RECEIVED!"); bs.GetBitArray((uint8_t*)&src,12*4*8); }