#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; /** * Some defines and settings * Tweak NUM_SECTIONS to get more/less amount of sections in the level (which means a longer/shorter level) */ //#define WINDOW_WIDTH (1920) //#define WINDOW_HEIGHT (1080) // 1080 //#define SECTION_WIDTH (8100) //#define NUM_SECTIONS (3) //#define LEVEL_WIDTH (SECTION_WIDTH * NUM_SECTIONS) ////////////////////////////////////////////////////////////////////////// /** * Function declarations * Earlier, some functions were declared inside one of the structures below, don't do that */ SDL_Texture* CreateTexture(const std::string& rPath); bool QuadVsQuad(const SDL_Rect& rQuad1, const SDL_Rect& rQuad2); float Interpolate(const float Start, const float End, const float Fraction); bool InitializeSDL(void); void DeinitializeSDL(void); bool Create(void); void Destroy(void); void HandleEvents(void); void Update(void); void Render(void); void Logger(string); bool checkFileProcess(); bool checkFileSDL(); bool checkFileReady(); int WindowWidth = 0; int WindowHeight = 0; int sectionWidth = 0; int numSection = 0; int levelWidth = 0; int balanceWidth = 0; int oddEvenRow = 0; int indexHeight = 0; int WindowStartPosInSecondScreen = 0; int WindowsStartYposInSecondScreen = 0; std::string fileName; int startFlag = 0; int delayTimer = 0; DWORD m_dwIP = 0; int cameraStartPosition = 0; ////////////////////////////////////////////////////////////////////////// // The different states the player can be in enum EPlayerState { PLAYER_STILL = 0, PLAYER_MOVING_LEFT, PLAYER_MOVING_RIGHT, NUM_PLAYER_STATES }; // The different states the camera can be in enum ECameraState { CAMERA_STILL = 0, CAMERA_SCROLLING_LEFT, CAMERA_SCROLLING_RIGHT, NUM_CAMERA_STATES }; /** * Just a simple way of collection the player's different variables * Tweak Velocity to get a faster/slower walking speed */ struct SPlayer { float Width = 0.0f; float Height = 0.0f; float XPosition = 0;// (WINDOW_WIDTH * 0.5f) - (Width * 0.5f); float PrevXPosition = XPosition; float Velocity = 0.0f; EPlayerState State = PLAYER_STILL; }; /** * Just a simple way of collection the camera's different variables * Tweak Velocity to get a faster/slower camera scrolling speed */ struct SCamera { float XPosition = 0.0f;//0.0//2250//2000 float PrevXPosition = XPosition; float Velocity = 0.0f; ECameraState State = CAMERA_STILL; SDL_Rect Quad; }; // Just a simple way of collection a texture's different variables struct STexture { SDL_Texture* pTexture = nullptr; SDL_Rect Quad; }; SDL_Window* pWindow = nullptr; SDL_Renderer* pRenderer = nullptr; SDL_Event Event; double DeltaTime = 0.0; double OldTime = 0.0; double NewTime = 0.0; // How near the player has to be the left- or right side of the window for the camera scrolling to start float DistanceToWindowEdge = 0.0f;//70 static bool Running = true; // And here we actually use the structures declared above SPlayer Player; SCamera Camera; STexture *BackgroundTexture; ////////////////////////////////////////////////////////////////////////// SDL_Texture* CreateTexture(const std::string& rPath) { SDL_Surface* pSurface = IMG_Load(rPath.c_str()); if (!pSurface) { std::cout << "Failed to create SDL surface. " << IMG_GetError() << std::endl; Logger("Failed to create SDL surface."); return nullptr; } else { Logger("Success to create SDL surface."); } SDL_Texture* pTexture = SDL_CreateTextureFromSurface(pRenderer, pSurface); SDL_FreeSurface(pSurface); pSurface = nullptr; if (!pTexture) { std::cout << "Failed to create SDL texture. " << SDL_GetError() << std::endl; Logger("Failed to create SDL texture."); return nullptr; } else { Logger("Success to create SDL texture."); } return pTexture; } bool QuadVsQuad(const SDL_Rect& rQuad1, const SDL_Rect& rQuad2) { // Quad vs quad intersection test if (rQuad1.x < rQuad2.x + rQuad2.w && rQuad1.x + rQuad1.w > rQuad2.x && rQuad1.y < rQuad2.y + rQuad2.h && rQuad1.y + rQuad1.h > rQuad2.y) return true; else return false; } bool InitializeSDL() { // Initialize SDL if (SDL_Init(SDL_INIT_EVERYTHING) < 0) // SDL_INIT_EVERYTHING { std::cout << "Failed to initialize SDL. " << SDL_GetError() << std::endl; Logger("Failed to initialize SDL"); return false; } else Logger("Success to initialize SDL."); // Initialize SDL_Image if (IMG_Init(IMG_INIT_TIF) == 0) { std::cout << "Failed to initialize SDL_Image. " << IMG_GetError() << std::endl; Logger("Failed to initialize SDL_Image."); return false; } else Logger("Success to initialize SDL_Image."); // Set render scale quality if (SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1") == SDL_FALSE) { std::cout << "Failed to set the render scale quality. " << SDL_GetError() << std::endl; Logger("Failed to set the render scale quality."); } else Logger("Success to set the render scale quality."); // Create the SDL window //pWindow = SDL_CreateWindow("IMGprocessor", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WindowWidth/1.5, WindowHeight/1.5, SDL_WINDOW_SHOWN);//SDL_WINDOW_FULLSCREEN_DESKTOP // SDL_WINDOW_SHOWN //SDL_WINDOW_BORDERLESS pWindow = SDL_CreateWindow("IMGprocessor", WindowStartPosInSecondScreen, WindowsStartYposInSecondScreen, WindowWidth, WindowHeight, SDL_WINDOW_BORDERLESS);//SDL_WINDOW_FULLSCREEN_DESKTOP // SDL_WINDOW_SHOWN // SDL_WINDOW_FULLSCREEN if (!pWindow) { std::cout << "Failed to create the SDL window. " << SDL_GetError() << std::endl; Logger("Failed to create the SDL window."); return false; } else Logger("Success to create the SDL window."); // Create the SDL renderer pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);//SDL_RENDERER_ACCELERATED//SDL_RENDERER_PRESENTVSYNC if (!pRenderer) { std::cout << "Failed to create the SDL renderer. " << SDL_GetError() << std::endl; Logger("Failed to create the SDL renderer."); return false; } else Logger("Success to create the SDL renderer."); // Initialize the render draw color if (SDL_SetRenderDrawColor(pRenderer, 0, 0, 0, 0xFF) == -1) // 0xFF { std::cout << "Failed to set the SDL render draw color. " << SDL_GetError() << std::endl; Logger("Failed to set the SDL render draw color."); } else Logger("Success to set the SDL render draw color."); return true; } void DeinitializeSDL() { if (pRenderer) { SDL_DestroyRenderer(pRenderer); pRenderer = nullptr; } if (pWindow) { SDL_DestroyWindow(pWindow); pWindow = nullptr; } IMG_Quit(); SDL_Quit(); } bool Create(void) { // The creation below can be made in a for loop, but I don't wanna cause confusion so I'll just do it the manual way const unsigned long maxDir = 260; char currentDir[maxDir]; GetCurrentDirectory(maxDir, currentDir); //cout << currentDir << endl; // Change the file path to work with your map structure for (int i = 0; i < numSection; i++) { char fileName[50] = "temp\\crop_"; string s = std::to_string(i); const char *cstr = s.c_str(); strcat_s(fileName, sizeof fileName, cstr); strcat_s(fileName, sizeof fileName, ".tif"); BackgroundTexture[i].pTexture = CreateTexture(fileName); } for (int i = 0; i < numSection; i++) { if (!BackgroundTexture[i].pTexture) { Logger("Image Loading failed in texture"); return false; } else Logger("Image Loading success in texture"); } int TextureWidth = 0; int TextureHeight = 0; SDL_QueryTexture(BackgroundTexture[0].pTexture, nullptr, nullptr, &TextureWidth, &TextureHeight); // Position each texture quad next to each other, will be used for culling later for (int i = 0; i < numSection; i++) { BackgroundTexture[i].Quad = { TextureWidth * i, 0, TextureWidth, TextureHeight }; } // Also used for culling later Camera.Quad = { 0, 0, WindowWidth, WindowHeight }; return true; } void Destroy(void) { for (int i = 0; i < numSection; ++i) { if (BackgroundTexture[i].pTexture) { SDL_DestroyTexture(BackgroundTexture[i].pTexture); BackgroundTexture[i].pTexture = nullptr; } } } void HandleEvents(void) { while (SDL_PollEvent(&Event)) { //Sleep(3000); if (Camera.State == CAMERA_STILL) { //if (startFlag == 0) //{ // //Sleep(delayTimer); // //Running = true; // //Player.State = PLAYER_MOVING_RIGHT; // //Sleep(delayTimer); // startFlag = 1; // break; //} //else if (startFlag == 1) //{ // Sleep(delayTimer); // Running = true; // Player.State = PLAYER_MOVING_RIGHT; // startFlag = 2; // break; //} /*if (checkFileSDL()) { string line; ifstream myfile("sdl.txt"); if (myfile.is_open()) { while (getline(myfile, line)) {} myfile.close(); } int readyFlag = atoi(line.c_str()); std::string out_string; std::stringstream ss; ss << readyFlag; out_string = ss.str(); Logger("SDL Value - " + out_string); if (readyFlag == 1) { Running = true; Player.State = PLAYER_MOVING_RIGHT; bool status = remove("sdl.txt"); if (status) Logger("sdl.txt file deleted."); else Logger("Unable to delete sdl.txt file."); break; } else { Running = false; break; } }*/ } if (startFlag == 0) { SDL_Delay(delayTimer-825); startFlag = 1; break; } if (startFlag == 1) { Player.State = PLAYER_MOVING_RIGHT; startFlag = 2; break; } switch (Event.type) { case SDL_KEYDOWN: { switch (Event.key.keysym.sym) { case SDLK_ESCAPE: { Running = false; Camera.State = CAMERA_STILL; break; } /*case SDLK_s: { Running = true; Player.State = PLAYER_MOVING_RIGHT; break; }*/ } } } } } void Update(void) { // Handle events from the keyboard //Sleep(delayTimer); HandleEvents(); // Calculate the deltatime NewTime = SDL_GetTicks(); DeltaTime = (NewTime - OldTime) / 1000.0; OldTime = NewTime; /*if (Camera.XPosition > levelWidth) { Camera.State = CAMERA_STILL; Logger("Finished Odd row Auto scrolling "); Running = false; return; }*/ //if (Camera.XPosition < (levelWidth - WindowWidth)) //{ // //Logger("Camera.XPosition < (levelWidth - WindowWidth)"); // Camera.State = CAMERA_SCROLLING_RIGHT; // Player.XPosition = (Camera.XPosition + sectionWidth) - Player.Width - DistanceToWindowEdge; // Player.PrevXPosition = Player.XPosition; //} //return; ////////////////////////////////////////////////////////////////////////// // Whenever the player is moving if (Player.State != PLAYER_STILL) { //Logger("Player.State != PLAYER_STILL "); // Just a fancy way of saying: "If the player state is set to PLAYER_MOVING_LEFT, move the player to the left. Else, move the player to the right" Player.XPosition += (Player.State == PLAYER_MOVING_LEFT ? -Player.Velocity : Player.Velocity) * (float)DeltaTime; // If the player has reached the left side of the window if (Player.XPosition <= (Camera.XPosition + DistanceToWindowEdge)) { if (Camera.XPosition > levelWidth) { Camera.State = CAMERA_STILL; Logger("Finished Odd row Auto scrolling "); /*if (!checkFileReady()) { std::ofstream out("ready.txt"); out << "0"; out.close(); } if (!checkFileSDL()) { std::ofstream outFile("sdl.txt"); outFile << "0"; outFile.close(); }*/ Running = false; return; } // The camera is only allowed to scroll to the left if it's not at the start of the level if (Camera.XPosition > 0.0f) { //Logger("Camera.XPosition > 0.0f"); //Player.State = PLAYER_STILL; Player.XPosition = Camera.XPosition + DistanceToWindowEdge; Player.PrevXPosition = Player.XPosition; } } // If the player has reached the right side of the window else if (Player.XPosition + Player.Width > (Camera.XPosition + WindowWidth) - DistanceToWindowEdge) { // The camera is only allowed to scroll to the right if it's not at the end of the level if (Camera.XPosition < (levelWidth - WindowWidth)) { //Logger("Camera.XPosition < (levelWidth - WindowWidth)"); Camera.State = CAMERA_SCROLLING_RIGHT; //Player.State = PLAYER_STILL; Player.XPosition = (Camera.XPosition + sectionWidth) - Player.Width - DistanceToWindowEdge; Player.PrevXPosition = Player.XPosition; } } // Make sure that the player can't go outside the left- and the right side of the level if (Player.XPosition < 0.0f) Player.XPosition = 0.0f; else if (Player.XPosition > levelWidth - Player.Width) Player.XPosition = levelWidth - Player.Width; } // Whenever the camera is scrolling if (Camera.State != CAMERA_STILL) { const bool ScrollingLeft = (Camera.State == CAMERA_SCROLLING_LEFT); //Logger("Camera.State != CAMERA_STILL"); /* By making the player walk a bit by itself during the scrolling, the player won't end up outside the window edges when the scrolling is finished The walking direction depends on the direction the camera is scrolling The walking speed is based on the camera's velocity - a bigger division value (in this case it's 0.25f) will make the player walk faster, which means the player will end up further away from the window edge when the scrolling is finished A smaller division value does the opposite Note: a value smaller than 0.22f will, with the current player width, cause an endless scrolling loop bug */ Player.XPosition += (ScrollingLeft ? -(Camera.Velocity * 0.25f) : (Camera.Velocity * 0.25f)) * (float)DeltaTime; ////////////////////////////////////////////////////////////////////////// // See the player movement code above for an explanation on how this works Camera.XPosition += ((ScrollingLeft ? -Camera.Velocity : Camera.Velocity) * (float)DeltaTime); // Check the distance between the camera's current- and previous position // The calculation result depends on the direction the camera is scrolling in const float Distance = (ScrollingLeft ? (Camera.PrevXPosition - Camera.XPosition) : (Camera.XPosition - Camera.PrevXPosition)); // If the camera has scrolled a full section width if (Distance >= sectionWidth) { //Logger("CDistance >= sectionWidthL"); // Calculate the camera's final position // Again, this calculation result depends on the direction the camera is scrolling in const float FinalCameraPosition = (ScrollingLeft ? (Camera.PrevXPosition - sectionWidth) : (Camera.PrevXPosition + sectionWidth)); Camera.XPosition = FinalCameraPosition; Camera.PrevXPosition = FinalCameraPosition; //Camera.State = CAMERA_STILL; } } if (Player.State != PLAYER_STILL) { if (Camera.XPosition < (levelWidth - WindowWidth)) { //Logger("Camera.XPosition < (levelWidth - WindowWidth)"); Camera.State = CAMERA_SCROLLING_RIGHT; Player.XPosition = (Camera.XPosition + sectionWidth) - Player.Width - DistanceToWindowEdge; Player.PrevXPosition = Player.XPosition; } } } void UpdateEvenRow(void) { // Handle events from the keyboard HandleEvents(); // Calculate the deltatime NewTime = SDL_GetTicks(); DeltaTime = (NewTime - OldTime) / 1000.0; OldTime = NewTime; ////////////////////////////////////////////////////////////////////////// // Whenever the player is moving if (Player.State != PLAYER_STILL) { // Just a fancy way of saying: "If the player state is set to PLAYER_MOVING_LEFT, move the player to the left. Else, move the player to the right" Player.XPosition += (Player.State == PLAYER_MOVING_LEFT ? -Player.Velocity : Player.Velocity) * (float)DeltaTime; // If the player has reached the left side of the window if (Player.XPosition <= (Camera.XPosition + DistanceToWindowEdge)) { // The camera is only allowed to scroll to the left if it's not at the start of the level if (Camera.XPosition > 0.0f) { Camera.State = CAMERA_SCROLLING_LEFT; Player.XPosition = Camera.XPosition + DistanceToWindowEdge; Player.PrevXPosition = Player.XPosition; } } // If the player has reached the right side of the window else if (Player.XPosition + Player.Width > (Camera.XPosition + WindowWidth) - DistanceToWindowEdge) { // The camera is only allowed to scroll to the right if it's not at the end of the level if (Camera.XPosition < (levelWidth - WindowWidth)) { Player.XPosition = (Camera.XPosition + sectionWidth) - Player.Width - DistanceToWindowEdge; Player.PrevXPosition = Player.XPosition; } } // Make sure that the player can't go outside the left- and the right side of the level if (Player.XPosition < 0.0f) Player.XPosition = 0.0f; else if (Player.XPosition > levelWidth - Player.Width) Player.XPosition = levelWidth - Player.Width; } // Whenever the camera is scrolling if (Camera.State != CAMERA_STILL) { if (Camera.XPosition <= cameraStartPosition)// -2000 { Camera.State = CAMERA_STILL; Logger("Finished even row Auto scrolling "); /*if (!checkFileReady()) { std::ofstream out("ready.txt"); out << "0"; out.close(); } if (!checkFileSDL()) { std::ofstream outFile("sdl.txt"); outFile << "0"; outFile.close(); }*/ Running = false; return; } const bool ScrollingLeft = (Camera.State == CAMERA_SCROLLING_LEFT); /* By making the player walk a bit by itself during the scrolling, the player won't end up outside the window edges when the scrolling is finished The walking direction depends on the direction the camera is scrolling The walking speed is based on the camera's velocity - a bigger division value (in this case it's 0.25f) will make the player walk faster, which means the player will end up further away from the window edge when the scrolling is finished A smaller division value does the opposite Note: a value smaller than 0.22f will, with the current player width, cause an endless scrolling loop bug */ Player.XPosition += (ScrollingLeft ? -(Camera.Velocity * 0.25f) : (Camera.Velocity * 0.25f)) * (float)DeltaTime; ////////////////////////////////////////////////////////////////////////// // See the player movement code above for an explanation on how this works Camera.XPosition += ((ScrollingLeft ? -Camera.Velocity : Camera.Velocity) * (float)DeltaTime); // Check the distance between the camera's current- and previous position // The calculation result depends on the direction the camera is scrolling in const float Distance = (ScrollingLeft ? (Camera.PrevXPosition - Camera.XPosition) : (Camera.XPosition - Camera.PrevXPosition)); // If the camera has scrolled a full section width if (Distance >= sectionWidth) { // Calculate the camera's final position // Again, this calculation result depends on the direction the camera is scrolling in const float FinalCameraPosition = (ScrollingLeft ? (Camera.PrevXPosition - sectionWidth) : (Camera.PrevXPosition + sectionWidth)); Camera.XPosition = FinalCameraPosition; Camera.PrevXPosition = FinalCameraPosition; } } if (Player.State != PLAYER_STILL) { if (Camera.XPosition < (levelWidth - WindowWidth)) { //Logger("Camera.XPosition < (levelWidth - WindowWidth)"); Camera.State = CAMERA_SCROLLING_LEFT; Player.XPosition = (Camera.XPosition + sectionWidth) - Player.Width - DistanceToWindowEdge; Player.PrevXPosition = Player.XPosition; } } } void Render(void) { // Clear the current render target SDL_RenderClear(pRenderer); ////////////////////////////////////////////////////////////////////////// for (int i = 0; i < numSection; ++i) { if (BackgroundTexture[i].pTexture) { // Create a temporary texture quad that is relative to the camera const SDL_Rect TextureQuad = { BackgroundTexture[i].Quad.x - (int)Camera.XPosition, BackgroundTexture[i].Quad.y, BackgroundTexture[i].Quad.w, BackgroundTexture[i].Quad.h }; /* Easy and fast culling Check if the texture quad is inside the camera quad (i.e, if the texture is in view) If it's not in view, just continue without rendering the texture During camera scrolling, 2 textures will be visible at the same time When no scrolling occurs, only 1 texture will be visible and rendered */ if (!QuadVsQuad(Camera.Quad, TextureQuad)) continue; SDL_RenderCopy(pRenderer, BackgroundTexture[i].pTexture, nullptr, &TextureQuad); } } //// Render the player as a quad //const SDL_Rect PlayerQuad = { (int)(Player.XPosition - Camera.XPosition), WindowHeight - (int)Player.Height, (int)Player.Width, (int)Player.Height }; SDL_SetRenderDrawColor(pRenderer, 0, 0, 0, SDL_ALPHA_OPAQUE); //SDL_RenderFillRect(pRenderer, &PlayerQuad); SDL_SetRenderDrawColor(pRenderer, 0, 0, 0, SDL_ALPHA_OPAQUE); ////////////////////////////////////////////////////////////////////////// // Update the screen SDL_RenderPresent(pRenderer); } int main(int argc, char *argv[]) { //_putenv("SDL_VIDEODRIVER = windib");500 2 0 -2000 1 1920 1080 0 0 //printf //printf(hex(display.get_flags() & 0xFFFFFFFF)); numSection = atoi(argv[2]); // Number of section like 8100 - each section balanceWidth = atoi(argv[3]); // balance width - reminder from imagewidth/8100 sectionWidth = 1080;// 1920;// 6480;// 8100;//8100 levelWidth = sectionWidth * numSection + balanceWidth; BackgroundTexture = new STexture[numSection]; Camera.Velocity = atof(argv[1]); Camera.XPosition = atof(argv[4]); Camera.PrevXPosition = Camera.XPosition; cameraStartPosition = atoi(argv[4]); oddEvenRow = atoi(argv[5]); WindowWidth = atoi(argv[6]); WindowHeight = atoi(argv[7]); WindowStartPosInSecondScreen = atoi(argv[8]); WindowsStartYposInSecondScreen = atoi(argv[9]); delayTimer = atoi(argv[10]); //Camera.State = CAMERA_STILL; //Running = true; //string line; //ifstream myfile("delay.txt"); //if (myfile.is_open()) //{ // while (getline(myfile, line)) // { // //cout << line << '\n'; // } // myfile.close(); //} //m_dwIP = std::strtoul(line.c_str(), NULL, 16); //delayTimer = atoi(line.c_str()); //int count = 1; // Initialize SDL, create the SDL window, the SDL renderer and so on if (InitializeSDL()) { // Create the textures and other data //Scroll: if (Create()) { while (Running) { if (oddEvenRow == 1) { Update(); } if (oddEvenRow == 2) { UpdateEvenRow(); } Render(); SDL_Delay(1); } // Wait for trigger and parameters //while (!Running) //{ // if (checkFileReady()) // { // //Sleep(2000); // Logger("Waiting for trigger in ready.txt"); // string line; // ifstream myfile("ready.txt"); // if (myfile.is_open()) // { // while (getline(myfile, line)) // {} // myfile.close(); // } // bool status = remove("ready.txt"); // if (status) // Logger("ready.txt file deleted."); // else // Logger("Unable to delete ready.txt file."); // int readyFlag = atoi(line.c_str()); // std::string out_string; // std::stringstream ss; // ss << readyFlag; // out_string = ss.str(); // Logger("Ready.txt Value - " + out_string); // if (readyFlag == -1) // { // Running = false; // Camera.State = CAMERA_STILL; // Destroy(); // DeinitializeSDL(); // return 0; // } // if (readyFlag == 1) // { // Logger("Check process.txt file available or not"); // // Read parameters from file to run the imgprocessor.exe // if (checkFileProcess()) // { // Logger("Process.txt available"); // ifstream myfile("process.txt"); // int lineCount = 0; // if (myfile.is_open()) // { // while (getline(myfile, line)) // { // if (lineCount == 0) // { // std::string str = line; // const char *cstr = str.c_str(); // Camera.Velocity = atof(cstr); // Logger("Assigned First Parameter."); // } // if (lineCount == 1) // { // std::string str = line; // const char *cstr = str.c_str(); // numSection = atoi(cstr); // Number of section like 8100 - each section // Logger("Assigned Second Parameter."); // } // sectionWidth = 1080;// 1920;// 6480;// 8100;//8100 // levelWidth = sectionWidth * numSection + balanceWidth; // BackgroundTexture = new STexture[numSection]; // if (lineCount == 2) // { // std::string str = line; // const char *cstr = str.c_str(); // balanceWidth = atoi(cstr); // balance width - reminder from imagewidth/8100 // Logger("Assigned Third Parameter."); // } // if (lineCount == 3) // { // std::string str = line; // const char *cstr = str.c_str(); // Camera.XPosition = atof(cstr); // Camera.PrevXPosition = Camera.XPosition; // Logger("Assigned Fourth Parameter."); // } // if (lineCount == 4) // { // std::string str = line; // const char *cstr = str.c_str(); // oddEvenRow = atoi(cstr); // Logger("Assigned Fifth Parameter."); // } // if (lineCount == 5) // { // std::string str = line; // const char *cstr = str.c_str(); // WindowWidth = atoi(cstr); // Logger("Assigned Sixth Parameter."); // } // if (lineCount == 6) // { // std::string str = line; // const char *cstr = str.c_str(); // WindowHeight = atoi(cstr); // Logger("Assigned Seventh Parameter."); // } // if (lineCount == 7) // { // std::string str = line; // const char *cstr = str.c_str(); // WindowStartPosInSecondScreen = atoi(cstr); // Logger("Assigned Eigth Parameter."); // } // if (lineCount == 8) // { // std::string str = line; // const char *cstr = str.c_str(); // WindowsStartYposInSecondScreen = atoi(cstr); // Logger("Assigned Ninth Parameter."); // Running = true; // goto Scroll; // } // lineCount = lineCount + 1; // } // myfile.close(); // bool status = remove("Process.txt"); // if (status) // Logger("Process.txt file deleted."); // else // Logger("Unable to delete Process.txt file."); // } // return 1; // } // else // Logger("Process.txt file not available"); // } // } //} // // Destroy all created data Logger("Destroy all created data"); Destroy(); } // Destroy SDL, the SDL window and the SDL renderer Logger("Destroy SDL, the SDL window and the SDL renderer"); DeinitializeSDL(); } return 0; } bool checkFileProcess() { if (FILE *file = fopen("process.txt", "r")) { fclose(file); return true; } else { return false; } } bool checkFileReady() { if (FILE *file = fopen("ready.txt", "r")) { fclose(file); return true; } else { return false; } } bool checkFileSDL() { if (FILE *file = fopen("sdl.txt", "r")) { fclose(file); return true; } else { return false; } } string getCurrentDateTime(string s) { time_t now = time(0); struct tm tstruct; char buf[80]; tstruct = *localtime(&now); if (s == "now") strftime(buf, sizeof(buf), "%H-%M-%S", &tstruct); else if (s == "date") strftime(buf, sizeof(buf), "%Y-%m-%d", &tstruct); return string(buf); } void Logger(string logMsg) { string filePath = "Log/log_" + getCurrentDateTime("date") + "_" + getCurrentDateTime("now") + ".txt"; string now = getCurrentDateTime("now"); ofstream ofs(filePath.c_str(), std::ios_base::out | std::ios_base::app); ofs << now << '\t' << logMsg << '\n'; ofs.close(); }