Inside3D!
     

Official Post Your Enging Coding Tips Thread
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming
View previous topic :: View next topic  
Author Message
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Sat Aug 01, 2009 10:18 pm    Post subject: Official Post Your Enging Coding Tips Thread Reply with quote

Hello, I thought this would be a helpful thread.

You just post all of your little Engine Coding Tips and common problems and what solves them.

I will start.


Unused Variable
Code:

gldraw.c:1010: warning: unused variable 'verts'


Solution

Go to line 1010 of "gldraw.c" and remove the variable "verts"
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Sun Aug 02, 2009 12:46 am    Post subject: Reply with quote

hmm ok Smile

warnings about mismatching formats (int to float etc)

say you have a variable that needs a float value like ent->fog[0] = 0.0;

this will give a warning about doubles so change 0.0 to 0.0f.
int needs long type as far as i know so if 0.0 is int change it to 0.0L.

the example ent->fog[number] above is btw an array "very usefull"
instead of having 3 or more float variable's you can get away with a single definition.

float x=1
float y=2
float z=3

can instead be float xyz[3] = {1,2,3};
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Aug 02, 2009 1:17 am    Post subject: Reply with quote

reckless wrote:

warnings about mismatching formats (int to float etc)


#pragma warning( 4 : 4244) //conversion from const double to float
#pragma warning( 4 : 4305) //truncation from const double to float
#pragma warning( 4 : 4018) //truncation from const double to float
#pragma warning( 4 : 4267) //truncation from const double to float

much easier.

But really:
#pragma warning(1:4013)

I highly recommend that one. Highly highly recommend it.
It makes functions without prototypes generate decent warnings (hint: change the 1 to 'error').
Note that functions without prototypes are assumed to take only int parameters. Everything breaks when the function really takes a float - floating point arguments are actually passed as doubles, and take twice as much memory as ints. Meaning that if you call a function without prototypes, your arguments all get shifted and mixed up and converted when they shouldn't be, etc. Its not pretty. Failing to warn about this kind of bad practise is not nice. Note that this is even more important when you're mixing int and pointers and floats and stuff on a 64bit build.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Sun Aug 02, 2009 6:11 pm    Post subject: Reply with quote

If you have this in your code:

Code:

   }
   else
   {


Then you can change it to this to make it shorter:

Code:

   }else{



Also speaking of floats:

Is it good to fix this error:

Code:

GlBlend undeclared first use in this function


by adding

Code:
   float      GlBlend;


to the top of that function?
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Sun Aug 02, 2009 10:38 pm    Post subject: Reply with quote

Team Xlink wrote:
If you have this in your code:

Code:

   }
   else
   {


Then you can change it to this to make it shorter:

Code:

   }else{


Rolling Eyes
Back to top
View user's profile Send private message
Creebo



Joined: 02 Aug 2009
Posts: 1

PostPosted: Sun Aug 02, 2009 10:43 pm    Post subject: Reply with quote

Oh and before you compile make sure you put everything on one line. I would make a backup, but one line will make the entire engine 200% faster.
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Sun Aug 02, 2009 11:20 pm    Post subject: Reply with quote

Creebo wrote:
Oh and before you compile make sure you put everything on one line. I would make a backup, but one line will make the entire engine 200% faster.


Huh ? Confused
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Aug 03, 2009 12:06 am    Post subject: Reply with quote

He's just screwing with you.
Back to top
View user's profile Send private message
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Mon Aug 03, 2009 2:25 am    Post subject: Reply with quote

So I shouldn't use that?

the:

Code:

}else{



I have seen it used in the code tho.
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Aug 03, 2009 2:39 am    Post subject: Reply with quote

Feel free to use it, it's just that it's basic knowledge regarding the syntax of many, many languages out there.
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Mon Aug 03, 2009 2:55 am    Post subject: Reply with quote

Use whatever makes your code more readable for you/your team.
Consistancy is often better than reducing line counts.
If you have a widescreen monitor, consider twisting it by 90 degrees for coding, then you don't have to try and keep line counts low.

Quake has a consistant style already, that is, braces are on their own lines. Zoid messed up parts of the quakeworld code by breaking that style - you can clearly distinguish the bits that were written by him.

I'm not going to argue about which style is best (gah gnu style!), but I will argue that a consistant code style is more important than mere line counts. Readability is king.

Creebo: My own engine has too many #defines for it to all fit on a single line, sadly enough.
Interestingly enough, if you find compiling C++ code slow, you can concatinate all your source files together into one blob (basically just #include "*.cpp"). This can increase compilation speed fairly significantly if you use a few different classes and inheritance and other stuff from a monolithic header file such as the one quake uses. Sure, okay, its not a single line, but mneh. That really would be a pain to fix any compile errors. 'Error on line 1 compiling everything.c'. Nooo!
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Mon Aug 03, 2009 5:51 am    Post subject: Reply with quote

hehe Laughing

ok heres one that might be usefull if someone decides to go compile the original quake source on newer msvc.

the assembler in NET. msvc has changed quite a bit over the years
for one inline assembly was removed :S.

also the syntax for the gas2masm conversion in old msvc used "command","variables" in NET it just uses command,variables

so remove all the "" and it works Wink


if you get sick of msvc NET's warnings add _CRT_SECURE_NO_WARNINGS or
_CRT_SECURE_NO_DEPRECATE to the preprocessor variables.

some might argue that it's not intended to turn of compiler warnings but unless you want to port everything in the source to microsofts secure library format "which will also break compatibility with free compilers like mingw etc" this will have to do.

and yes floats are evil Twisted Evil use byte or int instead if possible.
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Aug 03, 2009 3:09 pm    Post subject: Reply with quote

Haha it takes more effort and time to reduce everything to one line anyway, and it certainly won't help the game itself run faster, only the compile time if anything.
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Mon Aug 03, 2009 7:06 pm    Post subject: Reply with quote

Code:
}else{

Some people prefer it, some people don't. For me, code readability is far more important than vertical real estate, and I just find that style of coding to be completely unreadable. It's all about visually matching opening and closing braces in the same column. But everyone's different, and no one style is intrinsically superior to any other. Plus if someone's already made their mind up about their own preference, no amount of hot air and wasted energy is gonna convince them otherwise, so let's just leave it, eh?

Q1 specific: instead of doing positional and orientation interpolation in R_RotateForEntity, do it in CL_RelinkEntities.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Mon Aug 03, 2009 9:46 pm    Post subject: Reply with quote

Spike wrote:
Use whatever makes your code more readable for you/your team.
Consistancy is often better than reducing line counts.
If you have a widescreen monitor, consider twisting it by 90 degrees for coding, then you don't have to try and keep line counts low.

Quake has a consistant style already, that is, braces are on their own lines. Zoid messed up parts of the quakeworld code by breaking that style - you can clearly distinguish the bits that were written by him.

I'm not going to argue about which style is best (gah gnu style!), but I will argue that a consistant code style is more important than mere line counts. Readability is king.

Creebo: My own engine has too many #defines for it to all fit on a single line, sadly enough.
Interestingly enough, if you find compiling C++ code slow, you can concatinate all your source files together into one blob (basically just #include "*.cpp"). This can increase compilation speed fairly significantly if you use a few different classes and inheritance and other stuff from a monolithic header file such as the one quake uses. Sure, okay, its not a single line, but mneh. That really would be a pain to fix any compile errors. 'Error on line 1 compiling everything.c'. Nooo!


So adding everything into one file will make it run faster?

This will be excellent, there will be a lot of messed up defines and includes tho.
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group