class - C++ - Passing classes to other classes. How do i know when to use friend inheritance -


i have game. game class.

i have couple of lines in game dedicated showing debug information:

rect rct; rct.left = 10; rct.right = 780; rct.top = 10; rct.bottom = screen.getwindowheight() - rct.top;  std::string debugstringresult; std::stringstream debugstring; debugstring << "mouse x: " << mouse.getmousex() << ",\nmouse y: " << mouse.getmousey() << ",\nleft mouse down: " << mouse.leftmousedown() << ",\nright mouse down: " << mouse.rightmousedown() << ",\nscreen width: " << screen.getscreenwidth() << ",\nscreen height: " << screen.getscreenheight() << "\nsystem resolution: " << screen.getwindowwidth() << " x " << screen.getwindowheight(); debugstringresult = debugstring.str();   font.handle->drawtext( null, debugstringresult.c_str(), -1, &rct, 0, font.color ); 

this code in game drawing loop. lazy isn't :)

so want declare variable not keep re-declaring memory rct , position properties , strings using "debugstringresult" , "debugstring". less lazy :)

i decide create class called debug aforementioned variables , couple of methods. realise have make variable in game class allow creation of instance

debug debug; 

then realise have pass mouse, screen , gfx (for actual draw screen part) class references through debug debug class has them output screen.

game::game( hwnd hwnd, const mouseserver &mouseserver, const screenserver &screenserver )     :   mouse( mouseserver ),         screen( screenserver ),         gfx( screen, hwnd ),         font( gfx ),         viewport( screen, gfx ),         debug( gfx, mouse, screen ) { 

then hits me. why don't create function in game class called debug() , holds previous code rct , stuff in it. realise, in game class need declare variables of rct, debugstring , debugresult... honest, not game, debugging game... massively huge list of game variables got bigger...

after question is:

what guys if wanted set of debug related stuff has access variables ever being used in game class.

do make friend of game class?

do bite lip , on passing classes debug constructor?

do declare mouse, keyboard, screen , graphics globally can access them everywhere? assume not coz it's harder debug need watch item.

do create kind of "other" class , batch weird funky miscellaneous stuff debug

do create class acts set of references classes end passing through lots...? instead of passing through viewport , debug class specific things need, pass through "reference" class create holds references game constructor?

i don't know other people , it's becoming harder commit methods of doing things?

your drawing code should not know how build "debug string". want separation of model , view.

for example, have method dedicated output debug info screen part of rendering engine. function calls kind of getdebuginfo() game engine pull necessary information modules , push call debug object format string, whatever wants information , return appropriate debug informations game engine. game engine returns debug string interface draws without interpretation @ all.

i want add information push debug object should flexible possible may want use hash map of properties, example. may not best way (the hash map) encourage @ different ways of mapping properties values (what do if have floating points , string values ?). way debug object can or not @ properties wants process , not make parameters heavier in function calls. pass object (or collection, map, whatever) , processed debug object.

here simple system sequence diagram put visually.

getting debug information


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -