Skip to content

Commit e865e2d

Browse files
committed
Enhance function handling and refactor file modifications
- Added a loop in `ImGuiDefinitionsPatch.cs` to manage functions ending with '0', updating the ignored functions list accordingly. - Introduced a `FilePatch` struct in `ImGuiGenQuirksPostPatch.cs` to streamline file modification processes, eliminating the need for existence checks. - Updated `config.base.json` to include the new define `CIMGUI_VARGS0=1` for configuration purposes.
1 parent 2e5d818 commit e865e2d

32 files changed

+9421
-9567
lines changed

Generator/Caching/GenCacheFile.cs

Lines changed: 0 additions & 134 deletions
This file was deleted.

Generator/Caching/MurmurHash3.cs

Lines changed: 0 additions & 75 deletions
This file was deleted.

Generator/ImGuiDefinitionsPatch.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ protected override void PatchCompilation(CsCodeGeneratorConfig settings, CppComp
117117
}
118118
settings.ClassMappings.Add(mapping);
119119
}
120+
121+
foreach (var function in compilation.Functions)
122+
{
123+
if (function.Name.EndsWith('0'))
124+
{
125+
var name = function.Name.TrimEnd('0');
126+
settings.IgnoredFunctions.Add(name);
127+
if (settings.TryGetFunctionMapping(name, out var mapping))
128+
{
129+
mapping.ExportedName = function.Name;
130+
}
131+
else
132+
{
133+
settings.FunctionMappings.Add(new(function.Name, settings.GetCsFunctionName(name), null, [], []));
134+
}
135+
}
136+
}
120137
}
121138
}
122139
}

Generator/ImGuiGenQuirksPostPatch.cs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using HexaGen.Metadata;
44
using HexaGen.Patching;
5+
using System.Text;
56

67
public class ImGuiGenQuirksPostPatch : PostPatch
78
{
@@ -21,21 +22,63 @@ public override void Apply(PatchContext context, CsCodeGeneratorMetadata metadat
2122
// Pointer = unchecked((int)ImGuiDataType.Count),
2223

2324
var enumPath = Path.Combine(ImGuiOutputPath, "Enums/ImGuiDataTypePrivate.cs");
24-
if (File.Exists(enumPath))
25-
{
26-
File.WriteAllText(enumPath, File.ReadAllText(enumPath).Replace("unchecked((int)Count)", "unchecked((int)ImGuiDataType.Count)"));
27-
}
25+
FilePatch.Create(enumPath)
26+
.Replace("unchecked((int)Count)", "unchecked((int)ImGuiDataType.Count)")
27+
.Done();
2828

2929
// Fix for generator artifact in ImDrawData.cs
3030
// Where:
3131
// ImVector<ImTextureDataPtr>Ptr
3232
// but should be
3333
// ImVector<ImTextureDataPtr>
34+
//
35+
// Also:
36+
// ref Unsafe.AsRef<ImVector<ImTextureDataPtr>Ptr>(&Handle->Textures)
37+
// but should be
38+
// ref Unsafe.AsRef<ImVector<ImTextureDataPtr>>(Handle->Textures)
39+
3440
var imDrawDataPath = Path.Combine(ImGuiOutputPath, "Structs/ImDrawData.cs");
35-
if (File.Exists(imDrawDataPath))
41+
FilePatch.Create(imDrawDataPath)
42+
.Replace("ref Unsafe.AsRef<ImVector<ImTextureDataPtr>Ptr>(&Handle->Textures)", "ref Unsafe.AsRef<ImVector<ImTextureDataPtr>>(Handle->Textures)")
43+
.Replace("ImVector<ImTextureDataPtr>Ptr", "ImVector<ImTextureDataPtr>")
44+
.Done();
45+
}
46+
}
47+
48+
public ref struct FilePatch
49+
{
50+
string? path;
51+
StringBuilder? content;
52+
53+
public static FilePatch Create(string path)
54+
{
55+
return new FilePatch().WithTarget(path);
56+
}
57+
58+
public FilePatch WithTarget(string path)
59+
{
60+
this.path = path;
61+
content = null!;
62+
if (File.Exists(path))
3663
{
37-
File.WriteAllText(imDrawDataPath, File.ReadAllText(imDrawDataPath).Replace("ImVector<ImTextureDataPtr>Ptr", "ImVector<ImTextureDataPtr>"));
64+
content = new(File.ReadAllText(path));
3865
}
66+
return this;
67+
}
68+
69+
public readonly FilePatch Replace(string target, string replacement)
70+
{
71+
content?.Replace(target, replacement);
72+
return this;
73+
}
74+
75+
public FilePatch Done()
76+
{
77+
if (path == null || content == null) return this;
78+
File.WriteAllText(path, content.ToString());
79+
path = null;
80+
content = null;
81+
return this;
3982
}
4083
}
4184
}

Generator/config.base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"Usings": [ "System.Numerics" ],
3+
"Defines": [ "CIMGUI_VARGS0=1" ],
34
"ImportType": "FunctionTable",
45
"EnableExperimentalOptions": true,
56
"GenerateConstructorsForStructs": true,

Hexa.NET.ImGui/Generated/Constants/Constants.000.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace Hexa.NET.ImGui
1515
{
1616
public unsafe partial class ImGui
1717
{
18+
public const int CIMGUI_VARGS0 = 1;
19+
1820
public const int IMGUI_USE_WCHAR32 = 1;
1921

2022
public const int IMGUI_ENABLE_FREETYPE = 1;

0 commit comments

Comments
 (0)