示例#1
0
    public static ChunkRenderCache?GenerateCache(ClientWorld world, Vector3Int from, Vector3Int to, int padding)
    {
        int startX = from.x - padding >> 4;
        int startZ = from.z - padding >> 4;
        int lastX  = to.x + padding >> 4;
        int lastZ  = to.z + padding >> 4;

        var chunks = new Chunk[lastX - startX + 1, lastZ - startZ + 1];

        for (int x = startX; x <= lastX; ++x)
        {
            for (int z = startZ; z <= lastZ; ++z)
            {
                chunks[x - startX, z - startZ] = world.GetChunk(x, z);
            }
        }

        var startPos = from - Vector3Int.one;
        var endPos   = to + Vector3Int.one;

        if (ContainsGaps(startPos, endPos, startX, startZ, chunks))
        {
            return(null);
        }

        return(new ChunkRenderCache(world, startX, startZ, startPos, endPos, chunks));
    }
示例#2
0
        public BowheadHUD(ClientWorld world, GameState gameState) : base(world, gameState)
        {
            _equipHUD     = GameObject.Instantiate(GameManager.instance.clientData.hudEquipPrefab, hudCanvas.transform, false);
            _inventoryHUD = GameObject.Instantiate(GameManager.instance.clientData.hudInventoryPrefab, hudCanvas.transform, false);
            _interactHint = GameObject.Instantiate(GameManager.instance.clientData.hudButtonHintPrefab, hudCanvas.transform, false);
            _lockMarker   = GameObject.Instantiate(GameManager.instance.clientData.hudLockPrefab, hudCanvas.transform, false);
            _lockMarker.gameObject.SetActive(false);
            _worldmap = GameObject.Instantiate(GameManager.instance.clientData.worldMapPrefab, hudCanvas.transform, false);
            _compass  = GameObject.Instantiate(GameManager.instance.clientData.compassPrefab, hudCanvas.transform, false);

            _pawnHUDs = new GameObject("PawnHuds");
            _pawnHUDs.transform.parent = hudCanvas.transform;

            _playerHUD = new GameObject("PlayerHud");
            _playerHUD.transform.parent = worldHUDCanvas.transform;

            _worldmap.transform.SetAsLastSibling();             // keep world-map on top of everything.
            _worldmap.gameObject.SetActive(false);

            _inventoryHUD.transform.SetAsLastSibling();             // keep world-map on top of everything.
            _inventoryHUD.gameObject.SetActive(false);

            world.CritterActiveEvent     += OnCritterActive;
            world.DamageEvent            += OnDamage;
            world.StatusEffectAddedEvent += OnStatusEffectAdded;
        }
示例#3
0
        public ClientWorldHost()
        {
            var services = new ServiceCollection();

            services.AddLogging(builder =>
            {
                builder.AddConsole();
                builder.SetMinimumLevel(LogLevel.Trace);
            });

            var commandType = typeof(GameCommand);
            IEnumerable <Type> eventTypes = new List <Type>
            {
                typeof(GameActionEvent),
            };
            IEnumerable <KeyValuePair <Type, Type> > entityTypes = new Dictionary <Type, Type>
            {
                [typeof(ClientControlledEntity)] = typeof(MyState),
                [typeof(ClientDummyEntity)]      = typeof(DummyEntityState),
                [typeof(ClientMimicEntity)]      = typeof(MyState),
            };
            var pools   = new ClientPools(commandType, eventTypes, entityTypes);
            var manager = new ClientWorld(new ClientProtocol(pools), pools);

            //var manager = new ClientWorld(new MessagePackClientPacketProtocol(), pools);
            services.AddSingleton(manager);

            ServiceProvider = services.BuildServiceProvider();

            InitializeCommon();
            Initialize();
        }
