Example #1
0
        public bool Init(bool noPixelShader, bool noPixelWrite, EPlatformType platforms)
        {
            RName noPsShader = RName.GetRName("Shaders/ShadingEnv/Sys/NoPixelShader.shadingenv");
            var   rc         = CEngine.Instance.RenderContext;
            var   shaderDesc = rc.CreateShaderDesc(noPsShader, "PS_Main", EShaderType.EST_PixelShader, new CShaderDefinitions(), platforms);

            if (shaderDesc == null)
            {
                return(false);
            }

            var ps = rc.CreatePixelShader(shaderDesc);

            SDK_GraphicsProfiler_SetEmptyPixelShader(CoreObject, ps.CoreObject);

            if (noPixelWrite)
            {
                CFrameBuffersDesc FBDesc = new CFrameBuffersDesc();
                FBDesc.IsSwapChainBuffer = vBOOL.FromBoolean(false);
                FBDesc.UseDSV            = vBOOL.FromBoolean(false);
                var mFrameBuffer = rc.CreateFrameBuffers(FBDesc);
                if (mFrameBuffer == null)
                {
                    return(false);
                }

                CTexture2DDesc TexDesc = new CTexture2DDesc();
                TexDesc.Init();
                TexDesc.Width     = 1;
                TexDesc.Height    = 1;
                TexDesc.Format    = EPixelFormat.PXF_R8G8B8A8_UNORM;
                TexDesc.BindFlags = (UInt32)(EBindFlags.BF_SHADER_RES | EBindFlags.BF_RENDER_TARGET);
                var Tex2D = rc.CreateTexture2D(TexDesc);

                CShaderResourceViewDesc SRVDesc = new CShaderResourceViewDesc();
                SRVDesc.mTexture2D = Tex2D.CoreObject;
                var SRV = rc.CreateShaderResourceView(SRVDesc);
                mFrameBuffer.BindSRV_RT((UInt32)0, SRV);

                CRenderTargetViewDesc RTVDesc = new CRenderTargetViewDesc();
                RTVDesc.mTexture2D = Tex2D.CoreObject;
                var RTV = rc.CreateRenderTargetView(RTVDesc);
                mFrameBuffer.BindRenderTargetView((UInt32)0, RTV);

                //depth stencil view;
                CDepthStencilViewDesc mDSVDesc = new CDepthStencilViewDesc();
                mDSVDesc.Width  = 1;
                mDSVDesc.Height = 1;
                var mDepthStencilView = rc.CreateDepthStencilView(mDSVDesc);

                mFrameBuffer.BindDepthStencilView(mDepthStencilView);

                SDK_GraphicsProfiler_SetOnePixelFrameBuffers(CoreObject, mFrameBuffer.CoreObject);
            }

            NoPixelShader = noPixelShader;
            NoPixelWrite  = noPixelWrite;

            return(true);
        }
