Пример #1
0
        public BoxedData GetLocalGeoDataOfExitElements(int wmId, int parentObjectId)
        {
            BoxedData             data       = new BoxedData();
            List <GeoDataElement> resultList = null;
            string msg = "";

            try
            {
                WorldPlaceData worldPlace = GetWorldPlaceByWmId(wmId);
                if (worldPlace == null)
                {
                    throw new Exception("world place not found!");
                }

                PlaceInstance placeInstance = worldPlace.GetPredefinedInstanceByParentObjectId(parentObjectId);
                if (placeInstance == null)
                {
                    throw new Exception("place instance not found!");
                }

                resultList = placeInstance.GetGeoDataOfExitElements();
            }
            catch (Exception exception)
            {
                msg = $"An error occured while getting geo data (exit elements), wm_id [{wmId}] parent obj, ID [{parentObjectId}]: {exception.Message}";
            }

            data.Data = (resultList ?? new List <GeoDataElement>());
            data.Msg  = msg;
            return(data);
        }
Пример #2
0
        public BoxedData GetLocalGeoData(int wmId, int parentObjectId, Point3 <int> from, Point3 <int> to)
        {
            BoxedData             data       = new BoxedData();
            List <GeoDataElement> resultList = null;
            string msg = "";

            try
            {
                #region Bounds

                int pointFromX = from.X - DbTerrainObjectDefinitions.MaxCollisionXOfAllObjects;
                int pointFromY = from.Y - DbTerrainObjectDefinitions.MaxCollisionYOfAllObjects;
                int pointFromZ = from.Z - DbTerrainObjectDefinitions.MaxCollisionZOfAllObjects;
                //Console.WriteLine($"mod. point from [{pointFromX}, {pointFromY}, {pointFromZ}]");

                Point3 <int> pointFromTemp = new Point3 <int>
                                             (
                    (pointFromX <= to.X ? pointFromX - 1 : to.X - 1), //NOTE: -1 to prevent rounding error
                    (pointFromY <= to.Y ? pointFromY - 1 : to.Y - 1), //NOTE: -1 to prevent rounding error
                    (pointFromZ <= to.Z ? pointFromZ - 1 : to.Z - 1)  //NOTE: -1 to prevent rounding error
                                             );

                Point3 <int> pointToTemp = new Point3 <int>
                                           (
                    (from.X >= to.X ? from.X + 1 : to.X + 1), //NOTE: +1 to prevent rounding error
                    (from.Y >= to.Y ? from.Y + 1 : to.Y + 1), //NOTE: +1 to prevent rounding error
                    (from.Z >= to.Z ? from.Z + 1 : to.Z + 1)  //NOTE: +1 to prevent rounding error
                                           );

                #endregion

                WorldPlaceData worldPlace = GetWorldPlaceByWmId(wmId);
                if (worldPlace == null)
                {
                    throw new Exception("world place not found!");
                }

                PlaceInstance placeInstance = worldPlace.GetPredefinedInstanceByParentObjectId(parentObjectId);
                if (placeInstance == null)
                {
                    throw new Exception("place instance not found!");
                }

                resultList = placeInstance.GetGeoData(pointFromTemp, pointToTemp);
            }
            catch (Exception exception)
            {
                msg = $"An error occured while getting geo data, wm_id [{wmId}] parent obj, ID [{parentObjectId}]: {exception.Message}";
            }

            data.Data = (resultList ?? new List <GeoDataElement>());
            data.Msg  = msg;
            return(data);
        }
Пример #3
0
        public async void AddPredefinedInstanceAsync(List <DbTerrainObjectsData> terrainDataList, int parentTerrainObjectId)
        {
            WorldPlaceData.InstanceCreationInProgress = true;

            try
            {
                DeletePredefinedInstanceIfExists(parentTerrainObjectId);

                PlaceInstance instance = new PlaceInstance
                                         (
                    _terrainObjectDefinitionList,
                    _parent.LocalBoundX,
                    _parent.LocalBoundY,
                    _parent.LocalBoundZ,
                    this.WorldPosX,
                    this.WorldPosY,
                    parentTerrainObjectId
                                         );

                bool terrainFillingSuccess = false;
                using (BoxedData terrainFillingPacket = await instance.FillTerrainDetailsTaskStart(terrainDataList))
                {
                    terrainFillingSuccess = (bool)terrainFillingPacket.Data;
                    if (!String.IsNullOrEmpty(terrainFillingPacket.Msg))
                    {
                        _logger.UpdateLog(terrainFillingPacket.Msg);
                    }
                }

                if (terrainFillingSuccess)
                {
                    lock (_instanceLock)
                    {
                        _predefinedPlacesList.Add(instance);
                    }

                    _logger.UpdateLog($"Added predefined instance, ID [{instance.PlaceInstanceId}] world pos. [{this.WorldPosX}, {this.WorldPosY}] parent object ID [{parentTerrainObjectId}]");
                }
                else
                {
                    _logger.UpdateLog("Predefined instance creation failed!");
                }
            }
            catch (Exception exception)
            {
                _logger.UpdateLog($"An error occured during predefined instance creation: {exception.Message}");
            }

            WorldPlaceData.InstanceCreationInProgress = false;
        }
Пример #4
0
        public PlaceInstance GetPredefinedInstanceByParentObjectId(int parentTerrainObjectId) //-1 for main instance
        {
            PlaceInstance result = null;

            lock (_instanceLock)
            {
                foreach (PlaceInstance instance in _predefinedPlacesList)
                {
                    if (instance.TerrainParentId == parentTerrainObjectId)
                    {
                        result = instance;
                        break;
                    }
                }
            }

            return(result);
        }