Beispiel #1
0
        public SpriteBatch()
        {
            IRenderSystemProvider renderSystem = Engine.Services.GetService <IRenderSystemProvider>();

            _renderer = renderSystem.Renderer;

            _indexBuffer = new IndexBuffer(IndexFormat.SixteenBits, MaxBatchSize * 6, ResourceUsage.Static);

            _vertices     = new VertexPositionColorTexture[MaxBatchSize * 4];
            _vertexBuffer = new VertexBuffer(VertexPositionColorTexture.VertexDeclaration, MaxBatchSize * 4, ResourceUsage.Dynamic);
            _spriteVbPos  = 0;

            _spriteEffect = renderSystem.DefaultContent.Load <Effect>("SpriteEffect.tebo");
            _matrixParam  = _spriteEffect.Parameters["SpriteTransform"];

            _textureComparer     = new TextureComparer(this);
            _frontToBackComparer = new OrthoComparer(this, true);
            _backToFrontComparer = new OrthoComparer(this, false);

            _spriteQueue      = new Sprite[MaxBatchSize];
            _spriteQueueCount = 0;
            _inBeginEnd       = false;
            _sortMode         = SpriteSortMode.Deferred;

            CreateIndexData();
        }
Beispiel #2
0
        /**
         * @brief Create a variable according to type and value
         *
         * @param _type the string of the type
         * @param _value the string value
         *
         * @result the variable
         * */
        public static IEffectParameter CreateVariable(string _type, string _value)
        {
            IEffectParameter newVariable = null;

            if (_type == typeof(CatMatrix).ToString())
            {
                newVariable = new CatMatrix();
            }
            else if (_type == typeof(CatFloat).ToString())
            {
                newVariable = new CatFloat();
            }
            else if (_type == typeof(CatTexture).ToString())
            {
                newVariable = new CatTexture();
            }
            else if (_type == typeof(CatVector4).ToString())
            {
                newVariable = new CatVector4();
            }
            else if (_type == typeof(CatColor).ToString())
            {
                newVariable = new CatColor();
            }
            else
            {
                Debug.Assert(false, "No matching type found. type=" + _type + " value=" + _value);
            }
            if (newVariable != null && _value != null && _value != "")
            {
                newVariable.FromString(_value);
            }

            return(newVariable);
        }
        /**
         * @brief Create a material according to _node and corresponding template in the list
         *
         * @param _node xml node
         *
         * @result the material
         * */
        public CatMaterial CreateMaterialInstanceByXml(XmlNode _node)
        {
            // get name of materialTemplate
            XmlElement node = (XmlElement)_node;

            if (node == null)
            {
                return(null);
            }
            string name = node.GetAttribute("name");

            if (m_materialTemplates != null && m_materialTemplates.ContainsKey(name))
            {
                // fetch the material prototype
                // TODO: set name in constructor
                CatMaterial newMaterial = m_materialTemplates[name].GetMaterialPrototype().Clone();
                //newMaterial.m_name = name;
                // read and set parameters
                foreach (XmlNode child in node.ChildNodes)
                {
                    XmlElement       eleChild   = (XmlElement)child;
                    string           childName  = eleChild.GetAttribute("name");
                    string           childType  = eleChild.GetAttribute("type");
                    string           childValue = eleChild.GetAttribute("value");
                    IEffectParameter parameter  = CatMaterial.CreateVariable(childType, childValue);
                    if (parameter != null)
                    {
                        newMaterial.SetParameter(childName, parameter);
                    }
                }
                return(newMaterial);
            }
            Debug.Assert(false, "Cannot find material template name: " + name);
            return(null);
        }
 public MaterialEngineParameter(IEffectParameter parameter, String name, bool isSemantic, EngineValue value)
 {
     _effectParameter = parameter;
     _isSemantic      = isSemantic;
     _name            = name;
     _engineValue     = value;
 }
 public MaterialEngineParameter(MaterialEngineParameter engineParam, String name, IEffectParameter replacement)
 {
     _effectParameter = replacement;
     _isSemantic      = engineParam.IsSemantic;
     _engineValue     = engineParam.EngineValue;
     _name            = name;
 }
 public MaterialEngineParameter(MaterialEngineParameter engineParam)
 {
     _effectParameter = engineParam.EffectParameter;
     _isSemantic      = engineParam.IsSemantic;
     _engineValue     = engineParam.EngineValue;
     _name            = engineParam.Name;
 }
