18 void P_ArchivePlayers(void)
24 for(i = 0; i < MAXPLAYERS; i++)
30 memcpy(&dest, &players[i], sizeof(player_t));
31 for(j = 0; j < NUMPSPRITES; j++)
33 if(dest.psprites[j].state)
35 dest.psprites[j].state =
36 (state_t *)(dest.psprites[j].state-states);
39 SV_Write(&dest, sizeof(player_t));
51 void P_UnArchivePlayers (void)
55 for (i=0 ; i<MAXPLAYERS ; i++)
59 memcpy (&players[i],save_p, sizeof(player_t));
60 save_p += sizeof(player_t);
61 players[i].mo = NULL; // will be set when unarc thinker
62 players[i].message = NULL;
63 players[i].attacker = NULL;
64 for (j=0 ; j<NUMPSPRITES ; j++)
65 if (players[i]. psprites[j].state)
66 players[i]. psprites[j].state
67 = &states[ (int)players[i].psprites[j].state ];
71 //=============================================================================
82 void P_ArchiveWorld(void)
90 for(i = 0, sec = sectors; i < numsectors; i++, sec++)
92 SV_WriteWord(sec->floorheight>>FRACBITS);
93 SV_WriteWord(sec->ceilingheight>>FRACBITS);
94 SV_WriteWord(sec->floorpic);
95 SV_WriteWord(sec->ceilingpic);
96 SV_WriteWord(sec->lightlevel);
97 SV_WriteWord(sec->special); // needed?
98 SV_WriteWord(sec->tag); // needed?
102 for(i = 0, li = lines; i < numlines; i++, li++)
104 SV_WriteWord(li->flags);
105 SV_WriteWord(li->special);
106 SV_WriteWord(li->tag);
107 for(j = 0; j < 2; j++)
109 if(li->sidenum[j] == -1)
113 si = &sides[li->sidenum[j]];
114 SV_WriteWord(si->textureoffset>>FRACBITS);
115 SV_WriteWord(si->rowoffset>>FRACBITS);
116 SV_WriteWord(si->toptexture);
117 SV_WriteWord(si->bottomtexture);
118 SV_WriteWord(si->midtexture);
131 void P_UnArchiveWorld (void)
139 get = (short *)save_p;
144 for (i=0, sec = sectors ; i<numsectors ; i++,sec++)
146 sec->floorheight = *get++ << FRACBITS;
147 sec->ceilingheight = *get++ << FRACBITS;
148 sec->floorpic = *get++;
149 sec->ceilingpic = *get++;
150 sec->lightlevel = *get++;
151 sec->special = *get++; // needed?
152 sec->tag = *get++; // needed?
153 sec->specialdata = 0;
154 sec->soundtarget = 0;
160 for (i=0, li = lines ; i<numlines ; i++,li++)
163 li->special = *get++;
165 for (j=0 ; j<2 ; j++)
167 if (li->sidenum[j] == -1)
169 si = &sides[li->sidenum[j]];
170 si->textureoffset = *get++ << FRACBITS;
171 si->rowoffset = *get++ << FRACBITS;
172 si->toptexture = *get++;
173 si->bottomtexture = *get++;
174 si->midtexture = *get++;
178 save_p = (byte *)get;
181 //=============================================================================
197 void P_ArchiveThinkers(void)
202 for(th = thinkercap.next; th != &thinkercap; th = th->next)
204 if(th->function == P_MobjThinker)
206 SV_WriteByte(tc_mobj);
207 memcpy(&mobj, th, sizeof(mobj_t));
208 mobj.state = (state_t *)(mobj.state-states);
211 mobj.player = (player_t *)((mobj.player-players)+1);
213 SV_Write(&mobj, sizeof(mobj_t));
216 //I_Error("P_ArchiveThinkers: Unknown thinker function");
219 // Add a terminating marker
220 SV_WriteByte(tc_end);
226 = P_UnArchiveThinkers
231 void P_UnArchiveThinkers (void)
234 thinker_t *currentthinker, *next;
238 // remove all the current thinkers
240 currentthinker = thinkercap.next;
241 while (currentthinker != &thinkercap)
243 next = currentthinker->next;
244 if (currentthinker->function == P_MobjThinker)
245 P_RemoveMobj ((mobj_t *)currentthinker);
247 Z_Free (currentthinker);
248 currentthinker = next;
252 // read in saved thinkers
259 return; // end of list
262 mobj = Z_Malloc (sizeof(*mobj), PU_LEVEL, NULL);
263 memcpy (mobj, save_p, sizeof(*mobj));
264 save_p += sizeof(*mobj);
265 mobj->state = &states[(int)mobj->state];
269 mobj->player = &players[(int)mobj->player-1];
270 mobj->player->mo = mobj;
272 P_SetThingPosition (mobj);
273 mobj->info = &mobjinfo[mobj->type];
274 mobj->floorz = mobj->subsector->sector->floorheight;
275 mobj->ceilingz = mobj->subsector->sector->ceilingheight;
276 mobj->thinker.function = P_MobjThinker;
277 P_AddThinker (&mobj->thinker);
281 I_Error ("Unknown tclass %i in savegame",tclass);
288 //=============================================================================
310 void P_ArchiveSpecials(void)
313 T_MoveCeiling, (ceiling_t: sector_t * swizzle), - active list
314 T_VerticalDoor, (vldoor_t: sector_t * swizzle),
315 T_MoveFloor, (floormove_t: sector_t * swizzle),
316 T_LightFlash, (lightflash_t: sector_t * swizzle),
317 T_StrobeFlash, (strobe_t: sector_t *),
318 T_Glow, (glow_t: sector_t *),
319 T_PlatRaise, (plat_t: sector_t *), - active list
331 for(th = thinkercap.next; th != &thinkercap; th = th->next)
333 if(th->function == T_MoveCeiling)
335 SV_WriteByte(tc_ceiling);
336 memcpy(&ceiling, th, sizeof(ceiling_t));
337 ceiling.sector = (sector_t *)(ceiling.sector-sectors);
338 SV_Write(&ceiling, sizeof(ceiling_t));
341 if(th->function == T_VerticalDoor)
343 SV_WriteByte(tc_door);
344 memcpy(&door, th, sizeof(vldoor_t));
345 door.sector = (sector_t *)(door.sector-sectors);
346 SV_Write(&door, sizeof(vldoor_t));
349 if(th->function == T_MoveFloor)
351 SV_WriteByte(tc_floor);
352 memcpy(&floor, th, sizeof(floormove_t));
353 floor.sector = (sector_t *)(floor.sector-sectors);
354 SV_Write(&floor, sizeof(floormove_t));
357 if(th->function == T_PlatRaise)
359 SV_WriteByte(tc_plat);
360 memcpy(&plat, th, sizeof(plat_t));
361 plat.sector = (sector_t *)(plat.sector-sectors);
362 SV_Write(&plat, sizeof(plat_t));
365 if(th->function == T_LightFlash)
367 SV_WriteByte(tc_flash);
368 memcpy(&flash, th, sizeof(lightflash_t));
369 flash.sector = (sector_t *)(flash.sector-sectors);
370 SV_Write(&flash, sizeof(lightflash_t));
373 if(th->function == T_StrobeFlash)
375 SV_WriteByte(tc_strobe);
376 memcpy(&strobe, th, sizeof(strobe_t));
377 strobe.sector = (sector_t *)(strobe.sector-sectors);
378 SV_Write(&strobe, sizeof(strobe_t));
381 if(th->function == T_Glow)
383 SV_WriteByte(tc_glow);
384 memcpy(&glow, th, sizeof(glow_t));
385 glow.sector = (sector_t *)(glow.sector-sectors);
386 SV_Write(&glow, sizeof(glow_t));
390 // Add a terminating marker
391 SV_WriteByte(tc_endspecials);
397 = P_UnArchiveSpecials
402 void P_UnArchiveSpecials (void)
414 // read in saved thinkers
421 return; // end of list
424 ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVEL, NULL);
425 memcpy (ceiling, save_p, sizeof(*ceiling));
426 save_p += sizeof(*ceiling);
427 ceiling->sector = §ors[(int)ceiling->sector];
428 ceiling->sector->specialdata = T_MoveCeiling;
429 if (ceiling->thinker.function)
430 ceiling->thinker.function = T_MoveCeiling;
431 P_AddThinker (&ceiling->thinker);
432 P_AddActiveCeiling(ceiling);
436 door = Z_Malloc (sizeof(*door), PU_LEVEL, NULL);
437 memcpy (door, save_p, sizeof(*door));
438 save_p += sizeof(*door);
439 door->sector = §ors[(int)door->sector];
440 door->sector->specialdata = door;
441 door->thinker.function = T_VerticalDoor;
442 P_AddThinker (&door->thinker);
446 floor = Z_Malloc (sizeof(*floor), PU_LEVEL, NULL);
447 memcpy (floor, save_p, sizeof(*floor));
448 save_p += sizeof(*floor);
449 floor->sector = §ors[(int)floor->sector];
450 floor->sector->specialdata = T_MoveFloor;
451 floor->thinker.function = T_MoveFloor;
452 P_AddThinker (&floor->thinker);
456 plat = Z_Malloc (sizeof(*plat), PU_LEVEL, NULL);
457 memcpy (plat, save_p, sizeof(*plat));
458 save_p += sizeof(*plat);
459 plat->sector = §ors[(int)plat->sector];
460 plat->sector->specialdata = T_PlatRaise;
461 if (plat->thinker.function)
462 plat->thinker.function = T_PlatRaise;
463 P_AddThinker (&plat->thinker);
464 P_AddActivePlat(plat);
468 flash = Z_Malloc (sizeof(*flash), PU_LEVEL, NULL);
469 memcpy (flash, save_p, sizeof(*flash));
470 save_p += sizeof(*flash);
471 flash->sector = §ors[(int)flash->sector];
472 flash->thinker.function = T_LightFlash;
473 P_AddThinker (&flash->thinker);
477 strobe = Z_Malloc (sizeof(*strobe), PU_LEVEL, NULL);
478 memcpy (strobe, save_p, sizeof(*strobe));
479 save_p += sizeof(*strobe);
480 strobe->sector = §ors[(int)strobe->sector];
481 strobe->thinker.function = T_StrobeFlash;
482 P_AddThinker (&strobe->thinker);
486 glow = Z_Malloc (sizeof(*glow), PU_LEVEL, NULL);
487 memcpy (glow, save_p, sizeof(*glow));
488 save_p += sizeof(*glow);
489 glow->sector = §ors[(int)glow->sector];
490 glow->thinker.function = T_Glow;
491 P_AddThinker (&glow->thinker);
495 I_Error ("P_UnarchiveSpecials:Unknown tclass %i "
496 "in savegame",tclass);
506 ===============================================================================
510 All thinkers should be allocated by Z_Malloc so they can be operated on uniformly. The actual
511 structures will vary in size, but the first element must be thinker_t.
513 ===============================================================================
516 thinker_t thinkercap; // both the head and tail of the thinker list
526 void P_InitThinkers (void)
528 thinkercap.prev = thinkercap.next = &thinkercap;
537 = Adds a new thinker at the end of the list
542 void P_AddThinker (thinker_t *thinker)
544 thinkercap.prev->next = thinker;
545 thinker->next = &thinkercap;
546 thinker->prev = thinkercap.prev;
547 thinkercap.prev = thinker;
555 = Deallocation is lazy -- it will not actually be freed until its
556 = thinking turn comes up
561 void P_RemoveThinker (thinker_t *thinker)
563 thinker->function = (think_t)-1;
571 = Allocates memory and adds a new thinker at the end of the list
576 void P_AllocateThinker (thinker_t *thinker)
589 void P_RunThinkers (void)
591 thinker_t *currentthinker;
593 currentthinker = thinkercap.next;
594 while (currentthinker != &thinkercap)
596 if (currentthinker->function == (think_t)-1)
597 { // time to remove it
598 currentthinker->next->prev = currentthinker->prev;
599 currentthinker->prev->next = currentthinker->next;
600 Z_Free (currentthinker);
604 if (currentthinker->function)
605 currentthinker->function (currentthinker);
607 currentthinker = currentthinker->next;
611 //----------------------------------------------------------------------------
615 //----------------------------------------------------------------------------
625 for(i = 0; i < MAXPLAYERS; i++)
629 P_PlayerThink(&players[i]);