Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


TheComet

Member Since 02 Oct 2013
Online Last Active Today, 07:33 AM

#5211085 What are the recommended places to store save data?

Posted by TheComet on 16 February 2015 - 06:21 PM


Call me old-school but whatever happened to storing system configuration in /etc?

/etc is for system configurations, user application configurations go into /usr/local/share or /usr/share if they are not to be touched by the user.




#5211060 What are the recommended places to store save data?

Posted by TheComet on 16 February 2015 - 04:06 PM

On Windows machines it's best to place savefiles in %appdata%. Depending on the situation you can also place them directly in the home folder for them to be more accessible to the end user.

 

On Linux there are a few locations, most applications put user created content in ~/.local/share/<app_name>/ and user configuration files in ~/.config/<app_name>/. System configurations (things the user shouldn't touch) are usually placed in /usr/local/share/<app_name>/. Again, depending on the situation, you may also want to place user files directly in the home folder ~/.

 

I am not sure what mac does.




#5207578 Some programmers actually hate OOP languages? WHAT?!

Posted by TheComet on 29 January 2015 - 06:48 PM


Still... what might "well-coded" games in C look like? Or would it be quite close to a game in C++ but mostly just without the encapsulation given by things like access modifiers, and semi-advanced concepts like templates?

Being someone who is currently coding a game in C for the lulz, I think I can answer this.

 

The structure of code is quite different than what I'd do in C++, but the same basic concepts apply. For instance, a lot of systems have system_init() and system_deinit() functions instead of constructors/destructors. There are no classes with methods, but there are structs for holding data and functions which act upon the data of these structs. Templates don't exist, but you can implement the majority of what templates are used for with macros. Compositing can be done with structs.

 

Polymorphism doesn't exist per se. I've seen my fair share of home made polymorphism in C, but I believe it's not really necessary. Most of the time you can composite. 




#5207543 Programming

Posted by TheComet on 29 January 2015 - 04:20 PM

Spiro speaks the truth.

 

I started a project as a somewhat average programmer with some artists, but I chose a game that was so far out of my league we had to can the entire thing after a few months. I disappointed everyone on the team.

 

One of the team members wrote me a really long and hurtful message. Spraying salt on my skinned body would have been less painful than some of the things he said, but it was the truth. He felt extremely passionate about what we were creating, and he blamed me for being an incompetent idiot for throwing the entire thing away and wasting everyone's time.

 

Trust me, you do not want to go through that pain. I learned my lesson the hard way.




#5195162 Best comment ever

Posted by TheComet on 28 November 2014 - 06:43 AM

These are hilarious. During my undergrad I was working on a partner project and found this in a 20 line .c file:

;;;;;  ;;;;;;  ;;      ;; ;;             ;;;;;;;  ;;;;;;;  ;;       ;;;;;;;  ;;   ;;  ;;;;; 
;;     ;;      ;;;;  ;;;;                ;;       ;;   ;;  ;;       ;;   ;;  ;;;  ;;  ;;   
;;;;;  ;;;;;;  ;;  ;;  ;; ;;   ;;;;;;    ;;       ;;   ;;  ;;       ;;   ;;  ;; ; ;;  ;;;;;
   ;;  ;;      ;;      ;; ;;             ;;       ;;   ;;  ;;       ;;   ;;  ;;  ;;;     ;;
;;;;;  ;;;;;;  ;;      ;; ;;             ;;;;;;;  ;;;;;;;  ;;;;;;;  ;;;;;;;  ;;   ;;  ;;;;;

Which much to my surprise compiles just fine.

(;) is a null statement and usually compiles to nothing at all.

 

A compiler I was working with for programming MSP430 microcontrollers would interpret a null statement as an actual NOP instruction. If I had pasted that thing into our code a lot of people would have been mad.




#5191644 Problem with A*

Posted by TheComet on 07 November 2014 - 05:43 AM

for(unsigned int i=0; i < openList.size(); i++)

It's never a good idea to iterate a container AND modify it at the same time. Elements can become invalid.

 

According to the Wikipedia article, you should loop while the openList is not empty:

while(openList.size())  // instead of while(!foundFinish)
{
    // pathfinding stuff here
}

I also don't see you ever remove anything from the openList. You've commented that part of your code out:

//openList.erase(openList.begin());



#5191212 Thread-post never made ... almost

Posted by TheComet on 04 November 2014 - 04:28 PM

Well excuse me princess, I'm sorry for helping you.




#5191180 Thread-post never made ... almost

Posted by TheComet on 04 November 2014 - 02:32 PM

Either do:

void skipX(char const* const& at)

or

void skipX(char*& at)

depending on whether at should be const or not.

 

However, I advise you not to take a reference to a pointer because that's one extra memory read you'll be doing (i.e. it's slower). It's always faster to copy primitive types than reference them.

void skipX(char* at)



#5188619 O(pow(N,12))

Posted by TheComet on 22 October 2014 - 04:01 PM

#include "main.h"
#include "renderSystem.h"
#include "largeAsteroid.h"

// To future Karl, or anybody who may have the joy of upkeeping this code.
// I am truly sorry.
#define ASTEROID_SIZE 50

AsteroidVoxel::AsteroidVoxel() :
	mExist( false )
{
}

AsteroidVoxelVertex::AsteroidVoxelVertex()
{
	mExist = true;
}

void AsteroidVoxelVertex::setVertex( u32 vertex )
{
	mVertex = vertex;
}

AsteroidVoxelVertex::~AsteroidVoxelVertex()
{
}

AsteroidData::AsteroidData()
{

	//This part is a pain, but initialize the mVoxelData array
	for( s32 x = 0; x < ASTEROID_SIZE; x++ )
	{
		for( s32 y = 0; y < ASTEROID_SIZE; y++ )
		{
			for( s32 z = 0; z < ASTEROID_SIZE; z++ )
			{
				mVoxelData[x][y][z].mExist = false;
			}
		}
	}

}

AsteroidData::~AsteroidData()
{

}

void AsteroidData::genTestShape()
{
	for( s32 x = 2; x < ASTEROID_SIZE - 2 ; x++ )
		for( s32 y = 2; y < ASTEROID_SIZE - 2; y++ )
			for( s32 z = 2; z < ASTEROID_SIZE - 2; z++ )
				mVoxelData[x][y][z].mExist = true;
}

void AsteroidData::generateBaseShape()
{
	// Set up random number generator.
	mt19937 generator;
	generator.seed( gRenderSystem->getOgreRoot()->getTimer()->getMilliseconds() * rand() % 100000 );

	Vec3 center( ASTEROID_SIZE / 2.0f , ASTEROID_SIZE / 2.0f, ASTEROID_SIZE / 2.0f );
	for( s32 x = 0; x < ASTEROID_SIZE; x++ )
		for( s32 y = 0; y < ASTEROID_SIZE; y++ )
			for( s32 z = 0; z < ASTEROID_SIZE; z++ )
				if( ( Vec3( x, y, z ) - center ).LengthSq() < ( ( ASTEROID_SIZE / 2.0f ) * ( ASTEROID_SIZE / 2.0f ) ) )
					mVoxelData[x][y][z].mExist = true;

	//Add craters.
	uniform_int_distribution<s32> craterImpacts( 2, 10 );
	uniform_real_distribution<f32> craterPosition( 0.0f, ASTEROID_SIZE );
	uniform_real_distribution<f32> craterRadius( ASTEROID_SIZE / 8.0f, ASTEROID_SIZE / 4.0f );

	u32 noCraterImpacts = craterImpacts( generator );

	for( u32 i = 0; i < noCraterImpacts; ++i )
	{
		Vec3 origin( craterPosition( generator ), craterPosition( generator ), craterPosition( generator ) );
		f32 lCraterRadius = craterRadius( generator );

		for( u32 x = 0; x < ASTEROID_SIZE; x++ )
			for( u32 y = 0; y < ASTEROID_SIZE; y++ )
				for( u32 z = 0; z < ASTEROID_SIZE; z++ )
					if( ( Vec3( x, y, z ) - origin ).LengthSq() < lCraterRadius * lCraterRadius ) {}
		//mVoxelData[x][y][z].mExist = false;
	}

}

void AsteroidData::generateIndexVertexBuffers()
{
	// Eliminate non-visible voxels
	// Check each of the 6 sides.
	vector<AsteroidVoxelVertex*> mVisibleVoxels;
	AsteroidVoxelVertex* mVisVoxelStructure[ASTEROID_SIZE][ASTEROID_SIZE][ASTEROID_SIZE];

	u32 vertexCount = 0;

	for( s32 x = 0; x < ASTEROID_SIZE; x++ )
	{
		for( s32 y = 0; y < ASTEROID_SIZE; y++ )
		{
			for( s32 z = 0; z < ASTEROID_SIZE; z++ )
			{

				bool canBeSeen = 0;

				if( x == 0 || x == ASTEROID_SIZE - 1 || y == 0 || y == ASTEROID_SIZE - 1 || z == 0 || z == ASTEROID_SIZE - 1 )
					if( mVoxelData[x][y][z].mExist == true )
						canBeSeen = true;

				if( x > 0 )
					if( mVoxelData[x - 1][y][z].mExist == false )
						canBeSeen = true;

				if( y > 0 )
					if( mVoxelData[x][y - 1][z].mExist == false )
						canBeSeen = true;

				if( z > 0 )
					if( mVoxelData[x][y][z - 1].mExist == false )
						canBeSeen = true;

				if( x < ASTEROID_SIZE - 1 )
					if( mVoxelData[x + 1][y][z].mExist == false )
						canBeSeen = true;

				if( y < ASTEROID_SIZE - 1 )
					if( mVoxelData[x][y + 1][z].mExist == false )
						canBeSeen = true;

				if( z < ASTEROID_SIZE - 1 )
					if( mVoxelData[x][y][z + 1].mExist == false )
						canBeSeen = true;

				if( canBeSeen )
				{
					if( mVoxelData[x][y][z].mExist == true )
					{
						// Set vertex
						AsteroidVoxelVertex* vertex = new AsteroidVoxelVertex;
						vertex->setVertex( vertexCount );

						//Add to data structures
						mVisibleVoxels.push_back( vertex );
						mVisVoxelStructure[x][y][z] = vertex;

						// Add to vertex list
						mVertex.push_back( f32( x ) * 100.0 );
						mVertex.push_back( f32( y ) * 100.0 );
						mVertex.push_back( f32( z ) * 100.0 );

						vertexCount++;
					}
					else
					{
						AsteroidVoxelVertex* vertex = new AsteroidVoxelVertex;
						vertex->mExist = false;

						mVisibleVoxels.push_back( vertex );
						mVisVoxelStructure[x][y][z] = vertex;
					}
				}
				else
				{
					AsteroidVoxelVertex* vertex = new AsteroidVoxelVertex;
					vertex->mExist = false;

					mVisibleVoxels.push_back( vertex );
					mVisVoxelStructure[x][y][z] = vertex;
				}
			}
		}
	}

	// Use brute force against the VoxelCloud to generate index.

	for( u32 x = 0; x < ASTEROID_SIZE - 1; x ++ )
	{
		for( u32 y = 0; y < ASTEROID_SIZE - 1; y++ )
		{
			for( u32 z = 0; z < ASTEROID_SIZE - 1; z++ )
			{
				for( u32 basex = x; basex <= x + 1; basex++ )
					for( u32 basey = y; basey <= y + 1; basey++ )
						for( u32 basez = z; basez <= z + 1; basez++ )
							// Find all triangles
							// Find second vertex, then find the next vertex using the second vertex as a starting point
							for( u32 ox = 0; ox <= 1; ox++ )
							{
								for( u32 oy = 0; oy <= 1; oy++ )
								{
									for( u32 oz = 0; oz <= 1; oz++ )
									{
										for( s32 ox1 = -1; ox1 <= 1; ox1++ )
										{
											for( s32 oy1 = - 1; oy1 <= 1; oy1++ )
											{
												for( s32 oz1 = - 1; oz1 <= 1; oz1++ )
												{
													if( basex + ox1 + ox >= x )
														if( basex + ox1 + ox <= x + 1 )
															if( basey + oy1 + oy >= y )
																if( basey + oy1 + oy <= y + 1 )
																	if( basez + oz1 + oz >= z )
																		if( basez + oz1 + oz <= z + 1 )
																			if( basex + ox1 + ox <= x + 1 )
																				if( basey + oy1 + oy <= y + 1 )
																					if( basez + oz + oz1 <= z + 1 )
																						if( basex + ox <= x + 1 )
																							if( basey + oy <= y + 1 )
																								if( basez + oz <= z + 1 )
																									if( mVisVoxelStructure[basex][basey][basez]->mExist == true )
																										if( mVisVoxelStructure[basex + ox][basey + oy][basez + oz]->mExist == true )
																											if( mVisVoxelStructure[basex + ox + ox1][basey + oy + oy1][basez + oz + oz1]->mExist == true )
																												if( mVisVoxelStructure[basex][basey][basez]->mVertex != mVisVoxelStructure[basex + ox][basey + oy][basez + oz]->mVertex )
																													if( mVisVoxelStructure[basex][basey][basez]->mVertex != mVisVoxelStructure[basex + ox][basey + oy][basez + oz]->mVertex )
																														if( mVisVoxelStructure[basex + ox][basey + oy][basez + oz]->mVertex != mVisVoxelStructure[basex + ox + ox1][basey + oy + oy1][basez + oz + oz1]->mVertex )
																														{
																															mIndex.push_back( mVisVoxelStructure[basex + ox + ox1][basey + oy + oy1][basez + oz + oz1]->mVertex );
																															mIndex.push_back( mVisVoxelStructure[basex + ox][basey + oy][basez + oz]->mVertex );
																															mIndex.push_back( mVisVoxelStructure[basex][basey][basez]->mVertex );

																															mIndex.push_back( mVisVoxelStructure[basex + ox + ox1][basey + oy + oy1][basez + oz + oz1]->mVertex );
																															mIndex.push_back( mVisVoxelStructure[basex][basey][basez]->mVertex );
																															mIndex.push_back( mVisVoxelStructure[basex + ox][basey + oy][basez + oz]->mVertex );

																														}

												}
											}
										}
									}
								}
							}

			}
		}
	}

	//Clear up after myself.
	for( auto i = mVisibleVoxels.begin(); i != mVisibleVoxels.end(); ++i )
	{
		delete(*i);
	}

	mVisibleVoxels.empty();

}


////////////////////////////////////////////////////
// Divide between AsteroidData and LargeAsteroid //
////////////////////////////////////////////////////


LargeAsteroid::LargeAsteroid() :
	mMeshData( nullptr ),
	mSceneNode( nullptr )
{

	mMeshData = new AsteroidData;

	mMeshData->generateBaseShape();
	mMeshData->generateIndexVertexBuffers();

	// set up mesh, vertex decl, entity and scene node.
	mMesh = Ogre::MeshManager::getSingleton().createManual( generateName(), "General" );
	mSubMesh = mMesh->createSubMesh();

	mMesh->sharedVertexData = new Ogre::VertexData;
	mMesh->sharedVertexData->vertexCount = mMeshData->mVertex.size();

	mDecl = mMesh->sharedVertexData->vertexDeclaration;

	size_t offset = 0;
	mDecl->addElement( 0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION );
	offset += Ogre::VertexElement::getTypeSize( Ogre::VET_FLOAT3 );

	mVBuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( offset, mMeshData->mVertex.size(), Ogre::HardwareBuffer::HBU_DYNAMIC, false );
	mIBuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer( Ogre::HardwareIndexBuffer::IT_32BIT, mMeshData->mIndex.size(), Ogre::HardwareBuffer::HBU_DYNAMIC );

	mMesh->sharedVertexData->vertexBufferBinding->setBinding( 0, mVBuf );
	mSubMesh->indexData->indexBuffer = mIBuf;
	mSubMesh->indexData->indexCount = mMeshData->mIndex.size();
	mSubMesh->indexData->indexStart = 0;

	//lock buffers
	f32* vertices = static_cast<f32*>( mVBuf->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );

	u32 vx = 0;

	for( auto i = mMeshData->mVertex.begin(); i != mMeshData->mVertex.end(); ++i )
	{
		vertices[vx] = (*i);
		vx++;
	}

	u32* indices = static_cast<u32*>( mIBuf->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );

	vx = 0;
	for( auto i = mMeshData->mIndex.begin(); i != mMeshData->mIndex.end(); ++i )
	{
		indices[vx] = (*i);
		vx++;
	}

	//unlock buffers
	mVBuf->unlock();
	mIBuf->unlock();


	mMesh->_setBounds( Ogre::AxisAlignedBox( 0, 0, 0, ASTEROID_SIZE * 100.0f, ASTEROID_SIZE * 100.0f, ASTEROID_SIZE * 100.0f ) );
	mMesh->load();

	mEntity = gRenderSystem->getSceneMgr()->createEntity( generateName(), mMesh );
	mSceneNode = gRenderSystem->getRootSceneNode()->createChildSceneNode();
	mSceneNode->attachObject( mEntity );

	gRenderSystem->getSceneMgr()->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5f ) );

}

