适应推
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@ String ptrtow(const QWORD value) { return qwtowb16(value, 16); }
|
||||
namespace $LimitedUse {
|
||||
Release::~Release() {
|
||||
delete &gc;
|
||||
Logger.put(L"--------- Last Check ---------\n");
|
||||
Logger.put(L"--------- Last Check ---------");
|
||||
for (const auto& [addr, info] : memoryManager.allocated) { Logger.print(L" using", addr, info.size, L"B", info.msg); }
|
||||
delete &Logger;
|
||||
delete &memoryManager;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#define __CARLBEKS_DEBUG__
|
||||
#define __CARLBEKS_MEMORY__ 3
|
||||
#define __CARLBEKS_MEMORY__ 2
|
||||
|
||||
#pragma warning(disable: 4819)
|
||||
|
||||
@@ -69,6 +69,8 @@ using Function = std::function<F>;
|
||||
#pragma comment(lib, "Uxtheme.lib")
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
|
||||
#include "warnings.h"
|
||||
|
||||
template <typename T>
|
||||
concept Copyable = requires(const T& t) { T(t); };
|
||||
template <typename T>
|
||||
@@ -94,18 +96,19 @@ namespace $LimitedUse {
|
||||
|
||||
~Release();
|
||||
} inline gcRelease_LoggerRelease_memoryManagerRelease;
|
||||
} // namespace $LimitedUse
|
||||
|
||||
struct MemoryManager {
|
||||
struct MemoryManager {
|
||||
struct MemoryInfo {
|
||||
const String msg;
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
Map<void*, MemoryInfo> allocated{};
|
||||
std::atomic_bool acquiring = false;
|
||||
|
||||
constexpr MemoryManager() noexcept = default;
|
||||
} inline& [[carlbeks::releasedat("def.cpp")]] memoryManager = *new MemoryManager;
|
||||
} inline& [[carlbeks::releasedat("def.cpp")]] memoryManager = *new MemoryManager;
|
||||
}
|
||||
|
||||
void requireNonnull(const void* value) noexcept(false);
|
||||
void checkAllocation(const void* value) noexcept(false);
|
||||
@@ -123,30 +126,40 @@ extern String atow(const char* chars);
|
||||
template <typename T>
|
||||
T* allocatedFor$(T* value, const String& msg = L"", std::size_t size = sizeof(T)) {
|
||||
requireNonnull(value);
|
||||
const auto& k = memoryManager.allocated.emplace(value, MemoryManager::MemoryInfo{L"[" + atow(typeid(T).name()) + L"] " + msg, size}).first;
|
||||
#if __CARLBEKS_MEMORY__ > 1
|
||||
bool expect = false;
|
||||
while (!$LimitedUse::memoryManager.acquiring.compare_exchange_strong(expect, true)) expect = false;
|
||||
const auto& k = $LimitedUse::memoryManager.allocated.emplace(value, $LimitedUse::MemoryManager::MemoryInfo{L"[" + atow(typeid(T).name()) + L"] " + msg, size}).first;
|
||||
#if __CARLBEKS_MEMORY__ > 2
|
||||
$LimitedUse::printAllocate(value, k->second.size, k->second.msg);
|
||||
#endif
|
||||
$LimitedUse::memoryManager.acquiring.store(false);
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* deallocating$(T* value, const String& stack) {
|
||||
#if __CARLBEKS_MEMORY__ > 1
|
||||
const MemoryManager::MemoryInfo* info = nullptr;
|
||||
if (memoryManager.allocated.contains(value)) info = &memoryManager.allocated.at(value);
|
||||
bool expect = false;
|
||||
while (!$LimitedUse::memoryManager.acquiring.compare_exchange_strong(expect, true)) expect = false;
|
||||
#if __CARLBEKS_MEMORY__ > 2
|
||||
const $LimitedUse::MemoryManager::MemoryInfo* info = nullptr;
|
||||
if ($LimitedUse::memoryManager.allocated.contains(value)) info = &$LimitedUse::memoryManager.allocated.at(value);
|
||||
$LimitedUse::printDeallocate(value, info ? info->size : 0, info ? info->msg : L"???");
|
||||
#endif
|
||||
if (value) { if (!memoryManager.allocated.erase(value)) $LimitedUse::printDeallocateWarning(value, L"value not recorded" + stack); }
|
||||
if (value) { if (!$LimitedUse::memoryManager.allocated.erase(value)) $LimitedUse::printDeallocateWarning(value, L"value not recorded" + stack); }
|
||||
$LimitedUse::memoryManager.acquiring.store(false);
|
||||
return value;
|
||||
}
|
||||
|
||||
#ifndef __FUNCSIG__
|
||||
#define __FUNCSIG__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
#if __CARLBEKS_MEMORY__ > 3
|
||||
#define allocatedFor(val, ...) allocatedFor$(val, L"\n From " __FUNCSIG__ "\n At " __FILE__ ":" _STL_STRINGIZE(__LINE__) __VA_OPT__(,) __VA_ARGS__)
|
||||
#else
|
||||
#define allocatedFor(val, ...) allocatedFor$(val, L"" __VA_OPT__(,) __VA_ARGS__)
|
||||
#endif
|
||||
#if __CARLBEKS_MEMORY__ > 2
|
||||
#if __CARLBEKS_MEMORY__ > 1
|
||||
#define deallocating(val) deallocating$(val, L"\n From " __FUNCSIG__ "\n At " __FILE__ ":" _STL_STRINGIZE(__LINE__))
|
||||
#else
|
||||
#define deallocating(val) deallocating$(val)
|
||||
|
||||
+4
-4
@@ -4,10 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../utils/gc.h"
|
||||
#include "../ui/Hud.h"
|
||||
#include "../utils/Task.h"
|
||||
#include "../ui/Window.h"
|
||||
// #include "..\utils\gc.h"
|
||||
#include "..\ui\Hud.h"
|
||||
#include "..\utils\Task.h"
|
||||
#include "..\ui\Window.h"
|
||||
|
||||
class [[carlbeks::predecl, carlbeks::defineat("World.h")]] WorldManager;
|
||||
class [[carlbeks::predecl, carlbeks::defineat("Entity.h")]] EntityManager;
|
||||
|
||||
@@ -121,6 +121,7 @@ public:
|
||||
block->onRemove();
|
||||
}
|
||||
gc.submit<World>(this);
|
||||
Logger.debug(L"World::onRemove() called");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,22 +2,12 @@
|
||||
|
||||
#include "def.h"
|
||||
|
||||
inline BOOL NewProcess(const String& cmdline) noexcept {
|
||||
STARTUPINFOW si = {
|
||||
sizeof(si), nullptr, nullptr, nullptr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr
|
||||
};
|
||||
PROCESS_INFORMATION pi{
|
||||
nullptr, nullptr, 0, 0
|
||||
};
|
||||
return CreateProcessW(nullptr, const_cast<wchar*>(cmdline.c_str()), nullptr, nullptr, 0, 0, nullptr, nullptr, &si, &pi);
|
||||
}
|
||||
|
||||
inline HRESULT RemoveDefaultCaption(const HWND hWnd, const MARGINS* p) noexcept { return DwmExtendFrameIntoClientArea(hWnd, p); }
|
||||
|
||||
inline bool ShowConsoleIO() noexcept {
|
||||
AllocConsole();
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "r+", stdin);
|
||||
freopen("CONIN$", "r+", stdin);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+20
-17
@@ -494,13 +494,16 @@ void renderThread() {
|
||||
using Time = time_point<system_clock>;
|
||||
renderer.initialize();
|
||||
Time lastRender = system_clock::now();
|
||||
// bool _TestFlag = false;
|
||||
while (isRunning) {
|
||||
const Time thisTime = system_clock::now();
|
||||
if (thisTime - lastRender < milliseconds(interactSettings.constants.msPerRender)) {
|
||||
Sleep(1);
|
||||
// if (_TestFlag) _TestFlag = false, Logger.debug(L"Render Test: " + std::to_wstring((thisTime - lastRender) / milliseconds(1)));
|
||||
continue;
|
||||
}
|
||||
game.render(nRange(static_cast<double>((thisTime - lastTick).count()) / interactSettings.constants.msPerRender, 0.0, 1.0));
|
||||
// _TestFlag = true;
|
||||
game.render(nRange(static_cast<double>((thisTime - lastTick).count()) / static_cast<double>(interactSettings.constants.msPerRender), 0.0, 1.0));
|
||||
lastRender = thisTime;
|
||||
}
|
||||
} catch (const Exception& e) { Logger.log(L"Render thread exception: " + e.getMessage()); }
|
||||
@@ -516,7 +519,7 @@ int __stdcall wWinMain(const HINSTANCE hInstance, const HINSTANCE, [[maybe_unuse
|
||||
SetUnhandledExceptionFilter(UnhandledExceptionFilter);
|
||||
translator.initialize();
|
||||
Logger.info(L"--------Program Start--------");
|
||||
for (const auto& [addr, info] : memoryManager.allocated) { Logger.print(L" using", addr, info.size, L"B", info.msg); }
|
||||
for (const auto& [addr, info] : $LimitedUse::memoryManager.allocated) { Logger.print(L" using", addr, info.size, L"B", info.msg); }
|
||||
WNDCLASSEX wc = {};
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
@@ -541,26 +544,26 @@ int __stdcall wWinMain(const HINSTANCE hInstance, const HINSTANCE, [[maybe_unuse
|
||||
.cyBottomHeight = 0
|
||||
};
|
||||
RemoveDefaultCaption(MainWindowHandle, &margins);
|
||||
int a = -40;
|
||||
game.tasks.pushNewed(new Task([&a](Task& self) {
|
||||
if (a) {
|
||||
++a;
|
||||
SetLayeredWindowAttributes(MainWindowHandle, 0xffffff, static_cast<BYTE>(0xff * (40 + a) / 40), LWA_COLORKEY | LWA_ALPHA);
|
||||
} else {
|
||||
SetLayeredWindowAttributes(MainWindowHandle, 0xffffff, 0xff, LWA_COLORKEY | LWA_ALPHA);
|
||||
self.schedulePop(true);
|
||||
SetWindowLongW(MainWindowHandle, GWL_EXSTYLE, GetWindowLongW(MainWindowHandle, GWL_EXSTYLE) & ~WS_EX_LAYERED);
|
||||
}
|
||||
return 0;
|
||||
}));
|
||||
SetWindowLongW(MainWindowHandle, GWL_EXSTYLE, GetWindowLongW(MainWindowHandle, GWL_EXSTYLE) | WS_EX_LAYERED);
|
||||
SetLayeredWindowAttributes(MainWindowHandle, 0xffffff, 0xe0, LWA_COLORKEY | LWA_ALPHA);
|
||||
// SetLayeredWindowAttributes(MainWindowHandle, 0xffffff, 0xe0, LWA_COLORKEY | LWA_ALPHA);
|
||||
SetLayeredWindowAttributes(MainWindowHandle, 0xffffff, 0, LWA_COLORKEY);
|
||||
ShowWindow(MainWindowHandle, nShowCmd);
|
||||
const HHOOK hook = SetWindowsHookW(WH_GETMESSAGE, HookProc);
|
||||
const HACCEL hAccelTable = LoadAcceleratorsW(hInstance, MAKEINTRESOURCE(109));
|
||||
if (!hook) Logger.error(Logger.of(L"SetWindowsHookW failed. LastError:", GetLastError()));
|
||||
test();
|
||||
{
|
||||
// int a = -40;
|
||||
// game.tasks.pushNewed(allocatedFor(new Task([&a](Task& self) {
|
||||
// if (a) SetLayeredWindowAttributes(MainWindowHandle, 0xffffff, static_cast<BYTE>(0xff * (40 + ++a) / 40), LWA_COLORKEY | LWA_ALPHA);
|
||||
// else {
|
||||
// SetLayeredWindowAttributes(MainWindowHandle, 0xffffff, 0xff, LWA_COLORKEY | LWA_ALPHA);
|
||||
// self.schedulePop(true);
|
||||
// SetWindowLongW(MainWindowHandle, GWL_EXSTYLE, GetWindowLongW(MainWindowHandle, GWL_EXSTYLE) & ~WS_EX_LAYERED);
|
||||
// }
|
||||
// return 0;
|
||||
// })
|
||||
// ));
|
||||
game.initialize();
|
||||
interactManager.initialize();
|
||||
World* w = StartWorld::create();
|
||||
@@ -584,10 +587,10 @@ int __stdcall wWinMain(const HINSTANCE hInstance, const HINSTANCE, [[maybe_unuse
|
||||
DestroyAcceleratorTable(hAccelTable);
|
||||
UnhookWindowsHookEx(hook);
|
||||
Logger.info(L"------- Program End --------");
|
||||
for (const auto& [addr, info] : memoryManager.allocated) { Logger.print(L" using", addr, info.size, L"B", info.msg); }
|
||||
_wsystem(L"pause");
|
||||
for (const auto& [addr, info] : $LimitedUse::memoryManager.allocated) { Logger.print(L" using", addr, info.size, L"B", info.msg); }
|
||||
{
|
||||
fontManager.finalize(); // 似乎GDI有终止自动回收,所以此代码需要提前
|
||||
}
|
||||
_wsystem(L"pause");
|
||||
return static_cast<int>(msg.wParam);
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ public:
|
||||
virtual void onMouseUp(const MouseButtonCode code) noexcept {
|
||||
if (mouseUp) mouseUp(*this, code);
|
||||
if (hasMouseTrigger) onMouseClick(code);
|
||||
hasMouseTrigger = false;
|
||||
}
|
||||
|
||||
virtual void onMouseLeave(const MouseButtonCode value) noexcept {
|
||||
|
||||
+5
-5
@@ -108,11 +108,11 @@ static constexpr wchar Table16[17] = L"0123456789ABCDEF";
|
||||
[[nodiscard]] inline String qwtowb10(QWORD value, const unsigned int fills = 1) noexcept {
|
||||
static constexpr wchar Table10[11] = L"0123456789";
|
||||
static constexpr QWORD Compare10[20] = {
|
||||
0, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
|
||||
100000000, 1000000000, 10000000000, 100000000000,
|
||||
1000000000000, 10000000000000, 100000000000000,
|
||||
1000000000000000, 10000000000000000, 100000000000000000,
|
||||
1000000000000000000, 10000000000000000000
|
||||
0ull, 10ull, 100ull, 1000ull, 10000ull, 100000ull, 1000000ull, 10000000ull,
|
||||
100000000ull, 1000000000ull, 10000000000ull, 100000000000ull,
|
||||
1000000000000ull, 10000000000000ull, 100000000000000ull,
|
||||
1000000000000000ull, 10000000000000000ull, 100000000000000000ull,
|
||||
1000000000000000000ull, 10000000000000000000ull
|
||||
};
|
||||
String ret;
|
||||
if (value < Compare10[fills]) {
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
|
||||
#pragma warning(disable: 4554)
|
||||
#pragma warning(default: 4555)
|
||||
#pragma warning(disable: 4996)
|
||||
#pragma warning(disable: 5030)
|
||||
|
||||
Reference in New Issue
Block a user