|
Coding
Tips: Hacking the Half-Life SDK
#1 - Make Backup Copies
Make backup copies
-- make them often -- and use a naming scheme for your files and directories,
so you can keep track of each version.
If you've got
the drive space, keep a complete copy of the "clean" SDK
in one directory, and another "working" copy in your working
directory. You might want to keep a clean copy of the SDK on removeable
non-rewritable media, for convenient safekeeping.
Another good
time to store a backup is when you've made a lot of changes, you know
that things work, and you're happy with this version. By burning a
copy to CD now, you can be confident that you won't lose your work
to system crash or file corruption.
It's very likely
that you'll make mistakes as you go -- mistakes that you won't be
able to figure out how to undo. This is sad, and seems unnecessary,
but is all too common, even with seasoned professional programmers
such as myself. So keep backup copies -- when your working copy gets
corrupted, you can overwrite the corrupted file with a clean backup
version.
DATE NAMING
SCHEME -- when naming backup files, use a naming scheme to describe
the files. I use a scheme which incorporates the date of the backup.
For instance, before modifying file.cpp, use Save As to make
a copy named file_011227a.cpp. (This date code represents 01-12-27-a
... year 2001, month 12, day 27, version a. Many variations are possible.
Choose a naming scheme which works for you.)
#2 - Use Comments
Use comments
-- use lots of comments -- use them everywhere you change anything
in the SDK. Comment lines are ignored by the compiler. In C++, there
are two forms of comments -- Line and Block:
// This is
a comment line: two slashes = stand-alone comment
int iVariable; // You can also use use
the comment after code
/*
This text is enclosed within a comment
block
e.g. the above line is a comment, and
so is this line
*/
Use comments
everywhere you many any changes whatsoever. Whatever changes you make,
you must keep track of what and where. If you are unable to undo a
change, you won't be able to debug your code -- and then the game
is lost, because debugging is ninety percent of coding.
MARKER COMMENTS:
develop a system of marker comments that you can use to remind yourself
about things that you have found or changed in the SDK -- a system
of "breadcrumbs in the forest" indicating structure and
function. I recommend using your initials -- for instance, when I'm
working on a new monster, I leave comments like this
(monster code
goes here) ; // KGJ:NEWMONSTER
(I also include
a comment markers that read "KGJ:INTERESTING" wherever something
in the Valve code looks interesting -- things for later review.)
Coded marker
comments allow you to retrieve specific chunks of code using "Find
in Files" -- a vital tool, when you're making changes that span
several files.
COMMENTS and
CODING TEAMS: when combining the work of two or more coders into one
project, one lead coder should coordinate the final product. Everyone,
MAKE SURE TO COMMENT YOUR WORK so the leader coder knows what code
is what.
#3 - "Find In Files"
Use the "Find
in Files" feature to hunt for all keyword references in all source
files. The Valve developers have included numerous useful comments
in the SDK -- by studying these comments, you can learn much about
the structure and function of the code.
What keywords?
Depends on what you need to know. If you want to change the rate at
which a player experiences drowning, try "drown" or "drowning"
or "water", etc.
Class names and
methods are also useful keywords -- for example, "CBaseMonster",
"CreateEntity", etc.
Similarly, use
Find in Files to locate your comment markers -- for instance, I might
search for "KGJ:" when I want to find all my markers, but
then search for "KGJ:NOODLE" when I want to find the new
Monster_DeathNoodle code.
USE TWO PANES:
in Microsoft Visual C++ 6, the Find in Files features allows you to
select which of two panes to use when displaying the results of the
Find comman. Selection is performed via a checkbox on the Find in
Files dialog box. Having two panes allows you to keep the results
of one search in the first pane, while performing other searches in
the second pane.
#4 - Learn the SDK
Don't worry too
much about the C++ ... you can pick that up as you go ... the main
thing to focus on is the SDK ... the structure and function of the
SDK ... if you map out the SDK with comments, and get to know the
SDK in your head, you can figure out much of the C++ as you need it.
Learning the
SDK means learning about the structure and function of the SDK: how
the parts relate to the whole, the interaction between server dll
and client dll, the layout of the code, using Find in Files, etc.
The secret to
a great mod: new entities, and new behaviors for existing entities.
To know these things, you must know the SDK.
ADAPTING CODE:
Use existing code as raw material from which to build new code. For
example, when developing the HornetCannon for Xen Rebels, I studied
(and borrowed from) the code for weapon_hornetgun, as well as the
code for monster_alien_grunt.
#5 - Have Faith
Coding is far
and away the most valuable game design skill of all. It's where the
magicians make their new tools, build their new toys.
What else is
there? ... maps, textures, sounds, sprites ... player models in deathmatch
... that's about it -- other than that, coding makes the mod.
Hacking the SDK
is a mammoth task; it takes a lot of time. Pace yourself.
You will experience
setbacks: such is the nature of mammoth software. Be calm, be patient.
With our tools and skills, we can mitigate the setbacks. Let's review
the basics:
- Keep good
backups
- Use comment
markers -- use lots of them, wherever you go in the SDK
- Use Find in
Files to pick out keywords from source files
- Meditate upon
the structure and function of the SDK
- Give yourself
time to learn, keep an open mind, be at peace yet like a warrior
-- this is the Way of the Hacker.
Trust yourself.
What the mind can imagine, the will can attain; and a little faith
goes a long way.
#6 - Tutorials and Forums
See Coding
page for links to tutorials and forums
Some online tutorials
are full of bugs and will lead you to frustration, but others can
be useful and enlightening. You can learn much about the structure
and function of the SDK by implementing tutorials. Furthermore, the
code in tutorials can sometimes be adapted to meet other coding needs.
Forums provide
a searchable database of topic-specific information. Try mining the
archives for keywords -- short, simple words or phrases, preferably
specific technical terms such as error messages or C++ keywords. Bookmark
the relevant hits -- or save the text in text files or web pages,
for later use (this is how the Handy Vandal's Almanac was born!).
If archive mining
doesn't dig up what you're looking for, try posting your question
directly to the forums (taking care to state your question clearly,
completely, and politely). Remember that replies take time ... bookmark
the forum pages, return every day or two for several weeks, and be
patient while waiting for replies ....
#7 - UTIL_Client PrintAll
Use the
UTIL_ClientPrintAll utility to display message during gameplay.
The simplest form of the utility looks like this:
UTIL_ClientPrintAll(
HUD_PRINTNOTIFY, UTIL_VarArgs("Message"));
Put this in your
source anywhere you want to display a message. This way, you can tell
that the code has executed by watching the HUD.
To see more complex
forms of the utility -- e.g. displaying variables -- use "Find in Files"
with the keyword UTIL_ClientPrintAll.
|