mirror of
https://github.com/glest/glest-source.git
synced 2025-08-30 11:19:48 +02:00
Trying an experiment with a thread for playing streamed sounds
This commit is contained in:
@@ -36,6 +36,34 @@ public:
|
||||
void setTechDataPaths(vector<string> techDataPaths) { this->techDataPaths = techDataPaths; }
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SimpleTaskThread
|
||||
// =====================================================
|
||||
|
||||
//
|
||||
// This interface describes the methods a callback object must implement
|
||||
//
|
||||
class SimpleTaskCallbackInterface {
|
||||
public:
|
||||
virtual void simpleTask() = 0;
|
||||
};
|
||||
|
||||
class SimpleTaskThread : public BaseThread
|
||||
{
|
||||
protected:
|
||||
|
||||
SimpleTaskCallbackInterface *simpleTaskInterface;
|
||||
unsigned int executionCount;
|
||||
unsigned int millisecsBetweenExecutions;
|
||||
|
||||
public:
|
||||
SimpleTaskThread();
|
||||
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
|
||||
unsigned int executionCount=0,
|
||||
unsigned int millisecsBetweenExecutions=0);
|
||||
virtual void execute();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
||||
|
@@ -63,4 +63,42 @@ void FileCRCPreCacheThread::execute() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
|
||||
SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface,
|
||||
unsigned int executionCount,
|
||||
unsigned int millisecsBetweenExecutions) {
|
||||
this->simpleTaskInterface = simpleTaskInterface;
|
||||
this->executionCount = executionCount;
|
||||
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
|
||||
}
|
||||
|
||||
void SimpleTaskThread::execute() {
|
||||
try {
|
||||
setRunningStatus(true);
|
||||
|
||||
unsigned int idx = 0;
|
||||
for(;this->simpleTaskInterface != NULL;) {
|
||||
this->simpleTaskInterface->simpleTask();
|
||||
if(this->executionCount > 0) {
|
||||
idx++;
|
||||
if(idx >= this->executionCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(getQuitStatus() == true) {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(this->millisecsBetweenExecutions);
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
setRunningStatus(false);
|
||||
|
||||
throw runtime_error(ex.what());
|
||||
}
|
||||
setRunningStatus(false);
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
Reference in New Issue
Block a user