Commit 169e0254 authored by fallenstardust's avatar fallenstardust

封装android log

封装play BGM
parent eeeabdae
...@@ -150,9 +150,7 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt, int errNo) { ...@@ -150,9 +150,7 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt, int errNo) {
if(pStmt) if(pStmt)
sqlite3_finalize(pStmt); sqlite3_finalize(pStmt);
int len = strlen(msg); int len = strlen(msg);
char buff[len+32]; ALOGE("cdb Error code=%d,msg=%s", errNo, msg);
sprintf(buff, "cdb Error code=%d,msg=%s", errNo, msg);
os::Printer::log(buff);
spmemvfs_close_db(pDB); spmemvfs_close_db(pDB);
spmemvfs_env_fini(); spmemvfs_env_fini();
return false; return false;
......
...@@ -33,12 +33,68 @@ void Game::process(irr::SEvent &event) { ...@@ -33,12 +33,68 @@ void Game::process(irr::SEvent &event) {
s32 y = event.MouseInput.Y; s32 y = event.MouseInput.Y;
event.MouseInput.X = optX(x); event.MouseInput.X = optX(x);
event.MouseInput.Y = optY(y); event.MouseInput.Y = optY(y);
// __android_log_print(ANDROID_LOG_DEBUG, "ygo", "Android comman process %d,%d -> %d,%d", x, y,
// event.MouseInput.X, event.MouseInput.Y);
} }
} }
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
void Game::stopBGM() {
ALOGD("stop bgm");
gMutex.lock();
soundManager->StopBGM();
gMutex.unlock();
}
void Game::playBGM() {
ALOGV("play bgm");
gMutex.lock();
if(dInfo.isStarted) {
if(dInfo.isFinished && showcardcode == 1)
soundManager->PlayBGM(SoundManager::BGM::WIN);
else if(dInfo.isFinished && (showcardcode == 2 || showcardcode == 3))
soundManager->PlayBGM(SoundManager::BGM::LOSE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] <= dInfo.lp[1] / 2)
soundManager->PlayBGM(SoundManager::BGM::DISADVANTAGE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] >= dInfo.lp[1] * 2)
soundManager->PlayBGM(SoundManager::BGM::ADVANTAGE);
else
soundManager->PlayBGM(SoundManager::BGM::DUEL);
} else if(is_building) {
soundManager->PlayBGM(SoundManager::BGM::DECK);
} else {
soundManager->PlayBGM(SoundManager::BGM::MENU);
}
gMutex.unlock();
}
void Game::onHandleAndroidCommand(ANDROID_APP app, int32_t cmd){
switch (cmd)
{
case APP_CMD_PAUSE:
ALOGD("APP_CMD_PAUSE");
if(ygo::mainGame != nullptr){
ygo::mainGame->stopBGM();
}
break;
case APP_CMD_RESUME:
//第一次不一定调用
ALOGD("APP_CMD_RESUME");
if(ygo::mainGame != nullptr){
ygo::mainGame->playBGM();
}
break;
case APP_CMD_STOP:
case APP_CMD_INIT_WINDOW:
case APP_CMD_SAVE_STATE:
case APP_CMD_TERM_WINDOW:
case APP_CMD_GAINED_FOCUS:
case APP_CMD_LOST_FOCUS:
case APP_CMD_DESTROY:
case APP_CMD_WINDOW_RESIZED:
default:
break;
}
}
bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
this->appMain = app; this->appMain = app;
#endif #endif
...@@ -76,6 +132,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -76,6 +132,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
// logger->setLogLevel(ELL_WARNING); // logger->setLogLevel(ELL_WARNING);
isPSEnabled = options->isPendulumScaleEnabled(); isPSEnabled = options->isPendulumScaleEnabled();
dataManager.FileSystem = device->getFileSystem(); dataManager.FileSystem = device->getFileSystem();
((CIrrDeviceAndroid*)device)->onAppCmd = onHandleAndroidCommand;
xScale = android::getXScale(app); xScale = android::getXScale(app);
yScale = android::getYScale(app); yScale = android::getYScale(app);
...@@ -112,9 +169,9 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -112,9 +169,9 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
for(int i=0;i<len;i++){ for(int i=0;i<len;i++){
io::path zip_path = zips[i]; io::path zip_path = zips[i];
if(dataManager.FileSystem->addFileArchive(zip_path.c_str(), false, false, EFAT_ZIP)) { if(dataManager.FileSystem->addFileArchive(zip_path.c_str(), false, false, EFAT_ZIP)) {
os::Printer::log("add arrchive ok ", zip_path.c_str()); ALOGD("add arrchive ok:%s", zip_path.c_str());
}else{ }else{
os::Printer::log("add arrchive fail ", zip_path.c_str()); ALOGW("add arrchive fail:%s", zip_path.c_str());
} }
} }
#endif #endif
...@@ -174,15 +231,15 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -174,15 +231,15 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
wchar_t wpath[1024]; wchar_t wpath[1024];
BufferIO::DecodeUTF8(cdb_path.c_str(), wpath); BufferIO::DecodeUTF8(cdb_path.c_str(), wpath);
if(dataManager.LoadDB(wpath)) { if(dataManager.LoadDB(wpath)) {
os::Printer::log("add cdb ok ", cdb_path.c_str()); ALOGD("add cdb ok:%s", cdb_path.c_str());
}else{ }else{
os::Printer::log("add cdb fail ", cdb_path.c_str()); ALOGW("add cdb fail:%s", cdb_path.c_str());
} }
} }
//if(!dataManager.LoadDB(workingDir.append("/cards.cdb").c_str())) //if(!dataManager.LoadDB(workingDir.append("/cards.cdb").c_str()))
// return false; // return false;
if(dataManager.LoadStrings((workingDir + path("/expansions/strings.conf")).c_str())){ if(dataManager.LoadStrings((workingDir + path("/expansions/strings.conf")).c_str())){
os::Printer::log("loadStrings expansions/strings.conf"); ALOGD("loadStrings expansions/strings.conf");
} }
if(!dataManager.LoadStrings((workingDir + path("/strings.conf")).c_str())) if(!dataManager.LoadStrings((workingDir + path("/strings.conf")).c_str()))
return false; return false;
...@@ -195,7 +252,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) { ...@@ -195,7 +252,7 @@ bool Game::Initialize(ANDROID_APP app, android::InitOptions *options) {
titleFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, (int)32 * yScale, isAntialias, true); titleFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, (int)32 * yScale, isAntialias, true);
textFont = guiFont; textFont = guiFont;
if(!numFont || !textFont) { if(!numFont || !textFont) {
os::Printer::log("add font fail "); ALOGW("add font fail ");
} }
smgr = device->getSceneManager(); smgr = device->getSceneManager();
device->setWindowCaption(L"[---]"); device->setWindowCaption(L"[---]");
...@@ -1287,6 +1344,7 @@ void Game::MainLoop() { ...@@ -1287,6 +1344,7 @@ void Game::MainLoop() {
} }
#endif #endif
while(device->run()) { while(device->run()) {
ALOGV("game draw frame");
linePatternD3D = (linePatternD3D + 1) % 30; linePatternD3D = (linePatternD3D + 1) % 30;
linePatternGL = (linePatternGL << 1) | (linePatternGL >> 15); linePatternGL = (linePatternGL << 1) | (linePatternGL >> 15);
atkframe += 0.1f; atkframe += 0.1f;
...@@ -1313,16 +1371,6 @@ void Game::MainLoop() { ...@@ -1313,16 +1371,6 @@ void Game::MainLoop() {
#endif #endif
gMutex.lock(); gMutex.lock();
if(dInfo.isStarted) { if(dInfo.isStarted) {
if(dInfo.isFinished && showcardcode == 1)
soundManager->PlayBGM(SoundManager::BGM::WIN);
else if(dInfo.isFinished && (showcardcode == 2 || showcardcode == 3))
soundManager->PlayBGM(SoundManager::BGM::LOSE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] <= dInfo.lp[1] / 2)
soundManager->PlayBGM(SoundManager::BGM::DISADVANTAGE);
else if(dInfo.lp[0] > 0 && dInfo.lp[0] >= dInfo.lp[1] * 2)
soundManager->PlayBGM(SoundManager::BGM::ADVANTAGE);
else
soundManager->PlayBGM(SoundManager::BGM::DUEL);
DrawBackImage(imageManager.tBackGround); DrawBackImage(imageManager.tBackGround);
DrawBackGround(); DrawBackGround();
DrawCards(); DrawCards();
...@@ -1331,14 +1379,12 @@ void Game::MainLoop() { ...@@ -1331,14 +1379,12 @@ void Game::MainLoop() {
driver->setMaterial(irr::video::IdentityMaterial); driver->setMaterial(irr::video::IdentityMaterial);
driver->clearZBuffer(); driver->clearZBuffer();
} else if(is_building) { } else if(is_building) {
soundManager->PlayBGM(SoundManager::BGM::DECK);
DrawBackImage(imageManager.tBackGround_deck); DrawBackImage(imageManager.tBackGround_deck);
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
driver->enableMaterial2D(true); driver->enableMaterial2D(true);
DrawDeckBd(); DrawDeckBd();
driver->enableMaterial2D(false); driver->enableMaterial2D(false);
} else { } else {
soundManager->PlayBGM(SoundManager::BGM::MENU);
DrawBackImage(imageManager.tBackGround_menu); DrawBackImage(imageManager.tBackGround_menu);
} }
driver->enableMaterial2D(true); driver->enableMaterial2D(true);
...@@ -1347,13 +1393,15 @@ void Game::MainLoop() { ...@@ -1347,13 +1393,15 @@ void Game::MainLoop() {
driver->enableMaterial2D(false); driver->enableMaterial2D(false);
#else #else
} else { } else {
soundManager->PlayBGM(SoundManager::BGM::MENU);
DrawBackImage(imageManager.tBackGround_menu); DrawBackImage(imageManager.tBackGround_menu);
} }
DrawGUI(); DrawGUI();
DrawSpec(); DrawSpec();
#endif #endif
gMutex.unlock(); gMutex.unlock();
#ifdef _IRR_ANDROID_PLATFORM_
playBGM();
#endif
if(signalFrame > 0) { if(signalFrame > 0) {
signalFrame--; signalFrame--;
if(!signalFrame) if(!signalFrame)
......
...@@ -12,6 +12,14 @@ ...@@ -12,6 +12,14 @@
namespace ygo { namespace ygo {
#ifdef _IRR_ANDROID_PLATFORM_
#define LOG_TAG "ygo-jni"
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG ,__VA_ARGS__)
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG ,__VA_ARGS__)
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG ,__VA_ARGS__)
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG ,__VA_ARGS__)
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG ,__VA_ARGS__)
#endif
struct Config { struct Config {
bool _init; bool _init;
bool use_d3d; bool use_d3d;
...@@ -121,6 +129,8 @@ class Game :IProcessEventReceiver{ ...@@ -121,6 +129,8 @@ class Game :IProcessEventReceiver{
public: public:
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
void stopBGM();
void playBGM();
bool Initialize(ANDROID_APP app, android::InitOptions *options); bool Initialize(ANDROID_APP app, android::InitOptions *options);
#else #else
bool Initialize(); bool Initialize();
...@@ -643,6 +653,7 @@ public: ...@@ -643,6 +653,7 @@ public:
s32 ogles2BlendTexture; s32 ogles2BlendTexture;
irr::android::CustomShaderConstantSetCallBack customShadersCallback; irr::android::CustomShaderConstantSetCallBack customShadersCallback;
Signal externalSignal; Signal externalSignal;
static void onHandleAndroidCommand(ANDROID_APP app, int32_t cmd);
#endif #endif
void setPositionFix(core::position2di fix){ void setPositionFix(core::position2di fix){
InputFix = fix; InputFix = fix;
...@@ -733,7 +744,7 @@ private: ...@@ -733,7 +744,7 @@ private:
#define BUTTON_DELETE_REPLAY 133 #define BUTTON_DELETE_REPLAY 133
#define BUTTON_RENAME_REPLAY 134 #define BUTTON_RENAME_REPLAY 134
#define BUTTON_EXPORT_DECK 135 #define BUTTON_EXPORT_DECK 135
#define BUTTON_SHARE_REPLAY 136 #define BUTTON_SHARE_REPLAY 136
#define BUTTON_REPLAY_START 140 #define BUTTON_REPLAY_START 140
#define BUTTON_REPLAY_PAUSE 141 #define BUTTON_REPLAY_PAUSE 141
#define BUTTON_REPLAY_STEP 142 #define BUTTON_REPLAY_STEP 142
......
...@@ -65,8 +65,7 @@ int main(int argc, char* argv[]) { ...@@ -65,8 +65,7 @@ int main(int argc, char* argv[]) {
*/ */
bool keep_on_return = false; bool keep_on_return = false;
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_WARN, "ygo", "handle args %d", argc); ALOGD("handle args %d", argc);
__android_log_print(ANDROID_LOG_WARN, "ygo", "handle args %s", argv);
//android //android
for(int i = 0; i < argc; ++i) { for(int i = 0; i < argc; ++i) {
const char* arg = argv[i].c_str(); const char* arg = argv[i].c_str();
...@@ -112,7 +111,7 @@ int main(int argc, char* argv[]) { ...@@ -112,7 +111,7 @@ int main(int argc, char* argv[]) {
wchar_t fname[1024]; wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname); BufferIO::DecodeUTF8(name, fname);
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname); index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "open replay file:index=%d, name=%s", index, name); ALOGD("open replay file:index=%d, name=%s", index, name);
} }
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu); ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
...@@ -138,7 +137,7 @@ int main(int argc, char* argv[]) { ...@@ -138,7 +137,7 @@ int main(int argc, char* argv[]) {
wchar_t fname[1024]; wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname); BufferIO::DecodeUTF8(name, fname);
index = GetListBoxIndex(ygo::mainGame->lstSinglePlayList, fname); index = GetListBoxIndex(ygo::mainGame->lstSinglePlayList, fname);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "open single file:index=%d, name=%s", index, name); ALOGD("open single file:index=%d, name=%s", index, name);
} }
if(index >= 0){ if(index >= 0){
ygo::mainGame->lstSinglePlayList->setSelected(index); ygo::mainGame->lstSinglePlayList->setSelected(index);
......
...@@ -284,9 +284,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -284,9 +284,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
prev_operation = id; prev_operation = id;
prev_sel = sel; prev_sel = sel;
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "1share replay file=%s", name); ALOGD("1share replay file=%s", name);
android::OnShareFile(mainGame->appMain, "yrp", name); android::OnShareFile(mainGame->appMain, "yrp", name);
__android_log_print(ANDROID_LOG_DEBUG, "ygo", "2after share replay file:index=%d", sel); ALOGD("2after share replay file:index=%d", sel);
#endif #endif
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment