implement basic sound engine using OpenAL

This commit is contained in:
Eduardo Bart
2012-04-13 16:54:08 -03:00
parent 9b4115a7e5
commit c4525059ce
25 changed files with 1236 additions and 75 deletions

View File

@@ -32,15 +32,20 @@ Clock::Clock()
m_startupTime = std::chrono::high_resolution_clock::now();
m_currentTicks = 0;
}
ticks_t Clock::updateTicks()
{
auto timeNow = std::chrono::high_resolution_clock::now();
m_currentTicks = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow - m_startupTime).count();
m_currentTicks = asyncTicks();
m_currentTime = m_currentTicks/1000.0f;
return m_currentTicks;
}
ticks_t Clock::asyncTicks()
{
auto timeNow = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(timeNow - m_startupTime).count();
}
void Clock::sleep(int ms)
{
usleep(ms * 1000);

View File

@@ -33,10 +33,12 @@ public:
ticks_t updateTicks();
void sleep(int ms);
ticks_t asyncTicks();
ticks_t ticks() { return m_currentTicks; }
ticks_t ticksElapsed(long prevTicks) { return m_currentTicks - prevTicks; }
ticks_t ticksFor(int delay) { return m_currentTicks + delay; }
float asyncTime() { return asyncTicks()/1000.0f; }
float time() { return m_currentTime; }
float timeElapsed(float prevTime) { return m_currentTime - prevTime; }
float timeFor(float delay) { return m_currentTime + delay; }

View File

@@ -35,38 +35,53 @@ FileStream::~FileStream()
close();
}
void FileStream::close()
bool FileStream::close()
{
if(m_fileHandle) {
if(PHYSFS_isInit() && PHYSFS_close(m_fileHandle) == 0)
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
m_fileHandle = nullptr;
return true;
}
return false;
}
void FileStream::flush()
bool FileStream::flush()
{
if(PHYSFS_flush(m_fileHandle) == 0)
if(PHYSFS_flush(m_fileHandle) == 0) {
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
return false;
}
return true;
}
void FileStream::read(void *buffer, uint count)
int FileStream::read(void *buffer, int size, int nmemb)
{
if(PHYSFS_read(m_fileHandle, buffer, 1, count) != count)
int res = PHYSFS_read(m_fileHandle, buffer, size, nmemb);
if(res == -1) {
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
return 0;
}
return res;
}
void FileStream::write(void *buffer, uint count)
bool FileStream::write(void *buffer, int count)
{
if(PHYSFS_write(m_fileHandle, buffer, 1, count) != count)
if(PHYSFS_write(m_fileHandle, buffer, 1, count) != count) {
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
return false;
}
return true;
}
void FileStream::seek(uint pos)
bool FileStream::seek(int pos)
{
if(PHYSFS_seek(m_fileHandle, pos) == 0)
if(PHYSFS_seek(m_fileHandle, pos) == 0) {
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
return false;
}
return true;
}
int FileStream::size()
@@ -74,6 +89,11 @@ int FileStream::size()
return PHYSFS_fileLength(m_fileHandle);
}
int FileStream::tell()
{
return PHYSFS_tell(m_fileHandle);
}
uint8 FileStream::getU8()
{
uint8 v = 0;

View File

@@ -37,12 +37,13 @@ protected:
public:
~FileStream();
void close();
void flush();
void write(void *buffer, uint count);
void read(void *buffer, uint count);
void seek(uint pos);
bool close();
bool flush();
bool write(void *buffer, int count);
int read(void *buffer, int size, int nmemb = 1);
bool seek(int pos);
int size();
int tell();
std::string name() { return m_name; }
std::string readAll();