adonthell-commits
[Top][All Lists]
Advanced

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

[Adonthell-commits] CVS: adonthell/src event.cc,1.12.2.1,1.12.2.2 event_


From: Kai Sterker <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/src event.cc,1.12.2.1,1.12.2.2 event_handler.cc,1.1.2.1,1.1.2.2 event_handler.h,1.1.2.1,1.1.2.2 gamedate.cc,1.1.2.2,1.1.2.3 python_class.cc,1.5.2.2,1.5.2.3 python_class.h,1.6,1.6.2.1 time_event.h,1.1.2.2,1.1.2.3
Date: Fri, 07 Jun 2002 03:41:27 -0400

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

Modified Files:
      Tag: Branch_road_to_0-4
        event.cc event_handler.cc event_handler.h gamedate.cc 
        python_class.cc python_class.h time_event.h 
Log Message:
ADDED ability to partly save/restore Python dicts
STARTED integration of time events


Index: event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.cc,v
retrieving revision 1.12.2.1
retrieving revision 1.12.2.2
diff -C2 -r1.12.2.1 -r1.12.2.2
*** event.cc    12 May 2002 18:36:06 -0000      1.12.2.1
--- event.cc    7 Jun 2002 07:41:23 -0000       1.12.2.2
***************
*** 2,6 ****
     $Id$
  
!    Copyright (C) 2000/2001 Kai Sterker <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
--- 2,6 ----
     $Id$
  
!    Copyright (C) 2000/2001/2002 Kai Sterker <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
***************
*** 18,22 ****
   * @author Kai Sterker <address@hidden>
   * 
!  * @brief  Defines the event_list, event and event_handler class.
   * 
   */
--- 18,22 ----
   * @author Kai Sterker <address@hidden>
   * 
!  * @brief  Defines the base event class.
   * 
   */

Index: event_handler.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/event_handler.cc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** event_handler.cc    12 May 2002 18:36:07 -0000      1.1.2.1
--- event_handler.cc    7 Jun 2002 07:41:23 -0000       1.1.2.2
***************
*** 30,34 ****
  // See whether a matching event is registered and execute the
  // according script(s) 
! void event_handler::raise_event (event& e)
  {
      vector<event*>::iterator i;
--- 30,34 ----
  // See whether a matching event is registered and execute the
  // according script(s) 
! void event_handler::raise_event (const event& e)
  {
      vector<event*>::iterator i;

Index: event_handler.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/event_handler.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** event_handler.h     12 May 2002 18:36:07 -0000      1.1.2.1
--- event_handler.h     7 Jun 2002 07:41:23 -0000       1.1.2.2
***************
*** 25,28 ****
--- 25,31 ----
  #define EVENT_HANDLER_H__
  
+ #include <vector>
+ #include "event.h"
+ 
  /**
   * Keeps track of registered scripts, recieves triggered events 
***************
*** 51,55 ****
       * @param ev event to raise.
       */
!     static void raise_event (event& ev);
      
  private:
--- 54,58 ----
       * @param ev event to raise.
       */
!     static void raise_event (const event& ev);
      
  private:

Index: gamedate.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/gamedate.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** gamedate.cc 12 May 2002 18:36:07 -0000      1.1.2.2
--- gamedate.cc 7 Jun 2002 07:41:23 -0000       1.1.2.3
***************
*** 23,26 ****
--- 23,27 ----
  #include "gametime.h"
  #include "time_event.h"
+ #include "event_handler.h"
  
  // gametime minutes spent in the gameworld so far

Index: python_class.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/python_class.cc,v
retrieving revision 1.5.2.2
retrieving revision 1.5.2.3
diff -C2 -r1.5.2.2 -r1.5.2.3
*** python_class.cc     11 Apr 2002 14:08:42 -0000      1.5.2.2
--- python_class.cc     7 Jun 2002 07:41:23 -0000       1.5.2.3
***************
*** 2,6 ****
     $Id$
  
!    Copyright (C) 2001 Kai Sterker <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
--- 2,6 ----
     $Id$
  
!    Copyright (C) 2001/2002 Kai Sterker <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
***************
*** 28,36 ****
  using std::cerr;
  using std::endl;
  
  PyObject * data::globals;
  
- using std::string;
- 
  /*
   * Start Python
--- 28,35 ----
  using std::cerr;
  using std::endl;
+ using std::string;
  
  PyObject * data::globals;
  
  /*
   * Start Python
***************
*** 79,82 ****
--- 78,82 ----
      {
          cerr << "exec_file: " << filename << " load failed!" << endl;
+         show_traceback ();
          return false;
      }
***************
*** 85,99 ****
  
      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;
  }
  
--- 85,88 ----
***************
*** 171,268 ****
  }
  
! 
! // 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;
  }
  
! PyObject * python::get_tuple (igzstream & file)
  {
!     PyObject * tuple; 
!     u_int32 l;
!     l << file;
! 
!     tuple = PyTuple_New (l);
! 
!     for (u_int32 i = 0; i < l; i++) 
!     {
!         string ms;
!         u_int32 j;
!         char c;
!         
!         c << file;
!         switch (c) 
          {
!             case 's':
!                 ms << file;
!                 // Stolen reference
!                 PyTuple_SetItem (tuple, i, PyString_FromString (ms.c_str ()));
!                 break;
!                 
!             case 'i':
!                 j << file;
!                 // Stolen reference
!                 PyTuple_SetItem (tuple, i, PyInt_FromLong (j));
!                 break; 
          }
      }
!     return tuple; 
  }
  
! void python::put_tuple (PyObject * tuple, ogzstream & file)
  {
!     u_int32 l = PyTuple_Size (tuple);
!     l >> file;
!     for (u_int32 i = 0; i < l; i++) 
!     {
!         // Borrowed reference
!         PyObject * item = PyTuple_GetItem (tuple, i);
!         
!         // Check for the type of this object
!         // String?
!         if (PyString_Check (item)) 
          {
!             's' >> file;
!             char * s = PyString_AsString (item); 
!             string (s) >> file;
          }
!         
!         // Integer?
!         else if (PyInt_Check (item)) 
          {
!             'i' >> file;
!             u_int32 li = PyInt_AsLong (item); 
!             li >> file;
          }
      }
  }
--- 160,305 ----
  }
  
! // load tuple from file
! PyObject * python::get_tuple (igzstream & file)
  {
!     PyObject *tuple, *item;
!     u_int32 size;
! 
!     size << file;
!     tuple = PyTuple_New (size);
  
!     for (u_int32 i = 0; i < size; i++)
      {
!         item = get_object (file);
!         if (item != NULL) PyTuple_SetItem (tuple, i, item);
!     }
  
!     return tuple;
! }
  
! // save contents of a tuple to file
! void python::put_tuple (PyObject * tuple, ogzstream & file)
! {
!     if (!PyTuple_Check (tuple))
!     {
!         fprintf (stderr, "*** python::put_tuple: argument is no tuple!");
!         return;
      }
  
!     u_int32 size = PyTuple_Size (tuple);
!     size >> file;
! 
!     for (u_int32 i = 0; i < size; i++)
!         put_object (PyTuple_GetItem (tuple, i), file);
  }
  
! // load dict from file
! PyObject *python::get_dict (igzstream & file)
! {
!     PyObject *dict, *key, *value;
!     u_int8 load;
! 
!     dict = PyDict_New ();
!     load << file;
! 
!     while (load != 0)
!     {
!         key = get_object (file);
!         value = get_object (file);
! 
!         PyDict_SetItem (dict, key, value);
!         load << file;
!     }
! 
!     return dict;
! }
! 
! // save contents of a dict to file
! void python::put_dict (PyObject * dict, ogzstream & file)
  {
!     if (!PyDict_Check (dict))
!     {
!         fprintf (stderr, "*** python::put_dict: argument is no dict!");
!         return;
!     }
! 
!     PyObject *key, *value;
!     s_int32 pos = 0;
!     u_int8 load = 1;
! 
!     while (PyDict_Next (dict, &pos, &key, &value))
!     {
!         // save key only if saving value will succeed
!         if (PyInt_Check (value) || PyString_Check (value))
          {
!             load >> file;
!             put_object (key, file);
!             put_object (value, file);
          }
      }
! 
!     // end of dict
!     load = 0;
!     load >> file;
  }
  
! // load string or integer from file
! PyObject *python::get_object (igzstream &file)
  {
!     char c;
!     c << file;
! 
!     switch (c)
!     {
!         // string
!         case 's':
          {
!             string str;
!             str << file;
! 
!             return PyString_FromString (str.c_str ());
          }
! 
!         // integer
!         case 'i':
          {
!             u_int32 i;
!             i << file;
! 
!             return PyInt_FromLong (i);
!         }
! 
!         // error:
!         default:
!         {
!             fprintf (stderr, "*** python::get_object: unknown object code 
'%c'", c);
          }
      }
+ 
+     return NULL;
+ }
+ 
+ // save basic python objects to file
+ bool python::put_object (PyObject *item, ogzstream & file)
+ {
+     // Check for the type of this object
+     // String?
+     if (PyString_Check (item))
+     {
+         's' >> file;
+         char * s = PyString_AsString (item);
+         string (s) >> file;
+         return true;
+     }
+ 
+     // Integer?
+     if (PyInt_Check (item))
+     {
+         'i' >> file;
+         u_int32 i = PyInt_AsLong (item);
+         i >> file;
+         return true;
+     }
+ 
+     return false;
  }

Index: python_class.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/python_class.h,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -C2 -r1.6 -r1.6.2.1
*** python_class.h      23 Sep 2001 14:05:45 -0000      1.6
--- python_class.h      7 Jun 2002 07:41:23 -0000       1.6.2.1
***************
*** 2,6 ****
     $Id$
  
!    Copyright (C) 2001 Kai Sterker <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
--- 2,6 ----
     $Id$
  
!    Copyright (C) 2001/2002 Kai Sterker <address@hidden>
     Part of the Adonthell Project http://adonthell.linuxgames.com
  
***************
*** 107,138 ****
  
      /**
-      * 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 ().
!      * 
       * @param file Opened file where to load the tuple from.
!      * 
       * @return Restored Python tuple.
       */
!     static PyObject * get_tuple (igzstream & file); 
  
!     /** 
       * Save a Python tuple into a file.
       *
       * @warning The Python tuple MUST ONLY be composed of Python strings
       * or integers!
!      * 
       * @param tuple Python tuple to save.
       * @param file Opened file where to save the tuple to.
       */
!     static void put_tuple (PyObject * tuple, ogzstream & file);  
  
  private:
--- 107,148 ----
  
      /**
       * Loads a Python tuple previously saved with put_tuple ().
!      *
       * @param file Opened file where to load the tuple from.
!      *
       * @return Restored Python tuple.
       */
!     static PyObject * get_tuple (igzstream & file);
  
!     /**
       * Save a Python tuple into a file.
       *
       * @warning The Python tuple MUST ONLY be composed of Python strings
       * or integers!
!      *
       * @param tuple Python tuple to save.
       * @param file Opened file where to save the tuple to.
       */
!     static void put_tuple (PyObject * tuple, ogzstream & file);
! 
!     /**
!      * Loads a Python dictionary previously saved with put_dict ().
!      *
!      * @param file Opened file where to load the dictionary from.
!      *
!      * @return Restored Python dictionary.
!      */
!     static PyObject * get_dict (igzstream & file);
! 
!     /**
!      * Save a Python dictionary into a file.
!      *
!      * @warning Only integer and string values of the dictionary
!      * are saved!
!      *
!      * @param dict Python dict to save.
!      * @param file Opened file where to save the tuple to.
!      */
!     static void put_dict (PyObject * dict, ogzstream & file);
  
  private:
***************
*** 141,145 ****
       *
       */
!     static char *python::ptr_to_string (char *c, void *ptr, int sz);
  };
  
--- 151,172 ----
       *
       */
!     static char *ptr_to_string (char *c, void *ptr, int sz);
! 
!     /**
!      * Saves basic Python types, like integers or strings to file.
!      *
!      * @param item Python object to save.
!      * @param file Opened file where to save the tuple to.
!      */
!     static bool put_object (PyObject *item, ogzstream & file);
! 
!     /**
!      * Loads a Python object previously saved with put_object ().
!      *
!      * @param file Opened file where to load the object from.
!      *
!      * @return Restored Python object.
!      */
!     static PyObject * get_object (igzstream & file);
  };
  

Index: time_event.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/time_event.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** time_event.h        12 May 2002 18:36:07 -0000      1.1.2.2
--- time_event.h        7 Jun 2002 07:41:23 -0000       1.1.2.3
***************
*** 91,95 ****
      bool equals (event & evnt)
      {
!         return Time == event->time ();
      }
      
--- 91,96 ----
      bool equals (event & evnt)
      {
!         time_event e = (time_event &) evnt;
!         return Time == e.time ();
      }
      




reply via email to

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