Exemplo n.º 1
0
        static public void ProcessWorld(IRealtimeCallback _callback)
        {
            //if another Process is taking care of it, return
            if (IsProcessingMatches())
            {
                return;
            }

            var _context = GetDatabaseContext();
            //skipping time == jumping to the first upcoming event(s) and processes those
            //
            DateTime next_date = GetEarliestEvent(_context);


            GetWorldState().AsyncProcessesCount++;

            _callback.OnWorldStateChanged(GetWorldState());
            //set world date
            GetWorldState().CurrentDateTime = next_date;
            _context.SaveChanges();

            ProcessGameTick(_context, _callback, true);

            GetWorldState().AsyncProcessesCount--;
            _context.SaveChanges();
            _callback.OnWorldStateChanged(GetWorldState());
        }
Exemplo n.º 2
0
        static private void ProcessGameTick(SoccerWorldDatabaseContext _context, IRealtimeCallback _callback, bool first_run = false)
        {
            //check if new CompetitionEvents are found, and activate them
            ExecuteCompetitionEvents(_context, _callback, GetWorldState().CurrentDateTime);

            //check if new matches found on current time, to add to matches-pool
            UpdateMatchPool(_context, _callback, GetWorldState().CurrentDateTime);
            //if matches-pool is empty
            if (_MATCHES.Count == 0)
            {
                //  end Process
                return;
            }

            //else process all matches
            ProcessMatchPool();
            GetWorldState().CurrentDateTime = GetWorldState().CurrentDateTime.AddMinutes(1);
            GetDatabaseContext().SaveChanges();
            if (_MATCHES.Count > 0)
            {
                _callback.OnMatchesChanged(_MATCHES);
            }

            _callback.OnWorldStateChanged(GetWorldState());

            Thread.Sleep(2000);
            ProcessGameTick(_context, _callback);
        }
Exemplo n.º 3
0
        static private void ProcessWorld(SoccerWorldDatabaseContext _context, IRealtimeCallback _callback, DateTime target_date)
        {
            //if another Process is taking care of it, return
            if (IsProcessingMatches())
            {
                return;
            }

            //as long we did not reach target date
            while (GetWorldState().CurrentDateTime < target_date)
            {
                DateTime eventdate = GetEarliestEvent(_context);
                //update world date with the first next date (target or event)
                GetWorldState().CurrentDateTime = (eventdate < target_date ? eventdate : target_date);


                GetWorldState().AsyncProcessesCount++;
                _context.SaveChanges();
                _callback.OnWorldStateChanged(GetWorldState());
                ProcessGameTick(_context, _callback, true);
                GetWorldState().AsyncProcessesCount--;
                _context.SaveChanges();
            }
        }