|
发表于 2007-11-5 20:00:00
|
显示全部楼层
Re:mir3 源代码研究
fsfool地图程序的一点改进
鼠标点击浏览地图
byte bFileIdx 改为
word bFileIdx
#include <string>
#include <control.h>
#include<windows.h>
//#include <d3d.h>
//#include <dshow.h>
//#include "..\StdAfx.h"
#include "StdAfx.h"
#include "WindHorn\WHEngine.h" //这个头文件中包含了d3d.h,如果上面再包含则出现二义性。
#include "WindHorn\WHEngine.h" //这个头文件中包含了d3d.h,如果上面再包含则出现二义性。
#include "WindHorn\WHWilImage.h" //包含外部库函数的声明(窗口引擎类)
#include "Common\DblList.h" //避免编译错误,将模板类头文件从预编译头文件中移出,vc6.0会出现内部错误!
#include "GFun.h"
#include "Define.h"
//连接时使用的外部库所在的目录,
//作为参数时要使用“\\”,作为字符串时“\”或“\\”都 可以。
#pragma comment(lib, "Lib\\WindHorn.lib")
#define WIDTH 800
#define HEIGHT 492
#define DEPTH 16
//图形主窗口对象,注意这里创建了主窗口对象,
//需要时再通过定制这个窗口对象实现需要的窗口。
CWHDXGraphicWindow g_xMainWnd(WIDTH,HEIGHT ,DEPTH); //注意构造函数参数列表指定一个硬件支持的模式
CImageHandler g_xImage; //图像处理器
CMapHandler g_xMap; //地图处理器
void RenderObject(INT nLoopTime);
/*
win32程序主进程的启动代码块调用的窗口主函数
*/
CMirSound g_xSound;//1游戏声音对象
//CWHDXGraphicWindow g_xMainWnd;//2//大的类 主游戏对象
CLoginProcess g_xLoginProc; //3//大的类 游戏登陆对象
CCharacterProcess g_xChrSelProc; //4//大的类 角色选择对象
CGameProcess g_xGameProc; //5游戏消息处理对象
CSprite g_xSpriteInfo;//6初始化角色信息,读取INI的对象
CChatEdit g_xChatEditBox;//7角色编辑箱
CClientSocket g_xClientSocket; //8客户端Socket对象
HWND hWnd;
//CImageHandler g_xImage; //图像处理器
//CMapHandler g_xMap; //地图处理器
INT g_nCertifyCode;//验证码
char g_szUserID[20];//用户
char g_szCharName[20];
char g_szServerIP[16];
INT g_nServerPort;
INT g_nVersion;
BYTE g_bProcState = _LOGIN_PROC;
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
//*******************************************************************
//函数:InitWindow()
//功能:创建窗口
//日期:2005.1.3 22:43
//编写人:张小斌
//*******************************************************************
static BOOL InitWindow(HINSTANCE hInstance,int nCmdShow)
{
//定义窗口风格:
WNDCLASS wc;
wc.style=NULL;//窗口的风格
wc.lpfnWndProc=(WNDPROC)WinProc;//窗口消息处理函数的指针
wc.cbClsExtra=0;//分配给窗口类结构之后的额外字节数
wc.cbWndExtra=0;//分配给窗口实例之后的额外的字节数
wc.hInstance=hInstance;//窗口所对应的应用程序的句柄
wc.hIcon=NULL;//窗口图标
wc.hbrBackground=CreateSolidBrush(RGB(100,0,0));//暗红色背景
wc.lpszMenuName=NULL;//窗口的菜单资源名称
wc.lpszClassName="My_Test";//窗口类的名称
//RegisterClass(&wc);//注册窗口
if (!RegisterClass(&wc))
return(0);
//按所给参数创建窗口
hWnd = CreateWindow("My_Test",
"My First program",//窗口标题
WS_POPUP|WS_MAXIMIZE,0,0,
800,
600,
//GetSystemMetrics(SM_CXSCREEN),//此函数返回屏幕宽度
//GetSystemMetrics(SM_CYSCREEN),//此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if(!hWnd)return FALSE;
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);//刷新窗口
return TRUE;
}
//*******************************************************************
//函数:WinProc()
//功能:处理窗口消息
//日期:2005.1.3 22:56
//编写人:张小斌
//*******************************************************************
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg; //用于保存从消息队列检索到的消息
//WS_CHILD
//WNDCLASSEX wc;
// MSG Msg;
// HWND hWnd;
// CoInitialize(NULL);
/* wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = NULL;//WindowPro;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
// wc.hIcon = NULL:
//LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = NULL;//LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "地形渲染演示";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
*/
// if (!RegisterClassEx(&wc))
// return(0);
/*HWND hWnd1 ;
if (!( hWnd1 = CreateWindowEx(NULL, //创建窗口
"地形渲染演示",
"地形渲染演示",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,
800,600,
NULL,
NULL,
hInstance,
NULL)))
return(0);
*/
// if(!InitWindow(hInstance,nCmdShow))return FALSE;
//调CWHDXGraphicWindow对象的方法创建一个DX窗口
INT h = g_xMainWnd.Create(
hInstance, //应用程序进程句柄
NULL,
// "Mir3 mapview ", //主窗口标题
NULL, //菜单
NULL, //图标
_DXG_SCREENMODE_WINDOW, //窗口模式。
//_DXG_SCREENMODE_FULLSCREEN, //全屏模式
_DXG_DEVICEMODE_PRIMARY|_DXG_DEVICEMODE_D3D|_DXG_DEVICEMODE_ZBUFFER //主表面、D3D、Z缓冲
);
DWORD dwStyle;
dwStyle = GetWindowStyle(g_xMainWnd.GetSafehWnd()); //取得DX图形窗口的风格
dwStyle &= ~dwStyle; //原始窗口风格清零
dwStyle |= WS_OVERLAPPED | WS_CAPTION|WS_HSCROLL | WS_CHILD|WS_THICKFRAME | WS_MINIMIZEBOX | WS_SYSMENU;
SetWindowLong(g_xMainWnd.GetSafehWnd(), GWL_STYLE, dwStyle); //重新设置窗口风格
//g_xMainWnd.CenterMainWindow();
//UpdateWindow(hWnd1);
//显示窗口
// ShowWindow(hWnd1, SW_NORMAL); //显示窗口
//设置主窗口显示特性
ShowWindow(g_xMainWnd.GetSafehWnd(),
SW_SHOW
);
g_xImage.LoadAllImage(); //加载所有图像库
g_xMap.LoadMapImage(&g_xImage); //加载指向构成地图的瓷砖图像库的指针
//CHero CHero1;
//CHero1.Create(
//开始游戏的观察点单元坐标
g_xMap.m_shStartViewTileX = 468; //468 358察看0.map 察看238
g_xMap.m_shStartViewTileY = 388; //388 264察看0.map 察看238
//g_xSpriteInfo.SetInfo();
//g_xMap.LoadMapData("0");
//加载指定名字的地图数据
g_xMap.LoadMapData("0"); //这里给m_wSavedMapBuffer缓冲区加载了解密后的图像数据
//这里给m_wSavedMapBuffer缓冲区加载了解密后的图像数据
//绘制地图的地面。
//g_xMap.LoadNewMapBuffer();
WORD* pwSrc = g_xMap.m_wSavedMapBuffer; //地图的一个视区的图像数据源缓冲区24*24个48*32的瓷砖范围
//下面的代码块可以替换g_xMainWnd.DrawWithImagePerLineClipRgn函数调用。
{
DDSURFACEDESC2 ddsd;
//取得后缓冲区指针
LPDIRECTDRAWSURFACE7 pBackBuffer = g_xMainWnd.GetBackBuffer();
if ( pBackBuffer != NULL )
{
//初始化DD表面描述结构
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.lpSurface = NULL;
//锁定后缓冲区表面
pBackBuffer->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
if ( !ddsd.lpSurface ) return FALSE; //锁定失败返回
WORD* pwdDst;
pwdDst = (WORD*)ddsd.lpSurface; //使用16位指针指向后缓冲区表面,
//按列(按行)绘制后缓冲区表面,16位色深每次拷贝2个字节.
//这里(0,0) 是目标矩形的左上角,WIDTH,HEIGHT 是目标矩形的宽高,
//目标矩形与DD主表面必须有交集矩形
//注意,源缓冲区可以看成是_VIEW_CELL_X_COUNT*_CELL_WIDTH*_VIEW_CELL_Y_COUNT*_CELL_HEIGHT*16的表面,
/*for (INT Y = 0 ; Y <HEIGHT; Y++) //目标矩形高
for(INT X = 0; X<WIDTH; X++) //目标矩形宽
//for (INT Y = 0 ; Y <HEIGHT; Y++)
{
memcpy(&pwdDst[Y * (ddsd.lPitch >> 1) + X], &pwSrc[Y*_VIEW_CELL_X_COUNT*_CELL_WIDTH + X], 2);
}
*///lzp
pBackBuffer->Unlock(NULL); //解锁
}
}
g_xMainWnd.DrawWithImagePerLineClipRgn(
g_xMap.m_rcView.left - g_xMap.m_shViewOffsetX, //目标矩形x
g_xMap.m_rcView.top - g_xMap.m_shViewOffsetY, //目标矩形y
g_xMap.m_rcView.right - g_xMap.m_rcView.left, //目标矩形宽
g_xMap.m_rcView.bottom - g_xMap.m_rcView.top, //目标矩形高
g_xMap.m_wSavedMapBuffer, //地图的图像数据源缓冲区
_CLIP_WIDTH, _CLIP_HEIGHT
); //剪刀矩形宽高
//g_xMainWnd.CenterMainWindow();
DWORD dwLastTime, dwTime, dwDelay; //用于纪录最后时间,时间,延时等数据的全局变量
dwLastTime = dwTime = dwDelay = 0; //初值为0
//CPoint point1;
POINT point;
int x= g_xMap.m_shStartViewTileX ;
int y=g_xMap.m_shStartViewTileY ;
int dx=0;
int dy=0;
//消息循环
while (TRUE)
{
if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) )
{// if(g_pKeyboard != NULL)
// g_pKeyboard->RecieveKeyboardInput();// 获得键盘数据
if (msg.message==WM_KEYDOWN)
{dx+=1;
}
if (msg.message==WM_LBUTTONDOWN)
{ // MessageBox(NULL,"ESC 键按下了!确定后推出!","KEYboard",MB_OK);
GetCursorPos(&point);
//g_xMainWnd.
// g_xMap.m_shStartViewTileX = point.x; //358察看0.map 察看238
//g_xMap.m_shStartViewTileY = point.y; //264察看0.map 察看238
//ddsd.lpSurface = NULL;
if (point.x>400)
dx+=1;
if (point.x<400)
dx-=1;
if (point.y>300)
dy+=1;
if (point.y<300)
dy-=1;
//g_xMap.LoadMapData("0");
}
if ( 0 == GetMessage(&msg, NULL, 0, 0) )
return (int) msg.wParam;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//没有消息处理就来呈现场景,也就是将后缓冲区表面交换到主表面,若失败则重建主窗口对象的表面。
else {
dwTime = timeGetTime(); //获取系统当前消息循环的滴答数
dwDelay = dwTime - dwLastTime; //当前消息循环滴答数减去上一次的消息循环的滴答数为两次消息处理的延时间隔。
dwLastTime = dwTime; //保存当前滴答数为最近一次消息循环的时间
if ( dwDelay!=0)
{
/*g_xMainWnd.DrawWithImagePerLineClipRgn(
g_xMap.m_rcView.left - g_xMap.m_shViewOffsetX, //目标矩形x
g_xMap.m_rcView.top - g_xMap.m_shViewOffsetY, //目标矩形y
g_xMap.m_rcView.right - g_xMap.m_rcView.left, //目标矩形宽
g_xMap.m_rcView.bottom - g_xMap.m_rcView.top, //目标矩形高
g_xMap.m_wSavedMapBuffer, //地图的图像数据源缓冲区
_CLIP_WIDTH, _CLIP_HEIGHT
); //剪刀矩形宽高
*/
g_xMap.m_shStartViewTileX =x+dx; //358察看0.map 察看238
g_xMap.m_shStartViewTileY = y+dy; //264察看0.map 察看238
g_xMap.LoadNewMapBuffer();
g_xMainWnd.DrawWithImagePerLineClipRgn(
g_xMap.m_rcView.left+_VIEW_CELL_X_START-g_xMap.m_shViewOffsetX,
g_xMap.m_rcView.top+_VIEW_CELL_Y_START-g_xMap.m_shViewOffsetY,
g_xMap.m_rcView.right-g_xMap.m_rcView.left,
g_xMap.m_rcView.bottom-g_xMap.m_rcView.top,
g_xMap.m_wSavedMapBuffer, _CLIP_WIDTH, _CLIP_HEIGHT);
RenderObject(dwDelay); //渲染地图上的物体
}
if( FAILED(g_xMainWnd.Present()))
g_xMainWnd.RestoreSurfaces();
}
}//end while
return msg.wParam; //将消息参数返回给进程主代码块
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_KEYDOWN://击键消息
switch(wParam)
{
case VK_ESCAPE:
MessageBox(hWnd,"ESC 键按下了!确定后推出!","KEYboard",MB_OK);
PostMessage(hWnd,WM_CLOSE,0,0);//给窗口发送WM_CLOSE消息break;
}
return 0;//处理完一个消息后返回0
case WM_CLOSE://准备退出
DestroyWindow(hWnd);//释放窗口
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);
return 0;
case WM_DESTROY://如果窗口被释放...
PostQuitMessage(0);//给窗口发送WM_QUIT消息
return 0;
}
//调用缺省消息处理过程
return DefWindowProc(hWnd,message,wParam,lParam);
}
void RenderObject(INT nLoopTime)
{
INT nStartX , nStartY ;
INT nObjFileIdx , nImgIdx , nArrayNum;
BOOL bFocused = FALSE;
BOOL bLongObj = FALSE;
BOOL bBlend = FALSE;
BOOL bDrawShadow = TRUE;
g_xMap.SetAniTileFrame(nLoopTime); //设置地图上的动画帧
// 以地图单元为单位扫描地图的可视区域
for ( INT nXCnt = g_xMap.m_shStartViewTileX; nXCnt < g_xMap.m_shStartViewTileX + _VIEW_CELL_X_COUNT; nXCnt++ )
{
for ( INT nYCnt = g_xMap.m_shStartViewTileY; nYCnt < g_xMap.m_shStartViewTileY + _VIEW_CELL_Y_COUNT; nYCnt++ )
{
//扫描按列进行,外循环纵向达到或超过地图边界则说明扫描完毕,应该退出循环。
if ( nXCnt >= g_xMap.m_stMapFileHeader.shWidth )
break;
//内循环横向达到或超过地图边界则说明横向一列扫描完毕,继续扫描下一列。
if ( nYCnt >= g_xMap.m_stMapFileHeader.shHeight || nXCnt < 0 || nYCnt < 0 )
continue;
//由当前二维地图单元坐标换算出一维地图单元数组的索引
nArrayNum = nYCnt + nXCnt*g_xMap.m_stMapFileHeader.shHeight;
// 渲染底层对象 ,底层对象索引文件合法。
BYTE d=LOBYTE(g_xMap.m_pstCellInfo[nArrayNum].bFileIdx);//
//if ( g_xMap.m_pstCellInfo[nArrayNum].bFileIdx != 255 )
if (d!= 255 )
{
// 底层对象索引号合法
if ( g_xMap.m_pstCellInfo[nArrayNum].wObj2 != 65535 )
{
//注意如何从单元结构的bFileIdx成员计算出图像库文件的索引号,这个算法必须与对应的图像存储一致。
//这里bFileIdx2的低4位是底层对象图像库文件的索引,先绘制底层对象,再绘制顶层对象。
//lzp nObjFileIdx = (g_xMap.m_pstCellInfo[nArrayNum].bFileIdx & 0X0F);
nObjFileIdx = (d & 0X0F);
//底层图像在图像库里的索引号
nImgIdx = g_xMap.m_pstCellInfo[nArrayNum].wObj2;
//图像库文件索引合法,0~2是背景瓷砖。
if ( nObjFileIdx > 2 && nObjFileIdx < 14 )
{
//当前图像设置成功
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
if ( g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx) ) //有了对象文件库和图像索引就可以定位对象图像了
{
//图像的宽高合乎规定
if ( g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth == 48 &&
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight >= 32 )
{
bBlend = FALSE; //非混合绘制
// nImgIdx += g_xMap.GetDoorImgIdx(nXCnt, nYCnt); //越过门,门由单独的代码处理
//底层动画
if ( g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani != 255 )
{
BYTE bTickType;
SHORT shAniCnt;
//计算滴答类型和动画帧数
bTickType = (g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani & 0X70) >> 4;
shAniCnt = g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani & 0X0F;
//计算是否混合绘制
if ( (g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani & 0X80) >> 7 )
bBlend = TRUE;
//得到动画图像索引并设置为当前图像
nImgIdx += g_xMap.m_bAniTileFrame[bTickType][shAniCnt];
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx);
}
if ( !bBlend ) //非混合绘制
{
g_xMainWnd.DrawWithImageForCompClipRgn(
(nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH -g_xMap.m_shViewOffsetX,
(nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight,
(WORD*)g_xMap.m_pxTileImg[nObjFileIdx]->m_pbCurrImage,
_CLIP_WIDTH, _CLIP_HEIGHT);
// return;
}
else //混合绘制
{
g_xImage.AddTextr(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
LPDIRECTDRAWSURFACE7 lpddsTextr = g_xImage.GetTextrImg(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
nStartX = (nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH -g_xMap.m_shViewOffsetX;
nStartY = (nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY;
D3DMATERIAL7 mtrl;
D3DVECTOR vecTrans(nStartX, nStartY, 0);
D3DVECTOR vecScale(g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth, g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight, 1);
D3DUtil_InitMaterial(mtrl, (FLOAT)255/255.0f, (FLOAT)255/255.0f, (FLOAT)255/255.0f);
mtrl.diffuse.a = 1.0f/255.0f;
g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
g_xImage.DrawBillBoard(g_xMainWnd.Get3DDevice(), vecTrans, vecScale, mtrl, lpddsTextr);
}
}//if图像的宽高合乎规定
}//if当前图像设置成功
}//if图像库文件索引合法
}//if底层对象索引号合法
}//当前单元的底层图像库文件索引合法
//渲染顶层对象
//顶层对象库文件索引合法
BYTE dd=HIBYTE(g_xMap.m_pstCellInfo[nArrayNum].bFileIdx);
//lzp if (g_xMap.m_pstCellInfo[nArrayNum].bFileIdx != 255 )
if (dd != 255 )
{
//顶层对象索引合法
if ( g_xMap.m_pstCellInfo[nArrayNum].wObj1 != 65535 )
{
//bFileIdx1 & 0X0F是低4位表示顶层对象图像库文件的索引
//lzp nObjFileIdx = (g_xMap.m_pstCellInfo[nArrayNum].bFileIdx & 0XF0);
nObjFileIdx = (dd & 0X0F);
nImgIdx = g_xMap.m_pstCellInfo[nArrayNum].wObj1;
//在规定的对象文件索引范围
if ( nObjFileIdx > 2 && nObjFileIdx < 14 )
{
//成功设置当前图像
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
if ( g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx) )
{
//画面尺寸符合规范
if ( g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth == 48 &&
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight >= 32 )
{
bBlend = FALSE;
// nImgIdx += g_xMap.GetDoorImgIdx(nXCnt, nYCnt); //越过门
//顶层动画
if ( g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani != 255 )
{
BYTE bTickType;
SHORT shAniCnt;
bTickType = (g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani & 0X70) >> 4;
shAniCnt = g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani & 0X0F; //低4位是动画帧数
if ( (g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani & 0X80) >> 7 )
bBlend = TRUE;
nImgIdx += g_xMap.m_bAniTileFrame[bTickType][shAniCnt];
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx);
}
if ( !bBlend )
g_xMainWnd.DrawWithImageForCompClipRgn(
(nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH-g_xMap.m_shViewOffsetX,
(nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight,
(WORD*)g_xMap.m_pxTileImg[nObjFileIdx]->m_pbCurrImage,
_CLIP_WIDTH, _CLIP_HEIGHT);
else
{
g_xImage.AddTextr(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
LPDIRECTDRAWSURFACE7 lpddsTextr = g_xImage.GetTextrImg(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
nStartX = (nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH -g_xMap.m_shViewOffsetX;
nStartY = -(nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY;
D3DMATERIAL7 mtrl;
D3DVECTOR vecTrans(nStartX, nStartY, 0);
D3DVECTOR vecScale(g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth, g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight, 1);
D3DUtil_InitMaterial(mtrl, (FLOAT)255/255.0f, (FLOAT)255/255.0f, (FLOAT)255/255.0f);
mtrl.diffuse.a = 1.0f/255.0f;
g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
g_xImage.DrawBillBoard(g_xMainWnd.Get3DDevice(), vecTrans, vecScale, mtrl, lpddsTextr);
}
}//画面尺寸符合规范
}//成功设置当前图像
}//在规定的对象文件索引范围
}//顶层对象索引合法
}//渲染顶层对象
}//for
}//for
// 48*32
for ( nXCnt = g_xMap.m_shStartViewTileX; nXCnt < g_xMap.m_shStartViewTileX + _VIEW_CELL_X_COUNT; nXCnt++ )
{
for ( INT nYCnt = g_xMap.m_shStartViewTileY; nYCnt < g_xMap.m_shStartViewTileY + _VIEW_CELL_Y_COUNT; nYCnt++ )
{
if ( nXCnt >= g_xMap.m_stMapFileHeader.shHeight )
break;
if ( nYCnt >= g_xMap.m_stMapFileHeader.shWidth || nXCnt < 0 || nYCnt < 0 )
continue;
bLongObj = FALSE;
nArrayNum = nYCnt + nXCnt*g_xMap.m_stMapFileHeader.shHeight;
BYTE ddd=LOBYTE(g_xMap.m_pstCellInfo[nArrayNum].bFileIdx);//
//图像库文件索引合法
//if ( g_xMap.m_pstCellInfo[nArrayNum].bFileIdx2 != 255 )
if (ddd != 255 )
{
//底层对象索引合法
if ( g_xMap.m_pstCellInfo[nArrayNum].wObj2 != 65535 )
{
nObjFileIdx = (ddd & 0X0F);
nImgIdx = g_xMap.m_pstCellInfo[nArrayNum].wObj2 - 1;
if(nImgIdx <0) nImgIdx = 0;
if ( nObjFileIdx > 2 && nObjFileIdx < 14 )
{
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
if ( g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx) )
{
if ( !(g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth == 48 &&
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight >= 32) )
{
bBlend = FALSE;
nImgIdx += g_xMap.GetDoorImgIdx(nXCnt, nYCnt);
//底层动画对象索引合法
if ( g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani != 255 )
{
BYTE bTickType;
SHORT shAniCnt;
bTickType = (g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani & 0X70) >> 4;
shAniCnt = g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani & 0X0F;
if ( (g_xMap.m_pstCellInfo[nArrayNum].bObj2Ani & 0X80) >> 7 )
bBlend = TRUE;
nImgIdx += g_xMap.m_bAniTileFrame[bTickType][shAniCnt];
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx);
}
if ( !bBlend )
g_xMainWnd.DrawWithImageForCompClipRgn(
(nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH-g_xMap.m_shViewOffsetX,
(nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight,
(WORD*)g_xMap.m_pxTileImg[nObjFileIdx]->m_pbCurrImage,
_CLIP_WIDTH, _CLIP_HEIGHT);
else
{
g_xImage.AddTextr(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
LPDIRECTDRAWSURFACE7 lpddsTextr = g_xImage.GetTextrImg(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
nStartX = (nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH -g_xMap.m_shViewOffsetX+g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shPX;
nStartY = (nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY+g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shPY;
D3DMATERIAL7 mtrl;
D3DVECTOR vecTrans(nStartX, nStartY, 0);
D3DVECTOR vecScale(g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth, g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight, 1);
D3DUtil_InitMaterial(mtrl, (FLOAT)255/255.0f, (FLOAT)255/255.0f, (FLOAT)255/255.0f);
mtrl.diffuse.a = 0.0f/255.0f;
g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
g_xImage.DrawBillBoard(g_xMainWnd.Get3DDevice(), vecTrans, vecScale, mtrl, lpddsTextr);
}
bLongObj = TRUE;
}
}
}
}
//顶层对象索引合法
if ( g_xMap.m_pstCellInfo[nArrayNum].wObj1 != 65535 )
{BYTE dddd=HIBYTE(g_xMap.m_pstCellInfo[nArrayNum].bFileIdx);//
nObjFileIdx = (dddd & 0X0F);
nImgIdx = g_xMap.m_pstCellInfo[nArrayNum].wObj1 - 1;
if(nImgIdx<0) nImgIdx = 0;
if ( nObjFileIdx > 2 && nObjFileIdx < 14 )
{
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
if ( g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx) )
{
if ( !(g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth == 48 &&
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight >= 32) )
{
bBlend = FALSE;
nImgIdx += g_xMap.GetDoorImgIdx(nXCnt, nYCnt);
//顶层动画索引合法
if ( g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani != 255 )
{
BYTE bTickType;
SHORT shAniCnt;
bTickType = (g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani & 0X70) >> 4;
shAniCnt = g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani & 0X0F;
if ( (g_xMap.m_pstCellInfo[nArrayNum].bObj1Ani & 0X80) >> 7 )
bBlend = TRUE;
nImgIdx += g_xMap.m_bAniTileFrame[bTickType][shAniCnt];
assert(nImgIdx >=0 && nImgIdx <= 0x7fffffff);
g_xMap.m_pxTileImg[nObjFileIdx]->NewSetIndex(nImgIdx);
}
if ( !bBlend )
g_xMainWnd.DrawWithImageForCompClipRgn(
(nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH -g_xMap.m_shViewOffsetX,
(nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth,
g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight,
(WORD*)g_xMap.m_pxTileImg[nObjFileIdx]->m_pbCurrImage,
_CLIP_WIDTH, _CLIP_HEIGHT);
else
{
g_xImage.AddTextr(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
LPDIRECTDRAWSURFACE7 lpddsTextr = g_xImage.GetTextrImg(_TEXTR_FILE_MAP, nObjFileIdx, nImgIdx);
nStartX = (nXCnt-g_xMap.m_shStartViewTileX)*_CELL_WIDTH-g_xMap.m_shViewOffsetX;
nStartY = -(nYCnt-g_xMap.m_shStartViewTileY)*_CELL_HEIGHT-g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-g_xMap.m_shViewOffsetY;
D3DMATERIAL7 mtrl;
D3DVECTOR vecTrans(nStartX, nStartY, 0);
D3DVECTOR vecScale(g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shWidth, g_xMap.m_pxTileImg[nObjFileIdx]->m_lpstNewCurrWilImageInfo->shHeight, 1);
D3DUtil_InitMaterial(mtrl, (FLOAT)255/255.0f, (FLOAT)255/255.0f, (FLOAT)255/255.0f);
mtrl.diffuse.a = 1.0f/255.0f;
g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
g_xImage.DrawBillBoard(g_xMainWnd.Get3DDevice(), vecTrans, vecScale, mtrl, lpddsTextr);
}
bLongObj = TRUE;
}
}
}
}
}
//绘制开门
//g_xMap.DrawOpenDoor(nXCnt, nYCnt);
INT nMapViewX = 0;
INT nMapViewY = 0;
BOOL bIsMapViewTime = FALSE;
if ( nXCnt >= g_xMap.m_shStartViewTileX && nXCnt < g_xMap.m_shStartViewTileX + _VIEW_CELL_X_COUNT &&
nYCnt >= g_xMap.m_shStartViewTileY && nYCnt < g_xMap.m_shStartViewTileY + _VIEW_CELL_Y_COUNT )
{
bIsMapViewTime = TRUE;
nMapViewX = nXCnt - g_xMap.m_shStartViewTileX;
nMapViewY = nYCnt - g_xMap.m_shStartViewTileY;
}
} //for
} //for
}
|
|