summaryrefslogtreecommitdiff
path: root/3dc/win95/item.c
blob: af4edef0535f8a3f9296915fd0133c8cdcf0d783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

#include "3dc.h"
#include "module.h"
#include "inline.h"
#include "krender.h" /* KJL 11:37:53 12/05/96 - new scandraws patch */

/* KJL 15:02:50 05/14/97 - new max lighting intensity */
#define MAX_INTENSITY (65536*4-1)


#if StandardShapeLanguage


#define UseLocalAssert Yes

#include "ourasert.h"

/*
  The outputclockwise compile option has been
  maintained in case anyone wants to use the existing
  triangle array code with counterclockwise ordering.
  In the case of Win95, we might want to this if we can ever
  persuade the Direct3D rasterisation module to come up
  with CULL_CCW set. Note that outputtriangles has now been purged
  from the system.
*/

#define outputclockwise Yes

#define use_div_fixed	Yes

#define trip_debugger No

#if trip_debugger
int testa = 0;
int testb = 100;
int testc = 0;
#endif

/*
	To make scan draws work backwards as
	well as forwards, i.e. to cope with
    items that would be backface culled
	without the no cull flag set, as in racing
	game TLOs.
	This should now work for all polygon types.
*/

#define ReverseDraws Yes

/*
	To optimise scan draws with local variables
	explicitly braced to improve compiler
	optimisation.
    NOTE THIS IS -->ONLY<-- IMPLEMENTED FOR
	VIDEOMODETYPE_8, 2DTEXTURE, 3DTEXTURE (LINEAR)
	AND 3DTEXTURE (LINEAR_S) AT PRESENT.
	AND NOT ALL THE OPTIONS INSIDE THOSE!!!
	NOTE ALSO THAT THIS APPEARS TO PRODUCE BAD CODE
	WITH WATCOM 10.0 AND -oeitlr, BUT WE HOPE IT WILL
	WORK WITH WATCOM 10.6
	-->CRASHES, AS IT HAPPENS!!!<--
*/
/*
	Prototypes
*/



/*

 externs for commonly used global variables and arrays

*/

	extern int VideoModeType;
	extern int VideoModeTypeScreen;
	extern int ScanDrawMode;
	extern int **ShadingTableArray;
	extern unsigned char **PaletteShadingTableArray;
	extern VIEWDESCRIPTORBLOCK *Global_VDB_Ptr;
	extern unsigned char *ScreenBuffer;



	extern IMAGEHEADER *ImageHeaderPtrs[MaxImages];
	extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
	extern long BackBufferPitch;

    /* For multiple execute buffers */
	extern int NumVertices;


#endif /* for support3dtextures */

/*

 Global Variables

*/


//	int *ItemPointers[maxpolyptrs];

//	int ItemData[maxpolys * avgpolysize];


	int **NextFreeItemPtr;
	int *NextFreeItemData;

	int NumFreeItemPtrs;
	int NumFreeItemData;

	int ItemCount;							/* Instead of a Terminator */

	POLYHEADER *global_pheader;

	int MIP_Index;

/*

 Global Variables For Scan Convertors

*/

	int ScanData[maxpolys*maxscansize];
	int *NextFreeScanData;
	int NumFreeScanData;
	int NumScans;

   
	int NumPolyPts;



/*

 Item Data Structures.

 Buffer Initialisation and Allocation Functions.

*/




/*
	John and Neal's code
	Note this is only experimental, for the interface engine,
	and therefore does not go through the standard scan draw
	function array!!!  Also, it only works in VideoModeType_8!!!
	USE AT YOUR PERIL!!!!
*/

void Draw_Line_VMType_8(VECTOR2D* LineStart, VECTOR2D* LineEnd, int LineColour)
{
	int gosa, tame, hani, dire;
	int w, x, y;
	int x1, y1, x2, y2;
	unsigned char *sbufferptr;
	unsigned char colour = LineColour;

	x1 = LineStart->vx;
	y1 = LineStart->vy;
	x2 = LineEnd->vx;
	y2 = LineEnd->vy;

	x1=max(x1,Global_VDB_Ptr->VDB_ClipLeft);
	x1=min(x1,Global_VDB_Ptr->VDB_ClipRight-1);
	x2=max(x2,Global_VDB_Ptr->VDB_ClipLeft);
	x2=min(x2,Global_VDB_Ptr->VDB_ClipRight-1);

	y1=max(y1,Global_VDB_Ptr->VDB_ClipUp);
	y1=min(y1,Global_VDB_Ptr->VDB_ClipDown-1);
	y2=max(y2,Global_VDB_Ptr->VDB_ClipUp);
	y2=min(y2,Global_VDB_Ptr->VDB_ClipDown-1);

	if( abs( x2 - x1 ) < abs( y2 - y1 ) ) {
		if( y2 < y1 ) {
			w = y1;
			y1 = y2;
			y2 = w;
			w = x1;
			x1 = x2;
			x2 = w;
		}
		dire = x1 < x2 ? 1 : -1;
		gosa = abs( x2 - x1 );
		hani = y2 - y1;
		tame = hani / 2;
		x = x1;
		for( y = y1; y <= y2; y++ ) {
			sbufferptr =
				ScreenBuffer +
				(y * BackBufferPitch) + x;
			*sbufferptr = colour;
			tame += gosa;
			if( tame > hani ) {
				x += dire;
				tame -= hani;
			}
		}
	} else {
		if( x2 < x1 ) {
			w = x1;
			x1 = x2;
			x2 = w;
			w = y1;
			y1 = y2;
			y2 = w;
		}
		dire = y1 < y2 ? 1 : -1;
		gosa = abs( y2 - y1 );
		hani = x2 - x1;
		tame = hani / 2;
		y = y1;
		for( x = x1; x <= x2; x++ ) {
			sbufferptr =
				ScreenBuffer +
				(y * BackBufferPitch) + x;
			*sbufferptr = colour;
			tame += gosa;
			if( tame > hani ) {
				y += dire;
				tame -= hani;
			}
		}
	}

}



/*

 Scan Convert and Draw I_GouraudPolygon

*/


void Draw_Item_GouraudPolygon(int *itemptr)
{
	if (ScanDrawMode == ScanDrawDirectDraw)
   	{
   		KDraw_Item_GouraudPolygon(itemptr);
	}
}


void Draw_Item_2dTexturePolygon(int *itemptr)
{
	if (ScanDrawMode == ScanDrawDirectDraw)
    {
		KDraw_Item_2dTexturePolygon(itemptr);
	}
}

void Draw_Item_Gouraud2dTexturePolygon(int *itemptr)
{
	if (ScanDrawMode == ScanDrawDirectDraw)
	{
		KDraw_Item_Gouraud2dTexturePolygon(itemptr);
	}
}

void Draw_Item_Gouraud3dTexturePolygon(int *itemptr)
{
	if (ScanDrawMode == ScanDrawDirectDraw)
	{
		KDraw_Item_Gouraud3dTexturePolygon(itemptr);
	}
}

void Draw_Item_ZB_Gouraud3dTexturePolygon(int *itemptr)
{
}

void Draw_Item_ZB_GouraudPolygon(int *itemptr)
{
}


void Draw_Item_ZB_2dTexturePolygon(int *itemptr)
{
}


void Draw_Item_ZB_Gouraud2dTexturePolygon(int *itemptr)
{
}



void Draw_Item_ZB_3dTexturedPolygon(int *itemptr)
{
}