Exemple #1
0
 public static void TechniteStateChunk(Protocol.Client cl, Struct.TechniteStateChunk chunk)
 {
     Out.Log(Significance.Common, "Received technite state chunk containing " + chunk.states.Length + " technites");
     if (chunk.FlagIsSet(Struct.TechniteChunkFlags.IsFirst))
     {
         Technite.Reset();
     }
     foreach (var state in chunk.states)
     {
         Technite.CreateOrUpdate(state);
     }
     if (chunk.FlagIsSet(Struct.TechniteChunkFlags.IsLast))
     {
         Technite.Cleanup();
     }
 }
Exemple #2
0
            public static void InstructTechnites(Protocol.Client cl, Struct.InstructTechnites instruct)
            {
                Technite.Cleanup();                     //updates must be done by now
                Session.roundNumber            = instruct.roundNumber;
                Session.techniteSubRoundNumber = instruct.techniteSubRoundNumber;
                Out.Log(Significance.Common, "Instructing technites in round " + Session.roundNumber + "/" + Session.techniteSubRoundNumber);
                Logic.ProcessTechnites();


                SendColorState(cl);

                int numTechnites = Technite.Count;
                int numChunks    = numTechnites / Struct.TechniteInstructionChunk.MaxPerChunk;

                if ((numTechnites % Struct.TechniteInstructionChunk.MaxPerChunk) != 0)
                {
                    numChunks++;
                }


                Out.Log(Significance.Common, "Sending " + numChunks + " technite data response chunks");
                var e      = Technite.All.GetEnumerator();
                int offset = 0;

                for (int i = 0; i < numChunks; i++)
                {
                    int chunkSize = Math.Min(Struct.TechniteInstructionChunk.MaxPerChunk, numTechnites - offset);

                    Struct.TechniteInstructionChunk chunk = new Struct.TechniteInstructionChunk();
                    chunk.offset       = (uint)offset;
                    chunk.instructions = new Struct.TechniteInstruction[chunkSize];
                    for (int j = 0; j < chunkSize; j++)
                    {
                        bool success = e.MoveNext();
                        Debug.Assert(success);
                        Technite t = e.Current;
                        chunk.instructions[j] = t.ExportInstruction();
                    }

                    techniteInstructionChunk.SendTo(cl, chunk);

                    offset += chunkSize;
                }
            }