Lemme just quote line 7201 from that file:
Quote: "if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i[/i]].coords)>0)&&((i==0||k==0)||((player[i[i]].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i[/i]].currentanimation].attack==neutral)||(player[i[i]].isFlip()&&!player[i[/i]].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i[i]].targetanimation==jumpupanim||player[i[/i]].targetanimation==jumpdownanim||player[i[i]].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i[i][/i]].skeleton.oldfree&&!player[k].skeleton.oldfree))){"
Yes, that is
one line. Had a discussion with Alex (TheComet) too, and while I have less experience in C/C++ (mostly basic stuff) I too was baffled by the complete lack of comments, the nested 15 and more if-clauses (where all but the last one are lacking curly brackets... which will compile fine as the next line is just another if statement... but... that surely is not good style?) and other stuff.
Just look at this.
7152 if(player[i].coords.y>player[k].coords.y-3)
7153 if(player[i].coords.y<player[k].coords.y+3)
7154 if(player[i].coords.x>player[k].coords.x-3)
7155 if(player[i].coords.x<player[k].coords.x+3)
7156 if(player[i].coords.z>player[k].coords.z-3)
7157 if(player[i].coords.z<player[k].coords.z+3){
why would you nest these like this? Why not write a 3d distance function and write one humanly readable check?!
The GameTick file you linked seems to contain most of the game's code for whatever reason.
It also contains this part:
static const char *cmd_names[] = {
#define DECLARE_COMMAND(cmd) #cmd " ",
#include "ConsoleCmds.h"
#undef DECLARE_COMMAND
};
typedef void (*console_handler)(Game *game, const char *args);
#define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
#include "ConsoleCmds.h"
#undef DECLARE_COMMAND
static console_handler cmd_handlers[] = {
#define DECLARE_COMMAND(cmd) ch_##cmd,
#include "ConsoleCmds.h"
#undef DECLARE_COMMAND
};
static void ch_quit(Game *game, const char *args)
{
game->tryquit = 1;
}
and so on. The ConsoleCmds.h contains lines like e.g. "DECLARE_COMMAND(quit)" which are in the above snipped warped by some crazy pre-processor magic turning it into a) an array of the names of the commands; b) prototype declarations (I think that's what they're called) for the ch_* functions; and c) an array of the function handlers.
It might work, but somehow I don't get why they couldn't just write those three things manually or shove them into the ConsoleCmds Header or whatever? Maybe it's just me not being used to C++ but that code srsly confused me for a moment before I actually grasped what it does.
The Terrain.cpp / Terrain.h have this stuff for example:
117 void UpdateTransparency(int whichx, int whichy);
118 void UpdateTransparencyother(int whichx, int whichy);
119 void UpdateTransparencyotherother(int whichx, int whichy);
124 void drawpatch(int whichx, int whichy, float opacity);
125 void drawpatchother(int whichx, int whichy, float opacity);
126 void drawpatchotherother(int whichx, int whichy, float opacity);
And they differ only marginaly and in some strange way. Nothing gets explained there.
Why not have one of these functions each and have some macro-switch or a flag as an argument to change the behaviour of the function (and name it sensibly!)...
But, yes, I'll admit I have had code like this before too. Worse even. Didn't undestand my own project after a while because it got cluttered with testing bits and tweaks and hacks. But why for ponies sake would they then just throw the source out there? It is quite the enigma indeed...
Oh and kind regards from TheComet, who as I mentioned showed me this too a while ago.
Oh and he said that they're "using namespace std;" which as he told me is pretty darn horrible coding in itself. (As I said my C knowledge is limited and rusty...)
PS: It even had "if(1==1){" somewhere
PPS:
Link just look at "bool Person::isIdle(){" ....
Edit: Actually nevermind about the way the Commands are handled. It was actually worse before it got sorted out and structured the way it is by a certain "Alexander Monakov" (dunno if he's part of Wolfire but I don't think so.),
here's the changelog/diff for that. Before it was all parsed & executed manually inside "void Game::Tick()" as far as I can tell (that function handles all the keyboard-input, menues, animation-related stuff... imho it could all be split off into other parts of the code.
Wait. Wait. Waaait. GameTick() goes from line 2480 to 9435?! I hadn't realized 75% of the 10k lines of code in that file are
inside that one function... and it seems to handle basically ALL game mechanics... holy mother of code. With the commands in it too it must've been ONE big 10k lines function. I don't even.