Advertisement

Funny source code/documentation/comments?

Started by January 16, 2005 10:53 PM
75 comments, last by jonaakey 10 years, 5 months ago
This made its way into a terrain generating/heightmap renderer thing I wrote a month or two ago for a project. This crept in late at night after spending several days trying to debug the same function (and this is probably the cleanest part code-wise O_o). Even now, I'm still not sure what the hell I was even thinking when I wrote this.

if (x == right) goto gheyness; // testing for x == right in the next if statement fucks it up for some reason		if (y != bottom)		{			index[ii] = i;			index[ii+1] = i+1;			index[ii+2] = i+((right-left)/step)+1;			index[ii+3] = i+1;			index[ii+4] = i+((right-left)/step)+2;			index[ii+5] = i+((right-left)/step)+1;			ii += 6;		}gheyness:		j += step;                //etc.....
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
From the server data gathering code I wrote for CSports.Net
ProcessError(true,"", error);	//TODO: put sane error code here////////////////////////////////////////////////////////////////////////////	BattleField 1942 server parser//  Complete with dumb key_hash detection, coz you know it makes sense ;)//////////////////////////////////////////////////////////////////////////// we've got a pos <insert other swear words here> return, time to play fudge it :)// this is primaryly a hack for stupid UT2 servers... why oh why couldnt that have enforced a standard order ;(if(namestart == std::string::npos || score1start == std::string::npos || score2start == std::string::npos || score3start == std::string::npos || core4start == std::string::npos)	return;	// should never happen.if(nameend == std::string::npos)	break;	// regardless of which comes first we should ALWAYS find thiscatch (std::exception &e) {throw;	// something went wrong, probably an out-of-bounds exception}////////////////////////////////////////////////////////////////////////////	Super happy fun Quake3 parser////	Note: this is a mild cheat when compare with the old version. //	Once i'd looked at the Quake3 returns it became very quickly apprent//	that the getinfo request was basicaly, errm, useless for our needs//	as the only extra bit of data it returns is the clients connected and//	frankly, we can count that ourselves :)//	So instead, we are only using the getstatus command, which is half//	the network wait time, yey me!////	Also, I'll be using a cute stringstream trick to parse the data sanely.//	The basic plan is to throw the string into a stringstream, then read back//	a line at a time, as each section is \n delimited this should make things //	a lot easier.//	So the first line read is the \xff\xff\xff\xffstatusResponce line, the //	next will hold all of the \key\value pairs and then every line after that //	will hold the score and player details (<score> <ping> "name")//	bish bash bosh, how smooth is that ;)////	Note: pull server game port from data supplied for this game... errm.. somehow :E		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Null Delimited parser// Based on the data we found when looking at the BF:V returns // !!!!!IMPORTANT!!!!!// While this has been written to be generic there ISNT enuff details// On this format to make this true for the future as yet.// I'm HOPING that this is basicaly the ASE format so this can be reused// however i'm not counting on that// !!!!!IMPORTANT!!!!!// From the network setup code :throw std::exception();	// throw an exception, we'll put something sane here laterthrow std::exception();	// as before, throw back an exception as this shouldnt happenthrow std::exception();	// as abovereturn false;	// some other error, so run away!namespace Parsers{	// parser function defs go here}/**	hax0red microsecond clock*/


and from the old CSports system (or the bits I wrote at least) and some support programs
// cleaner for painkiller color coding (why cant every game use the same bloody codes)Sleep(0);	// sleep for a bit and around we go again :)Sleep(10);		// task switching friendly :)int id;	// if we need more than a short OMFG!//MessageBox("meep");


A reason not to try and be lazy:// Now we need to work out the per vertex normal// the correct way would be to store which vertex is used in which face// add the face normals together and devide by the number of faces// however, as i'm lazy i'm gonna cheat for the moment and instead// just workout the face normal and apply it to all the vertices for// that face.// the above didnt work :( Need to come up with a cunning fi><0r!Other stuff : // Mesh done.// huzza!// TODO : sweet custom dialog code :)// we have found the start of a strike thought, joy.


I seem to recall others around my code, something about being on crack when I wrote some code and not knowing why or how it worked, but i'll be buggered if i can find 'em [grin]


Advertisement
Almost all of my comments are just source that doesn't work but could still be important. I should really start commenting my code.
From my Linked-List template class.

///////////////////////////////////////////////////////////////////////////////////////////////// LIST::GetHead//// 10/12/2003 J.C.//// Makes a $2 hooker appear at your doorstep and return the head of the list to you =)/////////////////////////////////////////////////////////////////////////////////////////////////template<typename TYPE>DDNODE<TYPE>* LIST<TYPE>::GetHead(void) const{	return(lpHead);}///////////////////////////////////////////////////////////////////////////////////////////////// LIST::GetTail//// 10/12/2003 J.C.//// Gets some booty from that same hooker... and returns the tail of the list./////////////////////////////////////////////////////////////////////////////////////////////////template<typename TYPE>DDNODE<TYPE>* LIST<TYPE>::GetTail(void) const{	return(lpTail);}
Something I seem to periodicly put in my games

// Below are a bunch of variables used to hold various dataint x, y, z, time, speed;char name, o;
--------------------C++ Home - Check it out!Lol... - Amazing video
After replacing 'break' with 'continue' to fix an error:
continue;//break;	this "breaks" stuff, no pun intended... haha...






And a snippet of my partner's code:
// UPDATE: initial experiments show that is is basically un-noticeable to the user// Update of Update: This causes big problems, gotta fix it
Advertisement
Quote: Original post by Dmytry
node1->MakeChild(node2);// O la-la!


I once received an email from my boss because I had written.

//NOT SAFE FOR WORK
node1->MakeChild(node2);

He absolutely loved it.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
Do comments fall under any NDAs you had to sign to get the code? Because I have a real good quote but I'm not sure if I should post it.
ROFL. That's a good one.

At any rate, I've had some fun ones. Naming variable names funny things (only small-scope local, of course) is good, and other techniques.

I've also seen comments like "This is uglier than <insert coworker's name here> girlfriend" followed by a piece of code that's such a hack it makes me sick. Although it makes me laugh more than it makes me sick, so it's okay...
// Gordon: bleh, has no-one heard of switch statements...// Gordon: removing cuz, er, no-one knows why it's here!...// Gordon: looted corpses dont have any accsserories, evil looters :E// these are sent over the net as 8 bits (Gordon: upped to 9 bits, erm actually it was already at 9 bits, wtf? NEVAR TRUST GAMECODE COMMENTS, comments are evil :E, lets hope it doesnt horribly break anything....)


[Edited by - bani on February 11, 2005 9:41:23 PM]
[=^_^=]http://bani.anime.net/etpro/ - ETPro websitehttp://bani.anime.net/banimod/forums/ - ETPro discussion forums

This topic is closed to new replies.

Advertisement