home *** CD-ROM | disk | FTP | other *** search
- {
-
- TechTutor5
- Demo Recording/playing (ripped from SuperFX Engine)
-
- Coding by P.Bestebroer
- FreeWare
-
- Source does NOT work on its own, it was merely used for showing
- howto, instead of doing it foryou.
- The code DOES work when put inside the SuperFX engine (wich is
- allready done).
-
- Contacting:
-
- HTTP://people.zeelandnet.nl/rpb/
- EMAIL:just4fun@zeelandnet.nl
-
- }
- PROGRAM Tech05;
-
- USES CRT;
- {─────────────────────────────────────────────────────────────────────────────}
- {
- First create a few variables
-
- }
- VAR DEMrecord : boolean; { recording demo? }
- DEMplay : boolean; { playing a demo? }
- DEMfile : file; { filename of the .DEM file }
-
- CONST DEMID : string = 'SFX_DEMOv1'; { ID of the SuperFX Demo files }
-
- VAR DEMleft : boolean; { left key is pressed? }
- DEMright : boolean; { right key is pressed? }
- DEMup : boolean; { up key is pressed? }
- DEMdown : boolean; { down key is pressed? }
- DEMfire : boolean; { fire key is pressed? }
- DEMfire2 : boolean; { support for 4 joystick buttons }
- DEMfire3 : boolean;
- DEMfire4 : boolean;
- DEMpress : longint; { time the keys are pressed }
- {─────────────────────────────────────────────────────────────────────────────}
- {
- This procedure will create a new DEMO file
-
- Expects: Filename of the Demo
- Returns: Nothing
- }
- FUNCTION _NewDemo(filename:string):boolean;
- BEGIN
- Halt_Proc:='_NewDemo';
- assign(DEMfile,filename);
- {$I-}
- rewrite(DEMfile,1);
- {$I+}
- if IoResult<>0 then begin
- _NewDemo:=false;
- halt_Error:='Unable to assign demoname ('+filename+')';
- exit;
- end;
-
-
- blockwrite(DEMfile,DEMID[1],sizeof(DEMID)); { write DEMO ID }
- blockwrite(DEMfile,MapFile[1],32); { write map-filename }
- blockwrite(DEMfile,MapLib,1); { write map-using lib? }
-
- DEMleft:=false; { not pressed,}
- DEMright:=false; { not pressed neither, }
- DEMup:=false; { definetly not pressed, }
- DEMdown:=false; { maybe...NAH not pressed! }
- DEMfire:=false; { ...don't shoot!, don't shoot! }
- DEMfire2:=false; { support for 4 joystick buttons }
- DEMFire3:=false;
- DEMfire4:=false;
-
- DEMpress:=0; { the pressing-time of the keys }
- DEMrecord:=true; { silence please, we're recording! }
- {$IFDEF PLUGIN_SHOWEVENTS}
- _Ucase(Filename);
- _AddEvent('RECORDING DEMO ('+filename+')');
- {$ENDIF}
-
- _NewDemo:=true;
- END;
- {─────────────────────────────────────────────────────────────────────────────}
- {
- This procedure will OPEN a DEMO for playing
-
- Expects: Filename of the Demo
- Returns: Nothing
- }
- FUNCTION _OpenDemo(filename:string):Boolean;
- VAR testID : string[24];
- tmpFile : string;
- BEGIN
- Halt_Proc:='_OpenDemo';
- tmpFile:=filename;
- assign(DEMfile,filename);
- {$I-}
- reset(DEMfile,1);
- {$I+}
- if IoResult<>0 then begin
- _OpenDemo:=false;
- Halt_error:='Couldn''t spawn demo ('+tmpFile+')';
- exit;
- end;
-
- blockread(DEMfile,testID[1],sizeof(DEMID));
- testID[0]:=DEMid[0];
- if testID<>DEMid then begin
- halt_Error:='Not a valid DEMO file ('+filename+')';
- halt_proc:='_PlayDemo';
- halt;
- end;
-
- blockread(DEMfile,MapFile[1],32); { read map-filename }
- blockread(DEMfile,MapLib,1); { read map-using lib? }
- LoadMap(mapLib,MapFile);
-
- DEMpress:=0;
- DEMplay:=true;
-
- {$IFDEF PLUGIN_SHOWEVENTS}
- _Ucase(tmpFile);
- _AddEvent('PLAYING DEMO ('+tmpFile+')');
- {$ENDIF}
- _OpenDemo:=true;
- END;
- {─────────────────────────────────────────────────────────────────────────────}
- {
- This will END the DEMO file, and close it...
-
- Expects: Nothing
- Returns: Nothing
- }
- PROCEDURE _EndDemo;
- BEGIN
- {$I-}
- Close(DEMfile);
- {$I+}
- END;
- {─────────────────────────────────────────────────────────────────────────────}
- {
- This will handle the recording of key-presses, and save
- it to the DEMO file.
-
- Expects: all directions, and the fire presses
- Returns: Nothing
- }
- PROCEDURE _RecordDemo;
-
- PROCEDURE _ADDtoDEMObyte(code:byte);
- BEGIN
- blockwrite(DEMfile,code,1);
- END;
-
- PROCEDURE _ADDtoDEMO(code:longint);
- BEGIN
- blockwrite(DEMfile,code,4);
- END;
-
- BEGIN
- if (joystickleft<>demleft) or (joystickright<>demright) or
- (joystickup<>demup) or (joystickdown<>demdown) or (joystickA<>demfire) or
- (joystickB<>demfire2) or (joystickC<>demfire3) or (joystickD<>demfire4) then begin
- if demleft then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
- if demright then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
- if demup then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
- if demdown then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
- if demfire then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
- if demfire2 then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
- if demfire3 then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
- if demfire4 then _ADDtoDEMObyte(1) else _ADDtoDEMObyte(0);
-
- _ADDtoDEMO(dempress);
-
- DEMleft:=joystickleft;
- DEMright:=joystickright;
- DEMup:=joystickup;
- DEMdown:=joystickdown;
- DEMfire:=joystickA;
- DEMfire2:=joystickB;
- DEMfire3:=joystickC;
- DEMfire4:=joystickD;
-
- DEMpress:=0;
- end else inc(DemPress);
- END;
- {─────────────────────────────────────────────────────────────────────────────}
- {
- This will handle the PLAYING the demo
-
- Expects: all directions + fire keys (VARS to be returned)
- Returns: the boolean filled with TRUE or FALSE
- }
- PROCEDURE _PlayDemo;
-
- VAR i : byte;
-
- PROCEDURE _GETfromDEMObyte(var code:byte);
- BEGIN
- blockread(DEMfile,code,1);
- END;
-
- PROCEDURE _GETfromDEMO(var code:longint);
- BEGIN
- blockread(DEMfile,code,4);
- END;
-
- BEGIN
- Joystickleft:=DEMleft;
- JoystickRight:=DEMright;
- JoystickUp:=DEMup;
- JoystickDown:=DEMdown;
- JoystickA:=DEMfire;
- JoystickB:=DEMfire2;
- JoystickC:=DEMfire3;
- JoystickD:=DEMfire4;
-
- if DemPress>0 then dec(DemPress) else begin
- if eof(DEMfile) then DEMplay:=false else begin
- _GetFromDemoByte(i); if i=1 then DemLeft:=true else DemLeft:=false;
- _GetFromDemoByte(i); if i=1 then DemRight:=true else DemRight:=false;
- _GetFromDemoByte(i); if i=1 then DemUp:=true else DemUp:=false;
- _GetFromDemoByte(i); if i=1 then DemDown:=true else DemDown:=false;
- _GetFromDemoByte(i); if i=1 then DemFire:=true else DemFire:=false;
- _GetFromDemoByte(i); if i=1 then DemFire2:=true else DemFire2:=false;
- _GetFromDemoByte(i); if i=1 then DemFire3:=true else DemFire3:=false;
- _GetFromDemoByte(i); if i=1 then DemFire4:=true else DemFire4:=false;
- _GetFromDemo(DEMpress);
- end;
- end;
- END;
- {$ENDIF}
-
- {─────────────────────────────────────────────────────────────────────────────}
- BEGIN
-
- while port[$60]<>156 do ;
- textcolor(7); textbackground(0); clrscr;
- writeln('TechTutor #5');
- writeln('written by P.Bestebroer, Just4Fun Productions');
- writeln('');
- writeln('A great source code showing how you COULD implement demo-playing');
- writeln('and demo recording. The source does not work stand-alone, but it');
- writeln('can be used when some tweaking is done, and you have a game to put');
- writeln('it in.');
- writeln('The source code was taken from the SuperFX engine.');
- writeln;
- writeln('Watch out for the other techtutors...');
- writeln;
- writeln('Press a key');
-
- writeln;
- writeln;
- writeln;
- writeln('----------------------------------');
- writeln('Contacting: just4fun@zeelandnet.nl');
- writeln('http://people.zeelandnet.nl/rpb ');
- writeln('----------------------------------');
- repeat until port[$60]<>156;
- END.
-