Skip to content

Commit

Permalink
Cleanup some codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 17, 2024
1 parent 69f44ee commit 410f361
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Projects/Windows/Dora/Dora.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@
<ClInclude Include="..\..\..\Source\3rdParty\Other\AcfDelegate.h" />
<ClInclude Include="..\..\..\Source\3rdParty\Other\atlas.h" />
<ClInclude Include="..\..\..\Source\3rdParty\Other\rapidxml_sax3.hpp" />
<ClInclude Include="..\..\..\Source\3rdParty\Other\SdfBuilder.h" />
<ClInclude Include="..\..\..\Source\3rdParty\Other\sdf_gen2d.h" />
<ClInclude Include="..\..\..\Source\3rdParty\Other\utf8.h" />
<ClInclude Include="..\..\..\Source\3rdParty\playrho\ArrayList.hpp" />
<ClInclude Include="..\..\..\Source\3rdParty\playrho\BlockAllocator.hpp" />
Expand Down
2 changes: 1 addition & 1 deletion Projects/Windows/Dora/Dora.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -4314,7 +4314,7 @@
<ClInclude Include="..\..\..\Source\3rdParty\yoga\style\StyleSizeLength.h">
<Filter>3rdParty\yoga\style</Filter>
</ClInclude>
<ClInclude Include="..\..\..\Source\3rdParty\Other\SdfBuilder.h">
<ClInclude Include="..\..\..\Source\3rdParty\Other\sdf_gen2d.h">
<Filter>3rdParty\Other</Filter>
</ClInclude>
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Projects/iOS/Dora.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,6 @@
3C0FB67D2BF1970C0098E88D /* Effekseer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Effekseer.h; sourceTree = "<group>"; };
3C0FB67E2BF1970C0098E88D /* Effekseer.Modules.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Effekseer.Modules.h; sourceTree = "<group>"; };
3C0FB67F2BF1970C0098E88D /* Effekseer.SIMD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Effekseer.SIMD.h; sourceTree = "<group>"; };
3C1A452E2D0B48FF0025084B /* SdfBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SdfBuilder.h; sourceTree = "<group>"; };
3C1D41002703019800202534 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Dora/Assets.xcassets; sourceTree = "<group>"; };
3C1F87C81DF7B4C5005F1B4D /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
3C329DDD2B39D8AC002BC023 /* Dora.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Dora.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2551,6 +2550,7 @@
3CE331791D96D98700F9C3F6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
3CE3317B1D96D98D00F9C3F6 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
3CE331831D96E19100F9C3F6 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
3CE606882D1109EC0073BB73 /* sdf_gen2d.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sdf_gen2d.h; sourceTree = "<group>"; };
3CE994692AFB26820073A973 /* gamecontrollerdb.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = gamecontrollerdb.txt; sourceTree = "<group>"; };
3CFEBE4226930B91006D9974 /* DragonBones */ = {isa = PBXFileReference; lastKnownFileType = folder; path = DragonBones; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -4845,7 +4845,7 @@
3CDED0311E52A2D300B5E578 /* Other */ = {
isa = PBXGroup;
children = (
3C1A452E2D0B48FF0025084B /* SdfBuilder.h */,
3CE606882D1109EC0073BB73 /* sdf_gen2d.h */,
3C592EAF2CA4F57100CAF224 /* AcfDelegate.h */,
3C592EB02CA4F57100CAF224 /* atlas.h */,
3C592EB12CA4F57100CAF224 /* atlas.cpp */,
Expand Down
4 changes: 2 additions & 2 deletions Projects/macOS/Dora.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@
3C030CA024CABDFD0074786E /* DecisionTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecisionTree.h; sourceTree = "<group>"; };
3C0C774A27573F350030BDCD /* Data */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Data; sourceTree = "<group>"; };
3C0EBE2F1E2DB3FB0066450A /* libbx.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbx.a; path = ../../Source/3rdParty/BGFX/Lib/macOS/libbx.a; sourceTree = "<group>"; };
3C1A452D2D0979A00025084B /* SdfBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SdfBuilder.h; sourceTree = "<group>"; };
3C1D40EE2702FD7C00202534 /* Class.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Class.lua; sourceTree = "<group>"; };
3C1D40EF2702FD7C00202534 /* Initialization.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Initialization.lua; sourceTree = "<group>"; };
3C1D40F02702FD7C00202534 /* tl.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tl.lua; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1959,6 +1958,7 @@
3CE331521D96D12200F9C3F6 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
3CE331561D96D30100F9C3F6 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
3CE331641D96D56C00F9C3F6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
3CE606872D1108F50073BB73 /* sdf_gen2d.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sdf_gen2d.h; sourceTree = "<group>"; };
3CE7D3731EADF594008EADB3 /* libbimg_decode.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbimg_decode.a; path = ../../Source/3rdParty/BGFX/Lib/macOS/libbimg_decode.a; sourceTree = "<group>"; };
3CE7D3741EADF594008EADB3 /* libbimg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbimg.a; path = ../../Source/3rdParty/BGFX/Lib/macOS/libbimg.a; sourceTree = "<group>"; };
3CE994632AFA43680073A973 /* gamecontrollerdb.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = gamecontrollerdb.txt; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3908,7 +3908,7 @@
3CC54E5E1E039E1300462FD7 /* Other */ = {
isa = PBXGroup;
children = (
3C1A452D2D0979A00025084B /* SdfBuilder.h */,
3CE606872D1108F50073BB73 /* sdf_gen2d.h */,
3C5936E82CA4FA5B00CAF224 /* AcfDelegate.h */,
3C5936E92CA4FA5B00CAF224 /* atlas.h */,
3C5936EA2CA4FA5B00CAF224 /* atlas.cpp */,
Expand Down
92 changes: 46 additions & 46 deletions Source/3rdParty/Other/sdf_gen2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,47 @@ class sdf_fgen2d {

std::pair<std::unique_ptr<uint8_t[]>, uint32_t> build(uint8_t* bitmap, int width, int height, float dist_scale = 20.0f) {
assert(width > 0 && height > 0);
m_width = static_cast<uint32_t>(width);
m_height = static_cast<uint32_t>(height);
uint32_t size = width * height;
auto m_grid_out = std::make_unique<sdf_point2d[]>(size);
auto m_grid_in = std::make_unique<sdf_point2d[]>(size);

for (uint32_t i = 0; i < size; ++i) {
m_grid_out[i] = empty;
m_grid_in[i] = inside;
m_width = width;
m_height = height;
int size = width * height;
auto grid_out = std::make_unique<sdf_point2d[]>(size);
auto grid_in = std::make_unique<sdf_point2d[]>(size);

for (int i = 0; i < size; ++i) {
grid_out[i] = empty;
grid_in[i] = inside;
}

for (int y = 1; y < height - 1; ++y) {
for (int x = 1; x < width - 1; ++x) {
unsigned char val = bitmap[y * width + x];
uint8_t val = bitmap[y * width + x];
if (val > 128) {
m_grid_out[y * width + x] = inside;
m_grid_out[(y - 1) * width + x] = inside;
m_grid_out[(y)*width + x - 1] = inside;
m_grid_out[(y + 1) * width + x] = inside;
m_grid_out[(y)*width + x + 1] = inside;
m_grid_out[(y - 1) * width + x - 1] = inside;
m_grid_out[(y - 1) * width + x + 1] = inside;
m_grid_out[(y + 1) * width + x - 1] = inside;
m_grid_out[(y + 1) * width + x + 1] = inside;
m_grid_in[y * width + x] = empty;
grid_out[y * width + x] = inside;
grid_out[(y - 1) * width + x] = inside;
grid_out[(y)*width + x - 1] = inside;
grid_out[(y + 1) * width + x] = inside;
grid_out[(y)*width + x + 1] = inside;
grid_out[(y - 1) * width + x - 1] = inside;
grid_out[(y - 1) * width + x + 1] = inside;
grid_out[(y + 1) * width + x - 1] = inside;
grid_out[(y + 1) * width + x + 1] = inside;
grid_in[y * width + x] = empty;
}
}
}

generate_sdf(m_grid_out.get());
generate_sdf(m_grid_in.get());
generate_sdf(grid_out.get());
generate_sdf(grid_in.get());

auto ret = std::make_unique<uint8_t[]>(size);
int remain = size % 4;

for (int i = 0; i < size - remain; i += 4) {
ktm::fvec4 outx = ktm::fvec4(m_grid_out[i].x, m_grid_out[i + 1].x, m_grid_out[i + 2].x, m_grid_out[i + 3].x);
ktm::fvec4 outy = ktm::fvec4(m_grid_out[i].y, m_grid_out[i + 1].y, m_grid_out[i + 2].y, m_grid_out[i + 3].y);
ktm::fvec4 outx = ktm::fvec4(grid_out[i].x, grid_out[i + 1].x, grid_out[i + 2].x, grid_out[i + 3].x);
ktm::fvec4 outy = ktm::fvec4(grid_out[i].y, grid_out[i + 1].y, grid_out[i + 2].y, grid_out[i + 3].y);
ktm::fvec4 dist1 = ktm::sqrt(outx * outx + outy * outy);
ktm::fvec4 inx = ktm::fvec4(m_grid_in[i].x, m_grid_in[i + 1].x, m_grid_in[i + 2].x, m_grid_in[i + 3].x);
ktm::fvec4 iny = ktm::fvec4(m_grid_in[i].y, m_grid_in[i + 1].y, m_grid_in[i + 2].y, m_grid_in[i + 3].y);
ktm::fvec4 inx = ktm::fvec4(grid_in[i].x, grid_in[i + 1].x, grid_in[i + 2].x, grid_in[i + 3].x);
ktm::fvec4 iny = ktm::fvec4(grid_in[i].y, grid_in[i + 1].y, grid_in[i + 2].y, grid_in[i + 3].y);
ktm::fvec4 dist2 = ktm::sqrt(inx * inx + iny * iny);
ktm::fvec4 dist = dist2 - dist1;
ktm::svec4 group_c = ktm::svec4(dist * dist_scale + 180.f);
Expand All @@ -81,8 +81,8 @@ class sdf_fgen2d {
}

for (int i = 0; i < remain; ++i) {
float dist1 = sqrtf(static_cast<float>(dist_square(m_grid_out[i])));
float dist2 = sqrtf(static_cast<float>(dist_square(m_grid_in[i])));
float dist1 = sqrtf(static_cast<float>(dist_square(grid_out[i])));
float dist2 = sqrtf(static_cast<float>(dist_square(grid_in[i])));
float dist = dist2 - dist1;

int c = round(dist * dist_scale) + 180.f;
Expand Down Expand Up @@ -172,7 +172,7 @@ class sdf_fgen2d {
}
}

uint32_t m_width = 0, m_height = 0;
int m_width = 0, m_height = 0;
};

class sdf_igen2d {
Expand All @@ -192,34 +192,34 @@ class sdf_igen2d {

std::pair<std::unique_ptr<uint8_t[]>, uint32_t> build(uint8_t* bitmap, int width, int height) {
assert(width > 0 && height > 0);
m_width = static_cast<uint32_t>(width);
m_height = static_cast<uint32_t>(height);
uint32_t size = width * height;
auto m_grid_out = std::make_unique<sdf_point2d[]>(size);
auto m_grid_in = std::make_unique<sdf_point2d[]>(size);

for (uint32_t i = 0; i < size; ++i) {
m_grid_out[i] = empty;
m_grid_in[i] = inside;
m_width = width;
m_height = height;
int size = width * height;
auto grid_out = std::make_unique<sdf_point2d[]>(size);
auto grid_in = std::make_unique<sdf_point2d[]>(size);

for (int i = 0; i < size; ++i) {
grid_out[i] = empty;
grid_in[i] = inside;
}

for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
unsigned char val = bitmap[y * width + x];
uint8_t val = bitmap[y * width + x];
if (val > 128) {
m_grid_out[y * width + x] = inside;
m_grid_in[y * width + x] = empty;
grid_out[y * width + x] = inside;
grid_in[y * width + x] = empty;
}
}
}
GenerateSDF(m_grid_out.get());
GenerateSDF(m_grid_in.get());
GenerateSDF(grid_out.get());
GenerateSDF(grid_in.get());
auto ret = std::make_unique<uint8_t[]>(size);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
// Calculate the actual distance from the dx/dy
int dist1 = (int)(sqrt((double)Get(m_grid_out.get(), x, y).DistSq()));
int dist2 = (int)(sqrt((double)Get(m_grid_in.get(), x, y).DistSq()));
int dist1 = (int)(sqrt((double)Get(grid_out.get(), x, y).DistSq()));
int dist2 = (int)(sqrt((double)Get(grid_in.get(), x, y).DistSq()));
int dist = dist2 - dist1;

// Clamp and scale it, just for display purposes.
Expand Down Expand Up @@ -291,7 +291,7 @@ class sdf_igen2d {
}

private:
uint32_t m_width = 0, m_height = 0;
int m_width = 0, m_height = 0;
};

using sdf_gen2d = sdf_igen2d; // sdf_fgen2d
Expand Down

0 comments on commit 410f361

Please sign in to comment.