source: golgotha/src/golg/controller.hh

Last change on this file was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 7.7 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef CONTROLLER_HH
10#define CONTROLLER_HH
11
12// This class is used to display a perspective view from an object.  This
13// object is tracked and feed input that goes to the controller window.
14#include "window/window.hh"
15#include "math/num_type.hh"
16#include "error/error.hh"
17#include "math/transform.hh"
18#include "g1_object.hh"
19#include "time/time.hh"
20#include "g1_render.hh"
21#include "map_man.hh"
22#include "memory/que.hh"
23#include "camera.hh"
24#include "draw_context.hh"
25#include "time/timedev.hh"
26
27class g1_quad_object_class;
28class i4_graphical_style_class;
29class g1_player_piece_class;
30class g1_map_class;
31class r1_render_api_class;
32class i4_menu_class;
33class g1_map_view_class;
34class i4_event_handler_class;
35class g1_draw_context_class;
36class g1_map_piece_class;
37class i4_window_message_class;
38class i4_do_command_event_class;
39class i4_end_command_event_class;
40class g1_loader_class;
41class g1_saver_class;
42class g1_object_controller_class;
43
44
45class g1_controller_global_id_reset_notifier : public g1_global_id_reset_notifier
46{
47public:
48  g1_object_controller_class *for_who;
49
50  g1_controller_global_id_reset_notifier(g1_object_controller_class *for_who)
51    : for_who(for_who) {}
52
53
54  void reset();
55};
56
57
58
59class g1_object_controller_class : public i4_parent_window_class
60{
61protected:
62  g1_controller_global_id_reset_notifier notifier;
63  i4_bool first_frame;
64
65  g1_draw_context_class g1_context;
66  void setup_context(i4_draw_context_class &i4_context);
67
68
69  // this is the object we are currently tracking with the camera
70  g1_player_piece_class *get_track();
71
72  g1_map_view_class *radar_view; // maintains the view of the map as seen on radar
73
74  enum flag_type {
75    KEY_FOCUS          =1,     // if we have keyboard focus
76    GOT_KEYBOARD       =4,     // if a keyboard exists on sytem
77    NEED_CLEAR         =8      // if we need to clear the screen the next frame
78  } ;
79  w32 flags;
80
81  void set_flag(flag_type flag, i4_bool on=i4_T) { if (on) flags|=flag; else flags&=(~flag); }
82  i4_bool get_flag(flag_type flag) { if (flags & flag) return i4_T; else return i4_F; }
83
84
85  i4_float last_theta, last_h;
86  i4_float last_x, last_y;
87
88
89  i4_menu_class *context_menu;
90  i4_graphical_style_class *style;
91  w32 last_mouse_x, last_mouse_y;
92
93
94  w32 frames_to_count;
95  i4_float frame_rate;
96
97  enum { FRAME_MEASURE_INTERVAL=8 };
98
99  void create_context_menu();
100  void delete_context_menu();
101
102
103  void set_track(g1_player_piece_class *new_track);
104
105  void draw_overhead(g1_draw_context_class *context);
106
107  // Window Input
108  void get_keys();
109  void lose_keys();
110
111  void do_command_event(i4_do_command_event_class *ev);
112  void end_command_event(i4_end_command_event_class *ev);
113
114  void window_event(i4_window_message_class *wev);
115  void key_press(i4_key_press_event_class *ev);
116  void calc_camera_transform();
117
118  void change_mouse_mask(int new_mask);
119  void draw_counts();
120
121  g1_selectable_list selectable_list;
122
123  // Clipping
124
125  // Worldspace coordinates of the view frustrum
126  i4_3d_vector camera_point[8];
127
128  // View Frustrum bounding box
129  class bbox_class
130  {
131  public:
132    i4_3d_vector min, max;
133  } bbox;
134 
135  class plane_class
136  // View Frustrum Cutting Planes
137  {
138  public:
139    // Uses the plane equation: normal*x + D = 0
140    i4_3d_vector normal;
141    i4_float D;
142    w8 n,p;
143
144    void calc_np()
145    {
146      // calculate the index of the most positive(p) & negative(n) corners
147      //   in calculating the plane equation
148
149      p = 0;
150
151      // p points toward the normal
152      p |= (normal.x>0) ? 1 : 0;
153      p |= (normal.y>0) ? 2 : 0;
154      p |= (normal.z>0) ? 4 : 0;
155     
156      // n points away from the normal
157      n = p^7;
158    }
159
160    i4_float evaluate(const i4_3d_vector& point)
161    {
162      return normal.dot(point) + D;
163    }
164  } plane[4];
165
166  // Text Messages
167  void start_scroll();
168  void stop_scroll();
169  i4_time_device_class::id message_scroll_id;
170  i4_bool scroll_active;
171
172  enum { MAX_MESSAGES=3 };
173  struct message
174  {
175    w32 color;
176    char text[40];
177  };
178  message messages[MAX_MESSAGES];
179
180  // Spinning status indicators
181  i4_time_class last_stat_time;                   // time spin started
182
183  i4_float stat_x, stat_y;
184  int stat_type;
185  int stat_inc;
186  sw32 stat_time;                            // time left  in milli for spin
187
188  struct spin_event
189  {
190    g1_model_id_type model;
191    enum spin_type { GAINED, LOST} type;
192    spin_event() { model=0; }
193    spin_event(g1_model_id_type model, w8 type) : model(model), type((spin_type)type) {}
194  };
195
196  i4_fixed_que<spin_event,8> spin_events;     // list of models to spin up
197  spin_event current_spin;
198  virtual void reparent(i4_image_class *draw_area, i4_parent_window_class *parent);
199public:
200  void scroll_message(const i4_const_str &message, i4_color color=0xffffff);
201
202  void reset_global_ids();
203  virtual clear_if_cannot_draw() { return i4_T; }
204  g1_view_state_class view;
205
206  void pan(i4_float x, i4_float y, i4_float z);
207  void rotate(i4_float about_game_z, i4_float up_down);
208  void zoom(i4_float dist);
209 
210  i4_bool add_spin_event(char *model_name, w8 lost=0);
211
212
213  i4_transform_class transform;  // current transform to go world to screen space
214
215  void get_pos(i4_3d_vector& pos);
216
217  void setup_clip();           
218  // after transform is valid, setup clipping planes
219  int test_clip(const i4_3d_vector& min, const i4_3d_vector& max);
220  // test bounding box for visibility in the view frustrum
221  //   -1 = completely outside
222  //    0 = on boundary
223  //    1 = completely within view
224
225  w8 cursor_state;
226
227  virtual void update_cursor();
228
229  g1_typed_reference_class<g1_object_class> follow;
230
231  g1_player_type team_on() const;
232
233  void update_camera();
234  void set_exclusive_mode(i4_bool yes_no);
235
236  g1_map_class *get_map() { return g1_get_map(); }
237
238  i4_time_class last_frame_draw_time;      // time last frame draw took place
239
240  i4_bool view_to_game(sw32 mouse_x, sw32 mouse_y,
241                       i4_float &game_x, i4_float &game_y,
242                       i4_float &dir_x, i4_float &dir_y);
243  // converts 2D view coordinates & projects the point onto the game map
244  //   if doesn't intersect map, returns i4_F
245
246  // resize will change the width and height of our window and notify our parent of the change
247  virtual void resize(w16 new_width, w16 new_height);
248
249  i4_graphical_style_class *get_style() { return style; }
250  g1_object_controller_class(w16 w, w16 h,
251                             i4_graphical_style_class *style);
252
253  virtual void editor_pre_draw(i4_draw_context_class &context) { ; }
254  virtual void editor_post_draw(i4_draw_context_class &context) { ; }
255
256  virtual void parent_draw(i4_draw_context_class &context);
257
258  virtual void receive_event(i4_event *ev);
259
260  virtual void show_self(w32 indent)
261  {   
262    char fmt[50];
263    sprintf(fmt,"%%%ds object_controller_class",indent);
264    i4_warning(fmt," ");
265  }
266
267  g1_object_class *find_object_under_mouse(sw32 mx, sw32 my);
268
269  enum { MOUSE_LEFT=1,
270         MOUSE_RIGHT=2 };
271  w8 mouse_mask;
272
273  char *name() { return "g1_object_controller"; }
274  ~g1_object_controller_class();
275
276};
277   
278extern i4_event_handler_reference_class<g1_object_controller_class> g1_current_controller;
279
280
281#endif
282
283
284
285
286
Note: See TracBrowser for help on using the repository browser.