245 lines
6.5 KiB
C++
245 lines
6.5 KiB
C++
|
|
#include <gl\glaux.h>
|
|
#include <ddraw.h>
|
|
|
|
#include "vgs.hpp"
|
|
#include "file.hpp"
|
|
#include "main.hpp"
|
|
#include "effects.hpp"
|
|
|
|
|
|
#include <time.h>
|
|
|
|
clock_t __clock__(void)
|
|
{
|
|
//return timeGetTime();
|
|
return clock();
|
|
}
|
|
|
|
#define clock __clock__
|
|
|
|
static Game game;
|
|
|
|
DDPIXELFORMAT pixformat;
|
|
LPDIRECTDRAW lpDD; // DirectDraw object
|
|
LPDIRECTDRAWSURFACE lpDDSPrimary; // DirectDraw primary surface
|
|
LPDIRECTDRAWSURFACE lpDDSBack; // DirectDraw back surface
|
|
DDSURFACEDESC ddsd;
|
|
DDSCAPS ddscaps;
|
|
|
|
float
|
|
GamePixelWidth(void)
|
|
{
|
|
return ((float)game.fb.width / (float)game.fb.height) / (320.0f / 240.0f);
|
|
}
|
|
|
|
void CALLBACK
|
|
MainLoop(void)
|
|
{
|
|
}
|
|
|
|
static Pixel table[0x10000];
|
|
|
|
void
|
|
GammaTableCreate(int dst[], int n, float gamma)
|
|
{
|
|
gamma = 1.0f / gamma;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
dst[i] = (int) (pow(i / (n - 1.0f), gamma) * (n - 1.0f) + 0.5f);
|
|
}
|
|
}
|
|
|
|
void
|
|
SetupTable(float rg, float gg, float bg)
|
|
{
|
|
int gamma_r[32], gamma_g[32], gamma_b[32];
|
|
|
|
GammaTableCreate(gamma_r, 32, rg);
|
|
GammaTableCreate(gamma_g, 32, gg);
|
|
GammaTableCreate(gamma_b, 32, bg);
|
|
|
|
for (int i = 0; i < 0x10000; i++)
|
|
{
|
|
int r = gamma_r[PixelRed(i)];
|
|
int g = gamma_g[PixelGreen(i)];
|
|
int b = gamma_b[PixelBlue(i)];
|
|
|
|
table[i] = (Pixel)(
|
|
(r * ((pixformat.dwRBitMask / 31)) & pixformat.dwRBitMask) |
|
|
(g * ((pixformat.dwGBitMask / 31)) & pixformat.dwGBitMask) |
|
|
(b * ((pixformat.dwBBitMask / 31)) & pixformat.dwBBitMask) );
|
|
}
|
|
}
|
|
|
|
static void CALLBACK
|
|
TakeScreenShot(void)
|
|
{
|
|
PictureSavePPM(&game.fb, "screen.ppm");
|
|
}
|
|
|
|
static int gamma_level = 9;
|
|
|
|
static void CALLBACK
|
|
IncreaseGamma(void)
|
|
{
|
|
gamma_level = (gamma_level + 1) & 0x1F;
|
|
|
|
float g = gamma_level * 0.1f;
|
|
|
|
SetupTable(g, g, g);
|
|
}
|
|
|
|
static void CALLBACK
|
|
DecreaseGamma(void)
|
|
{
|
|
gamma_level = (gamma_level - 1) & 0x1F;
|
|
|
|
float g = gamma_level * 0.1f;
|
|
|
|
SetupTable(g, g, g);
|
|
}
|
|
|
|
void CALLBACK
|
|
IdleFunc(void)
|
|
{
|
|
POINT point;
|
|
|
|
for (int i = 0; i < 100 && game.timer_count < (clock() >> 2); game.timer_count++, i++)
|
|
{
|
|
GetCursorPos(&point);
|
|
SetCursorPos(game.fb.width >> 1, game.fb.height >> 1);
|
|
|
|
game.mousevel.x = point.x - (game.fb.width >> 1);
|
|
game.mousevel.y = point.y - (game.fb.height >> 1);
|
|
game.mousepos.x = Clamp(game.mousepos.x + game.mousevel.x, 0, game.fb.width - 1);
|
|
game.mousepos.y = Clamp(game.mousepos.y + game.mousevel.y, 0, game.fb.height - 1);
|
|
|
|
game.keyboard[KB_LTARROW] = GetAsyncKeyState(VK_LEFT ) < 0;
|
|
game.keyboard[KB_RTARROW] = GetAsyncKeyState(VK_RIGHT ) < 0;
|
|
game.keyboard[KB_UPARROW] = GetAsyncKeyState(VK_UP ) < 0;
|
|
game.keyboard[KB_DNARROW] = GetAsyncKeyState(VK_DOWN ) < 0;
|
|
game.keyboard[KB_SPACE ] = GetAsyncKeyState(VK_SPACE ) < 0;
|
|
game.keyboard[KB_CTRL ] = GetAsyncKeyState(VK_CONTROL) < 0;
|
|
game.keyboard[0x1E] = GetAsyncKeyState('A' ) < 0;
|
|
game.keyboard[0x2C] = GetAsyncKeyState('Z' ) < 0;
|
|
game.keyboard[KB_C] = GetAsyncKeyState('C' ) < 0;
|
|
|
|
GameMotion(&game);
|
|
}
|
|
GameRender(&game);
|
|
|
|
if (lpDDSPrimary->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL) == DD_OK)
|
|
{
|
|
char* surface = (char*) ddsd.lpSurface;
|
|
|
|
for (int i = 0; i < game.fb.height; i++)
|
|
{
|
|
Pixel* I = game.fb.pixels[i];
|
|
Pixel* O = (Pixel*) surface;
|
|
|
|
#undef AFFINE
|
|
#define AFFINE *O++ = table[*I++];
|
|
|
|
int j = game.fb.width; while (j--) {AFFINE;}
|
|
|
|
surface += ddsd.lPitch;
|
|
}
|
|
lpDDSPrimary->Unlock(ddsd.lpSurface);
|
|
}
|
|
}
|
|
|
|
#include <i86.h>
|
|
void
|
|
SpecialPrint(char* s)
|
|
{
|
|
int i = strlen(s);
|
|
|
|
while (i--)
|
|
{
|
|
printf("%s\r", &s[i]);
|
|
fflush(stdout);
|
|
delay(1);
|
|
}
|
|
printf("\n");
|
|
}
|
|
/*******************************************************************************
|
|
** main
|
|
*******************************************************************************/
|
|
void
|
|
Main(void)
|
|
{
|
|
printf("\n\n");
|
|
|
|
SpecialPrint("##### #### #### ### ### ## #### ## ");
|
|
SpecialPrint("## ## ## ## ## ## #### #### ### ## ## ### ");
|
|
SpecialPrint("## ## ## ## ## ## ## ### ## #### ## ### #### ");
|
|
SpecialPrint("##### ## ## ## ## ## # ## ## ###### ## ");
|
|
SpecialPrint("## ## ## ## ## ## ## ## ## ### ## ## ");
|
|
SpecialPrint("## ## ## ## ## ## ## ## ## ## ## ## ");
|
|
SpecialPrint("## ## #### #### ## ## ###### #### ######");
|
|
|
|
printf(
|
|
"\n\n (c) 1999-2000 by Derek J. Evans\n\n"
|
|
"This software is >>FREEWARE<<. USE AT YOUR OWN RISK.\n"
|
|
"All software containing source code taken from Room101,\n"
|
|
"should indicate so. Other than that, go nuts!\n"
|
|
"Please contact me for updates & bug reports. Thankyou.\n\n"
|
|
);
|
|
|
|
int width = atoi(FindArg("WIDTH" , NULL, "320"));
|
|
int height = atoi(FindArg("HEIGHT", NULL, "200"));
|
|
|
|
printf("Width: %d Height: %d\n", width, height);
|
|
|
|
PictureCreate(&game.fb, width, height);
|
|
PictureCreate(&game.zb, width, height);
|
|
|
|
game.mousepos.x = game.fb.width >> 1;
|
|
game.mousepos.y = game.fb.height >> 1;
|
|
|
|
GameCreate(&game);
|
|
|
|
auxInitPosition(0, 0, width, height);
|
|
auxInitWindow ("Room101 Graphics Library");
|
|
|
|
ShowCursor(FALSE);
|
|
|
|
DirectDrawCreate(NULL, &lpDD, NULL);
|
|
|
|
lpDD->SetCooperativeLevel(auxGetHWND(), DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
|
|
|
|
lpDD->SetDisplayMode(width, height, 16);
|
|
|
|
ddsd.dwSize = sizeof(ddsd);
|
|
ddsd.dwFlags = DDSD_CAPS;
|
|
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
|
|
|
lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL );
|
|
|
|
pixformat.dwSize = sizeof(DDPIXELFORMAT);
|
|
|
|
lpDDSPrimary->GetPixelFormat(&pixformat);
|
|
|
|
IncreaseGamma();
|
|
|
|
auxKeyFunc(AUX_0, IncreaseGamma );
|
|
auxKeyFunc(AUX_9, DecreaseGamma );
|
|
auxKeyFunc(AUX_p, TakeScreenShot);
|
|
|
|
|
|
auxIdleFunc(IdleFunc);
|
|
|
|
game.timer_count = (clock() >> 2);
|
|
|
|
auxMainLoop(MainLoop);
|
|
|
|
PictureDelete(&game.fb);
|
|
PictureDelete(&game.zb);
|
|
|
|
if (lpDDSPrimary) lpDDSPrimary->Release();
|
|
if (lpDD) lpDD->Release();
|
|
}
|
|
|
|
|