Ejemplo n.º 1
0
Archivo: Csvex.cs Proyecto: mengtest/fs
    public bool Load(LusuoStream lf, Encoding encoding)
    {
        if (m_bLoaded)
        {
            return(true);
        }

        if (null == lf)
        {
            return(false);
        }
        Clear();
        bool bRef = m_csv.Load(lf, encoding);

        if (bRef)
        {
            _Load();
        }
        else
        {
            //Debug.LogError(this.GetType() + "表格错误!");
        }

        m_bLoaded = bRef;
        return(bRef);
    }
Ejemplo n.º 2
0
 public void Load(LusuoStream ls)
 {
     //Debug.Log("模型自身读取数据");
     m_resID = ls.ReadInt();
     ls.ReadString(out m_strName);
     ls.ReadVector3(ref m_vPos);
     ls.ReadVector3(ref m_vRotate);
     ls.ReadVector3(ref m_vScale);
     ls.ReadBool(ref m_bStatic);
     // 读取光照图
     ls.ReadInt(ref m_lightMapIndexNum);
     m_lightMapIndex       = new int[m_lightMapIndexNum];
     m_lightMapScaleOffset = new Vector4[m_lightMapIndexNum];
     for (int i = 0; i < m_lightMapIndexNum; i++)
     {
         ls.ReadInt(ref m_lightMapIndex[i]);
     }
     for (int i = 0; i < m_lightMapIndexNum; i++)
     {
         ls.ReadVector4(ref m_lightMapScaleOffset[i]);
     }
     // 读取环境音效
     ls.ReadInt(ref m_envSoundNum);
     m_envSoundResId = new int[m_envSoundNum];
     for (int i = 0; i < m_envSoundNum; i++)
     {
         ls.ReadInt(ref m_envSoundResId[i]);
     }
 }
Ejemplo n.º 3
0
        private void HandleMsg()
        {
            LusuoStream stream = new LusuoStream(m_recvBuffer);
            int         msgLen = stream.ReadInt();
            ushort      msgId  = stream.ReadUShort();
            //Debug.Log("接受消息长度:" + msgLen);
            //Debug.Log("接受消息ID:" + (eNetMessageID)msgId);
            // 通过消息头,获取消息体
            NetMessage msg = NetManager.Inst.GetMessage((eNetMessageID)msgId);

            msg.OnRecv(msgLen, ref stream);
            if (msg is FspMsgFrame)
            {
                msg.OnRecv();
                GameManager.Inst.AddFrameMsg(msg);
            }
            //msg.OnRecv();
            m_msgList.Add(msg);


            // 如果id段大于1000,那么就是lua协议
            //if (msgId > s_luaStartId)
            //{
            //    LuaMsgStruct data;
            //    data.id = msgId;
            //    data.msgLen = msgLen;
            //    data.stream = stream;
            //    m_luaMsgList.Add(data);
            //}
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 接受消息时的外部方法,读取流对象取数据
 /// 子类无需重写
 /// </summary>
 public void OnRecv(int contentLen, ref LusuoStream ls)
 {
     eno         = ls.ReadInt();
     structBytes = new byte[contentLen - StringHelper.s_ShortSize - StringHelper.s_IntSize];
     ls.Read(ref structBytes);
     //Debug.Log("消息:" + msgID + " eno:" + eno);
 }
Ejemplo n.º 5
0
        public void Save(ref LusuoStream ls)
        {
            //Debug.Log("模型自身保存数据");
            ls.WriteInt(m_resID);
            ls.WriteString(m_strName);
            ls.WriteVector3(m_vPos.x, m_vPos.y, m_vPos.z);
            ls.WriteVector3(m_vRotate.x, m_vRotate.y, m_vRotate.z);
            ls.WriteVector3(m_vScale.x, m_vScale.y, m_vScale.z);
            ls.WriteBool(m_bStatic);

            // 读取子模型个数,遍历写入个数,索引,和偏移
            ls.WriteInt(m_lightMapIndexNum);
            for (int i = 0; i < m_lightMapIndexNum; i++)
            {
                ls.WriteInt(m_lightMapIndex[i]);
            }
            for (int i = 0; i < m_lightMapIndexNum; i++)
            {
                ls.WriteVector4(ref m_lightMapScaleOffset[i]);
            }
            // 写入环境音效
            ls.WriteInt(m_envSoundNum);
            for (int i = 0; i < m_envSoundNum; i++)
            {
                ls.WriteInt(m_envSoundResId[i]);
            }
        }
Ejemplo n.º 6
0
Archivo: Csvex.cs Proyecto: mengtest/fs
    public bool Load(byte[] uData, Encoding coding)
    {
        LusuoStream lf   = new LusuoStream(uData);
        bool        bRef = Load(lf, coding);

        lf.Close();
        return(bRef);
    }
Ejemplo n.º 7
0
Archivo: Csvex.cs Proyecto: mengtest/fs
 public bool Save(LusuoStream lf, Encoding encoding)
 {
     if (null == m_csv)
     {
         return(false);
     }
     _Save();
     m_csv.Save(lf, encoding);
     return(true);
 }
Ejemplo n.º 8
0
        private void InitStaticData()
        {
            if (m_staticDynamic == null)
            {
                return;
            }
            byte[]      data = m_staticDynamic.GetData();
            LusuoStream ls   = new LusuoStream(data);

            m_width      = ls.ReadInt();
            m_hight      = ls.ReadInt();
            m_staticData = new byte[m_width * m_hight];
            ls.Read(ref m_staticData);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 消息发送时的内部方法,将逻辑结构体数据存放到ls中
        /// 子类无需重载
        /// </summary>
        public void SetByte <T>(T t, ref LusuoStream ls)
        {
            ls.WriteInt(0);           // 预留总字节数
            ls.WriteUShort(msgID);    // 写消息编号
            ls.WriteInt(eno);         // 写eno
            byte[] bytes = ProtobufHelper.Serialize <T>(t);
            ls.Write(ref bytes);      // 写具体结构体
            ls.Seek(0);
            // 内容字节数
            int contentLen = StringHelper.s_ShortSize + StringHelper.s_IntSize + bytes.Length;

            ls.WriteInt(contentLen);                         // 再次写内容长度
            msgMaxLen = StringHelper.s_IntSize + contentLen; // 长度字节数 + 内容字节数
        }
Ejemplo n.º 10
0
 private void SendMessageNew()
 {
     // 一次发送一条
     if (_m_bSending)
     {
         return;
     }
     if (_m_listMsg.Count > 0)
     {
         _m_bSending = true;
         LusuoStream msg = _m_listMsg[0];
         m_socket.BeginSend(msg.GetBuffer(), 0, msg.m_byteLen, SocketFlags.None, _SendedEnd, null);
         _m_listMsg.RemoveAt(0);
         //Debug.LogWarning("最后发送消息:" + (eNetMessageID)msg.msgID);
     }
 }
Ejemplo n.º 11
0
        public void SendMessage <T>(ushort msgID, T t)
        {
            LusuoStream stream = new LusuoStream(new byte[m_uBufferSize]);

            stream.WriteInt(0);                  // 预留总字节数
            stream.WriteUShort(msgID);           // 写消息编号
            stream.WriteInt(1);
            byte[] bytes = ProtobufHelper.Serialize <T>(t);
            stream.Write(ref bytes);              // 写具体结构体
            stream.Seek(0);
            // 内容字节数
            int contentLen = StringHelper.s_ShortSize + StringHelper.s_IntSize + bytes.Length;

            stream.WriteInt(contentLen);                            // 再次写内容长度
            stream.m_byteLen = StringHelper.s_IntSize + contentLen; // 长度字节数 + 内容字节数

            _m_listMsg.Add(stream);
        }
Ejemplo n.º 12
0
    private static bool ProcessCsvBytes()
    {
        // 用于检测CSV是否写人LogicSystem
        CsvManager.Inst = new CsvManager();
        LogicSystem logicSystem = new LogicSystem();

        logicSystem.InitCsv(ref CsvManager.Inst);

        // 将所有的csv文件写入到m_csvStream
        m_csvNums   = 0;
        m_csvStream = new LusuoStream(new FileStream(m_csvBytesPath, FileMode.Create));
        m_csvStream.WriteUInt(0); // 预留文件个数
        bool bSucc = ProcessCsvFile(new DirectoryInfo(m_csvPath));

        m_csvStream.Seek(0);
        m_csvStream.WriteUInt(m_csvNums);
        Debug.Log("成功写入csv个数:" + m_csvNums);
        m_csvStream.Close();

        return(bSucc);
    }
Ejemplo n.º 13
0
Archivo: Csvex.cs Proyecto: mengtest/fs
    public bool Load(string strPath, Encoding encoding)
    {
        if (string.IsNullOrEmpty(strPath))
        {
            return(false);
        }

        LusuoStream lf = null;

        try
        {
            lf = new LusuoStream(new FileStream(strPath, FileMode.Open));
        }
        catch (System.Exception)
        {
            return(false);
        }
        bool bRef = Load(lf, encoding);

        lf.Close();
        return(bRef);
    }
Ejemplo n.º 14
0
        private void _HandleMsgNew()
        {
            for (int i = 0; i < _m_listMsg.Count; i++)
            {
                LusuoStream stream = _m_listMsg[i];
                int         msgLen = stream.ReadInt();
                //ushort msgId = stream.ReadUShort();
                int msgId = stream.ReadInt();
                //Debug.Log("接受消息长度:" + msgLen);
                //Debug.Log("接受消息ID:" + (eNetMessageID)msgId);
                byte[] structBytes = new byte[msgLen - StringHelper.s_IntSize];
                stream.Read(ref structBytes);
                //MyMessage recv = ProtobufHelper.DeSerialize<MyMessage>(structBytes);

                //Action<MyMessage> OnRecv;
                //if (_m_msgList.TryGetValue(msgId, out OnRecv))
                //{
                //    if (OnRecv != null)
                //        OnRecv(recv);
                //}
            }
            _m_listMsg.Clear();
        }
Ejemplo n.º 15
0
Archivo: Csvex.cs Proyecto: mengtest/fs
    public void Save(string strPath, Encoding encoding, bool bNewCreate)
    {
        if (string.IsNullOrEmpty(strPath))
        {
            return;
        }
        LusuoStream lf = null;

        try
        {
            if (bNewCreate)
            {
                if (File.Exists(strPath))
                {
                    File.Delete(strPath);
                }

                string strFullPath = Path.GetDirectoryName(strPath);

                if (!Directory.Exists(strFullPath))
                {
                    Directory.CreateDirectory(strFullPath);
                }
            }

            lf = new LusuoStream(new FileStream(strPath, bNewCreate ? FileMode.CreateNew : FileMode.Truncate, FileAccess.Write));
        }
        catch (System.Exception ex)
        {
            //Debug.LogError("Cann't Open csv  errinfo=" + ex.Message);
            return;
        }
        Save(lf, encoding);

        lf.Close();
    }
Ejemplo n.º 16
0
        private void HandleMsg(Conn conn)
        {
            LusuoStream stream     = new LusuoStream(conn.readBuff);
            int         contentLen = stream.ReadInt();
            ushort      msgId      = stream.ReadUShort();
            NetMessage  msg        = NetManager.Inst.GetMessage(msgId);

            if (msg == null)
            {
                return;
            }
            if (msgId != (int)eNetMessageID.MsgHeartBeat)
            {
                Console.WriteLine(m_serverType + ":接受消息:" + (eNetMessageID)msgId);
            }
            msg.OnRecv(ref conn, contentLen, ref stream);

            MessageCache cache;

            cache.conn = conn;
            cache.msg  = msg;
            // 每次接受存起来,然后一阵一个
            msgList.Add(cache);
        }
Ejemplo n.º 17
0
 public override void ToByte(ref LusuoStream ls)
 {
     eno = 0;
     //SetByte<int>(m_matchResult, ref ls);
 }
Ejemplo n.º 18
0
    private static void ProcessResBytes()
    {
        m_resInfoCsv     = new AllResInfoCsv();
        m_mapNameResInfo = new Dictionary <string, ResInfo>(); // 下面批处理文件时,处理一个加一个,会审核是否有重复资源
        m_lstResinfo     = new List <ResInfo>();               // 保持时使用的数据
        m_setUseList     = new HashSet <int>();                // 存资源id
        m_curResID       = 0;

        bool b = m_resInfoCsv.Load(m_resCsvPath, Encoding.Default);

        if (!b)
        {
            Debug.LogError("注意: 资源总表,打开csv失败。");
            return;
        }

        foreach (ResInfo key in m_resInfoCsv.m_lstResinfo)
        {
            m_setUseList.Add(key.nResID);
        }

        string strFull = Path.GetDirectoryName(m_resPath);

        Directory.CreateDirectory(strFull);

        // 然后处理该文件夹中所有的文件
        ProcessResFile(new DirectoryInfo(m_resPath));

        // 然后遍历原始资源表列表,将无资源的预留id也写入到资源列表
        foreach (ResInfo oldItem in m_resInfoCsv.m_lstResinfo)
        {
            bool bHave = false;
            foreach (ResInfo newItem in m_lstResinfo)
            {
                if (oldItem.nResID == newItem.nResID)
                {
                    bHave = true;
                }
            }
            // 如果新的不包含,就加到新的
            if (!bHave)
            {
                oldItem.iType  = ResType.None;
                oldItem.strUrl = "";
                if (m_mapNameResInfo.ContainsKey(oldItem.strName))
                {
                    Debug.LogError("总资源表含有重复的资源:" + oldItem.strName);
                    continue;
                }
                m_mapNameResInfo.Add(oldItem.strName, oldItem);
                m_lstResinfo.Add(oldItem);
            }
        }

        m_resInfoCsv.Clear();
        m_resInfoCsv.m_mapNameResInfo = m_mapNameResInfo;
        m_resInfoCsv.m_lstResinfo     = m_lstResinfo;

        // 保存资源总配置文件
        m_resInfoCsv.Save("", Encoding.Default, true);

        // 生成二进制文件
        FileStream stream =
            new FileStream(m_resBytesPath, FileMode.Create);
        LusuoStream ls    = new LusuoStream(stream);
        int         iNums = m_lstResinfo.Count;

        ls.WriteInt(iNums);                     // 将真的资源个数写入到流的开始位置
        Debug.Log("成功写入资源个数:" + iNums);
        foreach (KeyValuePair <string, ResInfo> item in m_mapNameResInfo)
        {
            item.Value.Save(ref ls);
        }
        ls.Close();
    }
Ejemplo n.º 19
0
 public override void ToByte(ref LusuoStream ls)
 {
     //SetByte<GC_PlayerPublicData>(playerData, ref ls);
 }
Ejemplo n.º 20
0
 public override void ToByte(ref LusuoStream ls)
 {
     eno = 0;
     SetByte <float[]>(m_sendProgress, ref ls);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 消息发送时的外部方法,将内部结构体数据存放到ls中
 /// 子类需重写无需重载,并调用 SetByte<T>
 /// </summary>
 public virtual void ToByte(ref LusuoStream ls)
 {
     Debug.Log("发送基类,把数据写入到Stream");
 }
Ejemplo n.º 22
0
 public override void ToByte(ref LusuoStream ls)
 {
     eno = 0;
     SetByte(m_progress, ref ls);
 }
Ejemplo n.º 23
0
 public override void Start()
 {
     // 填入IP等,进行连接初始化
     m_stream = new LusuoStream(new byte[m_uBufferSize]);
 }
Ejemplo n.º 24
0
    private static bool ProcessCsvFile(DirectoryInfo folder)
    {
        DirectoryInfo[] dirInfo = folder.GetDirectories();
        foreach (DirectoryInfo item in dirInfo)
        {
            if (item.Name.Contains(".svn"))
            {
                continue;
            }
            ProcessCsvFile(item);
        }
        FileInfo[] fileInfo = folder.GetFiles();
        foreach (FileInfo item in fileInfo)
        {
            string postfix = ".csv";
            int    iPos    = item.Name.IndexOf(postfix, 0);
            if (iPos != -1 && iPos + postfix.Length == item.Name.Length)
            {
                string csvName = item.Name.ToLower().Replace(".csv", "");
                // 如果这个表没有写入到LogicSystem中,就不需要打包
                if (CsvManager.Inst.GetType(csvName) == (int)eAllCSV.eAC_None)
                {
                    Debug.LogWarning(item.Name + " 没有写入到LogicSystem中,是否为客户端不需要的表格?");
                    continue;
                }
                FileStream file;
                try
                {
                    file = new FileStream(item.FullName, FileMode.Open);
                    if (file == null)
                    {
                        Debug.LogError(item.Name + "处理失败。");
                    }
                }
                catch (IOException ioe)
                {
                    Debug.LogError("处理csv失败,检查是否已经打开:" + item.FullName + " " + ioe);
                    EditorUtility.DisplayDialog(
                        "打包配置错误",
                        "请关闭配置表,重新打包: " + item.FullName,
                        "确定");
                    file        = null;
                    m_csvStream = null;
                    return(false);
                }

                m_csvNums++;
                // 这里存csv的id效率更好
                //m_csvStream.WriteString(ref csvName);
                int type = (int)CsvManager.Inst.GetType(csvName);
                m_csvStream.WriteInt(type);

                byte[] readData = new byte[file.Length];
                file.Read(readData, 0, (int)file.Length);
                // 转码并写入到流
                readData = Encoding.Convert(Encoding.Default, Encoding.UTF8, readData);
                m_csvStream.WriteInt((int)readData.Length);
                m_csvStream.Write(ref readData);
                Debug.Log("处理配置表:" + item.Name);
            }
        }
        return(true);
    }
Ejemplo n.º 25
0
 public override void ToByte(ref LusuoStream ls)
 {
     eno = 0;
     SetByte <int[]>(m_enterInfo, ref ls);
 }
Ejemplo n.º 26
0
 public override void ToByte(ref LusuoStream ls)
 {
     SetByte <CS_Login>(login, ref ls);
 }
Ejemplo n.º 27
0
 // 发送给其他人发送移动
 public override void ToByte(ref LusuoStream ls)
 {
     eno = 0;
     //SetByte<CG_UseSkill>(useSkill, ref ls);
 }
Ejemplo n.º 28
0
Archivo: Csvex.cs Proyecto: mengtest/fs
    public bool Load(LusuoStream lf, Encoding encoding)
    {
        if (null == lf)
        {
            return(false);
        }

        //if (lf.Length() <= 0)
        //{
        //    return false;
        //}

        StreamReader sr       = new StreamReader(lf.GetStream(), encoding);
        string       strEName = sr.ReadLine();

        if (string.IsNullOrEmpty(strEName))
        {
            return(false);
        }
        m_strArrEName = strEName.Split(',');
        if (!NoSame(ref m_strArrEName))
        {
            //Debug.LogError("表头第一行重复!读取失败!" + strEName);
            return(false);
        }

        string strCName = sr.ReadLine();

        if (string.IsNullOrEmpty(strCName))
        {
            return(false);
        }
        m_strArrCName = strCName.Split(',');
        if (!NoSame(ref m_strArrCName))
        {
            //Debug.LogError("表头第二行重复!读取失败!");
            return(false);
        }

        string strType = sr.ReadLine();

        if (string.IsNullOrEmpty(strType))
        {
            return(false);
        }
        string[] strArrType = strType.Split(',');
        m_IndexType = new CsvEx.eTypes[strArrType.Length];
        for (int ii = 0; ii < strArrType.Length; ii++)
        {
            m_IndexType[ii] = String2Type(ref strArrType[ii]);
        }

        string strTemp;

        while (!string.IsNullOrEmpty(strTemp = sr.ReadLine()))
        {
            List <string> listString = new List <string>();
            string[]      strArr     = strTemp.Split(',');

            if (strArr.Length > 0 && IsEmptyOrSpace(strArr[0]))
            {
                continue;
            }

            for (int i = 0; i < strArr.Length; i++)
            {
                listString.Add(strArr[i]);
            }
            m_dt.Add(listString);
        }

        if (!CheckCSV())
        {
            return(false);
        }
        return(true);
    }
Ejemplo n.º 29
0
 public override void ToByte(ref LusuoStream ls)
 {
     eno = 0;
     //SetByte<CG_CreateRoom>(m_joinRoom, ref ls);
 }
Ejemplo n.º 30
0
        //private Dictionary<int, Action<MyMessage>> _m_msgList = new Dictionary<int, Action<MyMessage>>();

        private void HandleMsgNew()
        {
            LusuoStream stream = new LusuoStream(m_recvBuffer);

            _m_listMsg.Add(stream);
        }