Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 9, 2012
1 parent a708a85 commit 9bf8c0b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
5 changes: 3 additions & 2 deletions doomsday/engine/api/doomsday.def
@@ -1,6 +1,6 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 852 <--
; Highest ordinal is currently: --> 853 <--
; Other free ordinals: 57

NAME "DOOMSDAY"
Expand Down Expand Up @@ -383,7 +383,8 @@ EXPORTS
BusyMode_ElapsedTime @851 NONAME
BusyMode_RunTask @852 NONAME
BusyMode_RunTasks @849 NONAME
BusyMode_RunNewTask @330 NONAME
BusyMode_RunNewTask @853 NONAME
BusyMode_RunNewTaskWithName @330 NONAME
BusyMode_WorkerEnd @331 NONAME
BusyMode_WorkerError @850 NONAME

Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/api/doomsday.h
Expand Up @@ -116,7 +116,8 @@ struct font_s;
timespan_t BusyMode_ElapsedTime(void);
int BusyMode_RunTask(BusyTask* task);
int BusyMode_RunTasks(BusyTask* tasks, int numTasks);
int BusyMode_RunNewTask(int flags, const char* taskName, busyworkerfunc_t worker, void* workerData);
int BusyMode_RunNewTask(int flags, busyworkerfunc_t worker, void* workerData);
int BusyMode_RunNewTaskWithName(int flags, busyworkerfunc_t worker, void* workerData, const char* taskName);

void BusyMode_WorkerEnd(void);
void BusyMode_WorkerError(const char* message);
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/busymode.h
Expand Up @@ -73,7 +73,8 @@ int BusyMode_RunTasks(BusyTask* tasks, int numTasks);
*
* @return Return value of the worker.
*/
int BusyMode_RunNewTask(int mode, const char* taskName, busyworkerfunc_t worker, void* workerData);
int BusyMode_RunNewTask(int mode, busyworkerfunc_t worker, void* workerData);
int BusyMode_RunNewTaskWithName(int mode, busyworkerfunc_t worker, void* workerData, const char* taskName);

/**
* To be called by the busy worker when it has finished processing, to signal
Expand Down
52 changes: 26 additions & 26 deletions doomsday/engine/portable/src/busymode.cpp
Expand Up @@ -242,23 +242,23 @@ static void postBusyCleanup(void)

/**
* @param mode Busy mode flags @ref busyModeFlags
* @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.
* @param taskName Optional task name (drawn with the progress bar).
*/
static BusyTask* newTask(int mode, const char* taskName, busyworkerfunc_t worker,
void* workerData)
static BusyTask* newTask(int mode, busyworkerfunc_t worker, void* workerData,
const char* taskName)
{
// Initialize the task.
BusyTask* task = (BusyTask*) calloc(1, sizeof(*task));
task->mode = mode;
task->worker = worker;
task->workerData = workerData;
// Take a copy of the task name.
if(taskName && taskName[0])
{
task->name = strdup(taskName);
}
task->mode = mode;
return task;
}

