slight optimization
This commit is contained in:
parent
83b45a0dea
commit
4793d6f26a
6 changed files with 39 additions and 25 deletions
|
|
@ -40,18 +40,4 @@ UiElementMouse::UiElementMouse(std::int_fast32_t anchorX, std::int_fast32_t anch
|
|||
|
||||
UiElementBuffer::UiElementBuffer(std::uint_fast32_t width, std::uint_fast32_t height) : width(width), height(height) {
|
||||
|
||||
}
|
||||
|
||||
void UiElement::UpdatePosition(WindowFramebuffer& window) {
|
||||
window.ScaleElement(transform);
|
||||
for(UiElement* child : children) {
|
||||
child->UpdatePosition(window, *this);
|
||||
}
|
||||
}
|
||||
|
||||
void UiElement::UpdatePosition(WindowFramebuffer& window, UiElement& parent) {
|
||||
window.ScaleElement(transform, parent.transform);
|
||||
for(UiElement* child : children) {
|
||||
UpdatePosition(window, *child);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module Crafter.Graphics:UiElementBufferBuffer_impl;
|
||||
import :UiElement;
|
||||
import :Window;
|
||||
import std;
|
||||
|
||||
using namespace Crafter;
|
||||
|
|
@ -30,4 +31,22 @@ UiElementBufferBuffer::UiElementBufferBuffer(std::int_fast32_t anchorX, std::int
|
|||
|
||||
UiElementBufferBuffer::UiElementBufferBuffer(std::uint_fast32_t width, std::uint_fast32_t height, std::int_fast32_t anchorX, std::int_fast32_t anchorY, std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight, std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY, std::int_fast32_t z, bool ignoreScaling) : UiElement(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), UiElementBufferBufferBase(width, height){
|
||||
|
||||
}
|
||||
|
||||
void UiElementBufferBuffer::UpdatePosition(WindowFramebuffer& window) {
|
||||
window.ScaleElement(transform);
|
||||
scaled.resize(transform.scaled.width*transform.scaled.height);
|
||||
CopyNearestNeighbour(scaled.data(), transform.scaled.width, transform.scaled.height);
|
||||
for(UiElement* child : children) {
|
||||
child->UpdatePosition(window, *this);
|
||||
}
|
||||
}
|
||||
|
||||
void UiElementBufferBuffer::UpdatePosition(WindowFramebuffer& window, UiElement& parent) {
|
||||
window.ScaleElement(transform, parent.transform);
|
||||
scaled.resize(transform.scaled.width*transform.scaled.height);
|
||||
CopyNearestNeighbour(scaled.data(),transform.scaled.width, transform.scaled.height);
|
||||
for(UiElement* child : children) {
|
||||
UpdatePosition(window, *child);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
|
|
|||
|
|
@ -70,9 +70,7 @@ void UiElementTextBuffer::Render(const std::string_view text, float size, Pixel_
|
|||
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
int bufIndex = ((baseline + j + c_y1) * bufferWidth + (x + i + c_x1));
|
||||
unsigned char val = bitmap[j * w + i];
|
||||
buffer[bufIndex] = {color.r, color.g, color.b, val};
|
||||
buffer[(baseline + j + c_y1) * bufferWidth + (x + i + c_x1)] = {color.r, color.g, color.b, bitmap[j * w + i]};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -252,21 +252,30 @@ void WindowWayland::xdg_wm_base_handle_ping(void* data, xdg_wm_base* xdg_wm_base
|
|||
xdg_wm_base_pong(xdg_wm_base, serial);
|
||||
}
|
||||
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> framEnd;
|
||||
|
||||
void WindowWayland::wl_surface_frame_done(void* data, struct wl_callback *cb, uint32_t time)
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
auto vblank = duration_cast<std::chrono::milliseconds>(start - framEnd);
|
||||
wl_callback_destroy(cb);
|
||||
WindowWayland* window = reinterpret_cast<WindowWayland*>(data);
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
if(window->updating) {
|
||||
cb = wl_surface_frame(window->surface);
|
||||
wl_callback_add_listener(cb, &WindowWayland::wl_callback_listener, window);
|
||||
auto startUpdate = std::chrono::high_resolution_clock::now();
|
||||
window->onUpdate.Invoke({start, start-window->lastFrameEnd});
|
||||
auto endUpdate = std::chrono::high_resolution_clock::now();
|
||||
auto startRender = std::chrono::high_resolution_clock::now();
|
||||
window->Render();
|
||||
auto endRender = std::chrono::high_resolution_clock::now();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
std::cout << std::format("Update: {}, Render: {}, Vblank: {}, Total: {}", duration_cast<std::chrono::milliseconds>(endUpdate - startUpdate), duration_cast<std::chrono::milliseconds>(endRender - startRender), vblank, duration_cast<std::chrono::milliseconds>((endUpdate - startUpdate)+(endRender - startRender)+vblank)) << std::endl;
|
||||
}
|
||||
|
||||
window->Render();
|
||||
|
||||
framEnd = std::chrono::high_resolution_clock::now();
|
||||
window->lastFrameEnd = start;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue