Skip to content

Commit

Permalink
Cleaned up video configuration, added message box for failed device c…
Browse files Browse the repository at this point in the history
…reation.
  • Loading branch information
jarmonik committed Jan 9, 2024
1 parent f344154 commit eb8e1c0
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 18 deletions.
9 changes: 5 additions & 4 deletions OVP/D3D9Client/D3D9Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ DLLCLBK void ExitModule(HINSTANCE hDLL)
delete TileCatalog;
delete Config;
delete g_pConst;
delete g_client;

DebugControls::Release();
AtmoControls::Release();

if (g_client) {
oapiUnregisterGraphicsClient(g_client);
delete g_client;
g_client = 0;
}

DebugControls::Release();
AtmoControls::Release();

#ifdef _NVAPI_H
if (bNVAPI) if (NvAPI_Unload()==NVAPI_OK) LogAlw("[nVidia API Unloaded]");
#endif
Expand Down Expand Up @@ -330,6 +330,7 @@ bool D3D9Client::clbkInitialise()
}
else {
oapiWriteLog("[D3D9][ERROR] Failed to create DirectX9");
FailedDeviceError();
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions OVP/D3D9Client/D3D9Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ HRESULT CD3DFramework9::Initialize(HWND _hWnd, GraphicsClient::VIDEODATA *vData)
bAAEnabled = (Config->SceneAntialias != 0);
bIsFullscreen = vData->fullscreen;
bNoVSync = vData->novsync;
dwFSMode = (vData->modeidx>>8)&0xFF;
dwFSMode = vData->style;
bGDIBB = vData->trystencil;
Adapter = vData->deviceidx;
Mode = vData->modeidx&0xFF;
Mode = vData->modeidx;

LogAlw("[VideoConfiguration] Adapter=%u, ModeIndex=%u", Adapter, Mode);

Expand Down
9 changes: 9 additions & 0 deletions OVP/D3D9Client/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ void MissingRuntimeError()
"D3D9Client Initialization Failed", MB_OK);
}

//-------------------------------------------------------------------------------------------
//
void FailedDeviceError()
{
MessageBoxA(NULL,
"DirectX9 Device Failed. Try to enable EnableDX12Wrapper from D3D9Client.cfg",
"D3D9Client Initialization Failed", MB_OK);
}

//-------------------------------------------------------------------------------------------
//
void RuntimeError(const char* File, const char* Fnc, UINT Line)
Expand Down
1 change: 1 addition & 0 deletions OVP/D3D9Client/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ double D3D9GetTime();
void D3D9SetTime(D3D9Time &inout, double ref);

void MissingRuntimeError();
void FailedDeviceError();
void LogAttribs(DWORD attrib, DWORD w, DWORD h, LPCSTR origin);

#define HALT() { RuntimeError(__FILE__,__FUNCTION__,__LINE__); }
Expand Down
17 changes: 10 additions & 7 deletions OVP/D3D9Client/VideoTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bool VideoTab::Initialise()
data->trystencil = false;

SendDlgItemMessage(hTab, IDC_VID_DEVICE, CB_RESETCONTENT, 0, 0);
SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hTab, IDC_VID_MODE, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hTab, IDC_VID_BPP, CB_RESETCONTENT, 0, 0);

ScanAtmoCfgs();
Expand All @@ -179,6 +179,7 @@ bool VideoTab::Initialise()

if (nAdapter == 0) {
LogErr("VideoTab::Initialize() No DirectX9 Adapters Found");
FailedDeviceError();
return false;
}

Expand All @@ -201,6 +202,7 @@ bool VideoTab::Initialise()

if (nModes == 0) {
LogErr("VideoTab::Initialize() No Display Modes Available");
FailedDeviceError();
}

for (UINT k=0;k<nModes;k++) {
Expand All @@ -214,13 +216,13 @@ bool VideoTab::Initialise()
SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"True Full Screen (no alt-tab)");
SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"Full Screen Window");
SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"Window with Taskbar");
SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_SETCURSEL, (data->modeidx>>8)&0xFF, 0);
SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_SETCURSEL, data->style, 0);

//SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC5), "Resolution");
SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC6), "Full Screen Mode");


SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0);
SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx, 0);
SendDlgItemMessage(hTab, IDC_VID_VSYNC, BM_SETCHECK, data->novsync ? BST_CHECKED : BST_UNCHECKED, 0);

SetWindowText(GetDlgItem(hTab, IDC_VID_WIDTH), std::to_string(data->winw).c_str());
Expand Down Expand Up @@ -258,7 +260,7 @@ void VideoTab::SelectMode(DWORD index)
{
GraphicsClient::VIDEODATA *data = gclient->GetVideoData();
SendDlgItemMessage(hTab, IDC_VID_MODE, CB_GETITEMDATA, index, 0);
data->modeidx = index + data->modeidx&0xFF00;
data->modeidx = index;
}


Expand Down Expand Up @@ -303,7 +305,7 @@ bool VideoTab::SelectAdapter(DWORD index)
SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_SETITEMDATA, k, (LPARAM)(mode.Height<<16 | mode.Width));
}

SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0);
SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx, 0);
}

return true;
Expand Down Expand Up @@ -395,8 +397,9 @@ void VideoTab::UpdateConfigData()
GraphicsClient::VIDEODATA *data = gclient->GetVideoData();

// device parameters
data->deviceidx = (int)SendDlgItemMessageA(hTab, IDC_VID_DEVICE, CB_GETCURSEL, 0, 0);
data->modeidx = (int)SendDlgItemMessage(hTab, IDC_VID_MODE, CB_GETCURSEL, 0, 0) + ((int)SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_GETCURSEL, 0, 0)<<8);
data->deviceidx = (int)SendDlgItemMessage (hTab, IDC_VID_DEVICE, CB_GETCURSEL, 0, 0);
data->modeidx = (int)SendDlgItemMessage (hTab, IDC_VID_MODE, CB_GETCURSEL, 0, 0);
data->style = SendDlgItemMessage (hTab, IDC_VID_BPP, CB_GETCURSEL, 0, 0);
data->fullscreen = (SendDlgItemMessage (hTab, IDC_VID_FULL, BM_GETCHECK, 0, 0) == BST_CHECKED);
data->novsync = (SendDlgItemMessage (hTab, IDC_VID_VSYNC, BM_GETCHECK, 0, 0) == BST_CHECKED);
data->pageflip = (SendDlgItemMessage (hTab, IDC_VID_PAGEFLIP, BM_GETCHECK, 0, 0) == BST_CHECKED);
Expand Down
1 change: 0 additions & 1 deletion OVP/D3D9Client/VideoTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class VideoTab {
void SaveSetupState(HWND hWnd);
void ScanAtmoCfgs();
bool GetConfigName(const char* file, string& cfg, string& planet);
void LoadAtmoCfg();

oapi::D3D9Client *gclient;
HINSTANCE hOrbiterInst; // orbiter instance handle
Expand Down
10 changes: 6 additions & 4 deletions Orbitersdk/include/GraphicsAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,12 @@ class OAPIFUNC GraphicsClient: public Module {
bool trystencil; ///< stencil buffer flag
bool novsync; ///< no vsync flag
bool pageflip; ///< allow page flipping in fullscreen
int deviceidx; ///< video device index
int modeidx; ///< video mode index
int winw; ///< window width
int winh; ///< window height
int deviceidx; ///< video device (adapter) index
int modeidx; ///< video mode index (fullscreen resolution)
int winw; ///< window/screen width
int winh; ///< window/screen height
int outputidx; ///< video output
int style; ///< true fullscreen, fulscreen window, window with taskbar
};

/**
Expand Down
7 changes: 7 additions & 0 deletions Src/Orbiter/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ CFG_RECPLAYPRM CfgRecPlayPrm_default = {
CFG_DEVPRM CfgDevPrm_default = {
-1, // Device_idx (-1=undefined)
0, // Device_mode
0,
0,
true, // bForceEnum (enumerate devices at each simulation start)
false, // bFullscreen (default to window mode)
false, // bStereo (no stereo support)
Expand Down Expand Up @@ -515,6 +517,8 @@ bool Config::Load(const char *fname)
// Device information
GetInt (ifs, "DeviceIndex", CfgDevPrm.Device_idx);
if (GetInt (ifs, "ModeIndex", i)) CfgDevPrm.Device_mode = (DWORD)i;
if (GetInt(ifs, "OutputIndex", i)) CfgDevPrm.Device_out = (DWORD)i;
if (GetInt(ifs, "Style", i)) CfgDevPrm.Device_style = (DWORD)i;
GetBool (ifs, "DeviceForceEnum", CfgDevPrm.bForceEnum);
GetBool (ifs, "Fullscreen", CfgDevPrm.bFullscreen);
GetBool (ifs, "Stereo", CfgDevPrm.bStereo);
Expand Down Expand Up @@ -1219,6 +1223,9 @@ BOOL Config::Write (const char *fname) const
ofs << "\n; === Device settings ===\n";
ofs << "DeviceIndex = " << CfgDevPrm.Device_idx << '\n';
ofs << "ModeIndex = " << CfgDevPrm.Device_mode << '\n';
ofs << "OutputIndex" << CfgDevPrm.Device_out << '\n';
ofs << "Style" << CfgDevPrm.Device_style << '\n';

if (CfgDevPrm.bForceEnum != CfgDevPrm_default.bForceEnum || bEchoAll)
ofs << "DeviceForceEnum = " << BoolStr (CfgDevPrm.bForceEnum) << '\n';
if (CfgDevPrm.bFullscreen != CfgDevPrm_default.bFullscreen || bEchoAll)
Expand Down
2 changes: 2 additions & 0 deletions Src/Orbiter/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ struct CFG_RECPLAYPRM {
struct CFG_DEVPRM {
int Device_idx; // index of default device
DWORD Device_mode; // index of default fullscreen mode
DWORD Device_out; // device output
DWORD Device_style; // Rendering layout
bool bForceEnum; // force enumeration, bypass device.dat
bool bFullscreen; // use window mode
bool bStereo; // use stereo mode
Expand Down
4 changes: 4 additions & 0 deletions Src/Orbiter/GraphicsAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ GraphicsClient::GraphicsClient (HINSTANCE hInstance): Module (hInstance)
VideoData.pageflip = true;
VideoData.deviceidx = -1;
VideoData.modeidx = 0;
VideoData.outputidx = 0;
VideoData.style = 1;
VideoData.winw = 1024;
VideoData.winh = 768;
surfBltTgt = RENDERTGT_NONE;
Expand Down Expand Up @@ -98,6 +100,8 @@ bool GraphicsClient::clbkInitialise ()
VideoData.novsync = cfg->CfgDevPrm.bNoVsync;
VideoData.pageflip = cfg->CfgDevPrm.bPageflip;
VideoData.deviceidx = cfg->CfgDevPrm.Device_idx;
VideoData.outputidx = cfg->CfgDevPrm.Device_out;
VideoData.style = cfg->CfgDevPrm.Device_style;
VideoData.modeidx = (int)cfg->CfgDevPrm.Device_mode;
VideoData.winw = (int)cfg->CfgDevPrm.WinW;
VideoData.winh = (int)cfg->CfgDevPrm.WinH;
Expand Down
4 changes: 4 additions & 0 deletions Src/Orbiter/TabVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ void orbiter::DefVideoTab::SetConfig (Config *cfg)
cfg->CfgDevPrm.WinH = data->winh;
cfg->CfgDevPrm.Device_idx = data->deviceidx;
cfg->CfgDevPrm.Device_mode = data->modeidx;
cfg->CfgDevPrm.Device_out = data->outputidx;
cfg->CfgDevPrm.Device_style= data->style;
} else {
// should not be required
cfg->CfgDevPrm.bFullscreen = false;
Expand All @@ -138,6 +140,8 @@ void orbiter::DefVideoTab::SetConfig (Config *cfg)
cfg->CfgDevPrm.WinH = 300;
cfg->CfgDevPrm.Device_idx = 0;
cfg->CfgDevPrm.Device_mode = 0;
cfg->CfgDevPrm.Device_out = 0;
cfg->CfgDevPrm.Device_style= 1;
}
cfg->CfgDevPrm.bStereo = false; // not currently set
}
Expand Down

0 comments on commit eb8e1c0

Please sign in to comment.