Mark Sibly 9 лет назад
Родитель
Сommit
f1c86590ef

+ 2 - 2
modules/gles20/gles20.monkey2

@@ -37,8 +37,8 @@ Using monkey
 	
 #Else If __TARGET__="android"
 
-	#import "<libGLESv1_CM.a>"
-	#import "<libGLESv2.a>"
+	#Import "<libGLESv1_CM.a>"
+	#Import "<libGLESv2.a>"
 	
 	#Import "<GLES2/gl2.h>"
 	

+ 1 - 0
modules/libc/libc.monkey2

@@ -53,6 +53,7 @@ Function fwrite:Int( buf:Void Ptr,size:Int,count:Int,stream:FILE Ptr )
 Function fclose:Int( stream:FILE Ptr )
 
 Function remove:Int( path:CString )
+Function rename:Int( oldPath:CString,newPath:CString )
 
 '***** stdlib.h *****
 

+ 55 - 11
modules/mojo/app/app.monkey2

@@ -98,13 +98,26 @@ Class AppInstance
 
 		_touchMouse=True
 
-		SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION,2 )
-	    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION,0 ) 
+		#rem		
+		SDL_GL_SetAttribute( SDL_GL_RED_SIZE,5 )
+		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE,6 )
+		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE,5 )
+		SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE,0 )
+		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,0 )
+		SDL_GL_SetAttribute( SDL_GL_RETAINED_BACKING,0 )
+		SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL,1 )
+		#end
+		
+		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,1 )
+		
     	SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK,SDL_GL_CONTEXT_PROFILE_ES )
+		SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION,2 )
+
+'	    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION,0 ) 
     	
 #endif
 
-#If __TARGET__="windows" Or __TARGET__="macos"
+#If __TARGET__="windows" Or __TARGET__="macos" Or __TARGET__="emscripten"
 
 		_captureMouse=True
 #Endif
@@ -148,8 +161,9 @@ Class AppInstance
 
 		Local _sdlGLContext:=SDL_GL_CreateContext( _sdlWindow )
 		Assert( _sdlGLContext,"FATAL ERROR: SDL_GL_CreateContext failed" )
-		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )	
-
+		
+		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )
+		
 #Endif
 		_defaultFont=Font.Open( "asset::fonts/DejaVuSans.ttf",16 )
 		
@@ -257,9 +271,7 @@ Class AppInstance
 
 #Else
 		Local dm:SDL_DisplayMode
-		
 		If SDL_GetDesktopDisplayMode( 0,Varptr dm ) Return New Vec2i
-		
 		Return New Vec2i( dm.w,dm.h )
 #Endif
 
@@ -708,7 +720,7 @@ Class AppInstance
 			_window=Window.WindowForID( mevent->windowID )
 			If Not _window Return
 			
-			_mouseLocation=New Vec2i( mevent->x,mevent->y )
+			_mouseLocation=_window.MouseScale * New Vec2i( mevent->x,mevent->y )
 			_mouseButton=Cast<MouseButton>( mevent->button )
 			
 			If Not _mouseView
@@ -746,7 +758,7 @@ Class AppInstance
 			_window=Window.WindowForID( mevent->windowID )
 			If Not _window Return
 			
-			_mouseLocation=New Vec2i( mevent->x,mevent->y )
+			_mouseLocation=_window.MouseScale * New Vec2i( mevent->x,mevent->y )
 			_mouseButton=Cast<MouseButton>( mevent->button )
 			
 			If _mouseView
@@ -776,7 +788,7 @@ Class AppInstance
 			_window=Window.WindowForID( mevent->windowID )
 			If Not _window Return
 				
-			_mouseLocation=New Vec2i( mevent->x,mevent->y )
+			_mouseLocation=_window.MouseScale * New Vec2i( mevent->x,mevent->y )
 			
 			If Not _touchMouse
 			
@@ -969,8 +981,40 @@ Class AppInstance
 				UpdateWindows()
 			
 				Return 0
-
+				
 			End
+
+#if __TARGET__="ios"
+
+		Case SDL_APP_TERMINATING
+			'Terminate the app.
+			'Shut everything down before returning from this function.		
+			return 0
+		Case SDL_APP_LOWMEMORY
+			'You will get this when your app is paused and iOS wants more memory.
+			'Release as much memory as possible.		
+	        return 0
+		Case SDL_APP_WILLENTERBACKGROUND
+			'Prepare your app to go into the background. Stop loops, etc.
+			'This gets called when the user hits the home button, or gets a call.
+	        return 0
+		Case SDL_APP_DIDENTERBACKGROUND
+			'This will get called if the user accepted whatever sent your app to the background.
+			'If the user got a phone call and canceled it, you'll instead get an SDL_APP_DIDENTERFOREGROUND event and restart your loops.
+			'When you get this, you have 5 seconds to save all your state or the app will be terminated.
+			'Your app is NOT active at this point.
+	        return 0
+		Case SDL_APP_WILLENTERFOREGROUND
+			'This call happens when your app is coming back to the foreground.
+			'Restore all your state here.
+	        return 0
+		Case SDL_APP_DIDENTERFOREGROUND
+			'Restart your loops here.
+			'Your app is interactive and getting CPU again.
+	        return 0
+
+#Endif
+	        
 		End
 		
 		Return 1

