Code: Select all
class Particle
{
public:
int life;
int x,y,max_life;
Particle(int X, int Y, int LIFE,string &image_name);
bool kill();
};
Moderator: Coders of Rage
Code: Select all
class Particle
{
public:
int life;
int x,y,max_life;
Particle(int X, int Y, int LIFE,string &image_name);
bool kill();
};
Code: Select all
class Emitter
{
public:
void Set(int bla, bool bla_, string bla__);
private:
static const int NUM=10000;
Particle[NUM] Particles;
};
void Emitter::Set(int bla, bool bla_, string bla__)
{
for(int i=0;i<NUM;i++)
{
Particles[i].Set(bla,bla_,bla__);
}
}
Code: Select all
void Emitter::Update()
{
for(int i=0;i<NUM;i++)
{
Particles[i].Update(); //move particles
}
}
Code: Select all
class Emitter
{
public:
void Set(int bla, bool bla_, string bla__);
private:
static const int NUM=10000;
Particle[NUM] Particles;
};
void Emitter::Set(int bla, bool bla_, string bla__)
{
for(int i=0;i<NUM;i++)
{
Particles[i].Set(bla,bla_,bla__);
}
}
acerookie1 wrote:mv2112 wrote:Do something like this:\Code: Select all
class Emitter { public: void Set(int bla, bool bla_, string bla__); private: static const int NUM=10000; Particle[NUM] Particles; }; void Emitter::Set(int bla, bool bla_, string bla__) { for(int i=0;i<NUM;i++) { Particles[i].Set(bla,bla_,bla__); } }
are you sure thats dynamic? y arent u using new or delete?
Ya, creating and deleting particles after each cycle is very slow and inefficient. Like xiphirx said, the only reason you'd want it dynamic is if you want to change the particle limit.xiphirx wrote: The only reason you should make it dynamic is if you are allowing the user to change the max amount of particles. Otherwise you should have a set limit.
Code: Select all
class Emitter
{
public:
Emitter();
~Emitter();
private:
static const int NUM=10000;
Particle * Particles;
};
Emitter::Emitter()
{
Particles=new Particle[NUM];
}
Emitter::~Emitter()
{
delete [] Particles;
}
yeah i fixed this. made it dynamic. idk what this was.mv2112 wrote:Ya, creating and deleting particles after each cycle is very slow and inefficient. Like xiphirx said, the only reason you'd want it dynamic is if you want to change the particle limit.xiphirx wrote: The only reason you should make it dynamic is if you are allowing the user to change the max amount of particles. Otherwise you should have a set limit.
Also, i'd like to change the code i posted:Having too many particles that arnt allocated at runtime can cause a crash.Code: Select all
class Emitter { public: Emitter(); ~Emitter(); private: static const int NUM=10000; Particle * Particles; }; Emitter::Emitter() { Particles=new Particle[NUM]; } Emitter::~Emitter() { delete [] Particles; }
thanx againMacJordan wrote:Following is way you can define array in C++ :
One dimensional array :
int arrrayone[] = {1,2,3,4,5};
here you can define infinite value in this array because we have not define the size of array .
i you would like to define the size of array then consider,
int arrayone[2]= {1,2};
it will accepts only 2 parameter. it will not exceed from 2 other wise it will show an error
two dimensional array :
int arraytwo[ ] [ ] = {(1,2),(3,4),(5,6)};
first parantheses define the row and second one define column or array.
three dimensional array :
int arraythree[ ] [ ] [ ] = {(1,2,3),(4,5,6)};
okay, for your 1D array, that declaration works. However, for 2D and 3D arrays, you're completely wrong. Even if you could do it that way, there are 2 things wrong: 1) you'd need {} around the 3D array, and you'd use {} instead of (). However, you can't, as this will give you an error saying "array type has incomplete element type". You can declare your 1D array like:MacJordan wrote:Following is way you can define array in C++ :
One dimensional array :
int arrrayone[] = {1,2,3,4,5};
here you can define infinite value in this array because we have not define the size of array .
i you would like to define the size of array then consider,
int arrayone[2]= {1,2};
it will accepts only 2 parameter. it will not exceed from 2 other wise it will show an error
two dimensional array :
int arraytwo[ ] [ ] = {(1,2),(3,4),(5,6)};
first parantheses define the row and second one define column or array.
three dimensional array :
int arraythree[ ] [ ] [ ] = {(1,2,3),(4,5,6)};
Code: Select all
int array[] = { /* stuff */ };
Code: Select all
int array[3][2];
for(int y=0;y<3;++y)
for(int x=0;x<2;++x)
array[y][x] = 5;
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Indeed, MacJordan's code isn't syntactically correct; however, the following code is:Ginto8 wrote:okay, for your 1D array, that declaration works. However, for 2D and 3D arrays, you're completely wrong. Even if you could do it that way, there are 2 things wrong: 1) you'd need {} around the 3D array, and you'd use {} instead of (). However, you can't, as this will give you an error saying "array type has incomplete element type". You can declare your 1D array like:but for 2D and 3D arrays, you'd have to populate it another way, ie:Code: Select all
int array[] = { /* stuff */ };
Code: Select all
int array[3][2]; for(int y=0;y<3;++y) for(int x=0;x<2;++x) array[y][x] = 5;
Code: Select all
int a[3][2] = {{5,5},{5,5},{5,5}};
You, Ginto8, appear to think you know everything, but you have repeatedly shown that you do not.Ginto8 wrote:You, MacJordan, appear to think you know how to program, but you have repeatedly shown that you do not.
You, wearymemory, appear to think you aren't an asshole, but you have repeatedly shown that you are not.wearymemory wrote:You, Ginto8, appear to think you know everything, but you have repeatedly shown that you do not.Ginto8 wrote:You, MacJordan, appear to think you know how to program, but you have repeatedly shown that you do not.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Lol. You just contradicted yourself.Ginto8 wrote: You, wearymemory, appear to think you aren't an asshole, but you have repeatedly shown that you are not.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
lolwut.dandymcgee wrote:Lol. You just contradicted yourself.Ginto8 wrote: You, wearymemory, appear to think you aren't an asshole, but you have repeatedly shown that you are not.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
dandymcgee wrote:Lol. You just contradicted yourself.Ginto8 wrote: You, wearymemory, appear to think you aren't an asshole, but you have repeatedly shown that you are not.