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.80.2.25,1.80.2.26 a


From: Kai Sterker <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/src Makefile.am,1.80.2.25,1.80.2.26 adonthell.cc,1.5,1.5.2.1 gametime.cc,1.10.2.1,1.10.2.2 gametime.h,1.11.2.1,1.11.2.2
Date: Sun, 05 May 2002 15:50:16 -0400

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

Modified Files:
      Tag: Branch_road_to_0-4
        Makefile.am adonthell.cc gametime.cc gametime.h 
Log Message:
ADDED gamedate class - reenables in-game time keeping


Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Makefile.am,v
retrieving revision 1.80.2.25
retrieving revision 1.80.2.26
diff -C2 -r1.80.2.25 -r1.80.2.26
*** Makefile.am 3 May 2002 11:42:53 -0000       1.80.2.25
--- Makefile.am 5 May 2002 19:50:14 -0000       1.80.2.26
***************
*** 23,26 ****
--- 23,27 ----
          fileops.cc \
        game.cc \
+         gamedate.cc \
          gametime.cc \
          quest.cc \
***************
*** 31,34 ****
--- 32,36 ----
        fileops.h \
        game.h \
+         gamedate.h \
          gametime.h \
          quest.h \

Index: adonthell.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/adonthell.cc,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -C2 -r1.5 -r1.5.2.1
*** adonthell.cc        7 Jan 2002 13:41:38 -0000       1.5
--- adonthell.cc        5 May 2002 19:50:14 -0000       1.5.2.1
***************
*** 24,27 ****
--- 24,28 ----
  #include "win_manager.h"
  #include "gametime.h"
+ #include "gamedate.h"
  #include "adonthell.h"
  #include "audio.h"
***************
*** 55,61 ****
          screen::show ();
      
!         // update the game clock and perform operations to keep the 
!         // game's speed constant
          gametime::update ();
      }
  
--- 56,64 ----
          screen::show ();
      
!         // perform operations to keep the game's speed constant
          gametime::update ();
+         
+         // update the internal clock
+         gamedate::update ();
      }
  

Index: gametime.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gametime.cc,v
retrieving revision 1.10.2.1
retrieving revision 1.10.2.2
diff -C2 -r1.10.2.1 -r1.10.2.2
*** gametime.cc 16 Feb 2002 21:36:19 -0000      1.10.2.1
--- gametime.cc 5 May 2002 19:50:14 -0000       1.10.2.2
***************
*** 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
  
***************
*** 18,68 ****
   * @author Kai Sterker
   * @brief Implements the gametime class.
!  */
  
- #include <string>
- // #include "event.h"
  #include "gametime.h"
  #include <SDL/SDL.h>
  
! 
  u_int32 gametime::timer1;
  u_int32 gametime::timer2;
! u_int8 gametime::fts = 0;
! bool gametime::running = false; 
! 
! // NEW_EVENT(time_event)
  
! gametime::gametime (u_int32 start, float ratio)
  {     
-     ticks = 0;
-     time = start;
-     
      fts = 0; 
      timer1 = 0;
      timer2 = 0;
      
!     // This decides how many realtime milliseconds make one gametime minute
!     minute = (int) (60000 * ratio);
      
! //     REGISTER_EVENT (TIME_EVENT, time_event)
  }
  
- // Increase gametime 
- // void gametime::tick (u_int32 val)
- // {
- //     ticks += val;
- 
- //     // notify the eventhandler whenever a minute has passed
- //     if (ticks >= minute)
- //     {
- //         ticks -= minute;
- //         time++;
- 
- //         time_event t;
- //         t.time = time;
- //         event_handler::raise_event (t);
- //     }
- // }
- 
  // Synchronize the game's speed to the machine it's running on.
  void gametime::update () 
--- 18,49 ----
   * @author Kai Sterker
   * @brief Implements the gametime class.
!   */
  
  #include "gametime.h"
  #include <SDL/SDL.h>
  
! u_int32 gametime::Minute;
  u_int32 gametime::timer1;
  u_int32 gametime::timer2;
! u_int8 gametime::fts;
! bool gametime::running; 
  
! // initialize the gametime class
! void gametime::init (u_int16 rt_minutes)
  {     
      fts = 0; 
      timer1 = 0;
      timer2 = 0;
      
!     running = false;
!     
!     // Number of game cycles during rt_minutes realtime minutes
!     u_int32 cycles = (1000 * rt_minutes) / CYCLE_LENGTH;
      
!     // Calculate how many game cycles make one gametime minute,
!     // so that one gametime day lasts rt_minutes realtime minutes.
!     Minute = cycles / 1440;
  }
  
  // Synchronize the game's speed to the machine it's running on.
  void gametime::update () 
***************
*** 70,75 ****
      // We declare this variable as static to avoid having to
      // perform the division every time.
!     // This value correspond to the minimum delay before between
!     // Two displayed frames (see FRAME_RATE).
      static u_int16 gfx_cycle_length = 1000 / FRAME_RATE;
      
--- 51,56 ----
      // We declare this variable as static to avoid having to
      // perform the division every time.
!     // Its value corresponds to the minimum delay between
!     // two displayed frames (see FRAME_RATE).
      static u_int16 gfx_cycle_length = 1000 / FRAME_RATE;
      
***************
*** 92,190 ****
      if (fts > FTS_LIMIT) fts = FTS_LIMIT;
  }
- 
- /* 
- time_event::time_event ()
- {
-     time = minute = hour = day =  0;
-     m_step = h_step = d_step = 1;
-     type = TIME_EVENT;
- }
- 
- // Save a time_event to file
- void time_event::save (ogzstream& out) const
- {
-     type >> out;
-     minute >> out;
-     m_step >> out;
-     hour >> out;
-     h_step >> out;
-     day >> out;
-     d_step >> out;
-     script_file () >> out;
- }
- 
- // Load a time event from file
- bool time_event::load (igzstream& f)
- {
-     string s; 
-     minute << f;
-     m_step << f;
-     hour << f;
-     h_step << f;
-     day << f;
-     d_step << f;
-     s << f;
-     set_script (s);
-     
-     return true;
- }
- 
- // Execute time event's script
- void time_event::execute (event &e)
- {
-     time_event t = (time_event&) e; 
- 
-     // Build the event script's local namespace
-     PyObject *locals = Py_BuildValue ("{s:i,s:i,s:i}", "minute", (int) 
t.minute, 
-         "hour", (int) t.hour, "day", (int) t.day);
- //     script.set_locals (locals);
-     script.run ();
- //     script.set_locals (NULL); 
-     
-     // Cleanup
-     Py_DECREF (locals);
- #ifdef PY_DEBUG
-     python::show_traceback ();
- #endif // PY_DEBUG
- }
- 
- // Check whether this time_even matches a given gametime
- bool time_event::equals (event &e)
- {
-     time_event t = (time_event &) e;
-     u_int32 time = t.time % 40320;
-     u_int32 d, h, m = time % 60;
-     
-     if (m_step != 0) {
-         if ((m - minute) % m_step != 0 || m < minute) return 0;
-     }
-     else
-         if (m != minute) return 0;
- 
-     // this is the current hour
-     h = ((time - m) % 1440) / 60;
- 
-     if (h_step != 0) {
-         if ((h - hour) % h_step != 0 || h < hour) return 0;
-     }
-     else
-         if (h != hour) return 0;
-          
-     // this is the current day
-     d = (time - (m + h * 60)) / 1440;
-     
-     if (d_step != 0) {
-         if ((d - day) % d_step != 0 || d < day) return 0; 
-     }
-     else
-         if (d != day) return 0;
- 
-     // if the event matches, we set the actual minute, hour and day,
-     // in case it is needed in the script
-     t.minute = m;
-     t.hour = h;
-     t.day = d;
-     
-     return 1;
- }
- */ 
--- 73,74 ----

Index: gametime.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gametime.h,v
retrieving revision 1.11.2.1
retrieving revision 1.11.2.2
diff -C2 -r1.11.2.1 -r1.11.2.2
*** gametime.h  16 Feb 2002 21:36:19 -0000      1.11.2.1
--- gametime.h  5 May 2002 19:50:14 -0000       1.11.2.2
***************
*** 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
  
***************
*** 23,44 ****
  #define GAMETIME_H_
  
- // Temporarly commented
- // #include "event.h"
  #include "types.h"
  
  /**
   * Length of a %game cycle, in milliseconds. Decrease it to speed up
!  * the %game, increase it to slow the %game down.
!  * This constant implicitly defines the maximum number of frames per 
!  * second (FPS): FPS = 1000 / CYCLE_LENGTH.
   */ 
  #define CYCLE_LENGTH 13
  
  /**
!  * Number of maximum displayed frames per second. This value only affect
!  * the renderer, and not the speed of the game itself. The choice has been
!  * made to allow this option so Adonthell doesn't eat all the CPU of the
!  * machine it runs on.
!  * 
   */ 
  #define FRAME_RATE 50
--- 23,41 ----
  #define GAMETIME_H_
  
  #include "types.h"
  
  /**
   * Length of a %game cycle, in milliseconds. Decrease it to speed up
!  * the %game, increase it to slow the %game down.  This constant 
!  * defines how often the state of the game world is updated. 
!  * A cycle length of 13 means 1000/13 = 76.9 updates per second. 
   */ 
  #define CYCLE_LENGTH 13
  
  /**
!  * Number of maximum displayed frames per second. This value affects
!  * the renderer only, not the speed of the game itself. Limiting the 
!  * frame rate prevents Adonthell from using all the CPU of the
!  * machine it runs on (as long as the machine is fast enough).
   */ 
  #define FRAME_RATE 50
***************
*** 50,64 ****
   * skip frames so that the correct number of updates can be performed,
   * thus keeping the speed constant. However, we can't skip too many
!  * frames, since that would perform in jerky animations and eventually
   * render the %game unplayable.
   */ 
  #define FTS_LIMIT 20
  
  class gametime
  {
  public:
!     gametime (u_int32, float);      // constructor
! //     void tick (u_int32);            // Increase the gametime
  
      static void start_action ()
      {
--- 47,87 ----
   * skip frames so that the correct number of updates can be performed,
   * thus keeping the speed constant. However, we can't skip too many
!  * frames, since that would result in jerky animations and eventually
   * render the %game unplayable.
   */ 
  #define FTS_LIMIT 20
  
+ /**
+  * Tehe %gametime class makes the speed of the %game independent of 
+  * the machine it runs on. This is achieved by keeping the number of 
+  * updates to the %game state constant, no matter how fast or slow 
+  * the machine. This won't work for very slow machines of course, 
+  * but Adonthell will still be playable on a 100 Ghz CPU.
+  */
  class gametime
  {
  public:
!     /**
!      * Initialize the gametime class.
!      *
!      * @param rt_minutes Defines how many real life minutes make one
!      *      gametime day. 
!      */
!     static void init (u_int16 rt_minutes);
! 
!     /**
!      * Return the in-game time that passed since the last call to
!      * this method. 
!      *
!      * @return %gametime in minutes.
!      */
!     static u_int32 minute ()
!     {
!         return Minute;
!     }
  
+     /**
+      *
+      */
      static void start_action ()
      {
***************
*** 67,70 ****
--- 90,96 ----
      }
      
+     /**
+      *
+      */
      static void stop_action () 
      {
***************
*** 72,75 ****
--- 98,105 ----
      }
  
+     /**
+      * @name Methods to sync the %game speed to the machine it runs on
+      */
+     //@{
      /** 
       * Returns the number of updates to perform before drawing
***************
*** 91,95 ****
        * delays the execution and for slower boxes it calculates the
        * number of frames to skip. If the engine should do 50 frames per
!       * second, for example, but the main loop takes 40ms to perform,
        * every second frame will be skipped to keep the %game' speed
        * constant.
--- 121,125 ----
        * delays the execution and for slower boxes it calculates the
        * number of frames to skip. If the engine should do 50 frames per
!       * second, for example, but the main loop takes 26ms to perform,
        * every second frame will be skipped to keep the %game' speed
        * constant.
***************
*** 99,107 ****
        */
      static void update (); 
      
  private:
!     u_int32 ticks;                  // Realtime in Milliseconds
!     u_int32 minute;                 // 1 min gametime in (realtime) 
milliseconds
!     u_int32 time;                   // Gametime in "minutes"
  
      static bool running; 
--- 129,138 ----
        */
      static void update (); 
+     //@}
      
  private:
! #ifndef SWIG
!     // One minute of gametime in game cycles
!     static u_int32 Minute;
  
      static bool running; 
***************
*** 112,138 ****
      // Timers used to calculate the delay between 2 update() calls.
      static u_int32 timer1, timer2;
  };
  
- // To notify at a certain time
- /* 
- class time_event : public event
- {
- public:
-     time_event ();
-     void save (ogzstream&) const;   // Save event data
- 
-     u_int8 minute;                  // 0 - 59
-     u_int8 m_step;                  // 0, 1, 2, ...
-     u_int8 hour;                    // 0 - 23
-     u_int8 h_step;                  // 0, 1, 2, ...
-     u_int8 day;                     // 0 - 27
-     u_int8 d_step;                  // 0, 1, 2, ...
-     u_int32 time;                   // the actual gametime in minutes
- 
- protected:
-     void execute (event& e);        // Run the event's script
-     bool equals (event&);           // Compare two events
-     bool load (igzstream&);         // Load event data
- };
- */ 
  #endif // GAMETIME_H_
--- 143,148 ----
      // Timers used to calculate the delay between 2 update() calls.
      static u_int32 timer1, timer2;
+ #endif // SWIG
  };
  
  #endif // GAMETIME_H_




reply via email to

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