Refactoring, Again

Published December 04, 2007
Advertisement
So, I haven't touched my rendering code in a month or so, which can only mean one thing. That's right, it's time to rewrite the whole thing [grin]!

It's hard to get any progress done on ISO whilst constantly rewriting my drawing code, but to be honest making a game out of it is kind of secondary. I started the project with mostly to tool around with DirectX, and so far that's pretty much what I've been doing.

So, quick review: right now, my architecture is pretty bare-bones. I have a monolithic Renderer class that holds all the game's geometry. Objects that reference that geometry, such as map tiles, simply hold indexes into the renderer's geometry buffers, and use those to tell the renderer what to draw and when to draw it. This was fine when all I was drawing was a bunch of tiles, but now it's getting annoying to have to add new buffers to the renderer for each new type of object I want to draw, and passing around buffer indices is, in my opinion, inelegant.

So, how am I going to fix this? I don't want a whole bunch of random objects holding on to vertex and index data in and of themselves. The solution is component based architecture. The new plan is to make a Renderable component that all drawable objects can contain. This component will hold all the geometry information, as well as things like world transforms, materials, and effects. When an object wants to draw, it's Renderable component will add a draw request to the renderer's render queue. The request will contain all necessary information that the renderer needs to draw the object (i.e., all the geometry and the like). This should all be pretty simple thanks to the handy event system I have in place.

I know talk is cheap, and none of this really means anything until I have my implementation done, but at least I know what I want to do now.

Here's what I'm going for, in pseudo-code:
Renderer{	hash_map MasterGeometry;	queue DrawRequests;	struct DrawInfo	{		FVF;		Vert vOffset;		Index iOffset;		Effect *effect;		Material *material;                int numPrims;	};	RequestDraw(FVF fvf, GeometryBuffer buffer, Effect *fx, Material *mat, int prims)	{		if (!IsInMasterGeometry(buffer))		{			AddGeometry(buffer);		}		DrawInfo info(fvf);		info.vOffset = GetVertOffset(buffer);		info.iOffset = GetIndOffset(buffer);		info.material = mat;		info.effect = fx;                info.numPrims = prims;		queue.insert(info);	}	Draw()	{		for each DrawInfo info in DrawRequests;		DrawIndexedPrimitive(stuff from info);	}}


So, the renderer still builds a list off all the geometry from the incoming draw requests, so I can batch things intelligently and minimize the actual draw calls. That's the plan at least, I'm sure there will be lots of complications and headaches to work out. This is the first time I've messed around with this sort of thing, so it should be an adventure. I'll get started on the implementation when I finish the dozen or so school projects that were due ...last week-ish.
Next Entry Wow...
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!
Advertisement

Latest Entries

/facepalm

1719 views

Baby Steps

1280 views

...

720 views

Stuff

1320 views

Productivity++

1207 views

Rock Band FTW

1239 views

Seattle Opera

1282 views

Christ

1208 views

I maek gaem!

1184 views
Advertisement