init commit over here
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user