The code looks like to be user error aprove

The code is also well documented (maybe there's too much text but, better much than nothing), and also, it'll warn the user about any situation that he can end up (like, changing the adapter on windowed, changing the adapter to a negative value or to *an invalid adapter ex: the user has 2 adapters, he write "vid_setadapter 3" and the console will warn with an invalid adapter message)...
Code: Select all
CCMD(vid_setadapter)
{
bool goodmode = true;
bool badadapter = false;
int selectedadapter = 1;//default value to the primary display. [IBM]
if (argv.argc() > 1)//ignore the trash wrote by the user and just get the needed info [IBM]
{
selectedadapter = atoi(argv[1]);
//if there's somewhere an atribute that stores that value, replace the commented area
//by the other side, the engine will set the render to the primary display in case the
//adapter is invalid, not an elegant solution, but it doesn't crash. [IBM]
if (/*selectedadapter > D3D->GetAdapterCount() || */selectedadapter < 1) //there's no negative adapter, neither zero value.
{
badadapter = true;
goodmode = false;
}
}
else
{
goodmode = false;
}
if (screen->IsFullscreen() == false && goodmode)
{
//if the game is windowed, there's no need to change the position of the render window
//it'll change to the right position when the player change the game to fullscreen. [IBM]
goodmode = false;
Printf("The adapter has changed, but it'll only be applied when running full screen");
}
if (goodmode)
{
// The actual change of resolution will take place
// near the beginning of D_Display().
if (gamestate != GS_STARTUP)
{
cvar_set("vid_adapter", argv[1]);
setmodeneeded = true;
NewWidth = SCREENWIDTH;
NewHeight = SCREENHEIGHT;
NewBits = DisplayBits;
//width and height are not going to be changed, only a refresh call is required. [IBM]
}
}
else if (badadapter == true)
{
Printf("Adapter %d not found\n", selectedadapter);
}
else if (argv.argc() == 1)
{
Printf("Usage: vid_adapter <Screen number>\n");
}
}
Also, is there some place over zdoom code where it's stored the data about how many adapters the user has? I only managed to find that information over the win32video.cpp and ehm, it's a Windows only solution :S
Also here's the modified Menudef (not the full menudef)
Code: Select all
OptionMenu VideoModeMenu
{
Title "VIDEO MODE"
Option "Fullscreen", "fullscreen", "YesNo"
Option "Default Display adapter", "vid_setadapter", "SelectedAdapter"
Option "Aspect ratio", "menu_screenratios", "Ratios"
Option "Force aspect ratio", "vid_aspect", "ForceRatios"
Option "Enable 5:4 aspect ratio","vid_tft", "YesNo"
StaticText " "
ScreenResolution "res_0"
ScreenResolution "res_1"
ScreenResolution "res_2"
ScreenResolution "res_3"
ScreenResolution "res_4"
ScreenResolution "res_5"
ScreenResolution "res_6"
ScreenResolution "res_7"
ScreenResolution "res_8"
ScreenResolution "res_9"
StaticTextSwitchable "Press ENTER to set mode", "", "VMEnterText"
StaticText " "
StaticTextSwitchable "T to test mode for 5 seconds", "Please wait 5 seconds...", "VMTestText"
class VideoModeMenu
}
OptionValue SelectedAdapter
{
1, "Primary"
2, "Secondary"
3, "Tertiary"
4, "Quaternary"
5, "Quinary"
6, "Senary"
7, "Septenary"
8, "Octonary"
9, "Nonary"
}
