Пример #1
0
        /// <summary>
        /// For sounds!
        /// </summary>
        /// <param name="lthing">The Thing this component is attached to</param>
        /// <param name="template">The template from the Thing</param>
        /// <param name="block">The block we're creating this component from</param>
        public SoundComponent(LThing lthing, ThingBlock template, SoundBlock block)
        {
            Name = block.GetStringProperty("name", template.ThingName);
            owner = lthing;

            var soundMain = LKernel.GetG<SoundMain>();
            ISoundSource source = soundMain.GetSource(block.GetStringProperty("File", null));

            bool looping = block.GetBoolProperty("looping", true);
            bool sfx = block.GetBoolProperty("SpecialEffects", false);
            relativePosition = block.GetVectorProperty("position", Vector3.ZERO);
            bool startPaused = block.GetBoolProperty("StartPaused", true);

            Sound = soundMain.Play3D(source, relativePosition, looping, startPaused, sfx);

            if(Sound != null) {
                Sound.PlaybackSpeed = block.GetFloatProperty("Speed", 1);
                float volume;
                if (block.FloatTokens.TryGetValue("volume", out volume))
                    Sound.Volume = volume;

                Sound.MinDistance = block.GetFloatProperty("mindistance", soundMain.Engine.Default3DSoundMinDistance);

                // TODO: effects, if we end up using any of them

                Update();
                Sound.Paused = false;
            }

            soundMain.AddSoundComponent(this);
        }
Пример #2
0
        /// <summary>
        /// For ribbons!
        /// </summary>
        /// <param name="lthing">The Thing this component is attached to</param>
        /// <param name="template">The template from the Thing</param>
        /// <param name="block">The block we're creating this component from</param>
        public RibbonComponent(LThing lthing, ThingBlock template, RibbonBlock block)
        {
            ID = IDs.Incremental;
            var sceneMgr = LKernel.GetG<SceneManager>();

            Name = block.GetStringProperty("name", template.ThingName);

            // if ribbons are disabled, don't bother creating anything
            if (!Options.GetBool("Ribbons"))
                return;

            Ribbon = LKernel.GetG<SceneManager>().CreateRibbonTrail(Name + ID + "Ribbon");

            // set up some properties
            Ribbon.SetMaterialName(block.GetStringProperty("material", "ribbon"));
            Ribbon.TrailLength = block.GetFloatProperty("length", 5f);
            Ribbon.MaxChainElements = (uint) block.GetFloatProperty("elements", 10f);
            Ribbon.SetInitialWidth(0, block.GetFloatProperty("width", 1f));
            Ribbon.SetInitialColour(0, block.GetQuatProperty("colour", new Quaternion(1, 1, 1, 1)).ToColourValue());
            Ribbon.SetColourChange(0, block.GetQuatProperty("colourchange", new Quaternion(0, 0, 0, 3)).ToColourValue());
            Ribbon.SetWidthChange(0, block.GetFloatProperty("widthchange", 1f));

            // attach it to the node
            RibbonNode = LKernel.GetG<SceneManager>().RootSceneNode.CreateChildSceneNode(Name + ID + "RibbonNode");
            TrackedRibbonNode = lthing.RootNode.CreateChildSceneNode(Name + ID + "TrackedRibbonNode");
            Ribbon.AddNode(TrackedRibbonNode);
            RibbonNode.AttachObject(Ribbon);

            TrackedRibbonNode.Position = block.GetVectorProperty("position", null);
        }
Пример #3
0
 /// <param name="thing">The connected lthing, used for updating sounds. You can pass null to skip updating sounds.</param>
 public MogreMotionState(LThing thing, Vector3 position, Quaternion orientation, SceneNode node)
 {
     transform = new Matrix4(orientation);
     transform.MakeTransform(position, Vector3.UNIT_SCALE, orientation);
     this.node = node;
     this.owner = thing;
 }
Пример #4
0
        /// <summary>
        /// For physics
        /// </summary>
        /// <param name="lthing">The Thing this component is attached to</param>
        /// <param name="block">The block we're creating this component from</param>
        public ShapeComponent(LThing lthing, ShapeBlock block)
        {
            var sceneMgr = LKernel.GetG<SceneManager>();

            Transform = block.Transform;

            Type = block.GetEnumProperty("type", null);
            switch (Type) {
                case ThingEnum.Box:
                case ThingEnum.Cylinder:
                    Dimensions = block.GetVectorProperty("dimensions", null) / 2f;
                    break;
                case ThingEnum.Capsule:
                case ThingEnum.Cone:
                    Height = block.GetFloatProperty("height", null);
                    Radius = block.GetFloatProperty("radius", null);
                    break;
                case ThingEnum.Sphere:
                    Radius = block.GetFloatProperty("radius", null);
                    break;
                case ThingEnum.Heightmap:
                    MinHeight = block.GetFloatProperty("MinHeight", null);
                    MaxHeight = block.GetFloatProperty("MaxHeight", null);
                    Width = (int) block.GetFloatProperty("Width", null);
                    Length = (int) block.GetFloatProperty("Length", null);
                    Mesh = block.GetStringProperty("mesh", null);
                    Dimensions = block.GetVectorProperty("dimensions", null) / 2f;
                    break;
                case ThingEnum.Hull:
                case ThingEnum.Mesh:
                    Mesh = block.GetStringProperty("mesh", null);
                    break;
            }
        }
Пример #5
0
 public DummyItem(string itemType, Player _focus)
 {
     focus = _focus;
     Vector3 pos = focus.NodePosition;
     pos.y += 2;
     dummy = LKernel.GetG<Spawner>().Spawn(itemType, pos);
     Launch.OnEveryUnpausedTenthOfASecondEvent += EveryTenth;
 }
        /// <summary>
        /// Creates a Rotater. This removes any existing nlerpers and rotaters attached to the lthing.
        /// </summary>
        /// <param name="owner">What lthing are we affecting?</param>
        /// <param name="duration">How long as we going to rotate?</param>
        /// <param name="angle">Rotation angle</param>
        /// <param name="mode">Rotation axis mode</param>
        /// <returns>The new rotater</returns>
        public Rotater CreateRotater(LThing owner, float duration, Radian angle, RotaterAxisMode mode)
        {
            RemoveRotater(owner);

            Rotater newRotater = new Rotater(owner, duration, angle, mode);
            Rotaters.TryAdd(owner, newRotater);
            return newRotater;
        }
Пример #7
0
        /// <summary>
        /// USE THE LThingHelperManager FOR THIS!
        /// 
        /// A nlerper is something that rotates a thing over a certain time to a certain orientation.
        /// Multiple nlerpers running at the same can cause problems, so you should check for other
        /// nlerpers and do something with them first before creating more.
        /// </summary>
        /// <param name="thingToNlerp">The thing we want to rotate</param>
        /// <param name="duration">The time the rotation should take, in seconds</param>
        /// <param name="orientDest">The destination orientation the kart should be when this is done</param>
        public Nlerper(LThing thingToNlerp, float duration, Quaternion orientDest)
        {
            this.duration = duration;
            this.orientSrc = thingToNlerp.Body.Orientation;
            this.orientDest = orientDest;
            this.thing = thingToNlerp;

            PhysicsMain.PreSimulate += PreSimulate;
        }
        /// <summary>
        /// Creates a Nlerper. This removes any existing nlerpers and rotaters attached to the lthing.
        /// </summary>
        /// <param name="owner">What lthing was we affecting?</param>
        /// <param name="duration">How long are we going to nlerp?</param>
        /// <param name="orientDest">Destination orientation when it is finished.</param>
        /// <returns>The new nlerper</returns>
        public Nlerper CreateNlerper(LThing owner, float duration, Quaternion orientDest)
        {
            RemoveNlerper(owner);
            RemoveRotater(owner);

            Nlerper newNlerper = new Nlerper(owner, duration, orientDest);
            Nlerpers.TryAdd(owner, newNlerper);
            return newNlerper;
        }
        /// <summary>
        /// Creates a Rotater. This removes any existing nlerpers and rotaters attached to the lthing.
        /// </summary>
        /// <param name="owner">What lthing are we affecting?</param>
        /// <param name="duration">How long as we going to rotate?</param>
        /// <param name="angle">Rotation angle</param>
        /// <param name="axis">Axis of rotation</param>
        /// <param name="mode">Rotation axis mode</param>
        /// <returns>The new rotater</returns>
        public Rotater CreateRotater(LThing owner, float duration, Radian angle, Vector3 axis, RotaterAxisMode mode = RotaterAxisMode.Explicit)
        {
            RemoveRotater(owner);
            RemoveNlerper(owner);

            Rotater newRotater = new Rotater(owner, duration, angle, axis, mode);
            Rotaters.TryAdd(owner, newRotater);
            return newRotater;
        }
