Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FreezingArcher.Content.GameState"/> class.
 /// </summary>
 /// <param name="name">Name.</param>
 /// <param name="env">Environment.</param>
 /// <param name="messageProvider">Message Manager.</param>
 public GameState(string name, Environment env, MessageProvider messageProvider)
 {
     Name = name;
     Environment = env;
     MessageProxy = new MessageProxy(messageProvider);
     PhysicsManager = new PhysicsManager(messageProvider);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an entity with the specified parameters.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="name">Name.</param>
        /// <param name="messageProvider"></param>
        /// <param name="components">Components.</param>
        /// <param name="systems">Systems.</param>
        public Entity CreateWith(string name, MessageProvider messageProvider, Type[] components = null, Type[] systems = null)
        {
            Entity e = ObjectManager.CreateOrRecycle<Entity>();
            e.Init(name, messageProvider);

            if (components != null)
            {
                foreach (var c in components)
                {
                    if (!e.AddComponent(c))
                    {
                        Logger.Log.AddLogEntry(LogLevel.Error, ModuleName, "Failed to add component {0}!", c.Name);
                    }
                }
            }

            if (systems != null)
            {
                foreach (var s in systems)
                {
                    if (!e.AddSystem(s))
                    {
                        Logger.Log.AddLogEntry(LogLevel.Error, ModuleName, "Failed to add system {0}!", s.Name);
                    }
                }
            }

            return e;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize this component. Within this method all properties may be reseted and reloaded from the attribute
        /// manager.
        /// </summary>
        /// <param name="entity">The entity this component is bounded to.</param>
        /// <param name="messageProvider">The message provider instance for the component.</param>
        public virtual void Init(Entity entity, MessageProvider messageProvider)
        {
            Entity = entity;
            this.messageProvider = messageProvider;
            messageProvider += this;
            // set type based default parameters for fields and properties
            Type t = GetType();
            var fields = t.GetFields().Where(f => !f.IsDefined(typeof(CompilerGeneratedAttribute), false) &&
                !f.Name.StartsWith("Default", StringComparison.InvariantCulture)).ToList();
            var props = t.GetProperties().Where(p => p.CanWrite);

            foreach(var field in fields)
            {
                field.SetValue(this, t.GetField("Default" + field.Name).GetValue(this));
            }

            foreach (var prop in props)
            {
                if (prop.Name != "Entity")
                    prop.SetValue(this, t.GetField("Default" + prop.Name).GetValue(this));
            }

            // set blueprint based default parameters for fields and properties
            // TODO

            // set instance based default parameters for fields and properties
            // TODO
        }
Exemplo n.º 4
0
        public LoadingScreen (Application application, MessageProvider messageProvider, string backgroundPath,
            string name,
            IEnumerable<Tuple<string, GameStateTransition>> from = null,
            IEnumerable<Tuple<string, GameStateTransition>> to = null)
        {
            if (application.Game.AddGameState(name, Content.Environment.Default, from, to))
                LoadingState = application.Game.GetGameState(name);
            else
            {
                Logger.Log.AddLogEntry(LogLevel.Error, "LoadingScreen", "Could not add loading screen game state!");
                return;
            }

            this.application = application;

            ValidMessages = new[] { (int) MessageId.WindowResize };
            messageProvider += this;

            image = new ImagePanel(application.RendererContext.Canvas);
            image.ImageName = backgroundPath;
            updateImage();
            image.BringToFront();

            progressBar = new ProgressBar (image);
            progressBar.IsHorizontal = true;
            progressBar.AutoLabel = false;
            progressBar.Y = application.RendererContext.Canvas.Height - 70;
            progressBar.X = 40 + (image.Width - application.RendererContext.Canvas.Width) / 2;
            progressBar.Height = 30;
            progressBar.Width = application.RendererContext.Canvas.Width - 80;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FreezingArcher.Renderer.Scene.CameraManager"/> class.
 /// </summary>
 /// <param name="messageProvider">The message provider for this camera manager instance.</param>
 /// <param name="name">Name.</param>
 /// <param name="cam">Cam.</param>
 public CameraManager (MessageProvider messageProvider, string name = "firstCam", BaseCamera cam = null)
 {
     CamTree = new Tree<Pair<string, BaseCamera>> (new Pair<string, BaseCamera>("root", null));
     ActiveCameraNode = new Tree<Pair<string, BaseCamera>> (new Pair<string, BaseCamera>(name, cam));
     ValidMessages = new int[] { (int)MessageId.Input };
     messageProvider += this;
 }
Exemplo n.º 6
0
        public override void Init (MessageProvider messageProvider, Entity entity)
        {
            base.Init (messageProvider, entity);

            NeededComponents = new[] { typeof (TransformComponent), typeof (LightComponent), typeof (ItemComponent) };

            onPositionChangedHandler = pos => {
                var light = Entity.GetComponent<LightComponent>().Light;
                if (light != null)
                {
                    light.PointLightPosition = pos + 
                        ((light.Type == FreezingArcher.Renderer.Scene.LightType.SpotLight) ? light.DirectionalLightDirection * 0.19f : 
                            Vector3.Zero);
                }
            };

            onRotationChangedHandler = rot => {
                var light = Entity.GetComponent<LightComponent>().Light;
                if (light != null)
                {
                    light.DirectionalLightDirection = Vector3.Normalize(Vector3.Transform (Vector3.UnitY, rot));        
                }
            };

            internalValidMessages = new[] { (int) MessageId.Update };
            messageProvider += this;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="messageProvider">The message provider instance for this instance.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            internalValidMessages = new[] { (int) MessageId.Input, (int) MessageId.Update };
            messageProvider += this;
        }
Exemplo n.º 8
0
 public CompositorWarpingNode (RendererContext rc, MessageProvider mp)
     : base ("NodeWarping", rc, mp)
 {
     WarpFactor = 0;
     ValidMessages = new [] { (int) MessageId.Update };
     mp += this;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Core.PhysicsManager"/> class.
        /// </summary>
        /// <param name="collisionSystem">Collision system.</param>
        public PhysicsManager(MessageProvider prov, CollisionSystem collisionSystem = CollisionSystem.SweepAndPrune)
        {
            this.collisionSystem = collisionSystem;

            MessageProvider = prov;

            Jitter.Collision.CollisionSystem system;
            switch (collisionSystem)
            {
                case CollisionSystem.Brute:
                    system = new CollisionSystemBrute();
                    break;
                case CollisionSystem.PersistentSweepAndPrune:
                    system = new CollisionSystemPersistentSAP();
                    break;
                default:
                    system = new CollisionSystemSAP();
                    break;
            }

            MessageProvider += this;

            World = new World(system);

            World.CollisionSystem.CollisionDetected += (Jitter.Dynamics.RigidBody body1, Jitter.Dynamics.RigidBody body2,
                Jitter.LinearMath.JVector point1, Jitter.LinearMath.JVector point2, Jitter.LinearMath.JVector normal, float penetration) => 
            {
                if(MessageCreated != null)
                    MessageCreated(new CollisionDetectedMessage(body1, body2));
            };

            Start();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="msgmnr">Msgmnr.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            //Added needed components
            NeededComponents = new[] { typeof(TransformComponent), typeof(ModelComponent) };

            onPositionChangedHandler = (pos) => {
                var model = Entity.GetComponent<ModelComponent>().Model;
                if (model != null)
                    model.Position = pos;
            };

            onRotationChangedHandler = (rot) => {
                var model = Entity.GetComponent<ModelComponent>().Model;
                if (model != null)
                    model.Rotation = rot;
            };

            onScaleChangedHandler = (scale) => {
                var model = Entity.GetComponent<ModelComponent>().Model;
                if (model != null)
                    model.Scaling = scale;
            };

            //internalValidMessages = new[] { (int) MessageId.PositionChanged,
            //    (int) MessageId.RotationChanged, (int) MessageId.ScaleChanged };
            internalValidMessages = new int[0];
            messageProvider += this;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes the <see cref="FreezingArcher.Localization.Localizer"/> class.
 /// </summary>
 public static void Initialize (MessageProvider messageProvider)
 {
     Logger.Log.AddLogEntry (LogLevel.Info, ClassName, "Initializing global localizer instance ...");
     Dictionary<LocaleEnum, LocalizationData> dic = new Dictionary<LocaleEnum, LocalizationData> ();
     dic.Add (LocaleEnum.en_US, new LocalizationData ("Localization/en_US.xml"));
     dic.Add (LocaleEnum.de_DE, new LocalizationData ("Localization/de_DE.xml"));
     Instance = new Localizer (dic, messageProvider);
 }
Exemplo n.º 12
0
        public AudioContext (MessageProvider mpv)
        {
            MessageProvider = mpv;

            SoundDictionary = new Dictionary<MessageId, List<SoundSourceDescription>> ();
            _ValidMessages = new List<int>();

            MessageProvider += this;
        }
Exemplo n.º 13
0
        public FenFireAI (Entity entity, GameState state)
        {
            gameState = state;
            this.entity = entity;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Exemplo n.º 14
0
        public CaligoAI (Entity entity, GameState state, CompositorWarpingNode warpingNode)
        {
            this.entity = entity;
            this.state = state;
            this.warpingNode = warpingNode;
            this.AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            this.Provider += this;
        }
Exemplo n.º 15
0
        public RoachesAI (RoachGroup roachGroup, Entity entity, GameState state)
        {
            this.roachGroup = roachGroup;
            this.entity = entity;
            this.state = state;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Exemplo n.º 16
0
        public ViridionAI (Entity entity, GameState state, CompositorColorCorrectionNode colorCorrectionNode)
        {
            this.colorCorrectionNode = colorCorrectionNode;
            this.entity = entity;
            gameState = state;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Exemplo n.º 17
0
        public ScobisAI (ScobisSmokeParticleEmitter smokeParticleEmitter, Entity entity, GameState state)
        {
            this.smokeParticleEmitter = smokeParticleEmitter;
            this.entity = entity;
            this.state = state;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Localization.Localizer"/> class.
        /// </summary>
        /// <param name="locales">Locales.</param>
        /// <param name="messageProvider">Message manager instance.</param>
        /// <param name="initialLocale">Initial locale.</param>
        public Localizer (Dictionary<LocaleEnum, LocalizationData> locales, MessageProvider messageProvider,
            LocaleEnum initialLocale = LocaleEnum.en_US)
        {
            Logger.Log.AddLogEntry (LogLevel.Fine, ClassName, "Creating localizer instance with initial locale '{0}'",
                initialLocale.ToString ());
            Locales = locales;
            CurrentLocale = initialLocale;

            if (messageProvider != null)
                messageProvider += this;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="messageProvider">The message provider for this system instance.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            NeededComponents = new[] { typeof(ItemComponent), typeof(ModelComponent),
                typeof (TransformComponent), typeof (PhysicsComponent) };

            internalValidMessages = new[] { (int) MessageId.ItemUse, (int) MessageId.ItemDropped,
                (int) MessageId.ItemCollected };
            messageProvider += this;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="messageProvider">The message provider for this system.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            NeededComponents = new[] { typeof(TransformComponent), typeof(PhysicsComponent) };



            internalValidMessages = new[] { (int) MessageId.Update };
            messageProvider += this;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="messageProvider">The message provider for this system instance.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            //Added needed components
            NeededComponents = new[] { typeof(PhysicsComponent), typeof(TransformComponent) };

            internalValidMessages = new[] { (int) MessageId.Movement, (int) MessageId.MoveStraight,
                (int) MessageId.MoveSidewards, (int)MessageId.MoveVertical, (int) MessageId.Update };
            messageProvider += this;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="messageProvider">Msgmnr.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            DoSmoothing = true;
            SmoothingFactor = 7;

            NeededComponents = new[] { typeof(TransformComponent) };

            internalValidMessages = new[] { (int) MessageId.Input };
            messageProvider += this;
        }
Exemplo n.º 23
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="messageProvider">The message provider for this instance.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            //Added needed components
            NeededComponents = new[] { typeof(TransformComponent), typeof(SkyboxComponent) };

            //Needs more Initializing?
            //Scene does this for me, so no!
            internalValidMessages = new int[0];
            messageProvider += this;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Content.Game"/> class.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="objmnr">Object Manager.</param>
        /// <param name="messageProvider">Message Manager.</param>
        public Game (string name, ObjectManager objmnr, MessageProvider messageProvider, CompositorNodeScene scenenode, RendererContext rendererContext)
        {
            Logger.Log.AddLogEntry (LogLevel.Info, ClassName, "Creating new game '{0}'", name);
            Name = name;
            MessageProvider = messageProvider;
            RendererContext = rendererContext;

            SceneNode = scenenode;

            GameStateGraph = objmnr.CreateOrRecycle<DirectedWeightedGraph<GameState, GameStateTransition>>();
            GameStateGraph.Init();
        }
Exemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FreezingArcher.Input.InputManager"/> class.
 /// </summary>
 internal InputManager (MessageProvider messageProvider, FreezingArcher.Core.Application app)
 {
     Logger.Log.AddLogEntry (LogLevel.Fine, ClassName, "Creating new input manager");
     Keys = new List<KeyboardInput> ();
     Mouse = new List<MouseInput> ();
     MouseMovement = Vector2.Zero;
     MouseScroll = Vector2.Zero;
     OldMousePosition = Vector2.Zero;
     KeyRegistry.Instance = new KeyRegistry (messageProvider);
     Stopwatch = new Stopwatch();
     messageProvider += this;
     ApplicationInstance = app;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Initialize this system. This may be used as a constructor replacement.
        /// </summary>
        /// <param name="msgmnr">Msgmnr.</param>
        /// <param name="entity">Entity.</param>
        public override void Init(MessageProvider messageProvider, Entity entity)
        {
            base.Init(messageProvider, entity);

            //Added needed components
            NeededComponents = new[] { typeof(TransformComponent), typeof(ParticleComponent) };

            onPositionChangedHandler = (pos) => {
                var model = Entity.GetComponent<ParticleComponent>().Emitter;
                if (model != null)
                    model.SpawnPosition = pos;
            };

            //internalValidMessages = new[] { (int) MessageId.PositionChanged,
            //    (int) MessageId.RotationChanged, (int) MessageId.ScaleChanged };
            internalValidMessages = new int[]{(int)MessageId.Update};
            messageProvider += this;
        }
Exemplo n.º 27
0
        public EndScreen (Application application, RendererContext rc, IEnumerable<Tuple<string, GameStateTransition>> from = null)
        {
            Renderer = rc;

            Application = application;

            if (!Application.Game.AddGameState ("endscreen_state", FreezingArcher.Content.Environment.Default, from))
            {
                Logger.Log.AddLogEntry (LogLevel.Error, "EndScreen", "Could not add Endscreen-State!");
            }

            State = Application.Game.GetGameState ("endscreen_state");
            MessageProvider = State.MessageProxy;
            BackgroundTexture = null;
            ValidMessages = new int [] { (int) MessageId.GameEnded, (int) MessageId.GameEndedDied,
                (int) MessageId.WindowResize, (int) MessageId.UpdateLocale };
            MessageProvider += this;
        }
Exemplo n.º 28
0
        public Inventory(MessageProvider messageProvider, GameState state, Entity player, Vector2i size, byte barSize)
        {
            Size = size;
            messageProvider += this;
            this.messageProvider = messageProvider;
            this.player = player;
            gameState = state;
            storage = new int?[Size.X, Size.Y];

            if (barSize < 1 || barSize > 10)
            {
                Logger.Log.AddLogEntry(LogLevel.Error, "Inventory",
                    "Inventory bar size must be between 1 and 10 but is {0}!", barSize);
                return;
            }

            inventoryBar = new int?[barSize];
        }
Exemplo n.º 29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Configuration.ConfigFile"/> class.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="defaults">Defaults values.</param>
        /// <param name="messageProvider">Message manager.</param>
        public ConfigFile (string name, Dictionary<string, Section> defaults, MessageProvider messageProvider)
        {
            Name = name;
            Logger.Log.AddLogEntry (LogLevel.Info, ClassName, "Reading {0}.conf", Name);
            messageProvider += this;
            IniConfig = new IniConfig (name + ".conf");
            Defaults = defaults;
            Overrides = new Dictionary<string, Section> ();

            // write default config to file if non existent
            if (!File.Exists (Name + ".conf"))
            {
                foreach (var section in Defaults)
                {
                    foreach (var value in section.Value)
                    {
                        switch (value.Value.Type)
                        {
                        case ValueType.Boolean:
                            IniConfig.SetValue (section.Key, value.Key, value.Value.Boolean);
                            break;
                        case ValueType.Integer:
                            IniConfig.SetValue (section.Key, value.Key, value.Value.Integer);
                            break;
                        case ValueType.Double:
                            IniConfig.SetValue (section.Key, value.Key, value.Value.Double);
                            break;
                        case ValueType.String:
                            IniConfig.SetValue (section.Key, value.Key, value.Value.String);
                            break;
                        case ValueType.Bytes:
                            IniConfig.SetValue (section.Key, value.Key, value.Value.Bytes);
                            break;
                        default:
                            Logger.Log.AddLogEntry (LogLevel.Severe, ClassName,
                                "The type '{0}' of the given value is not supported! This type shouldn't even exist!",
                                value.Value.Type.ToString ());
                            break;
                        }
                    }
                }
                Save ();
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Game.ECSTest"/> class.
        /// </summary>
        /// <param name="messageProvider">The message provider for this instance.</param>
        /// <param name="scene">Scene.</param>
        public ECSTest (MessageProvider messageProvider, CoreScene scene)
        {
            Entity player = EntityFactory.Instance.CreateWith ("player", messageProvider, systems: new[] {
                typeof (MovementSystem),
                typeof (KeyboardControllerSystem),
                typeof (MouseControllerSystem)
            });

            scene.CameraManager.AddCamera (new BaseCamera (player, messageProvider), "player");

            Entity skybox = EntityFactory.Instance.CreateWith ("skybox", messageProvider, systems: new[] { typeof(ModelSystem) });
            ModelSceneObject skyboxModel = new ModelSceneObject ("lib/Renderer/TestGraphics/Skybox/skybox.xml");
            skybox.GetComponent<TransformComponent>().Scale = 100.0f * Vector3.One;
            scene.AddObject (skyboxModel);
            skyboxModel.WaitTillInitialized ();
            skyboxModel.Model.EnableDepthTest = false;
            skyboxModel.Model.EnableLighting = false;
            skybox.GetComponent<ModelComponent> ().Model = skyboxModel;
            // as we do not update skybox position the player is able to leave the skybox ... i dont wanna fix it cause its just a test...
        }