예제 #1
0
        // Set parameter on a specific or all instances.
        // Return 'false' if not able to set the parameter.
        // Setting the value in the m_params block will change the value the physics engine
        //   will use the next time since it's pinned and shared memory.
        // Some of the values require calling into the physics engine to get the new
        //   value activated ('terrainFriction' for instance).
        public bool SetPhysicsParameter(string parm, float val, uint localID)
        {
            bool ret = false;

            BSParam.ParameterDefn theParam;
            if (BSParam.TryGetParameter(parm, out theParam))
            {
                theParam.setter(this, parm, localID, val);
                ret = true;
            }
            return(ret);
        }
예제 #2
0
        // Get parameter.
        // Return 'false' if not able to get the parameter.
        public bool GetPhysicsParameter(string parm, out string value)
        {
            string val = String.Empty;
            bool   ret = false;

            BSParam.ParameterDefnBase theParam;
            if (BSParam.TryGetParameter(parm, out theParam))
            {
                val = theParam.GetValue(this);
                ret = true;
            }
            value = val;
            return(ret);
        }
예제 #3
0
        // Get parameter.
        // Return 'false' if not able to get the parameter.
        public bool GetPhysicsParameter(string parm, out float value)
        {
            float val = 0f;
            bool  ret = false;

            BSParam.ParameterDefn theParam;
            if (BSParam.TryGetParameter(parm, out theParam))
            {
                val = theParam.getter(this);
                ret = true;
            }
            value = val;
            return(ret);
        }
예제 #4
0
        // Set parameter on a specific or all instances.
        // Return 'false' if not able to set the parameter.
        // Setting the value in the m_params block will change the value the physics engine
        //   will use the next time since it's pinned and shared memory.
        // Some of the values require calling into the physics engine to get the new
        //   value activated ('terrainFriction' for instance).
        public bool SetPhysicsParameter(string parm, string val, uint localID)
        {
            bool ret = false;

            BSParam.ParameterDefnBase theParam;
            if (BSParam.TryGetParameter(parm, out theParam))
            {
                // Set the value in the C# code
                theParam.SetValue(this, val);

                // Optionally set the parameter in the unmanaged code
                if (theParam.HasSetOnObject)
                {
                    // update all the localIDs specified
                    // If the local ID is APPLY_TO_NONE, just change the default value
                    // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs
                    // If the localID is a specific object, apply the parameter change to only that object
                    List <uint> objectIDs = new List <uint>();
                    switch (localID)
                    {
                    case PhysParameterEntry.APPLY_TO_NONE:
                        // This will cause a call into the physical world if some operation is specified (SetOnObject).
                        objectIDs.Add(TERRAIN_ID);
                        TaintedUpdateParameter(parm, objectIDs, val);
                        break;

                    case PhysParameterEntry.APPLY_TO_ALL:
                        lock (PhysObjects) objectIDs = new List <uint>(PhysObjects.Keys);
                        TaintedUpdateParameter(parm, objectIDs, val);
                        break;

                    default:
                        // setting only one localID
                        objectIDs.Add(localID);
                        TaintedUpdateParameter(parm, objectIDs, val);
                        break;
                    }
                }

                ret = true;
            }
            return(ret);
        }
예제 #5
0
        // schedule the actual updating of the paramter to when the phys engine is not busy
        private void TaintedUpdateParameter(string parm, List <uint> lIDs, float val)
        {
            float       xval  = val;
            List <uint> xlIDs = lIDs;
            string      xparm = parm;

            TaintedObject("BSScene.UpdateParameterSet", delegate() {
                BSParam.ParameterDefn thisParam;
                if (BSParam.TryGetParameter(xparm, out thisParam))
                {
                    if (thisParam.onObject != null)
                    {
                        foreach (uint lID in xlIDs)
                        {
                            BSPhysObject theObject = null;
                            PhysObjects.TryGetValue(lID, out theObject);
                            thisParam.onObject(this, theObject, xval);
                        }
                    }
                }
            });
        }
예제 #6
0
        // schedule the actual updating of the paramter to when the phys engine is not busy
        private void TaintedUpdateParameter(string parm, List <uint> lIDs, string val)
        {
            string      xval  = val;
            List <uint> xlIDs = lIDs;
            string      xparm = parm;

            TaintedObject("BSScene.UpdateParameterSet", delegate() {
                BSParam.ParameterDefnBase thisParam;
                if (BSParam.TryGetParameter(xparm, out thisParam))
                {
                    if (thisParam.HasSetOnObject)
                    {
                        foreach (uint lID in xlIDs)
                        {
                            BSPhysObject theObject = null;
                            if (PhysObjects.TryGetValue(lID, out theObject))
                            {
                                thisParam.SetOnObject(this, theObject);
                            }
                        }
                    }
                }
            });
        }