This commit is contained in:
Braedon Lewis 2023-03-19 13:57:40 -04:00
parent b49ad727ee
commit f4d56129de
62 changed files with 1201 additions and 3308 deletions

7
.gitignore vendored
View file

@ -1,3 +1,10 @@
## Beef
build
BeefSpace_User.toml
dist
*.zip
## Visual Studio & CS
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
## ##

View file

@ -1,6 +0,0 @@
FileVersion = 1
[Project]
Name = "raylib-beef"
StartupObject = "beef.Program"
DefaultNamespace = "beef"

View file

@ -1,113 +0,0 @@
FileVersion = 1
LastConfig = "Debug"
LastPlatform = "Win64"
RecentFilesList = ["src\\Program.bf"]
[MainWindow]
X = -1840
Y = 127
Width = 1468
Height = 908
ShowKind = "Maximized"
[MainDockingFrame]
Type = "DockingFrame"
SplitType = 2
[[MainDockingFrame.DockedWidgets]]
RequestedWidth = 350.0
RequestedHeight = 200.0
SizePriority = 200.0
Type = "DockingFrame"
SplitType = 1
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
RequestedWidth = 200.0
RequestedHeight = 200.0
Type = "TabbedView"
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
Active = true
TabLabel = "Workspace"
TabWidth = 115.0
Type = "ProjectPanel"
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
IsFillWidget = true
Permanent = true
RequestedWidth = 150.0
RequestedHeight = 150.0
SizePriority = 150.0
DefaultDocumentsTabbedView = true
Type = "TabbedView"
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
Active = true
TabLabel = "Program.bf"
TabWidth = 106.0
Type = "SourceViewPanel"
FilePath = "src\\Program.bf"
CursorPos = 76
ProjectName = "raylib-beef"
[[MainDockingFrame.DockedWidgets]]
RequestedWidth = 250.0
RequestedHeight = 250.0
Type = "DockingFrame"
SplitType = 1
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
RequestedWidth = 250.0
RequestedHeight = 250.0
SizePriority = 0.2994652
Type = "TabbedView"
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
TabLabel = "Memory"
TabWidth = 99.0
Type = "MemoryPanel"
AutoResize = "Auto_Mul8"
RequestedWidth = 300.0
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
TabLabel = "Watch"
TabWidth = 86.0
Type = "WatchPanel"
Columns = [{Width = 200.0}, {Width = 200.0}, {Width = 200.0}]
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
Active = true
TabLabel = "Auto"
TabWidth = 77.0
Type = "AutoWatchPanel"
Columns = [{Width = 200.0}, {Width = 200.0}, {Width = 200.0}]
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
RequestedWidth = 250.0
RequestedHeight = 250.0
SizePriority = 0.7005348
Type = "TabbedView"
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
TabLabel = "Threads"
TabWidth = 97.0
Type = "ThreadPanel"
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
TabLabel = "Call Stack"
TabWidth = 105.0
Type = "CallStackPanel"
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
TabLabel = "Immediate"
TabWidth = 111.0
Type = "ImmediatePanel"
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
Active = true
TabLabel = "Output"
TabWidth = 90.0
Type = "OutputPanel"
[[BookmarkFolders]]
Title = ""

View file

@ -1,2 +0,0 @@
IDE Process 8516
-out:c:\Dev\raylib-beef\beef\build\Debug_Win64\raylib-beef\raylib-beef.exe C:\Dev\raylib-beef\beef/build/Debug_Win64/corlib/corlib__.lib C:\Dev\raylib-beef\beef/build/Debug_Win64/raylib-beef/raylib-beef__.lib C:\Dev\raylib-beef\beef/build/Debug_Win64/raylib-beef/vdata.obj -defaultlib:libcmtd -nologo -incremental:no -pdb:c:\Dev\raylib-beef\beef\build\Debug_Win64\raylib-beef\raylib-beef.pdb -debug -opt:noref -libpath:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64" -libpath:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\ucrt\x64" -libpath:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\lib\x64" -libpath:"C:\Program Files\BeefLang\bin\lib\x64" -libpath:c:\Dev\raylib-beef\beef\build\Debug_Win64\raylib-beef Beef042RT64.lib Beef042Dbg64.lib /ignore:4099

