Exemplo n.º 1
0
        static void StreamSystemPrototypeKey <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                             BlamEngine engine,
                                                             ref Values.KGuid systemGuid)
            where TDoc : class
            where TCursor : class
        {
            s.StreamAttribute("guid", ref systemGuid);

            if (s.IsReading)
            {
                string invalid_guid_msg = null;

                if (systemGuid == Values.KGuid.Empty)
                {
                    invalid_guid_msg = "Invalid system guid: ";
                }
                else if (EngineRegistry.TryGetRegisteredSystem(systemGuid) == null)
                {
                    invalid_guid_msg = "Unknown system guid: ";
                }

                if (invalid_guid_msg != null)
                {
                    s.ThrowReadException(new System.IO.InvalidDataException(
                                             invalid_guid_msg +
                                             systemGuid.ToString(Values.KGuid.kFormatHyphenated, Util.InvariantCultureInfo)));
                }
            }
        }
Exemplo n.º 2
0
        public static void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                     ref BlamEngineTargetHandle value)
            where TDoc : class
            where TCursor : class
        {
            bool reading = s.IsReading;

            var build = reading
                                ? EngineBuildHandle.None
                                : value.Build;
            var platform_index = reading
                                ? TypeExtensions.kNone
                                : value.TargetPlatformIndex;
            var rsrc_model_index = reading
                                ? TypeExtensions.kNone
                                : value.ResourceModelIndex;

            EngineBuildHandle.Serialize(s, ref build);
            if (!build.IsNone)
            {
                if (EngineTargetPlatform.SerializeId(s, "targetPlatform", ref platform_index, true))
                {
                    EngineRegistry.SerializeResourceModelId(s, "resourceModel", ref rsrc_model_index, true);
                }
            }

            if (reading)
            {
                value = new BlamEngineTargetHandle(build, platform_index, rsrc_model_index);
            }
        }
Exemplo n.º 3
0
        public BlamEngineTargetHandle(EngineBuildHandle buildHandle, int platformIndex, int resourceModelIndex)
        {
            Contract.Requires <ArgumentOutOfRangeException>(EngineTargetPlatform.IsValidIndex(platformIndex));
            Contract.Requires <ArgumentOutOfRangeException>(EngineRegistry.IsValidResourceModelIndex(resourceModelIndex) ||
                                                            (platformIndex.IsNone() && resourceModelIndex.IsNone()));

            InitializeHandle(out mHandle, buildHandle, platformIndex, resourceModelIndex);
        }
Exemplo n.º 4
0
 void LoadExternsBegin()
 {
     using (var s = EngineRegistry.OpenEngineSystemTagElementStream(
                Engine, Prototype.SystemMetadata.Guid, Prototype.ExternsFile))
     {
         s.Owner = Prototype;
         SerializeExtern(s);
     }
 }
Exemplo n.º 5
0
        void RegisterSystem()
        {
            if (Engine.EngineRegistry.Systems.ContainsKey(Guid))
            {
                throw new InvalidOperationException(string.Format(
                                                        "An engine system other than {0} is already registered with the {1} guid",
                                                        EngineSystemType.Name, Guid.ToString(Values.KGuid.kFormatHyphenated)));
            }

            EngineRegistry.Register(this);
        }
Exemplo n.º 6
0
        void RegisterSystem()
        {
            if (Engine.EngineRegistry.Systems.ContainsKey(SystemGuid))
            {
                throw new InvalidOperationException(string.Format(Util.InvariantCultureInfo,
                                                                  "An engine system other than {0} is already registered with the {1} guid",
                                                                  EngineSystemType.Name, GetSystemGuidString()));
            }

            EngineRegistry.Register(this);
        }
Exemplo n.º 7
0
        EngineSystemBase TryGetSystem(Values.KGuid systemGuid)
        {
            if (!SupportsSystem(systemGuid))
            {
                return(null);
            }

            var system_metadata = EngineRegistry.TryGetRegisteredSystem(systemGuid);

            Contract.Assume(system_metadata != null);

            return(GetNewOrExistingSystem(system_metadata));
        }
Exemplo n.º 8
0
        //internal uint Handle { get { return mHandle; } }

        static void InitializeHandle(out uint handle,
                                     EngineBuildHandle buildHandle, int platformIndex, int resourceModelIndex)
        {
            if (platformIndex.IsNone() && resourceModelIndex.IsNone())
            {
                resourceModelIndex = 0;
            }

            var encoder = new Bitwise.HandleBitEncoder();

            EngineRegistry.BitEncodeResourceModelIndex(ref encoder, resourceModelIndex);
            EngineTargetPlatform.BitEncodeIndex(ref encoder, platformIndex);
            encoder.Encode32(buildHandle.Handle, EngineBuildHandle.Bitmask);

            Contract.Assert(encoder.UsedBitCount == BlamEngineTargetHandle.BitCount);

            handle = encoder.GetHandle32();
        }
Exemplo n.º 9
0
        EngineSystemBase GetSystem(Values.KGuid systemGuid, EngineBuildHandle forBuild)
        {
            if (!SupportsSystem(systemGuid))
            {
                string system_display_name = EngineRegistry.GetSystemDebugDisplayString(systemGuid);

                string msg = string.Format("{0} doesn't support the system {1}",
                                           forBuild.ToDisplayString(), system_display_name);

                throw new InvalidOperationException(msg);
            }

            var system_metadata = EngineRegistry.TryGetRegisteredSystem(systemGuid);

            Contract.Assume(system_metadata != null);

            return(GetNewOrExistingSystem(system_metadata));
        }
Exemplo n.º 10
0
        public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            bool reading = s.IsReading;

            var engine = KSoft.Debug.TypeCheck.CastReference <BlamEngine>(s.UserData);

            if (reading)
            {
                Engine = engine;
            }
            else
            {
                Contract.Assert(engine == Engine);
            }

            if (reading)
            {
                var system_guid = Values.KGuid.Empty;
                s.StreamAttribute("guid", ref system_guid);

                SystemMetadata = EngineRegistry.TryGetRegisteredSystem(system_guid);

                if (SystemMetadata == null)
                {
                    string msg = string.Format(Util.InvariantCultureInfo,
                                               "No system is registered with the GUID {0}",
                                               system_guid.ToString(Values.KGuid.kFormatHyphenated, Util.InvariantCultureInfo));

                    s.ThrowReadException(new System.IO.InvalidDataException(msg));
                }
            }
            else
            {
                Contract.Assert(false, "Writing not supported");
            }

            s.StreamAttribute("externs", this, o => o.ExternsFile);
        }