⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hong_sprite.cpp

📁 网络游戏龙族 完整的登陆器 C++ 源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************\
* Copyright (c), Future Entertainment World / Seoul, Republic of Korea        *
* All Rights Reserved.                                                        *
*                                                                             *
* This document contains proprietary and confidential information.  No        *
* parts of this document or the computer program it embodies may be in        *
* any way copied, duplicated, reproduced, translated into a different         *
* programming language, or distributed to any person, company, or             *
* corporation without the prior written consent of Future Entertainment World *
\*****************************************************************************/


#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <Io.h>
#include <Math.h>


#include "Dragon.h"
#include "Char.h"
#include "GameProc.h"
#include "Map.h"
#include "Hangul.h"
#include "Tool.h"

#include "DirectSound.h"

#define __HONG_SPRITE_H__
#include "Hong_Sprite.h"
#include "Hong_Light.h"
#include "Hong_Sub.h"

#include "Convert565to555.h"
#include "MouseCursor.h"
#include "Effect.h"


extern CHARACTERLIST		g_CharacterList;

WORD	AddTableR[128];
WORD	AddTableG[256];
WORD	AddTableB[128];

WORD	SubTableR[64];
//WORD	SubTableg[64];
WORD	SubTableG[128];
WORD	SubTableB[64];

bool	StartLoadCharSpriteDataThreadFlag;
bool	LoadingCharSpriteData;
bool g_bStopWeatherSystem = false; // CSD-CN-031215
bool g_bOffWeatherSystem = false; // CSD-CN-031217