Example #2
0
        public bool InitEngine(string pkgName, CEngineDesc desc, bool isServer = false)
        {
            if (mNativeRttiManager == null)
            {
                PreInitEngine();
            }
            InitVAssembly(isServer);
            IO.Serializer.TypeDescGenerator.Instance.BuildTypes(System.AppDomain.CurrentDomain.GetAssemblies(), (isServer ? ECSType.Server : ECSType.Client));

            var typeRedirectionFile = FileManager.ProjectContent + "typeredirection.xml";

            EngineNS.Rtti.TypeRedirectionHelper.Load(typeRedirectionFile);

            if (desc == null)
            {
                var rn = RName.GetRName($"{nameof(CEngineDesc)}.cfg");
                desc = IO.XmlHolder.CreateObjectFromXML(rn) as CEngineDesc;
                if (desc == null)
                {
                    desc = new CEngineDesc();
                    IO.XmlHolder.SaveObjectToXML(desc, rn);
                }
            }

            mDesc = desc;

            StartSystemThreads();

            MetaClassManager.MetaDirectory = RName.GetRName("MetaClasses");
            MetaClassManager.LoadMetaClasses();
            return(true);
        }
        public async Task SetObjectToEdit(ResourceEditorContext context)
        {
            if (context.ResInfo == null)
            {
                return;
            }

            await Particle_Client.Viewport.WaitInitComplated();

            SetBinding(TitleProperty, new Binding("ResourceName")
            {
                Source = context.ResInfo, Converter = new EditorCommon.Converter.RNameConverter_PureName()
            });

            await Particle_Client.SetObjectToEdit();

            // ResInfo 可能在不同的线程生成的,所以这里强制读取一下文件
            CurrentResourceInfo = await EditorCommon.Resources.ResourceInfoManager.Instance.CreateResourceInfoFromFile(context.ResInfo.AbsInfoFileName, context.ResInfo.ParentBrowser) as Macross.ResourceInfos.MacrossResourceInfo;

            CurrentParticleResourceInfo = CurrentResourceInfo as ParticleResourceInfo;
            UpdateUndoRedoKey();

            Particle_Client.CurrentResourceInfo = CurrentResourceInfo;
            //var ddd = new EngineNS.Bricks.Particle.McParticleEffector();
            await Particle_Client.Load();


            string filename = CurrentResourceInfo.AbsInfoFileName.Replace(CurrentResourceInfo.AbsPath, "").Replace(".macross.rinfo", "");
            string csname   = CurrentResourceInfo.ResourceName.Address + "/" + filename + "_Client.cs";

            if (!EngineNS.CEngine.Instance.FileManager.FileExists(csname))
            {
                await Save();
            }
            else
            {
                if (CurrentParticleResourceInfo.NeedRefresh)
                {
                    await CompileCode(EngineNS.EPlatformType.PLATFORM_WIN);

                    CurrentParticleResourceInfo.NeedRefresh = false;
                    await CurrentParticleResourceInfo.Save();
                }
                //await CompileCode(EngineNS.EPlatformType.PLATFORM_WIN);
                string         pfxcs   = CurrentResourceInfo.AbsInfoFileName.Replace(".rinfo", "");
                EngineNS.RName pfxname = EngineNS.RName.GetRName(pfxcs.Replace(CEngine.Instance.FileManager.ProjectContent, ""));

                await Particle_Client.AddPfxMacross(pfxname);
            }

            //await CompileCode(EngineNS.EPlatformType.PLATFORM_WIN);
        }
Example #4
0
        //public void BindCurrentSwapChain(CSwapChain swapChain)
        //{
        //    SDK_IRenderContext_BindCurrentSwapChain(CoreObject, swapChain.CoreObject);
        //}

        //public static Profiler.TimeScope ScopePresent = Profiler.TimeScopeManager.GetTimeScope(typeof(CRenderContext), nameof(Present));
        //public void Present(UInt32 SyncInterval, UInt32 Flags)
        //{
        //    ScopePresent.Begin();
        //    SDK_IRenderContext_Present(CoreObject, SyncInterval, Flags);
        //    ScopePresent.End();
        //}

        public CShaderResourceView LoadShaderResourceView(RName name)
        {
            unsafe
            {
                var obj = SDK_IRenderContext_LoadShaderResourceView(CoreObject, name.Address);
                if (obj.Pointer == IntPtr.Zero)
                {
                    return(null);
                }
                var rsv = new CShaderResourceView(obj);
                rsv.Name = name;
                return(rsv);
            }
        }
        async Task CompileCode(EngineNS.EPlatformType platform, bool usecache = false)
        {
            if (!Particle_Client.CheckError())
            {
                return;
            }

            CurrentResourceInfo.Version++;

            List <Macross.ResourceInfos.MacrossResourceInfo.CustomFunctionData> functions = new List <Macross.ResourceInfos.MacrossResourceInfo.CustomFunctionData>();

            Particle_Client.CollectFuncDatas(functions);

            //if (CheckCompileResult(await CompileCode(Macross_Client, platform, functions), platform) == false)
            //    return;
            //if (CheckCompileResult(await CompileMacrossCollector(Macross_Client, platform), platform) == false)
            //    return;
            if (await CompileCode(Particle_Client, ECSType.Client, usecache))
            {
                CompileStatusIcon = TryFindResource("Good") as ImageSource;
            }
            else
            {
                CompileStatusIcon = TryFindResource("Fail") as ImageSource;
                EditorCommon.MessageBox.Show($"{platform}平台MacrossScript编译失败!详细信息请编译游戏工程!\r\n");
                return;
            }

            if (platform == EngineNS.EPlatformType.PLATFORM_WIN)
            {
                //var scriptDllName = EngineNS.CEngine.Instance.FileManager.Bin + "MacrossScript.dll";
                //EngineNS.CEngine.Instance.MacrossDataManager.RefreshMacrossCollector();
                //var assembly = EngineNS.CEngine.Instance.MacrossDataManager.MacrossScripAssembly;//EngineNS.Rtti.RttiHelper.GetAssemblyFromDllFileName(EngineNS.CIPlatform.Instance.CSType, scriptDllName, "", true, true);
                //var clsTypeFullName = Macross.Program.GetClassNamespace(CurrentResourceInfo, ECSType.Client) + "." + Macross.Program.GetClassName(CurrentResourceInfo, ECSType.Client);
                //var clsType = assembly.GetType(clsTypeFullName);
                //var clsIdPro = clsType.GetProperty("ClassId");
                //var classId = (EngineNS.Hash64)clsIdPro.GetValue(null);
                //EngineNS.CEngine.Instance.MacrossDataManager.RefreshMacrossData(ref classId, clsType);
                EngineNS.Macross.MacrossFactory.SetVersion(CurrentResourceInfo.ResourceName, CurrentResourceInfo.Version);
            }

            Particle_Client.PG.Instance = null;

            string pfxcs = CurrentResourceInfo.AbsInfoFileName.Replace(".rinfo", "");

            EngineNS.RName pfxname = EngineNS.RName.GetRName(pfxcs.Replace(CEngine.Instance.FileManager.ProjectContent, ""));
            await Particle_Client.AddPfxMacross(pfxname);
        }
