aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-25 10:19:28 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-25 10:19:28 +0000
commit57f6e8e49c35a1e43d73255edc8fb35308563319 (patch)
tree8445bde251acc7d4f043f44eaf2b2c5a3145a2b5 /src
parente73b884d020019c29aadf11a2c5ac8fe5b53b0dd (diff)
downloadusdx-57f6e8e49c35a1e43d73255edc8fb35308563319.tar.gz
usdx-57f6e8e49c35a1e43d73255edc8fb35308563319.tar.xz
usdx-57f6e8e49c35a1e43d73255edc8fb35308563319.zip
MainThreadExec() can be used to delegate execution from e.g. a callback thread to the main thread.
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1468 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src')
-rw-r--r--src/base/UMain.pas49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/base/UMain.pas b/src/base/UMain.pas
index 6e6d2ad7..6c77ebc0 100644
--- a/src/base/UMain.pas
+++ b/src/base/UMain.pas
@@ -107,7 +107,6 @@ var
PlayListPath: string;
Done: Boolean;
- Event: TSDL_event;
// FIXME: ConversionFileName should not be global
ConversionFileName: string;
Restart: boolean;
@@ -122,6 +121,7 @@ const
MAX_SONG_SCORE = 10000; // max. achievable points per song
MAX_SONG_LINE_BONUS = 1000; // max. achievable line bonus per song
+
function FindPath(out PathResult: string; const RequestedPath: string; NeedsWritePermission: boolean): boolean;
procedure InitializePaths;
procedure AddSongPath(const Path: string);
@@ -138,6 +138,24 @@ function GetMidBeat(Time: real): real;
function GetTimeFromBeat(Beat: integer): real;
procedure ClearScores(PlayerNum: integer);
+
+type
+ TMainThreadExecProc = procedure(Data: Pointer);
+
+const
+ MAINTHREAD_EXEC_EVENT = SDL_USEREVENT + 2;
+
+{*
+ * Delegates execution of procedure Proc to the main thread.
+ * The Data pointer is passed to the procedure when it is called.
+ * The main thread is notified by signaling a MAINTHREAD_EXEC_EVENT which
+ * is handled in CheckEvents.
+ * Note that Data must not be a pointer to local data. If you want to pass local
+ * data, use Getmem() or New() or create a temporary object.
+ *}
+procedure MainThreadExec(Proc: TMainThreadExecProc; Data: Pointer);
+
+
implementation
uses
@@ -452,11 +470,13 @@ begin
End;
procedure CheckEvents;
+var
+ Event: TSDL_event;
begin
if Assigned(Display.NextScreen) then
Exit;
- while SDL_PollEvent( @event ) = 1 do
+ while (SDL_PollEvent(@Event) <> 0) do
begin
case Event.type_ of
SDL_QUITEV:
@@ -465,9 +485,10 @@ begin
Display.NextScreenWithCheck := nil;
Display.CheckOK := True;
end;
- {
SDL_MOUSEBUTTONDOWN:
- with Event.button Do
+ begin
+ {
+ with Event.button do
begin
if State = SDL_BUTTON_LEFT Then
begin
@@ -475,6 +496,7 @@ begin
end;
end;
}
+ end;
SDL_VIDEORESIZE:
begin
ScreenW := Event.resize.w;
@@ -560,10 +582,29 @@ begin
begin
// not implemented
end;
+ MAINTHREAD_EXEC_EVENT:
+ with Event.user do
+ begin
+ TMainThreadExecProc(data1)(data2);
+ end;
end; // case
end; // while
end;
+procedure MainThreadExec(Proc: TMainThreadExecProc; Data: Pointer);
+var
+ Event: TSDL_Event;
+begin
+ with Event.user do
+ begin
+ type_ := MAINTHREAD_EXEC_EVENT;
+ code := 0; // not used at the moment
+ data1 := @Proc;
+ data2 := Data;
+ end;
+ SDL_PushEvent(@Event);
+end;
+
function GetTimeForBeats(BPM, Beats: real): real;
begin
Result := 60 / BPM * Beats;