コード例 #1
0
ファイル: LLUDPClient.cs プロジェクト: ssatguru/opensim
        public override bool Dequeue(out T item)
        {
            if (highQueue.Dequeue(out item))
            {
                return(true);
            }

            return(base.Dequeue(out item));
        }
コード例 #2
0
        /// <summary>
        /// Process all queued raycast requests
        /// </summary>
        /// <returns>Time in MS the raycasts took to process.</returns>
        public int ProcessQueuedRequests()
        {
            if (m_PendingRequests.Count <= 0)
            {
                return(0);
            }

            if (m_scene.ContactgeomsArray == IntPtr.Zero || ray == IntPtr.Zero)
            // oops something got wrong or scene isn't ready still
            {
                m_PendingRequests.Clear();
                return(0);
            }

            int time = Util.EnvironmentTickCount();

            ODERayRequest       req;
            int                 closestHit;
            int                 backfacecull;
            CollisionCategories catflags;

            while (m_PendingRequests.Dequeue(out req))
            {
                if (req.callbackMethod != null)
                {
                    IntPtr geom = IntPtr.Zero;
                    if (req.actor != null)
                    {
                        if (m_scene.haveActor(req.actor))
                        {
                            if (req.actor is OdePrim)
                            {
                                geom = ((OdePrim)req.actor).prim_geom;
                            }
                            else if (req.actor is OdeCharacter)
                            {
                                geom = ((OdePrim)req.actor).prim_geom;
                            }
                        }
                        if (geom == IntPtr.Zero)
                        {
                            NoContacts(req);
                            continue;
                        }
                    }

                    CurrentRayFilter = req.filter;
                    CurrentMaxCount  = req.Count;

                    CollisionContactGeomsPerTest = req.Count & 0xffff;

                    closestHit   = ((CurrentRayFilter & RayFilterFlags.ClosestHit) == 0 ? 0 : 1);
                    backfacecull = ((CurrentRayFilter & RayFilterFlags.BackFaceCull) == 0 ? 0 : 1);

                    if (req.callbackMethod is ProbeBoxCallback)
                    {
                        if (CollisionContactGeomsPerTest > 80)
                        {
                            CollisionContactGeomsPerTest = 80;
                        }
                        SafeNativeMethods.GeomBoxSetLengths(Box, req.Normal.X, req.Normal.Y, req.Normal.Z);
                        SafeNativeMethods.GeomSetPosition(Box, req.Origin.X, req.Origin.Y, req.Origin.Z);
                        SafeNativeMethods.Quaternion qtmp;
                        qtmp.X = req.orientation.X;
                        qtmp.Y = req.orientation.Y;
                        qtmp.Z = req.orientation.Z;
                        qtmp.W = req.orientation.W;
                        SafeNativeMethods.GeomSetQuaternion(Box, ref qtmp);
                    }
                    else if (req.callbackMethod is ProbeSphereCallback)
                    {
                        if (CollisionContactGeomsPerTest > 80)
                        {
                            CollisionContactGeomsPerTest = 80;
                        }

                        SafeNativeMethods.GeomSphereSetRadius(Sphere, req.length);
                        SafeNativeMethods.GeomSetPosition(Sphere, req.Origin.X, req.Origin.Y, req.Origin.Z);
                    }
                    else if (req.callbackMethod is ProbePlaneCallback)
                    {
                        if (CollisionContactGeomsPerTest > 80)
                        {
                            CollisionContactGeomsPerTest = 80;
                        }

                        SafeNativeMethods.GeomPlaneSetParams(Plane, req.Normal.X, req.Normal.Y, req.Normal.Z, req.length);
                    }

                    else
                    {
                        if (CollisionContactGeomsPerTest > 25)
                        {
                            CollisionContactGeomsPerTest = 25;
                        }

                        SafeNativeMethods.GeomRaySetLength(ray, req.length);
                        SafeNativeMethods.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
                        SafeNativeMethods.GeomRaySetParams(ray, 0, backfacecull);

                        if (req.callbackMethod is RaycastCallback)
                        {
                            // if we only want one get only one per Collision pair saving memory
                            CurrentRayFilter |= RayFilterFlags.ClosestHit;
                            SafeNativeMethods.GeomRaySetClosestHit(ray, 1);
                        }
                        else
                        {
                            SafeNativeMethods.GeomRaySetClosestHit(ray, closestHit);
                        }
                    }

                    if ((CurrentRayFilter & RayFilterFlags.ContactsUnImportant) != 0)
                    {
                        unchecked
                        {
                            CollisionContactGeomsPerTest |= (int)SafeNativeMethods.CONTACTS_UNIMPORTANT;
                        }
                    }

                    if (geom == IntPtr.Zero)
                    {
                        // translate ray filter to Collision flags
                        catflags = 0;
                        if ((CurrentRayFilter & RayFilterFlags.volumedtc) != 0)
                        {
                            catflags |= CollisionCategories.VolumeDtc;
                        }
                        if ((CurrentRayFilter & RayFilterFlags.phantom) != 0)
                        {
                            catflags |= CollisionCategories.Phantom;
                        }
                        if ((CurrentRayFilter & RayFilterFlags.agent) != 0)
                        {
                            catflags |= CollisionCategories.Character;
                        }
                        if ((CurrentRayFilter & RayFilterFlags.PrimsNonPhantom) != 0)
                        {
                            catflags |= CollisionCategories.Geom;
                        }
                        if ((CurrentRayFilter & RayFilterFlags.land) != 0)
                        {
                            catflags |= CollisionCategories.Land;
                        }
                        if ((CurrentRayFilter & RayFilterFlags.water) != 0)
                        {
                            catflags |= CollisionCategories.Water;
                        }

                        if (catflags != 0)
                        {
                            if (req.callbackMethod is ProbeBoxCallback)
                            {
                                catflags |= CollisionCategories.Space;
                                SafeNativeMethods.GeomSetCollideBits(Box, (uint)catflags);
                                SafeNativeMethods.GeomSetCategoryBits(Box, (uint)catflags);
                                doProbe(req, Box);
                            }
                            else if (req.callbackMethod is ProbeSphereCallback)
                            {
                                catflags |= CollisionCategories.Space;
                                SafeNativeMethods.GeomSetCollideBits(Sphere, (uint)catflags);
                                SafeNativeMethods.GeomSetCategoryBits(Sphere, (uint)catflags);
                                doProbe(req, Sphere);
                            }
                            else if (req.callbackMethod is ProbePlaneCallback)
                            {
                                catflags |= CollisionCategories.Space;
                                SafeNativeMethods.GeomSetCollideBits(Plane, (uint)catflags);
                                SafeNativeMethods.GeomSetCategoryBits(Plane, (uint)catflags);
                                doPlane(req, IntPtr.Zero);
                            }
                            else
                            {
                                SafeNativeMethods.GeomSetCollideBits(ray, (uint)catflags);
                                doSpaceRay(req);
                            }
                        }
                    }
                    else
                    {
                        // if we select a geom don't use filters

                        if (req.callbackMethod is ProbePlaneCallback)
                        {
                            SafeNativeMethods.GeomSetCollideBits(Plane, (uint)CollisionCategories.All);
                            doPlane(req, geom);
                        }
                        else
                        {
                            SafeNativeMethods.GeomSetCollideBits(ray, (uint)CollisionCategories.All);
                            doGeomRay(req, geom);
                        }
                    }
                }

                if (Util.EnvironmentTickCountSubtract(time) > MaxTimePerCallMS)
                {
                    break;
                }
            }

            lock (m_contactResults)
                m_contactResults.Clear();

            return(Util.EnvironmentTickCountSubtract(time));
        }