|
VoxEd Source Code
Submitted by |
Hey guys this is the source of my Voxel Engine. It doesn't include the data files, so you may
not compile a working program with it, but you can look at it and send me feedback.
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [RESOURCE.H] - (1,267 bytes)
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by LandEd.rc
//
#define IDI_ICON 101
#define IDI_CURSOR 102
#define IDI_CROSS 103
#define IDI_FINGER 108
#define IDI_STOP 108
#define IDI_PINPET 109
#define IDR_ACCELERATOR1 110
#define IDI_UP 113
#define IDI_DOWN 114
#define IDI_RIGHT 115
#define IDI_LEFT 116
#define IDI_UPLEFT 118
#define IDI_UPRIGHT 119
#define IDI_DOWNRIGHT 120
#define IDI_DOWNLEFT 121
#define IDI_CLOCK 122
#define IDI_LEFTRIGHT 123
#define IDI_UPDOWN 124
#define ID_ACCEL40001 40001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 128
#define _APS_NEXT_COMMAND_VALUE 40002
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CCheckBox.cpp] - (1,493 bytes)
// CCheckBox.cpp
// by Comanche
#include "CCheckBox.h"
#include "CMain.h"
#include "CGraphics.h"
extern CMain GameMain;
extern CGraphics Graphics;
//////////////////////////////////////////////////////////////////////////////////
CCheckBox::CCheckBox(int x,int y,char *string)
{
Cx=x; Cy=y;
redraw=TRUE;
sprintf(caption,"%s",string);
State=FALSE;
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CCheckBox::RedrawCheckBox()
{
redraw=TRUE;
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CCheckBox::TestIfPressed()
{
Graphics.logfont.lfHeight = CHECKBOXFONTHEIGHT;
if(GameMain.CheckMouseRange(Cx,Cy,Cx+11,Cy+11,TRUE))
{
if(State)
{
State=FALSE;
Graphics.Lock();
Graphics.DrawCheckBoxOff(Cx,Cy);
Graphics.UnLock();
}
else
{
State=TRUE;
Graphics.Lock();
Graphics.DrawCheckBoxOn(Cx,Cy);
Graphics.UnLock();
}
while(GameMain.MouseB[0])
GameMain.GetMouseInfo();
}
if(redraw)
{
redraw=FALSE;
Graphics.Lock();
if(State)
Graphics.DrawCheckBoxOn(Cx,Cy);
else
Graphics.DrawCheckBoxOff(Cx,Cy);
Graphics.UnLock();
Graphics.OSGetLaDC();
Graphics.Text(Cx+16,Cy-2,caption);
Graphics.OSReleaseDC();
}
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CColor.cpp] - (1,993 bytes)
// CColor.cpp
// by Comanche
#include "CColor.h"
#include "CMain.h"
#include "CLog.h"
#include "CGraphics.h"
extern CMain GameMain;
extern CLog Log;
extern CGraphics Graphics;
//////////////////////////////////////////////////////////////////////////////////
CColor::CColor()
{
redpos=100;
greenpos=100;
bluepos=100;
}
//////////////////////////////////////////////////////////////////////////////////
void CColor::DrawColors()
{
Graphics.Lock();
Graphics.Quader(2,72,32,143,100,100,100);
Graphics.Quader(35,72,65,143,100,100,100);
Graphics.Quader(68,72,98,143,100,100,100);
for(int i=0;i<=6;i++)
{
Graphics.FullQuader(3,72+(i*10),31,82+(i*10),redpos+i,0,0);
Graphics.FullQuader(36,72+(i*10),64,82+(i*10),0,greenpos+i,0);
Graphics.FullQuader(69,72+(i*10),97,82+(i*10),0,0,bluepos+i);
}
Graphics.Quader(3,168,97,208,0,0,0);
Graphics.FullQuader(4,169,96,207,color.rgbtRed,color.rgbtGreen,color.rgbtBlue);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
void CColor::TestIfPressed()
{
Graphics.Lock();
if(GameMain.MouseX>=3 && GameMain.MouseX<=32 &&
GameMain.MouseY>=72 && GameMain.MouseY<=142 && GameMain.MouseB[0])
{
int y=GameMain.MouseY-72;
color.rgbtRed=redpos+(y/10);
Graphics.FullQuader(4,169,96,207,color.rgbtRed,color.rgbtGreen,color.rgbtBlue);
}
if(GameMain.MouseX>=36 && GameMain.MouseX<=64 &&
GameMain.MouseY>=72 && GameMain.MouseY<=142 && GameMain.MouseB[0])
{
int y=GameMain.MouseY-72;
color.rgbtGreen=greenpos+(y/10);
Graphics.FullQuader(4,169,96,207,color.rgbtRed,color.rgbtGreen,color.rgbtBlue);
}
if(GameMain.MouseX>=69 && GameMain.MouseX<=97 &&
GameMain.MouseY>=72 && GameMain.MouseY<=142 && GameMain.MouseB[0])
{
int y=GameMain.MouseY-72;
color.rgbtBlue=bluepos+(y/10);
Graphics.FullQuader(4,169,96,207,color.rgbtRed,color.rgbtGreen,color.rgbtBlue);
}
Graphics.UnLock();
} |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CGraphics.cpp] - (17,959 bytes)
// CGraphics.cpp
// by Comanche
#include "CGraphics.h"
#include "CMain.h"
#include "CLog.h"
#include "CTime.h"
#include "CLandScape.h"
#include "CVoxel.h"
#include "CCheckBox.h"
#include "CLiquid.h"
extern CMain GameMain;
extern CLog Log;
extern CTime Time;
extern CLandScape Land;
extern CVoxel Voxel;
extern CCheckBox *CheckBoxes[20];
extern CLiquid *Liquids[128];
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::Lock()
{
GameMain.lpddsos1->Lock(NULL,&GameMain.ddsd,DDLOCK_WAIT,NULL);
video_buffer = (BYTE*)GameMain.ddsd.lpSurface;
WordsPerLine = (GameMain.ddsd.lPitch);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::UnLock()
{
GameMain.lpddsos1->Unlock(NULL);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::LockBackBuffer()
{
GameMain.lpddsback->Lock(NULL,&GameMain.ddsd,DDLOCK_WAIT,NULL);
video_buffer = (BYTE*)GameMain.ddsd.lpSurface;
WordsPerLine = (GameMain.ddsd.lPitch);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::UnLockBackBuffer()
{
GameMain.lpddsback->Unlock(NULL);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::Flip()
{
GetDC();
if(!CheckBoxes[1]->State)
sprintf(buffer,"%d FPS",Time.GetFPS(Time.GetFrameTime()));
else sprintf(buffer,"%d VPF",Land.vps);
Text(50,237,buffer);
if(GameMain.Editor==0)
{
if(!CheckBoxes[2]->State)
sprintf(buffer,"%d,%d",Land.ScreenPosX,Land.ScreenPosY);
else
{
if(GameMain.ActiveLiquid<0)
{
sprintf(buffer,"%d",GameMain.ActiveLiquid);
}
else
{
sprintf(buffer,"%d,%d",GameMain.ActiveLiquid,
Liquids[GameMain.ActiveLiquid]->height);
}
}
Text(50,217,buffer);
}
if(GameMain.Editor==1)
{
sprintf(buffer,"%d,%d",Voxel.ViewX,Voxel.ViewY);
Text(50,217,buffer);
}
ReleaseDC();
GameMain.lpddsprimary->Flip(GameMain.lpddsback, DDFLIP_WAIT);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::BltToBackBuffer()
{
GameMain.lpddsback->BltFast(0,0,GameMain.lpddsos1,NULL,DDBLTFAST_WAIT|DDBLTFAST_NOCOLORKEY);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::GetDC()
{
GameMain.lpddsback->GetDC(&xdc);
Arial=CreateFontIndirect(&logfont);
if(DrawFont) SelectObject(xdc,Arial);
SetTextColor(xdc,RGB(textcolor.rgbtGreen,textcolor.rgbtGreen,textcolor.rgbtBlue));
SetBkMode(xdc, TRANSPARENT);
SetTextAlign(xdc,TA_CENTER);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::GetLaDC()
{
GameMain.lpddsback->GetDC(&xdc);
Arial=CreateFontIndirect(&logfont);
if(DrawFont) SelectObject(xdc,Arial);
SetTextColor(xdc,RGB(textcolor.rgbtGreen,textcolor.rgbtGreen,textcolor.rgbtBlue));
SetBkMode(xdc, TRANSPARENT);
SetTextAlign(xdc,TA_LEFT);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::ReleaseDC()
{
GameMain.lpddsback->ReleaseDC(xdc);
DeleteObject(Arial);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::OSGetDC()
{
GameMain.lpddsos1->GetDC(&xdc);
Arial=CreateFontIndirect(&logfont);
if(DrawFont) SelectObject(xdc,Arial);
SetTextColor(xdc,RGB(textcolor.rgbtGreen,textcolor.rgbtGreen,textcolor.rgbtBlue));
SetBkMode(xdc, TRANSPARENT);
SetTextAlign(xdc,TA_CENTER);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::OSGetLaDC()
{
GameMain.lpddsos1->GetDC(&xdc);
Arial=CreateFontIndirect(&logfont);
if(DrawFont) SelectObject(xdc,Arial);
SetTextColor(xdc,RGB(textcolor.rgbtGreen,textcolor.rgbtGreen,textcolor.rgbtBlue));
SetBkMode(xdc, TRANSPARENT);
SetTextAlign(xdc,TA_LEFT);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::OSReleaseDC()
{
GameMain.lpddsos1->ReleaseDC(xdc);
DeleteObject(Arial);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::RestorePrimarySurface()
{
if (GameMain.lpddsos1->IsLost()!=DD_OK)
GameMain.lpddsos1->Restore();
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::RestoreOffScreenSurface()
{
if (GameMain.lpddsprimary->IsLost()!=DD_OK)
GameMain.lpddsprimary->Restore();
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::Blt(int x,int y,int x2,int y2,int vx, int vy)
{
RECT source;
source.left=x;
source.right=x2;
source.top=y;
source.bottom=y2;
GameMain.lpddsos1->BltFast(x+vx,y+vy,GameMain.lpddsos1,&source,NULL);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::Text(int x,int y,char *string)
{
int len=strlen(string);
TextOut(xdc,x,y,string,len);
}
//////////////////////////////////////////////////////////////////////////////////
__declspec(naked) void CGraphics::PutPixel(int x,int y,BYTE red,BYTE green,BYTE blue)
{
__asm
{
push ebp
mov ebp,esp
push eax
push ebx
mov eax,y
mov ebx,x
mul WordsPerLine
lea eax,[eax+ebx*4]
add eax,video_buffer
mov bl,blue
mov BYTE PTR [eax],bl
inc eax
mov bl,green
mov BYTE PTR [eax],bl
inc eax
mov bl,red
mov BYTE PTR [eax],bl
pop ebx
pop eax
mov esp,ebp
pop ebp
ret 14h
}
}
//////////////////////////////////////////////////////////////////////////////////
__declspec(naked) void CGraphics::PutSafePixel(int x,int y,BYTE red,BYTE green,BYTE blue)
{
__asm
{
push ebp
mov ebp,esp
push eax
push ebx
mov ebx,x
mov eax,y
cmp eax,0
jl end
cmp eax,479
jg end
cmp ebx,101
jl end
cmp ebx,559
jg end
mul WordsPerLine
lea eax,[eax+ebx*4]
add eax,video_buffer
mov bl,blue
mov BYTE PTR [eax],bl
inc eax
mov bl,green
mov BYTE PTR [eax],bl
inc eax
mov bl,red
mov BYTE PTR [eax],bl
end: pop ebx
pop eax
mov esp,ebp
pop ebp
ret 14h
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::Quader(int x,int y,int x2,int y2,
BYTE red,BYTE green,BYTE blue)
{
int i;
for (i=x;i<=x2;i++)
{
PutPixel(i,y,red,green,blue);
PutPixel(i,y2,red,green,blue);
}
for (i=y;i<=y2;i++)
{
PutPixel(x,i,red,green,blue);
PutPixel(x2,i,red,green,blue);
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::FullQuader(int x,int y,int x2,int y2,
BYTE red,BYTE green,BYTE blue)
{
__asm
{
push eax
push ebx
push ecx
push edx
mov eax,x
mov ebx,x2
cmp eax,ebx
jg end
mov eax,y
mov ebx,y2
cmp eax,ebx
jg end
mov eax,y
mov ebx,x
mul WordsPerLine
lea eax,[eax+ebx*4]
add eax,video_buffer
mov edx,x2
sub edx,x
mov ecx,y2
sub ecx,y
jmp1: push ecx
push eax
mov ecx,edx
jmp2: mov bl,blue
mov BYTE PTR [eax],bl
inc eax
mov bl,green
mov BYTE PTR [eax],bl
inc eax
mov bl,red
mov BYTE PTR [eax],bl
add eax,2
loop jmp2
pop eax
pop ecx
add eax,WordsPerLine
loop jmp1
end: pop eax
pop ebx
pop edx
pop ecx
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::BlackQuader(int x,int y,int x2,int y2)
{
DDBLTFX ddbltfx;
RECT rect;
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0;
rect.left=x;
rect.right=x2;
rect.top=y;
rect.bottom=y2;
GameMain.lpddsos1->Blt(&rect,NULL,NULL,DDBLT_COLORFILL,&ddbltfx);
}
//////////////////////////////////////////////////////////////////////////////////
__declspec(naked) void CGraphics::PutTransPixel(int x,int y,BYTE red,BYTE green,BYTE blue)
{
__asm
{
push ebp
mov ebp,esp
push eax
push ebx
push ecx
mov ebx,x
mov eax,y
mul WordsPerLine
lea eax,[eax+ebx*4]
add eax,video_buffer
movzx ebx,BYTE PTR [eax]
movzx ecx,blue
add ebx,ecx
shr ebx,1
mov BYTE PTR [eax],bl
inc eax
movzx ebx,BYTE PTR [eax]
movzx ecx,green
add ebx,ecx
shr ebx,1
mov BYTE PTR [eax],bl
inc eax
movzx ebx,BYTE PTR [eax]
movzx ecx,red
add ebx,ecx
shr ebx,1
mov BYTE PTR [eax],bl
pop ecx
pop ebx
pop eax
mov esp,ebp
pop ebp
ret 14h
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::FullTransQuader(int x,int y,int x2,int y2,
BYTE red,BYTE green,BYTE blue)
{
BYTE color[8];
__asm
{
push eax
push ebx
push ecx
push edx
mov eax,x
mov ebx,x2
cmp eax,ebx
jg end
mov eax,y
mov ebx,y2
cmp eax,ebx
jg end
mov al,blue
mov bl,green
mov cl,red
mov BYTE PTR [color],al
mov BYTE PTR [color+1],bl
mov BYTE PTR [color+2],cl
mov BYTE PTR [color+3],0
mov BYTE PTR [color+4],al
mov BYTE PTR [color+5],bl
mov BYTE PTR [color+6],cl
mov BYTE PTR [color+7],0
pxor mm4,mm4
mov eax,y
mov ebx,x
mul WordsPerLine
lea eax,[eax+ebx*4]
add eax,video_buffer
mov edx,x2
sub edx,x
mov ecx,y2
sub ecx,y
movq mm5,color
jmp1: push ecx
push eax
mov ecx,edx
jmp2: dec ecx
jz jmp3
movq mm0,BYTE PTR [eax]
movq mm1,mm0
movq mm2,mm5
movq mm3,mm5
punpckhbw mm0,mm4
punpcklbw mm1,mm4
punpckhbw mm2,mm4
punpcklbw mm3,mm4
paddw mm0,mm2
paddw mm1,mm3
psrlw mm0,1
psrlw mm1,1
packuswb mm1,mm0
movq BYTE PTR [eax],mm1
add eax,8
loop jmp2
pop eax
pop ecx
add eax,WordsPerLine
loop jmp1
jmp end
jmp3: movd mm0,BYTE PTR [eax]
movd mm1,BYTE PTR [eax]
movd mm2,color
movd mm3,color
punpckhbw mm0,mm4
punpcklbw mm1,mm4
punpckhbw mm2,mm4
punpcklbw mm3,mm4
paddw mm0,mm2
paddw mm1,mm3
psrlw mm0,1
psrlw mm1,1
packuswb mm1,mm0
movd BYTE PTR [eax],mm1
pop eax
pop ecx
add eax,WordsPerLine
loop jmp1
end: pop eax
pop ebx
pop edx
pop ecx
emms
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::FullBrightQuader(int x,int y,int x2,int y2,BYTE red,BYTE green,BYTE blue)
{
BYTE color[8];
__asm
{
push eax
push ebx
push ecx
push edx
mov eax,x
mov ebx,x2
cmp eax,ebx
jg end
mov eax,y
mov ebx,y2
cmp eax,ebx
jg end
mov al,blue
mov bl,green
mov cl,red
mov BYTE PTR [color],al
mov BYTE PTR [color+1],bl
mov BYTE PTR [color+2],cl
mov BYTE PTR [color+3],0
mov BYTE PTR [color+4],al
mov BYTE PTR [color+5],bl
mov BYTE PTR [color+6],cl
mov BYTE PTR [color+7],0
mov eax,y
mov ebx,x
mul WordsPerLine
lea eax,[eax+ebx*4]
add eax,video_buffer
mov edx,x2
sub edx,x
mov ecx,y2
sub ecx,y
movq mm2,color
jmp1: push ecx
push eax
mov ecx,edx
jmp2: dec ecx
jz jmp3
movq mm0,BYTE PTR [eax]
movq mm1,mm2
paddusb mm0,mm1
movq BYTE PTR [eax],mm0
add eax,8
loop jmp2
pop eax
pop ecx
add eax,WordsPerLine
loop jmp1
jmp end
jmp3: movd mm0,BYTE PTR [eax]
movd mm1,mm2
paddusb mm0,mm1
movq BYTE PTR [eax],mm0
pop eax
pop ecx
add eax,WordsPerLine
loop jmp1
end: pop eax
pop ebx
pop edx
pop ecx
emms
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::Line(int x,int y,int x2,int y2,BYTE red,BYTE green,BYTE blue)
{
int lenx,leny;
if(x>x2) lenx=x-x2;
else lenx=x2-x;
if(y>y2) leny=y-y2;
else leny=y2-y;
if (lenx>leny)
{
float c=(float)(lenx)/(float)(leny);
int i=0;
while(y<=y2)
{
i++;y++;
for(int i2=0;i2<=((i+1)*c)-(i*c);i2++)
PutPixel((x+(float)(i*c))+i2,y,red,green,blue);
}
return;
}
else
{
float c=(float)(leny)/(float)(lenx);
int i=0;
while(x<=x2)
{
i++;x++;
for(int i2=0;i2<=c;i2++)
PutPixel(x,(y+(float)(i*c))-i2,red,green,blue);
}
}
}
//////////////////////////////////////////////////////////////////////////////////
/*void CGraphics::Line(int x,int y,int x2,int y2,BYTE red,BYTE green,BYTE blue)
{
if(x2>x) int len=x2-x;
if(x2==x) int len=0;
if(x2<x) int len=x-x2;
if(y2>y) int len2=y2-y;
if(y2==y) int len2=0;
if(y2<y) int len2=y-y2;
if(len==len2) return();
if(len>len2)
{
if(y>y2) c=y2;
if(y<y2) c=y;
for(int i=1; i<=len; i++)
{
float b=len2/i;
PutPixel(i,b,red,green,blue);
}
}
}*/
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::HLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue)
{
__asm
{
push eax
push ebx
push ecx
mov ebx,x
mov eax,y
shl ebx,2
mul WordsPerLine
add eax,ebx
add eax,video_buffer
mov ecx,p
inc ecx
jmp1: mov bl,blue
mov BYTE PTR [eax],bl
inc eax
mov bl,green
mov BYTE PTR [eax],bl
inc eax
mov bl,red
mov BYTE PTR [eax],bl
sub eax,2
add eax,WordsPerLine
loop jmp1
pop ecx
pop ebx
pop eax
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::VLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue)
{
__asm
{
push eax
push ebx
push ecx
mov ebx,x
mov eax,y
shl ebx,2
mul WordsPerLine
add eax,ebx
add eax,video_buffer
mov ecx,p
jmp1: mov bl,blue
mov BYTE PTR [eax],bl
inc eax
mov bl,green
mov BYTE PTR [eax],bl
inc eax
mov bl,red
mov BYTE PTR [eax],bl
add eax,2
loop jmp1
pop ecx
pop ebx
pop eax
}
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::TransHLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue)
{
for(int i=0;i<=p;i++)
PutTransPixel(x,y+i,red,green,blue);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::TransVLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue)
{
for(int i=0;i<=p;i++)
PutTransPixel(x+i,y,red,green,blue);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::DrawButton(int x,int y,int x2,int y2)
{
FullQuader(x,y,x2,y2,150,150,150);
VLine(x,y,x2-x,200,200,200);
VLine(x+1,y+1,x2-x-2,170,170,170);
HLine(x,y,y2-y-1,200,200,200);
HLine(x+1,y+1,y2-y-3,170,170,170);
VLine(x,y2,x2-x,10,10,10);
VLine(x+1,y2-1,x2-x-2,80,80,80);
HLine(x2,y,y2-y,10,10,10);
HLine(x2-1,y+1,y2-y-2,80,80,80);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::DrawPushedButton(int x,int y,int x2,int y2)
{
FullQuader(x+1,y+1,x2-1,y2-1,150,150,150);
VLine(x,y,x2-x,10,10,10);
VLine(x+1,y+1,x2-x-1,80,80,80);
HLine(x,y,y2-y,10,10,10);
HLine(x+1,y+1,y2-y-2,80,80,80);
VLine(x,y2,x2-x,200,200,200);
VLine(x+1,y2-1,x2-x-2,170,170,170);
HLine(x2,y,y2-y,200,200,200);
HLine(x2-1,y+1,y2-y-2,190,170,170);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::DrawCheckBoxOff(int x,int y)
{
FullQuader(x+1,y+1,x+10,y+10,220,220,220);
VLine(x,y,11,10,10,10);
VLine(x+1,y+1,10,80,80,80);
HLine(x,y,11,10,10,10);
HLine(x+1,y+1,9,80,80,80);
VLine(x,y+11,11,200,200,200);
VLine(x+1,y+10,9,170,170,170);
HLine(x+11,y,11,200,200,200);
HLine(x+10,y+1,9,190,170,170);
}
//////////////////////////////////////////////////////////////////////////////////
void CGraphics::DrawCheckBoxOn(int x,int y)
{
FullQuader(x+1,y+1,x+10,y+10,220,220,220);
VLine(x,y,11,10,10,10);
VLine(x+1,y+1,10,80,80,80);
HLine(x,y,11,10,10,10);
HLine(x+1,y+1,9,80,80,80);
VLine(x,y+11,11,200,200,200);
VLine(x+1,y+10,9,170,170,170);
HLine(x+11,y,11,200,200,200);
HLine(x+10,y+1,9,190,170,170);
for(int i=0;i<5;i++)
{
PutPixel(x+3+i,y+4+i,75,75,75);
PutPixel(x+4+i,y+3+i,75,75,75);
PutPixel(x+8-i,y+4+i,75,75,75);
PutPixel(x+7-i,y+3+i,75,75,75);
}
PutPixel(x+3,y+3,75,75,75);
PutPixel(x+3,y+8,75,75,75);
PutPixel(x+8,y+3,75,75,75);
PutPixel(x+8,y+8,75,75,75);
for(i=0;i<4;i++)
{
PutPixel(x+4+i,y+4+i,0,0,0);
PutPixel(x+7-i,y+4+i,0,0,0);
}
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CGraphics::StoreScreenArea(int x,int y,int x2,int y2)
{
x2++;y2++;
Sx=x;Sy=y;Sx2=x2;Sy2=y2;
memset(&GameMain.ddsd,0,sizeof(GameMain.ddsd));
GameMain.ddsd.dwSize = sizeof(GameMain.ddsd);
GameMain.ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
GameMain.ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
GameMain.ddsd.dwWidth = x2-x;
GameMain.ddsd.dwHeight = y2-y;
if(GameMain.lpdd2->CreateSurface(&GameMain.ddsd,&lpddsos2,NULL)!=DD_OK)
{
Log.WriteErrorToLogFile("> Error: Store Screen Area");
return(FALSE);
}
RECT source;
source.left=x;
source.right=x2;
source.top=y;
source.bottom=y2;
if(lpddsos2->BltFast(0,0,GameMain.lpddsos1,&source,NULL)!=DD_OK)
{
lpddsos2->Release();
Log.WriteErrorToLogFile("> Error: Store Screen Area");
return(FALSE);
}
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CGraphics::RestoreScreenArea()
{
if(GameMain.lpddsos1->BltFast(Sx,Sy,lpddsos2,NULL,NULL)!=DD_OK)
{
Log.WriteErrorToLogFile("> Error: Restore Screen Area");
lpddsos2->Release();
return(FALSE);
}
if(lpddsos2!=NULL)
{
lpddsos2->Release();
lpddsos2=NULL;
}
return(TRUE);
} |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CLandScape.cpp] - (41,281 bytes)
// CLandScape.cpp
// by Comanche
#include "CLandScape.h"
#include "CMain.h"
#include "CGraphics.h"
#include "CLog.h"
#include "CTexture.h"
#include "CMenu.h"
#include "CCheckBox.h"
extern CLandScape Land;
extern CMain GameMain;
extern CGraphics Graphics;
extern CLog Log;
extern CTexture *Masks[3];
extern CTexture *Textures[1024];
extern CCheckBox *CheckBoxes[20];
extern CMenu Menu;
//////////////////////////////////////////////////////////////////////////////////
CLandScape::CLandScape()
{
ScreenPosX=0; ScreenPosY=0;
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CLandScape::InitScreen()
{
FillScreen(101,0,559,479);
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
void CLandScape::PutVoxel(int x,int y,int x2,int y2)
{
int red,green,blue;
float multi;
////////////////////////////////////////////////////////////
// Algorithmus //
////////////////////////////////////////////////////////////
// //
// for(int i=64;i>=0;i--) //
// { //
// pointer=(BYTE*)&Landscape[x][y+i]; //
// if((y+i)>1999) continue; //
// height=*(pointer+3); //
// if(height>=i) //
// { //
// float shadow=GetShadow(x,y+i,i); //
// blue=(*pointer)*shadow; //
// if(blue>255) blue=255; //
// green=(*(++pointer))*shadow; //
// if(green>255) green=255; //
// red=(*(++pointer))*shadow; //
// if(red>255) red=255; //
// Graphics.PutPixel(x2,y2,red,green,blue); //
// break; //
// } //
// } //
// //
////////////////////////////////////////////////////////////
__asm
{
mov eax,x // Adresse berechnen
imul eax,8000 // 2000*4 Bytes pro Zeile
mov ebx,y
lea eax,[eax+ebx*4+Land.Landscape+3]
// 3 Bytes dazu weil Höhe Byte 4 im DWORD ist
mov ecx,64 // Counter auf 64 (max-Höhe = 64)
jmp1: mov dl,BYTE PTR [eax+ecx*4] // Höhe laden
cmp dl,cl // und mit Counter vergleichen
jae jmp2 // wenn gleich oder höher jmp2
loop jmp1 // loop (ecx-1)
jmp2: lea eax,[eax+ecx*4-3] // auf Farben gehen (minus 3 Bytes)
xor ebx,ebx // Farben 32-Bit breit speichern wegen FILD
mov bl,BYTE PTR [eax] // Blau
mov blue,ebx
inc eax // Grün
mov bl,BYTE PTR [eax]
mov green,ebx
inc eax // Rot
mov bl,BYTE PTR [eax]
mov red,ebx // auf Höhe gehen
cmp x,1998
ja equal
add eax,7997 // +1, -1 (+8000-4+1)
mov bl,BYTE PTR [eax] // dl old, bl new
cmp cl,bl
ja above // höher
jb below // niedriger
equal: jmp jmp4 // gleich, nicht zu tun !
above: inc bl
cmp cl,bl // testen ob nur 1 höher
jne above1
mov multi,03F4CCCCDh // ja x0.8
jmp jmp3
above1: inc bl // testen ob nur 2 höher
cmp cl,bl
jne above2
mov multi,03F19999Ah // ja x0.6
jmp jmp3
above2: inc bl // testen ob nur 3 höher
cmp cl,bl
jne above3
mov multi,03ECCCCCDh // ja x0.4
jmp jmp3
above3: mov multi,03E4CCCCDh // x0.2
jmp jmp3
below: dec bl // testen ob nur 1 niedriger
cmp cl,bl
jne below1
mov multi,03F99999Ah // ja x1.2
jmp jmp3
below1: dec bl // testen ob nur 2 niedriger
cmp cl,bl
jne below2
mov multi,03FB33333h // ja x1.4
jmp jmp3
below2: dec bl // testen ob nur 3 niedriger
cmp cl,bl
jne below3
mov multi,03FCCCCCDh // ja x1.6
jmp jmp3
below3: mov multi,03FE66666h // x1.8
jmp3: fld multi
fild red
fmul st,st(1)
fistp red
fild green
fmul st,st(1)
fistp green
fild blue
fmul st,st(1)
fistp blue
ffree st
mov eax,red
cmp eax,0FFh
jbe okr
mov red,0FFh
okr: mov eax,green
cmp eax,0FFh
jbe okg
mov green,0FFh
okg: mov eax,blue
cmp eax,0FFh
jbe jmp4
mov blue,0FFh
jmp4: mov eax,y2 // Grafikspeicher Koordinaten rechnen
mov ebx,x2
mul WordsPerLine
lea eax,[eax+ebx*4] // 32-Bit Farbtiefe
add eax,video_buffer
mov ebx,blue // Und Pixel speichern
mov BYTE PTR [eax],bl
inc eax
mov ebx,green
mov BYTE PTR [eax],bl
inc eax
mov ebx,red
mov BYTE PTR [eax],bl
end: inc Land.vps
}
}
//////////////////////////////////////////////////////////////////////////////////
void CLandScape::FillScreen(int x,int y,int x2,int y2)
{
/* __asm
{
mov edx,x2
sub edx,x
loop1: mov ecx,y2
sub ecx,y
loop2: push edx
push ecx
add edx,Land.ScreenPosX
sub edx,100
push edx
add ecx,Land.ScreenPosY
push ecx
call Land.PutVoxel
loop loop2
dec edx
jnz loop1
}*/
for(int i=x;i<=x2;i++)
{
for(int i2=y;i2<=y2;i2++)
{
int posx=ScreenPosX+i-100;
int posy=ScreenPosY+i2;
PutVoxel(posx,posy,i,i2);
}
}
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::PutBrightVoxel(int x,int y,int x2,int y2)
{
int red,green,blue;
float multi;
__asm
{
mov eax,x // Adresse berechnen
imul eax,8000 // 2000*4 Bytes pro Zeile
mov ebx,y
lea eax,[eax+ebx*4+Land.Landscape+3]
// 3 Bytes dazu weil Höhe Byte 4 im DWORD ist
mov ecx,64 // Counter auf 64 (max-Höhe = 64)
jmp1: mov dl,BYTE PTR [eax+ecx*4] // Höhe laden
cmp dl,cl // und mit Counter vergleichen
jae jmp2 // wenn gleich oder höher jmp2
loop jmp1 // loop (ecx-1)
jmp2: lea eax,[eax+ecx*4-3] // auf Farben gehen (minus 3 Bytes)
xor ebx,ebx // Farben 32-Bit breit speichern wegen FILD
mov bl,BYTE PTR [eax] // Blau
mov blue,ebx
mov bl,BYTE PTR [eax+1] // Grün
mov green,ebx
mov bl,BYTE PTR [eax+2] // Rot
mov red,ebx // auf Höhe gehen
mov bl,BYTE PTR [eax+7999] // dl old, bl new; +1, -1 (+8000-4+1)
cmp cl,bl
ja above // höher
jb below // niedriger
equal: jmp jmp4 // gleich, nicht zu tun !
above: inc bl
cmp cl,bl // testen ob nur 1 höher
jne above1
mov multi,03F4CCCCDh // ja x0.8
jmp jmp3
above1: inc bl // testen ob nur 2 höher
cmp cl,bl
jne above2
mov multi,03F19999Ah // ja x0.6
jmp jmp3
above2: inc bl // testen ob nur 3 höher
cmp cl,bl
jne above3
mov multi,03ECCCCCDh // ja x0.4
jmp jmp3
above3: mov multi,03E4CCCCDh // x0.2
jmp jmp3
below: dec bl // testen ob nur 1 niedriger
cmp cl,bl
jne below1
mov multi,03F99999Ah // ja x1.2
jmp jmp3
below1: dec bl // testen ob nur 2 niedriger
cmp cl,bl
jne below2
mov multi,03FB33333h // ja x1.4
jmp jmp3
below2: dec bl // testen ob nur 3 niedriger
cmp cl,bl
jne below3
mov multi,03FCCCCCDh // ja x1.6
jmp jmp3
below3: mov multi,03FE66666h // x1.8
jmp3: fld multi
fild red
fmul st,st(1)
fistp red
fild green
fmul st,st(1)
fistp green
fild blue
fmul st,st(1)
fistp blue
ffree st
jmp4: mov eax,red
cmp eax,0D7h // rot +20 (<=255!)
jbe rjmp
mov eax,0FFh
jmp rjmp2
rjmp: add eax,028h
rjmp2: mov red,eax
mov ebx,green
cmp ebx,0D7h // grün +20 (<=255!)
jbe gjmp
mov ebx,0FFh
jmp gjmp2
gjmp: add ebx,028h
gjmp2: mov green,ebx
mov ecx,blue
cmp ecx,0D7h // blau +20 (<=255!)
jbe bjmp
mov ecx,0FFh
jmp bjmp2
bjmp: add ecx,028h
bjmp2: mov blue,ecx
mov eax,y2 // Grafikspeicher Koordinaten rechnen
mov ebx,x2
mul WordsPerLine
lea eax,[eax+ebx*4] // 32-Bit Farbtiefe
add eax,video_buffer
mov ebx,blue // Und Pixel speichern
mov BYTE PTR [eax],bl
inc eax
mov ebx,green
mov BYTE PTR [eax],bl
inc eax
mov ebx,red
mov BYTE PTR [eax],bl
end: inc Land.vps
}
}
//////////////////////////////////////////////////////////////////////////////////
// RIP //
//////////////////////////////////////////////////////////////////////////////////
// inline float CLandScape::GetShadow(int x,int y,int height) //
// { //
// if((x+1)>1999) return(1.0); //
// if((y-1)<0) return(1.0); //
// //
// BYTE *pointer; //
// //
// pointer=(BYTE*)&Landscape[++x][--y]; //
// pointer+=3; //
// //
// if(*pointer+1==height) return(0.8); //
// if(*pointer+2==height) return(0.6); //
// if(*pointer+3==height) return(0.4); //
// if(*pointer<height) return(0.2); //
// if(*pointer-1==height) return(1.2); //
// if(*pointer-2==height) return(1.4); //
// if(*pointer-3==height) return(1.6); //
// if(*pointer>height) return(1.8); //
// return(1.0); //
// } //
//////////////////////////////////////////////////////////////////////////////////
void CLandScape::DrawBrush()
{
RGBTRIPLE color;
BYTE height;
BYTE *pointer;
if(GameMain.Status2==7)
return;
if(GameMain.MouseX>100 && GameMain.MouseX<560)
{
if(GameMain.Status==0)
{
Graphics.LockBackBuffer();
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
height=*pointer;
if(posy2-height<0) continue;
if(posy2-height>639) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
PutBrightVoxel(posx,posy-height,posx2,posy2-height);
}
Graphics.UnLockBackBuffer();
}
if(GameMain.Status==1)
{
Graphics.LockBackBuffer();
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
height=*pointer;
if(posy2-height<0) continue;
if(posy2-height>639) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
PutBrightVoxel(posx,posy-height,posx2,posy2-height);
}
Graphics.UnLockBackBuffer();
}
if(GameMain.Status==2)
{
Graphics.LockBackBuffer();
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
height=*pointer;
if(posy2-height<0) continue;
if(posy2-height>639) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
PutBrightVoxel(posx,posy-height,posx2,posy2-height);
}
Graphics.UnLockBackBuffer();
}
}
}
//////////////////////////////////////////////////////////////////////////////////
void CLandScape::UseBrush()
{
if(GameMain.Status2==0)
Higher();
if(GameMain.Status2==1)
Lower();
if(GameMain.Status2==2)
Brush();
if(GameMain.Status2==3)
Smoth();
if(GameMain.Status2==4)
Level();
if(GameMain.Status2==5)
Spray();
if(GameMain.Status2==6)
Transparent();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::Higher()
{
RGBTRIPLE color;
BYTE *pointer;
BYTE oldheight;
if(GameMain.Status==0)
{
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
*pointer+=1;
if(*pointer>64) *pointer=64;
}
}
Graphics.Lock();
for(i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
PutVoxel(posx,posy-*pointer,posx2,posy2-*pointer);
}
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==1)
{
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
*pointer+=1;
if(*pointer>64) *pointer=64;
}
}
Graphics.Lock();
for(i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
PutVoxel(posx,posy-*pointer,posx2,posy2-*pointer);
}
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==2)
{
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
*pointer+=1;
if(*pointer>64) *pointer=64;
PutVoxel(posx,posy-*pointer,posx2,posy2-*pointer);
}
}
Graphics.Lock();
for(i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
PutVoxel(posx,posy-*pointer,posx2,posy2-*pointer);
}
}
Graphics.UnLock();
}
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::Lower()
{
RGBTRIPLE color;
BYTE *pointer;
if(GameMain.Status==0)
{
Graphics.Lock();
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
if(*pointer!=0)
*pointer-=1;
PutVoxel(posx,posy,posx2,posy2);
}
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==1)
{
Graphics.Lock();
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
if(*pointer!=0)
*pointer-=1;
PutVoxel(posx,posy,posx2,posy2);
}
Graphics.UnLock();
}
}
///////////////////////////////////////////////////////////
if(GameMain.Status==2)
{
Graphics.Lock();
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
if(*pointer!=0)
*pointer-=1;
PutVoxel(posx,posy,posx2,posy2);
}
}
Graphics.UnLock();
}
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::Brush()
{
if(Menu.Selection==-1) return;
DWORD buffer2;
int TexPos=Menu.ScrolPos+Menu.Selection;
int x,y,x2,y2;
int a,b;
RGBTRIPLE color;
float red,green,blue;
float ored,ogreen,oblue;
BYTE *pointer;
BYTE height;
if(GameMain.Status==0)
{
Graphics.Lock();
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
a=255-color.rgbtRed;
x=posx/Textures[TexPos]->width;
y=posy/Textures[TexPos]->height;
x2=posx-(x*Textures[TexPos]->width);
y2=posy-(y*Textures[TexPos]->height);
pointer=(BYTE*)&Landscape[posx][posy];
oblue=*pointer;ogreen=*(++pointer);ored=*(++pointer);
color=Textures[TexPos]->GetPixel(x2,y2);
red=color.rgbtRed;green=color.rgbtGreen;blue=color.rgbtBlue;
red=GetAlpha(red,ored,a);
blue=GetAlpha(blue,oblue,a);
green=GetAlpha(green,ogreen,a);
pointer=(BYTE*)&Landscape[posx][posy];
*pointer=blue;
*(++pointer)=green;
*(++pointer)=red;
height=*(++pointer);
for(int i3=0;i3<=height;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==1)
{
Graphics.Lock();
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
a=255-color.rgbtRed;
x=posx/Textures[TexPos]->width;
y=posy/Textures[TexPos]->height;
x2=posx-(x*Textures[TexPos]->width);
y2=posy-(y*Textures[TexPos]->height);
pointer=(BYTE*)&Landscape[posx][posy];
oblue=*pointer;ogreen=*(++pointer);ored=*(++pointer);
color=Textures[TexPos]->GetPixel(x2,y2);
red=color.rgbtRed;green=color.rgbtGreen;blue=color.rgbtBlue;
red=GetAlpha(red,ored,a);
blue=GetAlpha(blue,oblue,a);
green=GetAlpha(green,ogreen,a);
pointer=(BYTE*)&Landscape[posx][posy];
*pointer=blue;
*(++pointer)=green;
*(++pointer)=red;
height=*(++pointer);
for(int i3=0;i3<=height;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==2)
{
Graphics.Lock();
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
a=255-color.rgbtRed;
x=posx/Textures[TexPos]->width;
y=posy/Textures[TexPos]->height;
x2=posx-(x*Textures[TexPos]->width);
y2=posy-(y*Textures[TexPos]->height);
pointer=(BYTE*)&Landscape[posx][posy];
oblue=*pointer;ogreen=*(++pointer);ored=*(++pointer);
color=Textures[TexPos]->GetPixel(x2,y2);
red=color.rgbtRed;green=color.rgbtGreen;blue=color.rgbtBlue;
red=GetAlpha(red,ored,a);
blue=GetAlpha(blue,oblue,a);
green=GetAlpha(green,ogreen,a);;
pointer=(BYTE*)&Landscape[posx][posy];
*pointer=blue;
*(++pointer)=green;
*(++pointer)=red;
height=*(++pointer);
for(int i3=0;i3<=height;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
}
Graphics.UnLock();
}
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::Smoth()
{
BYTE cache[128][128];
BYTE *pointer;
RGBTRIPLE color;
ZeroMemory(&cache,sizeof(cache));
if(GameMain.Status==0)
{
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559)
{
cache[i][i2]=255;
continue;
}
if(posy2<0 || posy2>479)
{
cache[i][i2]=255;
continue;
}
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
cache[i][i2]=*pointer;
}
for(i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
int z=0;
int z2=0;
for(int i3=-1;i3<2;i3++)
for(int i4=-1;i4<2;i4++)
{
if(i+i3<0) continue;
if(i2+i4<0) continue;
if(cache[i+i3][i2+i4]==255) continue;
z2++;
z+=cache[i+i3][i2+i4];
}
z=z/z2;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
*pointer=z;
}
}
Graphics.Lock();
for(i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
for(int i3=0;i3<=*pointer;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==1)
{
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559)
{
cache[i][i2]=255;
continue;
}
if(posy2<0 || posy2>479)
{
cache[i][i2]=255;
continue;
}
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
cache[i][i2]=*pointer;
}
for(i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
int z=0;
int z2=0;
for(int i3=-1;i3<2;i3++)
for(int i4=-1;i4<2;i4++)
{
if(i+i3<0) continue;
if(i2+i4<0) continue;
if(cache[i+i3][i2+i4]==255) continue;
z2++;
z+=cache[i+i3][i2+i4];
}
z=z/z2;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
*pointer=z;
}
}
Graphics.Lock();
for(i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
for(int i3=0;i3<=*pointer;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==2)
{
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559)
{
cache[i][i2]=255;
continue;
}
if(posy2<0 || posy2>479)
{
cache[i][i2]=255;
continue;
}
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
cache[i][i2]=*pointer;
}
for(i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
int z=0;
int z2=0;
for(int i3=-1;i3<2;i3++)
for(int i4=-1;i4<2;i4++)
{
if(i+i3<0) continue;
if(i2+i4<0) continue;
if(cache[i+i3][i2+i4]==255) continue;
z2++;
z+=cache[i+i3][i2+i4];
}
z=z/z2;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
*pointer=z;
}
}
Graphics.Lock();
for(i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
for(int i3=0;i3<=*pointer;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
Graphics.UnLock();
}
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::Level()
{
BYTE *pointer;
RGBTRIPLE color;
if(GameMain.Status==0)
{
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
if(*pointer==32) continue;
if(*pointer<32) ++*pointer;
if(*pointer>32) --*pointer;
}
}
}
///////////////////////////////////////////////////////////
if(GameMain.Status==1)
{
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
if(*pointer==32) continue;
if(*pointer<32) ++*pointer;
if(*pointer>32) --*pointer;
}
}
}
///////////////////////////////////////////////////////////
if(GameMain.Status==2)
{
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
if(*pointer==32) continue;
if(*pointer<32) ++*pointer;
if(*pointer>32) --*pointer;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::Spray()
{
BYTE *pointer;
RGBTRIPLE color;
srand((unsigned)time(NULL));
int r=0;
if(GameMain.Status==0)
{
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
r=rand()%4;
if(r==1 && *pointer<64) ++*pointer;
if(r==2 && *pointer<64) ++*pointer;
}
}
}
///////////////////////////////////////////////////////////
if(GameMain.Status==1)
{
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
r=rand()%4;
if(r==1 && *pointer<64) ++*pointer;
if(r==2 && *pointer<64) ++*pointer;
}
}
}
///////////////////////////////////////////////////////////
if(GameMain.Status==2)
{
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
pointer=(BYTE*)&Landscape[posx][posy];
pointer+=3;
r=rand()%4;
if(r==1 && *pointer<64) ++*pointer;
if(r==2 && *pointer<64) ++*pointer;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::Transparent()
{
if(Menu.Selection==-1) return;
DWORD buffer2;
int TexPos=Menu.ScrolPos+Menu.Selection;
int x,y,x2,y2;
int a,b;
RGBTRIPLE color;
float red,green,blue;
float ored,ogreen,oblue;
BYTE *pointer;
BYTE height;
if(GameMain.Status==0)
{
Graphics.Lock();
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-16;
int posy=ScreenPosY+GameMain.MouseY+i2-16;
int posx2=GameMain.MouseX+i-16;
int posy2=GameMain.MouseY+i2-16;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[2]->GetPixel(i,i2);
if(color.rgbtRed)
{
a=255-color.rgbtRed;
x=posx/Textures[TexPos]->width;
y=posy/Textures[TexPos]->height;
x2=posx-(x*Textures[TexPos]->width);
y2=posy-(y*Textures[TexPos]->height);
pointer=(BYTE*)&Landscape[posx][posy];
oblue=*pointer;ogreen=*(++pointer);ored=*(++pointer);
color=Textures[TexPos]->GetPixel(x2,y2);
red=color.rgbtRed;green=color.rgbtGreen;blue=color.rgbtBlue;
if(a<192) a=192;
red=GetAlpha(red,ored,a);
blue=GetAlpha(blue,oblue,a);
green=GetAlpha(green,ogreen,a);
pointer=(BYTE*)&Landscape[posx][posy];
*pointer=blue;
*(++pointer)=green;
*(++pointer)=red;
height=*(++pointer);
for(int i3=0;i3<=height;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==1)
{
Graphics.Lock();
for(int i=0;i<64;i++)
for(int i2=0;i2<64;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-32;
int posy=ScreenPosY+GameMain.MouseY+i2-32;
int posx2=GameMain.MouseX+i-32;
int posy2=GameMain.MouseY+i2-32;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[1]->GetPixel(i,i2);
if(color.rgbtRed)
{
a=255-color.rgbtRed;
x=posx/Textures[TexPos]->width;
y=posy/Textures[TexPos]->height;
x2=posx-(x*Textures[TexPos]->width);
y2=posy-(y*Textures[TexPos]->height);
pointer=(BYTE*)&Landscape[posx][posy];
oblue=*pointer;ogreen=*(++pointer);ored=*(++pointer);
color=Textures[TexPos]->GetPixel(x2,y2);
red=color.rgbtRed;green=color.rgbtGreen;blue=color.rgbtBlue;
if(a<192) a=192;
red=GetAlpha(red,ored,a);
blue=GetAlpha(blue,oblue,a);
green=GetAlpha(green,ogreen,a);
pointer=(BYTE*)&Landscape[posx][posy];
*pointer=blue;
*(++pointer)=green;
*(++pointer)=red;
height=*(++pointer);
for(int i3=0;i3<=height;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
}
Graphics.UnLock();
}
///////////////////////////////////////////////////////////
if(GameMain.Status==2)
{
Graphics.Lock();
for(int i=0;i<96;i++)
for(int i2=0;i2<96;i2++)
{
int posx=ScreenPosX+GameMain.MouseX-100+i-48;
int posy=ScreenPosY+GameMain.MouseY+i2-48;
int posx2=GameMain.MouseX+i-48;
int posy2=GameMain.MouseY+i2-48;
if(posx2<101 || posx2>559) continue;
if(posy2<0 || posy2>479) continue;
color=Masks[0]->GetPixel(i,i2);
if(color.rgbtRed)
{
a=255-color.rgbtRed;
x=posx/Textures[TexPos]->width;
y=posy/Textures[TexPos]->height;
x2=posx-(x*Textures[TexPos]->width);
y2=posy-(y*Textures[TexPos]->height);
pointer=(BYTE*)&Landscape[posx][posy];
oblue=*pointer;ogreen=*(++pointer);ored=*(++pointer);
color=Textures[TexPos]->GetPixel(x2,y2);
red=color.rgbtRed;green=color.rgbtGreen;blue=color.rgbtBlue;
if(a<192) a=192;
red=GetAlpha(red,ored,a);
blue=GetAlpha(blue,oblue,a);
green=GetAlpha(green,ogreen,a);;
pointer=(BYTE*)&Landscape[posx][posy];
*pointer=blue;
*(++pointer)=green;
*(++pointer)=red;
height=*(++pointer);
for(int i3=0;i3<=height;i3++)
PutVoxel(posx,posy-i3,posx2,posy2-i3);
}
}
Graphics.UnLock();
}
}
//////////////////////////////////////////////////////////////////////////////////
inline BYTE CLandScape::GetAlpha(BYTE a,BYTE b,float alpha)
{
float diff=a-b;
if(diff<0)
{
//diff=diff*(-1);
diff=diff*(alpha/-255);
return(a+diff);
}
else
{
diff=diff*(alpha/255);
return(a-diff);
}
}
//////////////////////////////////////////////////////////////////////////////////
// Move operations //
//////////////////////////////////////////////////////////////////////////////////
HICON CLandScape::CheckMouseCursor()
{
if(CheckBoxes[0]->State) return(GameMain.Cursor);
if(GameMain.KeyboardB[0]==129 && GameMain.KeyboardB[1]==132)
{
MoveLeftDown();
return(GameMain.Cursor);
}
if(GameMain.KeyboardB[0]==129 && GameMain.KeyboardB[1]==131)
{
MoveLeftUp();
return(GameMain.Cursor);
}
if(GameMain.KeyboardB[0]==130 && GameMain.KeyboardB[1]==132)
{
MoveRightDown();
return(GameMain.Cursor);
}
if(GameMain.KeyboardB[0]==130 && GameMain.KeyboardB[1]==131)
{
MoveRightUp();
return(GameMain.Cursor);
}
if(GameMain.KeyboardB[0]==132)
{
MoveDown();
return(GameMain.Cursor);
}
if(GameMain.KeyboardB[0]==131)
{
MoveUp();
return(GameMain.Cursor);
}
if(GameMain.KeyboardB[0]==130)
{
MoveRight();
return(GameMain.Cursor);
}
if(GameMain.KeyboardB[0]==129)
{
MoveLeft();
return(GameMain.Cursor);
}
if(GameMain.MouseX>=636 && GameMain.MouseY>=476)
{
MoveRightDown();
GameMain.CursorRegX=-16;
GameMain.CursorRegY=-14;
return(GameMain.RightDown);
}
if(GameMain.MouseX>=636 && GameMain.MouseY<=3)
{
MoveRightUp();
GameMain.CursorRegX=-14;
GameMain.CursorRegY=0;
return(GameMain.RightUp);
}
if(GameMain.MouseX<=3 && GameMain.MouseY<=3)
{
MoveLeftUp();
GameMain.CursorRegX=0;
GameMain.CursorRegY=0;
return(GameMain.LeftUp);
}
if(GameMain.MouseX<=3 && GameMain.MouseY>=476)
{
MoveLeftDown();
GameMain.CursorRegX=0;
GameMain.CursorRegY=-15;
return(GameMain.LeftDown);
}
if(GameMain.MouseX>=636)
{
MoveRight();
GameMain.CursorRegX=-19;
GameMain.CursorRegY=0;
return(GameMain.Right);
}
if(GameMain.MouseX<=3)
{
MoveLeft();
GameMain.CursorRegX=0;
GameMain.CursorRegY=0;
return(GameMain.Left);
}
if(GameMain.MouseY<=3)
{
MoveUp();
GameMain.CursorRegX=0;
GameMain.CursorRegY=0;
return(GameMain.Up);
}
if(GameMain.MouseY>=476)
{
MoveDown();
GameMain.CursorRegX=0;
GameMain.CursorRegY=-19;
return(GameMain.Down);
}
GameMain.CursorRegX=0;
GameMain.CursorRegY=0;
return(GameMain.Cursor);
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveRight()
{
if(ScreenPosX>1530) return;
ScreenPosX+=10;
Graphics.Blt(111,0,559,480,-10,0);
Graphics.Lock();
FillScreen(549,0,559,479);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveLeft()
{
if(ScreenPosX==0) return;
ScreenPosX-=10;
Graphics.Blt(100,0,550,480,10,0);
Graphics.Lock();
FillScreen(101,0,111,479);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveUp()
{
if(ScreenPosY==0) return;
ScreenPosY-=10;
Graphics.Blt(101,0,560,470,0,10);
Graphics.Lock();
FillScreen(101,0,559,10);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveDown()
{
if(ScreenPosY==1450) return;
ScreenPosY+=10;
Graphics.Blt(101,10,560,480,0,-10);
Graphics.Lock();
FillScreen(101,469,559,479);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveRightUp()
{
if(ScreenPosX>=1540)
{
MoveUp(); return;
}
if(ScreenPosY==0)
{
MoveRight(); return;
}
ScreenPosY-=10;
ScreenPosX+=10;
Graphics.Blt(111,0,560,470,-10,10);
Graphics.Lock();
FillScreen(549,0,559,479);
FillScreen(101,0,548,10);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveRightDown()
{
if(ScreenPosX>=1540)
{
MoveDown(); return;
}
if(ScreenPosY==1450)
{
MoveRight(); return;
}
ScreenPosY+=10;
ScreenPosX+=10;
Graphics.Blt(111,10,559,480,-10,-10);
Graphics.Lock();
FillScreen(549,0,559,470);
FillScreen(101,470,559,479);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveLeftUp()
{
if(ScreenPosX==0)
{
MoveUp(); return;
}
if(ScreenPosY==0)
{
MoveLeft(); return;
}
ScreenPosX-=10;
ScreenPosY-=10;
Graphics.Blt(101,0,549,470,10,10);
Graphics.Lock();
FillScreen(101,0,559,10);
FillScreen(101,10,110,479);
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
inline void CLandScape::MoveLeftDown()
{
if(ScreenPosX==0)
{
MoveDown(); return;
}
if(ScreenPosY==1450)
{
MoveLeft(); return;
}
ScreenPosX-=10;
ScreenPosY+=10;
Graphics.Blt(101,10,549,480,10,-10),
Graphics.Lock();
FillScreen(101,469,559,479);
FillScreen(101,10,111,479);
Graphics.UnLock();
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CLiquid.cpp] - (6,830 bytes)
// CLiquid.cpp
// by Comanche
#include "CMain.h"
#include "CGraphics.h"
#include "CLog.h"
#include "CLiquid.h"
#include "CLandScape.h"
#include "CTexture.h"
extern CMain GameMain;
extern CGraphics Graphics;
extern CLog Log;
extern CLandScape Land;
extern CTexture *Textures[1024];
//////////////////////////////////////////////////////////////////////////////////
CLiquid::CLiquid(int Texture)
{
int i=0;
int TempX,TempY,TempX2,TempY2;
height=0;
strcpy(TextureName,Textures[Texture]->Name);
TexId = Texture;
while(i<2)
{
GameMain.GetMouseInfo();
if(GameMain.MouseX<101) GameMain.MouseX=101;
if(GameMain.MouseX>559) GameMain.MouseX=559;
Graphics.BltToBackBuffer();
Graphics.LockBackBuffer();
if(GameMain.CheckMouseRange(101,0,559,479,FALSE) && i==0)
{
if(GameMain.MouseB[0])
{
TempX=GameMain.MouseX;
TempY=GameMain.MouseY;
i++;
}
}
if(GameMain.CheckMouseRange(101,0,559,479,FALSE) && i==1)
{
if(GameMain.MouseX>TempX && GameMain.MouseY>TempY)
{
Graphics.Quader(TempX,TempY,GameMain.MouseX,GameMain.MouseY,0,0,150);
if(GameMain.MouseB[0])
{
TempX2=GameMain.MouseX;
TempY2=GameMain.MouseY;
i++;
}
}
}
Graphics.UnLockBackBuffer();
GameMain.RenderLiquids();
x=TempX+Land.ScreenPosX-100;
y=TempY+Land.ScreenPosY;
x2=TempX2+Land.ScreenPosX-100;
y2=TempY2+Land.ScreenPosY;
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX-7,GameMain.MouseY-7,GameMain.Cross);
Graphics.ReleaseDC();
Graphics.Flip();
}
while(GameMain.MouseB[0])
GameMain.GetMouseInfo();
}
//////////////////////////////////////////////////////////////////////////////////
CLiquid::~CLiquid()
{
}
//////////////////////////////////////////////////////////////////////////////////
void CLiquid::Render()
{
}
//////////////////////////////////////////////////////////////////////////////////
void CLiquid::RenderOutline(BOOL Marked)
{
int TempX,TempY,TempX2,TempY2;
Graphics.LockBackBuffer();
TempX=x-Land.ScreenPosX+100;
TempY=y-Land.ScreenPosY-height;
TempX2=x2-Land.ScreenPosX+100;
TempY2=y2-Land.ScreenPosY-height;
if(Marked)
{
for (int i=TempX;i<=TempX2;i++)
{
Graphics.PutSafePixel(i,TempY,0,0,220);
Graphics.PutSafePixel(i,TempY2,0,0,220);
}
for (int i2=TempY;i2<=TempY2;i2++)
{
Graphics.PutSafePixel(TempX,i2,0,0,220);
Graphics.PutSafePixel(TempX2,i2,0,0,220);
}
}
else
{
for (int i=TempX;i<=TempX2;i++)
{
Graphics.PutSafePixel(i,TempY,0,0,150);
Graphics.PutSafePixel(i,TempY2,0,0,150);
}
for (int i2=TempY;i2<=TempY2;i2++)
{
Graphics.PutSafePixel(TempX,i2,0,0,150);
Graphics.PutSafePixel(TempX2,i2,0,0,150);
}
}
int Temp=TempY+((TempY2-TempY)/2)-1;
int Temp2=TempX+((TempX2-TempX)/2)-1;
for(int i=0;i<4;i++)
{
for(int i2=0;i2<4;i2++)
{
Graphics.PutSafePixel(i+TempX-2,i2+Temp,0,0,255);
Graphics.PutSafePixel(i+TempX2-1,i2+Temp,0,0,255);
Graphics.PutSafePixel(i+Temp2,i2+TempY-2,0,0,255);
Graphics.PutSafePixel(i+Temp2,i2+TempY2-1,0,0,255);
}
}
Graphics.UnLockBackBuffer();
}
//////////////////////////////////////////////////////////////////////////////////
void CLiquid::CheckMouse(int Liquid)
{
int TempX = x-Land.ScreenPosX+100;
int TempY = y-Land.ScreenPosY;
int TempX2 = x2-Land.ScreenPosX+100;
int TempY2 = y2-Land.ScreenPosY;
int TempX3 = (x2-x)/2;
int TempY3 = (y2-y)/2;
if(GameMain.CheckMouseRange(TempX-4,TempY-height,TempX+4,TempY2-height,FALSE))
{
GameMain.ActiveLiquid=Liquid;
}
if(GameMain.CheckMouseRange(TempX2-4,TempY-height,TempX2+4,TempY2-height,FALSE))
{
GameMain.ActiveLiquid=Liquid;
}
if(GameMain.CheckMouseRange(TempX,TempY-4-height,TempX2,TempY+4-height,FALSE))
{
GameMain.ActiveLiquid=Liquid;
}
if(GameMain.CheckMouseRange(TempX,TempY2-4,TempX2,TempY2+4-height,FALSE))
{
GameMain.ActiveLiquid=Liquid;
}
if(GameMain.CheckMouseRange(TempX-4,TempY+TempY3-4-height,
TempX+4,TempY+TempY3+4-height,FALSE))
{
GameMain.Icon=GameMain.LeftRight;
if(GameMain.MouseB[0])
{
while(GameMain.MouseB[0])
{
GameMain.GetMouseInfo();
if(GameMain.MouseX>=TempX2) GameMain.MouseX=TempX2-1;
if(GameMain.MouseX>559) GameMain.MouseX=559;
if(GameMain.MouseX<101) GameMain.MouseX=101;
x=GameMain.MouseX+Land.ScreenPosX-100;
Graphics.BltToBackBuffer();
GameMain.RenderLiquids();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX-7,GameMain.MouseY-7,GameMain.LeftRight);
Graphics.ReleaseDC();
Graphics.Flip();
}
}
while(GameMain.MouseB[0])
GameMain.GetMouseInfo();
return;
}
if(GameMain.CheckMouseRange(TempX2-4,TempY+TempY3-4-height,
TempX2+4,TempY+TempY3+4-height,FALSE))
{
GameMain.Icon=GameMain.LeftRight;
if(GameMain.MouseB[0])
{
while(GameMain.MouseB[0])
{
GameMain.GetMouseInfo();
if(GameMain.MouseX<=TempX) GameMain.MouseX=TempX+1;
if(GameMain.MouseX>559) GameMain.MouseX=559;
if(GameMain.MouseX<101) GameMain.MouseX=101;
x2=GameMain.MouseX+Land.ScreenPosX-100;
Graphics.BltToBackBuffer();
GameMain.RenderLiquids();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX-7,GameMain.MouseY-7,GameMain.LeftRight);
Graphics.ReleaseDC();
Graphics.Flip();
}
}
while(GameMain.MouseB[0])
GameMain.GetMouseInfo();
return;
}
if(GameMain.CheckMouseRange(TempX+TempX3-4,TempY-4-height,
TempX+TempX3+4,TempY+4-height,FALSE))
{
GameMain.Icon=GameMain.UpDown;
if(GameMain.MouseB[0])
{
while(GameMain.MouseB[0])
{
GameMain.GetMouseInfo();
if(GameMain.MouseY>=TempY2) GameMain.MouseY=TempY2-1;
y=GameMain.MouseY+Land.ScreenPosY;
Graphics.BltToBackBuffer();
GameMain.RenderLiquids();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX-7,GameMain.MouseY-7,GameMain.UpDown);
Graphics.ReleaseDC();
Graphics.Flip();
}
}
while(GameMain.MouseB[0])
GameMain.GetMouseInfo();
return;
}
if(GameMain.CheckMouseRange(TempX+TempX3-4,TempY2-4-height,
TempX+TempX3+4,TempY2+4-height,FALSE))
{
GameMain.Icon=GameMain.UpDown;
if(GameMain.MouseB[0])
{
while(GameMain.MouseB[0])
{
GameMain.GetMouseInfo();
if(GameMain.MouseY<=TempY) GameMain.MouseY=TempY+1;
y2=GameMain.MouseY+Land.ScreenPosY;
Graphics.BltToBackBuffer();
GameMain.RenderLiquids();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX-7,GameMain.MouseY-7,GameMain.UpDown);
Graphics.ReleaseDC();
Graphics.Flip();
}
}
while(GameMain.MouseB[0])
GameMain.GetMouseInfo();
return;
}
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CLog.cpp] - (2,590 bytes)
// Clog.cpp
// by Comanche
#include "CLog.h"
//////////////////////////////////////////////////////////////////////////////////
CLog::CLog()
{
MEMORYSTATUS mem;
GlobalMemoryStatus(&mem);
int memoryfree = mem.dwAvailPhys / 1024;
int memory = mem.dwTotalPhys / 1024;
lfh = OpenFile("VoxEd Log.html",&log_file_data,OF_CREATE);
WriteCodeToLogFile("<html>");
WriteCodeToLogFile("<body>");
WriteCodeToLogFile("<p> <font size=5 color=#000080 face=Arial>");
WriteToLogFile("Pulsar Entertainment LogFile Version 3.0");
WriteCodeToLogFile("</p> </font>");
WriteCodeToLogFile("<p> <font size=2 color=#000000 face=Arial>");
WriteToLogFile("> Voxel Editor: Version alpha 0.53 MMX");
_strtime(buffer);
sprintf(buffer2,"> Time: %s",buffer);
WriteToLogFile(buffer2);
_strdate(buffer);
sprintf(buffer2,"> Date: %s (month/day/year)",buffer);
WriteToLogFile(buffer2);
sprintf(buffer2,"> Total physical memory: %d KB",memory);
WriteToLogFile(buffer2);
sprintf(buffer2,"> Physical memory free: %d KB",memoryfree);
WriteToLogFile(buffer2);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CLog::CloseLogFile()
{
WriteCodeToLogFile("</p> </font>");
WriteCodeToLogFile("</body>");
WriteCodeToLogFile("</html>");
_close(lfh);
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CLog::WriteToLogFile(char *string)
{
_lwrite(lfh,"<BR> ",strlen("<BR> "));
_lwrite(lfh,string,strlen(string));
_lwrite(lfh,"\r\n",strlen("\r\n"));
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CLog::WriteCodeToLogFile(char *string)
{
_lwrite(lfh,string,strlen(string));
_lwrite(lfh,"\r\n",strlen("\r\n"));
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CLog::WriteErrorToLogFile(char *string)
{
WriteCodeToLogFile("</font>");
WriteCodeToLogFile("<font size=2 color=#FF0000 face=Arial>");
WriteToLogFile(string);
WriteCodeToLogFile("</font>");
WriteCodeToLogFile("<font size=2 color=#000000 face=Arial>");
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CLog::WriteStatusToLogFile(char *string)
{
WriteCodeToLogFile("</font>");
WriteCodeToLogFile("<font size=2 color=#008000 face=Arial>");
WriteToLogFile(string);
WriteCodeToLogFile("</font>");
WriteCodeToLogFile("<font size=2 color=#000000 face=Arial>");
return(TRUE);
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CMain.cpp] - (42,136 bytes)
// CMain.cpp
// by Comanche
#include "CLog.h"
#include "CButton.h"
#include "CGraphics.h"
#include "CMain.h"
#include "CLandScape.h"
#include "CMenu.h"
#include "CTexture.h"
#include "CTime.h"
#include "CViewport.h"
#include "CColor.h"
#include "CVoxel.h"
#include "CLiquid.h"
#include "CCheckBox.h"
extern CMain GameMain;
extern CLog Log;
extern CLandScape Land;
extern CGraphics Graphics;
extern CMenu Menu;
extern CTime Time;
extern CColor Color;
extern CVoxel Voxel;
extern CButton *Buttons[60];
extern CCheckBox *CheckBoxes[20];
extern CViewport *Viewports[4];
extern CTexture *Textures[1024];
extern CLiquid *Liquids[128];
extern CTexture *Masks[3];
extern HINSTANCE main_instance;
extern HWND main_window_handle;
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::GameInit(HWND main_window_handle)
{
Log.WriteToLogFile("> Checking DirectX");
if(!CheckDirectX())
{
Log.WriteErrorToLogFile("> Cannot find DirectX");
return(FALSE);
}
switch(DXVersion)
{
case 0x100:
Log.WriteToLogFile("> DirectX 1.0 found");
break;
case 0x200:
Log.WriteToLogFile("> DirectX 2.0 found");
break;
case 0x300:
Log.WriteToLogFile("> DirectX 3.0 found");
break;
case 0x500:
Log.WriteToLogFile("> DirectX 5.0 found");
break;
case 0x600:
Log.WriteToLogFile("> DirectX 6.0 found");
break;
case 0x601:
Log.WriteToLogFile("> DirectX 6.1 found");
break;
case 0x700:
Log.WriteToLogFile("> DirectX 7.0 or better found");
break;
}
if(DXVersion<0x700)
{
Log.WriteErrorToLogFile("> This Program cannot run on older Version than DirectX 7.0");
return(FALSE);
}
if(DXPlatform==VER_PLATFORM_WIN32_WINDOWS)
{
Log.WriteToLogFile("> Running under Win 9x");
}
if(DXPlatform==VER_PLATFORM_WIN32_NT)
{
Log.WriteToLogFile("> Running under Win NT");
}
CheckProzessor();
Log.WriteToLogFile("> Checking Prozessor");
sprintf(buffer,"> Vendor String: %s",VendorString);
Log.WriteToLogFile(buffer);
if(CPUID=TRUE)
{
sprintf(buffer,"> Prozessor class: %d86, Model: %d, Stepping ID: %d",
CpuFamily,CpuModel,CpuStepId);
Log.WriteToLogFile(buffer);
}
if(AMD)
Log.WriteToLogFile("> Yeah, AMD!");
if(INTEL)
Log.WriteToLogFile("> I HATE Intel!");
char features[80];
ZeroMemory(&features,sizeof(features));
if (CPUID) sprintf(features,"%s CPUID", features);
else sprintf(features,"%s Unknown",features);
if (FPU) sprintf(features,"%s FPU", features);
if (MMX) sprintf(features,"%s MMX", features);
if (CMOV) sprintf(features,"%s CMOV", features);
if (TSC) sprintf(features,"%s TSC",features);
if (MCA) sprintf(features,"%s MCA",features);
sprintf(buffer, "> CPU Features:%s", features);
Log.WriteToLogFile(buffer);
if (!CPUID)
{
Log.WriteErrorToLogFile("> Sorry, no MMX found!");
return(FALSE);
}
if (!MMX)
{
Log.WriteErrorToLogFile("> Sorry, no MMX found!");
return(FALSE);
}
if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)
{
Log.WriteErrorToLogFile("> Error: Create main DirectDraw object");
return(FALSE);
}
Log.WriteToLogFile("> Create main DirectDraw object: OK");
if (lpdd->QueryInterface(IID_IDirectDraw2,(LPVOID *)&lpdd2)!=S_OK)
{
Log.WriteErrorToLogFile("> Error: Query IDirectDraw2 Interface");
return(FALSE);
}
Log.WriteToLogFile("> Create IDirectDraw2 Interface: OK");
if (lpdd2->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE |
DDSCL_ALLOWREBOOT)!=DD_OK)
{
Log.WriteErrorToLogFile("> Error: Set exclusive cooperative level ");
return(FALSE);
}
Log.WriteToLogFile("> Set exclusive cooperative level: OK");
if (lpdd2->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,NULL)!=DD_OK)
{
sprintf(buffer,"> Error: Set %dx%d display mode",SCREEN_WIDTH,SCREEN_HEIGHT);
Log.WriteErrorToLogFile(buffer);
return(FALSE);
}
sprintf(buffer,"> Set %dx%d display mode: OK",SCREEN_WIDTH,SCREEN_HEIGHT);
Log.WriteToLogFile(buffer);
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |
DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
if(lpdd2->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)
{
Log.WriteErrorToLogFile("> Error: Create primary surface");
return(FALSE);
}
Log.WriteToLogFile("> Create primary surface: OK");
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if(lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback)!=DD_OK)
{
Log.WriteErrorToLogFile("> Error: Create back buffer");
return(FALSE);
}
Log.WriteToLogFile("> Create back buffer: OK");
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
ddsd.dwWidth = SCREEN_WIDTH;
ddsd.dwHeight = SCREEN_HEIGHT;
if(lpdd2->CreateSurface(&ddsd,&lpddsos1,NULL)!=DD_OK)
{
sprintf(buffer,"> Error: Create %dx%d off-screen surface",
SCREEN_WIDTH,SCREEN_HEIGHT);
Log.WriteErrorToLogFile(buffer);
return(FALSE);
}
sprintf(buffer,"> Create %dx%d off-screen surface: OK",SCREEN_WIDTH,SCREEN_HEIGHT);
Log.WriteToLogFile(buffer);
int alloc=(SCREEN_HEIGHT*SCREEN_WIDTH*(SCREEN_BPP/8)*3)/1024;
sprintf(buffer,"> Allocated %d KByte of video memory",alloc);
Log.WriteToLogFile(buffer);
int memory=(2000*2000*4)/1024;
sprintf(buffer,"> Allocated %d KByte for map data",memory);
Log.WriteToLogFile(buffer);
return(TRUE);
} // end GameInit
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::CheckProzessor()
{
int OpCPUID=0;
int OpMMX=0;
int OpFPU=0;
int OpCMOV=0;
int OpMCA=0;
int OpTSC=0;
char buffer2[32];
int CFT,CMT,CSIT;
ZeroMemory(&buffer2,sizeof(buffer2));
__asm
{
pushad
pushfd
pushfd
pop ebx
xor ebx,0100000h // test for CPUID
push ebx // Flag 21 des EFlag Registers
popfd // ist setzbar wenn CPUID unterstützt
pushfd // wird.
pop ebx
test ebx,0100000h
jz jmp1
popfd
mov OpCPUID,0
jmp end
jmp1: popfd
mov OpCPUID,1
mov eax,0 // CPUID
cpuid
cmp eax,0 // Nochmals überprüfen
jz end
mov DWORD PTR [buffer2],ebx // Vendor ID in ebx,edx und ecx
mov DWORD PTR [buffer2+4],edx
mov DWORD PTR [buffer2+8],ecx
mov eax,1 // CPUID
cpuid
mov ebx,eax // Prozessorklasse in EAX
and ebx,0780h // Bits 8-11
shr ebx,8
mov CFT,ebx
mov ebx,eax // Model in EAX Bits 4-8
and ebx,0F0h
shr ebx,4
mov CMT,ebx
mov ebx,eax // Stepping ID in EAX Bits 0-3
and ebx,0Fh
mov CSIT,ebx
mov eax,1
cpuid
test edx,08h // test for TSC (Bit 4 in edx nach CPUID)
jz notsc
mov OpTSC,1
jmp tsc
notsc: mov OpTSC,0
tsc: test edx,04000h // test for MCA (Bit 14 in edx nach CPUID)
jz nomca
mov OpMCA,1
jmp mca
nomca: mov OpMCA,0
mca: test edx,0800000h // test for MMX (Bit 23 in edx nach CPUID)
jz nommx
mov OpMMX,1
jmp mmx
nommx: mov OpMMX,0
mmx: test edx,010000h // test for CMOV (Bit 15 in edx nach CPUID)
jz nocmov
mov OpCMOV,1
jmp cmov
nocmov: mov OpCMOV,0
cmov: test edx,01h // test for FPU (Bit 0 in edx nach CPUID)
jz nofpu
mov OpFPU,1
jmp end
nofpu: mov OpFPU,0
end: popad
}
if(OpCPUID)
{
CPUID=TRUE;
strcpy(VendorString,buffer2);
}
else
{
CPUID=FALSE;
strcpy(VendorString,"Unknown");
}
AMD=FALSE;
INTEL=FALSE;
for(int i=0;i<29;i++)
{
if(strcmp(&VendorString[i],"AMD")==0)
{
AMD=TRUE;
}
}
for(i=0;i<27;i++)
{
if(strcmp(&VendorString[i],"Intel")==0)
{
INTEL=TRUE;
}
}
if(OpFPU) FPU=TRUE; else FPU=FALSE;
if(OpMMX) MMX=TRUE; else MMX=FALSE;
if(OpTSC) TSC=TRUE; else TSC=FALSE;
if(OpCMOV) CMOV=TRUE; else CMOV=FALSE;
if(OpMCA) MCA=TRUE; else MCA=FALSE;
CpuFamily = CFT;
CpuModel = CMT;
CpuStepId = CSIT;
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::CheckDirectX()
{
HRESULT hr;
HINSTANCE DDHinst = 0;
HINSTANCE DIHinst = 0;
LPDIRECTDRAW lpDDraw = 0;
LPDIRECTDRAW2 lpDDraw2 = 0;
LPDIRECTDRAW7 lpDDraw7 = 0;
DIRECTDRAWCREATE DirectDrawCreate = 0;
DIRECTDRAWCREATEEX DirectDrawCreateEx = 0;
DIRECTINPUTCREATE DirectInputCreate = 0;
OSVERSIONINFO OSVersion;
LPDIRECTDRAWSURFACE lpSurf = 0;
LPDIRECTDRAWSURFACE3 lpSurf3 = 0;
LPDIRECTDRAWSURFACE4 lpSurf4 = 0;
// First get the windows platform
OSVersion.dwOSVersionInfoSize = sizeof(OSVersion);
if(!GetVersionEx(&OSVersion))
{
DXPlatform = 0;
DXVersion = 0;
return(FALSE);
}
if( OSVersion.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
DXPlatform = VER_PLATFORM_WIN32_NT;
// NT is easy... NT 4.0 is DX2, 4.0 SP3 is DX3, 5.0 is DX5
// and no DX on earlier versions.
if( OSVersion.dwMajorVersion < 4 )
{
DXVersion = 0; // No DX on NT3.51 or earlier
return(FALSE);
}
if( OSVersion.dwMajorVersion == 4 )
{
// NT4 up to SP2 is DX2, and SP3 onwards is DX3, so we are at least DX2
DXVersion = 0x200;
// We're not supposed to be able to tell which SP we're on, so check for dinput
DIHinst = LoadLibrary( "DINPUT.DLL" );
if( DIHinst == 0 )
{
// No DInput... must be DX2 on NT 4 pre-SP3
OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
return(TRUE);
}
DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
"DirectInputCreateA" );
FreeLibrary( DIHinst );
if( DirectInputCreate == 0 )
{
// No DInput... must be pre-SP3 DX2
OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
return(TRUE);
}
// It must be NT4, DX2
DXVersion = 0x300; // DX3 on NT4 SP3 or higher
return(TRUE);
}
// Else it's NT5 or higher, and it's DX5a or higher: Drop through to
// Win9x tests for a test of DDraw (DX6 or higher)
}
else
{
// Not NT... must be Win9x
DXPlatform = VER_PLATFORM_WIN32_WINDOWS;
}
// Now we know we are in Windows 9x (or maybe 3.1), so anything's possible.
// First see if DDRAW.DLL even exists.
DDHinst = LoadLibrary( "DDRAW.DLL" );
if( DDHinst == 0 )
{
DXVersion = 0;
DXPlatform = 0;
FreeLibrary( DDHinst );
return(FALSE);
}
// See if we can create the DirectDraw object.
DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( DDHinst, "DirectDrawCreate" );
if( DirectDrawCreate == 0 )
{
DXVersion = 0;
DXPlatform = 0;
FreeLibrary( DDHinst );
OutputDebugString( "Couldn't LoadLibrary DDraw\r\n" );
return(FALSE);
}
hr = DirectDrawCreate( NULL, &lpDDraw, NULL );
if( FAILED(hr) )
{
DXVersion = 0;
DXPlatform = 0;
FreeLibrary( DDHinst );
OutputDebugString( "Couldn't create DDraw\r\n" );
return(FALSE);
}
// So DirectDraw exists. We are at least DX1.
DXVersion = 0x100;
// Let's see if IID_IDirectDraw2 exists.
hr = lpDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&lpDDraw2 );
if( FAILED(hr) )
{
// No IDirectDraw2 exists... must be DX1
lpDDraw->Release();
FreeLibrary( DDHinst );
OutputDebugString( "Couldn't QI DDraw2\r\n" );
return(TRUE);
}
// IDirectDraw2 exists. We must be at least DX2
lpDDraw2->Release();
DXVersion = 0x200;
///////////////////////////////////////////////////////////////////////////
// DirectX 3.0 Checks
///////////////////////////////////////////////////////////////////////////
// DirectInput was added for DX3
DIHinst = LoadLibrary( "DINPUT.DLL" );
if( DIHinst == 0 )
{
// No DInput... must not be DX3
OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
lpDDraw->Release();
FreeLibrary( DDHinst );
return(TRUE);
}
DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
"DirectInputCreateA" );
if( DirectInputCreate == 0 )
{
// No DInput... must be DX2
FreeLibrary( DIHinst );
FreeLibrary( DDHinst );
lpDDraw->Release();
OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
return(TRUE);
}
// DirectInputCreate exists. We are at least DX3
DXVersion = 0x300;
FreeLibrary( DIHinst );
// Can do checks for 3a vs 3b here
///////////////////////////////////////////////////////////////////////////
// DirectX 5.0 Checks
///////////////////////////////////////////////////////////////////////////
// We can tell if DX5 is present by checking for the existence of
// IDirectDrawSurface3. First, we need a surface to QI off of.
DDSURFACEDESC ddsd;
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = lpDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
if( FAILED(hr) )
{
// Failure. This means DDraw isn't properly installed.
lpDDraw->Release();
FreeLibrary( DDHinst );
DXVersion = 0;
OutputDebugString( "Couldn't Set coop level\r\n" );
return(FALSE);
}
hr = lpDDraw->CreateSurface( &ddsd, &lpSurf, NULL );
if( FAILED(hr) )
{
// Failure. This means DDraw isn't properly installed.
lpDDraw->Release();
FreeLibrary( DDHinst );
DXVersion = 0;
OutputDebugString( "Couldn't CreateSurface\r\n" );
return(FALSE);
}
// Query for the IDirectDrawSurface3 interface
if( FAILED( lpSurf->QueryInterface( IID_IDirectDrawSurface3,
(VOID**)&lpSurf3 ) ) )
{
lpDDraw->Release();
FreeLibrary( DDHinst );
return(TRUE);
}
// QI for IDirectDrawSurface3 succeeded. We must be at least DX5
DXVersion = 0x500;
///////////////////////////////////////////////////////////////////////////
// DirectX 6.0 Checks
///////////////////////////////////////////////////////////////////////////
// The IDirectDrawSurface4 interface was introduced with DX 6.0
if( FAILED( lpSurf->QueryInterface( IID_IDirectDrawSurface4,
(VOID**)&lpSurf4 ) ) )
{
lpDDraw->Release();
FreeLibrary( DDHinst );
return(TRUE);
}
// IDirectDrawSurface4 was create successfully. We must be at least DX6
DXVersion = 0x600;
lpSurf->Release();
lpDDraw->Release();
///////////////////////////////////////////////////////////////////////////
// DirectX 6.1 Checks
///////////////////////////////////////////////////////////////////////////
// Check for DMusic, which was introduced with DX6.1
LPDIRECTMUSIC lpDMusic = NULL;
CoInitialize( NULL );
hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
IID_IDirectMusic, (VOID**)&lpDMusic );
if( FAILED(hr) )
{
OutputDebugString( "Couldn't create CLSID_DirectMusic\r\n" );
FreeLibrary( DDHinst );
return(TRUE);
}
// DirectMusic was created successfully. We must be at least DX6.1
DXVersion = 0x601;
lpDMusic->Release();
CoUninitialize();
///////////////////////////////////////////////////////////////////////////
// DirectX 7.0 Checks
///////////////////////////////////////////////////////////////////////////
// Check for DirectX 7 by creating a DDraw7 object
LPDIRECTDRAW7 pDD7;
DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( DDHinst,
"DirectDrawCreateEx" );
if( NULL == DirectDrawCreateEx )
{
FreeLibrary( DDHinst );
return(TRUE);
}
if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&lpDDraw7, IID_IDirectDraw7,
NULL ) ) )
{
FreeLibrary( DDHinst );
return(TRUE);
}
// DDraw7 was created successfully. We must be at least DX7.0
DXVersion = 0x700;
lpDDraw7->Release();
///////////////////////////////////////////////////////////////////////////
// End of checks
///////////////////////////////////////////////////////////////////////////
// Close open libraries and return
FreeLibrary( DDHinst );
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::GameStart()
{
DrawCursor=TRUE;
Graphics.DrawFont = TRUE;
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
Graphics.logfont.lfWidth = 0;
Graphics.logfont.lfEscapement = 0;
Graphics.logfont.lfOrientation = 0;
Graphics.logfont.lfWeight = FW_BOLD;
Graphics.logfont.lfItalic = FALSE;
Graphics.logfont.lfUnderline = FALSE;
Graphics.logfont.lfStrikeOut = FALSE;
Graphics.logfont.lfCharSet = OEM_CHARSET;
Graphics.logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
Graphics.logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
Graphics.logfont.lfQuality = PROOF_QUALITY;
Graphics.logfont.lfPitchAndFamily = DEFAULT_PITCH;
lstrcpy(Graphics.logfont.lfFaceName, "Arial");
Viewports[0] = new CViewport(135,20,VIEWPORTTOP);
Viewports[1] = new CViewport(405,20,VIEWPORTFRONT);
Viewports[2] = new CViewport(135,260,VIEWPORTLEFT);
Viewports[3] = new CViewport(405,260,VIEWPORT3D);
Graphics.BlackQuader(0,0,640,480);
Graphics.Lock();
// Land Editor Buttons
Buttons[0] = new CButton(10,440,90,460,"Ende","");
Buttons[1] = new CButton(1,20,100,40,"Menu >","");
Buttons[2] = new CButton(562,8,570,239,"","");
Buttons[3] = new CButton(562,240,570,462,"","");
Buttons[4] = new CButton(2,60,32,90,"","data\\Button1.bmp"); //klein
Buttons[5] = new CButton(35,60,65,90,"","data\\Button2.bmp"); //mittel
Buttons[6] = new CButton(68,60,98,90,"","data\\Button3.bmp"); //groß
Buttons[7] = new CButton(2,92,32,122,"","data\\Button4.bmp"); //higher
Buttons[8] = new CButton(35,92,65,122,"","data\\Button5.bmp"); //lower
Buttons[9] = new CButton(68,92,98,122,"","data\\Button6.bmp"); //brush
Buttons[10] = new CButton(2,124,32,154,"","data\\Button7.bmp"); //smoth
Buttons[11] = new CButton(35,124,65,154,"","data\\Button8.bmp"); //level
Buttons[12] = new CButton(68,124,98,154,"","data\\Button9.bmp"); //redraw
Buttons[13] = new CButton(2,156,32,186,"","data\\Button10.bmp"); //spray
Buttons[14] = new CButton(35,156,65,186,"","data\\Button11.bmp"); //transparent
Buttons[15] = new CButton(68,156,98,186,"","data\\Button12.bmp"); //liquid mode
// Voxel Editor Buttons
Buttons[30] = new CButton(2,50,32,70,"","data\\ArrowUp.bmp");
Buttons[31] = new CButton(35,50,65,70,"","data\\ArrowUp.bmp");
Buttons[32] = new CButton(68,50,98,70,"","data\\ArrowUp.bmp");
Buttons[33] = new CButton(2,144,32,164,"","data\\ArrowDown.bmp");
Buttons[34] = new CButton(35,144,65,164,"","data\\ArrowDown.bmp");
Buttons[35] = new CButton(68,144,98,164,"","data\\ArrowDown.bmp");
// Check Boxes
CheckBoxes[0] = new CCheckBox(6,355,"Lock Screen");
CheckBoxes[1] = new CCheckBox(6,370,"Draw VPF");
CheckBoxes[2] = new CCheckBox(6,385,"ActiveLiquid");
CheckBoxes[3] = new CCheckBox(6,400,"Outlines Off");
CheckBoxes[4] = new CCheckBox(6,415,"Only Outlines");
Graphics.DrawButton(0,0,100,479);
Graphics.DrawButton(560,0,639,479);
Graphics.DrawPushedButton(13,267,84,338); // MiniMap
Graphics.DrawPushedButton(4,215,96,255);
for(int i=0;i<96;i++)
Graphics.HLine(2+i,2,15,0,0,240-i);
Graphics.UnLock();
Menu.Selection=-1;
Menu.DrawTextures();
Menu.DrawMiniMap();
Graphics.logfont.lfHeight = SMALFONTHEIGHT;
Graphics.OSGetDC();
Graphics.Text(50,5,Version);
Graphics.OSReleaseDC();
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
Graphics.BltToBackBuffer();
Graphics.Flip();
Cursor = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_CURSOR));
Cross = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_CROSS));
Finger = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_STOP));
Pinpet = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_PINPET));
Clock = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_CLOCK));
Right = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_RIGHT));
Left = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_LEFT));
Up = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_UP));
Down = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_DOWN));
RightDown = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_DOWNRIGHT));
RightUp = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_UPRIGHT));
LeftDown = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_DOWNLEFT));
LeftUp = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_UPLEFT));
LeftRight = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_LEFTRIGHT));
UpDown = LoadIcon(main_instance,MAKEINTRESOURCE(IDI_UPDOWN));
Log.WriteToLogFile("> Loading Cursors: OK");
Land.Day=TRUE;
ActiveLiquid=-1;
return(TRUE);
} // end GameStart
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::GameMain()
{
if(Editor==0)
{
GetMouseInfo();
GetKeyboardInfo();
Land.vps=0;
if(CheckMouseRange(3,2,99,17,TRUE))
Menu.MessageBox("Credits","VoxEd by Comanche",MS_OK);
if (Buttons[0]->TestIfPressed())
{
if(Menu.MessageBox("VoxEd","Do you realy want to exit?",MS_YESNO))
{
PostMessage(main_window_handle,WM_DESTROY,0,0);
return(TRUE);
}
}
if (Buttons[1]->TestIfPressed())
{
Menu.Menu();
return(TRUE);
}
if (Buttons[2]->TestIfPressed()) Menu.ScrollUp();
if (Buttons[3]->TestIfPressed()) Menu.ScrollDown();
if (Buttons[4]->TestIfPressed()) Status=0;
if (Buttons[5]->TestIfPressed()) Status=1;
if (Buttons[6]->TestIfPressed()) Status=2;
if (Buttons[7]->TestIfPressed()) Status2=0;
if (Buttons[8]->TestIfPressed()) Status2=1;
if (Buttons[9]->TestIfPressed()) Status2=2;
if (Buttons[10]->TestIfPressed()) Status2=3;
if (Buttons[11]->TestIfPressed()) Status2=4;
if (Buttons[12]->TestIfPressed())
{
Graphics.Lock();
Land.InitScreen();
Graphics.UnLock();
}
if (Buttons[13]->TestIfPressed()) Status2=5;
if (Buttons[14]->TestIfPressed()) Status2=6;
if (Buttons[15]->TestIfPressed()) Status2=7;
CheckBoxes[0]->TestIfPressed();
CheckBoxes[1]->TestIfPressed();
CheckBoxes[2]->TestIfPressed();
CheckBoxes[3]->TestIfPressed();
CheckBoxes[4]->TestIfPressed();
if (KeyboardB[0]=='R')
{
Graphics.Lock();
Land.InitScreen();
Graphics.UnLock();
}
if (KeyboardB[0]==219)
{
Buttons[1]->RedrawPushedButton();
Menu.Menu();
Buttons[1]->RedrawButton();
return(TRUE);
}
if (KeyboardB[0]==56 && KeyboardB[1]==62)
{
PostMessage(main_window_handle,WM_DESTROY,0,0);
}
if (CheckMouseRange(572,8,636,463,TRUE))
Menu.SelectTexture();
if (MouseX>100 && MouseX<560 && MouseB[0])
Land.UseBrush();
if (MouseX>100 && MouseX<560 && MouseB[1])
{
Land.UseBrush();
while(MouseB[1])
{
GetMouseInfo();
}
}
Icon=Land.CheckMouseCursor();
Graphics.BltToBackBuffer();
if(Status2==7)
{
if(KeyboardB[0]==211 && ActiveLiquid!=-1)
{
delete Liquids[ActiveLiquid];
Liquids[ActiveLiquid]=NULL;
}
if(KeyboardB[0]=='-' && ActiveLiquid!=-1)
{
if(Liquids[ActiveLiquid]->height>0)
Liquids[ActiveLiquid]->height-=1;
}
if(KeyboardB[0]=='+' && ActiveLiquid!=-1)
{
if(Liquids[ActiveLiquid]->height<32)
Liquids[ActiveLiquid]->height+=1;
}
RenderLiquids();
CheckLiquids();
if(MouseX>100 && MouseX<560 && MouseB[0]
&& Menu.Selection>-1 && ActiveLiquid==-1)
{
for(int i=0;i<128;i++)
{
if(!Liquids[i])
{
Liquids[i] = new CLiquid(Menu.Selection);
i=128;
}
}
}
}
Land.DrawBrush();
Graphics.GetDC();
if (MouseX>100 && MouseX<560 && Status2==7)
DrawIcon(Graphics.xdc,MouseX-7,MouseY-7,Icon);
if (MouseX<101 || MouseX>559)
DrawIcon(Graphics.xdc,MouseX+CursorRegX,MouseY+CursorRegY,Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
return(TRUE);
}
if(Editor==1)
{
GetMouseInfo();
GetKeyboardInfo();
if(CheckMouseRange(3,2,99,17,TRUE))
Menu.MessageBox("Credits","VoxEd by Comanche",MS_OK);
if (Buttons[0]->TestIfPressed())
{
PostMessage(main_window_handle,WM_DESTROY,0,0);
return(TRUE);
}
if (Buttons[1]->TestIfPressed())
{
Menu.Menu();
return(TRUE);
}
if(Buttons[30]->TestIfPressed())
{
if(Color.redpos<10)
Color.redpos=0;
else Color.redpos-=10;
Color.DrawColors();
}
if(Buttons[31]->TestIfPressed())
{
if(Color.greenpos<10)
Color.greenpos=0;
else Color.greenpos-=10;
Color.DrawColors();
}
if(Buttons[32]->TestIfPressed())
{
if(Color.bluepos<10)
Color.bluepos=0;
else Color.bluepos-=10;
Color.DrawColors();
}
if(Buttons[33]->TestIfPressed())
{
if(Color.redpos>239)
Color.redpos=249;
else Color.redpos+=10;
Color.DrawColors();
}
if(Buttons[34]->TestIfPressed())
{
if(Color.greenpos>239)
Color.greenpos=249;
else Color.greenpos+=10;
Color.DrawColors();
}
if(Buttons[35]->TestIfPressed())
{
if(Color.bluepos>239)
Color.bluepos=249;
else Color.bluepos+=10;
Color.DrawColors();
}
Color.TestIfPressed();
if (KeyboardB[0]==219)
{
Buttons[1]->RedrawPushedButton();
Menu.Menu();
Buttons[1]->RedrawButton();
return(TRUE);
}
if (KeyboardB[0]==56 && KeyboardB[1]==62)
{
PostMessage(main_window_handle,WM_DESTROY,0,0);
}
Graphics.BltToBackBuffer();
Voxel.ViewX=0; Voxel.ViewY=0;
Viewports[0]->UseViewport();
Viewports[1]->UseViewport();
Viewports[2]->UseViewport();
Viewports[3]->UseViewport();
HICON icon=Cursor;
Graphics.GetDC();
DrawIcon(Graphics.xdc,MouseX+CursorRegX,MouseY+CursorRegY,icon);
Graphics.ReleaseDC();
Graphics.Flip();
return(TRUE);
}
return(TRUE);
} // end GameMain
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::GameShutdown()
{
int i;
int i2=0;
Log.WriteStatusToLogFile("> GameShutdown: Shutting down game");
i2=0;
for(i=0;i<128;i++)
{
if(Liquids[i])
{
i2++;
delete Liquids[i];
}
}
sprintf(buffer,"> %d Liquids deleted",i2);
Log.WriteToLogFile(buffer);
i2=0;
for(i=0;i<60;i++)
{
if(Buttons[i])
{
i2++;
delete Buttons[i];
}
}
sprintf(buffer,"> %d Buttons deleted",i2);
Log.WriteToLogFile(buffer);
i2=0;
for(i=0;i<20;i++)
{
if(CheckBoxes[i])
{
i2++;
delete CheckBoxes[i];
}
}
sprintf(buffer,"> %d Check Boxes deleted",i2);
Log.WriteToLogFile(buffer);
i2=0;
for(i=0;i<1024;i++)
{
if(Textures[i])
{
i2++;
delete Textures[i];
}
}
sprintf(buffer,"> %d Textures deleted",i2);
Log.WriteToLogFile(buffer);
if(Masks[0]) delete Masks[0];
if(Masks[1]) delete Masks[1];
if(Masks[2]) delete Masks[2];
Log.WriteToLogFile("> 3 Masks deleted");
if(Viewports[0]) delete Viewports[0];
if(Viewports[1]) delete Viewports[1];
if(Viewports[2]) delete Viewports[2];
if(Viewports[3]) delete Viewports[3];
Log.WriteToLogFile("> 4 Viewports deleted");
if (lpddsprimary!=NULL)
lpddsprimary->Release();
Log.WriteToLogFile("> Release primary surface: OK");
if(lpddsos1!=NULL)
lpddsos1->Release();
Log.WriteToLogFile("> Release off-screen surface: OK");
if (lpdd!=NULL)
lpdd->Release();
Log.WriteToLogFile("> Release DirectDraw object: OK");
if (lpdidevice!=NULL)
{
lpdidevice->Unacquire();
lpdidevice->Release();
lpdidevice=NULL;
}
Log.WriteToLogFile("> Unacquire mouse: OK");
if(lpdidevice2!=NULL)
{
lpdidevice2->Unacquire();
lpdidevice2->Release();
lpdidevice2=NULL;
}
Log.WriteToLogFile("> Unacquire keyboard: OK");
if (lpdi!=NULL)
{
lpdi->Release();
lpdi=NULL;
}
Log.WriteToLogFile("> Release DirectInput object: OK");
Log.WriteToLogFile("> GameShutdown: OK");
Log.CloseLogFile();
return(TRUE);
} // end GameShutdown
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::GameRestart()
{
Graphics.RestorePrimarySurface();
Graphics.RestoreOffScreenSurface();
Graphics.BlackQuader(0,0,640,480);
if(Editor==0)
{
Graphics.Lock();
Graphics.DrawButton(0,0,100,479);
Graphics.DrawButton(560,0,639,479);
Graphics.DrawPushedButton(13,267,84,338); // MiniMap
Graphics.DrawPushedButton(4,215,96,255);
for(int i=0;i<96;i++)
Graphics.HLine(2+i,2,15,0,0,240-i);
Land.InitScreen();
Graphics.UnLock();
Menu.DrawTextures();
Menu.DrawMiniMap();
Log.WriteToLogFile("> Redraw Graphics: OK");
for(i=0;i<30;i++)
{
if(Buttons[i])
Buttons[i]->RedrawButton();
}
for(i=0;i<20;i++)
{
if(CheckBoxes[i])
CheckBoxes[i]->RedrawCheckBox();
}
Graphics.logfont.lfHeight = SMALFONTHEIGHT;
Graphics.OSGetDC();
Graphics.Text(50,5,Version);
Graphics.OSReleaseDC();
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
Graphics.BltToBackBuffer();
Graphics.Flip();
return(TRUE);
}
if(Editor==1)
{
Graphics.Lock();
Graphics.DrawButton(0,0,100,479);
Graphics.DrawPushedButton(4,215,96,255);
Graphics.DrawButton(101,0,369,239);
Graphics.DrawButton(370,0,639,239);
Graphics.DrawButton(101,240,369,479);
Graphics.DrawButton(370,240,639,479);
for(int i=0;i<96;i++)
Graphics.HLine(2+i,2,15,0,0,200-i);
Graphics.UnLock();
Viewports[0]->RedrawViewport();
Viewports[1]->RedrawViewport();
Viewports[2]->RedrawViewport();
Viewports[3]->RedrawViewport();
Log.WriteToLogFile("> Redraw Graphics: OK");
Buttons[0]->RedrawButton();
Buttons[1]->RedrawButton();
for(i=30;i<60;i++)
{
if(Buttons[i])
Buttons[i]->RedrawButton();
}
Graphics.logfont.lfHeight = SMALFONTHEIGHT;
Graphics.OSGetDC();
Graphics.Text(50,5,Version);
Graphics.OSReleaseDC();
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
Color.DrawColors();
Graphics.BltToBackBuffer();
Graphics.Flip();
return(TRUE);
}
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::MouseInit(HWND hwnd)
{
if (DirectInputCreate(main_instance,DIRECTINPUT_VERSION,&lpdi,NULL)!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Create main DirectInput object");
return(FALSE);
}
Log.WriteToLogFile("> Create main DirectInput object: OK");
if (lpdi->CreateDevice(GUID_SysMouse,&lpdidevice, NULL)!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Create mouse device");
return(FALSE);
}
Log.WriteToLogFile("> Create mouse device: OK");
if (lpdidevice->SetCooperativeLevel(hwnd,DISCL_EXCLUSIVE |
DISCL_FOREGROUND)!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Set exclusive cooperative level");
return(FALSE);
}
Log.WriteToLogFile("> Set exclusive cooperative level: OK");
if (lpdidevice->SetDataFormat(&c_dfDIMouse)!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Set mouse data format");
return(FALSE);
}
Log.WriteToLogFile("> Set mouse data format: OK");
if (lpdidevice->Acquire()!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Aquire mouse");
return(FALSE);
}
Log.WriteToLogFile("> Aquire mouse: OK");
MouseX=320;
MouseY=240;
return(TRUE);
} // end MouseInit
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::KeyboardInit(HWND hwnd)
{
if (lpdi->CreateDevice(GUID_SysKeyboard,&lpdidevice2, NULL)!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Create keyboard device");
return(FALSE);
}
Log.WriteToLogFile("> Create keyboard device: OK");
if (lpdidevice2->SetCooperativeLevel(hwnd,DISCL_NONEXCLUSIVE|
DISCL_BACKGROUND)!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Set exclusive cooperative level");
return(FALSE);
}
Log.WriteToLogFile("> Set exclusive cooperative level: OK");
if (lpdidevice2->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Set keyboard data format");
return(FALSE);
}
Log.WriteToLogFile("> Set keyboard data format: OK");
if (lpdidevice2->Acquire()!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Aquire keyboard");
return(FALSE);
}
Log.WriteToLogFile("> Aquire keyboard: OK");
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::GetMouseInfo()
{
HRESULT hresult;
hresult = lpdidevice->GetDeviceState(sizeof(DIMOUSESTATE),
(LPVOID)&mouse_state);
if (hresult==DIERR_INPUTLOST)
lpdidevice->Acquire();
else if (hresult!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Get device state of mouse");
return(FALSE);
}
// move the mouse cursor
MouseX=(MouseX+=mouse_state.lX);
MouseY=(MouseY+=mouse_state.lY);
for(int i=0;i<3;i++)
{
if (mouse_state.rgbButtons[i]==128) MouseB[i]=1;
else MouseB[i]=0;
}
// first x boundaries
if (MouseX >= SCREEN_WIDTH)
MouseX = SCREEN_WIDTH-1;
else
if (MouseX < 0)
MouseX = 0;
// now the y boundaries
if (MouseY >= SCREEN_HEIGHT)
MouseY= SCREEN_HEIGHT-1;
else
if (MouseY < 0)
MouseY = 0;
return(TRUE);
} // end GetMouseInfo
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::CheckMouseRange(int x,int y,int x2,int y2,BOOL Button)
{
if(Button)
{
if(MouseX>=x && MouseX<=x2 && MouseY>=y && MouseY<=y2 && MouseB[0])
return(TRUE);
}
else
{
if(MouseX>=x && MouseX<=x2 && MouseY>=y && MouseY<=y2)
return(TRUE);
}
return(FALSE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::GetKeyboardInfo()
{
HRESULT hresult;
hresult = lpdidevice2->GetDeviceState(sizeof(keyboard_state),
(LPVOID)&keyboard_state);
if (hresult==DIERR_INPUTLOST)
lpdidevice2->Acquire();
else if (hresult!=DI_OK)
{
Log.WriteErrorToLogFile("> Error: Get device state of keyboard");
return(FALSE);
}
KeyboardB[0]=0;
KeyboardB[1]=0;
KeyboardB[2]=0;
KeyboardB[3]=0;
int i2=0;
if(keyboard_state[DIK_A] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='A';
i2++;
}
if(keyboard_state[DIK_B] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='B';
i2++;
}
if(keyboard_state[DIK_C] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='C';
i2++;
}
if(keyboard_state[DIK_D] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='D';
i2++;
}
if(keyboard_state[DIK_E] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='E';
i2++;
}
if(keyboard_state[DIK_F] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='F';
i2++;
}
if(keyboard_state[DIK_G] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='G';
i2++;
}
if(keyboard_state[DIK_H] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='H';
i2++;
}
if(keyboard_state[DIK_I] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='I';
i2++;
}
if(keyboard_state[DIK_J] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='J';
i2++;
}
if(keyboard_state[DIK_K] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='K';
i2++;
}
if(keyboard_state[DIK_L] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='L';
i2++;
}
if(keyboard_state[DIK_M] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='M';
i2++;
}
if(keyboard_state[DIK_N] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='N';
i2++;
}
if(keyboard_state[DIK_O] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='O';
i2++;
}
if(keyboard_state[DIK_P] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='P';
i2++;
}
if(keyboard_state[DIK_Q] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='Q';
i2++;
}
if(keyboard_state[DIK_R] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='R';
i2++;
}
if(keyboard_state[DIK_S] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='S';
i2++;
}
if(keyboard_state[DIK_T] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='T';
i2++;
}
if(keyboard_state[DIK_U] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='U';
i2++;
}
if(keyboard_state[DIK_V] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='V';
i2++;
}
if(keyboard_state[DIK_W] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='W';
i2++;
}
if(keyboard_state[DIK_X] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='X';
i2++;
}
if(keyboard_state[DIK_Y] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='Z';
i2++;
}
if(keyboard_state[DIK_Z] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='Y';
i2++;
}
if(keyboard_state[DIK_1] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='1';
i2++;
}
if(keyboard_state[DIK_2] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='2';
i2++;
}
if(keyboard_state[DIK_3] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='3';
i2++;
}
if(keyboard_state[DIK_4] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='4';
i2++;
}
if(keyboard_state[DIK_5] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='5';
i2++;
}
if(keyboard_state[DIK_6] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='6';
i2++;
}
if(keyboard_state[DIK_7] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='7';
i2++;
}
if(keyboard_state[DIK_8] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='8';
i2++;
}
if(keyboard_state[DIK_9] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='9';
i2++;
}
if(keyboard_state[DIK_0] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]='0';
i2++;
}
if(keyboard_state[DIK_ESCAPE] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=27;
i2++;
}
if(keyboard_state[DIK_BACK] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=8;
i2++;
}
if(keyboard_state[DIK_RETURN] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=13;
i2++;
}
if(keyboard_state[DIK_LEFT] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=129;
i2++;
}
if(keyboard_state[DIK_RIGHT] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=130;
i2++;
}
if(keyboard_state[DIK_UP] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=131;
i2++;
}
if(keyboard_state[DIK_DOWN] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=132;
i2++;
}
if((keyboard_state[219] & 0x80) || (keyboard_state[220] & 0x80))
{
if(i2>3) return(TRUE);
KeyboardB[i2]=219;
i2++;
}
if(keyboard_state[56] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=56;
i2++;
}
if(keyboard_state[62] & 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=62;
i2++;
}
if((keyboard_state[27] && 0x80) || (keyboard_state[78] && 0x80))
{
if(i2>3) return(TRUE);
KeyboardB[i2]='+';
i2++;
}
if(keyboard_state[53] && 0x80 || (keyboard_state[74] && 0x80))
{
if(i2>3) return(TRUE);
KeyboardB[i2]='-';
i2++;
}
if(keyboard_state[211] && 0x80)
{
if(i2>3) return(TRUE);
KeyboardB[i2]=211;
i2++;
}
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::LoadTextures()
{
HANDLE SearchHandle;
WIN32_FIND_DATA finddata;
int NumFiles=0;
char name[MAX_PATH];
SearchHandle = FindFirstFile("textures\\*.bmp",&finddata);
do
{
sprintf(buffer,"textures\\%s",finddata.cFileName);
Textures[NumFiles] = new CTexture(buffer);
NumFiles++;
}
while(FindNextFile(SearchHandle,&finddata)!=FALSE);
FindClose(SearchHandle);
NumTextures=NumFiles;
sprintf(buffer,"> Loaded %d textures",NumFiles);
Log.WriteToLogFile(buffer);
Masks[0] = new CTexture("masks\\mask1.msk");
Masks[1] = new CTexture("masks\\mask2.msk");
Masks[2] = new CTexture("masks\\mask3.msk");
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::RenderLiquids()
{
Icon=Cross;
for(int i=0;i<128;i++)
{
if(Liquids[i])
{
if(!CheckBoxes[3]->State)
{
if(i!=ActiveLiquid)
Liquids[i]->RenderOutline(FALSE);
else Liquids[i]->RenderOutline(TRUE);
}
}
}
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMain::CheckLiquids()
{
ActiveLiquid=-1;
if(CheckBoxes[3]->State) return(TRUE);
for(int i=0;i<128;i++)
{
if(Liquids[i])
{
Liquids[i]->CheckMouse(i);
}
}
return(TRUE);
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CMenu.cpp] - (21,972 bytes)
// CMenu.cpp
// by Comanche
#include "CMenu.h"
#include "CMain.h"
#include "CLog.h"
#include "CButton.h"
#include "CGraphics.h"
#include "CLandScape.h"
#include "CTexture.h"
#include "CViewport.h"
#include "CLiquid.h"
extern CMain GameMain;
extern CLog Log;
extern CGraphics Graphics;
extern CLandScape Land;
extern CViewport *Viewports[4];
extern CTexture *Textures[1024];
//////////////////////////////////////////////////////////////////////////////////
// main menu functions //
//////////////////////////////////////////////////////////////////////////////////
BOOL CMenu::Menu()
{
Exit=FALSE;
Open=TRUE;
MenuButtons[1] = new CButton(101,62,198,82,"Editor >","");
MenuButtons[2] = new CButton(101,20,198,40,"File >","");
MenuButtons[3] = new CButton(101,41,198,61,"Terrain >","");
while(!GameMain.MouseB[0] && !Exit)
{
GameMain.GetMouseInfo();
GameMain.GetKeyboardInfo();
if(MenuButtons[1]->TestIfPressed())
{
Editor();
continue;
}
if(MenuButtons[2]->TestIfPressed() && GameMain.Editor==0)
{
File();
continue;
}
if(MenuButtons[3]->TestIfPressed() && GameMain.Editor==0)
{
TextureOps();
continue;
}
if(GameMain.KeyboardB[0]=='E')
{
MenuButtons[1]->RedrawPushedButton();
Editor();
continue;
}
if(GameMain.KeyboardB[0]=='F' && GameMain.Editor==0)
{
MenuButtons[2]->RedrawPushedButton();
File();
continue;
}
if(GameMain.KeyboardB[0]=='T' && GameMain.Editor==0)
{
MenuButtons[3]->RedrawPushedButton();
TextureOps();
continue;
}
if(GameMain.KeyboardB[0]==27)
break;
Graphics.BltToBackBuffer();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
}
if(GameMain.Editor==0)
{
Graphics.Lock();
Land.FillScreen(101,20,297,104);
Graphics.UnLock();
}
if(GameMain.Editor==1)
{
Graphics.Lock();
Graphics.DrawButton(101,0,369,239);
Graphics.UnLock();
Viewports[0]->RedrawViewport();
}
delete MenuButtons[1];
delete MenuButtons[2];
delete MenuButtons[3];
Open=FALSE;
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMenu::File()
{
MenuButtons[4] = new CButton(199,20,297,40,"Save File","");
MenuButtons[5] = new CButton(199,41,297,61,"Load File","");
while(!GameMain.MouseB[0] && !Exit)
{
GameMain.GetMouseInfo();
GameMain.GetKeyboardInfo();
if(GameMain.KeyboardB[0]==27)
break;
if(GameMain.KeyboardB[0]=='S') SaveMap();
if(GameMain.KeyboardB[0]=='L') LoadMap();
if(MenuButtons[4]->TestIfPressed()) SaveMap();
if(MenuButtons[5]->TestIfPressed()) LoadMap();
Graphics.BltToBackBuffer();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
}
delete MenuButtons[4];
delete MenuButtons[5];
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMenu::TextureOps()
{
MenuButtons[4] = new CButton(199,41,297,61,"Fill Land 32","");
MenuButtons[5] = new CButton(199,62,297,82,"Fill Land 16","");
MenuButtons[6] = new CButton(199,83,297,104,"Fill Land 0","");
while(!GameMain.MouseB[0] && !Exit)
{
GameMain.GetMouseInfo();
GameMain.GetKeyboardInfo();
if(GameMain.KeyboardB[0]==27)
break;
if(MenuButtons[4]->TestIfPressed()) FillLand(32);
if(MenuButtons[5]->TestIfPressed()) FillLand(16);
if(MenuButtons[6]->TestIfPressed()) FillLand(0);
Graphics.BltToBackBuffer();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
}
delete MenuButtons[4];
delete MenuButtons[5];
delete MenuButtons[6];
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMenu::Editor()
{
MenuButtons[4] = new CButton(199,62,297,82,"Land","");
MenuButtons[5] = new CButton(199,83,297,103,"Voxel","");
while(!GameMain.MouseB[0] && !Exit)
{
GameMain.GetMouseInfo();
GameMain.GetKeyboardInfo();
if(GameMain.KeyboardB[0]==27)
break;
if(MenuButtons[4]->TestIfPressed()) SetEditor(0);
if(MenuButtons[5]->TestIfPressed()) SetEditor(1);
if(GameMain.KeyboardB[0]=='L') SetEditor(0);
if(GameMain.KeyboardB[0]=='V') SetEditor(1);
Graphics.BltToBackBuffer();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
}
delete MenuButtons[4];
delete MenuButtons[5];
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMenu::FillLand(int height)
{
Exit=TRUE;
if(Selection==-1) return(TRUE);
int x,x2,y,y2;
RGBTRIPLE color;
BYTE red,green,blue;
DWORD buffer2;
int Pos=ScrolPos+Selection;
int percent;
if(Textures[Pos]->isfailure) return(TRUE);
for(int i=0;i<2000;i++)
{
for(int i2=0;i2<2000;i2++)
{
x=i/Textures[Pos]->width;
y=i2/Textures[Pos]->height;
x2=i-(x*Textures[Pos]->width);
y2=i2-(y*Textures[Pos]->height);
color=Textures[Pos]->GetPixel(x2,y2);
red=color.rgbtRed; green=color.rgbtGreen; blue=color.rgbtBlue;
buffer2=(((height)<<24)|((red)<<16)|((green)<<8)|(blue));
Land.Landscape[i][i2]=buffer2;
}
}
Land.InitScreen();
CreateMiniMap();
DrawMiniMap();
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CMenu::SetEditor(int editor)
{
Exit=TRUE;
if(editor==GameMain.Editor) return(TRUE);
GameMain.Editor=editor;
GameMain.GameRestart();
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
// MiniMap functions //
//////////////////////////////////////////////////////////////////////////////////
void CMenu::CreateMiniMap()
{
int red=0,green=0,blue=0;
int counter=0;
BYTE *pointer;
for(BYTE x=0;x<64;x++)
for(BYTE y=0;y<64;y++)
{
counter=0;
red=0;green=0;blue=0;
for(int i=0;i<32;i++)
for(int i2=0;i2<32;i2++)
{
counter++;
pointer=(BYTE*)&Land.Landscape[x+i][y+i2];
blue+=*pointer;
green+=*(++pointer);
red+=*(++pointer);
}
MiniMapR[x][y]=red/counter;
MiniMapG[x][y]=green/counter;
MiniMapB[x][y]=blue/counter;
}
}
//////////////////////////////////////////////////////////////////////////////////
void CMenu::DrawMiniMap()
{
for(int x=0;x<64;x++)
for(int y=0;y<64;y++)
{
Graphics.Lock();
Graphics.PutPixel(17+x,y+271,
MiniMapR[x][y],
MiniMapG[x][y],
MiniMapB[x][y]);
Graphics.UnLock();
}
}
//////////////////////////////////////////////////////////////////////////////////
// texture menu funktions //
//////////////////////////////////////////////////////////////////////////////////
void CMenu::DrawTextures()
{
int red=0,green=0,blue=0;
RGBTRIPLE color;
int colord=0;
int counter=0;
Graphics.logfont.lfHeight = TEXTUREFONTHEIGHT;
Graphics.textcolor.rgbtRed = 192;
Graphics.textcolor.rgbtGreen = 192;
Graphics.textcolor.rgbtBlue = 192;
for(int i=0;i<7;i++)
{
int TexPos=i+ScrolPos;
int PosX=573;
int PosY=9+(65*i);
Graphics.BlackQuader(PosX,PosY,PosX+64,PosY+64);
Graphics.Lock();
if(!Textures[TexPos]) continue;
if(Textures[TexPos]->isfailure) continue;
if(Textures[TexPos]->width<=64 && Textures[TexPos]->height<=64)
{
for(int x=0;x<Textures[TexPos]->width;x++)
for(int y=0;y<Textures[TexPos]->height;y++)
{
color=Textures[TexPos]->GetPixel(x,y);
Graphics.PutPixel(PosX+x,PosY+y,color.rgbtRed,
color.rgbtGreen,color.rgbtBlue);
}
}
else
{
int scale=0;
if(Textures[TexPos]->width>Textures[TexPos]->height)
scale=Textures[TexPos]->width/64;
else scale=Textures[TexPos]->height/64;
for(int x=0;x<Textures[TexPos]->width;x++)
for(int y=0;y<Textures[TexPos]->height;y++)
{
counter=0;
red=0;green=0;blue=0;
for(int i=0;i<scale;i++)
for(int i2=0;i2<scale;i2++)
{
if(Textures[TexPos]->width>(x+i) &&
Textures[TexPos]->height>(y+i2))
{
counter++;
color=Textures[TexPos]->GetPixel(x+i,y+i2);
red=red+color.rgbtRed;
green=green+color.rgbtGreen;
blue=blue=blue+color.rgbtBlue;
}
}
red=red/counter;
green=green/counter;
blue=blue/counter;
Graphics.PutPixel(PosX+x/scale,PosY+y/scale,red,green,blue);
}
}
Graphics.UnLock();
Graphics.OSGetLaDC();
Graphics.Text(PosX+2,PosY+2,Textures[TexPos]->Name);
Graphics.OSReleaseDC();
} // end for
Graphics.textcolor.rgbtRed = 0;
Graphics.textcolor.rgbtGreen = 0;
Graphics.textcolor.rgbtBlue = 0;
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
}
//////////////////////////////////////////////////////////////////////////////////
// file menu functions //
//////////////////////////////////////////////////////////////////////////////////
void CMenu::SaveMap()
{
while(GameMain.KeyboardB[0])
GameMain.GetKeyboardInfo();
int mfh;
OFSTRUCT map_file_data;
Exit=TRUE;
Graphics.Lock();
Land.FillScreen(101,20,297,82);
Graphics.DrawButton(101,450,559,479);
Graphics.DrawPushedButton(110,455,550,475);
Graphics.UnLock();
int i=0;
GameMain.GetKeyboardInfo();
sprintf(buffer,"");
while(GameMain.KeyboardB[0]!=13)
{
GameMain.GetKeyboardInfo();
if(GameMain.KeyboardB[0]==8)
{
if(i==0) continue;
buffer[i-1]=0;
i--;
while(GameMain.KeyboardB[0])
GameMain.GetKeyboardInfo();
}
if(GameMain.KeyboardB[0]==27)
{
Graphics.Lock();
Land.FillScreen(101,450,559,479);
Graphics.UnLock();
return;
}
if(GameMain.KeyboardB[0]!=0)
{
if(i>20) continue;
if(GameMain.KeyboardB[0]==27) continue;
if(GameMain.KeyboardB[0]==8) continue;
buffer[i]=GameMain.KeyboardB[0];
buffer[i+1]=0;
i++;
while(GameMain.KeyboardB[0])
GameMain.GetKeyboardInfo();
}
GameMain.GetMouseInfo();
Graphics.BltToBackBuffer();
Graphics.GetLaDC();
Graphics.Text(114,458,buffer);
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
GameMain.GetKeyboardInfo();
}
Graphics.Lock();
Land.FillScreen(101,450,559,479);
Graphics.UnLock();
Graphics.BltToBackBuffer();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Clock);
Graphics.ReleaseDC();
Graphics.Flip();
if(!buffer[0]) return;
char filename[80];
sprintf(filename,"MAPS\\%s.VMP",buffer);
mfh = OpenFile(filename,&map_file_data,OF_CREATE);
if(mfh == HFILE_ERROR)
{
sprintf(buffer,"> Error: Saving %s",filename);
Log.WriteErrorToLogFile(buffer);
return;
}
_lwrite(mfh,"PEVoxEd Map 1.1",strlen("PEVoxEd Map 1.0"));
_lwrite(mfh,(CHAR *)&Land.Day,sizeof(BOOL));
_lwrite(mfh,(CHAR *)&Land.Landscape,sizeof(Land.Landscape));
_close(mfh);
sprintf(buffer,"> Saved File: %s",filename);
Log.WriteToLogFile(buffer);
sprintf(buffer,"");
}
//////////////////////////////////////////////////////////////////////////////////
void CMenu::LoadMap()
{
while(GameMain.KeyboardB[0])
GameMain.GetKeyboardInfo();
int mfh;
OFSTRUCT map_file_data;
BOOL Cursor=TRUE;
char buffer2[80];
Exit=TRUE;
Graphics.Lock();
Land.FillScreen(101,20,297,82);
Graphics.DrawButton(101,450,559,479);
Graphics.DrawPushedButton(110,455,550,475);
Graphics.UnLock();
int i=0;
GameMain.GetKeyboardInfo();
sprintf(buffer,"");
while(GameMain.KeyboardB[0]!=13)
{
GameMain.GetKeyboardInfo();
if(GameMain.KeyboardB[0]==8)
{
if(i==0) continue;
buffer[i-1]=0;
i--;
while(GameMain.KeyboardB[0])
GameMain.GetKeyboardInfo();
}
if(GameMain.KeyboardB[0]==27)
{
Graphics.Lock();
Land.FillScreen(101,450,559,479);
Graphics.UnLock();
return;
}
if(GameMain.KeyboardB[0]!=0)
{
if(i>20) continue;
if(GameMain.KeyboardB[0]==27) continue;
if(GameMain.KeyboardB[0]==8) continue;
buffer[i]=GameMain.KeyboardB[0];
buffer[i+1]=0;
i++;
while(GameMain.KeyboardB[0])
GameMain.GetKeyboardInfo();
}
GameMain.GetMouseInfo();
Graphics.BltToBackBuffer();
Graphics.GetLaDC();
Graphics.Text(114,458,buffer);
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
GameMain.GetKeyboardInfo();
}
if(!buffer[0])
{
Graphics.Lock();
Land.FillScreen(101,450,559,479);
Graphics.UnLock();
return;
}
Graphics.Lock();
Land.FillScreen(101,450,559,479);
Graphics.UnLock();
Graphics.BltToBackBuffer();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Clock);
Graphics.ReleaseDC();
Graphics.Flip();
char filename[80];
sprintf(filename,"MAPS\\%s.VMP",buffer);
mfh = OpenFile(filename,&map_file_data,OF_READ);
if(mfh == HFILE_ERROR)
{
_close(mfh);
sprintf(buffer,"> Error: Reading %s",filename);
Log.WriteErrorToLogFile(buffer);
Graphics.Lock();
Land.FillScreen(101,450,559,479);
Graphics.UnLock();
MessageBox("Error","Can't read file",MS_OK);
return;
}
ZeroMemory(buffer,sizeof(buffer));
_lread(mfh,(LPVOID)buffer,strlen("PEVoxEd Map 1.0"));
if(strcmp(buffer,"PEVoxEd Map 1.0")==0)
{
Land.Day=TRUE;
_lread(mfh,&Land.Landscape,sizeof(Land.Landscape));
_close(mfh);
sprintf(buffer,"> Loaded File: %s",filename);
Log.WriteToLogFile(buffer);
}
else if(strcmp(buffer,"PEVoxEd Map 1.1")==0)
{
if(_lread(mfh,&Land.Day,sizeof(BOOL))==HFILE_ERROR)
Log.WriteErrorToLogFile("> Error");
if(_lread(mfh,&Land.Landscape,sizeof(Land.Landscape))==HFILE_ERROR)
Log.WriteErrorToLogFile("> Error");
_close(mfh);
sprintf(buffer,"> Loaded File: %s",filename);
Log.WriteToLogFile(buffer);
}
else
{
_close(mfh);
sprintf(buffer,"> %s: Not a PEVoxEd Map",filename);
Log.WriteErrorToLogFile(buffer);
MessageBox("Error","Can't read file",MS_OK);
return;
}
Graphics.Lock();
Land.InitScreen();
CreateMiniMap();
DrawMiniMap();
Graphics.UnLock();
}
//////////////////////////////////////////////////////////////////////////////////
void CMenu::DrawTextures(int TexPos)
{
int red=0,green=0,blue=0;
RGBTRIPLE color;
int colord=0;
int counter=0;
Graphics.logfont.lfHeight = TEXTUREFONTHEIGHT;
Graphics.textcolor.rgbtRed = 192;
Graphics.textcolor.rgbtGreen = 192;
Graphics.textcolor.rgbtBlue = 192;
int PosX=573;
int PosY=9+(65*TexPos);
TexPos=TexPos+ScrolPos;
Graphics.BlackQuader(PosX,PosY,PosX+64,PosY+64);
Graphics.Lock();
if(!Textures[TexPos]) return;
if(Textures[TexPos]->isfailure) return;
if(Textures[TexPos]->width<=64 && Textures[TexPos]->height<=64)
{
for(int x=0;x<Textures[TexPos]->width;x++)
for(int y=0;y<Textures[TexPos]->height;y++)
{
color=Textures[TexPos]->GetPixel(x,y);
Graphics.PutPixel(PosX+x,PosY+y,color.rgbtRed,
color.rgbtGreen,color.rgbtBlue);
}
}
else
{
int scale;
if(Textures[TexPos]->width>Textures[TexPos]->height)
scale=Textures[TexPos]->width/64;
else scale=Textures[TexPos]->height/64;
for(int x=0;x<Textures[TexPos]->width;x++)
for(int y=0;y<Textures[TexPos]->height;y++)
{
counter=0;
red=0;green=0;blue=0;
for(int i=0;i<scale;i++)
for(int i2=0;i2<scale;i2++)
{
if(Textures[TexPos]->width>(x+i) &&
Textures[TexPos]->height>(y+i2))
{
counter++;
color=Textures[TexPos]->GetPixel(x+i,y+i2);
red=red+color.rgbtRed;
green=green+color.rgbtGreen;
blue=blue=blue+color.rgbtBlue;
}
}
red=red/counter;
green=green/counter;
blue=blue/counter;
Graphics.PutPixel(PosX+x/scale,PosY+y/scale,red,green,blue);
}
}
Graphics.UnLock();
Graphics.OSGetLaDC();
Graphics.Text(PosX+2,PosY+2,Textures[TexPos]->Name);
Graphics.OSReleaseDC();
Graphics.textcolor.rgbtRed = 0;
Graphics.textcolor.rgbtGreen = 0;
Graphics.textcolor.rgbtBlue = 0;
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
}
//////////////////////////////////////////////////////////////////////////////////
void CMenu::DrawSelected(int TexPos)
{
int red=0,green=0,blue=0;
RGBTRIPLE color;
int colord=0;
int counter=0;
Graphics.logfont.lfHeight = TEXTUREFONTHEIGHT;
Graphics.textcolor.rgbtRed = 192;
Graphics.textcolor.rgbtGreen = 192;
Graphics.textcolor.rgbtBlue = 192;
int PosX=573;
int PosY=9+(65*TexPos);
TexPos=TexPos+ScrolPos;
Graphics.BlackQuader(PosX,PosY,PosX+64,PosY+64);
Graphics.Lock();
if(!Textures[TexPos]) return;
if(Textures[TexPos]->isfailure) return;
if(Textures[TexPos]->width<=64 && Textures[TexPos]->height<=64)
{
for(int x=0;x<Textures[TexPos]->width;x++)
for(int y=0;y<Textures[TexPos]->height;y++)
{
color=Textures[TexPos]->GetPixel(x,y);
blue=color.rgbtBlue;
if(blue>=205) blue=255;
else blue+=50;
Graphics.PutPixel(PosX+x,PosY+y,color.rgbtRed,
color.rgbtGreen,blue);
}
}
else
{
int scale;
if(Textures[TexPos]->width>Textures[TexPos]->height)
scale=Textures[TexPos]->width/64;
else scale=Textures[TexPos]->height/64;
for(int x=0;x<Textures[TexPos]->width;x++)
for(int y=0;y<Textures[TexPos]->height;y++)
{
counter=0;
red=0;green=0;blue=0;
for(int i=0;i<scale;i++)
for(int i2=0;i2<scale;i2++)
{
if(Textures[TexPos]->width>(x+i) &&
Textures[TexPos]->height>(y+i2))
{
counter++;
color=Textures[TexPos]->GetPixel(x+i,y+i2);
red=red+color.rgbtRed;
green=green+color.rgbtGreen;
blue=blue+color.rgbtBlue;
}
}
red=red/counter;
green=green/counter;
blue=blue/counter;
if(blue>=205) blue=255;
else blue+=50;
Graphics.PutPixel(PosX+x/scale,PosY+y/scale,red,green,blue);
}
}
Graphics.UnLock();
Graphics.OSGetLaDC();
Graphics.Text(PosX+2,PosY+2,Textures[TexPos]->Name);
Graphics.OSReleaseDC();
Graphics.textcolor.rgbtRed = 0;
Graphics.textcolor.rgbtGreen = 0;
Graphics.textcolor.rgbtBlue = 0;
Graphics.logfont.lfHeight = STANDARTFONTHEIGHT;
}
//////////////////////////////////////////////////////////////////////////////////
void CMenu::SelectTexture()
{
while(GameMain.MouseB[0])
GameMain.GetMouseInfo();
int y=GameMain.MouseY-8;
y=y/65;
// if(y>=GameMain.NumTextures) return;
if(Selection>=0)
DrawTextures(Selection);
Selection=y;
DrawSelected(y);
}
//////////////////////////////////////////////////////////////////////////////////
void CMenu::ScrollUp()
{
if(GameMain.NumTextures<8)
return;
if(ScrolPos==0)
return;
Selection=-1;
if(ScrolPos!=1)
{
ScrolPos-=2;
Graphics.Blt(573,9,637,334,0,130);
DrawTextures(0);
DrawTextures(1);
}
else
{
ScrolPos-=1;
Graphics.Blt(573,9,637,399,0,65);
DrawTextures(0);
}
}
//////////////////////////////////////////////////////////////////////////////////
void CMenu::ScrollDown()
{
if(GameMain.NumTextures<8)
return;
if(ScrolPos+8>GameMain.NumTextures)
return;
if(ScrolPos+8>1024)
return;
Selection=-1;
if(ScrolPos+9>GameMain.NumTextures)
{
ScrolPos+=1;
Graphics.Blt(573,74,637,464,0,-65);
DrawTextures(6);
}
else
{
ScrolPos+=2;
Graphics.Blt(573,139,637,464,0,-130);
DrawTextures(5);
DrawTextures(6);
}
}
//////////////////////////////////////////////////////////////////////////////////
// Message Box functions //
//////////////////////////////////////////////////////////////////////////////////
BOOL CMenu::MessageBox(char *caption,char *string,int ms)
{
Exit=FALSE;
State=FALSE;
BOOL Status7=FALSE;
if(GameMain.Status2==7)
{
GameMain.Status2=1;
Status7=TRUE;
}
while(GameMain.KeyboardB[0])
GameMain.GetKeyboardInfo();
if(!Graphics.StoreScreenArea(230,150,430,230)) return(FALSE);
Graphics.Lock();
Graphics.DrawButton(230,150,430,230);
for(int i=0;i<98;i++)
{
Graphics.FullQuader(232+i*2,152,234+i*2,166,0,0,200-i);
}
Graphics.UnLock();
Graphics.OSGetLaDC();
Graphics.Text(234,151,caption);
Graphics.OSReleaseDC();
Graphics.OSGetDC();
Graphics.Text(330,177,string);
Graphics.OSReleaseDC();
if(ms==MS_OK)
{
MenuButtons[0] = new CButton(290,200,370,220,"OK","");
}
if(ms==MS_YESNO)
{
MenuButtons[0] = new CButton(260,200,320,220,"Yes","");
MenuButtons[1] = new CButton(340,200,400,220,"No","");
}
while(!Exit)
{
GameMain.GetMouseInfo();
GameMain.GetKeyboardInfo();
if(GameMain.KeyboardB[0]==13)
{
State=TRUE;
Exit=TRUE;
}
if(ms==MS_OK)
if(MenuButtons[0]->TestIfPressed()) Exit=TRUE;
if(ms==MS_YESNO)
{
if(MenuButtons[0]->TestIfPressed())
{
State=TRUE;
Exit=TRUE;
}
if(MenuButtons[1]->TestIfPressed())
{
State=FALSE;
Exit=TRUE;
}
}
Graphics.BltToBackBuffer();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
}
if(ms==MS_OK)
{
delete MenuButtons[0];
}
if(ms==MS_YESNO)
{
delete MenuButtons[0];
delete MenuButtons[1];
}
if(!Graphics.RestoreScreenArea()) return(FALSE);
if(Status7==TRUE)
{
GameMain.Status2=7;
}
return(State);
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CTexture.cpp] - (3,841 bytes)
// CTexture.cpp
// by Comanche
#include "CTexture.h"
#include "CLog.h"
extern CLog Log;
//////////////////////////////////////////////////////////////////////////////////
CTexture::CTexture(char *filename)
{
tfh = OpenFile(filename,&file_data,OF_READ);
int i=0;
while(filename[i]!=0)
{
if(filename[i]=='\\')
{
i++;
break;
}
i++;
}
strcpy(Name,&filename[i]);
if(!strcmp(filename,""))
{
isfailure=TRUE;
return;
}
if(tfh==HFILE_ERROR)
{
isfailure=TRUE;
sprintf(buffer,"> Error: Reading %s (doesn't exist)",filename);
Log.WriteErrorToLogFile(buffer);
return;
}
_lread(tfh,&bitmap.bitmapfileheader,sizeof(BITMAPFILEHEADER));
if (bitmap.bitmapfileheader.bfType!=BITMAP_ID)
{
isfailure=TRUE;
sprintf(buffer,"> Error: Reading %s (not a bitmap)",filename);
Log.WriteErrorToLogFile(buffer);
_close(tfh);
return;
}
_lread(tfh,&bitmap.bitmapinfoheader,sizeof(BITMAPINFOHEADER));
if (bitmap.bitmapinfoheader.biBitCount!=8 &&
bitmap.bitmapinfoheader.biBitCount!=24)
{
isfailure=TRUE;
sprintf(buffer,"> Error: Reading %s (not 8 or 24 bit)",filename);
Log.WriteErrorToLogFile(buffer);
_close(tfh);
return;
}
if (bitmap.bitmapinfoheader.biWidth>256 ||
bitmap.bitmapinfoheader.biHeight>256)
{
isfailure=TRUE;
sprintf(buffer,"> Error: Reading %s (over 256x256)",filename);
Log.WriteErrorToLogFile(buffer);
_close(tfh);
return;
}
if(bitmap.bitmapinfoheader.biWidth%32!=0 &&
bitmap.bitmapinfoheader.biHeight%32!=0)
{
isfailure=TRUE;
sprintf(buffer,"> Error: Reading %s",filename);
Log.WriteErrorToLogFile(buffer);
_close(tfh);
return;
}
if(bitmap.bitmapinfoheader.biCompression!=BI_RGB)
{
isfailure=TRUE;
sprintf(buffer,"> Error: Reading %s (is compressed)",filename);
Log.WriteErrorToLogFile(buffer);
_close(tfh);
return;
}
if (bitmap.bitmapinfoheader.biBitCount==8)
{
int NumColor=256;
if(bitmap.bitmapinfoheader.biClrUsed!=0)
NumColor=bitmap.bitmapinfoheader.biClrUsed;
_lread(tfh, &bitmap.palette,NumColor*sizeof(PALETTEENTRY));
for (int index=0; index < NumColor; index++)
{
int temp_color = bitmap.palette[index].peRed;
bitmap.palette[index].peRed = bitmap.palette[index].peBlue;
bitmap.palette[index].peBlue = temp_color;
bitmap.palette[index].peFlags = PC_NOCOLLAPSE;
}
}
_lseek(tfh,-(int)(bitmap.bitmapinfoheader.biSizeImage),SEEK_END);
if (!(bitmap.buffer = (UCHAR *)malloc(bitmap.bitmapinfoheader.biSizeImage)))
{
sprintf(buffer,"> Error: Reading %s",filename);
Log.WriteErrorToLogFile(buffer);
_close(tfh);
return;
}
_lread(tfh,bitmap.buffer,bitmap.bitmapinfoheader.biSizeImage);
width = bitmap.bitmapinfoheader.biWidth;
height = bitmap.bitmapinfoheader.biHeight;
bitcount = bitmap.bitmapinfoheader.biBitCount;
isfailure=FALSE;
_close(tfh);
}
//////////////////////////////////////////////////////////////////////////////////
CTexture::~CTexture()
{
free(bitmap.buffer);
}
//////////////////////////////////////////////////////////////////////////////////
RGBTRIPLE CTexture::GetPixel(int x, int y)
{
RGBTRIPLE color;
if(bitcount==24)
{
int pos=(x*3)+((height-y-1)*width*3);
color.rgbtRed=bitmap.buffer[pos+2];
color.rgbtGreen=bitmap.buffer[pos+1];
color.rgbtBlue=bitmap.buffer[pos];
return(color);
}
else if(bitcount==8)
{
int pos=x+((height-y-1)*width);
BYTE index=bitmap.buffer[pos];
color.rgbtRed=bitmap.palette[index].peRed;
color.rgbtGreen=bitmap.palette[index].peGreen;
color.rgbtBlue=bitmap.palette[index].peBlue;
return(color);
}
color.rgbtBlue=255; // Dummies for Compiler
color.rgbtGreen=255;
color.rgbtRed=255;
return(color);
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CTime.cpp] - (449 bytes)
// CTime.cpp
// by Comanche
#include "CTime.h"
//////////////////////////////////////////////////////////////////////////////////
int CTime::GetFPS(int FrameTime)
{
if(!FrameTime) return(0);
return(1000/FrameTime);
}
//////////////////////////////////////////////////////////////////////////////////
int CTime::GetFrameTime()
{
FrameTime=timeGetTime()-LastFrameTime;
LastFrameTime=timeGetTime();
return(FrameTime);
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CViewport.cpp] - (8,252 bytes)
// CViewport.cpp
// by Comanche
#include "CViewport.h"
#include "CMain.h"
#include "CGraphics.h"
#include "CButton.h"
#include "CLog.h"
#include "CVoxel.h"
#include "CColor.h"
extern CMain GameMain;
extern CGraphics Graphics;
extern CLog Log;
extern CVoxel Voxel;
extern CColor Color;
//////////////////////////////////////////////////////////////////////////////////
CViewport::CViewport(int x,int y,int M)
{
Vx=x; Vy=y;
Vx2=Vx+195; Vy2=Vy+195;
Mode=M;
Voxel.FrontPos=48;
if(Mode!=VIEWPORT3D)
{
ViewportButtons[0] = new CButton(x+200,y,x+210,y+98,"","");
ViewportButtons[1] = new CButton(x+200,y+99,x+210,y+196,"","");
}
}
//////////////////////////////////////////////////////////////////////////////////
CViewport::~CViewport()
{
if(Mode!=VIEWPORT3D)
{
delete ViewportButtons[0];
delete ViewportButtons[1];
}
}
//////////////////////////////////////////////////////////////////////////////////
void CViewport::UseViewport()
{
if(Mode!=VIEWPORT3D)
{
if(ViewportButtons[0]->TestIfPressed())
{
if(Mode==VIEWPORTTOP)
if(Voxel.TopPos>0)
{
Voxel.TopPos--;
Graphics.Lock();
for(int i=0;i<49;i++)
for(int i2=0;i2<49;i2++)
{
Graphics.FullQuader(Vx+(i*4)+1,Vy+(i2*4)+1,
Vx+(i*4)+3,Vy+(i2*4)+3,
Voxel.Voxels[i][i2][Voxel.TopPos].rgbtRed,
Voxel.Voxels[i][i2][Voxel.TopPos].rgbtGreen,
Voxel.Voxels[i][i2][Voxel.TopPos].rgbtBlue);
}
Graphics.UnLock();
}
if(Mode==VIEWPORTFRONT)
if(Voxel.FrontPos>0)
{
Voxel.FrontPos--;
Graphics.Lock();
for(int i=0;i<49;i++)
for(int i2=0;i2<49;i2++)
{
Graphics.FullQuader(Vx+(i*4)+1,Vy+(i2*4)+1,
Vx+(i*4)+3,Vy+(i2*4)+3,
Voxel.Voxels[Voxel.FrontPos][i][i2].rgbtRed,
Voxel.Voxels[Voxel.FrontPos][i][i2].rgbtGreen,
Voxel.Voxels[Voxel.FrontPos][i][i2].rgbtBlue);
}
Graphics.UnLock();
}
if(Mode==VIEWPORTLEFT)
{
if(Voxel.LeftPos>0)
{
Voxel.LeftPos--;
Graphics.Lock();
for(int i=0;i<49;i++)
for(int i2=0;i2<49;i2++)
{
Graphics.FullQuader(Vx+(i*4)+1,Vy+(i2*4)+1,
Vx+(i*4)+3,Vy+(i2*4)+3,
Voxel.Voxels[i][Voxel.LeftPos][i2].rgbtRed,
Voxel.Voxels[i][Voxel.LeftPos][i2].rgbtGreen,
Voxel.Voxels[i][Voxel.LeftPos][i2].rgbtBlue);
}
Graphics.UnLock();
}
}
}
//////////////////////////////////////////////////////////////////////
if(ViewportButtons[1]->TestIfPressed())
{
if(Mode==VIEWPORTTOP)
if(Voxel.TopPos<48)
{
Voxel.TopPos++;
Graphics.Lock();
for(int i=0;i<49;i++)
for(int i2=0;i2<49;i2++)
{
Graphics.FullQuader(Vx+(i*4)+1,Vy+(i2*4)+1,
Vx+(i*4)+3,Vy+(i2*4)+3,
Voxel.Voxels[i][i2][Voxel.TopPos].rgbtRed,
Voxel.Voxels[i][i2][Voxel.TopPos].rgbtGreen,
Voxel.Voxels[i][i2][Voxel.TopPos].rgbtBlue);
}
Graphics.UnLock();
}
if(Mode==VIEWPORTFRONT)
if(Voxel.FrontPos<48)
{
Voxel.FrontPos++;
Graphics.Lock();
for(int i=0;i<49;i++)
for(int i2=0;i2<49;i2++)
{
Graphics.FullQuader(Vx+(i*4)+1,Vy+(i2*4)+1,
Vx+(i*4)+3,Vy+(i2*4)+3,
Voxel.Voxels[Voxel.FrontPos][i][i2].rgbtRed,
Voxel.Voxels[Voxel.FrontPos][i][i2].rgbtGreen,
Voxel.Voxels[Voxel.FrontPos][i][i2].rgbtBlue);
}
Graphics.UnLock();
}
if(Mode==VIEWPORTLEFT)
if(Voxel.LeftPos<48)
{
Voxel.LeftPos++;
Graphics.Lock();
for(int i=0;i<49;i++)
for(int i2=0;i2<49;i2++)
{
Graphics.FullQuader(Vx+(i*4)+1,Vy+(i2*4)+1,
Vx+(i*4)+3,Vy+(i2*4)+3,
Voxel.Voxels[i][Voxel.LeftPos][i2].rgbtRed,
Voxel.Voxels[i][Voxel.LeftPos][i2].rgbtGreen,
Voxel.Voxels[i][Voxel.LeftPos][i2].rgbtBlue);
}
Graphics.UnLock();
}
}
}
if(Mode==VIEWPORTLEFT)
{
Graphics.Lock();
Graphics.FullQuader(Vx+(Voxel.FrontPos*4)-4,Vy+199,
Vx+(Voxel.FrontPos*4)+7,Vy+203,150,150,150);
Graphics.FullQuader(Vx+(Voxel.FrontPos*4)+1,Vy+199,
Vx+(Voxel.FrontPos*4)+2,Vy+203,100,100,100);
Graphics.VLine(Vx+(Voxel.FrontPos*4),Vy+200,3,100,100,100);
Graphics.FullQuader(Vx-7,Vy+(Voxel.TopPos*4)-4,
Vx-3,Vy+(Voxel.TopPos*4)+7,150,150,150);
Graphics.FullQuader(Vx-7,Vy+(Voxel.TopPos*4)+1,
Vx-3,Vy+(Voxel.TopPos*4)+2,100,100,100);
Graphics.HLine(Vx-4,Vy+(Voxel.TopPos*4),3,100,100,100);
Graphics.UnLock();
if(GameMain.CheckMouseRange(Vx,Vy,Vx2,Vy2,FALSE))
{
if((GameMain.MouseX-Vx)%4!=0
&& (GameMain.MouseY-Vy)%4!=0)
{
Voxel.ViewX=(GameMain.MouseX-Vx)/4;
Voxel.ViewY=(GameMain.MouseY-Vy)/4;
if(GameMain.MouseB[0])
{
Voxel.Voxels[Voxel.ViewX][Voxel.LeftPos][Voxel.ViewY]
= Color.color;
Graphics.Lock();
Graphics.FullQuader(Vx+(Voxel.ViewX*4)+1,Vy+(Voxel.ViewY*4)+1,
Vx+(Voxel.ViewX*4)+3,Vy+(Voxel.ViewY*4)+3,
Color.color.rgbtRed,Color.color.rgbtGreen,
Color.color.rgbtBlue);
Graphics.UnLock();
}
}
}
return;
}
if(Mode==VIEWPORTTOP)
{
Graphics.Lock();
Graphics.FullQuader(Vx+(Voxel.LeftPos*4)-4,Vy+199,
Vx+(Voxel.LeftPos*4)+7,Vy+203,150,150,150);
Graphics.FullQuader(Vx+(Voxel.LeftPos*4)+1,Vy+199,
Vx+(Voxel.LeftPos*4)+2,Vy+203,100,100,100);
Graphics.VLine(Vx+(Voxel.LeftPos*4),Vy+200,3,100,100,100);
Graphics.FullQuader(Vx-7,Vy+(Voxel.FrontPos*4)-4,
Vx-3,Vy+(Voxel.FrontPos*4)+7,150,150,150);
Graphics.FullQuader(Vx-7,Vy+(Voxel.FrontPos*4)+1,
Vx-3,Vy+(Voxel.FrontPos*4)+2,100,100,100);
Graphics.HLine(Vx-4,Vy+(Voxel.FrontPos*4),3,100,100,100);
Graphics.UnLock();
if(GameMain.CheckMouseRange(Vx,Vy,Vx2,Vy2,FALSE))
{
if((GameMain.MouseX-Vx)%4!=0
&& (GameMain.MouseY-Vy)%4!=0)
{
Voxel.ViewX=(GameMain.MouseX-Vx)/4;
Voxel.ViewY=(GameMain.MouseY-Vy)/4;
if(GameMain.MouseB[0])
{
Voxel.Voxels[Voxel.ViewY][Voxel.ViewX][Voxel.TopPos]
= Color.color;
Graphics.Lock();
Graphics.FullQuader(Vx+(Voxel.ViewX*4)+1,Vy+(Voxel.ViewY*4)+1,
Vx+(Voxel.ViewX*4)+3,Vy+(Voxel.ViewY*4)+3,
Color.color.rgbtRed,Color.color.rgbtGreen,
Color.color.rgbtBlue);
Graphics.UnLock();
}
}
}
return;
}
if(Mode==VIEWPORTFRONT)
{
Graphics.Lock();
Graphics.FullQuader(Vx+(Voxel.LeftPos*4)-4,Vy+199,
Vx+(Voxel.LeftPos*4)+7,Vy+203,150,150,150);
Graphics.FullQuader(Vx+(Voxel.LeftPos*4)+1,Vy+199,
Vx+(Voxel.LeftPos*4)+2,Vy+203,100,100,100);
Graphics.VLine(Vx+(Voxel.LeftPos*4),Vy+200,3,100,100,100);
Graphics.FullQuader(Vx-7,Vy+(Voxel.TopPos*4)-4,
Vx-3,Vy+(Voxel.TopPos*4)+7,150,150,150);
Graphics.FullQuader(Vx-7,Vy+(Voxel.TopPos*4)+1,
Vx-3,Vy+(Voxel.TopPos*4)+2,100,100,100);
Graphics.HLine(Vx-4,Vy+(Voxel.TopPos*4),3,100,100,100);
Graphics.UnLock();
if(GameMain.CheckMouseRange(Vx,Vy,Vx2,Vy2,FALSE))
{
if((GameMain.MouseX-Vx)%4!=0
&& (GameMain.MouseY-Vy)%4!=0)
{
Voxel.ViewX=(GameMain.MouseX-Vx)/4;
Voxel.ViewY=(GameMain.MouseY-Vy)/4;
}
}
return;
}
if(Mode==VIEWPORT3D)
{
return;
}
}
//////////////////////////////////////////////////////////////////////////////////
void CViewport::RedrawViewport()
{
Graphics.BlackQuader(Vx+1,Vy+1,Vx+196,Vy+196);
Graphics.Lock();
Graphics.Quader(Vx,Vy,Vx+196,Vy+196,120,120,120);
Graphics.UnLock();
Graphics.OSGetDC();
if (Mode==VIEWPORT3D) Graphics.Text(Vx+98,Vy-16,"3D");
if (Mode==VIEWPORTFRONT) Graphics.Text(Vx+98,Vy-16,"Front");
if (Mode==VIEWPORTLEFT) Graphics.Text(Vx+98,Vy-16,"Left");
if (Mode==VIEWPORTTOP) Graphics.Text(Vx+98,Vy-16,"Top");
Graphics.OSReleaseDC();
if(Mode!=VIEWPORT3D)
{
ViewportButtons[0]->RedrawButton();
ViewportButtons[1]->RedrawButton();
}
}
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CVoxel.cpp] - (160 bytes)
// CVoxel.cpp
// by Comanche
#include "CVoxel.h"
#include "CMain.h"
//////////////////////////////////////////////////////////////////////////////////
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [PEVoxEd.cpp] - (5,472 bytes)
// PEVoxEd.cpp
// by Comanche
#include "defines.h"
#include "CMain.h"
#include "CLog.h"
#include "CGraphics.h"
#include "CButton.h"
#include "CLandScape.h"
#include "CMenu.h"
#include "CTime.h"
#include "CTexture.h"
#include "CViewport.h"
#include "CColor.h"
#include "CVoxel.h"
#include "CLiquid.h"
#include "CCheckBox.h"
//////////////////////////////////////////////////////////////////////////////////
CMain GameMain;
CLog Log;
CGraphics Graphics;
CLandScape Land;
CMenu Menu;
CTime Time;
CColor Color;
CButton *Buttons[60];
CCheckBox *CheckBoxes[20];
CViewport *Viewports[4];
CTexture *Textures[1024];
CLiquid *Liquids[128];
CTexture *Masks[3];
CVoxel Voxel;
//////////////////////////////////////////////////////////////////////////////////
HWND main_window_handle = NULL; // save the window handle
HINSTANCE main_instance = NULL; // save the instance
BOOL bActive=TRUE, // is the aplication minimized?
bMinimized=FALSE;
BYTE *video_buffer;
int WordsPerLine;
//////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context
switch(msg)
{
case WM_CREATE:
{
return(0);
} break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
case WM_ACTIVATEAPP:
{
bActive = (BOOL)wparam;
} break;
default:break;
} // end switch
return (DefWindowProc(hwnd, msg, wparam, lparam));
} // end WinProc
// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASS winclass; // this will hold the class we create
HWND hwnd; // generic window handle
MSG msg; // generic message
Log.WriteStatusToLogFile("> Initialize Window");
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_ICON));
winclass.hCursor = LoadCursor(hinstance,IDC_ARROW);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
if (!RegisterClass(&winclass))
{
Log.WriteErrorToLogFile("> Error: Register window class");
return(0);
}
Log.WriteToLogFile("> Register window class: OK");
if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
"VoxEd 2.0", // title
WS_POPUP | WS_VISIBLE,
0,0, // x,y
WINDOW_WIDTH, // width
WINDOW_HEIGHT, // height
NULL, // handle to parent
NULL, // handle to menu
hinstance,// instance
NULL))) // creation parms
{
Log.WriteErrorToLogFile("> Error: Create window");
return(FALSE);
}
Log.WriteToLogFile("> Create window: OK");
main_window_handle = hwnd;
main_instance = hinstance;
Log.WriteStatusToLogFile("> GameInit: Initialize MMX DirectDraw graphic subsystem");
if(!GameMain.GameInit(main_window_handle)) // Game initializing
{
GameMain.GameShutdown(); // an error
return(FALSE);
}
Log.WriteToLogFile("> GameInit: OK");
Log.WriteStatusToLogFile("> MouseInit: Initialize mouse");
if(!GameMain.MouseInit(hwnd)) // Mouse initializing
{
GameMain.GameShutdown(); // an error
return(FALSE);
}
Log.WriteToLogFile("> MouseInit: OK");
Log.WriteStatusToLogFile("> KeyboardInit: Intialize keyboard");
if(!GameMain.KeyboardInit(hwnd)) // Keyboard initializing
{
GameMain.GameShutdown();
return(FALSE);
}
Log.WriteToLogFile("> KeyboardInit: OK");
Log.WriteStatusToLogFile("> LoadTextures: Loading textures");
if(!GameMain.LoadTextures())
{
GameMain.GameShutdown();
return(FALSE);
}
Log.WriteToLogFile("> LoadTextures: OK");
Log.WriteStatusToLogFile("> GameStart: Draw window graphics");
if(!GameMain.GameStart()) // Window Graphics
{
GameMain.GameShutdown(); // an error
return(FALSE);
}
Log.WriteToLogFile("> GameStart: OK");
// enter main event loop
Log.WriteStatusToLogFile("> Entering message loop");
while( 1 )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{ // Messages abarbeiten
if( !GetMessage( &msg, NULL, 0, 0 ) )
{
GameMain.GameShutdown();
return msg.wParam;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else if ( bActive ) // Keine Messages und aktiv: Game_Main
{
if (bMinimized)
{
if (!GameMain.GameRestart())
{
GameMain.GameShutdown();
return msg.wParam;
}
Log.WriteToLogFile("> Game_Restart: OK");
Log.WriteToLogFile("> Maximized");
bMinimized=FALSE;
}
if (!GameMain.GameMain())
{
GameMain.GameShutdown(); // an error: shutdown the Game
return(FALSE);
} // end if
}
else // Nichts zu tun: Warten
{
if (!bMinimized)
Log.WriteToLogFile("> Minimized");
WaitMessage();
bMinimized=TRUE;
}
}
// shutdown game and release all resources
} // end WinMain |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CButton.h] - (563 bytes)
// CButton.h
// by Comanche
#include "defines.h"
#include "CTexture.h"
#ifndef CBUTTON
#define CBUTTON
//////////////////////////////////////////////////////////////////////////////////
class CButton
{
public:
CButton(int x1,int y1,int x2,int y2,char *string, char *bitmap);
~CButton();
BOOL RedrawButton();
BOOL RedrawPushedButton();
BOOL TestIfPressed();
private:
BOOL DrawPicture(BOOL pressed);
char caption[100];
int Bx,By,Bx2,By2;
BOOL waspressed;
BOOL isTextured;
char buffer[80];
CTexture *Texture;
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CCheckBox.h] - (405 bytes)
// CCheckBox.h
// by Comanche
#include "defines.h"
#ifndef CCHECKBOX
#define CCHECKBOX
//////////////////////////////////////////////////////////////////////////////////
class CCheckBox
{
public:
CCheckBox(int x,int y,char *string);
BOOL RedrawCheckBox();
BOOL TestIfPressed();
BOOL State;
private:
int Cx,Cy;
char caption[100];
char buffer[80];
BOOL redraw;
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CColor.h] - (350 bytes)
// CColor.h
// by Comanche
#include "defines.h"
#ifndef CCOLOR
#define CCOLOR
//////////////////////////////////////////////////////////////////////////////////
class CColor
{
public:
CColor();
void DrawColors();
void TestIfPressed();
BYTE redpos,greenpos,bluepos;
RGBTRIPLE color;
private:
char buffer[80];
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CGraphics.h] - (2,054 bytes)
// CGraphics.h
// by Comanche
#include "defines.h"
#ifndef CGRAPHICS
#define CGRAPHICS
//////////////////////////////////////////////////////////////////////////////////
extern BYTE *video_buffer;
extern int WordsPerLine;
class CGraphics
{
public:
void Init();
void Lock();
void UnLock();
void LockBackBuffer();
void UnLockBackBuffer();
void Flip();
void BltToBackBuffer();
void GetDC();
void GetLaDC();
void ReleaseDC();
void OSGetDC();
void OSGetLaDC();
void OSReleaseDC();
void RestorePrimarySurface();
void RestoreOffScreenSurface();
BOOL StoreScreenArea(int x,int y,int x2,int y2);
BOOL RestoreScreenArea();
void Blt(int x,int y,int x2,int y2,int vx, int vy);
void Text(int x,int y,char *string);
void PutPixel(int x,int y,BYTE red,BYTE green,BYTE blue);
void PutSafePixel(int x,int y,BYTE red,BYTE green,BYTE blue);
void Quader(int x,int y,int x2,int y2,
BYTE red,BYTE green,BYTE blue);
void FullQuader(int x,int y,int x2,int y2,
BYTE red,BYTE green,BYTE blue);
void BlackQuader(int x,int y,int x2,int y2);
void PutTransPixel(int x,int y,BYTE red, BYTE green,BYTE blue);
void FullTransQuader(int x,int y,int x2,int y2,
BYTE red,BYTE green,BYTE blue);
void FullBrightQuader(int x,int y,int x2,int y2,
BYTE red,BYTE green,BYTE blue);
void Line(int x,int y,int x2, int y2,BYTE red,BYTE green,BYTE blue);
void HLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue);
void VLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue);
void TransHLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue);
void TransVLine(int x,int y,int p,BYTE red,BYTE green,BYTE blue);
void DrawButton(int x,int y,int x2,int y2);
void DrawPushedButton(int x,int y,int x2,int y2);
void DrawCheckBoxOff(int x,int y);
void DrawCheckBoxOn(int x,int y);
HDC xdc;
LOGFONT logfont;
RGBTRIPLE textcolor;
BOOL DrawFont;
private:
char buffer[80];
int FrameTime;
HFONT Arial;
int Sx,Sy,Sx2,Sy2;
LPDIRECTDRAWSURFACE lpddsos2;
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CLandScape.h] - (1,067 bytes)
// CLandScape.h
// by Comanche
#include "defines.h"
#ifndef CLANDSCAPE
#define CLANDSCAPE
//////////////////////////////////////////////////////////////////////////////////
class CLandScape
{
public:
CLandScape();
BOOL InitScreen();
void FillScreen(int x,int y,int x2,int y2);
void MoveRight();
void MoveLeft();
void MoveUp();
void MoveDown();
void MoveRightUp();
void MoveRightDown();
void MoveLeftUp();
void MoveLeftDown();
void DrawBrush();
void UseBrush();
HICON CheckMouseCursor();
int ScreenPosX,ScreenPosY;
DWORD Landscape[2000][2000];
BOOL Day;
int vps;
private:
char buffer[80];
inline void PutVoxel(int x,int y,int x2,int y2);
inline void PutBrightVoxel(int x,int y,int x2,int y2);
inline void Higher();
inline void Lower();
inline void Level();
inline void Brush();
inline void Smoth();
inline void Spray();
inline void Transparent();
inline float GetShadow(int x,int y,int height);
inline BYTE GetAlpha(BYTE a,BYTE b,float alpha);
int BrushX,BrushY;
int test;
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CLiquid.h] - (506 bytes)
// CLiquids.h
// by Comanche
#include "defines.h"
#include "CTexture.h"
#ifndef CLIQUID
#define CLIQUID
//////////////////////////////////////////////////////////////////////////////////
class CLiquid
{
public:
CLiquid(int Texture);
~CLiquid();
void Render();
void RenderOutline(BOOL Marked);
void CheckMouse(int Liquid);
int height;
private:
char TextureName[100];
int TexId;
BOOL Transparent;
int x,y,x2,y2;
int bumpmap[8][8][8];
char buffer[80];
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CLog.h] - (508 bytes)
// Clog.h
// by Comanche
#include "defines.h"
#ifndef CLOG
#define CLOG
//////////////////////////////////////////////////////////////////////////////////
class CLog
{
public:
CLog();
BOOL CloseLogFile();
BOOL WriteToLogFile(char *string);
BOOL WriteCodeToLogFile(char *string);
BOOL WriteErrorToLogFile(char *string);
BOOL WriteStatusToLogFile(char *string);
private:
int lfh; // the file handle
OFSTRUCT log_file_data;
char buffer[200];
char buffer2[80];
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CMain.h] - (1,957 bytes)
// CMain.h
// by Comanche
#include "defines.h"
#ifndef CMAIN
#define CMAIN
//////////////////////////////////////////////////////////////////////////////////
class CMain
{
public:
BOOL GameInit(HWND main_window_handle);
BOOL CheckProzessor();
BOOL CheckDirectX();
BOOL GameMain();
BOOL GameStart();
BOOL GameShutdown();
BOOL GameRestart();
BOOL MouseInit(HWND hwnd);
BOOL KeyboardInit(HWND hwnd);
BOOL GetMouseInfo();
BOOL GetKeyboardInfo();
BOOL CheckMouseRange(int x,int y,int x2,int y2,BOOL Button);
BOOL LoadTextures();
BOOL RenderLiquids();
BOOL CheckLiquids();
LPDIRECTDRAW lpdd; // dd object
LPDIRECTDRAW2 lpdd2; // dd2 object
LPDIRECTDRAWSURFACE lpddsprimary; // dd primary surface
LPDIRECTDRAWSURFACE lpddsback; // dd back surface
LPDIRECTDRAWSURFACE lpddsos1; // dd off-screen surface 1
LPDIRECTINPUT lpdi; // di object
LPDIRECTINPUTDEVICE lpdidevice; // di device
LPDIRECTINPUTDEVICE lpdidevice2; // di device 2
DIMOUSESTATE mouse_state; // di mouse state
DDSURFACEDESC ddsd; // a direct draw surface description struct
DDSCAPS ddscaps; // a direct draw surface capabilities struct
HRESULT ddrval; // result back from dd calls
int MouseX,MouseY; // Mouse coordinates
BYTE MouseB[3]; // Mousebutton states
BYTE keyboard_state[256];
BYTE KeyboardB[4];
HICON Icon,Cursor,Cross,Finger,Pinpet,Clock,
Right,Left,Up,Down,LeftRight,UpDown,
RightDown,RightUp,LeftDown,LeftUp; // Cursors;
int NumTextures, CursorRegX,CursorRegY,Status,Status2;
BOOL DrawCursor; // Mouse Cursor ON/OFF
int Editor;
int ActiveLiquid;
BOOL MMX,CPUID,FPU,CMOV,MCA,TSC,AMD,INTEL;
int CpuFamily,CpuModel,CpuStepId;
char VendorString[32];
DWORD DXVersion, DXPlatform;
private:
char buffer[80];
};
#endif
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CMenu.h] - (853 bytes)
// CMenu.h
// by Comanche
#include "defines.h"
#include "CButton.h"
#ifndef CMENU
#define CMENU
//////////////////////////////////////////////////////////////////////////////////
class CMenu
{
public:
BOOL Menu();
BOOL File();
BOOL TextureOps();
BOOL Editor();
void SaveMap();
void LoadMap();
BOOL FillLand(int height);
BOOL SetEditor(int editor);
void DrawTextures();
void DrawTextures(int TexPos);
void DrawSelected(int TexPos);
void ScrollDown();
void ScrollUp();
void SelectTexture();
void CreateMiniMap();
void DrawMiniMap();
int Selection;
int ScrolPos;
BOOL MessageBox(char *caption,char *string,int ms);
BOOL Open;
private:
BOOL Exit;
BOOL State;
char buffer[80];
BYTE MiniMapR[64][64];
BYTE MiniMapG[64][64];
BYTE MiniMapB[64][64];
CButton *MenuButtons[60];
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CTexture.h] - (716 bytes)
// CTexture.h
// by Comanche
#include "defines.h"
#ifndef CTEXTURE
#define CTEXTURE
//////////////////////////////////////////////////////////////////////////////////
struct BITMAP_FILE
{
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
PALETTEENTRY palette[256];
BYTE *buffer;
};
//////////////////////////////////////////////////////////////////////////////////
class CTexture
{
public:
CTexture(char *filename);
~CTexture();
RGBTRIPLE GetPixel(int x,int y);
BYTE isfailure;
LONG width,height;
WORD bitcount;
char Name[255];
private:
int tfh;
OFSTRUCT file_data;
char buffer[80];
BITMAP_FILE bitmap;
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CTime.h] - (308 bytes)
// CTime.h
// by Comanche
#include "defines.h"
#ifndef CTIME
#define CTIME
//////////////////////////////////////////////////////////////////////////////////
class CTime
{
public:
int GetFPS(int FrameTime);
int GetFrameTime();
private:
int FrameTime;
int LastFrameTime;
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CViewport.h] - (421 bytes)
// CViewport.h
// by Comanche
#include "defines.h"
#include "CButton.h"
#ifndef CVIEWPORT
#define CVIEWPORT
//////////////////////////////////////////////////////////////////////////////////
class CViewport
{
public:
CViewport(int x,int y,int M);
CViewport::~CViewport();
void UseViewport();
void RedrawViewport();
private:
int Vx,Vy,Vx2,Vy2,Mode;
CButton *ViewportButtons[10];
};
#endif |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CVoxel.h] - (268 bytes)
// CVoxel.h
// by Comanche
#include "defines.h"
//////////////////////////////////////////////////////////////////////////////////
class CVoxel
{
public:
int ViewX, ViewY;
int FrontPos;
int TopPos;
int LeftPos;
RGBTRIPLE Voxels[49][49][49];
};
|
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [DEFINES.H] - (2,048 bytes)
// defines.h
// INCLUDES ///////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
#include <windows.h> // include important windows stuff
#include <windowsx.h>
#include <mmsystem.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <assert.h>
#include <fcntl.h>
#include <time.h>
#include <ddraw.h> // DirectX includes
#define DIRECTINPUT_VERSION 0x0700
#include <dinput.h>
#include <dmusici.h>
typedef HRESULT(WINAPI * DIRECTDRAWCREATE)( GUID*, LPDIRECTDRAW*, IUnknown* );
typedef HRESULT(WINAPI * DIRECTDRAWCREATEEX)( GUID*, VOID**, REFIID, IUnknown* );
typedef HRESULT(WINAPI * DIRECTINPUTCREATE)( HINSTANCE, DWORD, LPDIRECTINPUT*,
IUnknown* );
#include "resource.h"
// DEFINES ////////////////////////////////////////////////
#define DINPUT_BUFFERSIZE 16
#define VIEWPORTTOP 1
#define VIEWPORTFRONT 2
#define VIEWPORTLEFT 3
#define VIEWPORT3D 4
#define STANDARTFONTHEIGHT 15
#define CHECKBOXFONTHEIGHT 14
#define SMALFONTHEIGHT 11
#define TEXTUREFONTHEIGHT 10
#define Version "VoxEd 0.53 MMX"
// defines for windows
#define WINDOW_CLASS_NAME "WINXCLASS" // class name
#define WINDOW_WIDTH 0 // size of window
#define WINDOW_HEIGHT 0
#define SCREEN_WIDTH 640 // size of screen
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32 // bits per pixel
#define BITMAP_ID 0x4D42 // universal id for a bitmap
// MESSAGE BOX DEFINES ////////////////////////////////////
#define MS_OK 1
#define MS_YESNO 2
// TYPES //////////////////////////////////////////////////
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned int UINT;
typedef unsigned char UCHAR;
typedef unsigned char BYTE; |
|
Currently browsing [VoxEd.zip] (61,511 bytes) - [CButton.cpp] - (4,185 bytes)
// CButton.cpp
// by Comanche
#include "CButton.h"
#include "CLog.h"
#include "CGraphics.h"
#include "CMain.h"
#include "CTexture.h"
#include "CMenu.h"
extern CGraphics Graphics;
extern CMain GameMain;
extern CLog Log;
extern CMenu Menu;
//////////////////////////////////////////////////////////////////////////////////
CButton::CButton(int x1,int y1,int x2,int y2, char *string, char *bitmap)
{
Texture = new CTexture(bitmap);
if(!Texture->isfailure)
isTextured=TRUE;
Bx=x1; By=y1;
Bx2=x2; By2=y2;
sprintf(caption,"%s",string);
waspressed=TRUE;
}
//////////////////////////////////////////////////////////////////////////////////
CButton::~CButton()
{
delete Texture;
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CButton::RedrawButton()
{
Graphics.Lock();
Graphics.DrawButton(Bx,By,Bx2,By2);
DrawPicture(FALSE);
Graphics.UnLock();
Graphics.OSGetDC();
Graphics.Text((Bx+Bx2)/2,By+3,caption);
Graphics.OSReleaseDC();
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CButton::RedrawPushedButton()
{
Graphics.Lock();
Graphics.DrawPushedButton(Bx,By,Bx2,By2);
DrawPicture(FALSE);
Graphics.UnLock();
Graphics.OSGetDC();
Graphics.Text((Bx+Bx2)/2,By+4,caption);
Graphics.OSReleaseDC();
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CButton::TestIfPressed()
{
if (GameMain.CheckMouseRange(Bx,By,Bx2,By2,TRUE))
{
Graphics.Lock();
Graphics.DrawPushedButton(Bx,By,Bx2,By2);
DrawPicture(TRUE);
Graphics.UnLock();
while(GameMain.MouseB[0])
{
GameMain.GetMouseInfo();
if(GameMain.CheckMouseRange(Bx,By,Bx2,By2,FALSE))
{
Graphics.Lock();
Graphics.DrawPushedButton(Bx,By,Bx2,By2);
DrawPicture(TRUE);
Graphics.UnLock();
Graphics.OSGetDC();
Graphics.Text((Bx+Bx2)/2,By+4,caption);
Graphics.OSReleaseDC();
Graphics.BltToBackBuffer();
if(GameMain.Status2==7 && Menu.Open!=TRUE)
GameMain.RenderLiquids();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,
GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
}
else
{
Graphics.Lock();
Graphics.DrawButton(Bx,By,Bx2,By2);
DrawPicture(FALSE);
Graphics.UnLock();
Graphics.OSGetDC();
Graphics.Text((Bx+Bx2)/2,By+3,caption);
Graphics.OSReleaseDC();
Graphics.BltToBackBuffer();
if(GameMain.Status2==7 && Menu.Open!=TRUE)
GameMain.RenderLiquids();
Graphics.GetDC();
DrawIcon(Graphics.xdc,GameMain.MouseX,
GameMain.MouseY,GameMain.Cursor);
Graphics.ReleaseDC();
Graphics.Flip();
}
}
if(GameMain.CheckMouseRange(Bx,By,Bx2,By2,FALSE))
{
waspressed=TRUE;
return(TRUE);
}
else return(FALSE);
}
else
{
if(waspressed)
{
waspressed=FALSE;
Graphics.Lock();
Graphics.DrawButton(Bx,By,Bx2,By2);
DrawPicture(FALSE);
Graphics.UnLock();
Graphics.OSGetDC();
Graphics.Text((Bx+Bx2)/2,By+3,caption);
Graphics.OSReleaseDC();
}
return(FALSE);
}
}
//////////////////////////////////////////////////////////////////////////////////
BOOL CButton::DrawPicture(BOOL pressed)
{
RGBTRIPLE color;
if(!isTextured) return(TRUE);
int width=Texture->width;
int height=Texture->height;
for(int i=0;i<width;i++)
for(int i2=0;i2<height;i2++)
{
color=Texture->GetPixel(i,i2);
if(!pressed)
{
if((Bx+i)>(Bx2-2)) continue;
if((By+i2)>(By2-2)) continue;
if(color.rgbtRed == 255
&& color.rgbtGreen == 255
&& color.rgbtBlue == 255)
continue;
Graphics.PutPixel(Bx+1+i,By+1+i2,
color.rgbtRed,color.rgbtGreen,color.rgbtBlue);
}
else
{
if((Bx+i)>(Bx2-2)) continue;
if((By+i2)>(By2-3)) continue;
if(color.rgbtRed == 255
&& color.rgbtGreen == 255
&& color.rgbtBlue == 255)
continue;
Graphics.PutPixel(Bx+1+i,By+2+i2,
color.rgbtRed,color.rgbtGreen,color.rgbtBlue);
}
}
return(TRUE);
}
|
|
The zip file viewer built into the Developer Toolbox made use
of the zlib library, as well as the zlibdll source additions.
|