From 7f9c6d72ab439a8accf9d29fc0a76cadeb1dfec9 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 11 Feb 2000 22:27:23 +0000 Subject: [PATCH] Added a load/save state function contributed by David Megginson. --- src/Main/Makefile.am | 1 + src/Main/keyboard.cxx | 22 +++ src/Main/options.hxx | 30 +++ src/Main/save.cxx | 428 ++++++++++++++++++++++++++++++++++++++++++ src/Main/save.hxx | 44 +++++ 5 files changed, 525 insertions(+) create mode 100644 src/Main/save.cxx create mode 100644 src/Main/save.hxx diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 673113f34..5fb7798f8 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -37,6 +37,7 @@ fgfs_SOURCES = \ keyboard.cxx keyboard.hxx \ main.cxx \ options.cxx options.hxx \ + save.cxx save.hxx \ splash.cxx splash.hxx \ views.cxx views.hxx diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index a1d4f401b..cdf406825 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -63,6 +63,7 @@ #include "keyboard.hxx" #include "options.hxx" +#include "save.hxx" #include "views.hxx" extern void NewAltitude( puObject *cb ); @@ -383,6 +384,27 @@ void GLUTspecialkey(int k, int x, int y) { if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) { FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" ); switch (k) { + case GLUT_KEY_F1: { + ifstream input("fgfs.sav"); + if (input.good() && fgLoadFlight(input)) { + input.close(); + FG_LOG(FG_INPUT, FG_INFO, "Restored flight from fgfs.sav"); + } else { + FG_LOG(FG_INPUT, FG_ALERT, "Cannot load flight from fgfs.sav"); + } + return; + } + case GLUT_KEY_F2: { + FG_LOG(FG_INPUT, FG_INFO, "Saving flight"); + ofstream output("fgfs.sav"); + if (output.good() && fgSaveFlight(output)) { + output.close(); + FG_LOG(FG_INPUT, FG_INFO, "Saved flight to fgfs.sav"); + } else { + FG_LOG(FG_INPUT, FG_ALERT, "Cannot save flight to fgfs.sav"); + } + return; + } case GLUT_KEY_END: // numeric keypad 1 v->set_goal_view_offset( FG_PI * 0.75 ); return; diff --git a/src/Main/options.hxx b/src/Main/options.hxx index dd32db181..1c4d8b37d 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -271,12 +271,35 @@ public: inline string get_net_id() const { return net_id; } // Update functions + inline void set_fg_root (const string value) { fg_root = value; } inline void set_airport_id( const string id ) { airport_id = id; } + inline void set_lon (double value) { lon = value; } + inline void set_lat (double value) { lat = value; } + inline void set_altitude (double value) { altitude = value; } + inline void set_heading (double value) { heading = value; } + inline void set_roll (double value) { roll = value; } + inline void set_pitch (double value) { pitch = value; } + inline void set_uBody (double value) { uBody = value; } + inline void set_vBody (double value) { vBody = value; } + inline void set_wBody (double value) { wBody = value; } + inline void set_game_mode (bool value) { game_mode = value; } + inline void set_splash_screen (bool value) { splash_screen = value; } + inline void set_intro_music (bool value) { intro_music = value; } + inline void set_mouse_pointer (int value) { mouse_pointer = value; } + inline void set_pause (bool value) { pause = value; } inline void set_hud_status( bool status ) { hud_status = status; } + inline void set_sound (bool value) { sound = value; } + inline void set_flight_model (int value) { flight_model = value; } + inline void set_model_hz (int value) { model_hz = value; } + inline void set_fog (fgFogKind value) { fog = value; } inline void set_clouds( bool value ) { clouds = value; } inline void set_clouds_asl( double value ) { clouds_asl = value; } inline void set_fov( double amount ) { fov = amount; } + inline void set_fullscreen (bool value) { fullscreen = value; } + inline void set_shading (int value) { shading = value; } + inline void set_skyblend (bool value) { skyblend = value; } inline void set_textures( bool status ) { textures = status; } + inline void set_wireframe (bool status) { wireframe = status; } inline void cycle_fog( void ) { if ( fog == FG_FOG_DISABLED ) { fog = FG_FOG_FASTEST; @@ -291,6 +314,13 @@ public: void toggle_panel(); inline void set_xsize( int x ) { xsize = x; } inline void set_ysize( int y ) { ysize = y; } + inline void set_view_mode (fgViewMode value) { view_mode = value; } + inline void set_tile_radius (int value) { tile_radius = value; } + inline void set_tile_diameter (int value) { tile_diameter = value; } + inline void set_units (int value) { units = value; } + inline void set_tris_or_culled (int value) { tris_or_culled = value; } + inline void set_time_offset (int value) { time_offset = value; } + inline void set_time_offset_type (int value) { time_offset_type = value; } inline void cycle_view_mode() { if ( view_mode == FG_VIEW_PILOT ) { view_mode = FG_VIEW_FOLLOW; diff --git a/src/Main/save.cxx b/src/Main/save.cxx new file mode 100644 index 000000000..69f3b01ce --- /dev/null +++ b/src/Main/save.cxx @@ -0,0 +1,428 @@ +// save.cxx -- class to save and restore a flight. +// +// Written by Curtis Olson, started November 1999. +// +// Copyright (C) 1999 David Megginson - david@megginson.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +/* +CHANGES: +- time is now working +- autopilot is working (even with GPS) + +TODO: +- use a separate options object so that we can roll back on error +- use proper FGFS logging +- add view direction, and other stuff +*/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include +#include +#include +#include +#include +#include