示例#4
0
    // protected readonly BlockState[] blockStates;
    // protected readonly FluidState[] fluidStates;

    private ChunkRenderCache(ClientWorld world, int chunkStartX, int chunkStartZ, Vector3Int startPos, Vector3Int endPos, Chunk[,] chunks)
    {
        World         = world;
        ChunkStartX   = chunkStartX;
        ChunkStartZ   = chunkStartZ;
        Chunks        = chunks;
        CacheStartPos = startPos;
        CacheSizeX    = endPos.x - startPos.x + 1;
        CacheSizeY    = endPos.y - startPos.y + 1;
        CacheSizeZ    = endPos.z - startPos.z + 1;
        Tiles         = new Tile[CacheSizeX, CacheSizeY, CacheSizeZ];
        // blockStates = new BlockState[CacheSizeX * CacheSizeY * CacheSizeZ];
        // fluidStates = new FluidState[CacheSizeX * CacheSizeY * CacheSizeZ];

        for (int x = startPos.x; x < endPos.x; x++)
        {
            for (int z = startPos.z; z < endPos.z; z++)
            {
                var chunk = chunks[(x >> 4) - chunkStartX, (z >> 4) - chunkStartZ];

                for (int y = startPos.y; y < endPos.y; y++)
                {
                    Tiles[x - startPos.x, y - startPos.y, z - startPos.z] = chunk.GetTile(x, y, z);
                }
            }
        }
    }
示例#5
0
 public HUD(ClientWorld world, GameState gameState)
 {
     _world          = world;
     _gameState      = gameState;
     _hudCanvas      = GameObject.Instantiate(GameManager.instance.clientData.hudCanvasPrefab);
     _worldHUDCanvas = GameObject.Instantiate(GameManager.instance.clientData.worldHUDPrefab);
 }
示例#6
0
        public IEnumerator ShouldConnectMultipleClients()
        {
            bool        client1Connected = false, client2Connected = false;
            ClientWorld client2 = new ClientWorld(new ClientOptions
            {
                Address   = "127.0.0.1",
                Port      = (ushort)(21650 + testCount),
                WorldName = $"Test_Connection_Client_2_{testCount}"
            });

            NewClientServer();
            clientWorld.Connected    += e => client1Connected = true;
            client2.Connected        += e => client2Connected = true;
            clientWorld.Disconnected += () => client1Connected = false;
            client2.Disconnected     += () => client2Connected = false;
            serverWorld.Listen();
            yield return(new WaitForSeconds(0.1f));

            clientWorld.Connect();
            client2.Connect();
            int maxCount = 30;

            while (maxCount >= 0 && !(client1Connected && client2Connected))
            {
                yield return(new WaitForSeconds(0.25f));

                maxCount--;
            }

            Assert.IsTrue(client1Connected);
            Assert.IsTrue(client2Connected);
        }
