Example #1
0
Manager::Manager( const char* name, int width, int height, Engine::WindowMode wm ):
RTTI_CLASS_DEFINE( Manager ),
m_engine( 0 ),
m_game( 0 ),
m_pushState( 0 ),
m_progressState( 0 ),
m_progressStateDefault( 0 ),
m_popState( false ),
m_changeState( false ),
m_loading( false ),
m_states( 0 ),
m_scenes( 0 ),
m_materials( 0 ),
m_effects( 0 ),
m_fonts( 0 ),
m_textures( 0 ),
m_canvases( 0 ),
m_assets( 0 ),
m_assetsLoading( 0 ),
m_actors( 0 ),
m_controls( 0 ),
m_collisions( 0 ),
m_audio( 0 )
{
	m_engine = xnew Engine();
	m_engine->initiation( name, width, height, wm );
	m_states = xnew Stack< IState >();
	m_scenes = xnew SceneManager();
	m_materials = xnew MaterialManager();
	m_effects = xnew EffectManager();
	m_fonts = xnew FontManager();
	m_textures = xnew TextureManager();
	m_canvases = xnew CanvasManager();
	m_assets = xnew AssetManager();
	m_assetsLoading = xnew AssetManager();
	m_actors = xnew Stack< ActorManager >();
	m_controls = xnew Stack< ControlManager >();
	m_collisions = xnew Stack< CollisionManager >();
	m_audio = xnew AudioManager();

	Global::use().engine = m_engine;
	Global::use().scenes = m_scenes;
	Global::use().materials = m_materials;
	Global::use().effects = m_effects;
	Global::use().fonts = m_fonts;
	Global::use().textures = m_textures;
	Global::use().canvases = m_canvases;
	Global::use().assets = m_assets;
	Global::use().assetsLoading = m_assetsLoading;
	Global::use().actors = 0;
	Global::use().controls = 0;
	Global::use().collisions = 0;
	Global::use().audio = m_audio;
}
Example #2
0
int CALLBACK WinMain(
	  _In_ HINSTANCE hInstance,
	  _In_ HINSTANCE hPrevInstance,
	  _In_ LPSTR     lpCmdLine,
	  _In_ int       nCmdShow)
{
	int flags = 0;

	dfDeltaTime = 43.f;
	
	ScreenResolution.x = 800.f;
	ScreenResolution.y = 600.f;
	
	GameResolution.x = 640.f;
	GameResolution.y = 480.f;
	
	if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
	{
		printf( "Video initialization failed: %s\n",
			 SDL_GetError( ) );
		GameExit( 1 );
	}

	if( SDL_Init( SDL_INIT_JOYSTICK ) < 0 )
	{
		printf( "Input initialization failed: %s\n",
			 SDL_GetError( ) );
		GameExit( 1 );
	}

	if( SDL_Init( SDL_INIT_GAMECONTROLLER ) < 0 )
	{
		printf( "Input initialization failed: %s\n",
			 SDL_GetError( ) );
		GameExit( 1 );
	}

	if( SDL_Init( SDL_INIT_AUDIO ) < 0 )
	{
		printf( "Audio initialization failed: %s\n",
			 SDL_GetError( ) );
		GameExit( 1 );
	}

	//Initialize SDL_mixer
    if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
    {
        printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
        GameExit( 1 );
    }

	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	//flags = SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL;
	flags =  SDL_WINDOW_OPENGL;

	RenderSystem::window = SDL_CreateWindow("Dufresne",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		ScreenResolution.x, ScreenResolution.y, flags);

	flags = IMG_INIT_JPG | IMG_INIT_PNG;
	int initted = IMG_Init(flags);
	if(initted & flags != flags) 
	{
		printf("Failed to Init SDL Image\n");
		printf("IMG_Init: %s\n", IMG_GetError());
		GameExit( 1 );
		// handle error
	}

	// init gl
	SDL_GLContext glcontext;
    glcontext = SDL_GL_CreateContext(RenderSystem::window);
	GLint GlewInitResult = glewInit();
	if (GlewInitResult != GLEW_OK) 
	{
		printf("ERROR: %s\n",glewGetErrorString(GlewInitResult));
		GameExit( 1 );
	}
	glEnable(GL_TEXTURE_2D);

	tinyjson_init();

	InitEngine();
		
	assMan = AssetManager();
	std::wstring path = L"fart\\";
	assMan.CalculateLoosePackageSize(path);
	assMan.LoadLoosePackage(path);
	assMan.DebugTestWritePoolToFile();
	
	sfxMan = SoundSystem();
	sfxMan.Init();

	sceneMan.Init();

	input = Input();
	input.Init();
	
	dfScene* scene1 = sceneMan.CreateScene("scene-left");
	dfScene* scene2 = sceneMan.CreateScene("scene-right");
	scene1->setupFunc = &SetupScene1;
	scene2->setupFunc = &SetupScene2;
	
	sceneMan.LoadScene(scene1);

	Uint32 previousMiliseconds = 0;
	
	while(true)
	{
		Uint32 currentMiliseconds = SDL_GetTicks(); 
		dfRandomFloat = dfRand();
		dfTotalTime = currentMiliseconds / 1000.f;
		dfDeltaTime = (currentMiliseconds / 1000.f) - (previousMiliseconds / 1000.f);

		if(testDude->tf.rectangle.left > GameResolution.x)
		{
			sceneMan.LoadScene(scene2);
		}
		if(testDude->tf.rectangle.right < 0)
		{
			sceneMan.LoadScene(scene1);
		}

		if(input.keyboard.n1.tapped)
		{
			sceneMan.renderer.UpdateResolution(640, 480);
		}
		if(input.keyboard.n2.tapped)
		{
			sceneMan.renderer.UpdateResolution(300, 300);
		}
		if(input.keyboard.n3.tapped)
		{
			sceneMan.renderer.UpdateResolution(450, 300);
		}

		input.Update();

		sceneMan.Update();

		SDL_GL_SwapWindow(RenderSystem::window);
	}


	return 0;

}
 LuaGameState::LuaGameState(const std::shared_ptr<const TMX>& pTMX, const std::shared_ptr<Shader>& pShader, const glm::mat4& model)
     : LuaGameState(pTMX, pShader, model, AssetManager(pTMX))
 {}