Page 2 of 2

Posted: Fri Jul 04, 2008 12:59 pm
by JP
yes, yes, we all know you're a genius blindside ;)

Posted: Fri Jul 04, 2008 1:04 pm
by BlindSide
Ok I'm not gonna post anymore. :P

Posted: Tue Jul 08, 2008 9:02 pm
by }{ermanssoN
Well went with haveing an arry of players. each player has a scene node wich i added thesame mesh to, did samething with projectiles. and it worked fine.

Very nice examples and answers, thats the best thing with opensource, there are lots of users that share knowledge, It's nice :)

Posted: Tue Jul 08, 2008 9:53 pm
by sio2
dlangdev wrote:"I know Ogre has an instacing demo and Ogre like Irrlicht uses scene nodes and a scenemanager."

This is what he was talking about. Definitely GPU assisted instancing.

http://www.ogre3d.org/phpBB2/viewtopic.php?t=20193
Pah! They're not even animated! 8)

100 skinned meshes:
Image

Posted: Tue Jul 08, 2008 10:04 pm
by dlangdev
oh yeah!

don't expect me to believe ya right away...

gotta see the code as there's a dx demo of it in the dx sdk.

Posted: Wed Jul 09, 2008 11:54 am
by Saturn
sio2 wrote:
dlangdev wrote:"I know Ogre has an instacing demo and Ogre like Irrlicht uses scene nodes and a scenemanager."

This is what he was talking about. Definitely GPU assisted instancing.

http://www.ogre3d.org/phpBB2/viewtopic.php?t=20193
Pah! They're not even animated! 8)
The actual crowd demo is animated.

Posted: Sat Jul 19, 2008 1:49 pm
by }{ermanssoN
Well, having a lot of nodes seems to be heavy. I used boxnodes as bullets. I started to make an array of 25 boxesfor just one player.


Code: Select all

for( u8 i = 0; i< MAX_NUM_BOXPROJECTILES; i++ )
	{
		m_ppBoxProjectiles[ i ] = new SProjectile();
		m_ppBoxProjectiles[ i ]->Direction = vector3df( 0.0f, 0.0f, 0.0f );
		m_ppBoxProjectiles[ i ]->pMesh = NULL;
		m_ppBoxProjectiles[ i ]->pNode = pScene->addCubeSceneNode( 5.0f );
		m_ppBoxProjectiles[ i ]->Position = vector3df( 0.0f, 0.0f, 0.0f );
		m_ppBoxProjectiles[ i ]->Roration = Tmp;
		m_ppBoxProjectiles[ i ]->Speed = 300.0f;
		m_ppBoxProjectiles[ i ]->TimeToImpact = 0.0f;

		m_ppBoxProjectiles[ i ]->pNode->setVisible( false );
		
	}
This works perfectly, If you only have one player, or even two.
But i figured that the maximum amount of players should be 16, and every player shouls have 25 projectiles, so theoreticly we could hav as much as 400 projectiles in the air.
But initializing 400 boxes was not an good idea. The program won't even start. I managed to create up to 250. but more just makes the program crash. And a CubeSceneNode must be much "simpler" than an IAnimatedMeshSceneNode.

One thiing is strange, 25 nodes or 250 nodes make no difference on the fps. Is there a maximum number of nodes that a scenemanager can handle??

Posted: Sat Jul 19, 2008 5:02 pm
by rogerborg
}{ermanssoN wrote:But initializing 400 boxes was not an good idea. The program won't even start. I managed to create up to 250. but more just makes the program crash.
There is no hard limit, and a crash generally indicates user error. If you post a test case that reproduces the behaviour, I'm sure that we can find the problem.

Posted: Sat Jul 19, 2008 6:09 pm
by }{ermanssoN
there is no error message, windows just complains that the application don't respond and i end it with the taskmanager.

MAX_NUM_BOXPROJECTILES is set to 25, it starts and exits with out problem.

if BOXPROJECTILES is sett to high, around 300 it's forces a crash.

but i'l post the whole class:

Code: Select all

#ifndef _PROJECTILEMANAGER_CPP
#define _PROJECTILEMANAGER_CPP

#include "globals.h"

ProjectileManager::ProjectileManager( void )
{
	m_ppBoxProjectiles		= NULL;
	m_NumFired				= 0;
}
ProjectileManager::~ProjectileManager( void )
{
	
}

bool
ProjectileManager::InitializeManager( void )
{
	ISceneManager* pScene = g_pApp->GetSceneManager();
	
	m_ppBoxProjectiles = new SProjectile*[ MAX_NUM_BOXPROJECTILES ];
	
	memset( m_ppBoxProjectiles, 0, sizeof(SProjectile**) * MAX_NUM_BOXPROJECTILES );
		
		
	SRotation Tmp;
	Tmp.X = 0.0f;
	Tmp.Y = 0.0f;
	Tmp.Y = 0.0f;

	for( u8 i = 0; i< MAX_NUM_BOXPROJECTILES; i++ )
	{
		m_ppBoxProjectiles[ i ] = new SProjectile();
		m_ppBoxProjectiles[ i ]->Direction = vector3df( 0.0f, 0.0f, 0.0f );
		m_ppBoxProjectiles[ i ]->pMesh = NULL;
		m_ppBoxProjectiles[ i ]->pNode = pScene->addCubeSceneNode( 5.0f );
		m_ppBoxProjectiles[ i ]->Position = vector3df( 0.0f, 0.0f, 0.0f );
		m_ppBoxProjectiles[ i ]->Roration = Tmp;
		m_ppBoxProjectiles[ i ]->Speed = 300.0f;
		m_ppBoxProjectiles[ i ]->TimeToImpact = 0.0f;

		m_ppBoxProjectiles[ i ]->pNode->setVisible( false );
		
	}
	
	SWorld* pWorld = g_pApp->GetWorldManager()->GetActiveWorld();
	m_pTringleSelector = pScene->createOctTreeTriangleSelector( pWorld->pWorldMesh->getMesh( 0 ), pWorld->pWorldNode, 128 );
	return true;
}


bool
ProjectileManager::DestroyManager( void )
{
	if( m_ppBoxProjectiles )
	{
		for( u8 i = 0; i< MAX_NUM_BOXPROJECTILES; i++ )
		{
			if( m_ppBoxProjectiles [ i ] && m_ppBoxProjectiles [ i ]->pNode )
				m_ppBoxProjectiles[ i ]->pNode->remove();
		}
		delete [] m_ppBoxProjectiles;
	}

		return true;
}
void
ProjectileManager::FireProjectile(irr::core::vector3df Direction, irr::core::vector3df StartPosition)
{
		for( u8 i = 0; i< MAX_NUM_BOXPROJECTILES; i++ )
		{
			SProjectile* pProjectile = m_ppBoxProjectiles[ i ];

			if( pProjectile && !pProjectile->pNode->isVisible() )
			{
				MathManager* pMath = g_pApp->GetMathManager();
				ISceneCollisionManager* pCollision = g_pApp->GetSceneManager()->getSceneCollisionManager();
				vector3df TravelVec,Intersection;
				triangle3df Trinagle;

				if( pCollision->getCollisionPoint( pMath->GetLineOfFire( StartPosition, Direction, 2000.0f ), m_pTringleSelector, Intersection, Trinagle ))
					TravelVec = Intersection - StartPosition;
				pProjectile->Direction = Direction;
				pProjectile->Position = StartPosition;
				pProjectile->pNode->setVisible( true );
				pProjectile->TimeToImpact = pMath->CalculateTimeToIntersection( TravelVec.getLength(), pProjectile->Speed );
				pProjectile->pNode->setPosition( StartPosition );
				pProjectile->pNode->updateAbsolutePosition();
				m_NumFired ++;
				g_pApp->GetIrrDevice()->getLogger()->log( "Projectile fired\n" );
				return;
			}
				
		}
}
void
ProjectileManager::Update( void )
{
	f32 DeltaTime = g_pApp->GetTimeManager()->GetDeltaTime();
	for( u8 i = 0; i< MAX_NUM_BOXPROJECTILES; i++ )
	{
		SProjectile* pProjectile = m_ppBoxProjectiles[ i ];

		if( pProjectile && pProjectile->pNode->isVisible() )
		{
			if(	pProjectile->TimeToImpact > 0.0f )
			{
				pProjectile->Position += pProjectile->Direction * ( DeltaTime * pProjectile->Speed );
				pProjectile->pNode->setPosition( pProjectile->Position );
				pProjectile->pNode->updateAbsolutePosition();
				pProjectile->TimeToImpact -= DeltaTime;
			}
			else
			{
				g_pApp->GetIrrDevice()->getLogger()->log( "Prijectile hit\n" );
				pProjectile->pNode->setVisible( false );
				pProjectile->TimeToImpact = 0.0f;
			}
		}

	}
}
SProjectile*
ProjectileManager::GetProjectile( u8 Index )
{
	if( m_ppBoxProjectiles[ Index ] && Index <= MAX_NUM_BOXPROJECTILES )
		return m_ppBoxProjectiles[ Index ];	
	else 
		return NULL;
}
vector3df
ProjectileManager::GetProjectilePosition( u8 Index )
{
	if( m_ppBoxProjectiles[ Index ] && Index <= MAX_NUM_BOXPROJECTILES )
		return m_ppBoxProjectiles[ Index ]->Position;	
	else 
		return vector3df( 0.0f, 0.0f, 0.0f );
}
#endif //_PROJECTILEMANAGER_CPP

Posted: Sat Jul 19, 2008 9:17 pm
by rogerborg

Code: Select all

for( u8 i = 0; i< MAX_NUM_BOXPROJECTILES; i++ )
Image

Sew-crates has a method he'd like me to try out.

What's the maximum value that a u8 can hold?

What happens when you increment a u8 that's already at its maximum value?

Sew-creates thinks that it's important to identify the problem before coming up with a solution.

Posted: Sun Jul 20, 2008 12:40 am
by BlindSide
You should know that on a 32-bit system using a u8 is infact a tiny bit slower than a u32. :D

(So basically, I have no idea why the hell you did that.)

Posted: Sun Jul 20, 2008 11:58 am
by }{ermanssoN
ok foregting to switch the u8 to u32 is kind of embaressing :S

But no I did not know that a u32 is faster than u8.

Why is it?? 32 is bigger than 8??

Posted: Mon Jul 21, 2008 9:50 am
by rogerborg
A 32 bit CPU has 32 bit registers.

Moving a 32 bit value to or from a 32 bit register is generally a faster operation than moving an 8 bit value to or from a 32 bit register, as doing so requires padding or truncating it.