Skip to content

Commit

Permalink
Refactor available video modes processing mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed May 1, 2018
1 parent 3e6922e commit 18ef7a0
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 165 deletions.
1 change: 0 additions & 1 deletion src/Include/xrAPI/xrAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class XRAPI_API EngineGlobalEnvironment
IRender* Render;
IDebugRender* DRender;
CDUInterface* DU;
xr_token* vid_mode_token;
IUIRender* UIRender;
CGameMtlLibrary* PGMLib;
IRenderFactory* RenderFactory;
Expand Down
86 changes: 29 additions & 57 deletions src/Layers/xrRender/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@
#include "xrEngine/XR_IOConsole.h"
#include "xrCore/xr_token.h"

#ifndef _EDITOR
extern ENGINE_API xr_vector<xr_token> AvailableVideoModes;

void fill_vid_mode_list(CHW* _hw);
void free_vid_mode_list();

void fill_render_mode_list();
void free_render_mode_list();
#else
void fill_vid_mode_list(CHW* _hw) {}
void free_vid_mode_list() {}
void fill_render_mode_list() {}
void free_render_mode_list() {}
#endif

CHW HW;

CHW::CHW()
Expand Down Expand Up @@ -240,9 +232,7 @@ void CHW::DestroyDevice()

DestroyD3D();

#ifndef _EDITOR
free_vid_mode_list();
#endif
}

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -348,9 +338,9 @@ void CHW::selectResolution(u32& dwWidth, u32& dwHeight, BOOL bWindowed)
string64 buff;
xr_sprintf(buff, sizeof(buff), "%dx%d", psCurrentVidMode[0], psCurrentVidMode[1]);

if (_ParseItem(buff, GEnv.vid_mode_token) == u32(-1)) // not found
if (_ParseItem(buff, AvailableVideoModes.data()) == u32(-1)) // not found
{ // select safe
xr_sprintf(buff, sizeof(buff), "vid_mode %s", GEnv.vid_mode_token[0].name);
xr_sprintf(buff, sizeof(buff), "vid_mode %s", AvailableVideoModes[0].name);
Console->Execute(buff);
}

Expand Down Expand Up @@ -558,73 +548,55 @@ void CHW::updateWindowProps(HWND m_hWnd)
#endif
}

struct _uniq_mode
struct uniqueRenderingMode
{
_uniq_mode(LPCSTR v) : _val(v) {}
LPCSTR _val;
bool operator()(LPCSTR _other) { return !xr_stricmp(_val, _other); }
uniqueRenderingMode(pcstr v) : value(v) {}
pcstr value;
bool operator()(const xr_token other) const { return !xr_stricmp(value, other.name);}
};

#ifndef _EDITOR

void free_vid_mode_list()
{
for (int i = 0; GEnv.vid_mode_token[i].name; i++)
{
xr_free(GEnv.vid_mode_token[i].name);
}
xr_free(GEnv.vid_mode_token);
GEnv.vid_mode_token = nullptr;
for (auto& mode : AvailableVideoModes)
xr_free(mode.name);
AvailableVideoModes.clear();
}

