Пример #1
0
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();
    }
}
Пример #2
0
//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;
            }
        }
    }
}
Пример #3
0
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);
}
Пример #4
0
//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);
    }
}
Пример #5
0
int NetStructure::getPackedBitsConditional( BitStream &bs,int numbits )
{
    if(bs.GetBits(1))
    {
        return bs.GetPackedBits(numbits);
    }
    return 0;
}
Пример #6
0
int getPackedBitsConditional( BitStream &bs,uint8_t numbits )
{
    if(bs.GetBits(1))
    {
        return bs.GetPackedBits(numbits);
    }
    return 0;
}
Пример #7
0
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);
    }
}
Пример #8
0
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;
}
Пример #9
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();
        }
    }
Пример #10
0
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;
}
Пример #11
0
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());
    }
}
Пример #12
0
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);
}
Пример #13
0
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
}
Пример #14
0
void TradeWasUpdatedMessage::serializefrom(BitStream& bs)
{
    m_info.m_db_id     = static_cast<uint32_t>(bs.GetPackedBits(1));
    m_info.m_accepted  = bs.GetPackedBits(1);
    m_info.m_influence = static_cast<uint32_t>(bs.GetPackedBits(1));
    const int num_enhs = bs.GetPackedBits(1);
    const int num_insp = bs.GetPackedBits(1);

    for (int i = 0; i < num_enhs; ++i)
    {
        const uint32_t idx = static_cast<uint32_t>(bs.GetPackedBits(1));
        m_info.m_enhancements.push_back(idx);
    }

    for (int i = 0; i < num_insp; ++i)
    {
        const uint32_t col = static_cast<uint32_t>(bs.GetPackedBits(1));
        const uint32_t row = static_cast<uint32_t>(bs.GetPackedBits(1));
        m_info.m_inspirations.push_back(TradeInspiration(col, row));
    }
}
Пример #15
0
void CharacterResponse::serializefrom( BitStream &bs )
{
    bs.GetPackedBits(1);
    assert(!"TODO");
}
Пример #16
0
void UpdateCharacter::serializefrom( BitStream &bs )
{
    m_index = bs.GetPackedBits(1);
}
Пример #17
0
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));
}
Пример #18
0
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));
}
Пример #19
0
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);
}