Entity drawing!

Published June 29, 2008
Advertisement
I finally finished my entity-drawing algorithm! It was a huge pain, but I'm pretty happy with what I have now. The first version that actually worked was pretty clunky, with something like seven for-loops -- one for each entity, two for each sprite character coord, two for each possible looped-around drawing coord, and three consecutive loops to add the "good" X and Y values to vectors and draw them. This version is considerably condensed, heh. Only five for-loops...

COORD loopedtimes = {(viewloc.X+viewsize.X-1)/realsize.X, (viewloc.Y+viewsize.Y-1)/realsize.Y};for (std::list::iterator itr = entities.begin(); itr != entities.end(); ++itr){	entity* ent = *itr;	for (int Y = 0; Y < ent->Size().Y; ++Y)	{		for (int X = 0; X < ent->Size().X; ++X)		{			for (int j = 0; j <= loopedtimes.X; ++j)			{				for (int i = 0; i <= loopedtimes.Y; ++i)				{					COORD point = {ent->position.X + X, ent->position.Y + Y};					if (point.X >= realsize.X)						point.X -= realsize.X;					if (point.Y >= realsize.Y)						point.Y -= realsize.Y;					point.X += realsize.X * j - viewloc.X;					point.Y += realsize.Y * i - viewloc.Y;					if (point.X >= 0 && point.X < viewsize.X &&						  point.Y >= 0 && point.Y < viewsize.Y)					{						tempbuf[point.Y * viewsize.X + point.X].Attributes = (*ent)[Y*ent->Size().X+X].Attributes;						tempbuf[point.Y * viewsize.X + point.X].Char = (*ent)[Y*ent->Size().X+X].Char;					}				} // for each Y-looped point			} // for each X-looped point		} // for each X	} // for each Y} // for each entity


While I was working on this, I wasn't sure what most of the changes I made actually did! I've tested this a bit (and I've gone through with the debugger) and it looks like it works, so I'm going to start working on an entity-loading system, and then a map system.

Questions about the algorithm? (I know I have plenty!)
Previous Entry Minor changes
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement