1 /* $Id: render.c,v 1.14 2003-02-18 19:57:19 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * FIXME: put description here
20 * Revision 1.9 1995/11/20 17:17:48 allender
21 * *** empty log message ***
23 * Revision 1.8 1995/10/26 14:08:35 allender
24 * added assigment for physics optimization
26 * Revision 1.7 1995/09/22 14:28:46 allender
27 * changed render_zoom to make game match PC aspect
29 * Revision 1.6 1995/08/14 14:35:54 allender
30 * change transparency to 0
32 * Revision 1.5 1995/08/12 11:32:02 allender
33 * removed #ifdef NEWDEMO -- always in
35 * Revision 1.4 1995/07/05 16:48:31 allender
38 * Revision 1.3 1995/06/23 10:22:54 allender
41 * Revision 1.2 1995/06/16 16:11:18 allender
42 * changed sort func to accept const parameters
44 * Revision 1.1 1995/05/16 15:30:24 allender
47 * Revision 2.5 1995/12/19 15:31:36 john
48 * Made stereo mode only record 1 eye in demo.
50 * Revision 2.4 1995/03/20 18:15:53 john
51 * Added code to not store the normals in the segment structure.
53 * Revision 2.3 1995/03/13 16:11:05 john
54 * Maybe fixed bug that lighting didn't work with vr helmets.
56 * Revision 2.2 1995/03/09 15:33:49 john
57 * Fixed bug with iglasses timeout too long, and objects
58 * disappearing from left eye.
60 * Revision 2.1 1995/03/06 15:23:59 john
61 * New screen techniques.
63 * Revision 2.0 1995/02/27 11:31:01 john
64 * New version 2.0, which has no anonymous unions, builds with
65 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
67 * Revision 1.252 1995/02/22 13:49:38 allender
68 * remove anonymous unions from object structure
70 * Revision 1.251 1995/02/11 15:07:26 matt
71 * Took out code which was mostly intended as part of a larger renderer
72 * change which never happened. This new code was causing problems with
73 * the level 4 control center.
75 * Revision 1.250 1995/02/07 16:28:53 matt
76 * Fixed problem with new code
78 * Revision 1.249 1995/02/06 14:38:58 matt
79 * Took out some code that didn't compile when editor in
81 * Revision 1.248 1995/02/06 13:45:25 matt
82 * Structural changes, plus small sorting improvements
84 * Revision 1.247 1995/02/02 15:59:26 matt
85 * Changed assert to int3.
87 * Revision 1.246 1995/02/01 21:02:27 matt
88 * Added partial fix for rendering bugs
89 * Ripped out laser hack system
91 * Revision 1.245 1995/01/20 15:14:30 matt
92 * Added parens to fix precedence bug
94 * Revision 1.244 1995/01/14 19:16:59 john
95 * First version of new bitmap paging code.
97 * Revision 1.243 1995/01/03 20:19:25 john
98 * Pretty good working version of game save.
100 * Revision 1.242 1994/12/29 13:51:05 john
101 * Made the floating reticle draw in the spot
102 * regardless of the eye offset.
104 * Revision 1.241 1994/12/23 15:02:55 john
105 * Tweaked floating reticle.
107 * Revision 1.240 1994/12/23 14:27:45 john
108 * Changed offset of floating reticle to line up with
109 * lasers a bit better.
111 * Revision 1.239 1994/12/23 14:22:50 john
112 * Added floating reticle for VR helments.
114 * Revision 1.238 1994/12/13 14:07:50 matt
115 * Fixed tmap_num2 bug in search mode
117 * Revision 1.237 1994/12/11 00:45:53 matt
118 * Fixed problem when object sort buffer got full
120 * Revision 1.236 1994/12/09 18:46:06 matt
121 * Added a little debugging
123 * Revision 1.235 1994/12/09 14:59:16 matt
124 * Added system to attach a fireball to another object for rendering purposes,
125 * so the fireball always renders on top of (after) the object.
127 * Revision 1.234 1994/12/08 15:46:54 matt
128 * Fixed buffer overflow that caused seg depth screwup
130 * Revision 1.233 1994/12/08 11:51:53 matt
131 * Took out some unused stuff
133 * Revision 1.232 1994/12/06 16:31:48 mike
134 * fix detriangulation problems.
136 * Revision 1.231 1994/12/05 15:32:51 matt
137 * Changed an assert to an int3 & return
139 * Revision 1.230 1994/12/04 17:28:04 matt
140 * Got rid of unused no_render_flag array, and took out box clear when searching
142 * Revision 1.229 1994/12/04 15:51:14 matt
143 * Fixed linear tmap transition for objects
145 * Revision 1.228 1994/12/03 20:16:50 matt
146 * Turn off window clip for objects
148 * Revision 1.227 1994/12/03 14:48:00 matt
149 * Restored some default settings
151 * Revision 1.226 1994/12/03 14:44:32 matt
152 * Fixed another difficult bug in the window clip system
154 * Revision 1.225 1994/12/02 13:19:56 matt
155 * Fixed rect clears at terminus of rendering
156 * Made a bunch of debug code compile out
158 * Revision 1.224 1994/12/02 11:58:21 matt
159 * Fixed window clip bug
161 * Revision 1.223 1994/11/28 21:50:42 mike
164 * Revision 1.222 1994/11/28 01:32:15 mike
165 * turn off window clearing.
167 * Revision 1.221 1994/11/27 23:11:52 matt
168 * Made changes for new mprintf calling convention
170 * Revision 1.220 1994/11/20 15:58:55 matt
171 * Don't migrate the control center, since it doesn't move out of its segment
173 * Revision 1.219 1994/11/19 23:54:36 mike
174 * change window colors.
176 * Revision 1.218 1994/11/19 15:20:25 mike
177 * rip out unused code and data
179 * Revision 1.217 1994/11/18 13:21:24 mike
180 * Clear only view portals into rest of world based on value of Clear_window.
182 * Revision 1.216 1994/11/15 17:02:10 matt
183 * Re-added accidentally deleted variable
185 * Revision 1.215 1994/11/15 16:51:50 matt
186 * Made rear view only switch to rear cockpit if cockpit on in front view
188 * Revision 1.214 1994/11/14 20:47:57 john
189 * Attempted to strip out all the code in the game
190 * directory that uses any ui code.
192 * Revision 1.213 1994/11/11 15:37:07 mike
193 * write orange for background to show render bugs.
195 * Revision 1.212 1994/11/09 22:57:18 matt
196 * Keep tract of depth of segments rendered, for detail level optimization
198 * Revision 1.211 1994/11/01 23:40:14 matt
199 * Elegantly handler buffer getting full
201 * Revision 1.210 1994/10/31 22:28:13 mike
202 * Fix detriangulation bug.
204 * Revision 1.209 1994/10/31 11:48:56 mike
205 * Optimize detriangulation, speedup of about 4% in many cases, 0% in many.
207 * Revision 1.208 1994/10/30 20:08:34 matt
208 * For endlevel: added big explosion at tunnel exit; made lights in tunnel
209 * go out; made more explosions on walls.
211 * Revision 1.207 1994/10/27 14:14:35 matt
212 * Don't do light flash during endlevel sequence
214 * Revision 1.206 1994/10/11 12:05:42 mike
215 * Improve detriangulation.
217 * Revision 1.205 1994/10/07 15:27:00 john
218 * Commented out the code that moves your eye
221 * Revision 1.204 1994/10/05 16:07:38 mike
222 * Don't detriangulate sides if in player's segment. Prevents player going behind a wall,
223 * though there are cases in which it would be ok to detriangulate these.
225 * Revision 1.203 1994/10/03 12:44:05 matt
226 * Took out unreferenced code
228 * Revision 1.202 1994/09/28 14:08:45 john
229 * Added Zoom stuff back in, but ifdef'd it out.
231 * Revision 1.201 1994/09/25 23:41:49 matt
232 * Changed the object load & save code to read/write the structure fields one
233 * at a time (rather than the whole structure at once). This mean that the
234 * object structure can be changed without breaking the load/save functions.
235 * As a result of this change, the local_object data can be and has been
236 * incorporated into the object array. Also, timeleft is now a property
237 * of all objects, and the object structure has been otherwise cleaned up.
239 * Revision 1.200 1994/09/25 15:50:10 mike
240 * Integrate my debug changes which shows how many textures were rendered
243 * Revision 1.199 1994/09/25 15:45:22 matt
244 * Added OBJ_LIGHT, a type of object that casts light
245 * Added generalized lifeleft, and moved it to local_object
247 * Revision 1.198 1994/09/15 21:23:32 matt
248 * Changed system to keep track of whether & what cockpit is up
250 * Revision 1.197 1994/09/15 16:30:12 mike
251 * Comment out call to object_render_targets, which did nothing.
253 * Revision 1.196 1994/09/07 22:25:51 matt
254 * Don't migrate through semi-transparent walls
256 * Revision 1.195 1994/09/07 19:16:21 mike
259 * Revision 1.194 1994/08/31 20:54:17 matt
260 * Don't do flash effect while whiting out
262 * Revision 1.193 1994/08/23 17:20:12 john
263 * Added rear-view cockpit.
265 * Revision 1.192 1994/08/22 14:36:35 john
266 * Made R key make a "reverse" view render.
268 * Revision 1.191 1994/08/19 20:09:26 matt
269 * Added end-of-level cut scene with external scene
271 * Revision 1.190 1994/08/10 19:56:17 john
272 * Changed font stuff; Took out old menu; messed up lots of
273 * other stuff like game sequencing messages, etc.
275 * Revision 1.189 1994/08/10 14:45:05 john
276 * *** empty log message ***
278 * Revision 1.188 1994/08/09 16:04:06 john
279 * Added network players to editor.
281 * Revision 1.187 1994/08/05 17:07:05 john
282 * Made lasers be two objects, one drawing after the other
285 * Revision 1.186 1994/08/05 10:07:57 matt
286 * Disable window check checking (i.e., always use window check)
288 * Revision 1.185 1994/08/04 19:11:30 matt
289 * Changed a bunch of vecmat calls to use multiple-function routines, and to
290 * allow the use of C macros for some functions
292 * Revision 1.184 1994/08/04 00:21:14 matt
293 * Cleaned up fvi & physics error handling; put in code to make sure objects
294 * are in correct segment; simplified segment finding for objects and points
296 * Revision 1.183 1994/08/02 19:04:28 matt
297 * Cleaned up vertex list functions
299 * Revision 1.182 1994/07/29 15:13:33 matt
300 * When window check turned off, cut render depth in half
302 * Revision 1.181 1994/07/29 11:03:50 matt
303 * Use highest_segment_index instead of num_segments so render works from
306 * Revision 1.180 1994/07/29 10:04:34 mike
307 * Update Cursegp when an object is selected.
309 * Revision 1.179 1994/07/25 00:02:50 matt
310 * Various changes to accomodate new 3d, which no longer takes point numbers
311 * as parms, and now only takes pointers to points.
313 * Revision 1.178 1994/07/24 14:37:49 matt
314 * Added angles for player head
316 * Revision 1.177 1994/07/20 19:08:07 matt
317 * If in editor, don't move eye from center of viewer object
330 #include "pa_enabl.h" //$$POLY_ACC
341 #include "textures.h"
343 #include "segpoint.h"
345 #include "texmerge.h"
350 #include "lighting.h"
351 #include "cntrlcen.h"
354 #include "endlevel.h"
361 #include "ogl_init.h"
364 #define INITIAL_LOCAL_LIGHT (F1_0/4) // local light value in segment of occurence (of light emission)
367 #include "editor/editor.h"
370 #if defined(POLY_ACC)
371 #include "poly_acc.h"
374 //used for checking if points have been rotated
375 int Clear_window_color=-1;
376 int Clear_window=2; // 1 = Clear whole background window, 2 = clear view portals into rest of world, 0 = no clear
378 int RL_framecount=-1;
379 short Rotated_last[MAX_VERTICES];
381 // When any render function needs to know what's looking at it, it should
382 // access Viewer members.
383 object * Viewer = NULL;
385 vms_vector Viewer_eye; //valid during render
390 fix Render_zoom = 0x9000; //the player's zoom factor
392 fix Render_zoom = 0xB000;
396 ubyte object_rendered[MAX_OBJECTS];
399 #define DEFAULT_RENDER_DEPTH 16
400 int Render_depth=DEFAULT_RENDER_DEPTH; //how many segments deep to render
402 int Detriangulation_on = 1; // 1 = allow rendering of triangulated side as a quad, 0 = don't allow
405 int Render_only_bottom=0;
406 int Bottom_bitmap_num = 9;
409 fix Face_reflectivity = (F1_0/2);
411 #if 0 //this stuff could probably just be deleted
413 int inc_render_depth(void)
415 return ++Render_depth;
418 int dec_render_depth(void)
420 return Render_depth==1?Render_depth:--Render_depth;
423 int reset_render_depth(void)
425 return Render_depth = DEFAULT_RENDER_DEPTH;
431 int _search_mode = 0; //true if looking for curseg,side,face
432 short _search_x,_search_y; //pixel we're looking at
433 int found_seg,found_side,found_face,found_poly;
435 #define _search_mode 0
438 #ifdef NDEBUG //if no debug code, set these vars to constants
440 #define Outline_mode 0
441 #define Show_only_curside 0
445 int Outline_mode=0,Show_only_curside=0;
447 int toggle_outline_mode(void)
449 return Outline_mode = !Outline_mode;
452 int toggle_show_only_curside(void)
454 return Show_only_curside = !Show_only_curside;
457 void draw_outline(int nverts,g3s_point **pointlist)
461 gr_setcolor(BM_XRGB(63,63,63));
463 for (i=0;i<nverts-1;i++)
464 g3_draw_line(pointlist[i],pointlist[i+1]);
466 g3_draw_line(pointlist[i],pointlist[0]);
471 grs_canvas * reticle_canvas = NULL;
473 void free_reticle_canvas()
475 if (reticle_canvas) {
476 d_free( reticle_canvas->cv_bitmap.bm_data );
477 d_free( reticle_canvas );
478 reticle_canvas = NULL;
482 extern void show_reticle(int force_big);
484 // Draw the reticle in 3D for head tracking
485 void draw_3d_reticle(fix eye_offset)
487 g3s_point reticle_points[4];
489 g3s_point *pointlist[4];
492 grs_canvas *saved_canvas;
493 int saved_interp_method;
495 // if (!Use_player_head_angles) return;
497 for (i=0; i<4; i++ ) {
498 pointlist[i] = &reticle_points[i];
499 uvl[i].l = MAX_LIGHT;
501 uvl[0].u = 0; uvl[0].v = 0;
502 uvl[1].u = F1_0; uvl[1].v = 0;
503 uvl[2].u = F1_0; uvl[2].v = F1_0;
504 uvl[3].u = 0; uvl[3].v = F1_0;
506 vm_vec_scale_add( &v1, &Viewer->pos, &Viewer->orient.fvec, F1_0*4 );
507 vm_vec_scale_add2(&v1,&Viewer->orient.rvec,eye_offset);
509 vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, -F1_0*1 );
510 vm_vec_scale_add2( &v2, &Viewer->orient.uvec, F1_0*1 );
511 g3_rotate_point(&reticle_points[0],&v2);
513 vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, +F1_0*1 );
514 vm_vec_scale_add2( &v2, &Viewer->orient.uvec, F1_0*1 );
515 g3_rotate_point(&reticle_points[1],&v2);
517 vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, +F1_0*1 );
518 vm_vec_scale_add2( &v2, &Viewer->orient.uvec, -F1_0*1 );
519 g3_rotate_point(&reticle_points[2],&v2);
521 vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, -F1_0*1 );
522 vm_vec_scale_add2( &v2, &Viewer->orient.uvec, -F1_0*1 );
523 g3_rotate_point(&reticle_points[3],&v2);
525 if ( reticle_canvas == NULL ) {
526 reticle_canvas = gr_create_canvas(64,64);
527 if ( !reticle_canvas )
528 Error( "Couldn't malloc reticle_canvas" );
529 atexit( free_reticle_canvas );
530 reticle_canvas->cv_bitmap.bm_handle = 0;
531 reticle_canvas->cv_bitmap.bm_flags = BM_FLAG_TRANSPARENT;
534 saved_canvas = grd_curcanv;
535 gr_set_current_canvas(reticle_canvas);
536 gr_clear_canvas( TRANSPARENCY_COLOR ); // Clear to Xparent
538 gr_set_current_canvas(saved_canvas);
540 saved_interp_method=Interpolation_method;
541 Interpolation_method = 3; // The best, albiet slowest.
542 g3_draw_tmap(4,pointlist,uvl,&reticle_canvas->cv_bitmap);
543 Interpolation_method = saved_interp_method;
547 extern fix Seismic_tremor_magnitude;
551 #define FLASH_CYCLE_RATE f1_0
553 fix Flash_rate = FLASH_CYCLE_RATE;
555 //cycle the flashing light for when mine destroyed
558 static fixang flash_ang=0;
560 if (!Control_center_destroyed && !Seismic_tremor_magnitude)
563 if (Endlevel_sequence)
566 if (PaletteBlueAdd > 10 ) //whiting out
569 // flash_ang += fixmul(FLASH_CYCLE_RATE,FrameTime);
570 if (Seismic_tremor_magnitude) {
573 added_flash = abs(Seismic_tremor_magnitude);
574 if (added_flash < F1_0)
577 flash_ang += fixmul(Flash_rate, fixmul(FrameTime, added_flash+F1_0));
578 fix_fastsincos(flash_ang,&flash_scale,NULL);
579 flash_scale = (flash_scale + F1_0*3)/4; // gets in range 0.5 to 1.0
581 flash_ang += fixmul(Flash_rate,FrameTime);
582 fix_fastsincos(flash_ang,&flash_scale,NULL);
583 flash_scale = (flash_scale + f1_0)/2;
584 if (Difficulty_level == 0)
585 flash_scale = (flash_scale+F1_0*3)/4;
591 // ----------------------------------------------------------------------------
593 // It would be nice to not have to pass in segnum and sidenum, but
594 // they are used for our hideously hacked in headlight system.
595 // vp is a pointer to vertex ids.
596 // tmap1, tmap2 are texture map ids. tmap2 is the pasty one.
597 void render_face(int segnum, int sidenum, int nv, short *vp, int tmap1, int tmap2, uvl *uvlp, int wid_flags)
599 // -- Using new headlight system...fix face_light;
602 grs_bitmap *bm2 = NULL;
608 g3s_point *pointlist[8];
612 for (i=0; i<nv; i++) {
613 uvl_copy[i] = uvlp[i];
614 pointlist[i] = &Segment_points[vp[i]];
617 //handle cloaked walls
618 if (wid_flags & WID_CLOAKED_FLAG) {
619 int wall_num = Segments[segnum].sides[sidenum].wall_num;
620 Assert(wall_num != -1);
621 Gr_scanline_darkening_level = Walls[wall_num].cloak_value;
622 gr_setcolor(BM_XRGB(0,0,0)); //set to black (matters for s3)
624 g3_draw_poly(nv,pointlist); //draw as flat poly
626 Gr_scanline_darkening_level = GR_FADE_LEVELS;
631 // -- Using new headlight system...face_light = -vm_vec_dot(&Viewer->orient.fvec,norm);
633 if (tmap1 >= NumTextures) {
634 mprintf((0,"Invalid tmap number %d, NumTextures=%d, changing to 0\n",tmap1,NumTextures));
640 Segments[segnum].sides[sidenum].tmap_num = 0;
644 if (ogl_alttexmerge){
645 PIGGY_PAGE_IN(Textures[tmap1]);
646 bm = &GameBitmaps[Textures[tmap1].index];
648 PIGGY_PAGE_IN(Textures[tmap2&0x3FFF]);
649 bm2 = &GameBitmaps[Textures[tmap2&0x3FFF].index];
651 if (bm2 && (bm2->bm_flags&BM_FLAG_SUPER_TRANSPARENT)){
652 bm = texmerge_get_cached_bitmap( tmap1, tmap2 );
658 // New code for overlapping textures...
660 bm = texmerge_get_cached_bitmap( tmap1, tmap2 );
662 bm = &GameBitmaps[Textures[tmap1].index];
663 PIGGY_PAGE_IN(Textures[tmap1]);
666 Assert( !(bm->bm_flags & BM_FLAG_PAGED_OUT) );
668 //reflect = fl2f((1.0-TmapInfo[p->tmap_num].reflect)/2.0 + 0.5);
669 //reflect = fl2f((1.0-TmapInfo[p->tmap_num].reflect));
671 reflect = Face_reflectivity; // f1_0; //until we figure this stuff out...
673 //set light values for each vertex & build pointlist
677 // -- Using new headlight system...face_light = fixmul(face_light,reflect);
681 //the uvl struct has static light already in it
683 //scale static light for destruction effect
684 if (Control_center_destroyed || Seismic_tremor_magnitude) //make lights flash
685 uvl_copy[i].l = fixmul(flash_scale,uvl_copy[i].l);
687 //add in dynamic light (from explosions, etc.)
688 uvl_copy[i].l += Dynamic_light[vp[i]];
690 //add in light from player's headlight
691 // -- Using new headlight system...uvl_copy[i].l += compute_headlight_light(&Segment_points[vp[i]].p3_vec,face_light);
693 //saturate at max value
694 if (uvl_copy[i].l > MAX_LIGHT)
695 uvl_copy[i].l = MAX_LIGHT;
701 if ((Render_only_bottom) && (sidenum == WBOTTOM))
702 g3_draw_tmap(nv,pointlist,(g3s_uvl *) uvl_copy,&GameBitmaps[Textures[Bottom_bitmap_num].index]);
708 g3_draw_tmap_2(nv,pointlist,(g3s_uvl *) uvl_copy,bm,bm2,((tmap2&0xC000)>>14) & 3);
711 g3_draw_tmap(nv,pointlist,(g3s_uvl *) uvl_copy,bm);
714 if (Outline_mode) draw_outline(nv, pointlist);
719 // ----------------------------------------------------------------------------
720 // Only called if editor active.
721 // Used to determine which face was clicked on.
722 void check_face(int segnum, int sidenum, int facenum, int nv, short *vp, int tmap1, int tmap2, uvl *uvlp)
730 g3s_point *pointlist[4];
733 bm = texmerge_get_cached_bitmap( tmap1, tmap2 );
735 bm = &GameBitmaps[Textures[tmap1].index];
737 for (i=0; i<nv; i++) {
738 uvl_copy[i] = uvlp[i];
739 pointlist[i] = &Segment_points[vp[i]];
743 gr_pixel(_search_x,_search_y); //set our search pixel to color zero
744 gr_setcolor(1); //and render in color one
745 save_lighting = Lighting_on;
747 //g3_draw_poly(nv,vp);
748 g3_draw_tmap(nv,pointlist, (g3s_uvl *)uvl_copy, bm);
749 Lighting_on = save_lighting;
751 if (gr_ugpixel(&grd_curcanv->cv_bitmap,_search_x,_search_y) == 1) {
753 found_side = sidenum;
754 found_face = facenum;
760 fix Tulate_min_dot = (F1_0/4);
761 //--unused-- fix Tulate_min_ratio = (2*F1_0);
762 fix Min_n0_n1_dot = (F1_0*15/16);
764 extern int contains_flare(segment *segp, int sidenum);
765 extern fix Obj_light_xlate[16];
767 // -----------------------------------------------------------------------------------
769 // Check for normal facing. If so, render faces on side dictated by sidep->type.
770 void render_side(segment *segp, int sidenum)
772 short vertnum_list[4];
773 side *sidep = &segp->sides[sidenum];
775 fix v_dot_n0, v_dot_n1;
777 fix min_dot, max_dot;
778 vms_vector normals[2];
782 wid_flags = WALL_IS_DOORWAY(segp,sidenum);
784 if (!(wid_flags & WID_RENDER_FLAG)) //if (WALL_IS_DOORWAY(segp, sidenum) == WID_NO_WALL)
788 get_side_normals(segp, sidenum, &normals[0], &normals[1] );
790 normals[0] = segp->sides[sidenum].normals[0];
791 normals[1] = segp->sides[sidenum].normals[1];
794 // ========== Mark: Here is the change...beginning here: ==========
796 if (sidep->type == SIDE_IS_QUAD) {
798 vm_vec_sub(&tvec, &Viewer_eye, &Vertices[segp->verts[Side_to_verts[sidenum][0]]]);
800 // -- Old, slow way -- // Regardless of whether this side is comprised of a single quad, or two triangles, we need to know one normal, so
801 // -- Old, slow way -- // deal with it, get the dot product.
802 // -- Old, slow way -- if (sidep->type == SIDE_IS_TRI_13)
803 // -- Old, slow way -- vm_vec_normalized_dir(&tvec, &Viewer_eye, &Vertices[segp->verts[Side_to_verts[sidenum][1]]]);
804 // -- Old, slow way -- else
805 // -- Old, slow way -- vm_vec_normalized_dir(&tvec, &Viewer_eye, &Vertices[segp->verts[Side_to_verts[sidenum][0]]]);
807 get_side_verts(vertnum_list,segp-Segments,sidenum);
808 v_dot_n0 = vm_vec_dot(&tvec, &normals[0]);
810 // -- flare creates point -- {
811 // -- flare creates point -- int flare_index;
812 // -- flare creates point --
813 // -- flare creates point -- flare_index = contains_flare(segp, sidenum);
814 // -- flare creates point --
815 // -- flare creates point -- if (flare_index != -1) {
816 // -- flare creates point -- int tri;
817 // -- flare creates point -- fix u, v, l;
818 // -- flare creates point -- vms_vector *hit_point;
819 // -- flare creates point -- short vertnum_list[4];
820 // -- flare creates point --
821 // -- flare creates point -- hit_point = &Objects[flare_index].pos;
822 // -- flare creates point --
823 // -- flare creates point -- find_hitpoint_uv( &u, &v, &l, hit_point, segp, sidenum, 0); // last parm means always use face 0.
824 // -- flare creates point --
825 // -- flare creates point -- get_side_verts(vertnum_list, segp-Segments, sidenum);
826 // -- flare creates point --
827 // -- flare creates point -- g3_rotate_point(&Segment_points[MAX_VERTICES-1], hit_point);
828 // -- flare creates point --
829 // -- flare creates point -- for (tri=0; tri<4; tri++) {
830 // -- flare creates point -- short tri_verts[3];
831 // -- flare creates point -- uvl tri_uvls[3];
832 // -- flare creates point --
833 // -- flare creates point -- tri_verts[0] = vertnum_list[tri];
834 // -- flare creates point -- tri_verts[1] = vertnum_list[(tri+1) % 4];
835 // -- flare creates point -- tri_verts[2] = MAX_VERTICES-1;
836 // -- flare creates point --
837 // -- flare creates point -- tri_uvls[0] = sidep->uvls[tri];
838 // -- flare creates point -- tri_uvls[1] = sidep->uvls[(tri+1)%4];
839 // -- flare creates point -- tri_uvls[2].u = u;
840 // -- flare creates point -- tri_uvls[2].v = v;
841 // -- flare creates point -- tri_uvls[2].l = F1_0;
842 // -- flare creates point --
843 // -- flare creates point -- render_face(segp-Segments, sidenum, 3, tri_verts, sidep->tmap_num, sidep->tmap_num2, tri_uvls, &normals[0]);
844 // -- flare creates point -- }
845 // -- flare creates point --
846 // -- flare creates point -- return;
847 // -- flare creates point -- }
848 // -- flare creates point -- }
851 render_face(segp-Segments, sidenum, 4, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls, wid_flags);
853 check_face(segp-Segments, sidenum, 0, 4, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls);
857 // Regardless of whether this side is comprised of a single quad, or two triangles, we need to know one normal, so
858 // deal with it, get the dot product.
859 if (sidep->type == SIDE_IS_TRI_13)
860 vm_vec_normalized_dir_quick(&tvec, &Viewer_eye, &Vertices[segp->verts[Side_to_verts[sidenum][1]]]);
862 vm_vec_normalized_dir_quick(&tvec, &Viewer_eye, &Vertices[segp->verts[Side_to_verts[sidenum][0]]]);
864 get_side_verts(vertnum_list,segp-Segments,sidenum);
866 v_dot_n0 = vm_vec_dot(&tvec, &normals[0]);
868 // ========== Mark: The change ends here. ==========
870 // Although this side has been triangulated, because it is not planar, see if it is acceptable
871 // to render it as a single quadrilateral. This is a function of how far away the viewer is, how non-planar
872 // the face is, how normal to the surfaces the view is.
873 // Now, if both dot products are close to 1.0, then render two triangles as a single quad.
874 v_dot_n1 = vm_vec_dot(&tvec, &normals[1]);
876 if (v_dot_n0 < v_dot_n1) {
884 // Determine whether to detriangulate side: (speed hack, assumes Tulate_min_ratio == F1_0*2, should fixmul(min_dot, Tulate_min_ratio))
885 if (Detriangulation_on && ((min_dot+F1_0/256 > max_dot) || ((Viewer->segnum != segp-Segments) && (min_dot > Tulate_min_dot) && (max_dot < min_dot*2)))) {
888 // The other detriangulation code doesn't deal well with badly non-planar sides.
889 n0_dot_n1 = vm_vec_dot(&normals[0], &normals[1]);
890 if (n0_dot_n1 < Min_n0_n1_dot)
893 render_face(segp-Segments, sidenum, 4, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls, wid_flags);
895 check_face(segp-Segments, sidenum, 0, 4, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls);
899 if (sidep->type == SIDE_IS_TRI_02) {
901 render_face(segp-Segments, sidenum, 3, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls, wid_flags);
903 check_face(segp-Segments, sidenum, 0, 3, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls);
908 temp_uvls[0] = sidep->uvls[0]; temp_uvls[1] = sidep->uvls[2]; temp_uvls[2] = sidep->uvls[3];
909 vertnum_list[1] = vertnum_list[2]; vertnum_list[2] = vertnum_list[3]; // want to render from vertices 0, 2, 3 on side
910 render_face(segp-Segments, sidenum, 3, &vertnum_list[0], sidep->tmap_num, sidep->tmap_num2, temp_uvls, wid_flags);
912 check_face(segp-Segments, sidenum, 1, 3, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls);
915 } else if (sidep->type == SIDE_IS_TRI_13) {
917 render_face(segp-Segments, sidenum, 3, &vertnum_list[1], sidep->tmap_num, sidep->tmap_num2, &sidep->uvls[1], wid_flags); // rendering 1,2,3, so just skip 0
919 check_face(segp-Segments, sidenum, 1, 3, &vertnum_list[1], sidep->tmap_num, sidep->tmap_num2, sidep->uvls);
924 temp_uvls[0] = sidep->uvls[0]; temp_uvls[1] = sidep->uvls[1]; temp_uvls[2] = sidep->uvls[3];
925 vertnum_list[2] = vertnum_list[3]; // want to render from vertices 0,1,3
926 render_face(segp-Segments, sidenum, 3, vertnum_list, sidep->tmap_num, sidep->tmap_num2, temp_uvls, wid_flags);
928 check_face(segp-Segments, sidenum, 0, 3, vertnum_list, sidep->tmap_num, sidep->tmap_num2, sidep->uvls);
934 Error("Illegal side type in render_side, type = %i, segment # = %li, side # = %i\n", sidep->type, segp-Segments, sidenum);
936 Error("Illegal side type in render_side, type = %i, segment # = %i, side # = %i\n", sidep->type, segp-Segments, sidenum);
944 void render_object_search(object *obj)
948 //note that we draw each pixel object twice, since we cannot control
949 //what color the object draws in, so we try color 0, then color 1,
950 //in case the object itself is rendering color 0
953 gr_pixel(_search_x,_search_y); //set our search pixel to color zero
955 if (gr_ugpixel(&grd_curcanv->cv_bitmap,_search_x,_search_y) != 0)
959 gr_pixel(_search_x,_search_y); //set our search pixel to color zero
961 if (gr_ugpixel(&grd_curcanv->cv_bitmap,_search_x,_search_y) != 1)
965 if (obj->segnum != -1)
966 Cursegp = &Segments[obj->segnum];
967 found_seg = -(obj-Objects+1);
972 extern ubyte DemoDoingRight,DemoDoingLeft;
974 void do_render_object(int objnum, int window_num)
977 int save_3d_outline=0;
979 object *obj = &Objects[objnum];
983 Assert(objnum < MAX_OBJECTS);
986 if (object_rendered[objnum]) { //already rendered this...
987 Int3(); //get Matt!!!
991 object_rendered[objnum] = 1;
994 if (Newdemo_state==ND_STATE_PLAYBACK)
996 if ((DemoDoingLeft==6 || DemoDoingRight==6) && Objects[objnum].type==OBJ_PLAYER)
998 // A nice fat hack: keeps the player ship from showing up in the
999 // small extra view when guiding a missile in the big window
1001 mprintf ((0,"Returning from render_object prematurely...\n"));
1006 // Added by MK on 09/07/94 (at about 5:28 pm, CDT, on a beautiful, sunny late summer day!) so
1007 // that the guided missile system will know what objects to look at.
1008 // I didn't know we had guided missiles before the release of D1. --MK
1009 if ((Objects[objnum].type == OBJ_ROBOT) || (Objects[objnum].type == OBJ_PLAYER)) {
1010 //Assert(Window_rendered_data[window_num].rendered_objects < MAX_RENDERED_OBJECTS);
1011 // This peculiar piece of code makes us keep track of the most recently rendered objects, which
1012 // are probably the higher priority objects, without overflowing the buffer
1013 if (Window_rendered_data[window_num].num_objects >= MAX_RENDERED_OBJECTS) {
1015 Window_rendered_data[window_num].num_objects /= 2;
1017 Window_rendered_data[window_num].rendered_objects[Window_rendered_data[window_num].num_objects++] = objnum;
1020 if ((count++ > MAX_OBJECTS) || (obj->next == objnum)) {
1021 Int3(); // infinite loop detected
1022 obj->next = -1; // won't this clean things up?
1023 return; // get out of this infinite loop!
1026 //g3_draw_object(obj->class_id,&obj->pos,&obj->orient,obj->size);
1028 //check for editor object
1031 if (Function_mode==FMODE_EDITOR && objnum==Cur_object_index) {
1032 save_3d_outline = g3d_interp_outline;
1033 g3d_interp_outline=1;
1039 render_object_search(obj);
1042 //NOTE LINK TO ABOVE
1045 for (n=obj->attached_obj;n!=-1;n=Objects[n].ctype.expl_info.next_attach) {
1047 Assert(Objects[n].type == OBJ_FIREBALL);
1048 Assert(Objects[n].control_type == CT_EXPLOSION);
1049 Assert(Objects[n].flags & OF_ATTACHED);
1051 render_object(&Objects[n]);
1056 if (Function_mode==FMODE_EDITOR && objnum==Cur_object_index)
1057 g3d_interp_outline = save_3d_outline;
1061 //DEBUG mprintf( (0, "%d ", objnum ));
1067 int window_check=1,draw_edges=0,new_seg_sorting=1,pre_draw_segs=0;
1068 int no_migrate_segs=1,migrate_objects=1,behind_check=1;
1069 int check_window_check=0;
1071 #define draw_boxes 0
1072 #define window_check 1
1073 #define draw_edges 0
1074 #define new_seg_sorting 1
1075 #define pre_draw_segs 0
1076 #define no_migrate_segs 1
1077 #define migrate_objects 1
1078 #define behind_check 1
1079 #define check_window_check 0
1082 //increment counter for checking if points rotated
1083 //This must be called at the start of the frame if rotate_list() will be used
1084 void render_start_frame()
1088 if (RL_framecount==0) { //wrap!
1090 memset(Rotated_last,0,sizeof(Rotated_last)); //clear all to zero
1091 RL_framecount=1; //and set this frame to 1
1095 //Given a lit of point numbers, rotate any that haven't been rotated this frame
1096 g3s_codes rotate_list(int nv,short *pointnumlist)
1102 cc.and = 0xff; cc.or = 0;
1104 for (i=0;i<nv;i++) {
1106 pnum = pointnumlist[i];
1108 pnt = &Segment_points[pnum];
1110 if (Rotated_last[pnum] != RL_framecount) {
1112 g3_rotate_point(pnt,&Vertices[pnum]);
1114 Rotated_last[pnum] = RL_framecount;
1117 cc.and &= pnt->p3_codes;
1118 cc.or |= pnt->p3_codes;
1125 //Given a lit of point numbers, project any that haven't been projected
1126 void project_list(int nv,short *pointnumlist)
1130 for (i=0;i<nv;i++) {
1132 pnum = pointnumlist[i];
1134 if (!(Segment_points[pnum].p3_flags & PF_PROJECTED))
1136 g3_project_point(&Segment_points[pnum]);
1142 // -----------------------------------------------------------------------------------
1143 void render_segment(int segnum, int window_num)
1145 segment *seg = &Segments[segnum];
1149 Assert(segnum!=-1 && segnum<=Highest_segment_index);
1151 cc=rotate_list(8,seg->verts);
1153 if (! cc.and) { //all off screen?
1155 //mprintf( (0, "!"));
1156 //DEBUG mprintf( (0, "[Segment %d: ", segnum ));
1158 // set_segment_local_light_value(segnum,INITIAL_LOCAL_LIGHT);
1160 if (Viewer->type!=OBJ_ROBOT)
1161 Automap_visited[segnum]=1;
1163 for (sn=0; sn<MAX_SIDES_PER_SEGMENT; sn++)
1164 render_side(seg, sn);
1167 //draw any objects that happen to be in this segment
1170 //object_sort_segment_objects( seg );
1173 if (!migrate_objects) {
1175 for (objnum=seg->objects;objnum!=-1;objnum=Objects[objnum].next)
1176 do_render_object(objnum, window_num);
1180 //DEBUG mprintf( (0, "]\n", segnum ));
1184 // ----- This used to be called when Show_only_curside was set.
1185 // ----- It is wholly and superiorly replaced by render_side.
1186 // -- //render one side of one segment
1187 // -- void render_seg_side(segment *seg,int _side)
1190 // -- short vertnum_list[4];
1192 // -- cc=g3_rotate_list(8,&seg->verts);
1194 // -- if (! cc.and) { //all off screen?
1200 // -- s=&seg->sides[_side];
1202 // -- for (f=s->faces,fn=s->num_faces;fn;fn--,f++)
1203 // -- for (p=f->polys,pn=f->num_polys;pn;pn--,p++) {
1204 // -- grs_bitmap *tmap;
1206 // -- for (i=0;i<p->num_vertices;i++) vertnum_list[i] = seg->verts[p->verts[i]];
1208 // -- if (p->tmap_num >= NumTextures) {
1209 // -- Warning("Invalid tmap number %d, NumTextures=%d\n...Changing in poly structure to tmap 0",p->tmap_num,NumTextures);
1210 // -- p->tmap_num = 0; //change it permanantly
1213 // -- tmap = Textures[p->tmap_num];
1215 // -- g3_check_and_draw_tmap(p->num_vertices,vertnum_list,(g3s_uvl *) &p->uvls,tmap,&f->normal);
1217 // -- if (Outline_mode) draw_outline(p->num_vertices,vertnum_list);
1223 #define CROSS_WIDTH i2f(8)
1224 #define CROSS_HEIGHT i2f(8)
1228 //draw outline for curside
1229 void outline_seg_side(segment *seg,int _side,int edge,int vert)
1233 cc=rotate_list(8,seg->verts);
1235 if (! cc.and) { //all off screen?
1239 s=&seg->sides[_side];
1241 //render curedge of curside of curseg in green
1243 gr_setcolor(BM_XRGB(0,63,0));
1244 g3_draw_line(&Segment_points[seg->verts[Side_to_verts[_side][edge]]],&Segment_points[seg->verts[Side_to_verts[_side][(edge+1)%4]]]);
1246 //draw a little cross at the current vert
1248 pnt = &Segment_points[seg->verts[Side_to_verts[_side][vert]]];
1250 g3_project_point(pnt); //make sure projected
1252 // gr_setcolor(BM_XRGB(0,0,63));
1253 // gr_line(pnt->p3_sx-CROSS_WIDTH,pnt->p3_sy,pnt->p3_sx+CROSS_WIDTH,pnt->p3_sy);
1254 // gr_line(pnt->p3_sx,pnt->p3_sy-CROSS_HEIGHT,pnt->p3_sx,pnt->p3_sy+CROSS_HEIGHT);
1256 gr_line(pnt->p3_sx-CROSS_WIDTH,pnt->p3_sy,pnt->p3_sx,pnt->p3_sy-CROSS_HEIGHT);
1257 gr_line(pnt->p3_sx,pnt->p3_sy-CROSS_HEIGHT,pnt->p3_sx+CROSS_WIDTH,pnt->p3_sy);
1258 gr_line(pnt->p3_sx+CROSS_WIDTH,pnt->p3_sy,pnt->p3_sx,pnt->p3_sy+CROSS_HEIGHT);
1259 gr_line(pnt->p3_sx,pnt->p3_sy+CROSS_HEIGHT,pnt->p3_sx-CROSS_WIDTH,pnt->p3_sy);
1265 #if 0 //this stuff could probably just be deleted
1267 #define DEFAULT_PERSPECTIVE_DEPTH 6
1269 int Perspective_depth=DEFAULT_PERSPECTIVE_DEPTH; //how many levels deep to render in perspective
1271 int inc_perspective_depth(void)
1273 return ++Perspective_depth;
1277 int dec_perspective_depth(void)
1279 return Perspective_depth==1?Perspective_depth:--Perspective_depth;
1283 int reset_perspective_depth(void)
1285 return Perspective_depth = DEFAULT_PERSPECTIVE_DEPTH;
1290 typedef struct window {
1291 short left,top,right,bot;
1294 ubyte code_window_point(fix x,fix y,window *w)
1298 if (x <= w->left) code |= 1;
1299 if (x >= w->right) code |= 2;
1301 if (y <= w->top) code |= 4;
1302 if (y >= w->bot) code |= 8;
1308 void draw_window_box(int color,short left,short top,short right,short bot)
1314 l=left; t=top; r=right; b=bot;
1316 if ( r<0 || b<0 || l>=grd_curcanv->cv_bitmap.bm_w || (t>=grd_curcanv->cv_bitmap.bm_h && b>=grd_curcanv->cv_bitmap.bm_h))
1321 if (r>=grd_curcanv->cv_bitmap.bm_w) r=grd_curcanv->cv_bitmap.bm_w-1;
1322 if (b>=grd_curcanv->cv_bitmap.bm_h) b=grd_curcanv->cv_bitmap.bm_h-1;
1324 gr_line(i2f(l),i2f(t),i2f(r),i2f(t));
1325 gr_line(i2f(r),i2f(t),i2f(r),i2f(b));
1326 gr_line(i2f(r),i2f(b),i2f(l),i2f(b));
1327 gr_line(i2f(l),i2f(b),i2f(l),i2f(t));
1332 int matt_find_connect_side(int seg0,int seg1);
1335 char visited2[MAX_SEGMENTS];
1338 unsigned char visited[MAX_SEGMENTS];
1339 short Render_list[MAX_RENDER_SEGS];
1340 short Seg_depth[MAX_RENDER_SEGS]; //depth for each seg in Render_list
1341 ubyte processed[MAX_RENDER_SEGS]; //whether each entry has been processed
1342 int lcnt_save,scnt_save;
1343 //@@short *persp_ptr;
1344 short render_pos[MAX_SEGMENTS]; //where in render_list does this segment appear?
1345 //ubyte no_render_flag[MAX_RENDER_SEGS];
1346 window render_windows[MAX_RENDER_SEGS];
1348 short render_obj_list[MAX_RENDER_SEGS+N_EXTRA_OBJ_LISTS][OBJS_PER_SEG];
1354 #define RED BM_XRGB(63,0,0)
1355 #define WHITE BM_XRGB(63,63,63)
1357 //Given two sides of segment, tell the two verts which form the
1359 short Two_sides_to_edge[6][6][2] = {
1360 { {-1,-1}, {3,7}, {-1,-1}, {2,6}, {6,7}, {2,3} },
1361 { {3,7}, {-1,-1}, {0,4}, {-1,-1}, {4,7}, {0,3} },
1362 { {-1,-1}, {0,4}, {-1,-1}, {1,5}, {4,5}, {0,1} },
1363 { {2,6}, {-1,-1}, {1,5}, {-1,-1}, {5,6}, {1,2} },
1364 { {6,7}, {4,7}, {4,5}, {5,6}, {-1,-1}, {-1,-1} },
1365 { {2,3}, {0,3}, {0,1}, {1,2}, {-1,-1}, {-1,-1} }
1368 //given an edge specified by two verts, give the two sides on that edge
1369 int Edge_to_sides[8][8][2] = {
1370 { {-1,-1}, {2,5}, {-1,-1}, {1,5}, {1,2}, {-1,-1}, {-1,-1}, {-1,-1} },
1371 { {2,5}, {-1,-1}, {3,5}, {-1,-1}, {-1,-1}, {2,3}, {-1,-1}, {-1,-1} },
1372 { {-1,-1}, {3,5}, {-1,-1}, {0,5}, {-1,-1}, {-1,-1}, {0,3}, {-1,-1} },
1373 { {1,5}, {-1,-1}, {0,5}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {0,1} },
1374 { {1,2}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {2,4}, {-1,-1}, {1,4} },
1375 { {-1,-1}, {2,3}, {-1,-1}, {-1,-1}, {2,4}, {-1,-1}, {3,4}, {-1,-1} },
1376 { {-1,-1}, {-1,-1}, {0,3}, {-1,-1}, {-1,-1}, {3,4}, {-1,-1}, {0,4} },
1377 { {-1,-1}, {-1,-1}, {-1,-1}, {0,1}, {1,4}, {-1,-1}, {0,4}, {-1,-1} },
1380 //@@//perform simple check on tables
1385 //@@ for (i=0;i<8;i++)
1386 //@@ for (j=0;j<8;j++)
1387 //@@ Assert(Edge_to_sides[i][j][0] == Edge_to_sides[j][i][0] &&
1388 //@@ Edge_to_sides[i][j][1] == Edge_to_sides[j][i][1]);
1390 //@@ for (i=0;i<6;i++)
1391 //@@ for (j=0;j<6;j++)
1392 //@@ Assert(Two_sides_to_edge[i][j][0] == Two_sides_to_edge[j][i][0] &&
1393 //@@ Two_sides_to_edge[i][j][1] == Two_sides_to_edge[j][i][1]);
1399 //given an edge, tell what side is on that edge
1400 int find_seg_side(segment *seg,short *verts,int notside)
1415 for (i=0; i<8; i++) {
1416 int svv = *vp++; // seg->verts[i];
1418 if (vv0==-1 && svv == v0) {
1424 if (vv1==-1 && svv == v1) {
1431 Assert(vv0!=-1 && vv1!=-1);
1433 eptr = Edge_to_sides[vv0][vv1];
1438 Assert(side0!=-1 && side1!=-1);
1440 if (side0 != notside) {
1441 Assert(side1==notside);
1445 Assert(side0==notside);
1451 //find the two segments that join a given seg though two sides, and
1452 //the sides of those segments the abut.
1453 int find_joining_side_norms(vms_vector *norm0_0,vms_vector *norm0_1,vms_vector *norm1_0,vms_vector *norm1_1,vms_vector **pnt0,vms_vector **pnt1,segment *seg,int s0,int s1)
1455 segment *seg0,*seg1;
1456 short edge_verts[2];
1457 int notside0,notside1;
1458 int edgeside0,edgeside1;
1460 Assert(s0!=-1 && s1!=-1);
1462 seg0 = &Segments[seg->children[s0]];
1463 seg1 = &Segments[seg->children[s1]];
1465 edge_verts[0] = seg->verts[Two_sides_to_edge[s0][s1][0]];
1466 edge_verts[1] = seg->verts[Two_sides_to_edge[s0][s1][1]];
1468 Assert(edge_verts[0]!=-1 && edge_verts[1]!=-1);
1470 notside0 = find_connect_side(seg,seg0);
1471 Assert(notside0 != -1);
1472 notside1 = find_connect_side(seg,seg1);
1473 Assert(notside1 != -1);
1475 edgeside0 = find_seg_side(seg0,edge_verts,notside0);
1476 edgeside1 = find_seg_side(seg1,edge_verts,notside1);
1478 //deal with the case where an edge is shared by more than two segments
1480 //@@ if (IS_CHILD(seg0->children[edgeside0])) {
1481 //@@ segment *seg00;
1484 //@@ seg00 = &Segments[seg0->children[edgeside0]];
1486 //@@ if (seg00 != seg1) {
1488 //@@ notside00 = find_connect_side(seg0,seg00);
1489 //@@ Assert(notside00 != -1);
1491 //@@ edgeside0 = find_seg_side(seg00,edge_verts,notside00);
1497 //@@ if (IS_CHILD(seg1->children[edgeside1])) {
1498 //@@ segment *seg11;
1501 //@@ seg11 = &Segments[seg1->children[edgeside1]];
1503 //@@ if (seg11 != seg0) {
1504 //@@ notside11 = find_connect_side(seg1,seg11);
1505 //@@ Assert(notside11 != -1);
1507 //@@ edgeside1 = find_seg_side(seg11,edge_verts,notside11);
1512 // if ( IS_CHILD(seg0->children[edgeside0]) ||
1513 // IS_CHILD(seg1->children[edgeside1]))
1517 get_side_normals(seg0, edgeside0, norm0_0, norm0_1 );
1518 get_side_normals(seg1, edgeside1, norm1_0, norm1_1 );
1520 *norm0_0 = seg0->sides[edgeside0].normals[0];
1521 *norm0_1 = seg0->sides[edgeside0].normals[1];
1522 *norm1_0 = seg1->sides[edgeside1].normals[0];
1523 *norm1_1 = seg1->sides[edgeside1].normals[1];
1526 *pnt0 = &Vertices[seg0->verts[Side_to_verts[edgeside0][seg0->sides[edgeside0].type==3?1:0]]];
1527 *pnt1 = &Vertices[seg1->verts[Side_to_verts[edgeside1][seg1->sides[edgeside1].type==3?1:0]]];
1532 //see if the order matters for these two children.
1533 //returns 0 if order doesn't matter, 1 if c0 before c1, -1 if c1 before c0
1534 int compare_children(segment *seg,short c0,short c1)
1536 vms_vector norm0_0,norm0_1,*pnt0,temp;
1537 vms_vector norm1_0,norm1_1,*pnt1;
1538 fix d0_0,d0_1,d1_0,d1_1,d0,d1;
1541 if (Side_opposite[c0] == c1) return 0;
1543 Assert(c0!=-1 && c1!=-1);
1545 //find normals of adjoining sides
1547 t = find_joining_side_norms(&norm0_0,&norm0_1,&norm1_0,&norm1_1,&pnt0,&pnt1,seg,c0,c1);
1552 vm_vec_sub(&temp,&Viewer_eye,pnt0);
1553 d0_0 = vm_vec_dot(&norm0_0,&temp);
1554 d0_1 = vm_vec_dot(&norm0_1,&temp);
1556 vm_vec_sub(&temp,&Viewer_eye,pnt1);
1557 d1_0 = vm_vec_dot(&norm1_0,&temp);
1558 d1_1 = vm_vec_dot(&norm1_1,&temp);
1560 d0 = (d0_0 < 0 || d0_1 < 0)?-1:1;
1561 d1 = (d1_0 < 0 || d1_1 < 0)?-1:1;
1563 if (d0 < 0 && d1 < 0)
1575 int ssc_total=0,ssc_swaps=0;
1577 //short the children of segment to render in the correct order
1578 //returns non-zero if swaps were made
1579 int sort_seg_children(segment *seg,int n_children,short *child_list)
1583 int made_swaps,count;
1585 if (n_children == 0) return 0;
1589 //for each child, compare with other children and see if order matters
1590 //if order matters, fix if wrong
1597 for (i=0;i<n_children-1;i++)
1598 for (j=i+1;child_list[i]!=-1 && j<n_children;j++)
1599 if (child_list[j]!=-1) {
1600 r = compare_children(seg,child_list[i],child_list[j]);
1603 int temp = child_list[i];
1604 child_list[i] = child_list[j];
1605 child_list[j] = temp;
1610 } while (made_swaps && ++count<n_children);
1618 void add_obj_to_seglist(int objnum,int listnum)
1620 int i,checkn,marker;
1624 //first, find a slot
1626 //mprintf((0,"adding obj %d to %d",objnum,listnum));
1630 for (i=0;render_obj_list[checkn][i] >= 0;i++);
1632 Assert(i < OBJS_PER_SEG);
1634 marker = render_obj_list[checkn][i];
1638 //Assert(checkn < MAX_RENDER_SEGS+N_EXTRA_OBJ_LISTS);
1639 if (checkn >= MAX_RENDER_SEGS+N_EXTRA_OBJ_LISTS) {
1645 } while (marker != -1);
1647 //mprintf((0," slot %d,%d",checkn,i));
1650 //now we have found a slot. put object in it
1652 if (i != OBJS_PER_SEG-1) {
1654 render_obj_list[checkn][i] = objnum;
1655 render_obj_list[checkn][i+1] = -1;
1657 else { //chain to additional list
1660 //find an available sublist
1662 for (lookn=MAX_RENDER_SEGS;render_obj_list[lookn][0]!=-1 && lookn<MAX_RENDER_SEGS+N_EXTRA_OBJ_LISTS;lookn++);
1664 //Assert(lookn<MAX_RENDER_SEGS+N_EXTRA_OBJ_LISTS);
1665 if (lookn >= MAX_RENDER_SEGS+N_EXTRA_OBJ_LISTS) {
1670 render_obj_list[checkn][i] = -lookn;
1671 render_obj_list[lookn][0] = objnum;
1672 render_obj_list[lookn][1] = -1;
1676 //mprintf((0," added!\n"));
1680 #define SORT_LIST_SIZE 100
1682 typedef struct sort_item {
1684 int FLY_TRAP; // padding is a workaround for the solaris qsort bug
1689 int FLY_TRAP2; // padding is a workaround for the solaris qsort bug
1693 sort_item sort_list[SORT_LIST_SIZE];
1696 //compare function for object sort.
1697 int sort_func(const sort_item *a,const sort_item *b)
1700 object *obj_a,*obj_b;
1702 delta_dist = a->dist - b->dist;
1704 obj_a = &Objects[a->objnum];
1705 obj_b = &Objects[b->objnum];
1707 if (abs(delta_dist) < (obj_a->size + obj_b->size)) { //same position
1709 //these two objects are in the same position. see if one is a fireball
1710 //or laser or something that should plot on top. Don't do this for
1711 //the afterburner blobs, though.
1713 if (obj_a->type == OBJ_WEAPON || (obj_a->type == OBJ_FIREBALL && obj_a->id != VCLIP_AFTERBURNER_BLOB))
1714 if (!(obj_b->type == OBJ_WEAPON || obj_b->type == OBJ_FIREBALL))
1715 return -1; //a is weapon, b is not, so say a is closer
1716 else; //both are weapons
1718 if (obj_b->type == OBJ_WEAPON || (obj_b->type == OBJ_FIREBALL && obj_b->id != VCLIP_AFTERBURNER_BLOB))
1719 return 1; //b is weapon, a is not, so say a is farther
1721 //no special case, fall through to normal return
1724 return delta_dist; //return distance
1727 void build_object_lists(int n_segs)
1731 //mprintf((0,"build n_segs=%d",n_segs));
1733 for (nn=0;nn<MAX_RENDER_SEGS+N_EXTRA_OBJ_LISTS;nn++)
1734 render_obj_list[nn][0] = -1;
1736 for (nn=0;nn<n_segs;nn++) {
1739 segnum = Render_list[nn];
1741 //mprintf((0,"nn=%d seg=%d ",nn,segnum));
1747 for (objnum=Segments[segnum].objects;objnum!=-1;objnum = obj->next) {
1748 int new_segnum,did_migrate,list_pos;
1750 obj = &Objects[objnum];
1752 Assert( obj->segnum == segnum );
1754 if (obj->flags & OF_ATTACHED)
1755 continue; //ignore this object
1757 new_segnum = segnum;
1760 //mprintf((0,"objnum=%d ",objnum));
1761 if (obj->type != OBJ_CNTRLCEN && !(obj->type==OBJ_ROBOT && obj->id==65)) //don't migrate controlcen
1767 m = get_seg_masks(&obj->pos,new_segnum,obj->size);
1772 for (sn=0,sf=1;sn<6;sn++,sf<<=1)
1773 if (m.sidemask & sf) {
1774 segment *seg = &Segments[new_segnum];
1776 if (WALL_IS_DOORWAY(seg,sn) & WID_FLY_FLAG) { //can explosion migrate through
1777 int child = seg->children[sn];
1780 for (checknp=list_pos;checknp--;)
1781 if (Render_list[checknp] == child) {
1782 //mprintf((0,"mig from %d to %d ",new_segnum,child));
1791 } while (0); //while (did_migrate);
1793 add_obj_to_seglist(objnum,list_pos);
1800 //mprintf((0,"done build "));
1802 //now that there's a list for each segment, sort the items in those lists
1803 for (nn=0;nn<n_segs;nn++) {
1806 segnum = Render_list[nn];
1808 //mprintf((0,"nn=%d seg=%d ",nn,segnum));
1813 //first count the number of objects & copy into sort list
1816 i = n_sort_items = 0;
1817 while ((t=render_obj_list[lookn][i++])!=-1)
1821 if (n_sort_items < SORT_LIST_SIZE-1) { //add if room
1822 sort_list[n_sort_items].objnum = t;
1823 //NOTE: maybe use depth, not dist - quicker computation
1824 sort_list[n_sort_items].dist = vm_vec_dist_quick(&Objects[t].pos,&Viewer_eye);
1827 else { //no room for object
1831 FILE *tfile=fopen("sortlist.out","wt");
1833 //I find this strange, so I'm going to write out
1834 //some information to look at later
1836 for (ii=0;ii<SORT_LIST_SIZE;ii++) {
1837 int objnum = sort_list[ii].objnum;
1839 fprintf(tfile,"Obj %3d Type = %2d Id = %2d Dist = %08x Segnum = %3d\n",
1840 objnum,Objects[objnum].type,Objects[objnum].id,sort_list[ii].dist,Objects[objnum].segnum);
1846 Int3(); //Get Matt!!!
1848 //Now try to find a place for this object by getting rid
1849 //of an object we don't care about
1851 for (ii=0;ii<SORT_LIST_SIZE;ii++) {
1852 int objnum = sort_list[ii].objnum;
1853 object *obj = &Objects[objnum];
1854 int type = obj->type;
1856 //replace debris & fireballs
1857 if (type == OBJ_DEBRIS || type == OBJ_FIREBALL) {
1858 fix dist = vm_vec_dist_quick(&Objects[t].pos,&Viewer_eye);
1860 //don't replace same kind of object unless new
1863 if (Objects[t].type != type || dist < sort_list[ii].dist) {
1864 sort_list[ii].objnum = t;
1865 sort_list[ii].dist = dist;
1871 Int3(); //still couldn't find a slot
1876 #if defined(__WATCOMC__) || defined(MACINTOSH)
1877 qsort(sort_list,n_sort_items,sizeof(*sort_list),
1880 qsort(sort_list,n_sort_items,sizeof(*sort_list),
1881 (int (*)(const void*,const void*))sort_func);
1884 //now copy back into list
1889 while ((t=render_obj_list[lookn][i])!=-1 && n>0)
1893 render_obj_list[lookn][i++] = sort_list[--n].objnum;
1894 render_obj_list[lookn][i] = -1; //mark (possibly new) end
1899 int Use_player_head_angles = 0;
1900 vms_angvec Player_head_angles;
1902 extern int Num_tmaps_drawn;
1903 extern int Total_pixels;
1904 //--unused-- int Total_num_tmaps_drawn=0;
1907 extern ubyte RenderingType;
1909 void start_lighting_frame(object *viewer);
1912 fix Zoom_factor=F1_0;
1914 //renders onto current canvas
1915 void render_frame(fix eye_offset, int window_num)
1919 #if defined(POLY_ACC)
1920 //$$ not needed for Verite, probably optional for ViRGE. pa_flush();
1923 //Total_num_tmaps_drawn += Num_tmaps_drawn;
1924 //if ((FrameCount > 0) && (Total_num_tmaps_drawn))
1925 // mprintf((0, "Frame: %4i, total = %6i, Avg = %7.3f, Avgpix=%7.3f\n", Num_tmaps_drawn, Total_num_tmaps_drawn, (float) Total_num_tmaps_drawn/FrameCount, (float) Total_pixels/Total_num_tmaps_drawn));
1926 //Num_tmaps_drawn = 0;
1928 if (Endlevel_sequence) {
1929 render_endlevel_frame(eye_offset);
1935 if ( Newdemo_state == ND_STATE_RECORDING && eye_offset >= 0 ) {
1937 // mprintf ((0,"Objnum=%d objtype=%d objid=%d\n",Viewer-Objects,Viewer->type,Viewer->id));
1939 if (RenderingType==0)
1940 newdemo_record_start_frame(FrameCount, FrameTime );
1941 if (RenderingType!=255)
1942 newdemo_record_viewer_object(Viewer);
1948 start_lighting_frame(Viewer); //this is for ugly light-smoothing hack
1952 Viewer_eye = Viewer->pos;
1954 // if (Viewer->type == OBJ_PLAYER && (Cockpit_mode!=CM_REAR_VIEW))
1955 // vm_vec_scale_add2(&Viewer_eye,&Viewer->orient.fvec,(Viewer->size*3)/4);
1958 vm_vec_scale_add2(&Viewer_eye,&Viewer->orient.rvec,eye_offset);
1962 if (Function_mode==FMODE_EDITOR)
1963 Viewer_eye = Viewer->pos;
1966 start_seg_num = find_point_seg(&Viewer_eye,Viewer->segnum);
1968 if (start_seg_num==-1)
1969 start_seg_num = Viewer->segnum;
1971 if (Viewer==ConsoleObject && Use_player_head_angles) {
1972 vms_matrix headm,viewm;
1973 vm_angles_2_matrix(&headm,&Player_head_angles);
1974 vm_matrix_x_matrix(&viewm,&Viewer->orient,&headm);
1975 g3_set_view_matrix(&Viewer_eye,&viewm,Render_zoom);
1976 //@@} else if ((Cockpit_mode==CM_REAR_VIEW) && (Viewer==ConsoleObject)) {
1977 } else if (Rear_view && (Viewer==ConsoleObject)) {
1978 vms_matrix headm,viewm;
1979 Player_head_angles.p = Player_head_angles.b = 0;
1980 Player_head_angles.h = 0x7fff;
1981 vm_angles_2_matrix(&headm,&Player_head_angles);
1982 vm_matrix_x_matrix(&viewm,&Viewer->orient,&headm);
1983 g3_set_view_matrix(&Viewer_eye,&viewm,Render_zoom);
1986 if (keyd_pressed[KEY_RSHIFT] ) {
1987 Zoom_factor += FrameTime*4;
1988 if (Zoom_factor > F1_0*5 ) Zoom_factor=F1_0*5;
1990 Zoom_factor -= FrameTime*4;
1991 if (Zoom_factor < F1_0 ) Zoom_factor = F1_0;
1993 g3_set_view_matrix(&Viewer_eye,&Viewer->orient,fixdiv(Render_zoom,Zoom_factor));
1995 g3_set_view_matrix(&Viewer_eye,&Viewer->orient,Render_zoom);
1999 if (Clear_window == 1) {
2000 if (Clear_window_color == -1)
2001 Clear_window_color = BM_XRGB(0, 0, 0); //BM_XRGB(31, 15, 7);
2002 gr_clear_canvas(Clear_window_color);
2005 if (Show_only_curside)
2006 gr_clear_canvas(Clear_window_color);
2009 render_mine(start_seg_num, eye_offset, window_num);
2011 if (Use_player_head_angles )
2012 draw_3d_reticle(eye_offset);
2018 // -- Moved from here by MK, 05/17/95, wrong if multiple renders/frame! FrameCount++; //we have rendered a frame
2021 int first_terminal_seg;
2023 void update_rendered_data(int window_num, object *viewer, int rear_view_flag, int user)
2025 Assert(window_num < MAX_RENDERED_WINDOWS);
2026 Window_rendered_data[window_num].frame = FrameCount;
2027 Window_rendered_data[window_num].viewer = viewer;
2028 Window_rendered_data[window_num].rear_view = rear_view_flag;
2029 Window_rendered_data[window_num].user = user;
2032 //build a list of segments to be rendered
2033 //fills in Render_list & N_render_segs
2034 void build_segment_list(int start_seg_num, int window_num)
2040 memset(visited, 0, sizeof(visited[0])*(Highest_segment_index+1));
2041 memset(render_pos, -1, sizeof(render_pos[0])*(Highest_segment_index+1));
2042 //memset(no_render_flag, 0, sizeof(no_render_flag[0])*(MAX_RENDER_SEGS));
2043 memset(processed, 0, sizeof(processed));
2046 memset(visited2, 0, sizeof(visited2[0])*(Highest_segment_index+1));
2051 Render_list[lcnt] = start_seg_num; visited[start_seg_num]=1;
2052 Seg_depth[lcnt] = 0;
2055 render_pos[start_seg_num] = 0;
2059 render_segment(start_seg_num, window_num);
2062 render_windows[0].left=render_windows[0].top=0;
2063 render_windows[0].right=grd_curcanv->cv_bitmap.bm_w-1;
2064 render_windows[0].bot=grd_curcanv->cv_bitmap.bm_h-1;
2066 //breadth-first renderer
2070 for (l=0;l<Render_depth;l++) {
2072 //while (scnt < ecnt) {
2073 for (scnt=0;scnt < ecnt;scnt++) {
2076 short child_list[MAX_SIDES_PER_SEGMENT]; //list of ordered sides to process
2077 int n_children; //how many sides in child_list
2080 if (processed[scnt])
2085 segnum = Render_list[scnt];
2086 check_w = &render_windows[scnt];
2090 draw_window_box(RED,check_w->left,check_w->top,check_w->right,check_w->bot);
2093 if (segnum == -1) continue;
2095 seg = &Segments[segnum];
2098 //look at all sides of this segment.
2099 //tricky code to look at sides in correct order follows
2101 for (c=n_children=0;c<MAX_SIDES_PER_SEGMENT;c++) { //build list of sides
2104 wid = WALL_IS_DOORWAY(seg, c);
2106 ch=seg->children[c];
2108 if ( (window_check || !visited[ch]) && (wid & WID_RENDPAST_FLAG) ) {
2110 byte *sv = Side_to_verts[c];
2111 ubyte codes_and=0xff;
2114 rotate_list(8,seg->verts);
2118 codes_and &= Segment_points[seg->verts[sv[i]]].p3_codes;
2120 if (codes_and & CC_BEHIND) continue;
2123 child_list[n_children++] = c;
2127 //now order the sides in some magical way
2129 if (new_seg_sorting)
2130 sort_seg_children(seg,n_children,child_list);
2132 //for (c=0;c<MAX_SIDES_PER_SEGMENT;c++) {
2133 // ch=seg->children[c];
2135 for (c=0;c<n_children;c++) {
2138 siden = child_list[c];
2139 ch=seg->children[siden];
2140 //if ( (window_check || !visited[ch])&& (WALL_IS_DOORWAY(seg, c))) {
2144 ubyte codes_and_3d,codes_and_2d;
2145 short _x,_y,min_x=32767,max_x=-32767,min_y=32767,max_y=-32767;
2146 int no_proj_flag=0; //a point wasn't projected
2150 rotate_list(8,seg->verts);
2151 project_list(8,seg->verts);
2155 for (i=0,codes_and_3d=codes_and_2d=0xff;i<4;i++) {
2156 int p = seg->verts[Side_to_verts[siden][i]];
2157 g3s_point *pnt = &Segment_points[p];
2159 if (! (pnt->p3_flags&PF_PROJECTED)) {no_proj_flag=1; break;}
2161 _x = f2i(pnt->p3_sx);
2162 _y = f2i(pnt->p3_sy);
2164 codes_and_3d &= pnt->p3_codes;
2165 codes_and_2d &= code_window_point(_x,_y,check_w);
2169 gr_setcolor(BM_XRGB(31,0,31));
2170 gr_line(pnt->p3_sx,pnt->p3_sy,
2171 Segment_points[seg->verts[Side_to_verts[siden][(i+1)%4]]].p3_sx,
2172 Segment_points[seg->verts[Side_to_verts[siden][(i+1)%4]]].p3_sy);
2176 if (_x < min_x) min_x = _x;
2177 if (_x > max_x) max_x = _x;
2179 if (_y < min_y) min_y = _y;
2180 if (_y > max_y) max_y = _y;
2186 draw_window_box(WHITE,min_x,min_y,max_x,max_y);
2189 if (no_proj_flag || (!codes_and_3d && !codes_and_2d)) { //maybe add this segment
2190 int rp = render_pos[ch];
2191 window *new_w = &render_windows[lcnt];
2193 if (no_proj_flag) *new_w = *check_w;
2195 new_w->left = max(check_w->left,min_x);
2196 new_w->right = min(check_w->right,max_x);
2197 new_w->top = max(check_w->top,min_y);
2198 new_w->bot = min(check_w->bot,max_y);
2201 //see if this seg already visited, and if so, does current window
2202 //expand the old window?
2204 if (new_w->left < render_windows[rp].left ||
2205 new_w->top < render_windows[rp].top ||
2206 new_w->right > render_windows[rp].right ||
2207 new_w->bot > render_windows[rp].bot) {
2209 new_w->left = min(new_w->left,render_windows[rp].left);
2210 new_w->right = max(new_w->right,render_windows[rp].right);
2211 new_w->top = min(new_w->top,render_windows[rp].top);
2212 new_w->bot = max(new_w->bot,render_windows[rp].bot);
2214 if (no_migrate_segs) {
2215 //no_render_flag[lcnt] = 1;
2216 Render_list[lcnt] = -1;
2217 render_windows[rp] = *new_w; //get updated window
2218 processed[rp] = 0; //force reprocess
2229 draw_window_box(5,new_w->left,new_w->top,new_w->right,new_w->bot);
2232 render_pos[ch] = lcnt;
2233 Render_list[lcnt] = ch;
2234 Seg_depth[lcnt] = l;
2236 if (lcnt >= MAX_RENDER_SEGS) {mprintf((0,"Too many segs in render list!!\n")); goto done_list;}
2241 render_segment(ch, window_num);
2249 Render_list[lcnt] = ch;
2250 Seg_depth[lcnt] = l;
2252 if (lcnt >= MAX_RENDER_SEGS) {mprintf((0,"Too many segs in render list!!\n")); goto done_list;}
2268 first_terminal_seg = scnt;
2269 N_render_segs = lcnt;
2273 //renders onto current canvas
2274 void render_mine(int start_seg_num,fix eye_offset, int window_num)
2281 // Initialize number of objects (actually, robots!) rendered this frame.
2282 Window_rendered_data[window_num].num_objects = 0;
2289 for (i=0;i<=Highest_object_index;i++)
2290 object_rendered[i] = 0;
2293 //set up for rendering
2295 render_start_frame();
2298 #if defined(EDITOR) && !defined(NDEUBG)
2299 if (Show_only_curside) {
2300 rotate_list(8,Cursegp->verts);
2301 render_side(Cursegp,Curside);
2302 goto done_rendering;
2314 //NOTE LINK TO ABOVE!!
2315 build_segment_list(start_seg_num, window_num); //fills in Render_list & N_render_segs
2320 if (!window_check) {
2321 Window_clip_left = Window_clip_top = 0;
2322 Window_clip_right = grd_curcanv->cv_bitmap.bm_w-1;
2323 Window_clip_bot = grd_curcanv->cv_bitmap.bm_h-1;
2328 if (!(_search_mode)) {
2331 for (i=0;i<N_render_segs;i++) {
2334 segnum = Render_list[i];
2338 if (visited2[segnum])
2341 visited2[segnum] = 1;
2347 if (!(_search_mode))
2348 build_object_lists(N_render_segs);
2350 if (eye_offset<=0) // Do for left eye or zero.
2351 set_dynamic_light();
2353 if (!_search_mode && Clear_window == 2) {
2354 if (first_terminal_seg < N_render_segs) {
2357 if (Clear_window_color == -1)
2358 Clear_window_color = BM_XRGB(0, 0, 0); //BM_XRGB(31, 15, 7);
2360 gr_setcolor(Clear_window_color);
2362 for (i=first_terminal_seg; i<N_render_segs; i++) {
2363 if (Render_list[i] != -1) {
2365 if ((render_windows[i].left == -1) || (render_windows[i].top == -1) || (render_windows[i].right == -1) || (render_windows[i].bot == -1))
2369 //NOTE LINK TO ABOVE!
2370 gr_rect(render_windows[i].left, render_windows[i].top, render_windows[i].right, render_windows[i].bot);
2376 for (nn=N_render_segs;nn--;) {
2380 // Interpolation_method = 0;
2381 segnum = Render_list[nn];
2382 Current_seg_depth = Seg_depth[nn];
2384 //if (!no_render_flag[nn])
2385 if (segnum!=-1 && (_search_mode || visited[segnum]!=255)) {
2386 //set global render window vars
2389 Window_clip_left = render_windows[nn].left;
2390 Window_clip_top = render_windows[nn].top;
2391 Window_clip_right = render_windows[nn].right;
2392 Window_clip_bot = render_windows[nn].bot;
2395 //mprintf((0," %d",segnum));
2397 render_segment(segnum, window_num);
2398 visited[segnum]=255;
2400 if (window_check) { //reset for objects
2401 Window_clip_left = Window_clip_top = 0;
2402 Window_clip_right = grd_curcanv->cv_bitmap.bm_w-1;
2403 Window_clip_bot = grd_curcanv->cv_bitmap.bm_h-1;
2406 if (migrate_objects) {
2407 //int n_expl_objs=0,expl_objs[5],i;
2409 int save_linear_depth = Max_linear_depth;
2411 Max_linear_depth = Max_linear_depth_objects;
2415 //mprintf((0,"render objs seg %d",segnum));
2417 for (objnp=0;render_obj_list[listnum][objnp]!=-1;) {
2418 int ObjNumber = render_obj_list[listnum][objnp];
2420 if (ObjNumber >= 0) {
2422 //mprintf( (0, "Type: %d\n", Objects[ObjNumber].type ));
2424 //if (Objects[ObjNumber].type == OBJ_FIREBALL && n_expl_objs<5) {
2425 // expl_objs[n_expl_objs++] = ObjNumber;
2428 if ( (Objects[ObjNumber].type==OBJ_WEAPON) && //if its a weapon
2429 (Objects[ObjNumber].lifeleft==Laser_max_time ) && // and its in it's first frame
2430 (Hack_nlasers< MAX_HACKED_LASERS) && // and we have space for it
2431 (Objects[ObjNumber].laser_info.parent_num>-1) && // and it has a parent
2432 ((Viewer-Objects)==Objects[ObjNumber].laser_info.parent_num) // and it's parent is the viewer
2434 Hack_laser_list[Hack_nlasers++] = ObjNumber; //then make it draw after everything else.
2435 //mprintf( (0, "O%d ", ObjNumber ));
2438 do_render_object(ObjNumber, window_num); // note link to above else
2444 listnum = -ObjNumber;
2451 //for (i=0;i<n_expl_objs;i++)
2452 // do_render_object(expl_objs[i], window_num);
2454 //mprintf((0,"done seg %d\n",segnum));
2456 Max_linear_depth = save_linear_depth;
2463 //mprintf((0,"\n"));
2467 // Draw the hacked lasers last
2468 for (i=0; i < Hack_nlasers; i++ ) {
2469 //mprintf( (0, "D%d ", Hack_laser_list[i] ));
2470 do_render_object(Hack_laser_list[i], window_num);
2474 // -- commented out by mk on 09/14/94...did i do a good thing?? object_render_targets();
2478 //draw curedge stuff
2479 if (Outline_mode) outline_seg_side(Cursegp,Curside,Curedge,Curvert);
2490 extern int render_3d_in_big_window;
2492 //finds what segment is at a given x&y - seg,side,face are filled in
2493 //works on last frame rendered. returns true if found
2494 //if seg<0, then an object was found, and the object number is -seg-1
2495 int find_seg_side_face(short x,short y,int *seg,int *side,int *face,int *poly)
2499 _search_x = x; _search_y = y;
2503 if (render_3d_in_big_window) {
2504 grs_canvas temp_canvas;
2506 gr_init_sub_canvas(&temp_canvas,canv_offscreen,0,0,
2507 LargeView.ev_canv->cv_bitmap.bm_w,LargeView.ev_canv->cv_bitmap.bm_h);
2509 gr_set_current_canvas(&temp_canvas);
2514 gr_set_current_canvas(&VR_render_sub_buffer[0]); //render off-screen
2525 // mprintf((0,"found seg=%d, side=%d, face=%d, poly=%d\n",found_seg,found_side,found_face,found_poly));
2527 return (found_seg!=-1);