Exemple #1
0
        public static void SendColorState(Protocol.Client client)
        {
            colorBuffer.Clear();
            UInt32 at = 0;

            foreach (Technite t in Technite.All)
            {
                if (t.UsesCustomColor)
                {
                    //if (colorBuffer.Count == 0)
                    //	offset = at;
                    colorBuffer.Add(new Struct.Color(at, t.CustomColor));
                }
                //else
                //	if (colorBuffer.Count > 0)
                //{
                //	SendColorChunks(client, offset, colorBuffer);
                //	colorBuffer.Clear();
                //            }
                at++;
            }

            if (colorBuffer.Count > 0)
            {
                SendColorChunks(client, 0, colorBuffer);
                colorBuffer.Clear();
            }
        }
Exemple #2
0
        private static void SendColorChunks(Protocol.Client cl, UInt32 offset, List <Struct.Color> list)
        {
            //Struct.TechniteColorChunk chunk = new Struct.TechniteColorChunk();
            //chunk.offset = offset;
            //chunk.colors = colorBuffer.ToArray();
            //colorBuffer.Clear();
            //techniteColorChunk.SendTo(client, chunk);

            int numVecs   = list.Count();
            int numChunks = numVecs / Struct.TechniteInstructionChunk.MaxPerChunk;

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


            Out.Log(Significance.Common, "Sending " + numChunks + " technite color chunk(s), starting from " + offset);
            int localOffset = 0;

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

                Struct.TechniteColorChunk chunk = new Struct.TechniteColorChunk();
                chunk.offset = offset;
                chunk.colors = new Struct.Color[chunkSize];
                list.CopyTo(localOffset, chunk.colors, 0, chunkSize);
                techniteColorChunk.SendTo(cl, chunk);
                offset      += (uint)chunkSize;
                localOffset += chunkSize;
            }
        }
Exemple #3
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 #4
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;
                }
            }
Exemple #5
0
            internal static void GridConfig(Protocol.Client cl, Struct.GridConfig gridConfig)
            {
                Grid.BeginSession(gridConfig.heightPerLayer, gridConfig.numLayersPerStack);
                if (Technite.MatterYield.Length != gridConfig.matterYieldByContentType.Length)
                {
                    Out.Log(Significance.ProgramFatal, "Received matter yield vector (" + gridConfig.matterYieldByContentType.Length + ") does not match number of supported content types (" + Technite.MatterYield.Length + ").");
                    return;
                }
                if (Technite.MatterDegradeTo.Length != gridConfig.matterDegradationTable.Length)
                {
                    Out.Log(Significance.ProgramFatal, "Received matter degradation vector (" + gridConfig.matterDegradationTable.Length + ") does not match number of supported content types (" + Technite.MatterDegradeTo.Length + ").");
                    return;
                }

                Technite.MatterYield     = gridConfig.matterYieldByContentType;
                Technite.MatterDegradeTo = gridConfig.matterDegradationTable;

                Technite.InitialTTLAtLayer  = gridConfig.initialTTLAtLayer;
                Technite.EnergyYieldAtLayer = gridConfig.energyYieldAtLayer;
            }
Exemple #6
0
 internal static void BeginSession(Protocol.Client arg1, Struct.BeginSession session)
 {
     Session.Begin(session);
 }
Exemple #7
0
 internal static void RemoveGameObject(Protocol.Client arg1, Struct.GameObjectID objID)
 {
     Objects.Remove(objID);
 }
Exemple #8
0
 internal static void RemoveControlMarker(Protocol.Client arg1, UInt32 markerID)
 {
     Objects.RemoveControlMarker(markerID);
 }
Exemple #9
0
 internal static void CreateGameObject(Protocol.Client arg1, Struct.GameObject obj)
 {
     Objects.Add(obj);
 }
Exemple #10
0
 internal static void CreateControlMarker(Protocol.Client arg1, Struct.ControlMarker marker)
 {
     Objects.Add(marker);
 }
Exemple #11
0
 internal static void Error(Protocol.Client client, string message)
 {
     Out.Log(Significance.ProgramFatal, ">" + message);
     client.ForceDisconnect();
     return;
 }
Exemple #12
0
 internal static void WorldInfo(Protocol.Client cl, Struct.WorldInfo worldInfo)
 {
     Grid.World.Setup((Grid.Content)worldInfo.coreContent);
 }
Exemple #13
0
 internal static void NodeChunk(Protocol.Client cl, Struct.NodeChunk nodeChunk)
 {
     Grid.Graph.AddChunk(nodeChunk);
 }
Exemple #14
0
 internal static void GridDelta(Protocol.Client cl, Struct.GridDelta gridDelta)
 {
     Grid.ApplyDelta(gridDelta);
 }