示例#1
0
        private static void WriteSnapshot(Dictionary <EntityId, Entity> entities, string snapshotName)
        {
            Debug.Log("Writing snapshot to: " + snapshotName);
            var outputStream = new SnapshotOutputStream(snapshotName);

            foreach (var entry in entities)
            {
                var error = outputStream.WriteEntity(entry.Key, entry.Value);
                if (error.HasValue)
                {
                    Debug.Log(error.Value);
                }
            }

            outputStream.Dispose();
        }
        const string workerType   = "life"; //Layer name not workerType?

        static int Main(string[] arguments)
        {
            Console.WriteLine(String.Format("Generating snapshot file {0}", snapshotPath));
            Assembly.Load("GeneratedCode");

            // https://docs.improbable.io/reference/13.3/csharpsdk/using/snapshots

            // Construct a SnapshotOutputStream to write a snapshot to a file at the string path.
            SnapshotOutputStream sos = new SnapshotOutputStream(snapshotPath);

            var id             = 0;
            var maxRowCount    = 50; //dimensionsInWorldUnits z is 100
            var maxColumnCount = 50; //dimensionsInWorldUnits x is 100

            // TODO: Update to account for center being at (0.0)

            //Create a grid of entities
            for (double y = 0; y < maxRowCount; y++)        //Starts at 0
            {
                for (double x = 0; x < maxColumnCount; x++) //starts at 0
                {
                    id++;                                   //starts at 1
                    var entityId = new EntityId(id);
                    Improbable.Collections.List <EntityId> nList = getNeighbors(x, maxColumnCount, y, maxRowCount, id);
                    bool currIsAlive = RandomBool();
                    bool prevIsAlive = RandomBool();
                    var  entity      = createEntity(workerType, x, y, currIsAlive, 0, prevIsAlive, 0, nList);
                    var  error       = sos.WriteEntity(entityId, entity);
                    if (error.HasValue)
                    {
                        throw new System.SystemException("error saving: " + error.Value);
                    }
                }
            }

            // Writes the end of snapshot header and releases the resources of the SnapshotOutputStream.
            sos.Dispose();

            return(0);
        }
示例#3
0
 public void Dispose()
 {
     snapshotOutputStream.Dispose();
 }