Пример #10
0
 //public void Save() {
 //}
 /// <summary>
 /// Runs whenever we spawn something. This just adds it to the level's dictionary of Things.
 /// </summary>
 public void AddThing(LThing newThing)
 {
     // try adding it without its ID
     if (!Things.TryAdd(newThing.Name, newThing)) {
         // okay that didn't work, now try adding it with its ID
         if (!Things.TryAdd(newThing.Name + newThing.ID, newThing)) {
             // still didn't work so we must've had a problem while adding it.
             Launch.Log("[Level] **WARNING** (AddThing) A problem occurred when we tried to add this new LThing to the Things dictionary!");
         }
     }
 }
Пример #11
0
        /// <summary>
        /// USE THE LThingHelperManager FOR THIS!
        /// </summary>
        public Rotater(LThing thingToRotate, float duration, Radian angle, Vector3 axis, RotaterAxisMode mode = RotaterAxisMode.Explicit)
        {
            this.thing = thingToRotate;
            this.duration = duration;
            this.angle = angle;
            this.axis = axis;
            this.mode = mode;

            orient = new Quaternion();

            PhysicsMain.PreSimulate += PreSimulate;
        }
Пример #12
0
        public ComputerPlayer(LevelChangedEventArgs eventArgs, int id)
            : base(eventArgs, id, true)
        {
            //LKernel.GetG<CollisionReporter>().AddEvent(PonykartCollisionGroups.Karts, PonykartCollisionGroups.Environment, OnCol);
                #if DEBUG
                axis = LKernel.GetG<Core.Spawner>().Spawn("Axis", Kart.RootNode.Position);
                axis.ModelComponents[0].Node.SetScale(0.1f, 0.1f, 0.1f);
                axis2 = LKernel.GetG<Core.Spawner>().Spawn("Axis", Kart.RootNode.Position);
                axis2.ModelComponents[0].Node.SetScale(0.1f, 0.1f, 0.1f);
                #endif

            Launch.OnEveryUnpausedTenthOfASecondEvent += EveryTenth;
        }
        /// <summary>
        /// Creates a CollisionShape from the ShapeComponents of the given thing. If the shape already exists, we'll just return that instead.
        /// </summary>
        public CollisionShape CreateAndRegisterShape(LThing thing, ThingDefinition def)
        {
            CollisionShape shape;
            if (!Shapes.TryGetValue(thing.Name, out shape)) {
                // create the shape

                bool forceCompound = def.GetBoolProperty("forcecompound", false);

                // if we only have one shape we don't have to do as much
                if (thing.ShapeComponents.Count == 1) {
                    // force us to use a compound shape?
                    if (forceCompound) {
                        CompoundShape comp = new CompoundShape();
                        comp.AddChildShape(thing.ShapeComponents[0].Transform, CreateShapeForComponent(thing.ShapeComponents[0]));

                        shape = comp;
                    }
                    // one component, no compound is the easiest
                    else {
                        shape = CreateShapeForComponent(thing.ShapeComponents[0]);
                    }
                }
                // otherwise, make all of our shapes and stick them in a compound shape
                else {
                    CompoundShape comp = new CompoundShape();

                    foreach (ShapeComponent component in thing.ShapeComponents) {
                        comp.AddChildShape(component.Transform, CreateShapeForComponent(component));
                    }

                    shape = comp;
                }

                // then put the shape in our dictionary
                Shapes.Add(thing.Name, shape);
            }
            return shape;
        }
