示例#1
0
        public static string SerializedRNG(AbstractGenerator generator)
        {
            byte[] gen_bytes = ObjectToByteArray(generator);
            string gen_b64   = Convert.ToBase64String(gen_bytes);

            return(gen_b64);
        }
示例#2
0
 public Server(ref ModelTime time,
               AbstractGenerator aTypeGenerator,
               AbstractGenerator bTypeGenerator)
 {
     _time           = time;
     _aTypeGenerator = aTypeGenerator;
     _bTypeGenerator = bTypeGenerator;
     IsFree          = true;
 }
示例#3
0
    // Start is called before the first frame update
    private void Start()
    {
        SetGameState(GameState.Menu);

        _difficultyParams = _gameSettings.Params.First(param => param.Difficulty == _gameDifficulty);

        var diamondGenerator = _randomDiamondGeneration
            ? (AbstractDiamondGenerator) new RandomDiamondGenerator(_diamondPrefab, 5)
            : new SeriesDiamondGenerator(_diamondPrefab, 5);

        _generator = new CubeLevelGenerator(_subTilePrefab, _startPlatformWidth, diamondGenerator);
    }
示例#4
0
        public Model(
            AbstractGenerator sourceAGenerator,
            AbstractGenerator sourceBGenerator,
            AbstractGenerator serverAGenerator,
            AbstractGenerator serverBGenerator,
            ModelTime maxTime)
        {
            _time   = new ModelTime();
            MaxTime = maxTime;

            Source = new Source(ref _time, sourceAGenerator, sourceBGenerator);
            Drain  = new Drain(ref _time);

            Queue  = new Queue(ref _time);
            Server = new Server(ref _time, serverAGenerator, serverBGenerator);
        }
        public static Cell Reproduction(int x, int y, Tuple <Cell, Cell> parents, AbstractGenerator randomGenerator = null)
        {
            if (randomGenerator == null)
            {
                randomGenerator = defaultGenerator;
            }

            byte TakeMax(byte d1, byte d2) => d1 > d2 ? d1 : d2;

            (Cell parentA, Cell parentB) = parents;
            int choice = randomGenerator.Next(3);

            Cell offspring = new Cell(new Point(x, y));

            switch (choice)
            {
            case 0:
            {
                offspring.R = TakeMax(parentA.R, parentB.R);
                offspring.G = TakeMax(parentA.G, parentB.G);
                offspring.B = TakeMax(parentA.B, parentB.B);

                return(offspring);
            }

            case 1:
            {
                offspring.R = TakeMax(parentA.B, parentB.B);
                offspring.G = TakeMax(parentA.R, parentB.R);
                offspring.B = TakeMax(parentA.G, parentB.G);

                return(offspring);
            }

            case 2:
            {
                offspring.R = TakeMax(parentA.G, parentB.G);
                offspring.G = TakeMax(parentA.B, parentB.B);
                offspring.B = TakeMax(parentA.R, parentB.R);

                return(offspring);
            }

            default:
                throw new Exception("BAD CHOICE");
            }
        }
示例#6
0
        public Source(ref ModelTime time,
                      AbstractGenerator aTypeGenerator,
                      AbstractGenerator bTypeGenerator)
        {
            _time           = time;
            _aTypeGenerator = aTypeGenerator;
            _bTypeGenerator = bTypeGenerator;

            NextAGenerationTime = new ModelTime()
            {
                Time = _time.Time + _aTypeGenerator.Next()
            };
            NextBGenerationTime = new ModelTime()
            {
                Time = _time.Time + _bTypeGenerator.Next()
            };
        }
 /// <summary>
 /// Flushes an icon to disk.
 /// </summary>
 /// <param name="name">The name of the icon resource.</param>
 /// <param name="path">The name the flushed icon should have.</param>
 /// <param name="generator"> </param>
 public static void FlushIcon( string name, AbstractGenerator generator, string path  )
 {
     Log.InfoFormat( "Flushing '{0}'...", path );
       using(
     Stream resourceStream =
       Assembly.GetExecutingAssembly().GetManifestResourceStream(
     string.Format( "Typo3ExtensionGenerator.Resources.Icons.{0}", name ) ) ) {
     byte[] buffer = new byte[16 * 1024];
     using( MemoryStream ms = new MemoryStream() ) {
       int read;
       while( ( read = resourceStream.Read( buffer, 0, buffer.Length ) ) > 0 ) {
     ms.Write( buffer, 0, read );
       }
       generator.WriteFile( path, ms.ToArray(), DateTime.UtcNow );
     }
       }
 }