LargeAsteroid::~LargeAsteroid()
{
	gRenderSystem->getSceneMgr()->destroyEntity( mEntity );
	gRenderSystem->getSceneMgr()->destroySceneNode( mSceneNode );

	mMesh.setNull();
	mVBuf.setNull();
	mIBuf.setNull();

	//Free up memory.
	delete mMeshData;


}



#5185556 Funniest line of code ever ?

Posted by TheComet on 07 October 2014 - 09:55 AM

Somewhere in a text editor application I saw this line:

const char* CARROT = "^";



#5184002 Threading question

Posted by TheComet on 30 September 2014 - 01:59 AM

I'm trying to learn more about multithreading and am a little confused.

 

Currently, I'm using Ogre3D and I'm processing my game entities asynchronously. This means each entity is writing to Ogre::SceneNode asynchronously whenever its position changes:

void processMyGameEntity(Entity& e)
{
    Vector3 newPosition = doFancyMovementCode(e);
    e.sceneNode->setPosition(newPosition);
}

// ... elsewhere
void Game::updateGame()
{
    for(auto& entity : m_EntityList)
        this->threadPool.push(processMyGameEntity(entity));
}

I know Ogre3D is using boost.thread in the background for rendering, so it is asynchronously reading from scene nodes, but I'm not synchronising when writing to the scenenodes. Why is this working fine? Is it safe for me to continue doing this?

 

Another question I have: The thread pool I'm using uses std::thread, but Ogre3D is using boost::thread. How do I synchronise objects being shared between the two?




#5179641 And this is why you don't change names to lowercase

Posted by TheComet on 11 September 2014 - 12:10 PM

http://www.penisland.net/




#5172273 Funniest line of code ever ?

Posted by TheComet on 08 August 2014 - 08:15 AM

At work I came across lots of peculiar if-statements that always followed this pattern:

if(statement)
{
    foo();
}else if(!statement)
{
    bar();
}else
{
    fatal_error();
}

They all seemed to originate from a single developer, and apparently he has trust issues with the compiler/hardware.




#5166419 Amusing glitch gallery

Posted by TheComet on 12 July 2014 - 09:22 AM

 

tumblr_n8l3gicoIs1qdlh1io1_400.gif


This isn't normal?

 

This is actual footage of Brazil playing against Germany




#5166364 Amusing glitch gallery

Posted by TheComet on 12 July 2014 - 03:23 AM

tumblr_n8l3gicoIs1qdlh1io1_400.gif






PARTNERS