Esempio n. 1
0
    void Update()
    {
        if (Input.GetButtonDown("PauseTime") && EventSystem.current.currentSelectedGameObject == null)
        {
            if (useFixedTime == false)
            {
                StopTime();
            }
            else
            {
                useFixedTime = false;
            }
        }
        if (Input.GetButtonDown("TimeForward") && EventSystem.current.currentSelectedGameObject == null)
        {
            StopTime();
            fixedHour += 1;
        }
        if (Input.GetButtonDown("TimeReverse") && EventSystem.current.currentSelectedGameObject == null)
        {
            StopTime();
            fixedHour -= 1;
        }
        if (fixedHour >= 24)
        {
            fixedHour -= 24;
        }
        if (fixedHour < 0)
        {
            fixedHour += 24;
        }

        realTime = DFConnection.Instance.DFTime;

        if (DFConnection.Instance.DfPauseState)
        {
            Time.timeScale = 0;
            lastSeconds    = Time.realtimeSinceStartup;
            lastTicks      = realTime.CurrentYearTicks;
        }
        if (realTime.CurrentYearTicks != lastTicks)
        {
            float currentSeconds   = Time.realtimeSinceStartup;
            var   tickDifference   = realTime.CurrentYearTicks - lastTicks;
            var   secondDifference = currentSeconds - lastSeconds;
            Time.timeScale = Mathf.Clamp((tickDifference / secondDifference) / CanonFPS, 0, 100);
            lastSeconds    = currentSeconds;
            lastTicks      = realTime.CurrentYearTicks;
        }
        lastTicks = realTime.CurrentYearTicks;

        if (useFixedTime)
        {
            DisplayedTime = new DFTime(realTime.Year, realTime.Month, realTime.Day, fixedHour, 0);
        }
        else
        {
            DisplayedTime = realTime;
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (Input.GetButtonDown("PauseTime"))
        {
            if (useFixedTime == false)
                StopTime();
            else
                useFixedTime = false;
        }
        if (Input.GetButtonDown("TimeForward"))
        {
            StopTime();
            fixedHour += 1;
        }
        if (Input.GetButtonDown("TimeReverse"))
        {
            StopTime();
            fixedHour -= 1;
        }
        if (fixedHour >= 24)
            fixedHour -= 24;
        if (fixedHour < 0)
            fixedHour += 24;

        realTime = DFConnection.Instance.DFTime;

        if (useFixedTime)
            DisplayedTime = new DFTime(realTime.Year, realTime.Month, realTime.Day, fixedHour, 0);
        else
            DisplayedTime = realTime;
    }
Esempio n. 3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            if (useFixedTime == false)
                StopTime();
            else
                useFixedTime = false;
        }
        if (Input.GetKeyDown(KeyCode.RightBracket))
        {
            StopTime();
            fixedHour += 1;
        }
        if (Input.GetKeyDown(KeyCode.LeftBracket))
        {
            StopTime();
            fixedHour -= 1;
        }
        if (fixedHour >= 24)
            fixedHour -= 24;
        if (fixedHour < 0)
            fixedHour += 24;

        if (useFixedTime)
            displayedTime = new DFTime(realTime.Year, realTime.Month, realTime.Day, fixedHour, 0);
        else
            displayedTime = realTime;
    }
Esempio n. 4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var currentYearTicks = property.FindPropertyRelative("currentYearTicks");
        var year = property.FindPropertyRelative("year");
        DFTime time = new DFTime();
        time.CurrentYearTicks = currentYearTicks.intValue;
        time.Year = year.intValue;

        Rect runningPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

        unfolded = EditorGUI.Foldout(runningPosition, unfolded, label);

        if (unfolded)
        {
            runningPosition.y += EditorGUIUtility.singleLineHeight;
            EditorGUI.LabelField(runningPosition, time.ToString(), EditorStyles.boldLabel);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int yearLocal = EditorGUI.IntField(runningPosition, "Year", time.Year);
            if (time.Year != yearLocal)
                time.Year = yearLocal;

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int currentYearTicksLocal = EditorGUI.IntField(runningPosition, "Current Year Ticks", time.CurrentYearTicks);
            if (time.CurrentYearTicks != currentYearTicksLocal)
                time.CurrentYearTicks = currentYearTicksLocal;

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            DFTime.MonthName monthName = (DFTime.MonthName)EditorGUI.EnumPopup(runningPosition, "Month", time.MonthEnum);
            if (time.MonthEnum != monthName)
                time.MonthEnum = monthName;

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int monthInt = EditorGUI.IntField(runningPosition, "Month", time.Month);
            if (time.Month != monthInt)
                time.Month = monthInt;

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int day = EditorGUI.IntField(runningPosition, "Day", time.Day);
            if (time.Day != day)
                time.Day = day;

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int dayTicks = EditorGUI.IntField(runningPosition, "CurrentDayTicks", time.DayTicks);
            if (time.DayTicks != dayTicks)
                time.DayTicks = dayTicks;
        }

        currentYearTicks.intValue = time.CurrentYearTicks;
        year.intValue = time.Year;
    }
Esempio n. 5
0
    void Update()
    {
        if (Input.GetButtonDown("PauseTime") && EventSystem.current.currentSelectedGameObject == null)
        {
            if (useFixedTime == false)
            {
                StopTime();
            }
            else
            {
                useFixedTime = false;
            }
        }
        if (Input.GetButtonDown("TimeForward") && EventSystem.current.currentSelectedGameObject == null)
        {
            StopTime();
            fixedHour += 1;
        }
        if (Input.GetButtonDown("TimeReverse") && EventSystem.current.currentSelectedGameObject == null)
        {
            StopTime();
            fixedHour -= 1;
        }
        if (fixedHour >= 24)
        {
            fixedHour -= 24;
        }
        if (fixedHour < 0)
        {
            fixedHour += 24;
        }

        realTime = DFConnection.Instance.DFTime;

        if (useFixedTime)
        {
            DisplayedTime = new DFTime(realTime.Year, realTime.Month, realTime.Day, fixedHour, 0);
        }
        else
        {
            DisplayedTime = realTime;
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Performs a single update.
    /// </summary>
    /// <exception cref="System.Exception"></exception>
    void PerformSingleUpdate()
    {
        //pause df here, so it doesn't try to resume while we're working.
        networkClient.SuspendGame();

        //everything that controls DF.
        #region DF Control

        if (mapResetRequested.Pop())
        {
            mapResetCall.TryExecute();
        }

        if (digCommandCall != null)
        {
            while (netDigCommands.Count > 0)
            {
                digCommandCall.TryExecute(netDigCommands.Dequeue());
            }
        }
        if (setSideMenuCall != null)
        {
            while (netSidebarSets.Count > 0)
            {
                setSideMenuCall.TryExecute(netSidebarSets.Dequeue());
            }
        }
        if (pauseCommandCall != null)
        {
            while (pauseCommands.Count > 0)
            {
                pauseCommandCall.TryExecute(pauseCommands.Dequeue());
            }
        }
        if (keyboardEventCall != null)
        {
            KeyboardEvent dfEvent;
            while (keyPresses.TryDequeue(out dfEvent))
            {
                keyboardEventCall.TryExecute(dfEvent);
            }
        }
        if (moveCommandCall != null)
        {
            while (moveCommands.Count > 0)
            {
                moveCommandCall.TryExecute(moveCommands.Dequeue());
            }
        }
        if (jumpCommandCall != null)
        {
            while (jumpCommands.Count > 0)
            {
                jumpCommandCall.TryExecute(jumpCommands.Dequeue());
            }
        }
        if (movementSelectCommandCall != null)
        {
            while (carefulMoveCommands.Count > 0)
            {
                movementSelectCommandCall.TryExecute(carefulMoveCommands.Dequeue());
            }
        }

        if (miscMoveCall != null)
        {
            while (miscMoveCommands.Count > 0)
            {
                miscMoveCall.TryExecute(miscMoveCommands.Dequeue());
            }
        }

        #endregion

        #region DF Read

        if (menuQueryCall != null)
        {
            AdventureMenuContents = menuQueryCall.Execute();
        }

        if (getSideMenuCall != null)
        {
            SidebarState = getSideMenuCall.Execute();
        }

        if (fetchMap)
        {
            if (mapInfoCall != null)
            {
                var mapInfo = mapInfoCall.Execute();
                if (mapInfo == null)
                {
                    if (netMapInfo != null)
                    {
                        lock (mapInfoLock)
                        {
                            embarkMapPosition = new DFCoord(-1, -1, -1);
                            embarkMapSize     = new DFCoord(0, 0, 0);
                            MapDataStore.InitMainMap(embarkMapSize.x * 16, embarkMapSize.y * 16, embarkMapSize.z);
                        }
                    }
                }
                else
                {
                    if ((netMapInfo == null) ||
                        mapInfo.block_pos_x != netMapInfo.block_pos_x ||
                        mapInfo.block_pos_y != netMapInfo.block_pos_y ||
                        mapInfo.block_pos_z != netMapInfo.block_pos_z ||
                        mapInfo.block_size_x != netMapInfo.block_size_x ||
                        mapInfo.block_size_y != netMapInfo.block_size_y ||
                        mapInfo.block_size_z != netMapInfo.block_size_z)
                    {
                        lock (mapInfoLock)
                        {
                            embarkMapPosition = new DFCoord(mapInfo.block_pos_x, mapInfo.block_pos_y, mapInfo.block_pos_z);
                            embarkMapSize     = new DFCoord(mapInfo.block_size_x, mapInfo.block_size_y, mapInfo.block_size_z);
                            MapDataStore.InitMainMap(EmbarkMapSize.x * 16, EmbarkMapSize.y * 16, EmbarkMapSize.z);
                            mapResetCall.TryExecute();
                        }
                    }
                }
                netMapInfo = mapInfo;
            }
            if (viewInfoCall != null)
            {
                ViewInfo viewInfo;
                viewInfoCall.TryExecute(null, out viewInfo);
                netViewInfo.Set(viewInfo);
            }
        }
        if (fetchScreen)
        {
            if (copyScreenCall != null)
            {
                RemoteFortressReader.ScreenCapture screenCapture;
                copyScreenCall.TryExecute(null, out screenCapture);
                netScreenCapture.Set(screenCapture);
            }
        }

        BlockCoord.Range?requestRangeUpdate = requestRegion.Pop();

        if (requestRangeUpdate != null)
        {
            blockRequest.min_x = requestRangeUpdate.Value.Min.x * GameMap.blockSize / 16;
            blockRequest.min_y = requestRangeUpdate.Value.Min.y * GameMap.blockSize / 16;
            blockRequest.min_z = requestRangeUpdate.Value.Min.z;
            blockRequest.max_x = requestRangeUpdate.Value.Max.x * GameMap.blockSize / 16;
            blockRequest.max_y = requestRangeUpdate.Value.Max.y * GameMap.blockSize / 16;
            blockRequest.max_z = requestRangeUpdate.Value.Max.z;
        }

        if (fetchUnits)
        {
            if (unitListCall != null)
            {
                UnitList unitList = unitListCall.Execute(blockRequest);
                netUnitList.Set(unitList);
            }
            else if (unitListCallLegacy != null)
            {
                UnitList unitList = unitListCallLegacy.Execute();
                netUnitList.Set(unitList);
            }
        }

        if (fetchWorldMap)
        {
            if (worldMapCenterCall != null)
            {
                WorldMap tempWorldMap;
                worldMapCenterCall.TryExecute(null, out tempWorldMap);
                if (tempWorldMap != null)
                {
                    DFTime = new DFTime(tempWorldMap.cur_year, tempWorldMap.cur_year_tick);
                }
                if (netWorldMapCenter == null || (tempWorldMap != null &&
                                                  (netWorldMapCenter.center_x != tempWorldMap.center_x ||
                                                   netWorldMapCenter.center_y != tempWorldMap.center_y)))
                {
                    if (worldMapCall != null)
                    {
                        WorldMap worldMap;
                        worldMapCall.TryExecute(null, out worldMap);
                        netWorldMap.Set(worldMap);
                    }

                    netWorldMapCenter = tempWorldMap;

                    worldMapMoved.Set();
                    if (regionMapCall != null)
                    {
                        RegionMaps regionMaps;
                        regionMapCall.TryExecute(null, out regionMaps);
                        netRegionMaps.Set(regionMaps);
                    }
                    nextRegionUpdate = DateTime.Now.AddSeconds(0.2); //add another region map update after this one, to get delayed regions.s
                }
            }


            if (nextRegionUpdate < DateTime.Now)
            {
                if (regionMapCall != null)
                {
                    RegionMaps regionMaps;
                    regionMapCall.TryExecute(null, out regionMaps);
                    netRegionMaps.Set(regionMaps);
                }
                nextRegionUpdate = DateTime.MaxValue;
            }
        }

        if (pauseCommandCall != null)
        {
            SingleBool status;
            pauseStatusCall.TryExecute(null, out status);
            if (status != null)
            {
                _dfPauseState = status.Value;
            }
        }

        // since enqueueing results can block, we do it after we've unsuspended df
        BlockList resultList = null;
        if (fetchMap)
        {
            if (EmbarkMapSize.x > 0 &&
                EmbarkMapSize.y > 0 &&
                EmbarkMapSize.z > 0 && _needNewBlocks)
            {
                if (blockListCall != null)
                {
                    //Don't pull more blocks than we have room for in the queue. It blocks things unneccesarily.
                    blockRequest.blocks_needed = Mathf.Min(blockRequest.blocks_needed, pendingBlocks.Capacity - pendingBlocks.Count - 1);
                    if (blockRequest.blocks_needed > 0)
                    {
                        resultList = blockListCall.Execute(blockRequest);
                    }
                }
            }
        }

        Status stat = null;
        if (reportsCall != null)
        {
            reportsCall.TryExecute(null, out stat);
            if (stat != null)
            {
                netStatus.Set(stat);
            }
        }
        #endregion

        //All communication with DF should be before this.
        networkClient.ResumeGame();

        if (resultList != null)
        {
            try
            {
                foreach (MapBlock mapBlock in resultList.map_blocks)
                {
                    pendingBlocks.Enqueue(mapBlock);
                }
                engravings.Enqueue(resultList.engravings);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            waves            = resultList.ocean_waves;
            UpdatedAnyBlocks = true;
        }
    }
Esempio n. 7
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var    ticks = property.FindPropertyRelative("_ticks");
        DFTime time  = new DFTime(ticks.longValue);

        Rect runningPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

        unfolded = EditorGUI.Foldout(runningPosition, unfolded, label);

        if (unfolded)
        {
            runningPosition.y += EditorGUIUtility.singleLineHeight;
            EditorGUI.LabelField(runningPosition, time.ToString(), EditorStyles.boldLabel);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int yearLocal = EditorGUI.IntField(runningPosition, "Year", time.Year);
            if (time.Year != yearLocal)
            {
                time = new DFTime(yearLocal, time.CurrentYearTicks);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int currentYearTicksLocal = EditorGUI.IntField(runningPosition, "Current Year Ticks", time.CurrentYearTicks);
            if (time.CurrentYearTicks != currentYearTicksLocal)
            {
                time = new DFTime(time.Year, currentYearTicksLocal);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            DFTime.MonthName monthName = (DFTime.MonthName)EditorGUI.EnumPopup(runningPosition, "Month", time.MonthEnum);
            if (time.MonthEnum != monthName)
            {
                time = new DFTime(time.Year, (int)monthName + 1, time.Day, time.Hour, time.Minute, time.Second, time.Millisecond);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int monthInt = EditorGUI.IntField(runningPosition, "Month", time.Month);
            monthInt = Mathf.Clamp(monthInt, 1, 12);
            if (time.Month != monthInt)
            {
                time = new DFTime(time.Year, monthInt, time.Day, time.Hour, time.Minute, time.Second, time.Millisecond);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int day = EditorGUI.IntField(runningPosition, "Day", time.Day);
            day = Mathf.Clamp(day, 1, 28);
            if (time.Day != day)
            {
                time = new DFTime(time.Year, time.Month, day, time.Hour, time.Minute, time.Second, time.Millisecond);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int hour = EditorGUI.IntField(runningPosition, "Hour", time.Hour);
            hour = Mathf.Clamp(hour, 0, 24);
            if (time.Hour != hour)
            {
                time = new DFTime(time.Year, time.Month, time.Day, hour, time.Minute, time.Second, time.Millisecond);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int minute = EditorGUI.IntField(runningPosition, "Minute", time.Minute);
            minute = Mathf.Clamp(minute, 0, 59);
            if (time.Minute != minute)
            {
                time = new DFTime(time.Year, time.Month, time.Day, time.Hour, minute, time.Second, time.Millisecond);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int second = EditorGUI.IntField(runningPosition, "Second", time.Second);
            second = Mathf.Clamp(second, 0, 59);
            if (time.Second != second)
            {
                time = new DFTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, second, time.Millisecond);
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int milli = EditorGUI.IntField(runningPosition, "Millisecond", time.Millisecond);
            milli = Mathf.Clamp(milli, 0, 999);
            if (time.Millisecond != milli)
            {
                time = new DFTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second, milli);
            }
        }

        ticks.longValue = time.Ticks;
    }
    /// <summary>
    /// Performs a single update.
    /// </summary>
    /// <exception cref="System.Exception"></exception>
    void PerformSingleUpdate()
    {
        networkClient.suspend_game();

        if (mapResetRequested.Pop())
        {
            mapResetCall.execute();
        }

        if (mapInfoCall != null)
        {
            RemoteFortressReader.MapInfo mapInfo;
            mapInfoCall.execute(null, out mapInfo);
            if (mapInfo == null)
            {
                if (netMapInfo != null)
                {
                    lock (mapInfoLock)
                    {
                        embarkMapPosition = new DFCoord(-1, -1, -1);
                        embarkMapSize     = new DFCoord(0, 0, 0);
                        MapDataStore.InitMainMap(embarkMapSize.x * 16, embarkMapSize.y * 16, embarkMapSize.z);
                    }
                }
            }
            else
            {
                if ((netMapInfo == null) ||
                    mapInfo.block_pos_x != netMapInfo.block_pos_x ||
                    mapInfo.block_pos_y != netMapInfo.block_pos_y ||
                    mapInfo.block_pos_z != netMapInfo.block_pos_z ||
                    mapInfo.block_size_x != netMapInfo.block_size_x ||
                    mapInfo.block_size_y != netMapInfo.block_size_y ||
                    mapInfo.block_size_z != netMapInfo.block_size_z)
                {
                    lock (mapInfoLock)
                    {
                        embarkMapPosition = new DFCoord(mapInfo.block_pos_x, mapInfo.block_pos_y, mapInfo.block_pos_z);
                        embarkMapSize     = new DFCoord(mapInfo.block_size_x, mapInfo.block_size_y, mapInfo.block_size_z);
                        MapDataStore.InitMainMap(EmbarkMapSize.x * 16, EmbarkMapSize.y * 16, EmbarkMapSize.z);
                        mapResetCall.execute();
                    }
                }
            }
            netMapInfo = mapInfo;
        }

        if (viewInfoCall != null)
        {
            RemoteFortressReader.ViewInfo viewInfo;
            viewInfoCall.execute(null, out viewInfo);
            netViewInfo.Set(viewInfo);
        }
        if (copyScreenCall != null)
        {
            RemoteFortressReader.ScreenCapture screenCapture;
            copyScreenCall.execute(null, out screenCapture);
            netScreenCapture.Set(screenCapture);
        }

        if (unitListCall != null)
        {
            RemoteFortressReader.UnitList unitList;
            unitListCall.execute(null, out unitList);
            netUnitList.Set(unitList);
        }

        if (worldMapCenterCall != null)
        {
            RemoteFortressReader.WorldMap tempWorldMap;
            worldMapCenterCall.execute(null, out tempWorldMap);
            if (tempWorldMap != null)
            {
                DFTime = new DFTime(tempWorldMap.cur_year, tempWorldMap.cur_year_tick);
            }
            if (netWorldMapCenter == null || (tempWorldMap != null &&
                                              (netWorldMapCenter.center_x != tempWorldMap.center_x ||
                                               netWorldMapCenter.center_y != tempWorldMap.center_y)))
            {
                if (worldMapCall != null)
                {
                    RemoteFortressReader.WorldMap worldMap;
                    worldMapCall.execute(null, out worldMap);
                    netWorldMap.Set(worldMap);
                }

                netWorldMapCenter = tempWorldMap;

                worldMapMoved.Set();
                if (regionMapCall != null)
                {
                    RemoteFortressReader.RegionMaps regionMaps;
                    regionMapCall.execute(null, out regionMaps);
                    netRegionMaps.Set(regionMaps);
                }
                nextRegionUpdate = DateTime.Now.AddSeconds(0.2); //add another region map update after this one, to get delayed regions.s
            }
        }


        if (nextRegionUpdate < DateTime.Now)
        {
            if (regionMapCall != null)
            {
                RemoteFortressReader.RegionMaps regionMaps;
                regionMapCall.execute(null, out regionMaps);
                netRegionMaps.Set(regionMaps);
            }
            nextRegionUpdate = DateTime.MaxValue;
        }


        if (keyboardEventCall != null)
        {
            RemoteFortressReader.KeyboardEvent dfEvent;
            while (keyPresses.TryDequeue(out dfEvent))
            {
                keyboardEventCall.execute(dfEvent);
            }
        }

        // since enqueueing results can block, we do it after we've unsuspended df
        RemoteFortressReader.BlockList resultList = null;

        if (EmbarkMapSize.x > 0 &&
            EmbarkMapSize.y > 0 &&
            EmbarkMapSize.z > 0)
        {
            BlockCoord.Range?requestRangeUpdate = requestRegion.Pop();

            if (requestRangeUpdate != null)
            {
                blockRequest.min_x = requestRangeUpdate.Value.Min.x;
                blockRequest.min_y = requestRangeUpdate.Value.Min.y;
                blockRequest.min_z = requestRangeUpdate.Value.Min.z;
                blockRequest.max_x = requestRangeUpdate.Value.Max.x;
                blockRequest.max_y = requestRangeUpdate.Value.Max.y;
                blockRequest.max_z = requestRangeUpdate.Value.Max.z;
            }

            if (blockListCall != null)
            {
                blockListCall.execute(blockRequest, out resultList);
            }
        }
        networkClient.resume_game();

        if (resultList != null)
        {
            foreach (RemoteFortressReader.MapBlock mapBlock in resultList.map_blocks)
            {
                pendingBlocks.Enqueue(mapBlock);
            }
        }
    }
Esempio n. 9
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var    currentYearTicks = property.FindPropertyRelative("currentYearTicks");
        var    year             = property.FindPropertyRelative("year");
        DFTime time             = new DFTime();

        time.CurrentYearTicks = currentYearTicks.intValue;
        time.Year             = year.intValue;

        Rect runningPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

        unfolded = EditorGUI.Foldout(runningPosition, unfolded, label);

        if (unfolded)
        {
            runningPosition.y += EditorGUIUtility.singleLineHeight;
            EditorGUI.LabelField(runningPosition, time.ToString(), EditorStyles.boldLabel);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int yearLocal = EditorGUI.IntField(runningPosition, "Year", time.Year);
            if (time.Year != yearLocal)
            {
                time.Year = yearLocal;
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int currentYearTicksLocal = EditorGUI.IntField(runningPosition, "Current Year Ticks", time.CurrentYearTicks);
            if (time.CurrentYearTicks != currentYearTicksLocal)
            {
                time.CurrentYearTicks = currentYearTicksLocal;
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            DFTime.MonthName monthName = (DFTime.MonthName)EditorGUI.EnumPopup(runningPosition, "Month", time.MonthEnum);
            if (time.MonthEnum != monthName)
            {
                time.MonthEnum = monthName;
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int monthInt = EditorGUI.IntField(runningPosition, "Month", time.Month);
            if (time.Month != monthInt)
            {
                time.Month = monthInt;
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int day = EditorGUI.IntField(runningPosition, "Day", time.Day);
            if (time.Day != day)
            {
                time.Day = day;
            }

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int dayTicks = EditorGUI.IntField(runningPosition, "CurrentDayTicks", time.DayTicks);
            if (time.DayTicks != dayTicks)
            {
                time.DayTicks = dayTicks;
            }
        }

        currentYearTicks.intValue = time.CurrentYearTicks;
        year.intValue             = time.Year;
    }
Esempio n. 10
0
    /// <summary>
    /// Performs a single update.
    /// </summary>
    /// <exception cref="System.Exception"></exception>
    void PerformSingleUpdate()
    {
        //pause df here, so it doesn't try to resume while we're working.
        networkClient.suspend_game();

        //everything that controls DF.
        #region DF Control

        if (mapResetRequested.Pop())
        {
            mapResetCall.execute();
        }

        if (digCommandCall != null)
        {
            while (netDigCommands.Count > 0)
            {
                digCommandCall.execute(netDigCommands.Dequeue());
            }
        }
        if (pauseCommandCall != null)
        {
            while (pauseCommands.Count > 0)
            {
                pauseCommandCall.execute(pauseCommands.Dequeue());
            }
        }
        if (keyboardEventCall != null)
        {
            KeyboardEvent dfEvent;
            while (keyPresses.TryDequeue(out dfEvent))
            {
                keyboardEventCall.execute(dfEvent);
            }
        }

        #endregion

        #region DF Read

        if (fetchMap)
        {
            if (mapInfoCall != null)
            {
                MapInfo mapInfo;
                mapInfoCall.execute(null, out mapInfo);
                if (mapInfo == null)
                {
                    if (netMapInfo != null)
                    {
                        lock (mapInfoLock)
                        {
                            embarkMapPosition = new DFCoord(-1, -1, -1);
                            embarkMapSize     = new DFCoord(0, 0, 0);
                            MapDataStore.InitMainMap(embarkMapSize.x * 16, embarkMapSize.y * 16, embarkMapSize.z);
                        }
                    }
                }
                else
                {
                    if ((netMapInfo == null) ||
                        mapInfo.block_pos_x != netMapInfo.block_pos_x ||
                        mapInfo.block_pos_y != netMapInfo.block_pos_y ||
                        mapInfo.block_pos_z != netMapInfo.block_pos_z ||
                        mapInfo.block_size_x != netMapInfo.block_size_x ||
                        mapInfo.block_size_y != netMapInfo.block_size_y ||
                        mapInfo.block_size_z != netMapInfo.block_size_z)
                    {
                        lock (mapInfoLock)
                        {
                            embarkMapPosition = new DFCoord(mapInfo.block_pos_x, mapInfo.block_pos_y, mapInfo.block_pos_z);
                            embarkMapSize     = new DFCoord(mapInfo.block_size_x, mapInfo.block_size_y, mapInfo.block_size_z);
                            MapDataStore.InitMainMap(EmbarkMapSize.x * 16, EmbarkMapSize.y * 16, EmbarkMapSize.z);
                            mapResetCall.execute();
                        }
                    }
                }
                netMapInfo = mapInfo;
            }
            if (viewInfoCall != null)
            {
                ViewInfo viewInfo;
                viewInfoCall.execute(null, out viewInfo);
                netViewInfo.Set(viewInfo);
            }
        }
        if (fetchScreen)
        {
            if (copyScreenCall != null)
            {
                ScreenCapture screenCapture;
                copyScreenCall.execute(null, out screenCapture);
                netScreenCapture.Set(screenCapture);
            }
        }

        if (fetchUnits)
        {
            if (unitListCall != null)
            {
                UnitList unitList;
                unitListCall.execute(null, out unitList);
                netUnitList.Set(unitList);
            }
        }

        if (fetchWorldMap)
        {
            if (worldMapCenterCall != null)
            {
                WorldMap tempWorldMap;
                worldMapCenterCall.execute(null, out tempWorldMap);
                if (tempWorldMap != null)
                {
                    DFTime = new DFTime(tempWorldMap.cur_year, tempWorldMap.cur_year_tick);
                }
                if (netWorldMapCenter == null || (tempWorldMap != null &&
                                                  (netWorldMapCenter.center_x != tempWorldMap.center_x ||
                                                   netWorldMapCenter.center_y != tempWorldMap.center_y)))
                {
                    if (worldMapCall != null)
                    {
                        WorldMap worldMap;
                        worldMapCall.execute(null, out worldMap);
                        netWorldMap.Set(worldMap);
                    }

                    netWorldMapCenter = tempWorldMap;

                    worldMapMoved.Set();
                    if (regionMapCall != null)
                    {
                        RegionMaps regionMaps;
                        regionMapCall.execute(null, out regionMaps);
                        netRegionMaps.Set(regionMaps);
                    }
                    nextRegionUpdate = DateTime.Now.AddSeconds(0.2); //add another region map update after this one, to get delayed regions.s
                }
            }


            if (nextRegionUpdate < DateTime.Now)
            {
                if (regionMapCall != null)
                {
                    RegionMaps regionMaps;
                    regionMapCall.execute(null, out regionMaps);
                    netRegionMaps.Set(regionMaps);
                }
                nextRegionUpdate = DateTime.MaxValue;
            }
        }

        if (pauseCommandCall != null)
        {
            SingleBool status;
            pauseStatusCall.execute(null, out status);
            if (status != null)
            {
                _dfPauseState = status.Value;
            }
        }

        // since enqueueing results can block, we do it after we've unsuspended df
        BlockList resultList = null;
        if (fetchMap)
        {
            if (EmbarkMapSize.x > 0 &&
                EmbarkMapSize.y > 0 &&
                EmbarkMapSize.z > 0 && _needNewBlocks)
            {
                BlockCoord.Range?requestRangeUpdate = requestRegion.Pop();

                if (requestRangeUpdate != null)
                {
                    blockRequest.min_x = requestRangeUpdate.Value.Min.x;
                    blockRequest.min_y = requestRangeUpdate.Value.Min.y;
                    blockRequest.min_z = requestRangeUpdate.Value.Min.z;
                    blockRequest.max_x = requestRangeUpdate.Value.Max.x;
                    blockRequest.max_y = requestRangeUpdate.Value.Max.y;
                    blockRequest.max_z = requestRangeUpdate.Value.Max.z;
                }

                if (blockListCall != null)
                {
                    blockListCall.execute(blockRequest, out resultList);
                }
            }
        }
        #endregion

        //All communication with DF should be before this.
        networkClient.resume_game();

        if (resultList != null)
        {
            foreach (MapBlock mapBlock in resultList.map_blocks)
            {
                pendingBlocks.Enqueue(mapBlock);
            }
        }
    }
Esempio n. 11
0
 void CopyClouds(WorldMap remoteMap)
 {
     if (remoteMap == null)
     {
         Debug.Log("Didn't get world map!");
         return;
     }
     timeHolder.realTime = new DFTime(remoteMap.cur_year, remoteMap.cur_year_tick);
     if (timeHolder.realTime - lastUpdateTime < new System.TimeSpan(1, 0, 0))
         return;
     lastUpdateTime = timeHolder.realTime;
     for (int x = 0; x < width; x++)
         for (int y = 0; y < height; y++)
         {
             int index = y * remoteMap.world_width + x;
             cumulusMedium[x, y] = remoteMap.clouds[index].cumulus == CumulusType.CUMULUS_MEDIUM;
             cumulusMulti[x, y] = remoteMap.clouds[index].cumulus == CumulusType.CUMULUS_MULTI;
             cumulusNimbus[x, y] = remoteMap.clouds[index].cumulus == CumulusType.CUMULUS_NIMBUS;
             stratusAlto[x, y] = remoteMap.clouds[index].stratus == StratusType.STRATUS_ALTO;
             stratusProper[x, y] = remoteMap.clouds[index].stratus == StratusType.STRATUS_PROPER;
             stratusNimbus[x, y] = remoteMap.clouds[index].stratus == StratusType.STRATUS_NIMBUS;
             cirrus[x, y] = remoteMap.clouds[index].cirrus;
             fogMist[x, y] = remoteMap.clouds[index].fog == FogType.FOG_MIST;
             fogNormal[x, y] = remoteMap.clouds[index].fog == FogType.FOG_NORMAL;
             fogThick[x, y] = remoteMap.clouds[index].fog == FogType.F0G_THICK;
         }
     GenerateClouds();
 }
Esempio n. 12
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var ticks = property.FindPropertyRelative("_ticks");
        DFTime time = new DFTime(ticks.longValue);

        Rect runningPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

        unfolded = EditorGUI.Foldout(runningPosition, unfolded, label);

        if (unfolded)
        {
            runningPosition.y += EditorGUIUtility.singleLineHeight;
            EditorGUI.LabelField(runningPosition, time.ToString(), EditorStyles.boldLabel);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int yearLocal = EditorGUI.IntField(runningPosition, "Year", time.Year);
            if (time.Year != yearLocal)
                time = new DFTime(yearLocal, time.CurrentYearTicks);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int currentYearTicksLocal = EditorGUI.IntField(runningPosition, "Current Year Ticks", time.CurrentYearTicks);
            if (time.CurrentYearTicks != currentYearTicksLocal)
                time = new DFTime(time.Year, currentYearTicksLocal);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            DFTime.MonthName monthName = (DFTime.MonthName)EditorGUI.EnumPopup(runningPosition, "Month", time.MonthEnum);
            if (time.MonthEnum != monthName)
                time = new DFTime(time.Year, (int)monthName + 1, time.Day, time.Hour, time.Minute, time.Second, time.Millisecond);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int monthInt = EditorGUI.IntField(runningPosition, "Month", time.Month);
            monthInt = Mathf.Clamp(monthInt, 1, 12);
            if (time.Month != monthInt)
                time = new DFTime(time.Year, monthInt, time.Day, time.Hour, time.Minute, time.Second, time.Millisecond);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int day = EditorGUI.IntField(runningPosition, "Day", time.Day);
            day = Mathf.Clamp(day, 1, 28);
            if (time.Day != day)
                time = new DFTime(time.Year, time.Month, day, time.Hour, time.Minute, time.Second, time.Millisecond);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int hour = EditorGUI.IntField(runningPosition, "Hour", time.Hour);
            hour = Mathf.Clamp(hour, 0, 24);
            if (time.Hour != hour)
                time = new DFTime(time.Year, time.Month, time.Day, hour, time.Minute, time.Second, time.Millisecond);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int minute = EditorGUI.IntField(runningPosition, "Minute", time.Minute);
            minute = Mathf.Clamp(minute, 0, 59);
            if (time.Minute != minute)
                time = new DFTime(time.Year, time.Month, time.Day, time.Hour, minute, time.Second, time.Millisecond);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int second = EditorGUI.IntField(runningPosition, "Second", time.Second);
            second = Mathf.Clamp(second, 0, 59);
            if (time.Second != second)
                time = new DFTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, second, time.Millisecond);

            runningPosition.y += EditorGUIUtility.singleLineHeight;
            int milli = EditorGUI.IntField(runningPosition, "Millisecond", time.Millisecond);
            milli = Mathf.Clamp(milli, 0, 999);
            if (time.Millisecond != milli)
                time = new DFTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second, milli);
        }

        ticks.longValue = time.Ticks;
    }