From 506521695a75554ba82e58f081a4cd276b247bd6 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sat, 27 Jul 2024 22:20:14 +0300 Subject: [PATCH] Isolate 2dlib submodule Isolate 2dlib from rest of the project, minor cleanups --- 2dlib/CMakeLists.txt | 11 ++++++++--- 2dlib/font.cpp | 16 ++++++++-------- {lib => 2dlib}/gr.h | 1 - 2dlib/hardsurf.cpp | 2 +- 2dlib/memsurf.cpp | 23 +++++++++++----------- 2dlib/pentext.cpp | 3 +-- 2dlib/screen.cpp | 2 -- 2dlib/surface.cpp | 33 ++++++++++++++++---------------- 2dlib/viewport.cpp | 12 ++++++------ dd_grwin32/CMakeLists.txt | 1 + editor/WorldObjectsRobotDialog.h | 2 +- 11 files changed, 53 insertions(+), 53 deletions(-) rename {lib => 2dlib}/gr.h (99%) diff --git a/2dlib/CMakeLists.txt b/2dlib/CMakeLists.txt index 80c6ff10..5eff141e 100644 --- a/2dlib/CMakeLists.txt +++ b/2dlib/CMakeLists.txt @@ -1,4 +1,3 @@ -set(HEADERS lib2d.h) set(CPPS font.cpp hardsurf.cpp @@ -7,11 +6,17 @@ set(CPPS pentext.cpp screen.cpp surface.cpp - viewport.cpp) + viewport.cpp +) -add_library(2dlib STATIC ${HEADERS} ${CPPS}) +add_library(2dlib STATIC ${CPPS}) target_link_libraries(2dlib PRIVATE cfile mem misc ) +target_include_directories(2dlib PUBLIC + $ +) diff --git a/2dlib/font.cpp b/2dlib/font.cpp index 7befec09..aedfd724 100644 --- a/2dlib/font.cpp +++ b/2dlib/font.cpp @@ -116,16 +116,16 @@ * $NoKeywords: $ */ +#include +#include + +#include "bitmap.h" +#include "cfile.h" +#include "gr.h" +#include "mem.h" +#include "mono.h" #include "pserror.h" #include "renderer.h" -#include "gr.h" -#include "mono.h" -#include "cfile.h" -#include "bitmap.h" -#include "mem.h" - -#include -#include #define FT_COLOR 1 #define FT_PROPORTIONAL 2 diff --git a/lib/gr.h b/2dlib/gr.h similarity index 99% rename from lib/gr.h rename to 2dlib/gr.h index 762e1a57..e7237835 100644 --- a/lib/gr.h +++ b/2dlib/gr.h @@ -107,7 +107,6 @@ #include "Ddgr.h" #include "fix.h" #include "pserror.h" -#include "pstypes.h" class grMemorySurface; class grViewport; diff --git a/2dlib/hardsurf.cpp b/2dlib/hardsurf.cpp index 4762e292..16f4aeaa 100644 --- a/2dlib/hardsurf.cpp +++ b/2dlib/hardsurf.cpp @@ -55,5 +55,5 @@ grHardwareSurface::~grHardwareSurface() {} bool grHardwareSurface::create(int w, int h, int bpp, unsigned flags, const char *name) { grSurface::create(w, h, bpp, SURFTYPE_GENERIC, flags, name); - return 1; + return true; } diff --git a/2dlib/memsurf.cpp b/2dlib/memsurf.cpp index 6d96729a..6d9a1eca 100644 --- a/2dlib/memsurf.cpp +++ b/2dlib/memsurf.cpp @@ -68,12 +68,11 @@ * $NoKeywords: $ */ -#include "lib2d.h" +#include +#include #include "bitmap.h" - -#include -#include +#include "lib2d.h" #include "mem.h" // ---------------------------------------------------------------------------- @@ -81,19 +80,19 @@ // ---------------------------------------------------------------------------- grMemorySurface::grMemorySurface() : grSurface() { - m_FirstTimeInit = 1; - m_AllowInit = 1; + m_FirstTimeInit = true; + m_AllowInit = true; } grMemorySurface::grMemorySurface(int w, int h, int bpp, unsigned flags, const char *name) : grSurface(w, h, bpp, SURFTYPE_MEMORY, flags, name) { - m_FirstTimeInit = 0; - m_AllowInit = 0; + m_FirstTimeInit = false; + m_AllowInit = false; } grMemorySurface::grMemorySurface(int bm) { - m_FirstTimeInit = 1; - m_AllowInit = 1; + m_FirstTimeInit = true; + m_AllowInit = true; grMemorySurface::init(bm_w(bm, 0), bm_h(bm, 0), bm_bpp(bm), (char *)bm_data(bm, 0), bm_rowsize(bm, 0), SURFFLAG_COLORKEY); @@ -115,7 +114,7 @@ bool grMemorySurface::init(int w, int h, int bpp, char *data, int rowsize, unsig if (m_FirstTimeInit) { // add to list ONLY ONCE! add_to_list(&ddsfObj); - m_FirstTimeInit = 0; + m_FirstTimeInit = false; } ddsfObj.w = w; @@ -127,7 +126,7 @@ bool grMemorySurface::init(int w, int h, int bpp, char *data, int rowsize, unsig strncpy(ddsfObj.name, name, 15); if (!gr_mem_surf_Init(&ddsfObj, data, rowsize)) - return 0; + return false; surf_init(1); diff --git a/2dlib/pentext.cpp b/2dlib/pentext.cpp index c6892fe5..b018299a 100644 --- a/2dlib/pentext.cpp +++ b/2dlib/pentext.cpp @@ -83,9 +83,8 @@ #include #include +#include -#include -#include #include "gr.h" #include "mono.h" #include "renderer.h" diff --git a/2dlib/screen.cpp b/2dlib/screen.cpp index 10672999..279505c1 100644 --- a/2dlib/screen.cpp +++ b/2dlib/screen.cpp @@ -45,8 +45,6 @@ * $NoKeywords: $ */ -#include - #include "gr.h" #include "pserror.h" #include "renderer.h" diff --git a/2dlib/surface.cpp b/2dlib/surface.cpp index 4b94ad1d..3a924580 100644 --- a/2dlib/surface.cpp +++ b/2dlib/surface.cpp @@ -86,15 +86,14 @@ */ #include +#include +#include -#include -#include - +#include "bitmap.h" #include "lib2d.h" #include "pserror.h" -#include "bitmap.h" -#include "texture.h" #include "renderer.h" +#include "texture.h" static inline unsigned XLAT_RGB_TO_16(ddgr_color c) { uint8_t r, g, b; @@ -105,9 +104,9 @@ static inline unsigned XLAT_RGB_TO_16(ddgr_color c) { return (((r >> 3) << 10) + ((g >> 3) << 5) + (b >> 3)); } -ddgr_surface_node *grSurface::surf_list = NULL; // the surface list -ddgr_surface_node *grSurface::surf_list_cur = NULL; // current node on list. -ddgr_surface *grSurface::scratch_mem_surf = NULL; +ddgr_surface_node *grSurface::surf_list = nullptr; // the surface list +ddgr_surface_node *grSurface::surf_list_cur = nullptr; // current node on list. +ddgr_surface *grSurface::scratch_mem_surf = nullptr; void grSurface::init_system() { // allocate our scratch memory surface used in uniblt @@ -122,11 +121,11 @@ void grSurface::init_system() { void grSurface::close_system() { // cleanup our scratch memory surface for blt if (grSurface::scratch_mem_surf) { - if (grSurface::scratch_mem_surf->obj != NULL) + if (grSurface::scratch_mem_surf->obj != nullptr) gr_mem_surf_Destroy(grSurface::scratch_mem_surf); delete grSurface::scratch_mem_surf; - grSurface::scratch_mem_surf = NULL; + grSurface::scratch_mem_surf = nullptr; } } @@ -458,7 +457,7 @@ char *grSurface::lock(int *rowsize) { *rowsize = m_DataRowsize; if (!grerr) - return NULL; + return nullptr; surf_Locked++; // increment lock counter for this surface @@ -487,7 +486,7 @@ char *grSurface::lock(int x, int y, int *rowsize) { *rowsize = m_DataRowsize; if (!grerr) - return NULL; + return nullptr; /* calculate the adjusted data pointer based off of x,y,bpp */ char *data = m_OrigDataPtr; @@ -732,13 +731,13 @@ void grSurface::xlat32_16(char *data, int w, int h) { void grSurface::add_to_list(ddgr_surface *sf) { ddgr_surface_node *node; - ASSERT(sf != NULL); + ASSERT(sf != nullptr); if (!grSurface::surf_list_cur) { // first surface on list node = new ddgr_surface_node; node->sf = sf; - node->prev = NULL; + node->prev = nullptr; grSurface::surf_list = grSurface::surf_list_cur = node; } else { // next surface on list. @@ -755,12 +754,12 @@ void grSurface::remove_from_list(ddgr_surface *sf) { ddgr_surface_node *node, *next_node; ASSERT(grSurface::surf_list_cur); - ASSERT(sf != NULL); + ASSERT(sf != nullptr); // node is current node. next node is node after it on the list. since we are // going from end to beginning, this may confuse you. node = grSurface::surf_list_cur; - next_node = NULL; // grSurface::surf_list_cur should be at end of list, so no next node + next_node = nullptr; // grSurface::surf_list_cur should be at end of list, so no next node while (node) { if (node->sf == sf) { @@ -771,7 +770,7 @@ void grSurface::remove_from_list(ddgr_surface *sf) { } delete node; - node = NULL; // break out of loop + node = nullptr; // break out of loop } else { // go down one node. next_node = node; diff --git a/2dlib/viewport.cpp b/2dlib/viewport.cpp index 3e418c50..398a7f5b 100644 --- a/2dlib/viewport.cpp +++ b/2dlib/viewport.cpp @@ -118,14 +118,14 @@ #define CLIP_BOTTOM (vp_InitTop + vp_Bottom) int grViewport::vp_Locked = 0; -grViewport *grViewport::vp_Current_VP = NULL; +grViewport *grViewport::vp_Current_VP = nullptr; // --------------------------------------------------------------------------- // grViewport constructor and destructor // --------------------------------------------------------------------------- grViewport::grViewport(grScreen *scr_parent) { - ASSERT(scr_parent != NULL); + ASSERT(scr_parent != nullptr); sf_Parent = scr_parent; // screen is a child of grSurface, so we // can do this. @@ -148,7 +148,7 @@ grViewport::grViewport(grScreen *scr_parent) { } grViewport::grViewport(grSurface *sf_parent) { - ASSERT(sf_parent != NULL); + ASSERT(sf_parent != nullptr); sf_Parent = sf_parent; @@ -288,11 +288,11 @@ void grViewport::unlock() { sf_Parent->unlock(); vp_Locked = 0; - grViewport::vp_Current_VP = NULL; + grViewport::vp_Current_VP = nullptr; - pen_Obj.data = NULL; + pen_Obj.data = nullptr; pen_Obj.rowsize = 0; - pen_Obj.sf = NULL; + pen_Obj.sf = nullptr; } // --------------------------------------------------------------------------- diff --git a/dd_grwin32/CMakeLists.txt b/dd_grwin32/CMakeLists.txt index 44472456..a2a7650d 100644 --- a/dd_grwin32/CMakeLists.txt +++ b/dd_grwin32/CMakeLists.txt @@ -10,6 +10,7 @@ set(CPPS add_library(dd_grwin32 STATIC ${HEADERS} ${CPPS}) target_link_libraries(dd_grwin32 PRIVATE + 2dlib misc ) target_compile_definitions(dd_grwin32 PRIVATE DX_APP) diff --git a/editor/WorldObjectsRobotDialog.h b/editor/WorldObjectsRobotDialog.h index 4404e673..ecd8d392 100644 --- a/editor/WorldObjectsRobotDialog.h +++ b/editor/WorldObjectsRobotDialog.h @@ -19,7 +19,7 @@ // WorldObjectsRobotDialog.h : header file // -#include "../lib/gr.h" +#include "gr.h" ///////////////////////////////////////////////////////////////////////////// // CWorldObjectsRobotDialog dialog