fixup contrib example a bit
This commit is contained in:
parent
5c7dfb7bec
commit
a379fe572a
@ -13,8 +13,7 @@
|
|||||||
#include "bass.h"
|
#include "bass.h"
|
||||||
#include "sync-cpp.h"
|
#include "sync-cpp.h"
|
||||||
|
|
||||||
class BassTimer : public sync::Timer
|
class BassTimer : public sync::Timer {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BassTimer(HSTREAM stream, float bpm, int rowsPerBeat) : stream(stream)
|
BassTimer(HSTREAM stream, float bpm, int rowsPerBeat) : stream(stream)
|
||||||
{
|
{
|
||||||
@ -40,36 +39,49 @@ const unsigned int height = 600;
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// initialize directx
|
// initialize directx
|
||||||
IDirect3D9 *d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
IDirect3D9 *d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||||
if (NULL == d3d) throw std::string("update directx, fool.");
|
if (!d3d)
|
||||||
|
throw std::string("This application requires DirectX 9");
|
||||||
|
|
||||||
// create a window
|
// create a window
|
||||||
HWND hwnd = CreateWindowEx(0, "static", "GNU Rocket Example", WS_POPUP | WS_VISIBLE, 0, 0, width, height, 0, 0, GetModuleHandle(0), 0);
|
HWND hwnd = CreateWindowEx(0, "static", "GNU Rocket Example",
|
||||||
|
WS_POPUP | WS_VISIBLE, 0, 0, width, height, 0, 0,
|
||||||
|
GetModuleHandle(0), 0);
|
||||||
|
|
||||||
// create the device
|
// create the device
|
||||||
IDirect3DDevice9 *device = NULL;
|
IDirect3DDevice9 *device = NULL;
|
||||||
static D3DPRESENT_PARAMETERS present_parameters = {width, height, D3DFMT_X8R8G8B8, 3, D3DMULTISAMPLE_NONE, 0, D3DSWAPEFFECT_DISCARD, 0, WINDOWED, 1, D3DFMT_D24S8, 0, WINDOWED ? 0 : D3DPRESENT_RATE_DEFAULT, 0};
|
static D3DPRESENT_PARAMETERS present_parameters = {width,
|
||||||
if (D3D_OK != d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))
|
height, D3DFMT_X8R8G8B8, 3, D3DMULTISAMPLE_NONE, 0,
|
||||||
throw std::string("could not create device. you computer SUCKS!");
|
D3DSWAPEFFECT_DISCARD, 0, WINDOWED, 1, D3DFMT_D24S8,
|
||||||
|
0, WINDOWED ? 0 : D3DPRESENT_RATE_DEFAULT, 0
|
||||||
|
};
|
||||||
|
if (FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,
|
||||||
|
D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
|
||||||
|
&present_parameters, &device)))
|
||||||
|
throw std::string("Failed to create device");
|
||||||
|
|
||||||
// init BASS
|
// init BASS
|
||||||
int soundDevice = 1;
|
int soundDevice = 1;
|
||||||
if (!BASS_Init(soundDevice, 44100, 0, hwnd, 0)) throw std::string("failed to init bass");
|
if (!BASS_Init(soundDevice, 44100, 0, hwnd, 0))
|
||||||
|
throw std::string("Failed to init bass");
|
||||||
|
|
||||||
// load tune
|
// load tune
|
||||||
HSTREAM stream = BASS_StreamCreateFile(false, "tune.ogg", 0, 0, BASS_MP3_SETPOS | ((0 == soundDevice) ? BASS_STREAM_DECODE : 0));
|
HSTREAM stream = BASS_StreamCreateFile(false, "tune.ogg", 0, 0,
|
||||||
if (!stream) throw std::string("failed to open tune");
|
BASS_MP3_SETPOS | (!soundDevice ? BASS_STREAM_DECODE : 0));
|
||||||
|
if (!stream)
|
||||||
|
throw std::string("Failed to open tune");
|
||||||
|
|
||||||
// let's just assume 150 BPM (this holds true for the included tune)
|
// let's just assume 150 BPM (this holds true for the included tune)
|
||||||
float bpm = 150.0f;
|
float bpm = 150.0f;
|
||||||
|
|
||||||
// setup timer and construct sync-device
|
// setup timer and construct sync-device
|
||||||
BassTimer timer(stream, bpm, 8);
|
BassTimer timer(stream, bpm, 8);
|
||||||
std::auto_ptr<sync::Device> syncDevice = std::auto_ptr<sync::Device>(sync::createDevice("sync", timer));
|
std::auto_ptr<sync::Device> syncDevice = std::auto_ptr<sync::Device>(
|
||||||
if (NULL == syncDevice.get()) throw std::string("something went wrong - failed to connect to host?");
|
sync::createDevice("sync", timer));
|
||||||
|
if (!syncDevice.get())
|
||||||
|
throw std::string("Failed to connect to host?");
|
||||||
|
|
||||||
// get tracks
|
// get tracks
|
||||||
sync::Track &clearRTrack = syncDevice->getTrack("clear.r");
|
sync::Track &clearRTrack = syncDevice->getTrack("clear.r");
|
||||||
@ -80,11 +92,7 @@ int main(int argc, char *argv[])
|
|||||||
sync::Track &camDistTrack = syncDevice->getTrack("cam.dist");
|
sync::Track &camDistTrack = syncDevice->getTrack("cam.dist");
|
||||||
|
|
||||||
LPD3DXMESH cubeMesh = NULL;
|
LPD3DXMESH cubeMesh = NULL;
|
||||||
if (FAILED(D3DXCreateBox(
|
if (FAILED(D3DXCreateBox(device, 1.0f, 1.0f, 1.0f, &cubeMesh, NULL)))
|
||||||
device,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
&cubeMesh, NULL
|
|
||||||
)))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// let's roll!
|
// let's roll!
|
||||||
@ -92,18 +100,13 @@ int main(int argc, char *argv[])
|
|||||||
timer.play();
|
timer.play();
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (!done)
|
while (!done) {
|
||||||
{
|
|
||||||
float row = float(timer.getRow());
|
float row = float(timer.getRow());
|
||||||
if (!syncDevice->update(row)) done = true;
|
if (!syncDevice->update(row))
|
||||||
|
done = true;
|
||||||
|
|
||||||
// setup clear color
|
// setup clear color
|
||||||
D3DXCOLOR clearColor(
|
D3DXCOLOR clearColor(clearRTrack.getValue(row), clearGTrack.getValue(row), clearBTrack.getValue(row), 0.0);
|
||||||
clearRTrack.getValue(row),
|
|
||||||
clearGTrack.getValue(row),
|
|
||||||
clearBTrack.getValue(row),
|
|
||||||
0.0
|
|
||||||
);
|
|
||||||
|
|
||||||
// paint the window
|
// paint the window
|
||||||
device->BeginScene();
|
device->BeginScene();
|
||||||
@ -132,8 +135,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
BASS_Update(0); // decrease the chance of missing vsync
|
BASS_Update(0); // decrease the chance of missing vsync
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||||
{
|
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
|
|
||||||
@ -148,18 +150,14 @@ int main(int argc, char *argv[])
|
|||||||
device->Release();
|
device->Release();
|
||||||
d3d->Release();
|
d3d->Release();
|
||||||
DestroyWindow(hwnd);
|
DestroyWindow(hwnd);
|
||||||
}
|
} catch (const std::exception &e) {
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
#ifdef _CONSOLE
|
#ifdef _CONSOLE
|
||||||
fprintf(stderr, "*** error: %s\n", e.what());
|
fprintf(stderr, "*** error: %s\n", e.what());
|
||||||
#else
|
#else
|
||||||
MessageBox(NULL, e.what(), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
|
MessageBox(NULL, e.what(), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
|
||||||
#endif
|
#endif
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
} catch (const std::string &str) {
|
||||||
catch (const std::string &str)
|
|
||||||
{
|
|
||||||
#ifdef _CONSOLE
|
#ifdef _CONSOLE
|
||||||
fprintf(stderr, "*** error: %s\n", str.c_str());
|
fprintf(stderr, "*** error: %s\n", str.c_str());
|
||||||
#else
|
#else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user