Пример #14
0
 /// <summary>
 /// Cleans up a nlerper when it's finished
 /// </summary>
 void Nlerper_Finished(Nlerper nlerper, LThing thing)
 {
     if (Nlerpers.Values.Contains(nlerper)) {
         Nlerper existing;
         Nlerpers.TryRemove(thing, out existing);
     }
 }
Пример #15
0
 public void DoFunctionForLThing(string functionName, LThing thing)
 {
     if (LKernel.GetG<LevelManager>().IsValidLevel) {
         lock (LuaVM.Lua) {
             try {
                 LuaVM.Lua["lthing"] = thing;
                 LuaVM.Lua.GetFunction(functionName).Call(thing);
             }
             catch (LuaException ex) {
                 HandleException(ex);
             }
         }
     }
 }
Пример #16
0
 public static void AddSoundFrameEvent(LThing lthing, int componentID, SoundFrameEvent action)
 {
     lthing.SoundComponents[componentID].OnUpdate += action;
 }
Пример #17
0
 public static void ForceActivationState(LThing thing, int activationState)
 {
     if (thing != null && thing.Body != null)
         thing.Body.ForceActivationState((ActivationState) activationState);
 }
Пример #18
0
 public static void DeactivateThing(LThing thing)
 {
     if (thing != null && thing.Body != null)
         thing.Body.ForceActivationState(ActivationState.WantsDeactivation);
 }
Пример #19
0
 public static void RelativeSpawn(string thingName, LThing thing, Vector3 offset)
 {
     Vector3 pos = thing.RootNode.ConvertLocalToWorldPosition(offset);
     Spawn(thingName, pos);
 }
 /// <summary>
 /// Create a data holder using properties of an LThing object.
 /// </summary>
 public CollisionObjectDataHolder(LThing thing)
     : this(thing.Body, thing.CollisionGroup, thing.Name)
 {
     this.Thing = thing;
 }
Пример #21
0
 public static void SetMaterial(LThing thing, string newMaterial)
 {
     foreach (ModelComponent mc in thing.ModelComponents) {
         mc.Entity.SetMaterialName(newMaterial);
     }
 }
Пример #22
0
 public static void SetOneSubMaterial(LThing thing, int componentID, int subEntityID, string newMaterial)
 {
     thing.ModelComponents[componentID].Entity.GetSubEntity((uint) subEntityID).SetMaterialName(newMaterial);
 }
Пример #23
0
 public static void SetOneMaterial(LThing thing, int componentID, string newMaterial)
 {
     thing.ModelComponents[componentID].Entity.SetMaterialName(newMaterial);
 }
Пример #24
0
 public static void SetSubMaterial(LThing thing, int subEntityID, string newMaterial)
 {
     foreach (ModelComponent mc in thing.ModelComponents) {
         if (mc.Entity.NumSubEntities > subEntityID)
             mc.Entity.GetSubEntity((uint) subEntityID).SetMaterialName(newMaterial);
     }
 }
Пример #25
0
 /// <summary>
 /// USE THE LThingHelperManager FOR THIS!
 /// </summary>
 public Rotater(LThing thingToRotate, float duration, Radian angle, RotaterAxisMode mode)
     : this(thingToRotate, duration, angle, default(Vector3), mode)
 {
 }
Пример #26
0
        /// <summary>
        /// Clean up
        /// </summary>
        public void Detach()
        {
            if (thing != null) {
                if (Finished != null)
                    Finished(this, thing);

                PhysicsMain.PreSimulate -= PreSimulate;

                thing = null;
            }
        }
Пример #27
0
 /// <summary>
 /// Removes a rotater with the given key.
 /// </summary>
 public void RemoveRotater(LThing owner)
 {
     Rotater existing;
     if (Rotaters.TryRemove(owner, out existing)) {
         existing.Detach();
     }
 }
Пример #28
0
 /// <summary>
 /// Removes a nlerper with the given key.
 /// </summary>
 public void RemoveNlerper(LThing owner)
 {
     Nlerper existing;
     if (Nlerpers.TryRemove(owner, out existing)) {
         existing.Detach();
     }
 }
