colourless0.cc

Go to the documentation of this file.
00001 //
00002 // Example of pentagram design by Ryan Nunn 
00003 // 12th March 2002
00004 //
00005 
00006 class DisplayManager;
00007 
00008 
00009   //                            //
00010  // A generic map object class //
00011 //                            //
00012 class Map_object {
00013 protected:
00014         // Shape and frame (should probably be inherited from an exult ShapeID like class)
00015         int             shape, frame;
00016 
00017         // Our coords in the world. This is what is used by the objects themselves,
00018         // collision detection, usecode and whatever. 
00019         int             x, y, z;
00020 
00021         // Bitwise no interpolation flags
00022         // Bit 0:  temporary 1 frame interpolation disable (autoreset)
00023         // Bit 1:  permanent interpolation disable
00024         // Bit 16: used internally by Display Manager to implement bit 0
00025         // When an object is created Bit 0 should be set
00026         int             no_interp;
00027 
00028         // Cached pointer to shape
00029         Shape   *cached_shape;
00030 
00031 private:
00032         // The following are things only used by the display manager
00033         friend class DisplayManager;
00034 
00035         // Update of the following is automatically handled by DisplayManager
00036 
00037         // Screenspace coords of the shape (used for click detection)
00038         int             sx, sy;
00039 
00040         // The current and previous shape and frame (used for automatic dirty region detection)
00041         int             cshape, cframe;
00042         int             pshape, pframe;
00043 
00044         // Current and prev world coords of the shape (interpolate to/from these)
00045         int             cx, cy, cz;
00046         int             px, py, pz;
00047 
00048         // Is the shape dirty (automatically updated)
00049         // If position_dirty == true, the shape will need to be updated each
00050         // rendering frame.
00051         // If shape_dirty == true the shape needs to be updated on the first
00052         // rendering frame
00053         bool shape_dirty;
00054         bool position_dirty;
00055 
00056         // Used to update above (this in theory doesn't need to be done for fixed glob objects)
00057         // This is done after the world has been updated
00058         inline void update_current_and_prev() {
00059                 // Update the prev
00060                 pshape = cshape;
00061                 pframe = cframe;
00062                 px = cx;
00063                 py = cy;
00064                 pz = cz;
00065 
00066                 // Now copy the current
00067                 cshape = shape;
00068                 cframe = frame;
00069                 cx = x;
00070                 cy = y;
00071                 cz = z;
00072 
00073                 // is the object dirty (i.e. changed shape, position changed)
00074                 shape_dirty = cshape != pshape || cframe != pframe;
00075                 position_dirty = cx != px || cy != py || cz != pz;
00076         }
00077 
00078         // Interpolated screenspace calc (factor 0 to 256)
00079         inline void calc_screenspace_interp(TileCorrd &camera, int factor) {
00080 
00081                 // If no interp flag is set, disable interp
00082                 if (no_interp) factor = 256;
00083                 
00084                 // TODO: Put calcs here
00085         };
00086 
00087         // Non interpolated screenspace calc
00088         inline void calc_screenspace(TileCorrd &camera) {
00089 
00090                 // TODO: Write actual non interp function
00091                 calc_screenspace_interp(TileCorrd &camera, 256);
00092         };
00093 
00094 
00095 public:
00096 
00097         // Run the object... this would be used to run actor animations, handle
00098         // combat and whatever else an object or actor would want to do at a
00099         // predetermined time.
00100         //
00101         // Actual implimentation is doubtful to be like this :-)
00102         virtual void RunObject(int reason);
00103 };
00104 
00105  
00106    //                                              //
00107   // The DisplayManager manages the Display List. //
00108  //  It also is used to do click detection       //
00109 //                                              //
00110 class DisplayManager {
00111 
00112         // The display list
00113         Display_list_type               display_list;
00114 
00115         // The dirty region
00116         Rectangle                               dirty_region;
00117 
00118 public:
00119         // factor is below is the interpolation factor. Set to 256 for no interp
00120 
00121         // Sets up a new list after the world has been updated
00122         void                    SetupList(Map_object *objects, int factor);
00123         
00124         // Interpolates the list between world updates
00125         void                    UpdateList(Map_object *objects, int     factor);
00126 
00127         // Find an object in the list
00128         Map_object *    FindObject(int x, int y);
00129         void                    PaintObjects(Surface *surf);
00130 };
00131 DisplayManager  DispMan;
00132 
00133 
00134   //                                        //
00135  // A generic world class. //
00136 //                        //
00137 class WorldManager {
00138 
00139 public:
00140         // Run the world
00141         void                    RunTheWorld();
00142 
00143         // Get all the objects
00144         Map_object *    GetObject();
00145 };
00146 WorldManager    TheWorld;
00147 
00148 
00149   //                         //
00150  // A generic gump manager. //
00151 //                         //
00152 class GumpManager {
00153 public:
00154         // Paint the gumps
00155         void    PaintGumps(Surface *surf);
00156 
00157         // Handle click
00158         void    Clicked(int x, int y);
00159 }
00160 GumpManager             GumpMan;
00161 
00162 
00163   //                         //
00164  // A generic input manager //
00165 //                         //
00166 class InputManager {
00167 public:
00168         HandleInput();
00169 };
00170 InputManager    InMan;
00171 
00172 
00173   //                     //
00174  // The usecode machine //
00175 //                     //
00176 class UsecodeMachine {
00177 public:
00178         PaintText(Surface *surf);
00179         Run();
00180 }
00181 UsecodeMachine  Usecode;
00182 
00183 
00184 // A flag to specify if we are interpolating
00185 bool                    interpolating = true;
00186 
00187 // The animation rate, default to 50 MS (20 FPS)
00188 int                             ANIMATION_RATE = 50;
00189 
00190 // TODO Make a Clock Class instead of doing timing like 
00191 // how i've done below
00192 //
00193 // There are a number of very good reasons. 1 is to allow
00194 // pausing.
00195 //
00196 // The timing method below will attempt to keep the 
00197 // average timing to ANIMATION_RATE ms.
00198 class GameClock {
00199 }
00200 
00201 // The program loop
00202 int DoProgramLoop (void)
00203 {
00204         // The time to run the next frame at
00205         static int      next_time = -1;
00206 
00207         // Time of the current frame
00208         int                     time = GetCurrentTime();
00209 
00210         // Set the first time
00211         if (next_time == -1) next_time = time;
00212 
00213         // Handle the input
00214         InMan.HandleInput();
00215 
00216         // Run the world, if needed and run it as many times as we need to
00217         if (time >= next_time) while (time >= next_time) {
00218 
00219                 // Run the world
00220                 TheWorld.RunWorld();
00221 
00222                 // Run the usecode
00223                 Usecode.Run();
00224                 
00225                 // Update the next time to run
00226                 next_time += ANIMATION_RATE;
00227 
00228                 // Calc interp factor
00229                 int factor = next_time - time;
00230                 factor *= 256;
00231                 factor /= ANIMATION_RATE;
00232                 if (!interpolating) factor = 256;
00233 
00234                 // Note we do need to resetup the list for every running of the world
00235                 DispMan.SetupList(TheWorld.GetObjects(), factor);
00236         }
00237         else {
00238                 // Calc interp factor
00239                 int factor = next_time - time;
00240                 factor *= 256;
00241                 factor /= ANIMATION_RATE;
00242                 if (!interpolating) factor = 256;
00243 
00244                 // Update display list
00245                 DispMan.UpdateList(TheWorld.GetObjects(), factor);
00246         }
00247 
00248         // Now paint everything
00249         DispMan.PaintObjects(DisplaySurface);
00250         GumpMan.PaintGumps(DisplaySurface);
00251         Usecode.PaintText(DisplaySurface);
00252 }

Generated on Fri Jul 27 22:27:10 2007 for pentagram by  doxygen 1.4.7