Author Topic: Horrifying lines of code  (Read 16895 times)

0 Members and 1 Guest are viewing this topic.

Offline Mika

  • 28
Re: Horrifying lines of code
Code: [Select]
char*M,A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf(M="%d",&C);--E;J[E]=T[E]=E)printf("._");for(;(A-=Z=!Z)||(printf("\n|"),A=39,C--);Z||printf(M))M[Z]=Z[A-(E=A
[J-Z])&&!C&A==T[A]|6<<27<rand()||!C&!Z?J[T[E]=T[A]]=E,J[T[A]=A-Z]=A,"_.":" |"];}

This is probably the best I have seen for a while. It is a winning entry to Obfuscated C Code competition in 1985. It is still short enough to look like it could be understood, but confusing enough that you really don't want to try.

The whole thing is explained here:
http://homepages.cwi.nl/~tromp/maze.html

It's amazing what you can come up with when searching how to do object oriented kind of stuff with ANSI C. Object Oriented programming in ANSI C doesn't seem that difficult yet, I'm actually surprised how easily it can be done.
Relaxed movement is always more effective than forced movement.

 

Offline Echelon9

  • 210
Re: Horrifying lines of code
After horsing around in the ATL and MFC headers trying to track down a compile error, I'd like to nominate the ATL/MFC macros.  :eek:
I'd say some of the ATL developers inside Microsoft also feel that way, as they managed to get confused within the ATL library.

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: Horrifying lines of code
After horsing around in the ATL and MFC headers trying to track down a compile error, I'd like to nominate the ATL/MFC macros.  :eek:
I'd say some of the ATL developers inside Microsoft also feel that way, as they managed to get confused within the ATL library.

That was the funniest article I've read in a while. :lol:

 
Re: Horrifying lines of code
I'd like to nominate memset(this, 0, sizeof(ade_table_entry)); for provoking the following comment from WMCoolmon:

Code: [Select]
//std::vector<ade_table_entry> Subentries;
//std::vector<uint> Subentries;
//WMC - I have HAD it with these motherfriendly vectors
//on this motherfriendly class.
STRONGTEA. Why can't the x86 be sane?

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: Horrifying lines of code
I just discovered that in C# I can do this and it can be something that isn't bad:

Code: [Select]
public object this[int i]
{
    get
    {
        return something[i];
    }
    set
    {
        something[i] = value;
    }
}

and then:

Code: [Select]
this[i] = something;

 
Re: Horrifying lines of code
Found this gem inside missionbriefcommon.cpp:

Code: [Select]
strcat(errormsg, "\0");
STRONGTEA. Why can't the x86 be sane?

 
Re: Horrifying lines of code
WOAH.

Just found this function:

Code: [Select]
void lcl_translate_brief_icon_name(char *name)

It's about as in-efficient as it gets, and there're lots of examples in localize.cpp.
Worse, if this is called per-frame (not established yet), I wouldn't want to be French, German or Polish.

This one's good as well (from missiondebrief.cpp):
Code: [Select]
strcpy(voice_dest, "9_");
strcpy(voice_dest + 2, voice_base);
« Last Edit: July 24, 2009, 03:14:44 am by portej05 »
STRONGTEA. Why can't the x86 be sane?

 
Re: Horrifying lines of code
Almost as good as Mikas above:

From aicode.cpp line 5875:
Code: [Select]
int t = ((Missiontime /(65536*10)) ^ target_objnum ^ 0x01) % (NUM_SKILL_LEVELS+2);
STRONGTEA. Why can't the x86 be sane?

 
Re: Horrifying lines of code
Not horrifying, as such, but certainly made my (FSO) day:
Code: [Select]
// Stuffs a boolean value pointed at by Mp. 
// YES/NO (supporting 1/0 now as well)
// Now supports localization :) -WMC

void stuff_boolean(bool *b, bool a_to_eol)
{
char token[32];
stuff_string_white(token, sizeof(token)/sizeof(char));
if(a_to_eol)
advance_to_eoln(NULL);

if( isdigit(token[0]))
{
if(token[0] != '0')
*b = true;
else
*b = false;
}
else
{
if(!stricmp(token, "yes")
|| !stricmp(token, "true")
|| !stricmp(token, "ja") //German
|| !stricmp(token, "Oui") //French
|| !stricmp(token, "si") //Spanish
|| !stricmp(token, "ita vero") //Latin
|| !stricmp(token, "HIja'") || !stricmp(token, "HISlaH")) //Klingon
{
*b = true;
}
else if(!stricmp(token, "no")
|| !stricmp(token, "false")
|| !stricmp(token, "nein") //German
|| !stricmp(token, "Non") //French
//I don't know spanish for "no"
//But according to altavista, spanish for "No" is "no"
//Go figure.
|| !stricmp(token, "minime") //Latin
|| !stricmp(token, "ghobe'")) //Klingon
{
*b = false;
}
else
{
*b = false;
Warning(LOCATION, "Boolean '%s' type unknown; assuming 'no/false'",token);
}
}

diag_printf("Stuffed bool: %s\n", (b) ? NOX("true") : NOX("false"));
}

Note: This is not an endorsement to use anything other than YES or NO - these may be removed in the future for performance or security reasons.
STRONGTEA. Why can't the x86 be sane?

  

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Horrifying lines of code
wouldn't it have been better to run it through the localization functions?

