Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


LoneDwarf

Member Since 27 Oct 2006
Offline Last Active Yesterday, 04:51 PM

Topics I've Started

Game objects with voxel terrain

06 July 2009 - 11:00 AM

Hello all. I am making a mobile phone (no 3d support) that uses a 2d image for the voxel/height map and then renders it using ray casting. Just to be clear, the ray casting is basically the same as the old school Wolfenstein 3D. Each column of the screen is rendered casting a ray through the world. All is running well so far but now I want to add game objects that are 2d sprites. The only way I can think of to do it would be as follows:
For each game object sprite
  See if sprite image intersects the FOV
    Find the span of columns the sprite could effect
      Cast a ray for each column from the viewer to the sprite
      If the ray is below the top of the sprite when it reaches the sprite
        Copy the column of pixels from the sprite to the frame buffer
I also thought of doing this while casting the terrain in the first place but it will kill my inner loop. Any suggestions or maybe a reference?

Authoring tools

30 September 2008 - 04:40 AM

I was wondering what tool(s) people would suggest to use for writing my RPG game system? I have Adobe Master Collection CS3 so this gives me most of the Adobe tools and also I have Open Office.

Slow point light shadows using cubemaps.

12 August 2008 - 04:01 AM

I am having trouble getting my frame rate past 25fps. If I remove the depth clear I get 60fps. I am using a FBO with a 16bit depth and the cubemap is 1024x1024 RGBA8. If I reduce this to 512x512 I get 50fps and 70fps without clears. The clearing is just glClear with depth bit, I have also tried clearing stencil with it. Using a 8500GT with vsync off.
u32	shadowMap = 0;

for( u32 light = 0; light < numLights; light += cm_MaxLights, ++shadowMap )
{
	// These cubemaps are already created.
	ShadowMap*   pMap = shadowMapLevel( shadowMap );

	// FBO is also already created.
	FrameBuffer* pFBO = acquireFrameBuffer( pMap->vSize );

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, pFB->m_FrameBuffer );

	// Set projectin
	glMatrixMode( GL_PROJECTION);
	glLoadMatrixf( mProj );

	glViewport( 0, 0, pMap->vSize.x, pMap->vSize.y );
	glColorMask( 1, 1, 1, 1 );
	glClear( GL_COLOR_BUFFER_BIT );

	for( u32 face = 0; face < 6; ++face )
	{
		glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, pMap->cubeMap, 0 );

		switch( subLight )
		{
			// Each light uses one color channel (like Humus example)
			case 0:	glColorMask( 1, 0, 0, 0 );	break;
			case 1:	glColorMask( 0, 1, 0, 0 );	break;
			case 2:	glColorMask( 0, 0, 1, 0 );	break;
			case 3:	glColorMask( 0, 0, 0, 1 );	break;
		}

		glClear( GL_DEPTH_BUFFER_BIT );
		glMatrixMode( GL_MODELVIEW);
		glLoadMatrixf( MakeCubeMapTransform( pLight->getPos(), face ) );

		// Render effected geom.
	}
}

glColorMask( 1, 1, 1, 1 );


Component system: data dragons

05 June 2008 - 05:45 AM

There is always lots of talk about component systems but no much on how the data is managed. I am having two problems with my system that keep rearing thier ugly heads. So here is a small example of whas going on.
//-----------------------------------------------------------------------
class S_PointLight
{
private:
	float		m_fRadius;

public:
	virtual void	setRadius( float val ) { m_fRadius = val; }
	float		getRadius() const { m_fRadius = val; }
};
//-----------------------------------------------------------------------
class DM_Com
{
	void		setObject( DM_Object* pObject );
	DM_Object*	getObject() const;
	// Also common interface for stuff like events, serialize, etc
};
//-----------------------------------------------------------------------
class DM_ComPointLight : public DM_Com, public S_PointLight
{
public:
	// I hate this.
	void	setRadius( float val ) { markDirty( DirtyRadiusNetFlag ); S_PointLight::setRadius( val ); }
};

The S_PointLight comes from my render system (Simon). Simon doesn't know anything about the DM_ComPointLight. Only the DM system uses objects and components. I have clung onto this separation since I might want lights that don't have the extra weight of being a component. I am suffering from two problems. First, if the light radius changes, I need to notify some network clients about the change. The problem is that I tend to write wrapper stuff to do this and these wrappers are prone to error and just makes for more code to manage. Plus you have an unenforced policy to not change the values directly. It would be better if I could use metadata someplace that would define variables as replicate, serialize, etc. My system takes to long to add stuff now. The other problem is with my object schemas. My system is like Dungeon Siege in that it flattens out the inheritance tree. Now I build my world and run the game only to find out that my torches aren't bright enough or the particle system isn't configured right. If my system kept the inheritance tree intact and referenced it in a flyweight like manner, I could just change the schemas and reload. The problem is how do you do inheritance of components that don't use generic properties? My current system has schemas being defined with static fields and then flags determine which fields are valid.
class DM_ComPointLightSchema
{
private:
	u32        m_HasFlags;
	float      m_fRadius;
	S_Color4f  m_Color;
};

This is really ugly and doesn't save much memory. Gets worse with arrays and maps. So currently I have a schema for each component that is define in a lua file and then a I wrote a code generate that makes a schema class simular to above. I have thought about making the code generator make a DM_ComPointLightData class that manages all the access to the data but I it doesn't fix problems with data inheritance. I would still be stuck with schemas that have flags that show which fields are valid. The following will solve both problems but I am really afraid of the cost.
class DM_Value
{
	// basiclly a varriant
	// also has flags like READ_ONLY, INSTANCE, REPLICATE etc
	// can serialize itself.
};

