adonthell-commits
[Top][All Lists]
Advanced

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

[Adonthell-commits] CVS: adonthell/src gettext.h,1.1,1.2 game.cc,1.24,1.


From: Kai Sterker <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/src gettext.h,1.1,1.2 game.cc,1.24,1.25 game.h,1.22,1.23 main.cc,1.39,1.40 prefs.cc,1.10,1.11 python_class.cc,1.5,1.6 python_class.h,1.6,1.7
Date: Sun, 07 Apr 2002 05:51:32 -0400

Update of /cvsroot/adonthell/adonthell/src
In directory subversions:/tmp/cvs-serv32214/src

Modified Files:
        game.cc game.h main.cc prefs.cc python_class.cc python_class.h 
Added Files:
        gettext.h 
Log Message:
PREPARED code for i18n and ttf support
CHANGED game class and initialization
ADDED new dlgedit



Index: game.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/game.cc,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** game.cc     26 Jan 2002 21:52:07 -0000      1.24
--- game.cc     7 Apr 2002 09:51:28 -0000       1.25
***************
*** 3,6 ****
--- 3,7 ----
  
     Copyright (C) 1999/2000/2001/2002 Kai Sterker <address@hidden>
+    Copyright (C) 2002 Alexandre Courbot <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
***************
*** 13,33 ****
  */
  
- #include <iostream>
- #include "win_manager.h"
- #include "win_theme.h"
- #include "input.h"
- #include "screen.h"
- #include "game.h"
- #include "character.h"
- #include "quest.h"
- 
- #include "python_class.h"
-  
- #include "audio.h"
- 
- 
  /**
   * @file   game.cc
   * @author Kai Sterker <address@hidden>
   * 
   * @brief  Defines the game class.
--- 14,21 ----
  */
  
  /**
   * @file   game.cc
   * @author Kai Sterker <address@hidden>
+  * @author Alexandre Courbot <address@hidden>
   * 
   * @brief  Defines the game class.
***************
*** 37,200 ****
  
  
  
! initflags game::initiated = INIT_NONE;
! PyObject * game::py_module = NULL;
  
! /*
!  * SWIG init prototypes. Should we use dynamic linking??? 
!  */
! extern "C"
  {
!     /** 
!      * SWIG init prototype.
!      * 
!      */
!     void initadonthellc (void);
  }
  
! 
! // Initialize all parts of the game engine
! bool game::init (config & configuration, initflags to_init = INIT_ALL)
  {
!     // init game loading/saving system
!     if (to_init & INIT_SAVES) 
!     { 
!         gamedata::init (configuration.get_adonthellrc (), 
configuration.gamedir, configuration.game_name); 
!     }
!     
!     // init video subsystem
!     if (to_init & INIT_VIDEO) 
!     { 
!         screen::set_video_mode (320, 240);
!         screen::set_fullscreen (configuration.screen_mode); 
!     }
!      
!     // init audio subsystem
!     if (to_init & INIT_AUDIO)
!     {
!         if (configuration.audio_volume > 0)
!             audio::init (&configuration);
!     }
!     
!     // init input subsystem
!     if (to_init & INIT_INPUT) 
!     { 
!         input::init ();
!     }
!     
!     // init python interpreter
!     if (to_init & INIT_PYTHON)
!     { 
!         python::init (); 
!         
!         // initialise python import paths, SWIG module and globals
!         init_python (); 
!         // init the game data
!         init_data (); 
!     }
  
!     // init window manager
!     if (to_init & INIT_WIN) 
      {
!         win_manager::init (); 
      }
!     
!     initiated = to_init;
!     
!     // voila :)
!     return true;
  }
  
