예제 #1
0
 /// <summary>
 /// Awake is called when the script instance is being loaded.
 /// </summary>
 void Awake()
 {
     if (PhysicsConfig == null)
     {
         PhysicsConfig = Config.Get <PhysicsConfig>();
     }
 }
    public void ReplacePhysicsConfig(PhysicsConfig newValue)
    {
        var index     = GameComponentsLookup.PhysicsConfig;
        var component = (PhysicsConfigComponent)CreateComponent(index, typeof(PhysicsConfigComponent));

        component.Value = newValue;
        ReplaceComponent(index, component);
    }
예제 #3
0
 /// <summary>
 /// Start is called on the frame when a script is enabled just before
 /// any of the Update methods is called the first time.
 /// </summary>
 void Start()
 {
     pConfig = GameObject.FindObjectOfType <PhysicsConfig>();
     if (!pConfig)
     {
         pConfig = (PhysicsConfig) new GameObject().AddComponent(typeof(PhysicsConfig));
         pConfig.gameObject.name = "Physics Config";
         Debug.LogWarning("PhysicsConfig not found on the scene! Using default config.");
     }
 }
예제 #4
0
        public MainManager(int simulatorID, RedisNetworkingService redisNetworkingService, SimulatorGameTimeService gameTimeService, SimulatorConfig simulatorConfig, PhysicsConfig physicsConfig)
        {
            _simulatorID       = simulatorID;
            _redisServer       = redisNetworkingService.RedisServer;
            _networkingService = redisNetworkingService;
            _gameTimeService   = gameTimeService;
            _simulatorConfig   = simulatorConfig;
            _physicsConfig     = physicsConfig;

            Utilities.NextUnique();//Force the static to initialize now
        }
예제 #5
0
 /// <summary>
 /// Start is called on the frame when a script is enabled just before
 /// any of the Update methods is called the first time.
 /// </summary>
 void Start()
 {
     inputIcon.enabled = false;
     character         = GetComponent <CharacterController2D>();
     pConfig           = GameObject.FindObjectOfType <PhysicsConfig>();
     if (!pConfig)
     {
         pConfig = (PhysicsConfig) new GameObject().AddComponent(typeof(PhysicsConfig));
         pConfig.gameObject.name = "Physics Config";
         Debug.LogWarning("PhysicsConfig not found on the scene! Using default config.");
     }
 }
    public GameEntity SetPhysicsConfig(PhysicsConfig newValue)
    {
        if (hasPhysicsConfig)
        {
            throw new Entitas.EntitasException("Could not set PhysicsConfig!\n" + this + " already has an entity with PhysicsConfigComponent!",
                                               "You should check if the context already has a physicsConfigEntity before setting it or use context.ReplacePhysicsConfig().");
        }
        var entity = CreateEntity();

        entity.AddPhysicsConfig(newValue);
        return(entity);
    }
예제 #7
0
        //First argument is simulatorID (int), all subsequent arguments follow the format in _parseSimulationDatum
        public static void Main(string[] simulationData)
        {
            try
            {
                ConsoleManager.WriteLine("Starting simulator instance...", ConsoleMessageType.Debug);

                Logger.Initialize();

                TimeKeeper.Initialize();
                _simulatorConfig = new SimulatorConfig();
                _physicsConfig   = new PhysicsConfig();
                RedisServer            redisServer            = new RedisServer(Logger.LogRedisError, Logger.LogRedisInfo, new RedisConfig().Address);
                RedisNetworkingService redisNetworkingService = new RedisNetworkingService(_simulatorConfig,
                                                                                           redisServer);
                int simulatorID = int.Parse(simulationData[0]);

                List <string> dataArray = new List <string>();
                for (int i = 1; i < simulationData.Length; i++)
                {
                    dataArray.Add(simulationData[i]);
                }


                _mainManager = new MainManager(simulatorID, redisNetworkingService,
                                               new SimulatorGameTimeService(), _simulatorConfig, _physicsConfig);

                //IDs are parsed, then each ID is used to subscribe to a redis channel, which the server uses to communicate data about each system
                foreach (string s in dataArray)
                {
                    if (s == "")
                    {
                        continue;
                    }

                    var data = _parseSimulationDatum(s);
                    _mainManager.StartSimulatingArea(data.Item2, data.Item1);
                }


                _mainManager.ConnectToServer();

                Run();
            }

            catch (Exception e)
            {
                ConsoleManager.WriteLine("Exception in simulator", ConsoleMessageType.Error);
                ConsoleManager.WriteLine(e.ToString(), ConsoleMessageType.Error);
                ConsoleManager.WriteLine(e.Message, ConsoleMessageType.Error);
                Run();
            }
        }
 // Start is called before the first frame update
 public virtual void Start()
 {
     myCollider = GetComponent <BoxCollider2D>();
     CalculateSpacing();
     pConfig = GameObject.FindObjectOfType <PhysicsConfig>();
     if (!pConfig)
     {
         pConfig = (PhysicsConfig) new GameObject().AddComponent(typeof(PhysicsConfig));
         pConfig.gameObject.name = "Physics Config";
         Debug.LogWarning("PhysicsConfig not found on the scene! Using default config.");
     }
     collisionMask = pConfig.characterCollisionMask;
 }
    public void ReplacePhysicsConfig(PhysicsConfig newValue)
    {
        var entity = physicsConfigEntity;

        if (entity == null)
        {
            entity = SetPhysicsConfig(newValue);
        }
        else
        {
            entity.ReplacePhysicsConfig(newValue);
        }
    }