class DM_Com
{
private:
	std::map< std::string, DM_Value >	m_mapVlues;	// hash or guid

protected:
	virtual void		setProperty( const std::string& id, const DM_Value& v );
	virtual const DM_Value	getProperty( const std::string& id ) const;
};

class DM_ComPointLight : public DM_Com
{
};

So now each com will be able to serialize itself without extra code and handle whether data needs to be sent to network clients and such. Also the data inheritance would be easier. I feel it will make the code less prone to error and easier to maitain but at what price? What are people doing for this stuff? I read the thread about an outboard system but there isn't much mention about these two problems.

Component tree specialization

22 May 2008 - 05:56 AM

So I am deep into writing my MUD that uses a component like system. Now I have seen a lot of talk about com systems and how they work but the feeding of these systems tend to be glossed over. I have reached a point where I have to make some big choices and I was wondering what people thought. So first I will share what I have learned so far, hopefully someone will get something out of it. My system uses an object that has a flattened bag of components. Components have a common interface but they don't have anything for generic/variant type access to properties. There can only be one of each type of com and the object provides the query interface pattern. Coms also can't be added after the object has its onConstruct() called. This allows coms to cache pointers. The data layout uses a specialization tree. The tree is flattened out by adding coms to the object if not yet added and then overriding values it defines. Below is an example.
SCHEMA =
{
	name  = 'WallTorchBase',
	coms  =
	{
		Model = 
		{
			vars =
			{	
				Name = 'WallTorch01',
			}
		},
		Frame = 
		{
			vars =
			{	
			}
		},	
	}
}
SCHEMA =
{
	name  = 'WallTorch',
	super  = 'WallTorchBase',
	coms  =
	{
		PointLight = 
		{
			vars =
			{
				Radius  = 20.0,
				Diffuse = { 1.0, 1.0, 1.0 },
			}
		},
	}
}
SCHEMA =
{
	name  = 'WallTorchFlame',
	super  = 'WallTorchBase',
	coms  =
	{
		PointLight = 
		{
			vars =
			{
				Diffuse = { 1.0, 0.5, 0.5 },
			}
		},
		ParticleSystem =
		{
			vars =
			{
				Texture    = 'FirePage1',
				SpriteSize = { 64, 64 },
				Sprites    = 2,

				Particles  = 300,
				EmitPerSec = 0.5,
			}
		}
	}
}

First I started out with a system that had generic properties. I had a variant like class called Sim_Value and a Sim_Property that had a name, doc and value. It really all looked nice and made me feel like I had engineered something really powerful. Once I got past a graphical tech demo into actual game play, they property system became something that I struggled with. Working with properties that don't have a one to one mapping can be a pain. For example, you would likely define a texture property using the name but the com likely holds a pointer to the texture. So then maybe you store both and now you have to manage the link between them. Sure you can manage it but the pain of it all... There are also problems when you want an array or map of properties. Most examples don't touch on this at all. If your system doesn't flatten the tree then maybe some of these issues wouldn't matter as much. In the end the generic properties didn't help me with anything other than editing my data off-line. I dumped it since I felt I was pleasing my tools and not the game. Also I can't help but think this system has already been written, it's called lua or python. Originally I was using xml for my data layout. I did my best to try and convince myself that xml was the next coming. I got sick of writing xml handlers. I also found xml to be very static and longed for some easier flow control. Maybe many of these problems stem from my lack of xml knowledge. I don't know. Since I was already using lua, I dumped xml for lua. This was a bonus since now I only have to manage lua code instead of lua and xml. Now my data is all in lua. If I want to do something with the tree then I can simply write a lua script to do it instead of trying to use xml transformation or writing more SAX handlers. As a side note, I dumped using makefiles to build data for the same problems. I ended up making a custom lua build tool that runs a lua script. So more to the issue. Since I am writing a MUD, I have client and server stuff. Now I didn't want the client to know anymore than I had to. So not all coms get sent to the client and some coms are not even compiled into the client. Initially I had a transformed xml tree of all my object schemas for the client. I would send it over and then I could create objects on the client by name with very little bandwidth. The problem is that since the tree is flattened, I need code to diff the current object with the objects schema. This is a major pain and isn't the fastest process. Also since the client knows the name of the schema, they now can use that to some advantage. If the schema is called 'sword -1', they will know not to use it. I also didn't like the client having a list of all the objects in the game. In the end the solution was not to do the diff and send over a custom object. The server sends over the flattened object without a schema name. Now I don't have to diff and the client doesn't know what the object is. After the initial spawn is sent, I just send dirty updates. So here is the issue. Now I still have code that does the diff for when the server saves the objects to the database, but this code makes me very very angry. It is the one dragon in my code that I really hate! Since the code makes me so angry, maybe I am not thinking clearly. I kept this around since I thought it could be a huge space savings. Also it allows me to change values on my schema and have all the other objects get the change. Thing is, does it really, should I care? If I change a value on the schema but the object has also changed it's version, which value do you use? Objects created wouldn't change until the game shutdown and reloaded all the objects. Really I could likely write a script to change all the objects off-line. Maybe trying these changes while the game is running isn't all that wise anyways. Does anyone have experience with this, am I managing all this really crappy code for now reason?

PARTNERS