示例#7
0
 // Token: 0x06008BEF RID: 35823 RVA: 0x0028D8D4 File Offset: 0x0028BAD4
 public void Locate(Vector2 p, int dir)
 {
     if (!BJLuaObjHelper.IsSkipLuaHotfix && this.TryInitHotFix("") && this.m_LocateVector2Int32_hotfix != null)
     {
         this.m_LocateVector2Int32_hotfix.call(new object[]
         {
             this,
             p,
             dir
         });
         return;
     }
     BJLuaObjHelper.IsSkipLuaHotfix = false;
     this.m_position  = p;
     this.m_direction = dir;
     if (this.m_graphic != null)
     {
         this.m_graphic.SetPosition(ClientWorld.ComputeActorPosition(this.m_position, -0.08f));
         this.m_graphic.SetDirection(this.m_direction);
     }
     if (this.m_uiController != null)
     {
         this.m_uiController.transform.localPosition = ClientWorld.ComputeActorPosition(this.m_position, -0.099999994f);
     }
 }
        // Token: 0x06008C69 RID: 35945 RVA: 0x0028F708 File Offset: 0x0028D908
        public void Initialize(ClientWorld world, ConfigDataWaypointInfo waypointInfo)
        {
            if (!BJLuaObjHelper.IsSkipLuaHotfix && this.TryInitHotFix("") && this.m_InitializeClientWorldConfigDataWaypointInfo_hotfix != null)
            {
                this.m_InitializeClientWorldConfigDataWaypointInfo_hotfix.call(new object[]
                {
                    this,
                    world,
                    waypointInfo
                });
                return;
            }
            BJLuaObjHelper.IsSkipLuaHotfix = false;
            this.m_clientWorld             = world;
            this.m_waypointInfo            = waypointInfo;
            this.m_id = world.GetNextEntityId();
            bool flag = waypointInfo.FuncType == WaypointFuncType.WaypointFuncType_Scenario || waypointInfo.FuncType == WaypointFuncType.WaypointFuncType_Portal;

            this.m_graphicInitScale = 1f;
            this.m_graphic          = world.CreateGraphic(waypointInfo.Model, this.m_graphicInitScale);
            if (this.m_graphic != null)
            {
                this.m_graphic.SetName("Waypoint_" + waypointInfo.ID);
                this.m_graphic.SetRotation(ClientWorldConst.FaceCameraRotation);
                if (flag)
                {
                    this.m_graphic.SetSortingOrder(2);
                }
                this.m_graphicUIStateController = this.m_graphic.GetPrefab().GetComponent <CommonUIStateController>();
            }
            GameObject gameObject;

            if (flag)
            {
                gameObject = UnityEngine.Object.Instantiate <GameObject>(world.WaypointUIPrefab, world.WaypointUIRoot.transform, false);
            }
            else
            {
                gameObject = UnityEngine.Object.Instantiate <GameObject>(world.Waypoint2UIPrefab, world.WaypointUIRoot.transform, false);
            }
            if (gameObject != null)
            {
                gameObject.name     = "Waypoint_" + waypointInfo.ID;
                this.m_uiInitScale  = gameObject.transform.localScale;
                this.m_uiController = GameObjectUtility.AddControllerToGameObject <WorldWaypointUIController>(gameObject);
                this.m_uiController.SetWaypoint(this.m_waypointInfo);
                this.m_uiController.EventOnPointerDown += this.OnUIPointerDown;
                this.m_uiController.EventOnPointerUp   += this.OnUIPointerUp;
                this.m_uiController.EventOnClick       += this.OnUIClick;
                gameObject.transform.localRotation      = ClientWorldConst.FaceCameraRotation;
                if (flag)
                {
                    Canvas canvas = gameObject.AddComponent <Canvas>();
                    canvas.overrideSorting = true;
                    canvas.sortingOrder    = 2;
                    gameObject.AddComponent <GraphicRaycaster>();
                }
            }
        }
示例#9
0
	public void Initialize(ClientWorld world, ClientStateSettings settings)
	{
		_world = world;
		_network = _world.GetClientNode();
		_settings = (SpawnAvatarSettings)settings;
		_settings.Hide();
		_transitionState = ClientStateId.NO_TRANSITION;
	}
示例#10
0
        public Client(IClientConnection connection, IClientController controller, PlayerProfile profile)
        {
            Profile    = profile;
            Connection = connection;
            Controller = controller;

            World = new ClientWorld(this);
        }
示例#11
0
    public void SetWorldAndLoadRenderers(ClientWorld world)
    {
        _world = world;

        _camera                = _client.Camera;
        _cameraTransform       = _camera.transform;
        _frustum               = new ViewFrustum(renderDistance: 3);
        _chunkRenderDispatcher = new ChunkRenderDispatcher(world);
    }
示例#12
0
        public void ReceiveSpecs(GameSpecResponse ev)
        {
            if (_game != null)
            {
                throw new System.Exception("Received to register specs twice");
            }
            var world = new ClientWorld(ev);

            _game = new ClientStrategyGame(ev.Spec, world);
        }
示例#13
0
    public Client()
    {
        instance      = this;
        clientWorld   = new ClientWorld();
        networkClient = new NetworkClient(clientWorld);

        StateMachine = new StateMachine <ClientState>();
        StateMachine.Add(ClientState.Browsing, EnterBrowsingState, null, null);
        StateMachine.Add(ClientState.Connecting, EnterConnectingState, null, null);
        StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, null);
    }
示例#14
0
    public Avatar(AvatarSettings avatar, ClientWorld world)
    {
        _avatar = avatar;

        _avatar.avatarCamera.enabled = true;
        _avatar.avatarCamera.tag     = "MainCamera";

        world.DisableRoomCamera();
        _avatar.audioListener.enabled = true;

        OnTeleport();
    }
