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

📄 game_object_db.cpp.svn-base

📁 自己做的小游戏
💻 SVN-BASE
字号:
/* Copyright (C) Steve Rabin, 2000.  * All rights reserved worldwide. * * This software is provided "as is" without express or implied * warranties. You may freely copy and compile this source into * applications you distribute provided that the copyright text * below is included in the resulting source code, for example: * "Portions Copyright (C) Steve Rabin, 2000" */////////////////////////////////////////////////////////////////// Filename: game_object_db.cpp//// Author: Steve Rabin// E-mail: stevera@noa.nintendo.com// From the book "Game Programming Gems"// From the article "Designing a General Robust AI Engine"//// Brief Disclaimer:// This code is free to use for commercial use and is in the// public domain. You may distribute, copy, modify, or use as// is as long as this information is present. This code makes// no guarantees written or implied and is provided solely as// an example. Have a nice day!//// Purpose:// This file contains the code to deal with the game object// database.////////////////////////////////////////////////////////////////#include "game_object_db.h"#include "game_object.h"#include "malloc.h"#include "../gamedata/GameData.h"//#include "hud.h"#include <string.h>typedef struct{	GameObject* head;} GODB;// INTERNAL LOCAL VARIABLESGODB masterGODB;GameObject* GODBiterator;unsigned int nextGUID = 1;// INTERNAL HELPER FUNCTIONSvoid GODBPushBack( GameObject* go );void GODBDestroyMarkedForDeletion( void );//Every frame this function gets called to//update all of the game object logicvoid GODBUpdate( void ){	//GameObject* curGO = masterGODB.head;	//while( curGO != 0 )	//{	//	GOUpdate( curGO );	//	curGO = curGO->goNext;	//}	//GODBDestroyMarkedForDeletion();}//Draw all game objects//void GODBDraw( void )//{//	GameObject* curGO = masterGODB.head;//	while( curGO != 0 )//	{//		GODraw( curGO );//		curGO = curGO->goNext;//	}////}//Initializes the Game Object Databasevoid GODBInit( void ){	//masterGODB.head = 0;	//GODBiterator = 0;}//Creates and inserts a new game object into the database//Returns a pointer to the newly created object//GameObject* GODBCreateAndReturnGO( char* name )//{//	GameObject* newGO = (GameObject*) malloc( sizeof( GameObject ) );//	GOInitialize( newGO, nextGUID );//	nextGUID++;////	GODBPushBack( newGO );//	strcpy( newGO->szName, name );////	return( newGO );//	//	return (0);//}//Helper function for inserting a game object into the database//void GODBPushBack( GameObject* go )//{//	GameObject* curGO = masterGODB.head;////	if( curGO != 0 )//	{//		while( curGO->goNext != 0 ) {//			curGO = curGO->goNext;//		}////		curGO->goNext = go;//	}//	else {//		masterGODB.head = go;//	}//////}//Allows others to get the head of the database//GameObject* GODBGetHead( void )//{//	return( masterGODB.head );////}//Returns an object pointer from the database using a game object unique id (guid)GameObject* GODBGetGO( unsigned int unique_id ){	list<GameObject>::iterator i;	i = units.begin();	if ( unique_id != 0 ) {		while( i!= units.end() )		{			if (i->unique_id == unique_id) {				return &(*i);			}			i++;		}	}	return (0);	//if( unique_id != 0 )	//{	//	GameObject* curGO = masterGODB.head;	//	while( curGO != 0 )	//	{	//		if( curGO->unique_id == unique_id ) {	//			return( curGO );	//		}	//		curGO = curGO->goNext;	//	}	//}	//return( 0 );}//Returns an object pointer from the database using a string name//GameObject* GODBGetGOFromName( char* name )//{//	list<GameObject>::iterator i;//	i = units.begin();//	if ( i->unique_id != 0 ) {////		while( i!= units.end() )//		{//			if (strcmp(i->szName, name) == 0) {//				return &(*i);//			}//			i++;//		}//	}//	return (0);////////	GameObject* curGO = masterGODB.head;////	while( curGO != 0 )//	{//		if( strcmp( curGO->szName, name ) == 0 ) {//			return( curGO );//		}////		curGO = curGO->goNext;//	}////	return( 0 );////}//Removes all game objects from the database that have been marked for deletion//(When this is called, it is assumed that its a safe time to delete objects)void GODBDestroyMarkedForDeletion( void ){	list<GameObject>::iterator i = units.begin();		//GameObject* curGO = masterGODB.head;	//GameObject* lastGO = 0;	//while( curGO != 0 )	//{	//	if( curGO->bMarkedForDeletion ) {	//		if( lastGO != 0 ) {	//			lastGO->goNext = curGO->goNext;	//			free( curGO );	//			curGO = lastGO->goNext;	//		}	//		else {	//			masterGODB.head = curGO->goNext;	//			free( curGO );	//			curGO = masterGODB.head;	//		}	//			//	}	//	else if( curGO != 0 ) {	//		lastGO = curGO;	//		curGO = curGO->goNext;	//	}	//}}//////void GODBOutputStateInfoToHUD( void )//{//	char output[256];//	char state_name[256];//	GameObject* curGO = masterGODB.head;//	while( curGO != 0 )//	{//		TranslateStateName( curGO->state_machine_id, curGO->state, state_name );//		sprintf( output, "Name: %s    State: %s\n", curGO->szName, state_name  );//		HUDPrintToScreen( output );//		curGO = curGO->goNext;//	}//}////

⌨️ 快捷键说明

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