2
0
Mark Sibly 9 жил өмнө
parent
commit
a55bb20dc2

+ 8 - 6
bin/env_windows.txt

@@ -39,26 +39,28 @@ MX2_CPP_OPTS_WINDOWS_DEBUG=
 MX2_CPP_OPTS_WINDOWS_RELEASE=-O3 -DNDEBUG ' -fvtable-gc -fdata-sections -ffunction-sections
 MX2_CPP_OPTS_WINDOWS_RELEASE=-O3 -DNDEBUG ' -fvtable-gc -fdata-sections -ffunction-sections
 
 
 
 
-'***** EMSCRIPTEN *****
+'***** EMSCRIPTEN/WASM *****
 
 
-'Forbuild emscripten apps, you'll need to download and install emscripten.
+'To build emscripten apps, you'll need to download and install emscripten.
 '
 '
-'To run emscripten apps, you'll need MonkeyXFree86c in your devtools directory.
+'To build wasm apps, you'll to install/build emscripten 'icoming' branch.
+'
+'To run emscripten/wasm apps, you'll need MonkeyXFree86c in your devtools directory.
 
 
 MX2_MSERVER="${MX2_HOME}\devtools\mserver-v86c\mserver_winnt.exe"
 MX2_MSERVER="${MX2_HOME}\devtools\mserver-v86c\mserver_winnt.exe"
 
 
 'Linker options
 'Linker options
-MX2_LD_OPTS_EMSCRIPTEN=-s USE_SDL=2 -s TOTAL_MEMORY=67108864 -s DISABLE_EXCEPTION_CATCHING=1 '-s BINARYEN=1
+MX2_LD_OPTS_EMSCRIPTEN=-s USE_SDL=2 -s TOTAL_MEMORY=67108864 -s DISABLE_EXCEPTION_CATCHING=1
 MX2_LD_OPTS_EMSCRIPTEN_DEBUG=-O2
 MX2_LD_OPTS_EMSCRIPTEN_DEBUG=-O2
 MX2_LD_OPTS_EMSCRIPTEN_RELEASE=-O3
 MX2_LD_OPTS_EMSCRIPTEN_RELEASE=-O3
 
 
 'C Compiler options
 'C Compiler options
-MX2_CC_OPTS_EMSCRIPTEN=-std=gnu99 -s USE_SDL=2 -s TOTAL_MEMORY=67108864 -s DISABLE_EXCEPTION_CATCHING=1 '-s BINARYEN=1
+MX2_CC_OPTS_EMSCRIPTEN=-std=gnu99 -s USE_SDL=2 -s TOTAL_MEMORY=67108864 -s DISABLE_EXCEPTION_CATCHING=1
 MX2_CC_OPTS_EMSCRIPTEN_DEBUG=-O2
 MX2_CC_OPTS_EMSCRIPTEN_DEBUG=-O2
 MX2_CC_OPTS_EMSCRIPTEN_RELEASE=-O3
 MX2_CC_OPTS_EMSCRIPTEN_RELEASE=-O3
 
 
 'C++ Compiler options
 'C++ Compiler options
-MX2_CPP_OPTS_EMSCRIPTEN=-std=c++11 -s USE_SDL=2 -s TOTAL_MEMORY=67108864 -s DISABLE_EXCEPTION_CATCHING=1 '-s BINARYEN=1
+MX2_CPP_OPTS_EMSCRIPTEN=-std=c++11 -s USE_SDL=2 -s TOTAL_MEMORY=67108864 -s DISABLE_EXCEPTION_CATCHING=1
 MX2_CPP_OPTS_EMSCRIPTEN_DEBUG=-O2
 MX2_CPP_OPTS_EMSCRIPTEN_DEBUG=-O2
 MX2_CPP_OPTS_EMSCRIPTEN_RELEASE=-O3
 MX2_CPP_OPTS_EMSCRIPTEN_RELEASE=-O3
 
 

BIN
bin/mx2cc_windows.exe


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 192
products/emscripten/Monkey2Game_bak.html


+ 123 - 0
products/wasm/Monkey2Game.html