Beispiel #7
0
        public void SetParameter(String paramName, bool isSemantic, Color value)
        {
            if (IsValid)
            {
                IEffectParameter param = null;

                if (isSemantic)
                {
                    param = _effect.Parameters.GetParameterBySemantic(paramName);
                }
                else
                {
                    param = _effect.Parameters[paramName];
                }

                if (param == null)
                {
                    return;
                }

                Vector4 v = value.ToVector4();

                param.SetValue(v);
                _cachedParameters[paramName] = new MaterialParameter(param, paramName, isSemantic, v);
            }
            else
            {
                throw new ArgumentNullException("Material does not have a valid effect loaded, cannot set parameter. Call LoadEffect() first.");
            }
        }
Beispiel #8
0
        public void SetEngineParameter(String paramName, bool isSemantic, EngineValue engineValue)
        {
            if (IsValid)
            {
                IEffectParameter param = null;

                if (isSemantic)
                {
                    param = _effect.Parameters.GetParameterBySemantic(paramName);
                }
                else
                {
                    param = _effect.Parameters[paramName];
                }

                //Doesn't exist, don't create an entry
                if (param == null)
                {
                    return;
                }
                MaterialEngineParameter engineParam = new MaterialEngineParameter(param, paramName, isSemantic, engineValue);
                _cachedEngineParameters[paramName] = engineParam;
            }
            else
            {
                throw new ArgumentNullException("Material does not have a valid effect loaded, cannot set engine parameter. Call LoadEffect() first.");
            }
        }
Beispiel #9
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            IRoom      room       = parameter.Target as IRoom;
            DoorChange doorChange = DoorChange.NoChange;

            if (room != null)
            {
                if (GlobalReference.GlobalValues.GameDateTime.InGameDateTime.DayOfWeek == DayOfWeek.Saturday && //Death
                    GlobalReference.GlobalValues.GameDateTime.InGameDateTime.Hour > 12)    //night
                {
                    if (room.Down == null)
                    {
                        doorChange = DoorChange.Open;
                    }
                }
                else
                {
                    if (room.Down != null)
                    {
                        doorChange = DoorChange.Close;
                    }
                }
            }

            switch (doorChange)
            {
            case DoorChange.Open:
                OpenDoor(room);
                break;

            case DoorChange.Close:
                CloseDoor(room);
                break;
            }
        }
Beispiel #10
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            IRoom room = GlobalReference.GlobalValues.World.Zones[parameter.RoomId.Zone].Rooms[parameter.RoomId.Id];

            GlobalReference.GlobalValues.Notify.Room(parameter.Performer, parameter.Target, room, parameter.Message);

            if (Sound != null)
            {
                string serializeSounds;

                if (Sound.RandomSounds.Count > 1)
                {
                    //only pick one of the sounds to play, but we need to make a copy of it to serialize
                    ISound localSound = new Sound();
                    localSound.Loop      = Sound.Loop;
                    localSound.SoundName = Sound.RandomSounds[GlobalReference.GlobalValues.Random.Next(Sound.RandomSounds.Count)];
                    serializeSounds      = GlobalReference.GlobalValues.Serialization.Serialize(new List <ISound>()
                    {
                        localSound
                    });
                }
                else
                {
                    serializeSounds = GlobalReference.GlobalValues.Serialization.Serialize(new List <ISound>()
                    {
                        Sound
                    });
                }

                GlobalReference.GlobalValues.Notify.Room(null, null, room, new TranslationMessage(serializeSounds, TagType.Sound));
            }
        }
Beispiel #11
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            IBaseObject container = null;
            IItem       statue    = null;

            if (parameter.Container != null)
            {
                container = parameter.Container as IBaseObject;
            }

            statue = parameter.Item;

            if (container == null ||
                statue == null)
            {
                return;
            }

            if (container.Zone == Chest.Zone && container.Id == Chest.Id &&
                statue.Zone == Statue.Zone && statue.Id == Statue.Id)
            {
                IRoom room = parameter.ObjectRoom;

                CloseIfMatched(room.North?.Door, room);
                CloseIfMatched(room.East?.Door, room);
                CloseIfMatched(room.South?.Door, room);
                CloseIfMatched(room.West?.Door, room);
            }
        }
Beispiel #12
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            IMobileObject mob = parameter.Target as IMobileObject;

            if (mob != null)
            {
                if (parameter.Message != null)
                {
                    GlobalReference.GlobalValues.Notify.Mob(mob, parameter.Message);
                }
                else
                {
                    GlobalReference.GlobalValues.Notify.Mob(parameter.Performer, parameter.Target, mob, parameter.TargetMessage);
                }

                mob.TakeDamage(parameter.Damage.Dice.RollDice(), parameter.Damage, null);

                if (Sound != null)
                {
                    string serializeSounds = GlobalReference.GlobalValues.Serialization.Serialize(new List <ISound>()
                    {
                        Sound
                    });
                    GlobalReference.GlobalValues.Notify.Mob(mob, new TranslationMessage(serializeSounds, TagType.Sound));
                }
            }
        }
Beispiel #13
0
        private UserControl CreateMaterialPropertyWidget(IEffectParameter _parameter)
        {
            UserControl property = null;

            if (_parameter.GetType().ToString() == typeof(CatFloat).ToString())
            {
                property        = new NumericWidget();
                property.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
                ((NumericWidget)property).SetObserve((CatFloat)(_parameter));
            }
            else if (_parameter.GetType().ToString() == typeof(CatTexture).ToString())
            {
                property        = new TextureWidget();
                property.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
                ((TextureWidget)property).SetObserve((CatTexture)(_parameter));
            }
            else if (_parameter.GetType().ToString() == typeof(CatVector4).ToString())
            {
                property        = new VectorWidget();
                property.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
                ((VectorWidget)property).SetObserve((CatVector4)(_parameter));
            }
            else if (_parameter.GetType().ToString() == typeof(CatColor).ToString())
            {
                property        = new ColorWidget();
                property.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
                ((ColorWidget)property).SetObserve((CatColor)(_parameter));
            }
            // TODO: more here

            return(property);
        }
Beispiel #14
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            if (parameter.ObjectRoom != null)
            {
                IRoom room      = GlobalReference.GlobalValues.World.Zones[parameter.RoomId.Zone].Rooms[parameter.RoomId.Id];
                IDoor door      = null;
                IRoom otherRoom = null;
                IDoor otherDoor = null;

                switch (parameter.Direction)
                {
                case Direction.North:
                    door      = room.North.Door;
                    otherRoom = GlobalReference.GlobalValues.World.Zones[room.North.Zone].Rooms[room.North.Room];
                    otherDoor = otherRoom.South.Door;
                    break;

                case Direction.East:
                    door      = room.East.Door;
                    otherRoom = GlobalReference.GlobalValues.World.Zones[room.East.Zone].Rooms[room.East.Room];
                    otherDoor = otherRoom.West.Door;
                    break;

                case Direction.South:
                    door      = room.South.Door;
                    otherRoom = GlobalReference.GlobalValues.World.Zones[room.South.Zone].Rooms[room.South.Room];
                    otherDoor = otherRoom.North.Door;
                    break;

                case Direction.West:
                    door      = room.West.Door;
                    otherRoom = GlobalReference.GlobalValues.World.Zones[room.West.Zone].Rooms[room.West.Room];
                    otherDoor = otherRoom.East.Door;
                    break;

                case Direction.Up:
                    door      = room.Up.Door;
                    otherRoom = GlobalReference.GlobalValues.World.Zones[room.Up.Zone].Rooms[room.Up.Room];
                    otherDoor = otherRoom.Down.Door;
                    break;

                case Direction.Down:
                    door      = room.Down.Door;
                    otherRoom = GlobalReference.GlobalValues.World.Zones[room.Down.Zone].Rooms[room.Down.Room];
                    otherDoor = otherRoom.Up.Door;
                    break;
                }

                if (door != null)
                {
                    door.Opened = true;
                }

                if (otherDoor != null)
                {
                    otherDoor.Opened = true;
                }
            }
        }
