Add PSP support
This commit is contained in:
parent
1509b9bd0e
commit
9f8dcae52a
@ -21,145 +21,131 @@
|
|||||||
|
|
||||||
#include <bounce/common/settings.h>
|
#include <bounce/common/settings.h>
|
||||||
|
|
||||||
#define B3_WINDOWS 1
|
#if defined(__WIN32__)
|
||||||
#define B3_MAC 2
|
|
||||||
#define B3_UNIX 3
|
|
||||||
|
|
||||||
#if defined (_WIN32)
|
|
||||||
#define B3_PLATFORM B3_WINDOWS
|
|
||||||
#elif defined( __APPLE__ )
|
|
||||||
#define B3_PLATFORM B3_MAC
|
|
||||||
#elif defined(_arch_dreamcast)
|
|
||||||
#define B3_PLATFORM B3_DREAMCAST
|
|
||||||
#else
|
|
||||||
#define B3_PLATFORM B3_UNIX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if B3_PLATFORM == B3_WINDOWS
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
// A timer class that accumulates time.
|
// A timer class that accumulates time.
|
||||||
// Usefull for measuring elapsed times between code sections.
|
// Usefull for measuring elapsed times between code sections.
|
||||||
class b3Time
|
class b3Time
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
b3Time()
|
b3Time()
|
||||||
{
|
{
|
||||||
LARGE_INTEGER c;
|
LARGE_INTEGER c;
|
||||||
QueryPerformanceCounter(&c);
|
QueryPerformanceCounter(&c);
|
||||||
m_c0 = c.QuadPart;
|
m_c0 = c.QuadPart;
|
||||||
m_t0 = 0.0;
|
m_t0 = 0.0;
|
||||||
m_t = 0.0;
|
m_t = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the accumulated time in miliseconds from this timer.
|
|
||||||
float64 GetCurrentMilis() const
|
|
||||||
{
|
|
||||||
return m_t;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the elapsed time since this timer was updated.
|
// Get the accumulated time in miliseconds from this timer.
|
||||||
float64 GetElapsedMilis() const
|
float64 GetCurrentMilis() const
|
||||||
{
|
{
|
||||||
return m_t - m_t0;
|
return m_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the elapsed time since this function was called to this timer.
|
// Get the elapsed time since this timer was updated.
|
||||||
void Update()
|
float64 GetElapsedMilis() const
|
||||||
{
|
{
|
||||||
static float64 inv_frequency = 0.0;
|
return m_t - m_t0;
|
||||||
if (inv_frequency == 0.0)
|
}
|
||||||
{
|
|
||||||
LARGE_INTEGER c;
|
|
||||||
QueryPerformanceFrequency(&c);
|
|
||||||
|
|
||||||
float64 cycles_per_s = float64(c.QuadPart);
|
|
||||||
float64 s_per_cycle = 1.0 / cycles_per_s;
|
|
||||||
float64 ms_per_cycle = 1000.0 * s_per_cycle;
|
|
||||||
inv_frequency = ms_per_cycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
LARGE_INTEGER c;
|
// Add the elapsed time since this function was called to this timer.
|
||||||
QueryPerformanceCounter(&c);
|
void Update()
|
||||||
|
{
|
||||||
|
static float64 inv_frequency = 0.0;
|
||||||
|
if (inv_frequency == 0.0)
|
||||||
|
{
|
||||||
|
LARGE_INTEGER c;
|
||||||
|
QueryPerformanceFrequency(&c);
|
||||||
|
|
||||||
float64 dt = inv_frequency * float64(c.QuadPart - m_c0);
|
float64 cycles_per_s = float64(c.QuadPart);
|
||||||
m_c0 = c.QuadPart;
|
float64 s_per_cycle = 1.0 / cycles_per_s;
|
||||||
Add(dt);
|
float64 ms_per_cycle = 1000.0 * s_per_cycle;
|
||||||
}
|
inv_frequency = ms_per_cycle;
|
||||||
|
}
|
||||||
|
|
||||||
// Add time to this timer.
|
LARGE_INTEGER c;
|
||||||
void Add(float64 dt)
|
QueryPerformanceCounter(&c);
|
||||||
{
|
|
||||||
m_t0 = m_t;
|
float64 dt = inv_frequency * float64(c.QuadPart - m_c0);
|
||||||
m_t += dt;
|
m_c0 = c.QuadPart;
|
||||||
}
|
Add(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add time to this timer.
|
||||||
|
void Add(float64 dt)
|
||||||
|
{
|
||||||
|
m_t0 = m_t;
|
||||||
|
m_t += dt;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u64 m_c0;
|
u64 m_c0;
|
||||||
float64 m_t0;
|
float64 m_t0;
|
||||||
float64 m_t;
|
float64 m_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
#elif B3_PLATFORM == B3_MAC
|
#elif defined(__APPLE__)
|
||||||
|
|
||||||
#include <mach/mach_time.h>
|
#include <mach/mach_time.h>
|
||||||
|
|
||||||
// A timer class that accumulates time.
|
// A timer class that accumulates time.
|
||||||
// Usefull for measuring elapsed times between code sections.
|
// Usefull for measuring elapsed times between code sections.
|
||||||
class b3Time
|
class b3Time
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
b3Time()
|
b3Time()
|
||||||
{
|
{
|
||||||
m_c0 = mach_absolute_time();
|
m_c0 = mach_absolute_time();
|
||||||
m_t0 = 0.0;
|
m_t0 = 0.0;
|
||||||
m_t = 0.0;
|
m_t = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the accumulated time in miliseconds from this timer.
|
|
||||||
double GetCurrentMilis() const
|
|
||||||
{
|
|
||||||
return m_t;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the elapsed time since this timer was updated.
|
// Get the accumulated time in miliseconds from this timer.
|
||||||
double GetElapsedMilis() const
|
double GetCurrentMilis() const
|
||||||
{
|
{
|
||||||
return m_t - m_t0;
|
return m_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the elapsed time since this function was called to this timer.
|
// Get the elapsed time since this timer was updated.
|
||||||
void Update()
|
double GetElapsedMilis() const
|
||||||
{
|
{
|
||||||
static double inv_frequency = 0.0;
|
return m_t - m_t0;
|
||||||
if (inv_frequency == 0.0)
|
}
|
||||||
{
|
|
||||||
mach_timebase_info_data_t info;
|
|
||||||
mach_timebase_info(&info);
|
|
||||||
inv_frequency = double(info.numer) / (double(info.denom) * 1.0e6);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t c = mach_absolute_time();
|
|
||||||
double dt = inv_frequency * (double)(c - m_c0);
|
|
||||||
m_c0 = c;
|
|
||||||
Add(dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add time to this timer.
|
// Add the elapsed time since this function was called to this timer.
|
||||||
void Add(double dt)
|
void Update()
|
||||||
{
|
{
|
||||||
m_t0 = m_t;
|
static double inv_frequency = 0.0;
|
||||||
m_t += dt;
|
if (inv_frequency == 0.0)
|
||||||
}
|
{
|
||||||
|
mach_timebase_info_data_t info;
|
||||||
|
mach_timebase_info(&info);
|
||||||
|
inv_frequency = double(info.numer) / (double(info.denom) * 1.0e6);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t c = mach_absolute_time();
|
||||||
|
double dt = inv_frequency * (double)(c - m_c0);
|
||||||
|
m_c0 = c;
|
||||||
|
Add(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add time to this timer.
|
||||||
|
void Add(double dt)
|
||||||
|
{
|
||||||
|
m_t0 = m_t;
|
||||||
|
m_t += dt;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t m_c0;
|
uint64_t m_c0;
|
||||||
double m_t0;
|
double m_t0;
|
||||||
double m_t;
|
double m_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
#elif B3_PLATFORM == B3_DREAMCAST
|
#elif defined(_arch_dreamcast)
|
||||||
|
|
||||||
#include <kos.h>
|
#include <kos.h>
|
||||||
|
|
||||||
@ -207,55 +193,103 @@ private:
|
|||||||
double m_t;
|
double m_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#elif defined(__PSP__)
|
||||||
|
|
||||||
|
#include <pspthreadman.h>
|
||||||
|
|
||||||
|
class b3Time
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
b3Time()
|
||||||
|
{
|
||||||
|
m_c0 = sceKernelGetSystemTimeLow();
|
||||||
|
m_t0 = 0.0;
|
||||||
|
m_t = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the accumulated time in miliseconds from this timer.
|
||||||
|
double GetCurrentMilis() const
|
||||||
|
{
|
||||||
|
return m_t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the elapsed time since this timer was updated.
|
||||||
|
double GetElapsedMilis() const
|
||||||
|
{
|
||||||
|
return m_t - m_t0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the elapsed time since this function was called to this timer.
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
uint64_t c = sceKernelGetSystemTimeLow();
|
||||||
|
double dt = double(c - m_c0) * 0.000001;
|
||||||
|
m_c0 = c;
|
||||||
|
Add(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add time to this timer.
|
||||||
|
void Add(double dt)
|
||||||
|
{
|
||||||
|
m_t0 = m_t;
|
||||||
|
m_t += dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint64_t m_c0;
|
||||||
|
double m_t0;
|
||||||
|
double m_t;
|
||||||
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
// A timer class that accumulates time.
|
// A timer class that accumulates time.
|
||||||
// Usefull for measuring elapsed times between code sections.
|
// Usefull for measuring elapsed times between code sections.
|
||||||
class b3Time
|
class b3Time
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
b3Time()
|
b3Time()
|
||||||
{
|
{
|
||||||
clock_gettime(CLOCK_MONOTONIC, &m_c0);
|
clock_gettime(CLOCK_MONOTONIC, &m_c0);
|
||||||
m_t0 = 0.0;
|
m_t0 = 0.0;
|
||||||
m_t = 0.0;
|
m_t = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the accumulated time in miliseconds from this timer.
|
|
||||||
double GetCurrentMilis() const
|
|
||||||
{
|
|
||||||
return m_t;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the elapsed time since this timer was updated.
|
// Get the accumulated time in miliseconds from this timer.
|
||||||
double GetElapsedMilis() const
|
double GetCurrentMilis() const
|
||||||
{
|
{
|
||||||
return m_t - m_t0;
|
return m_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the elapsed time since this function was called to this timer.
|
// Get the elapsed time since this timer was updated.
|
||||||
void Update()
|
double GetElapsedMilis() const
|
||||||
{
|
{
|
||||||
struct timespec c;
|
return m_t - m_t0;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &c);
|
}
|
||||||
double dt = (double)(c.tv_nsec - m_c0.tv_nsec) * 1.0e-6;
|
|
||||||
m_c0 = c;
|
|
||||||
Add(dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add time to this timer.
|
// Add the elapsed time since this function was called to this timer.
|
||||||
void Add(double dt)
|
void Update()
|
||||||
{
|
{
|
||||||
m_t0 = m_t;
|
struct timespec c;
|
||||||
m_t += dt;
|
clock_gettime(CLOCK_MONOTONIC, &c);
|
||||||
}
|
double dt = (double)(c.tv_nsec - m_c0.tv_nsec) * 1.0e-6;
|
||||||
|
m_c0 = c;
|
||||||
|
Add(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add time to this timer.
|
||||||
|
void Add(double dt)
|
||||||
|
{
|
||||||
|
m_t0 = m_t;
|
||||||
|
m_t += dt;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct timespec m_c0;
|
struct timespec m_c0;
|
||||||
double m_t0;
|
double m_t0;
|
||||||
double m_t;
|
double m_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // B3_PLATFORM
|
#endif // B3_PLATFORM
|
||||||
|
Loading…
x
Reference in New Issue
Block a user