1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE file SYSTEM "./file.dtd">
<file title="Source code">
<chap title="General remarks">
<part title="Modularity">
<text>
Liquid War 5 is basically a big C program. I've splitted
the source code in many small files for I do not like to
have to handle big monolithic sources, but this does not
mean Liquid War is very modular. In fact Liquid War 5
is quite bloated with global variables and other ugly
stuff 8-(
</text>
</part>
<part title="Coding style">
<text>
To be honest, it's a big mess. You won't find 2 files
coded in the same maner... OK, I'm exagerating a bit.
From now I try to make an effort and
stick to basic rules such as:
</text>
<list>
<elem>
use the GNUish-style indentation - the default Emacs mode in fact
</elem>
<elem>
prefix global functions / variables / constants / types with
lw_<NAME_OF_THE_file>_. For instance, a "do_it" function
in myfile.c will be called lw_myfile_do_it
</elem>
<elem>
use capitals for constants, globals and types only. All functions
are in lowercase with "_" to separate words
</elem>
<elem>
keep on using 8.3 filenames for .c source files. This is for
better DOS integration. DOS version of Liquid War is still
maintained, you know 8-)
</elem>
<elem>
use English only for code and comments
</elem>
</list>
<text>
I might decide to rename and cleanup everything some day, for
it would help other coders to understand what I wrote, but well,
this is certainly not a thrilling task 8-/
</text>
</part>
</chap>
<chap title="Source files organization">
<part title="Main game code">
<text>
Here you'll find the main() function, the main game
loop, application-wide constants and other global stuff.
</text>
<text>
It might be a good start if you want to hack the code.
</text>
<list>
<elem>
base.h:
contains global constants used in many different files.
</elem>
<elem>
game.c / game.h:
contains the main game loop.
</elem>
<elem>
main.c / main.h:
the file where the main C function is declared.
Doesn't contain much except calling init functions and
running the GUI.
</elem>
</list>
</part>
<part title="Menus">
<text>
The menus are coded using the Allegro GUI system.
While this system is very powerfull, it's IMHO not adapted to
very complex GUIs, and one of its drawbacks is that it's not
so easy to redesign something once you've coded it.
</text>
<text>
Besides, when I started coding the GUI in 1998, I did it
in a rather ugly way, and now I'm paying for my being lazy
at that time, since I spent hours coding when I want to
change something 8-/
</text>
<list>
<elem>
about.c / about.h:
contains the code for the about menu.
</elem>
<elem>
advanced.c / advanced.h:
contains the GUI advanced options menu.
</elem>
<elem>
connect.c / connect.h:
contains code for the "connect" menu which displays which players
are connected to the server, before the game actually starts.
</elem>
<elem>
controls.c / controls.h:
contains the code for the controls menu.
</elem>
<elem>
graphics.c / graphics.h:
code for the graphic options menu.
</elem>
<elem>
internet.c / internet.h:
contains the code for the "Search for Internet games" menu, where one
can pick up a running server automatically with the help of the meta-server.
</elem>
<elem>
language.c / language.h:
contains the code for the "Language" menu.
</elem>
<elem>
level.c / level.h:
contains code for the menu where the player
can select a level and its options (texture or color).
</elem>
<elem>
menu.c / menu.h:
contains the code for the main menu.
</elem>
<elem>
netgame.c / netgame.h:
contains the code for the net game menu.
</elem>
<elem>
options.c / options.h:
contains the code for the options menu.
</elem>
<elem>
play.c / play.h:
contains the code which ties the menu to the main gameloop.
</elem>
<elem>
rules.c / rules.h:
code for the rules menu.
</elem>
<elem>
score.c / score.h:
functions to display the scores at the end of the game.
</elem>
<elem>
speeds.c / speeds.h:
contains the code for the speeds menu.
</elem>
<elem>
team.c / team.h:
code for the team menu, where one choses which teams will play.
</elem>
<elem>
volume.c / volume.h:
code for the sound menu.
</elem>
<elem>
wave.c / wave.h:
code for the wave menu.
</elem>
</list>
</part>
<part title="GUI tools">
<text>
These files contain various utilities which are used
in the menus.
</text>
<list>
<elem>
alleg2.c / alleg2.h:
contains some tweaked allegro functions. I wanted to use
bitmaps with sevral colors for my fonts, and change some
of the allegro default behavior. So rather than modifying
the allegro source code right in the library I copied
it in this file and then modified it.
</elem>
<elem>
back.c / back.h:
this modules displays the background image.
</elem>
<elem>
dialog.c / dialog.h:
contains code for standard dialog boxes.
</elem>
<elem>
error.c / error.h:
contains functions to display error messages once the game
is in graphical mode.
</elem>
<elem>
help.c / help.h:
generic functions to display the various help pages.
</elem>
</list>
</part>
<part title="Core algorithm">
<text>
Here's *the* interesting part.
All the rest of the code is just sugar coat to display stuff,
receive players commands, communicate with other computers,
handle errors, etc... But the real thing is here!
</text>
<text>
It's funny to note that these files have almost not been
modified since Liquid War 5.0.
</text>
<text>
It's also interesting to note that they represent a small
percentage of the total amount of code in the game.
This tends to prove - and I'm convinced of it - that game
programming does not only consists in having great ideas,
but also requires a lot of "dirty" and boring work.
Honestly, coding an option menu is as boring as
coding Liquid War algorithm is fun.
</text>
<list>
<elem>
fighter.c / fighter.h:
contains code to move the armies, once the gradient has been calculated.
</elem>
<elem>
grad.c / grad.h:
this module calculates the gradient for each team.
One could say it's the "kernel" of the game,
since most of the CPU time is spent in this module
(except if you have a slow display...).
</elem>
<elem>
mesh.c / mesh.h:
contains code to set up a usable mesh with a map.
Mesh are re-calculated at each time a new game is started,
the reason for this being that meshes are *very* big so
it would not be reasonnable to save them directly on the HD.
</elem>
<elem>
monster.s / monster.h:
assembly functions to speed-up the game.
It's a replacement for some fighter.c functions.
</elem>
<elem>
spread.s / spread.h:
contains assembly replacements for some functions of grad.c.
These replacements do the same than the original ones from grad.c,
but faster. Could still be optimized.
</elem>
</list>
</part>
<part title="Moving cursors">
<text>
It looks like nothing, but moving a cursor and deciding where
it should go if there's a wall in front of it is not that easy,
especially if you want things to work nicely.
</text>
<list>
<elem>
autoplay.c / autoplay.h:
contains the code for the computer AI.
This module simulates keypresses from the computer,
then the computer is handled as any other player.
</elem>
<elem>
move.c / move.h:
provides an API to move the cursors.
</elem>
</list>
</part>
<part title="User input">
<text>
Until 5.4.0, Liquid War did not have network support.
As it is designed to be multiplayer, one needed to have
several players on the same computer. The mouse also
needed to be handled in a special way since cursors
can *not* pass walls in Liquid War. Additionnally,
I wanted all input channels (keyboard mouse and joystick)
to be handled in a unified way.
</text>
<text>
This explains why there's so much code for user input,
when one would think at first sight that
"polling the keyboard is enough".
</text>
<list>
<elem>
joystick.c / joystick.h:
contains code to support joystick input. It wraps joystick buttons
to virtual keyboard keys, so that joystick and keyboard behave
exactly the same.
</elem>
<elem>
keyboard.c / keyboard.h:
contains code to handle key presses.
</elem>
<elem>
mouse.c / mouse.h:
wraps the mouse movements to virtual keyboard keys.
This way the mouse can be used to control the players.
</elem>
</list>
</part>
<part title="Initialisations">
<text>
These files contain functions to intialize various game
components. 100% boring code.
</text>
<list>
<elem>
area.c / area.h:
contains functions to create the game area.
Basically it contains functions to create
the data structures in which the level is
stored during the game.
</elem>
<elem>
army.c / army.h:
functions to create the armies, and place them on the
battlefield.
</elem>
<elem>
asm.c / asm.h:
various constants, macros and utilities to
ensure that asembly code works correctly.
</elem>
<elem>
bigdata.c / bigdata.h:
I had a really hard time with the malloc function with DJGPP
under Win95 dos box. I tried to have it working for hours and
hours but my program kept being buggy. So I decided to allocate
the memory myself, in a memory zone I create at startup.
This is what this module does: create a huge memory zone
and then give parts of it to the rest of the program.
</elem>
<elem>
config.c / config.h:
contains everything that is related to the game configuration.
This module contains in global variables all the parameters
that are stored in the config file.
</elem>
<elem>
cursor.c / cursor.h:
contains the code to init the cursors and place them
on the battlefield at the beginning of the game.
</elem>
<elem>
decal.c / decal.h:
This module makes the link between teams and players.
Its coding is quite ugly, for some modules in LW assume
that when 2 teams are playing they are always teams 0 and 1.
So when 3 teams are playing are playing and the second team loses,
one has to make team 2 become team 1.
That's what this module is for.
</elem>
<elem>
exit.c / exit.h:
contains code that is executed when the game ends,
it shuts down Allegro and displays messages on the console.
</elem>
<elem>
gfxmode.c / gfxmode.h:
contains code to set up the various video modes,
and defines which modes are available for each platform.
</elem>
<elem>
init.c / init.h:
contains code to initialize Allegro with proper options and analyze failures.
</elem>
<elem>
palette.c / palette.h:
contains function to set up the current color palette.
Liquid War uses different palettes, depending on what
colors are chosen for teams.
</elem>
</list>
</part>
<part title="Graphics">
<text>
Here lies most of the graphic functions in Liquid War.
There's not that much code since Liquid War's strength
is not its visual effects, but rather its gameplay.
</text>
<text>
The only "funny" thing is the wave effect. I'm quite
happy with it, and honestly, I do think it is rather fast,
given the fact that it uses no 3D hardware at all.
</text>
<list>
<elem>
disp.c / disp.h:
contains functions to display the battlefield.
</elem>
<elem>
distor.c / distor.h:
this module contains code to create the "wave effect".
It uses a lot of data tables, and is quite complicated
to understand...
</elem>
<elem>
glouglou.s / glouglou.h:
assembly module, it is a replacement for some functions of distor.c.
It goes much faster but does the same.
</elem>
<elem>
info.c / info.h:
contains code to display the info bar.
The info bar is the bar which display the time left and the amount of players
for each team while the game is running.
</elem>
<elem>
message.c / message.h:
provides an API to display messages during the game.
Very useful if you want to debug the game: you can trace
and display anything.
</elem>
<elem>
pion.c / pion.h:
contains code to display the cursors.
</elem>
<elem>
viewport.c / vieport.h:
code to allocate and resize the zone where the map is
displayed, also called "viewport".
</elem>
</list>
</part>
<part title="Sound and music">
<text>
Sound and music routines required some encapsulation,
since the game must be able to run even if the sound and/or
music did not load correctly.
</text>
<list>
<elem>
music.c / music.h:
contains the code to control MIDI playback.
</elem>
<elem>
sound.c / sound.h:
functions to play sound.
</elem>
</list>
</part>
<part title="Data management">
<text>
These functions handle the datafile contents and
also the custom data.
</text>
<text>
Note that the various utilities such as liquidwarcol,
liquidwarmap and liquidwartex do not share code with
the main executable. This is obviously a design error,
for liquidwarmap will handle maps in a very poor
way and is unable to autodetect map errors, whereas
the game does it rather well. Blame the programmer.
</text>
<list>
<elem>
disk.c / disk.h:
contains all the code to access data from the hard drive.
In fact, all the HD access is done at startup.
</elem>
<elem>
map.c / map.h:
contains code to load the maps from a datafile raw data
or a user defined bitmap
to a usable structure in RAM.
</elem>
<elem>
maptex.c / maptex.h:
contains code to handle the "use default texture"
option, and associate a map with a given texture
automatically.
</elem>
<elem>
texture.c / texture.h:
contains code to handle textures.
Textures are stored in a special format which uses
5 bits per pixel.
</elem>
</list>
</part>
<part title="Random map generator">
<text>
Liquid War has a "generate random map" feature which is
available within the game and also as an external program.
The source code for the external program is in ./utils/lwmapgen
in Liquid War source distribution. This program has been
coded by David Redick, is also available on
"http://www.cs.clemson.edu/~dredick/lwmapgen/"
and works on GNU/Linux. Compiling this program under DOS
and/or Windows is untested and unsupported.
</text>
<text>
The random map generator within Liquid War - which of course
works on any platform support by LW - uses for its greater
part the same source code as the external lwmapgen program.
</text>
<list>
<elem>
random.c / random.h:
wrapper for the map generator written by David Redick.
It basically does the same as ./utils/lwmapgen/main.c
except that it does it within Liquid War as it is running
and not in an external independant program.
</elem>
</list>
</part>
<part title="Time handling">
<text>
Time handling is fundamental in a game. Time is used for
visual effects (waves...) during the game, it's used to generate
some pseudo random stuff, well, it's used everywhere!
</text>
<text>
Note that on the client, I use 2 "different" clocks. The first
counts the "real" time, in seconds. The second one is counts "rounds"
and is incremented by 1 at each game round.
</text>
<list>
<elem>
srvtime.c / srvtime.h:
code used to handle time on the server, where Allegro's functions
are not available.
</elem>
<elem>
ticker.c / ticker.h:
sets up a timer callback.
</elem>
<elem>
time.c / time.h:
functions to know how long the game has been running,
knowing that it can be interrupted.
</elem>
</list>
</part>
<part title="In-game utilities">
<text>
These are various utilities use to monitor and control
the game while one's playing.
</text>
<list>
<elem>
capture.c / capture.h:
code used to capture the video output of the game and store it
in .bmp files while playing.
</elem>
<elem>
checksum.c / checksum.h:
utilities to generate a checksum from a given game state.
Used in network code to make sure all the clients stay
synchronized.
</elem>
<elem>
code.c / code.h:
This file contains the code to handle key presses during
the game. That's to say the pause key for instance.
</elem>
<elem>
profile.c / profile.h:
provides tools to calculate how fast the game is runnning
and what operations slow it down.
</elem>
<elem>
watchdog.c / watchdog.h:
this module waits for "secret codes" to be typed while
the game is running, and traps them.
</elem>
</list>
</part>
<part title="Command line handling">
<text>
OK, now to all the UNIX guys, I *know* there are many
ways to do things in a better and simple way than I did.
But keep in mind that in 1998, under DOS, I had a rotten command
line and even now I need everything to work on both UNIX and
Microsoft platforms.
</text>
<text>
These utilities are not perfect, but they work, that's all
I ask them.
</text>
<list>
<elem>
basicopt.c / basicopt.h:
handles basic command line parameters such as "-v" or "-h".
</elem>
<elem>
parser.c / parser.h:
contains code to parse and analyze the command line parameters.
</elem>
<elem>
startup.c / startup.h:
analyzes the command line parameters and stores them
into global variables.
</elem>
</list>
</part>
<part title="Locale support">
<text>
Liquid War now has locale support. Basically, all the
labels and texts in the UI are stored in constants.
There's simply file per language.
</text>
<text>
Note to translators: if you decide to translate the
menus in another language, keep in mind that all the
translations must fit in the various buttons and textboxes.
The best resolution to test this
- the one where letters take most place - is 640x480.
</text>
<list>
<elem>
lang.c / lang.h:
contains code to handle language dependant stuff.
</elem>
<elem>
langen.c / langen.h:
contains code to handle English specific stuff.
</elem>
<elem>
langfr.c / langfr.h:
contains code to handle French specific stuff.
</elem>
</list>
</part>
<part title="Log and various messages">
<text>
OK, the API of the log routines is a piece of crap.
Now I'm simply too lazy to change it. It works, that's
all I ask.
</text>
<text>
BTW, there's a clear advantage in using custom-made
log functions instead of plain calls to "fprintf(stderr,...".
It might not be obvious for UNIX users, but think about
Windows. Nothing like a "tail -f" there, nor a proper
output redirection system. When a user clicks on the
Liquid War icon, I want "console" information to be logged
in a file!
</text>
<list>
<elem>
log.h:
common header for logcli.c and logsrv.c.
</elem>
<elem>
logcli.c:
contains code to display messages on the console.
It's usefull for console may have different behaviors
when the games is used on different platforms.
This file is used to compile the client.
</elem>
<elem>
logsrv.c:
contains code to display messages on the console.
This file is used to compile the server, which does not
use Allegro at all.
</elem>
<elem>
popupgen.h:
common header for popup functions.
</elem>
<elem>
popupw32.c:
code to handle popup on the Win32 platform. Popups are a must-have
under Windows for error diagnostics, since the average Windows user
never gives any look at any log file...
</elem>
</list>
</part>
<part title="Macros, utilities and string support">
<text>
As usual, I needed to prepare a small set of usefull macros.
</text>
<list>
<elem>
macro.h:
contains basic wrappers/macros for
snprintf like functions. This mostly to ease up string
manipulation which is - as always - a nightmare in standard C.
</elem>
<elem>
path.c / path.h:
code used to handle filenames and paths, for instance remove
path and file extension from a filename.
</elem>
</list>
<text>
It's also important to note that Liquid War uses snprintf instead
of sprintf, for using the latter is very likely to cause buffer
overflows. Under Linux glibc provides this function but Microsoft
does not provide it natively on Windows. Therefore I used a
third party snprintf implementation by Mark Martinec:
"http://www.ijs.si/software/snprintf/" and its source is available
in the ./utils directory of Liquid War source distribution.
</text>
</part>
<part title="Byte order and endianess">
<text>
As you might know, PC Intel based computers are "little-endian"
while Sun Sparc stations and Mac computers are "big-endian".
This is an issue for LW since in network games maps are transmitted
in binary format. Therefore I needed to set up some
(un)serialization fonctions.
</text>
<list>
<elem>
serial.c / serial.h:
code used to transform integers and map headers into an uniform
cross-platform byte stream which is readable by both little and
big endian machines.
</elem>
</list>
</part>
<part title="Thread support">
<text>
Liquid War does have thread support, but it is a "limited"
thread support. I mean that the game is generally monothreaded,
but a few functions use threads. For instance, calls to
the meta-server are done within threads.
</text>
<text>
Basically, I do not really enjoy programming in a multithreaded
environnement. So when possible, I chose the monothread path,
and used threads only where I simply would not be able to
find another acceptable solution.
</text>
<text>
I also needed to use some mutexes to prevent crashes in the
user interface.
</text>
<list>
<elem>
mutxdos.c:
provides fake mutex support under DOS.
This module is here only to make compilation easier.
</elem>
<elem>
mutxgen.h:
header for mutxdos.c, mutxunix.c and mutxw32.c.
</elem>
<elem>
mutxunix.c:
provides mutex support on UNIX.
</elem>
<elem>
mutxw32.c:
provides mutex support on Win32.
</elem>
<elem>
thrddos.c:
provides fake thread support under DOS.
This module is here only to make compilation easier.
</elem>
<elem>
thrdgen.h:
header for thrddos.c, thrdunix.c and thrdw32.c.
</elem>
<elem>
thrdunix.c:
provides thread support on UNIX.
</elem>
<elem>
thrdw32.c:
provides thread support on Win32.
</elem>
</list>
</part>
<part title="Launching external programs">
<text>
Liquid War might sometimes launch external programs.
This is (for security reason) not a default behavior and has
to be activated and configured by yourself, using the "-callback"
command line option on the server for instance.
</text>
<list>
<elem>
execgen.h:
header for execunix.c and execw32.c.
</elem>
<elem>
execunix.c:
code to launch external programs on UNIX.
</elem>
<elem>
execw32.c:
code to launch external programs on Win32.
</elem>
<elem>
exec2.c:
code to launch external programs within the client, without any
interaction with the user, ie no unwanted popping window for instance.
</elem>
</list>
</part>
<part title="Low-level network code">
<text>
There are network packages for Allegro, but I decided not to
use them. Socket support is not that hard to implement under UNIX
and Win32 and besides, I've done it for my job recently, so I just
knew how to do it.
</text>
<text>
Another reason which decided me to code my own toolbox is that
I did not want Liquid War to have external dependencies - except
Allegro of course. This way, UNIX gamers to not have to set up and/or
download a specific network library. It's also easier to integrate
the game in projects like Debian if it has few dependencies.
</text>
<text>
This network code is not a masterpiece, it's just a little set
of tools that have proven to work. That's all.
</text>
<text>
BTW, it's important to notice that when linking with Allegro,
most blocking UNIX calls ("sleep" or "recv" for instance) stop
working: they alwasys return immediately. This led me to
implement weird ugly hacks, like calling "recv" in a loop until
it gets what it wants... This is theorically and practically
a performance killer, but I found no other way to fix this.
And FYI, this is not an Allegro bug, it's a feature 8-)
</text>
<list>
<elem>
dnsutil.c / dnsutil.h:
wrapper code to issue DNS requests, without having
to handle the hostent struct.
</elem>
<elem>
sock2cli.c:
sode used to wrap low-level network function on the client.
</elem>
<elem>
sock2gen.h:
header for sock2cli.c and sock2srv.c.
</elem>
<elem>
sock2srv.c:
code used to wrap low-level network function on the server.
</elem>
<elem>
sockdos.c:
network API for DOS.
</elem>
<elem>
sockex.c:
netowrk routines shared by sockunix and sockw32.
</elem>
<elem>
sockgen.h:
header for sockdos.c, sockunix.c and sockw32.c.
</elem>
<elem>
sockunix.c:
network API for UNIX.
</elem>
<elem>
sockw32.c:
network API for Win32.
</elem>
</list>
</part>
<part title="High-level network code">
<text>
These files contains network utilities
which are Liquid War specific.
</text>
<list>
<elem>
chat.c / chat.h:
functions used to handle chat messages in network games.
</elem>
<elem>
keyexch.c / keyexch.h:
functions to send and receive keys to the server. Used on the
client.
</elem>
<elem>
netconf.c / netconf.h:
code to send and receive the config of the clients over the network.
</elem>
<elem>
netkey.c / netkey.h:
contains some tools to manipulate key strokes over the network.
</elem>
<elem>
netmap.c / netmap.h:
code to send and receive the maps over the network.
</elem>
<elem>
netmess.c / netmess.h:
contains a parser to interpret plain text messages. Used when
exhanging information over the network.
</elem>
<elem>
netplay.c / netplay.h:
contains the code to set up and start network games.
</elem>
<elem>
network.c / network.h:
contains some network related functions and constants used on
the client.
</elem>
<elem>
ping.c / ping.h:
code used on the client to estimate the average ping time
with a server.
</elem>
<elem>
protocol.c / protocol.h:
contains the sequence of messages send and recevied by the
client when connecting on the server.
</elem>
<elem>
startinf.c / startinf.h:
contains struct and tools to handle some network informations while
starting a network game.
</elem>
</list>
</part>
<part title="Communication with the meta-server">
<text>
The meta-server is called by both client and server.
Basically, the server registers itself, and the client
asks for a list of servers.
</text>
<text>
The meta-server itself is just a set of simple PHP scripts
with a simple MySQL database. I chose PHP because my
provider allows execution of PHP pages, that's all.
</text>
<text>
The protocol is *very* basic, and uses HTTP 1.0 for
requests. Answers are received in plain text, with
one information per line. There's no garantee that
this would work with any HTTP server, but experience
proved that it works with my provider 8-)
</text>
<list>
<elem>
httputil.c / httputil.h:
low level functions to handle http requests.
</elem>
<elem>
wwwcli.c / wwwcli.h:
code used on the client to communicate with the meta-server.
</elem>
<elem>
wwwsrv.c / wwwsrv.h:
code used on the server to communicate with the meta-server.
</elem>
</list>
</part>
<part title="Server code">
<text>
The Liquid War server is a rather small program. The only
thing it does is accept new players, transmit map and
game parameters between them, and then "replicate keys".
</text>
<text>
By "replicate keys" I mean that the server asks each client
what keys have been pressed during the last round, and
then dispatches this informations to all clients.
This implies that the server has absolutely no idea of
who's loosing, who's winning, etc...
</text>
<text>
All the "logic" of the server is coded in these files,
the rest is only utilities and helper functions.
</text>
<list>
<elem>
server.c / server.h:
main code for the server (equivalent of main.c for the client).
</elem>
<elem>
srvchan.c / srvchan.h:
code used to handles channels on the server. A channel is associated
to a given computer and may manage several teams.
</elem>
<elem>
srvcont.c / srvcont.h:
global network controler used on the server.
</elem>
<elem>
srvteam.c / srvteam.h:
code used to handle teams on the server.
</elem>
</list>
</part>
</chap>
</file>
|