当前位置: 首页>>代码示例>>C#>>正文


C# MemoryStream.length方法代码示例

本文整理汇总了C#中KBEngine.MemoryStream.length方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.length方法的具体用法?C# MemoryStream.length怎么用?C# MemoryStream.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KBEngine.MemoryStream的用法示例。


在下文中一共展示了MemoryStream.length方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: send

        public bool send(MemoryStream stream)
        {
            int dataLength = (int)stream.length();
            if (dataLength <= 0)
                return true;

            if (0 == Interlocked.Add(ref _sending, 0))
            {
                if (_wpos == _spos)
                {
                    _wpos = 0;
                    _spos = 0;
                }
            }

            int t_spos = Interlocked.Add(ref _spos, 0);
            int space = 0;
            int tt_wpos = _wpos % _buffer.Length;
            int tt_spos = t_spos % _buffer.Length;

            if(tt_wpos >= tt_spos)
                space = _buffer.Length - tt_wpos + tt_spos - 1;
            else
                space = tt_spos - tt_wpos - 1;

            if (dataLength > space)
            {
                Dbg.ERROR_MSG("PacketSender::send(): no space, Please adjust 'SEND_BUFFER_MAX'! data(" + dataLength
                    + ") > space(" + space + "), wpos=" + _wpos + ", spos=" + t_spos);

                return false;
            }

            int expect_total = tt_wpos + dataLength;
            if(expect_total <= _buffer.Length)
            {
                Array.Copy(stream.data(), stream.rpos, _buffer, tt_wpos, dataLength);
            }
            else
            {
                int remain = _buffer.Length - tt_wpos;
                Array.Copy(stream.data(), stream.rpos, _buffer, tt_wpos, remain);
                Array.Copy(stream.data(), stream.rpos + remain, _buffer, 0, expect_total - _buffer.Length);
            }

            Interlocked.Add(ref _wpos, dataLength);

            if (Interlocked.CompareExchange(ref _sending, 1, 0) == 0)
            {
                _startSend();
            }

            return true;
        }
开发者ID:kbengine,项目名称:kbengine_unity3d_plugins,代码行数:54,代码来源:PacketSender.cs

示例2: Client_onEntityEnterWorld

        /*
            服务端通知一个实体进入了世界(如果实体是当前玩家则玩家第一次在一个space中创建了, 如果是其他实体则是其他实体进入了玩家的AOI)
        */
        public void Client_onEntityEnterWorld(MemoryStream stream)
        {
            Int32 eid = stream.readInt32();
            if(entity_id > 0 && entity_id != eid)
                _entityIDAliasIDList.Add(eid);

            UInt16 uentityType;
            if(EntityDef.idmoduledefs.Count > 255)
                uentityType = stream.readUint16();
            else
                uentityType = stream.readUint8();

            sbyte isOnGround = 1;

            if(stream.length() > 0)
                isOnGround = stream.readInt8();

            string entityType = EntityDef.idmoduledefs[uentityType].name;
            // Dbg.DEBUG_MSG("KBEngine::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + KBEngineApp.app.spaceID + ")!");

            Entity entity = null;

            if(!entities.TryGetValue(eid, out entity))
            {
                MemoryStream entityMessage = null;
                if(!_bufferedCreateEntityMessage.TryGetValue(eid, out entityMessage))
                {
                    Dbg.ERROR_MSG("KBEngine::Client_onEntityEnterWorld: entity(" + eid + ") not found!");
                    return;
                }

                ScriptModule module = null;
                if(!EntityDef.moduledefs.TryGetValue(entityType, out module))
                {
                    Dbg.ERROR_MSG("KBEngine::Client_onEntityEnterWorld: not found module(" + entityType + ")!");
                }

                Type runclass = module.script;
                if(runclass == null)
                    return;

                entity = (Entity)Activator.CreateInstance(runclass);
                entity.id = eid;
                entity.className = entityType;

                entity.cellMailbox = new Mailbox();
                entity.cellMailbox.id = eid;
                entity.cellMailbox.className = entityType;
                entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL;

                entities[eid] = entity;

                Client_onUpdatePropertys(entityMessage);
                _bufferedCreateEntityMessage.Remove(eid);

                entity.isOnGround = isOnGround > 0;
                entity.set_direction(entity.getDefinedPropterty("direction"));
                entity.set_position(entity.getDefinedPropterty("position"));

                entity.__init__();
                entity.enterWorld();
            }
            else
            {
                if(!entity.inWorld)
                {
                    // 安全起见, 这里清空一下
                    // 如果服务端上使用giveClientTo切换控制权
                    // 之前的实体已经进入世界, 切换后的实体也进入世界, 这里可能会残留之前那个实体进入世界的信息
                    _entityIDAliasIDList.Clear();
                    clearEntities(false);
                    entities[entity.id] = entity;

                    entity.cellMailbox = new Mailbox();
                    entity.cellMailbox.id = eid;
                    entity.cellMailbox.className = entityType;
                    entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL;

                    entity.set_direction(entity.getDefinedPropterty("direction"));
                    entity.set_position(entity.getDefinedPropterty("position"));

                    _entityServerPos = entity.position;
                    entity.isOnGround = isOnGround > 0;
                    entity.enterWorld();
                }
            }
        }
