mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-15 00:42:20 +00:00
- added printf.h header to avoid including more dirty ones for the console printing functions.
This commit is contained in:
parent
1fe667c6a0
commit
003294e598
9 changed files with 76 additions and 89 deletions
|
@ -265,12 +265,14 @@ private:
|
|||
|
||||
void *operator new(size_t len, nonew&)
|
||||
{
|
||||
GC::AllocBytes += len;
|
||||
return M_Malloc(len);
|
||||
}
|
||||
public:
|
||||
|
||||
void operator delete (void *mem, nonew&)
|
||||
{
|
||||
GC::AllocBytes -= _msize(mem);
|
||||
M_Free(mem);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ typedef TMap<int, PClassActor *> FClassMap;
|
|||
#endif
|
||||
|
||||
#include "basics.h"
|
||||
#include "printf.h"
|
||||
|
||||
extern bool batchrun;
|
||||
|
||||
|
@ -65,42 +66,6 @@ enum
|
|||
BOXRIGHT
|
||||
}; // bbox coordinates
|
||||
|
||||
|
||||
// [RH] This gets used all over; define it here:
|
||||
int Printf (int printlevel, const char *, ...) GCCPRINTF(2,3);
|
||||
int Printf (const char *, ...) GCCPRINTF(1,2);
|
||||
|
||||
// [RH] Same here:
|
||||
int DPrintf (int level, const char *, ...) GCCPRINTF(2,3);
|
||||
|
||||
extern "C" int mysnprintf(char *buffer, size_t count, const char *format, ...) GCCPRINTF(3,4);
|
||||
extern "C" int myvsnprintf(char *buffer, size_t count, const char *format, va_list argptr) GCCFORMAT(3);
|
||||
|
||||
|
||||
// game print flags
|
||||
enum
|
||||
{
|
||||
PRINT_LOW, // pickup messages
|
||||
PRINT_MEDIUM, // death messages
|
||||
PRINT_HIGH, // critical messages
|
||||
PRINT_CHAT, // chat messages
|
||||
PRINT_TEAMCHAT, // chat messages from a teammate
|
||||
PRINT_LOG, // only to logfile
|
||||
PRINT_BOLD = 200, // What Printf_Bold used
|
||||
PRINT_TYPES = 1023, // Bitmask.
|
||||
PRINT_NONOTIFY = 1024, // Flag - do not add to notify buffer
|
||||
PRINT_NOLOG = 2048, // Flag - do not print to log file
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
DMSG_OFF, // no developer messages.
|
||||
DMSG_ERROR, // general notification messages
|
||||
DMSG_WARNING, // warnings
|
||||
DMSG_NOTIFY, // general notification messages
|
||||
DMSG_SPAMMY, // for those who want to see everything, regardless of its usefulness.
|
||||
};
|
||||
|
||||
#include "palentry.h"
|
||||
|
||||
enum class ETextureType : uint8_t
|
||||
|
|
|
@ -45,20 +45,13 @@
|
|||
#endif
|
||||
|
||||
#include "doomerrors.h"
|
||||
#include "dobject.h"
|
||||
#include "m_alloc.h"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define _NORMAL_BLOCK 0
|
||||
#define _malloc_dbg(s,b,f,l) malloc(s)
|
||||
#define _realloc_dbg(p,s,b,f,l) realloc(p,s)
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
#define _msize(p) malloc_size(p)
|
||||
#elif defined(__solaris__) || defined(__OpenBSD__)
|
||||
#define _msize(p) (*((size_t*)(p)-1))
|
||||
#elif !defined(_WIN32)
|
||||
#define _msize(p) malloc_usable_size(p) // from glibc/FreeBSD
|
||||
#endif
|
||||
|
||||
#ifndef _DEBUG
|
||||
#if !defined(__solaris__) && !defined(__OpenBSD__)
|
||||
|
@ -69,22 +62,16 @@ void *M_Malloc(size_t size)
|
|||
if (block == NULL)
|
||||
I_FatalError("Could not malloc %zu bytes", size);
|
||||
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
void *M_Realloc(void *memblock, size_t size)
|
||||
{
|
||||
if (memblock != NULL)
|
||||
{
|
||||
GC::AllocBytes -= _msize(memblock);
|
||||
}
|
||||
void *block = realloc(memblock, size);
|
||||
if (block == NULL)
|
||||
{
|
||||
I_FatalError("Could not realloc %zu bytes", size);
|
||||
}
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
#else
|
||||
|
@ -99,7 +86,6 @@ void *M_Malloc(size_t size)
|
|||
*sizeStore = size;
|
||||
block = sizeStore+1;
|
||||
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
|
@ -108,10 +94,6 @@ void *M_Realloc(void *memblock, size_t size)
|
|||
if(memblock == NULL)
|
||||
return M_Malloc(size);
|
||||
|
||||
if (memblock != NULL)
|
||||
{
|
||||
GC::AllocBytes -= _msize(memblock);
|
||||
}
|
||||
void *block = realloc(((size_t*) memblock)-1, size+sizeof(size_t));
|
||||
if (block == NULL)
|
||||
{
|
||||
|
@ -122,7 +104,6 @@ void *M_Realloc(void *memblock, size_t size)
|
|||
*sizeStore = size;
|
||||
block = sizeStore+1;
|
||||
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
#endif
|
||||
|
@ -137,24 +118,18 @@ void *M_Malloc_Dbg(size_t size, const char *file, int lineno)
|
|||
void *block = _malloc_dbg(size, _NORMAL_BLOCK, file, lineno);
|
||||
|
||||
if (block == NULL)
|
||||
I_FatalError("Could not malloc %zu bytes", size);
|
||||
I_FatalError("Could not malloc %zu bytes in %s, line %d", size, file, lineno);
|
||||
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno)
|
||||
{
|
||||
if (memblock != NULL)
|
||||
{
|
||||
GC::AllocBytes -= _msize(memblock);
|
||||
}
|
||||
void *block = _realloc_dbg(memblock, size, _NORMAL_BLOCK, file, lineno);
|
||||
if (block == NULL)
|
||||
{
|
||||
I_FatalError("Could not realloc %zu bytes", size);
|
||||
I_FatalError("Could not realloc %zu bytes in %s, line %d", size, file, lineno);
|
||||
}
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
#else
|
||||
|
@ -163,13 +138,12 @@ void *M_Malloc_Dbg(size_t size, const char *file, int lineno)
|
|||
void *block = _malloc_dbg(size+sizeof(size_t), _NORMAL_BLOCK, file, lineno);
|
||||
|
||||
if (block == NULL)
|
||||
I_FatalError("Could not malloc %zu bytes", size);
|
||||
I_FatalError("Could not malloc %zu bytes in %s, line %d", size, file, lineno);
|
||||
|
||||
size_t *sizeStore = (size_t *) block;
|
||||
*sizeStore = size;
|
||||
block = sizeStore+1;
|
||||
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
|
@ -178,22 +152,17 @@ void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno)
|
|||
if(memblock == NULL)
|
||||
return M_Malloc_Dbg(size, file, lineno);
|
||||
|
||||
if (memblock != NULL)
|
||||
{
|
||||
GC::AllocBytes -= _msize(memblock);
|
||||
}
|
||||
void *block = _realloc_dbg(((size_t*) memblock)-1, size+sizeof(size_t), _NORMAL_BLOCK, file, lineno);
|
||||
|
||||
if (block == NULL)
|
||||
{
|
||||
I_FatalError("Could not realloc %zu bytes", size);
|
||||
I_FatalError("Could not realloc %zu bytes in %s, line %d", size, file, lineno);
|
||||
}
|
||||
|
||||
size_t *sizeStore = (size_t *) block;
|
||||
*sizeStore = size;
|
||||
block = sizeStore+1;
|
||||
|
||||
GC::AllocBytes += _msize(block);
|
||||
return block;
|
||||
}
|
||||
#endif
|
||||
|
@ -204,7 +173,6 @@ void M_Free (void *block)
|
|||
{
|
||||
if (block != NULL)
|
||||
{
|
||||
GC::AllocBytes -= _msize(block);
|
||||
free(block);
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +181,6 @@ void M_Free (void *block)
|
|||
{
|
||||
if(block != NULL)
|
||||
{
|
||||
GC::AllocBytes -= _msize(block);
|
||||
free(((size_t*) block)-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,14 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define _msize(p) malloc_size(p)
|
||||
#elif defined(__solaris__) || defined(__OpenBSD__)
|
||||
#define _msize(p) (*((size_t*)(p)-1))
|
||||
#elif !defined(_WIN32)
|
||||
#define _msize(p) malloc_usable_size(p) // from glibc/FreeBSD
|
||||
#endif
|
||||
|
||||
// These are the same as the same stdlib functions,
|
||||
// except they bomb out with a fatal error
|
||||
// when they can't get the memory.
|
||||
|
|
|
@ -21,7 +21,7 @@ This is a simplified version of VSMatrix that has been adjusted for GZDoom's nee
|
|||
static inline FLOATTYPE
|
||||
DegToRad(FLOATTYPE degrees)
|
||||
{
|
||||
return (FLOATTYPE)(degrees * (M_PI / 180.0f));
|
||||
return (FLOATTYPE)(degrees * (pi::pif() / 180.0f));
|
||||
};
|
||||
|
||||
// sets the square matrix mat to the identity matrix,
|
||||
|
@ -243,7 +243,7 @@ VSMatrix::lookAt(FLOATTYPE xPos, FLOATTYPE yPos, FLOATTYPE zPos,
|
|||
void
|
||||
VSMatrix::perspective(FLOATTYPE fov, FLOATTYPE ratio, FLOATTYPE nearp, FLOATTYPE farp)
|
||||
{
|
||||
FLOATTYPE f = 1.0f / tan (fov * (M_PI / 360.0f));
|
||||
FLOATTYPE f = 1.0f / tan (fov * (pi::pif() / 360.0f));
|
||||
|
||||
loadIdentity();
|
||||
mMatrix[0] = f / ratio;
|
||||
|
@ -392,13 +392,6 @@ VSMatrix::length(const FLOATTYPE *a) {
|
|||
}
|
||||
|
||||
|
||||
static inline int
|
||||
M3(int i, int j)
|
||||
{
|
||||
return (i*3+j);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// computes the derived normal matrix for the view matrix
|
||||
void
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include "vectors.h"
|
||||
#include "doomtype.h"
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
typedef double FLOATTYPE;
|
||||
|
@ -154,7 +153,7 @@ public:
|
|||
|
||||
FVector3 axis(ax, ay, az);
|
||||
axis.MakeUnit();
|
||||
double c = cos(angle * M_PI/180.), s = sin(angle * M_PI/180.), t = 1 - c;
|
||||
double c = cos(angle * pi::pi()/180.), s = sin(angle * pi::pi()/180.), t = 1 - c;
|
||||
double sx = s*axis.X, sy = s*axis.Y, sz = s*axis.Z;
|
||||
double tx, ty, txx, tyy, u, v;
|
||||
|
||||
|
|
|
@ -37,9 +37,10 @@
|
|||
** with destructors).
|
||||
*/
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "basics.h"
|
||||
#include "memarena.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "printf.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
struct FMemArena::Block
|
||||
{
|
||||
|
|
51
src/utility/printf.h
Normal file
51
src/utility/printf.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
# define ATTRIBUTE(attrlist) __attribute__(attrlist)
|
||||
#else
|
||||
# define ATTRIBUTE(attrlist)
|
||||
#endif
|
||||
|
||||
// This header collects all things printf, so that this doesn't need to pull in other, far more dirty headers, just for outputting some text.
|
||||
|
||||
extern "C" int mysnprintf(char* buffer, size_t count, const char* format, ...) ATTRIBUTE((format(printf, 3, 4)));
|
||||
extern "C" int myvsnprintf(char* buffer, size_t count, const char* format, va_list argptr) ATTRIBUTE((format(printf, 3, 0)));
|
||||
|
||||
// game print flags
|
||||
enum
|
||||
{
|
||||
PRINT_LOW, // pickup messages
|
||||
PRINT_MEDIUM, // death messages
|
||||
PRINT_HIGH, // critical messages
|
||||
PRINT_CHAT, // chat messages
|
||||
PRINT_TEAMCHAT, // chat messages from a teammate
|
||||
PRINT_LOG, // only to logfile
|
||||
PRINT_BOLD = 200, // What Printf_Bold used
|
||||
PRINT_TYPES = 1023, // Bitmask.
|
||||
PRINT_NONOTIFY = 1024, // Flag - do not add to notify buffer
|
||||
PRINT_NOLOG = 2048, // Flag - do not print to log file
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
DMSG_OFF, // no developer messages.
|
||||
DMSG_ERROR, // general notification messages
|
||||
DMSG_WARNING, // warnings
|
||||
DMSG_NOTIFY, // general notification messages
|
||||
DMSG_SPAMMY, // for those who want to see everything, regardless of its usefulness.
|
||||
};
|
||||
|
||||
|
||||
void I_Error(const char *fmt, ...) ATTRIBUTE((format(printf,1,2)));
|
||||
void I_FatalError(const char* fmt, ...) ATTRIBUTE((format(printf, 1, 2)));
|
||||
|
||||
// This really could need some cleanup - the main problem is that it'd create
|
||||
// lots of potential for merge conflicts.
|
||||
|
||||
int PrintString (int iprintlevel, const char *outline);
|
||||
int VPrintf(int printlevel, const char* format, va_list parms);
|
||||
int Printf (int printlevel, const char *format, ...) ATTRIBUTE((format(printf,2,3)));
|
||||
int Printf (const char *format, ...) ATTRIBUTE((format(printf,1,2)));
|
||||
int DPrintf (int level, const char *format, ...) ATTRIBUTE((format(printf,2,3)));
|
||||
|
||||
void debugprintf(const char* f, ...); // Prints to the debugger's log.
|
|
@ -52,7 +52,8 @@
|
|||
// make this a local inline function to avoid any dependencies on other headers and not pollute the global namespace
|
||||
namespace pi
|
||||
{
|
||||
inline double pi() { return 3.14159265358979323846; }
|
||||
inline constexpr double pi() { return 3.14159265358979323846; }
|
||||
inline constexpr double pif() { return 3.14159265358979323846f; }
|
||||
}
|
||||
|
||||
|
||||
|
@ -1356,7 +1357,7 @@ struct TAngle
|
|||
|
||||
double Tan() const
|
||||
{
|
||||
return g_tan(Degrees * (pi::pi() / 180.));
|
||||
return vec_t(g_tan(Radians()));
|
||||
}
|
||||
|
||||
// This is for calculating vertical velocity. For high pitches the tangent will become too large to be useful.
|
||||
|
|
Loading…
Reference in a new issue