2006-03-20 17:12:09 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING . txt .
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below .
* See COPYING . txt for license details .
2006-03-20 17:12:09 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ( " PARALLAX " ) . PARALLAX , IN DISTRIBUTING THE CODE TO
END - USERS , AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN , GRANTS A
ROYALTY - FREE , PERPETUAL LICENSE TO SUCH END - USERS FOR USE BY SUCH END - USERS
IN USING , DISPLAYING , AND CREATING DERIVATIVE WORKS THEREOF , SO LONG AS
SUCH USE , DISPLAY OR CREATION IS FOR NON - COMMERCIAL , ROYALTY OR REVENUE
FREE PURPOSES . IN NO EVENT SHALL THE END - USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE - BEARING PURPOSES . THE END - USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE .
COPYRIGHT 1993 - 1999 PARALLAX SOFTWARE CORPORATION . ALL RIGHTS RESERVED .
*/
/*
*
* Code to make a complete demo playback system .
*
*/
2015-09-09 03:27:52 +00:00
# include <cstdlib>
2015-02-28 22:34:07 +00:00
# include <ctime>
2006-03-20 17:12:09 +00:00
# include <stdio.h>
# include <stdarg.h>
# include <errno.h>
2010-07-19 18:17:08 +00:00
# include <ctype.h>
2006-03-20 17:12:09 +00:00
# include "u_mem.h"
# include "inferno.h"
# include "game.h"
# include "gr.h"
# include "bm.h"
# include "3d.h"
2015-07-25 23:10:45 +00:00
# include "weapon.h"
2006-03-20 17:12:09 +00:00
# include "segment.h"
2013-12-26 04:18:28 +00:00
# include "strutil.h"
2006-03-20 17:12:09 +00:00
# include "texmap.h"
# include "laser.h"
# include "key.h"
# include "gameseg.h"
# include "object.h"
# include "physics.h"
# include "slew.h"
# include "render.h"
# include "wall.h"
# include "vclip.h"
2015-04-02 02:36:57 +00:00
# include "robot.h"
2006-03-20 17:12:09 +00:00
# include "fireball.h"
# include "laser.h"
2012-07-07 18:35:06 +00:00
# include "dxxerror.h"
2006-03-20 17:12:09 +00:00
# include "ai.h"
# include "hostage.h"
# include "morph.h"
2015-04-19 04:18:49 +00:00
# include "physfs_list.h"
2006-03-20 17:12:09 +00:00
# include "powerup.h"
# include "fuelcen.h"
# include "sounds.h"
# include "collide.h"
# include "lighting.h"
# include "newdemo.h"
# include "gameseq.h"
2015-04-19 04:18:51 +00:00
# include "hudmsg.h"
2006-03-20 17:12:09 +00:00
# include "gamesave.h"
# include "gamemine.h"
# include "switch.h"
# include "gauges.h"
# include "player.h"
# include "vecmat.h"
2010-06-20 20:32:30 +00:00
# include "menu.h"
2006-03-20 17:12:09 +00:00
# include "args.h"
# include "palette.h"
# include "multi.h"
# include "text.h"
# include "cntrlcen.h"
# include "aistruct.h"
# include "mission.h"
# include "piggy.h"
2009-11-15 08:22:08 +00:00
# include "console.h"
# include "controls.h"
# include "playsave.h"
2006-03-20 17:12:09 +00:00
# ifdef EDITOR
# include "editor/editor.h"
# endif
2013-12-31 22:52:00 +00:00
# include "dxxsconf.h"
# include "compiler-type_traits.h"
2014-04-27 23:12:34 +00:00
# include "compiler-range_for.h"
2014-10-12 23:05:46 +00:00
# include "highest_valid.h"
2014-04-27 23:12:34 +00:00
# include "partial_range.h"
2013-12-31 22:52:00 +00:00
2009-11-15 08:22:08 +00:00
# define ND_EVENT_EOF 0 // EOF
# define ND_EVENT_START_DEMO 1 // Followed by 16 character, NULL terminated filename of .SAV file to use
# define ND_EVENT_START_FRAME 2 // Followed by integer frame number, then a fix FrameTime
# define ND_EVENT_VIEWER_OBJECT 3 // Followed by an object structure
# define ND_EVENT_RENDER_OBJECT 4 // Followed by an object structure
# define ND_EVENT_SOUND 5 // Followed by int soundum
# define ND_EVENT_SOUND_ONCE 6 // Followed by int soundum
# define ND_EVENT_SOUND_3D 7 // Followed by int soundum, int angle, int volume
2010-06-18 08:22:45 +00:00
# define ND_EVENT_WALL_HIT_PROCESS 8 // Followed by int segnum, int side, fix damage
2009-11-15 08:22:08 +00:00
# define ND_EVENT_TRIGGER 9 // Followed by int segnum, int side, int objnum
# define ND_EVENT_HOSTAGE_RESCUED 10 // Followed by int hostage_type
# define ND_EVENT_SOUND_3D_ONCE 11 // Followed by int soundum, int angle, int volume
# define ND_EVENT_MORPH_FRAME 12 // Followed by ? data
# define ND_EVENT_WALL_TOGGLE 13 // Followed by int seg, int side
# define ND_EVENT_HUD_MESSAGE 14 // Followed by char size, char * string (+null)
# define ND_EVENT_CONTROL_CENTER_DESTROYED 15 // Just a simple flag
# define ND_EVENT_PALETTE_EFFECT 16 // Followed by short r,g,b
# define ND_EVENT_PLAYER_ENERGY 17 // followed by byte energy
# define ND_EVENT_PLAYER_SHIELD 18 // followed by byte shields
# define ND_EVENT_PLAYER_FLAGS 19 // followed by player flags
# define ND_EVENT_PLAYER_WEAPON 20 // followed by weapon type and weapon number
# define ND_EVENT_EFFECT_BLOWUP 21 // followed by segment, side, and pnt
# define ND_EVENT_HOMING_DISTANCE 22 // followed by homing distance
# define ND_EVENT_LETTERBOX 23 // letterbox mode for death seq.
# define ND_EVENT_RESTORE_COCKPIT 24 // restore cockpit after death
# define ND_EVENT_REARVIEW 25 // going to rear view mode
# define ND_EVENT_WALL_SET_TMAP_NUM1 26 // Wall changed
# define ND_EVENT_WALL_SET_TMAP_NUM2 27 // Wall changed
# define ND_EVENT_NEW_LEVEL 28 // followed by level number
# define ND_EVENT_MULTI_CLOAK 29 // followed by player num
# define ND_EVENT_MULTI_DECLOAK 30 // followed by player num
# define ND_EVENT_RESTORE_REARVIEW 31 // restore cockpit after rearview mode
# define ND_EVENT_MULTI_DEATH 32 // with player number
# define ND_EVENT_MULTI_KILL 33 // with player number
# define ND_EVENT_MULTI_CONNECT 34 // with player number
# define ND_EVENT_MULTI_RECONNECT 35 // with player number
# define ND_EVENT_MULTI_DISCONNECT 36 // with player number
# define ND_EVENT_MULTI_SCORE 37 // playernum / score
# define ND_EVENT_PLAYER_SCORE 38 // followed by score
# define ND_EVENT_PRIMARY_AMMO 39 // with old/new ammo count
# define ND_EVENT_SECONDARY_AMMO 40 // with old/new ammo count
# define ND_EVENT_DOOR_OPENING 41 // with segment/side
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
# define ND_EVENT_LASER_LEVEL 42 // with old/new level
# define ND_EVENT_LINK_SOUND_TO_OBJ 43 // record digi_link_sound_to_object3
# define ND_EVENT_KILL_SOUND_TO_OBJ 44 // record digi_kill_sound_linked_to_object
# elif defined(DXX_BUILD_DESCENT_II)
2009-11-15 08:22:08 +00:00
# define ND_EVENT_LASER_LEVEL 42 // no data
# define ND_EVENT_PLAYER_AFTERBURNER 43 // followed by byte old ab, current ab
# define ND_EVENT_CLOAKING_WALL 44 // info changing while wall cloaking
# define ND_EVENT_CHANGE_COCKPIT 45 // change the cockpit
# define ND_EVENT_START_GUIDED 46 // switch to guided view
# define ND_EVENT_END_GUIDED 47 // stop guided view/return to ship
# define ND_EVENT_SECRET_THINGY 48 // 0/1 = secret exit functional/non-functional
# define ND_EVENT_LINK_SOUND_TO_OBJ 49 // record digi_link_sound_to_object3
# define ND_EVENT_KILL_SOUND_TO_OBJ 50 // record digi_kill_sound_linked_to_object
2013-03-03 01:03:33 +00:00
# endif
2009-11-15 08:22:08 +00:00
# define NORMAL_PLAYBACK 0
# define SKIP_PLAYBACK 1
2010-01-20 23:28:35 +00:00
# define INTERPOLATE_PLAYBACK 2
# define INTERPOL_FACTOR (F1_0 + (F1_0 / 5))
2009-11-15 08:22:08 +00:00
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
# define DEMO_VERSION_SHAREWARE 5
# define DEMO_VERSION 13
# define DEMO_GAME_TYPE_SHAREWARE 1
# define DEMO_GAME_TYPE 2
# elif defined(DXX_BUILD_DESCENT_II)
2009-11-15 08:22:08 +00:00
# define DEMO_VERSION 15 // last D1 version was 13
# define DEMO_GAME_TYPE 3 // 1 was shareware, 2 registered
2013-03-03 01:03:33 +00:00
# endif
2009-11-15 08:22:08 +00:00
# define DEMO_FILENAME DEMO_DIR "tmpdemo.dem"
# define DEMO_MAX_LEVELS 29
2006-03-20 17:12:09 +00:00
2015-03-22 18:49:21 +00:00
const array < file_extension_t , 1 > demo_file_extensions { { DEMO_EXT } } ;
2013-11-26 22:19:52 +00:00
2010-07-15 05:40:25 +00:00
// In- and Out-files
2015-01-29 00:56:21 +00:00
static RAIIPHYSFS_File infile ;
2015-01-29 00:45:18 +00:00
static RAIIPHYSFS_File outfile ;
2006-03-20 17:12:09 +00:00
2010-07-15 05:40:25 +00:00
// Some globals
2006-03-20 17:12:09 +00:00
int Newdemo_state = 0 ;
2009-11-30 14:59:37 +00:00
int Newdemo_game_mode = 0 ;
2006-03-20 17:12:09 +00:00
int Newdemo_vcr_state = 0 ;
2008-10-16 17:27:02 +00:00
int Newdemo_show_percentage = 1 ;
2010-07-15 05:40:25 +00:00
sbyte Newdemo_do_interpolate = 1 ;
int Newdemo_num_written ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2010-01-28 00:04:29 +00:00
ubyte DemoDoRight = 0 , DemoDoLeft = 0 ;
2010-07-15 05:40:25 +00:00
object DemoRightExtra , DemoLeftExtra ;
2012-11-11 00:14:30 +00:00
2014-10-02 03:02:34 +00:00
static void nd_render_extras ( ubyte which , const vcobjptr_t obj ) ;
2013-03-03 01:03:33 +00:00
# endif
2010-07-15 05:40:25 +00:00
// local var used for swapping endian demos
static int swap_endian = 0 ;
// playback variables
static unsigned int nd_playback_v_demosize ;
2014-07-05 16:48:12 +00:00
static callsign_t nd_playback_v_save_callsign ;
2010-07-15 05:40:25 +00:00
static sbyte nd_playback_v_at_eof ;
static sbyte nd_playback_v_cntrlcen_destroyed = 0 ;
static sbyte nd_playback_v_bad_read ;
static int nd_playback_v_framecount ;
static fix nd_playback_total , nd_recorded_total , nd_recorded_time ;
static sbyte nd_playback_v_style ;
2013-08-31 15:22:40 +00:00
static ubyte nd_playback_v_dead = 0 , nd_playback_v_rear = 0 ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
static ubyte nd_playback_v_guided = 0 ;
2010-07-15 05:40:25 +00:00
int nd_playback_v_juststarted = 0 ;
2013-03-03 01:03:33 +00:00
# endif
2010-07-15 05:40:25 +00:00
// record variables
# define REC_DELAY F1_0 / 20
static int nd_record_v_start_frame = - 1 ;
static int nd_record_v_frame_number = - 1 ;
static short nd_record_v_framebytes_written = 0 ;
static int nd_record_v_recordframe = 1 ;
2010-12-22 00:17:59 +00:00
static fix64 nd_record_v_recordframe_last_time = 0 ;
2010-07-15 05:40:25 +00:00
static sbyte nd_record_v_no_space ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
static int nd_record_v_juststarted = 0 ;
2015-04-02 02:36:52 +00:00
static array < sbyte , MAX_OBJECTS > nd_record_v_objs ,
nd_record_v_viewobjs ;
static array < sbyte , 32 > nd_record_v_rendering ;
2010-07-15 05:40:25 +00:00
static fix nd_record_v_player_afterburner = - 1 ;
2013-03-03 01:03:33 +00:00
# endif
2013-08-31 15:22:40 +00:00
static int nd_record_v_player_energy = - 1 ;
2010-07-15 05:40:25 +00:00
static int nd_record_v_player_shields = - 1 ;
static uint nd_record_v_player_flags = - 1 ;
static int nd_record_v_weapon_type = - 1 ;
static int nd_record_v_weapon_num = - 1 ;
static fix nd_record_v_homing_distance = - 1 ;
static int nd_record_v_primary_ammo = - 1 ;
static int nd_record_v_secondary_ammo = - 1 ;
2009-11-15 08:22:08 +00:00
2013-08-31 15:22:40 +00:00
static void newdemo_record_oneframeevent_update ( int wallupdate ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
static int shareware = 0 ; // reading shareware demo?
# elif defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
static const int shareware = 0 ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2009-11-15 08:22:08 +00:00
int newdemo_get_percent_done ( ) {
2008-10-16 17:27:02 +00:00
if ( Newdemo_state = = ND_STATE_PLAYBACK ) {
2010-07-15 05:40:25 +00:00
return ( PHYSFS_tell ( infile ) * 100 ) / nd_playback_v_demosize ;
2008-10-16 17:27:02 +00:00
}
if ( Newdemo_state = = ND_STATE_RECORDING ) {
return PHYSFS_tell ( outfile ) ;
}
return 0 ;
2006-03-20 17:12:09 +00:00
}
# define VEL_PRECISION 12
2014-10-02 03:02:34 +00:00
static void my_extract_shortpos ( const vobjptr_t objp , shortpos * spp )
2006-03-20 17:12:09 +00:00
{
2013-12-29 04:28:07 +00:00
segnum_t segnum ;
2006-03-20 17:12:09 +00:00
sbyte * sp ;
sp = spp - > bytemat ;
objp - > orient . rvec . x = * sp + + < < MATRIX_PRECISION ;
objp - > orient . uvec . x = * sp + + < < MATRIX_PRECISION ;
objp - > orient . fvec . x = * sp + + < < MATRIX_PRECISION ;
objp - > orient . rvec . y = * sp + + < < MATRIX_PRECISION ;
objp - > orient . uvec . y = * sp + + < < MATRIX_PRECISION ;
objp - > orient . fvec . y = * sp + + < < MATRIX_PRECISION ;
objp - > orient . rvec . z = * sp + + < < MATRIX_PRECISION ;
objp - > orient . uvec . z = * sp + + < < MATRIX_PRECISION ;
objp - > orient . fvec . z = * sp + + < < MATRIX_PRECISION ;
segnum = spp - > segment ;
objp - > segnum = segnum ;
objp - > pos . x = ( spp - > xo < < RELPOS_PRECISION ) + Vertices [ Segments [ segnum ] . verts [ 0 ] ] . x ;
objp - > pos . y = ( spp - > yo < < RELPOS_PRECISION ) + Vertices [ Segments [ segnum ] . verts [ 0 ] ] . y ;
objp - > pos . z = ( spp - > zo < < RELPOS_PRECISION ) + Vertices [ Segments [ segnum ] . verts [ 0 ] ] . z ;
objp - > mtype . phys_info . velocity . x = ( spp - > velx < < VEL_PRECISION ) ;
objp - > mtype . phys_info . velocity . y = ( spp - > vely < < VEL_PRECISION ) ;
objp - > mtype . phys_info . velocity . z = ( spp - > velz < < VEL_PRECISION ) ;
}
2013-12-31 23:25:38 +00:00
static int _newdemo_read ( void * buffer , int elsize , int nelem )
2006-03-20 17:12:09 +00:00
{
int num_read ;
2013-12-31 23:25:38 +00:00
num_read = ( PHYSFS_read ) ( infile , buffer , elsize , nelem ) ;
2006-03-20 17:12:09 +00:00
if ( num_read < nelem | | PHYSFS_eof ( infile ) )
2010-07-15 05:40:25 +00:00
nd_playback_v_bad_read = - 1 ;
2006-03-20 17:12:09 +00:00
return num_read ;
}
2013-12-31 23:25:38 +00:00
template < typename T >
static typename tt : : enable_if < tt : : is_integral < T > : : value , int > : : type newdemo_read ( T * buffer , int elsize , int nelem )
{
return _newdemo_read ( buffer , elsize , nelem ) ;
}
2015-03-22 18:49:21 +00:00
cobjptridx_t newdemo_find_object ( object_signature_t signature )
2006-03-20 17:12:09 +00:00
{
2015-02-05 03:03:49 +00:00
range_for ( const auto i , highest_valid ( Objects ) )
2014-10-12 23:05:46 +00:00
{
2015-03-22 18:49:21 +00:00
const auto objp = vcobjptridx ( i ) ;
2006-03-20 17:12:09 +00:00
if ( ( objp - > type ! = OBJ_NONE ) & & ( objp - > signature = = signature ) )
2015-03-22 18:49:21 +00:00
return objp ;
2006-03-20 17:12:09 +00:00
}
2013-12-29 04:28:07 +00:00
return object_none ;
2006-03-20 17:12:09 +00:00
}
2013-12-31 22:52:00 +00:00
static int _newdemo_write ( const void * buffer , int elsize , int nelem )
2006-03-20 17:12:09 +00:00
{
int num_written , total_size ;
total_size = elsize * nelem ;
2010-07-15 05:40:25 +00:00
nd_record_v_framebytes_written + = total_size ;
2006-03-20 17:12:09 +00:00
Newdemo_num_written + = total_size ;
2015-01-29 00:45:18 +00:00
Assert ( outfile ) ;
2013-12-31 22:52:00 +00:00
num_written = ( PHYSFS_write ) ( outfile , buffer , elsize , nelem ) ;
2010-06-18 08:22:45 +00:00
2010-07-15 05:40:25 +00:00
if ( num_written = = nelem & & ! nd_record_v_no_space )
2006-03-20 17:12:09 +00:00
return num_written ;
2010-07-15 05:40:25 +00:00
nd_record_v_no_space = 2 ;
2006-03-20 17:12:09 +00:00
newdemo_stop_recording ( ) ;
return - 1 ;
}
2013-12-31 22:52:00 +00:00
template < typename T >
static typename tt : : enable_if < tt : : is_integral < T > : : value , int > : : type newdemo_write ( const T * buffer , int elsize , int nelem )
{
return _newdemo_write ( buffer , elsize , nelem ) ;
}
2006-03-20 17:12:09 +00:00
/*
* The next bunch of files taken from Matt ' s gamesave . c . We have to modify
* these since the demo must save more information about objects that
* just a gamesave
*/
static void nd_write_byte ( sbyte b )
{
newdemo_write ( & b , 1 , 1 ) ;
}
static void nd_write_short ( short s )
{
newdemo_write ( & s , 2 , 1 ) ;
}
static void nd_write_int ( int i )
{
newdemo_write ( & i , 4 , 1 ) ;
}
2013-06-23 16:24:43 +00:00
static void nd_write_string ( const char * str )
2006-03-20 17:12:09 +00:00
{
nd_write_byte ( strlen ( str ) + 1 ) ;
newdemo_write ( str , strlen ( str ) + 1 , 1 ) ;
}
static void nd_write_fix ( fix f )
{
newdemo_write ( & f , sizeof ( fix ) , 1 ) ;
}
static void nd_write_fixang ( fixang f )
{
newdemo_write ( & f , sizeof ( fixang ) , 1 ) ;
}
2014-11-01 14:56:53 +00:00
static void nd_write_vector ( const vms_vector & v )
2006-03-20 17:12:09 +00:00
{
2014-11-01 14:56:53 +00:00
nd_write_fix ( v . x ) ;
nd_write_fix ( v . y ) ;
nd_write_fix ( v . z ) ;
2006-03-20 17:12:09 +00:00
}
2014-10-26 23:10:47 +00:00
static void nd_write_angvec ( const vms_angvec & v )
2006-03-20 17:12:09 +00:00
{
2014-10-26 23:10:47 +00:00
nd_write_fixang ( v . p ) ;
nd_write_fixang ( v . b ) ;
nd_write_fixang ( v . h ) ;
2006-03-20 17:12:09 +00:00
}
2014-10-02 03:02:34 +00:00
static void nd_write_shortpos ( const vcobjptr_t obj )
2006-03-20 17:12:09 +00:00
{
shortpos sp ;
ubyte render_type ;
2015-06-13 22:42:21 +00:00
create_shortpos_native ( & sp , obj ) ;
2006-03-20 17:12:09 +00:00
render_type = obj - > render_type ;
if ( ( ( render_type = = RT_POLYOBJ ) | | ( render_type = = RT_HOSTAGE ) | | ( render_type = = RT_MORPH ) ) | | ( obj - > type = = OBJ_CAMERA ) ) {
2014-12-14 05:23:00 +00:00
uint8_t mask = 0 ;
2014-12-14 05:23:01 +00:00
range_for ( auto & i , sp . bytemat )
2014-12-14 05:23:00 +00:00
{
2014-12-14 05:23:01 +00:00
nd_write_byte ( i ) ;
mask | = i ;
2006-03-20 17:12:09 +00:00
}
2014-12-14 05:23:00 +00:00
if ( ! mask )
{
2006-03-20 17:12:09 +00:00
Int3 ( ) ; // contact Allender about this.
}
}
nd_write_short ( sp . xo ) ;
nd_write_short ( sp . yo ) ;
nd_write_short ( sp . zo ) ;
nd_write_short ( sp . segment ) ;
nd_write_short ( sp . velx ) ;
nd_write_short ( sp . vely ) ;
nd_write_short ( sp . velz ) ;
}
static void nd_read_byte ( sbyte * b )
{
newdemo_read ( b , 1 , 1 ) ;
}
static void nd_read_short ( short * s )
{
newdemo_read ( s , 2 , 1 ) ;
2009-11-15 08:22:08 +00:00
if ( swap_endian )
* s = SWAPSHORT ( * s ) ;
2006-03-20 17:12:09 +00:00
}
2015-05-28 03:08:40 +00:00
static void nd_read_segnum16 ( segnum_t & s )
{
short i ;
nd_read_short ( & i ) ;
s = i ;
}
2013-12-29 04:28:07 +00:00
static void nd_read_objnum16 ( objnum_t & o )
{
short s ;
nd_read_short ( & s ) ;
o = s ;
}
2006-03-20 17:12:09 +00:00
static void nd_read_int ( int * i )
{
newdemo_read ( i , 4 , 1 ) ;
2009-11-15 08:22:08 +00:00
if ( swap_endian )
* i = SWAPINT ( * i ) ;
2006-03-20 17:12:09 +00:00
}
2014-04-27 23:12:34 +00:00
# if defined(DXX_BUILD_DESCENT_II)
static void nd_read_int ( unsigned * i )
{
newdemo_read ( i , 4 , 1 ) ;
if ( swap_endian )
* i = SWAPINT ( * i ) ;
}
# endif
2013-12-29 04:28:07 +00:00
static void nd_read_segnum32 ( segnum_t & s )
{
int i ;
nd_read_int ( & i ) ;
s = i ;
}
static void nd_read_objnum32 ( objnum_t & o )
{
int i ;
nd_read_int ( & i ) ;
o = i ;
}
2006-03-20 17:12:09 +00:00
static void nd_read_string ( char * str )
{
sbyte len ;
nd_read_byte ( & len ) ;
newdemo_read ( str , len , 1 ) ;
}
static void nd_read_fix ( fix * f )
{
newdemo_read ( f , sizeof ( fix ) , 1 ) ;
2009-11-15 08:22:08 +00:00
if ( swap_endian )
* f = SWAPINT ( * f ) ;
2006-03-20 17:12:09 +00:00
}
static void nd_read_fixang ( fixang * f )
{
newdemo_read ( f , sizeof ( fixang ) , 1 ) ;
2009-11-15 08:22:08 +00:00
if ( swap_endian )
* f = SWAPSHORT ( * f ) ;
2006-03-20 17:12:09 +00:00
}
2014-11-01 14:57:05 +00:00
static void nd_read_vector ( vms_vector & v )
2006-03-20 17:12:09 +00:00
{
2014-11-01 14:57:05 +00:00
nd_read_fix ( & v . x ) ;
nd_read_fix ( & v . y ) ;
nd_read_fix ( & v . z ) ;
2006-03-20 17:12:09 +00:00
}
2014-11-01 14:57:25 +00:00
static void nd_read_angvec ( vms_angvec & v )
2006-03-20 17:12:09 +00:00
{
2014-11-01 14:57:25 +00:00
nd_read_fixang ( & v . p ) ;
nd_read_fixang ( & v . b ) ;
nd_read_fixang ( & v . h ) ;
2006-03-20 17:12:09 +00:00
}
2014-10-02 03:02:34 +00:00
static void nd_read_shortpos ( const vobjptr_t obj )
2006-03-20 17:12:09 +00:00
{
ubyte render_type ;
2014-07-04 04:14:22 +00:00
shortpos sp { } ;
2008-03-08 22:37:09 +00:00
2006-03-20 17:12:09 +00:00
render_type = obj - > render_type ;
if ( ( ( render_type = = RT_POLYOBJ ) | | ( render_type = = RT_HOSTAGE ) | | ( render_type = = RT_MORPH ) ) | | ( obj - > type = = OBJ_CAMERA ) ) {
2014-12-14 05:23:01 +00:00
range_for ( auto & i , sp . bytemat )
nd_read_byte ( & ( i ) ) ;
2006-03-20 17:12:09 +00:00
}
nd_read_short ( & ( sp . xo ) ) ;
nd_read_short ( & ( sp . yo ) ) ;
nd_read_short ( & ( sp . zo ) ) ;
nd_read_short ( & ( sp . segment ) ) ;
nd_read_short ( & ( sp . velx ) ) ;
nd_read_short ( & ( sp . vely ) ) ;
nd_read_short ( & ( sp . velz ) ) ;
my_extract_shortpos ( obj , & sp ) ;
if ( ( obj - > id = = VCLIP_MORPHING_ROBOT ) & & ( render_type = = RT_FIREBALL ) & & ( obj - > control_type = = CT_EXPLOSION ) )
2015-07-12 01:04:21 +00:00
extract_orient_from_segment ( & obj - > orient , vcsegptr ( obj - > segnum ) ) ;
2006-03-20 17:12:09 +00:00
}
object * prev_obj = NULL ; //ptr to last object read in
2014-11-11 04:12:10 +00:00
static void nd_read_object ( const vobjptridx_t obj )
2006-03-20 17:12:09 +00:00
{
2010-01-28 15:26:27 +00:00
short shortsig = 0 ;
2006-03-20 17:12:09 +00:00
2014-07-04 04:14:22 +00:00
* obj = { } ;
2014-12-14 21:02:40 +00:00
obj - > next = obj - > prev = object_none ;
obj - > segnum = segment_none ;
2010-10-10 10:48:24 +00:00
2006-03-20 17:12:09 +00:00
/*
* Do render type first , since with render_type = = RT_NONE , we
* blow by all other object information
*/
nd_read_byte ( ( sbyte * ) & ( obj - > render_type ) ) ;
nd_read_byte ( ( sbyte * ) & ( obj - > type ) ) ;
if ( ( obj - > render_type = = RT_NONE ) & & ( obj - > type ! = OBJ_CAMERA ) )
return ;
nd_read_byte ( ( sbyte * ) & ( obj - > id ) ) ;
nd_read_byte ( ( sbyte * ) & ( obj - > flags ) ) ;
2010-01-28 15:26:27 +00:00
nd_read_short ( & shortsig ) ;
2015-03-22 18:49:21 +00:00
// It's OKAY! We made sure, obj->signature is never has a value which short cannot handle!!! We cannot do this otherwise, without breaking the demo format!
obj - > signature = object_signature_t { static_cast < uint16_t > ( shortsig ) } ;
2006-03-20 17:12:09 +00:00
nd_read_shortpos ( obj ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-10-07 23:52:33 +00:00
if ( ( obj - > type = = OBJ_ROBOT ) & & ( get_robot_id ( obj ) = = SPECIAL_REACTOR_ROBOT ) )
2006-03-20 17:12:09 +00:00
Int3 ( ) ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2013-12-26 22:21:16 +00:00
obj - > attached_obj = object_none ;
2006-03-20 17:12:09 +00:00
switch ( obj - > type ) {
case OBJ_HOSTAGE :
obj - > control_type = CT_POWERUP ;
obj - > movement_type = MT_NONE ;
obj - > size = HOSTAGE_SIZE ;
break ;
case OBJ_ROBOT :
obj - > control_type = CT_AI ;
// (MarkA and MikeK said we should not do the crazy last secret stuff with multiple reactors...
// This necessary code is our vindication. --MK, 2/15/96)
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-10-07 23:52:33 +00:00
if ( get_robot_id ( obj ) = = SPECIAL_REACTOR_ROBOT )
2006-03-20 17:12:09 +00:00
obj - > movement_type = MT_NONE ;
2013-08-31 15:22:40 +00:00
else
2013-03-03 01:03:33 +00:00
# endif
2013-08-31 15:22:40 +00:00
obj - > movement_type = MT_PHYSICS ;
2013-10-07 23:52:33 +00:00
obj - > size = Polygon_models [ Robot_info [ get_robot_id ( obj ) ] . model_num ] . rad ;
obj - > rtype . pobj_info . model_num = Robot_info [ get_robot_id ( obj ) ] . model_num ;
2006-03-20 17:12:09 +00:00
obj - > rtype . pobj_info . subobj_flags = 0 ;
2013-10-07 23:52:33 +00:00
obj - > ctype . ai_info . CLOAKED = ( Robot_info [ get_robot_id ( obj ) ] . cloak_type ? 1 : 0 ) ;
2006-03-20 17:12:09 +00:00
break ;
case OBJ_POWERUP :
obj - > control_type = CT_POWERUP ;
nd_read_byte ( ( sbyte * ) & ( obj - > movement_type ) ) ; // might have physics movement
2013-10-07 23:52:33 +00:00
obj - > size = Powerup_info [ get_powerup_id ( obj ) ] . size ;
2006-03-20 17:12:09 +00:00
break ;
case OBJ_PLAYER :
obj - > control_type = CT_NONE ;
obj - > movement_type = MT_PHYSICS ;
obj - > size = Polygon_models [ Player_ship - > model_num ] . rad ;
obj - > rtype . pobj_info . model_num = Player_ship - > model_num ;
obj - > rtype . pobj_info . subobj_flags = 0 ;
break ;
case OBJ_CLUTTER :
obj - > control_type = CT_NONE ;
obj - > movement_type = MT_NONE ;
obj - > size = Polygon_models [ obj - > id ] . rad ;
obj - > rtype . pobj_info . model_num = obj - > id ;
obj - > rtype . pobj_info . subobj_flags = 0 ;
break ;
default :
nd_read_byte ( ( sbyte * ) & ( obj - > control_type ) ) ;
nd_read_byte ( ( sbyte * ) & ( obj - > movement_type ) ) ;
nd_read_fix ( & ( obj - > size ) ) ;
break ;
}
2014-11-01 14:57:05 +00:00
nd_read_vector ( obj - > last_pos ) ;
2006-03-20 17:12:09 +00:00
if ( ( obj - > type = = OBJ_WEAPON ) & & ( obj - > render_type = = RT_WEAPON_VCLIP ) )
nd_read_fix ( & ( obj - > lifeleft ) ) ;
else {
sbyte b ;
2012-04-17 07:36:23 +00:00
// MWA old way -- won't work with big endian machines nd_read_byte((ubyte *)&(obj->lifeleft));
2006-03-20 17:12:09 +00:00
nd_read_byte ( & b ) ;
obj - > lifeleft = ( fix ) b ;
2012-04-17 07:36:23 +00:00
if ( obj - > lifeleft = = - 1 )
obj - > lifeleft = IMMORTAL_TIME ;
else
obj - > lifeleft = ( fix ) ( ( int ) obj - > lifeleft < < 12 ) ;
2006-03-20 17:12:09 +00:00
}
2013-08-31 15:22:40 +00:00
if ( ( obj - > type = = OBJ_ROBOT ) & & ! shareware ) {
2013-10-07 23:52:33 +00:00
if ( Robot_info [ get_robot_id ( obj ) ] . boss_flag ) {
2006-03-20 17:12:09 +00:00
sbyte cloaked ;
nd_read_byte ( & cloaked ) ;
obj - > ctype . ai_info . CLOAKED = cloaked ;
}
}
switch ( obj - > movement_type ) {
case MT_PHYSICS :
2014-11-01 14:57:05 +00:00
nd_read_vector ( obj - > mtype . phys_info . velocity ) ;
nd_read_vector ( obj - > mtype . phys_info . thrust ) ;
2006-03-20 17:12:09 +00:00
break ;
case MT_SPINNING :
2014-11-01 14:57:05 +00:00
nd_read_vector ( obj - > mtype . spin_rate ) ;
2006-03-20 17:12:09 +00:00
break ;
case MT_NONE :
break ;
default :
Int3 ( ) ;
}
switch ( obj - > control_type ) {
case CT_EXPLOSION :
nd_read_fix ( & ( obj - > ctype . expl_info . spawn_time ) ) ;
nd_read_fix ( & ( obj - > ctype . expl_info . delete_time ) ) ;
2013-12-29 04:28:07 +00:00
nd_read_objnum16 ( obj - > ctype . expl_info . delete_objnum ) ;
2006-03-20 17:12:09 +00:00
2013-12-26 22:21:16 +00:00
obj - > ctype . expl_info . next_attach = obj - > ctype . expl_info . prev_attach = obj - > ctype . expl_info . attach_parent = object_none ;
2006-03-20 17:12:09 +00:00
if ( obj - > flags & OF_ATTACHED ) { //attach to previous object
Assert ( prev_obj ! = NULL ) ;
if ( prev_obj - > control_type = = CT_EXPLOSION ) {
2013-12-26 22:21:16 +00:00
if ( prev_obj - > flags & OF_ATTACHED & & prev_obj - > ctype . expl_info . attach_parent ! = object_none )
2014-12-23 04:20:27 +00:00
obj_attach ( vobjptridx ( prev_obj - > ctype . expl_info . attach_parent ) , obj ) ;
2006-03-20 17:12:09 +00:00
else
obj - > flags & = ~ OF_ATTACHED ;
}
else
2014-12-23 04:20:27 +00:00
obj_attach ( vobjptridx ( prev_obj ) , obj ) ;
2006-03-20 17:12:09 +00:00
}
break ;
case CT_LIGHT :
nd_read_fix ( & ( obj - > ctype . light_info . intensity ) ) ;
break ;
case CT_AI :
case CT_WEAPON :
case CT_NONE :
case CT_FLYING :
case CT_DEBRIS :
case CT_POWERUP :
case CT_SLEW :
case CT_CNTRLCEN :
case CT_REMOTE :
case CT_MORPH :
break ;
case CT_FLYTHROUGH :
case CT_REPAIRCEN :
default :
Int3 ( ) ;
}
switch ( obj - > render_type ) {
case RT_NONE :
break ;
case RT_MORPH :
case RT_POLYOBJ : {
2014-10-26 22:51:27 +00:00
int tmo ;
2006-03-20 17:12:09 +00:00
if ( ( obj - > type ! = OBJ_ROBOT ) & & ( obj - > type ! = OBJ_PLAYER ) & & ( obj - > type ! = OBJ_CLUTTER ) ) {
nd_read_int ( & ( obj - > rtype . pobj_info . model_num ) ) ;
nd_read_int ( & ( obj - > rtype . pobj_info . subobj_flags ) ) ;
}
if ( ( obj - > type ! = OBJ_PLAYER ) & & ( obj - > type ! = OBJ_DEBRIS ) )
#if 0
2014-12-14 05:23:01 +00:00
range_for ( auto & i , obj - > pobj_info . anim_angles )
nd_read_angvec ( & ( i ) ) ;
2006-03-20 17:12:09 +00:00
# endif
2014-10-26 22:51:27 +00:00
range_for ( auto & i , partial_range ( obj - > rtype . pobj_info . anim_angles , Polygon_models [ obj - > rtype . pobj_info . model_num ] . n_models ) )
2014-11-01 14:57:25 +00:00
nd_read_angvec ( i ) ;
2006-03-20 17:12:09 +00:00
nd_read_int ( & tmo ) ;
# ifndef EDITOR
obj - > rtype . pobj_info . tmap_override = tmo ;
# else
if ( tmo = = - 1 )
obj - > rtype . pobj_info . tmap_override = - 1 ;
else {
int xlated_tmo = tmap_xlate_table [ tmo ] ;
if ( xlated_tmo < 0 ) {
Int3 ( ) ;
xlated_tmo = 0 ;
}
obj - > rtype . pobj_info . tmap_override = xlated_tmo ;
}
# endif
break ;
}
case RT_POWERUP :
case RT_WEAPON_VCLIP :
case RT_FIREBALL :
case RT_HOSTAGE :
nd_read_int ( & ( obj - > rtype . vclip_info . vclip_num ) ) ;
nd_read_fix ( & ( obj - > rtype . vclip_info . frametime ) ) ;
nd_read_byte ( & ( obj - > rtype . vclip_info . framenum ) ) ;
break ;
case RT_LASER :
break ;
default :
Int3 ( ) ;
}
prev_obj = obj ;
}
2014-10-02 03:02:34 +00:00
static void nd_write_object ( const vcobjptr_t obj )
2006-03-20 17:12:09 +00:00
{
int life ;
2010-01-28 15:26:27 +00:00
short shortsig = 0 ;
2006-03-20 17:12:09 +00:00
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-10-07 23:52:33 +00:00
if ( ( obj - > type = = OBJ_ROBOT ) & & ( get_robot_id ( obj ) = = SPECIAL_REACTOR_ROBOT ) )
2006-03-20 17:12:09 +00:00
Int3 ( ) ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
/*
* Do render_type first so on read , we can make determination of
* what else to read in
*/
nd_write_byte ( obj - > render_type ) ;
nd_write_byte ( obj - > type ) ;
if ( ( obj - > render_type = = RT_NONE ) & & ( obj - > type ! = OBJ_CAMERA ) )
return ;
nd_write_byte ( obj - > id ) ;
nd_write_byte ( obj - > flags ) ;
2015-03-22 18:49:21 +00:00
shortsig = obj - > signature . get ( ) ; // It's OKAY! We made sure, obj->signature is never has a value which short cannot handle!!! We cannot do this otherwise, without breaking the demo format!
2010-01-28 15:26:27 +00:00
nd_write_short ( shortsig ) ;
2006-03-20 17:12:09 +00:00
nd_write_shortpos ( obj ) ;
if ( ( obj - > type ! = OBJ_HOSTAGE ) & & ( obj - > type ! = OBJ_ROBOT ) & & ( obj - > type ! = OBJ_PLAYER ) & & ( obj - > type ! = OBJ_POWERUP ) & & ( obj - > type ! = OBJ_CLUTTER ) ) {
nd_write_byte ( obj - > control_type ) ;
nd_write_byte ( obj - > movement_type ) ;
nd_write_fix ( obj - > size ) ;
}
if ( obj - > type = = OBJ_POWERUP )
nd_write_byte ( obj - > movement_type ) ;
2014-11-01 14:56:53 +00:00
nd_write_vector ( obj - > last_pos ) ;
2006-03-20 17:12:09 +00:00
if ( ( obj - > type = = OBJ_WEAPON ) & & ( obj - > render_type = = RT_WEAPON_VCLIP ) )
nd_write_fix ( obj - > lifeleft ) ;
else {
life = ( int ) obj - > lifeleft ;
life = life > > 12 ;
if ( life > 255 )
life = 255 ;
nd_write_byte ( ( ubyte ) life ) ;
}
if ( obj - > type = = OBJ_ROBOT ) {
2013-10-07 23:52:33 +00:00
if ( Robot_info [ get_robot_id ( obj ) ] . boss_flag ) {
2010-12-22 00:17:59 +00:00
if ( ( GameTime64 > Boss_cloak_start_time ) & & ( GameTime64 < Boss_cloak_end_time ) )
2006-03-20 17:12:09 +00:00
nd_write_byte ( 1 ) ;
else
nd_write_byte ( 0 ) ;
}
}
switch ( obj - > movement_type ) {
case MT_PHYSICS :
2014-11-01 14:56:53 +00:00
nd_write_vector ( obj - > mtype . phys_info . velocity ) ;
nd_write_vector ( obj - > mtype . phys_info . thrust ) ;
2006-03-20 17:12:09 +00:00
break ;
case MT_SPINNING :
2014-11-01 14:56:53 +00:00
nd_write_vector ( obj - > mtype . spin_rate ) ;
2006-03-20 17:12:09 +00:00
break ;
case MT_NONE :
break ;
default :
Int3 ( ) ;
}
switch ( obj - > control_type ) {
case CT_AI :
break ;
case CT_EXPLOSION :
nd_write_fix ( obj - > ctype . expl_info . spawn_time ) ;
nd_write_fix ( obj - > ctype . expl_info . delete_time ) ;
nd_write_short ( obj - > ctype . expl_info . delete_objnum ) ;
break ;
case CT_WEAPON :
break ;
case CT_LIGHT :
nd_write_fix ( obj - > ctype . light_info . intensity ) ;
break ;
case CT_NONE :
case CT_FLYING :
case CT_DEBRIS :
case CT_POWERUP :
case CT_SLEW : //the player is generally saved as slew
case CT_CNTRLCEN :
case CT_REMOTE :
case CT_MORPH :
break ;
case CT_REPAIRCEN :
case CT_FLYTHROUGH :
default :
Int3 ( ) ;
}
switch ( obj - > render_type ) {
case RT_NONE :
break ;
case RT_MORPH :
case RT_POLYOBJ : {
if ( ( obj - > type ! = OBJ_ROBOT ) & & ( obj - > type ! = OBJ_PLAYER ) & & ( obj - > type ! = OBJ_CLUTTER ) ) {
nd_write_int ( obj - > rtype . pobj_info . model_num ) ;
nd_write_int ( obj - > rtype . pobj_info . subobj_flags ) ;
}
if ( ( obj - > type ! = OBJ_PLAYER ) & & ( obj - > type ! = OBJ_DEBRIS ) )
#if 0
2014-12-14 05:23:01 +00:00
range_for ( auto & i , obj - > pobj_info . anim_angles )
nd_write_angvec ( & i ) ;
2006-03-20 17:12:09 +00:00
# endif
2014-10-26 22:51:27 +00:00
range_for ( auto & i , partial_range ( obj - > rtype . pobj_info . anim_angles , Polygon_models [ obj - > rtype . pobj_info . model_num ] . n_models ) )
2014-10-26 23:10:47 +00:00
nd_write_angvec ( i ) ;
2006-03-20 17:12:09 +00:00
nd_write_int ( obj - > rtype . pobj_info . tmap_override ) ;
break ;
}
case RT_POWERUP :
case RT_WEAPON_VCLIP :
case RT_FIREBALL :
case RT_HOSTAGE :
nd_write_int ( obj - > rtype . vclip_info . vclip_num ) ;
nd_write_fix ( obj - > rtype . vclip_info . frametime ) ;
nd_write_byte ( obj - > rtype . vclip_info . framenum ) ;
break ;
case RT_LASER :
break ;
default :
Int3 ( ) ;
}
}
2015-10-18 21:01:20 +00:00
static void nd_record_meta ( char ( & buf ) [ 7 ] , const char * s )
{
for ( auto l = strlen ( s ) + 1 ; l ; )
{
const auto n = std : : min ( l , sizeof ( buf ) - 3 ) ;
std : : copy_n ( s , n , & buf [ 3 ] ) ;
s + = n ;
if ( ! ( l - = n ) )
/* On final fragment, overwrite any trailing garbage from
* previous iteration .
*/
std : : fill_n ( & buf [ 3 + n ] , sizeof ( buf ) - 3 - n , 0 ) ;
newdemo_write ( buf , 1 , sizeof ( buf ) ) ;
}
}
static void nd_rdt ( char ( & buf ) [ 7 ] )
{
time_t t ;
if ( time ( & t ) = = static_cast < time_t > ( - 1 ) )
return ;
/* UTC for easy comparison among demos from players in different
* timezones
*/
if ( const auto g = gmtime ( & t ) )
if ( const auto st = asctime ( g ) )
nd_record_meta ( buf , st ) ;
}
static void nd_rbe ( )
{
char buf [ 7 ] { ND_EVENT_PALETTE_EFFECT , 0x80 } ;
newdemo_write ( buf , 1 , sizeof ( buf ) ) ;
+ + buf [ 2 ] ;
nd_rdt ( buf ) ;
+ + buf [ 2 ] ;
# define DXX_RBE(A) \
extern const char g_descent_ # # A [ ] ; \
nd_record_meta ( buf , g_descent_ # # A ) ;
DXX_RBE ( CPPFLAGS ) ;
DXX_RBE ( CXX ) ;
DXX_RBE ( CXXFLAGS ) ;
DXX_RBE ( CXX_version ) ;
DXX_RBE ( LINKFLAGS ) ;
+ + buf [ 2 ] ;
DXX_RBE ( build_datetime ) ;
DXX_RBE ( git_diffstat ) ;
DXX_RBE ( git_status ) ;
DXX_RBE ( version ) ;
std : : fill_n ( & buf [ 1 ] , sizeof ( buf ) - 1 , 0 ) ;
newdemo_write ( buf , 1 , sizeof ( buf ) ) ;
}
2006-03-20 17:12:09 +00:00
void newdemo_record_start_demo ( )
{
2010-12-22 00:17:59 +00:00
nd_record_v_recordframe_last_time = GameTime64 - REC_DELAY ; // make sure first frame is recorded!
2007-11-06 20:33:22 +00:00
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_START_DEMO ) ;
nd_write_byte ( DEMO_VERSION ) ;
nd_write_byte ( DEMO_GAME_TYPE ) ;
2010-12-22 00:17:59 +00:00
nd_write_fix ( 0 ) ; // NOTE: This is supposed to write GameTime (in fix). Since our GameTime64 is fix64 and the demos do not NEED this time actually, just write 0.
2006-03-20 17:12:09 +00:00
if ( Game_mode & GM_MULTI )
nd_write_int ( Game_mode | ( Player_num < < 16 ) ) ;
else
// NOTE LINK TO ABOVE!!!
nd_write_int ( Game_mode ) ;
if ( Game_mode & GM_TEAM ) {
nd_write_byte ( Netgame . team_vector ) ;
nd_write_string ( Netgame . team_name [ 0 ] ) ;
nd_write_string ( Netgame . team_name [ 1 ] ) ;
}
if ( Game_mode & GM_MULTI ) {
nd_write_byte ( ( sbyte ) N_players ) ;
2014-12-14 05:23:01 +00:00
range_for ( auto & i , partial_range ( Players , N_players ) ) {
nd_write_string ( static_cast < const char * > ( i . callsign ) ) ;
nd_write_byte ( i . connected ) ;
2006-03-20 17:12:09 +00:00
if ( Game_mode & GM_MULTI_COOP ) {
2014-12-14 05:23:01 +00:00
nd_write_int ( i . score ) ;
2006-03-20 17:12:09 +00:00
} else {
2014-12-14 05:23:01 +00:00
nd_write_short ( i . net_killed_total ) ;
nd_write_short ( i . net_kills_total ) ;
2006-03-20 17:12:09 +00:00
}
}
} else
// NOTE LINK TO ABOVE!!!
2015-07-25 23:10:46 +00:00
nd_write_int ( get_local_player ( ) . score ) ;
2006-03-20 17:12:09 +00:00
2010-07-15 05:40:25 +00:00
nd_record_v_weapon_type = - 1 ;
nd_record_v_weapon_num = - 1 ;
nd_record_v_homing_distance = - 1 ;
nd_record_v_primary_ammo = - 1 ;
nd_record_v_secondary_ammo = - 1 ;
2014-12-14 05:23:00 +00:00
for ( int i = 0 ; i < MAX_PRIMARY_WEAPONS ; i + + )
2015-10-18 21:01:18 +00:00
nd_write_short ( i = = primary_weapon_index_t : : VULCAN_INDEX ? get_local_player ( ) . vulcan_ammo : 0 ) ;
2006-03-20 17:12:09 +00:00
2015-07-25 23:10:46 +00:00
range_for ( auto & i , get_local_player ( ) . secondary_ammo )
2014-12-14 05:23:01 +00:00
nd_write_short ( i ) ;
2006-03-20 17:12:09 +00:00
2015-07-25 23:10:46 +00:00
nd_write_byte ( ( sbyte ) get_local_player ( ) . laser_level ) ;
2006-03-20 17:12:09 +00:00
// Support for missions added here
nd_write_string ( Current_mission_filename ) ;
2015-07-25 23:10:46 +00:00
nd_record_v_player_energy = ( sbyte ) ( f2ir ( get_local_player ( ) . energy ) ) ;
nd_write_byte ( ( sbyte ) ( f2ir ( get_local_player ( ) . energy ) ) ) ;
nd_record_v_player_shields = ( sbyte ) ( f2ir ( get_local_player ( ) . shields ) ) ;
nd_write_byte ( ( sbyte ) ( f2ir ( get_local_player ( ) . shields ) ) ) ;
nd_record_v_player_flags = get_local_player ( ) . flags ;
nd_write_int ( get_local_player ( ) . flags ) ; // be sure players flags are set
2006-03-20 17:12:09 +00:00
nd_write_byte ( ( sbyte ) Primary_weapon ) ;
nd_write_byte ( ( sbyte ) Secondary_weapon ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_start_frame = nd_record_v_frame_number = 0 ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
nd_record_v_player_afterburner = 0 ;
2010-07-15 05:40:25 +00:00
nd_record_v_juststarted = 1 ;
2013-03-03 01:03:33 +00:00
# endif
2015-10-18 21:01:20 +00:00
nd_rbe ( ) ;
2006-03-20 17:12:09 +00:00
newdemo_set_new_level ( Current_level_num ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
newdemo_record_oneframeevent_update ( 1 ) ;
# elif defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
newdemo_record_oneframeevent_update ( 0 ) ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
}
2008-10-16 17:27:02 +00:00
void newdemo_record_start_frame ( fix frame_time )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( nd_record_v_no_space ) {
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
return ;
}
2007-11-06 20:33:22 +00:00
// Make demo recording waste a bit less space.
2010-07-15 05:40:25 +00:00
// First check if if at least REC_DELAY has passed since last recorded frame. If yes, record frame and set nd_record_v_recordframe true.
// nd_record_v_recordframe will be used for various other frame-by-frame events to drop some unnecessary bytes.
2007-11-06 20:33:22 +00:00
// frame_time must be modified to get the right playback speed.
2010-12-22 00:17:59 +00:00
if ( nd_record_v_recordframe_last_time > GameTime64 )
nd_record_v_recordframe_last_time = GameTime64 - REC_DELAY ;
2006-03-20 17:12:09 +00:00
2010-12-22 00:17:59 +00:00
if ( nd_record_v_recordframe_last_time + REC_DELAY < = GameTime64 | | frame_time > = REC_DELAY )
2006-03-20 17:12:09 +00:00
{
2007-11-06 20:33:22 +00:00
if ( frame_time < REC_DELAY )
frame_time = REC_DELAY ;
2010-12-22 00:17:59 +00:00
nd_record_v_recordframe_last_time = GameTime64 - ( GameTime64 - ( nd_record_v_recordframe_last_time + REC_DELAY ) ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_recordframe = 1 ;
2007-11-06 20:33:22 +00:00
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2010-06-18 08:22:45 +00:00
2013-08-31 15:22:40 +00:00
for ( int i = 0 ; i < MAX_OBJECTS ; i + + )
2007-11-06 20:33:22 +00:00
{
2010-07-15 05:40:25 +00:00
nd_record_v_objs [ i ] = 0 ;
nd_record_v_viewobjs [ i ] = 0 ;
2007-11-06 20:33:22 +00:00
}
2014-12-14 05:23:01 +00:00
range_for ( auto & i , nd_record_v_rendering )
i = 0 ;
2010-06-18 08:22:45 +00:00
2013-03-03 01:03:33 +00:00
# endif
2010-07-15 05:40:25 +00:00
nd_record_v_frame_number - = nd_record_v_start_frame ;
2009-11-15 08:22:08 +00:00
2007-11-06 20:33:22 +00:00
nd_write_byte ( ND_EVENT_START_FRAME ) ;
2010-07-15 05:40:25 +00:00
nd_write_short ( nd_record_v_framebytes_written - 1 ) ; // from previous frame
nd_record_v_framebytes_written = 3 ;
nd_write_int ( nd_record_v_frame_number ) ;
nd_record_v_frame_number + + ;
2007-11-06 20:33:22 +00:00
nd_write_int ( frame_time ) ;
}
else
{
2010-07-15 05:40:25 +00:00
nd_record_v_recordframe = 0 ;
2006-03-20 17:12:09 +00:00
}
}
2014-10-02 03:02:34 +00:00
void newdemo_record_render_object ( const vobjptridx_t obj )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( ! nd_record_v_recordframe )
2007-11-06 20:33:22 +00:00
return ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2014-01-12 00:44:12 +00:00
if ( nd_record_v_objs [ obj ] )
2010-07-15 05:40:25 +00:00
return ;
2014-01-12 00:44:12 +00:00
if ( nd_record_v_viewobjs [ obj ] )
2006-03-20 17:12:09 +00:00
return ;
2014-01-12 00:44:12 +00:00
nd_record_v_objs [ obj ] = 1 ;
2013-03-03 01:03:33 +00:00
# endif
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_RENDER_OBJECT ) ;
nd_write_object ( obj ) ;
}
2014-10-02 03:02:34 +00:00
void newdemo_record_viewer_object ( const vobjptridx_t obj )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( ! nd_record_v_recordframe )
2007-11-06 20:33:22 +00:00
return ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2014-01-12 00:44:12 +00:00
if ( nd_record_v_viewobjs [ obj ] & & ( nd_record_v_viewobjs [ obj ] - 1 ) = = RenderingType )
2006-03-20 17:12:09 +00:00
return ;
2010-07-15 05:40:25 +00:00
if ( nd_record_v_rendering [ RenderingType ] )
2006-03-20 17:12:09 +00:00
return ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2013-08-31 15:22:40 +00:00
nd_write_byte ( ND_EVENT_VIEWER_OBJECT ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2014-01-12 00:44:12 +00:00
nd_record_v_viewobjs [ obj ] = RenderingType + 1 ;
2010-07-15 05:40:25 +00:00
nd_record_v_rendering [ RenderingType ] = 1 ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( RenderingType ) ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
nd_write_object ( obj ) ;
}
void newdemo_record_sound ( int soundno )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_SOUND ) ;
nd_write_int ( soundno ) ;
}
void newdemo_record_sound_3d ( int soundno , int angle , int volume )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_SOUND_3D ) ;
nd_write_int ( soundno ) ;
nd_write_int ( angle ) ;
nd_write_int ( volume ) ;
}
void newdemo_record_sound_3d_once ( int soundno , int angle , int volume )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_SOUND_3D_ONCE ) ;
nd_write_int ( soundno ) ;
nd_write_int ( angle ) ;
nd_write_int ( volume ) ;
}
void newdemo_record_link_sound_to_object3 ( int soundno , short objnum , fix max_volume , fix max_distance , int loop_start , int loop_end )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_LINK_SOUND_TO_OBJ ) ;
nd_write_int ( soundno ) ;
2015-03-22 18:49:21 +00:00
nd_write_int ( Objects [ objnum ] . signature . get ( ) ) ;
2006-03-20 17:12:09 +00:00
nd_write_int ( max_volume ) ;
nd_write_int ( max_distance ) ;
nd_write_int ( loop_start ) ;
nd_write_int ( loop_end ) ;
}
2014-12-13 17:47:06 +00:00
void newdemo_record_kill_sound_linked_to_object ( const vcobjptridx_t objp )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_KILL_SOUND_TO_OBJ ) ;
2015-03-22 18:49:21 +00:00
nd_write_int ( objp - > signature . get ( ) ) ;
2006-03-20 17:12:09 +00:00
}
2013-12-29 04:28:07 +00:00
void newdemo_record_wall_hit_process ( segnum_t segnum , int side , int damage , int playernum )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_WALL_HIT_PROCESS ) ;
nd_write_int ( segnum ) ;
nd_write_int ( side ) ;
nd_write_int ( damage ) ;
nd_write_int ( playernum ) ;
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
void newdemo_record_guided_start ( )
{
nd_write_byte ( ND_EVENT_START_GUIDED ) ;
}
void newdemo_record_guided_end ( )
{
nd_write_byte ( ND_EVENT_END_GUIDED ) ;
}
void newdemo_record_secret_exit_blown ( int truth )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_SECRET_THINGY ) ;
nd_write_int ( truth ) ;
}
2013-12-29 04:28:07 +00:00
void newdemo_record_trigger ( segnum_t segnum , int side , objnum_t objnum , int shot )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_TRIGGER ) ;
nd_write_int ( segnum ) ;
nd_write_int ( side ) ;
nd_write_int ( objnum ) ;
nd_write_int ( shot ) ;
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2009-11-15 08:22:08 +00:00
void newdemo_record_hostage_rescued ( int hostage_number )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_HOSTAGE_RESCUED ) ;
nd_write_int ( hostage_number ) ;
}
void newdemo_record_morph_frame ( morph_data * md )
{
2010-07-15 05:40:25 +00:00
if ( ! nd_record_v_recordframe )
2007-11-06 20:33:22 +00:00
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MORPH_FRAME ) ;
2015-07-12 01:04:21 +00:00
nd_write_object ( vcobjptr ( md - > obj ) ) ;
2006-03-20 17:12:09 +00:00
}
2013-12-29 04:28:07 +00:00
void newdemo_record_wall_toggle ( segnum_t segnum , int side )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_WALL_TOGGLE ) ;
nd_write_int ( segnum ) ;
nd_write_int ( side ) ;
}
void newdemo_record_control_center_destroyed ( )
{
2011-03-27 23:39:51 +00:00
if ( ! nd_record_v_recordframe )
2010-07-15 05:40:25 +00:00
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_CONTROL_CENTER_DESTROYED ) ;
nd_write_int ( Countdown_seconds_left ) ;
}
2013-08-31 15:22:40 +00:00
void newdemo_record_hud_message ( const char * message )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_HUD_MESSAGE ) ;
nd_write_string ( message ) ;
}
void newdemo_record_palette_effect ( short r , short g , short b )
{
2010-07-15 05:40:25 +00:00
if ( ! nd_record_v_recordframe )
2007-11-06 20:33:22 +00:00
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PALETTE_EFFECT ) ;
nd_write_short ( r ) ;
nd_write_short ( g ) ;
nd_write_short ( b ) ;
}
2010-07-15 05:40:25 +00:00
void newdemo_record_player_energy ( int energy )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( nd_record_v_player_energy = = energy )
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PLAYER_ENERGY ) ;
2010-07-15 05:40:25 +00:00
nd_write_byte ( ( sbyte ) nd_record_v_player_energy ) ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ( sbyte ) energy ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_player_energy = energy ;
2006-03-20 17:12:09 +00:00
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2010-07-15 05:40:25 +00:00
void newdemo_record_player_afterburner ( fix afterburner )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( ( nd_record_v_player_afterburner > > 9 ) = = ( afterburner > > 9 ) )
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PLAYER_AFTERBURNER ) ;
2010-07-15 05:40:25 +00:00
nd_write_byte ( ( sbyte ) ( nd_record_v_player_afterburner > > 9 ) ) ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ( sbyte ) ( afterburner > > 9 ) ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_player_afterburner = afterburner ;
2006-03-20 17:12:09 +00:00
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2010-07-15 05:40:25 +00:00
void newdemo_record_player_shields ( int shield )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( nd_record_v_player_shields = = shield )
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PLAYER_SHIELD ) ;
2010-07-15 05:40:25 +00:00
nd_write_byte ( ( sbyte ) nd_record_v_player_shields ) ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ( sbyte ) shield ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_player_shields = shield ;
2006-03-20 17:12:09 +00:00
}
2010-07-15 05:40:25 +00:00
void newdemo_record_player_flags ( uint flags )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( nd_record_v_player_flags = = flags )
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PLAYER_FLAGS ) ;
2010-07-15 05:40:25 +00:00
nd_write_int ( ( ( short ) nd_record_v_player_flags < < 16 ) | ( short ) flags ) ;
nd_record_v_player_flags = flags ;
2006-03-20 17:12:09 +00:00
}
void newdemo_record_player_weapon ( int weapon_type , int weapon_num )
{
2010-07-15 05:40:25 +00:00
if ( nd_record_v_weapon_type = = weapon_type & & nd_record_v_weapon_num = = weapon_num )
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PLAYER_WEAPON ) ;
nd_write_byte ( ( sbyte ) weapon_type ) ;
nd_write_byte ( ( sbyte ) weapon_num ) ;
if ( weapon_type )
nd_write_byte ( ( sbyte ) Secondary_weapon ) ;
else
nd_write_byte ( ( sbyte ) Primary_weapon ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_weapon_type = weapon_type ;
nd_record_v_weapon_num = weapon_num ;
2006-03-20 17:12:09 +00:00
}
2015-05-28 03:08:40 +00:00
void newdemo_record_effect_blowup ( segnum_t segment , int side , const vms_vector & pnt )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_EFFECT_BLOWUP ) ;
nd_write_short ( segment ) ;
nd_write_byte ( ( sbyte ) side ) ;
2014-11-01 14:56:53 +00:00
nd_write_vector ( pnt ) ;
2006-03-20 17:12:09 +00:00
}
void newdemo_record_homing_distance ( fix distance )
{
2010-07-15 05:40:25 +00:00
if ( ( nd_record_v_homing_distance > > 16 ) = = ( distance > > 16 ) )
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_HOMING_DISTANCE ) ;
nd_write_short ( ( short ) ( distance > > 16 ) ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_homing_distance = distance ;
2006-03-20 17:12:09 +00:00
}
void newdemo_record_letterbox ( void )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_LETTERBOX ) ;
}
void newdemo_record_rearview ( void )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_REARVIEW ) ;
}
void newdemo_record_restore_cockpit ( void )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_RESTORE_COCKPIT ) ;
}
void newdemo_record_restore_rearview ( void )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_RESTORE_REARVIEW ) ;
}
void newdemo_record_wall_set_tmap_num1 ( short seg , ubyte side , short cseg , ubyte cside , short tmap )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_WALL_SET_TMAP_NUM1 ) ;
nd_write_short ( seg ) ;
nd_write_byte ( side ) ;
nd_write_short ( cseg ) ;
nd_write_byte ( cside ) ;
nd_write_short ( tmap ) ;
}
void newdemo_record_wall_set_tmap_num2 ( short seg , ubyte side , short cseg , ubyte cside , short tmap )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_WALL_SET_TMAP_NUM2 ) ;
nd_write_short ( seg ) ;
nd_write_byte ( side ) ;
nd_write_short ( cseg ) ;
nd_write_byte ( cside ) ;
nd_write_short ( tmap ) ;
}
void newdemo_record_multi_cloak ( int pnum )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_CLOAK ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
}
void newdemo_record_multi_decloak ( int pnum )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_DECLOAK ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
}
void newdemo_record_multi_death ( int pnum )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_DEATH ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
}
void newdemo_record_multi_kill ( int pnum , sbyte kill )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_KILL ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
nd_write_byte ( kill ) ;
}
2013-06-08 22:24:17 +00:00
void newdemo_record_multi_connect ( int pnum , int new_player , const char * new_callsign )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_CONNECT ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
nd_write_byte ( ( sbyte ) new_player ) ;
if ( ! new_player ) {
2014-07-05 16:48:12 +00:00
nd_write_string ( static_cast < const char * > ( Players [ pnum ] . callsign ) ) ;
2006-03-20 17:12:09 +00:00
nd_write_int ( Players [ pnum ] . net_killed_total ) ;
nd_write_int ( Players [ pnum ] . net_kills_total ) ;
}
nd_write_string ( new_callsign ) ;
}
void newdemo_record_multi_reconnect ( int pnum )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_RECONNECT ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
}
void newdemo_record_multi_disconnect ( int pnum )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_DISCONNECT ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
}
void newdemo_record_player_score ( int score )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PLAYER_SCORE ) ;
nd_write_int ( score ) ;
}
void newdemo_record_multi_score ( int pnum , int score )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_MULTI_SCORE ) ;
nd_write_byte ( ( sbyte ) pnum ) ;
nd_write_int ( score - Players [ pnum ] . score ) ; // called before score is changed!!!!
}
2010-07-15 05:40:25 +00:00
void newdemo_record_primary_ammo ( int new_ammo )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( nd_record_v_primary_ammo = = new_ammo )
2007-11-06 20:33:22 +00:00
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_PRIMARY_AMMO ) ;
2010-07-15 05:40:25 +00:00
if ( nd_record_v_primary_ammo < 0 )
2006-03-20 17:12:09 +00:00
nd_write_short ( ( short ) new_ammo ) ;
else
2010-07-15 05:40:25 +00:00
nd_write_short ( ( short ) nd_record_v_primary_ammo ) ;
2006-03-20 17:12:09 +00:00
nd_write_short ( ( short ) new_ammo ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_primary_ammo = new_ammo ;
2006-03-20 17:12:09 +00:00
}
2010-07-15 05:40:25 +00:00
void newdemo_record_secondary_ammo ( int new_ammo )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( nd_record_v_secondary_ammo = = new_ammo )
2007-11-06 20:33:22 +00:00
return ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_SECONDARY_AMMO ) ;
2010-07-15 05:40:25 +00:00
if ( nd_record_v_secondary_ammo < 0 )
2006-03-20 17:12:09 +00:00
nd_write_short ( ( short ) new_ammo ) ;
else
2010-07-15 05:40:25 +00:00
nd_write_short ( ( short ) nd_record_v_secondary_ammo ) ;
2006-03-20 17:12:09 +00:00
nd_write_short ( ( short ) new_ammo ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_secondary_ammo = new_ammo ;
2006-03-20 17:12:09 +00:00
}
2013-12-29 04:28:07 +00:00
void newdemo_record_door_opening ( segnum_t segnum , int side )
2006-03-20 17:12:09 +00:00
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_DOOR_OPENING ) ;
2013-12-29 04:28:07 +00:00
nd_write_short ( segnum ) ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ( sbyte ) side ) ;
}
void newdemo_record_laser_level ( sbyte old_level , sbyte new_level )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_LASER_LEVEL ) ;
nd_write_byte ( old_level ) ;
nd_write_byte ( new_level ) ;
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
void newdemo_record_cloaking_wall ( int front_wall_num , int back_wall_num , ubyte type , ubyte state , fix cloak_value , fix l0 , fix l1 , fix l2 , fix l3 )
{
Assert ( front_wall_num < = 255 & & back_wall_num < = 255 ) ;
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_CLOAKING_WALL ) ;
nd_write_byte ( front_wall_num ) ;
nd_write_byte ( back_wall_num ) ;
nd_write_byte ( type ) ;
nd_write_byte ( state ) ;
nd_write_byte ( cloak_value ) ;
nd_write_short ( l0 > > 8 ) ;
nd_write_short ( l1 > > 8 ) ;
nd_write_short ( l2 > > 8 ) ;
nd_write_short ( l3 > > 8 ) ;
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
void newdemo_set_new_level ( int level_num )
{
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2006-03-20 17:12:09 +00:00
nd_write_byte ( ND_EVENT_NEW_LEVEL ) ;
nd_write_byte ( ( sbyte ) level_num ) ;
nd_write_byte ( ( sbyte ) Current_level_num ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2010-07-15 05:40:25 +00:00
if ( nd_record_v_juststarted = = 1 )
2006-03-20 17:12:09 +00:00
{
nd_write_int ( Num_walls ) ;
2014-04-27 23:12:34 +00:00
range_for ( auto & w , partial_range ( Walls , Num_walls ) )
2006-03-20 17:12:09 +00:00
{
2014-04-27 23:12:34 +00:00
nd_write_byte ( w . type ) ;
nd_write_byte ( w . flags ) ;
nd_write_byte ( w . state ) ;
2006-03-20 17:12:09 +00:00
2014-04-27 23:12:34 +00:00
int side = w . sidenum ;
segment * seg = & Segments [ w . segnum ] ;
2006-03-20 17:12:09 +00:00
nd_write_short ( seg - > sides [ side ] . tmap_num ) ;
nd_write_short ( seg - > sides [ side ] . tmap_num2 ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_juststarted = 0 ;
2006-03-20 17:12:09 +00:00
}
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
}
2010-01-28 01:08:36 +00:00
/*
* By design , the demo code does not record certain events when demo recording starts or ends .
* To not break compability this function can be applied at start / end of demo recording to
* re - record these events . It will " simulate " those events without using functions older game
* versions cannot handle .
*/
2013-08-31 15:22:40 +00:00
static void newdemo_record_oneframeevent_update ( int wallupdate )
2010-01-28 01:08:36 +00:00
{
if ( Player_is_dead )
newdemo_record_letterbox ( ) ;
else
newdemo_record_restore_cockpit ( ) ;
if ( Rear_view )
newdemo_record_rearview ( ) ;
else
newdemo_record_restore_rearview ( ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
// This will record tmaps for all walls and properly show doors which were opened before demo recording started.
if ( wallupdate )
{
2014-04-27 23:12:34 +00:00
range_for ( auto & w , partial_range ( Walls , Num_walls ) )
2013-03-03 01:03:33 +00:00
{
int side ;
2014-10-02 03:02:34 +00:00
auto seg = & Segments [ w . segnum ] ;
2014-04-27 23:12:34 +00:00
side = w . sidenum ;
2013-03-03 01:03:33 +00:00
// actually this is kinda stupid: when playing ther same tmap will be put on front and back side of the wall ... for doors this is stupid so just record the front side which will do for doors just fine ...
if ( seg - > sides [ side ] . tmap_num ! = 0 )
2014-04-27 23:12:34 +00:00
newdemo_record_wall_set_tmap_num1 ( w . segnum , side , w . segnum , side , seg - > sides [ side ] . tmap_num ) ;
2013-03-03 01:03:33 +00:00
if ( seg - > sides [ side ] . tmap_num2 ! = 0 )
2014-04-27 23:12:34 +00:00
newdemo_record_wall_set_tmap_num2 ( w . segnum , side , w . segnum , side , seg - > sides [ side ] . tmap_num2 ) ;
2013-03-03 01:03:33 +00:00
}
}
# elif defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
( void ) wallupdate ;
2010-01-28 01:08:36 +00:00
if ( Viewer = = Guided_missile [ Player_num ] )
newdemo_record_guided_start ( ) ;
else
newdemo_record_guided_end ( ) ;
2013-03-03 01:03:33 +00:00
# endif
2010-01-28 01:08:36 +00:00
}
2009-11-15 08:22:08 +00:00
enum purpose_type
{
PURPOSE_CHOSE_PLAY = 0 ,
PURPOSE_RANDOM_PLAY ,
PURPOSE_REWRITE
} ;
2013-10-27 22:00:14 +00:00
static int newdemo_read_demo_start ( enum purpose_type purpose )
2006-03-20 17:12:09 +00:00
{
2015-04-26 20:15:56 +00:00
sbyte i = 0 , version = 0 , game_type = 0 , c = 0 ;
2008-10-16 17:27:02 +00:00
ubyte energy = 0 , shield = 0 ;
2010-01-07 14:49:07 +00:00
char current_mission [ 9 ] ;
2010-12-22 00:17:59 +00:00
fix nd_GameTime32 = 0 ;
2006-03-20 17:12:09 +00:00
2007-10-07 14:46:52 +00:00
Rear_view = 0 ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
shareware = 0 ;
# endif
2007-10-07 14:46:52 +00:00
2006-03-20 17:12:09 +00:00
nd_read_byte ( & c ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
nd_write_byte ( c ) ;
2010-07-15 05:40:25 +00:00
if ( ( c ! = ND_EVENT_START_DEMO ) | | nd_playback_v_bad_read ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " %s %s " , TXT_CANT_PLAYBACK , TXT_DEMO_CORRUPT ) ;
2006-03-20 17:12:09 +00:00
return 1 ;
}
nd_read_byte ( & version ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
nd_write_byte ( version ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
if ( version = = DEMO_VERSION_SHAREWARE )
shareware = 1 ;
else if ( version < DEMO_VERSION ) {
if ( purpose = = PURPOSE_CHOSE_PLAY ) {
nm_messagebox ( NULL , 1 , TXT_OK , " %s %s " , TXT_CANT_PLAYBACK , TXT_DEMO_OLD ) ;
}
return 1 ;
}
# endif
2006-03-20 17:12:09 +00:00
nd_read_byte ( & game_type ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
nd_write_byte ( game_type ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
if ( ( game_type = = DEMO_GAME_TYPE_SHAREWARE ) & & shareware )
2014-07-16 02:38:19 +00:00
; // all good
2013-03-03 01:03:33 +00:00
else if ( game_type ! = DEMO_GAME_TYPE ) {
nm_messagebox ( NULL , 1 , TXT_OK , " %s %s " , TXT_CANT_PLAYBACK , TXT_DEMO_OLD ) ;
return 1 ;
}
# elif defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
if ( game_type < DEMO_GAME_TYPE ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " %s %s \n %s " , TXT_CANT_PLAYBACK , TXT_RECORDED , " In Descent: First Strike " ) ;
2006-03-20 17:12:09 +00:00
return 1 ;
}
if ( game_type ! = DEMO_GAME_TYPE ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " %s %s \n %s " , TXT_CANT_PLAYBACK , TXT_RECORDED , " In Unknown Descent version " ) ;
2006-03-20 17:12:09 +00:00
return 1 ;
}
if ( version < DEMO_VERSION ) {
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_CHOSE_PLAY ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " %s %s " , TXT_CANT_PLAYBACK , TXT_DEMO_OLD ) ;
2006-03-20 17:12:09 +00:00
}
return 1 ;
}
2013-03-03 01:03:33 +00:00
# endif
2010-12-22 00:17:59 +00:00
nd_read_fix ( & nd_GameTime32 ) ; // NOTE: Demos write GameTime in fix.
GameTime64 = nd_GameTime32 ;
2009-11-30 14:59:37 +00:00
nd_read_int ( & Newdemo_game_mode ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
{
2010-12-22 00:17:59 +00:00
nd_write_fix ( nd_GameTime32 ) ;
2009-11-30 14:59:37 +00:00
nd_write_int ( Newdemo_game_mode ) ;
2009-11-15 08:22:08 +00:00
}
2010-12-22 00:17:59 +00:00
Boss_cloak_start_time = Boss_cloak_end_time = GameTime64 ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
2009-11-30 14:59:37 +00:00
change_playernum_to ( ( Newdemo_game_mode > > 16 ) & 0x7 ) ;
2013-03-03 01:03:33 +00:00
if ( shareware )
2013-08-31 15:22:40 +00:00
{
2013-03-03 01:03:33 +00:00
if ( Newdemo_game_mode & GM_TEAM )
2009-11-15 08:22:08 +00:00
{
2013-03-03 01:03:33 +00:00
nd_read_byte ( ( sbyte * ) & ( Netgame . team_vector ) ) ;
if ( purpose = = PURPOSE_REWRITE )
nd_write_byte ( Netgame . team_vector ) ;
2009-11-15 08:22:08 +00:00
}
2006-03-20 17:12:09 +00:00
2014-09-20 23:47:27 +00:00
range_for ( auto & i , Players )
{
i . cloak_time = 0 ;
i . invulnerable_time = 0 ;
2013-03-03 01:03:33 +00:00
}
}
else
{
if ( Newdemo_game_mode & GM_TEAM ) {
nd_read_byte ( ( sbyte * ) & ( Netgame . team_vector ) ) ;
2014-07-05 16:48:12 +00:00
nd_read_string ( Netgame . team_name [ 0 ] . buffer ( ) ) ;
nd_read_string ( Netgame . team_name [ 1 ] . buffer ( ) ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
{
2013-03-03 01:03:33 +00:00
nd_write_byte ( Netgame . team_vector ) ;
nd_write_string ( Netgame . team_name [ 0 ] ) ;
nd_write_string ( Netgame . team_name [ 1 ] ) ;
2009-11-15 08:22:08 +00:00
}
2013-03-03 01:03:33 +00:00
}
if ( Newdemo_game_mode & GM_MULTI ) {
2006-03-20 17:12:09 +00:00
2013-03-03 01:03:33 +00:00
if ( purpose ! = PURPOSE_REWRITE )
multi_new_game ( ) ;
nd_read_byte ( & c ) ;
N_players = ( int ) c ;
// changed this to above two lines -- breaks on the mac because of
// endian issues
// nd_read_byte((sbyte *)&N_players);
if ( purpose = = PURPOSE_REWRITE )
nd_write_byte ( N_players ) ;
2014-12-14 05:23:01 +00:00
range_for ( auto & i , partial_range ( Players , N_players ) ) {
i . cloak_time = 0 ;
i . invulnerable_time = 0 ;
nd_read_string ( i . callsign . buffer ( ) ) ;
nd_read_byte ( & ( i . connected ) ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
{
2014-12-14 05:23:01 +00:00
nd_write_string ( static_cast < const char * > ( i . callsign ) ) ;
nd_write_byte ( i . connected ) ;
2013-03-03 01:03:33 +00:00
}
if ( Newdemo_game_mode & GM_MULTI_COOP ) {
2014-12-14 05:23:01 +00:00
nd_read_int ( & ( i . score ) ) ;
2013-03-03 01:03:33 +00:00
if ( purpose = = PURPOSE_REWRITE )
2014-12-14 05:23:01 +00:00
nd_write_int ( i . score ) ;
2013-03-03 01:03:33 +00:00
} else {
2014-12-14 05:23:01 +00:00
nd_read_short ( ( short * ) & ( i . net_killed_total ) ) ;
nd_read_short ( ( short * ) & ( i . net_kills_total ) ) ;
2013-03-03 01:03:33 +00:00
if ( purpose = = PURPOSE_REWRITE )
{
2014-12-14 05:23:01 +00:00
nd_write_short ( i . net_killed_total ) ;
nd_write_short ( i . net_kills_total ) ;
2013-03-03 01:03:33 +00:00
}
2009-11-15 08:22:08 +00:00
}
2006-03-20 17:12:09 +00:00
}
2013-03-03 01:03:33 +00:00
Game_mode = Newdemo_game_mode ;
if ( purpose ! = PURPOSE_REWRITE )
multi_sort_kill_list ( ) ;
Game_mode = GM_NORMAL ;
} else
{
# if defined(DXX_BUILD_DESCENT_II)
2015-07-25 23:10:46 +00:00
nd_read_int ( & ( get_local_player ( ) . score ) ) ; // Note link to above if!
2013-03-03 01:03:33 +00:00
if ( purpose = = PURPOSE_REWRITE )
2015-07-25 23:10:46 +00:00
nd_write_int ( get_local_player ( ) . score ) ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
}
2013-03-03 01:03:33 +00:00
}
# if defined(DXX_BUILD_DESCENT_I)
if ( ! ( Newdemo_game_mode & GM_MULTI ) )
2009-11-15 08:22:08 +00:00
{
2015-07-25 23:10:46 +00:00
nd_read_int ( & ( get_local_player ( ) . score ) ) ; // Note link to above if!
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
2015-07-25 23:10:46 +00:00
nd_write_int ( get_local_player ( ) . score ) ;
2009-11-15 08:22:08 +00:00
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
for ( i = 0 ; i < MAX_PRIMARY_WEAPONS ; i + + )
2009-11-15 08:22:08 +00:00
{
2013-09-20 23:12:54 +00:00
short s ;
nd_read_short ( & s ) ;
2015-10-18 21:01:18 +00:00
if ( i = = primary_weapon_index_t : : VULCAN_INDEX )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . vulcan_ammo = s ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
2013-09-20 23:12:54 +00:00
nd_write_short ( s ) ;
2009-11-15 08:22:08 +00:00
}
2006-03-20 17:12:09 +00:00
2015-07-25 23:10:46 +00:00
range_for ( auto & i , get_local_player ( ) . secondary_ammo )
2009-11-15 08:22:08 +00:00
{
2014-12-14 05:23:01 +00:00
nd_read_short ( ( short * ) & ( i ) ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
2014-12-14 05:23:01 +00:00
nd_write_short ( i ) ;
2009-11-15 08:22:08 +00:00
}
2006-03-20 17:12:09 +00:00
2015-04-26 20:15:56 +00:00
nd_read_byte ( & i ) ;
const stored_laser_level laser_level ( i ) ;
2015-07-25 23:10:46 +00:00
if ( ( purpose ! = PURPOSE_REWRITE ) & & ( laser_level ! = get_local_player ( ) . laser_level ) ) {
get_local_player ( ) . laser_level = laser_level ;
2006-03-20 17:12:09 +00:00
update_laser_weapon_info ( ) ;
}
2009-11-15 08:22:08 +00:00
else if ( purpose = = PURPOSE_REWRITE )
nd_write_byte ( laser_level ) ;
2006-03-20 17:12:09 +00:00
// Support for missions
nd_read_string ( current_mission ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
nd_write_string ( current_mission ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
if ( ! shareware )
{
if ( ( purpose ! = PURPOSE_REWRITE ) & & ! load_mission_by_name ( current_mission ) ) {
if ( purpose = = PURPOSE_CHOSE_PLAY ) {
nm_messagebox ( NULL , 1 , TXT_OK , TXT_NOMISSION4DEMO , current_mission ) ;
}
return 1 ;
}
}
# elif defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
if ( ! load_mission_by_name ( current_mission ) ) {
2009-11-15 08:22:08 +00:00
if ( purpose ! = PURPOSE_RANDOM_PLAY ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , TXT_NOMISSION4DEMO , current_mission ) ;
2006-03-20 17:12:09 +00:00
}
return 1 ;
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
nd_recorded_total = 0 ;
nd_playback_total = 0 ;
2008-01-13 13:27:58 +00:00
nd_read_byte ( ( sbyte * ) & energy ) ;
nd_read_byte ( ( sbyte * ) & shield ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
{
nd_write_byte ( energy ) ;
nd_write_byte ( shield ) ;
}
2006-03-20 17:12:09 +00:00
2015-07-25 23:10:46 +00:00
nd_read_int ( ( int * ) & ( get_local_player ( ) . flags ) ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
2015-07-25 23:10:46 +00:00
nd_write_int ( get_local_player ( ) . flags ) ;
if ( get_local_player ( ) . flags & PLAYER_FLAGS_CLOAKED ) {
get_local_player ( ) . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
}
2015-07-25 23:10:46 +00:00
if ( get_local_player ( ) . flags & PLAYER_FLAGS_INVULNERABLE )
get_local_player ( ) . invulnerable_time = GameTime64 - ( INVULNERABLE_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( ( sbyte * ) & Primary_weapon ) ;
nd_read_byte ( ( sbyte * ) & Secondary_weapon ) ;
2009-11-15 08:22:08 +00:00
if ( purpose = = PURPOSE_REWRITE )
{
nd_write_byte ( Primary_weapon ) ;
nd_write_byte ( Secondary_weapon ) ;
}
2006-03-20 17:12:09 +00:00
2013-03-03 01:03:33 +00:00
// Next bit of code to fix problem that I introduced between 1.0 and 1.1
// check the next byte -- it _will_ be a load_new_level event. If it is
// not, then we must shift all bytes up by one.
if ( shareware )
{
unsigned char c ;
nd_read_byte ( ( sbyte * ) & c ) ;
if ( c ! = ND_EVENT_NEW_LEVEL ) {
int flags ;
2015-07-25 23:10:46 +00:00
flags = get_local_player ( ) . flags ;
2013-03-03 01:03:33 +00:00
energy = shield ;
shield = ( unsigned char ) flags ;
flags = ( flags > > 8 ) & 0x00ffffff ;
flags | = ( Primary_weapon < < 24 ) ;
2015-04-26 20:15:57 +00:00
Primary_weapon = static_cast < primary_weapon_index_t > ( Secondary_weapon ) ;
2013-03-03 01:03:33 +00:00
Secondary_weapon = c ;
} else
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) - 1 ) ;
}
# if defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
nd_playback_v_juststarted = 1 ;
2013-03-03 01:03:33 +00:00
# endif
2015-07-25 23:10:46 +00:00
get_local_player ( ) . energy = i2f ( energy ) ;
get_local_player ( ) . shields = i2f ( shield ) ;
2006-03-20 17:12:09 +00:00
return 0 ;
}
2013-10-27 22:00:14 +00:00
static void newdemo_pop_ctrlcen_triggers ( )
2006-03-20 17:12:09 +00:00
{
2014-12-14 05:23:00 +00:00
int anim_num , n ;
for ( int i = 0 ; i < ControlCenterTriggers . num_links ; i + + ) {
2015-07-12 01:04:21 +00:00
const auto & & seg = vsegptridx ( ControlCenterTriggers . seg [ i ] ) ;
const auto side = ControlCenterTriggers . side [ i ] ;
const auto & & csegp = vsegptr ( seg - > children [ side ] ) ;
2014-09-06 04:06:18 +00:00
auto cside = find_connect_side ( seg , csegp ) ;
2006-03-20 17:12:09 +00:00
anim_num = Walls [ seg - > sides [ side ] . wall_num ] . clip_num ;
n = WallAnims [ anim_num ] . num_frames ;
2009-11-15 08:22:08 +00:00
if ( WallAnims [ anim_num ] . flags & WCF_TMAP1 ) {
2006-03-20 17:12:09 +00:00
seg - > sides [ side ] . tmap_num = csegp - > sides [ cside ] . tmap_num = WallAnims [ anim_num ] . frames [ n - 1 ] ;
} else {
seg - > sides [ side ] . tmap_num2 = csegp - > sides [ cside ] . tmap_num2 = WallAnims [ anim_num ] . frames [ n - 1 ] ;
}
}
}
2013-10-27 22:00:14 +00:00
static int newdemo_read_frame_information ( int rewrite )
2006-03-20 17:12:09 +00:00
{
2014-12-14 05:23:00 +00:00
int done , side , soundno , angle , volume ;
2013-08-31 15:22:40 +00:00
sbyte c ;
2006-03-20 17:12:09 +00:00
done = 0 ;
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED )
2015-02-05 03:03:49 +00:00
range_for ( const auto segnum , highest_valid ( Segments ) )
2015-06-13 22:42:18 +00:00
{
const auto segp = vsegptr ( static_cast < segnum_t > ( segnum ) ) ;
segp - > objects = object_none ;
}
2006-03-20 17:12:09 +00:00
reset_objects ( 1 ) ;
2015-07-25 23:10:46 +00:00
get_local_player ( ) . homing_object_dist = - F1_0 ;
2006-03-20 17:12:09 +00:00
prev_obj = NULL ;
while ( ! done ) {
nd_read_byte ( & c ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite & & ( c ! = ND_EVENT_EOF ) )
nd_write_byte ( c ) ;
2006-03-20 17:12:09 +00:00
switch ( c ) {
case ND_EVENT_START_FRAME : { // Followed by an integer frame number, then a fix FrameTime
short last_frame_length ;
done = 1 ;
nd_read_short ( & last_frame_length ) ;
2010-07-15 05:40:25 +00:00
nd_read_int ( & nd_playback_v_framecount ) ;
2006-03-20 17:12:09 +00:00
nd_read_int ( ( int * ) & nd_recorded_time ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( last_frame_length ) ;
2010-07-15 05:40:25 +00:00
nd_record_v_framebytes_written = 3 ;
nd_write_int ( nd_playback_v_framecount ) ;
2009-11-15 08:22:08 +00:00
nd_write_int ( nd_recorded_time ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state = = ND_STATE_PLAYBACK )
nd_recorded_total + = nd_recorded_time ;
2010-07-15 05:40:25 +00:00
nd_playback_v_framecount - - ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_VIEWER_OBJECT : // Followed by an object structure
2013-08-31 15:22:40 +00:00
{
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
sbyte WhichWindow ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( & WhichWindow ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
nd_write_byte ( WhichWindow ) ;
2006-03-20 17:12:09 +00:00
if ( WhichWindow & 15 )
{
2014-12-14 21:02:40 +00:00
const auto obj = obj_allocate ( ) ;
if ( obj = = object_none )
break ;
nd_read_object ( obj ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read )
2006-03-20 17:12:09 +00:00
{
2006-10-08 15:57:11 +00:00
done = - 1 ;
break ;
2006-03-20 17:12:09 +00:00
}
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
2014-12-14 21:02:40 +00:00
nd_write_object ( obj ) ;
2009-11-15 08:22:08 +00:00
break ;
}
2008-03-08 22:37:09 +00:00
// offset to compensate inaccuracy between object and viewer
2014-12-14 21:02:40 +00:00
vm_vec_scale_add ( obj - > pos , obj - > pos , obj - > orient . fvec , F1_0 * 5 ) ;
nd_render_extras ( WhichWindow , obj ) ;
obj_delete ( obj ) ;
2006-03-20 17:12:09 +00:00
}
else
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
{
2015-07-12 01:04:21 +00:00
nd_read_object ( vobjptridx ( Viewer ) ) ;
2013-03-03 01:03:33 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
if ( rewrite )
{
2015-07-12 01:04:21 +00:00
nd_write_object ( vcobjptr ( Viewer ) ) ;
2013-03-03 01:03:33 +00:00
break ;
}
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED ) {
2014-11-20 03:00:36 +00:00
auto segnum = Viewer - > segnum ;
2013-12-26 22:21:16 +00:00
Viewer - > next = Viewer - > prev = object_none ;
Viewer - > segnum = segment_none ;
2006-03-20 17:12:09 +00:00
2013-03-03 01:03:33 +00:00
// HACK HACK HACK -- since we have multiple level recording, it can be the case
// HACK HACK HACK -- that when rewinding the demo, the viewer is in a segment
// HACK HACK HACK -- that is greater than the highest index of segments. Bash
// HACK HACK HACK -- the viewer to segment 0 for bogus view.
2006-03-20 17:12:09 +00:00
2013-03-03 01:03:33 +00:00
if ( segnum > Highest_segment_index )
segnum = 0 ;
obj_link ( Viewer - Objects , segnum ) ;
}
2006-03-20 17:12:09 +00:00
}
2013-08-31 15:22:40 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
case ND_EVENT_RENDER_OBJECT : // Followed by an object structure
2013-12-24 04:53:59 +00:00
{
2014-10-02 03:02:34 +00:00
const objptridx_t obj = obj_allocate ( ) ;
2013-12-24 04:53:59 +00:00
if ( obj = = object_none )
2006-03-20 17:12:09 +00:00
break ;
nd_read_object ( obj ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_object ( obj ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED ) {
2014-11-20 03:00:36 +00:00
auto segnum = obj - > segnum ;
2013-12-26 22:21:16 +00:00
obj - > next = obj - > prev = object_none ;
obj - > segnum = segment_none ;
2006-03-20 17:12:09 +00:00
// HACK HACK HACK -- don't render objects is segments greater than Highest_segment_index
// HACK HACK HACK -- (see above)
if ( segnum > Highest_segment_index )
break ;
2013-12-24 04:53:59 +00:00
obj_link ( obj , segnum ) ;
2009-11-30 14:59:37 +00:00
if ( ( obj - > type = = OBJ_PLAYER ) & & ( Newdemo_game_mode & GM_MULTI ) ) {
2006-03-20 17:12:09 +00:00
int player ;
2009-11-30 14:59:37 +00:00
if ( Newdemo_game_mode & GM_TEAM )
2013-10-07 23:52:33 +00:00
player = get_team ( get_player_id ( obj ) ) ;
2006-03-20 17:12:09 +00:00
else
2013-10-07 23:52:33 +00:00
player = get_player_id ( obj ) ;
2006-03-20 17:12:09 +00:00
if ( player = = 0 )
break ;
player - - ;
2014-12-14 05:23:00 +00:00
for ( int i = 0 ; i < Polygon_models [ obj - > rtype . pobj_info . model_num ] . n_textures ; i + + )
2006-03-20 17:12:09 +00:00
multi_player_textures [ player ] [ i ] = ObjBitmaps [ ObjBitmapPtrs [ Polygon_models [ obj - > rtype . pobj_info . model_num ] . first_texture + i ] ] ;
multi_player_textures [ player ] [ 4 ] = ObjBitmaps [ ObjBitmapPtrs [ First_multi_bitmap_num + ( player ) * 2 ] ] ;
multi_player_textures [ player ] [ 5 ] = ObjBitmaps [ ObjBitmapPtrs [ First_multi_bitmap_num + ( player ) * 2 + 1 ] ] ;
obj - > rtype . pobj_info . alt_textures = player + 1 ;
}
}
2013-12-24 04:53:59 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
case ND_EVENT_SOUND :
nd_read_int ( & soundno ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( soundno ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state = = ND_STATE_PLAYBACK )
digi_play_sample ( soundno , F1_0 ) ;
break ;
case ND_EVENT_SOUND_3D :
nd_read_int ( & soundno ) ;
nd_read_int ( & angle ) ;
nd_read_int ( & volume ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( soundno ) ;
nd_write_int ( angle ) ;
nd_write_int ( volume ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state = = ND_STATE_PLAYBACK )
digi_play_sample_3d ( soundno , angle , volume , 0 ) ;
break ;
case ND_EVENT_SOUND_3D_ONCE :
nd_read_int ( & soundno ) ;
nd_read_int ( & angle ) ;
nd_read_int ( & volume ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( soundno ) ;
nd_write_int ( angle ) ;
nd_write_int ( volume ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state = = ND_STATE_PLAYBACK )
digi_play_sample_3d ( soundno , angle , volume , 1 ) ;
break ;
case ND_EVENT_LINK_SOUND_TO_OBJ :
{
2013-12-29 04:28:07 +00:00
int soundno , max_volume , max_distance , loop_start , loop_end ;
2006-03-20 17:12:09 +00:00
int signature ;
nd_read_int ( & soundno ) ;
nd_read_int ( & signature ) ;
nd_read_int ( & max_volume ) ;
nd_read_int ( & max_distance ) ;
nd_read_int ( & loop_start ) ;
nd_read_int ( & loop_end ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( soundno ) ;
nd_write_int ( signature ) ;
nd_write_int ( max_volume ) ;
nd_write_int ( max_distance ) ;
nd_write_int ( loop_start ) ;
nd_write_int ( loop_end ) ;
break ;
}
2015-03-22 18:49:21 +00:00
auto objnum = newdemo_find_object ( object_signature_t { static_cast < uint16_t > ( signature ) } ) ;
2013-12-26 22:21:16 +00:00
if ( objnum ! = object_none & & Newdemo_vcr_state = = ND_STATE_PLAYBACK ) { // @mk, 2/22/96, John told me to.
2015-03-22 18:49:21 +00:00
digi_link_sound_to_object3 ( soundno , objnum , 1 , max_volume , vm_distance { max_distance } , loop_start , loop_end ) ;
2006-03-20 17:12:09 +00:00
}
}
break ;
case ND_EVENT_KILL_SOUND_TO_OBJ :
{
2013-12-29 04:28:07 +00:00
int signature ;
2006-03-20 17:12:09 +00:00
nd_read_int ( & signature ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( signature ) ;
break ;
}
2015-03-22 18:49:21 +00:00
auto objnum = newdemo_find_object ( object_signature_t { static_cast < uint16_t > ( signature ) } ) ;
2013-12-26 22:21:16 +00:00
if ( objnum ! = object_none & & Newdemo_vcr_state = = ND_STATE_PLAYBACK ) { // @mk, 2/22/96, John told me to.
2015-03-22 18:49:21 +00:00
digi_kill_sound_linked_to_object ( objnum ) ;
2006-03-20 17:12:09 +00:00
}
}
break ;
case ND_EVENT_WALL_HIT_PROCESS : {
2013-12-29 04:28:07 +00:00
int player ;
segnum_t segnum ;
2006-03-20 17:12:09 +00:00
fix damage ;
2013-12-29 04:28:07 +00:00
nd_read_segnum32 ( segnum ) ;
2006-03-20 17:12:09 +00:00
nd_read_int ( & side ) ;
nd_read_fix ( & damage ) ;
nd_read_int ( & player ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( segnum ) ;
nd_write_int ( side ) ;
nd_write_fix ( damage ) ;
nd_write_int ( player ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED )
2015-07-12 01:04:21 +00:00
wall_hit_process ( vsegptridx ( segnum ) , side , damage , player , vobjptr ( ConsoleObject ) ) ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_TRIGGER :
2013-08-31 15:22:40 +00:00
{
2013-12-29 04:28:07 +00:00
segnum_t segnum ;
objnum_t objnum ;
nd_read_segnum32 ( segnum ) ;
2006-03-20 17:12:09 +00:00
nd_read_int ( & side ) ;
2013-12-29 04:28:07 +00:00
nd_read_objnum32 ( objnum ) ;
2013-08-31 15:22:40 +00:00
int shot ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
shot = 0 ;
# elif defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
nd_read_int ( & shot ) ;
2013-03-03 01:03:33 +00:00
# endif
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( segnum ) ;
nd_write_int ( side ) ;
nd_write_int ( objnum ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
break ;
# elif defined(DXX_BUILD_DESCENT_II)
2009-11-15 08:22:08 +00:00
nd_write_int ( shot ) ;
2013-03-03 01:03:33 +00:00
# endif
2009-11-15 08:22:08 +00:00
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED )
{
2015-07-12 01:04:21 +00:00
const auto & & segp = vsegptridx ( segnum ) ;
2015-09-26 21:17:14 +00:00
/* Demo recording is buggy. Descent records
* ND_EVENT_TRIGGER for every segment transition , even
* if there is no wall .
*/
if ( segp - > sides [ side ] . wall_num ! = wall_none )
{
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2015-07-12 01:04:21 +00:00
if ( Triggers [ Walls [ segp - > sides [ side ] . wall_num ] . trigger ] . type = = TT_SECRET_EXIT ) {
2006-03-20 17:12:09 +00:00
int truth ;
nd_read_byte ( & c ) ;
Assert ( c = = ND_EVENT_SECRET_THINGY ) ;
nd_read_int ( & truth ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( c ) ;
nd_write_int ( truth ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ! truth )
2015-07-12 01:04:21 +00:00
check_trigger ( segp , side , objnum , shot ) ;
2009-11-15 08:22:08 +00:00
} else if ( ! rewrite )
2013-03-03 01:03:33 +00:00
# endif
2015-07-12 01:04:21 +00:00
check_trigger ( segp , side , objnum , shot ) ;
2015-09-26 21:17:14 +00:00
}
2006-03-20 17:12:09 +00:00
}
2013-08-31 15:22:40 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
case ND_EVENT_HOSTAGE_RESCUED : {
int hostage_number ;
nd_read_int ( & hostage_number ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( hostage_number ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED )
2014-10-17 02:04:08 +00:00
hostage_rescue ( ) ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_MORPH_FRAME : {
#if 0
morph_data * md ;
md = & morph_objects [ 0 ] ;
if ( newdemo_read ( md - > morph_vecs , sizeof ( md - > morph_vecs ) , 1 ) ! = 1 ) { done = - 1 ; break ; }
if ( newdemo_read ( md - > submodel_active , sizeof ( md - > submodel_active ) , 1 ) ! = 1 ) { done = - 1 ; break ; }
if ( newdemo_read ( md - > submodel_startpoints , sizeof ( md - > submodel_startpoints ) , 1 ) ! = 1 ) { done = - 1 ; break ; }
# endif
2014-10-02 03:02:34 +00:00
const objptridx_t obj = obj_allocate ( ) ;
2013-12-24 04:53:59 +00:00
if ( obj = = object_none )
2006-03-20 17:12:09 +00:00
break ;
nd_read_object ( obj ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_object ( obj ) ;
break ;
}
2006-03-20 17:12:09 +00:00
obj - > render_type = RT_POLYOBJ ;
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED ) {
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED ) {
2014-11-20 03:00:36 +00:00
auto segnum = obj - > segnum ;
2013-12-26 22:21:16 +00:00
obj - > next = obj - > prev = object_none ;
obj - > segnum = segment_none ;
2013-12-24 04:53:59 +00:00
obj_link ( obj , segnum ) ;
2006-03-20 17:12:09 +00:00
}
}
break ;
}
case ND_EVENT_WALL_TOGGLE :
2013-12-29 04:28:07 +00:00
{
segnum_t segnum ;
nd_read_segnum32 ( segnum ) ;
2006-03-20 17:12:09 +00:00
nd_read_int ( & side ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( segnum ) ;
nd_write_int ( side ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED )
2011-09-24 20:03:36 +00:00
wall_toggle ( segnum , side ) ;
2013-12-29 04:28:07 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
case ND_EVENT_CONTROL_CENTER_DESTROYED :
nd_read_int ( & Countdown_seconds_left ) ;
Control_center_destroyed = 1 ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( Countdown_seconds_left ) ;
break ;
}
2010-07-15 05:40:25 +00:00
if ( ! nd_playback_v_cntrlcen_destroyed ) {
2006-03-20 17:12:09 +00:00
newdemo_pop_ctrlcen_triggers ( ) ;
2010-07-15 05:40:25 +00:00
nd_playback_v_cntrlcen_destroyed = 1 ;
2006-03-20 17:12:09 +00:00
}
break ;
case ND_EVENT_HUD_MESSAGE : {
char hud_msg [ 60 ] ;
nd_read_string ( & ( hud_msg [ 0 ] ) ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_string ( & ( hud_msg [ 0 ] ) ) ;
break ;
}
2008-03-08 22:37:09 +00:00
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED )
2013-06-23 16:27:34 +00:00
HUD_init_message_literal ( HM_DEFAULT , hud_msg ) ;
2006-03-20 17:12:09 +00:00
break ;
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
case ND_EVENT_START_GUIDED :
2008-03-08 22:37:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_guided = 1 ;
2008-03-08 22:37:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_guided = 0 ;
2008-03-08 22:37:09 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
case ND_EVENT_END_GUIDED :
2008-03-08 22:37:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_guided = 1 ;
2008-03-08 22:37:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_guided = 0 ;
2008-03-08 22:37:09 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
case ND_EVENT_PALETTE_EFFECT : {
short r , g , b ;
nd_read_short ( & r ) ;
nd_read_short ( & g ) ;
nd_read_short ( & b ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( r ) ;
nd_write_short ( g ) ;
nd_write_short ( b ) ;
break ;
}
2006-03-20 17:12:09 +00:00
PALETTE_FLASH_SET ( r , g , b ) ;
break ;
}
case ND_EVENT_PLAYER_ENERGY : {
2007-02-08 02:43:55 +00:00
ubyte energy ;
ubyte old_energy ;
2013-08-31 15:22:40 +00:00
if ( ! shareware )
2007-02-08 02:43:55 +00:00
nd_read_byte ( ( sbyte * ) & old_energy ) ;
nd_read_byte ( ( sbyte * ) & energy ) ;
2006-03-20 17:12:09 +00:00
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( old_energy ) ;
nd_write_byte ( energy ) ;
break ;
}
2013-08-31 15:22:40 +00:00
if ( shareware )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . energy = i2f ( energy ) ;
2013-08-31 15:22:40 +00:00
else
{
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2015-07-25 23:10:46 +00:00
get_local_player ( ) . energy = i2f ( energy ) ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2007-02-08 02:43:55 +00:00
if ( old_energy ! = 255 )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . energy = i2f ( old_energy ) ;
2006-03-20 17:12:09 +00:00
}
2013-08-31 15:22:40 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
case ND_EVENT_PLAYER_AFTERBURNER : {
2007-02-08 02:43:55 +00:00
ubyte afterburner ;
ubyte old_afterburner ;
2006-03-20 17:12:09 +00:00
2007-02-08 02:43:55 +00:00
nd_read_byte ( ( sbyte * ) & old_afterburner ) ;
nd_read_byte ( ( sbyte * ) & afterburner ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( old_afterburner ) ;
nd_write_byte ( afterburner ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
Afterburner_charge = afterburner < < 9 ;
2007-02-08 02:43:55 +00:00
// if (Afterburner_charge < 0) Afterburner_charge=f1_0;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2007-02-08 02:43:55 +00:00
if ( old_afterburner ! = 255 )
2006-03-20 17:12:09 +00:00
Afterburner_charge = old_afterburner < < 9 ;
}
break ;
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
case ND_EVENT_PLAYER_SHIELD : {
2007-02-08 02:43:55 +00:00
ubyte shield ;
ubyte old_shield ;
2006-03-20 17:12:09 +00:00
2013-08-31 15:22:40 +00:00
if ( ! shareware )
2007-02-08 02:43:55 +00:00
nd_read_byte ( ( sbyte * ) & old_shield ) ;
nd_read_byte ( ( sbyte * ) & shield ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( old_shield ) ;
nd_write_byte ( shield ) ;
break ;
}
2013-08-31 15:22:40 +00:00
if ( shareware )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . shields = i2f ( shield ) ;
2013-08-31 15:22:40 +00:00
else
{
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2015-07-25 23:10:46 +00:00
get_local_player ( ) . shields = i2f ( shield ) ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2007-02-08 02:43:55 +00:00
if ( old_shield ! = 255 )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . shields = i2f ( old_shield ) ;
2006-03-20 17:12:09 +00:00
}
2013-08-31 15:22:40 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_PLAYER_FLAGS : {
uint oflags ;
2015-07-25 23:10:46 +00:00
nd_read_int ( ( int * ) & ( get_local_player ( ) . flags ) ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) { done = - 1 ; break ; }
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
2015-07-25 23:10:46 +00:00
nd_write_int ( get_local_player ( ) . flags ) ;
2009-11-15 08:22:08 +00:00
break ;
}
2010-06-18 08:22:45 +00:00
2015-07-25 23:10:46 +00:00
oflags = get_local_player ( ) . flags > > 16 ;
get_local_player ( ) . flags & = 0xffff ;
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) & & ( oflags ! = 0xffff ) ) ) {
2015-07-25 23:10:46 +00:00
if ( ! ( oflags & PLAYER_FLAGS_CLOAKED ) & & ( get_local_player ( ) . flags & PLAYER_FLAGS_CLOAKED ) ) {
get_local_player ( ) . cloak_time = 0 ;
2006-03-20 17:12:09 +00:00
}
2015-07-25 23:10:46 +00:00
if ( ( oflags & PLAYER_FLAGS_CLOAKED ) & & ! ( get_local_player ( ) . flags & PLAYER_FLAGS_CLOAKED ) ) {
get_local_player ( ) . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
}
2015-07-25 23:10:46 +00:00
if ( ! ( oflags & PLAYER_FLAGS_INVULNERABLE ) & & ( get_local_player ( ) . flags & PLAYER_FLAGS_INVULNERABLE ) )
get_local_player ( ) . invulnerable_time = 0 ;
if ( ( oflags & PLAYER_FLAGS_INVULNERABLE ) & & ! ( get_local_player ( ) . flags & PLAYER_FLAGS_INVULNERABLE ) )
get_local_player ( ) . invulnerable_time = GameTime64 - ( INVULNERABLE_TIME_MAX / 2 ) ;
get_local_player ( ) . flags = oflags ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2015-07-25 23:10:46 +00:00
if ( ! ( oflags & PLAYER_FLAGS_CLOAKED ) & & ( get_local_player ( ) . flags & PLAYER_FLAGS_CLOAKED ) ) {
get_local_player ( ) . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
}
2015-07-25 23:10:46 +00:00
if ( ( oflags & PLAYER_FLAGS_CLOAKED ) & & ! ( get_local_player ( ) . flags & PLAYER_FLAGS_CLOAKED ) ) {
get_local_player ( ) . cloak_time = 0 ;
2006-03-20 17:12:09 +00:00
}
2015-07-25 23:10:46 +00:00
if ( ! ( oflags & PLAYER_FLAGS_INVULNERABLE ) & & ( get_local_player ( ) . flags & PLAYER_FLAGS_INVULNERABLE ) )
get_local_player ( ) . invulnerable_time = GameTime64 - ( INVULNERABLE_TIME_MAX / 2 ) ;
if ( ( oflags & PLAYER_FLAGS_INVULNERABLE ) & & ! ( get_local_player ( ) . flags & PLAYER_FLAGS_INVULNERABLE ) )
get_local_player ( ) . invulnerable_time = 0 ;
2006-03-20 17:12:09 +00:00
}
update_laser_weapon_info ( ) ; // in case of quad laser change
break ;
}
2013-08-31 15:22:40 +00:00
case ND_EVENT_PLAYER_WEAPON :
2013-03-03 01:03:33 +00:00
if ( shareware )
{
ubyte weapon_type , weapon_num ;
nd_read_byte ( ( sbyte * ) & weapon_type ) ;
nd_read_byte ( ( sbyte * ) & weapon_num ) ;
if ( rewrite )
2013-08-31 15:22:40 +00:00
{
2013-03-03 01:03:33 +00:00
nd_write_byte ( weapon_type ) ;
nd_write_byte ( weapon_num ) ;
break ;
2013-08-31 15:22:40 +00:00
}
2013-03-03 01:03:33 +00:00
if ( weapon_type = = 0 )
2015-04-26 20:15:57 +00:00
Primary_weapon = static_cast < primary_weapon_index_t > ( weapon_num ) ;
2013-08-31 15:22:40 +00:00
else
2013-03-03 01:03:33 +00:00
Secondary_weapon = ( int ) weapon_num ;
break ;
}
else
2013-08-31 15:22:40 +00:00
{
2007-02-08 02:43:55 +00:00
ubyte weapon_type , weapon_num ;
ubyte old_weapon ;
2006-03-20 17:12:09 +00:00
2007-02-08 02:43:55 +00:00
nd_read_byte ( ( sbyte * ) & weapon_type ) ;
nd_read_byte ( ( sbyte * ) & weapon_num ) ;
nd_read_byte ( ( sbyte * ) & old_weapon ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( weapon_type ) ;
nd_write_byte ( weapon_num ) ;
nd_write_byte ( old_weapon ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
if ( weapon_type = = 0 )
2015-04-26 20:15:57 +00:00
Primary_weapon = static_cast < primary_weapon_index_t > ( weapon_num ) ;
2006-03-20 17:12:09 +00:00
else
Secondary_weapon = ( int ) weapon_num ;
} else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
if ( weapon_type = = 0 )
2015-04-26 20:15:57 +00:00
Primary_weapon = static_cast < primary_weapon_index_t > ( old_weapon ) ;
2006-03-20 17:12:09 +00:00
else
Secondary_weapon = ( int ) old_weapon ;
}
break ;
}
case ND_EVENT_EFFECT_BLOWUP : {
2013-12-29 04:28:07 +00:00
segnum_t segnum ;
2006-03-20 17:12:09 +00:00
sbyte side ;
vms_vector pnt ;
2015-05-28 03:08:40 +00:00
nd_read_segnum16 ( segnum ) ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( & side ) ;
2014-11-01 14:57:05 +00:00
nd_read_vector ( pnt ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( segnum ) ;
nd_write_byte ( side ) ;
2014-11-01 14:56:53 +00:00
nd_write_vector ( pnt ) ;
2009-11-15 08:22:08 +00:00
break ;
}
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state ! = ND_STATE_PAUSED )
2015-04-19 04:18:52 +00:00
{
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
2015-07-13 01:09:37 +00:00
check_effect_blowup ( vsegptridx ( segnum ) , side , pnt , nullptr , 0 , 0 ) ;
2013-03-03 01:03:33 +00:00
# elif defined(DXX_BUILD_DESCENT_II)
2015-04-19 04:18:52 +00:00
//create a dummy object which will be the weapon that hits
//the monitor. the blowup code wants to know who the parent of the
//laser is, so create a laser whose parent is the player
laser_parent dummy ;
dummy . parent_type = OBJ_PLAYER ;
dummy . parent_num = Player_num ;
check_effect_blowup ( vsegptridx ( segnum ) , side , pnt , dummy , 0 , 0 ) ;
2013-03-03 01:03:33 +00:00
# endif
2015-04-19 04:18:52 +00:00
}
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_HOMING_DISTANCE : {
short distance ;
nd_read_short ( & distance ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( distance ) ;
break ;
}
2015-07-25 23:10:46 +00:00
get_local_player ( ) . homing_object_dist = i2f ( ( int ) ( distance < < 16 ) ) ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_LETTERBOX :
if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_dead = 1 ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
2010-07-15 05:40:25 +00:00
nd_playback_v_dead = 0 ;
2006-03-20 17:12:09 +00:00
break ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
case ND_EVENT_CHANGE_COCKPIT : {
int dummy ;
nd_read_int ( & dummy ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
nd_write_int ( dummy ) ;
2006-03-20 17:12:09 +00:00
break ;
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
case ND_EVENT_REARVIEW :
if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_rear = 1 ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_rear = 0 ;
2006-03-20 17:12:09 +00:00
}
break ;
case ND_EVENT_RESTORE_COCKPIT :
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_dead = 1 ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
2010-07-15 05:40:25 +00:00
nd_playback_v_dead = 0 ;
2006-03-20 17:12:09 +00:00
break ;
case ND_EVENT_RESTORE_REARVIEW :
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_rear = 1 ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2010-07-15 05:40:25 +00:00
nd_playback_v_rear = 0 ;
2006-03-20 17:12:09 +00:00
}
break ;
case ND_EVENT_WALL_SET_TMAP_NUM1 : {
short seg , cseg , tmap ;
sbyte side , cside ;
nd_read_short ( & seg ) ;
nd_read_byte ( & side ) ;
nd_read_short ( & cseg ) ;
nd_read_byte ( & cside ) ;
nd_read_short ( & tmap ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( seg ) ;
nd_write_byte ( side ) ;
nd_write_short ( cseg ) ;
nd_write_byte ( cside ) ;
nd_write_short ( tmap ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state ! = ND_STATE_PAUSED ) & & ( Newdemo_vcr_state ! = ND_STATE_REWINDING ) & & ( Newdemo_vcr_state ! = ND_STATE_ONEFRAMEBACKWARD ) )
Segments [ seg ] . sides [ side ] . tmap_num = Segments [ cseg ] . sides [ cside ] . tmap_num = tmap ;
break ;
}
case ND_EVENT_WALL_SET_TMAP_NUM2 : {
short seg , cseg , tmap ;
sbyte side , cside ;
nd_read_short ( & seg ) ;
nd_read_byte ( & side ) ;
nd_read_short ( & cseg ) ;
nd_read_byte ( & cside ) ;
nd_read_short ( & tmap ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( seg ) ;
nd_write_byte ( side ) ;
nd_write_short ( cseg ) ;
nd_write_byte ( cside ) ;
nd_write_short ( tmap ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state ! = ND_STATE_PAUSED ) & & ( Newdemo_vcr_state ! = ND_STATE_REWINDING ) & & ( Newdemo_vcr_state ! = ND_STATE_ONEFRAMEBACKWARD ) ) {
Assert ( tmap ! = 0 & & Segments [ seg ] . sides [ side ] . tmap_num2 ! = 0 ) ;
Segments [ seg ] . sides [ side ] . tmap_num2 = Segments [ cseg ] . sides [ cside ] . tmap_num2 = tmap ;
}
break ;
}
case ND_EVENT_MULTI_CLOAK : {
sbyte pnum ;
nd_read_byte ( & pnum ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
Players [ pnum ] . flags & = ~ PLAYER_FLAGS_CLOAKED ;
Players [ pnum ] . cloak_time = 0 ;
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
Players [ pnum ] . flags | = PLAYER_FLAGS_CLOAKED ;
2010-12-22 00:17:59 +00:00
Players [ pnum ] . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
}
break ;
}
case ND_EVENT_MULTI_DECLOAK : {
sbyte pnum ;
nd_read_byte ( & pnum ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
break ;
}
2010-06-18 08:22:45 +00:00
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
Players [ pnum ] . flags | = PLAYER_FLAGS_CLOAKED ;
2010-12-22 00:17:59 +00:00
Players [ pnum ] . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
Players [ pnum ] . flags & = ~ PLAYER_FLAGS_CLOAKED ;
Players [ pnum ] . cloak_time = 0 ;
}
break ;
}
case ND_EVENT_MULTI_DEATH : {
sbyte pnum ;
nd_read_byte ( & pnum ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
Players [ pnum ] . net_killed_total - - ;
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
Players [ pnum ] . net_killed_total + + ;
break ;
}
case ND_EVENT_MULTI_KILL : {
sbyte pnum , kill ;
nd_read_byte ( & pnum ) ;
nd_read_byte ( & kill ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
nd_write_byte ( kill ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
Players [ pnum ] . net_kills_total - = kill ;
2009-11-30 14:59:37 +00:00
if ( Newdemo_game_mode & GM_TEAM )
2006-03-20 17:12:09 +00:00
team_kills [ get_team ( pnum ) ] - = kill ;
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
Players [ pnum ] . net_kills_total + = kill ;
2009-11-30 14:59:37 +00:00
if ( Newdemo_game_mode & GM_TEAM )
2006-03-20 17:12:09 +00:00
team_kills [ get_team ( pnum ) ] + = kill ;
}
2009-11-30 14:59:37 +00:00
Game_mode = Newdemo_game_mode ;
2006-03-20 17:12:09 +00:00
multi_sort_kill_list ( ) ;
2009-11-30 14:59:37 +00:00
Game_mode = GM_NORMAL ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_MULTI_CONNECT : {
sbyte pnum , new_player ;
int killed_total , kills_total ;
2014-07-05 16:48:12 +00:00
callsign_t new_callsign , old_callsign ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( & pnum ) ;
nd_read_byte ( & new_player ) ;
if ( ! new_player ) {
2014-07-05 16:48:12 +00:00
nd_read_string ( old_callsign . buffer ( ) ) ;
2006-03-20 17:12:09 +00:00
nd_read_int ( & killed_total ) ;
nd_read_int ( & kills_total ) ;
}
2014-07-05 16:48:12 +00:00
nd_read_string ( new_callsign . buffer ( ) ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
nd_write_byte ( new_player ) ;
if ( ! new_player ) {
nd_write_string ( old_callsign ) ;
nd_write_int ( killed_total ) ;
nd_write_int ( kills_total ) ;
}
2014-07-05 16:48:12 +00:00
nd_write_string ( static_cast < const char * > ( new_callsign ) ) ;
2009-11-15 08:22:08 +00:00
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2009-11-24 09:48:53 +00:00
Players [ pnum ] . connected = CONNECT_DISCONNECTED ;
2006-03-20 17:12:09 +00:00
if ( ! new_player ) {
2014-07-05 16:48:12 +00:00
Players [ pnum ] . callsign = old_callsign ;
2006-03-20 17:12:09 +00:00
Players [ pnum ] . net_killed_total = killed_total ;
Players [ pnum ] . net_kills_total = kills_total ;
} else {
N_players - - ;
}
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2009-11-24 09:48:53 +00:00
Players [ pnum ] . connected = CONNECT_PLAYING ;
2006-03-20 17:12:09 +00:00
Players [ pnum ] . net_kills_total = 0 ;
Players [ pnum ] . net_killed_total = 0 ;
2014-07-05 16:48:12 +00:00
Players [ pnum ] . callsign = new_callsign ;
2006-03-20 17:12:09 +00:00
if ( new_player )
N_players + + ;
}
break ;
}
case ND_EVENT_MULTI_RECONNECT : {
sbyte pnum ;
nd_read_byte ( & pnum ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
2009-11-24 09:48:53 +00:00
Players [ pnum ] . connected = CONNECT_DISCONNECTED ;
2006-03-20 17:12:09 +00:00
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
2009-11-24 09:48:53 +00:00
Players [ pnum ] . connected = CONNECT_PLAYING ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_MULTI_DISCONNECT : {
sbyte pnum ;
nd_read_byte ( & pnum ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
break ;
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
Players [ pnum ] . connected = CONNECT_DISCONNECTED ;
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
Players [ pnum ] . connected = CONNECT_PLAYING ;
# elif defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
2009-11-24 09:48:53 +00:00
Players [ pnum ] . connected = CONNECT_PLAYING ;
2006-03-20 17:12:09 +00:00
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
2009-11-24 09:48:53 +00:00
Players [ pnum ] . connected = CONNECT_DISCONNECTED ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_MULTI_SCORE : {
int score ;
sbyte pnum ;
nd_read_byte ( & pnum ) ;
nd_read_int ( & score ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( pnum ) ;
nd_write_int ( score ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
Players [ pnum ] . score - = score ;
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
Players [ pnum ] . score + = score ;
2009-11-30 14:59:37 +00:00
Game_mode = Newdemo_game_mode ;
2006-03-20 17:12:09 +00:00
multi_sort_kill_list ( ) ;
2009-11-30 14:59:37 +00:00
Game_mode = GM_NORMAL ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_PLAYER_SCORE : {
int score ;
nd_read_int ( & score ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_int ( score ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . score - = score ;
2006-03-20 17:12:09 +00:00
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . score + = score ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_PRIMARY_AMMO : {
2007-02-08 02:43:55 +00:00
unsigned short old_ammo , new_ammo ;
2006-03-20 17:12:09 +00:00
2007-02-08 02:43:55 +00:00
nd_read_short ( ( short * ) & old_ammo ) ;
nd_read_short ( ( short * ) & new_ammo ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( old_ammo ) ;
nd_write_short ( new_ammo ) ;
break ;
}
2010-06-18 08:22:45 +00:00
2013-09-20 23:12:54 +00:00
unsigned short value ;
2007-02-08 02:43:55 +00:00
// NOTE: Used (Primary_weapon==GAUSS_INDEX?VULCAN_INDEX:Primary_weapon) because game needs VULCAN_INDEX updated to show Gauss ammo
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
2013-09-20 23:12:54 +00:00
value = old_ammo ;
2006-03-20 17:12:09 +00:00
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
2013-09-20 23:12:54 +00:00
value = new_ammo ;
else
break ;
# if defined(DXX_BUILD_DESCENT_II)
2015-10-18 21:01:18 +00:00
if ( Primary_weapon = = primary_weapon_index_t : : OMEGA_INDEX ) // If Omega cannon, we need to update Omega_charge - not stored in primary_ammo
2013-09-20 23:12:54 +00:00
Omega_charge = ( value < = 0 ? f1_0 : value ) ;
else
2013-03-03 01:03:33 +00:00
# endif
2013-09-20 23:12:54 +00:00
if ( weapon_index_uses_vulcan_ammo ( Primary_weapon ) )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . vulcan_ammo = value ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_SECONDARY_AMMO : {
short old_ammo , new_ammo ;
nd_read_short ( & old_ammo ) ;
nd_read_short ( & new_ammo ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( old_ammo ) ;
nd_write_short ( new_ammo ) ;
break ;
}
2010-06-18 08:22:45 +00:00
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . secondary_ammo [ Secondary_weapon ] = old_ammo ;
2006-03-20 17:12:09 +00:00
else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . secondary_ammo [ Secondary_weapon ] = new_ammo ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_DOOR_OPENING : {
2013-12-29 04:28:07 +00:00
segnum_t segnum ;
2006-03-20 17:12:09 +00:00
sbyte side ;
2015-05-28 03:08:40 +00:00
nd_read_segnum16 ( segnum ) ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( & side ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_short ( segnum ) ;
nd_write_byte ( side ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
int anim_num ;
2015-07-12 01:04:21 +00:00
const auto & & segp = vsegptridx ( segnum ) ;
const auto & & csegp = vsegptr ( segp - > children [ side ] ) ;
const auto & & cside = find_connect_side ( segp , csegp ) ;
2006-03-20 17:12:09 +00:00
anim_num = Walls [ segp - > sides [ side ] . wall_num ] . clip_num ;
if ( WallAnims [ anim_num ] . flags & WCF_TMAP1 ) {
segp - > sides [ side ] . tmap_num = csegp - > sides [ cside ] . tmap_num = WallAnims [ anim_num ] . frames [ 0 ] ;
} else {
segp - > sides [ side ] . tmap_num2 = csegp - > sides [ cside ] . tmap_num2 = WallAnims [ anim_num ] . frames [ 0 ] ;
}
}
break ;
}
case ND_EVENT_LASER_LEVEL : {
sbyte old_level , new_level ;
nd_read_byte ( & old_level ) ;
nd_read_byte ( & new_level ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( old_level ) ;
nd_write_byte ( new_level ) ;
break ;
}
2006-03-20 17:12:09 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) ) {
2015-07-25 23:10:46 +00:00
get_local_player ( ) . laser_level = stored_laser_level ( old_level ) ;
2006-03-20 17:12:09 +00:00
update_laser_weapon_info ( ) ;
} else if ( ( Newdemo_vcr_state = = ND_STATE_PLAYBACK ) | | ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) ) {
2015-07-25 23:10:46 +00:00
get_local_player ( ) . laser_level = stored_laser_level ( new_level ) ;
2006-03-20 17:12:09 +00:00
update_laser_weapon_info ( ) ;
}
break ;
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2006-03-20 17:12:09 +00:00
case ND_EVENT_CLOAKING_WALL : {
2008-01-13 13:27:58 +00:00
sbyte type , state , cloak_value ;
ubyte back_wall_num , front_wall_num ;
2006-03-20 17:12:09 +00:00
short l0 , l1 , l2 , l3 ;
int sidenum ;
2008-01-13 13:27:58 +00:00
nd_read_byte ( ( sbyte * ) & front_wall_num ) ;
nd_read_byte ( ( sbyte * ) & back_wall_num ) ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( & type ) ;
nd_read_byte ( & state ) ;
nd_read_byte ( & cloak_value ) ;
nd_read_short ( & l0 ) ;
nd_read_short ( & l1 ) ;
nd_read_short ( & l2 ) ;
nd_read_short ( & l3 ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( front_wall_num ) ;
nd_write_byte ( back_wall_num ) ;
nd_write_byte ( type ) ;
nd_write_byte ( state ) ;
nd_write_byte ( cloak_value ) ;
nd_write_short ( l0 ) ;
nd_write_short ( l1 ) ;
nd_write_short ( l2 ) ;
nd_write_short ( l3 ) ;
break ;
}
2010-06-18 08:22:45 +00:00
2006-03-20 17:12:09 +00:00
Walls [ front_wall_num ] . type = type ;
Walls [ front_wall_num ] . state = state ;
Walls [ front_wall_num ] . cloak_value = cloak_value ;
2014-10-02 03:02:34 +00:00
auto segp = & Segments [ Walls [ front_wall_num ] . segnum ] ;
2006-03-20 17:12:09 +00:00
sidenum = Walls [ front_wall_num ] . sidenum ;
segp - > sides [ sidenum ] . uvls [ 0 ] . l = ( ( int ) l0 ) < < 8 ;
segp - > sides [ sidenum ] . uvls [ 1 ] . l = ( ( int ) l1 ) < < 8 ;
segp - > sides [ sidenum ] . uvls [ 2 ] . l = ( ( int ) l2 ) < < 8 ;
segp - > sides [ sidenum ] . uvls [ 3 ] . l = ( ( int ) l3 ) < < 8 ;
Walls [ back_wall_num ] . type = type ;
Walls [ back_wall_num ] . state = state ;
Walls [ back_wall_num ] . cloak_value = cloak_value ;
segp = & Segments [ Walls [ back_wall_num ] . segnum ] ;
sidenum = Walls [ back_wall_num ] . sidenum ;
segp - > sides [ sidenum ] . uvls [ 0 ] . l = ( ( int ) l0 ) < < 8 ;
segp - > sides [ sidenum ] . uvls [ 1 ] . l = ( ( int ) l1 ) < < 8 ;
segp - > sides [ sidenum ] . uvls [ 2 ] . l = ( ( int ) l2 ) < < 8 ;
segp - > sides [ sidenum ] . uvls [ 3 ] . l = ( ( int ) l3 ) < < 8 ;
break ;
}
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
case ND_EVENT_NEW_LEVEL : {
sbyte new_level , old_level , loaded_level ;
nd_read_byte ( & new_level ) ;
nd_read_byte ( & old_level ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
nd_write_byte ( new_level ) ;
nd_write_byte ( old_level ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
break ;
# elif defined(DXX_BUILD_DESCENT_II)
2009-11-15 08:22:08 +00:00
load_level_robots ( new_level ) ; // for correct robot info reading (specifically boss flag)
2013-03-03 01:03:33 +00:00
# endif
2009-11-15 08:22:08 +00:00
}
else
{
if ( Newdemo_vcr_state = = ND_STATE_PAUSED )
break ;
2006-03-20 17:12:09 +00:00
2015-10-09 02:46:09 +00:00
pause_game_world_time p ;
2009-11-15 08:22:08 +00:00
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
loaded_level = old_level ;
else {
loaded_level = new_level ;
2014-09-20 23:47:27 +00:00
range_for ( auto & i , Players )
{
i . cloak_time = 0 ;
i . flags & = ~ PLAYER_FLAGS_CLOAKED ;
2009-11-15 08:22:08 +00:00
}
}
if ( ( loaded_level < Last_secret_level ) | | ( loaded_level > Last_level ) ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " %s \n %s \n %s " , TXT_CANT_PLAYBACK , TXT_LEVEL_CANT_LOAD , TXT_DEMO_OLD_CORRUPT ) ;
2014-07-20 22:13:25 +00:00
Current_mission . reset ( ) ;
2009-11-15 08:22:08 +00:00
return - 1 ;
2006-03-20 17:12:09 +00:00
}
2009-11-15 08:22:08 +00:00
LoadLevel ( ( int ) loaded_level , 1 ) ;
2010-07-15 05:40:25 +00:00
nd_playback_v_cntrlcen_destroyed = 0 ;
2006-03-20 17:12:09 +00:00
}
2015-08-30 12:04:59 +00:00
if ( ! rewrite )
stop_time ( ) ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_juststarted )
2006-03-20 17:12:09 +00:00
{
nd_read_int ( & Num_walls ) ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
nd_write_int ( Num_walls ) ;
2014-04-27 23:12:34 +00:00
range_for ( auto & w , partial_range ( Walls , Num_walls ) )
// restore the walls
2006-03-20 17:12:09 +00:00
{
2014-04-27 23:12:34 +00:00
nd_read_byte ( ( signed char * ) & w . type ) ;
nd_read_byte ( ( signed char * ) & w . flags ) ;
nd_read_byte ( ( signed char * ) & w . state ) ;
2006-03-20 17:12:09 +00:00
2013-08-31 15:22:40 +00:00
segment * seg ;
2009-11-15 08:22:08 +00:00
if ( rewrite ) // hack some dummy variables
{
seg = & Segments [ 0 ] ;
side = 0 ;
}
else
{
2014-04-27 23:12:34 +00:00
seg = & Segments [ w . segnum ] ;
side = w . sidenum ;
2009-11-15 08:22:08 +00:00
}
2006-03-20 17:12:09 +00:00
nd_read_short ( & seg - > sides [ side ] . tmap_num ) ;
nd_read_short ( & seg - > sides [ side ] . tmap_num2 ) ;
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
if ( rewrite )
{
2014-04-27 23:12:34 +00:00
nd_write_byte ( w . type ) ;
nd_write_byte ( w . flags ) ;
nd_write_byte ( w . state ) ;
2009-11-15 08:22:08 +00:00
nd_write_short ( seg - > sides [ side ] . tmap_num ) ;
nd_write_short ( seg - > sides [ side ] . tmap_num2 ) ;
}
2006-03-20 17:12:09 +00:00
}
2010-06-18 08:22:45 +00:00
2010-07-15 05:40:25 +00:00
nd_playback_v_juststarted = 0 ;
2009-11-15 08:22:08 +00:00
if ( rewrite )
break ;
2007-06-28 14:34:12 +00:00
2009-11-30 14:59:37 +00:00
Game_mode = Newdemo_game_mode ;
2013-08-11 16:03:47 +00:00
if ( game_mode_hoard ( ) )
2007-06-28 14:34:12 +00:00
init_hoard_data ( ) ;
2013-08-11 16:03:47 +00:00
if ( game_mode_capture_flag ( ) | | game_mode_hoard ( ) )
2006-03-20 17:12:09 +00:00
multi_apply_goal_textures ( ) ;
2009-11-30 14:59:37 +00:00
Game_mode = GM_NORMAL ;
2006-03-20 17:12:09 +00:00
}
2009-11-15 08:22:08 +00:00
if ( rewrite )
break ;
2013-03-03 01:03:33 +00:00
# endif
2006-03-20 17:12:09 +00:00
reset_palette_add ( ) ; // get palette back to normal
2010-02-05 02:31:36 +00:00
full_palette_save ( ) ; // initialise for palette_restore()
2015-08-30 12:04:59 +00:00
if ( ! rewrite )
start_time ( ) ;
2006-03-20 17:12:09 +00:00
break ;
}
case ND_EVENT_EOF : {
done = - 1 ;
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) - 1 ) ; // get back to the EOF marker
2010-07-15 05:40:25 +00:00
nd_playback_v_at_eof = 1 ;
nd_playback_v_framecount + + ;
2006-03-20 17:12:09 +00:00
break ;
}
default :
Int3 ( ) ;
}
}
2010-01-28 00:04:29 +00:00
// Now set up cockpit and views according to what we read out. Note that the demo itself cannot determinate the right views since it does not use a good portion of the real game code.
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_dead )
2010-01-28 00:04:29 +00:00
{
Rear_view = 0 ;
if ( PlayerCfg . CockpitMode [ 1 ] ! = CM_LETTERBOX )
select_cockpit ( CM_LETTERBOX ) ;
}
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2010-07-15 05:40:25 +00:00
else if ( nd_playback_v_guided )
2010-01-28 00:04:29 +00:00
{
Rear_view = 0 ;
if ( PlayerCfg . CockpitMode [ 1 ] ! = CM_FULL_SCREEN | | PlayerCfg . CockpitMode [ 1 ] ! = CM_STATUS_BAR )
{
select_cockpit ( ( PlayerCfg . CockpitMode [ 0 ] = = CM_FULL_SCREEN ) ? CM_FULL_SCREEN : CM_STATUS_BAR ) ;
}
}
2013-03-03 01:03:33 +00:00
# endif
2010-07-15 05:40:25 +00:00
else if ( nd_playback_v_rear )
2010-01-28 00:04:29 +00:00
{
2010-07-15 05:40:25 +00:00
Rear_view = nd_playback_v_rear ;
2010-01-28 00:04:29 +00:00
if ( PlayerCfg . CockpitMode [ 0 ] = = CM_FULL_COCKPIT )
select_cockpit ( CM_REAR_VIEW ) ;
}
else
{
Rear_view = 0 ;
if ( PlayerCfg . CockpitMode [ 1 ] ! = PlayerCfg . CockpitMode [ 0 ] )
select_cockpit ( PlayerCfg . CockpitMode [ 0 ] ) ;
}
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_bad_read ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " %s %s " , TXT_DEMO_ERR_READING , TXT_DEMO_OLD_CORRUPT ) ;
2014-07-20 22:13:25 +00:00
Current_mission . reset ( ) ;
2006-03-20 17:12:09 +00:00
}
return done ;
}
void newdemo_goto_beginning ( )
{
2010-07-15 05:40:25 +00:00
//if (nd_playback_v_framecount == 0)
2006-03-20 17:12:09 +00:00
// return;
PHYSFS_seek ( infile , 0 ) ;
Newdemo_vcr_state = ND_STATE_PLAYBACK ;
2013-10-06 03:02:50 +00:00
if ( newdemo_read_demo_start ( PURPOSE_CHOSE_PLAY ) )
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
2009-11-15 08:22:08 +00:00
if ( newdemo_read_frame_information ( 0 ) = = - 1 )
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
2009-11-15 08:22:08 +00:00
if ( newdemo_read_frame_information ( 0 ) = = - 1 )
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
Newdemo_vcr_state = ND_STATE_PAUSED ;
2010-07-15 05:40:25 +00:00
nd_playback_v_at_eof = 0 ;
2006-03-20 17:12:09 +00:00
}
2009-11-15 08:22:08 +00:00
void newdemo_goto_end ( int to_rewrite )
2006-03-20 17:12:09 +00:00
{
2008-10-16 17:27:02 +00:00
short frame_length = 0 , byte_count = 0 , bshort = 0 ;
2015-04-26 20:15:56 +00:00
sbyte level = 0 , bbyte = 0 , c = 0 , cloaked = 0 ;
2008-10-16 17:27:02 +00:00
ubyte energy = 0 , shield = 0 ;
2014-12-14 05:23:00 +00:00
int loc = 0 , bint = 0 ;
2006-03-20 17:12:09 +00:00
2011-06-01 07:59:55 +00:00
PHYSFSX_fseek ( infile , - 2 , SEEK_END ) ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( & level ) ;
2009-11-15 08:22:08 +00:00
if ( ! to_rewrite )
{
if ( ( level < Last_secret_level ) | | ( level > Last_level ) ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " %s \n %s \n %s " , TXT_CANT_PLAYBACK , TXT_LEVEL_CANT_LOAD , TXT_DEMO_OLD_CORRUPT ) ;
2014-07-20 22:13:25 +00:00
Current_mission . reset ( ) ;
2009-11-15 08:22:08 +00:00
newdemo_stop_playback ( ) ;
return ;
}
if ( level ! = Current_level_num )
LoadLevel ( level , 1 ) ;
}
2013-03-03 01:03:33 +00:00
else
# if defined(DXX_BUILD_DESCENT_II)
if ( level ! = Current_level_num )
# endif
2009-11-15 08:22:08 +00:00
{
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2009-11-15 08:22:08 +00:00
load_level_robots ( level ) ; // for correct robot info reading (specifically boss flag)
2013-03-03 01:03:33 +00:00
# endif
2009-11-15 08:22:08 +00:00
Current_level_num = level ;
2008-10-16 17:27:02 +00:00
}
2006-03-20 17:12:09 +00:00
2013-08-31 15:22:40 +00:00
if ( shareware )
{
2013-03-03 01:03:33 +00:00
if ( Newdemo_game_mode & GM_MULTI ) {
PHYSFSX_fseek ( infile , - 10 , SEEK_END ) ;
nd_read_byte ( & cloaked ) ;
2014-09-20 23:47:27 +00:00
for ( uint_fast32_t i = 0 ; i < MAX_PLAYERS ; i + + ) {
2013-03-03 01:03:33 +00:00
if ( ( 1 < < i ) & cloaked )
Players [ i ] . flags | = PLAYER_FLAGS_CLOAKED ;
Players [ i ] . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
}
}
if ( to_rewrite )
return ;
PHYSFSX_fseek ( infile , - 12 , SEEK_END ) ;
nd_read_short ( & frame_length ) ;
2013-08-31 15:22:40 +00:00
}
else
{
2011-06-01 07:59:55 +00:00
PHYSFSX_fseek ( infile , - 4 , SEEK_END ) ;
2006-03-20 17:12:09 +00:00
nd_read_short ( & byte_count ) ;
2011-06-01 07:59:55 +00:00
PHYSFSX_fseek ( infile , - 2 - byte_count , SEEK_CUR ) ;
2006-03-20 17:12:09 +00:00
nd_read_short ( & frame_length ) ;
2011-06-01 07:59:55 +00:00
loc = PHYSFS_tell ( infile ) ;
2009-11-30 14:59:37 +00:00
if ( Newdemo_game_mode & GM_MULTI )
2009-11-15 08:22:08 +00:00
{
nd_read_byte ( & cloaked ) ;
2014-09-20 23:47:27 +00:00
for ( uint_fast32_t i = 0 ; i < MAX_PLAYERS ; i + + )
2009-11-15 08:22:08 +00:00
if ( cloaked & ( 1 < < i ) )
Players [ i ] . flags | = PLAYER_FLAGS_CLOAKED ;
}
2006-03-20 17:12:09 +00:00
else
nd_read_byte ( & bbyte ) ;
nd_read_byte ( & bbyte ) ;
nd_read_short ( & bshort ) ;
nd_read_int ( & bint ) ;
2007-04-03 20:53:45 +00:00
nd_read_byte ( ( sbyte * ) & energy ) ;
nd_read_byte ( ( sbyte * ) & shield ) ;
2015-07-25 23:10:46 +00:00
get_local_player ( ) . energy = i2f ( energy ) ;
get_local_player ( ) . shields = i2f ( shield ) ;
nd_read_int ( ( int * ) & ( get_local_player ( ) . flags ) ) ;
if ( get_local_player ( ) . flags & PLAYER_FLAGS_CLOAKED ) {
get_local_player ( ) . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
}
if ( get_local_player ( ) . flags & PLAYER_FLAGS_INVULNERABLE )
get_local_player ( ) . invulnerable_time = GameTime64 - ( INVULNERABLE_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
nd_read_byte ( ( sbyte * ) & Primary_weapon ) ;
nd_read_byte ( ( sbyte * ) & Secondary_weapon ) ;
2014-12-14 05:23:00 +00:00
for ( int i = 0 ; i < MAX_PRIMARY_WEAPONS ; i + + )
2013-09-20 23:12:54 +00:00
{
short s ;
nd_read_short ( & s ) ;
2015-10-18 21:01:18 +00:00
if ( i = = primary_weapon_index_t : : VULCAN_INDEX )
2015-07-25 23:10:46 +00:00
get_local_player ( ) . vulcan_ammo = s ;
2013-09-20 23:12:54 +00:00
}
2015-07-25 23:10:46 +00:00
range_for ( auto & i , get_local_player ( ) . secondary_ammo )
2014-12-14 05:23:01 +00:00
nd_read_short ( ( short * ) & ( i ) ) ;
2015-04-26 20:15:56 +00:00
int8_t i ;
nd_read_byte ( & i ) ;
const stored_laser_level laser_level ( i ) ;
2015-07-25 23:10:46 +00:00
if ( laser_level ! = get_local_player ( ) . laser_level ) {
get_local_player ( ) . laser_level = laser_level ;
2009-11-15 08:22:08 +00:00
if ( ! to_rewrite )
update_laser_weapon_info ( ) ;
2006-03-20 17:12:09 +00:00
}
2009-11-30 14:59:37 +00:00
if ( Newdemo_game_mode & GM_MULTI ) {
2006-03-20 17:12:09 +00:00
nd_read_byte ( & c ) ;
N_players = ( int ) c ;
// see newdemo_read_start_demo for explanation of
// why this is commented out
// nd_read_byte((sbyte *)&N_players);
2014-12-14 05:23:01 +00:00
range_for ( auto & i , partial_range ( Players , N_players ) ) {
nd_read_string ( i . callsign . buffer ( ) ) ;
nd_read_byte ( & ( i . connected ) ) ;
2009-11-30 14:59:37 +00:00
if ( Newdemo_game_mode & GM_MULTI_COOP ) {
2014-12-14 05:23:01 +00:00
nd_read_int ( & ( i . score ) ) ;
2006-03-20 17:12:09 +00:00
} else {
2014-12-14 05:23:01 +00:00
nd_read_short ( ( short * ) & ( i . net_killed_total ) ) ;
nd_read_short ( ( short * ) & ( i . net_kills_total ) ) ;
2006-03-20 17:12:09 +00:00
}
}
} else {
2015-07-25 23:10:46 +00:00
nd_read_int ( & ( get_local_player ( ) . score ) ) ;
2006-03-20 17:12:09 +00:00
}
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
if ( to_rewrite )
return ;
2006-03-20 17:12:09 +00:00
2011-06-01 07:59:55 +00:00
PHYSFSX_fseek ( infile , loc , SEEK_SET ) ;
2013-08-31 15:22:40 +00:00
}
2011-06-01 07:59:55 +00:00
PHYSFSX_fseek ( infile , - frame_length , SEEK_CUR ) ;
2010-07-15 05:40:25 +00:00
nd_read_int ( & nd_playback_v_framecount ) ; // get the frame count
nd_playback_v_framecount - - ;
2011-06-01 07:59:55 +00:00
PHYSFSX_fseek ( infile , 4 , SEEK_CUR ) ;
2006-03-20 17:12:09 +00:00
Newdemo_vcr_state = ND_STATE_PLAYBACK ;
2009-11-15 08:22:08 +00:00
newdemo_read_frame_information ( 0 ) ; // then the frame information
2006-03-20 17:12:09 +00:00
Newdemo_vcr_state = ND_STATE_PAUSED ;
return ;
}
2013-10-27 22:00:14 +00:00
static void newdemo_back_frames ( int frames )
2006-03-20 17:12:09 +00:00
{
short last_frame_length ;
2014-12-14 05:23:00 +00:00
for ( int i = 0 ; i < frames ; i + + )
2006-03-20 17:12:09 +00:00
{
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) - 10 ) ;
nd_read_short ( & last_frame_length ) ;
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) + 8 - last_frame_length ) ;
2010-07-15 05:40:25 +00:00
if ( ! nd_playback_v_at_eof & & newdemo_read_frame_information ( 0 ) = = - 1 ) {
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
return ;
}
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_at_eof )
nd_playback_v_at_eof = 0 ;
2006-03-20 17:12:09 +00:00
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) - 10 ) ;
nd_read_short ( & last_frame_length ) ;
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) + 8 - last_frame_length ) ;
}
}
2010-01-20 23:28:35 +00:00
/*
* routine to interpolate the viewer position . the current position is
* stored in the Viewer object . Save this position , and read the next
* frame to get all objects read in . Calculate the delta playback and
* the delta recording frame times between the two frames , then intepolate
* the viewers position accordingly . nd_recorded_time is the time that it
* took the recording to render the frame that we are currently looking
* at .
*/
2013-10-27 22:00:14 +00:00
static void interpolate_frame ( fix d_play , fix d_recorded )
2006-03-20 17:12:09 +00:00
{
2014-12-14 05:23:01 +00:00
unsigned num_cur_objs ;
2010-01-20 23:28:35 +00:00
fix factor ;
static fix InterpolStep = fl2f ( .01 ) ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_framecount < 1 )
2010-06-20 20:32:30 +00:00
return ;
2010-01-20 23:28:35 +00:00
factor = fixdiv ( d_play , d_recorded ) ;
if ( factor > F1_0 )
factor = F1_0 ;
2006-03-20 17:12:09 +00:00
2010-01-20 23:28:35 +00:00
num_cur_objs = Highest_object_index ;
2013-12-12 21:53:23 +00:00
std : : vector < object > cur_objs ( Objects . begin ( ) , Objects . begin ( ) + num_cur_objs + 1 ) ;
2006-03-20 17:12:09 +00:00
Newdemo_vcr_state = ND_STATE_PAUSED ;
2010-01-20 23:28:35 +00:00
if ( newdemo_read_frame_information ( 0 ) = = - 1 ) {
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
return ;
}
2010-01-26 12:04:50 +00:00
InterpolStep - = FrameTime ;
2010-06-18 08:22:45 +00:00
2010-01-26 12:04:50 +00:00
// This interpolating looks just more crappy on high FPS, so let's not even waste performance on it.
if ( InterpolStep < = 0 )
{
2014-12-14 05:23:01 +00:00
range_for ( auto & i , partial_range ( cur_objs , 1 + num_cur_objs ) ) {
2015-02-05 03:03:49 +00:00
range_for ( const auto j , highest_valid ( Objects ) )
2014-10-12 23:05:46 +00:00
{
2015-06-13 22:42:18 +00:00
const auto & & objp = vobjptr ( static_cast < objnum_t > ( j ) ) ;
if ( i . signature = = objp - > signature ) {
2014-12-14 05:23:01 +00:00
sbyte render_type = i . render_type ;
2010-01-26 12:04:50 +00:00
fix delta_x , delta_y , delta_z ;
// Extract the angles from the object orientation matrix.
// Some of this code taken from ai_turn_towards_vector
// Don't do the interpolation on certain render types which don't use an orientation matrix
if ( ! ( ( render_type = = RT_LASER ) | | ( render_type = = RT_FIREBALL ) | | ( render_type = = RT_POWERUP ) ) ) {
vms_vector fvec1 , fvec2 , rvec1 , rvec2 ;
fix mag1 ;
2014-12-14 05:23:01 +00:00
fvec1 = i . orient . fvec ;
2014-09-28 21:11:05 +00:00
vm_vec_scale ( fvec1 , F1_0 - factor ) ;
2015-06-13 22:42:18 +00:00
fvec2 = objp - > orient . fvec ;
2014-09-28 21:11:05 +00:00
vm_vec_scale ( fvec2 , factor ) ;
2014-09-28 21:43:00 +00:00
vm_vec_add2 ( fvec1 , fvec2 ) ;
2014-09-28 21:11:04 +00:00
mag1 = vm_vec_normalize_quick ( fvec1 ) ;
2010-01-26 12:04:50 +00:00
if ( mag1 > F1_0 / 256 ) {
2014-12-14 05:23:01 +00:00
rvec1 = i . orient . rvec ;
2014-09-28 21:11:05 +00:00
vm_vec_scale ( rvec1 , F1_0 - factor ) ;
2015-06-13 22:42:18 +00:00
rvec2 = objp - > orient . rvec ;
2014-09-28 21:11:05 +00:00
vm_vec_scale ( rvec2 , factor ) ;
2014-09-28 21:43:00 +00:00
vm_vec_add2 ( rvec1 , rvec2 ) ;
2014-09-28 21:11:04 +00:00
vm_vec_normalize_quick ( rvec1 ) ; // Note: Doesn't matter if this is null, if null, vm_vector_2_matrix will just use fvec1
2014-12-14 05:23:01 +00:00
vm_vector_2_matrix ( i . orient , fvec1 , nullptr , & rvec1 ) ;
2010-01-26 12:04:50 +00:00
}
2006-03-20 17:12:09 +00:00
}
2010-01-20 23:28:35 +00:00
2010-01-26 12:04:50 +00:00
// Interpolate the object position. This is just straight linear
// interpolation.
2010-01-20 23:28:35 +00:00
2015-06-13 22:42:18 +00:00
delta_x = objp - > pos . x - i . pos . x ;
delta_y = objp - > pos . y - i . pos . y ;
delta_z = objp - > pos . z - i . pos . z ;
2010-01-20 23:28:35 +00:00
2010-01-26 12:04:50 +00:00
delta_x = fixmul ( delta_x , factor ) ;
delta_y = fixmul ( delta_y , factor ) ;
delta_z = fixmul ( delta_z , factor ) ;
2010-01-20 23:28:35 +00:00
2014-12-14 05:23:01 +00:00
i . pos . x + = delta_x ;
i . pos . y + = delta_y ;
i . pos . z + = delta_z ;
2010-01-26 12:04:50 +00:00
}
2006-03-20 17:12:09 +00:00
}
}
2010-01-26 12:04:50 +00:00
InterpolStep = fl2f ( .01 ) ;
2006-03-20 17:12:09 +00:00
}
2010-01-20 23:28:35 +00:00
// get back to original position in the demo file. Reread the current
// frame information again to reset all of the object stuff not covered
// with Highest_object_index and the object array (previously rendered
// objects, etc....)
newdemo_back_frames ( 1 ) ;
newdemo_back_frames ( 1 ) ;
if ( newdemo_read_frame_information ( 0 ) = = - 1 )
newdemo_stop_playback ( ) ;
Newdemo_vcr_state = ND_STATE_PLAYBACK ;
2013-12-12 21:53:23 +00:00
std : : copy ( cur_objs . begin ( ) , cur_objs . begin ( ) + num_cur_objs + 1 , Objects . begin ( ) ) ;
2010-01-20 23:28:35 +00:00
Highest_object_index = num_cur_objs ;
2006-03-20 17:12:09 +00:00
}
void newdemo_playback_one_frame ( )
{
2014-12-14 05:23:00 +00:00
int frames_back , level ;
2010-01-20 23:28:35 +00:00
static fix base_interpol_time = 0 ;
static fix d_recorded = 0 ;
2006-03-20 17:12:09 +00:00
2014-09-20 23:47:27 +00:00
range_for ( auto & i , Players )
if ( i . flags & PLAYER_FLAGS_CLOAKED )
i . cloak_time = GameTime64 - ( CLOAK_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
2015-07-25 23:10:46 +00:00
if ( get_local_player ( ) . flags & PLAYER_FLAGS_INVULNERABLE )
get_local_player ( ) . invulnerable_time = GameTime64 - ( INVULNERABLE_TIME_MAX / 2 ) ;
2006-03-20 17:12:09 +00:00
if ( Newdemo_vcr_state = = ND_STATE_PAUSED ) // render a frame or not
return ;
Control_center_destroyed = 0 ;
Countdown_seconds_left = - 1 ;
PALETTE_FLASH_SET ( 0 , 0 , 0 ) ; //clear flash
if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) | | ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) )
{
level = Current_level_num ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_framecount = = 0 )
2006-03-20 17:12:09 +00:00
return ;
2010-07-15 05:40:25 +00:00
else if ( ( Newdemo_vcr_state = = ND_STATE_REWINDING ) & & ( nd_playback_v_framecount < 10 ) ) {
2006-03-20 17:12:09 +00:00
newdemo_goto_beginning ( ) ;
return ;
}
if ( Newdemo_vcr_state = = ND_STATE_REWINDING )
frames_back = 10 ;
else
frames_back = 1 ;
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_at_eof ) {
2013-08-31 15:22:40 +00:00
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) + ( shareware ? - 2 : + 11 ) ) ;
2006-03-20 17:12:09 +00:00
}
newdemo_back_frames ( frames_back ) ;
if ( level ! = Current_level_num )
newdemo_pop_ctrlcen_triggers ( ) ;
if ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEBACKWARD ) {
if ( level ! = Current_level_num )
newdemo_back_frames ( 1 ) ;
Newdemo_vcr_state = ND_STATE_PAUSED ;
}
}
else if ( Newdemo_vcr_state = = ND_STATE_FASTFORWARD ) {
2010-07-15 05:40:25 +00:00
if ( ! nd_playback_v_at_eof )
2006-03-20 17:12:09 +00:00
{
2014-12-14 05:23:00 +00:00
for ( int i = 0 ; i < 10 ; i + + )
2006-03-20 17:12:09 +00:00
{
2009-11-15 08:22:08 +00:00
if ( newdemo_read_frame_information ( 0 ) = = - 1 )
2006-03-20 17:12:09 +00:00
{
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_at_eof )
2006-03-20 17:12:09 +00:00
Newdemo_vcr_state = ND_STATE_PAUSED ;
else
newdemo_stop_playback ( ) ;
break ;
}
}
}
else
Newdemo_vcr_state = ND_STATE_PAUSED ;
}
else if ( Newdemo_vcr_state = = ND_STATE_ONEFRAMEFORWARD ) {
2010-07-15 05:40:25 +00:00
if ( ! nd_playback_v_at_eof ) {
2006-03-20 17:12:09 +00:00
level = Current_level_num ;
2009-11-15 08:22:08 +00:00
if ( newdemo_read_frame_information ( 0 ) = = - 1 ) {
2010-07-15 05:40:25 +00:00
if ( ! nd_playback_v_at_eof )
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
}
if ( level ! = Current_level_num ) {
2009-11-15 08:22:08 +00:00
if ( newdemo_read_frame_information ( 0 ) = = - 1 ) {
2010-07-15 05:40:25 +00:00
if ( ! nd_playback_v_at_eof )
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
}
}
Newdemo_vcr_state = ND_STATE_PAUSED ;
} else
Newdemo_vcr_state = ND_STATE_PAUSED ;
}
else {
2010-01-20 23:28:35 +00:00
2006-03-20 17:12:09 +00:00
// First, uptate the total playback time to date. Then we check to see
2010-01-20 23:28:35 +00:00
// if we need to change the playback style to interpolate frames or
// skip frames based on where the playback time is relative to the
// recorded time.
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_framecount < = 0 )
2006-03-20 17:12:09 +00:00
nd_playback_total = nd_recorded_total ; // baseline total playback time
else
nd_playback_total + = FrameTime ;
2007-11-06 20:33:22 +00:00
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_style = = NORMAL_PLAYBACK )
2007-11-06 20:33:22 +00:00
{
if ( nd_playback_total > nd_recorded_total )
2010-07-15 05:40:25 +00:00
nd_playback_v_style = SKIP_PLAYBACK ;
2010-01-20 23:28:35 +00:00
if ( nd_recorded_total > 0 & & nd_recorded_time > 0 )
{
2010-07-15 05:40:25 +00:00
nd_playback_v_style = INTERPOLATE_PLAYBACK ;
2010-01-20 23:28:35 +00:00
nd_playback_total = nd_recorded_total + FrameTime ; // baseline playback time
base_interpol_time = nd_recorded_total ;
d_recorded = nd_recorded_time ; // baseline delta recorded
}
2007-11-06 20:33:22 +00:00
}
2006-03-20 17:12:09 +00:00
2010-01-20 23:28:35 +00:00
2010-07-15 05:40:25 +00:00
if ( ( nd_playback_v_style = = INTERPOLATE_PLAYBACK ) & & Newdemo_do_interpolate ) {
2010-01-20 23:28:35 +00:00
fix d_play = 0 ;
if ( nd_recorded_total - nd_playback_total < FrameTime ) {
d_recorded = nd_recorded_total - nd_playback_total ;
while ( nd_recorded_total - nd_playback_total < FrameTime ) {
2014-12-14 05:23:01 +00:00
int level ;
unsigned num_objs ;
2010-01-20 23:28:35 +00:00
num_objs = Highest_object_index ;
2013-12-12 21:53:23 +00:00
std : : vector < object > cur_objs ( Objects . begin ( ) , Objects . begin ( ) + num_objs + 1 ) ;
2010-01-20 23:28:35 +00:00
level = Current_level_num ;
if ( newdemo_read_frame_information ( 0 ) = = - 1 ) {
newdemo_stop_playback ( ) ;
return ;
}
if ( level ! = Current_level_num ) {
if ( newdemo_read_frame_information ( 0 ) = = - 1 )
newdemo_stop_playback ( ) ;
break ;
}
// for each new object in the frame just read in, determine if there is
// a corresponding object that we have been interpolating. If so, then
// copy that interpolated object to the new Objects array so that the
// interpolated position and orientation can be preserved.
2014-12-14 05:23:01 +00:00
range_for ( auto & i , partial_range ( cur_objs , 1 + num_objs ) ) {
2015-02-05 03:03:49 +00:00
range_for ( const auto j , highest_valid ( Objects ) )
2014-10-12 23:05:46 +00:00
{
2015-06-13 22:42:18 +00:00
const auto & & objp = vobjptr ( static_cast < objnum_t > ( j ) ) ;
if ( i . signature = = objp - > signature ) {
objp - > orient = i . orient ;
objp - > pos = i . pos ;
2010-01-20 23:28:35 +00:00
break ;
}
}
}
d_recorded + = nd_recorded_time ;
base_interpol_time = nd_playback_total - FrameTime ;
}
}
d_play = nd_playback_total - base_interpol_time ;
interpolate_frame ( d_play , d_recorded ) ;
2006-03-20 17:12:09 +00:00
return ;
}
2010-01-20 23:28:35 +00:00
else {
if ( newdemo_read_frame_information ( 0 ) = = - 1 ) {
newdemo_stop_playback ( ) ;
return ;
}
2010-07-15 05:40:25 +00:00
if ( nd_playback_v_style = = SKIP_PLAYBACK ) {
2010-01-20 23:28:35 +00:00
while ( nd_playback_total > nd_recorded_total ) {
if ( newdemo_read_frame_information ( 0 ) = = - 1 ) {
newdemo_stop_playback ( ) ;
return ;
}
2006-03-20 17:12:09 +00:00
}
}
}
}
}
void newdemo_start_recording ( )
{
Newdemo_num_written = 0 ;
2010-07-15 05:40:25 +00:00
nd_record_v_no_space = 0 ;
2006-03-20 17:12:09 +00:00
Newdemo_state = ND_STATE_RECORDING ;
2009-11-15 08:22:08 +00:00
PHYSFS_mkdir ( DEMO_DIR ) ; //always try making directory - could only exist in read-only path
2008-10-16 17:27:02 +00:00
outfile = PHYSFSX_openWriteBuffered ( DEMO_FILENAME ) ;
2006-03-20 17:12:09 +00:00
2015-01-29 00:45:18 +00:00
if ( ! outfile )
2006-03-20 17:12:09 +00:00
{
Newdemo_state = ND_STATE_NORMAL ;
2009-11-15 08:22:08 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " Cannot open demo temp file " ) ;
2006-03-20 17:12:09 +00:00
}
else
newdemo_record_start_demo ( ) ;
}
2013-10-27 22:00:14 +00:00
static void newdemo_write_end ( )
2006-03-20 17:12:09 +00:00
{
sbyte cloaked = 0 ;
unsigned short byte_count = 0 ;
nd_write_byte ( ND_EVENT_EOF ) ;
2010-07-15 05:40:25 +00:00
nd_write_short ( nd_record_v_framebytes_written - 1 ) ;
2006-03-20 17:12:09 +00:00
if ( Game_mode & GM_MULTI ) {
2014-12-14 05:23:00 +00:00
for ( int i = 0 ; i < N_players ; i + + ) {
2009-11-15 08:22:08 +00:00
if ( Players [ i ] . flags & PLAYER_FLAGS_CLOAKED )
cloaked | = ( 1 < < i ) ;
2006-03-20 17:12:09 +00:00
}
nd_write_byte ( cloaked ) ;
nd_write_byte ( ND_EVENT_EOF ) ;
} else {
nd_write_short ( ND_EVENT_EOF ) ;
}
nd_write_short ( ND_EVENT_EOF ) ;
nd_write_int ( ND_EVENT_EOF ) ;
2010-06-18 08:22:45 +00:00
2013-08-31 15:22:40 +00:00
if ( ! shareware )
{
2010-07-15 05:40:25 +00:00
byte_count + = 10 ; // from nd_record_v_framebytes_written
2010-06-18 08:22:45 +00:00
2015-07-25 23:10:46 +00:00
nd_write_byte ( ( sbyte ) ( f2ir ( get_local_player ( ) . energy ) ) ) ;
nd_write_byte ( ( sbyte ) ( f2ir ( get_local_player ( ) . shields ) ) ) ;
nd_write_int ( get_local_player ( ) . flags ) ; // be sure players flags are set
2006-03-20 17:12:09 +00:00
nd_write_byte ( ( sbyte ) Primary_weapon ) ;
nd_write_byte ( ( sbyte ) Secondary_weapon ) ;
byte_count + = 8 ;
2010-06-18 08:22:45 +00:00
2014-12-14 05:23:00 +00:00
for ( int i = 0 ; i < MAX_PRIMARY_WEAPONS ; i + + )
2015-10-18 21:01:18 +00:00
nd_write_short ( i = = primary_weapon_index_t : : VULCAN_INDEX ? get_local_player ( ) . vulcan_ammo : 0 ) ;
2010-06-18 08:22:45 +00:00
2015-07-25 23:10:46 +00:00
range_for ( auto & i , get_local_player ( ) . secondary_ammo )
2014-12-14 05:23:01 +00:00
nd_write_short ( i ) ;
2006-03-20 17:12:09 +00:00
byte_count + = ( sizeof ( short ) * ( MAX_PRIMARY_WEAPONS + MAX_SECONDARY_WEAPONS ) ) ;
2010-06-18 08:22:45 +00:00
2015-07-25 23:10:46 +00:00
nd_write_byte ( get_local_player ( ) . laser_level ) ;
2006-03-20 17:12:09 +00:00
byte_count + + ;
2010-06-18 08:22:45 +00:00
2006-03-20 17:12:09 +00:00
if ( Game_mode & GM_MULTI ) {
nd_write_byte ( ( sbyte ) N_players ) ;
byte_count + + ;
2014-12-14 05:23:01 +00:00
range_for ( auto & i , partial_range ( Players , N_players ) ) {
nd_write_string ( static_cast < const char * > ( i . callsign ) ) ;
byte_count + = ( strlen ( static_cast < const char * > ( i . callsign ) ) + 2 ) ;
nd_write_byte ( i . connected ) ;
2006-03-20 17:12:09 +00:00
if ( Game_mode & GM_MULTI_COOP ) {
2014-12-14 05:23:01 +00:00
nd_write_int ( i . score ) ;
2006-03-20 17:12:09 +00:00
byte_count + = 5 ;
} else {
2014-12-14 05:23:01 +00:00
nd_write_short ( i . net_killed_total ) ;
nd_write_short ( i . net_kills_total ) ;
2006-03-20 17:12:09 +00:00
byte_count + = 5 ;
}
}
} else {
2015-07-25 23:10:46 +00:00
nd_write_int ( get_local_player ( ) . score ) ;
2006-03-20 17:12:09 +00:00
byte_count + = 4 ;
}
nd_write_short ( byte_count ) ;
2013-08-31 15:22:40 +00:00
}
2010-06-18 08:22:45 +00:00
2006-03-20 17:12:09 +00:00
nd_write_byte ( Current_level_num ) ;
nd_write_byte ( ND_EVENT_EOF ) ;
2009-11-15 08:22:08 +00:00
}
2015-02-28 19:36:02 +00:00
static bool guess_demo_name ( ntstring < PATH_MAX - 1 > & filename )
{
filename [ 0 ] = 0 ;
2015-03-22 18:49:20 +00:00
const auto & n = GameArg . SysRecordDemoNameTemplate ;
if ( n . empty ( ) )
2015-02-28 19:36:02 +00:00
return false ;
2015-03-22 18:49:20 +00:00
auto p = n . c_str ( ) ;
2015-02-28 19:36:02 +00:00
if ( ! strcmp ( p , " . " ) )
p = " %Y%m%d.%H%M%S-$p-$m " ;
std : : size_t i = 0 ;
time_t t = 0 ;
tm * ptm = nullptr ;
for ( ; ; + + p )
{
if ( * p = = ' % ' )
{
if ( ! p [ 1 ] )
/* Trailing bare % is ill-formed. Ignore entire
* template .
*/
return false ;
/* Time conversions */
if ( unlikely ( ! t ) )
t = time ( nullptr ) ;
if ( unlikely ( t = = - 1 | | ! ( ptm = gmtime ( & t ) ) ) )
continue ;
char sbuf [ 4 ] ;
sbuf [ 0 ] = ' % ' ;
sbuf [ 1 ] = * + + p ;
# ifndef _WIN32
/* Not supported on Windows */
if ( sbuf [ 1 ] = = ' O ' | | sbuf [ 1 ] = = ' E ' )
{
sbuf [ 2 ] = * + + p ;
sbuf [ 3 ] = 0 ;
}
else
# endif
{
sbuf [ 2 ] = 0 ;
}
filename [ i ] = 0 ;
auto a = strftime ( & filename [ i ] , sizeof ( filename ) - i , sbuf , ptm ) ;
if ( a > = sizeof ( filename ) - i )
return false ;
i + = a ;
continue ;
}
if ( * p = = ' $ ' )
{
/* Variable conversions */
const char * insert ;
switch ( * + + p )
{
case ' m ' : /* mission */
insert = Current_mission_filename ;
break ;
case ' p ' : /* pilot */
2015-07-25 23:10:46 +00:00
insert = get_local_player ( ) . callsign ;
2015-02-28 19:36:02 +00:00
break ;
default :
return false ;
}
i + = filename . copy_if ( i , insert ) ;
continue ;
}
filename [ i + + ] = * p ;
if ( ! * p )
break ;
if ( i > = sizeof ( filename ) - 1 )
return false ;
}
return filename [ 0 ] ;
}
2013-06-08 22:24:17 +00:00
static const char demoname_allowed_chars [ ] = " azAZ09__-- " ;
2013-12-18 03:38:38 +00:00
# define DEMO_FORMAT_STRING(S) DEMO_DIR S "." DEMO_EXT
2009-11-15 08:22:08 +00:00
void newdemo_stop_recording ( )
{
int exit ;
static sbyte tmpcnt = 0 ;
2015-02-28 19:36:02 +00:00
ntstring < PATH_MAX - 1 > filename ;
2009-11-15 08:22:08 +00:00
exit = 0 ;
2010-07-15 05:40:25 +00:00
if ( ! nd_record_v_no_space )
2010-06-18 08:22:45 +00:00
{
2013-08-31 15:22:40 +00:00
newdemo_record_oneframeevent_update ( 0 ) ;
2009-11-15 08:22:08 +00:00
newdemo_write_end ( ) ;
2010-06-18 08:22:45 +00:00
}
2006-03-20 17:12:09 +00:00
2015-01-29 00:45:18 +00:00
outfile . reset ( ) ;
2006-03-20 17:12:09 +00:00
Newdemo_state = ND_STATE_NORMAL ;
gr_palette_load ( gr_palette ) ;
try_again :
;
Newmenu_allowed_chars = demoname_allowed_chars ;
2015-02-28 19:36:02 +00:00
if ( guess_demo_name ( filename ) )
{
}
else if ( ! nd_record_v_no_space ) {
2015-03-22 18:49:21 +00:00
array < newmenu_item , 1 > m { {
2015-01-18 01:58:31 +00:00
nm_item_input ( filename ) ,
2015-03-22 18:49:21 +00:00
} } ;
2015-01-18 01:58:32 +00:00
exit = newmenu_do ( NULL , TXT_SAVE_DEMO_AS , m , unused_newmenu_subfunction , unused_newmenu_userdata ) ;
2010-07-15 05:40:25 +00:00
} else if ( nd_record_v_no_space = = 2 ) {
2015-03-22 18:49:21 +00:00
array < newmenu_item , 2 > m { {
2015-01-18 01:58:31 +00:00
nm_item_text ( TXT_DEMO_SAVE_NOSPACE ) ,
nm_item_input ( filename ) ,
2015-03-22 18:49:21 +00:00
} } ;
2015-01-18 01:58:32 +00:00
exit = newmenu_do ( NULL , NULL , m , unused_newmenu_subfunction , unused_newmenu_userdata ) ;
2006-03-20 17:12:09 +00:00
}
Newmenu_allowed_chars = NULL ;
if ( exit = = - 2 ) { // got bumped out from network menu
2009-12-08 11:01:36 +00:00
char save_file [ PATH_MAX ] ;
2006-03-20 17:12:09 +00:00
if ( filename [ 0 ] ! = ' \0 ' ) {
2015-02-28 19:36:02 +00:00
snprintf ( save_file , sizeof ( save_file ) , DEMO_FORMAT_STRING ( " %s " ) , filename . data ( ) ) ;
2006-03-20 17:12:09 +00:00
} else
2013-12-18 03:38:38 +00:00
snprintf ( save_file , sizeof ( save_file ) , DEMO_FORMAT_STRING ( " tmp%d " ) , tmpcnt + + ) ;
2006-03-20 17:12:09 +00:00
remove ( save_file ) ;
PHYSFSX_rename ( DEMO_FILENAME , save_file ) ;
return ;
}
if ( exit = = - 1 ) { // pressed ESC
PHYSFS_delete ( DEMO_FILENAME ) ; // might as well remove the file
return ; // return without doing anything
}
if ( filename [ 0 ] = = 0 ) //null string
goto try_again ;
//check to make sure name is ok
2015-02-28 19:36:02 +00:00
range_for ( const unsigned c , filename )
{
if ( ! c )
break ;
if ( ! isalnum ( c ) & & c ! = ' _ ' & & c ! = ' - ' & & c ! = ' . ' )
{
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_CONTINUE , TXT_DEMO_USE_LETTERS ) ;
2006-03-20 17:12:09 +00:00
goto try_again ;
}
2015-02-28 19:36:02 +00:00
}
2006-03-20 17:12:09 +00:00
2013-12-18 03:38:38 +00:00
char fullname [ PATH_MAX ] ;
2015-02-28 19:36:02 +00:00
snprintf ( fullname , sizeof ( fullname ) , DEMO_FORMAT_STRING ( " %s " ) , filename . data ( ) ) ;
2006-03-20 17:12:09 +00:00
PHYSFS_delete ( fullname ) ;
PHYSFSX_rename ( DEMO_FILENAME , fullname ) ;
}
//returns the number of demo files on the disk
int newdemo_count_demos ( )
{
int NumFiles = 0 ;
2015-01-23 03:55:05 +00:00
auto find = PHYSFSX_findFiles ( DEMO_DIR , demo_file_extensions ) ;
2006-03-20 17:12:09 +00:00
2015-01-23 03:55:05 +00:00
for ( auto i = find . get ( ) ; * i ; + + i )
2006-03-20 17:12:09 +00:00
NumFiles + + ;
return NumFiles ;
}
2013-06-08 22:24:17 +00:00
void newdemo_start_playback ( const char * filename )
2006-03-20 17:12:09 +00:00
{
2013-10-06 03:02:50 +00:00
enum purpose_type rnd_demo = PURPOSE_CHOSE_PLAY ;
2006-03-20 17:12:09 +00:00
char filename2 [ PATH_MAX + FILENAME_LEN ] = DEMO_DIR ;
change_playernum_to ( 0 ) ;
if ( filename )
strcat ( filename2 , filename ) ;
else
{
// Randomly pick a filename
int NumFiles = 0 , RandFileNum ;
2013-10-06 03:02:50 +00:00
rnd_demo = PURPOSE_RANDOM_PLAY ;
2006-03-20 17:12:09 +00:00
NumFiles = newdemo_count_demos ( ) ;
if ( NumFiles = = 0 ) {
2010-07-16 13:03:12 +00:00
GameArg . SysAutoDemo = 0 ;
2006-03-20 17:12:09 +00:00
return ; // No files found!
}
RandFileNum = d_rand ( ) % NumFiles ;
NumFiles = 0 ;
2015-01-23 03:55:05 +00:00
auto find = PHYSFSX_findFiles ( DEMO_DIR , demo_file_extensions ) ;
2006-03-20 17:12:09 +00:00
2015-01-23 03:55:05 +00:00
for ( auto i = find . get ( ) ; * i ; + + i )
2006-03-20 17:12:09 +00:00
{
if ( NumFiles = = RandFileNum )
{
strcat ( filename2 , * i ) ;
break ;
}
NumFiles + + ;
}
if ( NumFiles > RandFileNum )
2010-07-16 13:03:12 +00:00
{
GameArg . SysAutoDemo = 0 ;
2006-03-20 17:12:09 +00:00
return ;
2010-07-16 13:03:12 +00:00
}
2006-03-20 17:12:09 +00:00
}
infile = PHYSFSX_openReadBuffered ( filename2 ) ;
2015-01-29 00:56:21 +00:00
if ( ! infile ) {
2006-03-20 17:12:09 +00:00
return ;
}
2010-07-15 05:40:25 +00:00
nd_playback_v_bad_read = 0 ;
2006-03-20 17:12:09 +00:00
change_playernum_to ( 0 ) ; // force playernum to 0
2015-07-25 23:10:46 +00:00
nd_playback_v_save_callsign = get_local_player ( ) . callsign ;
get_local_player ( ) . lives = 0 ;
2006-03-20 17:12:09 +00:00
Viewer = ConsoleObject = & Objects [ 0 ] ; // play properly as if console player
2008-03-08 22:37:09 +00:00
2006-03-20 17:12:09 +00:00
if ( newdemo_read_demo_start ( rnd_demo ) ) {
2015-01-29 00:56:21 +00:00
infile . reset ( ) ;
2006-03-20 17:12:09 +00:00
return ;
}
2009-11-30 14:59:37 +00:00
Game_mode = GM_NORMAL ;
2006-03-20 17:12:09 +00:00
Newdemo_state = ND_STATE_PLAYBACK ;
Newdemo_vcr_state = ND_STATE_PLAYBACK ;
2010-07-15 05:40:25 +00:00
nd_playback_v_demosize = PHYSFS_fileLength ( infile ) ;
nd_playback_v_bad_read = 0 ;
nd_playback_v_at_eof = 0 ;
nd_playback_v_framecount = 0 ;
nd_playback_v_style = NORMAL_PLAYBACK ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2009-02-02 08:49:58 +00:00
init_seismic_disturbances ( ) ;
2010-01-29 00:30:54 +00:00
PlayerCfg . Cockpit3DView [ 0 ] = PlayerCfg . Cockpit3DView [ 1 ] = CV_NONE ; //turn off 3d views on cockpit
DemoDoLeft = DemoDoRight = 0 ;
2013-08-31 15:22:40 +00:00
nd_playback_v_guided = 0 ;
2013-03-03 01:03:33 +00:00
# endif
2013-08-31 15:22:40 +00:00
nd_playback_v_dead = nd_playback_v_rear = 0 ;
2007-04-03 22:12:54 +00:00
HUD_clear_messages ( ) ;
2010-06-20 20:32:30 +00:00
if ( ! Game_wind )
hide_menus ( ) ;
2006-03-20 17:12:09 +00:00
newdemo_playback_one_frame ( ) ; // this one loads new level
newdemo_playback_one_frame ( ) ; // get all of the objects to renderb game
2010-02-08 05:34:43 +00:00
if ( ! Game_wind )
2010-06-20 20:32:30 +00:00
Game_wind = game_setup ( ) ; // create game environment
2006-03-20 17:12:09 +00:00
}
void newdemo_stop_playback ( )
{
2015-01-29 00:56:21 +00:00
infile . reset ( ) ;
2006-03-20 17:12:09 +00:00
Newdemo_state = ND_STATE_NORMAL ;
change_playernum_to ( 0 ) ; //this is reality
2015-07-25 23:10:46 +00:00
get_local_player ( ) . callsign = nd_playback_v_save_callsign ;
2007-10-07 14:46:52 +00:00
Rear_view = 0 ;
2013-08-31 15:22:40 +00:00
nd_playback_v_dead = nd_playback_v_rear = 0 ;
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2013-08-31 15:22:40 +00:00
nd_playback_v_guided = 0 ;
2013-03-03 01:03:33 +00:00
# endif
2009-11-30 14:59:37 +00:00
Newdemo_game_mode = Game_mode = GM_GAME_OVER ;
2012-04-17 07:46:39 +00:00
2012-04-17 09:15:09 +00:00
// Required for the editor
obj_relink_all ( ) ;
2010-01-27 04:30:31 +00:00
if ( Game_wind )
window_close ( Game_wind ) ; // Exit game loop
2006-03-20 17:12:09 +00:00
}
2013-06-08 22:24:17 +00:00
int newdemo_swap_endian ( const char * filename )
2009-11-15 08:22:08 +00:00
{
char inpath [ PATH_MAX + FILENAME_LEN ] = DEMO_DIR ;
int complete = 0 ;
if ( filename )
strcat ( inpath , filename ) ;
else
return 0 ;
2010-06-18 08:22:45 +00:00
2015-01-29 00:56:21 +00:00
infile = PHYSFSX_openReadBuffered ( inpath ) ;
if ( ! infile )
2009-11-15 08:22:08 +00:00
goto read_error ;
2010-06-18 08:22:45 +00:00
2010-07-15 05:40:25 +00:00
nd_playback_v_demosize = PHYSFS_fileLength ( infile ) ; // should be exactly the same size
2015-01-29 00:45:18 +00:00
outfile = PHYSFSX_openWriteBuffered ( DEMO_FILENAME ) ;
if ( ! outfile )
2009-11-15 08:22:08 +00:00
{
2015-01-29 00:56:21 +00:00
infile . reset ( ) ;
2009-11-15 08:22:08 +00:00
goto read_error ;
}
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
Newdemo_num_written = 0 ;
2010-07-15 05:40:25 +00:00
nd_playback_v_bad_read = 0 ;
2009-11-15 08:22:08 +00:00
swap_endian = 1 ;
2010-07-15 05:40:25 +00:00
nd_playback_v_at_eof = 0 ;
2009-11-15 08:22:08 +00:00
Newdemo_state = ND_STATE_NORMAL ; // not doing anything special really
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
if ( newdemo_read_demo_start ( PURPOSE_REWRITE ) ) {
2015-01-29 00:56:21 +00:00
infile . reset ( ) ;
2015-01-29 00:45:18 +00:00
outfile . reset ( ) ;
2009-11-15 08:22:08 +00:00
swap_endian = 0 ;
return 0 ;
}
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
while ( newdemo_read_frame_information ( 1 ) = = 1 ) { } // rewrite all frames
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
newdemo_goto_end ( 1 ) ; // get end of demo data
newdemo_write_end ( ) ; // and write it
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
swap_endian = 0 ;
2010-07-15 05:40:25 +00:00
complete = nd_playback_v_demosize = = Newdemo_num_written ;
2015-01-29 00:56:21 +00:00
infile . reset ( ) ;
2015-01-29 00:45:18 +00:00
outfile . reset ( ) ;
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
if ( complete )
{
char bakpath [ PATH_MAX + FILENAME_LEN ] ;
change_filename_extension ( bakpath , inpath , DEMO_BACKUP_EXT ) ;
PHYSFSX_rename ( inpath , bakpath ) ;
PHYSFSX_rename ( DEMO_FILENAME , inpath ) ;
}
else
PHYSFS_delete ( DEMO_FILENAME ) ; // clean up the mess
2010-06-18 08:22:45 +00:00
2009-11-15 08:22:08 +00:00
read_error :
{
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , complete ? " Demo %s converted%s " : " Error converting demo \n %s \n %s " , filename ,
2010-07-15 05:40:25 +00:00
complete ? " " : ( nd_playback_v_at_eof ? TXT_DEMO_CORRUPT : PHYSFS_getLastError ( ) ) ) ;
2009-11-15 08:22:08 +00:00
}
2010-07-15 05:40:25 +00:00
return nd_playback_v_at_eof ;
2009-11-15 08:22:08 +00:00
}
2006-03-20 17:12:09 +00:00
# ifndef NDEBUG
# define BUF_SIZE 16384
void newdemo_strip_frames ( char * outname , int bytes_to_strip )
{
char * buf ;
2011-09-26 23:31:19 +00:00
int read_elems , bytes_back ;
2006-03-20 17:12:09 +00:00
int trailer_start , loc1 , loc2 , stop_loc , bytes_to_read ;
short last_frame_length ;
2015-01-17 18:31:42 +00:00
auto outfile = PHYSFSX_openWriteBuffered ( outname ) ;
2015-01-17 18:31:42 +00:00
if ( ! outfile ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " Can't open output file " ) ;
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
return ;
}
2013-09-29 20:35:56 +00:00
MALLOC ( buf , char , BUF_SIZE ) ;
2006-03-20 17:12:09 +00:00
if ( buf = = NULL ) {
2010-01-07 14:49:07 +00:00
nm_messagebox ( NULL , 1 , TXT_OK , " Can't malloc output buffer " ) ;
2006-03-20 17:12:09 +00:00
newdemo_stop_playback ( ) ;
return ;
}
2009-11-15 08:22:08 +00:00
newdemo_goto_end ( 0 ) ;
2006-03-20 17:12:09 +00:00
trailer_start = PHYSFS_tell ( infile ) ;
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) + 11 ) ;
bytes_back = 0 ;
while ( bytes_back < bytes_to_strip ) {
loc1 = PHYSFS_tell ( infile ) ;
newdemo_back_frames ( 1 ) ;
loc2 = PHYSFS_tell ( infile ) ;
bytes_back + = ( loc1 - loc2 ) ;
}
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) - 10 ) ;
nd_read_short ( & last_frame_length ) ;
PHYSFS_seek ( infile , PHYSFS_tell ( infile ) - 3 ) ;
stop_loc = PHYSFS_tell ( infile ) ;
PHYSFS_seek ( infile , 0 ) ;
while ( stop_loc > 0 ) {
if ( stop_loc < BUF_SIZE )
bytes_to_read = stop_loc ;
else
bytes_to_read = BUF_SIZE ;
read_elems = PHYSFS_read ( infile , buf , 1 , bytes_to_read ) ;
PHYSFS_write ( outfile , buf , 1 , read_elems ) ;
stop_loc - = read_elems ;
}
stop_loc = PHYSFS_tell ( outfile ) ;
PHYSFS_seek ( infile , trailer_start ) ;
while ( ( read_elems = PHYSFS_read ( infile , buf , 1 , BUF_SIZE ) ) ! = 0 )
PHYSFS_write ( outfile , buf , 1 , read_elems ) ;
PHYSFS_seek ( outfile , stop_loc ) ;
PHYSFS_seek ( outfile , PHYSFS_tell ( infile ) + 1 ) ;
PHYSFS_write ( outfile , & last_frame_length , 2 , 1 ) ;
newdemo_stop_playback ( ) ;
}
# endif
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2014-10-02 03:02:34 +00:00
static void nd_render_extras ( ubyte which , const vcobjptr_t obj )
2006-03-20 17:12:09 +00:00
{
ubyte w = which > > 4 ;
ubyte type = which & 15 ;
if ( which = = 255 )
{
Int3 ( ) ; // how'd we get here?
2015-04-02 02:36:57 +00:00
do_cockpit_window_view ( w , WBU_WEAPON ) ;
2006-03-20 17:12:09 +00:00
return ;
}
if ( w )
{
2013-12-12 21:53:23 +00:00
DemoRightExtra = * obj ; DemoDoRight = type ;
2006-03-20 17:12:09 +00:00
}
else
{
2013-12-12 21:53:23 +00:00
DemoLeftExtra = * obj ; DemoDoLeft = type ;
2006-03-20 17:12:09 +00:00
}
}
2013-03-03 01:03:33 +00:00
# endif