Selaa lähdekoodia

Started work on resurrecting emscripten.

Mark Sibly 9 vuotta sitten
vanhempi
commit
d8e3e9b32c

+ 51 - 20
modules/mojo/app/app.monkey2

@@ -43,6 +43,8 @@ Class AppInstance
 	
 		SDL_Init( SDL_INIT_EVERYTHING )
 
+#If __TARGET__<>"emscripten"
+
 		_glWindow=SDL_CreateWindow( "",0,0,0,0,SDL_WINDOW_HIDDEN|SDL_WINDOW_OPENGL )
 
 		_glContext=SDL_GL_CreateContext( _glWindow )
@@ -51,12 +53,13 @@ Class AppInstance
 		
 		SDL_GL_SetAttribute( SDL_GL_SHARE_WITH_CURRENT_CONTEXT,1 )
 		
+#Endif
 		_keyMatrix=SDL_GetKeyboardState( Varptr _numKeys )
-			
+		
 		_defaultFont=Font.Open( DefaultFontName,16 )
 		
 		_defaultMonoFont=Font.Open( DefaultMonoFontName,16 )
-		
+
 		Local style:=Style.GetStyle( "" )
 		style.DefaultFont=_defaultFont
 		style.DefaultColor=Color.White
@@ -158,11 +161,20 @@ Class AppInstance
 	#end	
 	Property DesktopSize:Vec2i()
 	
+#If __TARGET__="emscripten"
+
+		Return New Vec2i( 1280,960 )
+
+#Else
+	
 		Local dm:SDL_DisplayMode
 		
 		If SDL_GetDesktopDisplayMode( 0,Varptr dm ) Return New Vec2i
 		
 		Return New Vec2i( dm.w,dm.h )
+		
+#Endif
+
 	End
 
 	#rem monkeydoc The current active window.
@@ -228,35 +240,54 @@ Class AppInstance
 		_requestRender=True
 	End
 
+	#rem @hidden
+	#end
+	Method MainLoop()
+	
+		If Not _requestRender 
+		
+			SDL_WaitEvent( Null )
+			
+		Endif
+	
+		UpdateEvents()
+		
+		If Not _requestRender Return
+		
+		_requestRender=False
+			
+		For Local window:=Eachin Window.VisibleWindows()
+			window.Render()
+		Next
+			
+	End
+	
+	Function EmscriptenMainLoop()
+	
+		App._requestRender=True
+		
+		App.MainLoop()
+	End
+	
 	#rem monkeydoc Run the app.
 	#end
 	Method Run()
 	
 		SDL_AddEventWatch( _EventFilter,Null )
-	
+		
 		RequestRender()
-	
-		Repeat
 		
-			If Not _requestRender 
-			
-				SDL_WaitEvent( Null )
-				
-			Endif
+#If __TARGET__="emscripten"
+
+		emscripten_set_main_loop( EmscriptenMainLoop,0,1 )
 		
-			UpdateEvents()
+#Else
+		Repeat
 		
-			If _requestRender
-
-				_requestRender=False
-				
-				For Local window:=Eachin Window.VisibleWindows()
-					window.Render()
-				Next
-				
-			Endif
+			MainLoop()
 			
 		Forever
+#Endif
 	
 	End
 

+ 7 - 0
modules/mojo/app/window.monkey2

@@ -76,6 +76,13 @@ Class Window Extends View
 	#end
 	Method Update()
 	
+		'ugly...fixme.
+#If __TARGET__="emscripten"
+		Local w:Int,h:Int,fs:Int
+		emscripten_get_canvas_size( Varptr w,Varptr h,Varptr fs )
+		If w<>Frame.Width Or h<>Frame.Height Frame=New Recti( 0,0,w,h )
+#Endif
+
 		'ugly...fixme.
 		If MinSize<>_minSize Or MaxSize<>_maxSize Or Frame<>_frame
 			_minSize=MinSize

+ 2 - 0
modules/mojo/mojo.monkey2

@@ -1,6 +1,7 @@
 
 Namespace mojo
 
+#Import "<emscripten>"
 #Import "<std>"
 #Import "<sdl2>"
 
@@ -26,6 +27,7 @@ Namespace mojo
 #Import "graphics/texture"
 #Import "graphics/vertex"
 
+Using emscripten..
 Using std..
 Using sdl2..
 Using gles20..

+ 4 - 0
modules/sdl2/makefile_emscripten.monkey2

@@ -1,6 +1,8 @@
 
 Namespace sdl2
 
+#rem
+
 'source files
 
 'root
@@ -130,3 +132,5 @@ Namespace sdl2
 #Import "SDL/src/video/emscripten/SDL_emscriptenmouse.c"
 #Import "SDL/src/video/emscripten/SDL_emscriptenopengles.c"
 #Import "SDL/src/video/emscripten/SDL_emscriptenvideo.c"
+
+#end