int KG_SetRuntimeEnvironment(const char cszAppFullPathName[MAX_PATH]) { int nResult = false; int nRetCode = false; char szProgramPath[MAX_PATH]; KGLOG_PROCESS_ERROR(cszAppFullPathName); // Set the locale to the default, which is the user-default ANSI code page obtained from // the operating system. setlocale(LC_ALL, ""); // Set working path to application path. g_ExtractFilePath(szProgramPath, const_cast<char *>(cszAppFullPathName)); szProgramPath[sizeof(szProgramPath) - 1] = '\0'; if (szProgramPath[0]) { nRetCode = chdir(szProgramPath); KG_PROCESS_ERROR(nRetCode == 0); // Set root path for config file. g_SetRootPath(szProgramPath); } else { g_SetRootPath(NULL); } nResult = true; Exit0: return nResult; }
STDMETHODIMP CAtlBase::SetRootPath(BSTR str3DEngineDir) { g_SetRootPath(BSTR_TO_STRING(str3DEngineDir)); SetCurrentDirectory(BSTR_TO_STRING(str3DEngineDir)); SetDefWorkingDir(str3DEngineDir); return S_OK; }
int main(int argc, char* argv[]) { int nResult = false; int nRetCode = false; int nLogInitFlag = false; int nRdbFlag = false; KGLOG_PARAM LogParam; KSO3RoleDBUpdater* pKSO3RoleDBUpdater = NULL; #ifdef WIN32 SetConsoleInfo(); #endif setlocale(LC_ALL, ""); g_SetRootPath(NULL); strncpy(LogParam.szPath, "logs", sizeof(LogParam.szPath)); LogParam.szPath[sizeof(LogParam.szPath) - 1] = '\0'; strncpy(LogParam.szIdent, "SO3RoleDBUpdaterTest", sizeof(LogParam.szIdent)); LogParam.szIdent[sizeof(LogParam.szIdent) - 1] = '\0'; LogParam.Options = (KGLOG_OPTIONS)(KGLOG_OPTION_FILE | KGLOG_OPTION_CONSOLE); LogParam.nMaxLineEachFile = 160000; nRetCode = KGLogInit(LogParam, NULL); KGLOG_PROCESS_ERROR(nRetCode); nLogInitFlag = true; pKSO3RoleDBUpdater = new KSO3RoleDBUpdater(); KGLOG_PROCESS_ERROR(pKSO3RoleDBUpdater); nRetCode = pKSO3RoleDBUpdater->Init(); KGLOG_PROCESS_ERROR(nRetCode); nRdbFlag = true; KGLogPrintf(KGLOG_INFO, "SO3RoleDBUpdaterTest had started up ... ..."); nRetCode = pKSO3RoleDBUpdater->Run(); KGLOG_PROCESS_ERROR(nRetCode); KGLogPrintf(KGLOG_INFO, "SO3RoleDB UpdateTest Complete..."); nResult = true; Exit0: if (nRdbFlag) { pKSO3RoleDBUpdater->UnInit(); nRdbFlag = false; } KG_DELETE(pKSO3RoleDBUpdater); if (nLogInitFlag) { KGLogUnInit(NULL); nLogInitFlag = false; } return nResult ? 0 : 1; }
STDMETHODIMP CBaseLib::Init(int nhWnd) { InitLog(); // TODO: Add your implementation code here typedef HRESULT (*fnGet3DEngineInterface)(void**); HRESULT hResult = E_FAIL; HRESULT hRetCode = E_FAIL; fnGet3DEngineInterface pfnGet3DEngineInterface; g_SetRootPath(NULL); g_SetFindFileMode(TRUE); g_SetFilePath(""); KGLOG_PROCESS_ERROR(nhWnd); m_hWnd = (HWND)nhWnd; // TODO: Add your implementation code here #ifdef _DEBUG g_hModule = ::LoadLibraryA("KG3DEngineD.dll"); #else g_hModule = ::LoadLibraryA("KG3DEngine.dll"); #endif KGLOG_PROCESS_ERROR(g_hModule); pfnGet3DEngineInterface = (fnGet3DEngineInterface)GetProcAddress(g_hModule, "Get3DEngineInterface"); KGLOG_PROCESS_ERROR(pfnGet3DEngineInterface); hRetCode = pfnGet3DEngineInterface((void**)&g_p3DEngine); KGLOG_PROCESS_ERROR(SUCCEEDED(hRetCode)); KGLOG_PROCESS_ERROR(g_p3DEngine); IEKG3DEngineManager* pEngine = static_cast<IEKG3DEngineManager*>(g_p3DEngine); KGLOG_PROCESS_ERROR(pEngine); pEngine->GetGraphicsTool(&g_p3DTools); KGLOG_PROCESS_ERROR(g_p3DTools); hRetCode = g_p3DEngine->Init(0, KG3DENG_CLIENT | KG3DENG_RECORD, m_hWnd, m_hWnd); KGLOG_PROCESS_ERROR(SUCCEEDED(hRetCode)); hResult = S_OK; Exit0: return S_OK; }
BOOL KSOEditor::Init() { BOOL bResult = false; int nRetCode = 0; BOOL bNetWorkInitFlag = false; IIniFile* piFile = NULL; int nPort = 0; int nMaxConnection = 0; char szLocalIP[32]; g_SetRootPath(NULL); piFile = g_OpenIniFile("KSOEditorServer.ini"); KGLOG_PROCESS_ERROR(piFile); piFile->GetString("Server", "IP", "127.0.0.1", szLocalIP, sizeof(szLocalIP)); piFile->GetInteger("Server", "Port", 0, &nPort); piFile->GetInteger("Server", "MaxConnection", 100, &nMaxConnection); m_pNetworkMgr = new KNetworkMgr; KGLOG_PROCESS_ERROR(m_pNetworkMgr); nRetCode = m_pNetworkMgr->Init(szLocalIP, nPort, nMaxConnection); KGLOG_PROCESS_ERROR(nRetCode); bNetWorkInitFlag = true; bResult = true; Exit0: if (!bResult) { if (bNetWorkInitFlag) { m_pNetworkMgr->UnInit(); bNetWorkInitFlag = false; } SAFE_DELETE(m_pNetworkMgr); } KG_COM_RELEASE(piFile); return bResult; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { HRESULT hRetCode = E_FAIL; int nRetCode = false; int nKGLogInitFlag = false; int nKG3DEngineInitFlag = false; int nX = 0; int nY = 0; int nWidth = 0; int nHeight = 0; char szBuffer[MAX_PATH] = ""; KGLOG_PARAM LogParam = {"logs", "KG3DEngine", KGLOG_OPTION_FILE, 65536}; WNDCLASSEX wcex = {0}; MSG msg = {0}; UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); nRetCode = KGLogInit(LogParam, NULL); KG_PROCESS_ERROR(nRetCode); nKGLogInitFlag = true; g_SetRootPath(NULL); //SetLowerConfig(); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.hInstance = hInstance; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszClassName = TEXT("KG3DEnginePerformanceAnalyzer"); RegisterClassEx(&wcex); nX = 0; nY = 0; nWidth = 800; nHeight = 600; g_hWnd = ::CreateWindow( wcex.lpszClassName, TEXT("3D引擎性能分析程序"), WS_OVERLAPPEDWINDOW | WS_VISIBLE/*WS_CAPTION | WS_SYSMENU*/, nX, nY, nWidth, nHeight, NULL, NULL, hInstance, NULL ); KGLOG_PROCESS_ERROR(g_hWnd); ShowWindow(g_hWnd, true/*nCmdShow*/); UpdateWindow(g_hWnd); //ASSERT(FALSE); //-------------------------------- hRetCode = g_cEngineManager.Init(0, KG3DENG_CLIENT, g_hWnd, g_hWnd); KGLOG_COM_PROCESS_ERROR(hRetCode); nKG3DEngineInitFlag = true; for (int nIndex = 0; nIndex < EXT_T0TAL; ++nIndex) { DeleteFile(g_cszErrorFileName[nIndex]); } ::MessageBox(NULL, "搜索所有列表,进行Mesh,Mdl,Speedtree,Sfx,Mtl,Tani的检查,请耐心等待……", "提示", MB_OK); //TestScene(); //TestLoadAllMesh(); //KGLogPrintf(KGLOG_INFO, "Load Mesh Over\n"); //TestLoadAllDetail(); //KGLogPrintf(KGLOG_INFO, "Load Detail Over\n"); //TestLoadAllMDL(); //KGLogPrintf(KGLOG_INFO, "Load MDL Over\n"); //TestLoadAllSPEEDTREE(); //KGLogPrintf(KGLOG_INFO, "Load SPEEDTREE Over\n"); //TestLoadAllSFX(); //KGLogPrintf(KGLOG_INFO, "Load SFX Over\n"); //TestLoadAllMaterial(); //TestLoadAllSound(); TestLoadAllBSP(); KGLogPrintf(KGLOG_INFO, "Load Bsp Over\n"); snprintf( szBuffer, sizeof(szBuffer), "检查完毕,请查看文件%s", g_cszErrorFileName ); szBuffer[sizeof(szBuffer) - 1] = '\0'; ::MessageBox(NULL, szBuffer, "提示", MB_OK); Exit0: if (nKG3DEngineInitFlag) { g_cEngineManager.UnInit(); nKG3DEngineInitFlag = false; } if (nKGLogInitFlag) { KGLogUnInit(NULL); nKGLogInitFlag = false; } return (int) msg.wParam; }
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { typedef HRESULT (*fnGet3DEngineInterface)(void**); fnGet3DEngineInterface pfnGet3DEngineInterface = NULL; g_hMod = NULL; HRESULT hr = E_FAIL; if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { //TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { //TRACE0("Failed to create status bar\n"); return -1; // fail to create } if(!m_wndProgressDialogBar.Create(this,IDD_PROGRESS_DIALOGBAR, CBRS_ALIGN_BOTTOM | CBRS_BOTTOM | CBRS_TOOLTIPS | CBRS_FLYBY,IDD_PROGRESS_DIALOGBAR)) { //TRACE0("Failed to create toolbar\n"); return -1; } if(!m_wndMasterlistDialogBar.Create(this,IDD_MASTERLIST_DIALOGBAR, CBRS_ALIGN_RIGHT | CBRS_RIGHT | CBRS_TOOLTIPS | CBRS_FLYBY,IDD_MASTERLIST_DIALOGBAR)) { //TRACE0("Failed to create toolbar\n"); return -1; } // TODO: Delete these three lines if you don't want the toolbar to be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); m_wndMasterlistDialogBar.EnableDocking(CBRS_ALIGN_RIGHT); DockControlBar(&m_wndMasterlistDialogBar); m_wndProgressDialogBar.EnableDocking(CBRS_ALIGN_BOTTOM); DockControlBar(&m_wndProgressDialogBar); g_bSlider = TRUE; KGLOG_PARAM LogParam = {"logs", "Record", KGLOG_OPTION_FILE, 65536}; int nRetCode = KGLogInit(LogParam, NULL); g_SetRootPath(); g_SetFilePath(""); g_GetRootPath(g_szDefWorkDirectory); //SetCurrentDirectory(); #ifdef _DEBUG g_hMod = ::LoadLibraryA("KG3DEngineD.dll"); #else g_hMod = ::LoadLibraryA("KG3DEngine.dll"); #endif if (g_hMod == NULL) return -1; pfnGet3DEngineInterface = (fnGet3DEngineInterface)GetProcAddress(g_hMod, "Get3DEngineInterface"); if (pfnGet3DEngineInterface == NULL) return -1; hr = pfnGet3DEngineInterface((void**)&g_p3DEngine); if (hr == E_FAIL) return -1; ASSERT(g_p3DEngine); IEKG3DEngineManager* pEngine = static_cast<IEKG3DEngineManager*>(g_p3DEngine); ASSERT(pEngine); pEngine->GetGraphicsTool(&g_p3DTools); ASSERT(g_p3DTools); hr = g_p3DEngine->Init(0,KG3DENG_CLIENT | KG3DENG_RECORD, m_hWnd, m_hWnd); if (hr == E_FAIL) return -1; //pEngine->SetAutoReloadTexture(TRUE); RecordOption recordOption; recordOption.Size.cx = 1024; recordOption.Size.cy = 768; recordOption.nAutoScale = FALSE; recordOption.FiterType = D3DTEXF_LINEAR; recordOption.fInterval = 41; recordOption.ImageType = D3DXIFF_JPG; recordOption.bKeep = FALSE; g_p3DEngine->SetRecordOption(&recordOption); return 0; }
BOOL Init3DEngine(unsigned uMode, unsigned int uFlag, HWND hBaseWindow, HWND hRenderWindow, BSTR strEnginePath, BSTR strStartUpPath) { ATLTRACE("#####################3DEngine Initializing!##################\r\n"); BOOL bRetCode = false; KGLOG_PARAM LogParam; char szCWD[MAX_PATH]; getcwd(szCWD, sizeof(szCWD)); memset(&LogParam, 0, sizeof(LogParam)); snprintf(LogParam.szPath,sizeof(LogParam.szPath),"%s\\logs",szCWD); LogParam.szPath[sizeof(LogParam.szPath) - 1] = '\0'; strcpy(LogParam.szIdent, "AtlaxKG3D"); LogParam.nMaxLineEachFile = 65536; LogParam.Options = (KGLOG_OPTIONS)KGLOG_OPTION_FILE; bRetCode = KGLogInit(LogParam, NULL); if (!bRetCode) { ::MessageBox(NULL, "Log文件初始化失败!", NULL, NULL); return FALSE; } TCHAR szCurDir[MAX_PATH]; sprintf(szCurDir, BSTR_TO_STRING(strStartUpPath)); strcat(szCurDir, "/3DProxy/"); g_SetRootPath(szCurDir); SetCurrentDirectory(szCurDir); KGLogPrintf(KGLOG_DEBUG, "strStartUpPath=%s", BSTR_TO_STRING(strStartUpPath)); #ifdef _DEBUG strcat(szCurDir, "KG3DEngineD.dll"); #else strcat(szCurDir, "KG3DEngine.dll"); #endif g_3dEngineDll.Init(szCurDir); KGLogPrintf(KGLOG_DEBUG, "%s loaddll成功", szCurDir); g_SetRootPath(BSTR_TO_STRING(strEnginePath)); // in Engine_lua5(D).dll lstrcpy(g_EnginePath, BSTR_TO_STRING(strEnginePath)); SetCurrentDirectory(BSTR_TO_STRING(strEnginePath)); lstrcpy(g_szDefWorkDirectory, g_EnginePath); HMODULE h = g_3dEngineDll.GetDllHandle(); _ASSERTE(h); if (!h) return FALSE; KGLogPrintf(KGLOG_DEBUG, "g_3dEngineDll loaddll成功"); if (lstrlen(g_EnginePath) <= 0) { HMODULE hDll = GetModuleHandle("atlax.dll"); if (hDll) { KGLogPrintf(KGLOG_DEBUG, "atlax.dll loaddll成功"); TCHAR szBuf[MAX_PATH + 1]; GetModuleFileName(hDll, szBuf, MAX_PATH); CString strTemp = szBuf; CString strDir = strTemp.Left(strTemp.ReverseFind('\\')); SetCurrentDirectory(strDir); } } else // { SetCurrentDirectory(g_EnginePath); } typedef HRESULT (*pfnGet3DEngineInterface)(void** pEngineManager); pfnGet3DEngineInterface Get3DEngineInterface = (pfnGet3DEngineInterface)GetProcAddress(h, "Get3DEngineInterface"); _ASSERTE(Get3DEngineInterface); if (!Get3DEngineInterface) return FALSE; IEKG3DEngineManager* pInterface = NULL; HRESULT hret = Get3DEngineInterface((void**)&pInterface); if (FAILED(hret)) return FALSE; else { KGLogPrintf(KGLOG_DEBUG, "pre pInterface->Init"); if (FAILED(pInterface->Init(uMode, uFlag, hBaseWindow, hRenderWindow))) { return FALSE; } pInterface->SetAutoReloadTexture(TRUE); InitGlobalVars(pInterface); ATLTRACE("=================3DEngine Initialized!==================\r\n"); return TRUE; } }
int KGTestMapDisuseResource::LoadEngineDLL() { int nResult = false; int nRetCode = false; HRESULT hrRetCode = E_FAIL; HWND hWindow = NULL; char szEngineDll[MAX_PATH] = {0}; g_SetRootPath(m_szClientPath); ::SetCurrentDirectory(m_szClientPath); nRetCode = _snprintf_s( szEngineDll, sizeof(szEngineDll), sizeof(szEngineDll) - 1, "%s%s", g_szApplicationPath, ENGINE_DLL_NAME ); KGLOG_PROCESS_ERROR(nRetCode > 0); nRetCode = _access(szEngineDll, 0); if (nRetCode != 0) { nRetCode = _snprintf_s( szEngineDll, sizeof(szEngineDll), sizeof(szEngineDll) - 1, "%s%s", m_szClientPath, ENGINE_DLL_NAME ); KGLOG_PROCESS_ERROR(nRetCode > 0); } m_hEngineDLL = LoadLibrary(szEngineDll); KGLOG_PROCESS_ERROR(m_hEngineDLL); hWindow = ::GetDesktopWindow(); KGLOG_PROCESS_ERROR(hWindow); typedef HRESULT (*pfnGet3DEngineInterface)(void** ppvEngineManager); pfnGet3DEngineInterface Get3DEngineInterface; Get3DEngineInterface = (pfnGet3DEngineInterface)GetProcAddress(m_hEngineDLL, "Get3DEngineInterface"); Get3DEngineInterface((void**)&m_pEngineMgr); KGLOG_PROCESS_ERROR(m_pEngineMgr); hrRetCode = m_pEngineMgr->Init(0, KG3DENG_CLIENT, hWindow, hWindow); KGLOG_COM_PROCESS_ERROR(hrRetCode); nResult = true; Exit0: if (!nResult) { if (m_pEngineMgr) { hrRetCode = m_pEngineMgr->UnInit(); KGLOG_COM_CHECK_ERROR(hrRetCode); m_pEngineMgr = NULL; } if (m_hEngineDLL) { nRetCode = FreeLibrary(m_hEngineDLL); KGLOG_CHECK_ERROR(hrRetCode); m_hEngineDLL = NULL; } } return nResult; }
int main(int argc, char *argv[]) { int nResult = false; int nRetCode = false; KGLOG_PARAM LogParam = {"Logs", "KG_BoneCheker", KGLOG_OPTION_FILE, 65535}; vector<string>vecBipList; char szDir[MAX_PATH]; int nIsCheckClientAni = false; g_SetRootPath(); nRetCode = KGLogInit(LogParam, NULL); KG_PROCESS_ERROR(nRetCode); KGLogPrintf(KGLOG_INFO, "%s\n", "BoneChecker Build at " __TIME__ " " __DATE__); KGLogPrintf(KGLOG_INFO, "Begin...\n"); szDir[0] = '\0'; if (argc == 3) { if (!stricmp(argv[1], "-client")) nIsCheckClientAni = true; else if (!stricmp(argv[1], "-bip")) nIsCheckClientAni = false; else KGLOG_PROCESS_ERROR(false && "wrong argument"); memcpy(szDir, argv[2], _countof(szDir) - 1); szDir[_countof(szDir) - 1] = '\0'; } else { nRetCode = LoadConfig(&nIsCheckClientAni, szDir, _countof(szDir)); KGLOG_PROCESS_ERROR(nRetCode && "Load Config Failed"); } if (nIsCheckClientAni) { KGLogPrintf( KGLOG_INFO, "Check all SO3Client bip && clip...\n" "SO3ClientDir=\"%s\"\n", szDir ); nRetCode = GenerateJX3BipFileList(szDir, vecBipList); KG_PROCESS_ERROR(nRetCode); nRetCode = AnalyseBip(vecBipList); KG_PROCESS_ERROR(nRetCode); } else { KGLogPrintf(KGLOG_INFO, "Check Ani file with bip \"%s\"\n", szDir); nRetCode = IsBipFileExist(szDir); KG_PROCESS_ERROR(nRetCode); vecBipList.push_back(szDir); } nRetCode = AnalyseAni(vecBipList); KG_PROCESS_ERROR(nRetCode); nResult = true; Exit0: if (nResult) KGLogPrintf(KGLOG_INFO, "done successful."); else KGLogPrintf(KGLOG_INFO, "!!!done with some error, please check log file."); KGLogUnInit(NULL); return nResult ? 0 : 1; }
BOOL Init3DEngine(unsigned uMode, unsigned int uFlag, HWND hBaseWindow, HWND hRenderWindow, BSTR strEnginePath, BSTR strStartUpPath) { ATLTRACE("#####################3DEngine Initializing!##################\r\n"); TCHAR szCurDir[MAX_PATH]; sprintf(szCurDir, BSTR_TO_STRING(strStartUpPath)); //strcat(szCurDir, "/3DProxy/"); //g_SetRootPath(szCurDir); //SetCurrentDirectory(szCurDir); #ifdef _DEBUG strcat(szCurDir, "KG3DEngineD.dll"); #else strcat(szCurDir, "KG3DEngine.dll"); #endif g_3dEngineDll.Init(szCurDir); g_SetRootPath(BSTR_TO_STRING(strEnginePath)); // in Engine_lua5(D).dll lstrcpy(g_EnginePath, BSTR_TO_STRING(strEnginePath)); SetCurrentDirectory(BSTR_TO_STRING(strEnginePath)); lstrcpy(g_szDefWorkDirectory, g_EnginePath); HMODULE h = g_3dEngineDll.GetDllHandle(); _ASSERTE(h); if (!h) return FALSE; if (lstrlen(g_EnginePath) <= 0) { HMODULE hDll = GetModuleHandle("atlax.dll"); if (hDll) { TCHAR szBuf[MAX_PATH + 1]; GetModuleFileName(hDll, szBuf, MAX_PATH); CString strTemp = szBuf; CString strDir = strTemp.Left(strTemp.ReverseFind('\\')); SetCurrentDirectory(strDir); } } else // { SetCurrentDirectory(g_EnginePath); } typedef HRESULT (*pfnGet3DEngineInterface)(void** pEngineManager); pfnGet3DEngineInterface Get3DEngineInterface = (pfnGet3DEngineInterface)GetProcAddress(h, "Get3DEngineInterface"); _ASSERTE(Get3DEngineInterface); if (!Get3DEngineInterface) return FALSE; IEKG3DEngineManager* pInterface = NULL; HRESULT hret = Get3DEngineInterface((void**)&pInterface); if (FAILED(hret)) return FALSE; else { if (FAILED(pInterface->Init(uMode, uFlag, hBaseWindow, hRenderWindow))) { return FALSE; } pInterface->SetAutoReloadTexture(TRUE); InitGlobalVars(pInterface); ATLTRACE("=================3DEngine Initialized!==================\r\n"); return TRUE; } }
BOOL KSceneEditorApp::InitInstance() { BOOL bResult = false; BOOL bRetCode = false; HRESULT hr = E_FAIL; char* pszRetCWD = NULL; IRecorderFactory* piRecorderFactory = NULL; CMultiDocTemplate* pDocTemplate = NULL; MFCFramework::CMainFrame* pMainFrame = NULL; KGLOG_PARAM LogParam; char szCWD[MAX_PATH]; CCommandLineInfo cmdInfo; //使用Dummper m_hDummperModule = LoadLibrary(_T("dumper.dll")); pszRetCWD = getcwd(szCWD, sizeof(szCWD)); KGLOG_PROCESS_ERROR(pszRetCWD); g_SetRootPath(); g_SetFindFileMode(TRUE); g_SetFilePath(""); g_LoadPackageFiles("config.ini", "PackFile"); memset(&LogParam, 0, sizeof(LogParam)); snprintf(LogParam.szPath,sizeof(LogParam.szPath),"%s\\logs",szCWD); LogParam.szPath[sizeof(LogParam.szPath) - 1] = '\0'; strcpy(LogParam.szIdent, "SceneEditor"); LogParam.nMaxLineEachFile = 65536; LogParam.Options = (KGLOG_OPTIONS)KGLOG_OPTION_FILE; bRetCode = KGLogInit(LogParam, NULL); KGLOG_PROCESS_ERROR(bRetCode); m_bLogInitFlag = true; bRetCode = KMemory::Initialize("SceneEditor.memory"); KGLOG_PROCESS_ERROR(bRetCode); m_bMemoryInitFlag = true; g_cEditorDirectory.Load(); { TCHAR AppDir[256] = {0}; GetCurrentDirectory(256, AppDir); wsprintf(g_szDefWorkDirectory,"%s\\",AppDir); wsprintf(g_szDefExeDirectory,"%s\\",AppDir); } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(10); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. pDocTemplate = new CMultiDocTemplate( IDR_SCENEETYPE, RUNTIME_CLASS(KSceneEditorDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(KSceneEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDR_MESHETYPE, RUNTIME_CLASS(KSceneModelEditorDoc), RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame RUNTIME_CLASS(KSceneModelEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDS_OBJECTTYPE, RUNTIME_CLASS(KSceneObjectEditorDoc), RUNTIME_CLASS(KSceneObjectEditorFrameWnd), // custom MDI child frame RUNTIME_CLASS(KSceneObjectEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDR_SFXEDITOR, RUNTIME_CLASS(KSceneSFXEditorDoc), RUNTIME_CLASS(KSceneSFXEditorFrame), // custom MDI child frame RUNTIME_CLASS(KSceneSFXEditorView)); pDocTemplate->SetContainerInfo(IDR_SFXEDITOR); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDR_MODELTYPE, RUNTIME_CLASS(KSceneModelEditorDoc), RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame RUNTIME_CLASS(KSceneModelEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDS_DATAFLOWFILE, RUNTIME_CLASS(KSceneDataFlowEditorDoc), RUNTIME_CLASS(KScneDataFlowEditorFrameWnd), // custom MDI child frame RUNTIME_CLASS(KSceneDataFlowEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDR_PVSTYPE, RUNTIME_CLASS(KPvsEditorDoc), RUNTIME_CLASS(KPvsEditorFrame), // custom MDI child frame RUNTIME_CLASS(KPvsEditorView)); pDocTemplate->SetContainerInfo(IDR_PVSTYPE); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDR_MODELTYPE2, RUNTIME_CLASS(KSceneModelEditorDoc), RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame RUNTIME_CLASS(KSceneModelEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDR_SPEEDTREETYPE, RUNTIME_CLASS(KSceneModelEditorDoc), RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame RUNTIME_CLASS(KSceneModelEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); pDocTemplate = new CMultiDocTemplate( IDR_MODELTYPE3, RUNTIME_CLASS(KSceneModelEditorDoc), RUNTIME_CLASS(KSceneModelEditorFrameWnd), // custom MDI child frame RUNTIME_CLASS(KSceneModelEditorView)); pDocTemplate->SetContainerInfo(IDR_SCENEETYPE_CNTR_IP); AddDocTemplate(pDocTemplate); // create main MDI Frame window pMainFrame = new MFCFramework::CMainFrame; bRetCode = pMainFrame->LoadFrame(IDR_SCENEETYPE); KGLOG_PROCESS_ERROR(bRetCode); m_pMainWnd = pMainFrame; //(by dengzhihui 2006年12月7日 15:48:16 extern BYTE* g_SceneEditorKeyState;//键盘状态 ZeroMemory(g_SceneEditorKeyState,sizeof(BYTE)*256); //) // Parse command line for standard shell commands, DDE, file open ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line //if (!ProcessShellCommand(cmdInfo)) // return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(SW_MAXIMIZE); pMainFrame->UpdateWindow(); g_pEngineManager->GetUseSO3Logical(&g_bUseSO3Logical); if (g_bUseSO3Logical) { piRecorderFactory = CreateRecorderFactoryInterface(ermNormal); KGLOG_PROCESS_ERROR(piRecorderFactory); g_pSO3World = new KSO3World; KGLOG_PROCESS_ERROR(g_pSO3World); bRetCode = g_pSO3World->Init(piRecorderFactory); KGLOG_PROCESS_ERROR(bRetCode); m_bGameWorldOpenFlag = true; if (InitRepresent() && InitUI()) { HWND hWnd = NULL; g_SetGameWorldUIHandler(&g_pUI->GetGameWorldUIHandler()); g_SetGameWorldRepresentHandler(g_pRepresent->GetGameWorldRepresentHandler()); g_pRepresentHandler = g_pRepresent->GetRepresentHandelr(); g_pRepresent->GetRepresentHandelr()->AttachGameWorld(g_pSO3World, QuerySO3WorldClientInterface()); g_pRepresent->GetRepresentHandelr()->Attach3DEngine(g_GetEngineIEInterface(), g_pEngineManager->Get3DModelTable(), g_pEngineManager->Get3DUI()); g_pRepresent->GetRepresentHandelr()->AttachUI(g_pUI, &g_pUI->GetGameWorldUIHandler()); g_pEngineManager->GetBaseWnd(&hWnd); g_pRepresent->GetRepresentHandelr()->InitHWND(hWnd); if (!g_pRepresent->Init()) { ::MessageBox(NULL, "表现逻辑初始化失败!", NULL, 0); } } } //创建声音 g_pSoundShell = Create3DSoundShell(); if (!g_pSoundShell) { KGLogPrintf(KGLOG_WARNING, "声音创建失败."); } else { g_pSoundShell->Init(m_pMainWnd->GetSafeHwnd()); } //在这里把需要使用sound的地方都统一设置上soundshell g_pEngineManager->SetSoundShell(g_pSoundShell); if (g_pRepresent) { g_pRepresent->SetSoundShell(g_pSoundShell); } bResult = true; Exit0: if (!bResult) { if (m_bGameWorldOpenFlag) { g_pSO3World->UnInit(); m_bGameWorldOpenFlag = false; } KG_DELETE(g_pSO3World); if (m_bMemoryInitFlag) { KMemory::Finalize(); m_bMemoryInitFlag = false; } if (m_bLogInitFlag) { KGLogUnInit(NULL); m_bLogInitFlag = false; } } KG_COM_RELEASE(piRecorderFactory); return bResult; }
BOOL KSO3Gateway::Init() { BOOL bResult = false; BOOL bRetCode = false; const char* pszLocale = NULL; BOOL bPaysysAgencyInit = false; BOOL bRelayAgencyInit = false; BOOL bPlayerManagerInit = false; BOOL bEyesInit = false; BOOL bSDOAInit = false; g_SetRootPath(NULL); bRetCode = LoadConfig(); KGLOG_PROCESS_ERROR(bRetCode); pszLocale = setlocale(LC_ALL, m_szLocale); KGLOG_PROCESS_ERROR(pszLocale); KGLogPrintf(KGLOG_INFO, "Set locale: %s\n", pszLocale); m_PaysysAgency.AttachModule(&m_RelayAgency); m_PaysysAgency.AttachModule(&m_PlayerManager); m_RelayAgency.AttachModule(&m_PaysysAgency); m_RelayAgency.AttachModule(&m_PlayerManager); m_RelayAgency.AttachModule(this); m_RelayAgency.AttachModule(&m_QueueManager); m_RelayAgency.AttachModule(&m_SndaAgency); m_PlayerManager.AttachModule(&m_PaysysAgency); m_PlayerManager.AttachModule(&m_RelayAgency); m_PlayerManager.AttachModule(&m_QueueManager); m_PlayerManager.AttachModule(this); m_QueueManager.AttachModule(&m_PlayerManager); m_QueueManager.AttachModule(&m_RelayAgency); m_Eyes.AttachModule(&m_PlayerManager); m_Eyes.AttachModule(&m_PaysysAgency); m_Eyes.AttachModule(&m_QueueManager); m_SndaAgency.AttachModule(&m_PlayerManager); m_SndaAgency.AttachModule(&m_PaysysAgency); m_SndaAgency.AttachModule(this); //bRetCode = m_PaysysAgency.Init(); //KGLOG_PROCESS_ERROR(bRetCode); //bPaysysAgencyInit = true; bRetCode = m_RelayAgency.Init(); KGLOG_PROCESS_ERROR(bRetCode); bRelayAgencyInit = true; bRetCode = m_PlayerManager.Init(); KGLOG_PROCESS_ERROR(bRetCode); bPlayerManagerInit = true; bRetCode = m_Eyes.Init(); KGLOG_PROCESS_ERROR(bRetCode); bEyesInit = true; bRetCode = m_SndaAgency.Init(); KGLOG_PROCESS_ERROR(bRetCode); bSDOAInit = true; m_bRunFlag = true; bResult = true; Exit0: if (!bResult) { if (bPlayerManagerInit) { m_PlayerManager.UnInit(); bPlayerManagerInit = false; } if (bRelayAgencyInit) { m_RelayAgency.UnInit(); bRelayAgencyInit = false; } if (bPaysysAgencyInit) { m_PaysysAgency.UnInit(); bPaysysAgencyInit = false; } if (bEyesInit) { m_Eyes.UnInit(); bEyesInit = false; } if (bSDOAInit) { m_SndaAgency.UnInit(); bSDOAInit = false; } } return bResult; }
int KGPostRenderTestingMgr::LoadEngineDLL() { int nResult = false; int nRetCode = false; HRESULT hrRetCode = E_FAIL; TCHAR szDllFile[MAX_PATH] = {0}; g_SetRootPath(m_szClientPath); SetCurrentDirectory(m_szClientPath); nRetCode = _snprintf_s( szDllFile, sizeof(szDllFile) - 1, "%s%s", g_szApplicationPath, ENGINE_DLL_NAME ); KGLOG_PROCESS_ERROR(nRetCode > 0); nRetCode = _access(szDllFile, 0); if (nRetCode != 0) { nRetCode = _snprintf_s( szDllFile, sizeof(szDllFile) - 1, "%s%s", m_szClientPath, ENGINE_DLL_NAME ); KGLOG_PROCESS_ERROR(nRetCode > 0); } m_hEngineDLL = LoadLibrary(szDllFile); KGLOG_PROCESS_ERROR(m_hEngineDLL); typedef HRESULT (*pfnGet3DEngineInterface)(void** ppvEngineManager); pfnGet3DEngineInterface Get3DEngineInterface; Get3DEngineInterface = (pfnGet3DEngineInterface)GetProcAddress(m_hEngineDLL, "Get3DEngineInterface"); Get3DEngineInterface((void**)&m_pEngineMgr); KGLOG_PROCESS_ERROR(m_pEngineMgr); hrRetCode = m_pEngineMgr->Init(0, KG3DENG_CLIENT, m_hRenderWindow, m_hRenderWindow); KGLOG_COM_PROCESS_ERROR(hrRetCode); nResult = true; Exit0: if (!nResult) { if (m_pEngineMgr) { hrRetCode = m_pEngineMgr->UnInit(); KGLOG_COM_CHECK_ERROR(hrRetCode); m_pEngineMgr = NULL; } if (m_hEngineDLL) { nRetCode = FreeLibrary(m_hEngineDLL); KGLOG_CHECK_ERROR(hrRetCode); m_hEngineDLL = NULL; } } return nResult; }
int main(int argc, char* argv[]) { BOOL bRetCode = false; int nRetCode = 0; const char* pcszRetCWD = NULL; BOOL bLockInitFlag = false; BOOL bMergeToolInitFlag = false; BOOL bMemoryPoolInit = false; BOOL bLogInitFlag = false; char szCWD[MAX_PATH]; KProcessLock Lock; KGLOG_PARAM LogParam; g_SetRootPath(); bMemoryPoolInit = KMemory::Initialize("MergeTool.memory"); KG_PROCESS_ERROR(bMemoryPoolInit); pcszRetCWD = getcwd(szCWD, sizeof(szCWD)); KG_PROCESS_ERROR(pcszRetCWD); memset(&LogParam, 0, sizeof(LogParam)); snprintf(LogParam.szPath, sizeof(LogParam.szPath), "%s/logs", szCWD); strcpy(LogParam.szIdent, "MergeTool"); LogParam.nMaxLineEachFile = 65536 * 2; LogParam.Options = (KGLOG_OPTIONS)(KGLOG_OPTION_FILE | KGLOG_OPTION_CONSOLE); bLogInitFlag = KGLogInit(LogParam, NULL); KG_PROCESS_ERROR(bLogInitFlag); bLockInitFlag = Lock.CreateLock(LOCK_FILE_NAME); KG_PROCESS_ERROR(bLockInitFlag); g_pMergeTool = KMemory::New<KMergeTool>(); KG_PROCESS_ERROR(g_pMergeTool); bMergeToolInitFlag = g_pMergeTool->Init(); KGLOG_PROCESS_ERROR(bMergeToolInitFlag); bRetCode = g_pMergeTool->Run(); KGLOG_PROCESS_ERROR(bRetCode); Exit0: if (bMergeToolInitFlag) { g_pMergeTool->UnInit(); bMergeToolInitFlag = false; } if (g_pMergeTool) { KMemory::Delete(g_pMergeTool); g_pMergeTool = NULL; } if (bLogInitFlag) { KGLogUnInit(NULL); bLogInitFlag = false; } if (bMemoryPoolInit) { KMemory::Finalize(); bMemoryPoolInit = false; } if (bLockInitFlag) { Lock.FreeLock(); bLockInitFlag = false; } return 0; }
int main(int argc, char *argv[]) { INT nRet = 0; INT nLogInitFlag = FALSE; { QLOG_PARAM sLogParam; LPSTR pszRetCWD = NULL; CHAR szCWD[MAX_PATH]; pszRetCWD = getcwd(szCWD, sizeof(szCWD)); memset(&sLogParam, 0, sizeof(sLogParam)); snprintf(sLogParam.szPath, sizeof(sLogParam.szPath), "%s/log", szCWD); QStrCpyLen(sLogParam.szIdent, "roleserver", sizeof(sLogParam.szIdent)); sLogParam.nMaxLineEachFile = USHRT_MAX; sLogParam.Options = (QLOG_OPTIONS)(LOG_OPTION_FILE | LOG_OPTION_CONSOLE); QLogInit(sLogParam, NULL); #ifndef _DEBUG //LogSetPriorityMask(KGLOG_UPTO(LOG_INFO)); #endif // _DEBUG nLogInitFlag = TRUE; } #ifdef __unix // 允许产生coredump文件 rlimit sLimit; sLimit.rlim_cur = -1; sLimit.rlim_max = -1; ::setrlimit(RLIMIT_CORE, &sLimit); // 设置创建的新文件权限为(rw.r.r) umask(022); #endif QLogPrintf(LOG_DEBUG, "%s", "9SKy Role Server"); QLogPrintf(LOG_DEBUG, "%s", "BUILD " __TIME__ " " __DATE__); g_SetRootPath(NULL); g_SetFilePath("\\"); nRet = g_cRoleSvc.Init(); #ifdef WIN32 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT); //_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); //_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); SetConsoleCtrlHandler(ConsoleHandlerRoutine, TRUE); #endif // WIN32 // the signal only has effect on Linux, windows just define it, do noting signal(SIGTERM, _SignalHandler); // when terminal by kill, call OnQuitSignal signal(SIGINT, _SignalHandler); // when Ctrl+C, call OnQuitSignal if (nRet) { nRet = g_cRoleSvc.Start(); //g_cRoleSvc.TestCase_Functionality(); } g_cRoleSvc.Uninit(); QLogPrintf(LOG_INFO, "RoleServer Closed."); if (nLogInitFlag) QLogUnInit(NULL); return nRet ? 0 : 1; }