void draw_init(int draw_flags) { flags = draw_flags; makeShuffledList(imageFuncList, NUM_IMAGE_FUNCTIONS); #ifdef ENABLE_THREADS abort_draw = 0; quit_draw = 0; if (!(draw_mtx = SDL_CreateMutex()) || !(drawdone_cond = SDL_CreateCond()) || !(drawnext_cond = SDL_CreateCond())) fatalSDLError("creating drawing synchronization primitives"); drawing_thread = SDL_CreateThread(drawing_main, #if SDL_VERSION_ATLEAST(2,0,0) "DrawingThread", #endif NULL); if (drawing_thread == NULL) fatalSDLError("creating drawing thread"); /* TODO check SDL errors */ #else /* !ENABLE_THREADS */ draw_first = 1; #endif /* !ENABLE_THREADS */ }
void GE161::Game::main(int x) { if (x != 8675309) { fatalSDLError("Do not invoke GE161::Game::main()"); return; } if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { fatalSDLError("SDL_Init(SDL_INIT_EVERYTHING) Error in main(): ", SDL_GetError()); return; } // Invoke the game's overridden setup() method, and create the SDL window. window_ = new GE161::Window(); /***********************************************************************/ // <Game-main.cpp> // initialize the world_ // otherwise we cannot operate the operations like ObjectMap of World Class world_ = new GE161::World(); setup(); window_->initialize(); window_->clearBackground(); //theGame->BackgroundColor(window_, 0, 0, 0); eventQueue_ = new GE161::EventQueue(); std::string sceneName = GE161::Game::START_GAME; //int returnCode = code; // Loop through the outer while loop once per scene. // A negative return code from a scene says "Stop the program!" // <Game-main.cpp> // Outer Loop per scene while (code >= 0) { // Ask the game which scene to do next. sceneName = GE161::Game::theGame->chooseScene(sceneName, code); GE161::EventListener* scene = GE161::Game::theGame->lookUpScene(sceneName); // Now we have the scene to use. First, run its setup(). // because of the void setup() // I need to distinguish the setup() success from instruction and Gameplay scene->setup(); bool success; if (sceneName == "Instructions") { success = theGame->setupSuccess; } else if (sceneName == "GamePlay") { success = theGame->setupGameSuccess; } if (!success) { fatalSDLError("error in main(), setup failed for scene", sceneName); return; } // setup() succeeded. Run its draw() until a non-zero return code. code = GE161::Game::CONTINUE_SCENE; // I have changed the inner loop to world_ class theGame->world_->gameLoop(code, scene); std::string m = std::string("return code from ") + sceneName + std::string(": ") + std::to_string(code); debugOut(m); } SDL_Quit(); return; }