Subversion Repositories plumbers

Compare Revisions

Regard whitespace Rev 18 → Rev 19

/trunk/Win32_Player/Game.pas
22,7 → 22,7
TShowPictureCallback = procedure(Game: TGame; AFilename: string; AType: TPictureType) of object;
TPlaySoundCallback = procedure(Game: TGame; AFilename: string) of object;
TSimpleCallback = procedure(Game: TGame) of object;
TWaitCallback = procedure(Game: TGame; AMilliseconds: integer) of object;
TWaitCallback = function(Game: TGame; AMilliseconds: integer): boolean of object;
TSetHotspotCallback = procedure(Game: TGame; AIndex: THotspotIndex; AHotspot: THotspot) of object;
TClearHotspotsCallback = procedure(Game: TGame) of object;
41,7 → 41,7
procedure PrevDecisionScene;
protected
GameData: TGameBinFile;
procedure Wait(AMilliseconds: integer);
function Wait(AMilliseconds: integer): boolean;
procedure PlayScene(scene: PSceneDef; goToDecision: boolean);
public
procedure PerformAction(action: PActionDef);
113,13 → 113,18
end;
end;
 
procedure TGame.Wait(AMilliseconds: integer);
function TGame.Wait(AMilliseconds: integer): boolean;
begin
if Assigned(WaitCallback) then
WaitCallback(Self, AMilliseconds)
begin
result := WaitCallback(Self, AMilliseconds)
end
else
begin
Sleep(AMilliseconds);
result := false; // don't cancel
end;
end;
 
procedure TGame.PlayScene(scene: PSceneDef; goToDecision: boolean);
var
144,7 → 149,11
PictureShowCallback(Self, IncludeTrailingPathDelimiter(FDirectory) +
scene^.szSceneFolder + PathDelim + GameData.pictures[i].szBitmapFile, ptDia);
end;
Wait(GameData.pictures[i].duration * 100);
if Wait(GameData.pictures[i].duration * 100) then
begin
AsyncSoundCallback(Self, '');
break;
end;
if Application.Terminated then Abort;
end;
end;
/trunk/Win32_Player/Main.pas
22,7 → 22,7
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Game, MPlayer;
Dialogs, ExtCtrls, StdCtrls, Game, MPlayer, SyncObjs;
 
type
TMainForm = class(TForm)
42,10 → 42,13
procedure cbPictureShow(ASender: TGame; AFilename: string; AType: TPictureType);
procedure cbAsyncSound(ASender: TGame; AFilename: string);
procedure cbExit(ASender: TGame);
procedure cbWait(ASender: TGame; AMilliseconds: integer);
function cbWait(ASender: TGame; AMilliseconds: integer): boolean;
procedure cbSetHotspot(ASender: TGame; AIndex: THotspotIndex; AHotspot: THotspot);
procedure cbClearHotspots(ASender: TGame);
procedure ClickEvent(X, Y: Integer);
private
FCancelSceneRequest: boolean;
csCancelSceneRequest: TCriticalSection;
public
game: TGame;
end;
58,20 → 61,8
{$R *.dfm}
 
uses
MMSystem, IniFiles, Math;
MMSystem, IniFiles, Math, GameBinStruct;
 
procedure Delay(const Milliseconds: DWord);
var
FirstTickCount: DWord;
begin
FirstTickCount := GetTickCount; // TODO: Attention, GetTickCount can overflow
while not Application.Terminated and ((GetTickCount - FirstTickCount) < Milliseconds) do
begin
Application.ProcessMessages;
Sleep(0);
end;
end;
 
function AddThouSeps(const S: string): string;
var
LS, L2, I, N: Integer;
106,6 → 97,10
resourcestring
S_YOUR_SCORE = 'Your score is: %s';
begin
{$IFDEF DEBUG}
Caption := AFileName;
{$ENDIF}
 
if FileExists(AFilename) then
begin
Image1.Visible := false;
137,6 → 132,7
end
else
begin
ShowMessageFmt('File not found: %s', [AFileName]);
Image1.Picture := nil;
end;
 
185,12 → 181,31
Application.Terminate;
end;
 
procedure TMainForm.cbWait(ASender: TGame; AMilliseconds: integer);
function TMainForm.cbWait(ASender: TGame; AMilliseconds: integer): boolean;
var
FirstTickCount: DWord;
begin
//Cursor := crHourglass;
try
Delay(AMilliseconds);
result := false; // don't cancel
FirstTickCount := GetTickCount; // TODO: Attention, GetTickCount can overflow
while not Application.Terminated and ((GetTickCount - FirstTickCount) < AMilliseconds) do
begin
csCancelSceneRequest.Acquire;
try
if FCancelSceneRequest then
begin
FCancelSceneRequest := false;
result := true; // cancel
exit;
end;
finally
csCancelSceneRequest.Release;
end;
Application.ProcessMessages;
Sleep(0);
end;
finally
//Cursor := crDefault;
end;
end;
200,6 → 215,7
ini: TMemIniFile;
iniFilename: string;
begin
csCancelSceneRequest := TCriticalSection.Create;
iniFilename := ChangeFileExt(ExtractFileName(ParamStr(0)), '.ini');
 
DoubleBuffered := true;
228,6 → 244,8
// Without this, some audio drivers could crash if you press ESC to end the game.
// (VPC 2007 with Win95; cpsman.dll crashes sometimes)
PlaySound(nil, hinstance, 0);
FreeAndNil(csCancelSceneRequest);
if Assigned(Game) then FreeAndNil(Game);
end;
 
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
237,6 → 255,19
begin
if MediaPlayer1.Mode = mpPlaying then MediaPlayer1.Stop;
end;
if KEY = VK_RETURN then
begin
if MediaPlayer1.Mode = mpPlaying then
begin
MediaPlayer1.Position := MediaPlayer1.EndPos;
end;
csCancelSceneRequest.Acquire;
try
FCancelSceneRequest := true;
finally
csCancelSceneRequest.Release;
end;
end;
if Key = VK_ESCAPE then Close;
end;
 
243,7 → 274,19
procedure TMainForm.ClickEvent(X, Y: Integer);
var
i: integer;
ac: TActionDef;
begin
// Debug: Go to prev decision by clicking on the top left edge
if (X < 20) and (Y < 20) then
begin
// TODO: Also allow to go back multiple steps
ac.scoreDelta := 0;
ac.nextSceneID := SCENEID_PREVDECISION;
ac.sceneSegment := 0;
Game.PerformAction(@ac);
Exit;
end;
 
// If hotspots are overlaying, the lowest action will be chosen (same behavior as original game)
for i := Low(FHotspots) to High(FHotspots) do
begin