Skip to content

Commit

Permalink
Added CustomWindow and NativeWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 3, 2024
1 parent 8a63b04 commit 07ecf2a
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 28 deletions.
17 changes: 14 additions & 3 deletions src/RenderLibrary/Exports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
#define API __declspec(dllimport)
#endif

/* Нативное окно для Авалонии */
extern "C"
{
API bool Frame();
API void MessageLoop();
API bool FrameNative();
API void MessageNativeLoop();
API HWND CreateNativeWindow();
API void DestroyNativeWindow();
API void CreateScene(HWND ptr);
API void CreateNativeScene(HWND ptr);
}

/*Кастомное окно для отдельных тестов */
extern "C"
{
API bool FrameCustom();
API void MessageCustomLoop();
API HWND CreateCustomWindow();
API void DestroyCustomWindow();
API void CreateCustomScene(HWND pointer);
}
98 changes: 98 additions & 0 deletions src/RenderLibrary/FabricCustomWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,101 @@ using namespace DirectX;
#include "FabricCustomWindow.hpp"

using namespace RenderLibary;

API HWND CreateCustomWindow()
{
_renderCustomObject._wndClassExW.cbSize = sizeof(WNDCLASSEX);
_renderCustomObject._wndClassExW.style = CS_HREDRAW | CS_VREDRAW;

_renderCustomObject._wndClassExW.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT
{
switch (message)
{
case WM_CREATE:
case WM_CLOSE:
case WM_ACTIVATE:
case WM_MOVE:
case WM_SIZE:
case WM_MOUSEMOVE:
case WM_LBUTTONUP:
case WM_LBUTTONDOWN:
case WM_MBUTTONUP:
case WM_MBUTTONDOWN:
case WM_RBUTTONUP:
case WM_RBUTTONDOWN:
case WM_MOUSEWHEEL:
case WM_KEYDOWN:
case WM_KEYUP:
break;
default:
return DefWindowProcW(hWnd, message, wParam, lParam);
}

return 0;
};

_renderCustomObject._wndClassExW.cbClsExtra = 0;
_renderCustomObject._wndClassExW.cbWndExtra = 0;
_renderCustomObject._wndClassExW.hInstance = GetModuleHandle(nullptr);
_renderCustomObject._wndClassExW.hbrBackground = CreateSolidBrush(RGB(0, 156, 65));
_renderCustomObject._wndClassExW.lpszClassName = _renderCustomObject._wndClassName;
_renderCustomObject._wndClassExW.hCursor = LoadCursor(NULL, IDC_ARROW);
_renderCustomObject._wndClassExW.hIcon = LoadIcon(NULL, IDI_APPLICATION);

RegisterClassExW(&_renderCustomObject._wndClassExW);

#ifdef _DEBUG
constexpr auto _debug = true;
#else
constexpr auto _debug = false;
#endif

auto ACreateWindowW = []() -> HWND
{
return CreateWindowW
(
_renderCustomObject._wndClassName,
_debug ? L"Main Render (Debug)" : L"Main Render (Release)",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
nullptr,
nullptr,
GetModuleHandle(nullptr),
nullptr
);
};

_renderCustomObject._window = ACreateWindowW();

ShowWindow(_renderCustomObject._window, SW_SHOWNORMAL);
UpdateWindow(_renderCustomObject._window);

return _renderCustomObject._window;
}

API void CreateCustomScene(HWND pointer)
{

}

API void MessageCustomLoop()
{
while (PeekMessage(&_renderCustomObject._msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&_renderCustomObject._msg);
DispatchMessage(&_renderCustomObject._msg);
}
}

API void DestroyCustomWindow()
{
DestroyWindow(_renderCustomObject._window);
_renderCustomObject._window = nullptr;
}