示例#15
0
    public void LoadWorld()
    {
        _screenManager.ShowGameMenu();

        _renderWorld = true;

        _worldRenderer = new WorldRenderer(this);
        _world         = new ClientWorld(_worldRenderer);

        _worldRenderer.SetWorldAndLoadRenderers(_world);
        _server = MinecraftServer.CreateServer(thread => new IntegratedServer(thread));
    }
	public void Initialize( ClientWorld world, ClientStateSettings settings )
	{
		_world = world;
		_settings = (ConnectToServerSettings)settings;
		_settings.Hide();
		_transitionState = ClientStateId.NO_TRANSITION;
		
		_network = _world.GetClientNode();

		int maxChars = _network.GetMaxMessageLength() / sizeof(char);
		_charBuffer = new char[maxChars];
		_sb = new StringBuilder( maxChars );
	}
示例#17
0
        // Token: 0x06008D23 RID: 36131 RVA: 0x00293140 File Offset: 0x00291340
        public bool FindPath(ClientWorld world, int start, int goal, List <int> path, bool checkWaypointStatus)
        {
            this.InitiatePathfind();
            this.m_clientWorld           = world;
            this.m_isCheckWaypointStatus = checkWaypointStatus;
            ConfigDataWaypointInfo waypointInfo;
            Vector2 position;

            if (!this.GetWaypoint(start, out waypointInfo, out position))
            {
                return(false);
            }
            ConfigDataWaypointInfo waypointInfo2;
            Vector2 position2;

            if (!this.GetWaypoint(goal, out waypointInfo2, out position2))
            {
                return(false);
            }
            WorldPathNode worldPathNode = this.AllocatePathNode();

            worldPathNode.m_waypointInfo = waypointInfo;
            worldPathNode.m_position     = position;
            WorldPathNode worldPathNode2 = this.AllocatePathNode();

            worldPathNode2.m_waypointInfo = waypointInfo2;
            worldPathNode2.m_position     = position2;
            this.SetStartAndGoalStates(worldPathNode, worldPathNode2);
            do
            {
                this.SearchStep();
            }while (this.m_State == WorldPathfinder.SearchState.Searching);
            if (this.m_State == WorldPathfinder.SearchState.Succeeded)
            {
                WorldPathNode worldPathNode3 = this.GetSolutionStart();
                path.Add(worldPathNode3.m_waypointInfo.ID);
                for (;;)
                {
                    worldPathNode3 = this.GetSolutionNext();
                    if (worldPathNode3 == null)
                    {
                        break;
                    }
                    path.Add(worldPathNode3.m_waypointInfo.ID);
                }
                this.FreeSolutionNodes();
                return(true);
            }
            return(false);
        }
示例#18
0
        private void NewClientServer()
        {
            ushort port = (ushort)(21650 + testCount);

            Debug.Log(port);
            serverOptions = new ServerOptions
            {
                Address               = "0.0.0.0",
                Port                  = port,
                WorldName             = $"Test_Connection_Server{testCount}",
                GhostCollectionPrefab = prefab
            };
            clientOptions = new ClientOptions
            {
                Address               = "127.0.0.1",
                Port                  = port,
                TimeOut               = 5,
                WorldName             = $"Test_Connection_Client{testCount}",
                GhostCollectionPrefab = prefab
            };


            serverWorld = new ServerWorld(serverOptions);
            clientWorld = new ClientWorld(clientOptions);

            serverWorld.ListenSuccess += () =>
            {
                Debug.Log($"{serverOptions.WorldName}: Listening");
                serverListening = true;
            };
            clientWorld.Connecting += () =>
            {
                Debug.Log($"{clientOptions.WorldName}: Connecting");
                clientConnecting = true;
            };
            clientWorld.Connected += x =>
            {
                Debug.Log($"{clientOptions.WorldName}: Connected");
                clientConnected = true;
            };
            clientWorld.ConnectionFailed += x =>
            {
                Debug.Log($"{clientOptions.WorldName}: Connect Failed: " + x);
                clientConnectFailed = true;
            };
            testCount++;
        }
示例#19
0
 // Token: 0x06008C3C RID: 35900 RVA: 0x0028EB90 File Offset: 0x0028CD90
 public void Initialize(ClientWorld world, ConfigDataRegionInfo regionInfo)
 {
     if (!BJLuaObjHelper.IsSkipLuaHotfix && this.TryInitHotFix("") && this.m_InitializeClientWorldConfigDataRegionInfo_hotfix != null)
     {
         this.m_InitializeClientWorldConfigDataRegionInfo_hotfix.call(new object[]
         {
             this,
             world,
             regionInfo
         });
         return;
     }
     BJLuaObjHelper.IsSkipLuaHotfix = false;
     this.m_regionInfo = regionInfo;
     this.m_id         = world.GetNextEntityId();
     this.m_gameObject = null;
 }
