Simple macros for init code

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

Simple macros for init code

Postby Dreadstew » Tue Mar 13, 2018 11:03 pm

I have some macros I made for my init code. Very simple but make code cleaner, especially QuickScene

cpp Code: Select all
 
#define MessageBoxAndQuit(lstr) MessageBox(0, (lstr), 0, MB_OK | MB_ICONERROR); \
                                return 1

 
//allows you to draw any number of components by putting them between begin and end scene
#define QuickScene(drawcalls)   driver->beginScene(); \
                                (drawcalls) \
                                driver->endScene()

 
#define LoadValidate(pointer, errormessage) if (!(pointer)) { MessageBoxAndQuit((errormessage)); }
 


use quick scene by putting drawcalls ended with a semicolon. Like this.

cpp Code: Select all
 
QuickScene(guiobject->draw(); otherobject->draw(); thing->draw(););
 


You have to name your driver variable "driver" for this to work

Also, MessageBox is in Windows.h. I planned on supporting Linux, but after finding that it takes hundreds of crazy lines to make a message box that isn't even standard, I dropped support for it lol (aka deleted 10 lines of preprocessor addled code) 8)
Dreadstew
 
Posts: 11
Joined: Wed Apr 01, 2015 5:18 pm

Re: Simple macros for init code

Postby hendu » Wed Mar 14, 2018 8:15 am

FLTK lets you have OS-independent things like that easily. fl_alert("Something happened");
hendu
 
Posts: 2599
Joined: Sat Dec 18, 2010 12:53 pm

Re: Simple macros for init code

Postby Dreadstew » Thu Mar 15, 2018 10:55 pm

I'll look into that! Thanks for letting me know!
Dreadstew
 
Posts: 11
Joined: Wed Apr 01, 2015 5:18 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest