示例#1
0
    public Region AddRegion(RegionHandle handle, Host host)
    {
        Region     region;
        Capability seedCapability = null;

        if (RegionByHandle.ContainsKey(handle))
        {
            // Region already exists
            region = RegionByHandle[handle];
            Host oldHost = region.Host;
            if (host == oldHost && region.Alive)
            {
                Logger.LogInfo($"Region with handle {handle} already exists and is alive, using existing region.");
                return(region);
            }

            if (host != oldHost)
            {
                Logger.LogWarning($"Region with handle {handle} already exists but with a different host. Removing and creating new.");
            }
            if (region.Alive == false)
            {
                Logger.LogWarning($"Region with handle {handle} already exists but it isn't alive. Removing and creating new.");
            }

            // Save capabilities seed URL
            seedCapability = region.GetCapability(Capability.SEED_CAPABILITY_NAME);

            // Kill the old host, and then we can continue on and add the new host.  We have to kill even if the host
            // matches, because all the agent state for the new camera is completely different.
            RemoveRegion(oldHost);
        }
        else
        {
            Logger.LogInfo($"Region with handle {handle} does not exist, creating a new one.");
        }

        UInt32 iindex = handle.X;
        UInt32 jindex = handle.Y;

        int x = (int)(iindex / WIDTH);
        int y = (int)(jindex / WIDTH);

        Logger.LogInfo($"Adding new region {handle} on {host}.");

        Vector3Double origin_global = handle.ToVector3Double();

        region = new Region(handle, host, WIDTH, WORLD_PATCH_SIZE, WIDTH_IN_METRES);

        if (seedCapability != null)
        {
            region.SetCapability(seedCapability);
        }

        RegionList.Add(region);
        ActiveRegionList.Add(region);
        CulledRegionList.Add(region);
        RegionByHandle[handle] = region;
        RegionByHost[host]     = region;

        // Find all the adjacent regions, and attach them.
        // Generate handles for all of the adjacent regions, and attach them in the correct way.
        // connect the edges
        float        adj_x      = 0f;
        float        adj_y      = 0f;
        float        region_x   = handle.X;
        float        region_y   = handle.Y;
        RegionHandle adj_handle = new RegionHandle(0);

        float width = WIDTH_IN_METRES;

        // Iterate through all directions, and connect neighbors if there.
        for (int dir = 0; dir < 8; dir++)
        {
            adj_x = region_x + width * DirectionAxes[dir, 0];
            adj_y = region_y + width * DirectionAxes[dir, 1];
            if (adj_x >= 0)
            {
                adj_handle.X = (UInt32)adj_x;
            }
            if (adj_y >= 0)
            {
                adj_handle.Y = (UInt32)adj_y;
            }

            if (RegionByHandle.ContainsKey(adj_handle))
            {
                region.ConnectNeighbour(RegionByHandle[adj_handle], (DirectionIndex)dir);
            }
        }

        // TODO: UpdateWaterObjects();

        return(region);
    }
示例#2
0
文件: Region.cs 项目: Siccity/UnitySL
    /// <summary>
    /// Creates a new region
    /// </summary>
    /// <param name="handle"></param>
    /// <param name="host"></param>
    /// <param name="gridsPerRegionEdge"></param>
    /// <param name="gridsPerPatchEdge"></param>
    /// <param name="regionWidth"> in metres</param>
    public Region(RegionHandle handle, Host host, UInt32 gridsPerRegionEdge, UInt32 gridsPerPatchEdge, float regionWidth)
    {
        Host         = host;
        Handle       = handle;
        TimeDilation = 1.0f;

        Name   = "";
        Zoning = "";

        IsCurrentPlayerEstateOwner = false;

        RegionFlags     = RegionFlags.Default;
        RegionProtocols = RegionProtocols.None;
        SimAccess       = SimAccess.Min;

        BillableFactor = 1.0f;

        MaxTasks = DEFAULT_MAX_REGION_WIDE_PRIM_COUNT;

        CentralBakeVersion = 1;

        CpuClassId = 0;
        CpuRatio   = 0;

        ColoName       = "unknown";
        ProductSku     = "unknown";
        ProductName    = "unknown";
        ViewerAssetUrl = "";

        CacheLoaded = false;
        CacheDirty  = false;

        ReleaseNotesRequested     = false;
        CapabilitiesReceived      = false;
        SimulatorFeaturesReceived = false;

        BitsReceived    = 0f;
        PacketsReceived = 0f;

        Dead = false;
        // TODO: LastVisitedEntry = null;
        InvisibilityCheckHistory = 0xffffffff;
        Paused = false;
        RegionCacheHitCount  = 0;
        RegionCacheMissCount = 0;

        Width        = regionWidth;
        OriginGlobal = handle.ToVector3Double();
        //TODO: updateRenderMatrix();

        Land = new Surface(SurfaceType.Land, null);  //TODO: Why not set the region right away?

        // Create the composition layer for the surface
        //Composition = new VolumeLayerComposition (Land, gridsPerRegionEdge, regionWidth / gridsPerRegionEdge);
        //Composition.SetSurface (Land);

        // Create the surfaces
        Land.SetRegion(this);
        Land.Create(gridsPerRegionEdge, gridsPerPatchEdge, OriginGlobal, Width);

        //TODO: ParcelOverlay = new LLViewerParcelOverlay(this, regionWidth);

        //TODO: CalculateCenterGlobal();

        // Create the object lists
        // TODO: InitStats();

        //TODO: create object partitions
        //MUST MATCH declaration of eObjectPartitions
        //ObjectPartition.Add (new LLHUDPartition(this));        //PARTITION_HUD
        //ObjectPartition.Add (new LLTerrainPartition(this));    //PARTITION_TERRAIN
        //ObjectPartition.Add (new LLVoidWaterPartition(this));  //PARTITION_VOIDWATER
        //ObjectPartition.Add (new LLWaterPartition(this));      //PARTITION_WATER
        //ObjectPartition.Add (new LLTreePartition(this));       //PARTITION_TREE
        //ObjectPartition.Add (new LLParticlePartition(this));   //PARTITION_PARTICLE
        //ObjectPartition.Add (new LLGrassPartition(this));      //PARTITION_GRASS
        //ObjectPartition.Add (new LLVolumePartition(this)); //PARTITION_VOLUME
        //ObjectPartition.Add (new LLBridgePartition(this)); //PARTITION_BRIDGE
        //ObjectPartition.Add (new LLAvatarPartition(this)); //PARTITION_AVATAR
        //ObjectPartition.Add (new LLControlAVPartition(this));  //PARTITION_CONTROL_AV
        //ObjectPartition.Add (new LLHUDParticlePartition(this));//PARTITION_HUD_PARTICLE
        //ObjectPartition.Add (new LLVOCachePartition(this)); //PARTITION_VO_CACHE
        //ObjectPartition.Add (null);                    //PARTITION_NONE
        //VOCachePartition = getVOCachePartition();

        // TODO: setCapabilitiesReceivedCallback(boost::bind(&LLAvatarRenderInfoAccountant::scanNewRegion, _1));
    }