File diff suppressed because it is too large Load diff

View file

@ -1,11 +0,0 @@
namespace beef;
using Raylib;
class Program
{
public static int Main()
{
return 0;
}
}

View file

@ -1,25 +0,0 @@
using System;
namespace Raylib;
ty
[CRepr]
public struct RenderTexture
{
// OpenGL framebuffer object id
public int id;
// Color buffer attachment texture
public Texture texture;
// Depth buffer attachment texture
public Texture depth;
public this(int id, Texture texture, Texture depth)
{
this.id = id;
this.texture = texture;
this.depth = depth;
}
}

View file

@ -1,2 +0,0 @@
c:\Dev\raylib-beef\beef\src\test\Material.bf BFC698AC4E10695ED31AAB47ADBB91F6 0880BB8D2D2DD86E15919D346569685C 222
c:\Dev\raylib-beef\beef\src\test\Raylib.bf 23F18076295C7EFD5C4FB3F597CD1B2D 1578C895B1171CBF04FBBB82851AC82F 88968

View file

@ -1,11 +0,0 @@
namespace beef;
using Raylib;
class Program
{
public static int Main()
{
return 0;
}
}

View file

@ -13,20 +13,31 @@ namespace RaylibBeefGenerator
// Current Output Beef Code // Current Output Beef Code
private static StringBuilder OutputString = new StringBuilder(); private static StringBuilder OutputString = new StringBuilder();
private static string OutputDir = @"C:\Dev\raylib-beef\beef\src\test\"; private static string OutputDir = @"C:\Dev\raylib-beef\raylib-beef\src\test\";
private static Root API; private static Root API;
#region Output Defines #region Output Defines
private static string ImportLib = "raylib.dll";
private static string Namespace = "Raylib"; private static string Namespace = "Raylib";
#endregion #endregion
// TODO:
// Defines
// Enums
// Other things like RLGL and stuff.
// Output generated code to actual directory.
// Organize Beef project.
public static void Main(string[] args) public static void Main(string[] args)
{ {
string raylibjson = @"C:\Dev\raylib-beef\raylib-api\raylib.json"; string raylibjson = @"C:\Dev\raylib-beef\raylib-api\raylib.json";
API = JsonConvert.DeserializeObject<Root>(File.ReadAllText(raylibjson)); API = JsonConvert.DeserializeObject<Root>(File.ReadAllText(raylibjson));
Console.WriteLine($"Generating files at {OutputDir}");
Console.WriteLine($"...");
RaylibBf(); RaylibBf();
for (int i = 0; i < API.Structs.Count; i++) for (int i = 0; i < API.Structs.Count; i++)
@ -47,13 +58,16 @@ namespace RaylibBeefGenerator
var callback = API.Callbacks[i]; var callback = API.Callbacks[i];
if (!string.IsNullOrEmpty(callback.Description)) AppendLine($"/// {callback.Description}"); if (!string.IsNullOrEmpty(callback.Description)) AppendLine($"/// {callback.Description}");
AppendLine($"public function {callback.ReturnType.ConvertTypes()} {callback.Name}({callback.Params.Parameters2String()});"); AppendLine($"public function {callback.ReturnType.ConvertTypes()} {callback.Name.ConvertName()}({callback.Params.Parameters2String()});");
AppendLine(""); AppendLine("");
} }
DecreaseTab(); DecreaseTab();
AppendLine("}"); AppendLine("}");
WriteToFile("Callbacks"); WriteToFile("Callbacks");
Console.WriteLine("Successfully Generated Bindings!");
Console.ReadLine();
} }
public static void StructBf(Struct structu) public static void StructBf(Struct structu)
@ -63,11 +77,14 @@ namespace RaylibBeefGenerator
UniversalHeader(); UniversalHeader();
var alias = API.Aliases.Find(c => c.Type == structu.Name); var alias = API.Aliases.FindAll(c => c.Type == structu.Name);
if (alias != null) if (alias != null)
{ {
AppendLine($"typealias {alias.Name} = {alias.Type};"); for (int i = 0; i < alias.Count; i++)
AppendLine(""); {
AppendLine($"typealias {alias[i].Name} = {alias[i].Type};");
}
if (alias.Count > 0) AppendLine("");
} }
AppendLine($"[CRepr]"); AppendLine($"[CRepr]");
@ -80,11 +97,15 @@ namespace RaylibBeefGenerator
for (int i = 0; i < structu.Fields.Count; i++) for (int i = 0; i < structu.Fields.Count; i++)
{ {
var field = structu.Fields[i]; var field = structu.Fields[i];
// This is like the only thing that is hardcoded, and that saddens me.
if (field.Type == "rAudioProcessor *" || field.Type == "rAudioBuffer *") continue;
AppendLine($"/// {field.Description}"); AppendLine($"/// {field.Description}");
AppendLine($"public {field.Type.ConvertTypes()} {field.Name.ConvertName()};"); AppendLine($"public {field.Type.ConvertTypes()} {field.Name.ConvertName()};");
AppendLine(""); AppendLine("");
constructorLine += $"{field.Type.ConvertTypes()} {field.Name}"; constructorLine += $"{field.Type.ConvertTypes()} {field.Name.ConvertName()}";
if (i < structu.Fields.Count - 1) constructorLine += ", "; if (i < structu.Fields.Count - 1) constructorLine += ", ";
} }
@ -96,7 +117,9 @@ namespace RaylibBeefGenerator
for (int i = 0; i < structu.Fields.Count; i++) for (int i = 0; i < structu.Fields.Count; i++)
{ {
var field = structu.Fields[i]; var field = structu.Fields[i];
AppendLine($"this.{field.Name} = {field.Name};"); if (field.Type == "rAudioProcessor *" || field.Type == "rAudioBuffer *") continue;
AppendLine($"this.{field.Name.ConvertName()} = {field.Name.ConvertName()};");
} }
DecreaseTab(); DecreaseTab();
@ -116,12 +139,25 @@ namespace RaylibBeefGenerator
AppendLine("static"); AppendLine("static");
AppendLine("{"); AppendLine("{");
IncreaseTab(); IncreaseTab();
AppendLine($"/// Used internally for bindings.");
AppendLine($"public const String RAYLIB_LIB = \"{ImportLib}\";");
AppendLine("");
// Skip first one, no value.
for (int i = 1; i < API.Defines.Count; i++)
{
var define = API.Defines[i];
// AppendLine($"public static {define.Type.ConvertTypes()} {define.Name.ConvertName()} = ")
}
for (int i = 0; i < API.Functions.Count; i++) for (int i = 0; i < API.Functions.Count; i++)
{ {
var func = API.Functions[i]; var func = API.Functions[i];
AppendLine($"[CallingConvention(.Cdecl), LinkName(\"{func.Name}\")]"); AppendLine($"[Import(RAYLIB_LIB), CallingConvention(.Cdecl), LinkName(\"{func.Name}\")]");
AppendLine($"/// {func.Description}"); AppendLine($"/// {func.Description}");
AppendLine($"public static extern {func.ReturnType.ConvertTypes()} {func.Name.ConvertName()}({Parameters2String(func.Params)});"); AppendLine($"public static extern {func.ReturnType.ConvertTypes()} {func.Name.ConvertName()}({Parameters2String(func.Params)});");
AppendLine(""); AppendLine("");
@ -162,6 +198,7 @@ namespace RaylibBeefGenerator
public static void WriteToFile(string name) public static void WriteToFile(string name)
{ {
File.WriteAllText(OutputDir + name + ".bf", OutputString.ToString()); File.WriteAllText(OutputDir + name + ".bf", OutputString.ToString());
Console.WriteLine($"Generated {name}.bf");
} }
/// <summary> /// <summary>
@ -169,9 +206,12 @@ namespace RaylibBeefGenerator
/// </summary> /// </summary>
public static string ConvertTypes(this string input) public static string ConvertTypes(this string input)
{ {
if (input == "unsigned char") return "uint8"; // idunno
input = ReplaceWholeWord(input, "char", "char8"); input = ReplaceWholeWord(input, "char", "char8");
input = ReplaceWholeWord(input, "long", "int32"); input = ReplaceWholeWord(input, "long", "int32");
input = ReplaceWholeWord(input, "va_list", "void*"); input = ReplaceWholeWord(input, "va_list", "void*");
input = ReplaceWholeWord(input, "short", "uint16");
if (input.StartsWith("const")) if (input.StartsWith("const"))
input = input.Remove(0, 6); input = input.Remove(0, 6);

View file

@ -133,7 +133,7 @@
"description": "" "description": ""
}, },
{ {
"name": "LIGHTGRAY", "name": "",
"type": "COLOR", "type": "COLOR",
"value": "CLITERAL(Color){ 200, 200, 200, 255 }", "value": "CLITERAL(Color){ 200, 200, 200, 255 }",
"description": "Light Gray" "description": "Light Gray"

14
raylib-beef/BeefProj.toml Normal file
View file

@ -0,0 +1,14 @@
FileVersion = 1
[Project]
Name = "raylib-beef"
StartupObject = "beef.Program"
DefaultNamespace = "Raylib"
[Configs.Debug.Win64]
CLibType = "DynamicDebug"
LibPaths = ["$(ProjectDir)\\dist\\x64\\raylib.lib"]
[Configs.Release.Win64]
CLibType = "Dynamic"
LibPaths = ["$(ProjectDir)\\dist\\x64\\raylib.lib"]

View file

@ -0,0 +1,24 @@
using System;
using System.Interop;
namespace Raylib;
[CRepr]
public struct AudioStream
{
/// Frequency (samples per second)
public int sampleRate;
/// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
public int sampleSize;
/// Number of channels (1-mono, 2-stereo, ...)
public int channels;
public this(int sampleRate, int sampleSize, int channels)
{
this.sampleRate = sampleRate;
this.sampleSize = sampleSize;
this.channels = channels;
}
}

View file

@ -0,0 +1,14 @@
FileVersion = 1
[Project]
Name = "raylib-beef"
StartupObject = "beef.Program"
DefaultNamespace = "Raylib"
[Configs.Debug.Win64]
CLibType = "DynamicDebug"
LibPaths = ["$(ProjectDir)\\dist\\x64\\raylib.lib"]
[Configs.Release.Win64]
CLibType = "Dynamic"
LibPaths = ["$(ProjectDir)\\dist\\x64\\raylib.lib"]

View file

@ -19,6 +19,6 @@ public struct Material
{ {
this.shader = shader; this.shader = shader;
this.maps = maps; this.maps = maps;
this.params = @params; this.@params = @params;
} }
} }

View file

@ -0,0 +1,21 @@
namespace beef;
using Raylib;
class Program
{
public static int Main()
{
InitWindow(1280, 720, "Raylib Beef");
while (!WindowShouldClose())
{
BeginDrawing();
DrawText("Hello!", 20, 20, 20, Color(200, 200, 200, 255));
EndDrawing();
}
CloseWindow();
return 0;
}
}

View file

@ -0,0 +1,2 @@
c:\Dev\raylib-beef\raylib-beef\src\Program.bf C8BF3BBC68E6F725F4EF92FA2E4588A4 ACC24C233D8B9895C0C5C8F9B5E2599B 234
c:\Dev\raylib-beef\raylib-beef\src\test\Raylib.bf 1578C895B1171CBF04FBBB82851AC82F B92351C2B34DAC710F0D51092D2E0F9B 116

View file

@ -0,0 +1,21 @@
namespace beef;
using Raylib;
class Program
{
public static int Main()
{
InitWindow(1280, 720, "Raylib Beef");
while (!WindowShouldClose())
{
BeginDrawing();
DrawText("Hello!", 20, 20, 20, Color(200, 200, 200, 255));
EndDrawing();
}
CloseWindow();
return 0;
}
}

View file

@ -6,12 +6,6 @@ namespace Raylib;
[CRepr] [CRepr]
public struct AudioStream public struct AudioStream
{ {
/// Pointer to internal data used by the audio system
public rAudioBuffer * buffer;
/// Pointer to internal data processor, useful for audio effects
public rAudioProcessor * processor;
/// Frequency (samples per second) /// Frequency (samples per second)
public int sampleRate; public int sampleRate;
@ -21,10 +15,8 @@ public struct AudioStream
/// Number of channels (1-mono, 2-stereo, ...) /// Number of channels (1-mono, 2-stereo, ...)
public int channels; public int channels;
public this(rAudioBuffer * buffer, rAudioProcessor * processor, int sampleRate, int sampleSize, int channels) public this(int sampleRate, int sampleSize, int channels)
{ {
this.buffer = buffer;
this.processor = processor;
this.sampleRate = sampleRate; this.sampleRate = sampleRate;
this.sampleSize = sampleSize; this.sampleSize = sampleSize;
this.channels = channels; this.channels = channels;

View file

@ -7,18 +7,18 @@ namespace Raylib;
public struct Color public struct Color
{ {
/// Color red value /// Color red value
public char8 r; public uint8 r;
/// Color green value /// Color green value
public char8 g; public uint8 g;
/// Color blue value /// Color blue value
public char8 b; public uint8 b;
/// Color alpha value /// Color alpha value
public char8 a; public uint8 a;
public this(char8 r, char8 g, char8 b, char8 a) public this(uint8 r, uint8 g, uint8 b, uint8 a)
{ {
this.r = r; this.r = r;
this.g = g; this.g = g;

View file

@ -19,6 +19,6 @@ public struct Material
{ {
this.shader = shader; this.shader = shader;
this.maps = maps; this.maps = maps;
this.params = @params; this.@params = @params;
} }
} }

View file

@ -31,7 +31,7 @@ public struct Mesh
public char8 * colors; public char8 * colors;
/// Vertex indices (in case vertex data comes indexed) /// Vertex indices (in case vertex data comes indexed)
public short * indices; public uint16 * indices;
/// Animated vertex positions (after bones transformations) /// Animated vertex positions (after bones transformations)
public float * animVertices; public float * animVertices;
@ -51,7 +51,7 @@ public struct Mesh
/// OpenGL Vertex Buffer Objects id (default vertex data) /// OpenGL Vertex Buffer Objects id (default vertex data)
public int * vboId; public int * vboId;
public this(int vertexCount, int triangleCount, float * vertices, float * texcoords, float * texcoords2, float * normals, float * tangents, char8 * colors, short * indices, float * animVertices, float * animNormals, char8 * boneIds, float * boneWeights, int vaoId, int * vboId) public this(int vertexCount, int triangleCount, float * vertices, float * texcoords, float * texcoords2, float * normals, float * tangents, char8 * colors, uint16 * indices, float * animVertices, float * animNormals, char8 * boneIds, float * boneWeights, int vaoId, int * vboId)
{ {
this.vertexCount = vertexCount; this.vertexCount = vertexCount;
this.triangleCount = triangleCount; this.triangleCount = triangleCount;

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,7 @@ using System.Interop;
namespace Raylib; namespace Raylib;
typealias Texture2D = Texture; typealias Texture2D = Texture;
typealias TextureCubemap = Texture;
[CRepr] [CRepr]
public struct Texture public struct Texture