

I was going through my data structure notes and was surfing the net to find out more about memory management. I chanced upon this website which has a pretty clear application that simulate the allocation and freeing of memory. Feel free to check it out!
http://research.cs.vt.edu/AVresearch/MMtutorial/index.php
Basic Memory Management
http://www.memorymanagement.org/articles/
Hey everyone! I am taking data structure this semester. I will be sharing some of the things that I learned over here and hopefully you can picked up one or two useful things.
Why Plan?
So How do I design an Algorithm?
Some Help
Implementation
Testing
Robustness
System Testing
Debugging
I am currently working on the particle engine of my game. My team mate forwarded me this link (http://rbwhitaker.wikidot.com/2d-particle-engine-1) that had a tutorial on how to make a particle engine. The tutorial consist of 4 whole page of texts. I think that is great but too long when you want to refer to it again and again.
I will give a summary of what the tutorial is about. Reason number #1 is that I learned better when I summed up things. Reason number #2 is that this allowed me to have a quick recap if I want to refer to it again. I do not want to waste time reading through all the 4 pages again.
What is a Particles?
A particles is a small point in your games that will be drawn with an image.
Anatomy of a Particle Engine
A particle engine consist of three major components:
1. Particles
2. A Particles Emitter
3. Engine itself
Particles often has:
1. A position in a game world
2. Velocity
3. Angle that it is rotated at
4. Angular Velocity (Indicates how quickly the particle is spinning)
5. Color and texture for drawing.
6. Life span
Particles Emitter is:
1. The location that the particles are coming from
2. Responsible for determining how many particles will be created at any given time.
Particle Engine:
Manages the state of the previous two components and is responsible for removing dead particles from the system.
Creating a Particle Class
I have rewrote the code in C++ so it’s abit different from what is shown in the website.
Particle.hpp
class Particle
{
public:
particle(Texture2D texture, Vector2 position, Vector2 velocity,float angle, float angularVelocity, Color color, float size, int ttl); //Constructor
~particle(); //Destructor
void Update();
void Draw();
private:
Texture2D Texture; //Texture that will be drawn to represent the particles
Vector2 Position; //Current Position of the particle
Vector2 Velocity; // Speed of the particle at the current instance
float Angle; //Current angle of rotation
float AngularVelocity; //Speed that angle is changing
Color Color; //Color of the particle
float Size; //Size of the particle
int TTL; //Time to live
}
Particle.cpp
particle::particle(Texture2D texture, Vector2 position, Vector2 velocity,float angle, float angularVelocity, Color color, float size, int ttl)
{
Texture= texture;
Position = position;
Velocity = velocity;
Angle = angle;
AngularVelcoity = angularVelocity;
Color = color;
Size = size;
TTL = ttl;
}
void particle::Update()
{
TTL–;
position += Velocity;
Angle += AngularVelocity;
}
void particle::Draw()
{
DrawParticles(); //The drawing will be done using the draw particles function I program in the graphic engine. More will be disclose about the engine in later stage.
}
ParticleEngine Class
ParticleEngine.hpp
class ParticleEngine
{
public:
ParticleEngine( List<Texture2D> textures, Vector2 location); //Constructor
Particle GenerateNewParticle();
void Update();
void Draw();
private:
Vector2 EmitterLocation;
Random random;
List<Particle> particles;
List<Texture2D> textures;
}
ParticleEngine.cpp
ParticleEngine::ParticleEngine( List<Texture2D>, Vector2 location)
{
EmitterLocation = location;
this.textures = textures;
this.particles = new List<Particle>();
random = new Random();
}
Particles ParticleEngine::GenerateNewParticle()
{
Texture2D texture = textures[random.Next(textures.count)]; //Assign a random texture to the generated texture.
Vector2 position = EmitterLocation;
Vector2 Velocity = new Vector2( 1f * (float)(random.NextDouble() * 2-1), 1f * (float)(random.NextDouble() * 2-1));
float angle = 0;
float angularVelocity = 0.1f * (float)(random.NextDouble() * 2-1 );
Color color = new Color( (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
float size = (float)random.NextDouble();
int ttl = 2- + random.Next(40);
return new Particle(texture, position, velocity, angle , angularVelocity, color, size , ttl);
}
void ParticlesEngine::Update()
{
int total = 10;
for(int i = 0; i<total; i++)
{
particles.Add(GenerateNewParticle());
}
for(int particle = 0; particle < particles.count; ++particle)
{
particle[particle].update();
if(particle[particle].TTL <=0)
{
particles.removeAt(particle);
–Particle;
}
}
void ParticleEngine::Draw(spriteBatch spriteBatch)
{
spriteBatch.Begin();
for()
{
particle[index].Draw(spriteBatch);
}
spriteBatch.End();
}
Using the particle Engine
Create an instance of the particle engine.
ParticleEngine particleEngine;
At Load()
List<Texture2D> texture = new List<Texture2D>();
texture.Add(content.Load<Texture2D>(“circle”));
texture.Add(content.Load<Texture2D>(“star”));
texture.Add(content.Load<Texture2D>(“diamond”));
particleEngine = new ParticleEngine(texture, new Vector2(400,200));
update()
particleEngine.EmitterLocation = new Vector2( Mouse.GetState().x, Mouse.GetState().y);
particleEngine.Update();
Draw()
particleEngine.Draw(spriteBatch);

I am currently using a Dell Laptop which I got it from an IT sale at a pretty good rate. It’s not the most powerful machine but it does the job for me. The 17 inch LCD monitor was reused from my family’s spoiled desktop. Again It’s not the most beautiful LCD but it does help me a lot especially when I need to refer to multiple windows.
The lamp was given to me from my boss when he closed down his company operation in Singapore. It was bought from Ikea at around s$50. I like how the lamp creates a studio-like environment but it can get the room slightly warm.
I have two board facing me. A white board and a magnetic board below. I will break down projects into smaller components and write them down onto a post it notes and paste it on the boards. This will give me a better overview of what has been done and what’s not. Once done I will shift them. Seeing the post it going from one side to another give me a great sense of accomplishment.
On my table, under the glass, I have pictures and notes that I will occasionally read them(especially when I am bored) to motivate me to work hard.
I am having my vacation now. Other than my school game project, I am working on a mini game with a friend who is studying computer science in Nanyang Technological University (NTU). He’s not train in game programming, so we have a bit to work on. Using my previous experience with game engine development we are going to make a new game engine. As I spent my whole of last semester working mainly on the graphic engine, I will take this opportunity to work on other parts of the engine. Game Design will be simple.
In this project we will be using google code for storing our code, tortoise SVN, visual studio 2010 and directX 9.

![]()