adonthell-commits
[Top][All Lists]
Advanced

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

[Adonthell-commits] CVS: adonthell/src Makefile.am,1.98,1.99 adonthell.


From: Kai Sterker <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/src Makefile.am,1.98,1.99 adonthell.cc,1.9,1.10 audio.cc,1.31,1.32 event.cc,1.19,1.20 item_base.cc,1.1,1.2 item_base.h,1.1,1.2 py_object.cc,1.13,1.14 py_object.h,1.9,1.10 win_wrappers.h,1.9,1.10
Date: Thu, 16 Jan 2003 06:22:47 -0500

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

Modified Files:
        Makefile.am adonthell.cc audio.cc event.cc item_base.cc 
        item_base.h py_object.cc py_object.h win_wrappers.h 
Log Message:
ADDED more attribute access methods to PyObject class


Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Makefile.am,v
retrieving revision 1.98
retrieving revision 1.99
diff -C2 -r1.98 -r1.99
*** Makefile.am 12 Jan 2003 23:24:29 -0000      1.98
--- Makefile.am 16 Jan 2003 11:22:45 -0000      1.99
***************
*** 55,59 ****
  py_adonthell_wrap.cc : py_adonthell.i $(headers)
        @if test "${P_SWIG}"; then \
!          ${P_SWIG} -python -shadow ${SDL_CFLAGS} -I$(srcdir) -I$(srcdir)/.. 
-c++ -make_default -o $(srcdir)/$*.cc $(srcdir)/py_adonthell.i; \
             mv $(srcdir)/adonthell.py modules/adonthell.py; \
        else \
--- 55,59 ----
  py_adonthell_wrap.cc : py_adonthell.i $(headers)
        @if test "${P_SWIG}"; then \
!          ${P_SWIG} -python -shadow ${SDL_CFLAGS} -I$(srcdir) -I$(srcdir)/.. 
-c++ -makedefault -o $(srcdir)/$*.cc $(srcdir)/py_adonthell.i; \
             mv $(srcdir)/adonthell.py modules/adonthell.py; \
        else \

Index: adonthell.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/adonthell.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** adonthell.cc        11 Aug 2002 11:58:21 -0000      1.9
--- adonthell.cc        16 Jan 2003 11:22:45 -0000      1.10
***************
*** 93,97 ****
          win_manager::active->input_update ();
          if (update_map ()) lmap.update ();
!         win_manager::active->update ();
          if (control_active ()) control.run ();
      }
--- 93,97 ----
          win_manager::active->input_update ();
          if (update_map ()) lmap.update ();
!         // win_manager::active->update ();
          if (control_active ()) control.run ();
      }
***************
*** 99,102 ****
--- 99,104 ----
      if (!letsexit) 
      {
+         win_manager::active->update ();
+ 
          // first clear the screen to avoid artifacts
          screen::clear ();

Index: audio.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/audio.cc,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -r1.31 -r1.32
*** audio.cc    25 Apr 2002 15:34:11 -0000      1.31
--- audio.cc    16 Jan 2003 11:22:45 -0000      1.32
***************
*** 331,335 ****
  
      // Save the schedule script state
!     schedule.object_file () >> file;
      if (schedule_args) 
      {
--- 331,335 ----
  
      // Save the schedule script state
!     schedule.class_name () >> file;
      if (schedule_args) 
      {

Index: event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.cc,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** event.cc    2 Sep 2002 10:57:41 -0000       1.19
--- event.cc    16 Jan 2003 11:22:45 -0000      1.20
***************
*** 146,150 ****
          case ACTION_SCRIPT:
          {
!             Script->object_file () >> file;
      
              if (Args)
--- 146,150 ----
          case ACTION_SCRIPT:
          {
!             Script->class_name () >> file;
      
              if (Args)

Index: item_base.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** item_base.cc        12 Jan 2003 23:24:29 -0000      1.1
--- item_base.cc        16 Jan 2003 11:22:45 -0000      1.2
***************
*** 25,29 ****
  
  // ctor
! item_base::item_base (std::string item) : py_object ()
  {
      std::cout << "Item instance of '" << item << "' created" << endl;
--- 25,29 ----
  
  // ctor
! item_base::item_base (const std::string & item)
  {
      std::cout << "Item instance of '" << item << "' created" << endl;
***************
*** 46,54 ****
      
      // set derived item instance
!     Py_XDECREF (instance);
!     instance = item;
      
      // init basic attributes
!     charge = 0;
  }
  
--- 46,55 ----
      
      // set derived item instance
!     Py_XDECREF (Instance);
!     Instance = item;
      
      // init basic attributes
!     Charge = 0;
!     MaxCharge = 0;
  }
  
***************
*** 84,89 ****
  {
      // only add if item does not already belong to that category
!     if (find (types.begin (), types.end (), type) != types.end ())
!         types.push_back (type);
  }
  
--- 85,90 ----
  {
      // only add if item does not already belong to that category
!     if (find (Types.begin (), Types.end (), type) != Types.end ())
!         Types.push_back (type);
  }
  
***************
*** 91,95 ****
  void item_base::remove_type (const std::string &type)
  {
!     types.erase (remove (types.begin (), types.end (), type), types.end ());
  }
  
--- 92,96 ----
  void item_base::remove_type (const std::string &type)
  {
!     Types.erase (remove (Types.begin (), Types.end (), type), Types.end ());
  }
  
***************
*** 122,123 ****
--- 123,139 ----
      return true;
  }
+ 
+ // recharge item
+ u_int16 item_base::recharge (u_int16 &charge)
+ {
+     Charge += charge;
+ 
+     if (Charge > MaxCharge)
+     {
+         charge = Charge - MaxCharge;
+         Charge = MaxCharge;
+     }
+     else charge = 0;
+     
+     return charge;
+ }
\ No newline at end of file

Index: item_base.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/item_base.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** item_base.h 12 Jan 2003 23:24:29 -0000      1.1
--- item_base.h 16 Jan 2003 11:22:45 -0000      1.2
***************
*** 37,45 ****
  {
  public:
      /**
!      * Create a new item from the given template. 
!      * @param item Name of the Python class defining the desired item.
       */
!     item_base (string item);
      
      /**
--- 37,51 ----
  {
  public:
+ 
      /**
!      * Default constructor. Creates an empty item.
       */
!     item_base () : py_object () {};
!     
!     /**
!      * Create a new item from the given item data. 
!      * @param item Name of the item data file defining the desired item.
!      */
!     item_base (const string &item);
      
      /**
***************
*** 81,84 ****
--- 87,115 ----
       */
      void remove_type (const string &type);
+ 
+     /**
+      * Get the charge the item has left.
+      * @return number of charges the item has.
+      */
+     u_int16 charge ()                       { return Charge; }
+ 
+     /**
+      * Add charges to the item. Recharges the item up to MaxCharge.
+      * @param charge number of charges to add.
+      * @return number of charges not added to the item
+      */
+     u_int16 recharge (u_int16 & charge);
+ 
+     /**
+      * Get the maximum number of charges the item may hold.
+      * @return item's maximum number of charges.
+      */
+     u_int16 max_charge ()                   { return MaxCharge; }
+ 
+     /**
+      * Set the maximum number of charges the item may hold.
+      * @param item's maximum number of charges.
+      */
+     void set_max_charge (u_int max_charge)  { MaxCharge = max_charge; }
      //@}
      
***************
*** 108,111 ****
--- 139,143 ----
      //@}
  
+ private:
      /**
       * @name Basic Item Attributes
***************
*** 115,124 ****
       * List of categories this item belongs to.
       */
!     std::vector<std::string> types;
      
      /**
       * Fuel or number of uses an item has.
       */
!     u_int16 charge;
      //@}
  };
--- 147,161 ----
       * List of categories this item belongs to.
       */
!     std::vector<std::string> Types;
      
      /**
       * Fuel or number of uses an item has.
       */
!     u_int16 Charge;
! 
!     /**
!      * Maximum amount of charge the item may have.
!      */
!     u_int16 MaxCharge;
      //@}
  };

Index: py_object.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/py_object.cc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** py_object.cc        10 Aug 2002 22:02:01 -0000      1.13
--- py_object.cc        16 Jan 2003 11:22:45 -0000      1.14
***************
*** 29,34 ****
  py_object::py_object ()
  {
!     instance = NULL;
!     script_file_ = "";
  }
  
--- 29,35 ----
  py_object::py_object ()
  {
!     Instance = NULL;
!     Filename = "";
!     Classname = "";
  }
  
***************
*** 41,49 ****
  void py_object::clear ()
  {
!     // Delete our instance
!     Py_XDECREF (instance);
!     instance = NULL;
!     
!     script_file_ = "";
  }
  
--- 42,51 ----
  void py_object::clear ()
  {
!     // Delete our Instance
!     Py_XDECREF (Instance);
!     Instance = NULL;
! 
!     Filename = "";
!     Classname = "";
  }
  
***************
*** 82,93 ****
      PyObject * classobj = PyObject_GetAttrString (module, (char *) 
classname.c_str ());
      Py_DECREF (module);
!     if (!classobj) return false;
! 
!     // Create the instance
!     instance = PyObject_CallObject (classobj, args);
      Py_DECREF (classobj);
!     if (!instance) return false;
  
!     script_file_ = classname;
  
      return true;
--- 84,104 ----
      PyObject * classobj = PyObject_GetAttrString (module, (char *) 
classname.c_str ());
      Py_DECREF (module);
!     if (!classobj)
!     {
!         python::show_traceback ();
!         return false;
!     }
!     
!     // Create the Instance
!     Instance = PyObject_CallObject (classobj, args);
      Py_DECREF (classobj);
!     if (!Instance)
!     {
!         python::show_traceback ();
!         return false;
!     }
  
!     Filename = file;
!     Classname = classname;
  
      return true;
***************
*** 98,110 ****
  {
      PyObject *result = NULL;
!      
!     if (instance)
      {
!         PyObject *tocall = PyObject_GetAttrString (instance, (char *) 
name.c_str ());
  
          if (PyCallable_Check (tocall) == 1)
!         {    
              result = PyObject_CallObject (tocall, args);
!             Py_DECREF (tocall); 
          }
  #ifdef PY_DEBUG
--- 109,121 ----
  {
      PyObject *result = NULL;
! 
!     if (Instance)
      {
!         PyObject *tocall = PyObject_GetAttrString (Instance, (char *) 
name.c_str ());
  
          if (PyCallable_Check (tocall) == 1)
!         {
              result = PyObject_CallObject (tocall, args);
!             Py_DECREF (tocall);
          }
  #ifdef PY_DEBUG
***************
*** 112,134 ****
  #endif
      }
!     
      return result;
  }
  
  // Get an attribute of the instance
  PyObject *py_object::get_attribute (const string &name)
  {
!     if (instance)
!         return PyObject_GetAttrString (instance, (char *) name.c_str ());
      else
          return NULL;
  }
  
! // check for a certain attribute
! bool py_object::has_attribute (const std::string & name)
  {
!     if (instance)
!         return PyObject_HasAttrString (instance, (char *) name.c_str ());
      else
!         return false;
  }
--- 123,218 ----
  #endif
      }
! 
      return result;
  }
  
+ // check for a certain attribute
+ bool py_object::has_attribute (const std::string & name)
+ {
+     if (Instance)
+         return PyObject_HasAttrString (Instance, (char *) name.c_str ());
+     else
+         return false;
+ }
+ 
  // Get an attribute of the instance
  PyObject *py_object::get_attribute (const string &name)
  {
!     if (Instance)
!         return PyObject_GetAttrString (Instance, (char *) name.c_str ());
      else
          return NULL;
  }
  
! // Get an int attribute of the instance
! s_int32 py_object::get_attribute_int (const string &name)
  {
!     if (Instance)
!     {
!         PyObject *attribute = PyObject_GetAttrString (Instance, (char *) 
name.c_str ());
!         if (!attribute) return 0;
! 
!         s_int32 value = PyInt_AsLong (attribute);
!         Py_DECREF (attribute);
!         
!         return value;
!     }
      else
!         return 0;
! }
! 
!  // Get a string attribute of the instance
! string py_object::get_attribute_string (const string &name)
! {
!     if (Instance)
!     {
!         PyObject *attribute = PyObject_GetAttrString (Instance, (char *) 
name.c_str ());
!         if (!attribute) return 0;
! 
!         string value = PyString_AsString (attribute);
!         Py_DECREF (attribute);
! 
!         return value;
!     }
!     else
!         return string ("");
! }
! 
! // Set an attribute of the instance
! void py_object::set_attribute (const string &name, PyObject *value)
! {
!     if (Instance)
!         if (PyObject_SetAttrString (Instance, (char *) name.c_str (), value) 
== -1)
!             python::show_traceback ();
!     else return;
! }
! 
! // Set an int attribute of the instance
! void py_object::set_attribute_int (const string &name, int value)
! {
!     if (Instance)
!     {
!         PyObject *val = PyInt_FromLong (value);
! 
!         if (PyObject_SetAttrString (Instance, (char *) name.c_str (), val) == 
-1)
!             python::show_traceback ();
! 
!         Py_DECREF (val);
!     }
!     else return;
! }
! 
! // Set a string attribute of the instance
! void py_object::set_attribute_string (const string &name, const string & 
value)
! {
!     if (Instance)
!     {
!         PyObject *val = PyString_FromString (value.c_str ());
! 
!         if (PyObject_SetAttrString (Instance, (char *) name.c_str (), val) == 
-1)
!             python::show_traceback ();
! 
!         Py_DECREF (val);
!     }
!     else return;
  }

Index: py_object.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/py_object.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** py_object.h 12 Jan 2003 23:24:29 -0000      1.9
--- py_object.h 16 Jan 2003 11:22:45 -0000      1.10
***************
*** 2,7 ****
     $Id$
  
!    Copyright (C) 1999/2000/2001    Kai Sterker
!    Copyright (C) 2001    Alexandre Courbot
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
--- 2,7 ----
     $Id$
  
!    Copyright (C) 1999/2000/2001/2003 Kai Sterker <address@hidden>
!    Copyright (C) 2001 Alexandre Courbot <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
***************
*** 21,37 ****
   * 
   * @brief  Declares the py_object class.
-  * 
-  * 
   */
  
  
! #ifndef PY_OBJECT_H_
! #define PY_OBJECT_H_
! 
! 
  #include <string>
  #include "python_class.h"
  
! using namespace std; 
  
  
--- 21,34 ----
   * 
   * @brief  Declares the py_object class.
   */
  
  
! #ifndef PY_OBJECT_H
! #define PY_OBJECT_H
!                    
  #include <string>
  #include "python_class.h"
  
! using std::string; 
  
  
***************
*** 39,46 ****
   * Python object class.
   *
!  * Use this class to create instances of Python classes
!  * contained in Python modules, then control their execution. You can pass
!  * arguments to the class constructor when the script is imported, then to
!  * any method you want to run.
   * 
   */ 
--- 36,43 ----
   * Python object class.
   *
!  * Use this class to create instances of Python classes contained in Python
!  * modules, then control their execution. You can pass an argument tuple to
!  * the class constructor and to any method you want to run. It is further
!  * possible to access and change attributes of the Python instance.
   * 
   */ 
***************
*** 65,69 ****
       */
      void clear (); 
!  
      /** 
       * Creates an instance of a Python class.
--- 62,70 ----
       */
      void clear (); 
! 
!     /**
!      * @name PyObject creation
!      */
!     //@{
      /** 
       * Creates an instance of a Python class.
***************
*** 87,111 ****
       */
      bool reload_instance (string file, string classname, PyObject * args = 
NULL);
  
      /**
!      * Direct access to the instance object
!      *
!      * @return the Python class instance
       */
!     PyObject *get_instance ()
!     {
!         return instance;
!     }
! 
!     /**
!      * Returns the module name of this object.
!      * 
!      * @return module name of this object.
!      */
!     string object_file () const
!     {
!         return script_file_;
!     }
!     
      /** 
       * Call a method of this object.
--- 88,97 ----
       */
      bool reload_instance (string file, string classname, PyObject * args = 
NULL);
+     //@}
  
      /**
!      * @name PyObject method calling
       */
!     //@{
      /** 
       * Call a method of this object.
***************
*** 140,143 ****
--- 126,143 ----
          call_method ("run", args); 
      }
+     //@}
+ 
+     /**
+      * @name PyObject member access
+      */
+     //@{
+     /**
+      * Tests whether the object contains a certain attribute (i.e. method
+      * or variable).
+      *
+      * @param name Name of the attribute to test for
+      * @return <b>true</b> if the attribute exists, <b>false</b> otherwise.
+      */
+     bool has_attribute (const std::string & name);
  
      /**
***************
*** 150,160 ****
  
      /**
!      * Tests whether the object contains a certain attribute (i.e. method
!      * or variable).
       *
!      * @param name Name of the attribute to test for
!      * @return <b>true</b> if the attribute exists, <b>false</b> otherwise.
       */
!     bool has_attribute (const std::string & name);
  
  protected:
--- 150,230 ----
  
      /**
!      * Returns the given attribute as integer value.
       *
!      * @param name Name of the attribute to access
!      * @return An integer.
       */
!     s_int32 get_attribute_int (const string & name);
! 
!     /**
!      * Returns the given attribute as string value.
!      *
!      * @param name Name of the attribute to access
!      * @return A string.
!      */
!     string get_attribute_string (const string & name);
! 
!     /**
!      * Assign a new attribute to the module, overriding an existing
!      * attribute of the same name.
!      *
!      * @param name The attribute's name
!      * @param value The attribute's value
!      */
!     void set_attribute (const string & name, PyObject *value);
! 
!     /**
!      * Assign a new integer attribute to the module, overriding an
!      * existing attribute of the same name.
!      *
!      * @param name The attribute's name
!      * @param value The attribute's value
!      */
!     void set_attribute_int (const string & name, s_int32 value);
! 
!     /**
!      * Assign a new string attribute to the module, overriding an
!      * existing attribute of the same name.
!      *
!      * @param name The attribute's name
!      * @param value The attribute's value
!      */
!     void set_attribute_string (const string & name, const string & value);
!     //@}
!     
!     /**
!      * @name Member access
!      */
!     //@{
!     /**
!      * Direct access to the instance object
!      *
!      * @return the Python class instance
!      */
!     PyObject *get_instance () const
!     {
!         return Instance;
!     }
! 
!     /**
!      * Returns the class name of this object.
!      *
!      * @return class name of this object.
!      */
!     std::string class_name () const
!     {
!         return Classname;
!     }
! 
!     /**
!      * Returns the file name of this object.
!      *
!      * @return fiƶe name of this object.
!      */
!     std::string file_name () const
!     {
!         return Filename;
!     }
!     //@}
  
  protected:
***************
*** 162,166 ****
       * The python class instance wrapped by %py_object
       */    
!     PyObject *instance;
  
  private:
--- 232,236 ----
       * The python class instance wrapped by %py_object
       */    
!     PyObject *Instance;
  
  private:
***************
*** 171,177 ****
      bool instanciate (PyObject*, string, string, PyObject*);
  
!     string script_file_;
! };
  
  
! #endif
--- 241,254 ----
      bool instanciate (PyObject*, string, string, PyObject*);
  
!     /**
!      * The class name of the current script
!      */
!     std::string Classname;
  
+     /**
+      * The file name of the current script
+      */
+     std::string Filename;
+ };
  
! #endif // PY_OBJECT_H

Index: win_wrappers.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/win_wrappers.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** win_wrappers.h      25 Dec 2001 20:06:00 -0000      1.9
--- win_wrappers.h      16 Jan 2003 11:22:45 -0000      1.10
***************
*** 530,534 ****
  {
  public:
!   win_image(); 
    ~win_image(); 
    bool draw(); 
--- 530,534 ----
  {
  public:
!   // win_image(); 
    ~win_image(); 
    bool draw(); 





reply via email to

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