diff --git a/src/avp/avpview.c b/src/avp/avpview.c index 08053dd..8de8435 100644 --- a/src/avp/avpview.c +++ b/src/avp/avpview.c @@ -11,7 +11,6 @@ #include "kshape.h" #include "kzsort.h" #include "frustum.h" -#include "krender.h" #include "vision.h" #include "lighting.h" #include "weapons.h" diff --git a/src/avp/game.c b/src/avp/game.c index 11a12eb..6090860 100644 --- a/src/avp/game.c +++ b/src/avp/game.c @@ -42,7 +42,6 @@ #include "pldnet.h" #include "kshape.h" -#include "krender.h" /* KJL 16:00:13 11/22/96 - One of my evil experiments.... */ #define PENTIUM_PROFILING_ON 0 diff --git a/src/avp/pmove.c b/src/avp/pmove.c index 24ed9b6..bed657a 100644 --- a/src/avp/pmove.c +++ b/src/avp/pmove.c @@ -32,7 +32,6 @@ #include "equipmnt.h" #include "bh_agun.h" #include "los.h" -#include "krender.h" #include "pldnet.h" #include "bonusabilities.h" #include "avp_menus.h" diff --git a/src/avp/win95/cheat.c b/src/avp/win95/cheat.c index 5754594..bdaebd5 100644 --- a/src/avp/win95/cheat.c +++ b/src/avp/win95/cheat.c @@ -8,7 +8,6 @@ #include "gameplat.h" #include "bh_types.h" -#include "krender.h" #include "huddefs.h" #include "language.h" #include "cheat.h" diff --git a/src/avp/win95/ddplat.cpp b/src/avp/win95/ddplat.cpp index e82cd5e..9c261d9 100644 --- a/src/avp/win95/ddplat.cpp +++ b/src/avp/win95/ddplat.cpp @@ -22,7 +22,6 @@ extern "C" { #include "font.h" #include "kshape.h" -#include "krender.h" #include "chnktexi.h" #include "awtexld.h" #include "ffstdio.h" diff --git a/src/avp/win95/dx_proj.cpp b/src/avp/win95/dx_proj.cpp deleted file mode 100644 index b01db10..0000000 --- a/src/avp/win95/dx_proj.cpp +++ /dev/null @@ -1,710 +0,0 @@ -// Project specific parts of the Win95 DirectX system, -// largely concerned with the rules for selecting a driver, -// draw mode, memory mode etc during system initialisation, which -// cannot readily be decided at a project independent level. - -// Must link to C code in main engine system - -// Note that TestInitD3DObject is called during InitialiseSystem, immediately -// after initialisation of the basic DirectDraw object. It is normally used -// to detect the hardware acceleration capabilities of a system, by creating a Direct3D -// object which is then collapsed again, so that the information can be passed to e.g. -// menu software to provide recommended options. The video mode can potentially -// be rewritten here, so that a 320x200x8 request mode is interpreted as e.g. 640x480x15 -// if hardware acceleration is detected and it is decided that it will be used. - -// Note that the ProcessorType global should be valid at this stage. - - -// TestMemoryAccess is run immediately after TestInitD3DObject in InitialiseSystem, -// and is used to determine whether the back buffer should be in system or video memory. -// Note that if you intend to use MMX scan draws the back buffer should be in system memory, -// if you are running with hardware accelerated draws it MUST be in video memory, and otherwise -// I would recommend video memory except in extreme circumstances (i.e. very old video cards -// with very slow VRAM access). Note that whether or not we will boot on hardware should have been -// decided by this stage. - -// NOTE THAT THE REQUESTSYSTEMMEMORYALWAYS OPTION IS A DEBUGGING FEATURE, SINCE THE WATCOM -// DEBUGGER CAN ONLY BE USED ON FUNCTIOSN WITHIN DRAWITEMLISTCONTENTS ETC IF THE RENDERING -// TARGET IS IN SYSTEM MEMORY AND THE SYSTEM DOES NOT HAVE TO TAKE A WIN16 LOCK TO -// REACH THE SURFACE. THIS REQUEST MODE OPTION REPLACES FORCEBUFFERSINTOSYSTEMMEMORY, WHICH -// WAS AT THE TOP OF DD_FUNC.CPP - -// SelectD3DDriverAndDrawMode is the final selection function for hardware acceleration, z buffering -// etc, run during SetVideoMode from InitialiseDirect3DImmediateMode. Note that your target video -// mode must have been selected before you enter this routine. This routine is separate so that a call -// to ChangeDisplayModes (in io.c) can be used to change the video mode, driver etc. - -// NOTE: USE OF CHANGEDISPLAYMODES MUST BE INTEGRATED WITH USE OF THE CHUNK SYSTEM, SINCE IT WILL -// REQUIRE A TEXTURE RELOAD AND PROBABLY A SHAPE RELOAD. - -// NOTE: IF YOU INTEND TO LET THE USER OVERRIDE VIDEO MODE, DRIVER ETC SETTINGS FROM MENUS RUN -// (UNAVOIDABLY, I SUSPECT) AFTER INITIALISESYSTEM, YOU MUST CALL SETVIDEOMODE BEFORE THE MENUS -// IF YOU WANT THEM TO BE DISPLAYED USING ENGINE (DIRECTX) FUNCTIONS AND THEN CALL CHANGEDISPLAYMODES -// TO CHANGE THE MODES TO THE FINAL ONES. DO NOT CALL SETVIDEOMODE TWICE DURING A SINGLE PROGRAM RUN. -// CHANGEDISPLAYMODES WILL CALL YOUR VERSION OF SELECTD3DDRIVERANDDRAWMODE FOR YOU, BUT TESTMEMORYACCESS -// AND TESTINITD3DOBJECT WILL NOT BE CALLED AGAIN. IF YOU WANT TO RESELECT THE MEMORY MODE OR RETEST -// HARDWARE ACCELERATION CAPABILITIES, YOU MUST DO IT YOURSELF IN THE MENUS SYSTEM. - -// NOTE: TO CHANGE PALETTE IN A PALETTISED MODE, CALL CHANGEPALETTE IN IO.C, NOT CHANGEDISPLAYMODES. - -extern "C" { - -#include "system.h" -#include "equates.h" -#include "platform.h" -#include "shape.h" -#include "prototyp.h" -#include "inline.h" - -#include "d3_func.h" -#include "d3dmacs.h" - -extern "C++" -{ -#include "pcmenus.h" -}; - -#include "dxlog.h" - -// Tell system to prefer palettised formats -// for textures. The alternative is to prefer -// non-palettised modes. -// Note that non-palettised modes certainly seem -// to look better on the software RGB driver, anyway, -// leading me to suspect that my runtime ppm quantiser -// is, ahem, less than totally perfect... -#define PreferPalettisedTextures Yes - -// Test hack to force driver zero (mono -// rather than RGB), plus others. Should -// all be No in theory. Turn on only one -// at a time!!! -#define ForceRampDriver No -#define ForceRGBDriver No -#define ForceHardwareDriver No -#define ForceDirectDraw No - -// Externs - -extern int VideoMode; -extern int VideoModeColourDepth; -extern int WindowMode; -extern int DrawMode; -extern int ScanDrawMode; -extern int ZBufferMode; -extern int DXMemoryMode; -extern int DXMemoryRequestMode; -extern int ZBufferRequestMode; -extern int RasterisationRequestMode; -extern int SoftwareScanDrawRequestMode; -extern int D3DDriverMode; -extern BOOL D3DHardwareAvailable; -extern D3DINFO d3d; -extern int StartDriver; -extern int StartFormat; -extern HRESULT LastError; -extern BOOL MMXAvailable; -extern LPDIRECTDRAW lpDD; - -// Globals -// Test only!!! -int TestHw = No; - - -// Callback function to enumerate texture -// formats available on the current D3D -// driver. Obviously this should be run -// AFTER the driver callback, and after -// a driver has been selected. -// A palette will be picked as the default -// (with preference given to palettized -// formats) and returned via the lpContext. - -HRESULT CALLBACK TextureFormatsEnumerator - (LPDDSURFACEDESC lpDDSD, LPVOID lpContext) -{ - unsigned long m; - int r, g, b; - int *lpStartFormat = (int*) lpContext; - - /* - Record the DDSURFACEDESC of this texture format - */ - - memset(&d3d.TextureFormat[d3d.NumTextureFormats], 0, - sizeof(D3DTEXTUREFORMAT)); - memcpy(&d3d.TextureFormat[d3d.NumTextureFormats].ddsd, - lpDDSD, sizeof(DDSURFACEDESC)); - - /* - Is this format palettized? How many bits? Otherwise, how many RGB - bits? - */ - - if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) - { - d3d.TextureFormat[d3d.NumTextureFormats].Palette = Yes; - d3d.TextureFormat[d3d.NumTextureFormats].IndexBPP = 8; - } - else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4) - { - d3d.TextureFormat[d3d.NumTextureFormats].Palette = Yes; - d3d.TextureFormat[d3d.NumTextureFormats].IndexBPP = 4; - } - else if (lpDDSD->ddpfPixelFormat.dwFlags & (DDPF_ALPHA|DDPF_ALPHAPIXELS|DDPF_FOURCC)) - { - return DDENUMRET_OK; - } - else if (lpDDSD->ddpfPixelFormat.dwFlags & DDPF_RGB) - { - // This bit is all fiendishly cunning, Dr Tringham, - // but one has to wonder if it actually, as such, - // works... - d3d.TextureFormat[d3d.NumTextureFormats].Palette = No; - d3d.TextureFormat[d3d.NumTextureFormats].IndexBPP = 0; - for (r = 0, m = lpDDSD->ddpfPixelFormat.dwRBitMask; - !(m & 1); r++, m >>= 1); - for (r = 0; m & 1; r++, m >>= 1); - for (g = 0, m = lpDDSD->ddpfPixelFormat.dwGBitMask; - !(m & 1); g++, m >>= 1); - for (g = 0; m & 1; g++, m >>= 1); - for (b = 0, m = lpDDSD->ddpfPixelFormat.dwBBitMask; - !(m & 1); b++, m >>= 1); - for (b = 0; m & 1; b++, m >>= 1); - d3d.TextureFormat[d3d.NumTextureFormats].RedBPP = r; - d3d.TextureFormat[d3d.NumTextureFormats].GreenBPP = g; - d3d.TextureFormat[d3d.NumTextureFormats].BlueBPP = b; - } - else - { - return DDENUMRET_OK; - } - - /* - If lpStartFormat is -1, this is the first format. - Select it. - */ - - if (*lpStartFormat == -1) - *lpStartFormat = d3d.NumTextureFormats; - else - { - if (PreferTextureFormat(&d3d.TextureFormat[*lpStartFormat],&d3d.TextureFormat[d3d.NumTextureFormats])) - *lpStartFormat = d3d.NumTextureFormats; - } - - d3d.NumTextureFormats++; - return DDENUMRET_OK; -} - - -// Code to pick a driver and scan draw mode -// based on what hardware is present on the -// system and the current request modes -// (specified by default in the InitialVideoMode -// call). -// The basic rules are that a hardware driver will -// always be picked if one is available unless -// software only rasterisation has been requested, -// in which case we will get a software driver anyway, -// and that hardware rgb scan draws will be picked if -// we are running on hardware, but otherwise the ramp -// software scan draw mode will be picked unless DirectDraw -// scan draws have been specifically requested. - -// Note that since rewrites to the VideoMode really ought -// to be done BEFORE SetVideoMode is run, this function's -// effects must be combined with those of -// InitialiseDirectDrawObject and TestInitD3DObject!!!! - -void SelectD3DDriverAndDrawMode(void) - -{ -// Note that if we have requested default rasterisation and hw is -// available, we may want to pick the software RGB driver if MMXAvailable -// is Yes!!! Fix later!!! - if ((D3DHardwareAvailable) - && (RasterisationRequestMode != RequestSoftwareRasterisation)) - { - int i=0; - BOOL EarlyExit = No; - - do - { - if (d3d.Driver[i].Hardware) - { - d3d.CurrentDriver = i; - EarlyExit = Yes; - } - } - while ((++i < d3d.NumDrivers) && !EarlyExit); - - D3DDriverMode = D3DHardwareRGBDriver; - ScanDrawMode = ScanDrawD3DHardwareRGB; - } -// Note that we may want to select the software RGB driver if default scan -// draws have been requested, should MMXAvailable be Yes... - else if (SoftwareScanDrawRequestMode == RequestScanDrawSoftwareRGB) - { - int i=0; - BOOL EarlyExit = No; - - do - { - if ((!d3d.Driver[i].Hardware) && - (d3d.Driver[i].Desc.dcmColorModel == D3DCOLOR_RGB)) - { - d3d.CurrentDriver = i; - EarlyExit = Yes; - } - } - while ((++i < d3d.NumDrivers) && !EarlyExit); - - D3DDriverMode = D3DSoftwareRGBDriver; - ScanDrawMode = ScanDrawD3DSoftwareRGB; - } -// Note that once everything, like, works, and Microsoft's code -// is dead fast and doesn't crash or anything, the default software -// scan draw mode should be changed from DirectDraw to Ramp. -// Probably. - else if (SoftwareScanDrawRequestMode == RequestScanDrawRamp) - { - int i=0; - BOOL EarlyExit = No; - - do - { - if ((!d3d.Driver[i].Hardware) && - (d3d.Driver[i].Desc.dcmColorModel == D3DCOLOR_MONO)) - { - d3d.CurrentDriver = i; - EarlyExit = Yes; - } - } - while ((++i < d3d.NumDrivers) && !EarlyExit); - - D3DDriverMode = D3DSoftwareRampDriver; - ScanDrawMode = ScanDrawD3DRamp; - } - else if ((SoftwareScanDrawRequestMode == RequestScanDrawDirectDraw) - || (SoftwareScanDrawRequestMode == RequestScanDrawDefault)) - { - int i=0; - BOOL EarlyExit = No; - - // Set ramp driver anyway for convenience - do - { - if ((!d3d.Driver[i].Hardware) && - (d3d.Driver[i].Desc.dcmColorModel == D3DCOLOR_MONO)) - { - d3d.CurrentDriver = i; - EarlyExit = Yes; - } - } - while ((++i < d3d.NumDrivers) && !EarlyExit); - - D3DDriverMode = D3DSoftwareRampDriver; - ScanDrawMode = ScanDrawDirectDraw; - } - else // bollocks - { - ReleaseDirect3D(); - exit(0xdeaf); - } - - #if SupportZBuffering - if (ZBufferRequestMode == RequestZBufferAlways) - { - if (d3d.Driver[d3d.CurrentDriver].ZBuffer) - ZBufferMode = ZBufferOn; - else - ZBufferMode = ZBufferOff; - } - else if (ZBufferRequestMode == RequestZBufferDefault) - { - if ((d3d.Driver[d3d.CurrentDriver].ZBuffer) - && (d3d.Driver[d3d.CurrentDriver].Hardware)) - ZBufferMode = ZBufferOn; - else - ZBufferMode = ZBufferOff; - } - else - ZBufferMode = ZBufferOff; - #endif - - - // Overrides for test purposes only - - #if ForceRampDriver - d3d.CurrentDriver = 0; - D3DDriverMode = D3DSoftwareRampDriver; - ScanDrawMode = ScanDrawD3DRamp; - #endif - - #if ForceRGBDriver - d3d.CurrentDriver = 1; - D3DDriverMode = D3DSoftwareRGBDriver; - ScanDrawMode = ScanDrawD3DSoftwareRGB; - #endif - - #if ForceHardwareDriver - d3d.CurrentDriver = 2; - D3DDriverMode = D3DHardwareRGBDriver; - ScanDrawMode = ScanDrawD3DHardwareRGB; - #endif - - #if ForceDirectDraw - d3d.CurrentDriver = 0; - D3DDriverMode = D3DSoftwareRampDriver; - ScanDrawMode = ScanDrawDirectDraw; - #endif - -} - -#if SUPPORT_MMX -int use_mmx_math; -void SelectMMXOptions(void) -{ - if (MMXAvailable) - use_mmx_math = 1; - else - use_mmx_math = 0; -} -#endif - -// Initialise temporary D3D object and then destroy -// it again, SOLELY for the purpose of determining -// whether hardware acceleration is available - -// NOTE THIS -->MUST<-- BE RUN -->AFTER<-- -// InitialiseDirectDrawObject!!! - -BOOL TestInitD3DObject(void) -{ - // Zero hardware available global - D3DHardwareAvailable = No; - -// Zero d3d structure - memset(&d3d, 0, sizeof(D3DINFO)); - -// Set up Direct3D interface object - LastError = lpDD->QueryInterface(IID_IDirect3D, (LPVOID*) &d3d.lpD3D); - - if (LastError != DD_OK) - return FALSE; - -// Use callback function to enumerate available devices on system -// and acquire device GUIDs etc - - LastError = d3d.lpD3D->EnumDevices(DeviceEnumerator, (LPVOID)&StartDriver); - - if (LastError != D3D_OK) - return FALSE; - - // select the usual driver - get its description - int old_rrm = RasterisationRequestMode; - RasterisationRequestMode = RequestDefaultRasterisation; - SelectD3DDriverAndDrawMode(); - d3d.ThisDriver = d3d.Driver[d3d.CurrentDriver].Desc; - RasterisationRequestMode = old_rrm; - -// THE TEXTURE FORMATS ENUMERATOR COULD ALSO BE CALLED HERE TO DETERMINE -// WHETHER PALETTISED FORMATS ETC ARE AVAILABLE. - -// NOTE THAT GETAVAILABLEVIDEOMEMORY (IN DD_FUNC.CPP) CAN BE USED TO REPORT -// THE FREE VIDEO MEMORY AT ANY TIME. - - -// Eliminate Direct3D object again - RELEASE(d3d.lpD3D); - -// Code to reset video mode depending on -// presence of hardware acceleration should -// go here. NOTE THAT AT A LATER DATE THIS CODE -// MUST ALSO TAKE ACCOUNT OF THE SETTING OF -// MMXAVAILABLE AND SUCH INFORMATION IN THE D3DINFO -// STRUCTURE AS DOES THE DRIVER DO TEXTURES -// OR Z-BUFFERING. FIXME!!! - - #if 0 - if ((D3DHardwareAvailable) && - (RasterisationRequestMode == RequestDefaultRasterisation)) - { - if ((VideoMode == VideoMode_DX_320x200x8) || - (VideoMode == VideoMode_DX_320x240x8)) - { - if (CheckForVideoModes(VideoMode_DX_320x200x15)) - { - VideoMode = VideoMode_DX_320x200x15; - return TRUE; - } - else if (CheckForVideoModes(VideoMode_DX_640x480x15)) - { - VideoMode = VideoMode_DX_640x480x15; - return TRUE; - } - else - return FALSE; - } - else if (VideoMode == VideoMode_DX_640x480x8) - { - if (CheckForVideoModes(VideoMode_DX_640x480x15)) - { - VideoMode = VideoMode_DX_640x480x15; - return TRUE; - } - else - return FALSE; - } - } - #else - // test only!!! - { - if (D3DHardwareAvailable) - TestHw = Yes; - else - TestHw = No; - } - #endif - - return TRUE; -} - -// Function to test access speed of VRAM -// against system memory using the DD blt -// members, and set DXMemoryMode using this -// result and the DXMemoryRequestMode as a basis. -// Note that we must allow for bank flipping -// speed. -// Potentially we should also test processor -// copy against video card blitter if the blitter -// is in hardware, since some blitters can be slower -// than the system processor. - -// THIS FUNCTION HAS NOT YET BEEN DONE, SEEING AS IT -// DOESN'T ACTUALLY MAKE MUCH DIFFERENCE TO THE SPEED -// IN PRACTICE. - -// NOTE ALSO that DXMemoryMode has itself -// not yet been fully implemented, since with -// all buffers forced into system memory DD -// doesn't seem to work properly anyway... - -// NOTE, HOWEVER, THAT THIS FUNCTION MUST READ -// MMXAvailable and D3DHardwareAvailable, -// since if MMX driver is picked we want the -// back buffer in SYSTEM memory, not video -// (as of 26 / 7 / 96). - -// MUST PUT BACK BUFFER IN VIDEO MEMORY ON -// AN ACCELERATOR!!! - -BOOL TestMemoryAccess(void) - -{ - // We take this request AT IT'S WORD, i.e. to mean - // that we will always do our best to provide a system - // memory target. Note that this means that if we then - // go on to boot up on hardware nothing will actually appear - // on the screen, though the debugger should work (in SubWindow - // mode, obviously). A more subtle test might be appropriate here, - // though it IS a debugging thing... - if (DXMemoryRequestMode == RequestSystemMemoryAlways) - DXMemoryMode = SystemMemoryPreferred; - else // assume default - { - // Note that at this stage we have a DirectDraw object on which - // to run GetCaps, we have detected the processor type and we have run - // TestInitD3DObject, so we have determined whether or not hardware - // acceleration is available. - - // Rendering target must be in VRAM if we are to run accelerated. - // Note that we really want to know whether we are going to run - // accelerated, not whether we can do, but this requires integration - // with the project's rules for deciding on its running mode. - // This function should probably be moved to d3_proj.cpp along - // with SelectD3DDriverAndMode and TestInitD3DObject... - if (D3DHardwareAvailable) - DXMemoryMode = VideoMemoryPreferred; - // For MMX we are currently assuming a high scan draw throughput, - // as VideoModeType_15 is likely to be the optimal solution, which - // is liable to result in a system gated by VRAM speed for a video - // memory rendering target. For this system we therfore want a system - // memory target. - else if (MMXAvailable) - DXMemoryMode = SystemMemoryPreferred; - // We are now assuming a DirectDraw software solution with our - // scan draws, on a standard(ish) video card. At this point we need - // to make an intelligent decision, remembering that in practice - // system memory targets are rarely faster than video memory ones - // for this situation. - else - { - // On the basis of experiment, these are the important - // video card capabilities for 3dc. - BOOL Flip; - BOOL BlitSysMem; - BOOL BlitVidMem; - BOOL BlitFloodFill; - BOOL BlitAsyncQueue; - BOOL BankSwitched; - // Timing factors - int TimeForVramWrite; - int TimeForSysMemWrite; - unsigned char* SurfacePtr; - // DirectX intfc - DDCAPS ddcaps; - HRESULT ddrval; - LPDIRECTDRAWSURFACE lpTestSurf; - DDSURFACEDESC ddsd; - // etc - int i; - int TestSurfHeight = 480; - int TestSurfWidth = 640; - - // Get caps on the DirectDraw object - memset(&ddcaps, 0, sizeof(ddcaps)); - ddcaps.dwSize = sizeof(ddcaps); - ddrval = lpDD->GetCaps(&ddcaps, NULL); - LOGDXERR(ddrval); - - if (ddrval != DD_OK) - #if debug - { - ReleaseDirect3D(); - exit(ddrval); - } - #else - { - return FALSE; - } - #endif - - if (ddcaps.dwCaps & DDCAPS_BLT) - BlitVidMem = TRUE; - else - BlitVidMem = FALSE; - - if (ddcaps.dwCaps & DDCAPS_BANKSWITCHED) - BankSwitched = TRUE; - else - BankSwitched = FALSE; - - if (ddcaps.dwCaps & DDCAPS_BLTCOLORFILL) - BlitFloodFill = TRUE; - else - BlitFloodFill = FALSE; - - if (ddcaps.dwCaps & DDCAPS_BLTQUEUE) - BlitAsyncQueue = TRUE; - else - BlitAsyncQueue = FALSE; - - if (ddcaps.dwCaps & DDCAPS_CANBLTSYSMEM) - BlitSysMem = TRUE; - else - BlitSysMem = FALSE; - - if (ddcaps.ddsCaps.dwCaps & DDSCAPS_FLIP) - Flip = TRUE; - else - Flip = FALSE; - - // Creating surfaces like this before setting exclusive mode - // und so weiter seems to REALLY UPSET IT. So for now, we - // shall say sod it and decide purely on the basis of the caps. - #if 0 - // Create a DD surface in Vram - memset(&ddsd,0,sizeof(DDSURFACEDESC)); - ddsd.dwSize = sizeof(DDSURFACEDESC); - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - // 640 x 480 would be a typical screen - ddsd.dwHeight = TestSurfHeight; - ddsd.dwWidth = TestSurfWidth; - ddsd.ddsCaps.dwCaps= (DDSCAPS_OFFSCREENPLAIN); - - ddrval = lpDD->CreateSurface(&ddsd, &lpTestSurf, NULL); - LOGDXERR(ddrval); - if (ddrval != DD_OK) - #if debug - { - ReleaseDirect3D(); - exit(ddrval); - } - #else - return FALSE; - #endif - - SurfacePtr = (unsigned char*) ddsd.lpSurface; - - // Time write - TimeForVramWrite = timeGetTime(); - for (i=0; iCreateSurface(&ddsd, &lpTestSurf, NULL); - LOGDXERR(ddrval); - if (ddrval != DD_OK) - #if debug - { - ReleaseDirect3D(); - exit(ddrval); - } - #else - return FALSE; - #endif - - SurfacePtr = (unsigned char*) ddsd.lpSurface; - - // Time write - TimeForSysMemWrite = timeGetTime(); - for (i=0; iONLY<-- 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) -{ -} - - - - - - - - - - diff --git a/src/win95/krender.c b/src/win95/krender.c deleted file mode 100644 index 3686310..0000000 --- a/src/win95/krender.c +++ /dev/null @@ -1,2830 +0,0 @@ -/*KJL********************************************************************* -* krender.c - Kevin's scandrawing code. (New render, new danger.) * -* * -* The new scandraws are called by patching the functions below into the * -* jumptables used in item.c. If the KRENDER_ON flag in krender.h is zero * -* then the old scandraws will be used. * -*********************************************************************KJL*/ - -/* this file is a bit messy at the moment, but I'll be back later... */ -#include "3dc.h" -#include "inline.h" -#include "module.h" -#include "gamedef.h" -#include "krender.h" -#include "vision.h" - -#define UseLocalAssert Yes -#include "ourasert.h" - -#define PENTIUM_PROFILING_ON 0 -#if PENTIUM_PROFILING_ON -#include "pentime.h" -#else -#define ProfileStart(); -#define ProfileStop(x); -#endif - -int ReciprocalTable[321]; -#if 1 -#define DIVIDE(a,b) ((a)/(b)) -#else -#define DIVIDE(a,b) (MUL_FIXED((a),ReciprocalTable[(b)])) -#endif - - -int Transparent; - -/* assembler fns */ -extern void ScanDraw2D_Gouraud(void); -extern void ScanDraw2D_GouraudTransparent(void); -extern void ScanDraw2D_VAlignedTransparent(void); -extern void ScanDraw2D_VAlignedOpaque(void); -extern void ScanDraw2D_Transparent(void); -extern void ScanDraw2D_TransparentLit(void); -extern void ScanDraw2D_Opaque(void); -extern void ScanDraw_GouraudScan(void); -extern void ScanDrawF3D_Gouraud(void); - -/* globals accessed by the assembler routines */ -unsigned char *SCASM_Lighting; -unsigned char *SCASM_Destination; -unsigned char *SCASM_Bitmap; -int SCASM_StartU; -int SCASM_StartV; -int SCASM_StartI; -int SCASM_DeltaU; -int SCASM_DeltaV; -int SCASM_DeltaI; -int SCASM_ScanLength; -int SCASM_ShadingTableSize; -int SCASM_TextureDeltaScan; - -/* things from item.c */ -extern int NumScans; -extern int ItemColour; -extern IMAGEHEADER *ImageHeaderPtrs[MaxImages]; -extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock; -extern unsigned char *TextureLightingTable; -extern int MIP_Index; -extern int ScanData[maxpolys*maxscansize]; -extern unsigned char *ScreenBuffer; -extern long BackBufferPitch; - -void Draw_Gouraud3dTexture_Spans(int *itemptr); - -int KRenderDrawMode = 0; - -/***********/ - -void KR_ScanDraw_Item_Gouraud2dTexturePolygon_VideoModeType_8(int *itemptr) -{ - POLYHEADER *pheader = (POLYHEADER *) itemptr; - I_GOURAUD2DTEXTUREPOLYGON_SCAN *sptr; - - if(NumScans) - { - int y = NumScans; - /* Get the Image Data required for the Draw */ - { - IMAGEHEADER *ImageHdr; - { - int TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - } - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - TEXTURE **TxImagePtr = &ImageHdr->ImagePtr; - SCASM_Bitmap = TxImagePtr[MIP_Index]; - GLOBALASSERT(SCASM_Bitmap); - SCASM_TextureDeltaScan = ImageHdr->ImageWidth >> MIP_Index; - #if MIP_ROUNDUP - if (ImageHdr->ImageWidth & (1<ImageWidth; - SCASM_Bitmap = ImageHdr->ImagePtr; - GLOBALASSERT(SCASM_Bitmap); - } - } - SCASM_Lighting = TextureLightingTable; - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_Raw256) SCASM_ShadingTableSize = 256; - else SCASM_ShadingTableSize = 64; - - sptr = (I_GOURAUD2DTEXTUREPOLYGON_SCAN *) ScanData; - do - { - int dx = sptr->ig2s_x2 - sptr->ig2s_x1; - if (dx>0 && !(sptr->ig2s_y & KRenderDrawMode) ) - { - /* Fixed Point U for Interpolation */ - { - int StartU = sptr->ig2s_u1; - SCASM_DeltaU = DIVIDE((sptr->ig2s_u2 - StartU),dx); - SCASM_StartU = StartU; - } - - /* Fixed Point V for Interpolation */ - { - int StartV = sptr->ig2s_v1; - SCASM_DeltaV = DIVIDE((sptr->ig2s_v2 - StartV),dx); - SCASM_StartV = StartV; - } - /* Fixed Point I for Interpolation */ - { - int StartI = sptr->ig2s_c1; - SCASM_DeltaI = DIVIDE((sptr->ig2s_c2 - StartI),dx); - SCASM_StartI = StartI; - } - /* Draw the Gouraud 2d Texture Scan */ - - SCASM_Destination = ScreenBuffer + (sptr->ig2s_y * BackBufferPitch) + sptr->ig2s_x1; - SCASM_ScanLength = dx; - - if(pheader->PolyFlags & iflag_ignore0) - { - ScanDraw2D_GouraudTransparent(); - } - else - { - ScanDraw2D_Gouraud(); - } - } - sptr++; - y--; - } - while(y); - } - -} - -void Draw3DScan(I_GOURAUD3DTEXTUREPOLYGON_SCAN *scanPtr, POLYHEADER *pheader) -{ - int dx = scanPtr->ig3s_x2 - scanPtr->ig3s_x1; - - if(dx > 0) - { - float uf; - float vf; - float uf2; - float vf2; - /* Get start and end UVs */ - { - float ooz1; - ooz1 = 65536.0 / scanPtr->ig3s_z1; - uf = scanPtr->ig3s_u1 * ooz1; - vf = scanPtr->ig3s_v1 * ooz1; - } - { - float ooz2; - ooz2 = 65536.0 / scanPtr->ig3s_z2; - uf2 = scanPtr->ig3s_u2 * ooz2; - vf2 = scanPtr->ig3s_v2 * ooz2; - } - if ( (uf>16700000.0) - ||(uf<0.0) - ||(vf>16700000.0) - ||(vf<0.0) ) - { - textprint("WARNING: UV coords invalid\n"); - // LOCALASSERT(0); - return; - } - if ( (uf2>16700000.0) - ||(uf2<0.0) - ||(vf2>16700000.0) - ||(vf2<0.0) ) - { - textprint("WARNING: UV coords invalid\n"); - // LOCALASSERT(0); - return; - } - /* For UV interpolation */ - f2i(SCASM_StartU,uf); - f2i(SCASM_StartV,vf); - { - int EndU,EndV; - f2i(EndU,uf2); - f2i(EndV,vf2); - SCASM_DeltaU =(EndU-SCASM_StartU)/dx; - SCASM_DeltaV =(EndV-SCASM_StartV)/dx; - } - - /* Fixed Point I for Interpolation */ - { - int StartI = scanPtr->ig3s_c1; - SCASM_DeltaI = (scanPtr->ig3s_c2 - StartI)/dx; - SCASM_StartI = StartI; - } - - /* Draw the 3d Texture Scan */ - SCASM_Destination = ScreenBuffer + (scanPtr->ig3s_y * BackBufferPitch) + scanPtr->ig3s_x1; - SCASM_ScanLength = dx; - - if(pheader->PolyFlags & iflag_ignore0) - { - ScanDraw2D_GouraudTransparent(); - } - else - { - ScanDraw2D_Gouraud(); - } - } -} - - -void KR_ScanDraw_Item_Gouraud3dTexturePolygon_Linear_S_VideoModeType_8(int *itemptr) -{ - POLYHEADER *pheader = (POLYHEADER *) itemptr; - - int num_scans_s; - I_GOURAUD3DTEXTUREPOLYGON_SCAN *sptr_array_ptr; - I_GOURAUD3DTEXTUREPOLYGON_SCAN *next_free_sptr; - I_GOURAUD3DTEXTUREPOLYGON_SCAN sptr_array[lin_s_max + 1]; - int StillSubdividing; - int i; - - - if(NumScans) - { - I_GOURAUD3DTEXTUREPOLYGON_SCAN *sptr; - int y; - /* Get the Image Data required for the Draw */ - { - IMAGEHEADER *ImageHdr; - { - int TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - } - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - TEXTURE **TxImagePtr = &ImageHdr->ImagePtr; - SCASM_Bitmap = TxImagePtr[MIP_Index]; - GLOBALASSERT(SCASM_Bitmap); - SCASM_TextureDeltaScan = ImageHdr->ImageWidth >> MIP_Index; - #if MIP_ROUNDUP - if (ImageHdr->ImageWidth & (1<ImageWidth; - SCASM_Bitmap = ImageHdr->ImagePtr; - GLOBALASSERT(SCASM_Bitmap); - } - } - SCASM_Lighting = TextureLightingTable; - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_Raw256) SCASM_ShadingTableSize = 256; - else SCASM_ShadingTableSize = 64; - - - sptr = (I_GOURAUD3DTEXTUREPOLYGON_SCAN *) ScanData; - - for(y = NumScans; y!=0; y--) - { - int dx = sptr->ig3s_x2 - sptr->ig3s_x1; - if (dx>0 && !(sptr->ig3s_y & KRenderDrawMode) ) - { - float zmax, zmin, z_ratio; - - /* Have a look at the z-ratio */ - if(sptr->ig3s_z1 > sptr->ig3s_z2) - { - zmax = sptr->ig3s_z1; - zmin = sptr->ig3s_z2; - } - else - { - zmax = sptr->ig3s_z2; - zmin = sptr->ig3s_z1; - } - z_ratio = (zmax * 256); - - - /* Draw if the z ratio is inside the threshold */ - if(z_ratio < lin_s_zthr*zmin) - { - Draw3DScan(sptr,pheader); - } - /* Else subdivide until scan segments are inside threshold */ - else - { - /* Copy the current scan to the subdivision array */ - sptr_array_ptr = sptr_array; - num_scans_s = 1; - - sptr_array_ptr->ig3s_u1 = sptr->ig3s_u1; - sptr_array_ptr->ig3s_v1 = sptr->ig3s_v1; - sptr_array_ptr->ig3s_z1 = sptr->ig3s_z1; - sptr_array_ptr->ig3s_c1 = sptr->ig3s_c1; - - sptr_array_ptr->ig3s_u2 = sptr->ig3s_u2; - sptr_array_ptr->ig3s_v2 = sptr->ig3s_v2; - sptr_array_ptr->ig3s_z2 = sptr->ig3s_z2; - sptr_array_ptr->ig3s_c2 = sptr->ig3s_c2; - - sptr_array_ptr->ig3s_x1 = sptr->ig3s_x1; - sptr_array_ptr->ig3s_x2 = sptr->ig3s_x2; - - sptr_array_ptr->ig3s_y = sptr->ig3s_y; - - - /* Subdivide until no further divisions are needed */ - - next_free_sptr = sptr_array_ptr + 1; - do - { - sptr_array_ptr = sptr_array; - - StillSubdividing = No; /* Assume not */ - - for(i = num_scans_s; i!=0; i--) - { - #if 0 - /* z ratio of this scan */ - if(sptr_array_ptr->ig3s_z1 > sptr_array_ptr->ig3s_z2) - { - z_ratio = (sptr_array_ptr->ig3s_z1 * 256) / - sptr_array_ptr->ig3s_z2; - } - else - { - z_ratio = (sptr_array_ptr->ig3s_z2 * 256) / - sptr_array_ptr->ig3s_z1; - } - /* Is it within the threshold? */ - if(z_ratio > lin_s_zthr && num_scans_s < lin_s_max) - #endif - int overThreshold=0; - /* z ratio of this scan */ - if(sptr_array_ptr->ig3s_z1 > sptr_array_ptr->ig3s_z2) - { - if ( (sptr_array_ptr->ig3s_z1 * 256) > (lin_s_zthr*sptr_array_ptr->ig3s_z2)) - overThreshold=1; - } - else - { - if ( (sptr_array_ptr->ig3s_z2 * 256) > (lin_s_zthr*sptr_array_ptr->ig3s_z1)) - overThreshold=1; - } - /* Is it within the threshold? */ - if(overThreshold && num_scans_s < lin_s_max) - { - int mid_x, mid_c; - float mid_u, mid_v, mid_z; - /* No - subdivide */ - StillSubdividing = Yes; - - mid_u = (sptr_array_ptr->ig3s_u1 + sptr_array_ptr->ig3s_u2) / 2; - - mid_v = (sptr_array_ptr->ig3s_v1 + sptr_array_ptr->ig3s_v2) / 2; - - mid_z = (sptr_array_ptr->ig3s_z1 + sptr_array_ptr->ig3s_z2) / 2; - - mid_c = (sptr_array_ptr->ig3s_c1 + sptr_array_ptr->ig3s_c2) / 2; - - mid_x = (sptr_array_ptr->ig3s_x1 + sptr_array_ptr->ig3s_x2) / 2; - - /* Create new scan */ - - next_free_sptr->ig3s_u1 = mid_u; - next_free_sptr->ig3s_v1 = mid_v; - next_free_sptr->ig3s_z1 = mid_z; - next_free_sptr->ig3s_c1 = mid_c; - next_free_sptr->ig3s_x1 = mid_x; - next_free_sptr->ig3s_u2 = sptr_array_ptr->ig3s_u2; - next_free_sptr->ig3s_v2 = sptr_array_ptr->ig3s_v2; - next_free_sptr->ig3s_z2 = sptr_array_ptr->ig3s_z2; - next_free_sptr->ig3s_c2 = sptr_array_ptr->ig3s_c2; - next_free_sptr->ig3s_x2 = sptr_array_ptr->ig3s_x2; - next_free_sptr->ig3s_y = sptr_array_ptr->ig3s_y; - /* Redefine old scan */ - - sptr_array_ptr->ig3s_u2 = mid_u; - sptr_array_ptr->ig3s_v2 = mid_v; - sptr_array_ptr->ig3s_z2 = mid_z; - sptr_array_ptr->ig3s_c2 = mid_c; - sptr_array_ptr->ig3s_x2 = mid_x; - - /* Update pointer and counter */ - - next_free_sptr++; - num_scans_s++; - - } - sptr_array_ptr++; - } - - } - while(StillSubdividing); - - /* Draw the scan array */ - sptr_array_ptr = sptr_array; - for(i = num_scans_s; i!=0; i--) - { - Draw3DScan(sptr_array_ptr,pheader); - sptr_array_ptr++; - } - } - } - sptr++; - } - } -} - - - -void KR_ScanDraw_Item_2dTexturePolygon_VideoModeType_8(int *itemptr) -{ - POLYHEADER *pheader = (POLYHEADER *) itemptr; - if(NumScans) - { - if(pheader->PolyFlags & iflag_nolight) - { - int y; - I_2DTEXTUREPOLYGON_SCAN *sptr = (I_2DTEXTUREPOLYGON_SCAN *) ScanData; - - /* Offset in Screen Buffer */ - { - IMAGEHEADER *ImageHdr; - { - int TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - } - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - TEXTURE **TxImagePtr = &ImageHdr->ImagePtr; - SCASM_Bitmap = TxImagePtr[MIP_Index]; - GLOBALASSERT(SCASM_Bitmap); - SCASM_TextureDeltaScan = ImageHdr->ImageWidth >> MIP_Index; - #if MIP_ROUNDUP - if (ImageHdr->ImageWidth & (1<ImageWidth; - SCASM_Bitmap = ImageHdr->ImagePtr; - GLOBALASSERT(SCASM_Bitmap); - } - } - - /* Get the Image Data required for the Draw */ - for(y=NumScans; y!=0; y--) - { - int dx = sptr->i2s_x2 - sptr->i2s_x1; - - if (dx>0 && !(sptr->i2s_y & KRenderDrawMode) ) - { - /* Fixed Point U for Interpolation */ - { - int StartU = sptr->i2s_u1; - SCASM_DeltaU = (sptr->i2s_u2 - StartU)/dx; - SCASM_StartU = StartU; - } - - /* Fixed Point V for Interpolation */ - { - int StartV = sptr->i2s_v1; - SCASM_DeltaV = (sptr->i2s_v2 - StartV)/dx; - SCASM_StartV = StartV; - } - - SCASM_Destination = ScreenBuffer + (sptr->i2s_y * BackBufferPitch) + sptr->i2s_x1; - SCASM_ScanLength = dx; - - - /* Is VDelta = 0? */ - if(SCASM_DeltaV == 0) - { - if(pheader->PolyFlags & iflag_ignore0) - { - ScanDraw2D_VAlignedTransparent(); - } - else - { - ScanDraw2D_VAlignedOpaque(); - } - - } - else - { - if(pheader->PolyFlags & iflag_ignore0) - { - ScanDraw2D_Transparent(); - } - else - { - ScanDraw2D_Opaque(); - } - } - } - sptr++; - } - } - #if 1 - else - { - int y; - I_2DTEXTUREPOLYGON_SCAN *sptr = (I_2DTEXTUREPOLYGON_SCAN *) ScanData; - /* Offset in Screen Buffer */ - { - IMAGEHEADER *ImageHdr; - { - int TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - } - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - TEXTURE **TxImagePtr = &ImageHdr->ImagePtr; - SCASM_Bitmap = TxImagePtr[MIP_Index]; - GLOBALASSERT(SCASM_Bitmap); - SCASM_TextureDeltaScan = ImageHdr->ImageWidth >> MIP_Index; - #if MIP_ROUNDUP - if (ImageHdr->ImageWidth & (1<ImageWidth; - SCASM_Bitmap = ImageHdr->ImagePtr; - GLOBALASSERT(SCASM_Bitmap); - } - } - SCASM_StartI = ItemColour >> TxDefn; - - SCASM_Lighting = TextureLightingTable; - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_Raw256) SCASM_ShadingTableSize = 256; - else SCASM_ShadingTableSize = 64; - - - /* Get the Image Data required for the Draw */ - for(y=NumScans; y!=0; y--) - { - int dx = sptr->i2s_x2 - sptr->i2s_x1; - if (dx>0 && !(sptr->i2s_y & KRenderDrawMode) ) - { - /* Fixed Point U for Interpolation */ - { - int StartU = sptr->i2s_u1; - SCASM_DeltaU = (sptr->i2s_u2 - StartU)/dx; - SCASM_StartU = StartU; - } - - /* Fixed Point V for Interpolation */ - { - int StartV = sptr->i2s_v1; - SCASM_DeltaV = (sptr->i2s_v2 - StartV)/dx; - SCASM_StartV = StartV; - } - - SCASM_Destination = ScreenBuffer + (sptr->i2s_y * BackBufferPitch) + sptr->i2s_x1; - SCASM_ScanLength = dx; - - ScanDraw2D_TransparentLit(); - // PredatorScanDraw(); - } - sptr++; - } - - - } - #endif - } - -} -unsigned char LighterTable[255]; -int predatorTimer = 0; -void ScanDraw_CloakedScan(void) -{ - unsigned char *screen = SCASM_Destination; - int x = SCASM_ScanLength; - - unsigned char buffer[1000]; - do - { - buffer[x] = *screen++; - } - while(--x); - - screen = SCASM_Destination; - x = SCASM_ScanLength; - - if (FastRandom()&3==3 && x>2) - { - x--; - screen++; - } - if (FastRandom()&3==3 && x>2) - { - x--; - } - - do - { - { - extern sine[]; - extern cosine[]; - unsigned char colour; - int offset = (GetCos( ((x*2047)/SCASM_ScanLength + predatorTimer)&4095 )+65536)/2; - offset = MUL_FIXED(offset,offset); - colour = (buffer[SCASM_ScanLength-x+1]); - // colour = (buffer[x]); - #if 0 - int i; - for (i=0; i<=255;i++) - { - if (colour==*(TextureLightingTable + 256*200 + i)) break; - } - #endif - colour=*(TextureLightingTable + 256*(60+MUL_FIXED(4,GetCos(predatorTimer&4095)) ) + colour); - *screen++ = colour; - - } - } - while(--x); - -} -#if 0 -void PredatorScanDraw(void) -{ - unsigned char *screen = SCASM_Destination; - unsigned char *source; - - do - { - source = SCASM_Bitmap+ (SCASM_StartU>>16) + (SCASM_StartV>>16)*SCASM_TextureDeltaScan; - - *screen++ = *source++; - - SCASM_StartU += SCASM_DeltaU; - SCASM_StartV += SCASM_DeltaV; - } - while(--SCASM_ScanLength); - -} -#else -void PredatorScanDraw(void) -{ - unsigned char *screen = SCASM_Destination; - unsigned char *source; - int x = SCASM_ScanLength; - do - { - source = SCASM_Bitmap+ (SCASM_StartU>>16) + (SCASM_StartV>>16)*SCASM_TextureDeltaScan; - - if (*source) - { - extern sine[]; - extern cosine[]; - unsigned char colour = *(screen); - *screen = LighterTable[colour]; - } - screen++; - SCASM_StartU += SCASM_DeltaU; - SCASM_StartV += SCASM_DeltaV; - } - while(--x); - -} -#endif - -void Draw_Item_CloakedPolygon(int *itemptr) -{ - POLYHEADER *pheader = (POLYHEADER *)itemptr; - int minYVertex = 0; - int maxYVertex = 0; - int maxVertexNum = 0; - - { - I_GOURAUDPOLYGON_PT *vertexPtr = (I_GOURAUDPOLYGON_PT*)&pheader->Poly1stPt; - int minY = vertexPtr->i_y; - int maxY = vertexPtr->i_y; - vertexPtr++; - - do - { - maxVertexNum++; - - if (minY > vertexPtr->i_y) - { - minY = vertexPtr->i_y; - minYVertex = maxVertexNum; - } - else if (maxY < vertexPtr->i_y) - { - maxY = vertexPtr->i_y; - maxYVertex = maxVertexNum; - } - vertexPtr++; - } - while(vertexPtr->i_x != Term); - - } - - - /* Initialise the Scan Data Buffer */ - { - I_GOURAUDPOLYGON_PT *vertexPtr = (I_GOURAUDPOLYGON_PT*)&pheader->Poly1stPt; - I_GOURAUDPOLYGON_SCAN *polyScan; - int curVertex; - int SecondOpinion=0; - - NumScans=0; - /* scan out the right edge */ - polyScan = (I_GOURAUDPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - int i,x,y; - int deltaX,deltaI; - - int nextVertex = curVertex-1; - if (nextVertex<0) nextVertex = maxVertexNum; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_int - vertexPtr[curVertex].i_int; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_int; - - for (y=vertexPtr[curVertex].i_y; yigs_x2 = x>>16; - x+=deltaX; - polyScan->igs_c2 = i; - i+=deltaI; - - polyScan->igs_y = y; - NumScans++; - polyScan++; - } - } - curVertex--; - if (curVertex<0) curVertex = maxVertexNum; - - } - while(curVertex!=maxYVertex); - - /* scan out the left edge */ - polyScan = (I_GOURAUDPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - int i,x,y; - int deltaX,deltaI; - - int nextVertex = curVertex+1; - if (nextVertex>maxVertexNum) nextVertex = 0; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_int - vertexPtr[curVertex].i_int; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_int; - - for (y=vertexPtr[curVertex].i_y; yigs_x1 = x>>16; - x+=deltaX; - polyScan->igs_c1 = i; - i+=deltaI; - - SecondOpinion++; - polyScan++; - } - } - curVertex++; - if (curVertex>maxVertexNum) curVertex = 0; - - } - while(curVertex!=maxYVertex); - - if (SecondOpinionPolyColour; - I_GOURAUDPOLYGON_SCAN *polyScan; - polyScan = (I_GOURAUDPOLYGON_SCAN*)ScanData; - SCASM_Lighting = TextureLightingTable+colour; - SCASM_ShadingTableSize = 256; - - while(NumScans) - { - int dx = polyScan->igs_x2 - polyScan->igs_x1; - if (dx>0) - { - SCASM_Destination = ScreenBuffer+(polyScan->igs_y * BackBufferPitch) + polyScan->igs_x1; - SCASM_ScanLength = dx; - SCASM_DeltaI = (polyScan->igs_c2-polyScan->igs_c1)/dx; - SCASM_StartI = polyScan->igs_c1; - ScanDraw_CloakedScan(); - } - NumScans--; - polyScan++; - } - } -} -#if 1 -void KDraw_Item_GouraudPolygon(int *itemptr) -{ - POLYHEADER *pheader = (POLYHEADER *)itemptr; - int minYVertex = 0; - int maxYVertex = 0; - int maxVertexNum = 0; - - { - I_GOURAUDPOLYGON_PT *vertexPtr = (I_GOURAUDPOLYGON_PT*)&pheader->Poly1stPt; - int minY = vertexPtr->i_y; - int maxY = vertexPtr->i_y; - vertexPtr++; - - do - { - maxVertexNum++; - - if (minY > vertexPtr->i_y) - { - minY = vertexPtr->i_y; - minYVertex = maxVertexNum; - } - else if (maxY < vertexPtr->i_y) - { - maxY = vertexPtr->i_y; - maxYVertex = maxVertexNum; - } - vertexPtr++; - } - while(vertexPtr->i_x != Term); - - } - - - /* Initialise the Scan Data Buffer */ - { - I_GOURAUDPOLYGON_PT *vertexPtr = (I_GOURAUDPOLYGON_PT*)&pheader->Poly1stPt; - I_GOURAUDPOLYGON_SCAN *polyScan; - int curVertex; - int SecondOpinion=0; - - NumScans=0; - /* scan out the right edge */ - polyScan = (I_GOURAUDPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - int i,x,y; - int deltaX,deltaI; - - int nextVertex = curVertex-1; - if (nextVertex<0) nextVertex = maxVertexNum; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_int - vertexPtr[curVertex].i_int; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_int; - - for (y=vertexPtr[curVertex].i_y; yigs_x2 = x>>16; - x+=deltaX; - polyScan->igs_c2 = i; - i+=deltaI; - - polyScan->igs_y = y; - NumScans++; - polyScan++; - } - } - curVertex--; - if (curVertex<0) curVertex = maxVertexNum; - - } - while(curVertex!=maxYVertex); - - /* scan out the left edge */ - polyScan = (I_GOURAUDPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - int i,x,y; - int deltaX,deltaI; - - int nextVertex = curVertex+1; - if (nextVertex>maxVertexNum) nextVertex = 0; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_int - vertexPtr[curVertex].i_int; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_int; - - for (y=vertexPtr[curVertex].i_y; yigs_x1 = x>>16; - x+=deltaX; - polyScan->igs_c1 = i; - i+=deltaI; - - SecondOpinion++; - polyScan++; - } - } - curVertex++; - if (curVertex>maxVertexNum) curVertex = 0; - - } - while(curVertex!=maxYVertex); - - if (SecondOpinionPolyColour; - I_GOURAUDPOLYGON_SCAN *polyScan; - polyScan = (I_GOURAUDPOLYGON_SCAN*)ScanData; - SCASM_Lighting = TextureLightingTable+colour; - SCASM_ShadingTableSize = 256; - - while(NumScans) - { - int dx = polyScan->igs_x2 - polyScan->igs_x1; - if (dx>0) - { - SCASM_Destination = ScreenBuffer+(polyScan->igs_y * BackBufferPitch) + polyScan->igs_x1; - SCASM_ScanLength = dx; - SCASM_DeltaI = (polyScan->igs_c2-polyScan->igs_c1)/dx; - SCASM_StartI = polyScan->igs_c1; - ScanDraw_GouraudScan(); - } - NumScans--; - polyScan++; - } - } -} -void KDraw_Item_2dTexturePolygon(int *itemptr) -{ - - POLYHEADER *pheader = (POLYHEADER *) itemptr; - int TxIndex; - IMAGEHEADER *ImageHdr; - ItemColour = pheader->PolyColour; - - TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - - - /* Colour */ - - /* If MIP Mapping, calculate the scale */ - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - I_2DTEXTUREPOLYGON_PT *vector1; - I_2DTEXTUREPOLYGON_PT *vector2; - I_2DTEXTUREPOLYGON_PT *vector3; - int mip1, mip2; - int xyd, uvd; - VECTOR2D s0, s1; - VECTOR2D t0, t1; - - - /* Screen and Texture Space Vectors */ - /* Express the "uvd / xyd" ratio as a binary scale */ - - vector1 = (I_2DTEXTUREPOLYGON_PT *) &pheader->Poly1stPt; - vector2 = &vector1[1]; - vector3 = &vector1[2]; - - - /* Vector 1 */ - - s0.vx = vector1->i_x; - s0.vy = vector1->i_y; - s1.vx = vector2->i_x; - s1.vy = vector2->i_y; - - t0.vx = vector1->i_u >> 16; - t0.vy = vector1->i_v >> 16; - t1.vx = vector2->i_u >> 16; - t1.vy = vector2->i_v >> 16; - - xyd = FandVD_Distance_2d(&s0, &s1); - uvd = FandVD_Distance_2d(&t0, &t1); - - mip1 = FindShift32(uvd, xyd); - - - /* Vector 2 */ - - s0.vx = vector2->i_x; - s0.vy = vector2->i_y; - s1.vx = vector3->i_x; - s1.vy = vector3->i_y; - - t0.vx = t1.vx; - t0.vy = t1.vy; - t1.vx = vector3->i_u >> 16; - t1.vy = vector3->i_v >> 16; - - xyd = FandVD_Distance_2d(&s0, &s1); - uvd = FandVD_Distance_2d(&t0, &t1); - - mip2 = FindShift32(uvd, xyd); - - - /* Choose the larger of the two */ - - if(pheader->PolyFlags & iflag_no_mip) { - - MIP_Index = 0; - - } - - else { - - #if UseMIPMax - if(mip1 > mip2) - MIP_Index = mip1; - else - MIP_Index = mip2; - #endif - - #if UseMIPMin - if(mip1 > mip2) - MIP_Index = mip2; - else - MIP_Index = mip1; - #endif - - #if UseMIPAvg - MIP_Index = (mip1 + mip2) >> 1; - #endif - - } - - - /* Clamp "MIP_Index" */ - - #if MIP_INDEX_SUBTRACT - - MIP_Index -= MIP_INDEX_SUBTRACT; - if(MIP_Index < 0) MIP_Index = 0; - else if(MIP_Index > 6) MIP_Index = 6; - - #else - - if(MIP_Index > 6) MIP_Index = 6; - - #endif - - } - - { - int minYVertex = 0; - int maxYVertex = 0; - int maxVertexNum = 0; - - { - I_2DTEXTUREPOLYGON_PT *vertexPtr = (I_2DTEXTUREPOLYGON_PT*)&pheader->Poly1stPt; - int minY = vertexPtr->i_y; - int maxY = vertexPtr->i_y; - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - vertexPtr->i_u >>= MIP_Index; - vertexPtr->i_v >>= MIP_Index; - } - vertexPtr++; - - do - { - maxVertexNum++; - - if (minY > vertexPtr->i_y) - { - minY = vertexPtr->i_y; - minYVertex = maxVertexNum; - } - else if (maxY < vertexPtr->i_y) - { - maxY = vertexPtr->i_y; - maxYVertex = maxVertexNum; - } - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - vertexPtr->i_u >>= MIP_Index; - vertexPtr->i_v >>= MIP_Index; - } - - vertexPtr++; - } - while(vertexPtr->i_x != Term); - - } - - - /* Initialise the Scan Data Buffer */ - { - I_2DTEXTUREPOLYGON_PT *vertexPtr = (I_2DTEXTUREPOLYGON_PT*)&pheader->Poly1stPt; - I_2DTEXTUREPOLYGON_SCAN *polyScan; - int curVertex; - int SecondOpinion = 0; - - NumScans=0; - /* scan out the right edge */ - polyScan = (I_2DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex-1; - if (nextVertex<0) nextVertex = maxVertexNum; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int x,y,u,v; - int deltaX,deltaU,deltaV; - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int widthU = vertexPtr[nextVertex].i_u - vertexPtr[curVertex].i_u; - int widthV = vertexPtr[nextVertex].i_v - vertexPtr[curVertex].i_v; - - deltaX = (width<<16)/height; - deltaU = widthU/height; - deltaV = widthV/height; - - x = vertexPtr[curVertex].i_x<<16; - u = vertexPtr[curVertex].i_u; - v = vertexPtr[curVertex].i_v; - - for (y=vertexPtr[curVertex].i_y; yi2s_x2 = x>>16; - x+=deltaX; - polyScan->i2s_u2 = u; - u+=deltaU; - polyScan->i2s_v2 = v; - v+=deltaV; - - polyScan->i2s_y = y; - NumScans++; - polyScan++; - } - } - curVertex--; - if (curVertex<0) curVertex = maxVertexNum; - - } - while(curVertex!=maxYVertex); - - /* scan out the left edge */ - polyScan = (I_2DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex+1; - if (nextVertex>maxVertexNum) nextVertex = 0; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int x,y,u,v; - int deltaX,deltaU,deltaV; - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int widthU = vertexPtr[nextVertex].i_u - vertexPtr[curVertex].i_u; - int widthV = vertexPtr[nextVertex].i_v - vertexPtr[curVertex].i_v; - - deltaX = (width<<16)/height; - deltaU = widthU/height; - deltaV = widthV/height; - - x = vertexPtr[curVertex].i_x<<16; - u = vertexPtr[curVertex].i_u; - v = vertexPtr[curVertex].i_v; - - for (y=vertexPtr[curVertex].i_y; yi2s_x1 = x>>16; - x+=deltaX; - polyScan->i2s_u1 = u; - u+=deltaU; - polyScan->i2s_v1 = v; - v+=deltaV; - - SecondOpinion++; - polyScan++; - } - } - curVertex++; - if (curVertex>maxVertexNum) curVertex = 0; - - } - while(curVertex!=maxYVertex); - - if (SecondOpinionPolyColour; - - TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - - - - /* Colour */ - - - /* If MIP Mapping, calculate the scale */ - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - I_GOURAUD2DTEXTUREPOLYGON_PT *vector1; - I_GOURAUD2DTEXTUREPOLYGON_PT *vector2; - I_GOURAUD2DTEXTUREPOLYGON_PT *vector3; - int mip1, mip2; - int xyd, uvd; - VECTOR2D s0, s1; - VECTOR2D t0, t1; - - - /* Screen and Texture Space Vectors */ - /* Express the "uvd / xyd" ratio as a binary scale */ - - vector1 = (I_GOURAUD2DTEXTUREPOLYGON_PT *) &pheader->Poly1stPt; - vector2 = &vector1[1]; - vector3 = &vector1[2]; - - - /* Vector 1 */ - - s0.vx = vector1->i_x; - s0.vy = vector1->i_y; - s1.vx = vector2->i_x; - s1.vy = vector2->i_y; - - t0.vx = vector1->i_u >> 16; - t0.vy = vector1->i_v >> 16; - t1.vx = vector2->i_u >> 16; - t1.vy = vector2->i_v >> 16; - - xyd = FandVD_Distance_2d(&s0, &s1); - uvd = FandVD_Distance_2d(&t0, &t1); - - mip1 = FindShift32(uvd, xyd); - - - /* Vector 2 */ - - s0.vx = vector2->i_x; - s0.vy = vector2->i_y; - s1.vx = vector3->i_x; - s1.vy = vector3->i_y; - - t0.vx = t1.vx; - t0.vy = t1.vy; - t1.vx = vector3->i_u >> 16; - t1.vy = vector3->i_v >> 16; - - xyd = FandVD_Distance_2d(&s0, &s1); - uvd = FandVD_Distance_2d(&t0, &t1); - - mip2 = FindShift32(uvd, xyd); - - - /* Choose the larger of the two */ - - if(pheader->PolyFlags & iflag_no_mip) { - - MIP_Index = 0; - - } - - else { - - #if UseMIPMax - if(mip1 > mip2) - MIP_Index = mip1; - else - MIP_Index = mip2; - #endif - - #if UseMIPMin - if(mip1 > mip2) - MIP_Index = mip2; - else - MIP_Index = mip1; - #endif - - #if UseMIPAvg - MIP_Index = (mip1 + mip2) >> 1; - #endif - - } - - - /* Clamp "MIP_Index" */ - - #if MIP_INDEX_SUBTRACT - - MIP_Index -= MIP_INDEX_SUBTRACT; - if(MIP_Index < 0) MIP_Index = 0; - else if(MIP_Index > 6) MIP_Index = 6; - - #else - - if(MIP_Index > 6) MIP_Index = 6; - - #endif - - } - - { - int minYVertex = 0; - int maxYVertex = 0; - int maxVertexNum = 0; - - { - I_GOURAUD2DTEXTUREPOLYGON_PT *vertexPtr = (I_GOURAUD2DTEXTUREPOLYGON_PT*)&pheader->Poly1stPt; - int minY = vertexPtr->i_y; - int maxY = vertexPtr->i_y; - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - vertexPtr->i_u >>= MIP_Index; - vertexPtr->i_v >>= MIP_Index; - } - vertexPtr++; - - do - { - maxVertexNum++; - - if (minY > vertexPtr->i_y) - { - minY = vertexPtr->i_y; - minYVertex = maxVertexNum; - } - else if (maxY < vertexPtr->i_y) - { - maxY = vertexPtr->i_y; - maxYVertex = maxVertexNum; - } - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - vertexPtr->i_u >>= MIP_Index; - vertexPtr->i_v >>= MIP_Index; - } - - vertexPtr++; - } - while(vertexPtr->i_x != Term); - - } - - - /* Initialise the Scan Data Buffer */ - { - I_GOURAUD2DTEXTUREPOLYGON_PT *vertexPtr = (I_GOURAUD2DTEXTUREPOLYGON_PT*)&pheader->Poly1stPt; - I_GOURAUD2DTEXTUREPOLYGON_SCAN *polyScan; - int curVertex; - int SecondOpinion=0; - - NumScans=0; - /* scan out the right edge */ - polyScan = (I_GOURAUD2DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex-1; - if (nextVertex<0) nextVertex = maxVertexNum; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int i,x,y,u,v; - int deltaX,deltaI,deltaU,deltaV; - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_i - vertexPtr[curVertex].i_i; - int widthU = vertexPtr[nextVertex].i_u - vertexPtr[curVertex].i_u; - int widthV = vertexPtr[nextVertex].i_v - vertexPtr[curVertex].i_v; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - deltaU = widthU/height; - deltaV = widthV/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_i; - u = vertexPtr[curVertex].i_u; - v = vertexPtr[curVertex].i_v; - - for (y=vertexPtr[curVertex].i_y; yig2s_x2 = x>>16; - x+=deltaX; - polyScan->ig2s_c2 = i; - i+=deltaI; - polyScan->ig2s_u2 = u; - u+=deltaU; - polyScan->ig2s_v2 = v; - v+=deltaV; - - polyScan->ig2s_y = y; - NumScans++; - polyScan++; - } - } - curVertex--; - if (curVertex<0) curVertex = maxVertexNum; - - } - while(curVertex!=maxYVertex); - - /* scan out the left edge */ - polyScan = (I_GOURAUD2DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex+1; - if (nextVertex>maxVertexNum) nextVertex = 0; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int i,x,y,u,v; - int deltaX,deltaI,deltaU,deltaV; - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_i - vertexPtr[curVertex].i_i; - int widthU = vertexPtr[nextVertex].i_u - vertexPtr[curVertex].i_u; - int widthV = vertexPtr[nextVertex].i_v - vertexPtr[curVertex].i_v; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - deltaU = widthU/height; - deltaV = widthV/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_i; - u = vertexPtr[curVertex].i_u; - v = vertexPtr[curVertex].i_v; - - for (y=vertexPtr[curVertex].i_y; yig2s_x1 = x>>16; - x+=deltaX; - polyScan->ig2s_c1 = i; - i+=deltaI; - polyScan->ig2s_u1 = u; - u+=deltaU; - polyScan->ig2s_v1 = v; - v+=deltaV; - - SecondOpinion++; - polyScan++; - } - } - curVertex++; - if (curVertex>maxVertexNum) curVertex = 0; - - } - while(curVertex!=maxYVertex); - - if (SecondOpinionPolyColour; - I_GOURAUD2DTEXTUREPOLYGON_SCAN *polyScan; - polyScan = (I_GOURAUD2DTEXTUREPOLYGON_SCAN*)ScanData; - SCASM_Lighting = TextureLightingTable+colour; - SCASM_ShadingTableSize = 256; - - while(NumScans) - { - int dx = polyScan->ig2s_x2 - polyScan->ig2s_x1; - if (dx>0) - { - SCASM_Destination = ScreenBuffer+(polyScan->ig2s_y * BackBufferPitch) + polyScan->ig2s_x1; - SCASM_ScanLength = dx; - SCASM_DeltaI = (polyScan->ig2s_c2-polyScan->ig2s_c1)/dx; - SCASM_StartI = polyScan->ig2s_c1; - ScanDraw_GouraudScan(); - } - NumScans--; - polyScan++; - } - } - #endif - } -} -#endif -#if 0 -void KDraw_Item_Gouraud3dTexturePolygon(int *itemptr) -{ - POLYHEADER *pheader = (POLYHEADER *) itemptr; - int TxIndex; - IMAGEHEADER *ImageHdr; - ItemColour = pheader->PolyColour; - - TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - - - - /* Colour */ - - - /* If MIP Mapping, calculate the scale */ - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - I_GOURAUD3DTEXTUREPOLYGON_PT *vector1; - I_GOURAUD3DTEXTUREPOLYGON_PT *vector2; - I_GOURAUD3DTEXTUREPOLYGON_PT *vector3; - int mip1, mip2; - int xyd, uvd; - VECTOR2D s0, s1; - VECTOR2D t0, t1; - - - /* Screen and Texture Space Vectors */ - /* Express the "uvd / xyd" ratio as a binary scale */ - - vector1 = (I_GOURAUD3DTEXTUREPOLYGON_PT *) &pheader->Poly1stPt; - vector2 = &vector1[1]; - vector3 = &vector1[2]; - - - /* Vector 1 */ - - s0.vx = vector1->i_x; - s0.vy = vector1->i_y; - s1.vx = vector2->i_x; - s1.vy = vector2->i_y; - - t0.vx = vector1->i_gtx3d_u / vector1->i_gtx3d_z; - t0.vy = vector1->i_gtx3d_v / vector1->i_gtx3d_z; - t1.vx = vector2->i_gtx3d_u / vector2->i_gtx3d_z; - t1.vy = vector2->i_gtx3d_v / vector2->i_gtx3d_z; - - xyd = FandVD_Distance_2d(&s0, &s1); - uvd = FandVD_Distance_2d(&t0, &t1); - - mip1 = FindShift32(uvd, xyd); - - - /* Vector 2 */ - - s0.vx = vector2->i_x; - s0.vy = vector2->i_y; - s1.vx = vector3->i_x; - s1.vy = vector3->i_y; - - t0.vx = t1.vx; - t0.vy = t1.vy; - t1.vx = vector3->i_gtx3d_u / vector3->i_gtx3d_z; - t1.vy = vector3->i_gtx3d_v / vector3->i_gtx3d_z; - - xyd = FandVD_Distance_2d(&s0, &s1); - uvd = FandVD_Distance_2d(&t0, &t1); - - mip2 = FindShift32(uvd, xyd); - - - /* Choose the larger of the two */ - - if(pheader->PolyFlags & iflag_no_mip) { - - MIP_Index = 0; - - } - - else { - - #if UseMIPMax - if(mip1 > mip2) - MIP_Index = mip1; - else - MIP_Index = mip2; - #endif - - #if UseMIPMin - if(mip1 > mip2) - MIP_Index = mip2; - else - MIP_Index = mip1; - #endif - - #if UseMIPAvg - MIP_Index = (mip1 + mip2) >> 1; - #endif - - } - - - /* Clamp "MIP_Index" */ - - #if MIP_INDEX_SUBTRACT - - MIP_Index -= MIP_INDEX_SUBTRACT; - if(MIP_Index < 0) MIP_Index = 0; - else if(MIP_Index > 6) MIP_Index = 6; - - #else - - if(MIP_Index > 6) MIP_Index = 6; - - #endif - - } - - { - int minYVertex = 0; - int maxYVertex = 0; - int maxVertexNum = 0; - float MIP_Divide = 1<Poly1stPt; - int minY = vertexPtr->i_y; - int maxY = vertexPtr->i_y; - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - vertexPtr->i_gtx3d_u /= MIP_Divide; - vertexPtr->i_gtx3d_v /= MIP_Divide; - } - vertexPtr++; - - do - { - maxVertexNum++; - - if (minY > vertexPtr->i_y) - { - minY = vertexPtr->i_y; - minYVertex = maxVertexNum; - } - else if (maxY < vertexPtr->i_y) - { - maxY = vertexPtr->i_y; - maxYVertex = maxVertexNum; - } - - if(ScreenDescriptorBlock.SDB_Flags & SDB_Flag_MIP && ImageHdr->ImageFlags & ih_flag_mip) - { - vertexPtr->i_gtx3d_u /= MIP_Divide; - vertexPtr->i_gtx3d_v /= MIP_Divide; - } - - vertexPtr++; - } - while(vertexPtr->i_x != Term); - - } - - - /* Initialise the Scan Data Buffer */ - { - I_GOURAUD3DTEXTUREPOLYGON_PT *vertexPtr = (I_GOURAUD3DTEXTUREPOLYGON_PT*)&pheader->Poly1stPt; - I_GOURAUD3DTEXTUREPOLYGON_SCAN *polyScan; - int curVertex; - int SecondOpinion=0; - - NumScans=0; - - /* scan out the right edge */ - polyScan = (I_GOURAUD3DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex-1; - if (nextVertex<0) nextVertex = maxVertexNum; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int i,x,y; - float u,v,z; - int deltaX,deltaI; - float deltaU,deltaV,deltaZ; - - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_gtx3d_i - vertexPtr[curVertex].i_gtx3d_i; - float widthU = vertexPtr[nextVertex].i_gtx3d_u - vertexPtr[curVertex].i_gtx3d_u; - float widthV = vertexPtr[nextVertex].i_gtx3d_v - vertexPtr[curVertex].i_gtx3d_v; - float widthZ = vertexPtr[nextVertex].i_gtx3d_z - vertexPtr[curVertex].i_gtx3d_z; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - deltaU = widthU/height; - deltaV = widthV/height; - deltaZ = widthZ/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_gtx3d_i; - u = vertexPtr[curVertex].i_gtx3d_u; - v = vertexPtr[curVertex].i_gtx3d_v; - z = vertexPtr[curVertex].i_gtx3d_z; - - for (y=vertexPtr[curVertex].i_y; yig3s_x2 = x>>16; - x+=deltaX; - polyScan->ig3s_c2 = i; - i+=deltaI; - polyScan->ig3s_u2 = u; - u+=deltaU; - polyScan->ig3s_v2 = v; - v+=deltaV; - polyScan->ig3s_z2 = z; - z+=deltaZ; - - polyScan->ig3s_y = y; - NumScans++; - polyScan++; - } - } - curVertex--; - if (curVertex<0) curVertex = maxVertexNum; - - } - while(curVertex!=maxYVertex); - - /* scan out the left edge */ - polyScan = (I_GOURAUD3DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex+1; - if (nextVertex>maxVertexNum) nextVertex = 0; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int i,x,y; - float u,v,z; - int deltaX,deltaI; - float deltaU,deltaV,deltaZ; - - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_gtx3d_i - vertexPtr[curVertex].i_gtx3d_i; - float widthU = vertexPtr[nextVertex].i_gtx3d_u - vertexPtr[curVertex].i_gtx3d_u; - float widthV = vertexPtr[nextVertex].i_gtx3d_v - vertexPtr[curVertex].i_gtx3d_v; - float widthZ = vertexPtr[nextVertex].i_gtx3d_z - vertexPtr[curVertex].i_gtx3d_z; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - deltaU = widthU/height; - deltaV = widthV/height; - deltaZ = widthZ/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_gtx3d_i; - u = vertexPtr[curVertex].i_gtx3d_u; - v = vertexPtr[curVertex].i_gtx3d_v; - z = vertexPtr[curVertex].i_gtx3d_z; - - for (y=vertexPtr[curVertex].i_y; yig3s_x1 = x>>16; - x+=deltaX; - polyScan->ig3s_c1 = i; - i+=deltaI; - polyScan->ig3s_u1 = u; - u+=deltaU; - polyScan->ig3s_v1 = v; - v+=deltaV; - polyScan->ig3s_z1 = z; - z+=deltaZ; - - SecondOpinion++; - polyScan++; - } - } - curVertex++; - if (curVertex>maxVertexNum) curVertex = 0; - - } - while(curVertex!=maxYVertex); - - if (SecondOpinionPolyColour; - - TxIndex = ItemColour & ClrTxDefn; - ImageHdr = ImageHeaderPtrs[TxIndex]; - - - - { - int minYVertex = 0; - int maxYVertex = 0; - int maxVertexNum = 0; - - - { - I_GOURAUD3DTEXTUREPOLYGON_PT *vertexPtr = (I_GOURAUD3DTEXTUREPOLYGON_PT*)&pheader->Poly1stPt; - int minY = vertexPtr->i_y; - int maxY = vertexPtr->i_y; - - vertexPtr++; - - do - { - maxVertexNum++; - - if (minY > vertexPtr->i_y) - { - minY = vertexPtr->i_y; - minYVertex = maxVertexNum; - } - else if (maxY < vertexPtr->i_y) - { - maxY = vertexPtr->i_y; - maxYVertex = maxVertexNum; - } - - vertexPtr++; - } - while(vertexPtr->i_x != Term); - - } - - - /* Initialise the Scan Data Buffer */ - { - I_GOURAUD3DTEXTUREPOLYGON_PT *vertexPtr = (I_GOURAUD3DTEXTUREPOLYGON_PT*)&pheader->Poly1stPt; - I_GOURAUD3DTEXTUREPOLYGON_SCAN *polyScan; - int curVertex; - int SecondOpinion=0; - - NumScans=0; - - /* scan out the right edge */ - polyScan = (I_GOURAUD3DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex-1; - if (nextVertex<0) nextVertex = maxVertexNum; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int i,x,y; - float u,v,z; - int deltaX,deltaI; - float deltaU,deltaV,deltaZ; - - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_gtx3d_i - vertexPtr[curVertex].i_gtx3d_i; - float widthU = vertexPtr[nextVertex].i_gtx3d_u - vertexPtr[curVertex].i_gtx3d_u; - float widthV = vertexPtr[nextVertex].i_gtx3d_v - vertexPtr[curVertex].i_gtx3d_v; - float widthZ = vertexPtr[nextVertex].i_gtx3d_z - vertexPtr[curVertex].i_gtx3d_z; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - deltaU = widthU/height; - deltaV = widthV/height; - deltaZ = widthZ/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_gtx3d_i; - u = vertexPtr[curVertex].i_gtx3d_u; - v = vertexPtr[curVertex].i_gtx3d_v; - z = vertexPtr[curVertex].i_gtx3d_z; - - for (y=vertexPtr[curVertex].i_y; yig3s_x2 = x>>16; - x+=deltaX; - polyScan->ig3s_c2 = i; - i+=deltaI; - polyScan->ig3s_u2 = u; - u+=deltaU; - polyScan->ig3s_v2 = v; - v+=deltaV; - polyScan->ig3s_z2 = z; - z+=deltaZ; - - polyScan->ig3s_y = y; - NumScans++; - polyScan++; - } - } - curVertex--; - if (curVertex<0) curVertex = maxVertexNum; - - } - while(curVertex!=maxYVertex); - - /* scan out the left edge */ - polyScan = (I_GOURAUD3DTEXTUREPOLYGON_SCAN*)ScanData; - curVertex = minYVertex; - do - { - int height; - - int nextVertex = curVertex+1; - if (nextVertex>maxVertexNum) nextVertex = 0; - - height = vertexPtr[nextVertex].i_y - vertexPtr[curVertex].i_y; - if (height!=0) - { - int i,x,y; - float u,v,z; - int deltaX,deltaI; - float deltaU,deltaV,deltaZ; - - int width = vertexPtr[nextVertex].i_x - vertexPtr[curVertex].i_x; - int contrast = vertexPtr[nextVertex].i_gtx3d_i - vertexPtr[curVertex].i_gtx3d_i; - float widthU = vertexPtr[nextVertex].i_gtx3d_u - vertexPtr[curVertex].i_gtx3d_u; - float widthV = vertexPtr[nextVertex].i_gtx3d_v - vertexPtr[curVertex].i_gtx3d_v; - float widthZ = vertexPtr[nextVertex].i_gtx3d_z - vertexPtr[curVertex].i_gtx3d_z; - - deltaX = (width<<16)/height; - deltaI = contrast/height; - deltaU = widthU/height; - deltaV = widthV/height; - deltaZ = widthZ/height; - - x = vertexPtr[curVertex].i_x<<16; - i = vertexPtr[curVertex].i_gtx3d_i; - u = vertexPtr[curVertex].i_gtx3d_u; - v = vertexPtr[curVertex].i_gtx3d_v; - z = vertexPtr[curVertex].i_gtx3d_z; - - for (y=vertexPtr[curVertex].i_y; yig3s_x1 = x>>16; - x+=deltaX; - polyScan->ig3s_c1 = i; - i+=deltaI; - polyScan->ig3s_u1 = u; - u+=deltaU; - polyScan->ig3s_v1 = v; - v+=deltaV; - polyScan->ig3s_z1 = z; - z+=deltaZ; - - SecondOpinion++; - polyScan++; - } - } - curVertex++; - if (curVertex>maxVertexNum) curVertex = 0; - - } - while(curVertex!=maxYVertex); - - if (SecondOpinionImageWidth; - SCASM_Bitmap = ImageHdr->ImagePtr; - GLOBALASSERT(SCASM_Bitmap); - } - } - SCASM_Lighting = TextureLightingTable; - - sptr = (I_GOURAUD3DTEXTUREPOLYGON_SCAN *) ScanData; - do - { - int length = sptr->ig3s_x2 - sptr->ig3s_x1; - int dx=length; - - if (dx>0 && !(sptr->ig3s_y & KRenderDrawMode) ) - { - float deltaZ; - float endZ; - - float endU,endV; - float deltaU,deltaV; - - { - int StartI = sptr->ig3s_c1; - SCASM_DeltaI = (sptr->ig3s_c2 - StartI)/dx; - SCASM_StartI = StartI; - } - - SCASM_Destination = ScreenBuffer + (sptr->ig3s_y * BackBufferPitch) + sptr->ig3s_x1; - SCASM_ScanLength = PERS_STEP; - - { - float oneOverdx = 1.0/dx; - - endZ = sptr->ig3s_z1; - deltaZ = (sptr->ig3s_z2 - endZ)*oneOverdx; - - endU = sptr->ig3s_u1; - deltaU = (sptr->ig3s_u2 - endU)*oneOverdx; - - endV = sptr->ig3s_v1; - deltaV = (sptr->ig3s_v2 - endV)*oneOverdx; - } - { - float z = 65536.0/endZ; - SCASM_StartU = endU*z; - SCASM_StartV = endV*z; - } - while(dx>PERS_STEP) - { - /* subdivide! */ - int u,v; - - dx -= PERS_STEP; - - endZ += PERS_STEP*deltaZ; - endU += PERS_STEP*deltaU; - endV += PERS_STEP*deltaV; - - { - float z = 65536.0/endZ; - u = endU*z; - v = endV*z; - } - SCASM_DeltaU = (u-SCASM_StartU)/PERS_STEP; - SCASM_DeltaV = (v-SCASM_StartV)/PERS_STEP; - - /* draw PERS_STEP pixels */ - ScanDraw2D_Gouraud(); - - SCASM_StartU = u; - SCASM_StartV = v; - - SCASM_Destination +=PERS_STEP; - SCASM_StartI += PERS_STEP*SCASM_DeltaI; - } - if (dx>0) - { - int u,v; - SCASM_ScanLength = dx; - { - float z = 65536.0/sptr->ig3s_z2; - u = sptr->ig3s_u2*z; - v = sptr->ig3s_v2*z; - } - SCASM_DeltaU = (u-SCASM_StartU)/dx; - SCASM_DeltaV = (v-SCASM_StartV)/dx; - - /* draw 8 pixels */ - ScanDraw2D_Gouraud(); - } - - - - - - } - sptr++; - y--; - } - while(y); - } - -} -#endif - - - - - - - - - - - -#if 0 -void MakeInverseLightingTable(void) -{ - int lookingForColour; - - for(lookingForColour=1; lookingForColour<=255; lookingForColour++) - { - int exit =0; - int table; - for (table=128; (table>0 && (!exit)); table--) - { - int entry; - for(entry=1; (entry<=255 && (!exit)); entry++) - { - if(lookingForColour == *(TextureLightingTable + 256*(table) + entry)) - { - LighterTable[lookingForColour] = entry; - exit=1; - } - } - } - if (exit==0) LighterTable[lookingForColour] = 255; - } -} -#endif -struct ColourVector -{ - VECTORCH Direction; - int Magnitude; -}; - -struct ColourVector ColourTable[256]; - -void MakeInverseLightingTable(void) -{ - extern unsigned char TestPalette[]; - unsigned char *palPtr = TestPalette; - int i; - - for(i = 0; i < 256; i++) - { - VECTORCH colour; - int mag; - - colour.vx = *palPtr++; - colour.vy = *palPtr++; - colour.vz = *palPtr++; - mag = Magnitude(&colour); - - if (mag!=0) - { - colour.vx = (colour.vx*32)/mag; - colour.vy = (colour.vy*32)/mag; - colour.vz = (colour.vz*32)/mag; - } - ColourTable[i].Magnitude = mag; - ColourTable[i].Direction = colour; - } - - for(i = 0; i < 256; i++) - { - int entry; - int brightest=0; - - for(entry = 0; entry < 256; entry++) - { - VECTORCH v1 = ColourTable[i].Direction; - VECTORCH v2 = ColourTable[entry].Direction; - - if ((v1.vx == v2.vx) - &&(v1.vy == v2.vy) - &&(v1.vz == v2.vz) - &&(ColourTable[i].Magnitude < ColourTable[entry].Magnitude) - &&(ColourTable[brightest].Magnitude > ColourTable[entry].Magnitude ||(!brightest))) - brightest = entry; - } - if (brightest==0) - { - for(entry = 0; entry < 256; entry++) - { - VECTORCH v1 = ColourTable[i].Direction; - VECTORCH v2 = ColourTable[entry].Direction; - - if ((v1.vx>>2 == v2.vx>>1) - &&(v1.vy>>2 == v2.vy>>1) - &&(v1.vz>>2 == v2.vz>>1) - &&(ColourTable[i].Magnitude < ColourTable[entry].Magnitude) - &&(ColourTable[brightest].Magnitude > ColourTable[entry].Magnitude ||(!brightest))) - - brightest = entry; - } - } - - if (brightest==0) - { - for(entry = 0; entry < 256; entry++) - { - VECTORCH v1 = ColourTable[i].Direction; - VECTORCH v2 = ColourTable[entry].Direction; - - if ((v1.vx>>2 == v2.vx>>2) - &&(v1.vy>>2 == v2.vy>>2) - &&(v1.vz>>2 == v2.vz>>2) - &&(ColourTable[i].Magnitude < ColourTable[entry].Magnitude) - &&(ColourTable[brightest].Magnitude > ColourTable[entry].Magnitude ||(!brightest))) - brightest = entry; - } - } - #if 0 - if (brightest==0) - { - for(entry = 0; entry < 256; entry++) - { - VECTORCH v1 = ColourTable[i].Direction; - VECTORCH v2 = ColourTable[entry].Direction; - - if ((v1.vx>>3 == v2.vx>>3) - &&(v1.vy>>3 == v2.vy>>3) - &&(v1.vz>>3 == v2.vz>>3) - &&(ColourTable[i].Magnitude < ColourTable[entry].Magnitude) - &&(ColourTable[brightest].Magnitude > ColourTable[entry].Magnitude ||(!brightest))) - brightest = entry; - } - } - - #endif - if (brightest==0) brightest = i; - - LighterTable[i] = brightest; - } - - -} - - -void DrawPaletteScreen(void) -{ - int sortedColours[256]; - { - extern unsigned char TestPalette[]; - unsigned char *palPtr = TestPalette; - int i; - - for(i = 0; i < 256; i++) - { - VECTORCH colour; - int mag; - - colour.vx = *palPtr++; - colour.vy = *palPtr++; - colour.vz = *palPtr++; - mag = Magnitude(&colour); - - if (mag!=0) - { - colour.vx = (colour.vx*7)/mag; - colour.vy = (colour.vy*7)/mag; - colour.vz = (colour.vz*7)/mag; - } - ColourTable[i].Magnitude = mag; - ColourTable[i].Direction = colour; - } - - for(i = 0; i<256; i++) - { - int e; - int maxKey=-1; - int selectedEntry=0; - - for (e=0; e<256; e++) - { - int key = ColourTable[e].Direction.vx + ColourTable[e].Direction.vy*64+ColourTable[e].Direction.vz*64*64; - if (key>maxKey) - { - maxKey = key; - selectedEntry = e; - } - else if (key==maxKey) - { - if (ColourTable[e].MagnitudemaxKey) - { - maxKey = key; - selectedEntry = e; - } - else if (key==maxKey) - { - int key2 = ColourTable[e].Direction.vx + ColourTable[e].Direction.vy*64+ColourTable[e].Direction.vz*64*64; - int key3 = ColourTable[selectedEntry].Direction.vx - + ColourTable[selectedEntry].Direction.vy*64 - + ColourTable[selectedEntry].Direction.vz*64*64; - - if (key2>16; - } - } - ChangePalette(TestPalette2); - } - else - { - d3d_light_ctrl.ctrl = LCCM_CONSTCOLOUR; - d3d_light_ctrl.r = fadeLevel; - d3d_light_ctrl.g = fadeLevel; - d3d_light_ctrl.b = fadeLevel; - } -} - -void FadeBetweenPalettes(unsigned char *palPtr, int fadeLevel) -{ - extern unsigned char TestPalette[]; - unsigned char TestPalette3[768]; - { - int x; - for (x=0; x<768; x++) - { - TestPalette3[x] = ( (unsigned int)TestPalette[x]*fadeLevel + (unsigned int)(palPtr[x])*(65536-fadeLevel) )>>16; - } - } - ChangePalette(TestPalette3); -} -void FadePaletteToWhite(unsigned char *palPtr,int fadeLevel) -{ - unsigned char TestPalette3[768]; - { - int x; - for (x=0; x<768; x++) - { - TestPalette3[x] = ( (unsigned int)(palPtr[x])*fadeLevel + 63*(65536-fadeLevel) )>>16; - } - } - ChangePalette(TestPalette3); -} - - -void BlankScreen(void) -{ - extern int ScanDrawMode; - - if (ScanDrawDirectDraw==ScanDrawMode) - { - extern unsigned char *ScreenBuffer; - extern unsigned char TestPalette[]; - unsigned int *screenPtr; - int i; - - screenPtr = (unsigned int *)ScreenBuffer; - i = ScreenDescriptorBlock.SDB_Width * ScreenDescriptorBlock.SDB_Height /4; - do - { - *screenPtr++=0; - } - while(--i); - } - else - { - ColourFillBackBuffer(0); - } - - // FlipBuffers(); -} - - - - -void GenerateReciprocalTable(void) -{ - int i=320; - - do - { - ReciprocalTable[i] = 65536/i; - } - while(--i); -} - - - - -#if 0 -#define NO_OF_STARS 500 -typedef struct -{ - VECTORCH Position; - int Colour; - -} STARDESC; -static STARDESC StarArray[NO_OF_STARS]; -#endif -void CreateStarArray(void) -{ - #if 0 - int i; - extern int sine[],cosine[]; - for(i=0; iVDB_Mat)); - - /* is star within alien (wide) view frustrum ? */ - if((-rotatedPosition.vx <= rotatedPosition.vz*2) - &&(rotatedPosition.vx <= rotatedPosition.vz*2) - &&(-rotatedPosition.vy*2 <= rotatedPosition.vz*3) - &&(rotatedPosition.vy*2 <= rotatedPosition.vz*3)) - { - /* project into screen space */ - int y = (rotatedPosition.vy*(Global_VDB_Ptr->VDB_ProjY))/rotatedPosition.vz+Global_VDB_Ptr->VDB_CentreY; - int x = (rotatedPosition.vx*(Global_VDB_Ptr->VDB_ProjX))/rotatedPosition.vz+Global_VDB_Ptr->VDB_CentreX; - - /* draw pixel of required bit depth */ - if (ScanDrawMode == ScanDrawDirectDraw) - { - /* 8 bit mode */ - *(ScreenBuffer + x + y*BackBufferPitch) = StarArray[i].Colour&255; - } - else - { - /* 16 bit mode */ - *(unsigned short*)(ScreenBuffer + (x*2 + y*BackBufferPitch)) = StarArray[i].Colour; - } - } - } - } - else /* normal frustrum */ - { - for(i=0; iVDB_Mat)); - - /* is star within normal view frustrum ? */ - if((-rotatedPosition.vx <= rotatedPosition.vz) - &&(rotatedPosition.vx <= rotatedPosition.vz) - &&(-rotatedPosition.vy*4 <= rotatedPosition.vz*3) - &&(rotatedPosition.vy*4 <= rotatedPosition.vz*3)) - { - /* project into screen space */ - int y = (rotatedPosition.vy*(Global_VDB_Ptr->VDB_ProjY))/rotatedPosition.vz+Global_VDB_Ptr->VDB_CentreY; - int x = (rotatedPosition.vx*(Global_VDB_Ptr->VDB_ProjX))/rotatedPosition.vz+Global_VDB_Ptr->VDB_CentreX; - - /* draw pixel of required bit depth */ - if (ScanDrawMode == ScanDrawDirectDraw) - { - /* 8 bit mode */ - *(ScreenBuffer + x + y*BackBufferPitch) = StarArray[i].Colour&255; - } - else - { - /* 16 bit mode */ - *(unsigned short*)(ScreenBuffer + (x*2 + y*BackBufferPitch)) = StarArray[i].Colour; - } - } - } - } - - UnlockSurface(); - #endif -} diff --git a/src/win95/krender.h b/src/win95/krender.h deleted file mode 100644 index ebd5dc1..0000000 --- a/src/win95/krender.h +++ /dev/null @@ -1,55 +0,0 @@ -/* If this define is set to a non-zero value then the new scandraws will be used */ -#define KRENDER_ON 1 - -/* prototypes of the replacement scandraw functions */ -extern void KR_ScanDraw_Item_2dTexturePolygon_VideoModeType_8(int *itemptr); -extern void KR_ScanDraw_Item_Gouraud2dTexturePolygon_VideoModeType_8(int *itemptr); -extern void KR_ScanDraw_Item_Gouraud3dTexturePolygon_Linear_S_VideoModeType_8(int *itemptr); -extern void MotionTrackerRotateBlit(void); -extern void MotionTrackerRotateBlit8(void); - - -/*KJL***************************************************** -* Palette fading; a value of 65536 corresponds to normal * -* palette, 0 is completely other (eg. all white). * -*****************************************************KJL*/ -extern void SetPaletteFadeLevel(int fadeLevel); -extern void FadeBetweenPalettes(unsigned char *palPtr, int fadeLevel); -extern void FadePaletteToWhite(unsigned char *palPtr,int fadeLevel); - -/*KJL********************************************* -* Fill the screen with black & flip then repeat. * -*********************************************KJL*/ -extern void BlankScreen(void); - - -/* KJL 16:06:24 04/04/97 - To choose between laced and full screen modes */ -extern int KRenderDrawMode; - - - - - - -extern void KDraw_Item_GouraudPolygon(int *itemptr); -extern void KDraw_Item_2dTexturePolygon(int *itemptr); -extern void KDraw_Item_Gouraud2dTexturePolygon(int *itemptr); -extern void KDraw_Item_Gouraud3dTexturePolygon(int *itemptr); - - - - - - - - - - - - -extern void MakeViewingWindowSmaller(void); -extern void MakeViewingWindowLarger(void); - -/* routines to draw a star filled sky */ -extern void CreateStarArray(void); -extern void DrawStarfilledSky(void); \ No newline at end of file diff --git a/src/win95/objedit.h b/src/win95/objedit.h deleted file mode 100644 index c39b2ec..0000000 --- a/src/win95/objedit.h +++ /dev/null @@ -1,84 +0,0 @@ - -#include "Chunk.hpp" - -#define VECTOR VECTORCH - -struct ChunkMapBlock -{ - char TemplateName[20]; - char TemplateNotes[100]; - int MapType; - int MapShape; - int MapFlags; - int MapFlags2; - int MapFlags3; - int MapCType; - int MapCGameType; - int MapCStrategyS; - int MapCStrategyL; - int MapInteriorType; - int MapLightType; - int MapMass; - VECTOR MapNewtonV; - VECTOR MapOrigin; - int MapViewType; - - int MapVDBData; - int SimShapeList; - - - -}; - -class Map_Block_Chunk : public Chunk -{ -public: - virtual size_t size_chunk() - { - return (chunk_size=216); - } - virtual BOOL output_chunk (HANDLE &); - - virtual void fill_data_block (char * data_start); - - ChunkMapBlock map_data; - friend class Object_Project_Data_Chunk; - - Map_Block_Chunk (Object_Project_Data_Chunk * parent) - :Chunk(parent,"MAPBLOCK") - {} -private: - - //constructor from buffer - Map_Block_Chunk (Object_Project_Data_Chunk * parent,const char* data); -}; - -struct ChunkStrategy -{ - char StrategyName[20]; - char StrategyNotes[100]; - int Strategy; -}; - -class Strategy_Chunk : public Chunk -{ -public : - virtual size_t size_chunk() - { - return (chunk_size=136); - } - virtual BOOL output_chunk (HANDLE &); - - virtual void fill_data_block (char * data_start); - - ChunkStrategy strategy_data; - friend class Object_Project_Data_Chunk; - - Strategy_Chunk(Object_Project_Data_Chunk *parent) - :Chunk(parent,"STRATEGY") - {} -private: - - //constructor from buffer - Strategy_Chunk (Object_Project_Data_Chunk * parent,const char* data); -}; diff --git a/src/win95/plspecfn.c b/src/win95/plspecfn.c index 0efb61e..1032ca0 100644 --- a/src/win95/plspecfn.c +++ b/src/win95/plspecfn.c @@ -13,7 +13,6 @@ #if SupportWindows95 -#include "krender.h" /* KJL 10:48:25 02/05/97 */ #include "kzsort.h" #include "kshape.h" #endif diff --git a/src/win95/smsopt.h b/src/win95/smsopt.h deleted file mode 100644 index 614b415..0000000 --- a/src/win95/smsopt.h +++ /dev/null @@ -1,40 +0,0 @@ -//------------------------------------------------------------------- -// DESCRIPTION: SMSOPT.H - Options for SMS compilation -// -// AUTHOR: Mark Tolley -// -// HISTORY: Created 19th Sept 1996 -// -//------------------------------------------------------------------- - -// Incorporated into sndmanag.h and xxxxxsnd.h - -#ifndef SMSOPT_H -#define SMSOPT_H - - -// #DEFINES -// General switches -#define SOUND_ON 0 // Compile sound commands in main game code -#define SOUND_3D 1 // Compile 3D sound functions - - // (NB switching this off makes SMS independent of 3DC) - -// Platform switches - ONLY ONE OF THESE SHOULD BE ON!! -#define SMS_SATURN 0 // Compile SMS for Saturn -#define SMS_PSX 0 // Compile SMS for PSX -#define SMS_PCDOS 0 // Compile SMS for PC-DOS -#define SMS_WIN32 1 // Compile SMS for PC-Win95 - -// Sound source switches -#define MIDI_ON 1 // Compile MIDI-specific code -#define DIGI_ON 1 // Compile WAV-specific code -#define CDDA_ON 1 // Compile CDDA-specific code - -// Any other sound-specific compiler switches -#define SMS_FORCE_PENTIUM_TO_DOS_QUALITY 0 // Forces Pentium to use - // DOS quality sound. May help to speed things - // up... NB 3D SOUND WON'T WORK PROPERLY -#define SMS_TIMER 1 // Implement timing for ONEHI. Relies on NormalFrameTime -#endif // SMSOPT_H -// END OF FILE