Skip to content

Commit

Permalink
Added an optional task name parameter to Con_Busy to be shown when di…
Browse files Browse the repository at this point in the history
…splaying the progress bar. Note this should be a simple, high-level explanation of what task is being carried out e.g. "Loading map..."
  • Loading branch information
danij committed Jun 28, 2008
1 parent 5e399b8 commit c1f1db3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
3 changes: 2 additions & 1 deletion doomsday/engine/api/doomsday.h
Expand Up @@ -114,7 +114,8 @@ extern "C" {
void Z_CheckHeap(void);

// Console.
int Con_Busy(int flags, int (*workerFunc)(void*), void *workerData);
int Con_Busy(int flags, const char* taskName,
int (*workerFunc)(void*), void *workerData);
void Con_BusyWorkerEnd(void);
boolean Con_IsBusy(void);
void Con_Open(int yes);
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/con_busy.h
Expand Up @@ -31,7 +31,8 @@

typedef int (C_DECL *busyworkerfunc_t) (void* parm);

int Con_Busy(int flags, busyworkerfunc_t worker, void *workerData);
int Con_Busy(int flags, const char* taskName,
busyworkerfunc_t worker, void *workerData);
boolean Con_IsBusy(void);
void Con_BusyWorkerEnd(void);
void Con_BusyWorkerError(const char* message);
Expand Down
26 changes: 23 additions & 3 deletions doomsday/engine/portable/src/con_busy.c
Expand Up @@ -67,6 +67,7 @@ static void Con_BusyDeleteTextures(void);

static boolean busyInited;
static int busyMode;
static char* busyTaskName;
static thread_t busyThread;
static timespan_t busyTime;
static volatile boolean busyDone;
Expand All @@ -84,13 +85,15 @@ static DGLuint texScreenshot; // Captured screenshot of the latest frame.
/**
* Busy mode.
*
* @param flags Busy mode flags (see BUSYF_PROGRESS_BAR and others).
* @param flags Busy mode flags (see BUSYF_PROGRESS_BAR and others).
* @param taskName Optional task name (drawn with the progress bar).
* @param worker Worker thread that does processing while in busy mode.
* @param workerData Data context for the worker thread.
*
* @return Return value of the worker.
*/
int Con_Busy(int flags, busyworkerfunc_t worker, void *workerData)
int Con_Busy(int flags, const char* taskName, busyworkerfunc_t worker,
void *workerData)
{
int result = 0;

Expand All @@ -107,6 +110,13 @@ int Con_Busy(int flags, busyworkerfunc_t worker, void *workerData)
busyMode = flags;
Sys_Lock(busy_Mutex);
busyDone = false;
if(taskName && taskName[0])
{ // Take a copy of the task name.
size_t len = strlen(taskName);

busyTaskName = M_Calloc(len);
snprintf(busyTaskName, len, "%s", taskName);
}
Sys_Unlock(busy_Mutex);

// Load any textures needed in this mode.
Expand All @@ -123,6 +133,9 @@ int Con_Busy(int flags, busyworkerfunc_t worker, void *workerData)

// Free resources.
Con_BusyDeleteTextures();
if(busyTaskName)
M_Free(busyTaskName);
busyTaskName = NULL;

if(busyError)
{
Expand Down Expand Up @@ -206,7 +219,7 @@ static void Con_BusyLoadTextures(void)
}
}

if(busyMode & BUSYF_CONSOLE_OUTPUT)
if((busyMode & BUSYF_CONSOLE_OUTPUT) || busyTaskName)
{
const char* fontName;

Expand Down Expand Up @@ -439,6 +452,13 @@ static void Con_BusyDrawIndicator(float x, float y, float radius, float pos)

DGL_MatrixMode(DGL_TEXTURE);
DGL_PopMatrix();

// Draw the task name.
if(busyTaskName)
{
DGL_Color4f(1.f, 1.f, 1.f, .66f);
FR_TextOut(busyTaskName, x+radius, y - busyFontHgt/2);
}
}

#define LINE_COUNT 4
Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -391,7 +391,8 @@ int DD_Main(void)
// Enter busy mode until startup complete.
Con_InitProgress(200);
Con_Busy(BUSYF_NO_UPLOADS | BUSYF_STARTUP | BUSYF_PROGRESS_BAR
| (verbose? BUSYF_CONSOLE_OUTPUT : 0), DD_StartupWorker, NULL);
| (verbose? BUSYF_CONSOLE_OUTPUT : 0), "Starting up...",
DD_StartupWorker, NULL);

// Engine initialization is complete. Now finish up with the GL.
if(!isDedicated)
Expand All @@ -402,7 +403,7 @@ int DD_Main(void)

// Do deferred uploads.
Con_Busy(BUSYF_PROGRESS_BAR | BUSYF_STARTUP | BUSYF_ACTIVITY
| (verbose? BUSYF_CONSOLE_OUTPUT : 0), DD_StartupWorker2, NULL);
| (verbose? BUSYF_CONSOLE_OUTPUT : 0), NULL, DD_StartupWorker2, NULL);

// Client connection command.
if(ArgCheckWith("-connect", 1))
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/net_main.c
Expand Up @@ -1398,7 +1398,7 @@ D_CMD(Connect)
}

return Con_Busy(BUSYF_ACTIVITY | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
Net_ConnectWorker, &param);
NULL, Net_ConnectWorker, &param);
}

/**
Expand Down

0 comments on commit c1f1db3

Please sign in to comment.