API bool FrameCustom()
{
MessageCustomLoop();

return true;
}
1 change: 0 additions & 1 deletion src/RenderLibrary/FabricCustomWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ namespace RenderLibary
HWND _window = {};
WNDCLASSEXW _wndClassExW = {};
const wchar_t* _wndClassName = L"ShaderPlaygroundRender";

} _renderCustomObject;
}
13 changes: 7 additions & 6 deletions src/RenderLibrary/FabricNativeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ API HWND CreateNativeWindow()
return _renderNativeObject._window;
}

API void CreateScene(HWND pointer)
API void CreateNativeScene(HWND pointer)
{

}

API void MessageLoop()
API void MessageNativeLoop()
{
while (PeekMessage(&_renderNativeObject._msg, 0, 0, 0, PM_REMOVE))
{
Expand All @@ -107,12 +107,13 @@ API void MessageLoop()

API void DestroyNativeWindow()
{
delete _renderNativeObject._window;
DestroyWindow(_renderNativeObject._window);
_renderNativeObject._window = nullptr;
}

API bool Frame()
API bool FrameNative()
{
MessageLoop();
MessageNativeLoop();

return true;
}
24 changes: 6 additions & 18 deletions src/RenderLibrary/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@

#include "Memory.hpp"

#pragma section(".Hook", read)

using namespace RenderLibary;

Allocator* Allocator::instance = nullptr;

std::unordered_set<void*> Allocator::objectCollection;
std::atomic<std::size_t> Allocator::uniqueIDCounter{ 0 };
std::atomic<std::size_t> Allocator::uniqueIDCounter = { 0 };
std::unordered_set<void*> Allocator::objectCollection = { 0 };

void* Allocator::operator new(std::size_t size)
{
Expand Down Expand Up @@ -61,30 +57,22 @@ void Allocator::PrintCollection()
{
for (const auto& obj : objectCollection)
{
//Log::Get()->Debug("~ Object at address: %p", obj);
// Log::Get()->Debug("~ Object at address: %p", obj);
}
}

std::size_t Allocator::GenerateUniqueID()
{
return ++uniqueIDCounter; // Увеличиваем и возвращаем уникальный идентификатор
return ++uniqueIDCounter;
}

Allocator& Allocator::GetInstance()
{
if (!instance)
{
instance = new Allocator();
}

return *instance;
static Allocator instance;
return instance;
}

Allocator::Allocator()
{
std::cout << "Allocator created" << std::endl;
}

#pragma init_seg(lib)
__declspec(allocate(".Hook"))
Allocator& Memory = Allocator::GetInstance();
2 changes: 2 additions & 0 deletions src/RenderLibrary/RenderLibrary.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CreateDirectXDevice.cpp" />
<ClCompile Include="Exports.cpp" />
<ClCompile Include="FabricCustomWindow.cpp" />
<ClCompile Include="FabricNativeWindow.cpp" />
Expand All @@ -178,6 +179,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CreateDirectXDevice.hpp" />
<ClInclude Include="Exports.hpp" />
<ClInclude Include="FabricCustomWindow.hpp" />
<ClInclude Include="FabricNativeWindow.hpp" />
Expand Down
2 changes: 2 additions & 0 deletions src/RenderLibrary/RenderLibrary.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
<ClCompile Include="Exports.cpp" />
<ClCompile Include="FabricCustomWindow.cpp" />
<ClCompile Include="Memory.cpp" />
<ClCompile Include="CreateDirectXDevice.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="FabricNativeWindow.hpp" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="Exports.hpp" />
<ClInclude Include="FabricCustomWindow.hpp" />
<ClInclude Include="Memory.hpp" />
<ClInclude Include="CreateDirectXDevice.hpp" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions src/RenderTestApp/StartUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@ using namespace DirectX;

void Start::Launch()
{
HWND windowHandle = CreateCustomWindow();

if (!windowHandle)
{
MessageBox(nullptr, L"Не удалось создать окно.", L"Ошибка", MB_ICONERROR);
return;
}

CreateCustomScene(windowHandle);

while (FrameCustom())
{

}

DestroyCustomWindow();
}

0 comments on commit 07ecf2a

Please sign in to comment.