Example #6
0
        public async System.Threading.Tasks.Task RefreshAllSaveFiles()
        {
            await Thread.AsyncDummyClass.DummyFunc();

            var files = FileManager.GetFiles(FileManager.ProjectContent, "*.gms", System.IO.SearchOption.AllDirectories);

            foreach (var i in files)
            {
                var rn  = FileManager._GetRelativePathFromAbsPath(i, FileManager.ProjectContent);
                var obj = await MeshManager.CreateMeshAsync(RenderContext, RName.GetRName(rn));

                if (obj != null)
                {
                    obj.SaveMesh();
                }
            }
            files = FileManager.GetFiles(FileManager.ProjectContent, "*.material", System.IO.SearchOption.AllDirectories);
            foreach (var i in files)
            {
                var rn  = FileManager._GetRelativePathFromAbsPath(i, FileManager.ProjectContent);
                var obj = await MaterialManager.GetMaterialAsync(RenderContext, RName.GetRName(rn));

                if (obj != null)
                {
                    obj.SaveMaterial();
                }
            }
            files = FileManager.GetFiles(FileManager.ProjectContent, "*.instmtl", System.IO.SearchOption.AllDirectories);
            foreach (var i in files)
            {
                var rn  = FileManager._GetRelativePathFromAbsPath(i, FileManager.ProjectContent);
                var obj = await MaterialInstanceManager.GetMaterialInstanceAsync(RenderContext, RName.GetRName(rn));

                if (obj != null)
                {
                    obj.SaveMaterialInstance();
                }
            }
        }
Example #7
0
        public async System.Threading.Tasks.Task <T> QueryObject(RName name)
        {
            if (mPool.Count == 0)
            {
                for (int i = 0; i < GrowStep; i++)
                {
                    var obj = await CreateObject(name);

                    lock (mPool)
                    {
                        mPool.Add(obj);
                    }
                }
            }
            lock (this)
            {
                var result = mPool[mPool.Count - 1];
                mPool.RemoveAt(mPool.Count - 1);
                OnObjectQuery(result);
                AliveNumber++;
                return(result);
            }
        }
Example #8
0
        protected override async Task <bool> MoveToFolderOverride(string absFolder, EngineNS.RName currentResourceName)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            throw new InvalidOperationException();
        }
Example #9
0
 protected override Task OnReferencedRNameChangedOverride(ResourceInfo referencedResInfo, EngineNS.RName newRName, EngineNS.RName oldRName)
 {
     throw new NotImplementedException();
 }
Example #10
0
#pragma warning disable 1998
        protected virtual async System.Threading.Tasks.Task <T> CreateObject(RName name)
        {
            return(new T());
        }
Example #11
0
        public async virtual System.Threading.Tasks.Task <T> AwaitResource(CRenderContext rc, RName name)
        {
            await Thread.AsyncDummyClass.DummyFunc();

            return(default(T));
        }
        protected override async Task<bool> MoveToFolderOverride(string absFolder, EngineNS.RName currentResourceName)
        {
            //if (EditorCommon.VersionControl.VersionControlManager.Instance.Enable)
            //{
            //    EditorCommon.VersionControl.VersionControlManager.Instance.Update((EditorCommon.VersionControl.VersionControlCommandResult result) =>
            //    {
            //        if (result.Result != EditorCommon.VersionControl.EProcessResult.Success)
            //        {
            //            EditorCommon.MessageReport.Instance.ReportMessage(EditorCommon.MessageReport.enMessageType.Error, $"资源浏览器:{ResourceTypeName}{Name}移动到目录{absFolder}失败!");
            //        }
            //        else
            //        {
            //            EditorCommon.VersionControl.VersionControlManager.Instance.Move((EditorCommon.VersionControl.VersionControlCommandResult resultMove) =>
            //            {
            //                if (resultMove.Result != EditorCommon.VersionControl.EProcessResult.Success)
            //                {
            //                    EditorCommon.MessageReport.Instance.ReportMessage(EditorCommon.MessageReport.enMessageType.Error, $"资源浏览器:{ResourceTypeName}{Name}移动到目录{absFolder}失败!");
            //                }
            //            }, absResourceFile, absFolder + ResourceFileName, $"AutoCommit {ResourceTypeName}{Name}从{EngineNS.CEngine.Instance.FileManager._GetRelativePathFromAbsPath(absResourceFile)}移动到{EngineNS.CEngine.Instance.FileManager._GetRelativePathFromAbsPath(absFolder + ResourceFileName)}");
            //            EditorCommon.VersionControl.VersionControlManager.Instance.Move((EditorCommon.VersionControl.VersionControlCommandResult resultMove) =>
            //            {
            //                if (resultMove.Result != EditorCommon.VersionControl.EProcessResult.Success)
            //                {
            //                    EditorCommon.MessageReport.Instance.ReportMessage(EditorCommon.MessageReport.enMessageType.Error, $"资源浏览器:{ResourceTypeName}{Name}移动到目录{absFolder}失败!");
            //                }
            //            }, absResourceFile + CCore.Graphics.TextureImageInfo.Suffix, absFolder + ResourceFileName + CCore.Graphics.TextureImageInfo.Suffix, $"AutoCommit {ResourceTypeName}{Name}从{EngineNS.CEngine.Instance.FileManager._GetRelativePathFromAbsPath(absResourceFile)}移动到{EngineNS.CEngine.Instance.FileManager._GetRelativePathFromAbsPath(absFolder + ResourceFileName)}");

            //            DoChangeReferencesRef(absResourceFile, absFolder + ResourceFileName);
            //            MoveInfoAction?.Invoke();
            //        }
            //    }, absResourceFile);

            //}
            //else
            //{
            //    try
            //    {
            //        if (System.IO.File.Exists(absFolder + ResourceFileName))
            //        {
            //            EditorCommon.MessageBox.enMessageBoxResult messageBoxResult = EditorCommon.MessageBox.enMessageBoxResult.None;
            //            messageBoxResult = EditorCommon.MessageBox.Show("该文件以存在,是否覆盖", "警告", EditorCommon.MessageBox.enMessageBoxButton.YesNo);
            //            switch (messageBoxResult)
            //            {
            //                case EditorCommon.MessageBox.enMessageBoxResult.Yes:
            //                    {
            //                        System.IO.File.Delete(absFolder + ResourceFileName);
            //                        System.IO.File.Move(absResourceFile, absFolder + ResourceFileName);
            //                        if(System.IO.File.Exists(absResourceFile + CCore.Graphics.TextureImageInfo.Suffix))
            //                        {
            //                            if (System.IO.File.Exists(absFolder + ResourceFileName + CCore.Graphics.TextureImageInfo.Suffix))
            //                            {
            //                                System.IO.File.Delete(absFolder + ResourceFileName + CCore.Graphics.TextureImageInfo.Suffix);
            //                            }
            //                            System.IO.File.Move(absResourceFile + CCore.Graphics.TextureImageInfo.Suffix, absFolder + ResourceFileName + CCore.Graphics.TextureImageInfo.Suffix);
            //                        }
            //                        DoChangeReferencesRef(absResourceFile, absFolder + ResourceFileName);
            //                        System.IO.File.Delete(absResourceFile + EditorCommon.Program.ResourceInfoExt);
            //                        //MoveInfoAction?.Invoke();
            //                    }
            //                    break;
            //                case EditorCommon.MessageBox.enMessageBoxResult.No:

            //                    break;
            //            }
            //        }
            //        else
            //        {
            //            System.IO.File.Move(absResourceFile, absFolder + ResourceFileName);
            //            if (System.IO.File.Exists(absResourceFile + CCore.Graphics.TextureImageInfo.Suffix))
            //                System.IO.File.Move(absResourceFile + CCore.Graphics.TextureImageInfo.Suffix, absFolder + ResourceFileName + CCore.Graphics.TextureImageInfo.Suffix);
            //            DoChangeReferencesRef(absResourceFile, absFolder + ResourceFileName);
            //            MoveInfoAction?.Invoke();
            //        }
            //    }
            //    catch (UnauthorizedAccessException)
            //    {
            //        EditorCommon.MessageReport.Instance.ReportMessage(EditorCommon.MessageReport.enMessageType.Error, $"资源浏览器:资源{Name}移动到目录{absFolder}失败,没有权限!");
            //        return false;
            //    }
            //    catch (PathTooLongException)
            //    {
            //        EditorCommon.MessageReport.Instance.ReportMessage(EditorCommon.MessageReport.enMessageType.Error, $"资源浏览器:资源{Name}移动到目录{absFolder}失败,路径太长!");
            //    }
            //    catch (Exception)
            //    {
            //        EditorCommon.MessageReport.Instance.ReportMessage(EditorCommon.MessageReport.enMessageType.Error, $"资源浏览器:资源{Name}移动到目录{absFolder}失败,路径太长!");
            //    }
            //}

            return true;
        }