+ 50 - 17
modules/mojo/app/window.monkey2

@@ -20,6 +20,7 @@ Enum WindowFlags
 	Resizable=8
 	Borderless=16
 	Fullscreen=32
+	HighDPI=64
 	Center=CenterX|CenterY
 End
 
@@ -130,7 +131,14 @@ Class Window Extends View
 	
 	'***** INTERNAL *****
 
-	#rem monkeydoc The internal SDL_Window used by this window.
+	#rem monkeydoc @hidden Mouse scale for ios retina devices.
+	#end
+	Property MouseScale:Vec2f()
+	
+		Return _mouseScale
+	End
+	
+	#rem monkeydoc @hidden The internal SDL_Window used by this window.
 	#end
 	Property SDLWindow:SDL_Window Ptr()
 	
@@ -232,6 +240,8 @@ Class Window Extends View
 	Field _minSize:Vec2i
 	Field _maxSize:Vec2i
 	Field _frame:Recti
+	
+	Field _mouseScale:=New Vec2f( 1,1 )
 
 	'Ok, angles glViewport appears To be 'lagging' by one frame, causing weirdness when resizing.
 	Field _weirdHack:Bool
@@ -253,25 +263,36 @@ Class Window Extends View
 	End
 	
 	Method GetFrame:Recti()
+	
+#If __DESKTOP_TARGET__
+
 		Local x:Int,y:Int,w:Int,h:Int
 		SDL_GetWindowPosition( _sdlWindow,Varptr x,Varptr y )
 		SDL_GetWindowSize( _sdlWindow,Varptr w,Varptr h )
 		Return New Recti( x,y,x+w,y+h )
+		
+#Else
+		
+		Local w:Int,h:Int,dw:Int,dh:Int
+		SDL_GetWindowSize( _sdlWindow,Varptr w,Varptr h )
+#If __TARGET__="emscripten"
+		emscripten_get_canvas_size( Varptr dw,Varptr dh,Null )'Varptr fs )
+#Else
+		SDL_GL_GetDrawableSize( _sdlWindow,Varptr dw,Varptr dh )
+#Endif
+		_mouseScale=New Vec2f( Float(dw)/w,Float(dh)/h )
+		Return New Recti( 0,0,dw,dh )
+
+#Endif
+
 	End
 	
 	Method LayoutWindow()
 
 		'All this polling is a bit 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
+		'		
+#If __DESKTOP_TARGET__
 
-#Else
 		If MinSize<>_minSize
 			SDL_SetWindowMinimumSize( _sdlWindow,MinSize.x,MinSize.y )
 			_minSize=GetMinSize()
@@ -291,8 +312,12 @@ Class Window Extends View
 			Frame=_frame
 			_weirdHack=True
 		Endif
-#Endif
+#Else
+
+		_frame=GetFrame()
+		Frame=_frame
 
+#Endif
 		Measure()
 		
 		UpdateLayout()
@@ -340,12 +365,25 @@ Class Window Extends View
 		If flags & WindowFlags.Resizable sdlFlags|=SDL_WINDOW_RESIZABLE
 		If flags & WindowFlags.Borderless sdlFlags|=SDL_WINDOW_BORDERLESS
 		If flags & WindowFlags.Fullscreen _fullscreen=True ; sdlFlags|=SDL_WINDOW_FULLSCREEN
+		If flags & WindowFlags.HighDPI sdlFlags|=SDL_WINDOW_ALLOW_HIGHDPI
 		
 		_flags=flags
 		
+		'Create Window
 		_sdlWindow=SDL_CreateWindow( title,x,y,rect.Width,rect.Height,sdlFlags )
-		Assert( _sdlWindow,"FATAL ERROR: SDL_CreateWindow failed" )
+		If Not _sdlWindow
+			Print "SDL_GetError="+String.FromCString( SDL_GetError() )
+			Assert( _sdlWindow,"FATAL ERROR: SDL_CreateWindow failed" )
+		Endif
 
+		'Create GL context
+		_sdlGLContext=SDL_GL_CreateContext( _sdlWindow )
+		If Not _sdlGLContext
+			Print "SDL_GetError="+String.FromCString( SDL_GetError() )
+			Assert( _sdlGLContext,"FATAL ERROR: SDL_GL_CreateContext failed" )
+		Endif
+		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )	
+		
 		_allWindows.Push( Self )
 		_windowsByID[SDL_GetWindowID( _sdlWindow )]=Self
 		If Not (flags & WindowFlags.Hidden) _visibleWindows.Push( Self )
