Example #1
0
bool gkSystem::Init( ISystemInitInfo& sii )
{
	gkLogMessage(_T("Initializing gkSystem..."));
    
    std::vector<gkStdString> result;

	gkStdString path;

#ifdef OS_IOS
    path = gkGetExecRootDir();
#else
	path = gkGetExecRootDir() + _T("paks/");
#endif

	enum_all_files_in_folder(path.c_str(), result, false);

    for (int i=0; i < result.size(); ++i) {

		gkStdString file = result[i];

		const TCHAR* strLastSlash = _tcsrchr( file.c_str(), _T( '.' ) );
		if( strLastSlash )
		{
			if ( !_tcsicmp( strLastSlash, _T(".gpk") ) )
			{
				gkNormalizePath(file);
				gkStdString filename = gkGetFilename( file.c_str() );

#ifdef OS_IOS
				
#else
				file = _T("/paks") + file;
#endif

				gkLogMessage( _T("pak file [%s] loaded."), filename.c_str() );
				m_ResFileManager.openPak( file.c_str() );
			}
		}
    }
    
    

#ifdef OS_WIN32
	m_fileMonitor = new FileChangeMonitor();
	m_fileMonitor->StartMonitor();
	gEnv->pFileChangeMonitor = m_fileMonitor;
#endif
	m_bEditor = (sii.hInstance != 0);

	//CrashRptHead();

	m_bIsSceneEmpty = true;

	/************************************************************************/
	/* Module Loading
	/************************************************************************/
#ifdef WIN32
	TCHAR wszRenderDll[MAX_PATH] = _T("gkRendererD3D9");

	if (!IsEditor())
	{
		gkStdString cfgfile = gkGetExecRootDir() + _T("media/config/startup.cfg");
		GetPrivateProfileString( _T("launcher"), _T("renderer"), _T("gkRendererD3D9"), wszRenderDll, MAX_PATH, cfgfile.c_str() );
	}
#else 
	TCHAR wszRenderDll[MAX_PATH] = _T("gkRendererGLES2");
#endif

#ifndef _STATIC_LIB
	if ( !_tcsicmp( wszRenderDll, _T("gkRendererD3D9") ))
	{
		LOAD_MODULE_GLOBAL( m_moduleHandles.hRenderer, gkRendererD3D9 );
	}
	else if (  !_tcsicmp( wszRenderDll, _T("gkRendererGLES2") ) )
	{
		LOAD_MODULE_GLOBAL( m_moduleHandles.hRenderer, gkRendererGLES2 );
	}
	else if (  !_tcsicmp( wszRenderDll, _T("gkRendererGL330") ) )
	{
		LOAD_MODULE_GLOBAL( m_moduleHandles.hRenderer, gkRendererGL330 );
	}
#else
	//LOAD_MODULE_GLOBAL( m_moduleHandles.hRenderer, gkRendererGLES2 );
#ifdef OS_APPLE
    LOAD_MODULE_GLOBAL( m_moduleHandles.hRenderer, gkRendererGL330 );
#elif defined( OS_IOS )
    LOAD_MODULE_GLOBAL( m_moduleHandles.hRenderer, gkRendererGLES2 );
#else
	LOAD_MODULE_GLOBAL( m_moduleHandles.hRenderer, gkRendererD3D9 );
#endif
    
#endif
	

	LOAD_MODULE_GLOBAL(m_moduleHandles.h3DEngine, gkCore);
	gEnv->p3DEngine->Init();


	LOAD_MODULE_GLOBAL(m_moduleHandles.hInputLayer, gkInput);

	//LoadLib(m_moduleHandles.hNetworkLayer,		_T("gkNetwork"));


	//////////////////////////////////////////////////////////////////////////
	// load physics module
#ifndef MUTE_PHYSICS
#	ifdef WIN32
	TCHAR wszPhysicDll[MAX_PATH] = _T("");

	gkStdString cfgfile = gkGetExecRootDir() + _T("media/config/startup.cfg");
	GetPrivateProfileString( _T("launcher"), _T("physicsengine"), _T(""), wszPhysicDll, MAX_PATH, cfgfile.c_str() );
#	else 
	TCHAR wszPhysicDll[MAX_PATH] = _T("gkHavok");
#	endif // WIN32

#	ifndef _STATIC_LIB
	gkLoadModule( m_moduleHandles.hPhysics, wszPhysicDll );
#	else
	//LOAD_MODULE_GLOBAL( m_moduleHandles.hPhysics, gkHavok );
#	endif // _STATIC_LIB

#endif // MUTE_PHYSICS    
	//////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////
	// load animation module
	{
#	ifdef WIN32
		TCHAR wszAnimationDll[MAX_PATH] = _T("gkAnimationHavok");

		gkStdString cfgfile = gkGetExecRootDir() + _T("media/config/startup.cfg");
		GetPrivateProfileString( _T("launcher"), _T("animationengine"), _T("gkAnimationHavok"), wszAnimationDll, MAX_PATH, cfgfile.c_str() );
#	else 
		TCHAR wszAnimationDll[MAX_PATH] = _T("gkAnimationHavok");
#	endif // WIN32

#ifdef OS_APPLE
        
#else
#	ifndef _STATIC_LIB
		gkLoadModule( m_moduleHandles.hAnimation, wszAnimationDll );
#	else
        #if TARGET_OS_IPHONE
        LOAD_MODULE_GLOBAL( m_moduleHandles.hAnimation,				gkAnimation );
        #endif
#	endif // _STATIC_LIB
#endif
    
    }
	//////////////////////////////////////////////////////////////////////////

	LOAD_MODULE_GLOBAL(m_moduleHandles.hGameObjectSystem,			gkGameObjectSystem);

	LOAD_MODULE_GLOBAL(m_moduleHandles.hFont,						gkFont);

#ifdef OS_WIN32
	LOAD_MODULE_GLOBAL(m_moduleHandles.hTrackBus,					gkTrackBus);

	LOAD_MODULE_GLOBAL(m_moduleHandles.hSound,						gkSound);

	//LOAD_MODULE_GLOBAL(m_moduleHandles.hVideo,						gkVideo);

	//LOAD_MODULE_GLOBAL(m_moduleHandles.hStereoDevice,				gkStereoDevice);

	{
		TCHAR wszStereoDevDll[MAX_PATH] = _T("null");
		gkStdString cfgfile = gkGetExecRootDir() + _T("media/config/startup.cfg");
		GetPrivateProfileString( _T("launcher"), _T("stereodevice"), _T("null"), wszStereoDevDll, MAX_PATH, cfgfile.c_str() );

		gkLoadModule( m_moduleHandles.hStereoDevice, wszStereoDevDll );
	}


#endif
    
	m_CVManager.initInput();
	gkLogMessage(_T("CVar Manager Initialized."));

	m_pSystemCVars = new gkSystemCVars;
	g_pSystemCVars = m_pSystemCVars;
	gkLogMessage(_T("System CVar Initialized."));

	m_CVManager.reloadAllParameters();

	// init Timer
	if (!m_Timer.Init(this))
		return (false);
	m_Timer.ResetTimer();

	gkLogMessage(_T("Timer Initialized."));


	gkIniParser startupFile( _T("config/startup.cfg") );
	startupFile.Parse();
	gkStdString ret = startupFile.FetchValue(  _T("launcher"), _T("width") );
	if( !ret.empty() )
	{
		gkStdStringstream ss(ret);
		ss >> sii.fWidth;
	}
Example #2
0
/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(struct android_app* app)
{
    // Make sure glue isn't stripped.
    app_dummy();

// 	NvEGLUtil* egl = NvEGLUtil::create();
//     if (!egl) 
//     {
//         // if we have a basic EGL failure, we need to exit immediately; nothing else we can do
//         nv_app_force_quit_no_cleanup(app);
//         return;
//     }

	void* gHandle;
	LOAD_MODULE_GLOBAL( gHandle, gkGameFramework );

	//= dlopen("/data/data/com.kkstudio.gklauncher/lib/libgkGameFrame.so", RTLD_LAZY |RTLD_GLOBAL );
	OsDisplayDebugString( "libloaded..." );
	if(gHandle)
	{ 
		STARTFUNC moduleInitialize = (STARTFUNC)(DLL_GETSYM(gHandle, "gkModuleInitialize"));
		if( moduleInitialize )
		{
			gGameFramework = moduleInitialize();
		}
		else
		{
			return;
		}
	}
	else
	{
		OsDisplayDebugString( "gkFramework not find..." );
	}

	OsDisplayDebugString( "system initialized..." );

    //Engine* engine = new Engine(*egl, app);

	//long lastTime = egl->getSystemTime();

    // loop waiting for stuff to do.

	OsDisplayDebugString( "system initialized..." );
	// Setup our android state
	//state->userData = &init;

	app->onAppCmd = handle_cmd;
	app->onInputEvent = handle_input;

	while (nv_app_status_running(app))
    {
        // Read all pending events.
        int ident;
        int events;
        struct android_poll_source* source;

        // If not rendering, we will block 250ms waiting for events.
        // If animating, we loop until all events are read, then continue
        // to draw the next frame of animation.
        while ((ident = ALooper_pollAll(((nv_app_status_focused(app)/* && engine->isGameplayMode()*/) ? 1 : 250),
        								NULL,
        								&events,
        								(void**)&source)) >= 0)
        {
            // Process this event. 
            if (source != NULL)
                source->process(app, source);

            // Check if we are exiting.  If so, dump out
            if (!nv_app_status_running(app))
				break;
        }

		if (gIntialized)
		{
			gGameFramework->Update();
		}

		if (exit_req)
		{
			break;
		}

// 		long currentTime = egl->getSystemTime();
// 
// 		// clamp time - it must not go backwards, and we don't
// 		// want it to be more than a half second to avoid huge
// 		// delays causing issues.  Note that we do not clamp to above
// 		// zero because some tools will give us zero delta
// 		long deltaTime = currentTime - lastTime;
// 		if (deltaTime < 0)
// 			deltaTime = 0;
// 		else if (deltaTime > 500)
// 			deltaTime = 500;
// 
// 		lastTime = currentTime;

		// Update the frame, which optionally updates time and animations
		// and renders
		//engine->updateFrame(nv_app_status_interactable(app), deltaTime);
    }

	//delete engine;
    //delete egl;
}
Example #3
0
/*!***************************************************************************
@function		android_main
@input			state	the android app state
@description	Main function of the program
*****************************************************************************/
void android_main(struct android_app* state)
{
	 // Make sure glue isn't stripped.
    app_dummy();

	OsDisplayDebugString( "coming..." );

	// check the tf card dog.
	//system(  );

	

    // Initialise the demo, process the command line, create the OS initialiser.

	void* gHandle;
	LOAD_MODULE_GLOBAL( gHandle, gkGameFramework );
	
	//= dlopen("/data/data/com.kkstudio.gklauncher/lib/libgkGameFrame.so", RTLD_LAZY |RTLD_GLOBAL );
	OsDisplayDebugString( "libloaded..." );
	if(gHandle)
	{ 
		STARTFUNC moduleInitialize = (STARTFUNC)(DLL_GETSYM(gHandle, "gkModuleInitialize"));
		if( moduleInitialize )
		{
			gGameFramework = moduleInitialize();
		}
		else
		{
			return;
		}
	}

	OsDisplayDebugString( "system initialized..." );
	// Setup our android state
	//state->userData = &init;

	state->onAppCmd = handle_cmd;
	state->onInputEvent = handle_input;
	
	//init.m_pAndroidState = state;
	//g_AssetManager = state->activity->assetManager;

	// Handle our events until we have a valid window or destroy has been requested
	int ident;
	int events;
    struct android_poll_source* source;

	//	Initialise our window/run/shutdown
	for(;;)
	{
		while ((ident = ALooper_pollAll(/*(init.m_eState == ePVRShellRender && init.m_bRendering) ? 0 : -1*/ 0, NULL, &events, (void**)&source)) >= 0)
		{
			// Process this event.
			if (source != NULL)
			{
				source->process(state, source);
			}

			// Check if we are exiting.
			if (state->destroyRequested != 0)
			{
				return;
			}
		}

		// Render our scene
// 		if(!init.Run())
// 		{
// 			ANativeActivity_finish(state->activity);
// 			break;
// 		}
		if (gIntialized)
		{
			gGameFramework->Update();
		}
		
// 		if( gGameFramework->Update() )
// 		{
// 			gGameFramework->PostUpdate();
// 		}
		
	}
}