示例#20
0
        internal GameScene(Application.Client client, ClientWorld world, GameConsole console)
        {
            this.client = client;

            Player = null !;

            Screen.SetCursor(visible: false, locked: true);

            ui = new GameUserInterface(
                client,
                client.Keybinds.Input.Listener,
                drawBackground: false);

            List <ISettingsProvider> settingsProviders = new()
            {
                client.Settings,
                Application.Client.Instance.Keybinds
            };

            ui.SetSettingsProviders(settingsProviders);
            ui.SetConsoleProvider(console);
            ui.SetPerformanceProvider(client);

            ui.WorldExit += client.LoadStartScene;

            ui.AnyOverlayOpen += () =>
            {
                Screen.SetOverlayLock();
                Screen.SetCursor(visible: true, locked: false);
            };

            ui.AnyOverlayClosed += () =>
            {
                Screen.ClearOverlayLock();
                Screen.SetCursor(visible: false, locked: true);
            };

            World   = world;
            counter = world.UpdateCounter;

            uiToggle = client.Keybinds.GetToggle(client.Keybinds.UI);

            screenshotButton = client.Keybinds.GetPushButton(client.Keybinds.Screenshot);
            consoleToggle    = client.Keybinds.GetToggle(client.Keybinds.Console);
            escapeButton     = client.Keybinds.GetPushButton(client.Keybinds.Escape);
        }
示例#21
0
        // Token: 0x06008B97 RID: 35735 RVA: 0x0028B9B4 File Offset: 0x00289BB4
        public void Initialize(ClientWorld world, ConfigDataEventInfo eventInfo, RandomEvent randomEvent)
        {
            if (!BJLuaObjHelper.IsSkipLuaHotfix && this.TryInitHotFix("") && this.m_InitializeClientWorldConfigDataEventInfoRandomEvent_hotfix != null)
            {
                this.m_InitializeClientWorldConfigDataEventInfoRandomEvent_hotfix.call(new object[]
                {
                    this,
                    world,
                    eventInfo,
                    randomEvent
                });
                return;
            }
            BJLuaObjHelper.IsSkipLuaHotfix = false;
            this.m_clientWorld             = world;
            this.m_eventInfo        = eventInfo;
            this.m_randomEvent      = randomEvent;
            this.m_id               = world.GetNextEntityId();
            this.m_graphicInitScale = (float)eventInfo.ModelScale * 0.01f;
            this.m_graphic          = world.CreateGraphic(eventInfo.Model, this.m_graphicInitScale);
            if (this.m_graphic != null)
            {
                this.m_graphic.SetName("Event_" + eventInfo.ID);
                this.m_graphic.SetRotation(ClientWorldConst.FaceCameraRotation);
                this.m_graphic.SetSortingOrder(2);
            }
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(world.EventUIPrefab, world.EventUIRoot.transform, false);

            if (gameObject != null)
            {
                gameObject.name     = "Event_" + eventInfo.ID;
                this.m_uiInitScale  = gameObject.transform.localScale;
                this.m_uiController = GameObjectUtility.AddControllerToGameObject <WorldEventActorUIController>(gameObject);
                this.m_uiController.SetEvent(eventInfo);
                this.m_uiController.EventOnPointerDown += this.OnUIPointerDown;
                this.m_uiController.EventOnPointerUp   += this.OnUIPointerUp;
                this.m_uiController.EventOnClick       += this.OnUIClick;
                gameObject.transform.localRotation      = ClientWorldConst.FaceCameraRotation;
                Canvas canvas = gameObject.AddComponent <Canvas>();
                canvas.overrideSorting = true;
                canvas.sortingOrder    = 2;
                gameObject.AddComponent <GraphicRaycaster>();
            }
            this.PlayAnimation("idle", true);
        }
