Skip to content

Commit

Permalink
Remove HAVE_PHYSFS define (we always have it); update some macros/end…
Browse files Browse the repository at this point in the history
…ian stuff
  • Loading branch information
dashodanger committed Jun 9, 2024
1 parent 800f1c0 commit 9c75fcb
Show file tree
Hide file tree
Showing 26 changed files with 386 additions and 438 deletions.
1 change: 0 additions & 1 deletion source_files/obsidian_main/aj_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "sys_endian.h"
#include "sys_macro.h"

#define HAVE_PHYSFS 1
#include "physfs.h"

namespace ajpoly {
Expand Down
27 changes: 14 additions & 13 deletions source_files/obsidian_main/aj_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "aj_local.h"
#include "aj_parse.h"
#include "main.h"
#include "sys_macro.h"

#define DEBUG_LOAD 0

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions source_files/obsidian_main/aj_poly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cstddef>
#include "aj_local.h"
#include "sys_macro.h"

#define DEBUG_POLY 0

Expand Down Expand Up @@ -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.
Expand Down
46 changes: 1 addition & 45 deletions source_files/obsidian_main/aj_wad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -89,21 +85,13 @@ 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) {
SetErrorMsg("Trouble reading wad directory --> %s",
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);
Expand All @@ -127,21 +115,13 @@ 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) {
SetErrorMsg("Error reading wad header --> %s",
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.");
Expand All @@ -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()) {
Expand Down Expand Up @@ -225,23 +201,14 @@ 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) {
SetErrorMsg("Cannot open WAD file: %s --> %s", 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);

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions source_files/obsidian_main/aj_wad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<lump_c *> lumps;
Expand Down
Loading

0 comments on commit 9c75fcb

Please sign in to comment.