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

📄 datamanager.cpp

📁 一个3D的保龄球的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

/*
* ============================================================================
*  Name     : DataManager.cpp: 
*  Part of  : Game
*  Created  : 2004-11-8 by Yi Wen Hu
*  Version  :
*  Copyright: Gameloft S.A.
*
* ============================================================================
*/

#include "DataManager.h"

#include "CPlayer.h"
#include "CBall.h"
#include "..\System\IMath.h"
#include "CTenpin.h"
#include "def.h"
#include "..\3d\render3d.h"

#include "..\System\engine.h"
#include "..\System\resfile.h"

//#include "..\zlib\zconf.h"

#include "..\System\simplememory.h"

#include "..\\System\\Sysdef.h"
#include "..\\System\\Sound.h"
#include "..\\game\\res.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDataManager::CDataManager()
{
	m_pRender=NULL;

	m_iModelCount=0;
	m_iBallCount=0;
	m_iPlayerCount=0;
	m_iBgCount = 0;

	m_iBonusCount=0;

	// ball
	m_pBallWeight=NULL;

	// player
	m_pPlayer=NULL;


	// bonuses	
	m_pBonuses=NULL;

	m_Coins=NULL;

	//Qiu Li, 2005-1-31
	m_pStringBuffer = NULL;
	//Qiu Li end
}


CDataManager::~CDataManager()
{

}