Example #13
0
 public virtual T GetResource(CRenderContext rc, RName name, bool firstLoad = false)
 {
     return(default(T));
 }
 protected override bool MoveToFolderOverride(string absFolder, EngineNS.RName resourceName, Action MoveInfoAction)
 {
     return(true);
 }
        protected override async Task <ResourceInfo> CreateResourceInfoFromResourceOverride(EngineNS.RName resourceName)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var retValue = new MacrossEnumResourceInfo();

            return(retValue);
        }
Example #16
0
        public CShaderDesc CreateShaderDesc(RName shader, string entry, EShaderType type, CShaderDefinitions defines, EPlatformType platforms)
        {
            string cachedName = "";
            string sm         = "vs_5_0";
            var    shaderHash = UniHash.APHash(shader.Name + entry + defines.ToString());
            var    macro      = defines.GetHash64().ToString();

            switch (type)
            {
            case EShaderType.EST_ComputeShader:
                cachedName = $"cs/{shaderHash}_{macro}.cshader";
                sm         = "cs_5_0";
                if (ShaderModel == 3)
                {
                    return(null);
                }
                break;

            case EShaderType.EST_VertexShader:
                cachedName = $"vs/{shaderHash}_{macro}.vshader";
                sm         = "vs_5_0";
                break;

            case EShaderType.EST_PixelShader:
                cachedName = $"ps/{shaderHash}_{macro}.pshader";
                sm         = "ps_5_0";
                break;
            }
            var smStr      = CRenderContext.ShaderModelString;
            var shaderFile = CEngine.Instance.FileManager.DDCDirectory + smStr + "/" + cachedName;

            using (var xnd = IO.XndHolder.SyncLoadXND(shaderFile))
            {
                if (xnd != null)
                {
                    bool needCompile = false;
                    var  fileDesc    = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        var hashAttr = xnd.Node.FindAttrib("HashCode");
                        if (hashAttr != null)
                        {
                            hashAttr.BeginRead();
                            string savedHash;
                            hashAttr.Read(out savedHash);
                            hashAttr.EndRead();
                            if (savedHash != fileDesc.HashCode.ToString())
                            {
                                needCompile = true;
                            }
                        }
                    }
                    if (needCompile == false)
                    {
                        CShaderDesc desc = new CShaderDesc(type);
                        desc.LoadXnd(xnd.Node);
                        return(desc);
                    }
                }

                {
                    var xml = IO.XmlHolder.NewXMLHolder($"{type.ToString()}", "");
                    xml.RootNode.AddAttrib("Shader", shader.ToString());
                    xml.RootNode.AddAttrib("Entry", entry);
                    var node = xml.RootNode.AddNode("Macro", "", xml);
                    foreach (var i in defines.mShaderMacroArray)
                    {
                        node.AddAttrib(i.Name, i.Definition);
                    }
                    var fileDesc = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        xml.RootNode.AddAttrib("HashCode", fileDesc.HashCode.ToString());
                    }

                    var shaderDescFile = CEngine.Instance.FileManager.DDCDirectory + "shaderinfo/" + cachedName + ".shaderxml";
                    IO.XmlHolder.SaveXML(shaderDescFile, xml);

                    var desc  = CompileHLSLFromFile(shader.Address, entry, sm, defines, platforms);
                    var saved = IO.XndHolder.NewXNDHolder();

                    if (fileDesc != null)
                    {
                        var hashAttr = saved.Node.AddAttrib("HashCode");
                        hashAttr.BeginWrite();
                        hashAttr.Write(fileDesc.HashCode.ToString());
                        hashAttr.EndWrite();
                    }

                    desc.Save2Xnd(saved.Node, platforms);

                    IO.XndHolder.SaveXND(shaderFile, saved);

                    return(desc);
                }
            }
        }
Example #17
0
        public void CookShaderDesc(RName shader, string entry, EShaderType type, CShaderDefinitions defines, int ShaderModel, EPlatformType platforms)
        {
            string cachedName = "";
            string sm         = "vs_5_0";
            var    shaderHash = UniHash.APHash(shader.Name + entry + defines.ToString());
            var    macro      = defines.GetHash64().ToString();

            switch (type)
            {
            case EShaderType.EST_ComputeShader:
                cachedName = $"cs/{shaderHash}_{macro}.cshader";
                sm         = "cs_5_0";
                if (ShaderModel == 3)
                {
                    return;
                }
                break;

            case EShaderType.EST_VertexShader:
                cachedName = $"vs/{shaderHash}_{macro}.vshader";
                sm         = "vs_5_0";
                break;

            case EShaderType.EST_PixelShader:
                cachedName = $"ps/{shaderHash}_{macro}.pshader";
                sm         = "ps_5_0";
                break;
            }
            var shaderFile = "";

            switch (CIPlatform.Instance.PlayMode)
            {
            case CIPlatform.enPlayMode.Cook:
                shaderFile = CEngine.Instance.FileManager.CookingRoot + "deriveddatacache/" + $"sm{ShaderModel}/" + cachedName;
                break;

            case CIPlatform.enPlayMode.Game:
            case CIPlatform.enPlayMode.Editor:
            case CIPlatform.enPlayMode.PlayerInEditor:
                shaderFile = CEngine.Instance.FileManager.DDCDirectory + $"sm{ShaderModel}/" + cachedName;
                break;
            }
            using (var xnd = IO.XndHolder.SyncLoadXND(shaderFile))
            {
                if (xnd != null)
                {
                    bool needCompile = false;
                    var  fileDesc    = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        var hashAttr = xnd.Node.FindAttrib("HashCode");
                        if (hashAttr != null)
                        {
                            hashAttr.BeginRead();
                            string savedHash;
                            hashAttr.Read(out savedHash);
                            hashAttr.EndRead();
                            if (savedHash != fileDesc.HashCode.ToString())
                            {
                                needCompile = true;
                            }
                        }
                    }
                    if (needCompile == false)
                    {
                        CShaderDesc desc = new CShaderDesc(type);
                        desc.LoadXnd(xnd.Node);
                        return;
                    }
                }

                {
                    var desc  = CompileHLSLFromFile(shader.Address, entry, sm, defines, platforms);
                    var saved = IO.XndHolder.NewXNDHolder();

                    var fileDesc = CEngine.Instance.FileManager.HLSLFileDescManager.FindFileDesc(shader.Address);
                    if (fileDesc != null)
                    {
                        var hashAttr = saved.Node.AddAttrib("HashCode");
                        hashAttr.BeginWrite();
                        hashAttr.Write(fileDesc.HashCode.ToString());
                        hashAttr.EndWrite();
                        desc.Save2Xnd(saved.Node, platforms);
                    }

                    IO.XndHolder.SaveXND(shaderFile, saved);
                }
            }
        }
Example #18
0
        public async System.Threading.Tasks.Task <bool> StartGame(Type gameInstanceType, IntPtr WinHandle, UInt32 width, UInt32 height, EngineNS.GamePlay.GGameInstanceDesc desc, EngineNS.Graphics.CGfxCamera camera, RName startScript)
        {
#if PWindow
            //Bricks.RemoteServices.RPCExecManager.Insance.SaveCode();
#endif
            McGame = CEngine.Instance.MacrossDataManager.NewObjectGetter <GamePlay.McGameInstance>(startScript);

            TickableNum = CEngine.Instance.TickManager.GetTickableNum();
            if (mGameInstance != null && mGameInstance.GameState != GamePlay.GGameInstance.enGameState.Stopped)
            {
                return(false);
            }

            var savedLogic  = CEngine.Instance.ThreadLogic.LimitTime;
            var savedRender = CEngine.Instance.ThreadRHI.LimitTime;
            CEngine.Instance.ThreadLogic.LimitTime = long.MaxValue;
            CEngine.Instance.ThreadRHI.LimitTime   = long.MaxValue;

            mGameInstance           = System.Activator.CreateInstance(gameInstanceType) as GamePlay.GGameInstance;
            mGameInstance.GameState = GamePlay.GGameInstance.enGameState.initializing;
            try
            {
                if (false == await mGameInstance.InitGame(WinHandle, width, height, desc, camera))
                {
                    CEngine.Instance.ThreadLogic.LimitTime = savedLogic;
                    CEngine.Instance.ThreadRHI.LimitTime   = savedRender;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Profiler.Log.WriteException(ex);
            }

            foreach (var i in AutoMembers)
            {
                await i.Key.OnGameStart(i.Value);
            }

            OnGameStarted();

            CEngine.Instance.ThreadLogic.LimitTime = savedLogic;
            CEngine.Instance.ThreadRHI.LimitTime   = savedRender;

            var smp = Thread.ASyncSemaphore.CreateSemaphore(1);
            EngineNS.CEngine.Instance.EventPoster.RunOn(async() =>
            {
                var mcGame = McGame.Get();
                if (mcGame != null)
                {
                    Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Macross", "Macross begin mcGame.OnGameStart");
                    try
                    {
                        await mcGame.OnGameStart(mGameInstance);
                    }
                    catch (Exception ex)
                    {
                        Profiler.Log.WriteException(ex);
                    }
                    Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Macross", "Macross end mcGame.OnGameStart");
                }

                smp.Release();
                return(true);
            }, Thread.Async.EAsyncTarget.Logic);

            await smp.Await();

            mGameInstance.GameState = GamePlay.GGameInstance.enGameState.Initialized;
            await mGameInstance.OnGameInited();

            return(true);
        }
        protected override async Task OnReferencedRNameChangedOverride(ResourceInfo referencedResInfo, EngineNS.RName newRName, EngineNS.RName oldRName)
        {
            if (referencedResInfo.ResourceType == EngineNS.Editor.Editor_RNameTypeAttribute.Material)
            {
                ReferenceRNameList.Remove(ParentMaterialRName);
                if (newRName != null)
                {
                    ParentMaterialRName = referencedResInfo.ResourceName;
                    ReferenceRNameList.Add(ParentMaterialRName);
                }
                await Save();

                var matIns = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(EngineNS.CEngine.Instance.RenderContext, ResourceName);

                EngineNS.CEngine.Instance.MaterialInstanceManager.RemoveMaterialFromDic(ResourceName);
                matIns.OnlySetMaterialName(referencedResInfo.ResourceName);
                matIns.SaveMaterialInstance();
            }
            else if (referencedResInfo.ResourceType == EngineNS.Editor.Editor_RNameTypeAttribute.Texture)
            {
                ReferenceRNameList.Remove(oldRName);
                if (newRName != null)
                {
                    ReferenceRNameList.Add(referencedResInfo.ResourceName);
                }
                await Save();

                var matIns = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(EngineNS.CEngine.Instance.RenderContext, ResourceName);

                for (uint i = 0; i < matIns.SRVNumber; i++)
                {
                    var srvName = matIns.GetSRVName(i);
                    if (srvName == oldRName)
                    {
                        var texture = CEngine.Instance.TextureManager.GetShaderRView(CEngine.Instance.RenderContext, referencedResInfo.ResourceName);
                        matIns.SetSRV(i, texture);
                    }
                }
                matIns.SaveMaterialInstance();
            }
        }