示例#22
0
	void Update()
	{
		if (_fsm != null)
		{
			_fsm.OnUpdate();
		}
		else
		{
			if( _load.isDone )
			{
				WorldSettings worldSettings = Utility.GetWorldSettingsFromCommonScene();

				// create the world, which is all data that needs to be shared between states
				_world = new ClientWorld(worldSettings, _clientWorldSettings);

				// setup the FSM, creating each state and passing along its associated settings
				_fsm = new StateMachine<ClientState>((int)ClientStateId.COUNT);
				{
					ClientState s;

					s = new ConnectToServer();
					s.Initialize(_world, _connectToServerSettings);
					_fsm.AddState(s);

					s = new LoadClientRoom();
					s.Initialize(_world, _loadRoomSceneSettings);
					_fsm.AddState(s);

					s = new SpawnAvatar();
					s.Initialize(_world, _spawnAvatarSettings);
					_fsm.AddState(s);

					s = new Playing();
					s.Initialize(_world, _playingSettings);
					_fsm.AddState(s);
				}

				// start the FSM
				_fsm.TransitionTo((int)ClientStateId.ConnectToServer);
			}
		}
	}
示例#23
0
        // Token: 0x06008BE7 RID: 35815 RVA: 0x0028D194 File Offset: 0x0028B394
        public void Initialize(ClientWorld world)
        {
            if (!BJLuaObjHelper.IsSkipLuaHotfix && this.TryInitHotFix("") && this.m_InitializeClientWorld_hotfix != null)
            {
                this.m_InitializeClientWorld_hotfix.call(new object[]
                {
                    this,
                    world
                });
                return;
            }
            BJLuaObjHelper.IsSkipLuaHotfix = false;
            this.m_clientWorld             = world;
            this.m_id = world.GetNextEntityId();
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(world.PlayerUIPrefab, world.PlayerUIRoot.transform, false);

            if (gameObject != null)
            {
                gameObject.name     = "Player";
                this.m_uiController = GameObjectUtility.AddControllerToGameObject <WorldPlayerActorUIController>(gameObject);
                gameObject.transform.localRotation = ClientWorldConst.FaceCameraRotation;
            }
        }
示例#24
0
        public IEnumerator Server_ShouldSendRpcToMultipleClients()
        {
            ClientWorld client2 = new ClientWorld(new ClientOptions
            {
                Address   = "127.0.0.1",
                Port      = (ushort)(21650 + testCount),
                WorldName = $"TestServer_ShouldSendRpcToMultipleClients{testCount}"
            });

            Debug.Log((ushort)(21650 + testCount));
            NewClientServer();


            serverWorld.Listen();
            yield return(new WaitForSeconds(0.3f));

            clientWorld.Connect();
            yield return(new WaitForSeconds(0.2f));

            bool client2Connected = false;
            bool client2Failed    = false;

            client2.Connected        += e => client2Connected = true;
            client2.ConnectionFailed += s => client2Failed = true;
            client2.Connect();
            yield return(new WaitForSeconds(0.2f));

            int maxCount = 90;

            while (maxCount >= 0 && !(clientConnected || clientConnectFailed) && !(client2Connected || client2Failed))
            {
                yield return(new WaitForSeconds(0.1f));

                maxCount--;
            }

            Assert.IsTrue(clientConnected, "Client 1 did not connect to begin test");
            Assert.IsTrue(client2Connected, "Client 2 did not connect to begin test");

            serverWorld.World.CreateRpcRequest <PlayModeTestRequest>(
                serverWorld.GetNetworkConnectionEntityById(clientWorld.NetworkId));
            serverWorld.World.CreateRpcRequest <PlayModeTestRequest>(
                serverWorld.GetNetworkConnectionEntityById(client2.NetworkId));

            /*Assert.IsNotNull(clientWorld, "cw");
             * Assert.IsNotNull(clientWorld.World, "cww");
             * Assert.IsNotNull(clientWorld.World.GetExistingSystem<CreateRpcRequestSystem>(), "cws");*/

            PlayModeTestRequestReceiveSystem system1 =
                clientWorld.World.GetExistingSystem <PlayModeTestRequestReceiveSystem>();
            PlayModeTestRequestReceiveSystem system2 =
                client2.World.GetExistingSystem <PlayModeTestRequestReceiveSystem>();

            maxCount = 60;
            while (maxCount >= 0 && !system1.ReceivedRpc && !system2.ReceivedRpc)
            {
                yield return(new WaitForSeconds(0.1f));

                maxCount--;
            }

            Assert.IsTrue(system1.ReceivedRpc && system2.ReceivedRpc);
        }
示例#25
0
 public ClientChunkProvider(ClientWorld world, int viewDistance)
 {
     _world      = world;
     _chunkArray = new ChunkArray(AdjustViewDistance(viewDistance));
 }
示例#26
0
 public ChunkRenderDispatcher(ClientWorld world)
 {
     _world = world;
 }
示例#27
0
        private void OnButton2Pressed()
        {
            Console.WriteLine("OnButton2Pressed");

            var host = new ClientWorldHost();

            world = host.ServiceProvider.GetRequiredService <ClientWorld>();

            var loggerFactory = host.ServiceProvider.GetService <ILoggerFactory>();
            var logger        = loggerFactory.CreateLogger <MyControl>();

            // Unity:
            // GameObject[] prefabs
            // var go = Instantiate(prefabs[archetypeId])
            // go.GetComponent<Controlled/Dummy/MimicEntityBehaviour>().Controlled/Dummy/MimicEntity = entity;
            host.Client_OnControlledCreated += entity =>
            {
                logger.LogInformation($"ControlledCreated entity: {entity.Id} ArchetypeId: {entity.State.ArchetypeId}");

                var scene = GD.Load <PackedScene>("res://Entities/ControlledEntitySpatial.tscn");
                var node  = scene.Instance() as ControlledEntitySpatial;

                node.Entity = entity;

                var parent = GetParent <Node>() as MySpatial;
                parent.AddChild(node);
            };
            host.Client_OnDummyCreated += entity =>
            {
                logger.LogInformation($"DummyCreated entity: {entity.Id} ArchetypeId: {entity.State.ArchetypeId}");

                var scene = GD.Load <PackedScene>("res://Entities/DummyEntitySpatial.tscn");
                var node  = scene.Instance() as DummyEntitySpatial;

                node.Entity = entity;

                var parent = GetParent <Node>() as MySpatial;
                parent.AddChild(node);
            };
            host.Client_OnMimicCreated += entity =>
            {
                logger.LogInformation($"MimicCreated entity: {entity.Id} ArchetypeId: {entity.State.ArchetypeId}");

                var scene = GD.Load <PackedScene>("res://Entities/MimicEntitySpatial.tscn");
                var node  = scene.Instance() as MimicEntitySpatial;

                node.Entity = entity;

                var parent = GetParent <Node>() as MySpatial;
                parent.AddChild(node);
            };

            host.Client_OnGameActionEvent += evnt =>
            {
                //logger.LogWarning($"evnt {evnt.Key}");
            };


            NetConfig.LatencySimulation = true;

            network = new NetCore("NetDemo1.0", false);
            network.PeerConnected += (peer, token) =>
            {
                Console.WriteLine($"PeerConnected peer: {peer.EndPoint} token: {token}");
                var wrapper = new MiniUDPConnection(peer);
                world.SetConnection(wrapper);
            };
            network.PeerClosed += (peer, reason, userKickReason, error) =>
            {
                Console.WriteLine($"PeerClosed peer: {peer.EndPoint} reason: {reason} userKickReason: {userKickReason} error: {error}");
            };
            network.PeerPayload += (peer, data, dataLength) =>
            {
                //Console.WriteLine($"PeerPayload data: {data} dataLength: {dataLength}");
                receivedThisFrame += dataLength;
            };
            network.PeerNotification += (peer, data, dataLength) =>
            {
                //Console.WriteLine($"PeerNotification data: {data} dataLength: {dataLength}");
            };

            logger.LogInformation("Client Connecting...");
            var _peer = network.Connect(NetUtil.StringToEndPoint("127.0.0.1:44325"), "SampleAuthToken");

            logger.LogInformation("Client Connected.");

            //network.Stop();
        }
示例#28
0
 public InterpolationManager(ClientWorld clientWorld)
 {
     instance         = this;
     this.clientWorld = clientWorld;
     simulationStep   = localTickInterval / serverTickInterval;
 }
示例#29
0
 protected virtual void Start()
 {
     client = FindObjectOfType <ClientWorld>();
     world  = client.world;
 }