bool CDataManager::LoadResourceInfo(CEngine *pEngine)
{
	
	char filename[20]="res\\resource.bin";
	
	CResFile *pRes = pEngine->GetRes();
	void *pFile;
	int rest_size = pRes->LoadFileToStack(filename,&pFile);

	CBufReader pData;
	if( pFile )
	{
		pData.CBufReader_init( pFile, rest_size);
	}
	else
		return false;

	int i,j,k; // loop variables`

	// models
	m_iModelCount=pData.ReadShort();
	//m_pModelFile=new char[m_iModelCount][STRING_MAX_LENGTH];
	m_pModelFile =(char(*)[STRING_MAX_LENGTH])pEngine->GetMem()->GlobalMalloc(m_iModelCount*STRING_MAX_LENGTH*sizeof(char));
	m_pRender->SetModelCount(m_iModelCount);

	for(i=0;i<m_iModelCount;i++)
	{
		pData.ReadString(m_pModelFile[i]);
	}
	
	// balls
	m_iBallCount=pData.ReadShort();
	//m_pBallName=new char[m_iBallCount][STRING_MAX_LENGTH];
	//m_pBallTexture=new char[m_iBallCount][STRING_MAX_LENGTH];
	//m_pBallWeight=new int[m_iBallCount];
	m_pBallName=(char(*)[STRING_MAX_LENGTH])pEngine->GetMem()->GlobalMalloc(m_iBallCount*STRING_MAX_LENGTH*sizeof(char));
	m_pBallTexture=(char(*)[STRING_MAX_LENGTH])pEngine->GetMem()->GlobalMalloc(m_iBallCount*STRING_MAX_LENGTH*sizeof(char));
	m_pBallWeight=(int *)pEngine->GetMem()->GlobalMalloc(m_iBallCount*sizeof(int));

	for(i=0;i<m_iBallCount;i++)
	{
		m_pBallWeight[i]=pData.ReadChar();		
		pData.ReadString(m_pBallName[i]);		
		pData.ReadString(m_pBallTexture[i]);	
	}
	
	// players
	m_iPlayerCount=pData.ReadShort();
	//m_pPlayer=new CPlayerRes[m_iPlayerCount];
	m_pPlayer=(CPlayerRes *)pEngine->GetMem()->GlobalMalloc(m_iPlayerCount*sizeof(CPlayerRes));
	for(i=0;i<m_iPlayerCount;i++)
	{
		// name	
		pData.ReadString(m_pPlayer[i].name);	

	    // power
		m_pPlayer[i].power=pData.ReadShort();

        // precision
		m_pPlayer[i].precision=pData.ReadShort();

        // rotation
		m_pPlayer[i].rotation=pData.ReadShort();

		// mentation
		m_pPlayer[i].mentation=pData.ReadShort();

	    // model index
		m_pPlayer[i].modelIndex=pData.ReadChar();

	    // ball index
		m_pPlayer[i].ballIndex=pData.ReadChar();


		// ball trace
		m_pPlayer[i].ballStepsCount=pData.ReadShort();  
		//m_pPlayer[i].pballTrace=new int[m_pPlayer[i].ballStepsCount*6];
		m_pPlayer[i].pballTrace=(int *)pEngine->GetMem()->GlobalMalloc(m_pPlayer[i].ballStepsCount*6*sizeof(int));
		int j;
		for(j=0;j<m_pPlayer[i].ballStepsCount*6;j++)
			m_pPlayer[i].pballTrace[j]=pData.ReadInt();


		// action
		int count=pData.ReadInt();
		int maxactions=PLAYER_ANI_COUNT;

		for(j=0;j<count;j++)
		{
			if(j<maxactions)
			{
				m_pPlayer[i].actionstart[j] = pData.ReadInt();  
				m_pPlayer[i].actionend[j] = pData.ReadInt();  
				m_pPlayer[i].actioninterval[j] = pData.ReadInt();  
				m_pPlayer[i].actionkeep[j] = pData.ReadInt();
			}
			else
			{
				pData.ReadInt();
				pData.ReadInt();
				pData.ReadInt();
				pData.ReadInt();
			}
		}
		
		count=pData.ReadInt();
		m_pPlayer[i].clothsCount=count;
		//m_pPlayer[i].cloths=new char*[count];
		m_pPlayer[i].cloths=(char **)pEngine->GetMem()->GlobalMalloc(count*sizeof(char *));
		//Qiu Li add decoration, 2005/2/2
		//m_pPlayer[i].decor= new short[count];
		m_pPlayer[i].decor=(short *)pEngine->GetMem()->GlobalMalloc(count*sizeof(short));
		//Qiu Li end
		for(j=0;j<count;j++)
		{	
			//m_pPlayer[i].cloths[j]=new char[50];
			m_pPlayer[i].cloths[j]=(char *)pEngine->GetMem()->GlobalMalloc(50*sizeof(char));
			pData.ReadString(m_pPlayer[i].cloths[j]);
			//Qiu Li add decoration, 2005/2/2
			m_pPlayer[i].decor[j] = pData.ReadShort();
			//Qiu Li end
		}

	}

	m_iBgCount = pData.ReadShort();
	//m_pBgs = new Bg[m_iBgCount];
	m_pBgs = (Bg *)pEngine->GetMem()->GlobalMalloc(m_iBgCount*sizeof(Bg));
	for (i=0; i<m_iBgCount; i++)
	{
		pData.ReadString(m_pBgs[i].name);
	    pData.ReadString(m_pBgs[i].grabTex);

		m_pBgs[i].modelIndex = pData.ReadChar();
		m_pBgs[i].floorModelIndex = pData.ReadChar();
		m_pBgs[i].skyboxModelIndex = pData.ReadChar();
		m_pBgs[i].audienceIndex = pData.ReadChar();
		m_pBgs[i].furnitureIndex = pData.ReadChar();


		m_pBgs[i].lightTypeCount = pData.ReadChar();
		m_pBgs[i].lightItemCount = pData.ReadChar();
		//m_pBgs[i].lightTexName = new char[m_pBgs[i].lightTypeCount][STRING_MAX_LENGTH];
		//m_pBgs[i].lights = new LightItem[m_pBgs[i].lightItemCount];
		//m_pBgs[i].lighttex = new CTexture[m_pBgs[i].lightTypeCount];
		//m_pBgs[i].lightid = new int[m_pBgs[i].lightTypeCount];
		m_pBgs[i].lightTexName = (char(*)[STRING_MAX_LENGTH])pEngine->GetMem()->GlobalMalloc(m_pBgs[i].lightTypeCount*STRING_MAX_LENGTH*sizeof(char));
		m_pBgs[i].lights = (LightItem *)pEngine->GetMem()->GlobalMalloc(m_pBgs[i].lightItemCount*sizeof(LightItem));
		m_pBgs[i].lighttex = (CTexture *)pEngine->GetMem()->GlobalMalloc(m_pBgs[i].lightTypeCount*sizeof(CTexture));
		m_pBgs[i].lightid = (int *)pEngine->GetMem()->GlobalMalloc(m_pBgs[i].lightTypeCount*sizeof(int));
		int count = 0, temp;
		for (j=0; j<m_pBgs[i].lightTypeCount; j++)
		{
			pData.ReadString(m_pBgs[i].lightTexName[j]);
			temp = pData.ReadChar();
			for (int m=count; m<count+temp; m++)
			{
				m_pBgs[i].lights[m].lightid = j;
				m_pBgs[i].lights[m].posx = pData.ReadShort();
				m_pBgs[i].lights[m].posy = pData.ReadShort();
				m_pBgs[i].lights[m].posz = pData.ReadShort();
				m_pBgs[i].lights[m].size = pData.ReadShort();

			}
			count = temp;
		}
	}


	// bonus
	m_iBonusCount=pData.ReadShort();
	if(m_iBonusCount!=0)
	{
		//m_pBonuses=new short[m_iBonusCount];
		m_pBonuses = (short *)pEngine->GetMem()->GlobalMalloc(m_iBonusCount*sizeof(short));
		for(i=0;i<m_iBonusCount;i++)
			m_pBonuses[i]=pData.ReadShort();
	}


	// coin delivery info
	int count=pData.ReadShort();
	//m_Coins=new Coin**[count];
	m_Coins = (Coin***)pEngine->GetMem()->GlobalMalloc(count*sizeof(Coin**));
	for(i=0;i<count;i++)
	{	
		// read level 
		m_CoinLevelRounds[i]=pData.ReadShort();
		//m_Coins[i]=new Coin*[m_CoinLevelRounds[i]];
		m_Coins[i] = (Coin**)pEngine->GetMem()->GlobalMalloc(m_CoinLevelRounds[i]*sizeof(Coin*));
		for(j=0;j<m_CoinLevelRounds[i];j++)
		{
			// read round
			m_CoinRoundCoins[i][j]=pData.ReadShort();
			//m_Coins[i][j]=new Coin[m_CoinRoundCoins[i][j]];
			m_Coins[i][j] = (Coin *)pEngine->GetMem()->GlobalMalloc(m_CoinRoundCoins[i][j]*sizeof(Coin));
			for(k=0;k<m_CoinRoundCoins[i][j];k++)
			{
				m_Coins[i][j][k].id =pData.ReadChar();
				m_Coins[i][j][k].type =pData.ReadChar();
				m_Coins[i][j][k].info =pData.ReadChar();
				m_Coins[i][j][k].posX =pData.ReadShort();
				m_Coins[i][j][k].posY =pData.ReadShort();
			}
		}

⌨️ 快捷键说明

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