After including <list> in your code make sure you add:
using namespace std
This effect took me some time to debug as each time I was erasing an item within the list the program would crash. I fixed this after reading up the MSDN docs and found that list::erase returns a pointer for the iterator to the next available item.
Main.cpp
#include "DarkGDK.h"
using namespace std;
#include "camcontrol.h"
#include <list>
#include "rain.h"
void DarkGDK ( void )
{
char text[10]; int cnt;
CamControl cam;
RAIN_LIST rain;
dbAutoCamOff();
cam.position(0,100,0);
dbMakeObjectPlain(1,1000,1000);
dbSyncOn ( );
dbSyncRate ( 60 );
while ( LoopGDK ( ) )
{
cnt=rain.getcount();
itoa(cnt,text,10);
dbText(0,0,text);
cam.update();
rain.update();
dbSync ( );
}
return;
}
rain.h
/* RAIN FX
Uses default settings to start with
*/
#define RAIN_GRAVITY 5
#define RAIN_HEIGHT 300
#define RAIN_RADIUS 500
#define RAIN_AMOUNT 30
#define RAIN_ON TRUE
#define RAIN_OFF FALSE
#define RAIN_OBJECTS 6000
#define RAIN_OBJW 1
#define RAIN_OBJH 10
#define RAIN_MAINOBJ 5999
class RAIN_DROPLET {
public:
float xp,yp,zp;
int object;
~RAIN_DROPLET() {
if (dbObjectExist(object))
dbDeleteObject(object);
}
};
class RAIN_LIST {
private:
list<RAIN_DROPLET> lst;
list<RAIN_DROPLET>::iterator itr;
public:
int flag;
RAIN_DROPLET tmp;
RAIN_LIST() {
// initialise defaults
flag=RAIN_ON;
dbMakeObjectPlain(RAIN_MAINOBJ,RAIN_OBJW,RAIN_OBJH);
dbColorObject(RAIN_MAINOBJ,0x0088ff);
//dbRotateObject(RAIN_MAINOBJ,-90,0,0);
}
~RAIN_LIST() {
dbDeleteObject(RAIN_MAINOBJ);
}
void update() {
int loop; float angle, dist;
// add new rain
if (flag==TRUE) {
for (loop=0; loop<RAIN_AMOUNT; loop++) {
angle=(float)dbRND(360000)/1000.0f;
dist=(float)dbRND(RAIN_RADIUS*1000)/1000.0f;
tmp.xp=(float)dbCameraPositionX()+sin(angle)*dist;
tmp.zp=(float)dbCameraPositionZ()+cos(angle)*dist;
tmp.yp=RAIN_HEIGHT;
// create droplet object
tmp.object=findobj();
dbCloneObject(tmp.object,RAIN_MAINOBJ);
lst.push_back(tmp);
}
}
// now move droplets (deleting grounded ones)
for (itr=lst.begin(); itr!=lst.end(); ++itr) {
itr->yp-=RAIN_GRAVITY;
if (itr->yp<=0) {
dbDeleteObject(itr->object);
// erase item in list but return next available pointer
itr=lst.erase(itr);
} else {
dbPositionObject(itr->object,itr->xp,itr->yp,itr->zp);
}
}
}
int findobj() {
int curr=RAIN_OBJECTS;
while (dbObjectExist(curr)) curr++;
return curr;
}
int getcount() {
return (lst.size());
}
};
camcontrol.h
#define MAX_CAMROTX 5
#define MAX_CAMROTY 5
#define MAX_CAMMOVE 5
class CamControl {
private:
// position
float xp,yp,zp;
// orientation
float xo,yo,zo;
// movement
float xm,ym,zm;
// rotation
float xr,yr,zr;
// strafe movement
float strafe;
// forward/backward movement
float move;
public:
CamControl() {
xp=yp=zp=
xo=yo=zo=
xm=ym=zm=
xr=yr=zr=
0;
}
void position(float x, float y, float z) {
xp=x; yp=y; zp=z;
}
void update() {
float mousex,mousey;
int mousec;
mousec=dbMouseClick();
mousex=dbMouseMoveX()/2;
mousey=dbMouseMoveY()/2;
// control y rotation
yr=dbWrapValue(yr+mousex);
// control x rotation
xr=dbWrapValue(xr+mousey);
dbPositionCamera(xp,yp,zp);
dbRotateCamera(xr,yr,zr);
// strafe controls
if (dbLeftKey()) {
strafe-=2;
if (strafe<-MAX_CAMMOVE)
strafe=-MAX_CAMMOVE;
}
if (dbRightKey()) {
strafe+=2;
if (strafe>MAX_CAMMOVE)
strafe=MAX_CAMMOVE;
}
dbTurnCameraRight(90);
dbMoveCamera(strafe);
dbTurnCameraLeft(90);
if (strafe<0) strafe += 0.5;
if (strafe>0) strafe -= 0.5;
// move forward/backward
if (dbUpKey()) {
move+=2;
if (move>MAX_CAMMOVE)
move=MAX_CAMMOVE;
}
if (dbDownKey()) {
move-=2;
if (move<-MAX_CAMMOVE)
move=-MAX_CAMMOVE;
}
if (move>0) move-=0.5;
if (move<0) move+=0.5;
dbMoveCamera(move);
xp=dbCameraPositionX();
yp=dbCameraPositionY();
zp=dbCameraPositionZ();
}
};
I do hope this helps people out understanding the use of lists in C++...
EDIT:
To get this to compile and build you will need to set the Options:
Properties/Configuration properties/C C++/Code Generation
and set it to /MT (not /MTd)
Warning! May contain Nuts!