Skip to content

Commit

Permalink
more docimentation, add offsets back to console for now, more constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeCrazyGuy committed Jun 16, 2024
1 parent c0b258c commit 607590b
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 79 deletions.
351 changes: 304 additions & 47 deletions betterapi.h

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,15 @@ extern void setup_console(const BetterAPI* api) {
}


extern const struct console_api_t* GetConsoleAPI() {
static const struct console_api_t Console {
[](char* command) noexcept -> void {
console_run(NULL, command);
}
};
static void run_comand(char* command) {
console_run(NULL, command);
}


static constexpr struct console_api_t Console {
run_comand
};

extern constexpr const struct console_api_t* GetConsoleAPI() {
return &Console;
}
2 changes: 1 addition & 1 deletion src/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
extern void setup_console(const BetterAPI* api);

// but I still need to send out the console api to other components
extern const struct console_api_t* GetConsoleAPI();
extern constexpr const struct console_api_t* GetConsoleAPI();
17 changes: 4 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "broadcast_api.h"
#include "std_api.h"
#include "hotkeys.h"
#include "std_api.h"

#include "d3d11on12ui.h"

Expand Down Expand Up @@ -73,16 +74,6 @@ extern char* GetPathInDllDir(char* path_max_buffer, const char* filename) {
}


const char* const filename_only(const char* path) {
const char* p = path;
while (*path) {
if (*path == '\\') p = path;
++path;
}
return ++p;
}


#ifdef MODMENU_DEBUG
#include <mutex>
std::mutex logging_mutex;
Expand All @@ -106,7 +97,7 @@ static void write_log(const char* const str) noexcept {
logging_mutex.unlock();
}
extern void DebugImpl(const char* const filename, const char* const func, int line, const char* const fmt, ...) noexcept {
auto bytes = snprintf(format_buffer, buffer_size, "%s:%s:%d>", filename_only(filename), func, line);
auto bytes = snprintf(format_buffer, buffer_size, "%s:%s:%d>", filename, func, line);
ASSERT(bytes > 0);
ASSERT(bytes < buffer_size);

Expand All @@ -132,7 +123,7 @@ extern void AssertImpl [[noreturn]] (const char* const filename, const char* con
"In function '%s'\n"
"On line '%d'\n"
"Message: '%s'",
filename_only(filename),
filename,
func,
line,
text
Expand All @@ -146,7 +137,7 @@ extern void AssertImpl [[noreturn]] (const char* const filename, const char* con
extern void TraceImpl(const char* const filename, const char* const func, int line, const char* const fmt, ...) noexcept {
static bool init = false;
static char tracebuff[2048];
const auto bytes = snprintf(tracebuff, sizeof(tracebuff), "%s:%s:%d> ", filename_only(filename), func, line);
const auto bytes = snprintf(tracebuff, sizeof(tracebuff), "%s:%s:%d> ", filename, func, line);
ASSERT(bytes > 0 && "trace buffer too small ?");
va_list args;
va_start(args, fmt);
Expand Down
23 changes: 20 additions & 3 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,29 @@
#endif // !MODMENU_DEBUG

#ifdef MODMENU_DEBUG

constexpr const char* next_slash(const char* const path) {
return (!path)
? nullptr
: (*path == '/' || *path == '\\')
? path
: (*path == 0)
? nullptr
: next_slash(path + 1);
}

constexpr const char* filename_only(const char* const path) {
return (next_slash(path))
? filename_only(next_slash(path + 1))
: path;
}

extern void DebugImpl(const char* const filename, const char* const func, int line, const char* const fmt, ...) noexcept;
extern void AssertImpl(const char* const filename, const char* const func, int line, const char* const text) noexcept;
extern void TraceImpl(const char* const filename, const char* const func, int line, const char* const fmt, ...) noexcept;
#define DEBUG(...) do { DebugImpl(__FILE__, __func__, __LINE__, " " __VA_ARGS__); } while(0)
#define ASSERT(CONDITION) do { if (!(CONDITION)) { AssertImpl(__FILE__, __func__, __LINE__, " " #CONDITION); } } while(0)
#define TRACE(...) do { TraceImpl(__FILE__, __func__, __LINE__, " " __VA_ARGS__); } while(0)
#define DEBUG(...) do { DebugImpl(filename_only(__FILE__), __func__, __LINE__, " " __VA_ARGS__); } while(0)
#define ASSERT(CONDITION) do { if (!(CONDITION)) { AssertImpl(filename_only(__FILE__), __func__, __LINE__, " " #CONDITION); } } while(0)
#define TRACE(...) do { TraceImpl(filename_only(__FILE__), __func__, __LINE__, " " __VA_ARGS__); } while(0)
#define IMGUI_DEBUG_PARANOID
#else
#define DEBUG(...) do { } while(0)
Expand Down
17 changes: 9 additions & 8 deletions src/std_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#include <stdio.h>


extern const struct std_api_t* GetStdAPI() {
static const struct std_api_t api {
&malloc,
&free,
&snprintf,
&memcpy,
&memset
};
static constexpr struct std_api_t api {
&malloc,
&free,
&snprintf,
&memcpy,
&memset
};

extern constexpr const struct std_api_t* GetStdAPI() {
return &api;
}
2 changes: 1 addition & 1 deletion src/std_api.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#include "../betterapi.h"
extern const struct std_api_t* GetStdAPI();
extern constexpr const struct std_api_t* GetStdAPI();

0 comments on commit 607590b

Please sign in to comment.