void fill_vid_mode_list(CHW* _hw)
{
if (GEnv.vid_mode_token != nullptr)
if (!AvailableVideoModes.empty())
return;
xr_vector<LPCSTR> _tmp;
xr_vector<D3DDISPLAYMODE> modes;

xr_vector<D3DDISPLAYMODE> displayModes;

// Get the number of display modes available
UINT cnt = _hw->pD3D->GetAdapterModeCount(_hw->DevAdapter, _hw->Caps.fTarget);
const auto cnt = _hw->pD3D->GetAdapterModeCount(_hw->DevAdapter, _hw->Caps.fTarget);

// Get the list of display modes
modes.resize(cnt);
displayModes.resize(cnt);
for (auto i = 0; i < cnt; ++i)
_hw->pD3D->EnumAdapterModes(_hw->DevAdapter, _hw->Caps.fTarget, i, &modes[i]);
_hw->pD3D->EnumAdapterModes(_hw->DevAdapter, _hw->Caps.fTarget, i, &displayModes[i]);

for (auto &i : modes)
int i = 0;
auto& AVM = AvailableVideoModes;
for (const auto& it : displayModes)
{
string32 str;

if (i.Width < 800)
if (it.Width < 800)
continue;

xr_sprintf(str, sizeof(str), "%dx%d", i.Width, i.Height);
xr_sprintf(str, sizeof(str), "%dx%d", it.Width, it.Height);

if (_tmp.end() != std::find_if(_tmp.begin(), _tmp.end(), _uniq_mode(str)))
if (AVM.cend() != std::find_if(AVM.cbegin(), AVM.cend(), uniqueRenderingMode(str)))
continue;

_tmp.push_back(nullptr);
_tmp.back() = xr_strdup(str);
AVM.emplace_back(xr_token(xr_strdup(str), i));
++i;
}
AVM.emplace_back(xr_token(nullptr, -1));

u32 _cnt = _tmp.size() + 1;

GEnv.vid_mode_token = xr_alloc<xr_token>(_cnt);

GEnv.vid_mode_token[_cnt - 1].id = -1;
GEnv.vid_mode_token[_cnt - 1].name = nullptr;

#ifdef DEBUG
Msg("Available video modes[%d]:", _tmp.size());
#endif // DEBUG
for (auto i = 0; i < _tmp.size(); ++i)
{
GEnv.vid_mode_token[i].id = i;
GEnv.vid_mode_token[i].name = _tmp[i];
#ifdef DEBUG
Msg("[%s]", _tmp[i]);
#endif // DEBUG
}
Msg("Available video modes[%d]:", AVM.size());
for (const auto& mode : AVM)
Msg("[%s]", mode.name);
}
#endif
86 changes: 29 additions & 57 deletions src/Layers/xrRenderDX10/dx10HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@
#include "StateManager/dx10SamplerStateCache.h"
#include "StateManager/dx10StateCache.h"

#ifndef _EDITOR
extern ENGINE_API xr_vector<xr_token> AvailableVideoModes;

void fill_vid_mode_list(CHW* _hw);
void free_vid_mode_list();

void fill_render_mode_list();
void free_render_mode_list();
#else
void fill_vid_mode_list(CHW* _hw) {}
void free_vid_mode_list() {}
void fill_render_mode_list() {}
void free_render_mode_list() {}
#endif

CHW HW;

CHW::CHW()
Expand Down Expand Up @@ -186,7 +178,7 @@ void CHW::CreateDevice(HWND m_hWnd, bool move_window)
// Create render target and depth-stencil views here
UpdateViews();

size_t memory = Desc.DedicatedVideoMemory;
const auto memory = Desc.DedicatedVideoMemory;
Msg("* Texture memory: %d M", memory / (1024 * 1024));
//Msg("* DDI-level: %2.1f", float(D3DXGetDriverLevel(pDevice)) / 100.f);
#ifndef _EDITOR
Expand Down Expand Up @@ -228,9 +220,7 @@ void CHW::DestroyDevice()

DestroyD3D();

#ifndef _EDITOR
free_vid_mode_list();
#endif
}

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -286,9 +276,9 @@ void CHW::selectResolution(u32& dwWidth, u32& dwHeight, BOOL bWindowed)
string64 buff;
xr_sprintf(buff, sizeof(buff), "%dx%d", psCurrentVidMode[0], psCurrentVidMode[1]);

if (_ParseItem(buff, GEnv.vid_mode_token) == u32(-1)) // not found
if (_ParseItem(buff, AvailableVideoModes.data()) == u32(-1)) // not found
{ // select safe
xr_sprintf(buff, sizeof(buff), "vid_mode %s", GEnv.vid_mode_token[0].name);
xr_sprintf(buff, sizeof(buff), "vid_mode %s", AvailableVideoModes[0].name);
Console->Execute(buff);
}