开发者ID:buckyu,项目名称:kbengine_unity3d_plugins,代码行数:90,代码来源:KBEngine.cs

示例3: Client_onEntityEnterSpace

        /*
            服务端通知当前玩家进入了一个新的space
        */
        public void Client_onEntityEnterSpace(MemoryStream stream)
        {
            Int32 eid = stream.readInt32();
            spaceID = stream.readUint32();

            sbyte isOnGround = 1;

            if(stream.length() > 0)
                isOnGround = stream.readInt8();

            Entity entity = null;

            if(!entities.TryGetValue(eid, out entity))
            {
                Dbg.ERROR_MSG("KBEngine::Client_onEntityEnterSpace: entity(" + eid + ") not found!");
                return;
            }

            entity.isOnGround = isOnGround > 0;
            _entityServerPos = entity.position;
            entity.enterSpace();
        }
开发者ID:buckyu,项目名称:kbengine_unity3d_plugins,代码行数:25,代码来源:KBEngine.cs

示例4: Client_initSpaceData

        /*
            服务端初始化客户端的spacedata, spacedata请参考API
        */
        public void Client_initSpaceData(MemoryStream stream)
        {
            clearSpace(false);
            spaceID = stream.readUint32();

            while(stream.length() > 0)
            {
                string key = stream.readString();
                string val = stream.readString();
                Client_setSpaceData(spaceID, key, val);
            }

            Dbg.DEBUG_MSG("KBEngine::Client_initSpaceData: spaceID(" + spaceID + "), size(" + _spacedatas.Count + ")!");
        }
开发者ID:buckyu,项目名称:kbengine_unity3d_plugins,代码行数:17,代码来源:KBEngine.cs

示例5: onUpdatePropertys_

        public void onUpdatePropertys_(Int32 eid, MemoryStream stream)
        {
            Entity entity = null;

            if(!entities.TryGetValue(eid, out entity))
            {
                MemoryStream entityMessage = null;
                if(_bufferedCreateEntityMessage.TryGetValue(eid, out entityMessage))
                {
                    Dbg.ERROR_MSG("KBEngine::Client_onUpdatePropertys: entity(" + eid + ") not found!");
                    return;
                }

                MemoryStream stream1 = new MemoryStream();
                stream1.wpos = stream.wpos;
                stream1.rpos = stream.rpos - 4;
                Array.Copy(stream.data(), stream1.data(), stream.data().Length);
                _bufferedCreateEntityMessage[eid] = stream1;
                return;
            }

            ScriptModule sm = EntityDef.moduledefs[entity.className];
            Dictionary<UInt16, Property> pdatas = sm.idpropertys;

            while(stream.length() > 0)
            {
                UInt16 utype = 0;

                if(sm.usePropertyDescrAlias)
                {
                    utype = stream.readUint8();
                }
                else
                {
                    utype = stream.readUint16();
                }

                Property propertydata = pdatas[utype];
                utype = propertydata.properUtype;
                System.Reflection.MethodInfo setmethod = propertydata.setmethod;

                object val = propertydata.utype.createFromStream(stream);
                object oldval = entity.getDefinedProptertyByUType(utype);

                 // Dbg.DEBUG_MSG("KBEngine::Client_onUpdatePropertys: " + entity.className + "(id=" + eid  + " " +
                 // propertydata.name + "=" + val + "), hasSetMethod=" + setmethod + "!");

                entity.setDefinedProptertyByUType(utype, val);
                if(setmethod != null)
                {
                    if(propertydata.isBase() || entity.inWorld)
                        setmethod.Invoke(entity, new object[]{oldval});
                }
            }
        }
