Original Post
I have recently decided to try converting the arrays within my game to std::vector, due to pressure from forum members :) I have already been asking questions about this in an unrelated thread, but I thought I should put these questions under their own topic. Here's the situation: I have a few main objects in my game. The arrays I want to convert are members of these objects. These are the arrays that I want to convert: -CELL cells[], SHOT shots[], and PUFF puffs[] (these are all game logic arrays; a CELL is a moving entity, a SHOT is a projectile, and a PUFF is a simple particle. These three are all struct arrays, not class arrays.) -some arrays of vertices which I memcpy() to my LPDIRECT3D9VERTEXBUFFER at draw time. Here are my questions: 1) Is it possible and practical to turn my vertex arrays into std::vectors? What function do I use to copy memory from an std::vector to a direct3d vertex buffer? 2) Does anyone know what's going on with the problem described below? The following is a quote from another thread describing my attempt to convert a small SHOT shot_types array (used to define characteristics for types of projectiles) to a std::vector ////////////////////////////////////BEGIN QUOTE//////////////////// I have a question about std::fill(), which I want to be able to use in the same way I used ZeroMemory() to zero out arrays. Jpetrie, I tried out what you told me and there was a problem. Here's what I did: The resize() command works OK, but there is a problem with the std::fill() command. I do not understand the error message for this command. I have it right here: .............................................................................. c:\program files\microsoft visual studio 8\vc\include\xutility(2726) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const int' (or there is no acceptable conversion) game_structs.h(147): could be 'SHOT &SHOT::operator =(const SHOT &)' while trying to match the argument list '(SHOT, const int)' c:\program files\microsoft visual studio 8\vc\include\xutility(2754) : see reference to function template instantiation 'void std::_Fill,int>(_FwdIt,_FwdIt,const int &)' being compiled with [ _Ty=SHOT, _Alloc=std::allocator, _FwdIt=std::_Vector_iterator> ] synthgame.cpp(36) : see reference to function template instantiation 'void std::fill,int>(_FwdIt,_FwdIt,const int &)' being compiled with [ _Ty=SHOT, _Alloc=std::allocator, _FwdIt=std::_Vector_iterator> ] ..................................................................... The problem seems to be with the '0' parameter within the std::fill() call. The problem persisted when I changed it to NULL and to (SHOT)0 (which is undefined, anyway.) Can you please tell me why I am unable to do std::fill()? Does std::vector::resize() always set everything to NULL on it's own? Even if it does, I still need to be able to use std::fill() because some of my vectors will need to be "cleared" (not resized, but just set to all NULL values) at various points in the game. ////////////////////////////////////END QUOTE//////////////////// Thanks a lot! -synth_cat
//define a struct somewhere
struct SHOT
{
//simple flags
bool alive;
ShotType type;
//physical dimensions
D3DXVECTOR2 pos;
D3DXVECTOR2 mov;
float height;
float radius;
float tail_length;
float damage; //reflects impact of shot
float life; //from 0 to 1
float wall_loss; //from 0 to 1 - nonfactored by fps_factor
float fade_time; //from 0 to 1 -represents the amount of life the
//shot loses in one second
D3DXVECTOR2 uv; //texcoords
};
//within class declaration
std::vector<SHOT> shot_types;
//within constructor
shot_types.resize(NUM_SHOT_TYPES);
std::fill(shot_types.begin(),shot_types.end(),NULL);