Skip to content

Commit

Permalink
upgraded to stb image resize 2; fixed some issues when compiling with…
Browse files Browse the repository at this point in the history
… clang on windows
  • Loading branch information
nem0 committed Oct 10, 2023
1 parent fe87e5a commit 3d5d805
Show file tree
Hide file tree
Showing 26 changed files with 10,336 additions and 2,869 deletions.
1 change: 0 additions & 1 deletion external/imgui/imgui_user.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,6 @@ namespace ImGuiEx {
bool changed = false;
SetNextItemWidth(width);
BeginGroup();
float w = CalcItemWidth();
SetNextItemWidth(width - CalcTextSize(ICON_FA_TIMES).x - 1);
SetNextItemAllowOverlap();
if (set_keyboard_focus) SetKeyboardFocusHere();
Expand Down
2,634 changes: 0 additions & 2,634 deletions external/stb/stb_image_resize.h

This file was deleted.

10,303 changes: 10,303 additions & 0 deletions external/stb/stb_image_resize2.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/animation/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct AnimationSampler {
if (anim.m_max_accessed_bone_index >= pose.count) return; // can happen if skeletons do not match
const Model& model = *ctx.model;
const Time time = ctx.time;
const BoneMask* mask = ctx.mask;
//const BoneMask* mask = ctx.mask;
const float weight = ctx.weight;

ASSERT(!pose.is_absolute);
Expand Down
5 changes: 0 additions & 5 deletions src/animation/editor/animation_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ struct AnimationAssetBrowserPlugin : AssetBrowser::IPlugin {
{
m_resource = app.getEngine().getResourceManager().load<Animation>(path);

Engine& engine = m_app.getEngine();


m_viewer.m_world->createComponent(ANIMABLE_TYPE, *m_viewer.m_mesh);

auto* anim_module = static_cast<AnimationModule*>(m_viewer.m_world->getModule(ANIMABLE_TYPE));
Expand Down Expand Up @@ -212,8 +209,6 @@ struct AnimationAssetBrowserPlugin : AssetBrowser::IPlugin {

if ((!rotations.empty() || !const_rotations.empty()) && ImGui::TreeNode("Rotations")) {
for (const Animation::RotationTrack& track : rotations) {
u32 track_idx = u32(&track - rotations.begin());

const Model::Bone& bone = m_model->getBone(track.bone_index);
ImGuiTreeNodeFlags flags = m_selected_bone == track.bone_index ? ImGuiTreeNodeFlags_Selected : 0;
flags |= ImGuiTreeNodeFlags_OpenOnArrow;
Expand Down
13 changes: 3 additions & 10 deletions src/animation/editor/controller_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
{
FileSystem& fs = m_app.getEngine().getFileSystem();
OutputMemoryStream data(m_allocator);
ResourceManagerHub& rm = m_app.getEngine().getResourceManager();
if (fs.getContentSync(Path(path), data)) {
if (fs.getContentSync(path, data)) {
InputMemoryStream str(data);
if (m_controller.deserialize(str)) {
checkSkeleton();
Expand Down Expand Up @@ -329,7 +328,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup();
if (ImGui::IsWindowAppearing()) m_node_filter_selection = 0;
if (m_node_filter.gui("Filter", 150, ImGui::IsWindowAppearing())) m_node_filter_selection = 0;
Node* n = nullptr;
if (m_node_filter.isActive()) {
struct : INodeTypeVisitor {
bool beginCategory(const char* _category) override {
Expand All @@ -346,7 +344,7 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp

StaticString<128> label(category, _label);
if (shortcut) label.append(" (LMB + ", shortcut, ")");
if (ImGui::Selectable(label, selected) || insert_enter && selected) {
if (ImGui::Selectable(label, selected) || (insert_enter && selected)) {
n = creator.create(*win);
ImGui::CloseCurrentPopup();
}
Expand Down Expand Up @@ -588,7 +586,7 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
float weight = blob.read<float>();
Time time = blob.read<Time>();
bool looped = blob.read<bool>();
ImGui::Text("slot = %d, weight = %f, time = %f", slot, weight, time.seconds());
ImGui::Text("slot = %d, weight = %f, time = %f, looped = %s", slot, weight, time.seconds(), looped ? "true" : "false");
break;
}
}
Expand Down Expand Up @@ -836,7 +834,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
StringView subres = Path::getSubresource(path);
if (Path::hasExtension(subres, "ani")) {
Controller::AnimationEntry& entry = m_controller.m_animation_entries.emplace();
ResourceManagerHub& res_manager = m_app.getEngine().getResourceManager();
entry.animation = path;
entry.set = 0;
entry.slot = m_controller.m_animation_slots.size();
Expand All @@ -852,7 +849,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
StringView subres = Path::getSubresource(path);
if (Path::hasExtension(subres, "ani")) {
Controller::AnimationEntry& entry = m_controller.m_animation_entries.emplace();
ResourceManagerHub& res_manager = m_app.getEngine().getResourceManager();
entry.animation = path;
entry.set = 0;
entry.slot = m_controller.m_animation_slots.size();
Expand Down Expand Up @@ -1020,8 +1016,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
}

void windowGUI() override {
const CommonActions& actions = m_app.getCommonActions();

if (!m_to_fix_skeleton.empty()) {
ImGui::OpenPopup(ICON_FA_EXCLAMATION_TRIANGLE " Fix skeleton");
}
Expand Down Expand Up @@ -1184,7 +1178,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
}

void createResource(OutputMemoryStream& blob) override {
ResourceManager* rm = m_app.getEngine().getResourceManager().get(anim::Controller::TYPE);
anim_editor::Controller controller(Path("new controller"), m_app.getAllocator());
controller.serialize(blob);
}
Expand Down
4 changes: 1 addition & 3 deletions src/animation/editor/editor_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void Blend2DNode::dataChanged() {
u32 a, b;
bool valid = true;
bool operator ==(const Edge& rhs) {
return a == rhs.a && b == rhs.b || a == rhs.b && b == rhs.a;
return (a == rhs.a && b == rhs.b) || (a == rhs.b && b == rhs.a);
}
};

Expand Down Expand Up @@ -368,7 +368,6 @@ bool Blend1DNode::propertiesGUI(Model& skeleton) {

ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-1);
static i32 selected = -1;
res = editSlot(m_controller, "##anim", &child.slot) || res;

ImGui::PopID();
Expand Down Expand Up @@ -431,7 +430,6 @@ anim::Node* AnimationNode::compile(anim::Controller& controller) {

bool AnimationNode::propertiesGUI(Model& skeleton) {
ImGuiEx::Label("Slot");
static i32 selected = -1;
bool res = editSlot(m_controller, "##slot", &m_slot);
ImGuiEx::Label("Looping");
bool loop = m_flags & Flags::LOOPED;
Expand Down
2 changes: 0 additions & 2 deletions src/editor/asset_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,6 @@ struct AssetCompilerImpl : AssetCompiler {
}
}
else {
StringView ext = Path::getExtension(path_obj);

auto dep_iter = m_dependencies.find(path_obj);
if (dep_iter.isValid()) {
for (const Path& p : dep_iter.value()) {
Expand Down
1 change: 0 additions & 1 deletion src/editor/entity_folders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ EntityFolders::EntityFolders(World& world, IAllocator& allocator)
: m_entities(allocator)
, m_world(world)
, m_folders(allocator)
, m_allocator(allocator)
{
ASSERT(!world.getFirstEntity().isValid());
world.entityDestroyed().bind<&EntityFolders::onEntityDestroyed>(this);
Expand Down
1 change: 0 additions & 1 deletion src/editor/entity_folders.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ struct LUMIX_EDITOR_API EntityFolders final {
void unlink(Folder& folder);
FolderHandle generateUniqueID();

IAllocator& m_allocator;
World& m_world;
Array<Entity> m_entities;
Array<Folder> m_folders;
Expand Down
2 changes: 0 additions & 2 deletions src/editor/profiler_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {

void timeline(float from_x, float to_x, float top, float bottom, u64 start_t) {
const float view_length_us = (float)1'000'000 * float(m_range / double(profiler::frequency()));
const float timeline_height = ImGui::GetTextLineHeightWithSpacing();
const ImColor border_color(ImGui::GetStyle().Colors[ImGuiCol_FrameBg]);

ImDrawList* dl = ImGui::GetWindowDrawList();
Expand Down Expand Up @@ -1348,7 +1347,6 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {
}
ImGui::EndChild();

ImDrawList* dl = ImGui::GetWindowDrawList();
timeline(from_x, to_x, timeline_y, before_gpu_y, timeline_start_t);
}

Expand Down
4 changes: 1 addition & 3 deletions src/editor/studio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,6 @@ struct StudioAppImpl final : StudioApp
if (selected) {
char filename[MAX_PATH];
Path::normalize(m_file_selector.getPath(), filename);
const char* base_path = m_engine->getFileSystem().getBasePath();
EntityRef entity = selected_entities[0];
m_editor->getPrefabSystem().savePrefab(entity, Path(filename));
ImGui::CloseCurrentPopup();
Expand Down Expand Up @@ -1845,7 +1844,6 @@ struct StudioAppImpl final : StudioApp
node_open = ImGui::TreeNodeEx((void*)folder, flags, "%s%s", ICON_FA_FOLDER, folder->name);
}
}
const ImGuiID node_id = ImGui::GetItemID();

if (ImGui::BeginDragDropTarget()) {
if (auto* payload = ImGui::AcceptDragDropPayload("entity")) {
Expand Down Expand Up @@ -3001,7 +2999,7 @@ struct StudioAppImpl final : StudioApp
LuaWrapper::push(L, world); // [Entity.new, Lumix.Entity, world]
LuaWrapper::push(L, entity.index); // [Entity.new, Lumix.Entity, world, entity_index]
const bool error = !LuaWrapper::pcall(L, 3, 1); // [entity]
return 1;
return error ? 0 : 1;
}

static int LUA_getResources(lua_State* L)
Expand Down
27 changes: 10 additions & 17 deletions src/editor/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum class TokenType : u8 {
};

static bool isWordChar(char c) {
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_';
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}

static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_token_type) {
Expand Down Expand Up @@ -196,7 +196,7 @@ static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_to
return *c;
}

if (*c >= 'a' && *c <= 'z' || *c >= 'A' && *c <= 'Z' || *c == '_') {
if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') {
token_type = (u8)TokenType::IDENTIFIER;
while (isWordChar(*c)) ++c;
token_len = u32(c - str);
Expand Down Expand Up @@ -246,7 +246,7 @@ enum class TokenType : u8 {
};

static bool isWordChar(char c) {
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_';
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}

static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_token_type) {
Expand Down Expand Up @@ -381,7 +381,7 @@ static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_to
return *c;
}

if (*c >= 'a' && *c <= 'z' || *c >= 'A' && *c <= 'Z' || *c == '_') {
if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') {
token_type = (u8)TokenType::IDENTIFIER;
while (isWordChar(*c)) ++c;
token_len = u32(c - str);
Expand Down Expand Up @@ -417,8 +417,8 @@ struct CodeEditorImpl final : CodeEditor {
i32 line = 0;
bool operator !=(const TextPoint& rhs) const { return col != rhs.col || line != rhs.line; }
bool operator ==(const TextPoint& rhs) const { return col == rhs.col && line == rhs.line; }
bool operator < (const TextPoint& rhs) const { return line < rhs.line || line == rhs.line && col < rhs.col; }
bool operator > (const TextPoint& rhs) const { return line > rhs.line || line == rhs.line && col > rhs.col; }
bool operator < (const TextPoint& rhs) const { return line < rhs.line || (line == rhs.line && col < rhs.col); }
bool operator > (const TextPoint& rhs) const { return line > rhs.line || (line == rhs.line && col > rhs.col); }
};

struct Cursor : TextPoint {
Expand Down Expand Up @@ -641,7 +641,6 @@ struct CodeEditorImpl final : CodeEditor {
}

ImVec2 toScreenPosition(u32 line, u32 col) {
ImVec2 v = m_text_area_screen_pos;
float y = line * ImGui::GetTextLineHeight();
const char* line_str = m_lines[line].value.c_str();
float x = ImGui::CalcTextSize(line_str, line_str + col).x;
Expand Down Expand Up @@ -810,9 +809,7 @@ struct CodeEditorImpl final : CodeEditor {

void moveCursorDown(Cursor& cursor, u32 line_count = 1) {
const char* line_str = m_lines[cursor.line].value.c_str();
float old_x = ImGui::CalcTextSize(line_str, line_str + cursor.col).x;

ImVec2 cursor_pos = toScreenPosition(cursor.line, cursor.col);
cursor.line = minimum(m_lines.size() - 1, cursor.line + line_count);

u32 num_chars_in_line = m_lines[cursor.line].length();
Expand Down Expand Up @@ -1056,7 +1053,7 @@ struct CodeEditorImpl final : CodeEditor {
}

static bool isWordChar(char c) {
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_';
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}

Cursor getWord(TextPoint& point) const {
Expand Down Expand Up @@ -1090,7 +1087,7 @@ struct CodeEditorImpl final : CodeEditor {
Cursor& getBottomCursor() {
Cursor* bottom = &m_cursors[0];
for (Cursor& cursor : m_cursors) {
if (bottom->line < cursor.line || bottom->line == cursor.line && bottom->col < cursor.col) {
if (bottom->line < cursor.line || (bottom->line == cursor.line && bottom->col < cursor.col)) {
bottom = &cursor;
}
}
Expand Down Expand Up @@ -1151,7 +1148,6 @@ struct CodeEditorImpl final : CodeEditor {
r.to = to;
r.execute(*this, false);

i32 line = from.line;
for (Cursor& cursor : m_cursors) {
if (cursor < from) continue;

Expand Down Expand Up @@ -1343,9 +1339,6 @@ struct CodeEditorImpl final : CodeEditor {
p.x += text_area_size.x - 350;
p.x = maximum(p.x, text_area_pos.x);
ImGui::SetCursorScreenPos(p);
float w = text_area_pos.x + text_area_size.x - p.x;
float h = ImGui::GetTextLineHeightWithSpacing();
ImGui::SetCursorScreenPos(p);
ImGui::SetNextItemWidth(-1);
if (m_focus_search) ImGui::SetKeyboardFocusHere();
m_focus_search = false;
Expand All @@ -1358,7 +1351,7 @@ struct CodeEditorImpl final : CodeEditor {
else if (ImGui::InputTextWithHint("##findtext", ICON_FA_SEARCH " Find Text", m_search_text, sizeof(m_search_text), flags)) {
find(m_search_from);
}
if (ImGui::IsItemActive() && ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_F3)) {
if ((ImGui::IsItemActive() && ImGui::IsKeyPressed(ImGuiKey_Enter)) || ImGui::IsKeyPressed(ImGuiKey_F3)) {
find(m_cursors[0]);
}
if (font) ImGui::PopFont();
Expand Down Expand Up @@ -1472,7 +1465,7 @@ struct CodeEditorImpl final : CodeEditor {
ImGui::ItemAdd(bb, id);
const bool hovered = ImGui::ItemHoverable(bb, id, 0);
const bool clicked = hovered && ImGui::IsItemClicked();
if (m_focus_editor || clicked && !ImGui::IsItemActive()) {
if (m_focus_editor || (clicked && !ImGui::IsItemActive())) {
m_focus_editor = false;
ImGuiWindow* window = ImGui::GetCurrentWindow();
ImGui::SetActiveID(id, window);
Expand Down
1 change: 0 additions & 1 deletion src/editor/world_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2199,7 +2199,6 @@ struct WorldEditorImpl final : WorldEditor
ASSERT(entities);
if (count <= 0) return;

World* world = getWorld();
UniquePtr<IEditorCommand> command = UniquePtr<LocalRotateEntityCommand>::create(m_allocator, *this, entities, local_rotations, count, m_allocator);
executeCommand(command.move());
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static struct Instance
}

static EVENT_TRACE_LOGFILE trace = {};
trace.LoggerName = KERNEL_LOGGER_NAME;
trace.LoggerName = (decltype(trace.LoggerName))KERNEL_LOGGER_NAME;
trace.ProcessTraceMode = PROCESS_TRACE_MODE_RAW_TIMESTAMP | PROCESS_TRACE_MODE_REAL_TIME | PROCESS_TRACE_MODE_EVENT_RECORD;
trace.EventRecordCallback = TraceTask::callback;
trace_task.open_handle = OpenTrace(&trace);
Expand Down
1 change: 0 additions & 1 deletion src/engine/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ Span<u8> OutputPagedStream::reserve(u32 size) {
}

bool OutputPagedStream::write(const void* data, u64 size) {
const u8* src = (const u8*)data;
while (size > 0) {
Span<u8> dst = reserve((u32)size);
memcpy(dst.begin(), data, dst.length());
Expand Down
2 changes: 1 addition & 1 deletion src/engine/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct LUMIX_ENGINE_API String {
u32 length() const { return m_size; }
const char* c_str() const { return isSmall() ? m_small : m_big; }
template <typename... T>
void append(T... args) { int tmp[] = { 0, (add(args), 0)... }; }
void append(T... args) { int tmp[] = { 0, (add(args), 0)... }; (void)tmp; }
void insert(u32 position, const char* value);
void insert(u32 position, StringView value);
void eraseAt(u32 position);
Expand Down
1 change: 1 addition & 0 deletions src/engine/win/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ struct NetworkStream* listen(const char* ip, u16 port, IAllocator& allocator) {
if (retVal == SOCKET_ERROR) return nullptr;

i32 res = ::listen(listen_socket, 10);
if (res != 0) return nullptr;

SOCKET socket = ::accept(listen_socket, nullptr, nullptr);
closesocket(listen_socket);
Expand Down
8 changes: 3 additions & 5 deletions src/renderer/editor/composite_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "renderer/renderer.h"
#include "stb/stb_image.h"
#include <math.h>
#include <stb/stb_image_resize.h>
#include <stb/stb_image_resize2.h>

namespace Lumix {

Expand Down Expand Up @@ -886,9 +886,7 @@ struct ResizeNode final : CompositeTexture::Node {
const u32 h = type == Type::PIXELS ? size.y : u32(in.h * scale.y * 0.01f + 0.5f);
CompositeTexture::Image& out = m_outputs.emplace(w, h, in.channels, m_allocator);

const i32 res = stbir_resize_float(in.pixels.data(), in.w, in.h, 0, out.pixels.data(), w, h, 0, out.channels);
if (res != 1) return error("Failed to resize image");
return true;
return nullptr != stbir_resize_float_linear(in.pixels.data(), in.w, in.h, 0, out.pixels.data(), w, h, 0, (stbir_pixel_layout)out.channels);
}

bool gui() override {
Expand Down Expand Up @@ -3374,7 +3372,7 @@ struct CompositeTextureEditorImpl : CompositeTextureEditor, NodeEditor {
Renderer* renderer = (Renderer*)m_resource.m_app.getEngine().getSystemManager().getSystem("renderer");
if (renderer) {
const CompositeTexture::Image& pd = preview_node->m_outputs[0];
gpu::TextureFormat format;
gpu::TextureFormat format = gpu::TextureFormat::RGBA32F;
switch (pd.channels) {
case 1: format = gpu::TextureFormat::R32F; break;
case 2: format = gpu::TextureFormat::RG32F; break;
Expand Down
Loading

0 comments on commit 3d5d805

Please sign in to comment.