// Update is called once per frame public void JoinPlayer() { client = Instantiate(ClientPrefab, new Vector3(0, 0.5f, 0), Quaternion.identity); var id = RandomId(); client.name = id; client.GetComponent <CubeId>().Id = id; clients.Add(id, client); client.GetComponent <MeshRenderer>().material = material; var packet4 = Packet.Obtain(); packet4.buffer.PutString(id); var cube = new CubeEntity(client, id); cube.Serialize(packet4.buffer); packet4.buffer.Flush(); int port = 9003; Send(serverIP, port, channel, packet4); conciliateGameObject = Instantiate(ClientPrefab, new Vector3(0, 0.5f, 0), Quaternion.identity); conciliateGameObject.name = id; conciliateGameObject.GetComponent <CubeId>().Id = id; conciliateGameObject.GetComponent <MeshRenderer>().material = conciliateMaterial; }
public FaceEditor(CubeEntity e, Location norm) { ent = e; Normal = norm; if (Normal.Z == 1) { TextureName = e.Textures[0]; CoordIndex = 0; } else if (Normal.Z == -1) { TextureName = e.Textures[1]; CoordIndex = 1; } else if (Normal.X == 1) { TextureName = e.Textures[2]; CoordIndex = 2; } else if (Normal.X == -1) { TextureName = e.Textures[3]; CoordIndex = 3; } else if (Normal.Y == 1) { TextureName = e.Textures[4]; CoordIndex = 4; } else if (Normal.Y == -1) { TextureName = e.Textures[5]; CoordIndex = 5; } InitializeComponent(); }
private void UpdateClientWord() { //send position float sendRate = (1f / pps); if (accum >= sendRate) { var snapshot = new Snapshot(); //generate word foreach (var auxCubeEntity in cubeServer) { var cubeEntity = new CubeEntity(auxCubeEntity.Value, auxCubeEntity.Value.GetComponent <CubeId>().Id); snapshot.Add(cubeEntity); } foreach (var kv in playerIps) { var auxPlayerId = kv.Key; snapshot.packetNumber = lastSnapshot[auxPlayerId]; lastSnapshot[auxPlayerId]++; //serialize var packet = Packet.Obtain(); snapshot.Serialize(packet.buffer); packet.buffer.Flush(); string serverIP = kv.Value; int port = 9000; Send(serverIP, port, channel2, packet); // Restart accum } accum -= sendRate; } }
private IEnumerator RespawnPlayer(CubeEntity cube) { yield return(new WaitForSeconds(10)); print("Respawning player.."); cube.GO.transform.position = Utils.RandomStartPos(); }
public GameObject createClient(int idJoined, bool me) { playerIds.Add(idJoined); GameObject clientCube; if (me) { clientCube = Instantiate(clientCubePrefab1p, new Vector3(0, 0.2f, 0), new Quaternion()); camera = clientCube.transform.Find("Main Camera"); } else { clientCube = Instantiate(clientCubePrefab3p, new Vector3(0, 0.05f, 0), new Quaternion()); clientCube.name = "soldier " + idJoined; } CubeEntity newCubeEntity = new CubeEntity(clientCube, idJoined); if (!me) { clientCube.transform.Find("Cube").GetComponent <HealthSignal>().id = idJoined; clientCube.transform.Find("Cube").GetComponent <HealthSignal>().cm = this; } else { clientCube.transform.Find("Main Camera").transform.Find("HUD_Life").GetComponent <HealthSignal2>().id = idJoined; clientCube.transform.Find("Main Camera").transform.Find("HUD_Life").GetComponent <HealthSignal2>().cm = this; clientCube.transform.Find("Main Camera").transform.Find("Kills").GetComponent <Kills>().id = idJoined; clientCube.transform.Find("Main Camera").transform.Find("Kills").GetComponent <Kills>().cm = this; clientCube.transform.Find("Main Camera").transform.Find("Latency").GetComponent <Latency>().cm = this; } clientCubes.Add(newCubeEntity); return(clientCube); }
public static Dictionary <String, CubeEntity> createInterpolated(Snapshot previousEntities, Snapshot nextEntities, float t, Dictionary <String, GameObject> players, String id) { var newEntities = new Dictionary <string, CubeEntity>(); foreach (var currentPlayer in previousEntities.cubeEntities) { if (!currentPlayer.Key.Equals(id)) { var previous = currentPlayer.Value; var next = nextEntities.cubeEntities[previous.id]; var cubeEntity = new CubeEntity(previous.cubeGameObject, next.id); cubeEntity.position = cubeEntity.position + Vector3.Lerp(previous.position, next.position, t); var deltaRot = Quaternion.Lerp(previous.rotation, next.rotation, t); var rot = new Quaternion(); rot.x = previous.rotation.x + deltaRot.x; rot.w = previous.rotation.w + deltaRot.w; rot.y = previous.rotation.y + deltaRot.y; rot.z = previous.rotation.z + deltaRot.z; cubeEntity.rotation = rot; cubeEntity.cubeGameObject = players[currentPlayer.Key]; newEntities.Add(cubeEntity.id, cubeEntity); } } return(newEntities); }
public static Cube Map(CubeEntity entity) { return(new Cube() { Id = entity.Id, Dimension = entity.Dimension }); }
private void SendAck(CubeEntity cube) { var packet3 = Packet.Obtain(); packet3.buffer.PutInt((int)Utils.Ports.ACK); packet3.buffer.PutInt(maxInputs[cube.id]); packet3.buffer.Flush(); Utils.Send(packet3, channel, cube.port); }
private void PlayerJoined(int id, bool isBot = false) // Server { // init new player var cubeGO = Instantiate(serverCubePrefab, Utils.RandomStartPos(), Quaternion.identity); // Attach label on top of his head var canvas = Instantiate(playerUICanvas, new Vector3(), Quaternion.identity); canvas.transform.SetParent(cubeGO.transform); canvas.transform.localPosition = new Vector3(0f, 2f, 0f); cubeGO.transform.SetParent(GameObject.Find("Players(Server)").transform); cubeGO.name = $"player-{id}"; var newCube = new CubeEntity(cubeGO, id, isBot); cubeEntitiesServer[newCube.id] = newCube; newCube.SetUIManager(canvas.GetComponent <UIManager>(), $"{id}", 1f); if (isBot) { bots[newCube.id] = newCube; // store bots in another list to test applying movement to them } else { packetNumbers[newCube.id] = 0; maxInputs[newCube.id] = 0; } print($"{cubeGO.name} joined"); foreach (var cube in cubeEntitiesServer.Values) { if (cube.isBot) { continue; } // send player joined packet to everyone (including to the new player as a confirmation) Packet playerJoinedPacket = Packet.Obtain(); var buffer = playerJoinedPacket.buffer; buffer.PutInt((int)Utils.Ports.PLAYER_JOINED); buffer.PutInt(id); buffer.PutInt(cubeEntitiesServer.Count - 1); foreach (var sendCube in cubeEntitiesServer.Values) { if (sendCube.id == cube.id) { continue; // dont send a player to himself } buffer.PutInt(sendCube.id); sendCube.Serialize(buffer); } buffer.Flush(); Utils.Send(playerJoinedPacket, channel, cube.port); } }
public CubeEntity(CubeEntity original) { GO = original.GO; id = original.id; position = new Vector3(original.position.x, original.position.y, original.position.z); rotation = new Quaternion(original.rotation.x, original.rotation.y, original.rotation.z, original.rotation.w); port = original.port; points = original.points; shootingCooldown = original.shootingCooldown; uiManager = original.uiManager; }
public void Deserialize(BitBuffer buffer) { packetNumber = buffer.GetInt(); var quatity = buffer.GetInt(); for (int i = 0; i < quatity; i++) { var cubeEntity = new CubeEntity(); cubeEntity.Deserialize(buffer); cubeEntities.Add(cubeEntity.id, cubeEntity); } }
private void Apply(Commands command, CubeEntity cube, CharacterController characterController) { if (cube == null || characterController == null) { return; } var _transform = cube.GO.transform; Vector3 move = _transform.forward * command.forwards + Vector3.down * Utils.gravity; characterController.Move(move * (Utils.speed * Time.deltaTime)); _transform.Rotate(new Vector3(0f, command.rotate * (Utils.rotateSpeed * Time.deltaTime), 0f)); }
private void setCurrentHealths(Snapshot snap, List <CubeEntity> cubes) { foreach (var cube in cubes) { CubeEntity other = snap.getEntityById(cube.Id); if (other == null) { //me } else { cube.Health = other.Health; } } }
public static Solution PrepareSolution() { Solution solution = new Solution("SSAS_OLAP", "SSAS 测试"); CubeEntity salesCube = new CubeEntity("SalesCube", "Sales"); salesCube.TableName = "SaleHistory"; solution.Cubes.Add(salesCube); var customerDim = new DimensionEntity("CustomerDim", "Customer") { FKColumn = "CustomerId" }; customerDim.Levels.Add(new LevelEntity("customerlevel", "Customer") { SourceTable = "Customer", KeyColumn = "Id", NameColumn = "Name" }); salesCube.Dimensions.Add(customerDim); var ProductDim = new DimensionEntity("ProductDim", "Product") { FKColumn = "ProductId" }; ProductDim.Levels.Add(new LevelEntity("Productlevel", "Product") { SourceTable = "Product", KeyColumn = "Id", NameColumn = "Name" }); salesCube.Dimensions.Add(ProductDim); //var DateDim = new SSASDim("DateDim"); //DateDim.Levels = new List<ILevel>(); //DateDim.Levels.Add(new Level("Datelevel", "Datelevel") { SourceTable = "" }); //solution.Dims.Add(DateDim); salesCube.Measures.Add(new MeasureEntity("ProductCount", "ProductCount") { ColumnName = "ProductCount", Aggregator = Aggregator.Sum }); salesCube.Measures.Add(new MeasureEntity("UnitPrice", "UnitPrice") { ColumnName = "UnitPrice", Aggregator = Aggregator.Sum }); return(solution); }
public static Snapshot CreateInterpolated(Snapshot previous, Snapshot next, float t, int clientId) { Dictionary <int, CubeEntity> cubeEntities = new Dictionary <int, CubeEntity>(); foreach (var kv in previous.cubeEntities) { if (kv.Value.id != clientId) // Do not interpolate client { // var step = Vector3.Distance(kv.Value.cubeGameObject.transform.position, // next.cubeEntities[kv.Key].cubeGameObject.transform.position); // if (step > 0f) Debug.Log(step); // if (step > 0.5f) Debug.Log("something wrong"); cubeEntities[kv.Key] = CubeEntity.createInterpolated(kv.Value, next.cubeEntities[kv.Key], t); } } return(new Snapshot(cubeEntities, -1, new List <Bullet>())); }
public static CubeEntity createInterpolated(CubeEntity previous, CubeEntity next, float t) { var cubeEntity = new CubeEntity(previous.GO, previous.id); cubeEntity.position = cubeEntity.position + Vector3.Lerp(previous.position, next.position, t); next.rotation = new Quaternion(next.rotation.x + 0.001f, next.rotation.y + 0.001f, next.rotation.z + 0.001f, next.rotation.w + 0.001f); var deltaRot = Quaternion.Lerp(previous.rotation, next.rotation, t); var rot = new Quaternion { x = previous.rotation.x + deltaRot.x, w = previous.rotation.w + deltaRot.w, y = previous.rotation.y + deltaRot.y, z = previous.rotation.z + deltaRot.z }; cubeEntity.rotation = rot; return(cubeEntity); }
public void processJoinGame(JoinGameMessage message) { int id = message.GetId; IPEndPoint endPoint = message.Packet.fromEndPoint; if (!players.Contains(new PlayerInfo(id, endPoint))) { lastSnapshot.Add(id, 0); kills.Add(id, 0); players.Add(new PlayerInfo(id, endPoint)); var serverCube = Instantiate(serverGameObject, new Vector3(Random.Range(-20, 20), 0.5f, Random.Range(-20, 20)), Quaternion.identity); // serverCube.layer = 8; // Server Layer SetLayerRecursively(serverCube, 8); CubeEntity newcube = new CubeEntity(serverCube, id); serverCube.transform.Find("Cube").GetComponent <HealthSignal>().cm = this; serverCube.transform.Find("Cube").GetComponent <HealthSignal>().id = id; serverCubes.Add(newcube); SendPlayerJoined(id); SendInitStatus(id); } }
private void AddUIToCube(CubeEntity cube, int cubeId) { var canvas = Instantiate(playerUICanvas, new Vector3(), Quaternion.identity); canvas.transform.SetParent(cube.GO.transform); canvas.transform.localPosition = new Vector3(0f, 2f, 0f); cube.SetUIManager(canvas.GetComponent <UIManager>(), $"{cubeId}", 1f); // var healthBar = canvas.GetComponent<HealthBar>(); // if (healthBar != null) // { // var healthBarComp = healthBar.GetComponent<HealthBar>(); // if(healthBarComp != null) cube.SetHealthBar(healthBarComp); // else // { // print("mini not"); // cube.SetHealthBar(healthBar); // } // } // else // { // print("not"); // } }
private void CreateCube(Database database, DataSource dataSource, DataSourceView dataSourceView, CubeEntity cube) { Cube ssasCube = database.Cubes.Find(cube.ID); if (ssasCube != null) { ssasCube.Drop(); } ssasCube = database.Cubes.Add(cube.Name, cube.ID); ssasCube.Source = new DataSourceViewBinding(dataSourceView.ID); ssasCube.StorageMode = StorageMode.Molap; ssasCube.Visible = true; foreach (var item in cube.Dimensions) { ssasCube.Dimensions.Add(item.ID); } var defaultGroup = ssasCube.MeasureGroups.Add("Default"); defaultGroup.StorageMode = StorageMode.Molap; defaultGroup.ProcessingMode = ProcessingMode.LazyAggregations; foreach (var outerMeasure in cube.Measures) { var ssasMeasure = defaultGroup.Measures.Add(outerMeasure.Name, outerMeasure.ID); ssasMeasure.Source = this.CreateDataItem(dataSourceView, cube.TableName, outerMeasure.ColumnName); ssasMeasure.AggregateFunction = this.GetAggregator(outerMeasure.Aggregator); //measure.FormatString = format;// "000,000.##"; //measure.Description = description; //measure.DisplayFolder = folderName; ssasMeasure.Visible = outerMeasure.Visable; } foreach (var dim in cube.Dimensions) { var cubeDim = ssasCube.Dimensions.Find(dim.ID); var groupDim = defaultGroup.Dimensions.Add(dim.ID); string levelId = ""; for (int i = 0; i < cubeDim.Attributes.Count; i++) { if (cubeDim.Dimension.Attributes[i].Usage == AttributeUsage.Key) { levelId = cubeDim.Dimension.Attributes[i].ID; break; } } var measureGroupAttribute = groupDim.Attributes.Add(levelId); measureGroupAttribute.Type = MeasureGroupAttributeType.Granularity; measureGroupAttribute.KeyColumns.Add(CreateDataItem(dataSourceView, cube.TableName, dim.FKColumn)); } CreatePartition(defaultGroup, dataSource, cube.TableName, DateTime.Now); ssasCube.Update(UpdateOptions.ExpandFull); ssasCube.Process(); }
private IEnumerator removeObject(CubeEntity cube) { yield return(new WaitForSeconds(5f)); Destroy(cube.GameObject); }
public void TestAddEntity() { var sceneEntity = new CubeEntity(); _stage.Add(sceneEntity); }
private void glControlView_KeyDown(object sender, KeyEventArgs e) { if (NoClickyClicky()) { return; } if (e.KeyCode == Keys.W) { tW_Tick(null, null); tW.Start(); } else if (e.KeyCode == Keys.A) { tA_Tick(null, null); tA.Start(); } else if (e.KeyCode == Keys.S) { tS_Tick(null, null); tS.Start(); } else if (e.KeyCode == Keys.D) { tD_Tick(null, null); tD.Start(); } else if (e.KeyCode == Keys.Z) { view_selected = !view_selected; } else if (e.KeyCode == Keys.Up) { CameraPitch += 10f; if (CameraPitch > 89.9f) { CameraPitch = 89.9f; } invalidateAll(); } else if (e.KeyCode == Keys.Down) { CameraPitch -= 10f; if (CameraPitch < -89.9f) { CameraPitch = -89.9f; } invalidateAll(); } else if (e.KeyCode == Keys.Right) { CameraYaw -= 10f; if (CameraYaw < 0) { CameraYaw += 360; } invalidateAll(); } else if (e.KeyCode == Keys.Left) { CameraYaw += 10f; if (CameraYaw > 360) { CameraYaw -= 360; } invalidateAll(); } else if (e.KeyCode == Keys.P) { Location normal; Entity hit = RayTraceEntity(ContextView, CameraPos, CameraPos + (view_mousepos - CameraPos) * 1000000, out normal); if (hit != null && hit is CubeEntity) { CubeEntity ce = (CubeEntity)hit; string tex = ContextView.Textures.LoadedTextures[tex_sel].Name; if (IsCloseTo(normal.Z, 1, 0.1f)) { ce.Textures[0] = tex; } else if (IsCloseTo(normal.Z, -1, 0.1f)) { ce.Textures[1] = tex; } else if (IsCloseTo(normal.X, 1, 0.1f)) { ce.Textures[2] = tex; } else if (IsCloseTo(normal.X, -1, 0.1f)) { ce.Textures[3] = tex; } else if (IsCloseTo(normal.Y, 1, 0.1f)) { ce.Textures[4] = tex; } else if (IsCloseTo(normal.Y, -1, 0.1f)) { ce.Textures[5] = tex; } ce.Recalculate(); glControlView.Invalidate(); } } else if (e.KeyCode == Keys.F) { Location normal; Entity hit = RayTraceEntity(ContextView, CameraPos, CameraPos + (view_mousepos - CameraPos) * 1000000, out normal); if (hit != null && hit is CubeEntity) { CubeEntity ce = (CubeEntity)hit; fe = new FaceEditor(ce, normal); fe.Show(); view_selected = false; } } PrimaryEditor_KeyDown(sender, e); }
public static Snapshot CreateInterpolated(Snapshot previous, Snapshot next, float t, Dictionary <String, GameObject> players, String id) { var cubes = CubeEntity.createInterpolated(previous, next, t, players, id); return(new Snapshot(-1, cubes)); }
public void Add(CubeEntity cubeEntity) { cubeEntities.Add(cubeEntity.id, cubeEntity); }
private void PlayerJoined(Packet packet) { var receivedId = packet.buffer.GetInt(); if (cubeEntitiesClient.ContainsKey(receivedId)) { return; // Skip anyone you already added } var cubeGO = Instantiate(clientCubePrefab, Utils.startPos, Quaternion.identity); cubeGO.transform.SetParent(GameObject.Find("Players(Client)").transform); var cube = new CubeEntity(cubeGO, receivedId); cubeEntitiesClient[cube.id] = cube; // Attach label on top of his head AddUIToCube(cube, receivedId); // Check if player joined is this client (server confirmation that I'm joined) if (receivedId == clientId) { // Add myself cubeGO.name = $"client-{clientId}"; print($"I joined, I'm {cubeGO.name}"); clientCharacterController = cubeGO.GetComponent <CharacterController>(); clientCube = cube; GameManager.clientId = clientId; // Add my reconciliation clone var reconciliateGO = Instantiate(clientReconciliateCubePrefab, Utils.startPos, Quaternion.identity); reconciliateGO.name = $"reconciliate-{clientId}"; reconciliateClientCube = new CubeEntity(reconciliateGO, clientId); reconciliateCharacterController = reconciliateGO.GetComponent <CharacterController>(); // Now add all players already in-game int previousCubesAmount = packet.buffer.GetInt(); print($"client-{clientId} receiving join with {previousCubesAmount} players"); for (int i = 0; i < previousCubesAmount; i++) { int newCubeId = packet.buffer.GetInt(); if (!cubeEntitiesClient.ContainsKey(newCubeId)) { var newCubeGO = Instantiate(clientCubePrefab, Utils.startPos, Quaternion.identity); newCubeGO.name = $"player-{newCubeId}"; print($"adding {newCubeGO.name}"); newCubeGO.transform.SetParent(GameObject.Find("Players(Client)").transform); var newCube = new CubeEntity(newCubeGO, newCubeId); newCube.Deserialize(packet.buffer); cubeEntitiesClient[newCubeId] = newCube; AddUIToCube(newCube, newCubeId); } } connected = true; } else { // If new player is not the client cubeGO.name = $"player-{receivedId}"; print($"{cubeGO.name} joined"); } }