/////////////////////
char *GetSurfacePointer(LPDIRECTDRAWSURFACE  pSurface)
{	
    char *buf;
    DDSURFACEDESC ddSurfaceDesc;
    
	memset(&ddSurfaceDesc, 0, sizeof(DDSURFACEDESC));
    ddSurfaceDesc.dwSize = sizeof(DDSURFACEDESC);
    HRESULT result;
    result = pSurface->Lock(NULL, &ddSurfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
	
	buf = (char *)ddSurfaceDesc.lpSurface;
	
	if ( buf == NULL )
	{
		result = RestoreAllSurfaces(  &g_DirectDrawInfo );
		memset(&ddSurfaceDesc, 0, sizeof(DDSURFACEDESC));
		ddSurfaceDesc.dwSize = sizeof(DDSURFACEDESC);
		HRESULT result;
		result = pSurface->Lock(NULL, &ddSurfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
	}
	
    pSurface->Unlock( NULL ); //ddSurfaceDesc.lpSurface);
	
	return buf;
}	



//		
// Return:	8	256 Color
//			16	High Color
//			24	24Bits Color
//			32	32Bits Color
int	GetBitsPerPixel( void )
{	
	HDC		hDC;
	int		nBitPerPixel;
	
	hDC = GetDC( NULL );
	nBitPerPixel = GetDeviceCaps( hDC, PLANES ) * GetDeviceCaps( hDC, BITSPIXEL );
	ReleaseDC( NULL, hDC );
	
	return	nBitPerPixel;
}		





void	CheckColorBitMask(  LPDIRECTDRAWSURFACE  surface )
{		
	DDSURFACEDESC ddSurfaceDesc;
	
	ZeroMemory( &ddSurfaceDesc, sizeof( DDSURFACEDESC ) );
	ddSurfaceDesc.dwSize  = sizeof( ddSurfaceDesc );
	//ddSurfaceDesc.dwFlags = DDSD_PIXELFORMAT | DDSD_PITCH;
	HRESULT hResult = surface->GetSurfaceDesc( &ddSurfaceDesc );
	
	if( g_DirectDrawInfo.bFullscreen )
	{	
		FILE *fp = Fopen( "c:/dxsize.txt", "wt" );
		wSurDxSize = (WORD)ddSurfaceDesc.lPitch;
		dSurDxSize = (DWORD)ddSurfaceDesc.lPitch;
		
		fprintf( fp, "%d %d \n", wDxSize, dSurDxSize );
		fclose(fp);
	}	
	else 
	{	
		wDxSize = SCREEN_WIDTH * 2;
		dDxSize = SCREEN_WIDTH * 2;
	}	
	
	wDxSize = SCREEN_WIDTH * 2;
	dDxSize = SCREEN_WIDTH * 2;
	
	if (hResult != 0)//DD_OK)
		return;
	
	_PixelInfo.BitMaskR = ddSurfaceDesc.ddpfPixelFormat.dwRBitMask;
	_PixelInfo.BitMaskG = ddSurfaceDesc.ddpfPixelFormat.dwGBitMask;
	_PixelInfo.BitMaskB = ddSurfaceDesc.ddpfPixelFormat.dwBBitMask; 
	
	if (_PixelInfo.BitMaskR == 0xF800) 
	{	
		// 夸芭捞 RGB 5:6:5 器杆捞聪尝府 弊犯霸 舅扼快.
		//			 4444----3333----2222----1111----
		//           84218421842184218421842184218421
		//           00000000000000011111011111011110;
		_PixelInfo.ShiftRightR = 11;
		_PixelInfo.ShiftLeftR  = 0;
		
		_PixelInfo.ShiftRightG = 5;
		_PixelInfo.ShiftLeftG  = 5;
		
		_PixelInfo.ShiftRightB = 0;
		_PixelInfo.ShiftLeftB  = 11;
	}else
		if (_PixelInfo.BitMaskR == 0x7C00) 
		{	
			// 夸绊 RGB 5:5:5 器杆 酒捞啊.
			//			   4444----3333----2222----1111----
			//             84218421842184218421842184218421
			//             00000000000000001111101111011110;
			_PixelInfo.ShiftRightR = 10;
			_PixelInfo.ShiftLeftR  = 1;
			
			_PixelInfo.ShiftRightG = 5;
			_PixelInfo.ShiftLeftG  = 6;
			
			_PixelInfo.ShiftRightB = 0;
			_PixelInfo.ShiftLeftB  = 11;
		}else
			if (_PixelInfo.BitMaskR == 0x001F)
			{	
				// 酒蝶 夸巴 BGR 5:6:5 器杆捞巴力.
				//			   4444----3333----2222----1111----
				//             84218421842184218421842184218421
				_PixelInfo.ShiftRightR = 0;
				_PixelInfo.ShiftLeftR  = 11;
				
				_PixelInfo.ShiftRightG = 5;
				_PixelInfo.ShiftLeftG  = 5;
				
				_PixelInfo.ShiftRightB = 11;
				_PixelInfo.ShiftLeftB  = 0;
			}	
}		




void	InitSpriteTransTable( LPDIRECTDRAWSURFACE  surface )
{		
	CheckColorBitMask( surface );
	
	WORD	MaskG;
	if( _PixelInfo.BitMaskR == 0x7c00)
	{	
		MaskG = 0x1f;
	}	
	else
	{	
		MaskG = 0x3f;
	}	
	
	//Make ADD Table
	for(int i=0; i < 128; i++){
		if(i<32)
		{
			AddTableR[i] = i << _PixelInfo.ShiftRightR;
			AddTableB[i] = i << _PixelInfo.ShiftRightB;
		}	
		else
		{
			AddTableR[i] = 0x1f << _PixelInfo.ShiftRightR;
			AddTableB[i] = 0x1f << _PixelInfo.ShiftRightB;
		}
	}	
	for(i=0; i < 256; i++){
		if(i<=MaskG)
		{
			AddTableG[i] = i << _PixelInfo.ShiftRightG;
		}
		else
		{
			AddTableG[i] = MaskG << _PixelInfo.ShiftRightG;
		}
	}	
	
	//Make SUB Table
	for( i=0 ; i < 64 ; i++ ){
		if(i<32)
		{
			SubTableR[i] = 0;
			SubTableB[i] = 0;
		}
		else
		{
			SubTableR[i] = (i - 32) << _PixelInfo.ShiftRightR;
			SubTableB[i] = (i - 32) << _PixelInfo.ShiftRightB;
		}
		//SubTableG[i] = i << _PixelInfo.ShiftRightG;
		//SubTableg[i] = 0;
	}
	for(i=0; i < 128; i++){
		if(i<64)
		{
			SubTableG[i] = 0;
		}
		else
		{
			SubTableG[i] = (i - 64) << _PixelInfo.ShiftRightG;
		}
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//           Put Sprite Transperensy..
//
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
void PutCmprsImgClipingTrans565( int x, int y, LPVOID Stmp, LPVOID dest, int lx, int rx, int ty, int by, WORD MSK)
{
	int		l, kkk = lx << 1;
	LPVOID	Dtmp = (LPVOID)( (char *)dest + y * wDxSize + (x * 2 ));
	rx <<= 1;
	lx <<= 1;
	
	_asm{
		push	es;
		
		push	ds;
		pop		es;
		
		xor		eax,eax;
		xor		ecx,ecx;
		
		mov		esi,Stmp;
		
		mov		cx,word ptr ty;
		
		or		cx,cx;
		jz		exit_1;
loop_1:
		cmp		word ptr[esi],0xffff;
		jz		exit_xxxx;
		
		mov		ax,[esi+2];
		add		esi,4;
		add		esi,eax;
		jmp		loop_1;
exit_xxxx:
		inc		esi;
		inc		esi;
		loop	loop_1;
exit_1:
	}
	_asm{
		mov		bx,word ptr by;		//
loop_for1:
		or		bx,bx;		//for(i=0;i<by;i++)
		jz		exit_for1;	//
		xor		eax,eax;
		xor		edx,edx;
		xor		ecx,ecx;
		mov		edi,Dtmp;
		
		mov		ax,word ptr lx;	//if(lx)
		or		ax,ax;			//
		jz		exit_if1;
loop_while1:
		cmp		word ptr[esi],0xffff;	//while(*stmp != 0xffff)
		jz		exit_while1;			//
		add		dx,[esi];
		add		esi,2;
		cmp		dx,word ptr lx;		//if(j>lx)
		jle		jmp_if1;			//
		sub		dx,word ptr lx;		//j-=lx
		
		cmp		dx,word ptr rx;
		jg		jmp_00001;
		
		add		edi,edx;			//dtmp+=j
		
		lodsw;						//k=*stmp
		add		dx,ax;				//j+=k
		mov		cx,ax;				//
		
		cmp		dx,word ptr rx;	//new
		jle		jmp_0000;
		add		cx,word ptr rx;
		sub		cx,dx;
		
		jmp		xxxxxxx1;
jmp_00001:
		lodsw;
		add		esi,eax;
		jmp		ext_loop;
		
jmp_if1:///////////////////////////////////////
		lodsw;				//
		add		dx,ax;		//
		add		esi,eax;	//
		cmp		dx,word ptr lx;		//
		jle		loop_while1;
		sub		dx,word ptr lx;
		sub		esi,edx;
		mov		cx,dx;
		
		cmp		dx,word ptr rx;	//new
		jle		jmp_0000;		//"
		mov		cx,word ptr rx;	//"
xxxxxxx1:
jmp_0000:					//"
		
		//************ move	data ***********
		shr		cx,1;//*********************************************************
		or		cx,cx;
		jz		exit_movedata1;
loop_TR1:
		lodsw
			and		ax,1111101111011110b;
		and		word ptr [edi],1111101111011110b;
		add		ax,[edi];
		shr		ax,1;
		mov		[edi],ax;
		add		edi,2;
		loop	loop_TR1;
exit_movedata1:
		
		cmp		dx,word ptr rx;	//new		
		jle		exit_while1;	//"
		mov		eax,edx;		//"
		sub		ax,word ptr rx;	//"
		add		esi,eax;		//new
		
exit_while1:	//end while(*stmp != 0xffff)*/
exit_if1:	//end if(lx)
		
		
loop_while2:	
		cmp		word ptr[esi],0xffff;
		jz		exit_while2;
		
		lodsw;
		
		add		edi,eax;	//dtmp+=*stmp
		add		dx,ax;		//j+=*stmp
		
		lodsw;
		mov		cx,ax;		//l=k=*stmp
		mov		word ptr l,ax;
		
		add		ax,dx;
		cmp		ax,word ptr rx;
		jle		exit_if0;
		cmp		dx,word ptr rx;
		jg		exit_if0;
		//mov		ax,cx;
		mov		cx,word ptr rx;
		sub		cx,dx;
exit_if0:
		cmp		dx,word ptr rx;
		jg		else_if;
		
		add		dx,word ptr l;	//j+=l;
		sub		word ptr l,cx;	//l-k;
		
		//************ move	data ***********
		shr		cx,1;//*********************************************************
		or		cx,cx;
		jz		exit_movedata2;
loop_TR2:
		lodsw
			and		ax,1111101111011110b;
		and		word ptr [edi],1111101111011110b;
		add		ax,[edi];
		shr		ax,1;
		mov		[edi],ax;
		add		edi,2;
		loop	loop_TR2;
exit_movedata2:
		
		mov		ax,word ptr l;
		add		esi,eax;
		jmp		loop_while2;
		
else_if:
		mov		ax,word ptr l;
		add		esi,eax;
ext_loop:
		cmp		word ptr[esi],0xffff;
		jz		ext;
		add		esi,2;
		lodsw
			add		esi,eax;
		jmp		ext_loop;
ext:
		
exit_while2:
		add		esi,2;
		
		mov		ax,wDxSize;
		add		dword ptr Dtmp,eax;
		dec		bx;
		jmp		loop_for1;
exit_for1:
		
		pop		es;
	};
}

void PutCmprsImgNOTClipingTrans565(int x, int y, int yl, LPVOID Stmp, LPVOID dest, WORD MSK)
{
	DWORD	j, tmpclr;
	LPVOID	Dtmp = (LPVOID)( (char *)dest + y * dDxSize + (x * 2));
	j = yl;
	
	_asm{
		push	es;
		
		push	ds;
		pop		es;
		
		mov		edx,Dtmp;
		mov		esi,Stmp;
		
		mov		ebx,j;
		
		xor		eax,eax;
		xor		ecx,ecx;
loop_1:
		or		ebx,ebx;	// if(SY==0)
		jz		exit_1;
		mov		edi,edx;
		
loop_2:	
		cmp		word ptr[esi],0xffff;
		jz		exit_2;
		
		mov		ax,[esi];
		add		edi,eax;	//0 skip
		
		mov		cx,[esi+2];	//load data num
		add		esi,4;
		shr		ecx,1;
		
loop_TR:
		mov		ax,[esi];
		and		eax,1110011100011100b;
		mov		tmpclr,eax;
		
		mov		ax,[edi];
		and		eax,1110011100011100b;
		add		eax,tmpclr;
		
		shr		eax,2;
		mov		[edi],ax;
		add		esi,2;
		add		edi,2;
		loop	loop_TR;
		
		jmp		loop_2;
exit_2:
		add		esi,2;
		
		add		edx,dDxSize;
		dec		bx;
		jmp		loop_1;
exit_1:
		pop		es;
	};
}

void PutCmprsImgClipingTrans555( int x, int y, LPVOID Stmp, LPVOID dest, int lx, int rx, int ty, int by, WORD MSK)
{
	int		l, kkk = lx << 1;
	LPVOID	Dtmp = (LPVOID)( (char *)dest + y * wDxSize + (x * 2 ));
	rx <<= 1;
	lx <<= 1;
	
	_asm{
		push	es;
		
		push	ds;
		pop		es;
		
		xor		eax,eax;
		xor		ecx,ecx;
		
		mov		esi,Stmp;
		
		mov		cx,word ptr ty;
		
		or		cx,cx;
		jz		exit_1;
loop_1:
		cmp		word ptr[esi],0xffff;
		jz		exit_xxxx;
		
		mov		ax,[esi+2];
		add		esi,4;
		add		esi,eax;
		jmp		loop_1;
exit_xxxx:
		inc		esi;
		inc		esi;
		loop	loop_1;
exit_1:
	}
	_asm{
		mov		bx,word ptr by;		//
loop_for1:
		or		bx,bx;		//for(i=0;i<by;i++)
		jz		exit_for1;	//
		xor		eax,eax;
		xor		edx,edx;
		xor		ecx,ecx;
		mov		edi,Dtmp;
		
		mov		ax,word ptr lx;	//if(lx)
		or		ax,ax;			//
		jz		exit_if1;
loop_while1:
		cmp		word ptr[esi],0xffff;	//while(*stmp != 0xffff)
		jz		exit_while1;			//
		add		dx,[esi];
		add		esi,2;
		cmp		dx,word ptr lx;		//if(j>lx)
		jle		jmp_if1;			//
		sub		dx,word ptr lx;		//j-=lx
		
		cmp		dx,word ptr rx;
		jg		jmp_00001;
		
		add		edi,edx;			//dtmp+=j
		
		lodsw;						//k=*stmp
		add		dx,ax;				//j+=k
		mov		cx,ax;				//
		
		cmp		dx,word ptr rx;	//new
		jle		jmp_0000;
		add		cx,word ptr rx;
		sub		cx,dx;
		
		jmp		xxxxxxx1;
jmp_00001:
		lodsw;
		add		esi,eax;
		jmp		ext_loop;
		
jmp_if1:///////////////////////////////////////
		lodsw;				//
		add		dx,ax;		//
		add		esi,eax;	//
		cmp		dx,word ptr lx;		//
		jle		loop_while1;
		sub		dx,word ptr lx;
		sub		esi,edx;
		mov		cx,dx;
		
		cmp		dx,word ptr rx;	//new
		jle		jmp_0000;		//"
		mov		cx,word ptr rx;	//"
xxxxxxx1:
jmp_0000:					//"
		
		//************ move	data ***********
		shr		cx,1;//*********************************************************
		or		cx,cx;
		jz		exit_movedata1;
loop_TR1:
		lodsw
			and		ax,1111101111011110b;
		and		word ptr [edi],1111101111011110b;
		add		ax,[edi];
		shr		ax,1;
		mov		[edi],ax;
		add		edi,2;
		loop	loop_TR1;
exit_movedata1:
		
		cmp		dx,word ptr rx;	//new		
		jle		exit_while1;	//"
		mov		eax,edx;		//"
		sub		ax,word ptr rx;	//"
		add		esi,eax;		//new
		
exit_while1:	//end while(*stmp != 0xffff)*/
exit_if1:	//end if(lx)
		
		
loop_while2:	
		cmp		word ptr[esi],0xffff;
		jz		exit_while2;
		
		lodsw;
		
		add		edi,eax;	//dtmp+=*stmp
		add		dx,ax;		//j+=*stmp
		
		lodsw;
		mov		cx,ax;		//l=k=*stmp
		mov		word ptr l,ax;
		
		add		ax,dx;
		cmp		ax,word ptr rx;
		jle		exit_if0;
		cmp		dx,word ptr rx;
		jg		exit_if0;
		//mov		ax,cx;
		mov		cx,word ptr rx;
		sub		cx,dx;
exit_if0:
		cmp		dx,word ptr rx;
		jg		else_if;
		
		add		dx,word ptr l;	//j+=l;
		sub		word ptr l,cx;	//l-k;
		
		//************ move	data ***********
		shr		cx,1;//*********************************************************
		or		cx,cx;
		jz		exit_movedata2;
loop_TR2:
		lodsw
			and		ax,1111101111011110b;
		and		word ptr [edi],1111101111011110b;
		add		ax,[edi];
		shr		ax,1;
		mov		[edi],ax;
		add		edi,2;
		loop	loop_TR2;
exit_movedata2:
		
		mov		ax,word ptr l;
		add		esi,eax;
		jmp		loop_while2;
		
else_if:
		mov		ax,word ptr l;
		add		esi,eax;
ext_loop:
		cmp		word ptr[esi],0xffff;
		jz		ext;
		add		esi,2;
		lodsw
			add		esi,eax;
		jmp		ext_loop;
ext:
		
exit_while2:
		add		esi,2;
		
		mov		ax,wDxSize;
		add		dword ptr Dtmp,eax;
		dec		bx;
		jmp		loop_for1;
exit_for1:
		
		pop		es;
	};
}

void PutCmprsImgNOTClipingTrans555(int x, int y, int yl, LPVOID Stmp, LPVOID dest, WORD MSK)
{
	DWORD	j, tmpclr;
	LPVOID	Dtmp = (LPVOID)( (char *)dest + y * dDxSize + (x * 2));
	j = yl;
	
	_asm{
		push	es;
		
		push	ds;
		pop		es;
		
		mov		edx,Dtmp;
		mov		esi,Stmp;
		
		mov		ebx,j;
		
		xor		eax,eax;
		xor		ecx,ecx;
loop_1:
		or		ebx,ebx;	// if(SY==0)
		jz		exit_1;
		mov		edi,edx;
		
loop_2:	
		cmp		word ptr[esi],0xffff;
		jz		exit_2;
		
		mov		ax,[esi];
		add		edi,eax;	//0 skip
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -