Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/DIFFERENCES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Replaced [`flxanimate`](https://github.com/Dot-Stuff/flxanimate) with [`flixel-animate`](https://github.com/MaybeMaru/flixel-animate) for better performance for texture atlases
- Replaced [`hxCodec`](https://github.com/polybiusproxy/hxCodec) with [`hxvlc`](https://github.com/ShadowEngineTeam/hxvlc) for better customizability in video cutscenes
- Replaced [`SScript`](https://github.com/ShadowEngineTeam/SScript) with [`ShadowScript`](https://github.com/ShadowEngineTeam/SScript) for better compatibility in HScripting
- Replaced [`linc_luajit`](https://github.com/ShadowEngineTeam/linc_luajit) with [`hxluau`](https://github.com/ShadowEngineTeam/hxluau) for better performance and compatibility in Lua scripting (we are so roblox)
- Mobile Support (duh)
- Applies OpenAL Soft Config For better audio
- Slightly more accurate FPS and less RAM Usage
Expand Down
8 changes: 4 additions & 4 deletions hmm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "openfl",
"type": "git",
"ref": "bd1a0223ef3a9d494b40b1e111cbd044a34dc947",
"ref": "bd1a0223ef3a9d494b40b1e111cbd044a34dc947",
"url": "https://github.com/ShadowEngineTeam/openfl"
},
{
Expand Down Expand Up @@ -43,10 +43,10 @@
"url": "https://github.com/MAJigsaw77/hxdiscord_rpc"
},
{
"name": "hxluajit",
"name": "hxluau",
"type": "git",
"ref": "015ca428e5dcc8e4f9ecea8a1be5958cf9cea7b1",
"url": "https://github.com/ShadowEngineTeam/hxluajit"
"ref": "7b1e703b80cc9d1196bd131d244e75ec183186a1",
"url": "https://github.com/ShadowEngineTeam/hxluau"
},
{
"name": "hxgamemode",
Expand Down
4 changes: 2 additions & 2 deletions project.hxp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Project extends HXProject
static final TITLE_MOBILE:String = "FNF: Shadow Engine";
static final EXECUTABLE:String = "ShadowEngine";
static final VERSION:String = "0.9.0";
static final BUILD_NUMBER:Int = 727;
static final BUILD_NUMBER:Int = 735;
static final COMPANY:String = "ShadowEngineTeam";
static final PACKAGE:String = "org.shadowengineteam.fnf";
static final MAIN_CLASS:String = "backend.Main";
Expand Down Expand Up @@ -397,7 +397,7 @@ class Project extends HXProject
includeHaxelib("flixel-animate");

if (FEATURE_LUA.isEnabled())
includeHaxelib("hxluajit");
includeHaxelib("hxluau");
if (FEATURE_HSCRIPT.isEnabled())
includeHaxelib("SScript");
if (FEATURE_VIDEOS.isEnabled())
Expand Down
4 changes: 2 additions & 2 deletions source/engine/import.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import backend.Discord;
import haxe.Json;
// Psych
#if FEATURE_LUA
import hxluajit.*;
import hxluajit.Types;
import hxluau.*;
import hxluau.Types;
import psychlua.*;
#else
import psychlua.LuaUtils;
Expand Down
20 changes: 17 additions & 3 deletions source/engine/psychlua/Convert.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package psychlua;
#if FEATURE_LUA
import haxe.Constraints.IMap;
import psychlua.FunkinLua.State;
import hxluajit.Types;
import hxluau.Types;

/**
* Some borrowed code from hxluajit-wrapper.
Expand All @@ -20,7 +20,7 @@ class Convert
callbacks.set(name, func);

Lua.pushstring(l, name);
Lua.pushcclosure(l, cpp.Callable.fromStaticFunction(handleCallback), 1);
Lua.pushcclosure(l, cpp.Callable.fromStaticFunction(handleCallback), name, 1);
Lua.setglobal(l, name);
}

Expand Down Expand Up @@ -105,7 +105,21 @@ class Convert
case type if (type == Lua.TTABLE):
ret = convertTable(l, idx);
case type if (type == Lua.TFUNCTION):
ret = new LuaFunction(cpp.Pointer.fromRaw(l), LuaL.ref(l, Lua.REGISTRYINDEX));
ret = new LuaFunction(cpp.Pointer.fromRaw(l), Lua.ref(l, Lua.REGISTRYINDEX));
case type if (type == Lua.TINTEGER):
var isInt:Int = 0;
var isIntPtr = cpp.Pointer.addressOf(isInt);
ret = Lua.tointeger64(l, idx, isIntPtr.raw);
case type if (type == Lua.TVECTOR):
// lua_tovector returns const float* so fuck you
var x:Float = 0, y:Float = 0, z:Float = 0, w:Float = 0;
untyped __cpp__("if (lua_type({0},{1}) == LUA_TVECTOR) {{ const float* _v = lua_tovector({0},{1}); {2} = _v[0]; {3} = _v[1]; {4} = _v[2]; {5} = _v[3]; }}", l, idx, x, y, z, w);
ret = [x, y, z, w];
case type if (type == Lua.TBUFFER):
var size:cpp.SizeT = 0;
var sizePtr = cpp.Pointer.addressOf(size);
var bufPtr:cpp.RawPointer<cpp.Void> = Lua.tobuffer(l, idx, sizePtr.raw);
ret = bufPtr != null ? cpp.Pointer.fromRaw(bufPtr) : null;
case type if (type == Lua.TUSERDATA || type == Lua.TLIGHTUSERDATA):
ret = cpp.Pointer.fromRaw(Lua.touserdata(l, idx));
case type if (type == Lua.TNIL):
Expand Down
49 changes: 31 additions & 18 deletions source/engine/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class FunkinLua

// LuaL.dostring(lua, CLENSE);

// Luau performance tweaks
Luau.enableCodegen(1);
Luau.bytecodeCacheSetCapacity(256);
Luau.setCompileOptions(2, 1, 0);

this.scriptName = scriptName.trim();
game.luaArray.push(this);

Expand Down Expand Up @@ -1785,18 +1790,21 @@ class FunkinLua
try
{
var isString:Bool = !FileSystem.exists(scriptName);
var result:Dynamic = null;
var status:Int = 0;
if (!isString)
result = #if MODS_ALLOWED sys.FileSystem.exists(scriptName) ? LuaL.dofile(lua, scriptName) : #end LuaL.dostring(lua, File.getContent(scriptName));
status = #if MODS_ALLOWED sys.FileSystem.exists(scriptName) ? LuaL.dofile(lua, scriptName) : #end LuaL.dostring(lua, File.getContent(scriptName));
else
result = LuaL.dostring(lua, scriptName);
status = LuaL.dostring(lua, scriptName);

var resultStr:String = Lua.tostring(lua, result);
if (resultStr != null && result != 0)
if (status != 0)
{
trace(resultStr);
CoolUtil.showPopUp(resultStr, 'Error on lua script!');
luaTrace('$scriptName\n$resultStr', true, false, FlxColor.RED);
var errorMsg:String = Lua.tostring(lua, -1);
Lua.pop(lua, 1);
if (errorMsg == null)
errorMsg = getErrorMessage(status);
trace(errorMsg);
CoolUtil.showPopUp(errorMsg, 'Error on lua script!');
luaTrace('$scriptName\n$errorMsg', true, false, FlxColor.RED);
lua = null;
return;
}
Expand Down Expand Up @@ -1850,8 +1858,19 @@ class FunkinLua
// Checks if it's not successful, then show a error.
if (status != Lua.OK)
{
var error:String = getErrorMessage(status);
luaTrace("ERROR (" + func + "): " + error, false, false, FlxColor.RED);
var errorStr:String;
var error:String = Lua.tostring(lua, -1);
if (error != null)
{
LuaL.traceback(lua, lua, error, 2);
errorStr = Lua.tostring(lua, -1);
Lua.pop(lua, 2);
}
else
{
errorStr = getErrorMessage(status);
}
luaTrace("ERROR (" + func + "): " + errorStr, false, false, FlxColor.RED);
return LuaUtils.Function_Continue;
}

Expand Down Expand Up @@ -1955,16 +1974,10 @@ class FunkinLua
if (lua == null)
return false;

var result:String = null;
Lua.getglobal(lua, variable);
result = Convert.fromLua(lua, -1);
final result:Bool = Lua.toboolean(lua, -1) == 1;
Lua.pop(lua, 1);

if (result == null)
{
return false;
}
return (result == 'true');
return result;
#else
return false;
#end
Expand Down
4 changes: 2 additions & 2 deletions source/engine/psychlua/LuaFunction.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package psychlua;

#if FEATURE_LUA
import hxluajit.Types;
import hxluau.Types;

/**
* Holds a Lua function that can be called from Haxe.
Expand Down Expand Up @@ -56,7 +56,7 @@ class LuaFunction
{
if (l != null)
{
LuaL.unref(l.raw, Lua.REGISTRYINDEX, ref);
Lua.unref(l.raw, ref);
l = null;
}
}
Expand Down
6 changes: 6 additions & 0 deletions source/engine/psychlua/LuaUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ class LuaUtils
return "table";
case type if (type == Lua.TFUNCTION):
return "function";
case type if (type == Lua.TINTEGER):
return "integer";
case type if (type == Lua.TVECTOR):
return "vector";
case type if (type == Lua.TBUFFER):
return "buffer";
case type if (type <= Lua.TNIL):
return "nil";
}
Expand Down