From 986492d72d0e84c2ba2dfdad366f5c7414ee6ac9 Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 20 Sep 2004 13:21:51 +0000 Subject: [PATCH] Finish what was committed in a broken state yesterday. Split up main.cxx into a program manegement part (which remains in main.cxx) and a render part (the new renderer.?xx files). Also turn the renderer into a small class of it's own. At this time not really exctining because most of the stuff is still global, but it allows us to slowly migrate some of the global definitions into the new class. The FGRenderer class is now managed by globals, so to get the renderer just call gloabals->get_renderer() At some pijt it might be a good idea to also turn the remaining code in main into a class of it's own. With a bit of luck we end up with a more robust, and better maintainable code. --- src/GUI/gui_funcs.cxx | 36 +- src/GUI/gui_local.cxx | 2 +- src/Main/Makefile.am | 1 + src/Main/globals.cxx | 8 + src/Main/globals.hxx | 5 + src/Main/main.cxx | 898 ++--------------------------------- src/Main/main.hxx | 19 +- src/Main/renderer.cxx | 21 +- src/Main/renderer.hxx | 6 +- src/Model/acmodel.hxx | 2 - src/MultiPlayer/mpplayer.hxx | 1 + src/Scenery/hitlist.hxx | 1 + src/Scenery/scenery.hxx | 2 + src/Scenery/tileentry.hxx | 2 +- src/Scenery/tilemgr.hxx | 4 +- 15 files changed, 75 insertions(+), 933 deletions(-) diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index 5a05d8872..7989cd0f7 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -102,7 +102,6 @@ extern void fgLatLonFormatToggle( puObject *); #if defined( TR_HIRES_SNAP) #include -extern void trRenderFrame( void ); extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start, GLfloat x_end, GLfloat y_end ); #endif @@ -376,8 +375,8 @@ void guiTogglePanel(puObject *cb) else fgSetBool("/sim/panel/visibility", true); - fgReshape(fgGetInt("/sim/startup/xsize"), - fgGetInt("/sim/startup/ysize")); + globals->get_renderer()->resize(fgGetInt("/sim/startup/xsize"), + fgGetInt("/sim/startup/ysize")); } void goodBye(puObject *) @@ -534,15 +533,16 @@ void fgHiResDump() puHideCursor(); } - fgInitVisuals(); - fgReshape( fgGetInt("/sim/startup/xsize"), - fgGetInt("/sim/startup/ysize") ); + FGRenderer *renderer = globals->get_renderer(); + renderer->init(); + renderer->resize( fgGetInt("/sim/startup/xsize"), + fgGetInt("/sim/startup/ysize") ); // we need two render frames here to clear the menu and cursor // ... not sure why but doing an extra fgRenderFrame() shouldn't // hurt anything - fgRenderFrame(); - fgRenderFrame(); + renderer->update(); + renderer->update(); // Make sure we have SSG projection primed for current view glMatrixMode(GL_MODELVIEW); @@ -633,7 +633,7 @@ void fgHiResDump() trBeginTile(tr); int curColumn = trGet(tr, TR_CURRENT_COLUMN); int curRow = trGet(tr, TR_CURRENT_ROW); - trRenderFrame(); + globals->get_renderer()->screendump(); if ( do_hud ) fgUpdateHUD( curColumn*hud_col_step, curRow*hud_row_step, (curColumn+1)*hud_col_step, (curRow+1)*hud_row_step ); @@ -670,7 +670,7 @@ void fgHiResDump() } - fgReshape( width, height ); + globals->get_renderer()->resize( width, height ); trDelete(tr); @@ -714,7 +714,7 @@ GLubyte *hiResScreenCapture( int multiplier ) float fov = oldfov / multiplier; FGViewer *v = globals->get_current_view(); fgSetDouble("/sim/current-view/field-of-view", fov); - fgInitVisuals(); + globals->get_renderer()->init(); int cur_width = fgGetInt("/sim/startup/xsize"); int cur_height = fgGetInt("/sim/startup/ysize"); if (b1) delete( b1 ); @@ -723,10 +723,10 @@ GLubyte *hiResScreenCapture( int multiplier ) int x,y; for ( y = 0; y < multiplier; y++ ) { for ( x = 0; x < multiplier; x++ ) { - fgReshape( cur_width, cur_height ); + globals->get_renderer()->resize( cur_width, cur_height ); // pan to tile rotateView( 0, (y*fov)-((multiplier-1)*fov/2), (x*fov)-((multiplier-1)*fov/2) ); - fgRenderFrame(); + globals->get_renderer()->update(); // restore view GlBitmap b2; b1->copyBitmap( &b2, cur_width*x, cur_height*y ); @@ -794,15 +794,15 @@ void fgDumpSnapShot () { puHideCursor(); } - fgInitVisuals(); - fgReshape( fgGetInt("/sim/startup/xsize"), - fgGetInt("/sim/startup/ysize") ); + globals->get_renderer()->init(); + globals->get_renderer()->resize( fgGetInt("/sim/startup/xsize"), + fgGetInt("/sim/startup/ysize") ); // we need two render frames here to clear the menu and cursor // ... not sure why but doing an extra fgRenderFrame() shouldn't // hurt anything - fgRenderFrame(); - fgRenderFrame(); + globals->get_renderer()->update(); + globals->get_renderer()->update(); while (count < 1000) { FILE *fp; diff --git a/src/GUI/gui_local.cxx b/src/GUI/gui_local.cxx index e881cd2a7..adb75f656 100644 --- a/src/GUI/gui_local.cxx +++ b/src/GUI/gui_local.cxx @@ -81,7 +81,7 @@ void reInit(puObject *cb) globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") ); - fgReshape( xsize, ysize ); + globals->get_renderer()->resize( xsize, ysize ); // BusyCursor(1); diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 9a3064fda..87fc984aa 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -37,6 +37,7 @@ noinst_LIBRARIES = libMain.a libMain_a_SOURCES = \ main.cxx main.hxx \ + renderer.cxx renderer.hxx \ fg_commands.cxx fg_commands.hxx \ fg_init.cxx fg_init.hxx \ fg_io.cxx fg_io.hxx \ diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 73adb93ea..d8b2997c8 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -42,6 +42,7 @@ FGGlobals *globals; // Constructor FGGlobals::FGGlobals() : + renderer( new FGRenderer ), subsystem_mgr( new SGSubsystemMgr ), event_mgr( new SGEventMgr ), sim_time_sec( 0.0 ), @@ -95,6 +96,7 @@ FGGlobals::~FGGlobals() delete props; delete commands; delete io; + delete renderer; // make sure only to delete the initial waypoints list if it acually // still exists. @@ -157,6 +159,12 @@ void FGGlobals::set_fg_scenery (const string &scenery) { } +FGRenderer * +FGGlobals::get_renderer () const +{ + return renderer; +} + SGSubsystemMgr * FGGlobals::get_subsystem_mgr () const { diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 3077e750e..13215e6ee 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -42,6 +42,8 @@ SG_USING_STD( string ); typedef vector string_list; +#include "renderer.hxx" + // Forward declarations // This file is included, directly or indirectly, almost everywhere in @@ -97,6 +99,7 @@ class FGGlobals private: + FGRenderer *renderer; SGSubsystemMgr *subsystem_mgr; SGEventMgr *event_mgr; @@ -217,6 +220,8 @@ public: FGGlobals(); virtual ~FGGlobals(); + virtual FGRenderer *get_renderer () const; + virtual SGSubsystemMgr *get_subsystem_mgr () const; virtual SGSubsystem *get_subsystem (const char * name); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 0915f2d23..8f80effbb 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -41,31 +41,23 @@ # include #endif -#include #include -#include -#include #include -#include #include -#include -#include -#include #include + +// Class refferences +#include #include +#include +#include +#include +#include