00001
00002
00003
00004
00005
00006 class DisplayManager;
00007
00008
00009
00010
00011
00012 class Map_object {
00013 protected:
00014
00015 int shape, frame;
00016
00017
00018
00019 int x, y, z;
00020
00021
00022
00023
00024
00025
00026 int no_interp;
00027
00028
00029 Shape *cached_shape;
00030
00031 private:
00032
00033 friend class DisplayManager;
00034
00035
00036
00037
00038 int sx, sy;
00039
00040
00041 int cshape, cframe;
00042 int pshape, pframe;
00043
00044
00045 int cx, cy, cz;
00046 int px, py, pz;
00047
00048
00049
00050
00051
00052
00053 bool shape_dirty;
00054 bool position_dirty;
00055
00056
00057
00058 inline void update_current_and_prev() {
00059
00060 pshape = cshape;
00061 pframe = cframe;
00062 px = cx;
00063 py = cy;
00064 pz = cz;
00065
00066
00067 cshape = shape;
00068 cframe = frame;
00069 cx = x;
00070 cy = y;
00071 cz = z;
00072
00073
00074 shape_dirty = cshape != pshape || cframe != pframe;
00075 position_dirty = cx != px || cy != py || cz != pz;
00076 }
00077
00078
00079 inline void calc_screenspace_interp(TileCorrd &camera, int factor) {
00080
00081
00082 if (no_interp) factor = 256;
00083
00084
00085 };
00086
00087
00088 inline void calc_screenspace(TileCorrd &camera) {
00089
00090
00091 calc_screenspace_interp(TileCorrd &camera, 256);
00092 };
00093
00094
00095 public:
00096
00097
00098
00099
00100
00101
00102 virtual void RunObject(int reason);
00103 };
00104
00105
00106
00107
00108
00109
00110 class DisplayManager {
00111
00112
00113 Display_list_type display_list;
00114
00115
00116 Rectangle dirty_region;
00117
00118 public:
00119
00120
00121
00122 void SetupList(Map_object *objects, int factor);
00123
00124
00125 void UpdateList(Map_object *objects, int factor);
00126
00127
00128 Map_object * FindObject(int x, int y);
00129 void PaintObjects(Surface *surf);
00130 };
00131 DisplayManager DispMan;
00132
00133
00134
00135
00136
00137 class WorldManager {
00138
00139 public:
00140
00141 void RunTheWorld();
00142
00143
00144 Map_object * GetObject();
00145 };
00146 WorldManager TheWorld;
00147
00148
00149
00150
00151
00152 class GumpManager {
00153 public:
00154
00155 void PaintGumps(Surface *surf);
00156
00157
00158 void Clicked(int x, int y);
00159 }
00160 GumpManager GumpMan;
00161
00162
00163
00164
00165
00166 class InputManager {
00167 public:
00168 HandleInput();
00169 };
00170 InputManager InMan;
00171
00172
00173
00174
00175
00176 class UsecodeMachine {
00177 public:
00178 PaintText(Surface *surf);
00179 Run();
00180 }
00181 UsecodeMachine Usecode;
00182
00183
00184
00185 bool interpolating = true;
00186
00187
00188 int ANIMATION_RATE = 50;
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 class GameClock {
00199 }
00200
00201
00202 int DoProgramLoop (void)
00203 {
00204
00205 static int next_time = -1;
00206
00207
00208 int time = GetCurrentTime();
00209
00210
00211 if (next_time == -1) next_time = time;
00212
00213
00214 InMan.HandleInput();
00215
00216
00217 if (time >= next_time) while (time >= next_time) {
00218
00219
00220 TheWorld.RunWorld();
00221
00222
00223 Usecode.Run();
00224
00225
00226 next_time += ANIMATION_RATE;
00227
00228
00229 int factor = next_time - time;
00230 factor *= 256;
00231 factor /= ANIMATION_RATE;
00232 if (!interpolating) factor = 256;
00233
00234
00235 DispMan.SetupList(TheWorld.GetObjects(), factor);
00236 }
00237 else {
00238
00239 int factor = next_time - time;
00240 factor *= 256;
00241 factor /= ANIMATION_RATE;
00242 if (!interpolating) factor = 256;
00243
00244
00245 DispMan.UpdateList(TheWorld.GetObjects(), factor);
00246 }
00247
00248
00249 DispMan.PaintObjects(DisplaySurface);
00250 GumpMan.PaintGumps(DisplaySurface);
00251 Usecode.PaintText(DisplaySurface);
00252 }