init commit over here
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const raylib_dep = b.dependency("raylib_zig", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const lua_dep = b.dependency("zlua", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const raylib = raylib_dep.module("raylib");
|
||||
const raygui = raylib_dep.module("raygui");
|
||||
const raylib_artifact = raylib_dep.artifact("raylib");
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "MistoxEngine",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize
|
||||
});
|
||||
exe.linkLibrary(raylib_artifact);
|
||||
exe.root_module.addImport("raylib", raylib);
|
||||
exe.root_module.addImport("raygui", raygui);
|
||||
exe.root_module.addImport("zlua", lua_dep.module("zlua"));
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
.{
|
||||
// This is the default name used by packages depending on this one. For
|
||||
// example, when a user runs `zig fetch --save <url>`, this field is used
|
||||
// as the key in the `dependencies` table. Although the user can choose a
|
||||
// different name, most users will stick with this provided value.
|
||||
//
|
||||
// It is redundant to include "zig" in this name because it is already
|
||||
// within the Zig package namespace.
|
||||
.name = .MistoxEngine,
|
||||
|
||||
// This is a [Semantic Version](https://semver.org/).
|
||||
// In a future version of Zig it will be used for package deduplication.
|
||||
.version = "0.0.0",
|
||||
|
||||
// Together with name, this represents a globally unique package
|
||||
// identifier. This field is generated by the Zig toolchain when the
|
||||
// package is first created, and then *never changes*. This allows
|
||||
// unambiguous detection of one package being an updated version of
|
||||
// another.
|
||||
//
|
||||
// When forking a Zig project, this id should be regenerated (delete the
|
||||
// field and run `zig build`) if the upstream project is still maintained.
|
||||
// Otherwise, the fork is *hostile*, attempting to take control over the
|
||||
// original project's identity. Thus it is recommended to leave the comment
|
||||
// on the following line intact, so that it shows up in code reviews that
|
||||
// modify the field.
|
||||
.fingerprint = 0xc63be6cd2240c41e, // Changing this has security and trust implications.
|
||||
|
||||
// Tracks the earliest Zig version that the package considers to be a
|
||||
// supported use case.
|
||||
.minimum_zig_version = "0.15.0-dev.56+d0911786c",
|
||||
|
||||
// This field is optional.
|
||||
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
||||
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
|
||||
// Once all dependencies are fetched, `zig build` no longer requires
|
||||
// internet connectivity.
|
||||
.dependencies = .{
|
||||
.raylib_zig = .{
|
||||
.url = "git+https://github.com/Not-Nik/raylib-zig#d4fc514d54a3b37b9b3e4f4983f611c3469e8c2a",
|
||||
.hash = "raylib_zig-5.6.0-dev-KE8REHguBQAE0xoNkra7mtEqr8cCZHk7k_03txLZB-cZ",
|
||||
},
|
||||
.zlua = .{
|
||||
.url = "git+https://github.com/natecraddock/ziglua#320a91cb5ea93044b51c2e2a89b747063dfb0a33",
|
||||
.hash = "zlua-0.1.0-hGRpC7nIBACkB1YcjxLQwbqFbKwJBTW8HPBhGZzNUVL-",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src",
|
||||
// For example...
|
||||
//"LICENSE",
|
||||
//"README.md",
|
||||
},
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
|
||||
var _alloc: std.mem.Allocator = undefined;
|
||||
|
||||
pub const RenderMode = enum {
|
||||
twoD,
|
||||
threeD
|
||||
};
|
||||
|
||||
pub fn Init(Allocator: std.mem.Allocator, renderMode: RenderMode, targetFPS: i32, width: i32, height: i32, gameTitle: []const u8) void {
|
||||
_alloc = Allocator;
|
||||
rl.setTargetFPS(targetFPS);
|
||||
rl.initWindow(width, height, gameTitle);
|
||||
if (renderMode == .twoD ){
|
||||
while(!rl.windowShouldClose()){
|
||||
PhysicsUpdate();
|
||||
rl.beginDrawing();
|
||||
rl.beginMode2D(); // Needs 2D Camera input
|
||||
Render3D();
|
||||
rl.endMode2D();
|
||||
RenderUI();
|
||||
rl.endDrawing();
|
||||
}
|
||||
}else if (renderMode == .threeD){
|
||||
while(!rl.windowShouldClose()){
|
||||
PhysicsUpdate();
|
||||
rl.beginDrawing();
|
||||
rl.beginMode3D(); // Needs 3D Camera input
|
||||
Render3D();
|
||||
rl.endMode3D();
|
||||
RenderUI();
|
||||
rl.endDrawing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn PhysicsUpdate() void {
|
||||
|
||||
}
|
||||
|
||||
fn Render3D() void {
|
||||
|
||||
}
|
||||
|
||||
fn RenderUI() void {
|
||||
|
||||
}
|
||||
|
||||
|
||||
pub fn Destroy() void {
|
||||
rl.closeWindow();
|
||||
}
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
const std = @import("std");
|
||||
const zlua = @import("zlua");
|
||||
const lua = zlua.Lua;
|
||||
|
||||
const luafuncts = @import("Libraries/Test.zig");
|
||||
|
||||
pub var LuaRuntime: *zlua.Lua = undefined;
|
||||
|
||||
pub fn Init(allocator: std.mem.Allocator) !void {
|
||||
LuaRuntime = try lua.init(allocator);
|
||||
lua.openLibs(LuaRuntime);
|
||||
|
||||
// Add the mistox library
|
||||
CreateLibrary(luafuncts, "Mistox");
|
||||
}
|
||||
|
||||
|
||||
pub fn CreateMetaTable(MetaTableName: []const u8){
|
||||
lua.newMetatable(LuaRuntime, MetaTableName);
|
||||
}
|
||||
|
||||
|
||||
pub fn AddFnToLib(Function: zlua.CFn, FunctionName: []const u8 ) void {
|
||||
const str = lua.pushString(LuaRuntime, FunctionName);
|
||||
_ = str;
|
||||
lua.pushFunction(LuaRuntime, Function);
|
||||
lua.setTable(LuaRuntime, -3);
|
||||
}
|
||||
|
||||
fn CreateLibrary(LibraryFolder: type ,LibraryName: [:0]const u8) void {
|
||||
lua.newTable(LuaRuntime);
|
||||
LibraryFolder.ImportFns();
|
||||
lua.setGlobal(LuaRuntime, LibraryName);
|
||||
}
|
||||
|
||||
pub fn DeInit() void {
|
||||
LuaRuntime.deinit();
|
||||
}
|
||||
|
||||
const MetaTable_t = struct {
|
||||
Function: *usize,
|
||||
Name: []const u8
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
const std = @import("std");
|
||||
const Interop = @import("../Interop.zig");
|
||||
const zlua = @import("zlua");
|
||||
const lua = zlua.Lua;
|
||||
|
||||
pub fn ImportFns() void {
|
||||
Interop.AddFnToLib(add_numbers, "add");
|
||||
Interop.AddFnToLib(greet, "greet");
|
||||
}
|
||||
|
||||
fn add_numbers(luaState: ?*zlua.LuaState ) callconv(.c) c_int {
|
||||
const context: *zlua.Lua = @ptrCast(luaState.?); // Cast the LuaState to a Lua Runtime Object
|
||||
const num1 = lua.checkNumber(context, 1); // Get arguemnt 1 from the lua stack
|
||||
const num2 = lua.checkNumber(context, 2); // Get arguemnt 2 from the lua stack
|
||||
lua.pushNumber(context, num1 + num2); // Push result onto the lua stack
|
||||
return 1; // Number of results on lua stack
|
||||
}
|
||||
|
||||
fn greet(luaState: ?*zlua.LuaState ) callconv(.c) c_int {
|
||||
const context: *zlua.Lua = @ptrCast(luaState.?); // Cast the LuaState to a Lua Runtime Object
|
||||
const num1 = lua.checkString(context, 1); // Get arguemnt 1 from the lua stack
|
||||
std.debug.print("{s}", .{num1});
|
||||
return 0; // Number of results on lua stack
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
const std = @import("std");
|
||||
|
||||
const MaxFileDepth: u32 = 20;
|
||||
|
||||
fn StrConcat(Allocator: std.mem.Allocator, StrLeft: []const u8, StrRight: []const u8) ![]u8 {
|
||||
var StringBuilder: []u8 = undefined;
|
||||
StringBuilder = try Allocator.alloc(u8, StrLeft.len + StrRight.len);
|
||||
std.mem.copyForwards(u8, StringBuilder, StrLeft);
|
||||
std.mem.copyForwards(u8, StringBuilder[StrLeft.len..], StrRight);
|
||||
return StringBuilder;
|
||||
}
|
||||
|
||||
pub fn GetFilePathRelative(Allocator: std.mem.Allocator, FilePath: []const u8) ![]u8 {
|
||||
// Load Lua Main Funct
|
||||
const ExePath = try std.fs.selfExeDirPathAlloc(Allocator);
|
||||
defer Allocator.free(ExePath);
|
||||
|
||||
// Get the full path
|
||||
const FullPath = try StrConcat( Allocator, ExePath, FilePath );
|
||||
defer Allocator.free(FullPath);
|
||||
|
||||
// Calculate relative paths by traversing the path and going back up a link when it sees the '..'
|
||||
var PathSteps: [MaxFileDepth][]u8 = undefined;
|
||||
var LetterIndex: u16 = 0;
|
||||
var StartIndex: u16 = 0;
|
||||
var ListIndex: u16 = 0;
|
||||
for (FullPath) |cur| {
|
||||
if ((cur == '/' or cur == '\\') and LetterIndex != 0){
|
||||
const subStr = FullPath[StartIndex..LetterIndex];
|
||||
if (std.mem.eql(u8, subStr, "/..") or std.mem.eql(u8, subStr, "\\..")){
|
||||
ListIndex -= 1;
|
||||
}else{
|
||||
PathSteps[ListIndex] = subStr;
|
||||
ListIndex += 1;
|
||||
}
|
||||
StartIndex = LetterIndex;
|
||||
}
|
||||
LetterIndex += 1;
|
||||
}
|
||||
PathSteps[ListIndex] = FullPath[StartIndex..LetterIndex];
|
||||
ListIndex += 1;
|
||||
|
||||
// Concat all the strings together back into a path string
|
||||
LetterIndex = 0;
|
||||
var returnPath: []u8 = "";
|
||||
while (LetterIndex < ListIndex){
|
||||
const temp = try StrConcat(Allocator, returnPath, PathSteps[LetterIndex]);
|
||||
Allocator.free(returnPath);
|
||||
returnPath = temp;
|
||||
LetterIndex += 1;
|
||||
}
|
||||
|
||||
return returnPath;
|
||||
}
|
||||
|
||||
pub fn FileRead(Allocator: std.mem.Allocator, AbsolutePath: []const u8) ![]u8 {
|
||||
var file = try std.fs.cwd().openFile(AbsolutePath, .{});
|
||||
defer file.close();
|
||||
|
||||
var bufReader = std.io.bufferedReader(file.reader());
|
||||
var inStream = bufReader.reader();
|
||||
|
||||
const FileText = try inStream.readAllAlloc(Allocator, 10000);
|
||||
|
||||
return FileText;
|
||||
}
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
|
||||
const Vector3_t = rl.Vector3;
|
||||
|
||||
pub const Entity_t = struct {
|
||||
// Node
|
||||
Name: []const u8 = undefined,
|
||||
Parent: ?*Entity_t = undefined,
|
||||
Children: ?std.ArrayList(Entity_t) = undefined,
|
||||
// Transform -> rl.Transform
|
||||
// Transform.Position -> rl.Vector3
|
||||
Px: f32,
|
||||
Py: f32,
|
||||
Pz: f32,
|
||||
// Transform.Rotation -> rl.Quaternion
|
||||
Rx: f32,
|
||||
Ry: f32,
|
||||
Rz: f32,
|
||||
Rw: f32,
|
||||
// Transform.Scale -> rl.Vector3
|
||||
Sx: f32,
|
||||
Sy: f32,
|
||||
Sz: f32,
|
||||
// Collider <------ Needs to be flattened for SOA
|
||||
boundingRadius: f32 = 1,
|
||||
boundingCenter: Vector3_t = Vector3_t{.x=0,.y=0,.z=0},
|
||||
// Mesh
|
||||
meshData: rl.Mesh = undefined,
|
||||
meshMaterial: rl.Material = undefined,
|
||||
lod_Distance: f32 = 1,
|
||||
// Flags
|
||||
flag1: bool = false,
|
||||
flag2: bool = false,
|
||||
flag3: bool = false,
|
||||
flag4: bool = false,
|
||||
flag5: bool = false,
|
||||
flag6: bool = false,
|
||||
flag7: bool = false,
|
||||
flag8: bool = false,
|
||||
};
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
local x = Mistox.greet("hello world")
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
const std = @import("std");
|
||||
const LuaInterop = @import("Lua/Interop.zig");
|
||||
const Fs = @import("Mistox/IO.zig");
|
||||
|
||||
const Publish = false;
|
||||
pub fn main() !void {
|
||||
|
||||
// Create the allocator
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
defer _ = gpa.deinit();
|
||||
|
||||
// Initilize the lua runtime
|
||||
try LuaInterop.Init(allocator);
|
||||
defer LuaInterop.DeInit();
|
||||
|
||||
// Work on a method to auto detect all lua files
|
||||
var filePath: []const u8 = undefined;
|
||||
if (Publish){
|
||||
// Get the file path offset from the executable
|
||||
filePath = try Fs.GetFilePathRelative(allocator, "/../../../src/main.lua");
|
||||
defer allocator.free(filePath);
|
||||
|
||||
std.debug.print( "File Location To Load : {s}\n\n", .{filePath} );
|
||||
}else{
|
||||
// Use debug for now - I can remove this later
|
||||
filePath = "/home/derek/Desktop/MistoxEngine/src/main.lua";
|
||||
}
|
||||
|
||||
// Open the file and read all the content
|
||||
const FileContent = try Fs.FileRead(allocator, filePath);
|
||||
defer allocator.free(FileContent);
|
||||
|
||||
// Load lua files
|
||||
try LuaInterop.LuaRuntime.doString( @ptrCast( FileContent ) );
|
||||
}
|
||||
|
||||
|
||||
// 18004566004 - Auto insurance quote fix
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Reference in New Issue
Block a user