@@ -0,0 +1,123 @@
+<!doctype html>
+
+<html>
+
+<head>
+	<meta charset="utf-8">
+	<title>Simplelight</title>
+	<link rel="stylesheet" href="style.css">
+</head>
+
+<body>
+
+<div class="header">
+<span>Resize canvas <input type="checkbox" id="resize"></span>&nbsp;&nbsp;
+<span>Hide mouse pointer <input type="checkbox" id="pointerLock"></span>&nbsp;&nbsp;
+<a class="button" onclick="Module.requestFullScreen(document.getElementById('pointerLock').checked,document.getElementById('resize').checked)">Fullscreen</a>
+</div>
+
+<div class="status">
+<span id="status"></span>
+</div>
+
+<div class="canvas">
+<div class="center">
+<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
+</div>
+</div>
+
+<textarea id="output" rows="10"></textarea>
+ 
+<script type="text/javascript">
+
+var statusElement = document.getElementById('status');
+
+var Module = {
+
+	preRun: [],
+
+	postRun: [],
+
+	print: (function() {
+
+		var element = document.getElementById('output');
+
+		if (element) element.value = ''; // clear browser cache
+
+		return function(text) {
+			if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
+			// These replacements are necessary if you render to raw HTML
+			//text = text.replace(/&/g, "&amp;");
+			//text = text.replace(/</g, "&lt;");
+			//text = text.replace(/>/g, "&gt;");
+			//text = text.replace('\n', '<br>', 'g');
+			console.log(text);
+			if (element) {
+				element.value += text + "\n";
+				element.scrollTop = element.scrollHeight; // focus on bottom
+			}
+		};
+	})(),
+
+	printErr: function(text) {
+		if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
+		if (0) { // XXX disabled for safety typeof dump == 'function') {
+			dump(text + '\n'); // fast, straight to the real console
+		} else {
+			console.error(text);
+		}
+	},
+
+	canvas: (function() {
+
+		var canvas = document.getElementById('canvas');
+
+		// As a default initial behavior, pop up an alert when webgl context is lost. To make your
+		// application robust, you may want to override this behavior before shipping!
+		// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
+		canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
+
+		return canvas;
+	})(),
+
+	setStatus: function(text) {
+
+		if( !statusElement ) return;
+
+		if( text ){
+			statusElement.innerHTML=text;
+			statusElement.hidden=false;
+		}else{
+			statusElement.hidden=true;
+		}
+	}
+};
+
+Module.setStatus( 'Downloading...' );
+
+window.onerror=function(event) {
+
+	// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
+	Module.setStatus('Exception thrown, see JavaScript console');
+
+	Module.setStatus = function(text) {
+		if (text) Module.printErr('[post-exception status] ' + text);
+	};
+};
+
+var xhr=new XMLHttpRequest();
+xhr.open( 'GET','${APPLICATION_NAME}.wasm',true );
+xhr.responseType='arraybuffer';
+xhr.onload=function(){
+	Module.wasmBinary=xhr.response;
+	var script=document.createElement( 'script' );
+	script.src='${APPLICATION_NAME}.js';
+	document.body.appendChild(script);
+};
+xhr.send( null );
+
+</script>
+	
+</body>
+
+</html>

+ 81 - 0
products/wasm/style.css

@@ -0,0 +1,81 @@
+
+*,
+*:after,
+*:before{
+	box-sizing: inherit;
+	padding:0;
+	border:0;
+	margin:0;
+}
+
+html{
+	box-sizing: border-box;
+	width: 100%;
+	height: 100%;
+	font-weight: 300;
+}
+
+body{
+	color: #eeeeee;
+	background: #323232;
+	font-family: Verdana, sans-serif;
+	font-size: 16px;
+	line-height: 140%;
+}
+
+div{
+	text-align:center;
+}
+
+div.header{
+	padding: 12px;
+}
+
+div.status{
+}
+
+div.canvas{
+}
+
+canvas{
+}
+
+input[type="checkbox"]{
+	vertical-align: middle;
+}
+
+textarea{
+	width:100%;
+	position:absolute;
+	opacity: .9;
+	bottom:0;
+}
+
+a{
+	color: #eeee00;
+	text-decoration: none;
+	cursor: pointer;
+}
+
+a:hover{
+	color: #00ee00;
+}
+
+a.button{
+	color: #ffffff;
+	background-color: #4c4c4c;
+	border: 1px solid #4c4c4c;
+	border-radius: 3px;
+	padding: 4px 7px;
+	font-size: 11px;
+	font-weight: 400;
+	text-align: center;
+}
+
+a.button:hover{
+	color: #ffff00;
+	background-color: #888888;
+	border-color: #888888;
+	outline: 0;
+}
+

