protected override void OnCreateManager()
    {
        m_DataStream = new DataStreamWriter(2048, Allocator.Persistent);
        ghostGroup   = GetComponentGroup(typeof(GhostComponent), typeof(GhostSystemStateComponent));
        var filterSpawn = new EntityArchetypeQuery
        {
            All  = new ComponentType[] { typeof(GhostComponent) },
            None = new ComponentType[] { typeof(GhostSystemStateComponent) }
        };
        var filterDespawn = new EntityArchetypeQuery
        {
            All  = new ComponentType[] { typeof(GhostSystemStateComponent) },
            None = new ComponentType[] { typeof(GhostComponent) }
        };

        ghostSpawnGroup   = GetComponentGroup(filterSpawn);
        ghostDespawnGroup = GetComponentGroup(filterDespawn);

        m_FreeGhostIds         = new NativeQueue <int>(Allocator.Persistent);
        m_AllocatedGhostIds    = new NativeArray <int>(1, Allocator.Persistent);
        m_AllocatedGhostIds[0] = 1; // To make sure 0 is invalid

        connectionGroup = GetComponentGroup(
            ComponentType.ReadWrite <NetworkStreamConnection>(),
            ComponentType.ReadOnly <PlayerStateComponentData>());

        m_ServerSimulation = World.GetExistingManager <ServerSimulationSystemGroup>();
        m_Barrier          = World.GetOrCreateManager <BeginSimulationEntityCommandBufferSystem>();

        m_ConnectionStates      = new List <ConnectionStateData>(256);
        m_ConnectionStateLookup = new NativeHashMap <Entity, int>(256, Allocator.Persistent);
        m_CompressionModel      = new NetworkCompressionModel(Allocator.Persistent);

        m_SerialSpawnChunks = new NativeList <PrioChunk>(1024, Allocator.Persistent);
    }
Пример #2
0
    protected override void OnCreate()
    {
        m_ServerSimulationSystemGroup = World.GetOrCreateSystem <ServerSimulationSystemGroup>();

        m_Players = GetEntityQuery(
            ComponentType.ReadWrite <RepCubeComponentData>(),
            ComponentType.ReadOnly <PlayerCommandData>(),
            ComponentType.ReadWrite <Transform>());
    }
Пример #3
0
        protected override void OnCreate()
        {
            m_AsteroidGroup = GetEntityQuery(ComponentType.ReadWrite <AsteroidTagComponentData>());
            m_Barrier       = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
            m_ServerSimulationSystemGroup = World.GetExistingSystem <ServerSimulationSystemGroup>();

            m_LevelGroup = GetEntityQuery(ComponentType.ReadWrite <LevelComponent>());
            RequireForUpdate(m_LevelGroup);
            m_ConnectionGroup = GetEntityQuery(ComponentType.ReadWrite <NetworkStreamConnection>());
        }
        protected override void OnCreate( )
        {
            m_validatePhysicEntitySnapshots = World.GetExistingSystem <ValidatePhysicEntitySnapshots>( );
            m_clientSimulationSystemGroup   = World.GetExistingSystem <ClientSimulationSystemGroup>( );
            m_serverSimulationSystemGroup   = World.GetExistingSystem <ServerSimulationSystemGroup>( );
            m_barrier           = World.GetExistingSystem <EndSimulationEntityCommandBufferSystem>( );
            m_ghostLookupSystem = World.GetExistingSystem <GhostLookupSystem>( );

            m_isServer = m_serverSimulationSystemGroup != null;
        }
Пример #5
0
        protected override void OnCreate()
        {
            base.OnCreate();
            _ = this;

#if !UNITY_CLIENT
            m_ServerComponentGroup = World.GetExistingSystem <ServerSimulationSystemGroup>();
#endif
#if !UNITY_SERVER
            m_ClientPresentationGroup = World.GetExistingSystem <ClientPresentationSystemGroup>();
            m_ClientComponentGroup    = World.GetExistingSystem <ClientSimulationSystemGroup>();
#endif
        }
Пример #6
0
        protected override void OnCreate()
        {
            shipGroup = GetEntityQuery(ComponentType.ReadOnly <Translation>(),
                                       ComponentType.ReadOnly <CollisionSphereComponent>(), ComponentType.ReadOnly <ShipTagComponentData>());
            bulletGroup = GetEntityQuery(ComponentType.ReadOnly <Translation>(),
                                         ComponentType.ReadOnly <CollisionSphereComponent>(), ComponentType.ReadOnly <BulletTagComponent>(),
                                         ComponentType.ReadOnly <BulletAgeComponent>());
            asteroidGroup = GetEntityQuery(ComponentType.ReadOnly <Translation>(),
                                           ComponentType.ReadOnly <CollisionSphereComponent>(), ComponentType.ReadOnly <AsteroidTagComponentData>());
            barrier = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
            m_ServerSimulationSystemGroup = World.GetExistingSystem <ServerSimulationSystemGroup>();
            playerClearQueue = new NativeQueue <Entity>(Allocator.Persistent);

            m_LevelGroup = GetEntityQuery(ComponentType.ReadWrite <LevelComponent>());
            RequireForUpdate(m_LevelGroup);

            settingsGroup = GetEntityQuery(ComponentType.ReadOnly <ServerSettings>());
        }
Пример #7
0
        public void Initialize()
        {
            foreach (var world in World.All)
            {
                if (world.GetExistingSystem <ClientSimulationSystemGroup>() != null)
                {
                    m_clientSimulationSystemGroup = world.GetExistingSystem <ClientSimulationSystemGroup>();
                    Client         = world;
                    HasClientWorld = true;
                }
                else if (world.GetExistingSystem <ServerSimulationSystemGroup>() != null)
                {
                    m_serverSimulationSystemGroup = world.GetExistingSystem <ServerSimulationSystemGroup>();
                    Server         = world;
                    HasServerWorld = true;
                }

                if (world.GetExistingSystem <TransformSystemGroup>() != null)
                {
                    Default = world;
                }
            }
        }
Пример #8
0
    public static void InitServerSystems()
    {
        serverWorld = new World("ServerWorld");
        serverSimulationSystemGroup = serverWorld.GetOrCreateSystem <ServerSimulationSystemGroup>();

        foreach (var sys in allSystems)
        {
            var groups = sys.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
            foreach (var grp in groups)
            {
                var group = grp as UpdateInGroupAttribute;

                if (group.GroupType == typeof(ServerSimulationSystemGroup) ||
                    group.GroupType == typeof(ClientAndServerSimulationSystemGroup))
                {
                    serverSimulationSystemGroup.AddSystemToUpdateList(serverWorld.GetOrCreateSystem(sys) as ComponentSystemBase);
                }
                else if (group.GroupType == typeof(ClientSimulationSystemGroup) ||
                         group.GroupType == typeof(ClientPresentationSystemGroup))
                {
                    // do nothing
                }
                else
                {
                    var mask = GetTopLevelWorldMask(group.GroupType);
                    if ((mask & WorldType.ServerWorld) != 0)
                    {
                        var groupSys = serverWorld.GetOrCreateSystem(group.GroupType) as ComponentSystemGroup;
                        groupSys.AddSystemToUpdateList(serverWorld.GetOrCreateSystem(sys) as ComponentSystemBase);
                    }
                }
            }
        }

        serverSimulationSystemGroup.SortSystemUpdateList();
        World.Active.GetOrCreateSystem <TickServerSimulationSystem>().AddSystemToUpdateList(serverSimulationSystemGroup);
    }
Пример #9
0
 protected override void OnCreateManager()
 {
     barrier = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
     serverSimulationSystemGroup = World.GetOrCreateSystem <ServerSimulationSystemGroup>();
     RequireSingletonForUpdate <ServerSettings>();
 }
Пример #10
0
 protected override void OnCreateManager()
 {
     serverSimulationSystemGroup = World.GetExistingSystem <ServerSimulationSystemGroup>();
 }
Пример #11
0
 protected override void OnCreateManager()
 {
     m_ServerSimulationSystemGroup = World.GetOrCreateSystem <ServerSimulationSystemGroup>();
     m_NetworkConnection           = GetEntityQuery(ComponentType.ReadWrite <NetworkIdComponent>());
 }
 protected override void OnCreate( )
 {
     m_serverSimulationSystemGroup = World.GetExistingSystem <ServerSimulationSystemGroup>( );
     m_clientSimulationSystemGroup = World.GetExistingSystem <ClientSimulationSystemGroup>( );
 }
