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.5,1.12.2.6 event.


From: Kai Sterker <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/src event.cc,1.12.2.5,1.12.2.6 event.h,1.25.2.5,1.25.2.6 gamedate.cc,1.1.2.6,1.1.2.7 schedule.cc,1.1.2.4,1.1.2.5 schedule.h,1.1.2.3,1.1.2.4 time_event.cc,1.1.2.5,1.1.2.6
Date: Sun, 16 Jun 2002 16:55:40 -0400

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

Modified Files:
      Tag: Branch_road_to_0-4
        event.cc event.h gamedate.cc schedule.cc schedule.h 
        time_event.cc 
Log Message:
ADDED C/C++ callbacks as event 'action' (schedule code now using these)
REMOVED 'shared scripts' from events
FIXED old schedule cleared before running the manager script


Index: event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.cc,v
retrieving revision 1.12.2.5
retrieving revision 1.12.2.6
diff -C2 -r1.12.2.5 -r1.12.2.6
*** event.cc    15 Jun 2002 20:23:24 -0000      1.12.2.5
--- event.cc    16 Jun 2002 20:55:38 -0000      1.12.2.6
***************
*** 28,32 ****
  {
      Repeat = -1;
-     Shared = false;
      Script = NULL;
      PyFunc = NULL;
--- 28,31 ----
***************
*** 49,59 ****
          case ACTION_SCRIPT:
          {
!             if (!Shared)
!             {
!                 delete Script;
!                 Py_XDECREF (Args);
!                 Args = NULL;
!             }
!             else Script = NULL;
              
              break;
--- 48,55 ----
          case ACTION_SCRIPT:
          {
!             delete Script;
!             Py_XDECREF (Args);
!             Args = NULL;
!             Script = NULL;
              
              break;
***************
*** 85,89 ****
      Py_XINCREF (args);
      Args = args; 
-     Shared = false;
         
      u_int16 argssize = args == NULL ? 1 : PyTuple_Size (args) + 1; 
--- 81,84 ----
***************
*** 107,127 ****
  }
  
! // make the event script a pointer to an existing script
! void event::set_shared_script (py_object * script)
! {
!     // cleanup
!     clear ();
! 
!     // attach the given script
!     Script = script;
!     
!     // tell the script not to save any arguments
!     Shared = true;
! 
!     // tell the event what to do    
!     Action = ACTION_SCRIPT;
! }
! 
! // set a callback as event's action
  void event::set_callback (PyObject *callback, PyObject *args)
  {
--- 102,106 ----
  }
  
! // set a python callback as event's action
  void event::set_callback (PyObject *callback, PyObject *args)
  {
***************
*** 136,139 ****
--- 115,128 ----
  }
  
+ // set a C/C++ callback as event's action
+ void event::set_callback (const Functor0 & callback)
+ {
+     // cleanup
+     clear ();
+ 
+     Callback = callback;
+     Action = ACTION_CPPFUNC;
+ }
+ 
  // save the state of the script associated with the event
  void event::put_state (ogzstream & file) const
***************
*** 144,152 ****
      
      if (Action != ACTION_SCRIPT) return;
!     
!     Shared >> file;
!     
!     if (Shared) return;
!     
      Script->class_name () >> file;
      
--- 133,137 ----
      
      if (Action != ACTION_SCRIPT) return;
!         
      Script->class_name () >> file;
      
***************
*** 172,181 ****
      
      if (Action != ACTION_SCRIPT) return true;
!     
!     Shared << file;
!     
!     // shared scripts have to be restored by the event's owner
!     if (Shared) return true;
!     
      name << file;
      has_args << file;
--- 157,161 ----
      
      if (Action != ACTION_SCRIPT) return true;
!         
      name << file;
      has_args << file;

Index: event.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.h,v
retrieving revision 1.25.2.5
retrieving revision 1.25.2.6
diff -C2 -r1.25.2.5 -r1.25.2.6
*** event.h     15 Jun 2002 20:23:24 -0000      1.25.2.5
--- event.h     16 Jun 2002 20:55:38 -0000      1.25.2.6
***************
*** 24,28 ****
  #define EVENT_H__
  
! #include "fileops.h" 
  #include "py_object.h"
  #include "py_callback.h"
--- 24,29 ----
  #define EVENT_H__
  
! #include "fileops.h"
! #include "callback.h"
  #include "py_object.h"
  #include "py_callback.h"
***************
*** 53,57 ****
      ACTION_NOTHING  = 0,
      ACTION_SCRIPT   = 1,
!     ACTION_PYFUNC   = 2
  };
  #endif // SWIG
--- 54,59 ----
      ACTION_NOTHING  = 0,
      ACTION_SCRIPT   = 1,
!     ACTION_PYFUNC   = 2,
!     ACTION_CPPFUNC  = 3
  };
  #endif // SWIG
