Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PlatformDefines.cpp
Go to the documentation of this file.
1
2
3
4#include "config.h"
5
8
9#include "GUI/Headers/GUI.h"
10
13
14namespace Divide
15{
16
17 namespace
18 {
20 };
21
22 namespace Assert
23 {
24
25 bool DIVIDE_ASSERT_FUNC( const bool expression, const char* expressionStr, const char* file, const int line, const char* failMessage ) noexcept
26 {
27 if constexpr ( !Config::Build::IS_SHIPPING_BUILD )
28 {
29 if ( !expression ) [[unlikely]]
30 {
31 if ( failMessage == nullptr || strlen( failMessage ) == 0 ) [[unlikely]]
32 {
33 return DIVIDE_ASSERT_FUNC( false, expressionStr, file, line, "Message truncated" );
34 }
35
36 const string msgOut = Util::StringFormat( "ASSERT [{} : {}]: {} : {}", file, line, expressionStr, failMessage );
37 if constexpr ( Config::Assert::LOG_ASSERTS )
38 {
39 Console::errorfn( msgOut.c_str() );
40 }
41
42 DIVIDE_ASSERT_MSG_BOX( msgOut.c_str() );
44
46 {
47 DebugBreak();
48 }
49 else
50 {
51 assert( expression && msgOut.c_str() );
52 }
53 }
54 }
55
56 return expression;
57 }
58 }; // namespace Assert
59
60 SysInfo& sysInfo() noexcept
61 {
62 return g_sysInfo;
63 }
64
65 const SysInfo& const_sysInfo() noexcept
66 {
67 return g_sysInfo;
68 }
69
70 ErrorCode PlatformInit( const int argc, char** argv )
71 {
72 Runtime::mainThreadID( std::this_thread::get_id() );
73 SeedRandom();
74
75 InitSysInfo( sysInfo(), argc, argv );
76 Paths::initPaths();
77 if ( Paths::g_logPath.empty() )
78 {
80 }
83 !Util::FindCommandLineArgument( argc, argv, "disableCopyright" ) );
84
85 return ErrorCode::NO_ERR;
86 }
87
89 {
92
93 return true;
94 }
95
96 void InitSysInfo( SysInfo& info, [[maybe_unused]] const I32 argc, [[maybe_unused]] char** argv )
97 {
98 if ( !GetAvailableMemory( info ) )
99 {
100 DebugBreak();
101 // Assume 256Megs as a minimum
102 info._availableRamInBytes = (1 << 8) * 1024 * 1024;
103 }
104
106 }
107
108 const char* GetClipboardText() noexcept
109 {
110 return SDL_GetClipboardText();
111 }
112
113 void SetClipboardText( const char* text ) noexcept
114 {
115 SDL_SetClipboardText( text );
116 }
117
118 void ToggleCursor( const bool state ) noexcept
119 {
120 if ( CursorState() != state )
121 {
122 SDL_ShowCursor( state ? SDL_TRUE : SDL_FALSE );
123 }
124 }
125
126 bool CursorState() noexcept
127 {
128 return SDL_ShowCursor( SDL_QUERY ) == SDL_ENABLE;
129 }
130
132 {
133 const std::time_t t = std::time( nullptr );
134 std::tm* now = std::localtime( &t );
135
136 char buffer[128];
137 strftime( buffer, sizeof( buffer ), "%d_%m_%Y__%H_%M_%S", now );
138 return buffer;
139 }
140
141}; // namespace Divide
#define NO_DESTROY
char * argv[]
Definition: main.cpp:8
constexpr char ERROR_LOG_FILE[]
Definition: config.h:209
constexpr char OUTPUT_LOG_FILE[]
Definition: config.h:208
bool DIVIDE_ASSERT_FUNC(const bool expression, const char *expressionStr, const char *file, int line, const char *failMessage) noexcept
It is safe to call evaluate expressions and call functions inside the assert check as it will compile...
constexpr bool LOG_ASSERTS
Log assert fails messages to the error log file.
Definition: config.h:73
constexpr bool CONTINUE_ON_ASSERT
Do not call the platform "assert" function in order to continue application execution.
Definition: config.h:79
constexpr bool IS_SHIPPING_BUILD
Definition: config.h:60
bool resetMainThreadID() noexcept
const std::thread::id & mainThreadID() noexcept
Str StringFormat(const char *fmt, Args &&...args)
bool FindCommandLineArgument(int argc, char **argv, const char *target_arg, const char *arg_prefix="--")
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
void SetClipboardText(const char *text) noexcept
bool CursorState() noexcept
SysInfo & sysInfo() noexcept
int32_t I32
ResourcePath getWorkingDirectory()
bool DebugBreak(const bool condition) noexcept
std::string CurrentDateTimeString()
void DIVIDE_ASSERT_MSG_BOX(const char *failMessage) noexcept
Definition: GUI.cpp:110
const char * GetClipboardText() noexcept
ErrorCode PlatformInit(int argc, char **argv)
const SysInfo & const_sysInfo() noexcept
void SeedRandom()
Definition: MathHelper.inl:101
bool PlatformClose()
bool GetAvailableMemory(SysInfo &info)
void ToggleCursor(bool state) noexcept
void InitSysInfo(SysInfo &info, I32 argc, char **argv)
static NO_INLINE void errorfn(const char *format, T &&... args)
static void Flush()
Definition: Console.cpp:126
static void Start(std::string_view logFilePath, std::string_view erroFilePath, bool printCopyright) noexcept
Definition: Console.cpp:144
static void Stop()
Definition: Console.cpp:179
ResourcePath _workingDirectory
size_t _availableRamInBytes