though I guess that's why it's here.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 
Re: Horrifying lines of code
The localisation functions would be better implemented as maps - they're one VERY expensive function call.

Probably because the localisation functions were so damn slow.
STRONGTEA. Why can't the x86 be sane?

 

Offline sigtau

  • 29
  • unfortunate technical art assclown
Re: Horrifying lines of code
Code: [Select]
unsigned int epicfail = 0/0;
'nuff said.
Who uses forum signatures anymore?

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: Horrifying lines of code
Code: [Select]
if(_wrappedtext[end-1] == ' ') //DirectX ignores spaces because microsoft likes hiring retards, so we have to improvise
{
_wrappedtext.insert(end,1,L'X');
_driver->calcTexcRect(_wrappedtext.String()+linepos,_fontID,&strdim,_drawflags,count+1);
_wrappedtext.erase(end,1);
count = strdim.right;
memset(&strdim,0,sizeof(tagRECT));
_driver->calcTexcRect(L"X",_fontID,&strdim,_drawflags,1);
strdim.right=count-strdim.right;
}

This code is even more horrifying when you realize that there isn't a way around this. I hate DirectX.

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: Horrifying lines of code
Code: [Select]
bool __fastcall SetUVCoords(unsigned char index, float u, float v)
{
  float* uvcoords=(float*)(((char*)this)+sizeof(cVertexMulti)); uvcoords[(index*=2)] = u; uvcoords[++index] = v;
}

Try and guess why I had to do this.
« Last Edit: October 04, 2009, 04:27:34 am by blackhole »

 

Offline Mika

  • 28
Re: Horrifying lines of code
This has something to do with parametric U and V coordinates? Otherwise, I don't know, I'm C++ illiterate (and will remain so). Algorithm wise, that index*=2 and later 
++index results in a nice, confusing effect...
Relaxed movement is always more effective than forced movement.

 

Offline Mika

  • 28
Re: Horrifying lines of code
Code: [Select]
int t = ((Missiontime /(65536*10)) ^ target_objnum ^ 0x01) % (NUM_SKILL_LEVELS+2);
Whoa! There surely isn't an easier way to do this? Or is it because of performance?
Relaxed movement is always more effective than forced movement.

 
Re: Horrifying lines of code
Code: [Select]
bool __fastcall SetUVCoords(unsigned char index, float u, float v)
{
  float* uvcoords=(float*)(((char*)this)+sizeof(cVertexMulti)); uvcoords[(index*=2)] = u; uvcoords[++index] = v;
}

Try and guess why I had to do this.

Code: [Select]
struct UVCoord { float u, float v};
class MyClass {
std::vector<UVCoord> uvcoords;
//...
public:
//...
bool __fastcall SetUVCoords(Uint8 index, float u, float v)
{
  UVCoord tmp = {u,v};
  uvcoords[index] = tmp;
}
};
Why wouldn't it work this way? Or am I misunderstanding what your code is supposed to do..?

 

Offline blackhole

  • Still not over the rainbow
  • 29
  • Destiny can suck it
    • Black Sphere Studios
Re: Horrifying lines of code
Sadly, no. The reason i had to do it this crazy way is because its for graphics card data. The data inside the struct must be packed in a very specific manner, so I cannot use anything like vectors or virtual functions or *anything* that might introduce hidden data within the struct. Normally only 1 set of UV coordinates is required, so you just make a struct with that, but in this case i needed to allow for any number of UV coordinate pairs, and thus this monstrosity was born.

In reality, I never actually create the struct in the first place, (its pointed to a block of memory within a vertex buffer) so its slightly less insane then it appears to be... slightly.

 
Re: Horrifying lines of code
Truly horrifying.

 
Re: Horrifying lines of code
Someone at some point had a very late night:

From neblightning.cpp (674)
Code: [Select]
// add some flavor to the bolt. mmmmmmmm, lightning
if(!IS_VEC_NULL_SQ_SAFE(&Storm->flavor)){
// start with your basic hot sauce. measure how much you have
vec3d your_basic_hot_sauce;
vm_vec_sub(&your_basic_hot_sauce, &strike, &start);
float how_much_hot_sauce = vm_vec_normalize(&your_basic_hot_sauce);

// now figure out how much of that good wing sauce to add
vec3d wing_sauce = Storm->flavor;
if(frand_range(0.0, 1.0f) < 0.5f){
vm_vec_scale(&wing_sauce, -1.0f);
}
float how_much_of_that_good_wing_sauce_to_add = vm_vec_normalize(&wing_sauce);

// mix the two together, taking care not to add too much
vec3d the_mixture;
if(how_much_of_that_good_wing_sauce_to_add > 1000.0f){
how_much_of_that_good_wing_sauce_to_add = 1000.0f;
}
vm_vec_interp_constant(&the_mixture, &your_basic_hot_sauce, &wing_sauce, how_much_of_that_good_wing_sauce_to_add / 1000.0f);

// take the final sauce and store it in the proper container
vm_vec_scale(&the_mixture, how_much_hot_sauce);

// make sure to put it on everything! whee!
vm_vec_add(&strike, &start, &the_mixture);
}
STRONGTEA. Why can't the x86 be sane?