kb1
Junior Member
Posts: 229
Registered: 11-06 |
Ok, here's your weekend homework...
code:
****** STEP 1: Translate and add the following code. I decided to just go ahead and give you ALL of the instrumentation I use *
when tracking down sync problems. By the way, this code works equally well when trying to synchronize net games.
******
[d_main.c:(global scope)]
FILE *syncdebugfile;
[d_main.c:D_DoomMain (somewhere near top of function)]
// [kb] open the sync debug file
syncdebugfile = fopen("syncdbg.txt", "a");
fprintf(syncdebugfile, "*** Debugging started ***\n");
[(in your shutdown code)]
// [kb] be sure to close the file proper on program shutdown
fprintf(syncdebugfile, "*** Debugging stopped ***\n");
fclose(syncdebugfile);
[m_random.c:P_Random (replace whole function)]
int P_Random (int caller)
{
prndindex = (prndindex + 1) & 0xFF;
fprintf(syncdebugfile,"PR #%i [%i]=%i\n", (int)caller, (int)prndindex, (int)rndtable[prndindex]);
return rndtable[prndindex];
}
[p_inter.c:P_KillMobj (at the top of the function)]
if (source)
{
fprintf(syncdebugfile, "KillMobj src %i [%i] xyz=%i %i %i\n",
source->type, source->info->doomednum,
source->x, source->y, source->z);
}
fprintf(syncdebugfile, "KillMobj targ %i [%i] xyz=%i %i %i\n",
target->type, target->info->doomednum,
target->x, target->y, target->z);
[p_inter.c:P_DamageMobj (at the top of the function)]
fprintf(syncdebugfile, "DamageMobj Targ %i [%i] xyz=%i %i %i\n",
target->type, target->info->doomednum, target->x, target->y, target->z);
if (inflictor)
fprintf(syncdebugfile, "DamageMobj Infl %i [%i] xyz=%i %i %i\n",
inflictor->type, inflictor->info->doomednum,
inflictor->x, inflictor->y, inflictor->z);
if (source)
fprintf(syncdebugfile, "DamageMobj Src %i [%i] xyz=%i %i %i dtype %i\n",
source->type, source->info->doomednum,
source->x, source->y, source->z, damagetype);
[p_mobj.c:P_MobjThinker (at the top of the function)]
if (mobj->momx || mobj->momy)
{
fprintf(syncdebugfile,
"Mobj %i (%i) xyz %i,%i,%i (%i,%i,%i) mom %i,%i h=%i fl=%i\n",
mobj->info->doomednum, mobj->type, mobj->x, mobj->y,
mobj->z, mobj->x >> 16, mobj->y >> 16, mobj->z >> 16, mobj->momx,
mobj->momy, mobj->health, mobj->flags);
}
[p_mobj.c:P_SpawnMobj (near the top of the function, after "info" is valid)]
fprintf(syncdebugfile,
"Spn %i (%i) xyz %i,%i,%i\n",
(int)type, info->doomednum, x, y, z);
[p_tick.c:P_Ticker (at the top of the function)]
fprintf(syncdebugfile, "\n--- TIC %i ---\n", gametic);
[p_user.c:P_PlayerThink (at the top of the function)]
fprintf(syncdebugfile,
"Plr %i xyzpvv %i,%i,%i,%i,%i (%i,%i,%i) mom=%i,%i h=%i\n",
player->mo->info->doomednum, player->mo->x, player->mo->y, player->mo->z,
player->viewheight, player->viewz,
player->mo->x >> 16, player->mo->y >> 16, player->mo->z >> 16,
player->mo->momx, player->mo->momy, player->mo->health);
****** STEP 2: The hard part :) This part is difficult, simply because there's a lot of entries. Here we add enums to every instance of P_Random. See below:
// The following is just an example, please add your own. Basically, you want to create a new name for each instance of P_Random
// in your code, by creating a descriptive enum for each, and using the enum as an argument to each P_Random call.
//
// I was going to provide the list, but, my game has many hundreds of them, that don't all apply to Doom. Once you
// create your list, be sure to send me your enums so I can map them to my numbers (shouldn't be too difficult - I assume you
// followed the layout of v1.10 closely??). In naming them, please follow these guidelines:
//
// 1. Name should be short, but descriptive, and should really match the function name.
// 2. Follow multiple entries within the same function, with a number (like "pr_facetarget2").
// 3. Make sure they're unique, and that you covered them all.
// 4. Put the actual value in a comment as below. It'll suck otherwise.
[m_random.h: (Example enum list)]
typedef enum
{
...
pr_facetarget1, // 0
pr_facetarget2, // 1
pr_posattack, // 2
...
pr_bfgspray, // 57
...
} random_t;
[Here's an example of using the enum in a P_Random call]
damage += (P_Random(pr_bfgspray) & 7) + 1;
***********************
* STEP 3: Compile! *
***********************
Actually, here's the whole sequence:
1. Compile.
2. Run.
3. Load demo in question.
4. A syncdbg.txt file should be getting written. warning: The file will not grow too big for the iwad demos.
5. Stop the program when the demo goes out of sync.
6. Send me your enum list.
7. Send me your syncdbg.txt file - it will compress to a reasonable size.
*************
* NOTES: *
*************
The goal here is that you generate a syncdbg.txt file that, when compared with my syncdbg.txt file, will match byte-for-byte, if both
games are in sync. So, please be very careful when typing the file output strings, and be sure you're outputting signed 32-bit ints.
It's a bit of work to add the instrumentation. If I were you, I would place it all under conditional compile (except for the P_Random
entries - it's a bit difficult to conditionally compile them with/without that enum argument!).
Here's is what the output of tic 446 (~8 seconds in) of the first UD v1.9 demo looks like:
code:
--- TIC 446 ---
Plr -1 xyzpvv -10463644,-499023,0,2686976,2212600 (-160,-8,0) mom=685189,-81469 h=98
Mobj -1 (0) xyz -10463644,-499023,0 (-160,-8,0) mom 787090,-71394 h=98 fl=33557574
PR #2 [220]=123
PR #6 [221]=251
PR #23 [222]=26
PR #23 [223]=36
PR #30 [224]=17
PR #30 [225]=46
PR #31 [226]=52
PR #418 [227]=231
PR #418 [228]=232
Spn 38 (-1) xyz -9360852,-1582141,1895971
PR #395 [229]=76
PR #419 [230]=31
DamageMobj Targ 0 [-1] xyz=-9676554 -570417 0
DamageMobj Infl 2 [9] xyz=-9813184 -8992320 0
DamageMobj Src 2 [9] xyz=-9813184 -8992320 0 dtype 9
PR #358 [231]=221
PR #30 [232]=84
PR #30 [233]=37
PR #31 [234]=216
PR #418 [235]=165
PR #418 [236]=212
Spn 38 (-1) xyz -10213577,-1798670,1862513
PR #395 [237]=106
PR #419 [238]=197
DamageMobj Targ 0 [-1] xyz=-9676554 -570417 0
DamageMobj Infl 2 [9] xyz=-9813184 -8992320 0
DamageMobj Src 2 [9] xyz=-9813184 -8992320 0 dtype 9
PR #358 [239]=242
PR #30 [240]=98
PR #30 [241]=43
PR #31 [242]=39
PR #418 [243]=175
PR #418 [244]=254
Spn 38 (-1) xyz -10296023,-1889875,1835101
PR #395 [245]=145
PR #419 [246]=190
DamageMobj Targ 0 [-1] xyz=-9676554 -570417 0
DamageMobj Infl 2 [9] xyz=-9813184 -8992320 0
DamageMobj Src 2 [9] xyz=-9813184 -8992320 0 dtype 9
PR #358 [247]=84
Note: Your numbers after "PR #" will be different, but everything else should be the same. Good luck!
|