pouët.net

Random line of code thread

category: code [glöplog]
Code: // 2005 IA topology void IA_init() { CreateWispsLikeItIs(); InitBots(); } void IA_Play() { DoWispsTravelAndParseAllThe3DWorld(); for each bot { if (bots encounter wisp) ChangeStateOfMindAndShortMemory(of the bot); DoIAWithStuffs(bot); } } void IA_Free() { Thank(wisps); }
added on the 2016-12-10 07:40:57 by Barti Barti
Very simple mistake that made me loose my sleep and now I am too lazy to finish my Ludum Dare entry (I haven't even started as planned and not sure if I want to go for the Jam)

Code: if (hasHitWall(r)); { // do stuff }
added on the 2016-12-11 15:12:07 by Optimus Optimus
Optimus: That´s why i zoom the Text-Editor a lot when coding...lets me see such typos directly. If your Editor doesn´t support zooming just use a bigger font! ;)
any decent compiler should warn you about such constructs...
added on the 2016-12-11 20:59:16 by T$ T$
Maybe I didn't see the warning.
added on the 2016-12-11 21:02:08 by Optimus Optimus
Generally a problem amongst coders! Most just never look at warnings at all...while they should be handled like Errors in many cases.
It´s really a bad habit every coder that wants to be a good coder should get rid of asap!
Warning as errors is the way to go!
added on the 2016-12-11 23:53:05 by pantaloon pantaloon
Code:crc32 eax, dword [ebx]
added on the 2016-12-22 10:46:20 by Blueberry Blueberry
Code:if flashy: did dumb stuff then: do stuff
added on the 2016-12-22 10:48:35 by Flashira Flashira
Rudi, did you miss a struct for low and high?

Code: union Flags { WORD EFLAGS; BYTE low; BYTE high; struct flagbits bits; };
added on the 2016-12-22 20:01:05 by EvilOne EvilOne
Code: str[strlen(str)] = 0;

In a commercial project with millions of users.
added on the 2016-12-22 20:38:43 by 0xF 0xF
0xF: seems like a smart hack to ensure the string always ends with a 0, which is actually useful to avoid buffer memory leaks and such C foley. not sure if there are any misuse consequences though?!
added on the 2016-12-23 15:04:53 by psenough psenough
although strings should end with \0 not 0 itself... hmm.. fuck me if i'll ever know any proper c trickery.
added on the 2016-12-23 15:08:22 by psenough psenough
//code of random line
DrawLine(Random2D(), Random2D());

//TODO: add Threading
psenough: strlen counts the characters up to the first \0 (which is equal to 0)... i.e. this is just a (very expensive) NOP
Perhaps it's a fix for a race condition in case another thread overwrites the 0 with garbage inbetween the strlen() and the write. :P
added on the 2016-12-23 16:39:33 by kb_ kb_
More likely written by someone who switches between programming languages a lot.
added on the 2016-12-23 19:15:15 by tomaes tomaes
Quote:
0xF: seems like a smart hack to ensure the string always ends with a 0, which is actually useful to avoid buffer memory leaks and such C foley. not sure if there are any misuse consequences though?!

If the string hasnt a 0 it will write a 0 somewhere else in memory.
If the string already has 0 it an expensive shitload of nop.
Thats clearly retarted.
added on the 2016-12-25 03:21:48 by stfsux stfsux
It just zeroes twice to make the string extra secure!
added on the 2016-12-25 23:32:33 by T$ T$
Code:#define ES 0 #define IN_RIGHT 1 #define IN_DOWN 2 //down square is y+1 #define IN_LEFT 3 #define IN_UP 4 //up square is y-1 #define OUT_RIGHT 5 #define OUT_DOWN 6 #define OUT_LEFT 7 #define OUT_UP 8 char ClockwiseRotationImages[9]={0,IN_DOWN,IN_LEFT,IN_UP,IN_RIGHT,OUT_DOWN,OUT_LEFT,OUT_UP,OUT_RIGHT};
added on the 2017-01-01 11:16:23 by baah baah
When writing a math lib at night, always working with transposed matrices, and don't get the matrix inverse correct.

Code: // Shit cheat, just reverse the transformations. Matrix Matrix::Reverse() const { Matrix matrix; // Inverse determinant of rotation part. float f = 1.0f / (M11 * (M22 * M33 - M32 * M23) - M21 * (M12 * M33 - M32 * M13) + M31 * (M12 * M23 - M22 * M13)); // Rotation. matrix.M11 = f * (M22 * M33 - M32 * M23); matrix.M12 = -f * (M12 * M33 - M32 * M13); matrix.M13 = f * (M12 * M23 - M22 * M13); matrix.M21 = -f * (M21 * M33 - M31 * M23); matrix.M22 = f * (M11 * M33 - M31 * M13); matrix.M23 = -f * (M11 * M23 - M21 * M13); matrix.M31 = f * (M21 * M32 - M31 * M22); matrix.M32 = -f * (M11 * M32 - M31 * M12); matrix.M33 = f * (M11 * M22 - M21 * M12); // Translation. matrix.M14 = -(M14 * matrix.M11 + M24 * matrix.M12 + M34 * matrix.M13); matrix.M24 = -(M14 * matrix.M21 + M24 * matrix.M22 + M34 * matrix.M23); matrix.M34 = -(M14 * matrix.M31 + M24 * matrix.M32 + M34 * matrix.M33); // Last row. matrix.M41 = 0.0f; matrix.M42 = 0.0f; matrix.M43 = 0.0f; matrix.M44 = 1.0f; return matrix; }
added on the 2017-01-14 06:45:03 by EvilOne EvilOne
Code:for (;;) { //random stuff to do }
added on the 2017-01-17 16:01:18 by TBit TBit
Code: /// AAAAAAAAAA JAVA if (afd == null) { // (ノಥДಥ)ノ︵┻━┻・/ return; }

BB Image
added on the 2017-01-26 11:46:13 by kusma kusma
Is this a great way to greet?
Code:main (void){ definer greetingslist { greetz_goes_to: chrysalis conspiracy exceed pathos mfx+kewlers logicoma matt_current alcatraz nuance trsi umlaut_design you }};
added on the 2017-01-26 12:38:48 by Flashira Flashira
^ in what language does this work?
added on the 2017-01-26 13:23:32 by tomaes tomaes

login