Пример #29
0
        /// <summary>
        /// Creates a model component for a Thing.
        /// </summary>
        /// <param name="lthing">The Thing this component is attached to</param>
        /// <param name="template">The template from the Thing</param>
        /// <param name="block">The block we're creating this component from</param>
        public ModelComponent(LThing lthing, ThingBlock template, ModelBlock block, ThingDefinition def)
        {
            ID = IDs.Incremental;
            Owner = lthing;
            var sceneMgr = LKernel.GetG<SceneManager>();

            Name = block.GetStringProperty("name", template.ThingName);

            // set these up here because static/instanced geometry might need them
            // position
            SpawnPosition = block.GetVectorProperty("position", Vector3.ZERO);

            // orientation
            SpawnOrientation = block.GetQuatProperty("orientation", Quaternion.IDENTITY);
            // if orientation was not found, we fall back to rotation
            if (SpawnOrientation == Quaternion.IDENTITY) {
                Vector3 rot = block.GetVectorProperty("rotation", Vector3.ZERO);
                if (rot != Vector3.ZERO)
                    SpawnOrientation = rot.DegreeVectorToGlobalQuaternion();
            }
            // scale
            SpawnScale = block.GetVectorProperty("scale", Vector3.UNIT_SCALE);

            ThingEnum shad = block.GetEnumProperty("CastsShadows", ThingEnum.Some);
            // if we're static, set up the static geometry
            // don't set up static geometry if we want to cast shadows though, since static geometry doesn't work with shadows
            if ((block.GetBoolProperty("static", false) || def.GetBoolProperty("static", false))
                // make static if we never want shadows
                && (shad == ThingEnum.None
                // or if the mesh has "some" shadows but we don't want any
                    || (shad == ThingEnum.Some && Options.ShadowDetail == ShadowDetailOption.None)
                // or if the mesh has "many" shadows but we only want those with "some"
                    || (shad == ThingEnum.Many && Options.ShadowDetail != ShadowDetailOption.Many)))
            {
                LKernel.GetG<StaticGeometryManager>().Add(this, template, block, def);
                Entity = null;
            }
            else if (block.GetBoolProperty("instanced", false) || def.GetBoolProperty("instanced", false)) {
                LKernel.GetG<InstancedGeometryManager>().Add(this, template, block, def);
                Entity = null;
            }
            // for attachments
            else if (block.GetBoolProperty("Attached", false)) {
                SetupEntity(sceneMgr, block);
                SetupAnimation(block);

                string boneName = block.GetStringProperty("AttachBone", null);
                int modelComponentID = (int) block.GetFloatProperty("AttachComponentID", null);
                Quaternion offsetQuat = block.GetQuatProperty("AttachOffsetOrientation", Quaternion.IDENTITY);
                Vector3 offsetVec = block.GetVectorProperty("AttachOffsetPosition", Vector3.ZERO);

                lthing.ModelComponents[modelComponentID].Entity.AttachObjectToBone(boneName, Entity, offsetQuat, offsetVec);
            }
            // otherwise continue as normal
            else {
                Node = lthing.RootNode.CreateChildSceneNode(Name + "Node" + ID);

                Node.Position = SpawnPosition;
                Node.Orientation = SpawnOrientation;
                Node.Scale(SpawnScale);

                Node.InheritScale = block.GetBoolProperty("InheritScale", true);
                Node.InheritOrientation = block.GetBoolProperty("InheritOrientation", true);
                Node.SetInitialState();

                // make our entity
                SetupEntity(sceneMgr, block);

                SetupAnimation(block);

                // then attach it to the node!
                Node.AttachObject(Entity);
            }
        }
Пример #30
0
 /// <summary>
 /// Cleans up a rotater when it's finished
 /// </summary>
 void Rotater_Finished(Rotater rotater, LThing thing)
 {
     if (Rotaters.Values.Contains(rotater)) {
         Rotater existing;
         Rotaters.TryRemove(thing, out existing);
     }
 }