@@ -359,11 +397,6 @@ Class Window Extends View
 		_frame=GetFrame()
 		Frame=_frame
 		
-		'create GL context
-		_sdlGLContext=SDL_GL_CreateContext( _sdlWindow )
-		Assert( _sdlGLContext,"FATAL ERROR: SDL_GL_CreateContext failed" )
-		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )	
-		
 		_canvas=New Canvas( _frame.Width,_frame.Height )
 		
 		_clearColor=App.Theme.GetColor( "windowClearColor" )

+ 1 - 1
modules/mojo/input/mouse.monkey2

@@ -113,7 +113,7 @@ Class MouseDevice Extends InputDevice
 	Method Update()
 	
 		Local mask:=SDL_GetMouseState( Varptr _location.x,Varptr _location.y )
-		If App.ActiveWindow _location=App.ActiveWindow.TransformPointFromView( _location,Null )
+		If App.ActiveWindow	_location=App.ActiveWindow.TransformPointFromView( App.ActiveWindow.MouseScale * _location,Null )
 		
 		UpdateButton( MouseButton.Left,mask & 1 )
 		UpdateButton( MouseButton.Middle,mask & 2 )

+ 8 - 0
modules/mojo/mojo.monkey2

@@ -77,6 +77,14 @@ Function Main()
 
 	End
 
+#else if __TARGET__="ios"
+
+	Stream.OpenFuncs["asset"]=Lambda:Stream( proto:String,path:String,mode:String )
+	
+		Return SDL_RWStream.Open( "assets/"+path,mode )
+
+	End
+	
 #endif
 	
 End

+ 9 - 3
modules/monkey/native/bbdebug.h

@@ -10,6 +10,7 @@ struct bbDBVarType;
 struct bbDBVar;
 
 inline bbString bbDBType( const void *p ){ return "Void"; }
+inline bbString bbDBType( bbBool *p ){ return "Bool"; }
 inline bbString bbDBType( bbByte *p ){ return "Byte"; }
 inline bbString bbDBType( bbUByte *p ){ return "UByte"; }
 inline bbString bbDBType( bbShort *p ){ return "Short"; }
@@ -23,6 +24,7 @@ inline bbString bbDBType( bbDouble *p ){ return "Double"; }
 inline bbString bbDBType( bbString *p ){ return "String"; }
 
 inline bbString bbDBValue( void *p ){ return "?????"; }
+inline bbString bbDBValue( bbBool *p ){ return *p ? "True" : "False"; }
 inline bbString bbDBValue( bbByte *p ){ return *p; }
 inline bbString bbDBValue( bbUByte *p ){ return *p; }
 inline bbString bbDBValue( bbShort *p ){ return *p; }
@@ -33,14 +35,18 @@ inline bbString bbDBValue( bbLong *p ){ return *p; }
 inline bbString bbDBValue( bbULong *p ){ return *p; }
 inline bbString bbDBValue( bbFloat *p ){ return *p; }
 inline bbString bbDBValue( bbDouble *p ){ return *p; }
-bbString bbDBValue( bbString *p );
-
-template<class T> bbString bbDBType( T **p ){ return bbDBType( (T*)0 )+" Ptr"; }
+extern bbString bbDBValue( bbString *p );
 
 template<class T> bbString bbDBType(){
 	return bbDBType( (T*)0 );
 }
 
+template<class T> bbString bbDBType( bbGCVar<T> *p ){ return bbDBType<T*>(); }
+template<class T> bbString bbDBValue( bbGCVar<T> *p ){ T *t=p->get();return t ? bbDBValue( &t ) : "Null"; }
+
+template<class T> bbString bbDBType( T **p ){ return bbDBType<T>()+" Ptr"; }
+template<class T> bbString bbDBValue( T **p ){ char buf[64];sprintf( buf,"$%x",p );return buf; }
+
 struct bbDBVarType{
 	virtual bbString type()=0;
 	virtual bbString value( void *p )=0;

+ 4 - 2
modules/monkey/native/bbmonkey.cpp

@@ -1,6 +1,8 @@
 
 #include "bbmonkey.h"
 
+#include "bbplatform.h"
+
 #include <stdarg.h>
 
 int bb_argc;
@@ -8,7 +10,7 @@ char **bb_argv;
 
 void bbMain();
 
-#ifdef __ANDROID__
+#if BB_ANDROID
 
 #include <android/log.h>
 
@@ -39,7 +41,7 @@ void bb_printf( const char *fmt,... ){
 
 #endif
 
-#ifdef __ANDROID__
+#if BB_ANDROID || BB_IOS
 
 extern "C" int SDL_main( int argc,char *argv[] ){