Beispiel #15
0
        public void Setup()
        {
            Mock <INonPlayerCharacter> mockPerformerNpc = new Mock <INonPlayerCharacter>();
            Mock <IPlayerCharacter>    mockPerformerPc  = new Mock <IPlayerCharacter>();
            Mock <IWorld> world = new Mock <IWorld>();
            Mock <IZone>  zone  = new Mock <IZone>();

            room     = new Mock <IRoom>();
            room2    = new Mock <IRoom>();
            mockNpc  = new Mock <INonPlayerCharacter>();
            mockPc   = new Mock <IPlayerCharacter>();
            mockNpc2 = new Mock <INonPlayerCharacter>();
            mockPc2  = new Mock <IPlayerCharacter>();
            notify   = new Mock <INotify>();
            Dictionary <int, IZone> zoneDict = new Dictionary <int, IZone>();
            Dictionary <int, IRoom> roomDict = new Dictionary <int, IRoom>();

            lNpc  = new List <INonPlayerCharacter>();
            lPc   = new List <IPlayerCharacter>();
            lNpc2 = new List <INonPlayerCharacter>();
            lPc2  = new List <IPlayerCharacter>();

            zoneDict.Add(11, zone.Object);
            roomDict.Add(1, room.Object);
            roomDict.Add(11, room2.Object);

            room.Setup(e => e.Zone).Returns(11);
            room.Setup(e => e.Id).Returns(1);
            room.Setup(e => e.NonPlayerCharacters).Returns(lNpc);
            room.Setup(e => e.PlayerCharacters).Returns(lPc);
            room2.Setup(e => e.Zone).Returns(11);
            room2.Setup(e => e.Id).Returns(11);
            room2.Setup(e => e.NonPlayerCharacters).Returns(lNpc2);
            room2.Setup(e => e.PlayerCharacters).Returns(lPc2);
            mockPerformerNpc.Setup(e => e.Room).Returns(room.Object);
            mockPerformerPc.Setup(e => e.Room).Returns(room.Object);
            world.Setup(e => e.Zones).Returns(zoneDict);
            zone.Setup(e => e.Rooms).Returns(roomDict);
            mockPerformerNpc.Setup(e => e.SentenceDescription).Returns("npc");
            mockPerformerPc.Setup(e => e.SentenceDescription).Returns("pc");

            performerNpc = mockPerformerNpc.Object;
            performerPc  = mockPerformerPc.Object;
            param        = effect.Object;
            npc          = mockNpc.Object;
            pc           = mockPc.Object;
            npc2         = mockNpc2.Object;
            pc2          = mockPc2.Object;

            lNpc.Add(npc);
            lPc.Add(pc);
            lNpc2.Add(npc2);
            lPc2.Add(pc2);
            GlobalReference.GlobalValues.World  = world.Object;
            GlobalReference.GlobalValues.Notify = notify.Object;


            moveToOtherDimension = new MoveToOtherDimension();
        }
Beispiel #16
0
 /**
  * @brief Set the value of an existing parameter
  *
  * @param _name name of the parameter
  * @param _value value of the parameter
  *
  * @result success?
  * */
 // TODO: check whether it needs deep copy
 public bool SetParameter(string _name, IEffectParameter _value)
 {
     if (m_parameters.ContainsKey(_name))
     {
         m_parameters[_name] = _value;
         return(true);
     }
     return(false);
 }
Beispiel #17
0
 /**
  * @brief Add a parameter, the _variable is cloned inside the function
  *
  * @param _variable, the parameter to be added
  *
  * @result success?
  * */
 public bool AddParameter(string _name, IEffectParameter _variable)
 {
     if (m_parameters.ContainsKey(_name))
     {
         return(false);
     }
     m_parameters.Add(_name, _variable.ParameterClone());
     return(true);
 }
Beispiel #18
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            if (parameter.Target is IPlayerCharacter pc)
            {
                pc.RespawnPoint = parameter.ObjectId;

                GlobalReference.GlobalValues.Logger.Log(pc, LogLevel.DEBUG, string.Format("{0} respawn point was reset to {1}.", pc.Name, pc.RespawnPoint));
            }
        }
Beispiel #19
0
        /// <summary>
        /// Retrieves the parameters of an effect
        /// </summary>
        /// <param name="Handle">The effect handle</param>
        /// <param name="Parameters">The parameters structure to fill. The structure used depends on the effect type.</param>
        /// <returns>
        /// If successful, <see langword="true"/> is returned, else <see langword="false"/> is returned.
        /// Use <see cref="LastError"/> to get the error code.
        /// </returns>
        /// <exception cref="Errors.Handle"><paramref name="Handle"/> is not valid.</exception>
        /// <seealso cref="ChannelSetFX"/>
        /// <seealso cref="FXSetParameters(int,IntPtr)"/>
        public static bool FXGetParameters(int Handle, IEffectParameter Parameters)
        {
            var gch = GCHandle.Alloc(Parameters);

            var result = FXGetParameters(Handle, gch.AddrOfPinnedObject());

            gch.Free();

            return(result);
        }
