Skip to content

Commit

Permalink
xrCore refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
imdex committed May 6, 2017
1 parent d230dd1 commit 1d8d255
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 107 deletions.
4 changes: 2 additions & 2 deletions code/engine/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,9 @@ void CLocatorAPI::_initialize (u32 flags, LPCSTR target_folder, LPCSTR fs_name)
CTimer t;
t.Start();
Log ("Initializing File System...");
u32 M1 = Memory.mem_usage();
auto M1 = Memory.mem_usage();

m_Flags.set (flags,TRUE);
m_Flags.set (flags,true);

// scan root directory
bNoRecurse = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion code/engine/xrCore/LocatorAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class XRCORE_API CLocatorAPI

files_it file_find_it (LPCSTR n);
public:
enum{
enum : u32 {
flNeedRescan = (1<<0),
flBuildCopy = (1<<1),
flReady = (1<<2),
Expand Down
9 changes: 4 additions & 5 deletions code/engine/xrCore/_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

template <class T>
struct _flags {
public:
typedef T TYPE;
typedef _flags<T> Self;
typedef Self& SelfRef;
typedef const Self& SelfCRef;
public:

T flags;

IC TYPE get () const { return flags;}
Expand All @@ -20,9 +19,9 @@ struct _flags {
IC SelfRef assign (const Self& f) { flags = f.flags; return *this; }
IC SelfRef assign (const T mask) { flags = mask; return *this; }
IC SelfRef set (const T mask, BOOL value) { if (value) flags|=mask; else flags&=~mask; return *this; }
IC BOOL is (const T mask) const { return mask==(flags&mask); }
IC BOOL is_any (const T mask) const { return BOOL(!!(flags&mask)); }
IC BOOL test (const T mask) const { return BOOL(!!(flags&mask)); }
IC bool is (const T mask) const { return mask==(flags&mask); }
IC bool is_any (const T mask) const { return (flags&mask) != 0; }
IC bool test (const T mask) const { return (flags&mask) != 0; }
IC SelfRef or (const T mask) { flags|=mask; return *this; }
IC SelfRef or (const Self& f, const T mask) { flags=f.flags|mask; return *this; }
IC SelfRef and (const T mask) { flags&=mask; return *this; }
Expand Down
13 changes: 0 additions & 13 deletions code/engine/xrCore/_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,6 @@ void _initialize_cpu (void)
u32(CPU::clk_overhead)
);

// DUMP_PHASE;

if (strstr(Core.Params,"-x86")) {
CPU::ID.hasFeature(CpuFeature::Mmx);
CPU::ID.hasFeature(CpuFeature::_3dNow);
CPU::ID.hasFeature(CpuFeature::Sse);
CPU::ID.hasFeature(CpuFeature::Sse2);
CPU::ID.hasFeature(CpuFeature::Sse3);
CPU::ID.hasFeature(CpuFeature::Ssse3);
CPU::ID.hasFeature(CpuFeature::Sse41);
CPU::ID.hasFeature(CpuFeature::Sse42);
};

string256 features; xr_strcpy(features,sizeof(features),"RDTSC");
if (CPU::ID.hasFeature(CpuFeature::Mmx)) xr_strcat(features,", MMX");
if (CPU::ID.hasFeature(CpuFeature::_3dNow)) xr_strcat(features,", 3DNow!");
Expand Down
22 changes: 11 additions & 11 deletions code/engine/xrCore/xrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern char g_application_path[256];

//. extern xr_vector<shared_str>* LogFile;

void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs, LPCSTR fs_fname)
void xrCore::_initialize(const char* _ApplicationName, LogCallback cb, bool init_fs, const char* fs_fname)
{
xr_strcpy (ApplicationName,_ApplicationName);
if (0==init_counter) {
Expand All @@ -39,7 +39,7 @@ void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,
// Init COM so we can use CoCreateInstance
// HRESULT co_res =
if (!strstr(GetCommandLine(),"-editor"))
CoInitializeEx (NULL, COINIT_MULTITHREADED);
CoInitializeEx (nullptr, COINIT_MULTITHREADED);

xr_strcpy (Params,sizeof(Params),GetCommandLine());
_strlwr_s (Params,sizeof(Params));
Expand All @@ -48,7 +48,7 @@ void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,

// application path
GetModuleFileName(GetModuleHandle(MODULE_NAME),fn,sizeof(fn));
_splitpath (fn,dr,di,0,0);
_splitpath (fn,dr,di,nullptr,nullptr);
strconcat (sizeof(ApplicationPath),ApplicationPath,dr,di);
#ifndef _EDITOR
xr_strcpy (g_application_path,sizeof(g_application_path),ApplicationPath);
Expand All @@ -67,14 +67,14 @@ void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,
GetCurrentDirectory(sizeof(WorkingPath),WorkingPath);

// User/Comp Name
DWORD sz_user = sizeof(UserName);
GetUserName (UserName,&sz_user);
DWORD sz_user = sizeof(UserName);
GetUserName(UserName, &sz_user);

DWORD sz_comp = sizeof(CompName);
GetComputerName (CompName,&sz_comp);

// Mathematics & PSI detection
CPU::Detect ();
CPU::Detect();

Memory._initialize (strstr(Params,"-mem_debug") ? TRUE : FALSE);

Expand All @@ -93,9 +93,9 @@ void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,
//. R_ASSERT (co_res==S_OK);
}
if (init_fs){
u32 flags = 0;
if (0!=strstr(Params,"-build")) flags |= CLocatorAPI::flBuildCopy;
if (0!=strstr(Params,"-ebuild")) flags |= CLocatorAPI::flBuildCopy|CLocatorAPI::flEBuildCopy;
u32 flags = 0u;
if (nullptr!=strstr(Params,"-build")) flags |= CLocatorAPI::flBuildCopy;
if (nullptr!=strstr(Params,"-ebuild")) flags |= CLocatorAPI::flBuildCopy|CLocatorAPI::flEBuildCopy;
#ifdef DEBUG
if (strstr(Params,"-cache")) flags |= CLocatorAPI::flCacheFiles;
else flags &= ~CLocatorAPI::flCacheFiles;
Expand All @@ -107,10 +107,10 @@ void xrCore::_initialize (LPCSTR _ApplicationName, LogCallback cb, BOOL init_fs,

#ifndef _EDITOR
#ifndef ELocatorAPIH
if (0!=strstr(Params,"-file_activity")) flags |= CLocatorAPI::flDumpFileActivity;
if (nullptr!=strstr(Params,"-file_activity")) flags |= CLocatorAPI::flDumpFileActivity;
#endif
#endif
FS._initialize (flags,0,fs_fname);
FS._initialize (flags,nullptr,fs_fname);
Msg ("'%s' build %d, %s\n","xrCore",build_id, build_date);
EFS._initialize ();
#ifdef DEBUG
Expand Down
73 changes: 12 additions & 61 deletions code/engine/xrCore/xrCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,14 @@
#error Please enable multi-threaded library...
#endif

# include "xrCore_platform.h"

// *** try to minimize code bloat of STLport
#ifdef __BORLANDC__
#else
#ifdef XRCORE_EXPORTS // no exceptions, export allocator and common stuff
#define _STLP_DESIGNATED_DLL 1
#define _STLP_USE_DECLSPEC 1
#else
#define _STLP_USE_DECLSPEC 1 // no exceptions, import allocator and common stuff
#endif
#endif

// #include <exception>
// using std::exception;
#include "xrCore_platform.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <string.h>
#include <typeinfo.h>
//#include <process.h>

#ifndef DEBUG
#ifdef _DEBUG
Expand Down Expand Up @@ -118,48 +103,14 @@
#endif

#ifndef DEBUG
#pragma inline_depth ( 254 )
#pragma inline_recursion( on )
#ifndef __BORLANDC__
#pragma intrinsic (abs, fabs, fmod, sin, cos, tan, asin, acos, atan, sqrt, exp, log, log10, strcat)
#endif
#pragma inline_depth ( 254 )
#pragma inline_recursion( on )
#pragma intrinsic (abs, fabs, fmod, sin, cos, tan, asin, acos, atan, sqrt, exp, log, log10, strcat)
#endif

#include <time.h>
// work-around dumb borland compiler
#ifdef __BORLANDC__
#define ALIGN(a)

#include <assert.h>
#include <utime.h>
#define _utimbuf utimbuf
#define MODULE_NAME "xrCoreB.dll"

// function redefinition
#define fabsf(a) fabs(a)
#define sinf(a) sin(a)
#define asinf(a) asin(a)
#define cosf(a) cos(a)
#define acosf(a) acos(a)
#define tanf(a) tan(a)
#define atanf(a) atan(a)
#define sqrtf(a) sqrt(a)
#define expf(a) ::exp(a)
#define floorf floor
#define atan2f atan2
#define logf log
// float redefine
#define _PC_24 PC_24
#define _PC_53 PC_53
#define _PC_64 PC_64
#define _RC_CHOP RC_CHOP
#define _RC_NEAR RC_NEAR
#define _MCW_EM MCW_EM
#else
#define ALIGN(a) __declspec(align(a))
#include <sys\utime.h>
#define MODULE_NAME "xrCore.dll"
#endif
#include <sys\utime.h>
#define MODULE_NAME "xrCore.dll"


// Warnings
Expand Down Expand Up @@ -230,10 +181,10 @@
struct XRCORE_API xr_rtoken{
shared_str name;
int id;
xr_rtoken (LPCSTR _nm, int _id){name=_nm;id=_id;}
xr_rtoken (const char* _nm, int _id){name=_nm;id=_id;}
public:
void rename (LPCSTR _nm) {name=_nm;}
bool equal (LPCSTR _nm) {return (0==xr_strcmp(*name,_nm));}
void rename (const char* _nm) {name=_nm;}
bool equal (const char* _nm) {return (0==xr_strcmp(*name,_nm));}
};

#pragma pack (push,1)
Expand All @@ -250,7 +201,7 @@ struct XRCORE_API xr_shortcut{
};
u16 hotkey;
};
xr_shortcut (u8 k, BOOL a, BOOL c, BOOL s):key(k){ext.assign(u8((a?flAlt:0)|(c?flCtrl:0)|(s?flShift:0)));}
xr_shortcut (u8 k, bool a, bool c, bool s):key(k){ext.assign(u8((a?flAlt:0)|(c?flCtrl:0)|(s?flShift:0)));}
xr_shortcut (){ext.zero();key=0;}
bool similar (const xr_shortcut& v)const{return ext.equal(v.ext)&&(key==v.key);}
};
Expand All @@ -260,7 +211,7 @@ using RStringVec = xr_vector<shared_str>;
using RStringSet = xr_set<shared_str>;
using RTokenVec = xr_vector<xr_rtoken>;

#define xr_pure_interface __interface
#define xr_pure_interface __interface

#include "FS.h"
#include "log.h"
Expand Down Expand Up @@ -303,7 +254,7 @@ class XRCORE_API xrCore
DWORD dwFrame;

public:
void _initialize (LPCSTR ApplicationName, LogCallback cb=0, BOOL init_fs=TRUE, LPCSTR fs_fname=0);
void _initialize (const char* ApplicationName, LogCallback cb= nullptr, bool init_fs=true, const char* fs_fname=nullptr);
void _destroy ();
};

Expand Down
10 changes: 1 addition & 9 deletions code/engine/xrCore/xrCore_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
# define _WIN32_WINNT 0x0600
#endif

#ifdef __BORLANDC__
#include <vcl.h>
#include <mmsystem.h>
#include <stdint.h>
#endif

#define NOGDICAPMASKS
//#define NOSYSMETRICS
#define NOMENUS
Expand All @@ -44,9 +38,7 @@
#pragma warning(push)
#pragma warning(disable:4005)
#include <windows.h>
#ifndef __BORLANDC__
#include <windowsx.h>
#endif
#include <windowsx.h>
#pragma warning(pop)

#endif
2 changes: 1 addition & 1 deletion code/engine/xrRenderCommon/R_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ECORE_API CBackend
u32 vb_stride;

// Pixel/Vertex constants
ALIGN(16) R_constants constants;
alignas(16) R_constants constants;
R_constant_table* ctable;

// Shaders/State
Expand Down
8 changes: 4 additions & 4 deletions code/engine/xrRenderDX9/dx9r_constants_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ template <class T, u32 limit>
class R_constant_cache
{
private:
ALIGN(16) svector<T,limit> array;
alignas(16) svector<T,limit> array;
u32 lo,hi;
public:
R_constant_cache()
Expand All @@ -28,7 +28,7 @@ class R_constant_array
typedef R_constant_cache<Ivector4,16> t_i;
typedef R_constant_cache<BOOL,16> t_b;
public:
ALIGN(16) t_f c_f;
alignas(16) t_f c_f;
// ALIGN(16) t_i c_i;
// ALIGN(16) t_b c_b;
BOOL b_dirty;
Expand Down Expand Up @@ -131,8 +131,8 @@ class R_constant_array
class ECORE_API R_constants
{
public:
ALIGN(16) R_constant_array a_pixel;
ALIGN(16) R_constant_array a_vertex;
alignas(16) R_constant_array a_pixel;
alignas(16) R_constant_array a_vertex;

void flush_cache ();
public:
Expand Down

0 comments on commit 1d8d255

Please sign in to comment.