本文整理汇总了C++中StateManager::addState方法的典型用法代码示例。如果您正苦于以下问题:C++ StateManager::addState方法的具体用法?C++ StateManager::addState怎么用?C++ StateManager::addState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateManager
的用法示例。
在下文中一共展示了StateManager::addState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
{
// Something went very wrong in initialisation, all we can do is exit
Utility::log(Utility::E,"Whoops! Something went very wrong, cannot initialise SDL");
return -1;
}
TTF_Init();
Mix_Init(MIX_INIT_OGG | MIX_INIT_MP3);
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
{
Utility::log(Utility::E, "SDL_mixer init failed: " + std::string(Mix_GetError()));
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
int winPosX = SDL_WINDOWPOS_CENTERED;
int winPosY = SDL_WINDOWPOS_CENTERED;
int winWidth = 640;
int winHeight = 480;
SDL_Window *window = SDL_CreateWindow("PGG Assignment 2 by Richard Hancock", // The first parameter is the window title
winPosX, winPosY,
winWidth, winHeight,
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
// Call our initialisation function to set up GLEW and print out some GL info to console
if (!InitGL())
{
return -1;
}
unsigned int lastTime = SDL_GetTicks();
glEnable(GL_DEPTH_TEST);
Utility::randomInit();
//Create the Resource manager that loads resources
ResourceManager* resourceManager = new ResourceManager(renderer);
StateManager* manager = new StateManager(winWidth, winHeight);
manager->addState(new PlayState(manager, resourceManager));
bool go = true;
while (go)
{
unsigned int current = SDL_GetTicks();
float deltaTs = (float)(current - lastTime) / 1000.0f;
// Now that we've done this we can use the current time as the next frame's previous time
lastTime = current;
//Event Handling
go = manager->eventHandler();
//Update
Utility::Timer::update(deltaTs);
manager->update(deltaTs);
// Draw our world
//
// Specify the colour to clear the framebuffer to
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// This writes the above colour to the colour part of the framebuffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
manager->render();
// This tells the renderer to actually show its contents to the screen
// We'll get into this sort of thing at a later date - or just look up 'double buffering' if you're impatient :P
SDL_GL_SwapWindow(window);
// Limiter in case we're running really quick
if (deltaTs < (1.0f / 50.0f)) // not sure how accurate the SDL_Delay function is..
{
SDL_Delay((unsigned int)(((1.0f / 50.0f) - deltaTs)*1000.0f));
}
}
// If we get outside the main game loop, it means our user has requested we exit
manager->popLastState();
//.........这里部分代码省略.........