コード例 #1
0
int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)	
{
	//+++++++++++++++++++++++++++++ VARIABLE DECLARATIONS+++++++++++++++++++++++++++++++++++++++++++++++++++
	
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    //++++++++++++++++++++++++++++++++++++++ CODE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//Leak detections
	//Static detections FROM: http://cgempire.com/forum/tutorials-101/easy-memory-leak-detection-c-c-546.html
	FINDMEMLEAK(-1);

	//Game (edit mode false)!!!
	GameApp MyGame(false);

	//Nested in try-catch, when exception... well, show it to user and finish
	try
	{
		//Store app working path to generate relative paths from there
		g_ConfigOptions.SetupWorkingPath();
		MyGame.Load();  //Init
		MyGame.Run();   //Game loop
	}
	catch(std::exception &e)
	{
		//Show exception message
		::MessageBoxA( NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
	}

	return 0;
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}
コード例 #2
0
int IndieLib() {
#ifdef PLATFORM_WIN32
	//memory leaks for win32 creation
	FINDMEMLEAK(-1);    //When you find a mem. leak, refer to the number displayed in the console and put it here to break when it is created
#endif
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;
    
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
    // ----- Fcn pointer tests initialization -----
	initTests();

	testsvectoriterator itr;
    //LOOP - Prepare Permanent tests
	for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) {
		(*itr)->prepareTests();
	}//LOOP END

    //LOOP - Prepare Temporary tests
	for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) {
		(*itr)->prepareTests();
	}//LOOP END

	// ----- Main Loop -----
	g_mainTimer.start();
	double ticks = g_mainTimer.getTicks();
	double pastticks = g_mainTimer.getTicks();
    testsvectoriterator currentTest = g_tests.begin();
    (*currentTest)->setActive(true);

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) {
		// ----- Input Update ----

		mI->_input->update();

		// -------- Render -------
        mI->_render->clearViewPort(0,0,0);
		mI->_render->beginScene();
		//LOOP - Permanent Tests
		for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) {
			(*itr)->performTests(static_cast<float>(ticks - pastticks));
		}//LOOP END

		//LOOP - Tests
		for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) {
			(*itr)->performTests(static_cast<float>(ticks - pastticks));
		}//LOOP END

		mI->_entity2dManager->renderEntities2d();   //Entities rendering
		mI->_entity2dManager->renderGridAreas(g_gridcolorR,g_gridcolorG,g_gridcolorB,g_gridcolorA); //Grid areas rendering (on top of it) can be disabled per entity
		mI->_entity2dManager->renderCollisionAreas(g_collisionColorR,g_collisionColorG,g_collisionColorB,g_collisionColorA);  //Collision areas rendering (on top of it) can be disabled per entity
		mI->_render->endScene();
		//mI->_render->showFpsInWindowTitle();

		pastticks = ticks;
		ticks += g_mainTimer.getTicks();

        //Perform next test setup (if needed) Arrow keys change current temporary test using
        if (mI->_input->onKeyPress(IND_KEYRIGHT) && !mI->_input->onKeyPress(IND_KEYLEFT)){
            //Current test is not active
            (*currentTest)->setActive(false);
            currentTest++;
            
            //IF - Check limits
            if(currentTest == g_tests.end()){
                currentTest = g_tests.begin();
            }
            
            //Next test is active
            (*currentTest)->setActive(true);
        } else if (mI->_input->onKeyPress(IND_KEYLEFT) && !mI->_input->onKeyPress(IND_KEYRIGHT)){
            //Current test is not active
            (*currentTest)->setActive(false);
          
            //Decrement (taking into account limits)
            if(currentTest == g_tests.begin()){
                currentTest = g_tests.end();
            }
            currentTest--;
            
            //Next test is active
            (*currentTest)->setActive(true);
        }
            

	}

	// ----- Indielib End -----

    releaseTests();

    mI->end();
	return 0;
}