Small code for select driver mode

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Boca
Posts: 12
Joined: Tue Mar 04, 2008 4:35 pm
Location: Spain

Small code for select driver mode

Post by Boca »

This function select a driver type. Without that the user must select a driver.

Code: Select all

void init ()
	{
		irr::video::E_DRIVER_TYPE driver_type = irrr::video::EDT_DIRECT3D9;
		

	inic:
		device = createDevice(driver_type, core::dimension2d<s32>(1280, 1024),16,true,false,true,0);

		if (device == 0)
		{
			switch (driver_type)
			{
			case irr::video::EDT_DIRECT3D9: driver_type = irr::video::EDT_DIRECT3D8; goto inic;
			case irr::video::EDT_DIRECT3D8: driver_type = irr::video::EDT_OPENGL; goto inic; 
			case irr::video::EDT_OPENGL: driver_type = irr::video::EDT_BURNINGSVIDEO; goto inic;
			case irr::video::EDT_BURNINGSVIDEO: driver_type = irr::video::EDT_SOFTWARE; goto inic;
			default: return;
			}
		}
	}
Is thinked for Windows because I added Direct3D. You can tu use this in other platforms removing the "swith's" Direct3D "cases".

You can to change the priority of the drivers changing EDT_DIRECT3D9 to other...

If the system doesn't create a device with Direct3d 9, it try with Direct3d 8, if not with opengl and so on.

:!: Note: If you want to implement this function in a program, you must to add a irrlichtdevice* called device to be able to use in other functions. Also you can to add this function's code to your function.

This is my very humble contrabution though it's a bit silly. :)

Regards! :wink:
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

goto? :shock:
why not while(!device)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Boca
Posts: 12
Joined: Tue Mar 04, 2008 4:35 pm
Location: Spain

Post by Boca »

It's equal. :roll:
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, the word you were looking for is 'evil'.
Goto is evil
Goto is evil
Goto is evil
Boca
Posts: 12
Joined: Tue Mar 04, 2008 4:35 pm
Location: Spain

Post by Boca »

Hahaha :lol: Ok. I will to use While. :D
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: Small code for select driver mode

Post by rogerborg »

switch == goto

Gentlemen, start your cognitive dissonance.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, compiler induced gotos are not really problems, because they stay unseen. While switch statements can produce weird things also (check this one: http://en.wikipedia.org/wiki/Duff%27s_device ), it's rather simple to avoid them and still keep the code maintainable and well-structured. With gotos it's hardly possible.
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

old [programmers myths] are funny. goto is useful. YEA I SAID IT. lol
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Goto is useful no doubt. But is it useful in that situation? The answer is a most definite and absolute no! Reducing code without creating procedures in a switch statement is a valid use of goto, as with breaking out of multiple loops cleanly and efficiently.

Let the caviling begin.
TheQuestion = 2B || !2B
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Man Saying: bla bla C++ bla bla goto bla bla evil
Me: *shivers*
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

It's the same thing as putting 1's and 0's in variable and function names, using single letters for public class members, or refusing to use carriage returns or tabs and bunching all your code up on one line..
It doesn't break the code but it does obfuscate it, and it is a deviation from established protocol.
C++ is so flexible that you can do pretty much whatever you want, so you need some discipline so that other people can read your code. A well written piece of code is one that other people immediately read, understand, feel comfortable with and think "that's the way I would have written it".
Most people don't feel comfortable with gotos, which is why they're bad code.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Flamebait.

I will pull the line here now.

Structured programming became standard a while back, but not too far back to erase the GOTO culture so prevalent that time.

Hey, if you coded in BASIC or probably some old programming languages (ASM), you've probably never seen how they were used.
Image
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

bitplane:
...using single letters for public class members...
vector3d<T>:
T X
T Y
T Z
Hehe, just messin with ya ;)
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

haha how right you are, still, I'm pretty sure you know what I meant :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

yes, yes, quite ^^ i, j, k, l, m are not quite as clear ^^ (unless used in a class where the context is so obvious, just like the vector or dimention ^^ )

still, it was to good an occasion to poke fun at :P
Post Reply