Beispiel #20
0
 public void ProcessEffect(IEffectParameter parameter)
 {
     if (parameter.Target is IMobileObject mob)
     {
         mob.Stamina += parameter.Dice.RollDice();
         if (mob.Stamina > mob.MaxStamina)
         {
             mob.Stamina = mob.MaxStamina;
         }
     }
 }
Beispiel #21
0
 public void ProcessEffect(IEffectParameter parameter)
 {
     if (parameter.Target is IMobileObject mob)
     {
         mob.Health += parameter.Dice.RollDice();
         if (mob.Health > mob.MaxHealth)
         {
             mob.Health = mob.MaxHealth;
         }
     }
 }
 /// <summary>
 /// Gets the parameter specified by its semantic.
 /// </summary>
 /// <param name="name">Semantic of the parameter</param>
 /// <returns>
 /// The parameter, if it exists
 /// </returns>
 public IEffectParameter GetParameterBySemantic(string name)
 {
     for (int i = 0; i < _params.Count; i++)
     {
         IEffectParameter param = _params[i];
         if (param.Semantic.Equals(name))
         {
             return(param);
         }
     }
     return(null);
 }
 /// <summary>
 /// Gets the parameter specified by its index.
 /// </summary>
 /// <returns>The parameter, if it exists</returns>
 public IEffectParameter this[string name] {
     get {
         for (int i = 0; i < _params.Count; i++)
         {
             IEffectParameter param = _params[i];
             if (param.Name.Equals(name))
             {
                 return(param);
             }
         }
         return(null);
     }
 }
Beispiel #24
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            IMobileObject mob = parameter.Target as IMobileObject;

            if (mob != null)
            {
                mob.Mana += parameter.Dice.RollDice();
                if (mob.Mana > mob.MaxMana)
                {
                    mob.Mana = mob.MaxMana;
                }
            }
        }
Beispiel #25
0
 public MaterialParameter(MaterialParameter param, IEffectParameter replacement) {
     _type = param.ParameterType;
     _cachedParameter = replacement;
     _name = param.Name;
     _isSemantic = param.IsSemantic;
     _singleValue = param.SingleValue;
     _intValue = param.IntValue;
     _boolValue = param.BoolValue;
     _vector2Value = param.Vector2Value;
     _vector3Value = param.Vector3Value;
     _vector4Value = param.Vector4Value;
     _textureValue = param.TextureValue;
     _matrixValue = param.MatrixValue;
 }
Beispiel #26
0
 public MaterialParameter(IEffectParameter param, String name, bool isSemantic, Matrix value) {
     _type = MaterialParameterType.Matrix;
     _cachedParameter = param;
     _isSemantic = isSemantic;
     _name = name;
     _singleValue = 0;
     _intValue = 0;
     _boolValue = false;
     _vector2Value = Vector2.Zero;
     _vector3Value = Vector3.Zero;
     _vector4Value = Vector4.Zero;
     _textureValue = null;
     _matrixValue = value;
 }
Beispiel #27
0
 //This code is taken directly from the lighting logic that is
 //used by the material. Since the scene graph's Mesh class is an IRenderable,
 //it has a material exposed to the renderer. When the material is applied (render states set,
 //logic executed, pass applied), this logic checks if the light collection has been
 //changed since the last time the renderable was rendered. If it has been, light data
 //is sent to the shader.
 private void SetLight(IEffectParameter lParam, PointLight pl)
 {
     lParam.StructureMembers[0].SetValue(pl.Ambient.ToVector3());
     lParam.StructureMembers[1].SetValue(pl.Diffuse.ToVector3());
     lParam.StructureMembers[2].SetValue(pl.Specular.ToVector3());
     lParam.StructureMembers[3].SetValue(pl.Attenuate);
     lParam.StructureMembers[4].SetValue(pl.Constant);
     lParam.StructureMembers[5].SetValue(pl.Linear);
     lParam.StructureMembers[6].SetValue(pl.Quadratic);
     lParam.StructureMembers[7].SetValue(new Vector4(pl.Position, 0));
     lParam.StructureMembers[8].SetValue(Vector3.Down);
     lParam.StructureMembers[9].SetValue(0f);
     lParam.StructureMembers[10].SetValue(0f);
 }
