Compare commits

..

6 Commits

12 changed files with 158 additions and 35 deletions

4
hGameTest/.haxerc Normal file
View File

@ -0,0 +1,4 @@
{
"version": "4.3.6",
"resolveLibs": "scoped"
}

View File

@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/actuate#1.9.0" into actuate/1.9.0/haxelib
-cp ${HAXE_LIBCACHE}/actuate/1.9.0/haxelib/src
-D actuate=1.9.0

View File

@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/hxcpp-debug-server#1.2.4" into hxcpp-debug-server/1.2.4/haxelib
-cp ${HAXE_LIBCACHE}/hxcpp-debug-server/1.2.4/haxelib/
-D hxcpp-debug-server=1.2.4
--macro hxcpp.debug.jsonrpc.Macro.injectServer()

View File

@ -0,0 +1,6 @@
# @install: lix --silent download "haxelib:/lime#8.2.2" into lime/8.2.2/haxelib
# @run: haxelib run-dir lime "${HAXE_LIBCACHE}/lime/8.2.2/haxelib"
-cp ${HAXE_LIBCACHE}/lime/8.2.2/haxelib/src
-D lime=8.2.2
--macro lime._internal.macros.DefineMacro.run()
-lib ndll:${HAXE_LIBCACHE}/lime/8.2.2/haxelib/ndll/

View File

@ -0,0 +1,5 @@
# @install: lix --silent download "haxelib:/openfl#9.4.1" into openfl/9.4.1/haxelib
# @run: haxelib run-dir openfl "${HAXE_LIBCACHE}/openfl/9.4.1/haxelib"
-cp ${HAXE_LIBCACHE}/openfl/9.4.1/haxelib/src
-D openfl=9.4.1
--macro openfl.utils._internal.ExtraParamsMacro.include()

View File

@ -15,6 +15,10 @@
<!-- classpath, haxe libs -->
<source path="src" />
<!-- Macro configuration -->
<haxeflag name="--macro" value="addGlobalMetadata('', '@:build(engine.macros.CCmdDecorator.build())')" />
<assets path="./res/textures" rename="textures" />
<assets path="./res/fonts" rename="fonts" />
<assets path="./res/data" rename="data"/>
@ -24,6 +28,6 @@
<!--<icon path="assets/openfl.svg" /> -->
<!-- <assets path="assets/img" rename="img" /> -->
<!-- optimize output
<haxeflag name="-dce full" /> -->
<!-- optimize output -->
<haxeflag name="-dce full" />
</project>

View File

@ -1,9 +0,0 @@
package engine;
typedef CVar = {
var name:String;
var type:CVarType;
var value:Dynamic;
@:optional var callback:Void -> Void;
};

View File

