Sorry my internet is dead from last 2 days...
Posting from my mobile's GPRS
Hawkblood i copied the structures and pasted them like this
#include area
//variable deceleration area
//media loading area
//some functions
//then structures
struct WAYPOINT2{
WAYPOINT2(){Connection=NULL;};
~WAYPOINT2(){if (Connection!=NULL) delete Connection;Connection=NULL;}
D3DXVECTOR3 Location;
UINT NumberOfConnections;
UINT *Connection;
};
struct WPCONTROLLER2{//use this struct to load/save the controller data
WPCONTROLLER2(){WayPoint=NULL;}
~WPCONTROLLER2(){if (WayPoint!=NULL) delete WayPoint;WayPoint=NULL;}
UINT NumberOfWP;
WAYPOINT2 *WayPoint;
};
//**********************************************************************************************
struct WPPORT{
WPPORT(){To=-1;DistanceToWaypoint.clear();}
~WPPORT(){DistanceToWaypoint.clear();};
int To;//refers to the WAYPOINT this is attached to. (-1==not connected)
vector <float> DistanceToWaypoint;//from this port each WAYPOINT has a combined distance. This index is the same as vector <WAYPOINT> WayPoint; in WPCONTROLLER
//if DistanceToWaypoint==-1 this means that WayPoint has no connection to through this port
};
struct WAYPOINT{
WAYPOINT(float x,float y,float z);
~WAYPOINT();
bool HasConnection;
D3DXVECTOR3 Location;
vector <WPPORT> Port;//when a waypoint is connected to another waypoint, generate a new port.
};
WAYPOINT::WAYPOINT(float x,float y,float z){
Port.clear();
Location=D3DXVECTOR3(x,y,z);
HasConnection=false;
}
WAYPOINT::~WAYPOINT(){
Port.clear();
}
struct WPCONTROLLER{//************** THIS IS THE MAIN STRUCTURE
WPCONTROLLER();
~WPCONTROLLER();
vector <WAYPOINT> WayPoint;
UINT AddWP(float x,float y,float z);
UINT AddNextWP(UINT WP2,float x,float y,float z);
void DeleteWP(int WP);//********** needs to be done
void GenerateWayPointMap(void);
void ConnectWayPointToWayPoint(UINT WP1,UINT WP2);
int FindShortestPath(UINT Start,UINT Destination);
void ShowWayPoints(void);
void HideWPBoxes(void);//this will actually destroy them. it's better that way
vector <int> WPBox;
vector <int> ConnectionLine;
WPCONTROLLER2 WPImpExp;
void Import(void);//uses WPCONTROLLER2 data to generate WPCONTROLLER
void Export(void);//uses WPCONTROLLER data to generate WPCONTROLLER2 for use in save file
}WPController;
WPCONTROLLER::WPCONTROLLER(){
WayPoint.clear();
}
WPCONTROLLER::~WPCONTROLLER(){
WayPoint.clear();
}
int WPCONTROLLER::FindShortestPath(UINT StartWP,UINT DestinationWP){
if ((StartWP>=WayPoint.size())||(DestinationWP>=WayPoint.size())) return -1;
int WP=-1;//the waypoint next in the path
float d=100000.0f;//some big number
for (UINT p=0;p<WayPoint[StartWP].Port.size();p++){
if (WayPoint[StartWP].Port[p].DistanceToWaypoint[DestinationWP]>-1.0f){
if (WayPoint[StartWP].Port[p].DistanceToWaypoint[DestinationWP]<d){
d=WayPoint[StartWP].Port[p].DistanceToWaypoint[DestinationWP];
WP=WayPoint[StartWP].Port[p].To;
}
}
}
return WP;
}
UINT WPCONTROLLER::AddNextWP(UINT WP2,float x,float y,float z){
//WP2 is the waypoint you want this one to be auto-attached to
UINT WP1=AddWP(x,y,z);
ConnectWayPointToWayPoint(WP1,WP2);
return WP1;
}
UINT WPCONTROLLER::AddWP(float x,float y,float z){
WayPoint.push_back(WAYPOINT(x,y,z));
UINT WP=WayPoint.size()-1;
//loop all ports on all WayPoints
for (UINT w=0;w<WayPoint.size();w++){
for (UINT p=0;p<WayPoint[w].Port.size();p++){
WayPoint[w].Port[p].DistanceToWaypoint.push_back(-1.0f);//this will tell GenerateWayPointMap() that this waypoint from this port has no connection
}
}
return WP;
}
void WPCONTROLLER::ConnectWayPointToWayPoint(UINT WP1, UINT WP2){
if ((WP1>=WayPoint.size())||(WP2>=WayPoint.size())) return;
//check to see if the connection already exists
for (UINT p=0;p<WayPoint[WP1].Port.size();p++) if (WayPoint[WP1].Port[p].To==WP2) return;
//create the port at both ends
int p=WayPoint[WP1].Port.size();
WayPoint[WP1].Port.push_back(WPPORT());
WayPoint[WP1].Port[p].To=WP2;
int p2=WayPoint[WP2].Port.size();
WayPoint[WP2].Port.push_back(WPPORT());
WayPoint[WP2].Port[p2].To=WP1;
for (UINT w=0;w<WayPoint.size();w++){
WayPoint[WP1].Port[p].DistanceToWaypoint.push_back(-1.0f);//this will tell GenerateWayPointMap() that this waypoint from this port has no connection
WayPoint[WP2].Port[p2].DistanceToWaypoint.push_back(-1.0f);//this will tell GenerateWayPointMap() that this waypoint from this port has no connection
}
WayPoint[WP1].Port[p].DistanceToWaypoint[WP1]=0;//it is distance 0 to itself
WayPoint[WP2].Port[p2].DistanceToWaypoint[WP2]=0;//it is distance 0 to itself
WayPoint[WP1].HasConnection=true;
WayPoint[WP2].HasConnection=true;
//don't call GenerateWayPointMap() here! It would only slow down the load process
}
void WPCONTROLLER::DeleteWP(int WP){
//remove the connections at WP and from each WayPoint connected to WP
for (UINT p=0;p<WayPoint[WP].Port.size();p++){
UINT p2;
for (p2=0;p2<WayPoint[WayPoint[WP].Port[p].To].Port.size();p2++) if (WayPoint[WayPoint[WP].Port[p].To].Port[p2].To==WP) break;
if (p2<WayPoint[WayPoint[WP].Port[p].To].Port.size()) WayPoint[WayPoint[WP].Port[p].To].Port.erase(WayPoint[WayPoint[WP].Port[p].To].Port.begin()+p2);
}
WayPoint[WP].Port.clear();//delete the ports at the WP
WayPoint.erase(WayPoint.begin()+WP);
for (UINT w=0;w<WayPoint.size();w++){
for (UINT p=0;p<WayPoint[w].Port.size();p++){
if (WayPoint[w].Port[p].To>WP) WayPoint[w].Port[p].To--;//reduce the reference
WayPoint[w].Port[p].DistanceToWaypoint.clear();
for (UINT w2=0;w2<WayPoint.size();w2++) WayPoint[w].Port[p].DistanceToWaypoint.push_back(-1.0f);
WayPoint[w].Port[p].DistanceToWaypoint[w]=0;//so it has 0 to itself
}
}
GenerateWayPointMap();//needs to be called here to fix the connections. DeleteWP(..) should never be called in-game!
}
void WPCONTROLLER::GenerateWayPointMap(){
//I made this a seperate call function for speed purposes. When loading a level, this call should be done only at the end instead of each time a connection is made.
bool Unresolved=true;
bool Changed=false;
while (Unresolved){
Unresolved=false;
Changed=false;
for (UINT w=0;w<WayPoint.size();w++){
for (UINT p=0;p<WayPoint[w].Port.size();p++){
for (UINT d=0;d<WayPoint[w].Port[p].DistanceToWaypoint.size();d++){
if (d!=w){
if (WayPoint[d].HasConnection){//check it only if it has any connections
int wp2=WayPoint[w].Port[p].To;
if (WayPoint[w].Port[p].DistanceToWaypoint[d]<0.0f){//try to get info from the neighbor connected to that port
//loop all ports to find the shortest one
float s=100000.0f;//big number
for (UINT p2=0;p2<WayPoint[wp2].Port.size();p2++){
if (WayPoint[wp2].Port[p2].DistanceToWaypoint[d]>-1.0){
if (WayPoint[wp2].Port[p2].DistanceToWaypoint[d]<s) s=WayPoint[wp2].Port[p2].DistanceToWaypoint[d];
}
}
if (s<100000.0f){
WayPoint[w].Port[p].DistanceToWaypoint[d]=s+D3DXVec3Length(&(WayPoint[w].Location-WayPoint[wp2].Location));
Changed=true;
}
else Unresolved=true;
}
else{
//loop all ports to find the shortest one
for (UINT p2=0;p2<WayPoint[wp2].Port.size();p2++){
if (WayPoint[wp2].Port[p2].DistanceToWaypoint[d]>-1.0){
if (WayPoint[wp2].Port[p2].DistanceToWaypoint[d]<WayPoint[w].Port[p].DistanceToWaypoint[d]-D3DXVec3Length(&(WayPoint[w].Location-WayPoint[wp2].Location))){
WayPoint[w].Port[p].DistanceToWaypoint[d]=WayPoint[wp2].Port[p2].DistanceToWaypoint[d]+D3DXVec3Length(&(WayPoint[w].Location-WayPoint[wp2].Location));
Changed=true;
}
}
}
}
}
}
}
}
}
if (!Changed) Unresolved=false;//this condition can occur when two or more WPs are connected outside the group. This keeps it from a perpetual loop condition.
//this is not the way it's supposed to work. ALL WPs should be connected to the entire network within the same WPCONTROLLER
//if multiple WPCONTROLLERs are used, they don't (and won't) be connected to each other.
}
}
void WPCONTROLLER::ShowWayPoints(){
HideWPBoxes();//start fresh
for (UINT i=0;i<WayPoint.size();i++){
WPBox.push_back(0);
if (i==0){
WPBox[i]=dbCreateObjectCube(1,FindFreeObject());
dbSetObjectEmissive(WPBox[0],dbRGB(255,0,0));//makes it bright red
}
else WPBox[i]=dbInstanceObject(WPBox[0],FindFreeObject());//instanced objects render faster and take up less processor power
dbPositionObject(WPBox[i],WayPoint[i].Location.x,WayPoint[i].Location.y,WayPoint[i].Location.z);
}
//create the ports
//ConnectionLine
int i=0;
for (UINT w=0;w<WayPoint.size();w++){
for (UINT p=0;p<WayPoint[w].Port.size();p++){
ConnectionLine.push_back(0);
if (i==0){
ConnectionLine[i]=dbCreateObjectCube(1,FindFreeObject());
dbSetObjectEmissive(ConnectionLine[0],dbRGB(0,0,255));//makes it bright blue
}
else ConnectionLine[i]=dbInstanceObject(ConnectionLine[0],FindFreeObject());
//scale and position the box (it will look like a line)
float d=WayPoint[w].Port[p].DistanceToWaypoint[WayPoint[w].Port[p].To];
int to=WayPoint[w].Port[p].To;
dbScaleObject(ConnectionLine[i],10,10,d*100.0f);
dbPositionObject(ConnectionLine[i],WayPoint[w].Location.x,WayPoint[w].Location.y,WayPoint[w].Location.z);
dbPointObject(ConnectionLine[i],WayPoint[to].Location.x,WayPoint[to].Location.y,WayPoint[to].Location.z);
dbMoveObject(ConnectionLine[i],d/2.0f);
i++;
}
}
}
void WPCONTROLLER::HideWPBoxes(){
if (WPBox.size()>0) dbDeleteObject(WPBox[0]);//this should delete all the instanced objects
WPBox.clear();
//delete the ports also
if (ConnectionLine.size()>0) dbDeleteObject(ConnectionLine[0]);//this should delete all the instanced objects
ConnectionLine.clear();
}
void WPCONTROLLER::Export(){
if (WPImpExp.WayPoint!=NULL) delete WPImpExp.WayPoint;
WPImpExp.WayPoint=new WAYPOINT2[WayPoint.size()];
WPImpExp.NumberOfWP=WayPoint.size();
for (UINT w=0;w<WayPoint.size();w++){
WPImpExp.WayPoint[w].NumberOfConnections=WayPoint[w].Port.size();
WPImpExp.WayPoint[w].Connection=new UINT[WPImpExp.WayPoint[w].NumberOfConnections];
for (UINT c=0;c<WPImpExp.WayPoint[w].NumberOfConnections;c++){
WPImpExp.WayPoint[w].Connection[c]=WayPoint[w].Port[c].To;
}
WPImpExp.WayPoint[w].Location=WayPoint[w].Location;
}
}
// EXAMPLE OF HOW TO SAVE THE DATA
void SaveMyLevel(void){
FILE *F;
fopen_s(&F,"MyLevel.dat","wb");
//here is where you would save anything you want in whatever format you choose
//and then, save your WPController.WPImpExp
fwrite(&WPController.WPImpExp.NumberOfWP,sizeof(UINT),1,F);
for (UINT w=0;w<WPController.WPImpExp.NumberOfWP;w++){
fwrite(&WPController.WPImpExp.WayPoint[w].Location,sizeof(D3DXVECTOR3),1,F);
fwrite(&WPController.WPImpExp.WayPoint[w].NumberOfConnections,sizeof(UINT),1,F);
for (UINT c=0;c<WPController.WPImpExp.WayPoint[w].NumberOfConnections;c++){
fwrite(&WPController.WPImpExp.WayPoint[w].Connection[c],sizeof(UINT),1,F);
}
}
fclose(F);
//don't leave it soaking up memory
WPController.WPImpExp.~WPCONTROLLER2();
}
void WPCONTROLLER::Import(){//this funtion is called after data is loaded from disk
//***** YOU MUST HAVE ALREADY LOADED YOUR GAME LEVEL CONTAINING THIS INFO
//this will generate the waypoints
WayPoint.clear();//kill all the old info, if any
for (UINT i=0;i<WPImpExp.NumberOfWP;i++){//add all the waypoints
AddWP(WPImpExp.WayPoint[i].Location.x,WPImpExp.WayPoint[i].Location.y,WPImpExp.WayPoint[i].Location.z);
}
for (UINT i=0;i<WPImpExp.NumberOfWP;i++){//make all the connections
for (UINT c=0;c<WPImpExp.WayPoint[i].NumberOfConnections;c++){
ConnectWayPointToWayPoint(i,WPImpExp.WayPoint[i].Connection[c]);
}
}
GenerateWayPointMap();
//delete WPImpExp
WPImpExp.~WPCONTROLLER2();
}
// EXAMPLE OF HOW TO LOAD THE DATA
void LoadMyLevel(void){
//make sure it's all gone first
WPController.WPImpExp.~WPCONTROLLER2();
FILE *F;
fopen_s(&F,"MyLevel.dat","rb");
//here is where you would load anything you want in whatever format you choose
//and then, save your WPController.WPImpExp
fread(&WPController.WPImpExp.NumberOfWP,sizeof(UINT),1,F);
WPController.WPImpExp.WayPoint=new WAYPOINT2[WPController.WPImpExp.NumberOfWP];
for (UINT w=0;w<WPController.WPImpExp.NumberOfWP;w++){
fread(&WPController.WPImpExp.WayPoint[w].Location,sizeof(D3DXVECTOR3),1,F);
fread(&WPController.WPImpExp.WayPoint[w].NumberOfConnections,sizeof(UINT),1,F);
WPController.WPImpExp.WayPoint[w].Connection=new UINT[WPController.WPImpExp.WayPoint[w].NumberOfConnections];
for (UINT c=0;c<WPController.WPImpExp.WayPoint[w].NumberOfConnections;c++){
fread(&WPController.WPImpExp.WayPoint[w].Connection[c],sizeof(UINT),1,F);
}
}
fclose(F);
}
and in the main
void DarkGDK ( void )
{
dbSyncOn();
SC_Start();
dbSyncRate(60);
//Some Data
//creating waypoints
WPController.AddWP(0,0,0);//0
WPController.AddWP(50,0,10);//1
WPController.AddWP(-15,0,10);//2
WPController.AddWP(-20,0,20);//3
WPController.AddWP(-10,0,20);//4
WPController.AddWP(-10,0,30);//5
WPController.AddWP(20,0,-20);//6
//connecting waypoints to each other
WPController.ConnectWayPointToWayPoint(0,1);
WPController.ConnectWayPointToWayPoint(0,2);
WPController.ConnectWayPointToWayPoint(1,4);
WPController.ConnectWayPointToWayPoint(4,3);
WPController.ConnectWayPointToWayPoint(4,5);
WPController.ConnectWayPointToWayPoint(2,3);
WPController.ConnectWayPointToWayPoint(6,0);
// WPController.DeleteWP(2);
WPController.GenerateWayPointMap();//call this to get info so you can FindShortestPath(..)
WPController.ShowWayPoints();
while (LoopGDK( ) )
{
//functions call etc
}
return;
}
i am getting lots of errors.... cant' upload debug info bcoz of internet...Where i m wrong plz tell me...