#pragma once#include "WorldManager.h"void InitWorld(VWorld * world) {  Vector targetPos;  	InitCamera(&world->Camera);	world->Weapons = NULL;    InitObject(&world->CrossHair);	world->CrossHair.Position.x = 0.0;	world->CrossHair.Position.y = 0.0;	world->CrossHair.Position.z = -1.7;  BuildCrossHairModel(&world->CrossHair.Model);    world->Objects = (VObject *) NewPtr(sizeof(VObject));  if (world->Objects != NULL) {    InitObject(world->Objects);    BuildTargetModel(&world->Objects->Model);    targetPos.x = 2.0;    targetPos.y = 1.0;    targetPos.z = -7.0;    MoveObjectToPoint(world->Objects, &targetPos);    CalculateRadius(world->Objects);  }    world->Environment = (VObject *) NewPtr(sizeof(VObject));  if (world->Environment != NULL) {    InitObject(world->Environment);    BuildGrassModel(&world->Environment->Model);    targetPos.x = 0.0;    targetPos.y = -2.0;    targetPos.z = -0.0;    MoveObjectToPoint(world->Environment, &targetPos);  }  	world->Enemies = (VEnemy *) NewPtr(sizeof(VEnemy));	if (world->Enemies != NULL)	{		InitEnemy(world->Enemies, TestAI, world);	}		world->Explosions = NULL;		InitPhysics(&world->Physics);}void DrawCrossHair(VWorld * world){	DrawObject(&world->CrossHair);}void CleanUpWorld(VWorld * world) {	VWeapon * theWeapon;	VEnemy * theEnemy;	VObject * theObject;		CleanUpObject(&world->CrossHair);		while (world->Weapons != NULL) {		theWeapon = world->Weapons;		world->Weapons = theWeapon->next;		CleanUpWeapon(theWeapon);		DisposePtr((Ptr) theWeapon);	}		while (world->Enemies != NULL)	{		theEnemy = world->Enemies;		world->Enemies = theEnemy->next;		CleanUpEnemy(theEnemy);		DisposePtr((Ptr) theEnemy);	}		while (world->Objects != NULL)	{		theObject = world->Objects;		world->Objects = theObject->next;		CleanUpObject(theObject);		DisposePtr((Ptr) theObject);	}		while (world->Environment != NULL)	{		theObject = world->Environment;		world->Environment = theObject->next;		CleanUpObject(theObject);		DisposePtr((Ptr) theObject);	}}void DrawWorld(VWorld * world, float interval){	VWeapon * theWeapon;	VObject * theObject;	VEnemy * theEnemy;	VExplosion * theExplosion;	/* Fill with semi transparent background */	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	glDepthMask(GL_FALSE);	glColor4f(0.0, 0.0, 0.0, (0.017647059 / interval));	glBegin(GL_QUADS);		glVertex3f(-10.0, 10.0, -2.0);		glVertex3f(10.0, 10.0, -2.0);		glVertex3f(10.0, -10.0, -2.0);		glVertex3f(-10.0, -10.0, -2.0);	glEnd();	glDepthMask(GL_TRUE);	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);  	ApplyCamera(&world->Camera);  	for (theWeapon = world->Weapons; theWeapon != NULL; theWeapon = theWeapon->next)	{		DrawWeapon(theWeapon);	}  	for (theObject = world->Objects; theObject != NULL; theObject = theObject->next)	{		DrawObject(theObject);	}		for (theObject = world->Environment; theObject != NULL; theObject = theObject->next)	{		DrawObject(theObject);	}		for (theEnemy = world->Enemies; theEnemy != NULL; theEnemy = theEnemy->next)	{		DrawEnemy(theEnemy);	}		for (theExplosion = world->Explosions; theExplosion != NULL; theExplosion = theExplosion->next)	{		DrawExplosion(theExplosion);	}}void RunWorld(VWorld * world, float interval) {	VWeapon * theWeapon, * previousWeapon = NULL;	VObject * theObject, * previousObject = NULL;	VEnemy * theEnemy, * previousEnemy = NULL;	VExplosion * theExplosion, * previousExplosion = NULL;	Vector front, right;		theExplosion = world->Explosions;	while (theExplosion != NULL) {  	if (theExplosion->markedForRemoval) {  		if (previousExplosion == NULL) world->Explosions = NULL;  		else previousExplosion->next = theExplosion->next;  		previousExplosion = theExplosion;  		theExplosion = previousExplosion->next;  		CleanUpExplosion(previousExplosion);  		DisposePtr((Ptr) previousExplosion);  		if (theExplosion == NULL) break;  	}  	RunExplosion(theExplosion, interval);  	previousExplosion = theExplosion;  	theExplosion = theExplosion->next;  }		theWeapon = world->Weapons;	while (theWeapon != NULL) {		if (theWeapon->taggedForRemoval) {			if (previousWeapon == NULL) world->Weapons = theWeapon->next;			else previousWeapon->next = theWeapon->next;			previousWeapon = theWeapon;			theWeapon = previousWeapon->next;			CleanUpWeapon(previousWeapon);			DisposePtr((Ptr) previousWeapon);			if (theWeapon == NULL) break;		}		RunWeapon(theWeapon, interval, world->Objects, world->Enemies);		previousWeapon = theWeapon;		theWeapon = theWeapon->next;	}		for(theEnemy = world->Enemies; theEnemy != NULL; theEnemy = theEnemy->next)	{    if (theEnemy->Object.taggedForRemoval) {    	theExplosion = (VExplosion *) NewPtr(sizeof(VExplosion));			if (theExplosion != NULL)			{				InitExplosion(theExplosion, 10, 2.0, &theEnemy->Object.Position);							if(world->Explosions != NULL)					world->Explosions->next = theExplosion;				else					world->Explosions = theExplosion;			}			      if (previousEnemy == NULL) world->Enemies = theEnemy->next;      else previousEnemy->next = theEnemy->next;      previousEnemy = theEnemy;      theEnemy = previousEnemy->next;      CleanUpEnemy(previousEnemy);      DisposePtr((Ptr) previousEnemy);      if (theEnemy == NULL) break;    }		EnemyEvent(theEnemy, interval);    previousEnemy = theEnemy;	}		theObject = world->Objects;	while (theObject != NULL) {    if (theObject->taggedForRemoval) {    	theExplosion = (VExplosion *) NewPtr(sizeof(VExplosion));			if (theExplosion != NULL)			{				InitExplosion(theExplosion, 10, 2.0, &theObject->Position);							if(world->Explosions != NULL)					world->Explosions->next = theExplosion;				else					world->Explosions = theExplosion;			}			      if (previousObject == NULL) world->Objects = theObject->next;      else previousObject->next = theObject->next;      previousObject = theObject;      theObject = previousObject->next;      CleanUpObject(previousObject);      DisposePtr((Ptr) previousObject);      if (theObject == NULL) break;    }    /* Run object, if necessary */    previousObject = theObject;    theObject = theObject->next;  }  ForwardsVector(&world->Camera, 1.0, &front);  CrossProduct(&world->Camera.Up, &front, &right);  RunPhysics(&world->Physics, &world->Camera.Position, &front, &right, &world->Camera.Up, interval);  AddVector(&world->Camera.Position, &front, &world->Camera.Look);}