示例#8
0
        public async Task <DataTable> Abstract <T>(string whereTerm           = null, FilterRequest filter = null,
                                                   SqlTransaction transaction = null)
        {
            var result = new DataTable();
            var type   = typeof(T);
            await Task.Run(() =>
            {
                var query = new AbstractGenerator().GetAbstractQuery(type, whereTerm, filter);
                using (var connection = _connectionService.Create())
                {
                    using (SqlDataAdapter adp = new SqlDataAdapter(query, connection))
                    {
                        adp.Fill(result);
                    }
                }
            });

            return(result);
        }
示例#9
0
    /**Updates the tunnel meshes with the generated ones **/
    public void updateMeshes(AbstractGenerator generator)
    {
        List <Geometry.Mesh> proceduralMesh = generator.getMesh();
        long verticesNum = 0, trianglesNum = 0;
        int  actTunel = 0;

        //Tunnels
        foreach (Geometry.Mesh m in proceduralMesh)           //Attach the generated tunnels to Unity stuff
        //Check if a new tunnel has produced from last call
        {
            if (actTunel >= tunnelsList.Count)
            {
                createNewMeshGameObject(actTunel, "Tunnel");
            }
            //Update count
            verticesNum  += m.getNumVertices();
            trianglesNum += m.getNumTriangles();
            //Smooth the mesh
            if (generator.finished)
            {
                m.smooth(smoothItAfterGen);
            }
            //Attach it to game object
            UnityEngine.Mesh mesh = getUnityMesh(m, generator.finished);
            //Assing it to the corresponding game object
            GameObject tunnel = tunnelsList [actTunel];
            tunnel.GetComponent <MeshFilter> ().mesh        = mesh;
            tunnel.GetComponent <MeshCollider>().sharedMesh = mesh;
            ++actTunel;
        }
        //Stalagmites
        List <Geometry.Mesh> stalgmMesh = generator.getStalagmitesMesh();
        long verticesStalNum = 0, trianglesStalNum = 0;
        int  actStalgm = 0;

        foreach (Geometry.Mesh m in stalgmMesh)           //Attach the generated tunnels to Unity stuff
        //Check if a new tunnel has produced from last call
        {
            if (actStalgm >= stalgmList.Count)
            {
                createNewMeshGameObject(actStalgm, "Stalagmites");
            }
            //Update count
            verticesStalNum  += m.getNumVertices();
            trianglesStalNum += m.getNumTriangles();
            //Attach it to game object
            UnityEngine.Mesh mesh = getUnityMesh(m, generator.finished);
            //Assing it to the corresponding game object
            GameObject stalgm = stalgmList[actStalgm];
            stalgm.GetComponent <MeshFilter> ().mesh        = mesh;
            stalgm.GetComponent <MeshCollider>().sharedMesh = mesh;
            ++actStalgm;
        }
        //Mesh size
        if (generator.finished)
        {
            Debug.Log("Vertices generated from tunnels: " + verticesNum);
            Debug.Log("Triangles generated from tunnels: " + trianglesNum);
            Debug.Log("Vertices generated from stalagmites: " + verticesStalNum);
            Debug.Log("Triangles generated from stalagmites: " + trianglesStalNum);
            //Put the player on scene
            preparePlayer(initialPoints);
            Debug.Log("Cave generated");
        }
    }
 private void Awake()
 {
     generator = (AbstractGenerator)target;
 }
示例#11
0
 public void RegisterStoryboardGenerator(AbstractGenerator generator)
 {
     storyboardGenerators.Add(generator);
 }
        /// <summary>
        /// Generates the interface.
        /// </summary>
        /// <param name="parent">The generator that uses this <see cref="InterfaceGenerator"/>.</param>
        /// <param name="extension">The extension that is being worked on.</param>
        /// <param name="subject">The model for the interface defintion.</param>
        /// <param name="format">The format of the interface.</param>
        /// <returns></returns>
        /// <exception cref="GeneratorException">No display type given in interface.</exception>
        public static string Generate( AbstractGenerator parent, Extension extension, Typo3ExtensionGenerator.Model.Configuration.Interface.Interface subject, SimpleContainer.Format format )
        {
            string propertyTemplate = ( format == SimpleContainer.Format.PhpArray )
                                  ? SimpleContainer.PropertyTemplatePHP
                                  : SimpleContainer.PropertyTemplateXML;

              StringBuilder interfaceDefinition = new StringBuilder();

              // exclude
              interfaceDefinition.Append( string.Format( propertyTemplate, "exclude", subject.Exclude ? "1" : "0" ) );
              // label
              string labelLanguageConstant = string.Format(
            "{0}.{1}", NameHelper.GetAbsoluteModelName( extension, subject.ParentModel ),
            NameHelper.LowerUnderscoredCase( subject.Target ) );

              if( format == SimpleContainer.Format.PhpArray ) {
            interfaceDefinition.Append(
              string.Format(
            propertyTemplate, "label",
            string.Format(
              "'LLL:EXT:{0}/Resources/Private/Language/locallang_db.xml:{1}'", extension.Key,
              labelLanguageConstant ) ) );
              } else {
            interfaceDefinition.Append(
              string.Format(
            propertyTemplate, "label",
            string.Format(
              "LLL:EXT:{0}/Resources/Private/Language/locallang_db.xml:{1}", extension.Key,
              labelLanguageConstant ) ) );
              }

              parent.WriteVirtual( "Resources/Private/Language/locallang_db.xml", string.Format( "<label index=\"{0}\">{1}</label>", labelLanguageConstant, subject.Title ) );

              // config
              string configuration = string.Empty;

              // Add foreign_table
              if( subject.ParentModel.ForeignModels.ContainsKey( subject.Target ) ) {
            DataModel foreignModel = subject.ParentModel.ForeignModels[ subject.Target ];
            string typename = ( String.IsNullOrEmpty( foreignModel.InternalType ) )
                            ? NameHelper.GetAbsoluteModelName( extension, foreignModel )
                            : foreignModel.InternalType;

            subject.DisplayType.ParentModel = foreignModel;

            if( format == SimpleContainer.Format.PhpArray ) {
              configuration += String.Format( propertyTemplate, "foreign_table", "'" + typename + "'" );
              configuration += String.Format( propertyTemplate, "foreign_table_where", "'AND " + typename + ".sys_language_uid=0'" );
              configuration += String.Format( propertyTemplate, "allowed", "'" + typename + "'" );

            } else {
              configuration += String.Format( propertyTemplate, "foreign_table", typename );
              configuration += String.Format( propertyTemplate, "foreign_table_where", "AND " + typename + ".sys_language_uid=0" );
              configuration += String.Format( propertyTemplate, "allowed", typename );
            }
              }

              if( null != subject.DisplayType ) {
            // Add any additional properties to the configuration
            configuration += DisplayTypeGenerator.GeneratePropertyArray( extension, subject.DisplayType, format );

            if( format == SimpleContainer.Format.PhpArray ) {
              configuration += String.Format( propertyTemplate, "type", "'" + subject.DisplayType.Name + "'" );

            } else {
              configuration += String.Format( propertyTemplate, "type", subject.DisplayType.Name );
            }
              } else {
            throw new GeneratorException( string.Format( "No display type given in interface for '{0}'!", subject.Target ), subject.SourceFragment.SourceDocument );
              }

              if( null != subject.DefaultValue ) {
            if( format == SimpleContainer.Format.PhpArray ) {
              configuration += String.Format( propertyTemplate, "default", "'" + subject.DefaultValue + "'" );

            } else {
              configuration += String.Format( propertyTemplate, "default", subject.DefaultValue );
            }
              }

              // Trim trailing comma
              configuration = configuration.TrimEnd( new[] {','} );

              // Add the 'config' array to the interface
              if( format == SimpleContainer.Format.PhpArray ) {
            interfaceDefinition.Append( string.Format( propertyTemplate, "config", "array(" + configuration + ")" ) );
              } else {
            interfaceDefinition.Append( string.Format( propertyTemplate, "config", configuration ) );
              }
              // Add any additional parameters set in the interface
              interfaceDefinition.Append( subject.GeneratePropertyArray( SimpleContainer.Format.PhpArray)  );

              string finalInterface = interfaceDefinition.ToString().TrimEnd( new[] {','} );
              return finalInterface;
        }
示例#13
0
 public GeneratorImpl(GenerationModel generationModel)
 {
     _generationModel = generationModel;
     _generator       = GeneratorResolver.getGenerator(generationModel.GeneratorType);
     _clauseWriter    = new CnfClauseWriter();
 }