! // Cleanup everything
! void game::cleanup () 
  {
!     // close all windows
!     // delete all themes and fonts
!     if (initiated & INIT_WIN)
!     { 
!         win_manager::cleanup (); 
!     }
!     
!     // shutdown input subsystem
!     if (initiated & INIT_INPUT) 
!     { 
!         input::shutdown ();
!     }
! 
!     // shutdown audio
!     if (initiated & INIT_AUDIO)
!     {
!         audio::cleanup ();
!     }
  
!     // cleanup the saves
!     if (initiated & INIT_SAVES) 
!     {
!         gamedata::cleanup (); 
!     }
!     
!     // shutdown python
!     if (initiated & INIT_PYTHON) 
      {
!         cleanup_data ();
!         cleanup_python (); 
!         python::cleanup ();     
      }
  
!     // shutdown video and SDL
!     if (initiated & INIT_VIDEO)
!     {
!         SDL_Quit ();
!     }     
  }
  
! void game::init_data ()
  {
!     data::engine = new adonthell;
!     data::the_player = NULL;
! }
  
! void game::cleanup_data () 
! {
!     delete data::engine;
!     data::engine = NULL;
  
!     if (data::the_player)
!     { 
!         delete data::the_player;
!         data::the_player = NULL;
!     }
  }
  
! bool game::init_python () 
  {
!     // Initialise the import path.
!     // Shared modules path 
!     python::insert_path (DATA_DIR"/modules"); 
! 
!     // Game specific path
!     string t = gamedata::game_data_dir () + "/scripts/modules"; 
!     python::insert_path((char *) t.c_str ());
!     t = gamedata::game_data_dir () + "/scripts"; 
!     python::insert_path((char *) t.c_str ());
! 
!     /* Initialise SWIG module. This should go if we ever switch to dynamic 
!        link */
!     initadonthellc();
!         
!     py_module = python::import_module ("adonthell"); 
!     if (!py_module)
!         return false;     
!     
!     data::globals = PyModule_GetDict (py_module);
  
!     return true; 
! }
  
! void game::cleanup_python () 
! {
!     // Cleanup the global namespace of python interpreter
!     // Note that we don't have to DECREF data::globals, because they're a
!     // borrowed reference of py_module.
!     Py_DECREF (py_module); 
  }
--- 25,114 ----
  
  
+ #include "game.h"
+ #include <stdlib.h>
+ #include <sys/types.h>
+ #include <dirent.h>
+ 
  
! string game::User_data_dir; 
! string game::Global_data_dir; 
! string game::Game_data_dir; 
  
! 
! void game::init (string game_dir = "") 
  {
!     Global_data_dir = DATA_DIR;
!     User_data_dir = getenv ("HOME");
!     User_data_dir += "/.adonthell";
!     Game_data_dir = game_dir; 
  }
  
! bool game::directory_exist (const string & dirname)
  {
!     DIR * dir = opendir (dirname.c_str ());
  
!     if (dir) 
      {
!         closedir (dir);
!         return true; 
      }
! 
!     return false; 
  }
  
! bool game::file_exist (const string & fname) 
  {
!     FILE * file = fopen (fname.c_str (), "r");
  
!     if (file) 
      {
!         fclose (file);
!         return true; 
      }
  
!     return false; 
  }
  
! string game::find_file (const string & fname) 
  {
!     string ret;
  
!     // If the name is already absolute, no need to search...
!     if (fname[0] == '/') return fname; 
!     
!     // First check in the current game directory
!     if ((ret = game_data_dir () + "/") != "/" && file_exist (ret + fname))
!         ret += fname; 
!     // Then check the global data directory
!     else if (file_exist ((ret = global_data_dir () + "/") + fname)) 
!         ret += fname;
!     // Finally, try the user data directory
!     else if (file_exist ((ret = user_data_dir () + "/") + fname))
!         ret += fname;
!     // Nothing found! So bad...
!     else ret = "";
  
!     return ret; 
  }
  