Пример #13
0
    public List <Type> Initialize(List <Type> systems)
    {
        // Workaround for initialization being called multiple times when using game object conversion
#if !UNITY_SERVER
        if (clientWorld != null)
        {
            return(systems);
        }
#endif
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
        if (serverWorld != null)
        {
            return(systems);
        }
#endif

#if !UNITY_SERVER
#if UNITY_EDITOR
        int numClientWorlds = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_NumClients");
        if (numClientWorlds < 1)
        {
            numClientWorlds = 1;
        }
        if (numClientWorlds > 8)
        {
            numClientWorlds = 8;
        }
        int playModeType = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_Type");
#else
        int numClientWorlds = 1;
#endif
#endif

        var defaultBootstrap = new List <Type>();
#if !UNITY_SERVER
        clientWorld = null;
        ClientInitializationSystemGroup[] clientInitializationSystemGroup = null;
        ClientSimulationSystemGroup[]     clientSimulationSystemGroup     = null;
        ClientPresentationSystemGroup[]   clientPresentationSystemGroup   = null;
#if UNITY_EDITOR
        if (playModeType != 2)
#endif
        {
            clientWorld = new World[numClientWorlds];
            clientInitializationSystemGroup = new ClientInitializationSystemGroup[clientWorld.Length];
            clientSimulationSystemGroup     = new ClientSimulationSystemGroup[clientWorld.Length];
            clientPresentationSystemGroup   = new ClientPresentationSystemGroup[clientWorld.Length];
            for (int i = 0; i < clientWorld.Length; ++i)
            {
                clientWorld[i] = new World("ClientWorld" + i);
                clientInitializationSystemGroup[i] = clientWorld[i].GetOrCreateSystem <ClientInitializationSystemGroup>();
                clientSimulationSystemGroup[i]     = clientWorld[i].GetOrCreateSystem <ClientSimulationSystemGroup>();
#if UNITY_EDITOR
                clientSimulationSystemGroup[i].ClientWorldIndex = i;
#endif
                clientPresentationSystemGroup[i] = clientWorld[i].GetOrCreateSystem <ClientPresentationSystemGroup>();
            }
        }
#endif
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
        serverWorld = null;
        ServerInitializationSystemGroup serverInitializationSystemGroup = null;
        ServerSimulationSystemGroup     serverSimulationSystemGroup     = null;
#if UNITY_EDITOR
        if (playModeType != 1)
#endif
        {
            serverWorld = new World("ServerWorld");
            serverInitializationSystemGroup = serverWorld.GetOrCreateSystem <ServerInitializationSystemGroup>();
            serverSimulationSystemGroup     = serverWorld.GetOrCreateSystem <ServerSimulationSystemGroup>();
        }
#endif
        foreach (var type in systems)
        {
            if (type.GetCustomAttributes(typeof(NotClientServerSystemAttribute), true).Length > 0 ||
                type == typeof(InitializationSystemGroup) ||
                type == typeof(SimulationSystemGroup) ||
                type == typeof(PresentationSystemGroup))
            {
                defaultBootstrap.Add(type);
                continue;
            }
            var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
            if (groups.Length == 0)
            {
                defaultBootstrap.Add(type);
                // Treat the default group as both client and server
                groups = new object[] { new UpdateInGroupAttribute(typeof(ClientAndServerSimulationSystemGroup)) };
            }

            foreach (var grp in groups)
            {
                var group = grp as UpdateInGroupAttribute;
                if (group.GroupType == typeof(ClientAndServerSimulationSystemGroup) || group.GroupType == typeof(SimulationSystemGroup))
                {
                    if (group.GroupType == typeof(SimulationSystemGroup))
                    {
                        defaultBootstrap.Add(type);
                    }
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
                    if (serverWorld != null)
                    {
                        var defaultWorld = World.Active;
                        World.Active = serverWorld;
                        serverSimulationSystemGroup.AddSystemToUpdateList(
                            serverWorld.GetOrCreateSystem(type));
                        World.Active = defaultWorld;
                    }
#endif
#if !UNITY_SERVER
                    if (clientWorld != null)
                    {
                        var defaultWorld = World.Active;
                        for (int i = 0; i < clientSimulationSystemGroup.Length; ++i)
                        {
                            World.Active = clientWorld[i];
                            clientSimulationSystemGroup[i]
                            .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type));
                        }
                        World.Active = defaultWorld;
                    }
#endif
                }
                else if (group.GroupType == typeof(ClientAndServerInitializationSystemGroup) || group.GroupType == typeof(InitializationSystemGroup))
                {
                    if (group.GroupType == typeof(InitializationSystemGroup))
                    {
                        defaultBootstrap.Add(type);
                    }
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
                    if (serverWorld != null)
                    {
                        var defaultWorld = World.Active;
                        World.Active = serverWorld;
                        serverInitializationSystemGroup.AddSystemToUpdateList(
                            serverWorld.GetOrCreateSystem(type));
                        World.Active = defaultWorld;
                    }
#endif
#if !UNITY_SERVER
                    if (clientWorld != null)
                    {
                        var defaultWorld = World.Active;
                        for (int i = 0; i < clientInitializationSystemGroup.Length; ++i)
                        {
                            World.Active = clientWorld[i];
                            clientInitializationSystemGroup[i]
                            .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type));
                        }
                        World.Active = defaultWorld;
                    }
#endif
                }
                else if (group.GroupType == typeof(ServerInitializationSystemGroup))
                {
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
                    if (serverWorld != null)
                    {
                        var defaultWorld = World.Active;
                        World.Active = serverWorld;
                        serverInitializationSystemGroup.AddSystemToUpdateList(
                            serverWorld.GetOrCreateSystem(type));
                        World.Active = defaultWorld;
                    }
#endif
                }
                else if (group.GroupType == typeof(ClientInitializationSystemGroup))
                {
#if !UNITY_SERVER
                    if (clientWorld != null)
                    {
                        var defaultWorld = World.Active;
                        for (int i = 0; i < clientInitializationSystemGroup.Length; ++i)
                        {
                            World.Active = clientWorld[i];
                            clientInitializationSystemGroup[i]
                            .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type));
                        }
                        World.Active = defaultWorld;
                    }
