Tiny refactor

This commit is contained in:
2024-10-18 16:12:24 +02:00
parent 8ee000ab74
commit 1d5b4499a4
38 changed files with 645 additions and 637 deletions

View File

@@ -533,9 +533,9 @@ Image read_png(const void *data, size_t size)
retain.initialized = false;
ufbx_inflate_input input = { 0 };
input.total_size = deflate_data.size();
input.data_size = deflate_data.size();
input.data = deflate_data.data();
engine.input.total_size = deflate_data.size();
engine.input.data_size = deflate_data.size();
engine.input.data = deflate_data.data();
ptrdiff_t res = ufbx_inflate(src.data(), src.size(), &input, &retain);
if (res < 0) return { "deflate error" };
@@ -3309,7 +3309,7 @@ void render_frame(ufbx_scene *original_scene, const Opts &opts, int frame_offset
void render_file(const Opts &opts)
{
verbosef("Loading scene: %s\n", opts.input.value.c_str());
verbosef("Loading scene: %s\n", opts.engine.input.value.c_str());
ProgressState progress_state = { };
@@ -3371,9 +3371,9 @@ void parse_args(Opts &opts, int argc, char **argv, bool ignore_input)
}
} else {
if (!ignore_input) {
opts.input.value = arg;
opts.input.defined = true;
opts.input.from_arg = true;
opts.engine.input.value = arg;
opts.engine.input.defined = true;
opts.engine.input.from_arg = true;
}
}
}
@@ -3489,7 +3489,7 @@ int main(int argc, char **argv)
parse_args(opts, argc, argv, false);
if (opts.help.value) {
fprintf(stderr, "Usage: picort input.fbx <opts> (--help)\n");
fprintf(stderr, "Usage: picort engine.input.fbx <opts> (--help)\n");
for (OptBase &opt : opts) {
char name[64];
if (opt.alias) {
@@ -3511,13 +3511,13 @@ int main(int argc, char **argv)
return 0;
}
if (!opts.input.defined) {
fprintf(stderr, "Usage: picort input.fbx/.picort.txt <opts> (--help)\n");
if (!opts.engine.input.defined) {
fprintf(stderr, "Usage: picort engine.input.fbx/.picort.txt <opts> (--help)\n");
return 0;
}
if (ends_with(opts.input.value, ".txt")) {
std::string path = std::move(opts.input.value);
if (ends_with(opts.engine.input.value, ".txt")) {
std::string path = std::move(opts.engine.input.value);
opts = Opts{};
parse_file(opts, path.c_str());
parse_args(opts, argc, argv, true);

View File

@@ -532,7 +532,7 @@
When drag'n'drop is enabled, the event callback will be invoked with an
event of type SAPP_EVENTTYPE_FILES_DROPPED whenever the user drops files on
the application window.
the application engine.window.
After the SAPP_EVENTTYPE_FILES_DROPPED is received, you can query the
number of dropped files, and their absolute paths by calling separate
@@ -884,7 +884,7 @@
=================
On some platforms which don't provide a physical keyboard, sokol-app
can display the platform's integrated onscreen keyboard for text
input. To request that the onscreen keyboard is shown, call
engine.input. To request that the onscreen keyboard is shown, call
sapp_show_keyboard(true);
@@ -949,7 +949,7 @@
sapp_desc.win32_console_create (default: false)
When set to true, a new console window will be created and
stdout/stderr will be redirected to that console window. It
stdout/stderr will be redirected to that console engine.window. It
doesn't matter if the application is started from the command
line or via double-click.

View File

@@ -532,7 +532,7 @@
When drag'n'drop is enabled, the event callback will be invoked with an
event of type SAPP_EVENTTYPE_FILES_DROPPED whenever the user drops files on
the application window.
the application engine.window.
After the SAPP_EVENTTYPE_FILES_DROPPED is received, you can query the
number of dropped files, and their absolute paths by calling separate
@@ -884,7 +884,7 @@
=================
On some platforms which don't provide a physical keyboard, sokol-app
can display the platform's integrated onscreen keyboard for text
input. To request that the onscreen keyboard is shown, call
engine.input. To request that the onscreen keyboard is shown, call
sapp_show_keyboard(true);
@@ -949,7 +949,7 @@
sapp_desc.win32_console_create (default: false)
When set to true, a new console window will be created and
stdout/stderr will be redirected to that console window. It
stdout/stderr will be redirected to that console engine.window. It
doesn't matter if the application is started from the command
line or via double-click.
@@ -1750,7 +1750,7 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#include <winrt/Windows.Graphics.Display.h>
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.UI.Composition.h>
#include <winrt/Windows.UI.Input.h>
#include <winrt/Windows.UI.engine.input.h>
#include <winrt/Windows.UI.ViewManagement.h>
#include <winrt/Windows.System.h>
#include <ppltasks.h>
@@ -3096,13 +3096,13 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
styleMask:style
backing:NSBackingStoreBuffered
defer:NO];
_sapp.macos.window.releasedWhenClosed = NO; // this is necessary for proper cleanup in applicationWillTerminate
_sapp.macos.window.title = [NSString stringWithUTF8String:_sapp.window_title];
_sapp.macos.window.acceptsMouseMovedEvents = YES;
_sapp.macos.window.restorable = YES;
_sapp.macos.engine.window.releasedWhenClosed = NO; // this is necessary for proper cleanup in applicationWillTerminate
_sapp.macos.engine.window.title = [NSString stringWithUTF8String:_sapp.window_title];
_sapp.macos.engine.window.acceptsMouseMovedEvents = YES;
_sapp.macos.engine.window.restorable = YES;
_sapp.macos.win_dlg = [[_sapp_macos_window_delegate alloc] init];
_sapp.macos.window.delegate = _sapp.macos.win_dlg;
_sapp.macos.engine.window.delegate = _sapp.macos.win_dlg;
#if defined(SOKOL_METAL)
_sapp.macos.mtl_device = MTLCreateSystemDefaultDevice();
_sapp.macos.view = [[_sapp_macos_view alloc] init];
@@ -3113,7 +3113,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
_sapp.macos.view.depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
_sapp.macos.view.sampleCount = (NSUInteger) _sapp.sample_count;
_sapp.macos.view.autoResizeDrawable = false;
_sapp.macos.window.contentView = _sapp.macos.view;
_sapp.macos.engine.window.contentView = _sapp.macos.view;
[_sapp.macos.window makeFirstResponder:_sapp.macos.view];
_sapp.macos.view.layer.magnificationFilter = kCAFilterNearest;
#elif defined(SOKOL_GLCORE33)
@@ -3150,7 +3150,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
[_sapp.macos.view setWantsBestResolutionOpenGLSurface:NO];
}
_sapp.macos.window.contentView = _sapp.macos.view;
_sapp.macos.engine.window.contentView = _sapp.macos.view;
[_sapp.macos.window makeFirstResponder:_sapp.macos.view];
NSTimer* timer_obj = [NSTimer timerWithTimeInterval:0.001
@@ -3754,7 +3754,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) {
_sapp.ios.view_ctrl = [[UIViewController alloc] init];
_sapp.ios.view_ctrl.modalPresentationStyle = UIModalPresentationFullScreen;
_sapp.ios.view_ctrl.view = _sapp.ios.view;
_sapp.ios.window.rootViewController = _sapp.ios.view_ctrl;
_sapp.ios.engine.window.rootViewController = _sapp.ios.view_ctrl;
#else
if (_sapp.desc.gl_force_gles2) {
_sapp.ios.eagl_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
@@ -3787,7 +3787,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) {
_sapp.ios.view_ctrl = [[GLKViewController alloc] init];
_sapp.ios.view_ctrl.view = _sapp.ios.view;
_sapp.ios.view_ctrl.preferredFramesPerSecond = 60 / _sapp.swap_interval;
_sapp.ios.window.rootViewController = _sapp.ios.view_ctrl;
_sapp.ios.engine.window.rootViewController = _sapp.ios.view_ctrl;
#endif
[_sapp.ios.window makeKeyAndVisible];
@@ -4050,11 +4050,11 @@ EM_JS(void, sapp_js_add_beforeunload_listener, (void), {
event.returnValue = ' ';
}
};
window.addEventListener('beforeunload', Module.sokol_beforeunload);
engine.window.addEventListener('beforeunload', Module.sokol_beforeunload);
});
EM_JS(void, sapp_js_remove_beforeunload_listener, (void), {
window.removeEventListener('beforeunload', Module.sokol_beforeunload);
engine.window.removeEventListener('beforeunload', Module.sokol_beforeunload);
});
EM_JS(void, sapp_js_add_clipboard_listener, (void), {
@@ -4062,11 +4062,11 @@ EM_JS(void, sapp_js_add_clipboard_listener, (void), {
var pasted_str = event.clipboardData.getData('text');
ccall('_sapp_emsc_onpaste', 'void', ['string'], [pasted_str]);
};
window.addEventListener('paste', Module.sokol_paste);
engine.window.addEventListener('paste', Module.sokol_paste);
});
EM_JS(void, sapp_js_remove_clipboard_listener, (void), {
window.removeEventListener('paste', Module.sokol_paste);
engine.window.removeEventListener('paste', Module.sokol_paste);
});
EM_JS(void, sapp_js_write_clipboard, (const char* c_str), {
@@ -6781,17 +6781,17 @@ _SOKOL_PRIVATE uint32_t _sapp_uwp_mods(winrt::Windows::UI::Core::CoreWindow cons
using namespace winrt::Windows::UI::Core;
uint32_t mods = 0;
if ((sender_window.GetKeyState(VirtualKey::Shift) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) {
if ((sender_engine.window.GetKeyState(VirtualKey::Shift) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) {
mods |= SAPP_MODIFIER_SHIFT;
}
if ((sender_window.GetKeyState(VirtualKey::Control) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) {
if ((sender_engine.window.GetKeyState(VirtualKey::Control) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) {
mods |= SAPP_MODIFIER_CTRL;
}
if ((sender_window.GetKeyState(VirtualKey::Menu) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) {
if ((sender_engine.window.GetKeyState(VirtualKey::Menu) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) {
mods |= SAPP_MODIFIER_ALT;
}
if (((sender_window.GetKeyState(VirtualKey::LeftWindows) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) ||
((sender_window.GetKeyState(VirtualKey::RightWindows) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down))
if (((sender_engine.window.GetKeyState(VirtualKey::LeftWindows) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down) ||
((sender_engine.window.GetKeyState(VirtualKey::RightWindows) & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down))
{
mods |= SAPP_MODIFIER_SUPER;
}
@@ -6985,7 +6985,7 @@ private:
winrt::com_ptr<ID3D11DepthStencilView> m_d3dDepthStencilView;
D3D11_VIEWPORT m_screenViewport = { };
// Cached reference to the Window.
// Cached reference to the engine.window.
winrt::agile_ref< winrt::Windows::UI::Core::CoreWindow> m_window;
// Cached device properties.
@@ -7196,7 +7196,7 @@ void DeviceResources::CreateWindowSizeDependentResources() {
DXGI_SCALING scaling = (_sapp.uwp.dpi.content_scale == _sapp.uwp.dpi.window_scale) ? DXGI_SCALING_NONE : DXGI_SCALING_STRETCH;
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 };
swapChainDesc.Width = lround(m_d3dRenderTargetSize.Width); // Match the size of the window.
swapChainDesc.Width = lround(m_d3dRenderTargetSize.Width); // Match the size of the engine.window.
swapChainDesc.Height = lround(m_d3dRenderTargetSize.Height);
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format.
swapChainDesc.Stereo = false;
@@ -7216,7 +7216,7 @@ void DeviceResources::CreateWindowSizeDependentResources() {
winrt::com_ptr<IDXGIFactory4> dxgiFactory;
winrt::check_hresult(dxgiAdapter->GetParent(__uuidof(IDXGIFactory4), dxgiFactory.put_void()));
winrt::com_ptr<IDXGISwapChain1> swapChain;
winrt::check_hresult(dxgiFactory->CreateSwapChainForCoreWindow(m_d3dDevice.get(), m_window.get().as<::IUnknown>().get(), &swapChainDesc, nullptr, swapChain.put()));
winrt::check_hresult(dxgiFactory->CreateSwapChainForCoreWindow(m_d3dDevice.get(), m_engine.window.get().as<::IUnknown>().get(), &swapChainDesc, nullptr, swapChain.put()));
m_swapChain = swapChain.as<IDXGISwapChain3>();
// Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
@@ -7327,7 +7327,7 @@ void DeviceResources::UpdateRenderTargetSize() {
void DeviceResources::SetWindow(winrt::Windows::UI::Core::CoreWindow const& window) {
auto currentDisplayInformation = winrt::Windows::Graphics::Display::DisplayInformation::GetForCurrentView();
m_window = window;
m_logicalSize = winrt::Windows::Foundation::Size(window.Bounds().Width, window.Bounds().Height);
m_logicalSize = winrt::Windows::Foundation::Size(engine.window.Bounds().Width, engine.window.Bounds().Height);
m_nativeOrientation = currentDisplayInformation.NativeOrientation();
m_currentOrientation = currentDisplayInformation.CurrentOrientation();
m_dpi = currentDisplayInformation.LogicalDpi();
@@ -7349,8 +7349,8 @@ void DeviceResources::SetDpi(float dpi) {
m_dpi = dpi;
_sapp_uwp_configure_dpi(m_dpi);
// When the display DPI changes, the logical size of the window (measured in Dips) also changes and needs to be updated.
auto window = m_window.get();
m_logicalSize = winrt::Windows::Foundation::Size(window.Bounds().Width, window.Bounds().Height);
auto window = m_engine.window.get();
m_logicalSize = winrt::Windows::Foundation::Size(engine.window.Bounds().Width, engine.window.Bounds().Height);
CreateWindowSizeDependentResources();
}
}
@@ -7536,7 +7536,7 @@ bool DeviceResources::SdkLayersAvailable() {
// The first method called when the IFrameworkView is being created.
void App::Initialize(winrt::Windows::ApplicationModel::Core::CoreApplicationView const& applicationView) {
// Register event handlers for app lifecycle. This example includes Activated, so that we
// can make the CoreWindow active and start rendering on the window.
// can make the CoreWindow active and start rendering on the engine.window.
applicationView.Activated({ this, &App::OnActivated });
winrt::Windows::ApplicationModel::Core::CoreApplication::Suspending({ this, &App::OnSuspending });
@@ -7549,19 +7549,19 @@ void App::Initialize(winrt::Windows::ApplicationModel::Core::CoreApplicationView
// Called when the CoreWindow object is created (or re-created).
void App::SetWindow(winrt::Windows::UI::Core::CoreWindow const& window) {
window.SizeChanged({ this, &App::OnWindowSizeChanged });
window.VisibilityChanged({ this, &App::OnVisibilityChanged });
engine.window.SizeChanged({ this, &App::OnWindowSizeChanged });
engine.window.VisibilityChanged({ this, &App::OnVisibilityChanged });
window.KeyDown({ this, &App::OnKeyDown });
window.KeyUp({ this, &App::OnKeyUp });
window.CharacterReceived({ this, &App::OnCharacterReceived });
engine.window.KeyDown({ this, &App::OnKeyDown });
engine.window.KeyUp({ this, &App::OnKeyUp });
engine.window.CharacterReceived({ this, &App::OnCharacterReceived });
window.PointerEntered({ this, &App::OnPointerEntered });
window.PointerExited({ this, &App::OnPointerExited });
window.PointerPressed({ this, &App::OnPointerPressed });
window.PointerReleased({ this, &App::OnPointerReleased });
window.PointerMoved({ this, &App::OnPointerMoved });
window.PointerWheelChanged({ this, &App::OnPointerWheelChanged });
engine.window.PointerEntered({ this, &App::OnPointerEntered });
engine.window.PointerExited({ this, &App::OnPointerExited });
engine.window.PointerPressed({ this, &App::OnPointerPressed });
engine.window.PointerReleased({ this, &App::OnPointerReleased });
engine.window.PointerMoved({ this, &App::OnPointerMoved });
engine.window.PointerWheelChanged({ this, &App::OnPointerWheelChanged });
auto currentDisplayInformation = winrt::Windows::Graphics::Display::DisplayInformation::GetForCurrentView();

View File

@@ -575,10 +575,10 @@ static const char lit_pixel_source_glsl330[275] = {
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
a_position = stage_input.a_position;
a_vertex_index = stage_input.a_vertex_index;
a_normal = stage_input.a_normal;
a_uv = stage_input.a_uv;
a_position = stage_engine.input.a_position;
a_vertex_index = stage_engine.input.a_vertex_index;
a_normal = stage_engine.input.a_normal;
a_uv = stage_engine.input.a_uv;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
@@ -835,12 +835,12 @@ static const uint8_t static_vertex_bytecode_hlsl5[2276] = {
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
a_bone_indices = stage_input.a_bone_indices;
a_bone_weights = stage_input.a_bone_weights;
a_position = stage_input.a_position;
a_vertex_index = stage_input.a_vertex_index;
a_normal = stage_input.a_normal;
a_uv = stage_input.a_uv;
a_bone_indices = stage_engine.input.a_bone_indices;
a_bone_weights = stage_engine.input.a_bone_weights;
a_position = stage_engine.input.a_position;
a_vertex_index = stage_engine.input.a_vertex_index;
a_normal = stage_engine.input.a_normal;
a_uv = stage_engine.input.a_uv;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
@@ -1084,8 +1084,8 @@ static const uint8_t skinned_vertex_bytecode_hlsl5[3256] = {
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
v_normal = stage_input.v_normal;
v_uv = stage_input.v_uv;
v_normal = stage_engine.input.v_normal;
v_uv = stage_engine.input.v_uv;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.o_color = o_color;