Exemplo n.º 1
0
        private static void MainLoop(string fileName, MumbleLink ml)
        {
            while (!ShouldExit())
            {
                MumbleLink.LinkedMem  state;
                MumbleLink.GW2Context context;
                ml.Read(out state, out context);

                string newContents = genContents(state, context);
                if (newContents != oldContents)
                {
                    File.WriteAllText(fileName, newContents);

                    DayNightCycle.TimeOfDay tod = DayNightCycle.Classify();
                    Console.WriteLine("{0}: Updated file: GW2MapId = {1}, "
                                      + "GW2TOD = {2}, GW2Active = {3}.",
                                      DateTime.Now,
                                      context.mapId, (int)tod, active ? 1 : 0);

                    oldContents = newContents;
                    Thread.Sleep(WriteDelayMs);
                }

                Thread.Sleep(PollIntervalMs);
            }
        }
Exemplo n.º 2
0
        public static TimeOfDay Classify()
        {
            double time = DayNightCycle.Time();

            if (time < 5 / 120.0)
            {
                return(TimeOfDay.Dawn);
            }
            if (time < 75 / 120.0)
            {
                return(TimeOfDay.Day);
            }
            if (time < 80 / 120.0)
            {
                return(TimeOfDay.Dusk);
            }
            return(TimeOfDay.Night);
        }
Exemplo n.º 3
0
        private static string genContents(
            MumbleLink.LinkedMem state, MumbleLink.GW2Context context)
        {
            currentTick++;
            if (lastUiTickValue != state.uiTick)
            {
                lastChangedTick = currentTick;
            }
            lastUiTickValue = state.uiTick;
            active          = currentTick - lastChangedTick < ActivityTimeoutTicks;

            return(String.Format("#define GW2MapId {0}\n"
                                 + "#define GW2TOD {1}\n"
                                 + "#define GW2Active {2}\n"
                                 + "#define TimeZone {3}\n",
                                 context.mapId,
                                 (int)DayNightCycle.Classify(),
                                 active ? 1 : 0,
                                 (int)TimeZone.CurrentTimeZone.GetUtcOffset(
                                     DateTime.Now).TotalSeconds));
        }