feuerkraft-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Feuerkraft-CVS] rev 322 - in trunk/src: . input


From: Ingo Ruhnke
Subject: [Feuerkraft-CVS] rev 322 - in trunk/src: . input
Date: Thu, 11 Dec 2003 02:36:40 +0100

Author: grumbel
Date: 2003-12-11 02:36:40 +0100 (Thu, 11 Dec 2003)
New Revision: 322

Modified:
   trunk/src/command_line_arguments.cxx
   trunk/src/command_line_arguments.hxx
   trunk/src/feuerkraft.cxx
   trunk/src/game_session.cxx
   trunk/src/input/input_manager.cxx
   trunk/src/input/input_manager.hxx
   trunk/src/input/input_manager_player.cxx
Log:
- switched from argp to CL_CommandLine
- added a bunch of options for doing playback and recording of demos

Modified: trunk/src/command_line_arguments.cxx
===================================================================
--- trunk/src/command_line_arguments.cxx        2003-12-10 23:08:47 UTC (rev 
321)
+++ trunk/src/command_line_arguments.cxx        2003-12-11 01:36:40 UTC (rev 
322)
@@ -20,29 +20,9 @@
 #include <config.h>
 #include <iostream>
 #include <stdlib.h>
-#include <argp.h>
+#include <ClanLib/Core/System/command_line.h>
 #include "command_line_arguments.hxx"
 
-const char *argp_program_version     = PACKAGE_STRING;
-const char *argp_program_bug_address = "Ingo Ruhnke <address@hidden>";
-
-static char doc[] = "Feuerkraft is a tank battle game";
-
-static struct argp_option options[] = {
-  {"verbose",    'v', 0,         0,  "Produce verbose output" },
-  {"quiet",      'q', 0,         0,  "Produce no output" },
-  {"fullscreen", 'w', 0,         0,  "Switch to Fullscreen on startup" },
-  {"datadir",    'd', 0,         0,  "Set the path to search for gamedata" },
-  {"fps",        'f', "FPS",     0,  "Limit of frames per second" },
-  {"music",      'm', 0,         0,  "Enable music" },
-  {"sound",      's', 0,         0,  "Enable sound" },
-  {"controller", 'c', "FILE",    0,  "Use controller as defined in FILE" },
-  {"geometry",   'g', "WIDTHxHEIGHT", 0,  "Set screen size" },
-  { 0 }
-};
-
-static struct argp argp = { options, 
CommandLineArguments::parse_option_static, "MISSIONFILE", doc, 0, 0 };
-
 CommandLineArguments::CommandLineArguments()
 {
   load_defaults();
@@ -75,90 +55,113 @@
 void
 CommandLineArguments::parse_arguments(int argc, char** argv)
 {
-  argp_parse(&argp, argc, argv, 0, 0, this);
-}
+  CL_CommandLine argp;
+    
+  argp.set_help_indent(22);
+  argp.add_usage ("[LEVELFILE]");
+  argp.add_doc   ("Feuerkraft is a tank battle game");
 
-error_t
-CommandLineArguments::parse_option_static(int key, char *arg, struct 
argp_state *state)
-{ // Dispatch to the CommandLineArguments object
-  return static_cast<CommandLineArguments*>(state->input)->parse_option(key, 
arg, state);
-}
+  argp.add_group("General Options:");
+  argp.add_option('v', "verbose", "",  "Produce verbose output");
+  argp.add_option('V', "version", "",  "Print the exact version of the game");
+  argp.add_option('q', "quiet",   "",  "Produce no output");
+  argp.add_option('h', "help",   "",   "Produce this help output");
+  argp.add_option('d', "datadir", "DATADIR", "Set the path to search for 
gamedata");
 
-error_t
-CommandLineArguments::parse_option(int key, char *arg, struct argp_state 
*state)
-{
-  switch(key)
+  argp.add_group("Display Options:");
+  argp.add_option('g', "geometry",   "WIDTHxHEIGHT", "Set screen size");
+  argp.add_option('w', "fullscreen", "",    "Switch to Fullscreen on startup");
+  argp.add_option('f', "fps",        "FPS", "Limit of frames per second");
+
+  argp.add_group("Audio Options:");
+  argp.add_option('m', "music", "",  "Enable music");
+  argp.add_option('s', "sound", "",  "Enable sound");
+
+  argp.add_group("Input Options:");
+  argp.add_option('c', "controller", "FILE",   "Use controller as defined in 
FILE");
+
+  argp.add_group("Demo Recording/Playback Options:");
+  argp.add_option('r', "record",      "FILE", "Record input events to FILE");
+  argp.add_option('a', "record-video","DIR",  "Record a gameplay video to 
DIR");
+  argp.add_option('p', "play",        "FILE", "Playback input events from 
FILE");
+
+  argp.parse_args(argc, argv);
+
+  while (argp.next())
     {
-    case ARGP_KEY_ARGS:
-      break;
-    case ARGP_KEY_NO_ARGS:
-      break;
-    case ARGP_KEY_INIT:
-      break;
-    case ARGP_KEY_FINI:
-      break;
-    case ARGP_KEY_END:
-      break;
-    case ARGP_KEY_SUCCESS:
-      break;
-    case ARGP_KEY_ERROR:
-      std::cout << "ERROR" << std::endl;
-      break;
-      
-    case ARGP_KEY_ARG:
-      mission_file = arg;
-      break;
+      switch(argp.get_key())
+        {
+        case CL_CommandLine::REST_ARG:
+          mission_file = argp.get_argument();
+          break;
 
-    case 'f':
-      fps = strtof(arg, 0);
-      break;
+        case 'a':
+          video_record_directory = argp.get_argument();
+          break;
 
-    case 'V':
-      std::cout << PACKAGE_STRING << std::endl;
-      exit(EXIT_SUCCESS);
-      break;
+        case 'r':
+          event_record_file = argp.get_argument();
+          break;
 
-    case 'v':
-      verbose = true;
-      break;
+        case 'h':
+          argp.print_help();
+          exit(EXIT_SUCCESS);
+          break;
 
-    case 'd':
-      datadir = arg;
-      break;
+        case 'p':
+          playback_file = argp.get_argument();
+          break;
 
-    case 'q':
-      verbose = false;
-      break;
+        case 'f':
+          fps = strtof(argp.get_argument().c_str(), 0);
+          break;
 
-    case 'm':
-      music_enabled = true;
-      break;
+        case 'V':
+          std::cout << PACKAGE_STRING << std::endl;
+          exit(EXIT_SUCCESS);
+          break;
 
-    case 'c':
-      controller_file = arg;
-      break;
+        case 'v':
+          verbose = true;
+          break;
 
-    case 's':
-      sound_enabled = true;
-      break;
+        case 'd':
+          datadir = argp.get_argument();
+          break;
 
-    case 'w':
-      fullscreen = true;
-      break;
+        case 'q':
+          verbose = false;
+          break;
 
-    case 'g':
-      if (sscanf(arg, "%dx%d", &screen_width, &screen_height) != 2)
-        {
-          std::cout << "Screen size value incorrect: '" << arg << "'" << 
std::endl;
-          exit(EXIT_FAILURE);
+        case 'm':
+          music_enabled = true;
+          break;
+
+        case 'c':
+          controller_file = argp.get_argument();
+          break;
+
+        case 's':
+          sound_enabled = true;
+          break;
+
+        case 'w':
+          fullscreen = true;
+          break;
+
+        case 'g':
+          if (sscanf(argp.get_argument().c_str(), "%dx%d", &screen_width, 
&screen_height) != 2)
+            {
+              std::cout << "Screen size value incorrect: '" << 
argp.get_argument() << "'" << std::endl;
+              exit(EXIT_FAILURE);
+            }
+          break;
+
+        default: 
+          std::cout << "CommandLineArguments: Unhandled key: " << 
argp.get_key() << std::endl;
+          break;
         }
-      break;
-
-    default: 
-      std::cout << "CommandLineArguments: Unhandled key: " << key << std::endl;
-      break;
     }
-  return 0;
 }
 
 /* EOF */

Modified: trunk/src/command_line_arguments.hxx
===================================================================
--- trunk/src/command_line_arguments.hxx        2003-12-10 23:08:47 UTC (rev 
321)
+++ trunk/src/command_line_arguments.hxx        2003-12-11 01:36:40 UTC (rev 
322)
@@ -20,7 +20,6 @@
 #ifndef HEADER_FEUERKRAFT_COMMAND_LINE_ARGUMENTS_HXX
 #define HEADER_FEUERKRAFT_COMMAND_LINE_ARGUMENTS_HXX
 
-#include <argp.h>
 #include <string>
 
 /** */
@@ -37,6 +36,15 @@
   std::string datadir;
   std::string controller_file;
 
+  /** File to which all input events should be logged */
+  std::string event_record_file;
+
+  /** Directory to which gameplay-video (aka screenshots) get saved */
+  std::string video_record_directory;
+
+  /** File from which recorded events will be played back */
+  std::string playback_file;
+
   /** number of fps to which the game should limit itself */
   float fps;
 
@@ -55,13 +63,6 @@
 
   void load_defaults();
   void parse_arguments(int argc, char** argv);
-
-private:
-  error_t parse_option(int key, char *arg, struct argp_state *state);
-
-public:  
-  /** Dispatch dummy */
-  static error_t parse_option_static(int key, char *arg, struct argp_state 
*state);
 };
 
 #endif

Modified: trunk/src/feuerkraft.cxx
===================================================================
--- trunk/src/feuerkraft.cxx    2003-12-10 23:08:47 UTC (rev 321)
+++ trunk/src/feuerkraft.cxx    2003-12-11 01:36:40 UTC (rev 322)
@@ -110,7 +110,14 @@
   Fonts::init();
 
   KeyboardManager::instance();
-  InputManager::init();
+
+  if (args->playback_file.empty())
+    InputManager::init(args->controller_file);
+  else
+    InputManager::init_playback(args->playback_file);
+
+  if (!args->event_record_file.empty())
+    InputManager::setup_recorder(args->event_record_file);
 }
 
 void 
@@ -126,15 +133,15 @@
 int
 Feuerkraft::main(int argc, char** argv)
 {
-  // Make arguments accessible for all member functions
-  args = new CommandLineArguments(argc, argv);
-
   // Create a console window for text-output if not available
   CL_ConsoleWindow console("Console");
   console.redirect_stdio();
   
   try
     {
+      // Make arguments accessible for all member functions
+      args = new CommandLineArguments(argc, argv);
+
       // Init all subsystems
       init();
       

Modified: trunk/src/game_session.cxx
===================================================================
--- trunk/src/game_session.cxx  2003-12-10 23:08:47 UTC (rev 321)
+++ trunk/src/game_session.cxx  2003-12-11 01:36:40 UTC (rev 322)
@@ -234,8 +234,16 @@
   // Flip front and backbuffer. This makes the changes visible:
   CL_Display::flip ();
 
-  if (0) // AVI
-    Screenshot::write_screenshot_pnm("/tmp/feuerkraft/" + to_string(frames));
+  if (!args->video_record_directory.empty())
+    {
+      std::stringstream filename;
+      filename << args->video_record_directory;
+      filename.width(8);
+      filename.fill('0');
+      filename << frames;
+      filename << ".ppm";
+      Screenshot::write_screenshot_pnm(filename.str());
+    }
 
   ++frames;
            
@@ -276,7 +284,7 @@
     {
     case MENU_CONTROL:
       if (DisplayManager::current()->get_menu())
-        
DisplayManager::current()->get_menu()->process_events(InputManager::get_events());
+        
DisplayManager::current()->get_menu()->process_events(InputManager::get_controller().get_events());
       else
         {
           std::cout << "Error: Menu not available, fallback to unit" << 
std::endl;

Modified: trunk/src/input/input_manager.cxx
===================================================================
--- trunk/src/input/input_manager.cxx   2003-12-10 23:08:47 UTC (rev 321)
+++ trunk/src/input/input_manager.cxx   2003-12-11 01:36:40 UTC (rev 322)
@@ -34,78 +34,62 @@
 InputRecorder* InputManager::recorder = 0;
 
 void
-InputManager::init(InputManagerImpl* arg_impl)
+InputManager::init_playback(const std::string& filename)
 {
-  if (impl)
-    {
-      delete impl;
-      impl = 0;
-    }
+  impl = new InputManagerPlayer(filename);
+}
 
-  if (recorder)
+void
+InputManager::init(const std::string& filename)
+{
+  if (!filename.empty())
     {
-      delete recorder;
-      recorder = 0;
-    }
+      std::cout << "Reading: " << args->controller_file << std::endl;
+      SCM port = scm_open_file(gh_str02scm(args->controller_file.c_str()),
+                               gh_str02scm("r"));
+      SCM lst  = scm_read(port);
 
-  if (0)
-    {
-      recorder = new InputRecorder("/tmp/feuerkraft.rec");
-    }
+      gh_call1(gh_lookup("display"), lst);
+      gh_call1(gh_lookup("display"), gh_car(lst));
+      gh_call1(gh_lookup("display"), gh_symbol2scm("feuerkraft-controller"));
 
-  if (arg_impl)
-    { 
-      impl = arg_impl;
-    }
-  else
-    {
-      if (!args->controller_file.empty())
+      if (gh_equal_p(gh_symbol2scm("feuerkraft-controller"), gh_car(lst)))
         {
-          std::cout << "Reading: " << args->controller_file << std::endl;
-          SCM port = scm_open_file(gh_str02scm(args->controller_file.c_str()),
-                                   gh_str02scm("r"));
-          SCM lst  = scm_read(port);
-
-          gh_call1(gh_lookup("display"), lst);
-          gh_call1(gh_lookup("display"), gh_car(lst));
-          gh_call1(gh_lookup("display"), 
gh_symbol2scm("feuerkraft-controller"));
-
-          if (gh_equal_p(gh_symbol2scm("feuerkraft-controller"), gh_car(lst)))
-            {
-              impl = new InputManagerCustom(gh_cdr(lst));
-            }
-          else
-            {
-              std::cout << "Error: not a valid controller file: " << 
args->controller_file << std::endl;
-            }
-          scm_close_port(port);
+          impl = new InputManagerCustom(gh_cdr(lst));
         }
-      
-      if (!impl)
-        { 
-          if (0)
-            { // AVI
-              impl = new InputManagerPlayer("/tmp/feuerkraft1.rec");
-            }
-          else
-            {
-              // FIXME: Default to keyboard would be better
-              // Set default configuration
-              impl = new InputManagerCustom
-                (gh_eval_str("'("
-                             "(primary-button   (joystick-button 1 9))"
-                             "(secondary-button (joystick-button 1 8))"
-                             "(use-button       (joystick-button 1 3))"
-                             "(menu-button      (joystick-button 1 2))"
-                             "(orientation-axis (joystick-axis 1 0))"
-                             "(accelerate-axis  (joystick-axis 1 1))"
-                             "(strafe-axis      (joystick-axis 1 2))"
-                             ")"));
-            }
-        }     
+      else
+        {
+          std::cout << "Error: not a valid controller file: " << 
args->controller_file << std::endl;
+        }
+      scm_close_port(port);
     }
+      
+  if (!impl)
+    { 
+      // FIXME: Default to keyboard would be better
+      // Set default configuration
+      impl = new InputManagerCustom
+        (gh_eval_str("'("
+                     "(primary-button   (joystick-button 1 9))"
+                     "(secondary-button (joystick-button 1 8))"
+                     "(use-button       (joystick-button 1 3))"
+                     "(menu-button      (joystick-button 1 2))"
+                     "(orientation-axis (joystick-axis 1 0))"
+                     "(accelerate-axis  (joystick-axis 1 1))"
+                     "(strafe-axis      (joystick-axis 1 2))"
+                     ")"));
+    }     
 }
 
+void
+InputManager::setup_recorder(const std::string& filename)
+{
+  if (recorder)
+    delete recorder;
+
+  recorder = new InputRecorder(filename);
+}
+
 void 
 InputManager::deinit()
 {
@@ -121,13 +105,6 @@
     recorder->record(get_controller());
 }
 
-InputEventLst
-InputManager::get_events()
-{
-  assert(impl);
-  return impl->get_events();
-}
-
 Controller
 InputManager::get_controller()
 {

Modified: trunk/src/input/input_manager.hxx
===================================================================
--- trunk/src/input/input_manager.hxx   2003-12-10 23:08:47 UTC (rev 321)
+++ trunk/src/input/input_manager.hxx   2003-12-11 01:36:40 UTC (rev 322)
@@ -34,11 +34,17 @@
   static InputManagerImpl* impl;
   static InputRecorder* recorder;
 public:
-  static void init(InputManagerImpl* arg_impl = 0);
+  /** Init the InputManager with the data found in \a filename */
+  static void init(const std::string& filename = std::string());
+
+  /** Init the playback of a previously recorded file */
+  static void init_playback(const std::string& filenam);
   static void deinit();
 
+  /** Record all input events to \a filename */
+  static void setup_recorder(const std::string& filename);
+
   static void update(float delta);
-  static InputEventLst get_events();
   static Controller get_controller();
   static void clear();
 private:

Modified: trunk/src/input/input_manager_player.cxx
===================================================================
--- trunk/src/input/input_manager_player.cxx    2003-12-10 23:08:47 UTC (rev 
321)
+++ trunk/src/input/input_manager_player.cxx    2003-12-11 01:36:40 UTC (rev 
322)
@@ -78,7 +78,7 @@
 void
 InputManagerPlayer::update(float delta)
 {
-  std::cout << "Got: " << entry_counter << " " << entries.front().entry_num << 
std::endl;
+  //std::cout << "Got: " << entry_counter << " " << entries.front().entry_num 
<< std::endl;
   if (entries.front().entry_num == entry_counter)
     {
       events = entries.front().events;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]