Author Topic: CleanCode Quake II has gone public!  (Read 6562 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:

Costigan_Q2

November 11, 2024, 06:41:06 AM
"Stay cozy folks.

Everything is gonna be fine."

There'll be no excuses for having TDS after January 20th, there'll be no excuses AT ALL!!!
 

|iR|Focalor

November 06, 2024, 03:28:50 AM
 

RailWolf

November 05, 2024, 03:13:44 PM
Nice :)

Tom Servo

November 04, 2024, 05:05:24 PM
The Joe Rogan Experience episode 223 that dropped a couple hours ago with Musk, they're talking about Quake lol.

Costigan_Q2

November 04, 2024, 03:37:55 PM
Stay cozy folks.

Everything is gonna be fine.
 

|iR|Focalor

October 31, 2024, 08:56:37 PM

Costigan_Q2

October 17, 2024, 06:31:53 PM
Not activated your account yet?

Activate it now! join in the fun!

Tom Servo

October 11, 2024, 03:35:36 PM
HAHAHAHAHAHA
 

|iR|Focalor

October 10, 2024, 12:19:41 PM
I don't worship the devil. Jesus is Lord, friend. He died for your sins. He will forgive you if you just ask.
 

rikwad

October 09, 2024, 07:57:21 PM
Sorry, I couldn't resist my inner asshole.

Show 50 latest
Welcome, Guest. Please login or register.
November 22, 2024, 02:13:20 PM

Login with username, password and session length