CCMD Vid_SetAdapter

Moderator: GZDoom Developers

Post Reply
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm
Contact:

CCMD Vid_SetAdapter

Post by ibm5155 »

With this code, the user'll ve able to change the adapter, and automatically, zdoom (also tested with gloome) will change the adapter to the selected one.
The code looks like to be user error aprove :roll: and it was based over the vid_setmode CCMD.
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");
	}
}
This code was inserted inside the v_video.cpp (I added it belod the vid_setmode CCMD).
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"
}

I hope you guys enjoy my first code sumission :D
User avatar
Major Cooke
Posts: 8212
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: CCMD Vid_SetAdapter

Post by Major Cooke »

You should use github pull requests.
ibm5155 wrote:The code looks like to be user error aprove :roll:
What?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: CCMD Vid_SetAdapter

Post by Graf Zahl »

This is too poorly done. Sorry.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: CCMD Vid_SetAdapter

Post by Graf Zahl »

So what's wrong here, if anybody asks:

Ok, here it goes:

Code pasted into the post is a no-go and will be rejected by default. The forum may alter the formatting. Either post an attachment or better, a pull-request.
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm
Contact:

Re: CCMD Vid_SetAdapter

Post by ibm5155 »

Ok I'll...

I just have a question? do vid_adapter ever worked with zdoom? it's only working with gzdoom/gloome/zandronum (only in opengl mode) here :S

EDIT: I know the zdoom solution generates the file zdoom.pk3, but I didn't manage to find where in the code it generate the menudef.txt that's found inside zdoom.pk3 :S
_mental_
 
 
Posts: 3820
Joined: Sun Aug 07, 2011 4:32 am

Re: CCMD Vid_SetAdapter

Post by _mental_ »

menudef.txt isn't generated, you can find it in wadsrc/static directory. For GZDoom there is also menudef.z in the same directory.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”