Author Topic: CleanCode Quake II has gone public!  (Read 6396 times)

Offline Paril

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
  • Rated:
Re: CleanCode Quake II has gone public!
« Reply #15 on: December 20, 2009, 06:28:17 PM »
The key to portability is to avoid compiler extensions and OS-dependent functions or classes that don't have equivalents. Nothing is more annoying than dealing with a bunch of code full of #if WIN32 directives. Your OS dependencies should be wrapped such that your code hides these details.

Hence cc_platform.h.
Microsoft extensions (the ones that MSBuild put under "non-standard") are all disabled and a warning is brought up if any such as issued. Of course there might be other "little" extensions that don't raise this error, such as using a templated class as a base but not using the template arguments inside the class itself:

Code: [Select]
template <class what>
class CWhatever
{
};

class CTwo : public CWhatever<int>
{
    CTwo () :
      CWhatever ()
      {
      }
};

Whether the standard allows for this I don't know; VS6 didn't like it one bit. A VS6 project is still in development, but there are a lot of required changes before it will function.

As for #if WIN32 and such, I haven't been able to remove all of them as location matters in this case, but most of them are in Platform.h and cc_platform.h.
It can be confusing to programmers to have to manage all of these little details, but nearly every "cross-platform" library or application is swimming in these statements, and sadly there's not too much people can do about it other than wrapping the crap out of every function that is OS-dependent (which also becomes useless if, for example, one platform doesn't have the same functions another platform does)
Example being Sleep(0), which every Win32 programmer knows the meaning of but might have no use on any other system (besides them maybe not even having a proper sleep function)

Quote
Also, DON'T use constructs in your code like __CC_DEPENDENCY_H__ with leading/trailing underscores. Functions, variables and constants with leading underscores are reserved to the implementation, (the compiler writers) not user namespace. Functions with leading underscores for example, are compiler extensions or non-standard C runtime functions that are platform/implementation dependent and you should not use this namespace for your application code. If you find yourself using leading underscores or double leading underscores this is supposed to be a clue that you are venturing into non-portable territory.

Reason I used leading/trailing underscores is to avoid name conflictions with anything. I am aware that they are reserved, and it just developed into using that without much thought. I'll remove any trailing/leading underscores that I can find and hopefully won't break anything in the process.

Quote
There should be almost nothing in a Q2 mod that is OS dependent. The only exception is the code necessary to support the different DLL implementation and names. (Although I confess to using OutputDebugString occasionally, I undefine it in the header on non-windows platforms.) All the OS dependent code is in the engine, the mod only needs to call the engine API. All other functions in the mod should be completely contained and defined in the mod code, dependency on outside packages makes modding harder, not easier. If he downloads the wrong version of the package the modder ends up debugging the package, not his code. If you import package code then ship that code with the project. Make no use of Windows API or classes.

There shouldn't, but sadly I had to use some complex hacks to get a class-based Quake 2 to work properly. A good example is the fact that I had to have a DLL initialization function (DLLInit/DLLMain) to initialize CleanCode's own memory system. Linux that I know of supports a function that will be called before the CRT initialization and should have no problem with this, but there was no other capable workaround as static STL containers used our own memory allocation.


Quote
You should consider creating a VM and running your code through the GCC compiler concurrently with your Windows development since the vast majority of active servers are on Linux. idSoftware made the mistake of not paying enough attention to this and they ended up massaging the entire Quake 2 code base for Linux and the 3.21 release. OO helps you in this case since you can conceal platform dependencies inside a class but again, this should not be necessary at the mod level.

VM is not an option at this point, to keep complexity to a minimum. Porting to Linux should be straightforward, the problem I see is DLL initialization and possible compiler conflicts not liking VS08+ constructs and features (Microsoft extensions)

Quote
ALWAYS test your conditional switches and pathways to be sure they work. Test all cases to be sure your project builds successfully under all conditions of switches and packaging. Obviously, the more switches and special configurations you have the harder it becomes to maintain.

This has been a goal all the way through, problems arose mostly when I was working on systems like monsters and pathfinding or something would be left out, the codebase is constantly updated with fixes and it just happens that sometimes a fix breaks another fix. That's why we have SVN, and we're working diligently to make sure that these conflicts don't happen.

-P
« Last Edit: December 20, 2009, 07:02:58 PM by Paril »
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

 

El Box de Shoutamente

Last 10 Shouts:

 

RyU

September 03, 2024, 05:15:49 PM
And wow Derrick is still playing lol
 

RyU

September 03, 2024, 05:15:15 PM
Just know yesterday is gone and soon tomorrow will be gone too  :)
 

Lejionator

August 08, 2024, 07:28:01 PM
It's tiem to QuakeCon!!!  ;)

https://www.youtube.com/watch?v=ThQd_UJaTys
 

ImperiusDamian

July 26, 2024, 09:34:53 PM
In nomine Quake II et Id Software et Spiritus John Carmack, Amen.
 

QuakeDuke

July 26, 2024, 05:10:30 PM
Hey, shout, summertime blues
Jump up and down in you blue suede shoes
Hey, did you rock and roll? Rock on!!  ...QD
 

Yotematoi

July 24, 2024, 01:31:20 PM
Ayer me mato 5 veces para robarme en la vida real hará lo mismo? [img]<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid0wXU2VgS7atesBcSoMz5BWMJCJajeZFVT6GzSU6TtpJGddN9kLTvWNgcZaskkbKFQl&amp;show_text=true&amp;width=500
https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid0wXU2VgS7atesBcSoMz5BWMJCJajeZFVT6GzSU6TtpJGddN9kLTvWNgcZaskkbKFQl&show_text=true&width=500" width="500"
 

Yotematoi

July 24, 2024, 01:25:59 PM
hi ya está la basura de Martin, se cambió el nombre es un ladron estupido, asi llegó a 10000[img]<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&amp;show_text
https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&show_text
 

Yotematoi

July 24, 2024, 01:25:59 PM
hi ya está la basura de Martin, se cambió el nombre es un ladron estupido, asi llegó a 10000[img]<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&amp;show_text
https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&show_text
 

-Unh0ly-

July 05, 2024, 05:20:36 AM

Show 50 latest
Welcome, Guest. Please login or register.
September 21, 2024, 07:15:37 AM

Login with username, password and session length