public void ChangeLocation(NetGameObject target, Vector3 src_pos, Vector3 dest_pos) { var x = (short)Math.Round(dest_pos.x); var y = (short)Math.Round(dest_pos.y); var z = (short)Math.Round(dest_pos.z); var old_x = (short)Math.Round(src_pos.x); var old_y = (short)Math.Round(src_pos.y); var old_z = (short)Math.Round(src_pos.z); if (old_x == x && old_y == y && old_z == z) { return; } var src_tile = GetTile(old_x, old_y, old_z); if (src_tile != null) { src_tile.del(target); } var dest_tile = GetTile(x, y, z); if (dest_tile == null) { dest_tile = CreateTile(x, y, z); } dest_tile.add(target); LogHelper.LogInfo($"game object {target.GetNetworkId()}, from({old_x},{old_y},{old_z}) to({x},{y},{z})"); }
public void ChangeLocation(NetGameObject target, Vector3 src_pos, Vector3 dest_pos) { var x = (short)Math.Round(dest_pos.x); var y = (short)Math.Round(dest_pos.y); var z = (short)Math.Round(dest_pos.z); var old_x = (short)Math.Round(src_pos.x); var old_y = (short)Math.Round(src_pos.y); var old_z = (short)Math.Round(src_pos.z); if (old_x == x && old_y == y && old_z == z) { return; } var src_tile = GetTile(old_x, old_y, old_z); if (src_tile != null) { src_tile.del(target); } var dest_tile = GetTile(x, y, z); if (dest_tile == null) { dest_tile = CreateTile(x, y, z); } dest_tile.add(target); LogHelper.LogInfo(string.Format("game object {0}, from({1},{2},{3}) to({4},{5},{6})", target.GetNetworkId(), old_x, old_y, old_z, x, y, z)); }
public static void Update() { for (byte worldId = 0; worldId < sInstance.Length; ++worldId) { World world = sInstance[worldId]; world.mTickCounter.Update(); //update all game objects- sometimes they want to die, so we need to tread carefully... for (int i = 0, c = world.mGameObjects.Count; i < c; ++i) { NetGameObject go = world.mGameObjects[i]; if (!go.DoesWantToDie()) { go.Update(); } //you might suddenly want to die after your update, so check again if (go.DoesWantToDie()) { world.RemoveGameObject(go); go.HandleDying(); --i; --c; } } } }
public void RemoveGameObject(NetGameObject inGameObject) { int index = inGameObject.GetIndexInWorld(); int lastIndex = mGameObjects.Count - 1; if (index != lastIndex) { mGameObjects[index] = mGameObjects[lastIndex]; mGameObjects[index].SetIndexInWorld(index); } inGameObject.SetIndexInWorld(-1); mGameObjects.RemoveAt(lastIndex); inGameObject.CompleteRemove(); //mWorldMap.RemoveObject(inGameObject); if (inGameObject.GetMapId() != 0) { RemoveNetGameObject((GameObjectClassId)inGameObject.GetClassId(), inGameObject.GetMapId()); } }
public void AddGameObject(NetGameObject inGameObject) { mGameObjects.Add(inGameObject); inGameObject.SetIndexInWorld(mGameObjects.Count - 1); //mWorldMap.InsertObject(inGameObject); }
public static void LateUpdate() { #if _USE_BEPU_PHYSICS for (byte worldId = 0; worldId < sInstance.Length; ++worldId) { World world = sInstance[worldId]; world.space.Update(); for (int i = 0, c = world.mGameObjects.Count; i < c; ++i) { NetGameObject go = world.mGameObjects[i]; if (!go.DoesWantToDie()) { go.LateUpdate(); } } } #elif _USE_BULLET_SHARP for (byte worldId = 0; worldId < sInstance.Length; ++worldId) { World world = sInstance[worldId]; world.world.StepSimulation(Timing.sInstance.GetDeltaTime()); //BulletSharp.Math.Matrix trans; //world.floor.GetWorldTransform(out trans); //LogHelper.LogInfo($"floor {trans.ToString()}, {world.floor.CollisionShape}"); for (int i = 0, c = world.mGameObjects.Count; i < c; ++i) { NetGameObject go = world.mGameObjects[i]; if (!go.DoesWantToDie()) { go.LateUpdate(); } } } #elif _USE_BEPU_PHYSICS_V2 for (byte worldId = 0; worldId < sInstance.Length; ++worldId) { World world = sInstance[worldId]; world.Simulation.Timestep(Timing.sInstance.GetDeltaTime()); for (int i = 0, c = world.mGameObjects.Count; i < c; ++i) { NetGameObject go = world.mGameObjects[i]; if (!go.DoesWantToDie()) { go.LateUpdate(); } } } #endif }
public bool add(NetGameObject target) { if (gameObjects.Exists(x => x == target) == true) { LogHelper.LogError("deplicate game object while add in tile!"); return(false); } gameObjects.Add(target); return(true); }
public bool IsSameFloor(NetGameObject other) { if (other.GetAsAreaOfEffect() != null) { return(IsSameFloorWithHeight(floor, other)); } else { return(IsSameFloor(floor, other)); } }
public bool del(NetGameObject target) { var ret = gameObjects.Remove(target); if (ret == false) { LogHelper.LogError("not exist game object while del in tile!"); } return(ret); }
public static bool IsSameFloorWithHeight(float current_floor, NetGameObject other) { var target_floor = other.GetLocation().y; float heightMin = target_floor - other.heightHalf; float heightMax = target_floor + other.heightHalf; #if UNITY_EDITOR || DEBUG LogHelper.LogInfo($"curr {current_floor} heightMin {heightMin} heightMax {heightMax} target {target_floor}"); #endif return(current_floor <= heightMax && current_floor >= heightMin); }
public NetGameObject GetGameObject(int inNetworkId) { NetGameObject gameObjectIt = null; if (mNetworkIdToGameObjectMap.TryGetValue(inNetworkId, out gameObjectIt) == true) { return(gameObjectIt); } else { return(null); } }
public static bool IsSameFloor(float current_floor, NetGameObject other) { var target_floor = other.GetLocation().y; // 비교 대상이 플레이어이면 층 보정 x // 이전에 구해놓은 층으로 비교 if (other.GetAsActor() != null) { target_floor = other.floor; } return(current_floor == target_floor); }
public void InsertObject(NetGameObject target) { var x = (short)Math.Round(target.GetLocation().x); var y = (short)Math.Round(target.GetLocation().y); var z = (short)Math.Round(target.GetLocation().z); var dest_tile = GetTile(x, y, z); if (dest_tile == null) { dest_tile = CreateTile(x, y, z); } dest_tile.add(target); }
public void RegisterNetGameObject(GameObjectClassId class_id, int map_uid, NetGameObject gameObject) { //core.LogHelper.LogInfo($"RegisterNetGameObject class_id:{class_id}, map_uid:{map_uid}"); Dictionary <int, NetGameObject> map; if (mapNetGameObject.TryGetValue(class_id, out map)) { map.Add(map_uid, gameObject); } else { map = new Dictionary <int, NetGameObject>(); map.Add(map_uid, gameObject); mapNetGameObject.Add(class_id, map); } }
public void Dequeue(NetGameObject target) { int i = 0; while (event_queue.Count > i) { if (event_queue[i].mTimeToEvent <= Timing.sInstance.GetFrameStartTime()) { event_queue[i].eventCall(target); event_queue.RemoveAt(i); } else { ++i; } } }
public void RemoveObject(NetGameObject target) { var x = (short)Math.Round(target.GetLocation().x); var y = (short)Math.Round(target.GetLocation().y); var z = (short)Math.Round(target.GetLocation().z); var src_tile = GetTile(x, y, z); if (src_tile != null) { src_tile.del(target); } else { LogHelper.LogWarning(string.Format("cannot find object {0}", target.NetworkId)); } }
public Actor GetActor(int inPlayerId) { Entry entry = GetEntry(inPlayerId); if (entry == null) { LogHelper.LogError($"Can't find entry playerId : {inPlayerId}"); return(null); } NetGameObject netGameObject = mNetworkManager.GetGameObject(entry.mNetworkId, WorldId); if (netGameObject == null) { LogHelper.LogError($"netGameObject == null or netGameObject is not SActor playerId : {inPlayerId}, worldId : {WorldId}"); return(null); } return((Actor)netGameObject); }
public NetGameObject CreateGameObject(UInt32 inFourCCName, bool is_server, byte worldId = 0, bool is_use_pool = true) { NetGameObject gameObject = null; // 풀링된 데이터가 있는지 확인 if (gameObjectPool != null && is_use_pool == true) { Stack <NetGameObject> pool = null; if (gameObjectPool.TryGetValue((int)inFourCCName, out pool) && pool.Count > 0) { gameObject = pool.Pop(); } else { Debug.Log($"not enough :{(GameObjectClassId)inFourCCName}"); } } if (gameObject == null) { if (IsHost == true && is_server == true) { gameObject = mNameToGameObjectCreationFunctionMapInHost[inFourCCName](worldId); } else { gameObject = mNameToGameObjectCreationFunctionMap[inFourCCName](worldId); } } //no error checking- if the name isn't there, exception! //GameObjectCreationFunc creationFunc = mNameToGameObjectCreationFunctionMap[inFourCCName]; //var gameObject = creationFunc(worldId); //should the registry depend on the world? this might be a little weird //perhaps you should ask the world to spawn things? for now it will be like this World.Instance(worldId).AddGameObject(gameObject); return(gameObject); }
public static void LateUpdate() { #if _USE_BEPU_PHYSICS for (byte worldId = 0; worldId < sInstance.Length; ++worldId) { World world = sInstance[worldId]; world.space.Update(); for (int i = 0, c = world.mGameObjects.Count; i < c; ++i) { NetGameObject go = world.mGameObjects[i]; if (!go.DoesWantToDie()) { go.LateUpdate(); } } } #endif }
public List <Actor> GetMyTeam(Team team) { List <Actor> actors = new List <Actor>(); foreach (var entry in GetEntries()) { if (entry.GetTeam() != team) { continue; } NetGameObject netGameObject = mNetworkManager.GetGameObject(entry.mNetworkId, WorldId); if (netGameObject == null) { LogHelper.LogError($"netGameObject == null or netGameObject is not SActor playerId : {entry.GetPlayerId()}, worldId : {WorldId}"); continue; } actors.Add((Actor)netGameObject); } return(actors); }
private bool Collision(float sourceRadius, Vector3 sourceLocation, NetGameObject target) { if (target.GetNetworkId() != this.GetNetworkId() && !target.DoesWantToDie()) { // 같은 층이 아닌 경우는 충돌 검사에서 제외 if (target.DetectCollision(sourceRadius, sourceLocation) && IsSameFloor(target)) { //first, tell the other guy there was a collision with a cat, so it can do something... if (target.HandleCollisionWithActor(this)) { #if _USE_INPUT_SYNC //simple collision test for spheres- are the radii summed less than the distance? Vector3 targetLocation = target.GetLocation(); float targetRadius = target.GetCollisionRadius(); Vector3 delta = targetLocation - sourceLocation; float distSq = delta.sqrMagnitude; float collisionDist = (sourceRadius + targetRadius); //if (distSq < (collisionDist * collisionDist)) collisionDist = 1.02f; #if UNITY_EDITOR || DEBUG LogHelper.LogInfo($"collision source{sourceLocation}, target{targetLocation}, delta{delta}, dist{collisionDist}, mapID{target.GetMapId()}, objectCount{World.Instance(WorldId).GetGameObjects().Count+ World.mStaticGameObjects.Count}"); LogHelper.LogDrawRay(sourceLocation, delta, new Vector3(1, 0, 1), 1); Vector3 startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.left * 0.5f + Vector3.back * (0.5f + target.rh - 1); LogHelper.LogDrawLine(startPos, startPos + Vector3.right * (target.rw), new Vector3(1, 1, 1), 1); LogHelper.LogDrawLine(startPos, startPos + Vector3.forward * (target.rh), new Vector3(1, 1, 1), 1); startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.right * (0.5f + target.rw - 1) + Vector3.forward * 0.5f; LogHelper.LogDrawLine(startPos, startPos + Vector3.left * (target.rw), new Vector3(1, 1, 1), 1); LogHelper.LogDrawLine(startPos, startPos + Vector3.back * (target.rh), new Vector3(1, 1, 1), 1); #endif #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_IOS || UNITY_ANDROID if (distSq < ((targetLocation - lastLocation).sqrMagnitude - 0.01f)) { LogHelper.LogInfo($"cur {distSq}, last {(targetLocation - lastLocation).sqrMagnitude}"); SolveCollision(sourceRadius, sourceLocation, target.GetLocation().x, target.GetLocation().z, target.rw, target.rh); } return(true); #endif //okay, you hit something! //so, project your location far enough that you're not colliding Vector3 dirToTarget = delta; dirToTarget.Normalize(); Vector3 acceptableDeltaFromSourceToTarget = dirToTarget * collisionDist; //important note- we only move this cat. the other cat can take care of moving itself SetLocation(targetLocation - acceptableDeltaFromSourceToTarget); // Collision 크기가 1보다 큰 경우 처리 if (target.rw > 1 || target.rh > 1) { Vector3 movePosRW = Vector3.zero; Vector3 movePosRH = Vector3.zero; if (target.rw > 1 && sourceLocation.x >= targetLocation.x + 0.5f) { movePosRW = Vector3.right; } if (target.rh > 1 && sourceLocation.z >= targetLocation.z + 0.5f) { movePosRH = Vector3.forward; } Vector3 deltaRect = (targetLocation + movePosRW + movePosRH) - sourceLocation; Vector3 dirToTargetRect = deltaRect; dirToTargetRect.Normalize(); Vector3 acceptableDeltaFromSourceToTargetRect = dirToTargetRect * collisionDist; SetLocation((targetLocation + movePosRW + movePosRH) - acceptableDeltaFromSourceToTargetRect); #if UNITY_EDITOR || DEBUG LogHelper.LogDrawRay(sourceLocation, deltaRect, new Vector3(0, 1, 1), 1); startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.left * 0.5f + Vector3.back * (0.5f + target.rh - 1); LogHelper.LogDrawLine(startPos, startPos + Vector3.right * (target.rw), new Vector3(1, 1, 1), 1); LogHelper.LogDrawLine(startPos, startPos + Vector3.forward * (target.rh), new Vector3(1, 1, 1), 1); startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.right * (0.5f + target.rw - 1) + Vector3.forward * 0.5f; LogHelper.LogDrawLine(startPos, startPos + Vector3.left * (target.rw), new Vector3(1, 1, 1), 1); LogHelper.LogDrawLine(startPos, startPos + Vector3.back * (target.rh), new Vector3(1, 1, 1), 1); #endif } Vector3 relVel = mVelocity; //if other object is a cat, it might have velocity, so there might be relative velocity... Actor targetActor = target.GetAsActor(); if (targetActor != null) { relVel -= targetActor.mVelocity; } //got vel with dir between objects to figure out if they're moving towards each other //and if so, the magnitude of the impulse ( since they're both just balls ) float relVelDotDir = Vector3.Dot(relVel, dirToTarget); if (relVelDotDir > 0.0f) { Vector3 impulse = relVelDotDir * dirToTarget; if (targetActor != null) { mVelocity -= impulse; mVelocity *= mActorRestitution; } else { mVelocity -= impulse * 2.0f; mVelocity *= mWallRestitution; } } return(true); #else // Solve collision disable // LogHelper.LogInfo($"collision source{sourceLocation}, objectCount{World.Instance(WorldId).GetGameObjects().Count + World.mStaticGameObjects.Count}"); return(true); #endif } } else { target.HandleExitCollisionWithActor(this); } } return(false); }
public void AddToNetworkIdToGameObjectMap(NetGameObject inGameObject, byte inWorldId) { mNetworkIdToGameObjectMap[inWorldId][inGameObject.GetNetworkId()] = inGameObject; }
public void AddToNetworkIdToGameObjectMap(NetGameObject inGameObject) { mNetworkIdToGameObjectMap[inGameObject.GetNetworkId()] = inGameObject; }
public void RemoveFromNetworkIdToGameObjectMap(NetGameObject inGameObject, byte inWorldId) { mNetworkIdToGameObjectMap[inWorldId].Remove(inGameObject.GetNetworkId()); }
public void RemoveFromNetworkIdToGameObjectMap(NetGameObject inGameObject) { mNetworkIdToGameObjectMap.Remove(inGameObject.GetNetworkId()); }