Skip to content

Commit

Permalink
refactor: refactor theses
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jan 23, 2025
1 parent 1a72a11 commit d09661d
Show file tree
Hide file tree
Showing 45 changed files with 288 additions and 1,498 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
xmake repo -u
- run: |
xmake f -a x64 -m ${{ matrix.mode }} -p windows -v -y
xmake f -a x64 -m ${{ matrix.mode }} -p windows -v -y --publish=y
- run: |
xmake -v -y
Expand Down
56 changes: 28 additions & 28 deletions src-client/ll/core/gui/ImGuiAnsiColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static constexpr uint colors256[] = {
0xffd0d0d0, 0xffdadada, 0xffe4e4e4, 0xffeeeeee
};

bool parseColor(const char* s, ImU32* col, int* skipChars) {
bool parseColor(char const* s, ImU32* col, int* skipChars) {
if (s[0] != '\033' || s[1] != '[') {
return false;
}
Expand All @@ -60,7 +60,7 @@ bool parseColor(const char* s, ImU32* col, int* skipChars) {
return true;
}

const char* seqEnd = &s[2];
char const* seqEnd = &s[2];
while (*seqEnd != 'm') {
seqEnd++;
}
Expand All @@ -69,7 +69,7 @@ bool parseColor(const char* s, ImU32* col, int* skipChars) {
std::string colorStr;
char colorArgsType = 0;
std::vector<std::string_view> colorArgs;
for (const auto& el : string_utils::splitByPattern(seq, ";")) {
for (auto const& el : string_utils::splitByPattern(seq, ";")) {
if (colorStr.empty()) {
if (el.size() == 2 && el[0] == '3') { // 30-39
colorStr = el;
Expand Down Expand Up @@ -133,14 +133,14 @@ bool parseColor(const char* s, ImU32* col, int* skipChars) {
}

void ImFont_RenderAnsiText(
const ImFont* font,
ImFont const* font,
ImDrawList* draw_list,
float size,
ImVec2 pos,
ImU32 col,
const ImVec4& clip_rect,
const char* text_begin,
const char* text_end,
ImVec4 const& clip_rect,
char const* text_begin,
char const* text_end,
float wrap_width = 0.0f,
bool cpu_fine_clip = false
) {
Expand All @@ -159,13 +159,13 @@ void ImFont_RenderAnsiText(
const float scale = size / font->FontSize;
const float line_height = font->FontSize * scale;
const bool word_wrap_enabled = (wrap_width > 0.0f);
const char* word_wrap_eol = nullptr;
char const* word_wrap_eol = nullptr;

// Fast-forward to first visible line
const char* s = text_begin;
char const* s = text_begin;
if (y + line_height < clip_rect.y && !word_wrap_enabled)
while (y + line_height < clip_rect.y && s < text_end) {
s = (const char*)memchr(s, '\n', text_end - s);
s = (char const*)memchr(s, '\n', text_end - s);
s = s ? s + 1 : text_end;
y += line_height;
}
Expand All @@ -174,10 +174,10 @@ void ImFont_RenderAnsiText(
// Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer
// without a newline will likely crash atm)
if (text_end - s > 10000 && !word_wrap_enabled) {
const char* s_end = s;
char const* s_end = s;
float y_end = y;
while (y_end < clip_rect.w && s_end < text_end) {
s_end = (const char*)memchr(s_end, '\n', text_end - s_end);
s_end = (char const*)memchr(s_end, '\n', text_end - s_end);
s = s ? s + 1 : text_end;
y_end += line_height;
}
Expand All @@ -200,7 +200,7 @@ void ImFont_RenderAnsiText(
{
int index = 0;
int skipChars = 0;
const char* sLocal = s;
char const* sLocal = s;
ImU32 temp_col = col;
while (sLocal < text_end) {
if (sLocal <= text_end - 4 && parseColor(sLocal, &temp_col, &skipChars)) {
Expand All @@ -219,7 +219,7 @@ void ImFont_RenderAnsiText(
}


const char* s1 = s;
char const* s1 = s;
while (s < text_end) {
if (char_skip[s - s1]) {
s++;
Expand Down Expand Up @@ -278,7 +278,7 @@ void ImFont_RenderAnsiText(
}

float char_width = 0.0f;
if (const ImFontGlyph* glyph = font->FindGlyph((ImWchar)c)) {
if (ImFontGlyph const* glyph = font->FindGlyph((ImWchar)c)) {
char_width = glyph->AdvanceX * scale;

// Arbitrarily assume that both space and tabs are empty glyphs as an optimization
Expand Down Expand Up @@ -373,14 +373,14 @@ void ImFont_RenderAnsiText(

void ImDrawList_AddAnsiText(
ImDrawList* drawList,
const ImFont* font,
ImFont const* font,
float font_size,
const ImVec2& pos,
ImVec2 const& pos,
ImU32 col,
const char* text_begin,
const char* text_end = nullptr,
char const* text_begin,
char const* text_end = nullptr,
float wrap_width = 0.0f,
const ImVec4* cpu_fine_clip_rect = nullptr
ImVec4 const* cpu_fine_clip_rect = nullptr
) {
if ((col & IM_COL32_A_MASK) == 0) return;

Expand Down Expand Up @@ -417,12 +417,12 @@ void ImDrawList_AddAnsiText(
);
}

void RenderAnsiText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash) {
void RenderAnsiText(ImVec2 pos, char const* text, char const* text_end, bool hide_text_after_hash) {
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;

// Hide anything after a '##' string
const char* text_display_end;
char const* text_display_end;
if (hide_text_after_hash) {
text_display_end = FindRenderedTextEnd(text, text_end);
} else {
Expand All @@ -443,7 +443,7 @@ void RenderAnsiText(ImVec2 pos, const char* text, const char* text_end, bool hid
}
}

void RenderAnsiTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width) {
void RenderAnsiTextWrapped(ImVec2 pos, char const* text, char const* text_end, float wrap_width) {
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;

Expand All @@ -470,7 +470,7 @@ void textAnsiUnformatted(std::string_view view) {

ImGuiContext& g = *GImGui;
IM_ASSERT(text != nullptr);
const char* text_begin = text;
char const* text_begin = text;

const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
const float wrap_pos_x = window->DC.TextWrapPos;
Expand All @@ -484,7 +484,7 @@ void textAnsiUnformatted(std::string_view view) {
// because we are likely the biggest and only item on the line.
// - We use memchr(), pay attention that well optimized versions of those str/mem functions are much faster
// than a casually written loop.
const char* line = text;
char const* line = text;
const float line_height = GetTextLineHeight();
const ImRect clip_rect = window->ClipRect;
ImVec2 text_size(0, 0);
Expand All @@ -498,7 +498,7 @@ void textAnsiUnformatted(std::string_view view) {
if (lines_skippable > 0) {
int lines_skipped = 0;
while (line < text_end && lines_skipped < lines_skippable) {
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
char const* line_end = (char const*)memchr(line, '\n', text_end - line);
if (!line_end) line_end = text_end;
line = line_end + 1;
lines_skipped++;
Expand All @@ -513,7 +513,7 @@ void textAnsiUnformatted(std::string_view view) {
while (line < text_end) {
if (IsClippedEx(line_rect, 0)) break;

const char* line_end = (const char*)memchr(line, '\n', text_end - line);
char const* line_end = (char const*)memchr(line, '\n', text_end - line);
if (!line_end) line_end = text_end;
const ImVec2 line_size = CalcTextSize(line, line_end, false);
text_size.x = ImMax(text_size.x, line_size.x);
Expand All @@ -527,7 +527,7 @@ void textAnsiUnformatted(std::string_view view) {
// Count remaining lines
int lines_skipped = 0;
while (line < text_end) {
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
char const* line_end = (char const*)memchr(line, '\n', text_end - line);
if (!line_end) line_end = text_end;
line = line_end + 1;
lines_skipped++;
Expand Down
4 changes: 2 additions & 2 deletions src-client/ll/core/gui/ImGuiHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace ll::gui {
void init();
const std::string& getGPUName();
const std::string& getRendererType();
std::string const& getGPUName();
std::string const& getRendererType();
} // namespace ll::gui
16 changes: 8 additions & 8 deletions src-client/ll/core/gui/win/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class LogWindow {
bool autoScroll = true;

public:
LogWindow(const std::string& title) : title(title) { clear(); }
LogWindow(std::string const& title) : title(title) { clear(); }

void clear() {
buf.clear();
lineOffsets.clear();
lineOffsets.push_back(0);
}

void addLog(const std::string& log) {
void addLog(std::string const& log) {
if (log.empty()) {
return;
}
Expand Down Expand Up @@ -80,14 +80,14 @@ class LogWindow {
ImGui::LogToClipboard();
}
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
const char* bufBegin = this->buf.begin();
const char* bufEnd = this->buf.end();
char const* bufBegin = this->buf.begin();
char const* bufEnd = this->buf.end();
if (filter.IsActive()) {
// Don't use the clipper when Filter is enabled because we don't have random access
// to the result of the filter
for (int lineNum = 0; lineNum < lineOffsets.size(); lineNum++) {
const char* lineStart = bufBegin + lineOffsets[lineNum];
const char* lineEnd =
char const* lineStart = bufBegin + lineOffsets[lineNum];
char const* lineEnd =
(lineNum + 1 < lineOffsets.size()) ? (bufBegin + lineOffsets[lineNum + 1] - 1) : bufEnd;
if (filter.PassFilter(lineStart, lineEnd)) {
textAnsiUnformatted({lineStart, lineEnd});
Expand All @@ -99,8 +99,8 @@ class LogWindow {
clipper.Begin((int)lineOffsets.size());
while (clipper.Step()) {
for (int lineNum = clipper.DisplayStart; lineNum < clipper.DisplayEnd; lineNum++) {
const char* lineStart = bufBegin + lineOffsets[lineNum];
const char* lineEnd =
char const* lineStart = bufBegin + lineOffsets[lineNum];
char const* lineEnd =
(lineNum + 1 < lineOffsets.size()) ? (bufBegin + lineOffsets[lineNum + 1] - 1) : bufEnd;
textAnsiUnformatted({lineStart, lineEnd});
}
Expand Down
8 changes: 4 additions & 4 deletions src-client/ll/core/gui/win/ImGuiHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef HRESULT(STDMETHODCALLTYPE* PFN_IDXGIFactory2_CreateSwapChainForCoreWindo
/* [annotation][in] */
_In_ IUnknown* pWindow,
/* [annotation][in] */
_In_ const DXGI_SWAP_CHAIN_DESC1* pDesc,
_In_ DXGI_SWAP_CHAIN_DESC1 const* pDesc,
/* [annotation][in] */
_In_opt_ IDXGIOutput* pRestrictToOutput,
/* [annotation][out] */
Expand Down Expand Up @@ -70,9 +70,9 @@ static uint64_t gpuVideoMemory;
static uint32_t gpuVendorID;
static uint32_t gpuDeviceID;

const std::string& getGPUName() { return gpuName; }
std::string const& getGPUName() { return gpuName; }

const std::string& getRendererType() { return rendererType; }
std::string const& getRendererType() { return rendererType; }

static void replaceVtable(void* vptr, size_t index, void** outOldFunc, void* newFunc) {
void** ptr = (void**)vptr;
Expand Down Expand Up @@ -394,7 +394,7 @@ HRESULT STDMETHODCALLTYPE IDXGIFactory2_CreateSwapChainForC
IDXGIFactory2* This,
IUnknown* pDevice,
IUnknown* pWindow,
const DXGI_SWAP_CHAIN_DESC1* pDesc,
DXGI_SWAP_CHAIN_DESC1 const* pDesc,
IDXGIOutput* pRestrictToOutput,
IDXGISwapChain1** ppSwapChain
) {
Expand Down
2 changes: 1 addition & 1 deletion src-server/ll/api/form/CustomForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class CustomForm::CustomFormImpl : public FormImpl {

void setTitle(std::string const& title) { mTitle = title; }

void append(const std::shared_ptr<CustomFormElement>& element) { mElements.push_back(element); }
void append(std::shared_ptr<CustomFormElement> const& element) { mElements.push_back(element); }

void sendTo(Player& player, Callback callback) {
uint id = handler::addFormHandler(std::make_unique<handler::CustomFormHandler>(std::move(callback), mElements));
Expand Down
6 changes: 3 additions & 3 deletions src-server/ll/core/form/FormHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
namespace ll::form::handler {


nlohmann::ordered_json jsonCppValueToNlohmannOrderedJson(const Json::Value& value) {
nlohmann::ordered_json jsonCppValueToNlohmannOrderedJson(Json::Value const& value) {
if (value.isObject()) {
nlohmann::ordered_json result = nlohmann::ordered_json::object();
for (const auto& key : value.getMemberNames()) {
for (auto const& key : value.getMemberNames()) {
result[key] = jsonCppValueToNlohmannOrderedJson(value[key]);
}
return result;
} else if (value.isArray()) {
nlohmann::ordered_json result = nlohmann::ordered_json::array();
for (const auto& item : value) {
for (auto const& item : value) {
result.push_back(jsonCppValueToNlohmannOrderedJson(item));
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion src-test/server/FormTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void registerFormTestCommand() {
return;
}
for (auto [name, result] : *data) {
static auto logDebugResult = [&](const ll::form::CustomFormElementResult& var) {
static auto logDebugResult = [&](ll::form::CustomFormElementResult const& var) {
if (std::holds_alternative<uint64_t>(var)) {
logptr->info("CustomForm callback {} = {}", name, std::get<uint64_t>(var));
} else if (std::holds_alternative<double>(var)) {
Expand Down
4 changes: 2 additions & 2 deletions src-test/server/TestMolang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK(

ExpressionNode::registerQueryFunction(
"query.is_levilamina",
[&](RenderParams&, const std::vector<ExpressionNode>&) -> MolangScriptArg const& {
[&](RenderParams&, std::vector<ExpressionNode> const&) -> MolangScriptArg const& {
static auto v = MolangScriptArg(true);
return v;
},
Expand All @@ -42,7 +42,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK(
);
ExpressionNode::registerQueryFunction(
"query.homo_number",
[&](RenderParams&, const std::vector<ExpressionNode>&) -> MolangScriptArg const& {
[&](RenderParams&, std::vector<ExpressionNode> const&) -> MolangScriptArg const& {
static auto v = MolangScriptArg(114514);
return v;
},
Expand Down

This file was deleted.

Loading

0 comments on commit d09661d

Please sign in to comment.