2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-06-30 19:03:42 -04:00

Review and cleanup

- General cleanup.
- Fixed missing functions from raymath.
- Nuget info part of project file.
This commit is contained in:
2018-10-20 13:16:58 +01:00
parent a9da337c0e
commit fc0527a2ef
17 changed files with 276 additions and 341 deletions

View File

@ -3,7 +3,7 @@ using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace Raylibcs
namespace Generator
{
static class Generator
{
@ -36,10 +36,6 @@ namespace Raylibcs
{
//Console.WriteLine(match.Value);
}
// Console.WriteLine(matches.Count);
//return input;
//var match = Regex.IsMatch(input, pattern);
return Regex.Replace(input, pattern, replacement);
}
@ -71,9 +67,6 @@ namespace Raylibcs
//output += text;
output += "\n}";
// convert syntax to c#
//output = template.Replace("{{ CONTENT }}", output);
output = output.Replace("(void)", "()");
output = output.Replace("const char *", "string ");
output = output.Replace("const char * ", "string");
@ -99,12 +92,6 @@ namespace Raylibcs
// Design is close to raylib so only a few changes needed
public static void ProcessExample(string file, string folder, string path)
{
// fix #defines
// fix structs
// fix enums
// remove return 0 for main
// fix {} initialization(not all cases covered)
// load and setup
var fileName = Path.GetFileNameWithoutExtension(file);
var text = File.ReadAllText(file);

View File

@ -1,41 +1,46 @@
using System;
using System.IO;
namespace Raylibcs
namespace Generator
{
/// <summary>
/// Rough generator for Raylib-cs to help automate binding + porting raylib code
/// Output will still need to be modified
/// Rough generator for creating bindings and ports for raylib
/// Not a full parser so generated code is not perfect
/// </summary>
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Raylib-cs generator");
GenerateBindings();
GenerateExamples();
GenerateTemplates();
GenerateGames();
// GeneratePort("Examples");
// GeneratePort("Templates");
// GeneratePort("Games");
Console.WriteLine("Finished generating. Enjoy! :)");
Console.WriteLine("Press enter to exit");
Console.Read();
}
/// <summary>
/// Requires raylib headers
/// </summary>
static void GenerateBindings()
{
Console.WriteLine("Generating bindings");
Generator.Process("raylib.h", "RLAPI");
Generator.Process("raymath.h", "RMDEF");
Generator.Process("physac.h", "PDEF");
Generator.Process("rlgl.h", "RLGL");
}
static void GenerateExamples()
/// <summary>
/// Porting C to C#
/// </summary>
static void GeneratePort(string folder)
{
Console.WriteLine("Generating examples");
// output folder
var folder = "Examples";
Directory.CreateDirectory(folder);
var path = Generator.RaylibDirectory + folder.ToLower();
var dirs = Directory.GetDirectories(path);
@ -51,75 +56,5 @@ namespace Raylibcs
Generator.ProcessExample(file, folder, folder + "//" + name);
}
}
static void GenerateTemplates()
{
Console.WriteLine("Generating templates");
// output folder
var folder = "Templates";
Directory.CreateDirectory(folder);
var path = Generator.RaylibDirectory2 + folder.ToLower();
var dirs = Directory.GetDirectories(path);
// copy folder structure
foreach (string dirPath in Directory.GetDirectories(path, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(path, folder));
// process all c files in directory and output result
var files = Directory.GetFiles(path, "*.c", SearchOption.AllDirectories);
foreach (var file in files)
{
var dirName = Path.GetDirectoryName(file);
var name = new DirectoryInfo(dirName).Name;
if (name == folder.ToLower())
{
Generator.ProcessExample(file, folder, folder);
}
else
{
var t = file;
t = folder + t.Replace(path, "");
t = new FileInfo(t).Directory.FullName;
Generator.ProcessExample(file, folder, t);
}
}
}
static void GenerateGames()
{
Console.WriteLine("Generating games");
// output folder
var folder = "Games";
Directory.CreateDirectory(folder);
var path = Generator.RaylibDirectory2 + folder.ToLower();
var dirs = Directory.GetDirectories(path);
// copy folder structure
foreach (string dirPath in Directory.GetDirectories(path, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(path, folder));
// process all c files in directory and output result
var files = Directory.GetFiles(path, "*.c", SearchOption.AllDirectories);
foreach (var file in files)
{
var dirName = Path.GetDirectoryName(file);
var name = new DirectoryInfo(dirName).Name;
if (name == folder.ToLower())
{
Generator.ProcessExample(file, folder, folder);
}
else
{
var t = file;
t = folder + t.Replace(path, "");
t = new FileInfo(t).Directory.FullName;
Generator.ProcessExample(file, folder, t);
}
}
}
}
}