开发者ID:buckyu,项目名称:kbengine_unity3d_plugins,代码行数:55,代码来源:KBEngine.cs

示例6: onImportClientEntityDef

        public void onImportClientEntityDef(MemoryStream stream)
        {
            createDataTypeFromStreams(stream, true);

            while(stream.length() > 0)
            {
                string scriptmethod_name = stream.readString();
                UInt16 scriptUtype = stream.readUint16();
                UInt16 propertysize = stream.readUint16();
                UInt16 methodsize = stream.readUint16();
                UInt16 base_methodsize = stream.readUint16();
                UInt16 cell_methodsize = stream.readUint16();

                Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: import(" + scriptmethod_name + "), propertys(" + propertysize + "), " +
                        "clientMethods(" + methodsize + "), baseMethods(" + base_methodsize + "), cellMethods(" + cell_methodsize + ")!");

                ScriptModule module = new ScriptModule(scriptmethod_name);
                EntityDef.moduledefs[scriptmethod_name] = module;
                EntityDef.idmoduledefs[scriptUtype] = module;

                Type Class = module.script;

                while(propertysize > 0)
                {
                    propertysize--;

                    UInt16 properUtype = stream.readUint16();
                    UInt32 properFlags = stream.readUint32();
                    Int16 ialiasID = stream.readInt16();
                    string name = stream.readString();
                    string defaultValStr = stream.readString();
                    KBEDATATYPE_BASE utype = EntityDef.id2datatypes[stream.readUint16()];

                    System.Reflection.MethodInfo setmethod = null;

                    if(Class != null)
                    {
                        try{
                            setmethod = Class.GetMethod("set_" + name);
                        }
                        catch (Exception e)
                        {
                            string err = "KBEngine::Client_onImportClientEntityDef: " +
                                scriptmethod_name + ".set_" + name + ", error=" + e.ToString();

                            throw new Exception(err);
                        }
                    }

                    Property savedata = new Property();
                    savedata.name = name;
                    savedata.utype = utype;
                    savedata.properUtype = properUtype;
                    savedata.properFlags = properFlags;
                    savedata.aliasID = ialiasID;
                    savedata.defaultValStr = defaultValStr;
                    savedata.setmethod = setmethod;
                    savedata.val = savedata.utype.parseDefaultValStr(savedata.defaultValStr);

                    module.propertys[name] = savedata;

                    if(ialiasID >= 0)
                    {
                        module.usePropertyDescrAlias = true;
                        module.idpropertys[(UInt16)ialiasID] = savedata;
                    }
                    else
                    {
                        module.usePropertyDescrAlias = false;
                        module.idpropertys[properUtype] = savedata;
                    }

                    //Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), property(" + name + "/" + properUtype + ").");
                };

                while(methodsize > 0)
                {
                    methodsize--;

                    UInt16 methodUtype = stream.readUint16();
                    Int16 ialiasID = stream.readInt16();
                    string name = stream.readString();
                    Byte argssize = stream.readUint8();
                    List<KBEDATATYPE_BASE> args = new List<KBEDATATYPE_BASE>();

                    while(argssize > 0)
                    {
                        argssize--;
                        args.Add(EntityDef.id2datatypes[stream.readUint16()]);
                    };

                    Method savedata = new Method();
                    savedata.name = name;
                    savedata.methodUtype = methodUtype;
                    savedata.aliasID = ialiasID;
                    savedata.args = args;

                    if(Class != null)
                    {
                        try{
//.........这里部分代码省略.........
开发者ID:buckyu,项目名称:kbengine_unity3d_plugins,代码行数:101,代码来源:KBEngine.cs


注:本文中的KBEngine.MemoryStream.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。