diff --git a/.gitignore b/.gitignore index 18138779..f96bcbb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ .vscode /hGameTest/bin /hGameTest/node_modules + +hGameTest/exp/ +pp +bla \ No newline at end of file diff --git a/hGameTest/.haxerc b/hGameTest/.haxerc deleted file mode 100644 index ef431268..00000000 --- a/hGameTest/.haxerc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "version": "4.3.6", - "resolveLibs": "scoped" -} \ No newline at end of file diff --git a/hGameTest/BuildTool.hx b/hGameTest/BuildTool.hx new file mode 100644 index 00000000..0f874a95 --- /dev/null +++ b/hGameTest/BuildTool.hx @@ -0,0 +1,56 @@ +import lime.tools.HXProject; +import lime.tools.Platform; +import hxp.*; + +class BuildTool extends Script{ + public static function main() { + // Get command line arguments + var args = Sys.args(); + var target = "linux"; // Default + + trace(args); + // Check if a platform was specified + if (args.length > 0) { + target = args[0].toLowerCase(); + } + + // Create the project + var project = new Project(); + + // Set target platform + switch (target) { + case "windows": project.target = Platform.WINDOWS; + case "mac": project.target = Platform.MAC; + case "linux": project.target = Platform.LINUX; + case "android": project.target = Platform.ANDROID; + case "ios": project.target = Platform.IOS; + case "html5": project.target = Platform.HTML5; + default: Sys.println('Unknown platform: $target, using linux'); + project.target = Platform.LINUX; + } + + // Create build configuration + var command = "build"; + if (args.length > 1) { + command = args[1].toLowerCase(); + } + + // Additional flags + var flags = []; + if (args.length > 2) { + flags = args.slice(2); + } + + // Use Lime's internal CommandLineTools + var commandLineArgs = [command, target].concat(flags); + // var lime = new CommandLineTools(); + + // Pass the project directly to lime + // lime.project = project; + + HXProject.main(); + + // Execute the command + // lime.process(commandLineArgs); + } +} \ No newline at end of file diff --git a/hGameTest/Project.hx b/hGameTest/Project.hx new file mode 100644 index 00000000..e959e771 --- /dev/null +++ b/hGameTest/Project.hx @@ -0,0 +1,57 @@ +package; + +import lime.tools.*; +import openfl.tools.*; +import hxp.*; + +class Project extends HXProject { + public function new() { + super(); + + // Meta data + meta.title = "hgame"; + meta.packageName = "FLWork"; + meta.version = "1.0.0"; + meta.company = ""; + + // App settings + app.main = "Main"; + app.file = "hgame"; + app.path = "bin"; + + + // Window config + window.background = 0xFFFFFF; + window.fps = 60; + window.width = 1280; + window.height = 960; + window.vsync = false; + window.antialiasing = 0; + + // Source path + sources.push("src"); + sources.push("."); // we need this to enable code completion for this file + + // Libraries + haxelibs.push(new Haxelib("lime", "8.2.2")); + haxelibs.push(new Haxelib("openfl", "9.4.1")); + haxelibs.push(new Haxelib("actuate")); + haxelibs.push(new Haxelib("hxp")); + + + // Assets + includeAssets("res/textures", "textures"); + includeAssets("res/fonts", "fonts"); + includeAssets("res/data", "data"); + // assets.push(new lime.tools.Asset("res/textures", "textures")); + // assets.push(new lime.tools.Asset("res/fonts", "fonts")); + // assets.push(new lime.tools.Asset("res/data", "data")); + + // Haxe flags + haxeflags.push("--macro addGlobalMetadata('', '@:build(engine.macros.ConVarDecorators.build())')"); + haxeflags.push("--macro keep('Main')"); + haxeflags.push("-dce full"); + + // target = Platform.LINUX; + } +} \ No newline at end of file diff --git a/hGameTest/build.hxml b/hGameTest/build.hxml index 555a5341..e828b5f3 100644 --- a/hGameTest/build.hxml +++ b/hGameTest/build.hxml @@ -1,11 +1,9 @@ +-lib actuate +-lib lime +-lib openfl +-lib hxp -#-main App -#-js src/app.js -#-cp node_modules/openfl/lib -#-cp src -#-D buildhxml -#-D source-map - ---main --hl exp/out.hl +--main ApplicationMain -cp src + +--cpp bin/cpp \ No newline at end of file diff --git a/hGameTest/build.sh b/hGameTest/build.sh new file mode 100755 index 00000000..43cd7f94 --- /dev/null +++ b/hGameTest/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +haxe -lib lime -lib hxp --run BuildTool.hx diff --git a/hGameTest/build_hxp.hxml b/hGameTest/build_hxp.hxml new file mode 100644 index 00000000..a8d04cbd --- /dev/null +++ b/hGameTest/build_hxp.hxml @@ -0,0 +1,11 @@ +-L lime +-L openfl +-L hxp + +--class-path src + +--class-path bin/hl/haxe + +--main ApplicationMain + +--interp \ No newline at end of file diff --git a/hGameTest/haxe_libraries/hxp.hxml b/hGameTest/haxe_libraries/hxp.hxml new file mode 100644 index 00000000..f18db162 --- /dev/null +++ b/hGameTest/haxe_libraries/hxp.hxml @@ -0,0 +1,4 @@ +# @install: lix --silent download "haxelib:/hxp#1.3.0" into hxp/1.3.0/haxelib +# @run: haxelib run-dir hxp "${HAXE_LIBCACHE}/hxp/1.3.0/haxelib" +-cp ${HAXE_LIBCACHE}/hxp/1.3.0/haxelib/src +-D hxp=1.3.0 \ No newline at end of file diff --git a/hGameTest/project.hxp b/hGameTest/project.hxp new file mode 120000 index 00000000..22ba860c --- /dev/null +++ b/hGameTest/project.hxp @@ -0,0 +1 @@ +Project.hx \ No newline at end of file diff --git a/hGameTest/project.xml b/hGameTest/project.xml deleted file mode 100644 index 19b2ff25..00000000 --- a/hGameTest/project.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hGameTest/src/ApplicationMain.hx b/hGameTest/src/ApplicationMain.hx new file mode 100644 index 00000000..a2e6a8b5 --- /dev/null +++ b/hGameTest/src/ApplicationMain.hx @@ -0,0 +1,369 @@ +package; + +#if macro +import haxe.macro.Compiler; +import haxe.macro.Context; +import haxe.macro.Expr; +#end + +@:access(lime.app.Application) +@:access(lime.system.System) +@:access(openfl.display.Stage) +@:access(openfl.events.UncaughtErrorEvents) +@:dox(hide) +class ApplicationMain +{ + #if !macro + public static function main() + { + lime.system.System.__registerEntryPoint("::APP_FILE::", create); + + #if (js && html5) + #if (munit || (utest && openfl_enable_utest_legacy_mode)) + lime.system.System.embed("::APP_FILE::", null, ::WIN_WIDTH::, ::WIN_HEIGHT::); + #end + #else + create(null); + #end + } + + public static function create(config):Void + { + var app = new openfl.display.Application(); + + #if !disable_preloader_assets + ManifestResources.init(config); + #end + + app.meta["build"] = "::meta.buildNumber::"; + app.meta["company"] = "::meta.company::"; + app.meta["file"] = "::APP_FILE::"; + app.meta["name"] = "::meta.title::"; + app.meta["packageName"] = "::meta.packageName::"; + app.meta["version"] = "::meta.version::"; + + ::if (config.hxtelemetry != null)::#if hxtelemetry + app.meta["hxtelemetry-allocations"] = "::config.hxtelemetry.allocations::"; + app.meta["hxtelemetry-host"] = "::config.hxtelemetry.host::"; + #end::end:: + + #if !flash + ::foreach windows:: + var attributes:lime.ui.WindowAttributes = { + allowHighDPI: ::allowHighDPI::, + alwaysOnTop: ::alwaysOnTop::, + borderless: ::borderless::, + // display: ::display::, + element: null, + frameRate: ::fps::, + #if !web fullscreen: ::fullscreen::, #end + height: ::height::, + hidden: #if munit true #else ::hidden:: #end, + maximized: ::maximized::, + minimized: ::minimized::, + parameters: ::parameters::, + resizable: ::resizable::, + title: "::title::", + width: ::width::, + x: ::x::, + y: ::y::, + }; + + attributes.context = { + antialiasing: ::antialiasing::, + background: ::background::, + colorDepth: ::colorDepth::, + depth: ::depthBuffer::, + hardware: ::hardware::, + stencil: ::stencilBuffer::, + type: null, + vsync: ::vsync:: + }; + + if (app.window == null) + { + if (config != null) + { + for (field in Reflect.fields(config)) + { + if (Reflect.hasField(attributes, field)) + { + Reflect.setField(attributes, field, Reflect.field(config, field)); + } + else if (Reflect.hasField(attributes.context, field)) + { + Reflect.setField(attributes.context, field, Reflect.field(config, field)); + } + } + } + + #if sys + lime.system.System.__parseArguments(attributes); + #end + } + + app.createWindow(attributes); + ::end:: + #elseif air + app.window.title = "::meta.title::"; + #else + app.window.context.attributes.background = ::WIN_BACKGROUND::; + app.window.frameRate = ::WIN_FPS::; + #end + + var preloader = getPreloader(); + app.preloader.onProgress.add (function(loaded, total) + { + @:privateAccess preloader.update(loaded, total); + }); + app.preloader.onComplete.add(function() + { + @:privateAccess preloader.start(); + }); + + preloader.onComplete.add(start.bind((cast app.window:openfl.display.Window).stage)); + + #if !disable_preloader_assets + for (library in ManifestResources.preloadLibraries) + { + app.preloader.addLibrary(library); + } + + for (name in ManifestResources.preloadLibraryNames) + { + app.preloader.addLibraryName(name); + } + #end + + app.preloader.load(); + + var result = app.exec(); + + #if (sys && !ios && !nodejs && !emscripten) + lime.system.System.exit(result); + #end + } + + public static function start(stage:openfl.display.Stage):Void + { + #if flash + ApplicationMain.getEntryPoint(); + #else + if (stage.__uncaughtErrorEvents.__enabled) + { + try + { + ApplicationMain.getEntryPoint(); + + stage.dispatchEvent(new openfl.events.Event(openfl.events.Event.RESIZE, false, false)); + + if (stage.window.fullscreen) + { + stage.dispatchEvent(new openfl.events.FullScreenEvent(openfl.events.FullScreenEvent.FULL_SCREEN, false, false, true, true)); + } + } + catch (e:Dynamic) + { + #if !display + stage.__handleError(e); + #end + } + } + else + { + ApplicationMain.getEntryPoint(); + + stage.dispatchEvent(new openfl.events.Event(openfl.events.Event.RESIZE, false, false)); + + if (stage.window.fullscreen) + { + stage.dispatchEvent(new openfl.events.FullScreenEvent(openfl.events.FullScreenEvent.FULL_SCREEN, false, false, true, true)); + } + } + #end + } + #end + + macro public static function getEntryPoint() + { + var hasMain = false; + + switch (Context.follow(Context.getType("::APP_MAIN::"))) + { + case TInst(t, params): + + var type = t.get(); + for (method in type.statics.get()) + { + if (method.name == "main") + { + hasMain = true; + break; + } + } + + if (hasMain) + { + return Context.parse("@:privateAccess ::APP_MAIN::.main()", Context.currentPos()); + } + else if (type.constructor != null) + { + return macro + { + var current = stage.getChildAt (0); + + if (current == null || !(current is openfl.display.DisplayObjectContainer)) + { + current = new openfl.display.MovieClip(); + stage.addChild(current); + } + + new DocumentClass(cast current); + }; + } + else + { + Context.fatalError("Main class \"::APP_MAIN::\" has neither a static main nor a constructor.", Context.currentPos()); + } + + default: + + Context.fatalError("Main class \"::APP_MAIN::\" isn't a class.", Context.currentPos()); + } + + return null; + } + + macro public static function getPreloader() + { + ::if (PRELOADER_NAME != ""):: + var type = Context.getType("::PRELOADER_NAME::"); + + switch (type) + { + case TInst(classType, _): + + var searchTypes = classType.get(); + + while (searchTypes != null) + { + if (searchTypes.pack.length == 2 && searchTypes.pack[0] == "openfl" && searchTypes.pack[1] == "display" && searchTypes.name == "Preloader") + { + return macro + { + new ::PRELOADER_NAME::(); + }; + } + + if (searchTypes.superClass != null) + { + searchTypes = searchTypes.superClass.t.get(); + } + else + { + searchTypes = null; + } + } + + default: + } + + return macro + { + new openfl.display.Preloader(new ::PRELOADER_NAME::()); + } + ::else:: + return macro + { + new openfl.display.Preloader(new openfl.display.Preloader.DefaultPreloader()); + }; + ::end:: + } + + #if !macro + @:noCompletion @:dox(hide) public static function __init__() + { + var init = lime.app.Application; + + #if neko + // Copy from https://github.com/HaxeFoundation/haxe/blob/development/std/neko/_std/Sys.hx#L164 + // since Sys.programPath () isn't available in __init__ + var sys_program_path = { + var m = neko.vm.Module.local().name; + try + { + sys.FileSystem.fullPath(m); + } + catch (e:Dynamic) + { + // maybe the neko module name was supplied without .n extension... + if (!StringTools.endsWith(m, ".n")) + { + try + { + sys.FileSystem.fullPath(m + ".n"); + } + catch (e:Dynamic) + { + m; + } + } + else + { + m; + } + } + }; + + var loader = new neko.vm.Loader(untyped $loader); + loader.addPath(haxe.io.Path.directory(#if (haxe_ver >= 3.3) sys_program_path #else Sys.executablePath() #end)); + loader.addPath("./"); + loader.addPath("@executable_path/"); + #end + } + #end +} + +#if !macro +@:build(DocumentClass.build()) +@:keep @:dox(hide) class DocumentClass extends ::APP_MAIN:: {} +#else +class DocumentClass +{ + macro public static function build():Array + { + var classType = Context.getLocalClass().get(); + var searchTypes = classType; + + while (searchTypes != null) + { + if (searchTypes.module == "openfl.display.DisplayObject" || searchTypes.module == "flash.display.DisplayObject") + { + var fields = Context.getBuildFields(); + + var method = macro + { + current.addChild(this); + super(); + dispatchEvent(new openfl.events.Event(openfl.events.Event.ADDED_TO_STAGE, false, false)); + } + + fields.push({ name: "new", access: [ APublic ], kind: FFun({ args: [ { name: "current", opt: false, type: macro :openfl.display.DisplayObjectContainer, value: null } ], expr: method, params: [], ret: macro :Void }), pos: Context.currentPos() }); + + return fields; + } + + if (searchTypes.superClass != null) + { + searchTypes = searchTypes.superClass.t.get(); + } + else + { + searchTypes = null; + } + } + + return null; + } +} +#end diff --git a/hGameTest/src/Main.hx b/hGameTest/src/Main.hx index 8a653ded..527c92e0 100644 --- a/hGameTest/src/Main.hx +++ b/hGameTest/src/Main.hx @@ -1,3 +1,4 @@ +import openfl.display.Window; import assets.Scanner; import game.video.Mode; import openfl.events.KeyboardEvent; @@ -12,8 +13,6 @@ class Main extends Sprite { public function new () { super (); this.addEventListener(Event.ADDED_TO_STAGE, onInit); - //stage.application.window.resize(1920, 1080); - //stage.application.window.title = "Kanker"; } private function onInit(e:Event) { @@ -28,8 +27,23 @@ class Main extends Sprite { //Mode.setVideoMode(1280, 960); } private function onResize (event:Event):Void { + //Here we can do shit with window scaling //stage.stageWidth; //stage.stageHeight; } + + // static function main () { + // // Bootstrap the OpenFL project + // var application = new lime.app.Application(); + // application.createWindow({ + // hidden: false, + // x: 0, + // y: 0, + // width: 800, + // height: 600, + // title: "DSTEngine Window" + // }); + // } + } \ No newline at end of file diff --git a/hGameTest/src/engine/macros/ConVarDecorators.hx b/hGameTest/src/engine/macros/ConVarDecorators.hx index 821f1a4f..eb7a93a6 100644 --- a/hGameTest/src/engine/macros/ConVarDecorators.hx +++ b/hGameTest/src/engine/macros/ConVarDecorators.hx @@ -58,6 +58,7 @@ class ConVarDecorators { // Process command fields private static function processCommandField(field:Field, cmdMeta:MetadataEntry, extraFields:Array):Void { + if (!isFieldKind(field, "FFun")) { Context.error("The @:concmd metadata can only be applied to functions", field.pos); return; @@ -246,19 +247,20 @@ class ConVarDecorators { } public static macro function build():Array { - var fields = Context.getBuildFields(); - var extraFields:Array = []; + + var fields = Context.getBuildFields(); // Get all fields in the class + var extraFields:Array = []; // Extra fields to be added for (field in fields) { - if (field.meta == null) continue; + if (field.meta == null) continue; // Skip fields without metadata - var cmdMeta = Lambda.find(field.meta, function(m) return m.name == ":concmd"); - var cvarMeta = Lambda.find(field.meta, function(m) return m.name == ":convar"); + var cmdDecorator = Lambda.find(field.meta, function(m) return m.name == ":concmd"); // Check for command decorator + var cvarDecorator = Lambda.find(field.meta, function(m) return m.name == ":convar"); // Check for convar decorator - if (cmdMeta != null) { - processCommandField(field, cmdMeta, extraFields); - } else if (cvarMeta != null && cvarMeta.params.length > 0) { - processConVarField(field, cvarMeta, extraFields); + if (cmdDecorator != null) { + processCommandField(field, cmdDecorator, extraFields); + } else if (cvarDecorator != null && cvarDecorator.params.length > 0) { + processConVarField(field, cvarDecorator, extraFields); } } diff --git a/hGameTest/src/game/Input.hx b/hGameTest/src/game/Input.hx index 079431ca..7f6d2ebe 100644 --- a/hGameTest/src/game/Input.hx +++ b/hGameTest/src/game/Input.hx @@ -92,26 +92,28 @@ class Input{ { bindMap[input] = action; } - private static var bind:CCmd = ConVar.registerCCmd("bind", (cArgs:Array)->{ - cArgs[0] = cArgs[0].toUpperCase(); - if(cArgs.length == 2){ - if(keyCodeMap[cArgs[0]]!= null) { - if(cArgs[1].indexOf('"') == 0 && cArgs[1].lastIndexOf('"') == cArgs[1].length-1){ - bindKey(cArgs[0], cArgs[1].substring(1,cArgs[1].length-1)); + @:concmd("bind") + private static function bind(args:Array):Void + { + args[0] = args[0].toUpperCase(); + if(args.length == 2){ + if(keyCodeMap[args[0]]!= null) { + if(args[1].indexOf('"') == 0 && args[1].lastIndexOf('"') == args[1].length-1){ + bindKey(args[0], args[1].substring(1,args[1].length-1)); } else{ - bindKey(cArgs[0], cArgs[1]); + bindKey(args[0], args[1]); } } } - else if(cArgs.length == 1){ - Console.devMsg(bindMap[cArgs[0]]); + else if(args.length == 1){ + Console.devMsg(bindMap[args[0]]); } else{ Console.devMsg("usage: bind "); } - }); + }; public static function onEnterFrame() { if( keys[Kb.BACKQUOTE]){ diff --git a/hGameTest/src/game/ui/console/Console.hx b/hGameTest/src/game/ui/console/Console.hx index 555d6a43..554cb8bc 100644 --- a/hGameTest/src/game/ui/console/Console.hx +++ b/hGameTest/src/game/ui/console/Console.hx @@ -42,10 +42,13 @@ class Console extends Sprite { public static var scvar_mat_consolebg:CVar; public var cvar_mat_consolebg:CVar; - - public var ccmd_visible:CCmd = ConVar.registerCCmd("toggleconsole", (cArgs:Array) -> { + // public function cCmdToggleConsole(args:Array) { + // toggle(); + // } + @:concmd("toggleconsole") + public function ccmd_toggleconsole(cArgs:Array) { toggle(); - }); + }; public function new() { super(); diff --git a/hGameTest/src/game/video/Mode.hx b/hGameTest/src/game/video/Mode.hx index 42a64551..edb1d163 100644 --- a/hGameTest/src/game/video/Mode.hx +++ b/hGameTest/src/game/video/Mode.hx @@ -1,5 +1,6 @@ package game.video; +import game.ui.console.Console; import engine.ConVar; import engine.typedefs.console.CCmd; import openfl.Lib; @@ -14,22 +15,26 @@ class Mode public static function setVideoMode(width:Int, height:Int, fs:Int = null){ getWindow().resize(width,height); + if(fs == null){ + return; + } + switchFsMode(fs); } @:concmd("mat_setvideomode") public static function cCmdMatSetVideoMode(args:Array){ + Console.devMsg("Setting video mode to: "+args[0]+"x"+args[1]+"x"+args[2]); Mode.setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2])); } public static function switchFsMode(toState:Int = 0){ + Console.devMsg("Switching fullscreen mode to: "+toState); if(toState == 0){ - if(Lib.current.stage.displayState != StageDisplayState.FULL_SCREEN_INTERACTIVE){ - Lib.current.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE; - } - else{ - Lib.current.stage.displayState = StageDisplayState.NORMAL; - } + Lib.current.stage.displayState = StageDisplayState.FULL_SCREEN; + } + else if(toState == 1){ + Lib.current.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE; } else{ - + Lib.current.stage.displayState = StageDisplayState.NORMAL; } } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..19f4a4ce --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "DSTEngine", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/package.json @@ -0,0 +1 @@ +{}