+ 7 - 0
src/mx2cc/builder.monkey2

@@ -35,6 +35,8 @@ Class BuildOpts
 	
 	
 	Field reflection:Bool
 	Field reflection:Bool
 	
 	
+	Field wasm:Bool
+	
 End
 End
 
 
 Class BuilderInstance
 Class BuilderInstance
@@ -91,6 +93,11 @@ Class BuilderInstance
 		
 		
 			SetEnv( "PATH",GetEnv( "MX2_RASPBIAN_TOOLS" )+";"+GetEnv( "PATH" ) )
 			SetEnv( "PATH",GetEnv( "MX2_RASPBIAN_TOOLS" )+";"+GetEnv( "PATH" ) )
 			
 			
+		Else If opts.target="wasm"
+		
+			opts.target="emscripten"
+			opts.wasm=True
+			
 		Endif
 		Endif
 		
 		
 		ppsyms["__HOST__"]="~q"+HostOS+"~q"
 		ppsyms["__HOST__"]="~q"+HostOS+"~q"

+ 6 - 3
src/mx2cc/buildproduct.monkey2

@@ -507,6 +507,8 @@ Class GccBuildProduct Extends BuildProduct
 			If ExtractExt( outputFile ).ToLower()<>".js" And ExtractExt( outputFile ).ToLower()<>".html" outputFile+=".html"
 			If ExtractExt( outputFile ).ToLower()<>".js" And ExtractExt( outputFile ).ToLower()<>".html" outputFile+=".html"
 			
 			
 			cmd+=" --preload-file ~q"+assetsDir+"@/assets~q"
 			cmd+=" --preload-file ~q"+assetsDir+"@/assets~q"
+			
+			If opts.wasm cmd+=" -s BINARYEN=1"
 		End
 		End
 		
 		
 		If opts.verbose>=0 Print "Linking "+outputFile+"..."
 		If opts.verbose>=0 Print "Linking "+outputFile+"..."
@@ -560,12 +562,13 @@ Class GccBuildProduct Extends BuildProduct
 	Method Run() Override
 	Method Run() Override
 	
 	
 		Local run:=""
 		Local run:=""
-		If opts.target="emscripten"
+		Select opts.target
+		Case "emscripten"
 			Local mserver:=GetEnv( "MX2_MSERVER" )
 			Local mserver:=GetEnv( "MX2_MSERVER" )
 			run=mserver+" ~q"+outputFile+"~q"
 			run=mserver+" ~q"+outputFile+"~q"
-		Else
+		Default
 			run="~q"+outputFile+"~q"
 			run="~q"+outputFile+"~q"
-		Endif
+		End
 		
 		
 		If opts.verbose>=0 Print "Running "+outputFile
 		If opts.verbose>=0 Print "Running "+outputFile
 		Exec( run )
 		Exec( run )

+ 4 - 4
src/mx2cc/mx2cc.monkey2

@@ -21,7 +21,7 @@ Using mx2..
 
 
 Global StartDir:String
 Global StartDir:String
 
 
-Const TestArgs:="mx2cc makemods"' monkey libc miniz stb-image stb-image-write stb-vorbis std"
+Const TestArgs:="mx2cc makedocs chipmunk"'makemods"' monkey libc miniz stb-image stb-image-write stb-vorbis std"
 
 
 'Const TestArgs:="mx2cc makeapp -apptype=console src/mx2cc/test.monkey2"
 'Const TestArgs:="mx2cc makeapp -apptype=console src/mx2cc/test.monkey2"
 
 
@@ -78,7 +78,7 @@ Function Main()
 		Print "  -build       - parse, semant, translate and build"
 		Print "  -build       - parse, semant, translate and build"
 		Print "  -run         - the works! The default."
 		Print "  -run         - the works! The default."
 		Print "  -apptype=    - app type to make, one of : gui, console. Defaults to gui."
 		Print "  -apptype=    - app type to make, one of : gui, console. Defaults to gui."
-		print "  -target=     - build target, one of: windows, macos, linux, emscripten, android, ios, desktop. Desktop is alias for current host. Defaults to desktop."
+		print "  -target=     - build target, one of: windows, macos, linux, emscripten, wasm, android, ios, desktop. Desktop is an alias for current host. Defaults to desktop."
 		Print "  -config=     - build config, one of: debug, release. Defaults to debug."
 		Print "  -config=     - build config, one of: debug, release. Defaults to debug."
 		Print ""
 		Print ""
 		Print "Sources:"
 		Print "Sources:"
@@ -380,10 +380,10 @@ Function ParseOpts:String[]( opts:BuildOpts,args:String[] )
 			End
 			End
 		Case "-target"
 		Case "-target"
 			Select val
 			Select val
-			Case "desktop","windows","macos","linux","raspbian","emscripten","android","ios"
+			Case "desktop","windows","macos","linux","raspbian","emscripten","wasm","android","ios"
 				opts.target=val
 				opts.target=val
 			Default
 			Default
-				Fail( "Invalid value for 'target' option: '"+val+"' - must be 'desktop', 'raspbian', 'emscripten', 'android' or 'ios'" )
+				Fail( "Invalid value for 'target' option: '"+val+"' - must be 'desktop', 'raspbian', 'emscripten', 'wasm', 'android' or 'ios'" )
 			End
 			End
 		Case "-config"
 		Case "-config"
 			Select val
 			Select val

+ 16 - 1
src/ted2/buildactions.monkey2

@@ -109,6 +109,9 @@ Class BuildActions
 		_emscriptenTarget=New CheckButton( "Emscripten",,group )
 		_emscriptenTarget=New CheckButton( "Emscripten",,group )
 		_emscriptenTarget.Layout="fill-x"
 		_emscriptenTarget.Layout="fill-x"
 		
 		
+		_wasmTarget=New CheckButton( "Wasm",,group )
+		_wasmTarget.Layout="fill-x"
+		
 		_androidTarget=New CheckButton( "Android",,group )
 		_androidTarget=New CheckButton( "Android",,group )
 		_androidTarget.Layout="fill-x"
 		_androidTarget.Layout="fill-x"
 		
 		
@@ -121,6 +124,7 @@ Class BuildActions
 		targetMenu.AddSeparator()
 		targetMenu.AddSeparator()
 		targetMenu.AddView( _desktopTarget )
 		targetMenu.AddView( _desktopTarget )
 		targetMenu.AddView( _emscriptenTarget )
 		targetMenu.AddView( _emscriptenTarget )
+		targetMenu.AddView( _wasmTarget )
 		targetMenu.AddView( _androidTarget )
 		targetMenu.AddView( _androidTarget )
 		targetMenu.AddView( _iosTarget )
 		targetMenu.AddView( _iosTarget )
 		targetMenu.AddSeparator()
 		targetMenu.AddSeparator()
@@ -148,6 +152,14 @@ Class BuildActions
 			_emscriptenTarget.Enabled=False
 			_emscriptenTarget.Enabled=False
 		Endif
 		Endif
 
 
+		If _validTargets.Contains( "wasm" )
+			_wasmTarget.Clicked+=Lambda()
+				_buildTarget="wasm"
+			End
+		Else
+			_wasmTarget.Enabled=False
+		Endif
+
 		If _validTargets.Contains( "android" )
 		If _validTargets.Contains( "android" )
 			_androidTarget.Clicked+=Lambda()
 			_androidTarget.Clicked+=Lambda()
 				_buildTarget="android"
 				_buildTarget="android"
@@ -206,6 +218,8 @@ Class BuildActions
 					_desktopTarget.Checked=True
 					_desktopTarget.Checked=True
 				Case "emscripten"
 				Case "emscripten"
 					_emscriptenTarget.Checked=True
 					_emscriptenTarget.Checked=True
+				Case "wasm"
+					_wasmTarget.Checked=True
 				Case "android"
 				Case "android"
 					_androidTarget.Checked=True
 					_androidTarget.Checked=True
 				Case "ios"
 				Case "ios"
@@ -252,6 +266,7 @@ Class BuildActions
 	Field _releaseConfig:CheckButton
 	Field _releaseConfig:CheckButton
 	Field _desktopTarget:CheckButton
 	Field _desktopTarget:CheckButton
 	Field _emscriptenTarget:CheckButton
 	Field _emscriptenTarget:CheckButton
+	Field _wasmTarget:CheckButton
 	Field _androidTarget:CheckButton
 	Field _androidTarget:CheckButton
 	Field _iosTarget:CheckButton
 	Field _iosTarget:CheckButton
 	
 	
@@ -461,7 +476,7 @@ Class BuildActions
 
 
 			_debugView.DebugApp( exeFile,config )
 			_debugView.DebugApp( exeFile,config )
 
 
-		Case "emscripten"
+		Case "emscripten","wasm"
 		
 		
 			Local mserver:=GetEnv( "MX2_MSERVER" )
 			Local mserver:=GetEnv( "MX2_MSERVER" )
 			If mserver _console.Run( mserver+" ~q"+exeFile+"~q" )
 			If mserver _console.Run( mserver+" ~q"+exeFile+"~q" )

+ 44 - 2
src/ted2/buildproduct.monkey2

@@ -38,6 +38,8 @@ Class BuildProduct
 #endif
 #endif
 		Case "emscripten"
 		Case "emscripten"
 			product=New EmscriptenProduct( srcPath )
 			product=New EmscriptenProduct( srcPath )
+		Case "wasm"
+			product=New WasmProduct( srcPath )
 		Case "android"
 		Case "android"
 			product=New AndroidProduct( srcPath )
 			product=New AndroidProduct( srcPath )
 		Case "ios"
 		Case "ios"
@@ -430,9 +432,8 @@ Class EmscriptenProduct Extends BuildProduct
 
 
 	Method New( srcPath:String )
 	Method New( srcPath:String )
 		Super.New( srcPath,"emscripten" )
 		Super.New( srcPath,"emscripten" )
-		
-		AddExts( New String[]( ".html" ) )
 
 
+		AddExts( New String[]( ".html" ) )
 	End
 	End
 	
 	
 	Protected
 	Protected
@@ -454,6 +455,47 @@ Class EmscriptenProduct Extends BuildProduct
 	Method OnGetMx2ccOpts:String() Override
 	Method OnGetMx2ccOpts:String() Override
 
 
 		Local opts:=""
 		Local opts:=""
+		
+		opts+=" ~q-product="+ProductDir+AppName+".js~q"
+		
+		Return opts
+	End
+
+	Method OnGetExecutable:String() Override
+
+		Return ProductDir+AppName+".html"
+	
+	End
+End
+
+Class WasmProduct Extends BuildProduct
+
+	Method New( srcPath:String )
+		Super.New( srcPath,"wasm" )
+
+		AddExts( New String[]( ".html" ) )
+	End
+	
+	Protected
+	
+	Method OnCreateProduct() Override
+
+		CopyTemplate( "products/wasm",StripSlashes( ProductDir ) )
+		
+		CreateDir( ProductDir+"assets" )
+		
+		If AppName<>"Monkey2Game"
+		
+			CopyFile( ProductDir+"Monkey2Game.html",ProductDir+AppName+".html" )
+		
+			DeleteFile( ProductDir+"Monkey2Game.html" )
+		Endif
+	End
+	
+	Method OnGetMx2ccOpts:String() Override
+
+		Local opts:=""
+		
 		opts+=" ~q-product="+ProductDir+AppName+".js~q"
 		opts+=" ~q-product="+ProductDir+AppName+".js~q"
 		
 		
 		Return opts
 		Return opts

+ 1 - 0
src/ted2/mx2ccenv.monkey2

@@ -90,6 +90,7 @@ Function EnumValidTargets:StringStack( console:Console )
 	
 	
 	targets.Push( "desktop" )
 	targets.Push( "desktop" )
 	targets.Push( "emscripten" )
 	targets.Push( "emscripten" )
+	targets.Push( "wasm" )
 	targets.Push( "android" )
 	targets.Push( "android" )
 #If __TARGET__="macos"
 #If __TARGET__="macos"
 	targets.Push( "ios" )
 	targets.Push( "ios" )

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно