/// <summary> /// 发送数据 /// </summary> public void SendData(byte protoID, ProtoBase obj, ProtoType msgType) { #if UNITY_EDITOR sendSampler.Begin(); #endif byte[] data = Util.SerializeProtoData(protoID, obj); Send(data, msgType); #if UNITY_EDITOR sendSampler.End(); #endif }
static public int Begin(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 1) { UnityEngine.Profiling.CustomSampler self = (UnityEngine.Profiling.CustomSampler)checkSelf(l); self.Begin(); pushValue(l, true); return(1); } else if (argc == 2) { UnityEngine.Profiling.CustomSampler self = (UnityEngine.Profiling.CustomSampler)checkSelf(l); UnityEngine.Object a1; checkType(l, 2, out a1); self.Begin(a1); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function Begin to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <summary> /// 解析数据 /// </summary> /// <param name="data"></param> public void DeserializeMsg(byte[] data) { if (data != null && data.Length >= PACKER_OFFSET) { byte head = data[0]; if (head == PACKER_HEAD) { byte protoID = data[1]; int offset = PACKER_OFFSET; if (protoID == ProtoIDCfg.HEARTBEAT) { SendData(ProtoIDCfg.HEARTBEAT, null, ProtoType.Importance); ResetHeartBeat(); } else { #if UNITY_EDITOR recvSampler.Begin(); #endif byte[] proto = SerializeUtil.GetContextData(data, offset, data.Length - offset); FireEvent(protoID, proto); #if UNITY_EDITOR recvSampler.End(); #endif } } } }
static public int Begin(IntPtr l) { try { UnityEngine.Profiling.CustomSampler self = (UnityEngine.Profiling.CustomSampler)checkSelf(l); self.Begin(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer.Concurrent buffer = bufferSystem.CreateCommandBuffer().ToConcurrent(); // For each thing with a target that is now gone, remove its component // TODO: feels like a hack, checking if the Health component exists, but the CombatTarget.entity field will always be vaild even after the entity is destroyed :/ ComponentDataFromEntity <Health> healthFromEntities = GetComponentDataFromEntity <Health>(true); var jobCleanupDeadTargets = Entities .WithReadOnly(healthFromEntities) .WithAll <NavAgentTarget>() .ForEach((Entity e, int entityInQueryIndex, ref CombatTarget target) => { if (!healthFromEntities.Exists(target.entity)) { buffer.RemoveComponent <CombatTarget>(entityInQueryIndex, e); buffer.RemoveComponent <NavAgentTarget>(entityInQueryIndex, e); } }).Schedule(inputDeps); var jobCleanupDeadTargets2 = Entities .WithReadOnly(healthFromEntities) .WithNone <NavAgentTarget>() .ForEach((Entity e, int entityInQueryIndex, ref CombatTarget target) => { if (!healthFromEntities.Exists(target.entity)) { buffer.RemoveComponent <CombatTarget>(entityInQueryIndex, e); } }).Schedule(jobCleanupDeadTargets); sampleForEach.Begin(); // TODO: Skip searching for targets if none exist var jobAssignTeam1Targets = AssignTargetsForTeamUnits(new Team { Value = 1 }, new Team { Value = 0 }, jobCleanupDeadTargets2, buffer); var jobAssignTeam2Targets = AssignTargetsForTeamUnits(new Team { Value = 1 }, new Team { Value = 0 }, jobAssignTeam1Targets, buffer); sampleForEach.End(); return(JobHandle.CombineDependencies(jobAssignTeam1Targets, jobAssignTeam2Targets)); }
static public int Begin(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); if (argc == 1) { UnityEngine.Profiling.CustomSampler self = (UnityEngine.Profiling.CustomSampler)checkSelf(l); self.Begin(); pushValue(l, true); return(1); } else if (argc == 2) { UnityEngine.Profiling.CustomSampler self = (UnityEngine.Profiling.CustomSampler)checkSelf(l); UnityEngine.Object a1; checkType(l, 2, out a1); self.Begin(a1); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function Begin to call"); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
/// <summary> /// Starts the main part of the game. /// Checks if a game exists to load, and if so loads it. /// If not, we generate a game <see cref="GameManager.GenerateGame(int)"/> /// If we generate a game, at current we set the players location /// </summary> void Start() { Debug.BeginDeepProfile("game_start"); if (GameToLoad == null || GameToLoad == "none") { Stopwatch s = new Stopwatch(); s.Start(); //UnityEngine.Profiling.CustomSampler gen = UnityEngine.Profiling.CustomSampler.Create("GenSampler"); int seed = 0; Debug.Log("No game to load, generating with seed " + seed); GenerateGame(seed); PathFinder = new PathFinder(WorldManager.World); PathFinder.SetPlayerPosition(PlayerManager.Player.TilePos); System.GC.Collect(); s.Stop(); Debug.Log("Generation took total time: " + s.ElapsedMilliseconds / 1000f); DebugGUI.SetData("genTime", s.ElapsedMilliseconds / 1000f); } else { UnityEngine.Profiling.CustomSampler load = UnityEngine.Profiling.CustomSampler.Create("LoadSampler"); load.Begin(); GameLoadSave gls = LoadSave.Load(); World world = new World(); world.LoadWorld(gls); EntityManager.Load(gls); WorldManager.SetWorld(world); Player player = new Player(); TestSettle = WorldManager.World.GetSettlement(0); Vec2i set = TestSettle.Centre; //player.SetPosition(new Vector3(set.x * World.ChunkSize, 0, set.z * World.ChunkSize)); player.SetPosition(new Vector3(World.WorldSize / 2 * World.ChunkSize, 0, World.WorldSize / 2 * World.ChunkSize)); PlayerManager.SetPlayer(player); load.End(); } Debug.EndDeepProfile("game_start"); RNG = new GenerationRandom(System.DateTime.Now.Millisecond); }