! string game::find_directory (const string & dirname) 
  {
!     string ret;
  
!     // If the name is already absolute, no need to search...
!     if (dirname[0] == '/') return dirname; 
  
!     // First check in the current game directory
!     if ((ret = game_data_dir () + "/") != "/" && directory_exist (ret + 
dirname))
!         ret += dirname; 
!     // Then check the global data directory
!     else if (directory_exist ((ret = global_data_dir () + "/") + dirname)) 
!         ret += dirname;
!     // Finally, try the user data directory
!     else if (directory_exist ((ret = user_data_dir () + "/") + dirname))
!         ret += dirname;
!     // Nothing found! So bad...
!     else ret = "";
! 
!     return ret; 
  }

Index: game.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/game.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** game.h      31 Aug 2001 15:34:10 -0000      1.22
--- game.h      7 Apr 2002 09:51:28 -0000       1.23
***************
*** 3,6 ****
--- 3,7 ----
  
     Copyright (C) 1999/2000/2001 Kai Sterker <address@hidden>
+    Copyright (C) 2002 Alexandre Courbot <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
***************
*** 17,20 ****
--- 18,22 ----
   * @file   game.h
   * @author Kai Sterker <address@hidden>
+  * @author Alexandre Courbot <address@hidden>
   * 
   * @brief  Declares the game class.
***************
*** 29,132 ****
  
  
! #include "prefs.h"
! #include "gamedata.h"
! #include "python_class.h"
  
  /**
!  * Flags that can be passed to game::init () in order to select
!  * which subsystems should be initialized.
   * 
!  */ 
! typedef
! enum
! { INIT_NONE = 0, INIT_VIDEO = 1, INIT_AUDIO = 2, INIT_PYTHON = 4, INIT_DATA = 
8, 
!   INIT_SAVES = 16, INIT_INPUT = 32, INIT_WIN =  64, INIT_ALL = 255 } 
initflags; 
! 
! /** Responsible for game initialisation and finalisation.
!  *  It has only a few methods, however they are critical as they
!  *  are responsible for all the game initialisation and cleanup - so they must
!  *  ABSOLUTELY be called as the first and last functions called in the main
!  *  program.
!  */ 
  class game
  {
  public:
!     /**
!      * %Game initialisation function.
!      * Reads the configuration file,  
!      * check the validity of the data directory and
!      * initialize the display, input, sound, data and Python systems.
!      * It MUST be called before ANY other function in the game.
!      *
!      * @param argc The argc that has been passed to the main program.
!      * @param argv The argv that has been passed to the main program.
!      * @return
!      *     - true Initialisation sucessfull.
!      *     - false Initialisation failure - don't go any further and
!      *             quit.
!      */ 
!     static bool init (config & configuration, initflags to_init = INIT_ALL);
! 
!     /** Cleanup everything and quit.
!      *  Performs the following:
!      *         -# Destroy the window manager (win_manager).
!      *         -# Write the %configuration file.
!      *         -# Cleanup data.
!      *         -# Shutdown audio.
!      *         -# Shutdown Python.
!      *         -# Shutdown SDL and video.
!      */ 
!     static void cleanup (); 
  
- private:
-     static string game_name_;
  
!     /**
!      * Keep trace of initiated subsystems.
       * 
!      */ 
!     static initflags initiated;
!          
!     /**
!      * Initialise the game's data.
       * 
-      */ 
-     static void init_data (); 
- 
-     /**
-      * Cleanup the game's data.
       * 
!      */ 
!     static void cleanup_data (); 
! 
!     /**
!      * Initialise Python's import paths, globals and game module.
!      *
!      * @ bug memory leak in initadonthellc, seems to come from SWIG.
!      * @ bug memory leak in module import.
       */
  
!     static bool init_python ();
! 
!     /**
!      * Free the globals.
       * 
       */
  
!     static void cleanup_python (); 
  
!     /**
!      * The Adonthell Python wrapper.
       * 
!      */ 
!     static PyObject *py_module;
  };
