Esempio n. 1
0
        /// <summary>
        /// Ctor, a DataBase may have a parent if it is part of an external reference node.
        /// </summary>
        /// <param name="file"></param>
        public Database(string file, Record parent, ImportSettings settings)
        {
            Settings               = settings;
            Stream                 = new InStream(file);
            Header                 = this;
            Parent                 = parent;
            MaterialBank           = new MaterialBank();
            ExternalReferencesBank = new ExternalReferencesBank(null);
            if (parent != null)
            {
                parent.Children.Add(this);
                Log = parent.Log;                 // Use the same log
            }
            else
            {
                // Init log
                Log = new Log();

                // Add any additional directorties to our file finder.
                Settings.additionalSearchDirectories.ForEach(o => FileFinder.Instance.AddPath(o));
            }

            Log.Write("Loading file: " + file);

            MaterialPalettes = new Dictionary <int, MaterialPalette>();
            TexturePalettes  = new Dictionary <int, TexturePalette>();

            Opcode = Opcodes.DB;

            // Record the path for when we need to search for textures etc.
            FileFinder.Instance.AddPath(file);

            // Register handlers for this record type
            RootHandler.Handler[Opcodes.Header]          = HandleHeader;
            RootHandler.Handler[Opcodes.PushLevel]       = HandlePush;
            RootHandler.Handler[Opcodes.LongID]          = HandleLongID;
            RootHandler.Handler[Opcodes.Comment]         = HandleComment;
            RootHandler.Handler[Opcodes.ColorPalette]    = HandleColorPalette;
            RootHandler.Handler[Opcodes.TexturePalette]  = HandleTexturePalette;
            RootHandler.Handler[Opcodes.VertexPalette]   = HandleVertexPalette;
            RootHandler.Handler[Opcodes.MaterialPalette] = HandleMaterialPalette;

            ChildHandler.Handler[Opcodes.PushLevel]         = HandlePush;
            ChildHandler.Handler[Opcodes.PopLevel]          = HandlePop;
            ChildHandler.Handler[Opcodes.Object]            = HandleObject;
            ChildHandler.Handler[Opcodes.Switch]            = HandleSwitch;
            ChildHandler.Handler[Opcodes.Sound]             = HandleUnhandled;
            ChildHandler.Handler[Opcodes.ClipRegion]        = HandleUnhandled;
            ChildHandler.Handler[Opcodes.DegreeOfFreedom]   = HandleDOF;
            ChildHandler.Handler[Opcodes.Group]             = HandleGroup;
            ChildHandler.Handler[Opcodes.ExternalReference] = HandleExternalReference;
            ChildHandler.Handler[Opcodes.LevelOfDetail]     = HandleLevelOfDetail;
        }
Esempio n. 2
0
        /// <summary>
        /// Coroutine, Loads the db and textures in a seperate thread. Returns once the
        /// db is loaded and ready to be imported into the scene.
        /// <example>
        /// Database db = new Database( file );
        /// yield return StartCoroutine( db.ParseAsynchronously() ); // Seperate thread
        /// db.ImportIntoScene();
        /// </example>
        /// </summary>
        /// <returns></returns>
        public IEnumerator ParseAsynchronously(MonoBehaviour controller)
        {
            // TODO: Create a gameobject and place a coroutine controller script which we can use instead of asking the user. (What if the users was disabled!!)
            Thread t = new Thread(ParseAndPrepare);

            t.Start();

            // Just keep polling the thread.
            while (t.IsAlive)
            {
                yield return(0);
            }

            // Load textures.
            yield return(controller.StartCoroutine(MaterialBank.LoadTextures()));
        }