Expand All @@ -285,8 +285,7 @@ int BusyMode_RunTasks(BusyTask* tasks, int numTasks)
task = tasks;
for(i = 0; i < numTasks; ++i, task++)
{
// If no name is specified for this task, continue using the name of the
// the previous task.
// If no new task name is specified, continue using the name of the previous task.
if(task->name)
{
if(task->name[0])
Expand All @@ -295,33 +294,29 @@ int BusyMode_RunTasks(BusyTask* tasks, int numTasks)
currentTaskName = NULL;
}

if(!task->worker)
{
// Null tasks are not processed; so signal success.
//task->retVal = 0;
continue;
}

// Process the work.

// Is the worker updating its progress?
if(task->maxProgress > 0)
Con_InitProgress2(task->maxProgress, task->progressStart, task->progressEnd);

mode = task->mode;

/// @fixme Kludge: Force BUSYF_STARTUP here so that the animation of one task is
/// not drawn on top of the last frame of the previous.
/// @fixme Kludge: Force BUSYF_STARTUP here so that the animation of one task
/// is not drawn on top of the last frame of the previous.
if(numTasks > 1)
{
mode |= BUSYF_STARTUP;
}
// kludge end

// Busy mode invokes the worker on our behalf in a new thread.
// Null tasks are not processed (implicit success).
if(!task->worker) continue;

/**
* Process the work.
*/

// Is the worker updating its progress?
if(task->maxProgress > 0)
Con_InitProgress2(task->maxProgress, task->progressStart, task->progressEnd);

// Invoke the worker in a new thread.
/// @fixme Use a new temporary task.
{ BusyTask* tmp = newTask(mode, currentTaskName, task->worker, task->workerData);
{ BusyTask* tmp = newTask(mode, task->worker, task->workerData, currentTaskName);
result = runTask(tmp);
// We are now done with this task.
deleteTask(tmp);
Expand All @@ -341,14 +336,19 @@ int BusyMode_RunTask(BusyTask* task)
return BusyMode_RunTasks(task, 1);
}

int BusyMode_RunNewTask(int mode, const char* taskName, busyworkerfunc_t worker, void* workerData)
int BusyMode_RunNewTaskWithName(int mode, busyworkerfunc_t worker, void* workerData, const char* taskName)
{
BusyTask* task = newTask(mode, taskName, worker, workerData);
BusyTask* task = newTask(mode, worker, workerData, taskName);
int result = BusyMode_RunTask(task);
deleteTask(task);
return result;
}

int BusyMode_RunNewTask(int mode, busyworkerfunc_t worker, void* workerData)
{
return BusyMode_RunNewTaskWithName(mode, worker, workerData, NULL/*no task name*/);
}

/**
* Ends the busy event loop and sets its return value. The loop callback, which
* during busy mode points to the busy loop callback, is reset to NULL.
Expand Down
16 changes: 8 additions & 8 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -1569,17 +1569,17 @@ boolean DD_Init(void)

// Enter busy mode until startup complete.
Con_InitProgress2(200, 0, .25f); // First half.
BusyMode_RunNewTask(BUSYF_NO_UPLOADS | BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
"Starting up...", DD_StartupWorker, 0);
BusyMode_RunNewTaskWithName(BUSYF_NO_UPLOADS | BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
DD_StartupWorker, 0, "Starting up...");

// Engine initialization is complete. Now finish up with the GL.
GL_Init();
GL_InitRefresh();

// Do deferred uploads.
Con_InitProgress2(200, .25f, .25f); // Stop here for a while.
BusyMode_RunNewTask(BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
"Buffering...", DD_DummyWorker, 0);
BusyMode_RunNewTaskWithName(BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
DD_DummyWorker, 0, "Buffering...");

// Add resource paths specified using -iwad on the command line.
{ resourcenamespaceid_t rnId = F_DefaultResourceNamespaceForClass(RC_PACKAGE);
Expand Down Expand Up @@ -1612,8 +1612,8 @@ boolean DD_Init(void)

// Try to locate all required data files for all registered games.
Con_InitProgress2(200, .25f, 1); // Second half.
BusyMode_RunNewTask(BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
"Locating game resources...", DD_LocateAllGameResourcesWorker, 0);
BusyMode_RunNewTaskWithName(BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
DD_LocateAllGameResourcesWorker, 0, "Locating game resources...");

/*
// Unless we reenter busy-mode due to automatic game selection, we won't be
Expand Down Expand Up @@ -2008,8 +2008,8 @@ void DD_UpdateEngineState(void)
if(p.initiatedBusyMode)
{
Con_InitProgress(200);
BusyMode_RunNewTask(BUSYF_ACTIVITY | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
"Updating engine state...", DD_UpdateEngineStateWorker, &p);
BusyMode_RunNewTaskWithName(BUSYF_ACTIVITY | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
DD_UpdateEngineStateWorker, &p, "Updating engine state...");
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -2986,8 +2986,8 @@ void GL_TexReset(void)
if(useBusyMode)
{
Con_InitProgress(200);
BusyMode_RunNewTask(BUSYF_ACTIVITY | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
"Reseting textures...", reloadTextures, &useBusyMode);
BusyMode_RunNewTaskWithName(BUSYF_ACTIVITY | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
reloadTextures, &useBusyMode, "Reseting textures...");
}
else
{
Expand Down

0 comments on commit 9bf8c0b

Please sign in to comment.