Use SDL thread

This commit is contained in:
kichikuou
2016-03-27 19:11:38 +09:00
parent feab3b5f8e
commit 3de2dad0d4
4 changed files with 16 additions and 16 deletions
+6 -5
View File
@@ -29,8 +29,7 @@ MAKO::MAKO(NACT* parent) : nact(parent)
params.mako = this;
params.current_music = params.next_music = 0;
params.request_fill = params.terminate = false;
hThread = (HANDLE)_beginthread(thread, 0, &params);
SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST);
hThread = SDL_CreateThread(thread, "MidiThread", &params);
}
MAKO::~MAKO()
@@ -38,7 +37,7 @@ MAKO::~MAKO()
// MIDI再生スレッド終了
params.terminate = true;
if(hThread) {
WaitForSingleObject(hThread, INFINITE);
SDL_WaitThread(hThread, NULL);
}
hThread = NULL;
@@ -48,11 +47,13 @@ MAKO::~MAKO()
#endif
}
void MAKO::thread(PVOID pvoid)
int MAKO::thread(void* pvoid)
{
volatile PPARAMS pparams;
pparams = (PPARAMS)pvoid;
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
// MIDI初期化
pparams->mako->initialize_midi();
@@ -92,7 +93,7 @@ void MAKO::thread(PVOID pvoid)
pparams->mako->stop_midi();
pparams->mako->release_midi();
_endthread();
return 0;
}
void MAKO::play_music(int page)
+2 -3
View File
@@ -8,7 +8,6 @@
#define _MAKO_H_
#include <windows.h>
#include <process.h>
#include <mmsystem.h>
#include <stdio.h>
#include <limits.h>
@@ -47,8 +46,8 @@ private:
} PARAMS, *PPARAMS;
PARAMS params;
static void thread(PVOID pvoid);
HANDLE hThread;
static int thread(void* pvoid);
SDL_Thread* hThread;
// MIDI音源
union UNION_MIDI_DATA {
+6 -5
View File
@@ -131,8 +131,7 @@ NACT::NACT()
// メインスレッド起動
params.nact = this;
params.terminate = false;
hThread = (HANDLE)_beginthread(thread, 0, &params);
SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL);
hThread = SDL_CreateThread(thread, "NactThread", &params);
}
NACT::~NACT()
@@ -140,7 +139,7 @@ NACT::~NACT()
// メインスレッド終了
params.terminate = true;
if(hThread) {
WaitForSingleObject(hThread, INFINITE);
SDL_WaitThread(hThread, NULL);
}
hThread = NULL;
@@ -161,12 +160,14 @@ NACT::~NACT()
release_console();
}
void NACT::thread(PVOID pvoid)
int NACT::thread(void* pvoid)
{
volatile PPARAMS pparams;
pparams = (PPARAMS)pvoid;
int sleep_cnt = 0;
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_NORMAL);
while(!pparams->terminate) {
pparams->nact->execute();
// 512コマンド実行毎にSleep(10)
@@ -176,7 +177,7 @@ void NACT::thread(PVOID pvoid)
Sleep(0);
}
}
_endthread();
return 0;
}
// コマンドパーサ
+2 -3
View File
@@ -8,7 +8,6 @@
#define _NACT_H_
#include <windows.h>
#include <process.h>
#if defined(_DEBUG_CONSOLE)
#include <wincon.h>
#endif
@@ -231,8 +230,8 @@ private:
} PARAMS, *PPARAMS;
PARAMS params;
static void thread(PVOID pvoid);
HANDLE hThread;
static int thread(void* pvoid);
SDL_Thread* hThread;
// デバッグログ
void initialize_console();