- 
- 
- /**
-  * @namespace data
-  * Namespace that holds game data that are publicly available.
-  * 
-  */
  
  
--- 31,130 ----
  
  
! #include <string>
! #include "types.h"
! 
! using std::string; 
  
  /**
!  * Holds information about global settings.
!  *
!  * This static class should be the first to be initialised in your 
application,
!  * because many others depends on it's correct settings.
   * 
!  */
  class game
  {
  public:
!     static string User_data_dir;
!     static string Global_data_dir;
!     static string Game_data_dir; 
  
  
!     /** 
!      * Initialise the game parameters. If you are in need to use data 
contained
!      * in a certain directory (most often, a game), you can pass it as a
!      * parameter.
       * 
!      * @param game_dir optional game data directory.
!      */
!     static void init (string game_dir = ""); 
!     
!     /** 
!      * Returns the absolute path to the user data directory (usually 
~/.adonthell).
       * 
       * 
!      * @return user data directory
       */
+     static string user_data_dir ()
+     {
+         return User_data_dir; 
+     }
  
!     /** 
!      * Returns the absolute path to the global data directory.
!      * 
       * 
+      * @return global data directory
       */
+     static string global_data_dir ()
+     {
+         return Global_data_dir; 
+     }
  
!     /** 
!      * Returns the absolute path to the current game's directory (if any).
!      * 
!      * 
!      * @return current game data directory, or empty string if none set.
!      */
!     static string game_data_dir ()
!     {
!         return Game_data_dir; 
!     }
! 
!     /** 
!      * Finds a file in the directories hierarchy, starting searching from
!      * game_data_dir(), then global_data_dir() and finally user_data_dir().
!      *
!      * If a matching file is found, the full absolute path is returned, else
!      * an empty string "" is returned. If the path was already absolute, it is
!      * returned immediatly.
!      * 
!      * @param fname name of the find to search for.
!      * 
!      * @return complete absolute path to the file if found, passed string if 
the given
!      *         path was already absolute, or "" if the file wasn't found.
!      */
!     static string find_file (const string & fname);
  
!     /** 
!      * Finds a directory in the directories hierarchy, starting searching from
!      * game_data_dir(), then global_data_dir() and finally user_data_dir().
!      *
!      * If a matching directory is found, the full absolute path is returned, 
else
!      * an empty string "" is returned. If the path was already absolute, it is
!      * returned immediatly.
!      * 
!      * @param fname name of the find to search for.
       * 
!      * @return complete absolute path to the directory if found, passed 
string if the given
!      *         path was already absolute, or "" if the directory wasn't found.
!      */
!     static string find_directory (const string & dirname); 
!     
! private:
!     static bool directory_exist (const string & dirname); 
!     static bool file_exist (const string & fname); 
  };
  
  

Index: main.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/main.cc,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -r1.39 -r1.40
*** main.cc     19 Oct 2001 15:05:58 -0000      1.39
--- main.cc     7 Apr 2002 09:51:28 -0000       1.40
***************
*** 23,27 ****
   */
  
! 
  
  #ifdef MEMORY_LEAKS
--- 23,35 ----
   */
  
! #include "audio.h"
! #include "character.h"
! #include "game.h"
! #include "gamedata.h"
! #include "input.h"
! #include "python_class.h"
! #include "screen.h"
! #include "win_manager.h"
! #include "win_theme.h"
  
  #ifdef MEMORY_LEAKS
***************
*** 29,34 ****
  #endif
  
- #include "game.h"
- 
  using namespace std; 
  
--- 37,40 ----
***************
*** 61,73 ****
      myconfig.parse_arguments (argc, argv);
  
!     // initialise the different parts of the engine
!     // (video, audio, python ...)
!     if (!game::init (myconfig)) return 1;
  
      // It's up to the game what happens here
      python::exec_file ("init");
  
!     // shut down the different parts of the engine
!     game::cleanup ();
  
      return 0;
--- 67,123 ----
      myconfig.parse_arguments (argc, argv);
  
!     // init game environment
!     game::init (myconfig.gamedir);
!     
!     // init game loading/saving system
!     gamedata::init (myconfig.get_adonthellrc (), myconfig.gamedir, 
myconfig.game_name); 
!     
!     // init video subsystem
!     screen::set_video_mode (320, 240);
!     screen::set_fullscreen (myconfig.screen_mode); 
!      
!     // init audio subsystem
!     if (myconfig.audio_volume > 0)
!         audio::init (&myconfig);
!     
!     // init input subsystem
!     input::init ();
!     
!     // init python interpreter
!     python::init (); 
! 
!     // init the game data
!     data::engine = new adonthell;
!     data::the_player = NULL;
! 
!     // init window manager
!     win_manager::init (); 
  
      // It's up to the game what happens here
      python::exec_file ("init");
  
!     // close all windows
!     // delete all themes and fonts
!     win_manager::cleanup (); 
!     
!     // shutdown input subsystem
!     input::shutdown ();
! 
!     // shutdown audio
!     audio::cleanup ();
! 
!     // cleanup the saves
!     gamedata::cleanup (); 
!     
!     // cleanup data
!     delete data::engine;
!     if (data::the_player)
!         delete data::the_player;
! 
!     // shutdown python
!     python::cleanup ();     
! 
!     // shutdown video and SDL
!     SDL_Quit ();
  
      return 0;

Index: prefs.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/prefs.cc,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** prefs.cc    11 Mar 2002 18:28:09 -0000      1.10
--- prefs.cc    7 Apr 2002 09:51:28 -0000       1.11
***************
*** 13,16 ****
--- 13,19 ----
  */
  
+ #ifdef HAVE_CONFIG_H
+ #include <config.h>
+ #endif
  #include <iostream> 
  #include <fstream> 
***************
*** 21,28 ****
  #include <unistd.h>
  
! #ifdef HAVE_GETOPT_H
! #include <getopt.h>
! #else
  #include <_getopt.h>
  #endif
  
--- 24,31 ----
  #include <unistd.h>
  
! #ifdef HAVE__GETOPT_H
  #include <_getopt.h>
+ #else
+ #include <getopt.h>
  #endif
  

Index: python_class.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/python_class.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** python_class.cc     19 Oct 2001 15:06:00 -0000      1.5
--- python_class.cc     7 Apr 2002 09:51:28 -0000       1.6
***************
*** 24,43 ****
  
  #include "python_class.h"
  #include <iostream> 
  
  PyObject * data::globals;
  
  using namespace std;
  
  /*
   * Start Python
   */
! void python::init (void)
  {
!     Py_Initialize();
  }
  
  void python::cleanup () 
  {     
      Py_Finalize ();
  }
--- 24,83 ----
  
  #include "python_class.h"
+ #include "game.h"
  #include <iostream> 
  
  PyObject * data::globals;
+ PyObject * python::module;
  
  using namespace std;
  
  /*
+  * SWIG init prototypes. Should we use dynamic linking??? 
+  */
+ extern "C"
+ {
+     /** 
+      * SWIG init prototype.
+      * 
+      */
+     void initadonthellc (void);
+ }
+ 
+ /*
   * Start Python
   */
! bool python::init ()
  {
!     Py_Initialize ();
!     
!     // Initialise the import path.
!     // Shared modules path 
!     insert_path (DATA_DIR"/modules"); 
! 
!     // Game specific path
!     string t = game::game_data_dir () + "/scripts/modules"; 
!     insert_path ((char *) t.c_str ());
!     t = game::game_data_dir () + "/scripts"; 
!     insert_path ((char *) t.c_str ());
! 
!     // Initialise SWIG module. This should go if we ever switch 
!     // to dynamic linking
!     initadonthellc ();
!         
!     module = import_module ("adonthell"); 
!     if (!module) return false;     
!     
!     data::globals = PyModule_GetDict (module);
! 
!     return true; 
  }
  
  void python::cleanup () 
  {     
+     // Cleanup the global namespace of python interpreter
+     // Note that we don't have to DECREF data::globals, because they're a
+     // borrowed reference of py_module.
+     Py_DECREF (module); 
+ 
      Py_Finalize ();
  }
***************
*** 75,79 ****
      if (!mod)
      {
!         cerr << "exec_file: " << filename << " load failed!" << endl;
          return false;
      }
--- 115,122 ----
      if (!mod)
      {
!         cerr << "exec_file: " << filename << " load failed: " << endl;
! #ifdef PY_DEBUG
!         show_traceback ();
! #endif
          return false;
      }
***************
*** 82,96 ****
  
      return true; 
- //     result = PyRun_SimpleFile (f, (char*) fn.c_str ());
- //     if (result != 0)
- //     {
- //          cerr << "exec_file: " << fn << " execution failed: " << endl;
- #ifdef PY_DEBUG
-          show_traceback ();
- #endif
- //     }
-     
- //     fclose (f);
- //     return result == 0;
  }
  
--- 125,128 ----
***************
*** 166,205 ****
  
      return c;
- }
- 
- 
- // Grab a function's code object from a Python module
- PyCodeObject *python::get_function_code (PyObject *module, const char* 
func_name)
- {
-     PyCodeObject *code = NULL;
- 
-     // Try to grab the function object
-     if (PyObject_HasAttrString (module, (char*) func_name))
-     {
-         PyObject *function = PyObject_GetAttrString (module, (char*) 
func_name);
- 
-         // If the function exists, get it's code object
-         if (function && PyCallable_Check (function))
-         {
-             code = (PyCodeObject *) PyObject_GetAttrString (function, 
"func_code");
- /*
-             cout << "code->co_flags   " << code->co_flags << endl;
-             cout << "code->co_nlocals " << code->co_nlocals << endl;
-             cout << "code->co_names ";
-             PyObject_Print (code->co_names, stdout, 0);       
-             cout << endl << "code->co_varnames ";
-             PyObject_Print (code->co_varnames, stdout, 0);
-             cout << endl << endl;
- */
-             //if (code->co_flags & CO_NEWLOCALS)
-             //    code->co_flags -= CO_NEWLOCALS;
-             // code->co_flags = 0;
-         }
- 
-         // Clean up
-         Py_XDECREF (function);
-     }
- 
-     return code;
  }
  
--- 198,201 ----

Index: python_class.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/python_class.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** python_class.h      23 Sep 2001 14:05:45 -0000      1.6
--- python_class.h      7 Apr 2002 09:51:28 -0000       1.7
***************
*** 50,54 ****
       * @return true in case of success, false otherwise.
       */
!     static void init (void);
  
      /**
--- 50,54 ----
       * @return true in case of success, false otherwise.
       */
!     static bool init ();
  
      /**
***************
*** 106,119 ****
      static PyObject *pass_instance (void* instance, const char* class_name);
  
-     /**
-      * Return a function defined in the module as a code %object!
-      *
-      * @param pointer to the module.
-      * @param func_name name of the function to grab.
-      *
-      * @return pointer to the code %object, or NULL if the function does not 
exist.
-      */
-     static PyCodeObject *get_function_code (PyObject *module, const char* 
func_name);
- 
      /** 
       * Loads a Python tuple previously saved with put_tuple ().
--- 106,109 ----
***************
*** 138,145 ****
  private:
      /**
!      * Convert a Pointer to a String, like SWIG 1.3.7 does
       *
       */
      static char *python::ptr_to_string (char *c, void *ptr, int sz);
  };
  
--- 128,137 ----
  private:
      /**
!      * Convert a Pointer to a String, like SWIG 1.3.7+ does
       *
       */
      static char *python::ptr_to_string (char *c, void *ptr, int sz);
+ 
+     static PyObject *module;
  };
  




reply via email to

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