Beispiel #28
0
 private void SetLight(Light light, IEffectParameter lParam)
 {
     if (light.LightType == LightType.Directional)
     {
         DirectionalLight dl = light as DirectionalLight;
         lParam.StructureMembers[0].SetValue(dl.Ambient.ToVector3());
         lParam.StructureMembers[1].SetValue(dl.Diffuse.ToVector3());
         lParam.StructureMembers[2].SetValue(dl.Specular.ToVector3());
         lParam.StructureMembers[3].SetValue(false);
         lParam.StructureMembers[4].SetValue(dl.Constant);
         lParam.StructureMembers[5].SetValue(dl.Linear);
         lParam.StructureMembers[6].SetValue(dl.Quadratic);
         lParam.StructureMembers[7].SetValue(new Vector4(0, 0, 0, 1));
         lParam.StructureMembers[8].SetValue(dl.Direction);
         lParam.StructureMembers[9].SetValue(0f);
         lParam.StructureMembers[10].SetValue(0f);
     }
     else if (light.LightType == LightType.Point)
     {
         PointLight pl = light as PointLight;
         lParam.StructureMembers[0].SetValue(pl.Ambient.ToVector3());
         lParam.StructureMembers[1].SetValue(pl.Diffuse.ToVector3());
         lParam.StructureMembers[2].SetValue(pl.Specular.ToVector3());
         lParam.StructureMembers[3].SetValue(pl.Attenuate);
         lParam.StructureMembers[4].SetValue(pl.Constant);
         lParam.StructureMembers[5].SetValue(pl.Linear);
         lParam.StructureMembers[6].SetValue(pl.Quadratic);
         lParam.StructureMembers[7].SetValue(new Vector4(pl.Position, 0));
         lParam.StructureMembers[8].SetValue(Vector3.Down);
         lParam.StructureMembers[9].SetValue(0f);
         lParam.StructureMembers[10].SetValue(0f);
     }
     else if (light.LightType == LightType.Spot)
     {
         SpotLight sl = light as SpotLight;
         lParam.StructureMembers[0].SetValue(sl.Ambient.ToVector3());
         lParam.StructureMembers[1].SetValue(sl.Diffuse.ToVector3());
         lParam.StructureMembers[2].SetValue(sl.Specular.ToVector3());
         lParam.StructureMembers[3].SetValue(sl.Attenuate);
         lParam.StructureMembers[4].SetValue(sl.Constant);
         lParam.StructureMembers[5].SetValue(sl.Linear);
         lParam.StructureMembers[6].SetValue(sl.Quadratic);
         lParam.StructureMembers[7].SetValue(new Vector4(sl.Position, 0));
         lParam.StructureMembers[8].SetValue(sl.Direction);
         lParam.StructureMembers[9].SetValue(1 - (sl.InnerAngle / 180f));
         lParam.StructureMembers[10].SetValue(1 - (sl.OuterAngle / 180f));
     }
 }
Beispiel #29
0
        //Because we can not put a reference to the npc who will be telling
        //we need to scan through the zone to find them.  We iterate over
        //each room in the zone and check the npc to see if the id matches
        //the one we passed in via the parameter
        public void ProcessEffect(IEffectParameter parameter)
        {
            IZone zone = GlobalReference.GlobalValues.World.Zones[parameter.ObjectId.Zone];

            foreach (IRoom room in zone.Rooms.Values)
            {
                foreach (INonPlayerCharacter npc in room.NonPlayerCharacters)
                {
                    if (npc.Id == parameter.ObjectId.Id)
                    {
                        npc.EnqueueCommand(string.Format("Tell {0} {1}", parameter.Target.KeyWords[0], parameter.TargetMessage.GetTranslatedMessage(null)));
                        break;
                    }
                }
            }
        }
Beispiel #30
0
        public void ProcessEffect(IEffectParameter parameter)
        {
            IRoom room = GlobalReference.GlobalValues.World.Zones[parameter.RoomId.Zone].Rooms[parameter.RoomId.Id];

            GlobalReference.GlobalValues.Notify.Room(parameter.Performer, parameter.Target, room, parameter.RoomMessage);

            if (Sound != null)
            {
                string serializeSounds = GlobalReference.GlobalValues.Serialization.Serialize(new List <ISound>()
                {
                    Sound
                });

                GlobalReference.GlobalValues.Notify.Room(null, null, room, new TranslationMessage(serializeSounds, TagType.Sound));
            }
        }
 public void Bind( IEffectParameter parameter )
 {
     parameter.DataSource = this;
 }
        public void Apply( IEffectParameter parameter )
        {
            CgEffectParameter cgParam = ( ( CgEffectParameter )parameter );
            IntPtr context = cgParam.Context;
            IntPtr param = cgParam.Parameter;
            switch ( m_Binding )
            {
                case EffectRenderStateBinding.NearZ:
                    {
                        IProjectionCamera curCam = Graphics.Renderer.Camera as IProjectionCamera;
                        if ( curCam != null )
                        {
                            TaoCg.cgSetParameter1f( param, curCam.PerspectiveZNear );
                        }

                        break;
                    }

                case EffectRenderStateBinding.FarZ:
                    {
                        IProjectionCamera curCam = Graphics.Renderer.Camera as IProjectionCamera;
                        if ( curCam != null )
                        {
                            TaoCg.cgSetParameter1f( param, curCam.PerspectiveZFar );
                        }

                        break;
                    }

                case EffectRenderStateBinding.ModelMatrix:
                    {
                        Matrix44 modelMatrix = Graphics.Renderer.GetTransform( TransformType.LocalToWorld );
                        CgEffectParameter.cgSetMatrixParameterfc( param, modelMatrix.Elements );
                        break;
                    }

                case EffectRenderStateBinding.ViewMatrix:
                    {
                        Matrix44 viewMatrix = Graphics.Renderer.GetTransform( TransformType.WorldToView );
                        CgEffectParameter.cgSetMatrixParameterfc( param, viewMatrix.Elements );
                        break;
                    }

                case EffectRenderStateBinding.InverseTransposeModelMatrix:
                    {
                        Matrix44 itModelMatrix = Graphics.Renderer.GetTransform( TransformType.LocalToWorld );
                        itModelMatrix.Translation = Point3.Origin;
                        itModelMatrix.Transpose( );
                        itModelMatrix.Invert( );

                        CgEffectParameter.cgSetMatrixParameterfc( param, itModelMatrix.Elements );
                        break;
                    }

                case EffectRenderStateBinding.ProjectionMatrix:
                    {
                        TaoCgGl.cgGLSetStateMatrixParameter( param, TaoCgGl.CG_GL_PROJECTION_MATRIX, TaoCgGl.CG_GL_MATRIX_IDENTITY );
                        break;
                    }

                case EffectRenderStateBinding.TextureMatrix:
                    {
                        TaoCgGl.cgGLSetStateMatrixParameter( param, TaoCgGl.CG_GL_TEXTURE_MATRIX, TaoCgGl.CG_GL_MATRIX_IDENTITY );
                        break;
                    }

                case EffectRenderStateBinding.ModelViewMatrix:
                    {
                        TaoCgGl.cgGLSetStateMatrixParameter( param, TaoCgGl.CG_GL_MODELVIEW_MATRIX, TaoCgGl.CG_GL_MATRIX_IDENTITY );
                        break;
                    }

                case EffectRenderStateBinding.InverseModelViewMatrix:
                    {
                        TaoCgGl.cgGLSetStateMatrixParameter( param, TaoCgGl.CG_GL_MODELVIEW_MATRIX, TaoCgGl.CG_GL_MATRIX_INVERSE );
                        break;
                    }

                case EffectRenderStateBinding.InverseTransposeModelViewMatrix:
                    {
                        TaoCgGl.cgGLSetStateMatrixParameter( param, TaoCgGl.CG_GL_MODELVIEW_MATRIX, TaoCgGl.CG_GL_MATRIX_INVERSE_TRANSPOSE );
                        break;
                    }

                case EffectRenderStateBinding.ModelViewProjectionMatrix:
                    {
                        TaoCgGl.cgGLSetStateMatrixParameter( param, TaoCgGl.CG_GL_MODELVIEW_PROJECTION_MATRIX, TaoCgGl.CG_GL_MATRIX_IDENTITY );
                        break;
                    }

                case EffectRenderStateBinding.ViewportWidth:
                    {
                        throw new NotImplementedException( );
                    }

                case EffectRenderStateBinding.ViewportHeight:
                    {
                        throw new NotImplementedException( );
                    }

                case EffectRenderStateBinding.EyePosition:
                    {
                        ICamera3 curCam = ( ( ICamera3 )Graphics.Renderer.Camera );
                        if ( curCam != null )
                        {
                            Point3 eyePos = curCam.Frame.Translation;
                            TaoCg.cgSetParameter3f( param, eyePos.X, eyePos.Y, eyePos.Z );
                        }
                        break;
                    }

                case EffectRenderStateBinding.EyeZAxis:
                    {
                        ICamera3 curCam = ( ( ICamera3 )Graphics.Renderer.Camera );
                        if ( curCam != null )
                        {
                            Vector3 eyeVec = curCam.Frame.ZAxis;
                            TaoCg.cgSetParameter3f( param, eyeVec.X, eyeVec.Y, eyeVec.Z );
                        }
                        break;
                    }

                case EffectRenderStateBinding.PointLights:
                    {
                        //	TODO: This is REALLY SHIT. Need to refactor this mess
                        int numActiveLights = Graphics.Renderer.NumActiveLights;
                        int numPointLights = 0;
                        for ( int lightIndex = 0; lightIndex < numActiveLights; ++lightIndex )
                        {
                            IPointLight curLight = Graphics.Renderer.GetLight( lightIndex ) as IPointLight;
                            if ( curLight != null )
                            {
                                IntPtr positionParam = TaoCg.cgGetArrayParameter( TaoCg.cgGetNamedStructParameter( param, "m_Positions" ), numPointLights );
                                TaoCg.cgSetParameter4f( positionParam, curLight.Position.X, curLight.Position.Y, curLight.Position.Z, 0 );
                                ++numPointLights;
                            }
                        }

                        TaoCg.cgSetParameter1i( TaoCg.cgGetNamedStructParameter( param, "m_NumLights" ), numPointLights );

                        break;
                    }

                case EffectRenderStateBinding.SpotLights:
                    {
                        //	TODO: This is REALLY SHIT. Need to refactor this mess
                        int numActiveLights = Graphics.Renderer.NumActiveLights;
                        int numSpotLights = 0;
                        for ( int lightIndex = 0; lightIndex < numActiveLights; ++lightIndex )
                        {
                            ISpotLight curLight = Graphics.Renderer.GetLight( lightIndex ) as ISpotLight;
                            if ( curLight != null )
                            {
                                IntPtr positionParam = TaoCg.cgGetArrayParameter( TaoCg.cgGetNamedStructParameter( param, "m_Positions" ), numSpotLights );
                                IntPtr directionParam = TaoCg.cgGetArrayParameter( TaoCg.cgGetNamedStructParameter( param, "m_Directions" ), numSpotLights );
                                IntPtr arcParam = TaoCg.cgGetArrayParameter( TaoCg.cgGetNamedStructParameter( param, "m_Arcs" ), numSpotLights );
                                TaoCg.cgSetParameter3f( positionParam, curLight.Position.X, curLight.Position.Y, curLight.Position.Z );
                                TaoCg.cgSetParameter3f( directionParam, curLight.Direction.X, curLight.Direction.Y, curLight.Direction.Z );
                                TaoCg.cgSetParameter1f( arcParam, Functions.Cos( curLight.ArcDegrees * Constants.DegreesToRadians * 0.5f ) );
                                ++numSpotLights;
                            }
                        }

                        TaoCg.cgSetParameter1i( TaoCg.cgGetNamedStructParameter( param, "m_NumLights" ), numSpotLights );

                        break;
                    }

                case EffectRenderStateBinding.Texture0:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 0 ) );
                        break;
                    }
                case EffectRenderStateBinding.Texture1:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 1 ) );
                        break;
                    }
                case EffectRenderStateBinding.Texture2:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 2 ) );
                        break;
                    }
                case EffectRenderStateBinding.Texture3:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 3 ) );
                        break;
                    }
                case EffectRenderStateBinding.Texture4:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 4 ) );
                        break;
                    }
                case EffectRenderStateBinding.Texture5:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 5 ) );
                        break;
                    }
                case EffectRenderStateBinding.Texture6:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 6 ) );
                        break;
                    }
                case EffectRenderStateBinding.Texture7:
                    {
                        CgEffectParameter.BindTexture( context, param, Graphics.Renderer.GetTexture( 7 ) );
                        break;
                    }
                default:
                    {
                        throw new ApplicationException( string.Format( "Unhandled effect render state binding \"{0}\"", m_Binding ) );
                    }
            }
        }