home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / editor / editor.h < prev    next >
C/C++ Source or Header  |  1998-06-08  |  31KB  |  811 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/editor/rcs/editor.h $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:34:47 $
  18.  *
  19.  * Header for editor functions, data strcutures, etc.
  20.  *
  21.  * $Log: editor.h $
  22.  * Revision 2.0  1995/02/27  11:34:47  john
  23.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  24.  * for bitmaps.tbl.
  25.  * 
  26.  * Revision 1.113  1994/11/17  14:47:55  mike
  27.  * validation functions moved from editor to game.
  28.  * 
  29.  * Revision 1.112  1994/08/03  10:30:51  mike
  30.  * Prototype Stretch_scale_x and Stretch_scale_y.
  31.  * 
  32.  * Revision 1.111  1994/08/02  14:18:23  mike
  33.  * Clean up dialog boxes.
  34.  * 
  35.  * Revision 1.110  1994/07/28  16:59:45  mike
  36.  * objects containing objects.
  37.  * 
  38.  * Revision 1.109  1994/07/21  12:45:18  mike
  39.  * Add Editor_time_of_day, prototype render_3d_in_big_window, move_object_to_mouse_click.
  40.  * 
  41.  * Revision 1.108  1994/07/20  16:43:33  mike
  42.  * Move a bunch of things here so eobject can access variables in med
  43.  * 
  44.  * Revision 1.107  1994/07/06  16:36:43  mike
  45.  * Prototype draw_world_from_game.
  46.  * 
  47.  * Revision 1.106  1994/06/24  17:04:26  john
  48.  * *** empty log message ***
  49.  * 
  50.  * Revision 1.105  1994/06/08  18:13:53  mike
  51.  * Add prototype for med_validate_segment_all
  52.  * 
  53.  * Revision 1.104  1994/05/23  14:47:59  mike
  54.  * Make current segment be add segment.
  55.  * 
  56.  * Revision 1.103  1994/05/19  23:34:46  mike
  57.  * Change VMAG to be compatible with new uv coordinates in range 0..1.0.
  58.  * 
  59.  * Revision 1.102  1994/05/19  12:10:12  matt
  60.  * Use new vecmat macros and globals
  61.  * 
  62.  * Revision 1.101  1994/05/14  18:00:34  matt
  63.  * Got rid of externs in source (non-header) files
  64.  * 
  65.  * Revision 1.100  1994/05/14  17:18:12  matt
  66.  * Got rid of externs in source (non-header) files
  67.  * 
  68.  * Revision 1.99  1994/05/09  23:33:20  mike
  69.  * Current_group, make med_combine_duplicate_vertices take vlp parameter.
  70.  * Change med_find_closest_threshold_segment_side take threshold as a parameter.
  71.  * 
  72.  * Revision 1.98  1994/05/06  14:39:46  mike
  73.  * Prototype place_object.
  74.  * 
  75.  * Revision 1.97  1994/05/04  19:16:12  mike
  76.  * Add prototype for Degenerate_segment_found.
  77.  * 
  78.  * Revision 1.96  1994/05/04  13:07:34  matt
  79.  * Moved a bunch of color constants to meddraw.c, which was the only file
  80.  * that used them.
  81.  * 
  82.  * Revision 1.95  1994/05/03  11:06:08  mike
  83.  * Change VMAG, add constants for SEGSIZEMODE_FREE, etc.
  84.  * 
  85.  * Revision 1.94  1994/05/02  17:56:29  yuan
  86.  * Changed undo_status into array rather than malloced pointers.
  87.  * 
  88.  * Revision 1.93  1994/04/19  18:29:37  matt
  89.  * In wire-frame editor window, draw objects as "spheres"
  90.  * 
  91.  * Revision 1.92  1994/04/13  13:25:12  mike
  92.  * Add constant definitions for each keypad.
  93.  * 
  94.  * Revision 1.91  1994/04/01  11:17:08  yuan
  95.  * Added objects to objpage. Added buttons for easier tmap scrolling.
  96.  * Objects are selected fully from objpage and add object menu or pad.
  97.  * 
  98.  * Revision 1.90  1994/03/21  16:54:16  yuan
  99.  * Fixed bogus group generated by segment rotation.
  100.  * 
  101.  * Revision 1.89  1994/02/16  13:49:07  mike
  102.  * enable editor to compile out.
  103.  * 
  104.  * Revision 1.88  1994/02/10  16:04:57  mike
  105.  * separate editor based on EDITOR flag.
  106.  * 
  107.  * Revision 1.87  1994/02/08  12:41:29  yuan
  108.  * Added med_load_game function prototype
  109.  * 
  110.  * Revision 1.86  1994/01/14  12:16:04  yuan
  111.  * Fixed function prototype for med_find_closest_threshold_segment_side.
  112.  * 
  113.  * Revision 1.85  1994/01/14  11:58:55  yuan
  114.  * New function in build menu. 
  115.  * "Punch" through walls to force a joint formation with
  116.  * closest segment:side, if the closest segment:side allows
  117.  * a connection.
  118.  * 
  119.  * Revision 1.84  1994/01/06  12:57:47  mike
  120.  * Fix bug in assigning texture maps and uv coordinates to removable wall.
  121.  * 
  122.  * Revision 1.83  1994/01/05  17:51:04  mike
  123.  * Add prototypes for create_removable_wall and remove_removable_wall
  124.  * 
  125.  * Revision 1.82  1994/01/05  09:59:09  yuan
  126.  * Added med_load_pmine function prototype
  127.  * 
  128.  * Revision 1.81  1993/12/16  14:00:46  mike
  129.  * Add Curvert and Curedge.
  130.  * 
  131.  * Revision 1.80  1993/12/14  18:33:07  yuan
  132.  * Added prototype for timed autosave.
  133.  * 
  134.  * Revision 1.79  1993/12/10  14:48:48  mike
  135.  * Kill orthogonal views.
  136.  * 
  137.  * Revision 1.78  1993/12/09  16:27:16  yuan
  138.  * Added toggle for autosave
  139.  * 
  140.  * Revision 1.77  1993/12/09  14:02:52  mike
  141.  * Add prototype for med_combine_duplicate_vertices.
  142.  * 
  143.  * Revision 1.76  1993/12/08  10:59:52  mike
  144.  * Add DisplayCurrentRobotType and Cur_object_index.
  145.  * 
  146.  * Revision 1.75  1993/12/06  18:43:49  matt
  147.  * Changed object loading & handling
  148.  * 
  149.  * Revision 1.74  1993/12/05  22:50:49  matt
  150.  * Reworked include files in an attempt to cut down on build times
  151.  * 
  152.  * Revision 1.73  1993/12/02  17:51:31  john
  153.  * Changed my variable to match Mike's
  154.  * 
  155.  * Revision 1.72  1993/12/02  17:36:26  john
  156.  * added cur_obj_type
  157.  * 
  158.  * Revision 1.71  1993/11/30  17:06:33  mike
  159.  * Add prototype for med_set_vertex.
  160.  * 
  161.  * Revision 1.70  1993/11/29  19:47:11  matt
  162.  * Changed how coordinate axes draw routine gets vertices
  163.  * Added functions alloc_vert() & free_vert()
  164.  * 
  165.  */
  166.  
  167. #ifndef _EDITOR_H
  168. #define _EDITOR_H
  169.  
  170. #include "vecmat.h"
  171. #include "segment.h"
  172. #include "inferno.h"
  173. #include "gr.h"
  174. #include "ui.h"
  175.  
  176. /*
  177.  * Constants
  178.  *
  179.  */
  180.  
  181. #define ORTHO_VIEWS 0            // set to 1 to enable 3 orthogonal views
  182. #define ED_SCREEN_W    800        //width of editor screen
  183. #define ED_SCREEN_H    600        //height of editor screen
  184.  
  185. #define MENUBAR_H        16
  186.  
  187. #define GAMEVIEW_X    1        //where the 320x200 game window goes
  188. #define GAMEVIEW_Y    1+MENUBAR_H
  189. #define GAMEVIEW_W    320
  190. #define GAMEVIEW_H    200
  191.  
  192. #define STATUS_X    0
  193. #define STATUS_H    18
  194. #define STATUS_Y    (ED_SCREEN_H-STATUS_H)
  195. #define STATUS_W    ED_SCREEN_W
  196.  
  197. #define LVIEW_X    1            //large view
  198. #define LVIEW_Y    (GAMEVIEW_Y+GAMEVIEW_H+2)
  199. #define LVIEW_W    447
  200. #define LVIEW_H    (STATUS_Y-LVIEW_Y-2)
  201.  
  202. #define TMAPBOX_X    (LVIEW_X+LVIEW_W+4)    //location of first one
  203. #define TMAPBOX_Y    (LVIEW_Y+2)
  204. #define TMAPBOX_W    64
  205. #define TMAPBOX_H    64
  206.  
  207. #define TMAPCURBOX_X (TMAPBOX_X + 4*(TMAPBOX_W + 3))
  208. #define TMAPCURBOX_Y (TMAPBOX_Y + TMAPBOX_H)
  209.  
  210. #define OBJCURBOX_X (TMAPCURBOX_X)
  211. #define OBJCURBOX_Y (TMAPCURBOX_Y + 3*(TMAPBOX_H + 2) -40)
  212.  
  213. #define PAD_X (GAMEVIEW_X + GAMEVIEW_W + 16)
  214. #define PAD_Y (GAMEVIEW_Y + 4)
  215.  
  216. #define SMALLVIEW_W    173        //width of small view windows
  217. #define SMALLVIEW_H    148        //height of small view windows
  218.  
  219. #define TVIEW_X    (LVIEW_X+LVIEW_W+2)        //top view
  220. #define TVIEW_Y    LVIEW_Y
  221. #define TVIEW_W    SMALLVIEW_W
  222. #define TVIEW_H    SMALLVIEW_H
  223.  
  224. #define FVIEW_X    TVIEW_X                        //front view
  225. #define FVIEW_Y    (TVIEW_Y+SMALLVIEW_H+2)
  226. #define FVIEW_W    SMALLVIEW_W
  227. #define FVIEW_H    SMALLVIEW_H
  228.  
  229. #define RVIEW_X    (TVIEW_X+SMALLVIEW_W+2)    //right view
  230. #define RVIEW_Y    FVIEW_Y    
  231. #define RVIEW_W    SMALLVIEW_W
  232. #define RVIEW_H    SMALLVIEW_H
  233.  
  234. #define GVIEW_X    RVIEW_X                        //group view
  235. #define GVIEW_Y    TVIEW_Y    
  236. #define GVIEW_W    SMALLVIEW_W
  237. #define GVIEW_H    SMALLVIEW_H
  238.  
  239. //there were color constants here, but I moved them to meddraw.c - Matt
  240.  
  241. #define    SEGMOVE_PAD_ID        0
  242. #define    SEGSIZE_PAD_ID        1
  243. #define    CURVE_PAD_ID        2    
  244. #define    TEXTURE_PAD_ID        3
  245. #define    OBJECT_PAD_ID        4
  246. #define    OBJMOV_PAD_ID        5
  247. #define    GROUP_PAD_ID        6
  248. #define    LIGHTING_PAD_ID    7
  249. #define    TEST_PAD_ID            8
  250. #define    MAX_PAD_ID            8
  251.  
  252. /*
  253.  * Strucures
  254.  * 
  255.  */
  256.  
  257. #define VF_ANGLES 0
  258. #define VF_MATRIX 1
  259.  
  260. // Default size of a segment
  261. #define    DEFAULT_X_SIZE        F1_0*20
  262. #define    DEFAULT_Y_SIZE        F1_0*20
  263. #define    DEFAULT_Z_SIZE        F1_0*20
  264.  
  265. //    Scale factor from 3d units (integer portion) to uv coordinates (integer portion)
  266. #define    VMAG    (F1_0 / (DEFAULT_X_SIZE/F1_0))
  267. #define    UMAG    VMAG        // unused
  268.  
  269. //    Number of segments which can be found (size of Found_segs[])
  270. #define    MAX_FOUND_SEGS        200
  271. #define    MAX_SELECTED_SEGS    (MAX_SEGMENTS)
  272. #define    MAX_WARNING_SEGS    (MAX_SEGMENTS)
  273.  
  274. #define    MAX_GROUPS            10
  275. #define    ROT_GROUP            MAX_GROUPS
  276.  
  277. //    Modes for segment sizing
  278. #define SEGSIZEMODE_FREE         1
  279. #define SEGSIZEMODE_ALL             2
  280. #define SEGSIZEMODE_CURSIDE    3
  281. #define SEGSIZEMODE_EDGE        4
  282. #define SEGSIZEMODE_VERTEX        5
  283.  
  284. #define SEGSIZEMODE_MIN            SEGSIZEMODE_FREE
  285. #define SEGSIZEMODE_MAX            SEGSIZEMODE_VERTEX
  286.  
  287. //defines a view for an editor window
  288. typedef struct editor_view {
  289.     short ev_num;                //each view has it's own number
  290.     short ev_changed;            //set to true if view changed
  291.     grs_canvas *ev_canv;        //points to this window's canvas
  292.     fix ev_dist;                //the distance from the view point
  293.     vms_matrix ev_matrix;    //the view matrix
  294.     fix ev_zoom;                //zoom for this window
  295. } editor_view;
  296.  
  297. /*
  298.  * Global variables
  299.  * 
  300.  */
  301.  
  302. extern editor_view *Views[];
  303. extern int N_views;
  304. extern grs_canvas *canv_offscreen;        //for off-screen rendering
  305. extern int Large_view_index;
  306. extern UI_GADGET_USERBOX * LargeViewBox;
  307. extern int Found_seg_index;                // Index in Found_segs corresponding to Cursegp
  308. extern int gamestate_not_restored;
  309.  
  310.  
  311. extern    segment  *Cursegp;                // Pointer to current segment in the mine, the one to which things happen.
  312. extern    vms_vector Ed_view_target;        // what editor is looking at
  313. extern    segment  New_segment;            // The segment which can be added to the mine.
  314. extern    int        Curside;                    // Side index in 0..MAX_SIDES_PER_SEGMENT of active side.
  315. extern    int        Curedge;                    //    Current edge on current side, in 0..3
  316. extern    int        Curvert;                    //    Current vertex on current side, in 0..3
  317. extern    int        AttachSide;                //    Side on segment to attach
  318. extern    int        Draw_all_segments;    // Set to 1 means draw_world draws all segments in Segments, else draw only connected segments
  319. extern    segment    *Markedsegp;            // Marked segment, used in conjunction with *Cursegp to form joints.
  320. extern    int        Markedside;                // Marked side on Markedsegp.
  321. extern    byte        Vertex_active[MAX_VERTICES];    // !0 means vertex is in use, 0 means not in use.
  322.  
  323. extern    grs_canvas *Pad_text_canvas;        // Keypad text
  324.  
  325. // The extra group in the following arrays is used for group rotation.
  326. extern     group        GroupList[MAX_GROUPS+1];
  327. extern     segment  *Groupsegp[MAX_GROUPS+1];
  328. extern     int        Groupside[MAX_GROUPS+1];
  329. extern    int         current_group;
  330. extern    int         num_groups; 
  331. extern    int        Current_group;
  332.  
  333. extern    short        Found_segs[];            // List of segment numbers "found" under cursor click
  334. extern    int        N_found_segs;            // Number of segments found at Found_segs
  335.  
  336. extern    int        N_selected_segs;        // Number of segments found at Selected_segs
  337. extern    short        Selected_segs[];        // List of segment numbers currently selected
  338.  
  339. extern    int        N_warning_segs;        // Number of segments warning-worthy, such as a concave segment
  340. extern    short        Warning_segs[];        // List of warning-worthy segments
  341.  
  342. extern    int        Show_axes_flag;        // 0 = don't show, !0 = do show coordinate axes in *Cursegp orientation
  343.  
  344. extern   int        Autosave_count;        // Current counter for which autosave mine we are "on"
  345. extern    int        Autosave_flag;            // Whether or not Autosave is on.
  346. extern    struct tm Editor_time_of_day;
  347.  
  348. extern    int        SegSizeMode;            // Mode = 0/1 = not/is legal to move bound vertices, 
  349.  
  350. void init_editor(void);
  351. void editor(void);
  352. void close_editor(void);
  353. void init_editor_screen(void);
  354.  
  355. //    Returns true if vertex vi is contained in exactly one segment, else returns false.
  356. extern int is_free_vertex(int vi);
  357.  
  358. //    Set existing vertex vnum to value *vp.
  359. extern    int med_set_vertex(int vnum,vms_vector *vp);
  360.  
  361. extern void med_combine_duplicate_vertices(byte *vlp);
  362.  
  363. // Attach side newside of newseg to side destside of destseg.
  364. // Copies *newseg into global array Segments, increments Num_segments.
  365. // Forms a weld between the two segments by making the new segment fit to the old segment.
  366. // Updates number of faces per side if necessitated by new vertex coordinates.
  367. // Return value:
  368. //  0 = successful attach
  369. //  1 = No room in Segments[].
  370. //  2 = No room in Vertices[].
  371. extern    int med_attach_segment(segment *destseg, segment *newseg, int destside, int newside);
  372.  
  373. // Delete a segment.
  374. // Deletes a segment from the global array Segments.
  375. // Updates Cursegp to be the segment to which the deleted segment was connected.  If there is
  376. //    more than one connected segment, the new Cursegp will be the segment with the highest index
  377. //    of connection in the deleted segment (highest index = front)
  378. // Return value:
  379. //  0 = successful deletion
  380. //  1 = unable to delete
  381. extern    int med_delete_segment(segment *sp);
  382.  
  383. // Rotate the segment *seg by the pitch, bank, heading defined by *rot, destructively
  384. // modifying its four free vertices in the global array Vertices.
  385. // It is illegal to rotate a segment which has MAX_SIDES_PER_SEGMENT != 1.
  386. // Pitch, bank, heading are about the point which is the average of the four points
  387. // forming the side of connection.
  388. // Return value:
  389. //  0 = successful rotation
  390. //  1 = MAX_SIDES_PER_SEGMENT makes rotation illegal (connected to 0 or 2+ segments)
  391. //  2 = Rotation causes degeneracy, such as self-intersecting segment.
  392. extern    int med_rotate_segment(segment *seg, vms_matrix *rotmat);
  393. extern    int med_rotate_segment_ang(segment *seg, vms_angvec *ang);
  394.  
  395. // Scales a segment, destructively modifying vertex coordinates in global Vertices[].
  396. //    Uses scale factor in sp->scale.
  397. //    Modifies only free vertices (those which are not part of a segment other than *sp).
  398. // The vector *svp contains the x,y,z scale factors.  The x,y,z directions are relative
  399. // to the segment.  x scales in the dimension of the right vector, y of the up vector, z of the forward vector.
  400. // The dimension of the vectors is determined by averaging appropriate sets of 4 of the 8 points.
  401. extern void med_scale_segment(segment *sp);
  402.  
  403. //    Create a wall which can be removed.
  404. //    Creates wall at sp->sides[side], making it part of segment sp
  405. //    Removable walls must be placed between two connected segments.  You should add the removable
  406. //    wall on both sides.  In fact, you really must.
  407. extern void create_removable_wall(segment *sp, int side, int tmap_num);
  408.  
  409. // Loads mine *name from disk, updating global variables:
  410. //    Segments, Vertices
  411. //    Num_segments,Num_vertices
  412. //    Cursegp = pointer to active segment.  Written as an index in med_save_mine, converted to a pointer
  413. //        at load time.
  414. // Returns:
  415. //  0 = successfully loaded.
  416. //  1 = unable to load.
  417. extern    int med_load_mine(char *name);
  418.  
  419. // Loads game *name from disk.
  420. // This function automatically loads mine with name.MIN 
  421. extern    int med_load_game(char *name);
  422.  
  423.  
  424. // Loads a previous generation mine.  Needs to be updated in code. 
  425. extern    int med_load_pmine(char *name);
  426.  
  427. // Saves mine contained in Segments[] and Vertices[].
  428. // Num_segments = number of segments in mine.
  429. // Num_vertices = number of vertices in mine.
  430. // Cursegp = current segment.
  431. // Saves Num_segments, and index of current segment (which is Cursegp - Segments), which will be converted to a pointer
  432. // and written to Cursegp in med_load_mine.
  433. // Returns:
  434. //  0 = successfully saved.
  435. //  1 = unable to save.
  436. extern    int med_save_mine(char *name);
  437.  
  438. // Loads group *filename from disk.
  439. //    Adds group to global Segments and Vertices array.
  440. //    Returns:
  441. //     0 = successfully loaded.
  442. //     1 = unable to load.
  443. extern    int med_load_group( char *filename, short *vertex_ids, short *segment_ids, int *num_vertices, int *num_segments);
  444.  
  445. // Saves group *filename from disk.
  446. //    Saves group defined by vertex_ids and segment_ids to disk. 
  447. //    Returns:
  448. //     0 = successfully saved.
  449. //     1 = unable to save.
  450. extern    int med_save_group( char *filename, short *vertex_ids, short *segment_ids, int num_vertices, int num_segments);
  451.  
  452. // Updates the screen... (I put the prototype here for curves.c)
  453. extern   int medlisp_update_screen();
  454.  
  455. // Returns 0 if no error, 1 if error, whatever that might be.
  456. // Sets globals:
  457. //    Num_segments
  458. //    Num_vertices
  459. //    Cursegp = pointer to only segment.
  460. extern    int create_new_mine(void);
  461.  
  462. // extern    void med_create_segment(segment *sp, vms_vector *scale);
  463. extern    void old_med_attach_segment(segment *sp,int main_side,int branch_side,fix cx, fix cy, fix cz, fix length, fix width, fix height, vms_matrix *mp);
  464.  
  465. // Copy a segment from *ssp to *dsp.  Do not simply copy the struct.  Use *dsp's vertices, copying in
  466. //    just the values, not the indices.
  467. extern    void med_copy_segment(segment *dsp,segment *ssp);
  468.  
  469. //    Create a default segment.
  470. //    Useful for when user creates a garbage segment.
  471. extern    void med_create_default_segment(segment *sp);
  472.  
  473. //    Create New_segment with sizes found in *scale.
  474. extern    void med_create_new_segment(vms_vector *scale);
  475.  
  476. //    Create New_segment with sizes found in Cursegp.
  477. extern void med_create_new_segment_from_cursegp(void);
  478.  
  479. //    Update New_segment using scale factors.
  480. extern    void med_update_new_segment(void);
  481.  
  482. //    Replace *sp with New_segment.
  483. extern    void med_update_segment(segment *sp);
  484.  
  485. //    Create a new segment and use it to form a bridge between two existing segments.
  486. //    Specify two segment:side pairs.  If either segment:side is not open (ie, segment->children[side] != -1)
  487. //    then it is not legal to form the brider.
  488. //    Return:
  489. //        0    bridge segment formed
  490. //        1    unable to form bridge because one (or both) of the sides is not open.
  491. //    Note that no new vertices are created by this process.
  492. extern    int med_form_bridge_segment(segment *seg1, int side1, segment *seg2, int side2);
  493.  
  494. //    Compress mine at Segments and Vertices by squeezing out all holes.
  495. //    If no holes (ie, an unused segment followed by a used segment), then no action.
  496. //    If Cursegp or Markedsegp is a segment which gets moved to fill in a hole, then
  497. //    they are properly updated.
  498. extern    void med_compress_mine(void);
  499.  
  500. //    Extract the forward vector from segment *sp, return in *vp.
  501. //    The forward vector is defined to be the vector from the the center of the front face of the segment
  502. // to the center of the back face of the segment.
  503. extern    void med_extract_forward_vector_from_segment(segment *sp,vms_vector *vp);
  504.  
  505. //    Extract the right vector from segment *sp, return in *vp.
  506. //    The forward vector is defined to be the vector from the the center of the left face of the segment
  507. // to the center of the right face of the segment.
  508. extern    void med_extract_right_vector_from_segment(segment *sp,vms_vector *vp);
  509.  
  510. //    Extract the up vector from segment *sp, return in *vp.
  511. //    The forward vector is defined to be the vector from the the center of the bottom face of the segment
  512. // to the center of the top face of the segment.
  513. extern    void med_extract_up_vector_from_segment(segment *sp,vms_vector *vp);
  514.  
  515. // Compute the center point of a side of a segment.
  516. //    The center point is defined to be the average of the 4 points defining the side.
  517. extern    void med_compute_center_point_on_side(vms_vector *vp,segment *sp,int side);
  518.  
  519. extern void    set_matrix_based_on_side(vms_matrix *rotmat,int destside);
  520.  
  521. // Given a forward vector, compute and return an angvec triple.
  522. //    [ THIS SHOULD BE MOVED TO THE VECTOR MATRIX LIBRARY ]
  523. extern    vms_angvec *vm_vec_to_angles(vms_angvec *result, vms_vector *forvec);
  524.  
  525.  
  526. // Curves stuff.
  527.  
  528. #define ACCURACY 0.1*F1_0
  529.  
  530. typedef struct vms_equation {
  531.     union {
  532.             struct {fix x3, x2, x1, x0, y3, y2, y1, y0, z3, z2, z1, z0;};
  533.             fix xyz[3][4];
  534.     };
  535. } vms_equation;
  536.  
  537. extern void create_curve(vms_vector *p1, vms_vector *p4, vms_vector *r1, vms_vector *r4, vms_equation *coeffs);
  538. // Q(t) = (2t^3 - 3t^2 + 1) p1 + (-2t^3 + 3t^2) p4 + (t^3 - 2t^2 + t) r1 + (t^3 - t^2 ) r4
  539.  
  540. extern vms_vector evaluate_curve(vms_equation *coeffs, int degree, fix t);
  541.  
  542. extern fix curve_dist(vms_equation *coeffs, int degree, fix t0, vms_vector *p0, fix dist);
  543.  
  544. extern void curve_dir(vms_equation *coeffs, int degree, fix t0, vms_vector *dir);
  545.  
  546. extern void plot_parametric(vms_equation *coeffs, fix min_t, fix max_t, fix del_t);
  547.  
  548. // Curve generation routine.
  549. // Returns 1 if curve is generated.
  550. // Returns 0 if no curve.
  551. extern int generate_curve( fix r1scale, fix r4scale );
  552.  
  553. // Deletes existing curve generated in generate_curve().
  554. extern void delete_curve();
  555.  
  556. // --- // -- Temporary function, identical to med_rotate_segment, but it takes a vector instead of an angvec
  557. // --- extern    int med_rotate_segment_vec(segment *seg, vms_vector *vec);
  558.  
  559. extern    void med_extract_matrix_from_segment(segment *sp,vms_matrix *rotmat);
  560.  
  561. //    Assign default u,v coordinates to all sides of a segment.
  562. //    This routine should only be used for segments which are not connected to anything else,
  563. //    ie the segment created at mine creation.
  564. extern    void assign_default_uvs_to_segment(segment *segp);
  565. extern    void assign_default_uvs_to_side(segment *segp, int side);
  566.  
  567. extern    void assign_default_uvs_to_side(segment *segp,int side);
  568.  
  569. //    Assign u,v coordinates to con_seg, con_common_side from base_seg, base_common_side
  570. //    They are connected at the edge defined by the vertices abs_id1, abs_id2.
  571. extern    void med_assign_uvs_to_side(segment *con_seg, int con_common_side, segment *base_seg, int base_common_side, int abs_id1, int abs_id2);
  572.  
  573. // Debug -- show a matrix.
  574. //    type: 0 --> mprintf, 1 --> printf
  575. //    *s = string to display
  576. //    *mp = matrix to display
  577. extern    void show_matrix(char *s,vms_matrix *mp,int type);
  578.  
  579. //    Create coordinate axes in orientation of specified segment, stores vertices at *vp.
  580. extern    void create_coordinate_axes_from_segment(segment *sp,short *vertnums);
  581.  
  582. //    Scale a segment.  Then, if it is connected to something, rotate it.
  583. extern    int med_scale_and_rotate_segment(segment *seg, vms_angvec *rot);
  584.  
  585. //    Set Vertex_active to number of occurrences of each vertex.
  586. //    Set Num_vertices.
  587. extern    void set_vertex_counts(void);
  588.  
  589. //    Modify seg2 to share side2 with seg1:side1.  This forms a connection between
  590. //    two segments without creating a new segment.  It modifies seg2 by sharing
  591. //    vertices from seg1.  seg1 is not modified.  Four vertices from seg2 are
  592. //    deleted.
  593. //    If the four vertices forming side2 in seg2 are not free, the joint is not formed.
  594. //    Return code:
  595. //        0            joint formed
  596. //        1            unable to form joint because one or more vertices of side2 is not free
  597. //        2            unable to form joint because side1 is already used
  598. extern    int med_form_joint(segment *seg1, int side1, segment *seg2, int side2);
  599.  
  600. // The current texture... use by saying something=bm_lock_bitmap(CurrentTexture)
  601. extern int CurrentTexture;
  602.  
  603. extern void compute_segment_center(vms_vector *vp,segment *sp);
  604.  
  605. extern void med_propagate_tmaps_to_segments(segment *base_seg,segment *con_seg, int uv_only_flag);
  606.  
  607. extern void med_propagate_tmaps_to_back_side(segment *base_seg, int back_side, int uv_only_flag);
  608.  
  609. extern void med_propagate_tmaps_to_any_side(segment *base_seg, int back_side, int tmap_num, int uv_only_flag);
  610.  
  611. //    Find segment adjacent to sp:side.
  612. //    Adjacent means a segment which shares all four vertices.
  613. //    Return true if segment found and fill in segment in adj_sp and side in adj_side.
  614. //    Return false if unable to find, in which case adj_sp and adj_side are undefined.
  615. extern int med_find_adjacent_segment_side(segment *sp, int side, segment **adj_sp, int *adj_side);
  616.  
  617. // Finds the closest segment and side to sp:side.
  618. extern int med_find_closest_threshold_segment_side(segment *sp, int side, segment **adj_sp, int *adj_side, fix threshold);
  619.  
  620. //    Given two segments, return the side index in the connecting segment which connects to the base segment
  621. extern int find_connect_side(segment *base_seg, segment *con_seg);
  622.  
  623. // Select previous segment.
  624. //    If there is a connection on the side opposite to the current side, then choose that segment.
  625. // If there is no connecting segment on the opposite face, try any segment.
  626. extern void get_previous_segment(int curseg_num, int curside,int *newseg_num, int *newside);
  627.  
  628. // Select next segment.
  629. //    If there is a connection on the current side, then choose that segment.
  630. // If there is no connecting segment on the current side, try any segment.
  631. extern void get_next_segment(int curseg_num, int curside, int *newseg_num, int *newside);
  632.  
  633. //    Copy texture maps in newseg to nsp.
  634. extern void copy_uvs_seg_to_seg(segment *nsp,segment *newseg);
  635.  
  636. //    Return true if segment is concave.
  637. extern int check_seg_concavity(segment *s);
  638.  
  639. //    Return N_found_segs = number of concave segments in mine.
  640. //    Segment ids stored at Found_segs
  641. extern void find_concave_segs(void);
  642.  
  643. //    High level call.  Check for concave segments, print warning message (using editor_status)
  644. //    if any concave segments.
  645. //    Calls find_concave_segs, therefore N_found_segs gets set, and Found_segs filled in.
  646. extern void warn_if_concave_segments(void);
  647.  
  648. //    Warn if segment s is concave.
  649. extern void warn_if_concave_segment(segment *s);
  650.  
  651. //    Add a vertex to the vertex list.
  652. extern int med_add_vertex(vms_vector *vp);
  653.  
  654. //    Add a vertex to the vertex list which may be identical to another vertex (in terms of coordinates).
  655. //    Don't scan list, looking for presence of a vertex with same coords, add this one.
  656. extern int med_create_duplicate_vertex(vms_vector *vp);
  657.  
  658. //    Create a new segment, duplicating exactly, including vertex ids and children, the passed segment.
  659. extern int med_create_duplicate_segment(segment *sp);
  660.  
  661. //    Returns the index of a free segment.
  662. //    Scans the Segments array.
  663. extern int get_free_segment_number(void);
  664.  
  665. //      Diagnostic message.
  666. extern void diagnostic_message(const char *format, ... );
  667.  
  668. //      Status Icon.
  669. extern void print_status_icon( char icon[1], int position );
  670. extern void clear_status_icon( char icon[1], int position );
  671.  
  672. //      Editor status message.
  673. extern void editor_status(const char *format, ... );
  674.  
  675. // Variables in editor.c that the k*.c files need
  676.  
  677. #define UF_NONE             0x000       //nothing has changed
  678. #define UF_WORLD_CHANGED    0x001       //something added or deleted
  679. #define UF_VIEWPOINT_MOVED  0x002       //what we're watching has moved
  680.  
  681. #define UF_GAME_VIEW_CHANGED 0x004        //the game window changed    
  682. #define UF_ED_STATE_CHANGED  0x008        //something like curside,curseg changed
  683.  
  684. #define UF_ALL                    0xffffffff  //all flags
  685.  
  686. extern uint        Update_flags;
  687. extern int         Funky_chase_mode;
  688. extern vms_angvec  Seg_orientation;
  689. extern vms_vector  Seg_scale;
  690. extern int         mine_changed;
  691. extern int         ModeFlag;
  692. extern editor_view *current_view;
  693.  
  694. //the view for the different windows
  695. extern editor_view LargeView;
  696. extern editor_view TopView;
  697. extern editor_view FrontView;
  698. extern editor_view RightView;
  699.  
  700. extern void set_view_target_from_segment(segment *sp);
  701. extern int SafetyCheck();
  702.  
  703. extern void editor_status( const char *format, ...);
  704.  
  705. extern int MacroNumEvents;
  706. extern int MacroStatus;
  707.  
  708. //extern    int    Highest_vertex_index;            // Highest index in Vertices and Vertex_active, an efficiency hack
  709. //extern    int    Highest_segment_index;            // Highest index in Segments, an efficiency hack
  710. extern    int    Lock_view_to_cursegp;            // !0 means whenever cursegp changes, view it
  711.  
  712. //    eglobal.c
  713. extern    int    Num_tilings;                        // number of tilings/wall
  714. extern    int    Degenerate_segment_found;
  715.  
  716. extern    byte    Been_visited[];                    //    List of segments visited in a recursive search, if element n set, segment n done been visited
  717.  
  718. // Initializes autosave system.
  719. // Sets global Autosave_count to 0.
  720. extern void init_autosave(void);
  721.  
  722. // Closes autosave system.
  723. // Deletes all autosaved files.
  724. extern void close_autosave(void);
  725.  
  726. // Saves current mine to name.miX where name = suffix of mine name and X = Autosave_count.
  727. // For example, if name = "cookie.min", and Autosave_count = 3, then writes "cookie.mi3".
  728. // Increments Autosave_count, wrapping from 9 to 0.
  729. // (If there is no current mine name, assume "temp.min")
  730. // Call med_save_mine to save the mine.
  731. extern void autosave_mine(char *name);
  732.  
  733. // Timed autosave
  734. extern void TimedAutosave(char *name);
  735. extern void set_editor_time_of_day();
  736.  
  737. // Undo function
  738. extern int undo(void);
  739. extern char mine_filename[128];
  740. extern char undo_status[10][100];
  741.  
  742. //    group.c
  743. int AttachSegmentNewAng(vms_angvec *pbh);
  744. int RotateSegmentNew(vms_angvec *pbh);
  745. int rotate_segment_new(vms_angvec *pbh);
  746.  
  747. //get & free vertices
  748. int alloc_vert();
  749. void free_vert(int vert_num);
  750.  
  751. // The current robot type declared in eglobal.c
  752. extern int Cur_robot_type;
  753.  
  754. //    From med.c
  755. extern int DisplayCurrentRobotType(void);
  756. extern short            Cur_object_index;
  757.  
  758. extern int render_3d_in_big_window;
  759. extern void move_object_to_mouse_click(void);
  760.  
  761. //these are instances of canvases, pointed to by variables below
  762. extern grs_canvas _canv_editor_game;        //the game on the editor screen
  763.  
  764. //these are pointers to our canvases
  765. extern grs_canvas *Canv_editor;            //the editor screen
  766. extern grs_canvas *Canv_editor_game; //the game on the editor screen
  767.  
  768. extern grs_canvas *canv_offscreen;        //for off-screen rendering
  769. extern grs_canvas *Pad_text_canvas;        // Keypad text
  770.  
  771. //where the editor is looking
  772. extern vms_vector Ed_view_target;
  773.  
  774. extern int gamestate_not_restored;
  775.  
  776. extern UI_WINDOW * EditorWindow;
  777.  
  778. extern int     Large_view_index;
  779.  
  780. extern UI_GADGET_USERBOX * GameViewBox;
  781. extern UI_GADGET_USERBOX * LargeViewBox;
  782. extern UI_GADGET_USERBOX * GroupViewBox;
  783.  
  784. extern med_point_2_vec(grs_canvas *canv,vms_vector *v,short sx,short sy);
  785.  
  786. //shutdown ui on the editor screen
  787. close_editor_screen(void);
  788.  
  789. //    From eobject.c
  790. extern int place_object(segment *segp, vms_vector *object_pos, int object_type);
  791.  
  792. // from ksegsize.c
  793. extern void med_extract_up_vector_from_segment_side(segment *sp, int sidenum, vms_vector *vp);
  794. extern void med_extract_right_vector_from_segment_side(segment *sp, int sidenum, vms_vector *vp);
  795. extern void med_extract_forward_vector_from_segment_side(segment *sp, int sidenum, vms_vector *vp);
  796.  
  797. //    In medmisc.c
  798. extern void draw_world_from_game(void);
  799.  
  800. //    In medrobot.c
  801. extern void close_all_windows(void);
  802.  
  803. //    In seguvs.c
  804.  
  805. //    Amount to stretch a texture map by.
  806. //    The two different ones are for the two dimensions of a texture map.
  807. extern fix Stretch_scale_x, Stretch_scale_y;
  808.  
  809. #endif
  810.  
  811.