diff --git a/CDebug.cpp b/CDebug.cpp index 46b68b5..0152498 100644 --- a/CDebug.cpp +++ b/CDebug.cpp @@ -106,7 +106,7 @@ void CDebug::sendParam(int Param) void CDebug::actualizeData() { // del FrameCounterText before drawing new - if(FrameCounterText != nullptr) + if(FrameCounterText) dbgWnd->delText(FrameCounterText); // write new FrameCounterText and draw it sprintf(puffer1, "Actual Frame: %lu", global::s2->FrameCounter); @@ -117,7 +117,7 @@ void CDebug::actualizeData() if(tmpFrameCtr == 10) { // del FramesPerSecText before drawing new - if(FramesPerSecText != nullptr) + if(FramesPerSecText) dbgWnd->delText(FramesPerSecText); // write new FramesPerSecText and draw it sprintf(puffer1, "Frames per Sec: %.2f", tmpFrameCtr / (((float)SDL_GetTicks() - tmpTickCtr) / 1000)); @@ -129,14 +129,14 @@ void CDebug::actualizeData() tmpFrameCtr++; // del msWaitText before drawing new - if(msWaitText != nullptr) + if(msWaitText) dbgWnd->delText(msWaitText); // write new msWaitText and draw it sprintf(puffer1, "Wait: %ums", global::s2->msWait); msWaitText = dbgWnd->addText(puffer1, 0, 35, fontsize); // del MouseText before drawing new - if(MouseText != nullptr) + if(MouseText) dbgWnd->delText(MouseText); // write new MouseText and draw it sprintf(puffer1, "Mouse: x=%d y=%d %s", global::s2->Cursor.x, global::s2->Cursor.y, @@ -146,21 +146,21 @@ void CDebug::actualizeData() MouseText = dbgWnd->addText(puffer1, 0, 50, fontsize); // del RegisteredMenusText before drawing new - if(RegisteredMenusText != nullptr) + if(RegisteredMenusText) dbgWnd->delText(RegisteredMenusText); // write new RegisteredMenusText and draw it sprintf(puffer1, "Registered Menus: %d (max. %d)", global::s2->RegisteredMenus, MAXMENUS); RegisteredMenusText = dbgWnd->addText(puffer1, 0, 60, fontsize); // del RegisteredWindowsText before drawing new - if(RegisteredWindowsText != nullptr) + if(RegisteredWindowsText) dbgWnd->delText(RegisteredWindowsText); // write new RegisteredWindowsText and draw it sprintf(puffer1, "Registered Windows: %d (max. %d)", global::s2->RegisteredWindows, MAXWINDOWS); RegisteredWindowsText = dbgWnd->addText(puffer1, 0, 70, fontsize); // del RegisteredCallbacksText before drawing new - if(RegisteredCallbacksText != nullptr) + if(RegisteredCallbacksText) dbgWnd->delText(RegisteredCallbacksText); // write new RegisteredCallbacksText and draw it sprintf(puffer1, "Registered Callbacks: %d (max. %d)", global::s2->RegisteredCallbacks, MAXCALLBACKS); @@ -168,47 +168,47 @@ void CDebug::actualizeData() // we will now write the map data if a map is active MapObj = global::s2->MapObj; - if(MapObj != nullptr) + if(MapObj) { map = MapObj->map; const MapNode& vertex = map->getVertex(MapObj->VertexX_, MapObj->VertexY_); - if(MapNameText != nullptr) + if(MapNameText) { if(dbgWnd->delText(MapNameText)) MapNameText = nullptr; } - if(MapNameText == nullptr) + if(!MapNameText) { sprintf(puffer1, "Map Name: %s", map->name); MapNameText = dbgWnd->addText(puffer1, 260, 10, fontsize); } - if(MapSizeText != nullptr) + if(MapSizeText) { if(dbgWnd->delText(MapSizeText)) MapSizeText = nullptr; } - if(MapSizeText == nullptr) + if(!MapSizeText) { sprintf(puffer1, "Width: %d Height: %d", map->width, map->height); MapSizeText = dbgWnd->addText(puffer1, 260, 20, fontsize); } - if(MapAuthorText != nullptr) + if(MapAuthorText) { if(dbgWnd->delText(MapAuthorText)) MapAuthorText = nullptr; } - if(MapAuthorText == nullptr) + if(!MapAuthorText) { sprintf(puffer1, "Author: %s", map->author); MapAuthorText = dbgWnd->addText(puffer1, 260, 30, fontsize); } - if(MapTypeText != nullptr) + if(MapTypeText) { if(dbgWnd->delText(MapTypeText)) MapTypeText = nullptr; } - if(MapTypeText == nullptr) + if(!MapTypeText) { sprintf(puffer1, "Type: %d (%s)", map->type, (map->type == MAP_GREENLAND ? @@ -216,193 +216,193 @@ void CDebug::actualizeData() (map->type == MAP_WASTELAND ? "Wasteland" : (map->type == MAP_WINTERLAND ? "Winterland" : "Unknown")))); MapTypeText = dbgWnd->addText(puffer1, 260, 40, fontsize); } - if(MapPlayerText != nullptr) + if(MapPlayerText) { if(dbgWnd->delText(MapPlayerText)) MapPlayerText = nullptr; } - if(MapPlayerText == nullptr) + if(!MapPlayerText) { sprintf(puffer1, "Player: %d", map->player); MapPlayerText = dbgWnd->addText(puffer1, 260, 50, fontsize); } - if(VertexText != nullptr) + if(VertexText) { if(dbgWnd->delText(VertexText)) VertexText = nullptr; } - if(VertexText == nullptr) + if(!VertexText) { sprintf(puffer1, "Vertex: %d, %d", MapObj->VertexX_, MapObj->VertexY_); VertexText = dbgWnd->addText(puffer1, 260, 60, fontsize); } - if(VertexDataText != nullptr) + if(VertexDataText) { if(dbgWnd->delText(VertexDataText)) VertexDataText = nullptr; } - if(VertexDataText == nullptr) + if(!VertexDataText) { sprintf(puffer1, "Vertex Data: x=%d, y=%d, z=%d i=%.2f h=%#04x", vertex.x, vertex.y, vertex.z, ((float)vertex.i) / pow(2, 16), vertex.h); VertexDataText = dbgWnd->addText(puffer1, 260, 70, fontsize); } - if(VertexVectorText != nullptr) + if(VertexVectorText) { if(dbgWnd->delText(VertexVectorText)) VertexVectorText = nullptr; } - if(VertexVectorText == nullptr) + if(!VertexVectorText) { sprintf(puffer1, "Vertex Vector: (%.2f, %.2f, %.2f)", vertex.normVector.x, vertex.normVector.y, vertex.normVector.z); VertexVectorText = dbgWnd->addText(puffer1, 260, 80, fontsize); } - if(FlatVectorText != nullptr) + if(FlatVectorText) { if(dbgWnd->delText(FlatVectorText)) FlatVectorText = nullptr; } - if(FlatVectorText == nullptr) + if(!FlatVectorText) { sprintf(puffer1, "Flat Vector: (%.2f, %.2f, %.2f)", vertex.flatVector.x, vertex.flatVector.y, vertex.flatVector.z); FlatVectorText = dbgWnd->addText(puffer1, 260, 90, fontsize); } - if(rsuTextureText != nullptr) + if(rsuTextureText) { if(dbgWnd->delText(rsuTextureText)) rsuTextureText = nullptr; } - if(rsuTextureText == nullptr) + if(!rsuTextureText) { sprintf(puffer1, "RSU-Texture: %#04x", vertex.rsuTexture); rsuTextureText = dbgWnd->addText(puffer1, 260, 100, fontsize); } - if(usdTextureText != nullptr) + if(usdTextureText) { if(dbgWnd->delText(usdTextureText)) usdTextureText = nullptr; } - if(usdTextureText == nullptr) + if(!usdTextureText) { sprintf(puffer1, "USD-Texture: %#04x", vertex.usdTexture); usdTextureText = dbgWnd->addText(puffer1, 260, 110, fontsize); } - if(roadText != nullptr) + if(roadText) { if(dbgWnd->delText(roadText)) roadText = nullptr; } - if(roadText == nullptr) + if(!roadText) { sprintf(puffer1, "road: %#04x", vertex.road); roadText = dbgWnd->addText(puffer1, 260, 120, fontsize); } - if(objectTypeText != nullptr) + if(objectTypeText) { if(dbgWnd->delText(objectTypeText)) objectTypeText = nullptr; } - if(objectTypeText == nullptr) + if(!objectTypeText) { sprintf(puffer1, "objectType: %#04x", vertex.objectType); objectTypeText = dbgWnd->addText(puffer1, 260, 130, fontsize); } - if(objectInfoText != nullptr) + if(objectInfoText) { if(dbgWnd->delText(objectInfoText)) objectInfoText = nullptr; } - if(objectInfoText == nullptr) + if(!objectInfoText) { sprintf(puffer1, "objectInfo: %#04x", vertex.objectInfo); objectInfoText = dbgWnd->addText(puffer1, 260, 140, fontsize); } - if(animalText != nullptr) + if(animalText) { if(dbgWnd->delText(animalText)) animalText = nullptr; } - if(animalText == nullptr) + if(!animalText) { sprintf(puffer1, "animal: %#04x", vertex.animal); animalText = dbgWnd->addText(puffer1, 260, 150, fontsize); } - if(unknown1Text != nullptr) + if(unknown1Text) { if(dbgWnd->delText(unknown1Text)) unknown1Text = nullptr; } - if(unknown1Text == nullptr) + if(!unknown1Text) { sprintf(puffer1, "unknown1: %#04x", vertex.unknown1); unknown1Text = dbgWnd->addText(puffer1, 260, 160, fontsize); } - if(buildText != nullptr) + if(buildText) { if(dbgWnd->delText(buildText)) buildText = nullptr; } - if(buildText == nullptr) + if(!buildText) { sprintf(puffer1, "build: %#04x", vertex.build); buildText = dbgWnd->addText(puffer1, 260, 170, fontsize); } - if(unknown2Text != nullptr) + if(unknown2Text) { if(dbgWnd->delText(unknown2Text)) unknown2Text = nullptr; } - if(unknown2Text == nullptr) + if(!unknown2Text) { sprintf(puffer1, "unknown2: %#04x", vertex.unknown2); unknown2Text = dbgWnd->addText(puffer1, 260, 180, fontsize); } - if(unknown3Text != nullptr) + if(unknown3Text) { if(dbgWnd->delText(unknown3Text)) unknown3Text = nullptr; } - if(unknown3Text == nullptr) + if(!unknown3Text) { sprintf(puffer1, "unknown3: %#04x", vertex.unknown3); unknown3Text = dbgWnd->addText(puffer1, 260, 190, fontsize); } - if(resourceText != nullptr) + if(resourceText) { if(dbgWnd->delText(resourceText)) resourceText = nullptr; } - if(resourceText == nullptr) + if(!resourceText) { sprintf(puffer1, "resource: %#04x", vertex.resource); resourceText = dbgWnd->addText(puffer1, 260, 200, fontsize); } - if(shadingText != nullptr) + if(shadingText) { if(dbgWnd->delText(shadingText)) shadingText = nullptr; } - if(shadingText == nullptr) + if(!shadingText) { sprintf(puffer1, "shading: %#04x", vertex.shading); shadingText = dbgWnd->addText(puffer1, 260, 210, fontsize); } - if(unknown5Text != nullptr) + if(unknown5Text) { if(dbgWnd->delText(unknown5Text)) unknown5Text = nullptr; } - if(unknown5Text == nullptr) + if(!unknown5Text) { sprintf(puffer1, "unknown5: %#04x", vertex.unknown5); unknown5Text = dbgWnd->addText(puffer1, 260, 220, fontsize); } - if(editorModeText != nullptr) + if(editorModeText) { if(dbgWnd->delText(editorModeText)) editorModeText = nullptr; } - if(editorModeText == nullptr) + if(!editorModeText) { sprintf(puffer1, "Editor --> Mode: %d Content: %#04x Content2: %#04x", MapObj->mode, MapObj->modeContent, MapObj->modeContent2); editorModeText = dbgWnd->addText(puffer1, 260, 230, fontsize); @@ -410,123 +410,123 @@ void CDebug::actualizeData() } else { // del MapNameText before drawing new - if(MapNameText != nullptr) + if(MapNameText) { if(dbgWnd->delText(MapNameText)) MapNameText = nullptr; } - if(MapNameText == nullptr) + if(!MapNameText) { // write new MapNameText and draw it sprintf(puffer1, "No Map loaded!"); MapNameText = dbgWnd->addText(puffer1, 260, 10, fontsize); } - if(MapSizeText != nullptr) + if(MapSizeText) { if(dbgWnd->delText(MapSizeText)) MapSizeText = nullptr; } - if(MapAuthorText != nullptr) + if(MapAuthorText) { if(dbgWnd->delText(MapAuthorText)) MapAuthorText = nullptr; } - if(MapTypeText != nullptr) + if(MapTypeText) { if(dbgWnd->delText(MapTypeText)) MapTypeText = nullptr; } - if(MapPlayerText != nullptr) + if(MapPlayerText) { if(dbgWnd->delText(MapPlayerText)) MapPlayerText = nullptr; } - if(VertexText != nullptr) + if(VertexText) { if(dbgWnd->delText(VertexText)) VertexText = nullptr; } - if(VertexDataText != nullptr) + if(VertexDataText) { if(dbgWnd->delText(VertexDataText)) VertexDataText = nullptr; } - if(VertexVectorText != nullptr) + if(VertexVectorText) { if(dbgWnd->delText(VertexVectorText)) VertexVectorText = nullptr; } - if(FlatVectorText != nullptr) + if(FlatVectorText) { if(dbgWnd->delText(FlatVectorText)) FlatVectorText = nullptr; } - if(rsuTextureText != nullptr) + if(rsuTextureText) { if(dbgWnd->delText(rsuTextureText)) rsuTextureText = nullptr; } - if(usdTextureText != nullptr) + if(usdTextureText) { if(dbgWnd->delText(usdTextureText)) usdTextureText = nullptr; } - if(roadText != nullptr) + if(roadText) { if(dbgWnd->delText(roadText)) roadText = nullptr; } - if(objectTypeText != nullptr) + if(objectTypeText) { if(dbgWnd->delText(objectTypeText)) objectTypeText = nullptr; } - if(objectInfoText != nullptr) + if(objectInfoText) { if(dbgWnd->delText(objectInfoText)) objectInfoText = nullptr; } - if(animalText != nullptr) + if(animalText) { if(dbgWnd->delText(animalText)) animalText = nullptr; } - if(unknown1Text != nullptr) + if(unknown1Text) { if(dbgWnd->delText(unknown1Text)) unknown1Text = nullptr; } - if(buildText != nullptr) + if(buildText) { if(dbgWnd->delText(buildText)) buildText = nullptr; } - if(unknown2Text != nullptr) + if(unknown2Text) { if(dbgWnd->delText(unknown2Text)) unknown2Text = nullptr; } - if(unknown3Text != nullptr) + if(unknown3Text) { if(dbgWnd->delText(unknown3Text)) unknown3Text = nullptr; } - if(resourceText != nullptr) + if(resourceText) { if(dbgWnd->delText(resourceText)) resourceText = nullptr; } - if(shadingText != nullptr) + if(shadingText) { if(dbgWnd->delText(shadingText)) shadingText = nullptr; } - if(unknown5Text != nullptr) + if(unknown5Text) { if(dbgWnd->delText(unknown5Text)) unknown5Text = nullptr; } - if(editorModeText != nullptr) + if(editorModeText) { if(dbgWnd->delText(editorModeText)) editorModeText = nullptr; diff --git a/CGame.cpp b/CGame.cpp index f42a870..c03312a 100644 --- a/CGame.cpp +++ b/CGame.cpp @@ -15,14 +15,8 @@ namespace bfs = boost::filesystem; //#include CGame::CGame() + : GameResolution(1024, 768), fullscreen(false), Running(true), showLoadScreen(true), Surf_Display(nullptr), Surf_DisplayGL(nullptr) { - GameResolutionX = 1024; - GameResolutionY = 768; - MenuResolutionX = 640; - MenuResolutionY = 480; - fullscreen = false; - showLoadScreen = true; - #ifdef _ADMINMODE FrameCounter = 0; RegisteredCallbacks = 0; @@ -32,9 +26,6 @@ CGame::CGame() msWait = 0; - Surf_Display = nullptr; - Surf_DisplayGL = nullptr; - Running = true; // mouse cursor data Cursor.x = 0; Cursor.y = 0; @@ -42,12 +33,12 @@ CGame::CGame() Cursor.button.left = false; Cursor.button.right = false; - for(int i = 0; i < MAXMENUS; i++) - Menus[i] = nullptr; - for(int i = 0; i < MAXWINDOWS; i++) - Windows[i] = nullptr; - for(int i = 0; i < MAXCALLBACKS; i++) - Callbacks[i] = nullptr; + for(auto& Menu : Menus) + Menu = nullptr; + for(auto& Window : Windows) + Window = nullptr; + for(auto& Callback : Callbacks) + Callback = nullptr; MapObj = nullptr; } @@ -78,27 +69,27 @@ bool CGame::RegisterMenu(CMenu* Menu) { bool success = false; - if(Menu == nullptr) + if(!Menu) return success; - for(int i = 0; i < MAXMENUS; i++) + for(auto& i : Menus) { - if(!success && Menus[i] == nullptr) + if(!success && !i) { - Menus[i] = Menu; - Menus[i]->setActive(); + i = Menu; + i->setActive(); success = true; #ifdef _ADMINMODE RegisteredMenus++; #endif - } else if(Menus[i] != nullptr) - Menus[i]->setInactive(); + } else if(i) + i->setInactive(); } return success; } bool CGame::UnregisterMenu(CMenu* Menu) { - if(Menu == nullptr) + if(!Menu) return false; for(int i = 0; i < MAXMENUS; i++) { @@ -106,7 +97,7 @@ bool CGame::UnregisterMenu(CMenu* Menu) { for(int j = i - 1; j >= 0; j--) { - if(Menus[j] != nullptr) + if(Menus[j]) { Menus[j]->setActive(); break; @@ -129,34 +120,34 @@ bool CGame::RegisterWindow(CWindow* Window) int highestPriority = 0; // first find the highest priority - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr && Windows[i]->getPriority() > highestPriority) - highestPriority = Windows[i]->getPriority(); + if(Window && Window->getPriority() > highestPriority) + highestPriority = Window->getPriority(); } - if(Window == nullptr) + if(!Window) return success; - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& i : Windows) { - if(!success && Windows[i] == nullptr) + if(!success && !i) { - Windows[i] = Window; - Windows[i]->setActive(); - Windows[i]->setPriority(highestPriority + 1); + i = Window; + i->setActive(); + i->setPriority(highestPriority + 1); success = true; #ifdef _ADMINMODE RegisteredWindows++; #endif - } else if(Windows[i] != nullptr) - Windows[i]->setInactive(); + } else if(i) + i->setInactive(); } return success; } bool CGame::UnregisterWindow(CWindow* Window) { - if(Window == nullptr) + if(!Window) return false; for(int i = 0; i < MAXWINDOWS; i++) { @@ -183,13 +174,13 @@ bool CGame::UnregisterWindow(CWindow* Window) bool CGame::RegisterCallback(void (*callback)(int)) { - if(callback == nullptr) + if(!callback) return false; - for(int i = 0; i < MAXCALLBACKS; i++) + for(auto& Callback : Callbacks) { - if(Callbacks[i] == nullptr) + if(!Callback) { - Callbacks[i] = callback; + Callback = callback; #ifdef _ADMINMODE RegisteredCallbacks++; #endif @@ -201,13 +192,13 @@ bool CGame::RegisterCallback(void (*callback)(int)) bool CGame::UnregisterCallback(void (*callback)(int)) { - if(callback == nullptr) + if(!callback) return false; - for(int i = 0; i < MAXCALLBACKS; i++) + for(auto& Callback : Callbacks) { - if(Callbacks[i] == callback) + if(Callback == callback) { - Callbacks[i] = nullptr; + Callback = nullptr; #ifdef _ADMINMODE RegisteredCallbacks--; #endif diff --git a/CGame.h b/CGame.h index 5d4e85a..61bb836 100644 --- a/CGame.h +++ b/CGame.h @@ -12,11 +12,7 @@ class CGame friend class CDebug; public: - int GameResolutionX; - int GameResolutionY; - // MenuResolution is old and not used anymore - int MenuResolutionX; - int MenuResolutionY; + Extent GameResolution; bool fullscreen; bool Running; @@ -63,6 +59,7 @@ class CGame int Execute(); bool Init(); + bool ReCreateWindow(); void EventHandling(SDL_Event* Event); @@ -83,8 +80,7 @@ class CGame void delMapObj(); SDL_Surface* getDisplaySurface() { return Surf_Display; }; SDL_Surface* getDisplayGLSurface() { return Surf_DisplayGL; }; - int getResX() { return GameResolutionX; } - int getResY() { return GameResolutionY; } + auto getRes() { return GameResolution; } }; #endif diff --git a/CGame_Cleanup.cpp b/CGame_Cleanup.cpp index 170d3a2..904832d 100644 --- a/CGame_Cleanup.cpp +++ b/CGame_Cleanup.cpp @@ -7,33 +7,33 @@ void CGame::Cleanup() { // unregister menus - for(int i = 0; i < MAXMENUS; i++) + for(auto& Menu : Menus) { - if(Menus[i] != nullptr) - CSurface::Draw(Surf_Display, Menus[i]->getSurface(), 0, 0); + if(Menu) + CGame::UnregisterMenu(Menu); } // unregister windows - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr) - CSurface::Draw(Surf_Display, Windows[i]->getSurface(), 0, 0); + if(Window) + CGame::UnregisterWindow(Window); } // free all picture surfaces for(int i = 0; i < MAXBOBBMP; i++) { - if(global::bmpArray[i].surface != nullptr) + if(global::bmpArray[i].surface) SDL_FreeSurface(global::bmpArray[i].surface); } // free all shadow surfaces for(int i = 0; i < MAXBOBSHADOW; i++) { - if(global::shadowArray[i].surface != nullptr) + if(global::shadowArray[i].surface) SDL_FreeSurface(global::shadowArray[i].surface); } SDL_FreeSurface(Surf_Display); - if(Surf_DisplayGL != nullptr) + if(Surf_DisplayGL) SDL_FreeSurface(Surf_DisplayGL); SDL_Quit(); diff --git a/CGame_Event.cpp b/CGame_Event.cpp index ac2d5c8..40e06ca 100644 --- a/CGame_Event.cpp +++ b/CGame_Event.cpp @@ -18,18 +18,18 @@ void CGame::EventHandling(SDL_Event* Event) // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) // we have to change the prioritys of the windows (for rendering), so find the highest one int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) + for(auto& Window : Windows) { - if(Windows[j] != nullptr && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); + if(Window && Window->getPriority() > highestPriority) + highestPriority = Window->getPriority(); } - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr && !Windows[i]->isWaste() && Windows[i]->isMarked() && Windows[i]->getPriority() == highestPriority - && Windows[i]->hasActiveInputElement()) + if(Window && !Window->isWaste() && Window->isMarked() && Window->getPriority() == highestPriority + && Window->hasActiveInputElement()) { - Windows[i]->setKeyboardData(Event->key); + Window->setKeyboardData(Event->key); delivered = true; break; } @@ -40,7 +40,7 @@ void CGame::EventHandling(SDL_Event* Event) // deliver keyboard data to map if active if(!delivered) { - if(MapObj != nullptr && MapObj->isActive()) + if(MapObj && MapObj->isActive()) { MapObj->setKeyboardData(Event->key); // data has been delivered to map, so no menu is in the foreground --> stop delivering @@ -48,10 +48,10 @@ void CGame::EventHandling(SDL_Event* Event) } // deliver keyboard data to active menus - for(int i = 0; i < MAXMENUS; i++) + for(auto& Menu : Menus) { - if(Menus[i] != nullptr && Menus[i]->isActive() && !Menus[i]->isWaste()) - Menus[i]->setKeyboardData(Event->key); + if(Menu && Menu->isActive() && !Menu->isWaste()) + Menu->setKeyboardData(Event->key); } } @@ -126,7 +126,7 @@ void CGame::EventHandling(SDL_Event* Event) case SDL_KEYUP: { // deliver keyboard data to map - if(MapObj != nullptr) + if(MapObj) MapObj->setKeyboardData(Event->key); break; @@ -135,7 +135,7 @@ void CGame::EventHandling(SDL_Event* Event) case SDL_MOUSEMOTION: { // setup mouse cursor data - if(MapObj != nullptr && MapObj->isActive()) + if(MapObj && MapObj->isActive()) { if((Event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) == 0) { @@ -171,26 +171,26 @@ void CGame::EventHandling(SDL_Event* Event) // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) // we have to change the prioritys of the windows (for rendering), so find the highest one int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) + for(auto& Window : Windows) { - if(Windows[j] != nullptr && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); + if(Window && Window->getPriority() > highestPriority) + highestPriority = Window->getPriority(); } for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) { - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) + if(Window && !Window->isWaste() && Window->getPriority() == actualPriority) { // is the cursor INSIDE the window or does the user move or resize the window? - if(((Event->motion.x >= Windows[i]->getX()) && (Event->motion.x < Windows[i]->getX() + Windows[i]->getW()) - && (Event->motion.y >= Windows[i]->getY()) && (Event->motion.y < Windows[i]->getY() + Windows[i]->getH())) - || Windows[i]->isMoving() || Windows[i]->isResizing()) + if(((Event->motion.x >= Window->getX()) && (Event->motion.x < Window->getX() + Window->getW()) + && (Event->motion.y >= Window->getY()) && (Event->motion.y < Window->getY() + Window->getH())) + || Window->isMoving() || Window->isResizing()) { // Windows[i]->setActive(); // Windows[i]->setPriority(highestPriority+1); - Windows[i]->setMouseData(Event->motion); + Window->setMouseData(Event->motion); delivered = true; break; } @@ -204,7 +204,7 @@ void CGame::EventHandling(SDL_Event* Event) break; // deliver mouse motion data to map if active - if(MapObj != nullptr && MapObj->isActive()) + if(MapObj && MapObj->isActive()) { MapObj->setMouseData(Event->motion); // data has been delivered to map, so no menu is in the foreground --> stop delivering @@ -212,11 +212,11 @@ void CGame::EventHandling(SDL_Event* Event) } // deliver mouse motion data to active menus - for(int i = 0; i < MAXMENUS; i++) + for(auto& Menu : Menus) { - if(Menus[i] != nullptr && Menus[i]->isActive() && !Menus[i]->isWaste()) + if(Menu && Menu->isActive() && !Menu->isWaste()) { - Menus[i]->setMouseData(Event->motion); + Menu->setMouseData(Event->motion); break; } } @@ -249,29 +249,29 @@ void CGame::EventHandling(SDL_Event* Event) // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) // we have to change the prioritys of the windows (for rendering), so find the highest one int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) + for(auto& Window : Windows) { - if(Windows[j] != nullptr && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); + if(Window && Window->getPriority() > highestPriority) + highestPriority = Window->getPriority(); } for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) { - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) + if(Window && !Window->isWaste() && Window->getPriority() == actualPriority) { // is the cursor INSIDE the window? - if((Event->button.x >= Windows[i]->getX()) && (Event->button.x < Windows[i]->getX() + Windows[i]->getW()) - && (Event->button.y >= Windows[i]->getY()) && (Event->button.y < Windows[i]->getY() + Windows[i]->getH())) + if((Event->button.x >= Window->getX()) && (Event->button.x < Window->getX() + Window->getW()) + && (Event->button.y >= Window->getY()) && (Event->button.y < Window->getY() + Window->getH())) { - Windows[i]->setActive(); - Windows[i]->setPriority(highestPriority + 1); - Windows[i]->setMouseData(Event->button); + Window->setActive(); + Window->setPriority(highestPriority + 1); + Window->setMouseData(Event->button); delivered = true; break; - } else if(Windows[i]->isActive()) - Windows[i]->setInactive(); + } else if(Window->isActive()) + Window->setInactive(); } } if(delivered) @@ -282,7 +282,7 @@ void CGame::EventHandling(SDL_Event* Event) break; // deliver mouse button data to map if active - if(MapObj != nullptr && MapObj->isActive()) + if(MapObj && MapObj->isActive()) { MapObj->setMouseData(Event->button); // data has been delivered to map, so no menu is in the foreground --> stop delivering @@ -290,10 +290,10 @@ void CGame::EventHandling(SDL_Event* Event) } // deliver mouse button data to active menus - for(int i = 0; i < MAXMENUS; i++) + for(auto& Menu : Menus) { - if(Menus[i] != nullptr && Menus[i]->isActive() && !Menus[i]->isWaste()) - Menus[i]->setMouseData(Event->button); + if(Menu && Menu->isActive() && !Menu->isWaste()) + Menu->setMouseData(Event->button); } break; @@ -310,25 +310,25 @@ void CGame::EventHandling(SDL_Event* Event) // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) // we have to change the prioritys of the windows (for rendering), so find the highest one int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) + for(auto& Window : Windows) { - if(Windows[j] != nullptr && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); + if(Window && Window->getPriority() > highestPriority) + highestPriority = Window->getPriority(); } for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) { - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) + if(Window && !Window->isWaste() && Window->getPriority() == actualPriority) { // is the cursor INSIDE the window? - if((Event->button.x >= Windows[i]->getX()) && (Event->button.x < Windows[i]->getX() + Windows[i]->getW()) - && (Event->button.y >= Windows[i]->getY()) && (Event->button.y < Windows[i]->getY() + Windows[i]->getH())) + if((Event->button.x >= Window->getX()) && (Event->button.x < Window->getX() + Window->getW()) + && (Event->button.y >= Window->getY()) && (Event->button.y < Window->getY() + Window->getH())) { // Windows[i]->setActive(); // Windows[i]->setPriority(highestPriority+1); - Windows[i]->setMouseData(Event->button); + Window->setMouseData(Event->button); delivered = true; break; } @@ -349,7 +349,7 @@ void CGame::EventHandling(SDL_Event* Event) // if still not delivered, keep delivering to secondary elements like menu or map // deliver mouse button data to map if active - if(MapObj != nullptr && MapObj->isActive()) + if(MapObj && MapObj->isActive()) { MapObj->setMouseData(Event->button); // data has been delivered to map, so no menu is in the foreground --> stop delivering @@ -361,10 +361,10 @@ void CGame::EventHandling(SDL_Event* Event) break; // deliver mouse button data to active menus - for(int i = 0; i < MAXMENUS; i++) + for(auto& Menu : Menus) { - if(Menus[i] != nullptr && Menus[i]->isActive() && !Menus[i]->isWaste()) - Menus[i]->setMouseData(Event->button); + if(Menu && Menu->isActive() && !Menu->isWaste()) + Menu->setMouseData(Event->button); } break; } diff --git a/CGame_Init.cpp b/CGame_Init.cpp index f12076d..f1ab222 100644 --- a/CGame_Init.cpp +++ b/CGame_Init.cpp @@ -8,6 +8,31 @@ #include #include +bool CGame::ReCreateWindow() +{ + SDL_FreeSurface(Surf_Display); + Surf_Display = nullptr; + SDL_FreeSurface(Surf_DisplayGL); + Surf_DisplayGL = nullptr; + if(CSurface::useOpenGL) + { + Surf_DisplayGL = SDL_SetVideoMode(GameResolution.x, GameResolution.y, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)); + Surf_Display = SDL_CreateRGBSurface(SDL_SWSURFACE, GameResolution.x, GameResolution.y, 32, 0, 0, 0, 0); + if(!Surf_Display || !Surf_DisplayGL) + return false; + } else + { + Surf_Display = + SDL_SetVideoMode(GameResolution.x, GameResolution.y, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : 0)); + if(!Surf_Display) + return false; + } + + SDL_WM_SetCaption("Return to the Roots Mapeditor [BETA]", 0); + SetAppIcon(); + return true; +} + bool CGame::Init() { std::cout << "Return to the Roots Mapeditor\n"; @@ -23,29 +48,11 @@ bool CGame::Init() SDL_ShowCursor(SDL_DISABLE); std::cout << "\nCreate Window..."; - if(CSurface::useOpenGL) + if(!ReCreateWindow()) { - Surf_DisplayGL = SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)); - Surf_Display = SDL_CreateRGBSurface(SDL_SWSURFACE, GameResolutionX, GameResolutionY, 32, 0, 0, 0, 0); - if(Surf_Display == nullptr || Surf_DisplayGL == nullptr) - { - std::cout << "failure"; - return false; - } - } else - { - Surf_Display = - SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : 0)); - if(Surf_Display == nullptr) - { - std::cout << "failure"; - return false; - } + std::cout << "failure"; + return false; } - - SDL_WM_SetCaption("Return to the Roots Mapeditor [BETA]", 0); - SetAppIcon(); - CFile::init(); /*NOTE: its important to load a palette at first, diff --git a/CGame_Render.cpp b/CGame_Render.cpp index 2e1f78e..bcf090e 100644 --- a/CGame_Render.cpp +++ b/CGame_Render.cpp @@ -34,47 +34,10 @@ void CGame::SetAppIcon() void CGame::Render() { - // clear the surface before drawing new (in normal case not needed) - // SDL_FillRect( Surf_Display, nullptr, SDL_MapRGB(Surf_Display->format,0,0,0) ); - - // check resolution - /* - if (MapObj == nullptr || !MapObj->isActive()) + if(Extent(Surf_Display->w, Surf_Display->h) != GameResolution || fullscreen != ((Surf_Display->flags & SDL_FULLSCREEN) != 0)) { - //we are in menu - if ( (Surf_Display->w != MenuResolutionX || Surf_Display->h != MenuResolutionY) || - ( (fullscreen && !(Surf_Display->flags&SDL_FULLSCREEN)) || (!fullscreen && (Surf_Display->flags&SDL_FULLSCREEN)) ) - ) - { - SDL_FreeSurface(Surf_Display); - Surf_Display = SDL_SetVideoMode(MenuResolutionX, MenuResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? - SDL_FULLSCREEN : 0)); - } - } - else - { - */ - // we are in game - if((Surf_Display->w != GameResolutionX || Surf_Display->h != GameResolutionY) - || fullscreen != ((Surf_Display->flags & SDL_FULLSCREEN) != 0)) - { - SDL_FreeSurface(Surf_Display); - Surf_Display = nullptr; - - if(CSurface::useOpenGL) - { - SDL_FreeSurface(Surf_DisplayGL); - - Surf_DisplayGL = SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)); - Surf_Display = SDL_CreateRGBSurface(SDL_SWSURFACE, GameResolutionX, GameResolutionY, 32, 0, 0, 0, 0); - } else - { - Surf_Display = - SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : 0)); - } - SetAppIcon(); + ReCreateWindow(); } - //} // if the S2 loading screen is shown, render only this until user clicks a mouse button if(showLoadScreen) @@ -86,41 +49,38 @@ void CGame::Render() surfLoadScreen->h - 1); if(CSurface::useOpenGL) - { - // SDL_BlitSurface(Surf_Display, nullptr, Surf_DisplayGL, nullptr); - // SDL_Flip(Surf_DisplayGL); SDL_GL_SwapBuffers(); - } else + else SDL_Flip(Surf_Display); return; } // render the map if active - if(MapObj != nullptr && MapObj->isActive()) + if(MapObj && MapObj->isActive()) CSurface::Draw(Surf_Display, MapObj->getSurface(), 0, 0); // render active menus - for(int i = 0; i < MAXMENUS; i++) + for(auto& Menu : Menus) { - if(Menus[i] != nullptr && Menus[i]->isActive()) - CSurface::Draw(Surf_Display, Menus[i]->getSurface(), 0, 0); + if(Menu && Menu->isActive()) + CSurface::Draw(Surf_Display, Menu->getSurface(), 0, 0); } // render windows ordered by priority int highestPriority = 0; // first find the highest priority - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr && Windows[i]->getPriority() > highestPriority) - highestPriority = Windows[i]->getPriority(); + if(Window && Window->getPriority() > highestPriority) + highestPriority = Window->getPriority(); } // render from lowest priority to highest for(int actualPriority = 0; actualPriority <= highestPriority; actualPriority++) { - for(int i = 0; i < MAXWINDOWS; i++) + for(auto& Window : Windows) { - if(Windows[i] != nullptr && Windows[i]->getPriority() == actualPriority) - CSurface::Draw(Surf_Display, Windows[i]->getSurface(), Windows[i]->getX(), Windows[i]->getY()); + if(Window && Window->getPriority() == actualPriority) + CSurface::Draw(Surf_Display, Window->getSurface(), Window->getX(), Window->getY()); } } diff --git a/CIO/CButton.cpp b/CIO/CButton.cpp index cd0fd38..8e1dbf8 100644 --- a/CIO/CButton.cpp +++ b/CIO/CButton.cpp @@ -100,13 +100,13 @@ void CButton::setMouseData(const SDL_MouseMotionEvent& motion) if(motion.state == SDL_RELEASED) { marked = true; - if(motionEntryParam >= 0 && callback_ != nullptr) + if(motionEntryParam >= 0 && callback_) callback_(motionEntryParam); } } else { // button was marked before and mouse cursor is on the button now, so do the callback - if(motionLeaveParam >= 0 && callback_ != nullptr && marked == true) + if(motionLeaveParam >= 0 && callback_ && marked == true) callback_(motionLeaveParam); marked = false; } @@ -127,7 +127,7 @@ void CButton::setMouseData(const SDL_MouseButtonEvent& button) { clicked = false; // if mouse button is released ON the BUTTON (marked = true), then do the callback - if(marked && callback_ != nullptr) + if(marked && callback_) callback_(clickedParam); } } @@ -311,7 +311,7 @@ bool CButton::render() button_picture = -1; button_text = "PIC"; } - } else if(button_text != nullptr) + } else if(button_text) CFont::writeText(Surf_Button, button_text, (int)w / 2, (int)((h - 11) / 2), 11, button_text_color, ALIGN_MIDDLE); return true; diff --git a/CIO/CFile.cpp b/CIO/CFile.cpp index 8fd4475..b6153a6 100644 --- a/CIO/CFile.cpp +++ b/CIO/CFile.cpp @@ -24,10 +24,6 @@ bool CFile::loadPAL = false; if(!readCmd) \ throw std::runtime_error("Read failed at line " LINE_STRING) -CFile::CFile() {} - -CFile::~CFile() {} - void CFile::init() { fp = nullptr; @@ -42,10 +38,10 @@ void* CFile::open_file(const std::string& filename, char filetype, bool only_loa { void* return_value = nullptr; - if(filename.empty() || bmpArray == nullptr || shadowArray == nullptr || palArray == nullptr || palActual == nullptr) + if(filename.empty() || !bmpArray || !shadowArray || !palArray || !palActual) return nullptr; - else if((fp = boost::nowide::fopen(filename.c_str(), "rb")) == nullptr) + else if(!(fp = boost::nowide::fopen(filename.c_str(), "rb"))) return nullptr; if(only_loadPAL) @@ -103,7 +99,7 @@ void* CFile::open_file(const std::string& filename, char filetype, bool only_loa std::cerr << "Error while reading " << filename << ": " << e.what() << std::endl; } - if(fp != nullptr) + if(fp) { fclose(fp); fp = nullptr; @@ -213,7 +209,7 @@ bool CFile::open_idx(const std::string& filename) // save global filepointer fp_tmp = fp; // get a new filepointer to the '.IDX'-File - if((fp_idx = boost::nowide::fopen(filename.c_str(), "rb")) == nullptr) + if(!(fp_idx = boost::nowide::fopen(filename.c_str(), "rb"))) return false; // following code will open the corresponding '******.DAT'-File // allocate memory for new name @@ -226,7 +222,7 @@ bool CFile::open_idx(const std::string& filename) filename_dat[fileending + 1] = 'A'; filename_dat[fileending + 2] = 'T'; // get the filepointer of the corresponging '******.DAT'-File - if((fp_dat = boost::nowide::fopen(filename_dat.c_str(), "rb")) == nullptr) + if(!(fp_dat = boost::nowide::fopen(filename_dat.c_str(), "rb"))) return false; // we are finished opening the 'DAT'-File, now we can handle the content @@ -319,11 +315,11 @@ bool CFile::open_bbm() // skip header (48 Bytes) fseek(fp, 48, SEEK_CUR); - for(int i = 0; i < 256; i++) + for(auto& color : palArray->colors) { - CHECK_READ(libendian::read(&((palArray->colors[i]).r), 1, fp)); - CHECK_READ(libendian::read(&((palArray->colors[i]).g), 1, fp)); - CHECK_READ(libendian::read(&((palArray->colors[i]).b), 1, fp)); + CHECK_READ(libendian::read(&(color.r), 1, fp)); + CHECK_READ(libendian::read(&(color.g), 1, fp)); + CHECK_READ(libendian::read(&(color.b), 1, fp)); } palArray++; @@ -406,11 +402,11 @@ bool CFile::open_lbm(const std::string& filename) if(length != 3u * 256u) return false; // palette - for(int i = 0; i < 256; i++) + for(auto& color : colors) { - CHECK_READ(libendian::read(&colors[i].r, 1, fp)); - CHECK_READ(libendian::read(&colors[i].g, 1, fp)); - CHECK_READ(libendian::read(&colors[i].b, 1, fp)); + CHECK_READ(libendian::read(&color.r, 1, fp)); + CHECK_READ(libendian::read(&color.g, 1, fp)); + CHECK_READ(libendian::read(&color.b, 1, fp)); } /* READ THIRD CHUNK "BODY" */ @@ -438,7 +434,7 @@ bool CFile::open_lbm(const std::string& filename) CHECK_READ(libendian::be_read_ui(&length, fp)); // now we are ready to read the picture lines and fill the surface, so lets create one - if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == nullptr) + if(!(bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0))) return false; SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, colors, 0, 256); @@ -507,7 +503,7 @@ bool CFile::open_lbm(const std::string& filename) SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); bmpArray++; - if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, (bmpArray - 1)->w, (bmpArray - 1)->h, 32, 0, 0, 0, 0)) != nullptr) + if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, (bmpArray - 1)->w, (bmpArray - 1)->h, 32, 0, 0, 0, 0))) { SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); CSurface::Draw(bmpArray->surface, (bmpArray - 1)->surface, 0, 0); @@ -553,19 +549,19 @@ bobMAP* CFile::open_wld() CHECK_READ(libendian::read(&myMap->type, 1, fp)); CHECK_READ(libendian::read(&myMap->player, 1, fp)); CHECK_READ(libendian::read(myMap->author, 20, fp)); - for(int i = 0; i < 7; i++) - CHECK_READ(libendian::le_read_us(&myMap->HQx[i], fp)); - for(int i = 0; i < 7; i++) - CHECK_READ(libendian::le_read_us(&myMap->HQy[i], fp)); + for(unsigned short& i : myMap->HQx) + CHECK_READ(libendian::le_read_us(&i, fp)); + for(unsigned short& i : myMap->HQy) + CHECK_READ(libendian::le_read_us(&i, fp)); // go to big map header and read it fseek(fp, 92, SEEK_SET); - for(int i = 0; i < 250; i++) + for(auto& i : myMap->header) { - CHECK_READ(libendian::read(&myMap->header[i].type, 1, fp)); - CHECK_READ(libendian::le_read_us(&myMap->header[i].x, fp)); - CHECK_READ(libendian::le_read_us(&myMap->header[i].y, fp)); - CHECK_READ(libendian::le_read_ui(&myMap->header[i].area, fp)); + CHECK_READ(libendian::read(&i.type, 1, fp)); + CHECK_READ(libendian::le_read_us(&i.x, fp)); + CHECK_READ(libendian::le_read_us(&i.y, fp)); + CHECK_READ(libendian::le_read_ui(&i.area, fp)); } // go to real map height and width @@ -718,10 +714,10 @@ bool CFile::save_file(const std::string& filename, char filetype, void* data) { bool return_value = false; - if(filename.empty() || data == nullptr) + if(filename.empty() || !data) return return_value; - if((fp = boost::nowide::fopen(filename.c_str(), "wb")) == nullptr) + if(!(fp = boost::nowide::fopen(filename.c_str(), "wb"))) return return_value; switch(filetype) @@ -745,7 +741,7 @@ bool CFile::save_file(const std::string& filename, char filetype, void* data) break; } - if(fp != nullptr) + if(fp) { fclose(fp); fp = nullptr; @@ -817,21 +813,21 @@ bool CFile::save_wld(void* data) // author libendian::write(myMap->author, 20, fp); // headquarters x - for(int i = 0; i < 7; i++) - libendian::le_write_us(myMap->HQx[i], fp); + for(unsigned short i : myMap->HQx) + libendian::le_write_us(i, fp); // headquarters y - for(int i = 0; i < 7; i++) - libendian::le_write_us(myMap->HQy[i], fp); + for(unsigned short i : myMap->HQy) + libendian::le_write_us(i, fp); // unknown data (8 Bytes) for(int i = 0; i < 8; i++) libendian::write(&zero, 1, fp); // big map header with area information - for(int i = 0; i < 250; i++) + for(auto& i : myMap->header) { - libendian::write(&myMap->header[i].type, 1, fp); - libendian::le_write_us(myMap->header[i].x, fp); - libendian::le_write_us(myMap->header[i].y, fp); - libendian::le_write_ui(myMap->header[i].area, fp); + libendian::write(&i.type, 1, fp); + libendian::le_write_us(i.x, fp); + libendian::le_write_us(i.y, fp); + libendian::le_write_ui(i.area, fp); } // 0x11 0x27 temp = 0x11; @@ -1293,11 +1289,11 @@ bool CFile::read_bob05() // skip: unknown data (1x 2 Bytes) fseek(fp, 2, SEEK_CUR); - for(int i = 0; i < 256; i++) + for(auto& color : palArray->colors) { - CHECK_READ(libendian::read(&((palArray->colors[i]).r), 1, fp)); - CHECK_READ(libendian::read(&((palArray->colors[i]).g), 1, fp)); - CHECK_READ(libendian::read(&((palArray->colors[i]).b), 1, fp)); + CHECK_READ(libendian::read(&(color.r), 1, fp)); + CHECK_READ(libendian::read(&(color.g), 1, fp)); + CHECK_READ(libendian::read(&(color.b), 1, fp)); } palArray++; diff --git a/CIO/CFile.h b/CIO/CFile.h index 02d4883..f86361b 100644 --- a/CIO/CFile.h +++ b/CIO/CFile.h @@ -24,8 +24,6 @@ class CFile private: // Methods - CFile(); - ~CFile(); static bool open_lst(); static bool open_bob(); // not implemented yet static bool open_idx(const std::string& filename); diff --git a/CIO/CFont.cpp b/CIO/CFont.cpp index dd8ea86..8b38c5b 100644 --- a/CIO/CFont.cpp +++ b/CIO/CFont.cpp @@ -56,12 +56,12 @@ void CFont::setMouseData(SDL_MouseButtonEvent button) if((button.x >= x_) && (button.x < x_ + w) && (button.y >= y_) && (button.y < y_ + h)) { // if mouse button is pressed ON the text - if((button.state == SDL_PRESSED) && callback != nullptr) + if((button.state == SDL_PRESSED) && callback) { setColor(FONT_ORANGE); } else if(button.state == SDL_RELEASED) { - if(color_ == FONT_ORANGE && callback != nullptr) + if(color_ == FONT_ORANGE && callback) callback(clickedParam); } } @@ -82,14 +82,13 @@ bool CFont::writeText(const char* string) // pointer to the chiffres if(!string) string = this->string_; + if(!string) + return false; const unsigned char* chiffre = reinterpret_cast(string); // counter for the drawed pixels (cause we dont want to draw outside of the surface) int pos_x = 0; int pos_y = 0; - if(string == nullptr && this->string_ == nullptr) - return false; - // now lets draw the chiffres while(*chiffre != '\0') { @@ -233,9 +232,9 @@ bool CFont::writeText(const char* string) pixel_ctr_w = pixel_ctr_w_tmp; w = pixel_ctr_w; h = pixel_ctr_h; - if(Surf_Font != nullptr) + if(Surf_Font) SDL_FreeSurface(Surf_Font); - if((Surf_Font = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == nullptr) + if(!(Surf_Font = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0))) return false; SDL_SetColorKey(Surf_Font, SDL_SRCCOLORKEY, SDL_MapRGB(Surf_Font->format, 0, 0, 0)); chiffre = reinterpret_cast(string); @@ -293,7 +292,7 @@ bool CFont::writeText(SDL_Surface* Surf_Dest, const char* string, int x, int y, int pos_x = x; int pos_y = y; - if(Surf_Dest == nullptr || string == nullptr) + if(!Surf_Dest || !string) return false; // only three sizes are available (in pixels) diff --git a/CIO/CMenu.cpp b/CIO/CMenu.cpp index 39de422..89c52da 100644 --- a/CIO/CMenu.cpp +++ b/CIO/CMenu.cpp @@ -11,22 +11,22 @@ CMenu::CMenu(int pic_background) { this->pic_background = pic_background; - for(int i = 0; i < MAXBUTTONS; i++) - buttons[i] = nullptr; - for(int i = 0; i < MAXTEXTS; i++) - texts[i] = nullptr; - for(int i = 0; i < MAXPICTURES; i++) - pictures[i] = nullptr; - for(int i = 0; i < MAXPICTURES; i++) + for(auto& button : buttons) + button = nullptr; + for(auto& text : texts) + text = nullptr; + for(auto& picture : pictures) + picture = nullptr; + for(auto& static_picture : static_pictures) { - static_pictures[i].x = 0; - static_pictures[i].y = 0; - static_pictures[i].pic = -1; + static_picture.x = 0; + static_picture.y = 0; + static_picture.pic = -1; } - for(int i = 0; i < MAXTEXTFIELDS; i++) - textfields[i] = nullptr; - for(int i = 0; i < MAXSELECTBOXES; i++) - selectboxes[i] = nullptr; + for(auto& textfield : textfields) + textfield = nullptr; + for(auto& selectbox : selectboxes) + selectbox = nullptr; Surf_Menu = nullptr; needSurface = true; @@ -38,16 +38,16 @@ CMenu::CMenu(int pic_background) CMenu::~CMenu() { - for(int i = 0; i < MAXBUTTONS; i++) - delete buttons[i]; - for(int i = 0; i < MAXTEXTS; i++) - delete texts[i]; - for(int i = 0; i < MAXPICTURES; i++) - delete pictures[i]; - for(int i = 0; i < MAXTEXTFIELDS; i++) - delete textfields[i]; - for(int i = 0; i < MAXSELECTBOXES; i++) - delete selectboxes[i]; + for(auto& button : buttons) + delete button; + for(auto& text : texts) + delete text; + for(auto& picture : pictures) + delete picture; + for(auto& textfield : textfields) + delete textfield; + for(auto& selectbox : selectboxes) + delete selectbox; SDL_FreeSurface(Surf_Menu); } @@ -59,55 +59,55 @@ void CMenu::setBackgroundPicture(int pic_background) void CMenu::setMouseData(const SDL_MouseMotionEvent& motion) { - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] != nullptr) - pictures[i]->setMouseData(motion); + if(picture) + picture->setMouseData(motion); } - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] != nullptr) - buttons[i]->setMouseData(motion); + if(button) + button->setMouseData(motion); } - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectbox : selectboxes) { - if(selectboxes[i] != nullptr) - selectboxes[i]->setMouseData(motion); + if(selectbox) + selectbox->setMouseData(motion); } needRender = true; } void CMenu::setMouseData(const SDL_MouseButtonEvent& button) { - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] != nullptr) - pictures[i]->setMouseData(button); + if(picture) + picture->setMouseData(button); } - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& i : buttons) { - if(buttons[i] != nullptr) - buttons[i]->setMouseData(button); + if(i) + i->setMouseData(button); } - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr) - textfields[i]->setMouseData(button); + if(textfield) + textfield->setMouseData(button); } - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectboxe : selectboxes) { - if(selectboxes[i] != nullptr) - selectboxes[i]->setMouseData(button); + if(selectboxe) + selectboxe->setMouseData(button); } needRender = true; } void CMenu::setKeyboardData(const SDL_KeyboardEvent& key) { - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr) - textfields[i]->setKeyboardData(key); + if(textfield) + textfield->setKeyboardData(key); } } @@ -117,13 +117,13 @@ CButton* CMenu::addButton(void callback(int), int clickedParam, Uint16 x, Uint16 if(x >= Surf_Menu->w || y >= Surf_Menu->h) return nullptr; - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] == nullptr) + if(!button) { - buttons[i] = new CButton(callback, clickedParam, x, y, w, h, color, text, picture); + button = new CButton(callback, clickedParam, x, y, w, h, color, text, picture); needRender = true; - return buttons[i]; + return button; } } return nullptr; @@ -131,15 +131,15 @@ CButton* CMenu::addButton(void callback(int), int clickedParam, Uint16 x, Uint16 bool CMenu::delButton(CButton* ButtonToDelete) { - if(ButtonToDelete == nullptr) + if(!ButtonToDelete) return false; - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] == ButtonToDelete) + if(button == ButtonToDelete) { - delete buttons[i]; - buttons[i] = nullptr; + delete button; + button = nullptr; needRender = true; return true; } @@ -152,13 +152,13 @@ CFont* CMenu::addText(const char* string, int x, int y, int fontsize, int color) if(x >= Surf_Menu->w || y >= Surf_Menu->h) return nullptr; - for(int i = 0; i < MAXTEXTS; i++) + for(auto& text : texts) { - if(texts[i] == nullptr) + if(!text) { - texts[i] = new CFont(string, x, y, fontsize, color); + text = new CFont(string, x, y, fontsize, color); needRender = true; - return texts[i]; + return text; } } return nullptr; @@ -166,15 +166,15 @@ CFont* CMenu::addText(const char* string, int x, int y, int fontsize, int color) bool CMenu::delText(CFont* TextToDelete) { - if(TextToDelete == nullptr) + if(!TextToDelete) return false; - for(int i = 0; i < MAXTEXTS; i++) + for(auto& text : texts) { - if(texts[i] == TextToDelete) + if(text == TextToDelete) { - delete texts[i]; - texts[i] = nullptr; + delete text; + text = nullptr; needRender = true; return true; } @@ -184,16 +184,13 @@ bool CMenu::delText(CFont* TextToDelete) CPicture* CMenu::addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture) { - if(x >= global::s2->MenuResolutionX || y >= global::s2->MenuResolutionY) - return nullptr; - - for(int i = 0; i < MAXPICTURES; i++) + for(auto& i : pictures) { - if(pictures[i] == nullptr) + if(!i) { - pictures[i] = new CPicture(callback, clickedParam, x, y, picture); + i = new CPicture(callback, clickedParam, x, y, picture); needRender = true; - return pictures[i]; + return i; } } return nullptr; @@ -201,15 +198,15 @@ CPicture* CMenu::addPicture(void callback(int), int clickedParam, Uint16 x, Uint bool CMenu::delPicture(CPicture* PictureToDelete) { - if(PictureToDelete == nullptr) + if(!PictureToDelete) return false; - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] == PictureToDelete) + if(picture == PictureToDelete) { - delete pictures[i]; - pictures[i] = nullptr; + delete picture; + picture = nullptr; needRender = true; return true; } @@ -219,9 +216,6 @@ bool CMenu::delPicture(CPicture* PictureToDelete) int CMenu::addStaticPicture(int x, int y, int picture) { - if(x >= global::s2->MenuResolutionX || y >= global::s2->MenuResolutionY) - return -1; - if(picture < 0) return -1; @@ -257,13 +251,13 @@ CTextfield* CMenu::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, in if(x >= Surf_Menu->w || y >= Surf_Menu->h) return nullptr; - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] == nullptr) + if(!textfield) { - textfields[i] = new CTextfield(x, y, cols, rows, fontsize, text_color, bg_color, button_style); + textfield = new CTextfield(x, y, cols, rows, fontsize, text_color, bg_color, button_style); needRender = true; - return textfields[i]; + return textfield; } } return nullptr; @@ -271,15 +265,15 @@ CTextfield* CMenu::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, in bool CMenu::delTextfield(CTextfield* TextfieldToDelete) { - if(TextfieldToDelete == nullptr) + if(!TextfieldToDelete) return false; - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] == TextfieldToDelete) + if(textfield == TextfieldToDelete) { - delete textfields[i]; - textfields[i] = nullptr; + delete textfield; + textfield = nullptr; needRender = true; return true; } @@ -292,13 +286,13 @@ CSelectBox* CMenu::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int font if(x >= Surf_Menu->w || y >= Surf_Menu->h) return nullptr; - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectboxe : selectboxes) { - if(selectboxes[i] == nullptr) + if(!selectboxe) { - selectboxes[i] = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); + selectboxe = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); needRender = true; - return selectboxes[i]; + return selectboxe; } } return nullptr; @@ -306,15 +300,15 @@ CSelectBox* CMenu::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int font bool CMenu::delSelectBox(CSelectBox* SelectBoxToDelete) { - if(SelectBoxToDelete == nullptr) + if(!SelectBoxToDelete) return false; - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectbox : selectboxes) { - if(selectboxes[i] == SelectBoxToDelete) + if(selectbox == SelectBoxToDelete) { - delete selectboxes[i]; - selectboxes[i] = nullptr; + delete selectbox; + selectbox = nullptr; needRender = true; return true; } @@ -335,8 +329,8 @@ bool CMenu::render() if(needSurface) { SDL_FreeSurface(Surf_Menu); - Surf_Menu = nullptr; - if((Surf_Menu = SDL_CreateRGBSurface(SDL_SWSURFACE, global::s2->getResX(), global::s2->getResY(), 32, 0, 0, 0, 0)) == nullptr) + Surf_Menu = SDL_CreateRGBSurface(SDL_SWSURFACE, global::s2->getRes().x, global::s2->getRes().y, 32, 0, 0, 0, 0); + if(!Surf_Menu) return false; needSurface = false; } @@ -346,35 +340,35 @@ bool CMenu::render() sge_TexturedRect(Surf_Menu, 0, 0, Surf_Menu->w - 1, 0, 0, Surf_Menu->h - 1, Surf_Menu->w - 1, Surf_Menu->h - 1, surfBG, 0, 0, surfBG->w - 1, 0, 0, surfBG->h - 1, surfBG->w - 1, surfBG->h - 1); - for(int i = 0; i < MAXPICTURES; i++) + for(auto& static_picture : static_pictures) { - if(static_pictures[i].pic >= 0) - CSurface::Draw(Surf_Menu, global::bmpArray[static_pictures[i].pic].surface, static_pictures[i].x, static_pictures[i].y); + if(static_picture.pic >= 0) + CSurface::Draw(Surf_Menu, global::bmpArray[static_picture.pic].surface, static_picture.x, static_picture.y); } - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] != nullptr) - CSurface::Draw(Surf_Menu, pictures[i]->getSurface(), pictures[i]->getX(), pictures[i]->getY()); + if(picture) + CSurface::Draw(Surf_Menu, picture->getSurface(), picture->getX(), picture->getY()); } - for(int i = 0; i < MAXTEXTS; i++) + for(auto& text : texts) { - if(texts[i] != nullptr) - CSurface::Draw(Surf_Menu, texts[i]->getSurface(), texts[i]->getX(), texts[i]->getY()); + if(text) + CSurface::Draw(Surf_Menu, text->getSurface(), text->getX(), text->getY()); } - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr) - CSurface::Draw(Surf_Menu, textfields[i]->getSurface(), textfields[i]->getX(), textfields[i]->getY()); + if(textfield) + CSurface::Draw(Surf_Menu, textfield->getSurface(), textfield->getX(), textfield->getY()); } - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectbox : selectboxes) { - if(selectboxes[i] != nullptr) - CSurface::Draw(Surf_Menu, selectboxes[i]->getSurface(), selectboxes[i]->getX(), selectboxes[i]->getY()); + if(selectbox) + CSurface::Draw(Surf_Menu, selectbox->getSurface(), selectbox->getX(), selectbox->getY()); } - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] != nullptr) - CSurface::Draw(Surf_Menu, buttons[i]->getSurface(), buttons[i]->getX(), buttons[i]->getY()); + if(button) + CSurface::Draw(Surf_Menu, button->getSurface(), button->getX(), button->getY()); } return true; diff --git a/CIO/CPicture.cpp b/CIO/CPicture.cpp index 3e9ad64..2fbc4c9 100644 --- a/CIO/CPicture.cpp +++ b/CIO/CPicture.cpp @@ -36,13 +36,13 @@ void CPicture::setMouseData(const SDL_MouseMotionEvent& motion) if(motion.state == SDL_RELEASED) { marked = true; - if(motionEntryParam >= 0 && callback != nullptr) + if(motionEntryParam >= 0 && callback) callback(motionEntryParam); } } else { // picture was marked before and mouse cursor is on the picture now, so do the callback - if(motionLeaveParam >= 0 && callback != nullptr && marked == true) + if(motionLeaveParam >= 0 && callback && marked == true) callback(motionLeaveParam); marked = false; } @@ -63,7 +63,7 @@ void CPicture::setMouseData(const SDL_MouseButtonEvent& button) { clicked = false; // if mouse button is released ON the PICTURE (marked = true), then do the callback - if(marked && callback != nullptr) + if(marked && callback) callback(clickedParam); } } @@ -80,8 +80,8 @@ bool CPicture::render() if(needSurface) { SDL_FreeSurface(Surf_Picture); - Surf_Picture = nullptr; - if((Surf_Picture = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == nullptr) + Surf_Picture = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0); + if(!Surf_Picture) return false; SDL_SetColorKey(Surf_Picture, SDL_SRCCOLORKEY, SDL_MapRGB(Surf_Picture->format, 0, 0, 0)); needSurface = false; diff --git a/CIO/CSelectBox.cpp b/CIO/CSelectBox.cpp index e3f7fef..59e9913 100644 --- a/CIO/CSelectBox.cpp +++ b/CIO/CSelectBox.cpp @@ -15,8 +15,8 @@ CSelectBox::CSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int this->text_color = text_color; setColor(bg_color); // initialize CFont array - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - Entries[i] = nullptr; + for(auto& entry : Entries) + entry = nullptr; Surf_SelectBox = nullptr; needSurface = true; @@ -29,12 +29,12 @@ CSelectBox::CSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int CSelectBox::~CSelectBox() { - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + for(auto& entry : Entries) { - if(Entries[i]) + if(entry) { - delete Entries[i]; - Entries[i] = nullptr; + delete entry; + entry = nullptr; } } delete ScrollUpButton; @@ -47,12 +47,12 @@ void CSelectBox::setOption(const char* string, void (*callback)(int), int param) // explanation: row_height = row_separator + fontsize int row_height = (fontsize == 9 ? 1 : (fontsize == 11 ? 3 : 4)) + fontsize; - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + for(auto& Entry : Entries) { - if(Entries[i] == nullptr) + if(!Entry) { - Entries[i] = new CFont(string, 10, last_text_pos_y, fontsize, FONT_YELLOW); - Entries[i]->setCallback(callback, param); + Entry = new CFont(string, 10, last_text_pos_y, fontsize, FONT_YELLOW); + Entry->setCallback(callback, param); last_text_pos_y += row_height; break; } @@ -154,10 +154,10 @@ void CSelectBox::setMouseData(SDL_MouseButtonEvent button) button.y -= y_; manipulated = true; - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + for(auto& entry : Entries) { - if(Entries[i] != nullptr) - Entries[i]->setMouseData(button); + if(entry) + entry->setMouseData(button); } } } else if(button.state == SDL_RELEASED) @@ -172,10 +172,10 @@ void CSelectBox::setMouseData(SDL_MouseButtonEvent button) // test if first entry is on the most upper position if(Entries[0] != nullptr && Entries[0]->getY() < 10) { - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + for(auto& entry : Entries) { - if(Entries[i] != nullptr) - Entries[i]->setY(Entries[i]->getY() + 10); + if(entry) + entry->setY(entry->getY() + 10); } } } @@ -195,10 +195,10 @@ void CSelectBox::setMouseData(SDL_MouseButtonEvent button) j--; if(j >= 0 && Entries[j] != nullptr && Entries[j]->getY() > h_ - 10) { - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + for(auto& entry : Entries) { - if(Entries[i] != nullptr) - Entries[i]->setY(Entries[i]->getY() - 10); + if(entry) + entry->setY(entry->getY() - 10); } } } @@ -210,10 +210,10 @@ void CSelectBox::setMouseData(SDL_MouseButtonEvent button) button.y -= y_; manipulated = true; - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + for(auto& entry : Entries) { - if(Entries[i] != nullptr) - Entries[i]->setMouseData(button); + if(entry) + entry->setMouseData(button); } } scroll_up_button_marked = false; @@ -303,10 +303,10 @@ bool CSelectBox::render() } else SDL_FillRect(Surf_SelectBox, nullptr, SDL_MapRGB(Surf_SelectBox->format, 0, 0, 0)); - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + for(auto& entry : Entries) { - if(Entries[i] != nullptr) - CSurface::Draw(Surf_SelectBox, Entries[i]->getSurface(), Entries[i]->getX(), Entries[i]->getY()); + if(entry) + CSurface::Draw(Surf_SelectBox, entry->getSurface(), entry->getX(), entry->getY()); } CSurface::Draw(Surf_SelectBox, ScrollUpButton->getSurface(), w_ - 1 - 20, 0); diff --git a/CIO/CTextfield.cpp b/CIO/CTextfield.cpp index 5c3ae2a..dbec670 100644 --- a/CIO/CTextfield.cpp +++ b/CIO/CTextfield.cpp @@ -266,8 +266,8 @@ bool CTextfield::render() if(needSurface) { SDL_FreeSurface(Surf_Text); - Surf_Text = nullptr; - if((Surf_Text = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == nullptr) + Surf_Text = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0); + if(!Surf_Text) return false; needSurface = false; } diff --git a/CIO/CWindow.cpp b/CIO/CWindow.cpp index b1495f7..e1b35ff 100644 --- a/CIO/CWindow.cpp +++ b/CIO/CWindow.cpp @@ -39,22 +39,22 @@ CWindow::CWindow(void callback(int), int callbackQuitMessage, Uint16 x, Uint16 y minimized = false; priority = 0; pic_background = color; - for(int i = 0; i < MAXBUTTONS; i++) - buttons[i] = nullptr; - for(int i = 0; i < MAXTEXTS; i++) - texts[i] = nullptr; - for(int i = 0; i < MAXPICTURES; i++) - pictures[i] = nullptr; - for(int i = 0; i < MAXPICTURES; i++) - { - static_pictures[i].x_ = 0; - static_pictures[i].y_ = 0; - static_pictures[i].pic = -1; - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - textfields[i] = nullptr; - for(int i = 0; i < MAXSELECTBOXES; i++) - selectboxes[i] = nullptr; + for(auto& button : buttons) + button = nullptr; + for(auto& text : texts) + text = nullptr; + for(auto& picture : pictures) + picture = nullptr; + for(auto& static_picture : static_pictures) + { + static_picture.x_ = 0; + static_picture.y_ = 0; + static_picture.pic = -1; + } + for(auto& textfield : textfields) + textfield = nullptr; + for(auto& selectboxe : selectboxes) + selectboxe = nullptr; this->title = title; this->callback_ = callback; @@ -70,16 +70,16 @@ CWindow::CWindow(void callback(int), int callbackQuitMessage, Uint16 x, Uint16 y CWindow::~CWindow() { - for(int i = 0; i < MAXBUTTONS; i++) - delete buttons[i]; - for(int i = 0; i < MAXTEXTS; i++) - delete texts[i]; - for(int i = 0; i < MAXPICTURES; i++) - delete pictures[i]; - for(int i = 0; i < MAXTEXTFIELDS; i++) - delete textfields[i]; - for(int i = 0; i < MAXSELECTBOXES; i++) - delete selectboxes[i]; + for(auto& button : buttons) + delete button; + for(auto& text : texts) + delete text; + for(auto& picture : pictures) + delete picture; + for(auto& textfield : textfields) + delete textfield; + for(auto& selectboxe : selectboxes) + delete selectboxe; SDL_FreeSurface(Surf_Window); } @@ -97,8 +97,8 @@ void CWindow::setColor(int color) bool CWindow::hasActiveInputElement() { - for(int i = 0; i < MAXTEXTFIELDS; i++) - if(textfields[i] != nullptr && textfields[i]->isActive()) + for(auto& textfield : textfields) + if(textfield && textfield->isActive()) return true; return false; } @@ -192,20 +192,20 @@ void CWindow::setMouseData(SDL_MouseMotionEvent motion) // the motion-structure before give it to buttons, pictures....: x_absolute - x_window, y_absolute - y_window motion.x -= x_; motion.y -= y_; - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] != nullptr) - pictures[i]->setMouseData(motion); + if(picture) + picture->setMouseData(motion); } - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] != nullptr) - buttons[i]->setMouseData(motion); + if(button) + button->setMouseData(motion); } - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectboxe : selectboxes) { - if(selectboxes[i] != nullptr) - selectboxes[i]->setMouseData(motion); + if(selectboxe) + selectboxe->setMouseData(motion); } } @@ -253,7 +253,7 @@ void CWindow::setMouseData(SDL_MouseButtonEvent button) { canClose_clicked = false; // if mouse button is released ON the close button (marked = true), then send the quit message to the callback - if(canClose_marked && callback_ != nullptr) + if(canClose_marked && callback_) { callback_(callbackQuitMessage); return; @@ -299,25 +299,25 @@ void CWindow::setMouseData(SDL_MouseButtonEvent button) // the motion-structure before give it to buttons, pictures....: x_absolute - x_window, y_absolute - y_window button.x -= x_; button.y -= y_; - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] != nullptr) - pictures[i]->setMouseData(button); + if(picture) + picture->setMouseData(button); } - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& i : buttons) { - if(buttons[i] != nullptr) - buttons[i]->setMouseData(button); + if(i) + i->setMouseData(button); } - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr) - textfields[i]->setMouseData(button); + if(textfield) + textfield->setMouseData(button); } - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectboxe : selectboxes) { - if(selectboxes[i] != nullptr) - selectboxes[i]->setMouseData(button); + if(selectboxe) + selectboxe->setMouseData(button); } } @@ -329,10 +329,10 @@ void CWindow::setMouseData(SDL_MouseButtonEvent button) void CWindow::setKeyboardData(const SDL_KeyboardEvent& key) { - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr) - textfields[i]->setKeyboardData(key); + if(textfield) + textfield->setKeyboardData(key); } needRender = true; } @@ -344,13 +344,13 @@ CButton* CWindow::addButton(void callback(int), int clickedParam, Uint16 x, Uint int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] == nullptr) + if(!button) { - buttons[i] = new CButton(callback, clickedParam, x_abs, y_abs, w, h, color, text, picture); + button = new CButton(callback, clickedParam, x_abs, y_abs, w, h, color, text, picture); needRender = true; - return buttons[i]; + return button; } } return nullptr; @@ -358,15 +358,15 @@ CButton* CWindow::addButton(void callback(int), int clickedParam, Uint16 x, Uint bool CWindow::delButton(CButton* ButtonToDelete) { - if(ButtonToDelete == nullptr) + if(!ButtonToDelete) return false; - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] == ButtonToDelete) + if(button == ButtonToDelete) { - delete buttons[i]; - buttons[i] = nullptr; + delete button; + button = nullptr; needRender = true; return true; } @@ -380,13 +380,13 @@ CFont* CWindow::addText(const char* string, int x, int y, int fontsize, int colo int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - for(int i = 0; i < MAXTEXTS; i++) + for(auto& text : texts) { - if(texts[i] == nullptr) + if(!text) { - texts[i] = new CFont(string, x_abs, y_abs, fontsize, color); + text = new CFont(string, x_abs, y_abs, fontsize, color); needRender = true; - return texts[i]; + return text; } } return nullptr; @@ -394,15 +394,15 @@ CFont* CWindow::addText(const char* string, int x, int y, int fontsize, int colo bool CWindow::delText(CFont* TextToDelete) { - if(TextToDelete == nullptr) + if(!TextToDelete) return false; - for(int i = 0; i < MAXTEXTS; i++) + for(auto& text : texts) { - if(texts[i] == TextToDelete) + if(text == TextToDelete) { - delete texts[i]; - texts[i] = nullptr; + delete text; + text = nullptr; needRender = true; return true; } @@ -416,13 +416,13 @@ CPicture* CWindow::addPicture(void callback(int), int clickedParam, Uint16 x, Ui int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - for(int i = 0; i < MAXPICTURES; i++) + for(auto& i : pictures) { - if(pictures[i] == nullptr) + if(!i) { - pictures[i] = new CPicture(callback, clickedParam, x_abs, y_abs, picture); + i = new CPicture(callback, clickedParam, x_abs, y_abs, picture); needRender = true; - return pictures[i]; + return i; } } return nullptr; @@ -430,15 +430,15 @@ CPicture* CWindow::addPicture(void callback(int), int clickedParam, Uint16 x, Ui bool CWindow::delPicture(CPicture* PictureToDelete) { - if(PictureToDelete == nullptr) + if(!PictureToDelete) return false; - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] == PictureToDelete) + if(picture == PictureToDelete) { - delete pictures[i]; - pictures[i] = nullptr; + delete picture; + picture = nullptr; needRender = true; return true; } @@ -489,13 +489,13 @@ CTextfield* CWindow::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] == nullptr) + if(!textfield) { - textfields[i] = new CTextfield(x_abs, y_abs, cols, rows, fontsize, text_color, bg_color, button_style); + textfield = new CTextfield(x_abs, y_abs, cols, rows, fontsize, text_color, bg_color, button_style); needRender = true; - return textfields[i]; + return textfield; } } return nullptr; @@ -503,15 +503,15 @@ CTextfield* CWindow::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, bool CWindow::delTextfield(CTextfield* TextfieldToDelete) { - if(TextfieldToDelete == nullptr) + if(!TextfieldToDelete) return false; - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] == TextfieldToDelete) + if(textfield == TextfieldToDelete) { - delete textfields[i]; - textfields[i] = nullptr; + delete textfield; + textfield = nullptr; needRender = true; return true; } @@ -521,16 +521,16 @@ bool CWindow::delTextfield(CTextfield* TextfieldToDelete) CSelectBox* CWindow::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int text_color, int bg_color) { - if(Surf_Window != nullptr && (x >= Surf_Window->w || y >= Surf_Window->h)) + if(Surf_Window && (x >= Surf_Window->w || y >= Surf_Window->h)) return nullptr; - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectboxe : selectboxes) { - if(selectboxes[i] == nullptr) + if(!selectboxe) { - selectboxes[i] = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); + selectboxe = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); needRender = true; - return selectboxes[i]; + return selectboxe; } } return nullptr; @@ -538,15 +538,15 @@ CSelectBox* CWindow::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fo bool CWindow::delSelectBox(CSelectBox* SelectBoxToDelete) { - if(SelectBoxToDelete == nullptr) + if(!SelectBoxToDelete) return false; - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectboxe : selectboxes) { - if(selectboxes[i] == SelectBoxToDelete) + if(selectboxe == SelectBoxToDelete) { - delete selectboxes[i]; - selectboxes[i] = nullptr; + delete selectboxe; + selectboxe = nullptr; needRender = true; return true; } @@ -572,10 +572,10 @@ bool CWindow::render() int resizebutton = WINDOW_BUTTON_RESIZE; // test if a textfield has changed - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr) - if(textfields[i]->hasRendered()) + if(textfield) + if(textfield->hasRendered()) needRender = true; } @@ -638,35 +638,35 @@ bool CWindow::render() // if not minimized, draw the content now (this stands here to prevent the frames and corners from being overdrawn) if(!minimized) { - for(int i = 0; i < MAXBUTTONS; i++) + for(auto& button : buttons) { - if(buttons[i] != nullptr && buttons[i]->getX() < Surf_Window->w && buttons[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, buttons[i]->getSurface(), buttons[i]->getX(), buttons[i]->getY()); + if(button && button->getX() < Surf_Window->w && button->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, button->getSurface(), button->getX(), button->getY()); } - for(int i = 0; i < MAXPICTURES; i++) + for(auto& static_picture : static_pictures) { - if(static_pictures[i].pic >= 0 && static_pictures[i].x_ < Surf_Window->w && static_pictures[i].y_ < Surf_Window->h) - CSurface::Draw(Surf_Window, global::bmpArray[static_pictures[i].pic].surface, static_pictures[i].x_, static_pictures[i].y_); + if(static_picture.pic >= 0 && static_picture.x_ < Surf_Window->w && static_picture.y_ < Surf_Window->h) + CSurface::Draw(Surf_Window, global::bmpArray[static_picture.pic].surface, static_picture.x_, static_picture.y_); } - for(int i = 0; i < MAXPICTURES; i++) + for(auto& picture : pictures) { - if(pictures[i] != nullptr && pictures[i]->getX() < Surf_Window->w && pictures[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, pictures[i]->getSurface(), pictures[i]->getX(), pictures[i]->getY()); + if(picture && picture->getX() < Surf_Window->w && picture->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, picture->getSurface(), picture->getX(), picture->getY()); } - for(int i = 0; i < MAXTEXTS; i++) + for(auto& text : texts) { - if(texts[i] != nullptr && texts[i]->getX() < Surf_Window->w && texts[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, texts[i]->getSurface(), texts[i]->getX(), texts[i]->getY()); + if(text && text->getX() < Surf_Window->w && text->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, text->getSurface(), text->getX(), text->getY()); } - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr && textfields[i]->getX() < Surf_Window->w && textfields[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, textfields[i]->getSurface(), textfields[i]->getX(), textfields[i]->getY()); + if(textfield && textfield->getX() < Surf_Window->w && textfield->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, textfield->getSurface(), textfield->getX(), textfield->getY()); } - for(int i = 0; i < MAXSELECTBOXES; i++) + for(auto& selectboxe : selectboxes) { - if(selectboxes[i] != nullptr) - CSurface::Draw(Surf_Window, selectboxes[i]->getSurface(), selectboxes[i]->getX(), selectboxes[i]->getY()); + if(selectboxe) + CSurface::Draw(Surf_Window, selectboxe->getSurface(), selectboxe->getX(), selectboxe->getY()); } } @@ -694,7 +694,7 @@ bool CWindow::render() if(Surf_Window->w - pos_x > 0) CSurface::Draw(Surf_Window, global::bmpArray[upperframe].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); // write text in the upper frame - if(title != nullptr) + if(title) CFont::writeText(Surf_Window, title, (int)w_ / 2, (int)((global::bmpArray[WINDOW_UPPER_FRAME].h - 9) / 2), 9, FONT_YELLOW, ALIGN_MIDDLE); @@ -800,9 +800,9 @@ void CWindow::setInactive() marked = false; needRender = true; - for(int i = 0; i < MAXTEXTFIELDS; i++) + for(auto& textfield : textfields) { - if(textfields[i] != nullptr) - textfields[i]->setInactive(); + if(textfield) + textfield->setInactive(); } } diff --git a/CIO/CWindow.h b/CIO/CWindow.h index 47ed72f..8c45e96 100644 --- a/CIO/CWindow.h +++ b/CIO/CWindow.h @@ -65,6 +65,7 @@ class CWindow int getY() { return y_; }; int getW() { return w_; }; int getH() { return h_; }; + Rect getRect() const { return Rect(x_, y_, w_, h_); } int getPriority() { return priority; } void setPriority(int priority) { this->priority = priority; } void setTitle(const char* title); diff --git a/CMap.cpp b/CMap.cpp index da9b1ef..2be3c20 100644 --- a/CMap.cpp +++ b/CMap.cpp @@ -66,15 +66,14 @@ void CMap::constructMap(const std::string& filename, int width, int height, int map = nullptr; Surf_Map = nullptr; Surf_RightMenubar = nullptr; - displayRect.x = 0; - displayRect.y = 0; - displayRect.w = global::s2->GameResolutionX; - displayRect.h = global::s2->GameResolutionY; + displayRect.left = 0; + displayRect.top = 0; + displayRect.setSize(global::s2->GameResolution); if(!filename.empty()) map = (bobMAP*)CFile::open_file(filename, WLD); - if(map == nullptr) + if(!map) map = generateMap(width, height, type, texture, border, border_texture); // load the right MAP0x.LST for all pictures @@ -201,7 +200,7 @@ void CMap::destructMap() // free all surfaces that MAP0x.LST needed unloadMapPics(); // free concatenated list for "undo" and "do" - if(CurrPtr_savedVertices != nullptr) + if(CurrPtr_savedVertices) { // go to the end while(CurrPtr_savedVertices->next != nullptr) @@ -290,7 +289,7 @@ void CMap::rotateMap() std::vector new_vertex(map->vertex.size()); // free concatenated list for "undo" and "do" - if(CurrPtr_savedVertices != nullptr) + if(CurrPtr_savedVertices) { // go to the end while(CurrPtr_savedVertices->next != nullptr) @@ -375,8 +374,8 @@ void CMap::rotateMap() MouseBlitX = correctMouseBlitX(VertexX_, VertexY_); MouseBlitY = correctMouseBlitY(VertexX_, VertexY_); calculateVertices(); - displayRect.x = 0; - displayRect.y = 0; + displayRect.left = 0; + displayRect.top = 0; } void CMap::MirrorMapOnXAxis() @@ -510,41 +509,38 @@ void CMap::unloadMapPics() CFile::set_palArray(&global::palArray[PAL_IO + 1]); } +void CMap::moveMap(Position offset) +{ + displayRect.setOrigin(displayRect.getOrigin() + offset); + // reset coords of displayRects when end of map is reached + if(displayRect.left >= map->width_pixel) + displayRect.move(Position(-map->width_pixel, 0)); + else if(displayRect.left <= -static_cast(displayRect.getSize().x)) + displayRect.setOrigin(Position(map->width_pixel - displayRect.getSize().x, displayRect.top)); + + if(displayRect.top >= map->height_pixel) + displayRect.move(Position(0, -map->height_pixel)); + else if(displayRect.top <= -static_cast(displayRect.getSize().y)) + displayRect.setOrigin(Position(displayRect.left, map->height_pixel - displayRect.getSize().y)); +} + void CMap::setMouseData(const SDL_MouseMotionEvent& motion) { // following code important for blitting the right field of the map - static bool warping = false; - // SDL_Event TempEvent; // is right mouse button pressed? if(motion.state & SDL_BUTTON(3)) { - // this whole "warping-thing" is to prevent cursor-moving WITHIN the window while user moves over the map - if(warping == false) - { - if(!HorizontalMovementLocked) - displayRect.x += motion.xrel; - if(!VerticalMovementLocked) - displayRect.y += motion.yrel; - - // warping = true; - SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); - SDL_WarpMouse(motion.x - motion.xrel, motion.y - motion.yrel); - SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); - // SDL_PumpEvents(); - // SDL_PeepEvents(&TempEvent, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)); - } else - warping = false; + Position offset{}; + if(!HorizontalMovementLocked) + offset.x = motion.xrel; + if(!VerticalMovementLocked) + offset.y = motion.yrel; + moveMap(offset); - // reset coords of displayRects when end of map is reached - if(displayRect.x >= map->width * TRIANGLE_WIDTH) - displayRect.x = 0; - else if(displayRect.x <= -displayRect.w) - displayRect.x = map->width * TRIANGLE_WIDTH - displayRect.w; - - if(displayRect.y >= map->height * TRIANGLE_HEIGHT) - displayRect.y = 0; - else if(displayRect.y <= -displayRect.h) - displayRect.y = map->height * TRIANGLE_HEIGHT - displayRect.h; + // this whole "warping-thing" is to prevent cursor-moving WITHIN the window while user moves over the map + SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); + SDL_WarpMouse(motion.x - motion.xrel, motion.y - motion.yrel); + SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); } saveVertex(motion.x, motion.y, motion.state); @@ -557,49 +553,56 @@ void CMap::setMouseData(const SDL_MouseButtonEvent& button) #ifdef _EDITORMODE // find out if user clicked on one of the game menu pictures // we start with lower menubar - if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 236) && button.x <= (displayRect.w / 2 - 199) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 236) + && button.x <= (displayRect.getSize().x / 2 - 199) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the height-mode picture was clicked mode = EDITOR_MODE_HEIGHT_RAISE; return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 199) && button.x <= (displayRect.w / 2 - 162) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 199) + && button.x <= (displayRect.getSize().x / 2 - 162) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the texture-mode picture was clicked mode = EDITOR_MODE_TEXTURE; callback::EditorTextureMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 162) && button.x <= (displayRect.w / 2 - 125) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 162) + && button.x <= (displayRect.getSize().x / 2 - 125) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the tree-mode picture was clicked mode = EDITOR_MODE_TREE; callback::EditorTreeMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 125) && button.x <= (displayRect.w / 2 - 88) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 125) + && button.x <= (displayRect.getSize().x / 2 - 88) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the resource-mode picture was clicked mode = EDITOR_MODE_RESOURCE_RAISE; callback::EditorResourceMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 88) && button.x <= (displayRect.w / 2 - 51) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 88) + && button.x <= (displayRect.getSize().x / 2 - 51) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the landscape-mode picture was clicked mode = EDITOR_MODE_LANDSCAPE; callback::EditorLandscapeMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 51) && button.x <= (displayRect.w / 2 - 14) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 51) + && button.x <= (displayRect.getSize().x / 2 - 14) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the animal-mode picture was clicked mode = EDITOR_MODE_ANIMAL; callback::EditorAnimalMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 14) && button.x <= (displayRect.w / 2 + 23) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 14) + && button.x <= (displayRect.getSize().x / 2 + 23) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the player-mode picture was clicked mode = EDITOR_MODE_FLAG; @@ -607,34 +610,38 @@ void CMap::setMouseData(const SDL_MouseButtonEvent& button) setupVerticesActivity(); callback::EditorPlayerMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 96) && button.x <= (displayRect.w / 2 + 133) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 + 96) + && button.x <= (displayRect.getSize().x / 2 + 133) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the build-help picture was clicked RenderBuildHelp = !RenderBuildHelp; return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 131) && button.x <= (displayRect.w / 2 + 168) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 + 131) + && button.x <= (displayRect.getSize().x / 2 + 168) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the minimap picture was clicked callback::MinimapMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 166) && button.x <= (displayRect.w / 2 + 203) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 + 166) + && button.x <= (displayRect.getSize().x / 2 + 203) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the create-world picture was clicked callback::EditorCreateMenu(INITIALIZING_CALL); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 203) && button.x <= (displayRect.w / 2 + 240) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 + 203) + && button.x <= (displayRect.getSize().x / 2 + 240) && button.y >= (displayRect.getSize().y - 35) + && button.y <= (displayRect.getSize().y - 3)) { // the editor-main-menu picture was clicked callback::EditorMainMenu(INITIALIZING_CALL); return; } // now we check the right menubar - else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) - && button.y >= (displayRect.h / 2 + 162) && button.y <= (displayRect.h / 2 + 199)) + else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x - 37) && button.x <= (displayRect.getSize().x) + && button.y >= (displayRect.getSize().y / 2 + 162) && button.y <= (displayRect.getSize().y / 2 + 199)) { // the bugkill picture was clicked for quickload callback::PleaseWait(INITIALIZING_CALL); @@ -652,8 +659,8 @@ void CMap::setMouseData(const SDL_MouseButtonEvent& button) constructMap(global::userMapsPath + "/quicksave.swd"); callback::PleaseWait(WINDOW_QUIT_MESSAGE); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) - && button.y >= (displayRect.h / 2 + 200) && button.y <= (displayRect.h / 2 + 237)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x - 37) && button.x <= (displayRect.getSize().x) + && button.y >= (displayRect.getSize().y / 2 + 200) && button.y <= (displayRect.getSize().y / 2 + 237)) { // the bugkill picture was clicked for quicksave callback::PleaseWait(INITIALIZING_CALL); @@ -664,8 +671,8 @@ void CMap::setMouseData(const SDL_MouseButtonEvent& button) } callback::PleaseWait(WINDOW_QUIT_MESSAGE); return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) - && button.y >= (displayRect.h / 2 - 239) && button.y <= (displayRect.h / 2 - 202)) + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x - 37) && button.x <= (displayRect.getSize().x) + && button.y >= (displayRect.getSize().y / 2 - 239) && button.y <= (displayRect.getSize().y / 2 - 202)) { // the cursor picture was clicked callback::EditorCursorMenu(INITIALIZING_CALL); @@ -683,8 +690,9 @@ void CMap::setMouseData(const SDL_MouseButtonEvent& button) } #else // find out if user clicked on one of the game menu pictures - if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 74) && button.x <= (displayRect.w / 2 - 37) - && button.y >= (displayRect.h - 37) && button.y <= (displayRect.h - 4)) + if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.getSize().x / 2 - 74) + && button.x <= (displayRect.getSize().x / 2 - 37) && button.y >= (displayRect.getSize().y - 37) + && button.y <= (displayRect.getSize().y - 4)) { // the first picture was clicked callback::GameMenu(INITIALIZING_CALL); @@ -870,7 +878,7 @@ void CMap::setKeyboardData(const SDL_KeyboardEvent& key) { if (!saveCurrentVertices) { - if (CurrPtr_savedVertices != nullptr) + if (CurrPtr_savedVertices) { if (CurrPtr_savedVertices->next != nullptr) CurrPtr_savedVertices = CurrPtr_savedVertices->next; @@ -899,20 +907,9 @@ void CMap::setKeyboardData(const SDL_KeyboardEvent& key) }*/ else if(key.keysym.sym == SDLK_UP || key.keysym.sym == SDLK_DOWN || key.keysym.sym == SDLK_LEFT || key.keysym.sym == SDLK_RIGHT) { - // move displayRect - displayRect.x += (key.keysym.sym == SDLK_LEFT ? -100 : (key.keysym.sym == SDLK_RIGHT ? 100 : 0)); - displayRect.y += (key.keysym.sym == SDLK_UP ? -100 : (key.keysym.sym == SDLK_DOWN ? 100 : 0)); - - // reset coords of displayRects when end of map is reached - if(displayRect.x >= map->width_pixel) - displayRect.x = 0; - else if(displayRect.x <= -displayRect.w) - displayRect.x = map->width_pixel - displayRect.w; - - if(displayRect.y >= map->height_pixel) - displayRect.y = 0; - else if(displayRect.y <= -displayRect.h) - displayRect.y = map->height_pixel - displayRect.h; + Position offset{key.keysym.sym == SDLK_LEFT ? -100 : (key.keysym.sym == SDLK_RIGHT ? 100 : 0), + key.keysym.sym == SDLK_UP ? -100 : (key.keysym.sym == SDLK_DOWN ? 100 : 0)}; + moveMap(offset); } #ifdef _EDITORMODE // help menu @@ -1046,26 +1043,26 @@ void CMap::saveVertex(Uint16 MouseX, Uint16 MouseY, Uint8 /*MouseState*/) // get X // following out commented lines are the correct ones, but for tolerance (to prevent to early jumps of the cursor) we subtract - // "TRIANGLE_WIDTH/2" Xeven = (MouseX + displayRect.x) / TRIANGLE_WIDTH; - Xeven = (MouseX + displayRect.x - TRIANGLE_WIDTH / 2) / TRIANGLE_WIDTH; + // "TRIANGLE_WIDTH/2" Xeven = (MouseX + displayRect.left) / TRIANGLE_WIDTH; + Xeven = (MouseX + displayRect.left - TRIANGLE_WIDTH / 2) / TRIANGLE_WIDTH; if(Xeven < 0) Xeven += (map->width); else if(Xeven > map->width - 1) Xeven -= (map->width - 1); // Add rows are already shifted by TRIANGLE_WIDTH / 2 - Xodd = (MouseX + displayRect.x) / TRIANGLE_WIDTH; - // Xodd = (MouseX + displayRect.x) / TRIANGLE_WIDTH; + Xodd = (MouseX + displayRect.left) / TRIANGLE_WIDTH; + // Xodd = (MouseX + displayRect.left) / TRIANGLE_WIDTH; if(Xodd < 0) Xodd += (map->width - 1); else if(Xodd > map->width - 1) Xodd -= (map->width); - MousePosY = MouseY + displayRect.y; + MousePosY = MouseY + displayRect.top; // correct mouse position Y if displayRect is outside map edges if(MousePosY < 0) MousePosY += map->height_pixel; else if(MousePosY > map->height_pixel) - MousePosY = MouseY - (map->height_pixel - displayRect.y); + MousePosY = MouseY - (map->height_pixel - displayRect.top); // get Y for(int j = 0; j < map->height; j++) @@ -1109,22 +1106,22 @@ void CMap::saveVertex(Uint16 MouseX, Uint16 MouseY, Uint8 /*MouseState*/) int CMap::correctMouseBlitX(int VertexX, int VertexY) { int newBlitx = map->getVertex(VertexX, VertexY).x; - if(newBlitx < displayRect.x) + if(newBlitx < displayRect.left) newBlitx += map->width_pixel; - else if(newBlitx > (displayRect.x + displayRect.w)) + else if(newBlitx > displayRect.right) newBlitx -= map->width_pixel; - newBlitx -= displayRect.x; + newBlitx -= displayRect.left; return newBlitx; } int CMap::correctMouseBlitY(int VertexX, int VertexY) { int newBlity = map->getVertex(VertexX, VertexY).y; - if(newBlity < displayRect.y) + if(newBlity < displayRect.top) newBlity += map->height_pixel; - else if(newBlity > (displayRect.y + displayRect.h)) + else if(newBlity > displayRect.bottom) newBlity -= map->height_pixel; - newBlity -= displayRect.y; + newBlity -= displayRect.top; return newBlity; } @@ -1134,10 +1131,9 @@ void CMap::render() char textBuffer[100]; // check if gameresolution has been changed - if(displayRect.w != global::s2->GameResolutionX || displayRect.h != global::s2->GameResolutionY) + if(displayRect.getSize() != global::s2->GameResolution) { - displayRect.w = global::s2->GameResolutionX; - displayRect.h = global::s2->GameResolutionY; + displayRect.setSize(global::s2->GameResolution); needSurface = true; } @@ -1146,7 +1142,8 @@ void CMap::render() { SDL_FreeSurface(Surf_Map); Surf_Map = nullptr; - if((Surf_Map = SDL_CreateRGBSurface(SDL_SWSURFACE, displayRect.w, displayRect.h, BitsPerPixel, 0, 0, 0, 0)) == nullptr) + if((Surf_Map = SDL_CreateRGBSurface(SDL_SWSURFACE, displayRect.getSize().x, displayRect.getSize().y, BitsPerPixel, 0, 0, 0, 0)) + == nullptr) return; if(BitsPerPixel == 8) SDL_SetPalette(Surf_Map, SDL_LOGPAL, global::palArray[PAL_xBBM].colors, 0, 256); @@ -1223,79 +1220,93 @@ void CMap::render() #endif // draw the frame - if(displayRect.w == 640 && displayRect.h == 480) + if(displayRect.getSize() == Extent(640, 480)) CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, 0); - else if(displayRect.w == 800 && displayRect.h == 600) + else if(displayRect.getSize() == Extent(800, 600)) CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_800_600].surface, 0, 0); - else if(displayRect.w == 1024 && displayRect.h == 768) + else if(displayRect.getSize() == Extent(1024, 768)) CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_1024_768].surface, 0, 0); - else if(displayRect.w == 1280 && displayRect.h == 1024) + else if(displayRect.getSize() == Extent(1280, 1024)) { CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_LEFT_1280_1024].surface, 0, 0); CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_RIGHT_1280_1024].surface, 640, 0); } else { - int x = 150, y = 150; // draw the corners CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, 0, 0, 0, 150, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, displayRect.h - 150, 0, 480 - 150, 150, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 150, 0, 640 - 150, 0, 150, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 150, displayRect.h - 150, 640 - 150, - 480 - 150, 150, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, displayRect.getSize().y - 150, 0, 480 - 150, 150, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.getSize().x - 150, 0, 640 - 150, 0, 150, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.getSize().x - 150, displayRect.getSize().y - 150, + 640 - 150, 480 - 150, 150, 150); // draw the edges - while(x < displayRect.w - 150) + unsigned x = 150, y = 150; + while(x + 150 < displayRect.getSize().x) { CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, x, 0, 150, 0, 150, 12); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, x, displayRect.h - 12, 150, 0, 150, 12); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, x, displayRect.getSize().y - 12, 150, 0, 150, 12); x += 150; } - while(y < displayRect.h - 150) + while(y + 150 < displayRect.getSize().y) { CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, y, 0, 150, 12, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 12, y, 0, 150, 12, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.getSize().x - 12, y, 0, 150, 12, 150); y += 150; } } // draw the statues at the frame CSurface::Draw(Surf_Map, global::bmpArray[STATUE_UP_LEFT].surface, 12, 12); - CSurface::Draw(Surf_Map, global::bmpArray[STATUE_UP_RIGHT].surface, displayRect.w - global::bmpArray[STATUE_UP_RIGHT].w - 12, 12); - CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_LEFT].surface, 12, displayRect.h - global::bmpArray[STATUE_DOWN_LEFT].h - 12); - CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_RIGHT].surface, displayRect.w - global::bmpArray[STATUE_DOWN_RIGHT].w - 12, - displayRect.h - global::bmpArray[STATUE_DOWN_RIGHT].h - 12); + CSurface::Draw(Surf_Map, global::bmpArray[STATUE_UP_RIGHT].surface, displayRect.getSize().x - global::bmpArray[STATUE_UP_RIGHT].w - 12, + 12); + CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_LEFT].surface, 12, + displayRect.getSize().y - global::bmpArray[STATUE_DOWN_LEFT].h - 12); + CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_RIGHT].surface, + displayRect.getSize().x - global::bmpArray[STATUE_DOWN_RIGHT].w - 12, + displayRect.getSize().y - global::bmpArray[STATUE_DOWN_RIGHT].h - 12); // lower menubar // draw lower menubar - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR].surface, displayRect.w / 2 - global::bmpArray[MENUBAR].w / 2, - displayRect.h - global::bmpArray[MENUBAR].h); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR].surface, displayRect.getSize().x / 2 - global::bmpArray[MENUBAR].w / 2, + displayRect.getSize().y - global::bmpArray[MENUBAR].h); // draw pictures to lower menubar #ifdef _EDITORMODE // backgrounds - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 236, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 199, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 162, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 125, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 88, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 51, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 14, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 92, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 129, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 166, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 203, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 - 236, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 - 199, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 - 162, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 - 125, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 - 88, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 - 51, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 - 14, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 + 92, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 + 129, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 + 166, displayRect.getSize().y - 36, + 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x / 2 + 203, displayRect.getSize().y - 36, + 0, 0, 37, 32); // pictures - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_HEIGHT].surface, displayRect.w / 2 - 232, displayRect.h - 35); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TEXTURE].surface, displayRect.w / 2 - 195, displayRect.h - 35); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TREE].surface, displayRect.w / 2 - 158, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_RESOURCE].surface, displayRect.w / 2 - 121, displayRect.h - 32); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_LANDSCAPE].surface, displayRect.w / 2 - 84, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_ANIMAL].surface, displayRect.w / 2 - 48, displayRect.h - 36); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_PLAYER].surface, displayRect.w / 2 - 10, displayRect.h - 34); - - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUILDHELP].surface, displayRect.w / 2 + 96, displayRect.h - 35); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_MINIMAP].surface, displayRect.w / 2 + 131, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_NEWWORLD].surface, displayRect.w / 2 + 166, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_COMPUTER].surface, displayRect.w / 2 + 207, displayRect.h - 35); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_HEIGHT].surface, displayRect.getSize().x / 2 - 232, displayRect.getSize().y - 35); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TEXTURE].surface, displayRect.getSize().x / 2 - 195, displayRect.getSize().y - 35); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TREE].surface, displayRect.getSize().x / 2 - 158, displayRect.getSize().y - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_RESOURCE].surface, displayRect.getSize().x / 2 - 121, displayRect.getSize().y - 32); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_LANDSCAPE].surface, displayRect.getSize().x / 2 - 84, displayRect.getSize().y - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_ANIMAL].surface, displayRect.getSize().x / 2 - 48, displayRect.getSize().y - 36); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_PLAYER].surface, displayRect.getSize().x / 2 - 10, displayRect.getSize().y - 34); + + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUILDHELP].surface, displayRect.getSize().x / 2 + 96, displayRect.getSize().y - 35); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_MINIMAP].surface, displayRect.getSize().x / 2 + 131, displayRect.getSize().y - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_NEWWORLD].surface, displayRect.getSize().x / 2 + 166, displayRect.getSize().y - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_COMPUTER].surface, displayRect.getSize().x / 2 + 207, displayRect.getSize().y - 35); #else #endif @@ -1303,7 +1314,7 @@ void CMap::render() #ifdef _EDITORMODE // right menubar // do we need a surface? - if(Surf_RightMenubar == nullptr) + if(!Surf_RightMenubar) { // we permute width and height, cause we want to rotate the menubar 90 degrees if((Surf_RightMenubar = @@ -1316,36 +1327,51 @@ void CMap::render() } } // draw right menubar (remember permutation of width and height) - CSurface::Draw(Surf_Map, Surf_RightMenubar, displayRect.w - global::bmpArray[MENUBAR].h, - displayRect.h / 2 - global::bmpArray[MENUBAR].w / 2); + CSurface::Draw(Surf_Map, Surf_RightMenubar, displayRect.getSize().x - global::bmpArray[MENUBAR].h, + displayRect.getSize().y / 2 - global::bmpArray[MENUBAR].w / 2); // draw pictures to right menubar // backgrounds - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 239, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 202, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 165, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 128, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 22, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 15, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 52, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 89, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 126, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 163, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 200, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 - 239, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 - 202, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 - 165, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 - 128, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 - 22, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 + 15, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 + 52, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 + 89, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 + 126, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 + 163, + 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.getSize().x - 36, displayRect.getSize().y / 2 + 200, + 0, 0, 32, 37); // pictures // four cursor menu pictures - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.w - 33, displayRect.h / 2 - 237); - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.w - 20, displayRect.h / 2 - 235); - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.w - 33, displayRect.h / 2 - 220); - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.w - 20, displayRect.h / 2 - 220); + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.getSize().x - 33, + displayRect.getSize().y / 2 - 237); + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.getSize().x - 20, + displayRect.getSize().y / 2 - 235); + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.getSize().x - 33, + displayRect.getSize().y / 2 - 220); + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.getSize().x - 20, + displayRect.getSize().y / 2 - 220); // bugkill picture for quickload with text - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.w - 37, displayRect.h / 2 + 162); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.getSize().x - 37, displayRect.getSize().y / 2 + 162); sprintf(textBuffer, "Load"); - CFont::writeText(Surf_Map, textBuffer, displayRect.w - 35, displayRect.h / 2 + 193); + CFont::writeText(Surf_Map, textBuffer, displayRect.getSize().x - 35, displayRect.getSize().y / 2 + 193); // bugkill picture for quicksave with text - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.w - 37, displayRect.h / 2 + 200); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.getSize().x - 37, displayRect.getSize().y / 2 + 200); sprintf(textBuffer, "Save"); - CFont::writeText(Surf_Map, textBuffer, displayRect.w - 35, displayRect.h / 2 + 231); + CFont::writeText(Surf_Map, textBuffer, displayRect.getSize().x - 35, displayRect.getSize().y / 2 + 231); #endif } @@ -1504,9 +1530,10 @@ void CMap::drawMinimap(SDL_Surface* Window) #endif // draw the arrow --> 6px is width of left window frame and 20px is the height of the upper window frame - CSurface::Draw(Window, global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].surface, - 6 + (displayRect.x + displayRect.w / 2) / TRIANGLE_WIDTH / num_x - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx, - 20 + (displayRect.y + displayRect.h / 2) / TRIANGLE_HEIGHT / num_y - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny); + CSurface::Draw( + Window, global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].surface, + 6 + (displayRect.left + displayRect.getSize().x / 2) / TRIANGLE_WIDTH / num_x - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx, + 20 + (displayRect.top + displayRect.getSize().y / 2) / TRIANGLE_HEIGHT / num_y - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny); } void CMap::modifyVertex() @@ -1521,7 +1548,7 @@ void CMap::modifyVertex() // save vertices for "undo" and "do" if(saveCurrentVertices) { - if(CurrPtr_savedVertices != nullptr) + if(CurrPtr_savedVertices) { CurrPtr_savedVertices->empty = false; CurrPtr_savedVertices->VertexX = VertexX_; @@ -2256,8 +2283,8 @@ void CMap::modifyBuild(int x, int y) } std::array mapVertices; - for(unsigned i = 0; i < mapVertices.size(); i++) - mapVertices[i] = &map->getVertex(tempVertices[0].x, tempVertices[0].y); + for(auto& mapVertice : mapVertices) + mapVertice = &map->getVertex(tempVertices[0].x, tempVertices[0].y); // test if there is snow or lava at the vertex or around the vertex and touching the vertex (first section) if(building > 0x00) @@ -2406,8 +2433,8 @@ void CMap::modifyResource(int x, int y) calculateVerticesAround(tempVertices, x, y); MapNode& curVertex = map->getVertex(x, y); std::array mapVertices; - for(unsigned i = 0; i < mapVertices.size(); i++) - mapVertices[i] = &map->getVertex(tempVertices[0].x, tempVertices[0].y); + for(auto& mapVertice : mapVertices) + mapVertice = &map->getVertex(tempVertices[0].x, tempVertices[0].y); // SPECIAL CASE: test if we should set water only // test if vertex is surrounded by meadow and meadow-like textures diff --git a/CMap.h b/CMap.h index aa2186f..c12158b 100644 --- a/CMap.h +++ b/CMap.h @@ -88,6 +88,7 @@ class CMap void loadMapPics(); void unloadMapPics(); + void moveMap(Position offset); void setMouseData(const SDL_MouseMotionEvent& motion); void setMouseData(const SDL_MouseButtonEvent& button); void setKeyboardData(const SDL_KeyboardEvent& key); diff --git a/CSurface.cpp b/CSurface.cpp index a35f4fb..bd3c736 100644 --- a/CSurface.cpp +++ b/CSurface.cpp @@ -43,11 +43,9 @@ void DrawFadedTexturedTrigon(SDL_Surface* dest, Point16 p1, Point16 p2, Point16 bool CSurface::drawTextures = false; bool CSurface::useOpenGL = false; -CSurface::CSurface() {} - bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y) { - if(Surf_Dest == nullptr || Surf_Src == nullptr) + if(!Surf_Dest || !Surf_Src) return false; SDL_Rect DestR; @@ -62,7 +60,7 @@ bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y) bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int angle) { - if(Surf_Dest == nullptr || Surf_Src == nullptr) + if(!Surf_Dest || !Surf_Src) return false; Uint16 px, py; @@ -91,7 +89,7 @@ bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H) { - if(Surf_Dest == nullptr || Surf_Src == nullptr) + if(!Surf_Dest || !Surf_Src) return false; SDL_Rect DestR; @@ -114,56 +112,34 @@ bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, // this is the example function from the sdl-documentation to draw pixels void CSurface::DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color) { + int bpp = screen->format->BytesPerPixel; + /* Here p is the address to the pixel we want to retrieve */ + Uint8* p = (Uint8*)screen->pixels + y * screen->pitch + x * bpp; + if(SDL_MUSTLOCK(screen)) SDL_LockSurface(screen); - switch(screen->format->BytesPerPixel) + switch(bpp) { - case 1: - { - Uint8* bufp; + case 1: *p = color; break; - bufp = (Uint8*)screen->pixels + y * screen->pitch + x; - *bufp = color; - } - break; - - case 2: - { - Uint16* bufp; - - bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; - *bufp = color; - } - break; + case 2: *(Uint16*)p = color; break; case 3: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { - bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; + p[0] = color; + p[1] = color >> 8; + p[2] = color >> 16; } else { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; + p[2] = color; + p[1] = color >> 8; + p[0] = color >> 16; } - } - break; - - case 4: - { - Uint32* bufp; + break; - bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; //-V206 - *bufp = color; - } - break; + case 4: *(Uint32*)p = color; break; } if(SDL_MUSTLOCK(screen)) @@ -173,122 +149,12 @@ void CSurface::DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color) // this is the example function from the sdl-documentation to draw pixels void CSurface::DrawPixel_RGB(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) { - if(SDL_MUSTLOCK(screen)) - SDL_LockSurface(screen); - - Uint32 color = SDL_MapRGB(screen->format, R, G, B); - - switch(screen->format->BytesPerPixel) - { - case 1: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x; - *bufp = color; - } - break; - - case 2: - { - Uint16* bufp; - - bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; - *bufp = color; - } - break; - - case 3: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; - } else - { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; - } - } - break; - - case 4: - { - Uint32* bufp; - - bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; //-V206 - *bufp = color; - } - break; - } - - if(SDL_MUSTLOCK(screen)) - SDL_UnlockSurface(screen); + DrawPixel_Color(screen, x, y, SDL_MapRGB(screen->format, R, G, B)); } void CSurface::DrawPixel_RGBA(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B, Uint8 A) { - if(SDL_MUSTLOCK(screen)) - SDL_LockSurface(screen); - - Uint32 color = SDL_MapRGBA(screen->format, R, G, B, A); - - switch(screen->format->BytesPerPixel) - { - case 1: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x; - *bufp = color; - } - break; - - case 2: - { - Uint16* bufp; - - bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; - *bufp = color; - } - break; - - case 3: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; - } else - { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; - } - } - break; - - case 4: - { - Uint32* bufp; - - bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; //-V206 - *bufp = color; - } - break; - } - - if(SDL_MUSTLOCK(screen)) - SDL_UnlockSurface(screen); + DrawPixel_Color(screen, x, y, SDL_MapRGBA(screen->format, R, G, B, A)); } Uint32 CSurface::GetPixel(SDL_Surface* surface, int x, int y) @@ -327,12 +193,10 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d if(width < 8 || height < 8) return; - assert(displayRect.x < myMap.width_pixel); - assert(-displayRect.x <= displayRect.w); - assert(displayRect.x + displayRect.w > 0); - assert(displayRect.y < myMap.height_pixel); - assert(-displayRect.y <= displayRect.h); - assert(displayRect.y + displayRect.h > 0); + assert(displayRect.left < myMap.width_pixel); + assert(displayRect.right > 0); + assert(displayRect.top < myMap.height_pixel); + assert(displayRect.bottom > 0); // draw triangle field // NOTE: WE DO THIS TWICE, AT FIRST ONLY TRIANGLE-TEXTURES, AT SECOND THE TEXTURE-BORDERS AND OBJECTS @@ -347,10 +211,10 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d // IMPORTANT: integer values like +8 or -1 are for tolerance to beware of high triangles are not shown // at first call DrawTriangle for all triangles inside the map edges - int row_start = std::max(displayRect.y, 2 * TRIANGLE_HEIGHT) / TRIANGLE_HEIGHT - 2; - int row_end = (displayRect.y + displayRect.h) / TRIANGLE_HEIGHT + 8; - int col_start = std::max(displayRect.x, TRIANGLE_WIDTH) / TRIANGLE_WIDTH - 1; - int col_end = (displayRect.x + displayRect.w) / TRIANGLE_WIDTH + 1; + int row_start = std::max(displayRect.top, 2 * TRIANGLE_HEIGHT) / TRIANGLE_HEIGHT - 2; + int row_end = (displayRect.bottom) / TRIANGLE_HEIGHT + 8; + int col_start = std::max(displayRect.left, TRIANGLE_WIDTH) / TRIANGLE_WIDTH - 1; + int col_end = (displayRect.right) / TRIANGLE_WIDTH + 1; bool view_outside_edges; if(k > 0) @@ -361,24 +225,24 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d if(k == 1 || k == 3) { // at first call DrawTriangle for all triangles up or down outside - if(displayRect.y < 0) + if(displayRect.top < 0) { - row_start = std::max(0, height - 1 - (-displayRect.y / TRIANGLE_HEIGHT) - 1); + row_start = std::max(0, height - 1 - (-displayRect.top / TRIANGLE_HEIGHT) - 1); row_end = height - 1; view_outside_edges = true; - } else if((displayRect.y + displayRect.h) > myMap.height_pixel) + } else if(displayRect.bottom > myMap.height_pixel) { row_start = 0; - row_end = ((displayRect.y + displayRect.h) - myMap.height_pixel) / TRIANGLE_HEIGHT + 8; + row_end = (displayRect.bottom - myMap.height_pixel) / TRIANGLE_HEIGHT + 8; view_outside_edges = true; - } else if(displayRect.y <= 2 * TRIANGLE_HEIGHT) + } else if(displayRect.top <= 2 * TRIANGLE_HEIGHT) { // this is for draw triangles that are reduced under the lower map edge (have bigger y-coords as // myMap.height_pixel) row_start = height - 3; row_end = height - 1; view_outside_edges = true; - } else if((displayRect.y + displayRect.h) >= (myMap.height_pixel - 8 * TRIANGLE_HEIGHT)) + } else if(displayRect.bottom >= (myMap.height_pixel - 8 * TRIANGLE_HEIGHT)) { // this is for draw triangles that are raised over the upper map edge (have negative y-coords) row_start = 0; @@ -390,20 +254,20 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d if(k == 2 || k == 3) { // now call DrawTriangle for all triangles left or right outside - if(displayRect.x <= 0) + if(displayRect.left <= 0) { - col_start = std::max(0, width - 1 - (-displayRect.x / TRIANGLE_WIDTH) - 1); + col_start = std::max(0, width - 1 - (-displayRect.left / TRIANGLE_WIDTH) - 1); col_end = width - 1; view_outside_edges = true; - } else if(displayRect.x < TRIANGLE_WIDTH) + } else if(displayRect.left < TRIANGLE_WIDTH) { col_start = width - 2; col_end = width - 1; view_outside_edges = true; - } else if((displayRect.x + displayRect.w) > myMap.width_pixel) + } else if(displayRect.right > myMap.width_pixel) { col_start = 0; - col_end = ((displayRect.x + displayRect.w) - myMap.width_pixel) / TRIANGLE_WIDTH + 1; + col_end = (displayRect.right - myMap.width_pixel) / TRIANGLE_WIDTH + 1; view_outside_edges = true; } } @@ -529,17 +393,17 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa Point32 p2(node2.x, node2.y); Point32 p3(node3.x, node3.y); // prevent drawing triangles that are not shown - if(((p1.x < displayRect.x && p2.x < displayRect.x && p3.x < displayRect.x) - || (p1.x > (displayRect.x + displayRect.w) && p2.x > (displayRect.x + displayRect.w) && p3.x > (displayRect.x + displayRect.w))) - || ((p1.y < displayRect.y && p2.y < displayRect.y && p3.y < displayRect.y) - || (p1.y > (displayRect.y + displayRect.h) && p2.y > (displayRect.y + displayRect.h) && p3.y > (displayRect.y + displayRect.h)))) + if(((p1.x < displayRect.left && p2.x < displayRect.left && p3.x < displayRect.left) + || (p1.x > displayRect.right && p2.x > displayRect.right && p3.x > displayRect.right)) + || ((p1.y < displayRect.top && p2.y < displayRect.top && p3.y < displayRect.top) + || (p1.y > displayRect.bottom && p2.y > displayRect.bottom && p3.y > displayRect.bottom))) { bool triangle_shown = false; - if(displayRect.x <= 0) + if(displayRect.left <= 0) { - int outside_x = displayRect.x; - int outside_w = -displayRect.x; + int outside_x = displayRect.left; + int outside_w = -displayRect.left; if((((p1.x - myMap.width_pixel) >= (outside_x)) && ((p1.x - myMap.width_pixel) <= (outside_x + outside_w))) || (((p2.x - myMap.width_pixel) >= (outside_x)) && ((p2.x - myMap.width_pixel) <= (outside_x + outside_w))) || (((p3.x - myMap.width_pixel) >= (outside_x)) && ((p3.x - myMap.width_pixel) <= (outside_x + outside_w)))) @@ -549,9 +413,9 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa p3.x -= myMap.width_pixel; triangle_shown = true; } - } else if(displayRect.x < TRIANGLE_WIDTH) + } else if(displayRect.left < TRIANGLE_WIDTH) { - int outside_x = displayRect.x; + int outside_x = displayRect.left; int outside_w = TRIANGLE_WIDTH; if((((p1.x - myMap.width_pixel) >= (outside_x)) && ((p1.x - myMap.width_pixel) <= (outside_x + outside_w))) || (((p2.x - myMap.width_pixel) >= (outside_x)) && ((p2.x - myMap.width_pixel) <= (outside_x + outside_w))) @@ -562,10 +426,10 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa p3.x -= myMap.width_pixel; triangle_shown = true; } - } else if((displayRect.x + displayRect.w) > (myMap.width_pixel)) + } else if(displayRect.right > (myMap.width_pixel)) { int outside_x = myMap.width_pixel; - int outside_w = displayRect.x + displayRect.w - myMap.width_pixel; + int outside_w = displayRect.right - myMap.width_pixel; if((((p1.x + myMap.width_pixel) >= (outside_x)) && ((p1.x + myMap.width_pixel) <= (outside_x + outside_w))) || (((p2.x + myMap.width_pixel) >= (outside_x)) && ((p2.x + myMap.width_pixel) <= (outside_x + outside_w))) || (((p3.x + myMap.width_pixel) >= (outside_x)) && ((p3.x + myMap.width_pixel) <= (outside_x + outside_w)))) @@ -577,10 +441,10 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa } } - if(displayRect.y < 0) + if(displayRect.top < 0) { - int outside_y = displayRect.y; - int outside_h = -displayRect.y; + int outside_y = displayRect.top; + int outside_h = -displayRect.top; if((((p1.y - myMap.height_pixel) >= (outside_y)) && ((p1.y - myMap.height_pixel) <= (outside_y + outside_h))) || (((p2.y - myMap.height_pixel) >= (outside_y)) && ((p2.y - myMap.height_pixel) <= (outside_y + outside_h))) || (((p3.y - myMap.height_pixel) >= (outside_y)) && ((p3.y - myMap.height_pixel) <= (outside_y + outside_h)))) @@ -590,10 +454,10 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa p3.y -= myMap.height_pixel; triangle_shown = true; } - } else if((displayRect.y + displayRect.h) > (myMap.height_pixel)) + } else if(displayRect.bottom > (myMap.height_pixel)) { int outside_y = myMap.height_pixel; - int outside_h = displayRect.y + displayRect.h - myMap.height_pixel; + int outside_h = displayRect.bottom - myMap.height_pixel; if((((p1.y + myMap.height_pixel) >= (outside_y)) && ((p1.y + myMap.height_pixel) <= (outside_y + outside_h))) || (((p2.y + myMap.height_pixel) >= (outside_y)) && ((p2.y + myMap.height_pixel) <= (outside_y + outside_h))) || (((p3.y + myMap.height_pixel) >= (outside_y)) && ((p3.y + myMap.height_pixel) <= (outside_y + outside_h)))) @@ -608,9 +472,9 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa // now test if triangle has negative y-coords cause it's raised over the upper map edge if(p1.y < 0 || p2.y < 0 || p3.y < 0) { - if((((p1.y + myMap.height_pixel) >= displayRect.y) && ((p1.y + myMap.height_pixel) <= (displayRect.y + displayRect.h))) - || (((p2.y + myMap.height_pixel) >= displayRect.y) && ((p2.y + myMap.height_pixel) <= (displayRect.y + displayRect.h))) - || (((p3.y + myMap.height_pixel) >= displayRect.y) && ((p3.y + myMap.height_pixel) <= (displayRect.y + displayRect.h)))) + if((((p1.y + myMap.height_pixel) >= displayRect.top) && ((p1.y + myMap.height_pixel) <= displayRect.bottom)) + || (((p2.y + myMap.height_pixel) >= displayRect.top) && ((p2.y + myMap.height_pixel) <= displayRect.bottom)) + || (((p3.y + myMap.height_pixel) >= displayRect.top) && ((p3.y + myMap.height_pixel) <= displayRect.bottom))) { p1.y += myMap.height_pixel; p2.y += myMap.height_pixel; @@ -622,9 +486,9 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa // now test if triangle has bigger y-coords as myMap.height_pixel cause it's reduced under the lower map edge if(p1.y > myMap.height_pixel || p2.y > myMap.height_pixel || p3.y > myMap.height_pixel) { - if((((p1.y - myMap.height_pixel) >= displayRect.y) && ((p1.y - myMap.height_pixel) <= (displayRect.y + displayRect.h))) - || (((p2.y - myMap.height_pixel) >= displayRect.y) && ((p2.y - myMap.height_pixel) <= (displayRect.y + displayRect.h))) - || (((p3.y - myMap.height_pixel) >= displayRect.y) && ((p3.y - myMap.height_pixel) <= (displayRect.y + displayRect.h)))) + if((((p1.y - myMap.height_pixel) >= displayRect.top) && ((p1.y - myMap.height_pixel) <= displayRect.bottom)) + || (((p2.y - myMap.height_pixel) >= displayRect.top) && ((p2.y - myMap.height_pixel) <= displayRect.bottom)) + || (((p3.y - myMap.height_pixel) >= displayRect.top) && ((p3.y - myMap.height_pixel) <= displayRect.bottom))) { p1.y -= myMap.height_pixel; p2.y -= myMap.height_pixel; @@ -701,9 +565,9 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa // it's a harbour texture_raw -= 0x40; - const Point16 shiftedP1(p1 - Point32(displayRect.x, displayRect.y)); - const Point16 shiftedP2(p2 - Point32(displayRect.x, displayRect.y)); - const Point16 shiftedP3(p3 - Point32(displayRect.x, displayRect.y)); + const Point16 shiftedP1(p1 - Point32(displayRect.left, displayRect.top)); + const Point16 shiftedP2(p2 - Point32(displayRect.left, displayRect.top)); + const Point16 shiftedP3(p3 - Point32(displayRect.left, displayRect.top)); if(drawTextures) { @@ -1037,7 +901,7 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa borderSide = CalcBorders(myMap, tempP.usdTexture, node1.rsuTexture, BorderRect); if(borderSide != 0) { - Point16 thirdPt = (borderSide > 0) ? shiftedP3 : Point16(tempP.x - displayRect.x, tempP.y - displayRect.y); + Point16 thirdPt = (borderSide > 0) ? shiftedP3 : Point16(tempP.x - displayRect.left, tempP.y - displayRect.top); Point16 tipPt = (shiftedP1 + shiftedP2 + thirdPt) / Sint16(3); Point16 tmpP1 = (borderSide > 0) ? shiftedP1 : shiftedP1 + Point16(1, 0); Point16 tmpP2 = (borderSide > 0) ? shiftedP2 : shiftedP2 + Point16(1, 0); @@ -1059,7 +923,7 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa Uint16 col = (node1.VertexX - 1 < 0 ? myMap.width - 1 : node1.VertexX - 1); tempP = myMap.getVertex(col, node1.VertexY); - Point16 thirdPt = (borderSide > 0) ? shiftedP3 : Point16(tempP.x - displayRect.x, tempP.y - displayRect.y); + Point16 thirdPt = (borderSide > 0) ? shiftedP3 : Point16(tempP.x - displayRect.left, tempP.y - displayRect.top); Point16 tipPt = (shiftedP1 + shiftedP2 + thirdPt) / Sint16(3); Point16 tmpP1 = (borderSide < 0) ? shiftedP1 : shiftedP1 - Point16(1, 0); @@ -1080,7 +944,7 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa borderSide = CalcBorders(myMap, tempP.rsuTexture, node2.usdTexture, BorderRect); if(borderSide != 0) { - Point16 thirdPt = (borderSide > 0) ? shiftedP1 : Point16(tempP.x - displayRect.x, tempP.y - displayRect.y); + Point16 thirdPt = (borderSide > 0) ? shiftedP1 : Point16(tempP.x - displayRect.left, tempP.y - displayRect.top); Point16 tipPt = (shiftedP2 + shiftedP3 + thirdPt) / Sint16(3); if(global::s2->getMapObj()->getBitsPerPixel() == 8) DrawPreCalcFadedTexturedTrigon(display, shiftedP2, shiftedP3, tipPt, Surf_Tileset, BorderRect, node2.shading << 8, @@ -1232,8 +1096,8 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa default: break; } if(objIdx != 0) - Draw(display, global::bmpArray[objIdx].surface, (int)(p2.x - displayRect.x - global::bmpArray[objIdx].nx), - (int)(p2.y - displayRect.y - global::bmpArray[objIdx].ny)); + Draw(display, global::bmpArray[objIdx].surface, (int)(p2.x - displayRect.left - global::bmpArray[objIdx].nx), + (int)(p2.y - displayRect.top - global::bmpArray[objIdx].ny)); } #ifdef _EDITORMODE @@ -1244,35 +1108,35 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa { for(char i = 0x41; i <= node2.resource; i++) Draw(display, global::bmpArray[PICTURE_RESOURCE_COAL].surface, - (int)(p2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_COAL].nx), - (int)(p2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_COAL].ny - (4 * (i - 0x40)))); + (int)(p2.x - displayRect.left - global::bmpArray[PICTURE_RESOURCE_COAL].nx), + (int)(p2.y - displayRect.top - global::bmpArray[PICTURE_RESOURCE_COAL].ny - (4 * (i - 0x40)))); } else if(node2.resource >= 0x49 && node2.resource <= 0x4F) { for(char i = 0x49; i <= node2.resource; i++) Draw(display, global::bmpArray[PICTURE_RESOURCE_ORE].surface, - (int)(p2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_ORE].nx), - (int)(p2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_ORE].ny - (4 * (i - 0x48)))); + (int)(p2.x - displayRect.left - global::bmpArray[PICTURE_RESOURCE_ORE].nx), + (int)(p2.y - displayRect.top - global::bmpArray[PICTURE_RESOURCE_ORE].ny - (4 * (i - 0x48)))); } if(node2.resource >= 0x51 && node2.resource <= 0x57) { for(char i = 0x51; i <= node2.resource; i++) Draw(display, global::bmpArray[PICTURE_RESOURCE_GOLD].surface, - (int)(p2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_GOLD].nx), - (int)(p2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_GOLD].ny - (4 * (i - 0x50)))); + (int)(p2.x - displayRect.left - global::bmpArray[PICTURE_RESOURCE_GOLD].nx), + (int)(p2.y - displayRect.top - global::bmpArray[PICTURE_RESOURCE_GOLD].ny - (4 * (i - 0x50)))); } if(node2.resource >= 0x59 && node2.resource <= 0x5F) { for(char i = 0x59; i <= node2.resource; i++) Draw(display, global::bmpArray[PICTURE_RESOURCE_GRANITE].surface, - (int)(p2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_GRANITE].nx), - (int)(p2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_GRANITE].ny - (4 * (i - 0x58)))); + (int)(p2.x - displayRect.left - global::bmpArray[PICTURE_RESOURCE_GRANITE].nx), + (int)(p2.y - displayRect.top - global::bmpArray[PICTURE_RESOURCE_GRANITE].ny - (4 * (i - 0x58)))); } // blit animals if(node2.animal > 0x00 && node2.animal <= 0x06) { Draw(display, global::bmpArray[PICTURE_SMALL_BEAR + node2.animal].surface, - (int)(p2.x - displayRect.x - global::bmpArray[PICTURE_SMALL_BEAR + node2.animal].nx), - (int)(p2.y - displayRect.y - global::bmpArray[PICTURE_SMALL_BEAR + node2.animal].ny)); + (int)(p2.x - displayRect.left - global::bmpArray[PICTURE_SMALL_BEAR + node2.animal].nx), + (int)(p2.y - displayRect.top - global::bmpArray[PICTURE_SMALL_BEAR + node2.animal].ny)); } } #endif @@ -1285,18 +1149,18 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa switch(node2.build % 8) { case 0x01: - Draw(display, global::bmpArray[MAPPIC_FLAG].surface, (int)(p2.x - displayRect.x - global::bmpArray[MAPPIC_FLAG].nx), - (int)(p2.y - displayRect.y - global::bmpArray[MAPPIC_FLAG].ny)); + Draw(display, global::bmpArray[MAPPIC_FLAG].surface, (int)(p2.x - displayRect.left - global::bmpArray[MAPPIC_FLAG].nx), + (int)(p2.y - displayRect.top - global::bmpArray[MAPPIC_FLAG].ny)); break; case 0x02: Draw(display, global::bmpArray[MAPPIC_HOUSE_SMALL].surface, - (int)(p2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_SMALL].nx), - (int)(p2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_SMALL].ny)); + (int)(p2.x - displayRect.left - global::bmpArray[MAPPIC_HOUSE_SMALL].nx), + (int)(p2.y - displayRect.top - global::bmpArray[MAPPIC_HOUSE_SMALL].ny)); break; case 0x03: Draw(display, global::bmpArray[MAPPIC_HOUSE_MIDDLE].surface, - (int)(p2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_MIDDLE].nx), - (int)(p2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_MIDDLE].ny)); + (int)(p2.x - displayRect.left - global::bmpArray[MAPPIC_HOUSE_MIDDLE].nx), + (int)(p2.y - displayRect.top - global::bmpArray[MAPPIC_HOUSE_MIDDLE].ny)); break; case 0x04: if(node2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || node2.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR @@ -1304,16 +1168,16 @@ void CSurface::DrawTriangle(SDL_Surface* display, const DisplayRectangle& displa || node2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR || node2.rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR || node2.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) Draw(display, global::bmpArray[MAPPIC_HOUSE_HARBOUR].surface, - (int)(p2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_HARBOUR].nx), - (int)(p2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_HARBOUR].ny)); + (int)(p2.x - displayRect.left - global::bmpArray[MAPPIC_HOUSE_HARBOUR].nx), + (int)(p2.y - displayRect.top - global::bmpArray[MAPPIC_HOUSE_HARBOUR].ny)); else Draw(display, global::bmpArray[MAPPIC_HOUSE_BIG].surface, - (int)(p2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_BIG].nx), - (int)(p2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_BIG].ny)); + (int)(p2.x - displayRect.left - global::bmpArray[MAPPIC_HOUSE_BIG].nx), + (int)(p2.y - displayRect.top - global::bmpArray[MAPPIC_HOUSE_BIG].ny)); break; case 0x05: - Draw(display, global::bmpArray[MAPPIC_MINE].surface, (int)(p2.x - displayRect.x - global::bmpArray[MAPPIC_MINE].nx), - (int)(p2.y - displayRect.y - global::bmpArray[MAPPIC_MINE].ny)); + Draw(display, global::bmpArray[MAPPIC_MINE].surface, (int)(p2.x - displayRect.left - global::bmpArray[MAPPIC_MINE].nx), + (int)(p2.y - displayRect.top - global::bmpArray[MAPPIC_MINE].ny)); break; default: break; } diff --git a/CSurface.h b/CSurface.h index 91fd342..7d9229a 100644 --- a/CSurface.h +++ b/CSurface.h @@ -8,7 +8,6 @@ class CSurface friend class CDebug; public: - CSurface(); // blits from source on destination to position X,Y static bool Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y); // blits from source on destination to position X,Y and rotates (angle --> degrees --> 90, 180, 270) diff --git a/SGE/sge_blib.cpp b/SGE/sge_blib.cpp index 0ec8cce..fccdf8a 100644 --- a/SGE/sge_blib.cpp +++ b/SGE/sge_blib.cpp @@ -3945,7 +3945,7 @@ void sge_PreCalcFadedTexturedRect(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint1 class pline { public: - virtual ~pline() {} + virtual ~pline() = default; Sint16 x1, x2, y1, y2; Sint32 fx, fm; diff --git a/SGE/sge_bm_text.cpp b/SGE/sge_bm_text.cpp index 3fcecee..4fd49b1 100644 --- a/SGE/sge_bm_text.cpp +++ b/SGE/sge_bm_text.cpp @@ -49,7 +49,7 @@ sge_bmpFont* sge_BF_CreateFont(SDL_Surface* surface, Uint8 flags) sge_bmpFont* font; font = new(nothrow) sge_bmpFont; - if(font == nullptr) + if(!font) { SDL_SetError("SGE - Out of memory"); return nullptr; @@ -58,7 +58,7 @@ sge_bmpFont* sge_BF_CreateFont(SDL_Surface* surface, Uint8 flags) if(!(flags & SGE_BFNOCONVERT) && !(flags & SGE_BFSFONT)) { /* Get a converted copy */ font->FontSurface = SDL_DisplayFormat(surface); - if(font->FontSurface == nullptr) + if(!font->FontSurface) { SDL_SetError("SGE - Out of memory"); delete font; @@ -69,7 +69,7 @@ sge_bmpFont* sge_BF_CreateFont(SDL_Surface* surface, Uint8 flags) { // We want an 8bit surface SDL_Surface* tmp; tmp = SDL_AllocSurface(SDL_SWSURFACE, surface->w, surface->h, 8, 0, 0, 0, 0); - if(tmp == nullptr) + if(!tmp) { SDL_SetError("SGE - Out of memory"); SDL_FreeSurface(font->FontSurface); @@ -128,7 +128,7 @@ sge_bmpFont* sge_BF_CreateFont(SDL_Surface* surface, Uint8 flags) else /* Get a copy */ font->FontSurface = sge_copy_surface(surface); - if(font->FontSurface == nullptr) + if(!font->FontSurface) { SDL_SetError("SGE - Out of memory"); delete font; @@ -237,7 +237,7 @@ SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, S ret.w = 0; ret.h = 0; - if(font == nullptr) + if(!font) { return ret; } @@ -369,7 +369,7 @@ void sge_BF_CloseFont(sge_bmpFont* font) //================================================================================== void sge_BF_SetColor(sge_bmpFont* font, Uint8 R, Uint8 G, Uint8 B) { - if(font == nullptr) + if(!font) { return; } diff --git a/SGE/sge_collision.cpp b/SGE/sge_collision.cpp index 082affc..8de7284 100644 --- a/SGE/sge_collision.cpp +++ b/SGE/sge_collision.cpp @@ -229,7 +229,7 @@ int memand(Uint8* s1, Uint8* s2, int shift1, int shift2, int N) //================================================================================== int _sge_cmcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2, Sint16 y2) { - if(cd1->map == nullptr || cd2->map == nullptr) + if(!cd1->map || !cd2->map) return 0; Sint16 w1 = cd1->w; @@ -331,7 +331,7 @@ int sge_cmcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2, if(!sge_bbcheck(cd1, x1, y1, cd2, x2, y2)) return 0; - if(cd1->map == nullptr || cd2->map == nullptr) + if(!cd1->map || !cd2->map) return 1; return _sge_cmcheck(cd1, x1, y1, cd2, x2, y2); diff --git a/SGE/sge_textpp.cpp b/SGE/sge_textpp.cpp index 064dd73..50da048 100644 --- a/SGE/sge_textpp.cpp +++ b/SGE/sge_textpp.cpp @@ -722,7 +722,7 @@ int sge_text_input(sge_TextSurface* tc, Uint8 flags) if(flags & SGE_FLAG1 || !is_ttf) { /* Keep background? */ buffer = SDL_DisplayFormat(screen); - if(buffer == nullptr) + if(!buffer) { SDL_SetError("SGE - Out of memory"); return -3; diff --git a/SGE/sge_tt_text.cpp b/SGE/sge_tt_text.cpp index 92774ba..13dbf26 100644 --- a/SGE/sge_tt_text.cpp +++ b/SGE/sge_tt_text.cpp @@ -277,7 +277,7 @@ sge_TTFont* sge_TTF_OpenFontIndexRW(SDL_RWops* src, int freesrc, int ptsize, lon } font = (sge_TTFont*)malloc(sizeof(*font)); - if(font == nullptr) + if(!font) { SDL_SetError("SGE - Out of memory"); return (nullptr); @@ -288,7 +288,7 @@ sge_TTFont* sge_TTF_OpenFontIndexRW(SDL_RWops* src, int freesrc, int ptsize, lon font->freesrc = freesrc; stream = (FT_Stream)malloc(sizeof(*stream)); - if(stream == nullptr) + if(!stream) { SDL_SetError("SGE - Out of memory"); sge_TTF_CloseFont(font); @@ -856,7 +856,7 @@ Uint16* sge_Latin1_Uni(const char* text) /* Copy the Latin-1 text to a UNICODE text buffer */ unicode_len = static_cast(strlen(text)); unicode_text = (Uint16*)malloc((unicode_len + 1) * (sizeof *unicode_text)); - if(unicode_text == nullptr) + if(!unicode_text) { SDL_SetError("SGE - Out of memory"); return (nullptr); @@ -912,7 +912,7 @@ Uint16* sge_UTF8_Uni(const char* text) /* Copy the UTF-8 text to a UNICODE text buffer */ unicode_len = static_cast(strlen(text)); unicode_text = (Uint16*)malloc((unicode_len + 1) * (sizeof *unicode_text)); - if(unicode_text == nullptr) + if(!unicode_text) { SDL_SetError("SGE - Out of memory"); return (nullptr); @@ -1051,7 +1051,7 @@ SDL_Rect sge_TTF_TextSize(sge_TTFont* font, char* text) /* Copy the Latin-1 text to a UNICODE text buffer */ unicode_len = strlen(text); unicode_text = (Uint16*)malloc((unicode_len + 1) * (sizeof *unicode_text)); - if(unicode_text == nullptr) + if(!unicode_text) { SDL_SetError("SGE - Out of memory"); return ret; @@ -1125,7 +1125,7 @@ SDL_Surface* sge_TTF_Render(sge_TTFont* font, const Uint16* text, SDL_Color fg, textbuf = SDL_AllocSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask); } - if(textbuf == nullptr) + if(!textbuf) { SDL_SetError("SGE - Out of memory"); return (nullptr); @@ -1344,7 +1344,7 @@ SDL_Rect sge_tt_textout_UNI(SDL_Surface* Surface, sge_TTFont* font, const Uint16 SDL_Surface* text; text = sge_TTF_Render(font, uni, sge_GetRGB(Surface, fcolor), sge_GetRGB(Surface, bcolor), Alpha); - if(text == nullptr) + if(!text) { return ret; } @@ -1381,7 +1381,7 @@ SDL_Rect sge_tt_textout_UNI(SDL_Surface* Surface, sge_TTFont* font, const Uint16 SDL_Surface* text; text = sge_TTF_Render(font, uni, sge_FillPaletteEntry(fR, fG, fB), sge_FillPaletteEntry(bR, bG, bB), Alpha); - if(text == nullptr) + if(!text) { return ret; } diff --git a/callbacks.cpp b/callbacks.cpp index 7057e8f..d2c2499 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -32,7 +32,7 @@ void callback::PleaseWait(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDWait != nullptr) + if(WNDWait) break; WNDWait = new CWindow(PleaseWait, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 106, //-V807 global::s2->getDisplaySurface()->h / 2 - 35, 212, 70, "Please wait"); @@ -58,7 +58,7 @@ void callback::PleaseWait(int Param) case CALL_FROM_GAMELOOP: // This window gives a "Please Wait"-string, so it is shown while there is an intensive operation // during ONE gameloop. Therefore it is only shown DURING this ONE operation. If the next gameloop // appears, the operation MUST have been finished and we can destroy this window. - if(WNDWait != nullptr) + if(WNDWait) { global::s2->UnregisterCallback(PleaseWait); WNDWait->setWaste(); @@ -68,7 +68,7 @@ void callback::PleaseWait(int Param) case WINDOW_QUIT_MESSAGE: // this is the global window quit message, callback is explicit called with this value, so destroy the // window - if(WNDWait != nullptr) + if(WNDWait) { WNDWait->setWaste(); WNDWait = nullptr; @@ -94,7 +94,7 @@ void callback::ShowStatus(int Param) switch(Param) { case INITIALIZING_CALL: - if(WND != nullptr) + if(WND) break; WND = new CWindow(ShowStatus, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 106, global::s2->getDisplaySurface()->h / 2 - 35, @@ -120,7 +120,7 @@ void callback::ShowStatus(int Param) case WINDOWQUIT: case MAP_QUIT: - if(WND != nullptr) + if(WND) { WND->setWaste(); WND = nullptr; @@ -258,24 +258,24 @@ void callback::submenuOptions(int Param) return; } // add button for "back to main menu" - SubMenu->addButton(submenuOptions, MAINMENU, (int)(global::s2->GameResolutionX / 2 - 100), 440, 200, 20, BUTTON_RED1, "back"); + SubMenu->addButton(submenuOptions, MAINMENU, (int)(global::s2->GameResolution.x / 2 - 100), 440, 200, 20, BUTTON_RED1, "back"); // add menu title - SubMenu->addText("Options", (int)(global::s2->GameResolutionX / 2 - 20), 10, 14); + SubMenu->addText("Options", (int)(global::s2->GameResolution.x / 2 - 20), 10, 14); // add screen resolution - if(TextResolution != nullptr) + if(TextResolution) SubMenu->delText(TextResolution); - sprintf(puffer, "Game Resolution: %d*%d / %s", global::s2->GameResolutionX, global::s2->GameResolutionY, + sprintf(puffer, "Game Resolution: %d*%d / %s", global::s2->GameResolution.x, global::s2->GameResolution.y, (global::s2->fullscreen ? "Fullscreen" : "Window")); - TextResolution = SubMenu->addText(puffer, (int)(global::s2->GameResolutionX / 2 - 110), 50, 11); - if(ButtonFullscreen != nullptr) + TextResolution = SubMenu->addText(puffer, (int)(global::s2->GameResolution.x / 2 - 110), 50, 11); + if(ButtonFullscreen) SubMenu->delButton(ButtonFullscreen); - ButtonFullscreen = SubMenu->addButton(submenuOptions, FULLSCREEN, (int)(global::s2->GameResolutionX / 2 - 100), 190, 200, 20, + ButtonFullscreen = SubMenu->addButton(submenuOptions, FULLSCREEN, (int)(global::s2->GameResolution.x / 2 - 100), 190, 200, 20, BUTTON_RED1, (global::s2->fullscreen ? "WINDOW" : "FULLSCREEN")); - if(ButtonOpenGL != nullptr) + if(ButtonOpenGL) SubMenu->delButton(ButtonOpenGL); - // ButtonOpenGL = SubMenu->addButton(submenuOptions, OPENGL, (int)(global::s2->GameResolutionX/2-100), 210, 200, 20, + // ButtonOpenGL = SubMenu->addButton(submenuOptions, OPENGL, (int)(global::s2->GameResolution.x/2-100), 210, 200, 20, // BUTTON_RED1, (CSurface::useOpenGL ? "Software-Rendering" : "OpenGL")); add selectbox for resolutions - SelectBoxRes = SubMenu->addSelectBox((int)(global::s2->GameResolutionX / 2 - 100), 70, 200, 110, 11, FONT_YELLOW, BUTTON_GREY); + SelectBoxRes = SubMenu->addSelectBox((int)(global::s2->GameResolution.x / 2 - 100), 70, 200, 110, 11, FONT_YELLOW, BUTTON_GREY); SelectBoxRes->setOption("800 x 600 (SVGA)", submenuOptions, SELECTBOX_800_600); SelectBoxRes->setOption("832 x 624 (Half Megapixel)", submenuOptions, SELECTBOX_832_624); SelectBoxRes->setOption("960 x 540 (QHD)", submenuOptions, SELECTBOX_960_540); @@ -359,254 +359,254 @@ void callback::submenuOptions(int Param) break; case SELECTBOX_800_600: - global::s2->GameResolutionX = 800; - global::s2->GameResolutionY = 600; + global::s2->GameResolution.x = 800; + global::s2->GameResolution.y = 600; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_832_624: - global::s2->GameResolutionX = 832; - global::s2->GameResolutionY = 624; + global::s2->GameResolution.x = 832; + global::s2->GameResolution.y = 624; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_960_540: - global::s2->GameResolutionX = 960; - global::s2->GameResolutionY = 540; + global::s2->GameResolution.x = 960; + global::s2->GameResolution.y = 540; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_964_544: - global::s2->GameResolutionX = 964; - global::s2->GameResolutionY = 544; + global::s2->GameResolution.x = 964; + global::s2->GameResolution.y = 544; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_960_640: - global::s2->GameResolutionX = 960; - global::s2->GameResolutionY = 640; + global::s2->GameResolution.x = 960; + global::s2->GameResolution.y = 640; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_960_720: - global::s2->GameResolutionX = 960; - global::s2->GameResolutionY = 720; + global::s2->GameResolution.x = 960; + global::s2->GameResolution.y = 720; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1024_576: - global::s2->GameResolutionX = 1024; - global::s2->GameResolutionY = 576; + global::s2->GameResolution.x = 1024; + global::s2->GameResolution.y = 576; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1024_600: - global::s2->GameResolutionX = 1024; - global::s2->GameResolutionY = 600; + global::s2->GameResolution.x = 1024; + global::s2->GameResolution.y = 600; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1072_600: - global::s2->GameResolutionX = 1072; - global::s2->GameResolutionY = 600; + global::s2->GameResolution.x = 1072; + global::s2->GameResolution.y = 600; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1152_768: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 768; + global::s2->GameResolution.x = 1152; + global::s2->GameResolution.y = 768; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1024_768: - global::s2->GameResolutionX = 1024; - global::s2->GameResolutionY = 768; + global::s2->GameResolution.x = 1024; + global::s2->GameResolution.y = 768; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1152_864: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 864; + global::s2->GameResolution.x = 1152; + global::s2->GameResolution.y = 864; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1152_870: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 870; + global::s2->GameResolution.x = 1152; + global::s2->GameResolution.y = 870; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1152_900: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 900; + global::s2->GameResolution.x = 1152; + global::s2->GameResolution.y = 900; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1200_800: - global::s2->GameResolutionX = 1200; - global::s2->GameResolutionY = 800; + global::s2->GameResolution.x = 1200; + global::s2->GameResolution.y = 800; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1200_900: - global::s2->GameResolutionX = 1200; - global::s2->GameResolutionY = 900; + global::s2->GameResolution.x = 1200; + global::s2->GameResolution.y = 900; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1280_720: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 720; + global::s2->GameResolution.x = 1280; + global::s2->GameResolution.y = 720; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1280_768: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 768; + global::s2->GameResolution.x = 1280; + global::s2->GameResolution.y = 768; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1280_800: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 800; + global::s2->GameResolution.x = 1280; + global::s2->GameResolution.y = 800; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1280_854: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 854; + global::s2->GameResolution.x = 1280; + global::s2->GameResolution.y = 854; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1360_768: - global::s2->GameResolutionX = 1360; - global::s2->GameResolutionY = 768; + global::s2->GameResolution.x = 1360; + global::s2->GameResolution.y = 768; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1366_768: - global::s2->GameResolutionX = 1366; - global::s2->GameResolutionY = 768; + global::s2->GameResolution.x = 1366; + global::s2->GameResolution.y = 768; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1376_768: - global::s2->GameResolutionX = 1376; - global::s2->GameResolutionY = 768; + global::s2->GameResolution.x = 1376; + global::s2->GameResolution.y = 768; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1400_900: - global::s2->GameResolutionX = 1400; - global::s2->GameResolutionY = 900; + global::s2->GameResolution.x = 1400; + global::s2->GameResolution.y = 900; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1440_900: - global::s2->GameResolutionX = 1440; - global::s2->GameResolutionY = 900; + global::s2->GameResolution.x = 1440; + global::s2->GameResolution.y = 900; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1440_960: - global::s2->GameResolutionX = 1440; - global::s2->GameResolutionY = 960; + global::s2->GameResolution.x = 1440; + global::s2->GameResolution.y = 960; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1280_960: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 960; + global::s2->GameResolution.x = 1280; + global::s2->GameResolution.y = 960; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1280_1024: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 1024; + global::s2->GameResolution.x = 1280; + global::s2->GameResolution.y = 1024; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1360_1024: - global::s2->GameResolutionX = 1360; - global::s2->GameResolutionY = 1024; + global::s2->GameResolution.x = 1360; + global::s2->GameResolution.y = 1024; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1366_1024: - global::s2->GameResolutionX = 1366; - global::s2->GameResolutionY = 1024; + global::s2->GameResolution.x = 1366; + global::s2->GameResolution.y = 1024; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1600_768: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 768; + global::s2->GameResolution.x = 1600; + global::s2->GameResolution.y = 768; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1600_900: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 900; + global::s2->GameResolution.x = 1600; + global::s2->GameResolution.y = 900; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1600_1024: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 1024; + global::s2->GameResolution.x = 1600; + global::s2->GameResolution.y = 1024; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1400_1050: - global::s2->GameResolutionX = 1400; - global::s2->GameResolutionY = 1050; + global::s2->GameResolution.x = 1400; + global::s2->GameResolution.y = 1050; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1680_1050: - global::s2->GameResolutionX = 1680; - global::s2->GameResolutionY = 1050; + global::s2->GameResolution.x = 1680; + global::s2->GameResolution.y = 1050; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1600_1200: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 1200; + global::s2->GameResolution.x = 1600; + global::s2->GameResolution.y = 1200; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1920_1080: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1080; + global::s2->GameResolution.x = 1920; + global::s2->GameResolution.y = 1080; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1920_1200: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1200; + global::s2->GameResolution.x = 1920; + global::s2->GameResolution.y = 1200; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1920_1400: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1400; + global::s2->GameResolution.x = 1920; + global::s2->GameResolution.y = 1400; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_1920_1440: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1440; + global::s2->GameResolution.x = 1920; + global::s2->GameResolution.y = 1440; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_2048_1152: - global::s2->GameResolutionX = 2048; - global::s2->GameResolutionY = 1152; + global::s2->GameResolution.x = 2048; + global::s2->GameResolution.y = 1152; submenuOptions(GRAPHICS_CHANGE); break; case SELECTBOX_2048_1536: - global::s2->GameResolutionX = 2048; - global::s2->GameResolutionY = 1536; + global::s2->GameResolution.x = 2048; + global::s2->GameResolution.y = 1536; submenuOptions(GRAPHICS_CHANGE); break; @@ -634,7 +634,7 @@ void callback::EditorHelpMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDHelp != nullptr) + if(WNDHelp) break; WNDHelp = new CWindow(EditorHelpMenu, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 320, global::s2->getDisplaySurface()->h / 2 - 240, 640, 380, "Hilfe", WINDOW_GREEN2, @@ -708,7 +708,7 @@ void callback::EditorHelpMenu(int Param) case WINDOW_QUIT_MESSAGE: // this is the global window quit message, callback is explicit called with this value, so destroy the // window - if(WNDHelp != nullptr) + if(WNDHelp) { WNDHelp->setWaste(); WNDHelp = nullptr; @@ -717,7 +717,7 @@ void callback::EditorHelpMenu(int Param) break; case WINDOWQUIT: // this is the own window quit message of the callback - if(WNDHelp != nullptr) + if(WNDHelp) { WNDHelp->setWaste(); WNDHelp = nullptr; @@ -726,7 +726,7 @@ void callback::EditorHelpMenu(int Param) break; case MAP_QUIT: // this is the global window quit message, callback is explicit called with this value, so destroy the window - if(WNDHelp != nullptr) + if(WNDHelp) { WNDHelp->setWaste(); WNDHelp = nullptr; @@ -753,10 +753,10 @@ void callback::EditorMainMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDMain != nullptr) + if(WNDMain) break; - WNDMain = new CWindow(EditorMainMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 110, global::s2->GameResolutionY / 2 - 160, - 220, 320, "Main menu", WINDOW_GREEN1, WINDOW_CLOSE); + WNDMain = new CWindow(EditorMainMenu, WINDOWQUIT, global::s2->GameResolution.x / 2 - 110, + global::s2->GameResolution.y / 2 - 160, 220, 320, "Main menu", WINDOW_GREEN1, WINDOW_CLOSE); if(global::s2->RegisterWindow(WNDMain)) { WNDMain->addButton(EditorMainMenu, LOADMENU, 8, 100, 190, 20, BUTTON_GREEN2, "Load map"); @@ -772,7 +772,7 @@ void callback::EditorMainMenu(int Param) break; case WINDOWQUIT: - if(WNDMain != nullptr) + if(WNDMain) { WNDMain->setWaste(); WNDMain = nullptr; @@ -780,7 +780,7 @@ void callback::EditorMainMenu(int Param) break; case MAP_QUIT: - if(WNDMain != nullptr) + if(WNDMain) { WNDMain->setWaste(); WNDMain = nullptr; @@ -812,9 +812,9 @@ void callback::EditorLoadMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDLoad != nullptr) + if(WNDLoad) break; - WNDLoad = new CWindow(EditorLoadMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 140, global::s2->GameResolutionY / 2 - 45, + WNDLoad = new CWindow(EditorLoadMenu, WINDOWQUIT, global::s2->GameResolution.x / 2 - 140, global::s2->GameResolution.y / 2 - 45, 280, 120, "Load", WINDOW_GREEN1, WINDOW_CLOSE); if(global::s2->RegisterWindow(WNDLoad)) { @@ -833,7 +833,7 @@ void callback::EditorLoadMenu(int Param) break; case WINDOWQUIT: - if(WNDLoad != nullptr) + if(WNDLoad) { WNDLoad->setWaste(); WNDLoad = nullptr; @@ -842,7 +842,7 @@ void callback::EditorLoadMenu(int Param) break; case MAP_QUIT: - if(WNDLoad != nullptr) + if(WNDLoad) { WNDLoad->setWaste(); WNDLoad = nullptr; @@ -912,10 +912,10 @@ void callback::EditorSaveMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDSave != nullptr) + if(WNDSave) break; - WNDSave = new CWindow(EditorSaveMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 140, global::s2->GameResolutionY / 2 - 100, - 280, 200, "Save", WINDOW_GREEN1, WINDOW_CLOSE); + WNDSave = new CWindow(EditorSaveMenu, WINDOWQUIT, global::s2->GameResolution.x / 2 - 140, + global::s2->GameResolution.y / 2 - 100, 280, 200, "Save", WINDOW_GREEN1, WINDOW_CLOSE); if(global::s2->RegisterWindow(WNDSave)) { MapObj = global::s2->getMapObj(); @@ -940,7 +940,7 @@ void callback::EditorSaveMenu(int Param) break; case WINDOWQUIT: - if(WNDSave != nullptr) + if(WNDSave) { WNDSave->setWaste(); WNDSave = nullptr; @@ -951,7 +951,7 @@ void callback::EditorSaveMenu(int Param) break; case MAP_QUIT: - if(WNDSave != nullptr) + if(WNDSave) { WNDSave->setWaste(); WNDSave = nullptr; @@ -998,10 +998,10 @@ void callback::EditorQuitMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDBackToMainMenu != nullptr) + if(WNDBackToMainMenu) break; - WNDBackToMainMenu = new CWindow(EditorQuitMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 106, - global::s2->GameResolutionY / 2 - 55, 212, 110, "Exit?"); + WNDBackToMainMenu = new CWindow(EditorQuitMenu, WINDOWQUIT, global::s2->GameResolution.x / 2 - 106, + global::s2->GameResolution.y / 2 - 55, 212, 110, "Exit?"); if(global::s2->RegisterWindow(WNDBackToMainMenu)) { WNDBackToMainMenu->addButton(EditorQuitMenu, BACKTOMAIN, 0, 0, 100, 80, BUTTON_GREEN2, nullptr, PICTURE_SMALL_TICK); @@ -1015,7 +1015,7 @@ void callback::EditorQuitMenu(int Param) break; case BACKTOMAIN: - if(global::s2->getMapObj() != nullptr) + if(global::s2->getMapObj()) global::s2->delMapObj(); WNDBackToMainMenu->setWaste(); WNDBackToMainMenu = nullptr; @@ -1038,7 +1038,7 @@ void callback::EditorQuitMenu(int Param) break; case NOTBACKTOMAIN: - if(WNDBackToMainMenu != nullptr) + if(WNDBackToMainMenu) { WNDBackToMainMenu->setWaste(); WNDBackToMainMenu = nullptr; @@ -1085,7 +1085,7 @@ void callback::EditorTextureMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDTexture != nullptr) + if(WNDTexture) break; WNDTexture = new CWindow(EditorTextureMenu, WINDOWQUIT, PosX, PosY, 220, 133, "Terrain", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); @@ -1310,7 +1310,7 @@ void callback::EditorTextureMenu(int Param) break; case WINDOW_CLICKED_CALL: - if(MapObj != nullptr) + if(MapObj) { MapObj->setMode(EDITOR_MODE_TEXTURE); MapObj->setModeContent(lastContent); @@ -1318,7 +1318,7 @@ void callback::EditorTextureMenu(int Param) break; case WINDOWQUIT: - if(WNDTexture != nullptr) + if(WNDTexture) { PosX = WNDTexture->getX(); PosY = WNDTexture->getY(); @@ -1336,7 +1336,7 @@ void callback::EditorTextureMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDTexture != nullptr) + if(WNDTexture) { PosX = WNDTexture->getX(); PosY = WNDTexture->getY(); @@ -1384,7 +1384,7 @@ void callback::EditorTreeMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDTree != nullptr) + if(WNDTree) break; WNDTree = new CWindow(EditorTreeMenu, WINDOWQUIT, PosX, PosY, 148, 140, "Trees", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); @@ -1516,7 +1516,7 @@ void callback::EditorTreeMenu(int Param) break; case WINDOW_CLICKED_CALL: - if(MapObj != nullptr) + if(MapObj) { MapObj->setMode(EDITOR_MODE_TREE); MapObj->setModeContent(lastContent); @@ -1525,7 +1525,7 @@ void callback::EditorTreeMenu(int Param) break; case WINDOWQUIT: - if(WNDTree != nullptr) + if(WNDTree) { PosX = WNDTree->getX(); PosY = WNDTree->getY(); @@ -1543,7 +1543,7 @@ void callback::EditorTreeMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDTree != nullptr) + if(WNDTree) { PosX = WNDTree->getX(); PosY = WNDTree->getY(); @@ -1579,7 +1579,7 @@ void callback::EditorResourceMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDResource != nullptr) + if(WNDResource) break; WNDResource = new CWindow(EditorResourceMenu, WINDOWQUIT, PosX, PosY, 148, 55, "Resources", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); @@ -1621,7 +1621,7 @@ void callback::EditorResourceMenu(int Param) break; case WINDOW_CLICKED_CALL: - if(MapObj != nullptr) + if(MapObj) { MapObj->setMode(EDITOR_MODE_RESOURCE_RAISE); MapObj->setModeContent(lastContent); @@ -1629,7 +1629,7 @@ void callback::EditorResourceMenu(int Param) break; case WINDOWQUIT: - if(WNDResource != nullptr) + if(WNDResource) { PosX = WNDResource->getX(); PosY = WNDResource->getY(); @@ -1644,7 +1644,7 @@ void callback::EditorResourceMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDResource != nullptr) + if(WNDResource) { PosX = WNDResource->getX(); PosY = WNDResource->getY(); @@ -1687,7 +1687,7 @@ void callback::EditorLandscapeMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDLandscape != nullptr) + if(WNDLandscape) break; WNDLandscape = new CWindow(EditorLandscapeMenu, WINDOWQUIT, PosX, PosY, 112, 174, "Landscape", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); @@ -1814,7 +1814,7 @@ void callback::EditorLandscapeMenu(int Param) break; case WINDOW_CLICKED_CALL: - if(MapObj != nullptr) + if(MapObj) { MapObj->setMode(EDITOR_MODE_LANDSCAPE); MapObj->setModeContent(lastContent); @@ -1823,7 +1823,7 @@ void callback::EditorLandscapeMenu(int Param) break; case WINDOWQUIT: - if(WNDLandscape != nullptr) + if(WNDLandscape) { PosX = WNDLandscape->getX(); PosY = WNDLandscape->getY(); @@ -1841,7 +1841,7 @@ void callback::EditorLandscapeMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDLandscape != nullptr) + if(WNDLandscape) { PosX = WNDLandscape->getX(); PosY = WNDLandscape->getY(); @@ -1879,7 +1879,7 @@ void callback::EditorAnimalMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDAnimal != nullptr) + if(WNDAnimal) break; WNDAnimal = new CWindow(EditorAnimalMenu, WINDOWQUIT, PosX, PosY, 116, 106, "Animals", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); @@ -1930,7 +1930,7 @@ void callback::EditorAnimalMenu(int Param) break; case WINDOW_CLICKED_CALL: - if(MapObj != nullptr) + if(MapObj) { MapObj->setMode(EDITOR_MODE_ANIMAL); MapObj->setModeContent(lastContent); @@ -1938,7 +1938,7 @@ void callback::EditorAnimalMenu(int Param) break; case WINDOWQUIT: - if(WNDAnimal != nullptr) + if(WNDAnimal) { PosX = WNDAnimal->getX(); PosY = WNDAnimal->getY(); @@ -1953,7 +1953,7 @@ void callback::EditorAnimalMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDAnimal != nullptr) + if(WNDAnimal) { PosX = WNDAnimal->getX(); PosY = WNDAnimal->getY(); @@ -1991,7 +1991,7 @@ void callback::EditorPlayerMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDPlayer != nullptr) + if(WNDPlayer) break; WNDPlayer = new CWindow(EditorPlayerMenu, WINDOWQUIT, PosX, PosY, 100, 80, "Players", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); @@ -2044,14 +2044,14 @@ void callback::EditorPlayerMenu(int Param) if(PlayerHQx[PlayerNumber] != 0xFFFF && PlayerHQy[PlayerNumber] != 0xFFFF) { tempRect = MapObj->getDisplayRect(); - tempRect.x = PlayerHQx[PlayerNumber] * TRIANGLE_WIDTH - tempRect.w / 2; - tempRect.y = PlayerHQy[PlayerNumber] * TRIANGLE_HEIGHT - tempRect.h / 2; + tempRect.setOrigin(Position(PlayerHQx[PlayerNumber], PlayerHQy[PlayerNumber]) * Position(TRIANGLE_WIDTH, TRIANGLE_HEIGHT) + - tempRect.getSize() / 2); MapObj->setDisplayRect(tempRect); } break; case WINDOW_CLICKED_CALL: - if(MapObj != nullptr) + if(MapObj) { MapObj->setMode(EDITOR_MODE_FLAG); MapObj->setModeContent(PlayerNumber); @@ -2059,7 +2059,7 @@ void callback::EditorPlayerMenu(int Param) break; case WINDOWQUIT: - if(WNDPlayer != nullptr) + if(WNDPlayer) { PosX = WNDPlayer->getX(); PosY = WNDPlayer->getY(); @@ -2078,7 +2078,7 @@ void callback::EditorPlayerMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDPlayer != nullptr) + if(WNDPlayer) { PosX = WNDPlayer->getX(); PosY = WNDPlayer->getY(); @@ -2118,7 +2118,7 @@ void callback::EditorCursorMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDCursor != nullptr) + if(WNDCursor) break; WNDCursor = new CWindow(EditorCursorMenu, WINDOWQUIT, PosX, PosY, 210, 130, "Cursor", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); @@ -2132,7 +2132,7 @@ void callback::EditorCursorMenu(int Param) CursorModeButton = WNDCursor->addButton(EditorCursorMenu, CURSORMODE, 2, 2, 96, 32, BUTTON_GREY, "Hexagon"); CursorRandomButton = WNDCursor->addButton(EditorCursorMenu, CURSORRANDOM, 2, 34, 196, 32, BUTTON_GREY, "Cursor-Activity: static"); - if(MapObj != nullptr) + if(MapObj) { MapObj->setVertexFillRSU(true); MapObj->setVertexFillUSD(true); @@ -2209,7 +2209,7 @@ void callback::EditorCursorMenu(int Param) break; case CURSORMODE: - if(CursorModeButton != nullptr) + if(CursorModeButton) { WNDCursor->delButton(CursorModeButton); CursorModeButton = nullptr; @@ -2225,7 +2225,7 @@ void callback::EditorCursorMenu(int Param) } break; case CURSORRANDOM: - if(CursorRandomButton != nullptr) + if(CursorRandomButton) { WNDCursor->delButton(CursorRandomButton); CursorRandomButton = nullptr; @@ -2246,7 +2246,7 @@ void callback::EditorCursorMenu(int Param) case WINDOW_CLICKED_CALL: break; case WINDOWQUIT: - if(WNDCursor != nullptr) + if(WNDCursor) { PosX = WNDCursor->getX(); PosY = WNDCursor->getY(); @@ -2263,7 +2263,7 @@ void callback::EditorCursorMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT - if(WNDCursor != nullptr) + if(WNDCursor) { PosX = WNDCursor->getX(); PosY = WNDCursor->getY(); @@ -2302,7 +2302,7 @@ void callback::EditorCreateMenu(int Param) static int border = 0; static int border_texture = TRIANGLE_TEXTURE_SNOW; static char puffer[5]; - int PosX = global::s2->GameResolutionX / 2 - 125, PosY = global::s2->GameResolutionY / 2 - 175; + int PosX = global::s2->GameResolution.x / 2 - 125, PosY = global::s2->GameResolution.y / 2 - 175; enum { @@ -2332,7 +2332,7 @@ void callback::EditorCreateMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDCreate != nullptr) + if(WNDCreate) break; WNDCreate = new CWindow(EditorCreateMenu, WINDOWQUIT, PosX, PosY, 250, 350, "Create world", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE); @@ -2981,7 +2981,7 @@ void callback::EditorCreateMenu(int Param) break; case MAP_QUIT: - if(WNDCreate != nullptr) + if(WNDCreate) { PosX = WNDCreate->getX(); PosY = WNDCreate->getY(); @@ -3006,7 +3006,7 @@ void callback::EditorCreateMenu(int Param) break; case WINDOWQUIT: - if(WNDCreate != nullptr) + if(WNDCreate) { PosX = WNDCreate->getX(); PosY = WNDCreate->getY(); @@ -3050,10 +3050,10 @@ void callback::GameMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDBackToMainMenu != nullptr) + if(WNDBackToMainMenu) break; WNDBackToMainMenu = - new CWindow(GameMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 125, global::s2->GameResolutionY / 2 - 60, 250, 140, + new CWindow(GameMenu, WINDOWQUIT, global::s2->GameResolution.x / 2 - 125, global::s2->GameResolution.y / 2 - 60, 250, 140, "Back to the main menu?", WINDOW_GREEN1, WINDOW_CLOSE); if(global::s2->RegisterWindow(WNDBackToMainMenu)) { @@ -3075,7 +3075,7 @@ void callback::GameMenu(int Param) break; case WINDOWQUIT: - if(WNDBackToMainMenu != nullptr) + if(WNDBackToMainMenu) { WNDBackToMainMenu->setWaste(); WNDBackToMainMenu = nullptr; @@ -3105,7 +3105,7 @@ void callback::MinimapMenu(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDMinimap != nullptr) + if(WNDMinimap) break; { // this variables are needed to reduce the size of minimap-windows of big maps @@ -3118,8 +3118,8 @@ void callback::MinimapMenu(int Param) //--> 12px is width of left and right window frame and 30px is height of the upper and lower window frame if((global::s2->getDisplaySurface()->w - 12 < width) || (global::s2->getDisplaySurface()->h - 30 < height)) break; - WNDMinimap = new CWindow(MinimapMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - width / 2 - 6, - global::s2->GameResolutionY / 2 - height / 2 - 15, width + 12, height + 30, "Overview", + WNDMinimap = new CWindow(MinimapMenu, WINDOWQUIT, global::s2->GameResolution.x / 2 - width / 2 - 6, + global::s2->GameResolution.y / 2 - height / 2 - 15, width + 12, height + 30, "Overview", WINDOW_NOTHING, WINDOW_CLOSE | WINDOW_MOVE); if(global::s2->RegisterWindow(WNDMinimap) && global::s2->RegisterCallback(MinimapMenu)) WndSurface = WNDMinimap->getSurface(); @@ -3134,24 +3134,24 @@ void callback::MinimapMenu(int Param) break; case CALL_FROM_GAMELOOP: - if(MapObj != nullptr && WndSurface != nullptr) + if(MapObj && WndSurface) MapObj->drawMinimap(WndSurface); break; case WINDOW_CLICKED_CALL: - if(MapObj != nullptr) + if(MapObj) { - int MouseX, MouseY; - if(SDL_GetMouseState(&MouseX, &MouseY) & SDL_BUTTON(1)) + Position mouse; + if(SDL_GetMouseState(&mouse.x, &mouse.y) & SDL_BUTTON(1)) { - if(MouseX > (WNDMinimap->getX() + 6) && MouseX < (WNDMinimap->getX() + WNDMinimap->getW() - 6) - && MouseY > (WNDMinimap->getY() + 20) && MouseY < (WNDMinimap->getY() + WNDMinimap->getH() - 10)) + if(mouse.x > (WNDMinimap->getX() + 6) && mouse.x < (WNDMinimap->getX() + WNDMinimap->getW() - 6) + && mouse.y > (WNDMinimap->getY() + 20) && mouse.y < (WNDMinimap->getY() + WNDMinimap->getH() - 10)) { DisplayRectangle displayRect = MapObj->getDisplayRect(); - displayRect.x = - (MouseX - WNDMinimap->getX() - 6 - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx) * TRIANGLE_WIDTH * scaleNum; - displayRect.y = - (MouseY - WNDMinimap->getY() - 20 - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny) * TRIANGLE_HEIGHT * scaleNum; + displayRect.setOrigin( + (mouse - WNDMinimap->getRect().getOrigin() - Position(6, 20) + - Position(global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx, global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny)) + * Position(TRIANGLE_WIDTH, TRIANGLE_HEIGHT) * scaleNum); MapObj->setDisplayRect(displayRect); } } @@ -3159,7 +3159,7 @@ void callback::MinimapMenu(int Param) break; case WINDOWQUIT: - if(WNDMinimap != nullptr) + if(WNDMinimap) { WNDMinimap->setWaste(); WNDMinimap = nullptr; @@ -3171,7 +3171,7 @@ void callback::MinimapMenu(int Param) case MAP_QUIT: // we do the same like in case WINDOWQUIT - if(WNDMinimap != nullptr) + if(WNDMinimap) { WNDMinimap->setWaste(); WNDMinimap = nullptr; @@ -3196,7 +3196,7 @@ void callback::debugger(int Param) switch(Param) { case INITIALIZING_CALL: - if(Debugger != nullptr) + if(Debugger) break; Debugger = new CDebug(debugger, DEBUGGER_QUIT); break; @@ -3207,7 +3207,7 @@ void callback::debugger(int Param) break; default: - if(Debugger != nullptr) + if(Debugger) Debugger->sendParam(Param); break; } @@ -3236,7 +3236,7 @@ void callback::viewer(int Param) switch(Param) { case INITIALIZING_CALL: - if(WNDViewer != nullptr) + if(WNDViewer) break; WNDViewer = new CWindow(viewer, WINDOWQUIT, 0, 0, 250, 140, "Viewer", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MOVE | WINDOW_RESIZE | WINDOW_MINIMIZE); @@ -3262,12 +3262,12 @@ void callback::viewer(int Param) WNDViewer->delStaticPicture(PicInWndIndex); PicInWndIndex = WNDViewer->addStaticPicture(5, 30, index); - if(PicInfosText != nullptr) + if(PicInfosText) { if(WNDViewer->delText(PicInfosText)) PicInfosText = nullptr; } - if(PicInfosText == nullptr) + if(!PicInfosText) { sprintf(PicInfos, "index=%d, w=%d, h=%d, nx=%d, ny=%d", index, global::bmpArray[index].w, global::bmpArray[index].h, global::bmpArray[index].nx, global::bmpArray[index].ny); @@ -3308,7 +3308,7 @@ void callback::viewer(int Param) break; case WINDOWQUIT: - if(WNDViewer != nullptr) + if(WNDViewer) { WNDViewer->setWaste(); WNDViewer = nullptr; @@ -3414,12 +3414,12 @@ void callback::submenu1(int Param) testTextfield_testWindow = nullptr; testSelectBox = nullptr; global::s2->UnregisterCallback(submenu1); - if(testWindow != nullptr) + if(testWindow) { testWindow->setWaste(); testWindow = nullptr; } - if(testWindow2 != nullptr) + if(testWindow2) { testWindow2->setWaste(); testWindow2 = nullptr; @@ -3429,7 +3429,7 @@ void callback::submenu1(int Param) case GREATMOON: SubMenu->addText("Title!", 300, 10, 14); - sprintf(puffer, "Window X: %d Window Y: %d", global::s2->GameResolutionX, global::s2->GameResolutionY); + sprintf(puffer, "Window X: %d Window Y: %d", global::s2->GameResolution.x, global::s2->GameResolution.y); SubMenu->addText(puffer, 10, 10, 14); break; @@ -3445,7 +3445,7 @@ void callback::submenu1(int Param) break; case CREATEWINDOW: - if(testWindow == nullptr) + if(!testWindow) { testWindow = new CWindow(submenu1, TESTWINDOWQUITMESSAGE, 5, 5, 350, 240, "Window", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); @@ -3465,7 +3465,7 @@ void callback::submenu1(int Param) return; } } - if(testWindow2 == nullptr) + if(!testWindow2) { testWindow2 = new CWindow(submenu1, TESTWINDOW2QUITMESSAGE, 200, 5, 350, 240, "Another Window", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); @@ -3483,12 +3483,12 @@ void callback::submenu1(int Param) break; case GREATMOONENTRY: - if(greatMoonText == nullptr) + if(!greatMoonText) greatMoonText = SubMenu->addText("Test-Text", 100, 10, 14); break; case GREATMOONLEAVE: - if(greatMoonText != nullptr) + if(greatMoonText) { SubMenu->delText(greatMoonText); greatMoonText = nullptr; @@ -3496,7 +3496,7 @@ void callback::submenu1(int Param) break; case PICOBJECT: - if(greatMoon != nullptr) + if(greatMoon) { SubMenu->delButton(greatMoon); greatMoon = nullptr; @@ -3504,12 +3504,12 @@ void callback::submenu1(int Param) break; case PICOBJECTENTRY: - if(greatMoonText == nullptr) + if(!greatMoonText) greatMoonText = SubMenu->addText("Test-Text", 100, 10, 14); break; case PICOBJECTLEAVE: - if(greatMoonText != nullptr) + if(greatMoonText) { SubMenu->delText(greatMoonText); greatMoonText = nullptr; @@ -3517,7 +3517,7 @@ void callback::submenu1(int Param) break; case TESTWINDOWPICTURE: - if(testWindowText == nullptr) + if(!testWindowText) testWindowText = testWindow->addText("Clicked on castle", 10, 200, 11); else { @@ -3527,7 +3527,7 @@ void callback::submenu1(int Param) break; case TESTWINDOWPICTUREENTRY: - if(testWindowText2 != nullptr) + if(testWindowText2) { testWindow->delText(testWindowText2); testWindowText2 = nullptr; @@ -3536,7 +3536,7 @@ void callback::submenu1(int Param) break; case TESTWINDOWPICTURELEAVE: - if(testWindowText2 != nullptr) + if(testWindowText2) { testWindow->delText(testWindowText2); testWindowText2 = nullptr; @@ -3557,18 +3557,18 @@ void callback::submenu1(int Param) case CALL_FROM_GAMELOOP: if(counter % 10 == 0) { - if(counterText != nullptr) + if(counterText) { if(SubMenu->delText(counterText)) counterText = nullptr; } - if(counterText == nullptr) + if(!counterText) { sprintf(puffer, "counter: %d", counter); counterText = SubMenu->addText(puffer, 100, 20, 9); } - if(TextFrom_testTextfield != nullptr) + if(TextFrom_testTextfield) { SubMenu->delText(TextFrom_testTextfield); TextFrom_testTextfield = nullptr; diff --git a/defines.h b/defines.h index 2b735e9..1c0f3f0 100644 --- a/defines.h +++ b/defines.h @@ -3,6 +3,7 @@ #include "commonDefines.h" #include "Point.h" +#include "Rect.h" #include "gameData/DescIdx.h" #include @@ -139,11 +140,7 @@ struct MapNode } }; // structure for display, cause SDL_Rect's datatypes are too small -struct DisplayRectangle -{ - Sint32 x, y; - Sint32 w, h; -}; +using DisplayRectangle = RectBase; typedef Point Point16; typedef Point Point32; // map strutcture