@ -1,29 +1,59 @@
package engine;
import haxe.Constraints.Function;
import engine.typedefs.console.CVar;
import engine.typedefs.console.CCmd;
import engine.enums.console.CVarType;
import engine.enums.console.CVarFlag;
import game.ui.console.Console;
import engine.ConVars_Engine;
class ConVar{
// Hush the compiler about unused import
// static var ConVars_Engine:Class<ConVars_Engine> = ConVars_Engine;
static var CVarMap:Map<String, CVar> = [];
public static inline function registerCVar(_name:String, _type:CVarType, _value, _callback:Void->Void,_callOnSet:Bool=false)
static var CCmdMap:Map<String, CCmd> = [];
/**
* Registers a new CVar
* @param _name The name of the CVar. This is the way it is called in the console or referred to in code.
* @param _type CVar type as defined in the CVarType enum.
* @param _value The default value for this CVar. This needs to be in line with its CVarType.
* @param _flags CVar flags as defined in the CVarFlags enum.
* @param _helpString Help string that gets printed out in console when no value is specified.
* @param _callback The function that gets called when the CVar is set. Calls empty Void when left undefined.
* @param _callOnCreate Whether the callback function gets called or not after registering.
* @param _bMin Specifies if the CVar has a minimum numeric value.
* @param _fMin Specifies the minimum numeric value.
* @param _fMax Specifies the maximum numeric value.
* @param _bMax Specifies if the CVar has a maximum numeric value.
*/
public static inline function registerCVar(_name:String, _type:CVarType, _value:Dynamic, ?_flags:CVarFlag, ?_helpString:String = "", ?_callback:Void->Void, ?_callOnCreate:Bool=false, _bMin:Bool=false, _fMin:Float=0, _fMax:Float=0, _bMax:Bool = false):CVar
{
if(CVarMap[_name]!=null){
return;
if(CVarMap[_name]!=null || CCmdMap[_name]!= null){
Console.devMsg("Tried setting already defined convar: " + _name + ", returning null instead");
return null;
}
CVarMap[_name] = {
if(_bMin && _value < _fMin) _value = _fMin;
if(_bMax && _value > _fMax) _value = _fMax;
var cvar:CVar = CVarMap[_name] = {
name : _name,
type : _type,
value : _value,
flags: _flags,
helpString: _helpString,
bMin : _bMin,
fMin : _fMin,
fMax : _fMax,
bMax : _bMax,
callback : _callback == null ? ()->{} : _callback
}
if(_callback != null && _callOnCreate){
_callback();
}
return cvar;
}
public static inline function setCVar(_name:String, _value:Dynamic)
public static inline function registerCCmd(_name:String, ?_callback:Array<String>->Void):CCmd
{
if(CVarMap[_name]!=null || CCmdMap[_name]!=null){
Console.devMsg("Tried setting already defined command: " + _name + ", returning null instead");
@ -77,7 +107,7 @@ class ConVar{
}
else{
Console.consoleIndex.devMsg("trying to set null convar '"+_name+"'");
Console.devMsg("trying to set null convar '"+_name+"'");
}
}
@ -116,20 +146,13 @@ class ConVar{
});
return keys;
}
public static var cmdList:CCmd = ConVar.registerCCmd("list", (cArgs:Array<String>)->{
var keys:Array<String> = getCVarNames();
for(key in keys){
if(CVarMap[key] != null){
Console.devMsg(key+" "+CVarMap[key].value);
}
else{
Console.devMsg(key);
}
}
});
public static inline function getCVar(_name:String):CVar
{
return CVarMap[_name];
}
public static inline function getCVarMap():Map<String, CVar>
{
return CVarMap;
}
}

View File

@ -0,0 +1,36 @@
package engine;
import game.video.Mode;
import haxe.macro.Expr.Field;
import engine.typedefs.console.CVar;
import engine.typedefs.console.CCmd;
import engine.enums.console.CVarType;
import engine.enums.console.CVarFlag;
import engine.macros.CCmdDecorator;
import game.ui.console.Console;
@:keep
// @:build(engine.macros.CCmdDecorator.build()) // No longer needed because we added the build macro to the project.xml
class ConVars_Engine {
@:command("list")
public static function listCommands(args:Array<String>) {
var CVarMap:Map<String, CVar> = ConVar.getCVarMap();
var keys:Array<String> = ConVar.getCVarNames();
for(key in keys){
if(CVarMap[key] != null){
Console.devMsg(key+" "+ CVarMap[key].value);
}
else{
Console.devMsg(key);
}
}
}
@:command("test")
public static function testCommand() {
// Command implementation
trace("Test Output");
}
}

View File

@ -0,0 +1,46 @@
package engine.macros;
import haxe.macro.Expr;
import haxe.macro.Context;
class CCmdDecorator {
public static macro function build():Array<Field> {
var fields = Context.getBuildFields();
var pos = Context.currentPos();
for (field in fields) {
var meta = field.meta != null ? Lambda.find(field.meta, function(m) return m.name == ":command") : null;
if (meta != null) {
trace(meta);
switch field.kind {
case FFun(f):
var name = meta.params.length > 0
? switch(meta.params[0].expr) {
case EConst(CString(s)): s;
case _: field.name;
}
: field.name;
// Create a static initializer field
var initField = {
name: "__init__" + name,
access: [AStatic, APrivate],
kind: FVar(null, macro {
engine.ConVar.registerCCmd($v{name}, function(args:Array<String>) {
${f.expr};
});
}),
pos: pos,
doc: null,
meta: []
};
// Add the initializer field
fields.push(initField);
case _:
}
}
}
return fields;
}
}

View File

@ -21,7 +21,7 @@ import openfl.text.TextField;
import engine.ConVar;
import engine.geom.Geom.P2d;
@:enum abstract PaneLayout(Int) {
enum abstract PaneLayout(Int) {
var HORIZONTAL = 0;
var VERTICAL = 1;
}

View File

@ -15,9 +15,10 @@ class Mode
public static function setVideoMode(width:Int, height:Int, fs:Int = null){
getWindow().resize(width,height);
}
public static var cvMatSetVideoMode:CCmd = ConVar.registerCCmd("mat_setvideomode",(args:Array<String>)->{
setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
});
@:command("mat_setvideomode")
public static function cCmdMatSetVideoMode(args:Array<String>){
Mode.setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
}
public static function switchFsMode(toState:Int = 0){
if(toState == 0){
if(Lib.current.stage.displayState != StageDisplayState.FULL_SCREEN_INTERACTIVE){