***************
*** 150,169 ****
      
      /**
-      * Sets a script to be executed whenever the event occurs.
-      * This method allows to specify a script that is already
-      * in use elsewhere.
-      *
-      * @warning After calling this method, both the event and the 
-      * original owner share the same script instance. Therefore, the 
-      * event will <b>not</b> save the script. When loading a game,
-      * the original owner has to supply the event with the script.
-      *
-      * @param script pointer to a script initialized elsewhere.
-      */
-     void set_shared_script (py_object * script);
-     
-     /**
       * Sets a python function/method to be executed whenever the
!      * event occurs.
       *
       * @warning the callback won't be saved with the %event. It
--- 152,157 ----
      
      /**
       * Sets a python function/method to be executed whenever the
!      * %event occurs.
       *
       * @warning the callback won't be saved with the %event. It
***************
*** 175,178 ****
--- 163,180 ----
      void set_callback (PyObject *callback, PyObject *args = NULL);
       
+ #ifndef SWIG
+     /**
+      * Sets a C function/C++ method to be executed whenever the
+      * %event occurs.
+      *
+      * @warning the callback won't be saved with the %event. It
+      * must be restored by the event's owner.
+      *
+      * @param callback The callback, a function with no arguments
+      *      returning void
+      */
+     void set_callback (const Functor0 & callback);
+ #endif // SWIG
+ 
      /**
       * @name Loading / Saving
***************
*** 217,227 ****
      
      /**
-      * For events that share their script with another class, Shared
-      * has to be set <b>true</b>. This prevents the script from getting
-      * saved to file.
-      */
-     bool Shared;
-     
-     /**
       * Defines how often the %event should be repeated. <b>0</b> means
       * never, <b>-1</b> means infinitely and <b>n</b> (n > 0) means 
--- 219,222 ----
***************
*** 243,249 ****
      
      /**
!      * Python Callback that may be executed instead of the script.
       */
      py_callback *PyFunc;
      //@}
  #endif // SWIG
--- 238,249 ----
      
      /**
!      * Python callback that may be executed instead of the script.
       */
      py_callback *PyFunc;
+     
+     /**
+      * C++ callback that may be executed when the %event gets triggered.
+      */
+     Functor0 Callback;
      //@}
  #endif // SWIG

Index: gamedate.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/gamedate.cc,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -r1.1.2.6 -r1.1.2.7
*** gamedate.cc 15 Jun 2002 20:23:24 -0000      1.1.2.6
--- gamedate.cc 16 Jun 2002 20:55:38 -0000      1.1.2.7
***************
*** 139,143 ****
                  default:
                  {
!                     fprintf (stderr, "*** time_event::parse_date: Unknown 
time specifier '%c'\n", time[i]);
                      break;
                  }
--- 139,143 ----
                  default:
                  {
!                     fprintf (stderr, "*** gamedate::parse_time: Unknown time 
specifier '%c'\n", time[i]);
                      break;
                  }

Index: schedule.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/schedule.cc,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -r1.1.2.4 -r1.1.2.5
*** schedule.cc 16 Jun 2002 10:59:30 -0000      1.1.2.4
--- schedule.cc 16 Jun 2002 20:55:38 -0000      1.1.2.5
***************
*** 56,61 ****
      {
          // if no schedule queued, let the manager script decide
!         if (!Queue) 
              Manager.run ();
          
          // otherwise use the queued script
--- 56,66 ----
      {
          // if no schedule queued, let the manager script decide
!         if (!Queue)
!         {
!             // clearing the schedule before the manager runs
!             // allows the manager to access the most recent data
!             Schedule.clear ();
              Manager.run ();
+         }
          
          // otherwise use the queued script
***************
*** 63,67 ****
          {
              set_schedule (Queue->file, Queue->args);
!             set_alarm (Queue->time, Queue->absolute);
              
              delete Queue;
--- 68,73 ----
          {
              set_schedule (Queue->file, Queue->args);
!             if (Queue->time != "") 
!                 set_alarm (Queue->time, Queue->absolute);
              
              delete Queue;
***************
*** 77,80 ****
--- 83,92 ----
  void schedule::set_schedule (string file, PyObject *args)
  {
+     if (Running)
+     {
+         fprintf (stderr, "*** schedule::set_schedule: stop current schedule 
first!\n");
+         return;
+     }
+     
      // no need to clear anything, as py_object takes care of that
      Schedule.create_instance (SCHEDULE_DIR + file, file, args);
***************
*** 96,100 ****
  {
      if (Queue) delete Queue;
!     
      Queue = new schedule_data (file, args);
  }
--- 108,112 ----
  {
      if (Queue) delete Queue;
! 
      Queue = new schedule_data (file, args);
  }
***************
*** 104,110 ****
  {
      Manager.create_instance (SCHEDULE_DIR + file, file, args);
-     
-     // update the alarm with the new manager script
-     if (Alarm) Alarm->set_shared_script (&Manager);
  }
  
--- 116,119 ----
***************
*** 136,140 ****
      // create and register the new alarm
      Alarm = new time_event (time, absolute);
!     Alarm->set_shared_script (&Manager);
      event_handler::register_event (Alarm);
  }
--- 145,149 ----
      // create and register the new alarm
      Alarm = new time_event (time, absolute);
!     Alarm->set_callback (makeFunctor (*this, &schedule::on_alarm));
      event_handler::register_event (Alarm);
  }
***************
*** 216,220 ****
          Alarm = new time_event;
          Alarm->get_state (file);
!         Alarm->set_shared_script (&Manager);
          
          // don't forget to register the alarm!
--- 225,229 ----
          Alarm = new time_event;
          Alarm->get_state (file);
!         Alarm->set_callback (makeFunctor (*this, &schedule::on_alarm));
          
          // don't forget to register the alarm!

Index: schedule.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/schedule.h,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -r1.1.2.3 -r1.1.2.4
*** schedule.h  16 Jun 2002 10:59:30 -0000      1.1.2.3
--- schedule.h  16 Jun 2002 20:55:38 -0000      1.1.2.4
***************
*** 197,200 ****
--- 197,203 ----
  private:
  #ifndef SWIG
+     // callback for alarm event
+     void on_alarm () { set_running (false); }
+ 
      // whether the schedule should be executed 
      bool Active;

Index: time_event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Attic/time_event.cc,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -C2 -r1.1.2.5 -r1.1.2.6
*** time_event.cc       15 Jun 2002 20:23:24 -0000      1.1.2.5
--- time_event.cc       16 Jun 2002 20:55:38 -0000      1.1.2.6
***************
*** 57,61 ****
              break;
          }
!     
          default: return;
      }
--- 57,67 ----
              break;
          }
!         
!         case ACTION_CPPFUNC:
!         {
!             Callback ();
!             break;
!         }
!         
          default: return;
      }




reply via email to

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