#endif
                }
                else if (group.GroupType == typeof(ServerSimulationSystemGroup))
                {
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
                    if (serverWorld != null)
                    {
                        var defaultWorld = World.Active;
                        World.Active = serverWorld;
                        serverSimulationSystemGroup.AddSystemToUpdateList(
                            serverWorld.GetOrCreateSystem(type));
                        World.Active = defaultWorld;
                    }
#endif
                }
                else if (group.GroupType == typeof(ClientSimulationSystemGroup))
                {
#if !UNITY_SERVER
                    if (clientWorld != null)
                    {
                        var defaultWorld = World.Active;
                        for (int i = 0; i < clientSimulationSystemGroup.Length; ++i)
                        {
                            World.Active = clientWorld[i];
                            clientSimulationSystemGroup[i]
                            .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type));
                        }
                        World.Active = defaultWorld;
                    }
#endif
                }
                else if (group.GroupType == typeof(ClientPresentationSystemGroup) || group.GroupType == typeof(PresentationSystemGroup))
                {
                    if (group.GroupType == typeof(PresentationSystemGroup))
                    {
                        defaultBootstrap.Add(type);
                    }
#if !UNITY_SERVER
                    if (clientWorld != null)
                    {
                        var defaultWorld = World.Active;
                        for (int i = 0; i < clientPresentationSystemGroup.Length; ++i)
                        {
                            World.Active = clientWorld[i];
                            clientPresentationSystemGroup[i]
                            .AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type));
                        }
                        World.Active = defaultWorld;
                    }
#endif
                }
                else
                {
                    var mask = GetTopLevelWorldMask(group.GroupType);
                    if ((mask & WorldType.DefaultWorld) != 0)
                    {
                        defaultBootstrap.Add(type);
                    }
#if !UNITY_SERVER
                    if ((mask & WorldType.ClientWorld) != 0 && clientWorld != null)
                    {
                        var defaultWorld = World.Active;
                        for (int i = 0; i < clientWorld.Length; ++i)
                        {
                            World.Active = clientWorld[i];
                            var groupSys = clientWorld[i].GetOrCreateSystem(group.GroupType) as ComponentSystemGroup;
                            groupSys.AddSystemToUpdateList(clientWorld[i].GetOrCreateSystem(type));
                        }
                        World.Active = defaultWorld;
                    }
#endif
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
                    if ((mask & WorldType.ServerWorld) != 0 && serverWorld != null)
                    {
                        var defaultWorld = World.Active;
                        World.Active = serverWorld;
                        var groupSys = serverWorld.GetOrCreateSystem(group.GroupType) as ComponentSystemGroup;
                        groupSys.AddSystemToUpdateList(serverWorld.GetOrCreateSystem(type));
                        World.Active = defaultWorld;
                    }
#endif
                }
            }
        }
#if !UNITY_CLIENT || UNITY_SERVER || UNITY_EDITOR
        if (serverWorld != null)
        {
            serverInitializationSystemGroup.SortSystemUpdateList();
            serverSimulationSystemGroup.SortSystemUpdateList();
            World.Active.GetOrCreateSystem <TickServerInitializationSystem>().AddSystemToUpdateList(serverInitializationSystemGroup);
            World.Active.GetOrCreateSystem <TickServerSimulationSystem>().AddSystemToUpdateList(serverSimulationSystemGroup);
        }
#endif
#if !UNITY_SERVER
        if (clientWorld != null)
        {
            for (int i = 0; i < clientWorld.Length; ++i)
            {
                clientInitializationSystemGroup[i].SortSystemUpdateList();
                clientSimulationSystemGroup[i].SortSystemUpdateList();
                clientPresentationSystemGroup[i].SortSystemUpdateList();
                World.Active.GetOrCreateSystem <TickClientInitializationSystem>().AddSystemToUpdateList(clientInitializationSystemGroup[i]);
                World.Active.GetOrCreateSystem <TickClientSimulationSystem>().AddSystemToUpdateList(clientSimulationSystemGroup[i]);
                World.Active.GetOrCreateSystem <TickClientPresentationSystem>().AddSystemToUpdateList(clientPresentationSystemGroup[i]);
            }
        }
#endif
        return(defaultBootstrap);
    }
Пример #14
0
 protected override void OnCreateManager()
 {
     barrier = World.GetOrCreateManager <BeginSimulationEntityCommandBufferSystem>();
     serverSimulationSystemGroup = World.GetOrCreateManager <ServerSimulationSystemGroup>();
 }