Skip to content

Commit

Permalink
Stop usin' streams
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jun 11, 2024
1 parent 4078aca commit f69004a
Show file tree
Hide file tree
Showing 33 changed files with 602 additions and 525 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ set(OBSIDIAN_SOURCE_FILES
source/bsp_level.cc
source/bsp_misc.cc
source/bsp_node.cc
source/bsp_utility.cc
source/bsp_wad.cc
source/bsp.cc
source/csg_bsp.cc
Expand Down
1 change: 0 additions & 1 deletion source/bsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <string.h>

#include "bsp_utility.h"
#include "bsp_wad.h"
#include "lib_util.h"
#include "raw_def.h"
Expand Down
1 change: 0 additions & 1 deletion source/bsp_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <algorithm>

#include "bsp_local.h"
#include "bsp_utility.h"
#include "bsp_wad.h"
#include "lib_parse.h"
#include "miniz.h"
Expand Down
1 change: 0 additions & 1 deletion source/bsp_misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <algorithm>

#include "bsp_local.h"
#include "bsp_utility.h"
#include "bsp_wad.h"
#include "raw_def.h"
#include "sys_macro.h"
Expand Down
1 change: 0 additions & 1 deletion source/bsp_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <limits.h>

#include "bsp_local.h"
#include "bsp_utility.h"
#include "bsp_wad.h"
#include "sys_macro.h"

Expand Down
111 changes: 0 additions & 111 deletions source/bsp_utility.cc

This file was deleted.

37 changes: 0 additions & 37 deletions source/bsp_utility.h

This file was deleted.

1 change: 0 additions & 1 deletion source/bsp_wad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <algorithm>

#include "bsp_local.h"
#include "bsp_utility.h"
#include "lib_util.h"
#include "sys_endian.h"
#include "sys_macro.h"
Expand Down
3 changes: 3 additions & 0 deletions source/dm_extra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
//
//------------------------------------------------------------------------

#include <algorithm>
#include <iterator>

#include "csg_main.h"
#include "g_doom.h"
#ifndef CONSOLE_ONLY
Expand Down
4 changes: 3 additions & 1 deletion source/g_doom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "g_doom.h"

#include <locale.h>

#include <bitset>
#include <string>

Expand Down Expand Up @@ -532,7 +534,7 @@ bool Doom::StartWAD(std::string filename)
#ifndef CONSOLE_ONLY
DLG_ShowError(_("Unable to create wad file:\n\n%s"), strerror(errno));
#else
StdOutPrintf(_("Unable to create wad file:\n\n%s"), strerror(errno));
printf(_("Unable to create wad file:\n\n%s"), strerror(errno));
#endif
return false;
}
Expand Down
83 changes: 82 additions & 1 deletion source/lib_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void StringRemoveCRLF(std::string *str)
{
str->pop_back();
}
if (str->back() == '\r')
if (!str->empty() && str->back() == '\r')
{
str->pop_back();
}
Expand Down Expand Up @@ -912,5 +912,86 @@ uint32_t TimeGetMillies()
.count();
}

//------------------------------------------------------------------------
// MEMORY ALLOCATION
//------------------------------------------------------------------------

//
// Allocate memory with error checking. Zeros the memory.
//
void *UtilCalloc(int size)
{
void *ret = calloc(1, size);

if (!ret)
Main::FatalError("Out of memory (cannot allocate %d bytes)\n", size);

return ret;
}

//
// Reallocate memory with error checking.
//
void *UtilRealloc(void *old, int size)
{
void *ret = realloc(old, size);

if (!ret)
Main::FatalError("Out of memory (cannot reallocate %d bytes)\n", size);

return ret;
}

//
// Free the memory with error checking.
//
void UtilFree(void *data)
{
if (data == NULL)
Main::FatalError("Trying to free a NULL pointer\n");

free(data);
}

//------------------------------------------------------------------------
// MATH STUFF
//------------------------------------------------------------------------

//
// rounds the value _up_ to the nearest power of two.
//
int RoundPOW2(int x)
{
if (x <= 2)
return x;

x--;

for (int tmp = x >> 1; tmp; tmp >>= 1)
x |= tmp;

return x + 1;
}

//
// Compute angle of line from (0,0) to (dx,dy).
// Result is degrees, where 0 is east and 90 is north.
//
double ComputeAngle(double dx, double dy)
{
double angle;

if (dx == 0)
return (dy > 0) ? 90.0 : 270.0;

angle = atan2((double)dy, (double)dx) * 180.0 / M_PI;

if (angle < 0)
angle += 360.0;

return angle;
}


//--- editor settings ---
// vi:ts=4:sw=4:noexpandtab
10 changes: 10 additions & 0 deletions source/lib_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ char *mem_gets(char *buf, int size, const char **str_ptr);

uint32_t TimeGetMillies();

/* memory utilities */

void *UtilCalloc(int size);
void *UtilRealloc(void *old, int size);
void UtilFree(void *data);


/* math utilities */

uint32_t IntHash(uint32_t key);
Expand All @@ -155,5 +162,8 @@ std::pair<double, double> AlongCoord(double along, double px1, double py1, doubl

bool VectorSameDir(double dx1, double dy1, double dx2, double dy2);

int RoundPOW2(int x);
double ComputeAngle(double dx, double dy);

//--- editor settings ---
// vi:ts=4:sw=4:noexpandtab
Loading

0 comments on commit f69004a

Please sign in to comment.