2016-02-14 58 views
0

我的舊項目存在一些問題......如果很短 - 「使用Microsoft.DirectX」。 他們棄用了,現在,我在新PC上運行我的遊戲,並得到各種故障&麻煩,不存在反正之前。 由於他們不贊成,不再支持,我正在尋找解決方案,以取代gfx引擎的好方法,而不會丟失我所有的應用程序代碼。 例如,舊的XNA項目可以移植到MonoGame或FNA,而無需對其架構進行全面更改,我需要以同樣的方式進行。 這裏的任何框架靠近通過API管理directX而沒有很多痛苦的端口它們? SharpDX? SlimDX?任何其他? (我沒有與SharpDX或SlimDX之前的看法)取代Managed DirectX的方法?

這裏的一些關於我的GFX代碼的片段,只是想象它是如何。他們基於Managed DirectX。

public bool InitD3D(ref Form frmForm) 
{ 
    PresentParameters uParms = null; 
    bool bRes = false; 

    mfrmMain = frmForm; 

    Constants.gSettings.LoadSettings(); 

    //Debug.WriteLine("InitD3D in thread: " & Threading.Thread.CurrentThread.ManagedThreadId.ToString) 

    try { 
     CreateFlags lCreateFlags = default(CreateFlags); 
     bool bReduced = false; 
     uParms = CreatePresentationParams(mfrmMain); 
     if (uParms == null) 
      return false; 

     lCreateFlags = (CreateFlags)Constants.gSettings.VertexProcessing; 

     if (lCreateFlags != CreateFlags.HardwareVertexProcessing && lCreateFlags != CreateFlags.MixedVertexProcessing && lCreateFlags != CreateFlags.SoftwareVertexProcessing) { 
      lCreateFlags = CreateFlags.HardwareVertexProcessing; 
     } 

     Caps uDevCaps = Manager.GetDeviceCaps(Manager.Adapters.Default.Adapter, DeviceType.Hardware); 
     if (uDevCaps.DeviceCaps.SupportsHardwareTransformAndLight == false) { 
      if (lCreateFlags == CreateFlags.HardwareVertexProcessing) { 
       lCreateFlags = CreateFlags.SoftwareVertexProcessing; 
       bReduced = true; 
      } 
     } 

     try { 
      gfxDevice = new Device(0, DeviceType.Hardware, frmForm.Handle, lCreateFlags, uParms); 
     } catch { 
      bReduced = true; 
      if ((lCreateFlags & CreateFlags.HardwareVertexProcessing) == CreateFlags.HardwareVertexProcessing) { 
       lCreateFlags = (lCreateFlags^CreateFlags.HardwareVertexProcessing) | CreateFlags.MixedVertexProcessing; 
       try { 
        gfxDevice = new Device(0, DeviceType.Hardware, frmForm.Handle, lCreateFlags, uParms); 
       } catch { 
        lCreateFlags = (lCreateFlags^CreateFlags.MixedVertexProcessing) | CreateFlags.SoftwareVertexProcessing; 
        try { 
         gfxDevice = new Device(0, DeviceType.Hardware, frmForm.Handle, lCreateFlags, uParms); 
        } catch (Exception ex) { 
         Interaction.MsgBox("Game will not run on this computer because the video hardware is not sufficient.", MsgBoxStyle.OkOnly, "Error"); 
         System.Environment.Exit(0); 
        } 
       } 
      } else if ((lCreateFlags & CreateFlags.MixedVertexProcessing) == CreateFlags.MixedVertexProcessing) { 
       lCreateFlags = (lCreateFlags^CreateFlags.MixedVertexProcessing) | CreateFlags.SoftwareVertexProcessing; 
       try { 
        gfxDevice = new Device(0, DeviceType.Hardware, frmForm.Handle, lCreateFlags, uParms); 
       } catch (Exception ex) { 
        Interaction.MsgBox("Game will not run on this computer because the video hardware is not sufficient.", MsgBoxStyle.OkOnly, "Error"); 
        System.Environment.Exit(0); 
       } 
      } 
     } 

     if (bReduced == true) 
      Interaction.MsgBox("Game was required to alter settings that will affect performance in order to run the game.", MsgBoxStyle.OkOnly, "Error"); 
     Constants.gSettings.VertexProcessing = Convert.ToInt32(lCreateFlags); 

     bRes = (gfxDevice != null); 

     if (Constants.gSettings.MiniMapLocX > uParms.BackBufferWidth) 
      Constants.gSettings.MiniMapLocX = uParms.BackBufferWidth - Constants.gSettings.MiniMapWidthHeight; 
     if (Constants.gSettings.MiniMapLocY > uParms.BackBufferHeight) 
      Constants.gSettings.MiniMapLocY = uParms.BackBufferHeight - Constants.gSettings.MiniMapWidthHeight; 
    } catch { 
     Interaction.MsgBox(Err().Description, MsgBoxStyle.Critical | MsgBoxStyle.OkOnly, "Error in initialize Direct3D"); 
     bRes = false; 
    } finally { 
     uParms = null; 
    } 

    if (bRes == false) { 
     Interaction.MsgBox("Unable to initialize Direct3D 9.0c. Your video card may not fully support DirectX 9.0c. Download the latest drivers for your video card and try again.", MsgBoxStyle.OkOnly | MsgBoxStyle.Critical, "Unable to Initialize"); 
     return false; 
    } 

    var _with8 = gfxDevice.DeviceCaps.VertexShaderVersion; 
    if (_with8.Major == 1) { 
     Constants.gSettings.PostGlowAmt = 0f; 
     Constants.gSettings.LightQuality = EngineSettings.LightQualitySetting.VSPS1; 
    } 

    mbSupportsNewModelMethod = gfxDevice.DeviceCaps.TextureOperationCaps.SupportsBlendTextureAlpha == true && gfxDevice.DeviceCaps.MaxTextureBlendStages > 2 && gfxDevice.DeviceCaps.MaxSimultaneousTextures > 1; 

    if (Constants.gWMgr == null) 
     Constants.gWMgr = new WpnFXManager(); 
    if (Constants.gShldMgr == null) 
     Constants.gShldMgr = new ShieldFXManager(); 
    if (Constants.gExplMgr == null) 
     Constants.gExplMgr = new ExplosionManager(); 
    // New ExplosionFXManager(gfxDevice) 
    if (Constants.gPFXEngine32 == null) 
     Constants.gPFXEngine32 = new BurnFX.ParticleEngine(32); 
    //32 for size of points 
    if (Constants.gEntityDeath == null) 
     Constants.gEntityDeath = new DeathSequenceMgr(); 
    //If goRewards Is Nothing Then goRewards = New WarpointRewards() 
    if (Constants.gMissileMgr == null) 
     Constants.gMissileMgr = new MissileMgr(); 
    if (Constants.gBurnMarkMgr == null) 
     Constants.gBurnMarkMgr = new EntityBurnMarkManager(); 

    Constants.InitializeFXColors(); 

    var _with9 = matIronCurtain; 
    _with9.Emissive = System.Drawing.Color.FromArgb(255, 255, 0, 0); 
    _with9.Diffuse = System.Drawing.Color.FromArgb(255, 255, 0, 0); 
    _with9.Ambient = System.Drawing.Color.FromArgb(255, 255, 0, 0); 
    _with9.Specular = System.Drawing.Color.FromArgb(255, 255, 0, 0); 
    _with9.SpecularSharpness = 10; 


    gfxDevice.DeviceLost += gfxDevice_DeviceLost; 
    gfxDevice.DeviceReset += gfxDevice_DeviceReset; 
    gfxDevice.Disposing += gfxDevice_Disposing; 

    mbInitialized = bRes; 

    return bRes; 
} 

回答

0

對於託管DirectX 1.1 C#代碼現有的傳統的直接端口,SlimDX可能是你最好的選擇,因爲它的目的是直接替換。您也可以使用SharpDX,MonoGame,Unity3D或其他一些框架。

請參閱DirectX and .NET