mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
- added some utilities to cmdlib.cpp and changed its license to BSD, because no original Quake code is left here.
This commit is contained in:
parent
3113c6b69b
commit
58afc3d5b2
14 changed files with 126 additions and 86 deletions
|
@ -41,6 +41,7 @@
|
||||||
#include "c_dispatch.h"
|
#include "c_dispatch.h"
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ bool IsFloat (const char *str);
|
||||||
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
||||||
|
|
||||||
static FProduction *ParseExpression (FCommandLine &argv, int &parsept);
|
static FProduction *ParseExpression (FCommandLine &argv, int &parsept);
|
||||||
static const char *IsNum (const char *str);
|
static const char *CIsNum (const char *str);
|
||||||
static FStringProd *NewStringProd (const char *str);
|
static FStringProd *NewStringProd (const char *str);
|
||||||
static FStringProd *NewStringProd (size_t len);
|
static FStringProd *NewStringProd (size_t len);
|
||||||
static FDoubleProd *NewDoubleProd (double val);
|
static FDoubleProd *NewDoubleProd (double val);
|
||||||
|
@ -257,13 +258,13 @@ bool IsFloat (const char *str)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pt = IsNum (str);
|
pt = CIsNum (str);
|
||||||
if (pt == NULL)
|
if (pt == NULL)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (*pt == '.')
|
if (*pt == '.')
|
||||||
{
|
{
|
||||||
pt = IsNum (pt+1);
|
pt = CIsNum (pt+1);
|
||||||
if (pt == NULL)
|
if (pt == NULL)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -272,7 +273,7 @@ bool IsFloat (const char *str)
|
||||||
pt++;
|
pt++;
|
||||||
if (*pt == '+' || *pt == '-')
|
if (*pt == '+' || *pt == '-')
|
||||||
pt++;
|
pt++;
|
||||||
pt = IsNum (pt);
|
pt = CIsNum (pt);
|
||||||
}
|
}
|
||||||
return pt != NULL && *pt == 0;
|
return pt != NULL && *pt == 0;
|
||||||
}
|
}
|
||||||
|
@ -283,7 +284,7 @@ bool IsFloat (const char *str)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static const char *IsNum (const char *str)
|
static const char *CIsNum (const char *str)
|
||||||
{
|
{
|
||||||
const char *start = str;
|
const char *start = str;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "m_joy.h"
|
#include "m_joy.h"
|
||||||
#include "gameconfigfile.h"
|
#include "gameconfigfile.h"
|
||||||
#include "d_event.h"
|
#include "d_event.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "doomdata.h"
|
#include "doomdata.h"
|
||||||
#include "r_defs.h"
|
#include "r_defs.h"
|
||||||
#include "nodebuild.h"
|
#include "nodebuild.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
|
|
||||||
struct MapData
|
struct MapData
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "doomstat.h"
|
#include "doomstat.h"
|
||||||
#include "doomdata.h"
|
#include "doomdata.h"
|
||||||
#include "m_bbox.h"
|
#include "m_bbox.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
extern int validcount;
|
extern int validcount;
|
||||||
struct FBlockNode;
|
struct FBlockNode;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
typedef uint32_t BITFIELD;
|
typedef uint32_t BITFIELD;
|
||||||
typedef int INTBOOL;
|
typedef int INTBOOL;
|
||||||
|
@ -37,12 +38,6 @@ typedef uint32_t angle_t;
|
||||||
#define GCCNOWARN
|
#define GCCNOWARN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename T, size_t N>
|
|
||||||
char(&_ArraySizeHelper(T(&array)[N]))[N];
|
|
||||||
|
|
||||||
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAKE_ID
|
#ifndef MAKE_ID
|
||||||
#ifndef __BIG_ENDIAN__
|
#ifndef __BIG_ENDIAN__
|
||||||
#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
|
#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
|
||||||
|
|
|
@ -1,26 +1,38 @@
|
||||||
//-----------------------------------------------------------------------------
|
/*
|
||||||
//
|
** cmdlib.cpp
|
||||||
// Copyright 1996 id Software
|
** Misc utilities (mostly file handling stuff)
|
||||||
// Copyright 1999-2016 Randy Heit
|
**
|
||||||
// Copyright 2002-2016 Christoph Oelckers
|
**---------------------------------------------------------------------------
|
||||||
//
|
** Copyright 1999-2016 Randy Heit
|
||||||
// This program is free software: you can redistribute it and/or modify
|
** Copyright 2019 Christoph Oelckers
|
||||||
// it under the terms of the GNU General Public License as published by
|
** All rights reserved.
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
**
|
||||||
// (at your option) any later version.
|
** Redistribution and use in source and binary forms, with or without
|
||||||
//
|
** modification, are permitted provided that the following conditions
|
||||||
// This program is distributed in the hope that it will be useful,
|
** are met:
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
**
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
** 1. Redistributions of source code must retain the above copyright
|
||||||
// GNU General Public License for more details.
|
** notice, this list of conditions and the following disclaimer.
|
||||||
//
|
** 2. Redistributions in binary form must reproduce the above copyright
|
||||||
// You should have received a copy of the GNU General Public License
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
// along with this program. If not, see http://www.gnu.org/licenses/
|
** documentation and/or other materials provided with the distribution.
|
||||||
//
|
** 3. The name of the author may not be used to endorse or promote products
|
||||||
//-----------------------------------------------------------------------------
|
** derived from this software without specific prior written permission.
|
||||||
//
|
**
|
||||||
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
// cmdlib.c (mostly borrowed from the Q2 source)
|
|
||||||
|
|
||||||
#include "cmdlib.h"
|
#include "cmdlib.h"
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
|
@ -53,7 +65,7 @@ static inline bool IsSeperator (int c)
|
||||||
{
|
{
|
||||||
if (c == '/')
|
if (c == '/')
|
||||||
return true;
|
return true;
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
if (c == '\\' || c == ':')
|
if (c == '\\' || c == ':')
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
@ -311,6 +323,33 @@ FString ExtractFileBase (const char *path, bool include_extension)
|
||||||
return FString();
|
return FString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// StripExtension
|
||||||
|
//
|
||||||
|
// Returns the path with the extension removed
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
FString StripExtension(const char* path)
|
||||||
|
{
|
||||||
|
const char* src;
|
||||||
|
if (*path == 0) return "";
|
||||||
|
|
||||||
|
src = path + strlen(path) - 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// back up until a . and abort on a \
|
||||||
|
//
|
||||||
|
while (src != path && !IsSeperator(*(src - 1)))
|
||||||
|
{
|
||||||
|
if (*src == '.') return FString(path, src - path);
|
||||||
|
src--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -928,9 +967,45 @@ bool IsAbsPath(const char *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// M_ZlibError
|
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
void NormalizeFileName(FString& str)
|
||||||
|
{
|
||||||
|
FixPathSeperator(str);
|
||||||
|
auto splits = str.Split("/");
|
||||||
|
for (unsigned i = 1; i < splits.Size(); i++)
|
||||||
|
{
|
||||||
|
if (splits[i].Compare(".") == 0)
|
||||||
|
{
|
||||||
|
splits.Delete(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (splits[i].Compare("..") == 0 && splits[i - 1].Compare("..") != 0)
|
||||||
|
{
|
||||||
|
splits.Delete(i);
|
||||||
|
splits.Delete(i - 1);
|
||||||
|
i -= 2;
|
||||||
|
if (i < 1) i = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str = splits[0];
|
||||||
|
for (unsigned i = 1; i < splits.Size(); i++)
|
||||||
|
{
|
||||||
|
str << "/" << splits[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
FString M_ZLibError(int zerr)
|
FString M_ZLibError(int zerr)
|
||||||
{
|
{
|
||||||
if (zerr >= 0)
|
if (zerr >= 0)
|
||||||
|
|
|
@ -24,6 +24,10 @@ typedef struct _GUID
|
||||||
} GUID;
|
} GUID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template <typename T, size_t N>
|
||||||
|
char(&_ArraySizeHelper(T(&array)[N]))[N];
|
||||||
|
|
||||||
|
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
|
||||||
|
|
||||||
// the dec offsetof macro doesnt work very well...
|
// the dec offsetof macro doesnt work very well...
|
||||||
#define myoffsetof(type,identifier) ((size_t)&((type *)alignof(type))->identifier - alignof(type))
|
#define myoffsetof(type,identifier) ((size_t)&((type *)alignof(type))->identifier - alignof(type))
|
||||||
|
@ -39,9 +43,11 @@ void FixPathSeperator (char *path);
|
||||||
static void inline FixPathSeperator (FString &path) { path.ReplaceChars('\\', '/'); }
|
static void inline FixPathSeperator (FString &path) { path.ReplaceChars('\\', '/'); }
|
||||||
|
|
||||||
void DefaultExtension (FString &path, const char *extension);
|
void DefaultExtension (FString &path, const char *extension);
|
||||||
|
void NormalizeFileName(FString &str);
|
||||||
|
|
||||||
FString ExtractFilePath (const char *path);
|
FString ExtractFilePath (const char *path);
|
||||||
FString ExtractFileBase (const char *path, bool keep_extension=false);
|
FString ExtractFileBase (const char *path, bool keep_extension=false);
|
||||||
|
FString StripExtension(const char* path);
|
||||||
|
|
||||||
struct FScriptPosition;
|
struct FScriptPosition;
|
||||||
bool IsNum (const char *str); // [RH] added
|
bool IsNum (const char *str); // [RH] added
|
||||||
|
@ -71,8 +77,11 @@ struct FFileList
|
||||||
|
|
||||||
bool ScanDirectory(TArray<FFileList> &list, const char *dirpath);
|
bool ScanDirectory(TArray<FFileList> &list, const char *dirpath);
|
||||||
bool IsAbsPath(const char*);
|
bool IsAbsPath(const char*);
|
||||||
|
|
||||||
FString M_ZLibError(int zerrnum);
|
FString M_ZLibError(int zerrnum);
|
||||||
|
|
||||||
|
inline int32_t Scale(int32_t a, int32_t b, int32_t c)
|
||||||
|
{
|
||||||
|
return (int32_t)(((int64_t)a * b) / c);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,53 +4,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
|
|
||||||
// Unfortunately, the Scale function still gets badly handled on 32 bit x86 platforms so it's the last remaining piece of inline assembly
|
|
||||||
|
|
||||||
// GCC inlines
|
|
||||||
#if defined(__GNUC__) && defined(__i386__) && !defined(__clang__) && !defined(__PIC__)
|
|
||||||
#ifndef alloca
|
|
||||||
// MinGW does not seem to come with alloca defined.
|
|
||||||
#define alloca __builtin_alloca
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int32_t Scale(int32_t a, int32_t b, int32_t c)
|
|
||||||
{
|
|
||||||
int32_t result, dummy;
|
|
||||||
|
|
||||||
asm volatile
|
|
||||||
("imull %3\n\t"
|
|
||||||
"idivl %4"
|
|
||||||
: "=a,a,a,a,a,a" (result),
|
|
||||||
"=&d,&d,&d,&d,d,d" (dummy)
|
|
||||||
: "a,a,a,a,a,a" (a),
|
|
||||||
"m,r,m,r,d,d" (b),
|
|
||||||
"r,r,m,m,r,m" (c)
|
|
||||||
: "cc"
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// MSVC inlines
|
|
||||||
#elif defined(_MSC_VER) && defined(_M_IX86)
|
|
||||||
#pragma warning (disable: 4035)
|
|
||||||
|
|
||||||
__forceinline int32_t Scale(int32_t a, int32_t b, int32_t c)
|
|
||||||
{
|
|
||||||
__asm mov eax, a
|
|
||||||
__asm imul b
|
|
||||||
__asm idiv c
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma warning (default: 4035)
|
|
||||||
#else
|
|
||||||
|
|
||||||
static __forceinline int32_t Scale(int32_t a, int32_t b, int32_t c)
|
|
||||||
{
|
|
||||||
return (int32_t)(((int64_t)a*b) / c);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Modern compilers are smart enough to do these multiplications intelligently.
|
// Modern compilers are smart enough to do these multiplications intelligently.
|
||||||
__forceinline int32_t MulScale14(int32_t a, int32_t b) { return (int32_t)(((int64_t)a * b) >> 14); } // only used by R_DrawVoxel
|
__forceinline int32_t MulScale14(int32_t a, int32_t b) { return (int32_t)(((int64_t)a * b) >> 14); } // only used by R_DrawVoxel
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "m_swap.h"
|
#include "m_swap.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "gameconfigfile.h"
|
#include "gameconfigfile.h"
|
||||||
#include "m_argv.h"
|
#include "m_argv.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
|
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
#include "doomerrors.h"
|
#include "doomerrors.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "m_misc.h"
|
#include "m_misc.h"
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "gameconfigfile.h"
|
#include "gameconfigfile.h"
|
||||||
#include "m_argv.h"
|
#include "m_argv.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -434,9 +435,7 @@ void FXInputController::SetDefaultConfig()
|
||||||
|
|
||||||
FString FXInputController::GetIdentifier()
|
FString FXInputController::GetIdentifier()
|
||||||
{
|
{
|
||||||
char id[16];
|
return FStringf("XI:%d", Index);
|
||||||
mysnprintf(id, countof(id), "XI:%d", Index);
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
#include "st_start.h"
|
#include "st_start.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
#include "i_input.h"
|
#include "i_input.h"
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "m_argv.h"
|
#include "m_argv.h"
|
||||||
#include "doomerrors.h"
|
#include "doomerrors.h"
|
||||||
#include "win32basevideo.h"
|
#include "win32basevideo.h"
|
||||||
|
#include "cmdlib.h"
|
||||||
|
|
||||||
#include "gl/system/gl_framebuffer.h"
|
#include "gl/system/gl_framebuffer.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue