bool KX_GameActuator::Update() { // bool result = false; /*unused*/ bool bNegativeEvent = IsNegativeEvent(); RemoveAllEvents(); if (bNegativeEvent) return false; // do nothing on negative events switch (m_mode) { case KX_GAME_LOAD: case KX_GAME_START: { if (m_ketsjiengine) { std::string exitstring = "start other game"; m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME); m_ketsjiengine->SetNameNextGame(m_filename); m_scene->AddDebugProperty((this)->GetParent(), exitstring); } break; } case KX_GAME_RESTART: { if (m_ketsjiengine) { std::string exitstring = "restarting game"; m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME); m_ketsjiengine->SetNameNextGame(m_filename); m_scene->AddDebugProperty((this)->GetParent(), exitstring); } break; } case KX_GAME_QUIT: { if (m_ketsjiengine) { std::string exitstring = "quiting game"; m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME); m_scene->AddDebugProperty((this)->GetParent(), exitstring); } break; } case KX_GAME_SAVECFG: { #ifdef WITH_PYTHON if (m_ketsjiengine) { saveGamePythonConfig(); } break; #endif // WITH_PYTHON } case KX_GAME_LOADCFG: { #ifdef WITH_PYTHON if (m_ketsjiengine) { loadGamePythonConfig(); } break; #endif // WITH_PYTHON } case KX_GAME_SCREENSHOT: { RAS_ICanvas *canvas = m_ketsjiengine->GetCanvas(); if (canvas) { canvas->MakeScreenShot(m_filename); } else { CM_LogicBrickError(this, "KX_GAME_SCREENSHOT Rasterizer not available"); } break; } default: ; /* do nothing? this is an internal error !!! */ } return false; }
bool KX_GameActuator::Update() { // bool result = false; /*unused*/ bool bNegativeEvent = IsNegativeEvent(); RemoveAllEvents(); if (bNegativeEvent) return false; // do nothing on negative events switch (m_mode) { case KX_GAME_LOAD: case KX_GAME_START: { if (m_ketsjiengine) { STR_String exitstring = "start other game"; m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME); m_ketsjiengine->SetNameNextGame(m_filename); m_scene->AddDebugProperty((this)->GetParent(), exitstring); } break; } case KX_GAME_RESTART: { if (m_ketsjiengine) { STR_String exitstring = "restarting game"; m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME); m_ketsjiengine->SetNameNextGame(m_filename); m_scene->AddDebugProperty((this)->GetParent(), exitstring); } break; } case KX_GAME_QUIT: { if (m_ketsjiengine) { STR_String exitstring = "quiting game"; m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME); m_scene->AddDebugProperty((this)->GetParent(), exitstring); } break; } case KX_GAME_SAVECFG: { #ifdef WITH_PYTHON if (m_ketsjiengine) { char mashal_path[512]; char *marshal_buffer = NULL; unsigned int marshal_length; FILE *fp = NULL; pathGamePythonConfig(mashal_path); marshal_length = saveGamePythonConfig(&marshal_buffer); if (marshal_length && marshal_buffer) { fp = fopen(mashal_path, "wb"); if (fp) { if (fwrite(marshal_buffer, 1, marshal_length, fp) != marshal_length) { printf("Warning: could not write marshal data\n"); } fclose(fp); } else { printf("Warning: could not open marshal file\n"); } } else { printf("Warning: could not create marshal buffer\n"); } if (marshal_buffer) delete [] marshal_buffer; } break; #endif // WITH_PYTHON } case KX_GAME_LOADCFG: { #ifdef WITH_PYTHON if (m_ketsjiengine) { char mashal_path[512]; char *marshal_buffer; int marshal_length; FILE *fp = NULL; int result; pathGamePythonConfig(mashal_path); fp = fopen(mashal_path, "rb"); if (fp) { // obtain file size: fseek (fp , 0 , SEEK_END); marshal_length = ftell(fp); if (marshal_length == -1) { printf("warning: could not read position of '%s'\n", mashal_path); fclose(fp); break; } rewind(fp); marshal_buffer = (char*) malloc (sizeof(char)*marshal_length); result = fread (marshal_buffer, 1, marshal_length, fp); if (result == marshal_length) { loadGamePythonConfig(marshal_buffer, marshal_length); } else { printf("warning: could not read all of '%s'\n", mashal_path); } free(marshal_buffer); fclose(fp); } else { printf("warning: could not open '%s'\n", mashal_path); } } break; #endif // WITH_PYTHON } case KX_GAME_SCREENSHOT: { RAS_ICanvas *canvas = m_ketsjiengine->GetCanvas(); if (canvas) { canvas->MakeScreenShot(m_filename); } else { printf("KX_GAME_SCREENSHOT error: Rasterizer not available"); } break; } default: ; /* do nothing? this is an internal error !!! */ } return false; }
bool GPG_Application::startEngine(void) { if (m_engineRunning) { return false; } // Temporary hack to disable banner display for NaN approved content. /* m_canvas->SetBannerDisplayEnabled(true); Camera* cam; cam = (Camera*)scene->camera->data; if (cam) { if (((cam->flag) & 48)==48) { m_canvas->SetBannerDisplayEnabled(false); } } else { showError(CString("Camera data invalid.")); return false; } */ // create a scene converter, create and convert the stratingscene m_sceneconverter = new KX_BlenderSceneConverter(m_maggie, m_ketsjiengine); if (m_sceneconverter) { STR_String startscenename = m_startSceneName.Ptr(); m_ketsjiengine->SetSceneConverter(m_sceneconverter); // if (always_use_expand_framing) // sceneconverter->SetAlwaysUseExpandFraming(true); if (m_blendermat) m_sceneconverter->SetMaterials(true); if (m_blenderglslmat && (m_globalSettings->matmode == GAME_MAT_GLSL)) m_sceneconverter->SetGLSLMaterials(true); if (m_startScene->gm.flag & GAME_NO_MATERIAL_CACHING) m_sceneconverter->SetCacheMaterials(false); KX_Scene* startscene = new KX_Scene(m_keyboard, m_mouse, m_networkdevice, startscenename, m_startScene, m_canvas); #ifdef WITH_PYTHON // some python things PyObject *gameLogic, *gameLogic_keys; setupGamePython(m_ketsjiengine, startscene, m_maggie, NULL, &gameLogic, &gameLogic_keys, m_argc, m_argv); #endif // WITH_PYTHON //initialize Dome Settings if (m_startScene->gm.stereoflag == STEREO_DOME) m_ketsjiengine->InitDome(m_startScene->gm.dome.res, m_startScene->gm.dome.mode, m_startScene->gm.dome.angle, m_startScene->gm.dome.resbuf, m_startScene->gm.dome.tilt, m_startScene->gm.dome.warptext); // initialize 3D Audio Settings AUD_I3DDevice* dev = AUD_get3DDevice(); if (dev) { dev->setSpeedOfSound(m_startScene->audio.speed_of_sound); dev->setDopplerFactor(m_startScene->audio.doppler_factor); dev->setDistanceModel(AUD_DistanceModel(m_startScene->audio.distance_model)); } #ifdef WITH_PYTHON // Set the GameLogic.globalDict from marshal'd data, so we can // load new blend files and keep data in GameLogic.globalDict loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length); #endif m_sceneconverter->ConvertScene( startscene, m_rasterizer, m_canvas); m_ketsjiengine->AddScene(startscene); // Create a timer that is used to kick the engine if (!m_frameTimer) { m_frameTimer = m_system->installTimer(0, kTimerFreq, frameTimerProc, m_mainWindow); } m_rasterizer->Init(); m_ketsjiengine->StartEngine(true); m_engineRunning = true; // Set the animation playback rate for ipo's and actions // the framerate below should patch with FPS macro defined in blendef.h // Could be in StartEngine set the framerate, we need the scene to do this Scene *scene= startscene->GetBlenderScene(); // needed for macro m_ketsjiengine->SetAnimFrameRate(FPS); } if (!m_engineRunning) { stopEngine(); } return m_engineRunning; }