예제 #10
0
        // Use this for initialization
        protected override void OnInitialize(ModuleConfiguration configuration)
        {
            Active = false;

            PhysicsConfig physicsConfig = configuration as PhysicsConfig;

            AirDrag      = physicsConfig.AirDrag;
            GravityScale = physicsConfig.GravityScale;
            Bounciness   = physicsConfig.Bounciness;
            Friction     = physicsConfig.Friction;

            EnableOnCollisions = physicsConfig.EnableOnCollisions;

            PhysicsBody = FindPhysicsBody();

            InitializeEntitySpace();
        }
예제 #11
0
 public static PlanetStateManager BuildPlanetStateManager(ClientManager clientManager, INetworkingService _networkingService, PhysicsConfig _physicsConfig)
 {
     return(DrawlessStateBuilder.BuildPlanetStateManager(null, new LidgrenMessenger(clientManager),
                                                         _networkingService, _physicsConfig));
 }
예제 #12
0
 public static PlanetStateManager BuildPlanetStateManager(int areaID, RedisServer _redisServer, INetworkingService _networkingService, PhysicsConfig _physicsConfig)
 {
     return(DrawlessStateBuilder.BuildPlanetStateManager(areaID, new RedisMessenger(_redisServer, areaID),
                                                         _networkingService, _physicsConfig));
 }
예제 #13
0
        public static PlanetStateManager BuildPlanetStateManager(int?areaID, IMessenger messenger, INetworkingService _networkingService, PhysicsConfig _physicsConfig)
        {
            //Null references, unused by the Simulator
            TextureManager   textureManager   = null;
            SpriteBatch      spriteBatch      = null;
            ParticleManager  particleManager  = null;
            Texture2D        warpholeTexture  = null;
            SelectionManager selectionManager = null;


            MessageService_ToServer  messageService          = new MessageService_ToServer(messenger);
            SimulationManager        simulationManager       = new SimulationManager();
            CollisionManager         collisionManager        = new CollisionManager(messageService);
            PlayerShipManager        playerShipManager       = new PlayerShipManager(messageService);
            IClientPlayerInfoManager clientPlayerInfoManager = new PlayablePlayerInfoManager(playerShipManager);
            TargetingService         targetingService        = new TargetingService();
            TeamManager       teamManager       = new TeamManager(targetingService);
            PhysicsManager    physicsManager    = new PhysicsManager();
            ProjectileManager projectileManager = new ProjectileManager(particleManager, physicsManager.World, spriteBatch, targetingService, simulationManager, messageService, collisionManager);
            ClientShipManager clientShipManager = new ClientShipManager(particleManager, playerShipManager, spriteBatch, textureManager, simulationManager, targetingService, teamManager, projectileManager, messageService, clientPlayerInfoManager, true);

            clientShipManager.SendPositionUpdates = true;
            StructureFactoryManager structureFactoryManager = new StructureFactoryManager(messageService, physicsManager.World, projectileManager, targetingService, teamManager, null, clientShipManager, null, true);
            WarpHoleManager         warpholeManager         = new WarpHoleManager(messageService, particleManager, physicsManager, clientShipManager, warpholeTexture);

            FloatyAreaObjectManager floatyAreaObjectManager = new FloatyAreaObjectManager(physicsManager.World, textureManager, messageService, spriteBatch, particleManager);

            var mhi = areaID == null ? new MessageHandlerID() : new MessageHandlerID((int)areaID);

            PlanetStateManager planetStateManager = new PlanetStateManager(
                mhi,
                clientPlayerInfoManager,
                null,
                collisionManager,
                physicsManager,
                playerShipManager,
                projectileManager,
                clientShipManager,
                structureFactoryManager,
                warpholeManager,
                _networkingService,
                selectionManager,
                simulationManager,
                targetingService,
                teamManager,
                GameStateType.Planet,
                floatyAreaObjectManager, messageService,
                _physicsConfig.PlanetTileWidth, _physicsConfig.PlanetTileHeight);

            planetStateManager.SetAreaId(areaID);

            return(planetStateManager);
        }
예제 #14
0
        DrawablePlanetStateManager _buildPlanetStateManager(GlobalGameUISingleton globalGameUiSingleton, CameraService cameraService, TextureManager textureManager, ParticleManager particleManager, TextDrawingService textDrawingService, MessageService_ToServer messageService, LidgrenNetworkingService networkingService)
        {
            CollisionManager        instance_collisionManager;
            ParticleManager         instance_particleManager = null;
            SimulationManager       instance_simulationManager;
            TargetingService        instance_targetingService;
            TeamManager             instance_teamManager;
            UIConversionService     instance_uiConversionService;
            ClientShipManager       instance_clientShipManager;
            PhysicsManager          instance_physicsManager;
            ProjectileManager       instance_projectileManager;
            StructureFactoryManager instance_structureFactoryManager;
            WarpHoleManager         instance_warpholeManager;
            SelectionManager        instance_selectionManager;
            FloatyAreaObjectManager instance_floatyAreaObjectManager;



            instance_collisionManager = new CollisionManager(messageService);
            if (_loadGraphics)
            {
                instance_particleManager = new ParticleManager(_graphics, _spriteBatch, Content, textureManager);
            }

            instance_simulationManager = new SimulationManager();
            instance_targetingService  = new TargetingService();
            instance_teamManager       = new TeamManager(instance_targetingService);
            PlayerShipManager        instance_playerShipManager       = new PlayerShipManager(messageService);
            IClientPlayerInfoManager instance_clientPlayerInfoManager = new PlayablePlayerInfoManager(instance_playerShipManager);

            instance_uiConversionService     = new UIConversionService(cameraService, instance_playerShipManager, _spriteBatch);
            instance_physicsManager          = new PhysicsManager();
            instance_projectileManager       = new ProjectileManager(instance_particleManager, instance_physicsManager.World, _spriteBatch, instance_targetingService, instance_simulationManager, messageService, instance_collisionManager);
            instance_clientShipManager       = new ClientShipManager(instance_particleManager, instance_playerShipManager, _spriteBatch, textureManager, instance_simulationManager, instance_targetingService, instance_teamManager, instance_projectileManager, messageService, instance_clientPlayerInfoManager, false);
            instance_structureFactoryManager = new StructureFactoryManager(messageService, instance_physicsManager.World, instance_projectileManager, instance_targetingService, instance_teamManager, textureManager, instance_clientShipManager, _spriteBatch, false);
            instance_warpholeManager         = new WarpHoleManager(messageService, instance_particleManager, instance_physicsManager, instance_clientShipManager, _loadGraphics?textureManager.Warphole:null);
            instance_selectionManager        = new SelectionManager(textDrawingService, _spriteBatch, instance_clientShipManager, messageService, instance_physicsManager, instance_playerShipManager, instance_targetingService, instance_uiConversionService);
            instance_floatyAreaObjectManager = new FloatyAreaObjectManager(instance_physicsManager.World, textureManager, messageService, _spriteBatch, particleManager);

            PhysicsConfig physicsConfig = new PhysicsConfig();

            return(new DrawablePlanetStateManager(
                       _spriteBatch,
                       instance_clientPlayerInfoManager,
                       instance_collisionManager,
                       globalGameUiSingleton,
                       instance_particleManager,
                       instance_physicsManager,
                       instance_playerShipManager,
                       instance_projectileManager,
                       instance_clientShipManager,
                       instance_structureFactoryManager,
                       textureManager,
                       networkingService,
                       instance_selectionManager,
                       instance_simulationManager,
                       instance_targetingService,
                       instance_teamManager,
                       GameStateType.Planet,
                       instance_uiConversionService,
                       instance_warpholeManager,
                       Window,
                       instance_floatyAreaObjectManager,
                       messageService,
                       physicsConfig.PlanetTileWidth,
                       physicsConfig.PlanetTileHeight));
        }
예제 #15
0
        private void LoadConfig()
        {
            _netConfig = Config.Get<NetConfig>("network");
            _phyConfig = Config.Get<PhysicsConfig>("physics");
            _scriptConfig = Config.Get<ScriptConfig>("script");

            PathHelpers.SetBasePath(_scriptConfig.ScriptPath);

            _bifrost = new BifrostServer(_netConfig.Port, _netConfig.MaxConnections);
            RPCManager.SetConnection(_bifrost);
            AddInternalSystem(_bifrost, 0);
            PacketFactory.AddCallback<AckStatePacket>(OnAckState);
            PacketFactory.AddCallback<ClientStatePacket>(OnClientState);

            PlayerSystem ps = new PlayerSystem();
            AddEntitySystem(ps);
        }