diff --git a/source_files/obsidian_main/aj_local.h b/source_files/obsidian_main/aj_local.h index c2231fc65..94592b1a6 100644 --- a/source_files/obsidian_main/aj_local.h +++ b/source_files/obsidian_main/aj_local.h @@ -33,7 +33,6 @@ #include "sys_endian.h" #include "sys_macro.h" -#define HAVE_PHYSFS 1 #include "physfs.h" namespace ajpoly { diff --git a/source_files/obsidian_main/aj_map.cc b/source_files/obsidian_main/aj_map.cc index 9142d8c84..547e2fabe 100644 --- a/source_files/obsidian_main/aj_map.cc +++ b/source_files/obsidian_main/aj_map.cc @@ -19,6 +19,7 @@ #include "aj_local.h" #include "aj_parse.h" #include "main.h" +#include "sys_macro.h" #define DEBUG_LOAD 0 @@ -228,12 +229,12 @@ void ParseSectorField(sector_c *sector, const std::string& key, ajparse::token_k } else if (key == "texturefloor") { - std::copy(value.data(), value.data() + MIN(8, value.size()), + std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), sector->floor_tex); } else if (key == "textureceiling") { - std::copy(value.data(), value.data() + MIN(8, value.size()), + std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), sector->ceil_tex); } else if (key == "lightlevel") @@ -267,17 +268,17 @@ void ParseSidedefField(sidedef_c *side, const std::string& key, ajparse::token_k } else if (key == "texturetop") { - std::copy(value.data(), value.data() + MIN(8, value.size()), + std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), side->upper_tex); } else if (key == "texturebottom") { - std::copy(value.data(), value.data() + MIN(8, value.size()), + std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), side->lower_tex); } else if (key == "texturemiddle") { - std::copy(value.data(), value.data() + MIN(8, value.size()), + std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), side->mid_tex); } else if (key == "sector") @@ -1024,11 +1025,11 @@ void DetermineMapLimits() { int x2 = (int)L->end->x; int y2 = (int)L->end->y; - limit_x1 = MIN(limit_x1, MIN(x1, x2)); - limit_y1 = MIN(limit_y1, MIN(y1, y2)); + limit_x1 = OBSIDIAN_MIN(limit_x1, OBSIDIAN_MIN(x1, x2)); + limit_y1 = OBSIDIAN_MIN(limit_y1, OBSIDIAN_MIN(y1, y2)); - limit_x2 = MAX(limit_x2, MAX(x1, x2)); - limit_y2 = MAX(limit_y2, MAX(y1, y2)); + limit_x2 = OBSIDIAN_MAX(limit_x2, OBSIDIAN_MAX(x1, x2)); + limit_y2 = OBSIDIAN_MAX(limit_y2, OBSIDIAN_MAX(y1, y2)); } Appl_Printf("Map goes from (%d,%d) to (%d,%d)\n", limit_x1, limit_y1, @@ -1074,11 +1075,11 @@ void CheckSectorIsDummy(sector_c *sec) { int x = pass ? line->end->x : line->start->x; int y = pass ? line->end->y : line->start->y; - bound_x1 = MIN(bound_x1, x); - bound_y1 = MIN(bound_y1, y); + bound_x1 = OBSIDIAN_MIN(bound_x1, x); + bound_y1 = OBSIDIAN_MIN(bound_y1, y); - bound_x2 = MAX(bound_x2, x); - bound_y2 = MAX(bound_y2, y); + bound_x2 = OBSIDIAN_MAX(bound_x2, x); + bound_y2 = OBSIDIAN_MAX(bound_y2, y); } } diff --git a/source_files/obsidian_main/aj_poly.cc b/source_files/obsidian_main/aj_poly.cc index 4c92ae012..9031b2d02 100644 --- a/source_files/obsidian_main/aj_poly.cc +++ b/source_files/obsidian_main/aj_poly.cc @@ -18,6 +18,7 @@ #include #include "aj_local.h" +#include "sys_macro.h" #define DEBUG_POLY 0 @@ -361,8 +362,8 @@ int EvalPartition(edge_c *part, edge_c *edge_list) { } // increase cost by the difference between left and right - cost += 100 * ABS(real_left - real_right); - cost += 30 * ABS(mini_left - mini_right); + cost += 100 * OBSIDIAN_ABS(real_left - real_right); + cost += 30 * OBSIDIAN_ABS(mini_left - mini_right); // show a slight preference for purely horizontally or vertical // partition lines. diff --git a/source_files/obsidian_main/aj_wad.cc b/source_files/obsidian_main/aj_wad.cc index 4889f278f..d4f01c5ea 100644 --- a/source_files/obsidian_main/aj_wad.cc +++ b/source_files/obsidian_main/aj_wad.cc @@ -50,11 +50,7 @@ int CheckLevelLump(const char *name) { wad_c::~wad_c() { if (fp) { -#ifdef HAVE_PHYSFS PHYSFS_close(fp); -#else - fclose(fp); -#endif } FreeData(); @@ -89,7 +85,6 @@ void wad_c::FreeData() { bool wad_c::ReadDirEntry() { raw_wad_entry_t entry; -#ifdef HAVE_PHYSFS int len = (int)(PHYSFS_readBytes(fp, &entry, sizeof(entry)) / sizeof(entry)); if (len != 1) { @@ -97,13 +92,6 @@ bool wad_c::ReadDirEntry() { PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return false; } -#else - size_t len = fread(&entry, sizeof(entry), 1, fp); - if (len != 1) { - SetErrorMsg("Trouble reading wad directory --> %s", strerror(errno)); - return false; - } -#endif int start = LE_U32(entry.start); int length = LE_U32(entry.length); @@ -127,7 +115,6 @@ bool wad_c::ReadDirEntry() { bool wad_c::ReadDirectory() { raw_wad_header_t header; -#ifdef HAVE_PHYSFS int len = (int)(PHYSFS_readBytes(fp, &header, sizeof(header)) / sizeof(header)); if (len != 1) { @@ -135,13 +122,6 @@ bool wad_c::ReadDirectory() { PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return false; } -#else - size_t len = fread(&header, sizeof(header), 1, fp); - if (len != 1) { - SetErrorMsg("Error reading wad header --> %s", strerror(errno)); - return false; - } -#endif if (!CheckMagic(header.type)) { SetErrorMsg("File is not a WAD file."); @@ -153,11 +133,7 @@ bool wad_c::ReadDirectory() { Appl_Printf("Reading %d dir entries at 0x%X\n", num_entries, dir_start); -#ifdef HAVE_PHYSFS PHYSFS_seek(fp, dir_start); -#else - fseek(fp, dir_start, SEEK_SET); -#endif for (int i = 0; i < num_entries; i++) { if (!ReadDirEntry()) { @@ -225,7 +201,7 @@ void wad_c::DetermineLevels() { } wad_c *wad_c::Open(const char *filename) { -#ifdef HAVE_PHYSFS + PHYSFS_File *in_file = PHYSFS_openRead(filename); if (!in_file) { @@ -233,15 +209,6 @@ wad_c *wad_c::Open(const char *filename) { PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return NULL; } -#else - FILE *in_file = fopen(filename, "rb"); - - if (!in_file) { - SetErrorMsg("Cannot open WAD file: %s --> %s", filename, - strerror(errno)); - return NULL; - } -#endif Appl_Printf("Opened WAD file : %s\n", filename); @@ -313,7 +280,6 @@ uint8_t *wad_c::ReadLump(const char *name, int *length, int level) { uint8_t *data = AllocateData(L->length); if (L->length > 0) { -#ifdef HAVE_PHYSFS PHYSFS_seek(fp, L->start); int len = (int)(PHYSFS_readBytes(fp, data, L->length) / L->length); @@ -322,16 +288,6 @@ uint8_t *wad_c::ReadLump(const char *name, int *length, int level) { PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return NULL; } -#else - fseek(fp, L->start, SEEK_SET); - - size_t len = fread(data, L->length, 1, fp); - if (len != 1) { - SetErrorMsg("Trouble reading lump '%s' --> %s", name, - strerror(errno)); - return NULL; - } -#endif } return data; diff --git a/source_files/obsidian_main/aj_wad.h b/source_files/obsidian_main/aj_wad.h index cb64dd815..52298787f 100644 --- a/source_files/obsidian_main/aj_wad.h +++ b/source_files/obsidian_main/aj_wad.h @@ -55,11 +55,8 @@ class lump_c { class wad_c { private: -#ifdef HAVE_PHYSFS + PHYSFS_File *fp; -#else - FILE *fp; -#endif // directory entries std::vector lumps; diff --git a/source_files/obsidian_main/csg_bsp.cc b/source_files/obsidian_main/csg_bsp.cc index d2156f3f8..0d0b710be 100644 --- a/source_files/obsidian_main/csg_bsp.cc +++ b/source_files/obsidian_main/csg_bsp.cc @@ -32,6 +32,7 @@ #include "lib_util.h" #include "m_lua.h" #include "main.h" +#include "sys_macro.h" double QUANTIZE_GRID; @@ -78,11 +79,11 @@ class group_c { regs[k]->GetBounds(&x1, &y1, &x2, &y2); - *min_x = MIN(*min_x, x1); - *min_y = MIN(*min_y, y1); + *min_x = OBSIDIAN_MIN(*min_x, x1); + *min_y = OBSIDIAN_MIN(*min_y, y1); - *max_x = MAX(*max_x, x1); - *max_y = MAX(*max_y, y1); + *max_x = OBSIDIAN_MAX(*max_x, x1); + *max_y = OBSIDIAN_MAX(*max_y, y1); } } }; @@ -162,8 +163,8 @@ void snag_c::CalcAlongs() { a1 /= SNAG_EPSILON; a2 /= SNAG_EPSILON; - q_along1 = I_ROUND(a1); - q_along2 = I_ROUND(a2); + q_along1 = RoundToInteger(a1); + q_along2 = RoundToInteger(a2); } bool snag_c::SameSides() const { @@ -361,11 +362,11 @@ void region_c::GetBounds(double *x1, double *y1, double *x2, double *y2) const { for (unsigned int i = 0; i < snags.size(); i++) { const snag_c *S = snags[i]; - *x1 = MIN(*x1, MIN(S->x1, S->x2)); - *y1 = MIN(*y1, MIN(S->y1, S->y2)); + *x1 = OBSIDIAN_MIN(*x1, OBSIDIAN_MIN(S->x1, S->x2)); + *y1 = OBSIDIAN_MIN(*y1, OBSIDIAN_MIN(S->y1, S->y2)); - *x2 = MAX(*x1, MAX(S->x1, S->x2)); - *y2 = MAX(*y1, MAX(S->y1, S->y2)); + *x2 = OBSIDIAN_MAX(*x1, OBSIDIAN_MAX(S->x1, S->x2)); + *y2 = OBSIDIAN_MAX(*y1, OBSIDIAN_MAX(S->y1, S->y2)); } } @@ -395,8 +396,8 @@ void region_c::ComputeBounds() { for (unsigned int i = 0; i < snags.size(); i++) { const snag_c *S = snags[i]; - rw = MAX(rw, fabs(S->x1 - mid_x)); - rh = MAX(rh, fabs(S->y1 - mid_y)); + rw = OBSIDIAN_MAX(rw, fabs(S->x1 - mid_x)); + rh = OBSIDIAN_MAX(rh, fabs(S->y1 - mid_y)); } } @@ -426,7 +427,7 @@ double region_c::DistanceToPoint(float x, float y) const { double dist = PointLineDist(x, y, S->x1, S->y1, S->x2, S->y2); - best = MIN(best, dist); + best = OBSIDIAN_MIN(best, dist); } return best; @@ -440,7 +441,7 @@ double region_c::SquareDistance(float x, float y) const { double x_dist = (x < bx1) ? (bx1 - x) : (x > bx2) ? (x - bx2) : 0; double y_dist = (y < by1) ? (by1 - y) : (y > by2) ? (y - by2) : 0; - return MAX(x_dist, y_dist); + return OBSIDIAN_MAX(x_dist, y_dist); } bool region_c::HasSameBrushes(const region_c *other) const { @@ -609,11 +610,11 @@ void bsp_node_c::AddBBox(bsp_node_c *node) { node->ComputeBBox(); if (node->bb_x2 > node->bb_x1) { - bb_x1 = MIN(bb_x1, node->bb_x1); - bb_x2 = MAX(bb_x2, node->bb_x2); + bb_x1 = OBSIDIAN_MIN(bb_x1, node->bb_x1); + bb_x2 = OBSIDIAN_MAX(bb_x2, node->bb_x2); - bb_y1 = MIN(bb_y1, node->bb_y1); - bb_y2 = MAX(bb_y2, node->bb_y2); + bb_y1 = OBSIDIAN_MIN(bb_y1, node->bb_y1); + bb_y2 = OBSIDIAN_MAX(bb_y2, node->bb_y2); } } @@ -622,11 +623,11 @@ void bsp_node_c::AddBBox(region_c *leaf) { leaf->GetBounds(&x1, &y1, &x2, &y2); - bb_x1 = MIN(bb_x1, x1); - bb_x2 = MAX(bb_x2, x2); + bb_x1 = OBSIDIAN_MIN(bb_x1, x1); + bb_x2 = OBSIDIAN_MAX(bb_x2, x2); - bb_y1 = MIN(bb_y1, y1); - bb_y2 = MAX(bb_y2, y2); + bb_y1 = OBSIDIAN_MIN(bb_y1, y1); + bb_y2 = OBSIDIAN_MAX(bb_y2, y2); } /***** VARIABLES ******************/ @@ -640,8 +641,8 @@ bsp_node_c *bsp_root; //------------------------------------------------------------------------ static void QuantizeVert(const brush_vert_c *V, int *qx, int *qy) { - *qx = I_ROUND(V->x / QUANTIZE_GRID); - *qy = I_ROUND(V->y / QUANTIZE_GRID); + *qx = RoundToInteger(V->x / QUANTIZE_GRID); + *qy = RoundToInteger(V->y / QUANTIZE_GRID); } static bool OnSameLine(double x1, double y1, double x2, double y2, @@ -765,11 +766,11 @@ static void CreateRegion(group_c &root, csg_brush_c *P) { R->AddSnag(S); - min_qx = MIN(min_qx, MIN(qx1, qx2)); - min_qy = MIN(min_qy, MIN(qy1, qy2)); + min_qx = OBSIDIAN_MIN(min_qx, OBSIDIAN_MIN(qx1, qx2)); + min_qy = OBSIDIAN_MIN(min_qy, OBSIDIAN_MIN(qy1, qy2)); - max_qx = MAX(max_qx, MAX(qx1, qx2)); - max_qy = MAX(max_qy, MAX(qy1, qy2)); + max_qx = OBSIDIAN_MAX(max_qx, OBSIDIAN_MAX(qx1, qx2)); + max_qy = OBSIDIAN_MAX(max_qy, OBSIDIAN_MAX(qy1, qy2)); } if (R->snags.size() < 3 || max_qx <= min_qx || max_qy <= min_qy || @@ -872,8 +873,8 @@ static void DivideOneSnag(snag_c *S, partition_c *part, region_c *front, double along = AlongDist(ix, iy, part->x1, part->y1, part->x2, part->y2); - *along_min = MIN(*along_min, along); - *along_max = MAX(*along_max, along); + *along_min = OBSIDIAN_MIN(*along_min, along); + *along_max = OBSIDIAN_MAX(*along_max, along); } // completely on front side? @@ -1040,10 +1041,10 @@ static partition_c *ChoosePartition(group_c &group, bool *reached_chunk) { if (sw >= 2 || sh >= 2) { if (sw >= sh) { double px = (sx1 + sw / 2) * CHUNK_SIZE; - return AddPartition(px, gy1, px, MAX(gy2, gy1 + 4)); + return AddPartition(px, gy1, px, OBSIDIAN_MAX(gy2, gy1 + 4)); } else { double py = (sy1 + sh / 2) * CHUNK_SIZE; - return AddPartition(gx1, py, MAX(gx2, gx1 + 4), py); + return AddPartition(gx1, py, OBSIDIAN_MAX(gx2, gx1 + 4), py); } } @@ -1221,11 +1222,11 @@ static bool TestOverlap(std::vector &list, int i, int k) { return false; } - int a_min = MIN(A->q_along1, A->q_along2); - int a_max = MAX(A->q_along1, A->q_along2); + int a_min = OBSIDIAN_MIN(A->q_along1, A->q_along2); + int a_max = OBSIDIAN_MAX(A->q_along1, A->q_along2); - int b_min = MIN(B->q_along1, B->q_along2); - int b_max = MAX(B->q_along1, B->q_along2); + int b_min = OBSIDIAN_MIN(B->q_along1, B->q_along2); + int b_max = OBSIDIAN_MAX(B->q_along1, B->q_along2); if (a_min >= b_max || a_max <= b_min) { return false; @@ -1290,7 +1291,7 @@ static void ProcessOverlapList(std::vector &overlap_list) { overlap_list[i]->CalcAlongs(); } - // TODO: sort list by MIN(q_along), take advantage of that + // TODO: sort list by OBSIDIAN_MIN(q_along), take advantage of that int changes; @@ -1984,8 +1985,8 @@ static int TestVertex(snag_c *S, int which) { double x = which ? S->x2 : S->x1; double y = which ? S->y2 : S->y1; - int ix = I_ROUND(x + RX * 0); - int iy = I_ROUND(y + RY * 0); + int ix = RoundToInteger(x + RX * 0); + int iy = RoundToInteger(y + RY * 0); int id = (iy << 16) + ix; @@ -2041,7 +2042,7 @@ void CSG_TestRegions_Doom() { for (k = 0; k < R->entities.size(); k++) { csg_entity_c *E = R->entities[k]; - DM_AddThing(I_ROUND(E->x), I_ROUND(E->y), 0, 11, sec_id, 7, 0, 0, + DM_AddThing(RoundToInteger(E->x), RoundToInteger(E->y), 0, 11, sec_id, 7, 0, 0, NULL); } diff --git a/source_files/obsidian_main/csg_doom.cc b/source_files/obsidian_main/csg_doom.cc index 4435da4c1..7bf16ea62 100644 --- a/source_files/obsidian_main/csg_doom.cc +++ b/source_files/obsidian_main/csg_doom.cc @@ -33,6 +33,7 @@ #include "headers.h" #include "lib_util.h" #include "main.h" +#include "sys_macro.h" // Properties int ef_solid_type; @@ -581,8 +582,8 @@ class linedef_c { sidedef_c *B_front = B->front; sidedef_c *B_back = B->back; - int A_len = I_ROUND(length); - int B_len = I_ROUND(B->length); + int A_len = RoundToInteger(length); + int B_len = RoundToInteger(B->length); if (!CanMergeSides(front, B_front)) { return false; @@ -786,7 +787,7 @@ static void LightInSector(sector_c *S, region_c *R, csg_property_set_c *f_face, // use the shade computed in CSG_Shade() S->light = R->shade; - S->light = CLAMP(0, S->light, 255); + S->light = OBSIDIAN_CLAMP(0, S->light, 255); // handle "fx_delta" property for light effects @@ -833,8 +834,8 @@ static void MakeSector(region_c *R) { double f_delta = f_face->getDouble("delta_z"); double c_delta = c_face->getDouble("delta_z"); - S->f_h = I_ROUND(B->t.z + f_delta); - S->c_h = I_ROUND(T->b.z + c_delta); + S->f_h = RoundToInteger(B->t.z + f_delta); + S->c_h = RoundToInteger(T->b.z + c_delta); // when delta-ing up the floor, limit it to the ceiling // (this can be important in outdoor rooms) @@ -1053,7 +1054,7 @@ static int NaturalXOffset(Doom::linedef_c *L, int side) { along = AlongDist(0, 0, L->end->x, L->end->y, L->start->x, L->start->y); } - return I_ROUND(-along); + return RoundToInteger(-along); } static int CalcXOffset(snag_c *S, brush_vert_c *V, int ox) { @@ -1154,9 +1155,9 @@ static sidedef_c *MakeSidedef(linedef_c *L, sector_c *sec, sector_c *back, r_oy = rail->face.getInt("v1", 0); // adjust Y-offset for higher floor than expected - int sec_max_z = MAX(sec->f_h, back->f_h); + int sec_max_z = OBSIDIAN_MAX(sec->f_h, back->f_h); - r_oy += I_ROUND(rail->parent->b.z) - sec_max_z; + r_oy += RoundToInteger(rail->parent->b.z) - sec_max_z; } } @@ -1218,8 +1219,8 @@ static csg_property_set_c *FindTrigger(snag_c *S, sector_c *front, return NULL; } - float f_max = MAX(front->f_h, back->f_h) + 4; - float c_min = MIN(front->c_h, back->c_h) - 4; + float f_max = OBSIDIAN_MAX(front->f_h, back->f_h) + 4; + float c_min = OBSIDIAN_MIN(front->c_h, back->c_h) - 4; if (f_max >= c_min) { return NULL; @@ -1398,11 +1399,11 @@ static void MakeLine(region_c *R, snag_c *S) { } // skip snags which would become zero length linedefs - int x1 = I_ROUND(S->x1); - int y1 = I_ROUND(S->y1); + int x1 = RoundToInteger(S->x1); + int y1 = RoundToInteger(S->y1); - int x2 = I_ROUND(S->x2); - int y2 = I_ROUND(S->y2); + int x2 = RoundToInteger(S->x2); + int y2 = RoundToInteger(S->y2); if (x1 == x2 && y1 == y2) { return; @@ -1446,11 +1447,11 @@ static void MakeLine(region_c *R, snag_c *S) { } // update map's bounding box - map_bound_x1 = MIN(map_bound_x1, MIN(x1, x2)); - map_bound_y1 = MIN(map_bound_y1, MIN(y1, y2)); + map_bound_x1 = OBSIDIAN_MIN(map_bound_x1, OBSIDIAN_MIN(x1, x2)); + map_bound_y1 = OBSIDIAN_MIN(map_bound_y1, OBSIDIAN_MIN(y1, y2)); - map_bound_x2 = MAX(map_bound_x2, MAX(x1, x2)); - map_bound_y2 = MAX(map_bound_y2, MAX(y1, y2)); + map_bound_x2 = OBSIDIAN_MAX(map_bound_x2, OBSIDIAN_MAX(x1, x2)); + map_bound_y2 = OBSIDIAN_MAX(map_bound_y2, OBSIDIAN_MAX(y1, y2)); // create the line... @@ -1666,14 +1667,14 @@ static void AlignTextures() { while (P->sim_prev && P->sim_prev->front->x_offset == IVAL_NONE) { P->sim_prev->front->x_offset = - P->front->x_offset - I_ROUND(P->sim_prev->length); + P->front->x_offset - RoundToInteger(P->sim_prev->length); P = P->sim_prev; prev_count++; } while (N->sim_next && N->sim_next->front->x_offset == IVAL_NONE) { N->sim_next->front->x_offset = - N->front->x_offset + I_ROUND(N->length); + N->front->x_offset + RoundToInteger(N->length); N = N->sim_next; next_count++; } @@ -1692,11 +1693,11 @@ static bool RoundWouldClobber(int cx, int cy, int ox, int oy, const Doom::vertex_c *ignore1, const Doom::vertex_c *ignore2, const Doom::vertex_c *ignore3) { - int x1 = MIN(cx, ox); - int y1 = MIN(cy, oy); + int x1 = OBSIDIAN_MIN(cx, ox); + int y1 = OBSIDIAN_MIN(cy, oy); - int x2 = MAX(cx, ox); - int y2 = MAX(cy, oy); + int x2 = OBSIDIAN_MAX(cx, ox); + int y2 = OBSIDIAN_MAX(cy, oy); for (const auto *V : Doom::vertices) { if (V == ignore1 || V == ignore2 || V == ignore3) { @@ -2214,8 +2215,8 @@ static void SolidExtraFloor(sector_c *sec, gap_c *gap1, gap_c *gap2) { } } - EF->top_h = I_ROUND(gap2->bottom->t.z); - EF->bottom_h = I_ROUND(gap1->top->b.z); + EF->top_h = RoundToInteger(gap2->bottom->t.z); + EF->bottom_h = RoundToInteger(gap1->top->b.z); EF->top = gap2->bottom->t.face.getStr("tex", dummy_plane_tex); EF->bottom = gap1->top->b.face.getStr("tex", dummy_plane_tex); @@ -2244,10 +2245,10 @@ static void LiquidExtraFloor(sector_c *sec, csg_brush_c *liquid) { if (EF->line_special == 301) // Legacy style { EF->bottom_h = sec->f_h; - EF->top_h = I_ROUND(liquid->t.z); + EF->top_h = RoundToInteger(liquid->t.z); } else // EDGE style { - EF->bottom_h = I_ROUND(liquid->t.z); + EF->bottom_h = RoundToInteger(liquid->t.z); EF->top_h = EF->bottom_h + 128; // not significant } @@ -2404,13 +2405,13 @@ static int CalcDoorLight(const sector_c *S) { // we ignore closed neighbors if (front == S && back->f_h < back->c_h) { - l_min = MIN(l_min, back->light); - l_max = MAX(l_max, back->light); + l_min = OBSIDIAN_MIN(l_min, back->light); + l_max = OBSIDIAN_MAX(l_max, back->light); } if (back == S && front->f_h < front->c_h) { - l_min = MIN(l_min, front->light); - l_max = MAX(l_max, front->light); + l_min = OBSIDIAN_MIN(l_min, front->light); + l_max = OBSIDIAN_MAX(l_max, front->light); } } @@ -2631,9 +2632,9 @@ static void WriteThing(sector_c *S, csg_entity_c *E) { return; } - int x = I_ROUND(E->x); - int y = I_ROUND(E->y); - int z = I_ROUND(E->z); + int x = RoundToInteger(E->x); + int y = RoundToInteger(E->y); + int z = RoundToInteger(E->z); int h = z - S->f_h; diff --git a/source_files/obsidian_main/csg_main.cc b/source_files/obsidian_main/csg_main.cc index 4ef1352da..77e48feaf 100644 --- a/source_files/obsidian_main/csg_main.cc +++ b/source_files/obsidian_main/csg_main.cc @@ -126,8 +126,8 @@ int quake_plane_c::BrushSide(csg_brush_c *B, float epsilon) const { float d = PointDist(x, y, z); - min_d = MIN(min_d, d); - max_d = MAX(max_d, d); + min_d = OBSIDIAN_MIN(min_d, d); + max_d = OBSIDIAN_MAX(max_d, d); } } @@ -212,7 +212,7 @@ double csg_property_set_c::getDouble(std::string key, double def_val) const { int csg_property_set_c::getInt(std::string key, int def_val) const { std::string str = getStr(key); - return !str.empty() ? I_ROUND(StringToDouble(str)) : def_val; + return !str.empty() ? RoundToInteger(StringToDouble(str)) : def_val; } void csg_property_set_c::getHexenArgs(uint8_t *arg5) const { @@ -554,10 +554,10 @@ bool csg_brush_c::IntersectRay(float x1, float y1, float z1, float x2, float y2, double bz = b.CalcZ(x1, y1); double tz = t.CalcZ(x1, y1); - if (MAX(z1, z2) < bz - 0.1) { + if (OBSIDIAN_MAX(z1, z2) < bz - 0.1) { return false; } - if (MIN(z1, z2) > tz + 0.1) { + if (OBSIDIAN_MIN(z1, z2) > tz + 0.1) { return false; } @@ -690,17 +690,17 @@ class brush_quad_node_c { } bool BoxTouchesThis(double x1, double y1, double x2, double y2) const { - if (MAX(x1, x2) < lo_x) { + if (OBSIDIAN_MAX(x1, x2) < lo_x) { return false; } - if (MAX(y1, y2) < lo_y) { + if (OBSIDIAN_MAX(y1, y2) < lo_y) { return false; } - if (MIN(x1, x2) > hi_x()) { + if (OBSIDIAN_MIN(x1, x2) > hi_x()) { return false; } - if (MIN(y1, y2) > hi_y()) { + if (OBSIDIAN_MIN(y1, y2) > hi_y()) { return false; } @@ -756,8 +756,8 @@ class brush_quad_node_c { double t_delta = B->t.face.getDouble("delta_z", 0); double b_delta = B->b.face.getDouble("delta_z", 0); - int t_z = I_ROUND(B->t.z + t_delta); - int b_z = I_ROUND(B->b.z + b_delta); + int t_z = RoundToInteger(B->t.z + t_delta); + int b_z = RoundToInteger(B->b.z + b_delta); // skip brushes underneath the floor (or the floor itself) if (t_z < floor_h + 1) { @@ -790,8 +790,8 @@ class brush_quad_node_c { // rounding to integer here, I don't think it is any problem, // as the spot polygon-drawing code is fairly robust. - shape.push_back(I_ROUND(V->x)); - shape.push_back(I_ROUND(V->y)); + shape.push_back(RoundToInteger(V->x)); + shape.push_back(RoundToInteger(V->y)); } SPOT_FillPolygon(content, &shape[0], num_vert); diff --git a/source_files/obsidian_main/csg_shade.cc b/source_files/obsidian_main/csg_shade.cc index 98e31afbb..b82a7103f 100644 --- a/source_files/obsidian_main/csg_shade.cc +++ b/source_files/obsidian_main/csg_shade.cc @@ -166,7 +166,7 @@ static void SHADE_MergeResults() { int result = 0; for (n = i; n <= k; n++) { - result = MAX(result, all_regions[n]->shade); + result = OBSIDIAN_MAX(result, all_regions[n]->shade); } for (n = i; n <= k; n++) { @@ -261,13 +261,13 @@ static void SHADE_VisitRegion(region_c *R) { int br_light = LB->props.getInt("light_add", -1); int br_shadow = LB->props.getInt("shadow", -1); - light = MAX(light, br_light); - shadow = MAX(shadow, br_shadow); + light = OBSIDIAN_MAX(light, br_light); + shadow = OBSIDIAN_MAX(shadow, br_shadow); int sky_shadow = LB->props.getInt("sky_shadow", -1); if (sky_shadow > 0 && (T->bflags & BFLAG_Sky)) { - shadow = MAX(shadow, sky_shadow); + shadow = OBSIDIAN_MAX(shadow, sky_shadow); } } @@ -279,8 +279,8 @@ static void SHADE_VisitRegion(region_c *R) { int fc_light = P->getInt("light_add", -1); int fc_shadow = P->getInt("shadow", -1); - light = MAX(light, fc_light); - shadow = MAX(shadow, fc_shadow); + light = OBSIDIAN_MAX(light, fc_light); + shadow = OBSIDIAN_MAX(shadow, fc_shadow); } #if 0 // DISABLED, WE DO THIS IN LUA CODE NOW @@ -292,7 +292,7 @@ static void SHADE_VisitRegion(region_c *R) { int cave = SHADE_CaveLighting(R, z2); if (cave > 0) - light = MAX(light, cave); + light = OBSIDIAN_MAX(light, cave); } #endif diff --git a/source_files/obsidian_main/csg_spots.cc b/source_files/obsidian_main/csg_spots.cc index 0e4aabc5a..8d744b799 100644 --- a/source_files/obsidian_main/csg_spots.cc +++ b/source_files/obsidian_main/csg_spots.cc @@ -120,7 +120,7 @@ void SPOT_DumpGrid(const char *info) { for (int y = grid_H - 1; y >= 0; y--) { char buffer[MAX_WIDTH + 2]; - int width = MIN(MAX_WIDTH, grid_W); + int width = OBSIDIAN_MIN(MAX_WIDTH, grid_W); for (int x = 0; x < width; x++) { uint8_t content = spot_grid[x][y]; @@ -503,18 +503,18 @@ static void raw_pixel(int gx, int gy) { return; } - grid_lefties[gy] = MIN(grid_lefties[gy], gx); - grid_righties[gy] = MAX(grid_righties[gy], gx); + grid_lefties[gy] = OBSIDIAN_MIN(grid_lefties[gy], gx); + grid_righties[gy] = OBSIDIAN_MAX(grid_righties[gy], gx); - grid_botty = MIN(grid_botty, gy); - grid_toppy = MAX(grid_toppy, gy); + grid_botty = OBSIDIAN_MIN(grid_botty, gy); + grid_toppy = OBSIDIAN_MAX(grid_toppy, gy); } static void draw_line(int x1, int y1, int x2, int y2) { // basic cull, Y only // (doing X messes up polygons which overlap the sides) - if (MAX(y1, y2) < grid_min_y || MIN(y1, y2) > grid_max_y) { + if (OBSIDIAN_MAX(y1, y2) < grid_min_y || OBSIDIAN_MIN(y1, y2) > grid_max_y) { return; } @@ -573,8 +573,8 @@ static void draw_line(int x1, int y1, int x2, int y2) { int orig_py1 = py1; int orig_py2 = py2; - py1 = MAX(0, py1); - py2 = MIN(h2, py2); + py1 = OBSIDIAN_MAX(0, py1); + py2 = OBSIDIAN_MIN(h2, py2); // same column ? if (px1 == px2) { @@ -632,8 +632,8 @@ static void fill_rows(uint8_t content) { continue; } - int low_x = MAX(0, grid_lefties[y]); - int high_x = MIN(w2, grid_righties[y]); + int low_x = OBSIDIAN_MAX(0, grid_lefties[y]); + int high_x = OBSIDIAN_MIN(w2, grid_righties[y]); for (int x = low_x; x <= high_x; x++) { replace_cell(x, y, content); @@ -709,10 +709,10 @@ int SPOT_begin(lua_State *L) { // LUA: spots_draw_line(x1, y1, x2, y2, content) // int SPOT_draw_line(lua_State *L) { - int x1 = I_ROUND(luaL_checknumber(L, 1)); - int y1 = I_ROUND(luaL_checknumber(L, 2)); - int x2 = I_ROUND(luaL_checknumber(L, 3)); - int y2 = I_ROUND(luaL_checknumber(L, 4)); + int x1 = RoundToInteger(luaL_checknumber(L, 1)); + int y1 = RoundToInteger(luaL_checknumber(L, 2)); + int x2 = RoundToInteger(luaL_checknumber(L, 3)); + int y2 = RoundToInteger(luaL_checknumber(L, 4)); int content = luaL_checkinteger(L, 5); @@ -737,8 +737,8 @@ static int polygon_coord(lua_State *L, int stack_pos, // ignore non-XY coordinates, to allow passing whole brushes if (!lua_isnil(L, -2)) { - int x = I_ROUND(luaL_checknumber(L, -2)); - int y = I_ROUND(luaL_checknumber(L, -1)); + int x = RoundToInteger(luaL_checknumber(L, -2)); + int y = RoundToInteger(luaL_checknumber(L, -1)); points.push_back(grid_point_c(x, y)); } @@ -823,10 +823,10 @@ static void store_mon_or_item(lua_State *L, int stack_pos, unsigned int index, int ceil_h = grid_floor_h + (low_ceil ? spot_low_h : spot_high_h); // clip rectangle to the original room/chunk boundaries - x1 = MAX(x1, grid_min_x); - y1 = MAX(y1, grid_min_y); - x2 = MIN(x2, grid_max_x); - y2 = MIN(y2, grid_max_y); + x1 = OBSIDIAN_MAX(x1, grid_min_x); + y1 = OBSIDIAN_MAX(y1, grid_min_y); + x2 = OBSIDIAN_MIN(x2, grid_max_x); + y2 = OBSIDIAN_MIN(y2, grid_max_y); if ((x2 - x1) < 8 || (y2 - y1) < 8) { return; diff --git a/source_files/obsidian_main/dm_extra.cc b/source_files/obsidian_main/dm_extra.cc index 52e43e201..263ff2681 100644 --- a/source_files/obsidian_main/dm_extra.cc +++ b/source_files/obsidian_main/dm_extra.cc @@ -155,7 +155,7 @@ qLump_c *CreateFlat(int new_W, int new_H, const uint8_t *pixels, int W, int H) { for (int y = 0; y < new_H; y++) { for (int x = 0; x < new_W; x += W) { - int span = MIN(W, new_W - x); + int span = OBSIDIAN_MIN(W, new_W - x); SYS_ASSERT(span > 0); @@ -352,11 +352,11 @@ int fsky_solid_box(lua_State *L) { SYS_ASSERT(sky_pixels); // clip box to pixel rectangle - x1 = MAX(x1, 0); - y1 = MAX(y1, 0); + x1 = OBSIDIAN_MAX(x1, 0); + y1 = OBSIDIAN_MAX(y1, 0); - x2 = MIN(x2, sky_W); - y2 = MIN(y2, sky_H); + x2 = OBSIDIAN_MIN(x2, sky_W); + y2 = OBSIDIAN_MIN(y2, sky_H); for (int y = y1; y < y2; y++) { if (x2 > x1) { @@ -876,7 +876,7 @@ static void TransferWADtoWAD(int src_entry, const char *dest_lump) { char *buffer = new char[buf_size]; for (int pos = 0; pos < length;) { - int want_len = MIN(buf_size, length - pos); + int want_len = OBSIDIAN_MIN(buf_size, length - pos); // FIXME: handle error better if (!WAD_ReadData(src_entry, pos, want_len, buffer)) { @@ -902,7 +902,7 @@ static qLump_c *DoLoadLump(int src_entry) { char *buffer = new char[buf_size]; for (int pos = 0; pos < length;) { - int want_len = MIN(buf_size, length - pos); + int want_len = OBSIDIAN_MIN(buf_size, length - pos); // FIXME: handle error better if (!WAD_ReadData(src_entry, pos, want_len, buffer)) { @@ -1772,9 +1772,9 @@ static inline rgb_color_t CalcAdditive(rgb_color_t C1, rgb_color_t C2) { int g = RGB_GREEN(C1) + RGB_GREEN(C2); int b = RGB_BLUE(C1) + RGB_BLUE(C2); - r = MIN(r, 255); - g = MIN(g, 255); - b = MIN(b, 255); + r = OBSIDIAN_MIN(r, 255); + g = OBSIDIAN_MIN(g, 255); + b = OBSIDIAN_MIN(b, 255); return MAKE_RGBA(r, g, b, 255); } @@ -1784,9 +1784,9 @@ static inline rgb_color_t CalcSubtract(rgb_color_t C1, rgb_color_t C2) { int g = RGB_GREEN(C1) - RGB_GREEN(C2); int b = RGB_BLUE(C1) - RGB_BLUE(C2); - r = MAX(r, 0); - g = MAX(g, 0); - b = MAX(b, 0); + r = OBSIDIAN_MAX(r, 0); + g = OBSIDIAN_MAX(g, 0); + b = OBSIDIAN_MAX(b, 0); return MAKE_RGBA(r, g, b, 255); } @@ -1862,11 +1862,11 @@ static void TDraw_Box(int x, int y, int w, int h) { int x2 = x + w; int y2 = y + h; - x1 = MAX(x1, 0); - y1 = MAX(y1, 0); + x1 = OBSIDIAN_MAX(x1, 0); + y1 = OBSIDIAN_MAX(y1, 0); - x2 = MIN(x2, title_W3); - y2 = MIN(y2, title_H3); + x2 = OBSIDIAN_MIN(x2, title_W3); + y2 = OBSIDIAN_MIN(y2, title_H3); if (x1 > x2 || y1 > y2) { return; @@ -1904,11 +1904,11 @@ static void TDraw_Circle(int x, int y, int w, int h) { int x2 = x + w; int y2 = y + h; - x1 = MAX(x1, 0); - y1 = MAX(y1, 0); + x1 = OBSIDIAN_MAX(x1, 0); + y1 = OBSIDIAN_MAX(y1, 0); - x2 = MIN(x2, title_W3); - y2 = MIN(y2, title_H3); + x2 = OBSIDIAN_MIN(x2, title_W3); + y2 = OBSIDIAN_MIN(y2, title_H3); if (x1 > x2 || y1 > y2) { return; @@ -1978,8 +1978,8 @@ static void TDraw_Line(int x1, int y1, int x2, int y2) { x2 = tmp; } - x1 = MAX(0, x1); - x2 = MIN(title_W3 - 1, x2); + x1 = OBSIDIAN_MAX(0, x1); + x2 = OBSIDIAN_MIN(title_W3 - 1, x2); for (; x1 <= x2; x1++) { TDraw_LinePart(x1, y1); @@ -1995,8 +1995,8 @@ static void TDraw_Line(int x1, int y1, int x2, int y2) { y2 = tmp; } - y1 = MAX(0, y1); - y2 = MIN(title_H3 - 1, y2); + y1 = OBSIDIAN_MAX(0, y1); + y2 = OBSIDIAN_MIN(title_H3 - 1, y2); for (; y1 <= y2; y1++) { TDraw_LinePart(x1, y1); @@ -2241,7 +2241,7 @@ int title_draw_clouds(lua_State *L) { // create height field // [ it is a square, and size must be a power of two ] - int W = MAX(title_W, title_H) - 1; + int W = OBSIDIAN_MAX(title_W, title_H) - 1; for (int k = 0; k < 30; k++) { W |= (W >> 1); } @@ -2275,9 +2275,9 @@ int title_draw_clouds(lua_State *L) { b = RGB_BLUE(hue3) * src + RGB_BLUE(hue2) * (1.0 - src); } - int r2 = CLAMP(0, r, 255); - int g2 = CLAMP(0, g, 255); - int b2 = CLAMP(0, b, 255); + int r2 = OBSIDIAN_CLAMP(0, r, 255); + int g2 = OBSIDIAN_CLAMP(0, g, 255); + int b2 = OBSIDIAN_CLAMP(0, b, 255); rgb_color_t col = MAKE_RGBA(r2, g2, b2, 255); @@ -2396,7 +2396,7 @@ for (int kx = 0 ; kx < W ; kx++) // TEMP CRUD #if 1 int ity = 128 + (nx - ny + nz) * 128; - ity = CLAMP(0, ity, 255); + ity = OBSIDIAN_CLAMP(0, ity, 255); if ((int)(K * 32) & 3) col = MAKE_RGBA(0 , 0 , ity, 255); @@ -2405,7 +2405,7 @@ for (int kx = 0 ; kx < W ; kx++) #else // moon colors int ity = 80 + (nx + nx + nx) * 60; - ity = CLAMP(0, ity, 255); + ity = OBSIDIAN_CLAMP(0, ity, 255); col = MAKE_RGBA(ity, ity, ity, 255); #endif diff --git a/source_files/obsidian_main/g_wolf.cc b/source_files/obsidian_main/g_wolf.cc index af105b253..2b664cb8f 100644 --- a/source_files/obsidian_main/g_wolf.cc +++ b/source_files/obsidian_main/g_wolf.cc @@ -397,9 +397,9 @@ bool wolf_game_interface_c::Start(const char *ext) { } if (StringCompare(file_ext, "BC") == 0) { - map_fp = fopen(TEMP_MAPTEMP, "wb"); + map_fp = FileOpen(TEMP_MAPTEMP, "wb"); } else { - map_fp = fopen(TEMP_GAMEFILE, "wb"); + map_fp = FileOpen(TEMP_GAMEFILE, "wb"); } if (!map_fp) { @@ -409,7 +409,7 @@ bool wolf_game_interface_c::Start(const char *ext) { return false; } - head_fp = fopen(TEMP_HEADFILE, "wb"); + head_fp = FileOpen(TEMP_HEADFILE, "wb"); if (!head_fp) { fclose(map_fp); diff --git a/source_files/obsidian_main/headers.h b/source_files/obsidian_main/headers.h index f44417526..288d46c87 100644 --- a/source_files/obsidian_main/headers.h +++ b/source_files/obsidian_main/headers.h @@ -69,10 +69,6 @@ #include "sys_endian.h" #include "sys_macro.h" -#define HAVE_PHYSFS 1 - -#define MSG_BUF_LEN 2000 - /* Internationalization / Localization */ #define _(s) ob_gettext(s) diff --git a/source_files/obsidian_main/lib_tga.cc b/source_files/obsidian_main/lib_tga.cc index 2c5e53f8d..b4f6461d4 100644 --- a/source_files/obsidian_main/lib_tga.cc +++ b/source_files/obsidian_main/lib_tga.cc @@ -29,9 +29,7 @@ #include "headers.h" #include "main.h" -#ifdef HAVE_PHYSFS #include "m_addons.h" -#endif tga_image_c::tga_image_c(int W, int H) : width(W), height(H), opacity(OPAC_UNKNOWN) { @@ -393,11 +391,7 @@ tga_image_c *TGA_LoadImage(const char *path) { } } -#ifdef HAVE_PHYSFS VFS_FreeFile(buffer); -#else - FileFree(buffer); -#endif img->opacity = is_complex ? OPAC_Complex : is_masked ? OPAC_Masked diff --git a/source_files/obsidian_main/lib_util.cc b/source_files/obsidian_main/lib_util.cc index e1673fcd7..5f3418b8c 100644 --- a/source_files/obsidian_main/lib_util.cc +++ b/source_files/obsidian_main/lib_util.cc @@ -121,7 +121,7 @@ bool IsPathAbsolute(std::string_view path) FILE *FileOpen(std::string_view name, std::string_view mode) { SYS_ASSERT(!name.empty()); - return fopen(std::string(name).c_str(), std::string(mode).c_str()); + return FileOpen(std::string(name).c_str(), std::string(mode).c_str()); } bool FileRename(std::string_view oldname, std::string_view newname) { diff --git a/source_files/obsidian_main/lib_wad.cc b/source_files/obsidian_main/lib_wad.cc index 81e8013c5..86ab979fb 100644 --- a/source_files/obsidian_main/lib_wad.cc +++ b/source_files/obsidian_main/lib_wad.cc @@ -24,9 +24,7 @@ #include "headers.h" #include "main.h" -#ifdef HAVE_PHYSFS #include "physfs.h" -#endif #include "lib_util.h" #include "lib_wad.h" @@ -37,21 +35,13 @@ // WAD READING //------------------------------------------------------------------------ -#ifdef HAVE_PHYSFS static PHYSFS_File *wad_R_fp; -#else -static FILE *wad_R_fp; -#endif - static raw_wad_header_t wad_R_header; static raw_wad_lump_t *wad_R_dir; bool WAD_OpenRead(std::string filename) { -#ifdef HAVE_PHYSFS + wad_R_fp = PHYSFS_openRead(filename.c_str()); -#else - wad_R_fp = fopen(filename.c_str(), "rb"); -#endif if (!wad_R_fp) { LogPrintf("WAD_OpenRead: no such file: %s\n", filename.c_str()); @@ -60,29 +50,17 @@ bool WAD_OpenRead(std::string filename) { LogPrintf("Opened WAD file: %s\n", filename.c_str()); -#ifdef HAVE_PHYSFS if ((PHYSFS_readBytes(wad_R_fp, &wad_R_header, sizeof(wad_R_header)) / sizeof(wad_R_header)) != 1) -#else - if (fread(&wad_R_header, sizeof(wad_R_header), 1, wad_R_fp) != 1) -#endif { LogPrintf("WAD_OpenRead: failed reading header\n"); -#ifdef HAVE_PHYSFS PHYSFS_close(wad_R_fp); -#else - fclose(wad_R_fp); -#endif return false; } if (0 != memcmp(wad_R_header.magic + 1, "WAD", 3)) { LogPrintf("WAD_OpenRead: not a WAD file!\n"); -#ifdef HAVE_PHYSFS PHYSFS_close(wad_R_fp); -#else - fclose(wad_R_fp); -#endif return false; } @@ -95,27 +73,15 @@ bool WAD_OpenRead(std::string filename) { { LogPrintf("WAD_OpenRead: bad header (%u entries?)\n", static_cast(wad_R_header.num_lumps)); -#ifdef HAVE_PHYSFS PHYSFS_close(wad_R_fp); -#else - fclose(wad_R_fp); -#endif return false; } -#ifdef HAVE_PHYSFS if (!PHYSFS_seek(wad_R_fp, wad_R_header.dir_start)) -#else - if (fseek(wad_R_fp, wad_R_header.dir_start, SEEK_SET) != 0) -#endif { LogPrintf("WAD_OpenRead: cannot seek to directory (at 0x%u)\n", static_cast(wad_R_header.dir_start)); -#ifdef HAVE_PHYSFS PHYSFS_close(wad_R_fp); -#else - fclose(wad_R_fp); -#endif return false; } @@ -124,14 +90,9 @@ bool WAD_OpenRead(std::string filename) { for (int i = 0; i < (int)wad_R_header.num_lumps; i++) { raw_wad_lump_t *L = &wad_R_dir[i]; -#ifdef HAVE_PHYSFS size_t res = (PHYSFS_readBytes(wad_R_fp, L, sizeof(raw_wad_lump_t)) / sizeof(raw_wad_lump_t)); if (res != 1) -#else - int res = fread(L, sizeof(raw_wad_lump_t), 1, wad_R_fp); - if (res == EOF || res != 1 || ferror(wad_R_fp)) -#endif { if (i == 0) { LogPrintf("WAD_OpenRead: could not read any dir-entries!\n"); @@ -154,11 +115,7 @@ bool WAD_OpenRead(std::string filename) { } void WAD_CloseRead(void) { -#ifdef HAVE_PHYSFS PHYSFS_close(wad_R_fp); -#else - fclose(wad_R_fp); -#endif LogPrintf("Closed WAD file\n"); @@ -211,18 +168,11 @@ bool WAD_ReadData(int entry, int offset, int length, void *buffer) { return false; } -#if HAVE_PHYSFS if (!PHYSFS_seek(wad_R_fp, L->start + offset)) { return false; } return ((PHYSFS_readBytes(wad_R_fp, buffer, length) / length) == 1); -#else - if (fseek(wad_R_fp, L->start + offset, SEEK_SET) != 0) return false; - - int res = fread(buffer, length, 1, wad_R_fp); - return (res == 1); -#endif } //------------------------------------------------------------------------ diff --git a/source_files/obsidian_main/m_addons.cc b/source_files/obsidian_main/m_addons.cc index d9ccf8fe5..132f3e94c 100644 --- a/source_files/obsidian_main/m_addons.cc +++ b/source_files/obsidian_main/m_addons.cc @@ -257,7 +257,7 @@ bool VFS_CopyFile(const char *src_name, const char *dest_name) { return false; } - FILE *dest = fopen(dest_name, "wb"); + FILE *dest = FileOpen(dest_name, "wb"); if (!dest) { PHYSFS_close(src); return false; diff --git a/source_files/obsidian_main/m_theme.cc b/source_files/obsidian_main/m_theme.cc index ac0358548..f2415541d 100644 --- a/source_files/obsidian_main/m_theme.cc +++ b/source_files/obsidian_main/m_theme.cc @@ -121,7 +121,7 @@ std::string Theme_AskLoadFilename() { static void Parse_Theme_Option(std::string name, std::string value) { if (StringCompare(name, "window_scaling") == 0) { window_scaling = StringToInt(value); - window_scaling = CLAMP(0, window_scaling, 5); + window_scaling = OBSIDIAN_CLAMP(0, window_scaling, 5); } else if (StringCompare(name, "font_scaling") == 0) { font_scaling = StringToInt(value); } else if (StringCompare(name, "font_theme") == 0) { diff --git a/source_files/obsidian_main/m_trans.cc b/source_files/obsidian_main/m_trans.cc index 3ac38afde..b19c35e9b 100644 --- a/source_files/obsidian_main/m_trans.cc +++ b/source_files/obsidian_main/m_trans.cc @@ -1076,7 +1076,7 @@ void Trans_SetLanguage() { path = StringFormat("%s/language/%s.po", install_dir.c_str(), lang_plain.c_str()); } - FILE *fp = fopen(path.c_str(), "rb"); + FILE *fp = FileOpen(path.c_str(), "rb"); if (!fp) { LogPrintf("No translation file: language/%s.po\n", lang_plain.c_str()); LogPrintf("Using the default language (English)\n\n"); diff --git a/source_files/obsidian_main/main.cc b/source_files/obsidian_main/main.cc index 6d1c70c51..edcedaee4 100644 --- a/source_files/obsidian_main/main.cc +++ b/source_files/obsidian_main/main.cc @@ -352,7 +352,7 @@ void Determine_WorkingPath() { #ifdef _WIN32 home_dir = PHYSFS_getBaseDir(); #else - home_dir = PHYSFS_getPrefDir(NULL, "Obsidian Level Maker"); + home_dir = PHYSFS_getPrefDir("Obsidian Team", "Obsidian"); #endif } diff --git a/source_files/obsidian_main/sys_endian.h b/source_files/obsidian_main/sys_endian.h index 88ef500cd..eef5efc3c 100644 --- a/source_files/obsidian_main/sys_endian.h +++ b/source_files/obsidian_main/sys_endian.h @@ -1,15 +1,13 @@ //------------------------------------------------------------------------ -// EDGE Endian handling -//------------------------------------------------------------------------ -// -// OBSIDIAN Level Maker +// OBSIDIAN Endian handling +//---------------------------------------------------------------------------- // -// Copyright (C) 2021-2022 The OBSIDIAN Team -// Copyright (C) 2006-2017 Andrew Apted +// Copyright (c) 2024 The OBSIDIAN Team. +// Copyright (c) 2003-2024 The EDGE Team. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 +// as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, @@ -17,103 +15,206 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // -//------------------------------------------------------------------------ -// -// Using code from SDL_byteorder.h and SDL_endian.h. -// Copyright (C) 1997-2004 Sam Lantinga. -// -//------------------------------------------------------------------------ +//---------------------------------------------------------------------------- -#ifndef __SYS_ENDIAN_H__ -#define __SYS_ENDIAN_H__ +#pragma once #include +#include -// ---- determine byte order ---- - -#define UT_LIL_ENDIAN 1234 -#define UT_BIG_ENDIAN 4321 - -#if defined(__LITTLE_ENDIAN__) || defined(WIN32) || defined(__i386__) || \ - defined(__i386) || defined(__ia64__) || defined(__x86_64__) || \ - defined(__alpha__) || defined(__alpha) || defined(__arm__) || \ - defined(__aarch64__) || defined(__SYMBIAN32__) || \ - (defined(__mips__) && defined(__MIPSEL__)) -#define UT_BYTEORDER UT_LIL_ENDIAN +// Used to swap values. Try to use superfast macros on systems +// that support them, otherwise use regular C++ functions. +#if defined(__GNUC__) || defined(__clang__) +static inline uint16_t __Swap16(uint16_t n) +{ + return __builtin_bswap16(n); +} +static inline uint32_t __Swap32(uint32_t n) +{ + return __builtin_bswap32(n); +} +static inline uint64_t __Swap64(uint64_t n) +{ + return __builtin_bswap64(n); +} +#elif defined(_MSC_VER) +static inline uint16_t __Swap16(uint16_t n) +{ + return _byteswap_ushort(n); +} +static inline uint32_t __Swap32(uint32_t n) +{ + return _byteswap_ulong(n); +} +static inline uint64_t __Swap64(uint64_t n) +{ + return _byteswap_uint64(n); +} #else -#define UT_BYTEORDER UT_BIG_ENDIAN +static inline uint16_t __Swap16(uint16_t n) +{ + uint16_t a; + a = (n & 0xFF) << 8; + a |= (n >> 8) & 0xFF; + return a; +} +static inline uint32_t __Swap32(uint32_t n) +{ + uint32_t a; + a = (n & 0xFFU) << 24; + a |= (n & 0xFF00U) << 8; + a |= (n >> 8) & 0xFF00U; + a |= (n >> 24) & 0xFFU; + return a; +} +static inline uint64_t __Swap64(uint64_t n) +{ + uint64_t a; + a = (n & 0xFFULL) << 56; + a |= (n & 0xFF00ULL) << 40; + a |= (n & 0xFF0000ULL) << 24; + a |= (n & 0xFF000000ULL) << 8; + a |= (n >> 8) & 0xFF000000ULL; + a |= (n >> 24) & 0xFF0000ULL; + a |= (n >> 40) & 0xFF00ULL; + a |= (n >> 56) & 0xFFULL; + return a; +} #endif -// ---- the gruntwork of swapping ---- +#if defined(__LITTLE_ENDIAN__) || defined(__i386__) || defined(__ia64__) || defined(WIN32) || defined(__alpha__) || \ + defined(__alpha) || defined(__arm__) || (defined(__mips__) && defined(__MIPSEL__)) || defined(__SYMBIAN32__) || \ + defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__) -#if defined(__GNUC__) && defined(__i386__) -static inline uint16_t UT_Swap16(uint16_t x) { - __asm__("xchgb %b0,%h0" : "=q"(x) : "0"(x)); +inline uint16_t LE_U16(const uint16_t x) +{ return x; } -#elif defined(__GNUC__) && defined(__x86_64__) -static inline uint16_t UT_Swap16(uint16_t x) { - __asm__("xchgb %b0,%h0" : "=Q"(x) : "0"(x)); +inline int16_t LE_S16(const uint16_t x) +{ + return (int16_t)x; +} +inline uint32_t LE_U32(const uint32_t x) +{ return x; } -#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static inline uint16_t UT_Swap16(uint16_t x) { - uint16_t result; - - __asm__("rlwimi %0,%2,8,16,23" : "=&r"(result) : "0"(x >> 8), "r"(x)); - return result; +inline int32_t LE_S32(const uint32_t x) +{ + return (int32_t)x; } -#else -static inline uint16_t UT_Swap16(uint16_t x) { return ((x << 8) | (x >> 8)); } -#endif - -#if defined(__GNUC__) && defined(__i386__) -static inline uint32_t UT_Swap32(uint32_t x) { - __asm__("bswap %0" : "=r"(x) : "0"(x)); +inline uint64_t LE_U64(const uint64_t x) +{ return x; } -#elif defined(__GNUC__) && defined(__x86_64__) -static inline uint32_t UT_Swap32(uint32_t x) { - __asm__("bswapl %0" : "=r"(x) : "0"(x)); +inline int64_t LE_S64(const uint64_t x) +{ + return (int64_t)x; +} +inline float LE_FLOAT(const float x) +{ return x; } -#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) -static inline uint32_t UT_Swap32(uint32_t x) { - uint32_t result; - __asm__("rlwimi %0,%2,24,16,23" : "=&r"(result) : "0"(x >> 24), "r"(x)); - __asm__("rlwimi %0,%2,8,8,15" : "=&r"(result) : "0"(result), "r"(x)); - __asm__("rlwimi %0,%2,24,0,7" : "=&r"(result) : "0"(result), "r"(x)); - return result; +inline uint16_t BE_U16(const uint16_t x) +{ + return __Swap16(x); } -#else -static inline uint32_t UT_Swap32(uint32_t x) { - return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | - (x >> 24)); +inline int16_t BE_S16(const uint16_t x) +{ + return (int16_t)__Swap16(x); +} +inline uint32_t BE_U32(const uint32_t x) +{ + return __Swap32(x); +} +inline int32_t BE_S32(const uint32_t x) +{ + return (int32_t)__Swap32(x); +} +inline uint64_t BE_U64(const uint64_t x) +{ + return __Swap64(x); +} +inline int64_t BE_S64(const uint64_t x) +{ + return (int64_t)__Swap64(x); +} +inline float BE_FLOAT(const float x) +{ + union { + float f; + uint32_t u; + } in, out; + in.f = x; + out.u = BE_U32(in.u); + return out.f; } -#endif - -// ---- byte swap from specified endianness to native ---- - -#if (UT_BYTEORDER == UT_LIL_ENDIAN) -#define LE_U16(X) ((uint16_t)(X)) -#define LE_U32(X) ((uint32_t)(X)) -#define BE_U16(X) UT_Swap16(X) -#define BE_U32(X) UT_Swap32(X) #else -#define LE_U16(X) UT_Swap16(X) -#define LE_U32(X) UT_Swap32(X) -#define BE_U16(X) ((uint16_t)(X)) -#define BE_U32(X) ((uint32_t)(X)) -#endif -// signed versions of the above -#define LE_S16(X) ((int16_t)LE_U16((uint16_t)(X))) -#define LE_S32(X) ((int32_t)LE_U32((uint32_t)(X))) -#define BE_S16(X) ((int16_t)BE_U16((uint16_t)(X))) -#define BE_S32(X) ((int32_t)BE_U32((uint32_t)(X))) +inline uint16_t LE_U16(const uint16_t x) +{ + return __Swap16(x); +} +inline int16_t LE_S16(const uint16_t x) +{ + return (int16_t)__Swap16(x); +} +inline uint32_t LE_U32(const uint32_t x) +{ + return __Swap32(x); +} +inline int32_t LE_S32(const uint32_t x) +{ + return (int32_t)__Swap32(x); +} +inline uint64_t LE_U64(const uint64_t x) +{ + return __Swap64(x); +} +inline int64_t LE_S64(const uint64_t x) +{ + return (int64_t)__Swap64(x); +} +inline float LE_FLOAT(const float x) +{ + union { + float f; + uint32_t u; + } in, out; + in.f = x; + out.u = LE_U32(in.u); + return out.f; +} -#endif // __SYS_ENDIAN_H__ +inline uint16_t BE_U16(const uint16_t x) +{ + return x; +} +inline int16_t BE_S16(const uint16_t x) +{ + return (int16_t)x; +} +inline uint32_t BE_U32(const uint32_t x) +{ + return x; +} +inline int32_t BE_S32(const uint32_t x) +{ + return (int32_t)x; +} +inline uint64_t BE_U64(const uint64_t x) +{ + return x; +} +inline int64_t BE_S64(const uint64_t x) +{ + return (int64_t)x; +} +inline float BE_FLOAT(const float x) +{ + return x; +} +#endif //--- editor settings --- // vi:ts=4:sw=4:noexpandtab diff --git a/source_files/obsidian_main/sys_macro.h b/source_files/obsidian_main/sys_macro.h index 63b28e966..8868c8e9f 100644 --- a/source_files/obsidian_main/sys_macro.h +++ b/source_files/obsidian_main/sys_macro.h @@ -22,76 +22,27 @@ #ifndef SYS_MACRO_H_ #define SYS_MACRO_H_ -#include - -// basic macros - -// smallest distance between two points before being considered equal -#define DIST_EPSILON (1.0 / 128.0) - -// smallest degrees between two angles before being considered equal -#define ANG_EPSILON (1.0 / 1024.0) - +// basic constants +constexpr uint16_t MSG_BUF_LEN = 2000; +constexpr double DIST_EPSILON = (1.0 / 128.0); +constexpr double ANG_EPSILON = (1.0 / 1024.0); #ifndef M_PI -constexpr double M_PI = 3.14159265358979323846; -#endif - -#ifndef MAX -template >> -constexpr A MAX(A a, B b) { - if (a > b) { - return a; - } - return static_cast(b); -} -#endif - -#ifndef MIN -template >> -constexpr A MIN(A a, B b) { - if (a < b) { - return a; - } - return static_cast(b); -} -#endif - -#ifndef ABS -template -constexpr T ABS(T a) { - if (a < 0) { - return -a; - } - return a; -} +constexpr double M_PI = 3.14159265358979323846; #endif -#ifndef I_ROUND -template -constexpr int I_ROUND(T x) { - if (x < 0) { - return x - 0.5; - } - return x + 0.5; +// basic math +#define OBSIDIAN_MAX(a, b) ((a > b) ? a : b) +#define OBSIDIAN_MIN(a, b) ((a < b) ? a : b) +#define OBSIDIAN_ABS(a) ((a < 0) ? -a : a) +#define OBSIDIAN_CLAMP(low, x, high) ((x < low) ? low : ((x > high) ? high : x)) +inline int RoundToInteger(float x) +{ + return (int)roundf(x); } -#endif - -#ifndef CLAMP -template , std::is_convertible>>> -constexpr T CLAMP(L low, T x, U high) { - if (x < low) { - return static_cast(low); - } - if (x > high) { - return static_cast(high); - } - return x; +inline int RoundToInteger(double x) +{ + return (int)round(x); } -#endif #endif // SYS_MACRO_H_ diff --git a/source_files/obsidian_main/tx_forge.cc b/source_files/obsidian_main/tx_forge.cc index 0dce8a243..8dca47197 100644 --- a/source_files/obsidian_main/tx_forge.cc +++ b/source_files/obsidian_main/tx_forge.cc @@ -259,8 +259,8 @@ static void copy_and_scale(float *buf) { for (j = 0; j < meshsize; j++) { double r = Real(i, j); - rmin = MIN(rmin, r); - rmax = MAX(rmax, r); + rmin = OBSIDIAN_MIN(rmin, r); + rmax = OBSIDIAN_MAX(rmax, r); } } diff --git a/source_files/obsidian_main/tx_skies.cc b/source_files/obsidian_main/tx_skies.cc index 2eef7909b..33f70f321 100644 --- a/source_files/obsidian_main/tx_skies.cc +++ b/source_files/obsidian_main/tx_skies.cc @@ -86,7 +86,7 @@ void SKY_AddClouds(unsigned long long seed, uint8_t *pixels, int W, int H, v = (v - thresh) / (1.0 - thresh); int idx = (int)(v * map->size); - idx = CLAMP(0, idx, map->size - 1); + idx = OBSIDIAN_CLAMP(0, idx, map->size - 1); *dest++ = map->colors[idx]; } @@ -120,7 +120,7 @@ void SKY_AddStars(unsigned long long seed, uint8_t *pixels, int W, int H, v = (v - thresh) / (1.0 - thresh); int idx = (int)(v * map->size); - idx = CLAMP(0, idx, map->size - 1); + idx = OBSIDIAN_CLAMP(0, idx, map->size - 1); *dest++ = map->colors[idx]; } @@ -155,7 +155,7 @@ void SKY_AddHills(unsigned long long seed, uint8_t *pixels, int W, int H, float z0_max_h = -99; for (x = 0; x < W; x++) { - z0_max_h = MAX(z0_max_h, height_map[x]); + z0_max_h = OBSIDIAN_MAX(z0_max_h, height_map[x]); } if (z0_max_h > -0.05) { @@ -216,7 +216,7 @@ void SKY_AddHills(unsigned long long seed, uint8_t *pixels, int W, int H, } int col_idx = (int)(ity * map->size); - col_idx = CLAMP(0, col_idx, map->size - 1); + col_idx = OBSIDIAN_CLAMP(0, col_idx, map->size - 1); uint8_t col = map->colors[col_idx]; diff --git a/source_files/obsidian_main/ui_map.cc b/source_files/obsidian_main/ui_map.cc index b5ed2eb20..7e55be3fc 100644 --- a/source_files/obsidian_main/ui_map.cc +++ b/source_files/obsidian_main/ui_map.cc @@ -153,8 +153,8 @@ void UI_MiniMap::DrawLine(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, x2 = tmp; } - x1 = MAX(0, x1); - x2 = MIN(map_W - 1, x2); + x1 = OBSIDIAN_MAX(0, x1); + x2 = OBSIDIAN_MIN(map_W - 1, x2); for (; x1 <= x2; x1++) { RawPixel(x1, y1, r, g, b); @@ -170,8 +170,8 @@ void UI_MiniMap::DrawLine(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, y2 = tmp; } - y1 = MAX(0, y1); - y2 = MIN(map_H - 1, y2); + y1 = OBSIDIAN_MAX(0, y1); + y2 = OBSIDIAN_MIN(map_H - 1, y2); for (; y1 <= y2; y1++) { RawPixel(x1, y1, r, g, b); diff --git a/source_files/obsidian_main/ui_module.cc b/source_files/obsidian_main/ui_module.cc index 39f2b2e19..d1ced0793 100644 --- a/source_files/obsidian_main/ui_module.cc +++ b/source_files/obsidian_main/ui_module.cc @@ -1312,8 +1312,8 @@ void UI_CustomMods::PositionAll(UI_Module *focus) { offset_y = above_h - focus_oy; - offset_y = MAX(offset_y, 0); - offset_y = MIN(offset_y, new_height - mh); + offset_y = OBSIDIAN_MAX(offset_y, 0); + offset_y = OBSIDIAN_MIN(offset_y, new_height - mh); } else { // when not shrinking, offset_y will remain valid if (new_height < total_h) {