void engineRun() { engine.running = true; engine.frame = 0; while (engine.running) { // Check events since the last frame SDL_Event event; while (SDL_PollEvent(&event)) { // Handle event if (event.type == SDL_QUIT) { engine.running = false; } else if (guiHandleEvent(&event)) {} else if (mapHandleEvent(&event)) {} } if (engine.frame % 8 == 0) { physStep(); } gfxRender(); engine.frame++; } }
int main( int argc, char *argv[] ) { GLFWwindow *window; int Edit; //File name to load string fileName; //whether name inputtted is valid bool validFile = false; //Try to determine file input while(validFile == false) { printf("Type the file to load (Special options: 'd' = default, 'c' = clean):\n"); scanf("%s", &fileName[0]); ifstream toLoad(&fileName[0]); validFile = toLoad.good(); //If 'c' was entered, then load a clean level if(strcmp(&fileName[0], "c") == 0) { printf("Loading clean level...\n"); fileName = "clean"; validFile = true; } //If 'd' was entered, then deafult level else if(strcmp(&fileName[0], "d") == 0) { printf("Loading default level...\n"); fileName = "default"; validFile = true; } else if(validFile == false) { printf("Bad file, please type another file to load.\n"); } else if(validFile == true) { toLoad.close(); } } //Determine mode printf("Type 0 to play, any other int to edit\n"); scanf("%i", &Edit); glfwSetErrorCallback(glfwError); if (!glfwInit()) { exit(EXIT_FAILURE); } //If Edit Mode if(Edit) { //World Edit Init //initWorldEdit(window); window = glfwCreateWindow(800, 800, "World Editor", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } srand(time(0)); glfwMakeContextCurrent(window); glfwSetWindowPos(window, 80, 80); glfwSetWindowSizeCallback(window, glfwWindowResize); glfwSetWindowSize(window,1600,800); g_height =800; g_width = 1600; setDistance(7); SetEdit(1); paused = false; glfwSetKeyCallback( window, glfwEditKeyPress); glfwSetCursorPosCallback( window, glfwEditGetCursorPos ); glfwSetMouseButtonCallback( window, glfwEditMouse ); glfwSetScrollCallback( window, glfwEditScroll ); glewInit(); glInitialize(window); physicsInit(); InitGeom(); initLevelLoader(); loadLevel(fileName); } //If Play Mode else { //Game Play Init //initGamePlay(window); window = glfwCreateWindow(800, 800, "Grapple", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } srand(time(0)); SetEye(vec3(0, 0, 0)); glfwMakeContextCurrent(window); glfwSetWindowPos(window, 80, 80); glfwSetWindowSizeCallback(window, glfwWindowResize); glfwSetWindowSize(window,1600,800); g_height =800; g_width = 1600; setDistance(10); paused = false; glfwSetKeyCallback(window, glfwGameKeyPress); glfwSetCursorPosCallback( window, glfwGameGetCursorPos ); glewInit(); glInitialize(window); physicsInit(); InitGeom(); initLevelLoader(); loadLevel(fileName); } ShadowMap *shadowMap = new ShadowMap(); if (shadowMap->MakeShadowMap(g_width, g_height) == -1) { printf("SHADOW MAP FAILED\n"); exit(EXIT_FAILURE); } // Start the main execution loop. while (!glfwWindowShouldClose(window)) { glfwPollEvents(); if(Edit) { if(paused == false) { //Keep the cursor centered glfwSetCursorPos(window,g_width/2,g_height/2); renderScene(window, shadowMap); glfwEditGetCursorPos(NULL,g_width/2.0,g_height/2.0); //glfw Game Keyboard glfwEditKeyboard(); } } else { if(paused == false) { //player appy physics controls SetLookAt(glm::vec3(physGetPlayerX(),physGetPlayerY(),physGetPlayerZ())); SetSpeed(.05*magnitude(getPlayerSpeed())); //Keep the cursor centered glfwSetCursorPos(window,g_width/2,g_height/2); physStep(); //Draw stuff renderScene(window, shadowMap); glfwGameGetCursorPos(NULL,g_width/2.0,g_height/2.0); //glfw Game Keyboard glfwGameKeyboard(); } } usleep(15000); } // Clean up after GLFW. glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); }