Expand Down Expand Up @@ -418,31 +408,26 @@ void CHW::updateWindowProps(HWND m_hWnd)
SetForegroundWindow(m_hWnd);
}

struct _uniq_mode
struct uniqueRenderingMode
{
_uniq_mode(LPCSTR v) : _val(v) {}
LPCSTR _val;
bool operator()(LPCSTR _other) { return !xr_stricmp(_val, _other); }
uniqueRenderingMode(pcstr v) : value(v) {}
pcstr value;
bool operator()(const xr_token other) const { return !xr_stricmp(value, other.name); }
};

#ifndef _EDITOR

void free_vid_mode_list()
{
for (int i = 0; GEnv.vid_mode_token[i].name; i++)
{
xr_free(GEnv.vid_mode_token[i].name);
}
xr_free(GEnv.vid_mode_token);
GEnv.vid_mode_token = nullptr;
for (auto& mode : AvailableVideoModes)
xr_free(mode.name);
AvailableVideoModes.clear();
}

void fill_vid_mode_list(CHW* _hw)
{
if (GEnv.vid_mode_token != nullptr)
if (!AvailableVideoModes.empty())
return;
xr_vector<LPCSTR> _tmp;
xr_vector<DXGI_MODE_DESC> modes;

xr_vector<DXGI_MODE_DESC> displayModes;

IDXGIOutput* pOutput;
//_hw->m_pSwapChain->GetContainingOutput(&pOutput);
Expand All @@ -457,45 +442,33 @@ void fill_vid_mode_list(CHW* _hw)
pOutput->GetDisplayModeList(format, flags, &cnt, nullptr);

// Get the list of display modes
modes.resize(cnt);
pOutput->GetDisplayModeList(format, flags, &cnt, &modes.front());
displayModes.resize(cnt);
pOutput->GetDisplayModeList(format, flags, &cnt, displayModes.data());

_RELEASE(pOutput);

for (auto &i : modes)
int i = 0;
auto& AVM = AvailableVideoModes;
for (const auto& it : displayModes)
{
string32 str;

if (i.Width < 800)
if (it.Width < 800)
continue;

xr_sprintf(str, sizeof(str), "%dx%d", i.Width, i.Height);
xr_sprintf(str, sizeof(str), "%dx%d", it.Width, it.Height);

if (_tmp.end() != std::find_if(_tmp.begin(), _tmp.end(), _uniq_mode(str)))
if (AVM.cend() != std::find_if(AVM.cbegin(), AVM.cend(), uniqueRenderingMode(str)))
continue;

_tmp.push_back(nullptr);
_tmp.back() = xr_strdup(str);
AVM.emplace_back(xr_token(xr_strdup(str), i));
++i;
}
AVM.emplace_back(xr_token(nullptr, -1));

u32 _cnt = _tmp.size() + 1;

GEnv.vid_mode_token = xr_alloc<xr_token>(_cnt);

GEnv.vid_mode_token[_cnt - 1].id = -1;
GEnv.vid_mode_token[_cnt - 1].name = nullptr;

#ifdef DEBUG
Msg("Available video modes[%d]:", _tmp.size());
#endif // DEBUG
for (auto i = 0; i < _tmp.size(); ++i)
{
GEnv.vid_mode_token[i].id = i;
GEnv.vid_mode_token[i].name = _tmp[i];
#ifdef DEBUG
Msg("[%s]", _tmp[i]);
#endif // DEBUG
}
Msg("Available video modes[%d]:", AVM.size());
for (const auto& mode : AVM)
Msg("[%s]", mode.name);
}

void CHW::UpdateViews()
Expand Down Expand Up @@ -540,4 +513,3 @@ void CHW::UpdateViews()

_RELEASE(pDepthStencil);
}
#endif
Loading

0 comments on commit 18ef7a0

Please sign in to comment.