Przeglądaj źródła

Merge pull request #55 from blitz-research/develop

Develop up
abakobo 8 lat temu
rodzic
commit
292e4a169e
52 zmienionych plików z 508 dodań i 397 usunięć
  1. 4 6
      README.TXT
  2. 0 1
      bananas/commanche/commanche.monkey2
  3. 2 0
      bananas/rendertoimage/rendertoimage.monkey2
  4. 22 12
      bananas/spacechimps/spacechimps.monkey2
  5. 1 1
      bin/env_windows.txt
  6. 1 1
      modules/jni/module.json
  7. 1 1
      modules/libc/module.json
  8. 1 1
      modules/litehtml/module.json
  9. 1 1
      modules/miniz/module.json
  10. 1 4
      modules/mojo/app/skin.monkey2
  11. 0 2
      modules/mojo/app/theme.monkey2
  12. 22 16
      modules/mojo/app/window.monkey2
  13. 55 37
      modules/mojo/audio/audio.monkey2
  14. 0 2
      modules/mojo/graphics/canvas.monkey2
  15. 1 1
      modules/mojo/graphics/font.monkey2
  16. 16 13
      modules/mojo/graphics/freetypefont.monkey2
  17. 23 42
      modules/mojo/graphics/image.monkey2
  18. 1 14
      modules/mojo/graphics/rendertarget.monkey2
  19. 6 1
      modules/mojo/graphics/shader.monkey2
  20. 3 18
      modules/mojo/graphics/texture.monkey2
  21. 4 7
      modules/mojo/graphics/uniformblock.monkey2
  22. 1 1
      modules/mojo/module.json
  23. 1 1
      modules/mojox/module.json
  24. 1 1
      modules/mojox/tests/assets/about.html
  25. 1 1
      modules/mojox/tests/assets/mainwindow.monkey2
  26. 1 1
      modules/monkey/docs/sdks.md
  27. 4 0
      modules/monkey/gc.monkey2
  28. 1 1
      modules/monkey/module.json
  29. 58 11
      modules/monkey/native/bbgc.cpp
  30. 2 0
      modules/monkey/native/bbgc.h
  31. 3 3
      modules/monkey/types.monkey2
  32. 1 1
      modules/openal/module.json
  33. 1 1
      modules/reflection/module.json
  34. 1 1
      modules/sdl2-mixer/module.json
  35. 1 1
      modules/sdl2/module.json
  36. 1 1
      modules/stb-image-write/module.json
  37. 1 1
      modules/stb-image/module.json
  38. 1 1
      modules/stb-truetype/module.json
  39. 9 9
      modules/stb-vorbis/module.json
  40. 24 25
      modules/std/audio/audiodata.monkey2
  41. 29 4
      modules/std/audio/load_vorbis.monkey2
  42. 49 14
      modules/std/graphics/pixmap.monkey2
  43. 12 8
      modules/std/graphics/pixmaploader.monkey2
  44. 10 7
      modules/std/memory/databuffer.monkey2
  45. 1 1
      modules/std/module.json
  46. 60 79
      modules/std/resource/resource.monkey2
  47. 23 7
      modules/std/socket/socket.monkey2
  48. 10 15
      modules/std/stream/filestream.monkey2
  49. 24 5
      modules/std/stream/stream.monkey2
  50. 8 8
      modules/theoraplayer/module.json
  51. 3 3
      src/ted2/helpactions.monkey2
  52. 1 4
      src/ted2/modulemanager.monkey2

+ 4 - 6
README.TXT

@@ -10,7 +10,7 @@ Grabbing the most recently tagged version is recommended if you just want to giv
 
 
 1) Install the mingw-64 compiler. There is a self-extracting archive of mingw-64 that has been tested with monkey2 here:
 1) Install the mingw-64 compiler. There is a self-extracting archive of mingw-64 that has been tested with monkey2 here:
 
 
-http://monkey2.monkey-x.com/get-file?file=i686-6.2.0-posix-dwarf-rt_v5-rev1.exe
+http://monkeycoder.co.nz/get-file?file=i686-6.2.0-posix-dwarf-rt_v5-rev1.exe
 
 
 If you install this to the monkey2 'devtools' directory, the following steps should 'just work'.
 If you install this to the monkey2 'devtools' directory, the following steps should 'just work'.
 
 
@@ -44,10 +44,8 @@ When installing, you should select 'i686' for 'architecture', 'posix' for 'threa
 
 
 ***** More information *****
 ***** More information *****
 
 
-Monkey2 patreon page: https://www.patreon.com/monkey2?ty=h
+Monkey2 patreon page: https://www.patreon.com/monkey2
 
 
-Monkey2 development blog: http://monkey2.monkey-x.com/
+Monkey2 development blog: http://monkeycoder.co.nz/
 
 
-Monkey2 development forums: http://monkey2.monkey-x.com/forums
-
-Monkey2 xmas 2015 demo: http://monkey2.monkey-x.com/2015/12/23/xmas-demo-2015/
+Monkey2 development forums: http://monkeycoder.co.nz/forums

+ 0 - 1
bananas/commanche/commanche.monkey2

@@ -45,7 +45,6 @@ Class MyWindow Extends Window
 	End Method
 	End Method
 	'-----------------------------------------------------------------------------------------------------------
 	'-----------------------------------------------------------------------------------------------------------
 	Method OnRender( canvas:Canvas ) Override
 	Method OnRender( canvas:Canvas ) Override
-		GCCollect()
 		PmapDest.Clear(Color.Black)
 		PmapDest.Clear(Color.Black)
 		App.RequestRender()
 		App.RequestRender()
 		UpdateCamera()
 		UpdateCamera()

+ 2 - 0
bananas/rendertoimage/rendertoimage.monkey2

@@ -23,6 +23,8 @@ Class MyWindow Extends mojo.app.Window
 	
 	
 		image=New Image( 256,256,PixelFormat.RGBA8,Dynamic ? TextureFlags.Dynamic Else Null )
 		image=New Image( 256,256,PixelFormat.RGBA8,Dynamic ? TextureFlags.Dynamic Else Null )
 		
 		
+		image.Texture.Flags|=TextureFlags.Filter
+		
 		image.Handle=New Vec2f( .5,.5 )
 		image.Handle=New Vec2f( .5,.5 )
 		
 		
 		icanvas=New Canvas( image )
 		icanvas=New Canvas( image )

+ 22 - 12
bananas/spacechimps/spacechimps.monkey2

@@ -38,18 +38,10 @@ Class MyWindow Extends Window
 		'		
 		'		
 		ClearColor=New Color( .03,.03,.03 )
 		ClearColor=New Color( .03,.03,.03 )
 		
 		
-		'Load laser sound effect
-		'		
-		laser=Sound.Load( "asset::bang.wav" )
-		
-		'Load spaceship image.
-		'
-		'Note: scaling image here is faster than scaling via Canvas matrix.
+		'load audio/images
 		'
 		'
-		image=Image.Load( "asset::spaceship_32.png" )
-		image.Scale=New Vec2f( 2 )
-		image.Handle=New Vec2f( .5 )
-
+		LoadResources()
+		
 		'Set initial image pos
 		'Set initial image pos
 		'
 		'
 		pos=New Vec2f( VirtualWidth/2,VirtualHeight/2 )
 		pos=New Vec2f( VirtualWidth/2,VirtualHeight/2 )
@@ -63,6 +55,21 @@ Class MyWindow Extends Window
 		SwapInterval=1
 		SwapInterval=1
 	End
 	End
 	
 	
+	Method LoadResources()
+		
+		'Load laser sound effect
+		'		
+		laser=Sound.Load( "asset::bang.wav" )
+		
+		'Load spaceship image.
+		'
+		'Note: scaling image here via Image.Scale is faster than scaling via Canvas matrix.
+		'
+		image=Image.Load( "asset::spaceship_32.png" )
+		image.Scale=New Vec2f( 2 )
+		image.Handle=New Vec2f( .5 )
+	End
+	
 	Method OnKeyEvent( event:KeyEvent ) Override
 	Method OnKeyEvent( event:KeyEvent ) Override
 		Select event.Type
 		Select event.Type
 		Case EventType.KeyDown
 		Case EventType.KeyDown
@@ -109,6 +116,10 @@ Class MyWindow Extends Window
 	
 	
 		RequestRender()
 		RequestRender()
 		
 		
+		'give GC a bit of a thrash....
+		'
+		'LoadResources()
+		
 		'rotate
 		'rotate
 		'
 		'
 		If Keyboard.KeyDown( Key.Left )
 		If Keyboard.KeyDown( Key.Left )
@@ -194,7 +205,6 @@ Class MyWindow Extends Window
 	Method OnMeasure:Vec2i() Override
 	Method OnMeasure:Vec2i() Override
 	
 	
 		Return New Vec2i( VirtualWidth,VirtualHeight )
 		Return New Vec2i( VirtualWidth,VirtualHeight )
-		
 	End
 	End
 	
 	
 End
 End

+ 1 - 1
bin/env_windows.txt

@@ -8,7 +8,7 @@ MX2_WHOLE_ARCHIVE=0
 
 
 '***** WINDOWS DESKTOP TARGET - MINGW *****
 '***** WINDOWS DESKTOP TARGET - MINGW *****
 
 
-'Note: Requires MinGW compilers+build tools, see: https://monkey2.monkey-x.com/monkey2-files.
+'Note: Requires MinGW compilers+build tools, see: http://monkeycoder.co.nz/monkey2-files.
 '
 '
 '(Note: TDM GCC not recommended, as it uses SJLJ exceptions which are very slow)
 '(Note: TDM GCC not recommended, as it uses SJLJ exceptions which are very slow)
 '
 '

+ 1 - 1
modules/jni/module.json

@@ -3,6 +3,6 @@
 	"about":"Java JNI wrapper",
 	"about":"Java JNI wrapper",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc"]
 	"depends":["libc"]
 }
 }

+ 1 - 1
modules/libc/module.json

@@ -3,6 +3,6 @@
 	"about":"StdC library wrapper",
 	"about":"StdC library wrapper",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":[]
 	"depends":[]
 }
 }

+ 1 - 1
modules/litehtml/module.json

@@ -3,6 +3,6 @@
 	"about":"Simple html renderer",
 	"about":"Simple html renderer",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc"]
 	"depends":["libc"]
 }
 }

+ 1 - 1
modules/miniz/module.json

@@ -3,6 +3,6 @@
 	"about":"Mini Zip library",
 	"about":"Mini Zip library",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc"]
 	"depends":["libc"]
 }
 }

+ 1 - 4
modules/mojo/app/skin.monkey2

@@ -47,15 +47,12 @@ Class Skin Extends Resource
 		If Not pixmap Return Null
 		If Not pixmap Return Null
 		
 		
 		Return New Skin( pixmap )
 		Return New Skin( pixmap )
-		
-		pixmap.Release()
 	End
 	End
 	
 	
 	Protected
 	Protected
 	
 	
 	Method OnDiscard() Override
 	Method OnDiscard() Override
-
-		_image.Release()
+		_image=Null
 	End
 	End
 	
 	
 	Private
 	Private

+ 0 - 2
modules/mojo/app/theme.monkey2

@@ -133,8 +133,6 @@ Class Theme
 				icons.images[i]=image
 				icons.images[i]=image
 			Next
 			Next
 			
 			
-			icons.AddDependancy( atlas )
-
 			_res.AddResource( slug,icons )
 			_res.AddResource( slug,icons )
 		Endif
 		Endif
 		
 		

+ 22 - 16
modules/mojo/app/window.monkey2

@@ -259,7 +259,7 @@ Class Window Extends View
 		Case EventType.WindowMoved,EventType.WindowResized
 		Case EventType.WindowMoved,EventType.WindowResized
 			_frame=GetFrame()
 			_frame=GetFrame()
 			Frame=_frame
 			Frame=_frame
-			_weirdHack=true
+			_weirdHack=True
 		End
 		End
 		
 		
 		OnWindowEvent( event )
 		OnWindowEvent( event )
@@ -342,20 +342,6 @@ Class Window Extends View
 	Global _visibleWindows:=New Stack<Window>
 	Global _visibleWindows:=New Stack<Window>
 	Global _windowsByID:=New Map<UInt,Window>
 	Global _windowsByID:=New Map<UInt,Window>
 	
 	
-	Method UpdateMouseScale()
-	
-		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 )
-	End
-	
 	Method SetMinSize( size:Vec2i )
 	Method SetMinSize( size:Vec2i )
 		size/=_mouseScale
 		size/=_mouseScale
 		SDL_SetWindowMinimumSize( _sdlWindow,size.x,size.y )
 		SDL_SetWindowMinimumSize( _sdlWindow,size.x,size.y )
@@ -391,8 +377,22 @@ Class Window Extends View
 		Return New Recti( x,y,x+w,y+h ) * _mouseScale
 		Return New Recti( x,y,x+w,y+h ) * _mouseScale
 	End
 	End
 	
 	
+	Method UpdateMouseScale()
+	
+		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 )
+#Else
+		SDL_GL_GetDrawableSize( _sdlWindow,Varptr dw,Varptr dh )
+#Endif
+		_mouseScale=New Vec2f( Float(dw)/w,Float(dh)/h )
+	End
+	
 	Method LayoutWindow()
 	Method LayoutWindow()
-
+		
 		'All this polling is a bit ugly...fixme.
 		'All this polling is a bit ugly...fixme.
 		'		
 		'		
 #If __DESKTOP_TARGET__
 #If __DESKTOP_TARGET__
@@ -415,6 +415,12 @@ Class Window Extends View
 			_frame=Frame
 			_frame=Frame
 			_weirdHack=True
 			_weirdHack=True
 		Endif
 		Endif
+		
+#Else if __WEB_TARGET__
+
+		Local dw:Int,dh:Int
+		emscripten_get_canvas_size( Varptr dw,Varptr dh,Null )
+		Frame=New Recti( 0,0,dw,dh )
 #Else
 #Else
 		_frame=GetFrame()
 		_frame=GetFrame()
 		Frame=_frame
 		Frame=_frame

+ 55 - 37
modules/mojo/audio/audio.monkey2

@@ -69,11 +69,12 @@ End
 
 
 #rem monkeydoc The Sound class.
 #rem monkeydoc The Sound class.
 #end
 #end
-Class Sound
+Class Sound Extends Resource
 
 
 	#rem monkeydoc Creates a new sound.
 	#rem monkeydoc Creates a new sound.
 	#end
 	#end
 	Method New( data:AudioData )
 	Method New( data:AudioData )
+		
 		alGenBuffers( 1,Varptr _alBuffer )
 		alGenBuffers( 1,Varptr _alBuffer )
 		alBufferData( _alBuffer,ALFormat( data.Format ),data.Data,data.Size,data.Hertz )
 		alBufferData( _alBuffer,ALFormat( data.Format ),data.Data,data.Size,data.Hertz )
 		_format=data.Format
 		_format=data.Format
@@ -81,35 +82,31 @@ Class Sound
 		_hertz=data.Hertz
 		_hertz=data.Hertz
 	End
 	End
 	
 	
-	#rem monkeydoc Discards a sound.
-	#end
-	Method Discard()
-		If Not _alBuffer Return
-		alDeleteBuffers( 1,Varptr _alBuffer )
-		_alBuffer=0
-	End
-	
 	#rem monkeydoc The length, in samples, of the sound.
 	#rem monkeydoc The length, in samples, of the sound.
 	#end
 	#end
 	Property Length:Int()
 	Property Length:Int()
+		
 		Return _length
 		Return _length
 	End
 	End
 	
 	
 	#rem monkeydoc The format of the sound.
 	#rem monkeydoc The format of the sound.
 	#end
 	#end
 	Property Format:AudioFormat()
 	Property Format:AudioFormat()
+		
 		Return _format
 		Return _format
 	End
 	End
 	
 	
 	#rem monkeydoc The playback rate of the sound.
 	#rem monkeydoc The playback rate of the sound.
 	#end
 	#end
 	Property Hertz:Int()
 	Property Hertz:Int()
+		
 		Return _hertz
 		Return _hertz
 	End
 	End
 	
 	
 	#rem monkeydoc The duration, in seconds, of the sound.
 	#rem monkeydoc The duration, in seconds, of the sound.
 	#end
 	#end
 	Property Duration:Double()
 	Property Duration:Double()
+		
 		Return Double(_length)/Double(_hertz)
 		Return Double(_length)/Double(_hertz)
 	End
 	End
 	
 	
@@ -140,6 +137,24 @@ Class Sound
 		Return sound
 		Return sound
 	End
 	End
 	
 	
+	Protected
+	
+	#rem monkeydoc @hidden
+	#end
+	Method OnDiscard() Override
+		
+		If _alBuffer alDeleteBuffers( 1,Varptr _alBuffer )
+			
+		_alBuffer=0
+	End
+	
+	#rem monkeydoc @hidden
+	#end
+	Method OnFinalize() Override
+		
+		If _alBuffer alDeleteBuffers( 1,Varptr _alBuffer )
+	End
+	
 	Private
 	Private
 	
 	
 	Field _alBuffer:ALuint
 	Field _alBuffer:ALuint
@@ -157,10 +172,11 @@ End
 
 
 #end
 #end
 Enum ChannelFlags
 Enum ChannelFlags
+	
 	AutoDiscard=1
 	AutoDiscard=1
 End
 End
 
 
-Class Channel
+Class Channel Extends Resource
 
 
 	#rem monkeydoc Creates a new audio channel.
 	#rem monkeydoc Creates a new audio channel.
 	
 	
@@ -172,15 +188,11 @@ Class Channel
 	
 	
 		_flags=flags
 		_flags=flags
 	
 	
-		FlushTmpChannels()
+		FlushAutoDiscard()
 		
 		
 		alGenSources( 1,Varptr _alSource )
 		alGenSources( 1,Varptr _alSource )
 		
 		
-		If _flags & ChannelFlags.AutoDiscard _tmpChannels.Push( Self )
-		
-		_active+=1
-		
-'		Print "Active channels="+_active
+		If _flags & ChannelFlags.AutoDiscard _autoDiscard.Push( Self )
 	End
 	End
 	
 	
 	Property Flags:ChannelFlags()
 	Property Flags:ChannelFlags()
@@ -306,18 +318,6 @@ Class Channel
 		alSourcef( _alSource,AL_SEC_OFFSET,time )
 		alSourcef( _alSource,AL_SEC_OFFSET,time )
 	End
 	End
 	
 	
-	#rem monkeydoc Discards channel resources.
-	#end
-	Method Discard()
-		If Not _alSource Return
-		
-		alDeleteSources( 1,Varptr _alSource )
-		_alSource=0
-		
-		_active-=1
-		Print "Active channels="+_active
-	End
-
 	#rem monkeydoc Plays a sound through the channel.
 	#rem monkeydoc Plays a sound through the channel.
 	#end
 	#end
 	Method Play( sound:Sound,loop:Bool=False )
 	Method Play( sound:Sound,loop:Bool=False )
@@ -400,6 +400,24 @@ Class Channel
 		
 		
 		If _flags & ChannelFlags.AutoDiscard Discard()
 		If _flags & ChannelFlags.AutoDiscard Discard()
 	End
 	End
+	
+	Protected
+	
+	#rem monkeydoc @hidden
+	#end
+	Method OnDiscard() Override
+
+		If _alSource alDeleteSources( 1,Varptr _alSource )
+		
+		_alSource=0
+	End
+	
+	#rem monkeydoc @hidden
+	#end
+	Method OnFinalize() Override
+
+		If _alSource alDeleteSources( 1,Varptr _alSource )
+	End
 
 
 	Private
 	Private
 	
 	
@@ -409,9 +427,7 @@ Class Channel
 	Field _rate:Float=1
 	Field _rate:Float=1
 	Field _pan:Float=0
 	Field _pan:Float=0
 	
 	
-	Global _active:=0
-	
-	Global _tmpChannels:=New Stack<Channel>
+	Global _autoDiscard:=New Stack<Channel>
 	
 	
 	Method ALState:ALenum()
 	Method ALState:ALenum()
 		Local state:ALenum
 		Local state:ALenum
@@ -419,21 +435,25 @@ Class Channel
 		Return state
 		Return state
 	End
 	End
 	
 	
-	Function FlushTmpChannels()
+	Function FlushAutoDiscard()
 	
 	
 		Local put:=0
 		Local put:=0
-		For Local chan:=Eachin _tmpChannels
+		
+		For Local chan:=Eachin _autoDiscard
+			
 			If Not chan._alSource Continue
 			If Not chan._alSource Continue
 		
 		
 			If chan.ALState()<>AL_STOPPED
 			If chan.ALState()<>AL_STOPPED
-				_tmpChannels[put]=chan;put+=1
+				
+				_autoDiscard[put]=chan;put+=1
+				
 				Continue
 				Continue
 			Endif
 			Endif
 			
 			
 			chan.Discard()
 			chan.Discard()
 		Next
 		Next
 
 
-		_tmpChannels.Resize( put )
+		_autoDiscard.Resize( put )
 	End
 	End
 	
 	
 	#if __TARGET__<>"emscripten"
 	#if __TARGET__<>"emscripten"
@@ -450,8 +470,6 @@ Class Channel
 		Local proc:ALint
 		Local proc:ALint
 		alGetSourcei( _alSource,AL_BUFFERS_PROCESSED,Varptr proc )
 		alGetSourcei( _alSource,AL_BUFFERS_PROCESSED,Varptr proc )
 		
 		
-'		Print "processed: "+proc
-
 		If Not proc Return 0
 		If Not proc Return 0
 		
 		
 		For Local i:=0 Until proc
 		For Local i:=0 Until proc

+ 0 - 2
modules/mojo/graphics/canvas.monkey2

@@ -26,8 +26,6 @@ Class Canvas
 		
 		
 		Local rtarget:=New RenderTarget( New Texture[]( image.Texture ),Null )
 		Local rtarget:=New RenderTarget( New Texture[]( image.Texture ),Null )
 		
 		
-		image.Discarded+=rtarget.Release
-		
 		Init( rtarget,New GraphicsDevice )
 		Init( rtarget,New GraphicsDevice )
 		
 		
 		BeginRender( New Recti( 0,0,image.Rect.Size ),AffineMat3f.Translation( image.Rect.Origin ) )
 		BeginRender( New Recti( 0,0,image.Rect.Size ),AffineMat3f.Translation( image.Rect.Origin ) )

+ 1 - 1
modules/mojo/graphics/font.monkey2

@@ -132,7 +132,7 @@ Class Font Extends Resource
 	Method OnDiscard() Override
 	Method OnDiscard() Override
 
 
 		For Local page:=Eachin _pages
 		For Local page:=Eachin _pages
-			If page SafeRelease( page.image )
+			If page.image page.image.Discard()
 		Next
 		Next
 		
 		
 		_pages=Null
 		_pages=Null

+ 16 - 13
modules/mojo/graphics/freetypefont.monkey2

@@ -36,25 +36,17 @@ Class FreeTypeFont Extends Font
 		
 		
 		Local face:FT_Face
 		Local face:FT_Face
 		If FT_New_Memory_Face( FreeType,data.Data,data.Length,0,Varptr face ) 
 		If FT_New_Memory_Face( FreeType,data.Data,data.Length,0,Varptr face ) 
-			data.Release()
+			data.Discard()
 			Return Null
 			Return Null
 		Endif
 		Endif
 		
 		
 		Local font:=New FreeTypeFont( data,face,fheight,shader )
 		Local font:=New FreeTypeFont( data,face,fheight,shader )
-		font.Discarded+=data.Discard
 		
 		
 		Return font
 		Return font
 	End
 	End
 	
 	
 	Protected
 	Protected
 	
 	
-	Method OnDiscard() Override
-	
-		FT_Done_Face( _face )
-	
-		Super.OnDiscard()
-	End
-	
 	Method OnLoadGlyphPage( page:Int,gpage:GlyphPage ) Override
 	Method OnLoadGlyphPage( page:Int,gpage:GlyphPage ) Override
 	
 	
 		Const MaxTexWidth:=1024
 		Const MaxTexWidth:=1024
@@ -130,7 +122,7 @@ Class FreeTypeFont Extends Font
 			
 			
 			pixmap.Paste( tmp,tx,ty )
 			pixmap.Paste( tmp,tx,ty )
 			
 			
-			tmp.Release()
+			tmp.Discard()
 			
 			
 			Local glyph:=New Glyph( New Recti( tx,ty,tx+gw,ty+gh ),New Vec2f( slot->bitmap_left,_ascent-slot->bitmap_top ),slot->advance.x Shr 6 )
 			Local glyph:=New Glyph( New Recti( tx,ty,tx+gw,ty+gh ),New Vec2f( slot->bitmap_left,_ascent-slot->bitmap_top ),slot->advance.x Shr 6 )
 	
 	
@@ -143,11 +135,21 @@ Class FreeTypeFont Extends Font
 		gpage.image=New Image( pixmap,TextureFlags.Filter|TextureFlags.Mipmap,_shader )
 		gpage.image=New Image( pixmap,TextureFlags.Filter|TextureFlags.Mipmap,_shader )
 		gpage.glyphs=glyphs
 		gpage.glyphs=glyphs
 		
 		
-		pixmap.Release()
-		
 '		Print "Loading glyph page "+page+", image size="+gpage.image.Rect.Size
 '		Print "Loading glyph page "+page+", image size="+gpage.image.Rect.Size
 	End
 	End
-
+	
+	Method OnDiscard() Override
+	
+		FT_Done_Face( _face )
+		
+		_data.Discard()
+		
+		_data=Null
+		_face=Null
+		_shader=Null
+		
+	End
+	
 	Private
 	Private
 	
 	
 	Field _data:DataBuffer
 	Field _data:DataBuffer
@@ -157,6 +159,7 @@ Class FreeTypeFont Extends Font
 	Field _ascent:Int
 	Field _ascent:Int
 	
 	
 	Method New( data:DataBuffer,face:FT_Face,fheight:Float,shader:Shader )
 	Method New( data:DataBuffer,face:FT_Face,fheight:Float,shader:Shader )
+		
 		_data=data
 		_data=data
 		_face=face
 		_face=face
 		_shader=shader
 		_shader=shader

+ 23 - 42
modules/mojo/graphics/image.monkey2

@@ -35,8 +35,6 @@ Class Image Extends Resource
 	
 	
 	New( image,... ) Creates an image from within an 'atlas' image.
 	New( image,... ) Creates an image from within an 'atlas' image.
 	
 	
-	Note: `textureFlags` should be null for static images or TextureFlags.Dynamic for dynamic images.
-
 	@param pixmap Source image.
 	@param pixmap Source image.
 	
 	
 	@param textureFlags Image texture flags. 
 	@param textureFlags Image texture flags. 
@@ -52,29 +50,21 @@ Class Image Extends Resource
 	@param width,height Image size.
 	@param width,height Image size.
 	
 	
 	#end	
 	#end	
-	Method New( pixmap:Pixmap,textureFlags:TextureFlags=Null,shader:Shader=Null )
+	Method New( pixmap:Pixmap,textureFlags:TextureFlags=TextureFlags.FilterMipmap,shader:Shader=Null )
 		
 		
-		textureFlags=MakeTextureFlags( textureFlags )
-	
 		Local texture:=New Texture( pixmap,textureFlags )
 		Local texture:=New Texture( pixmap,textureFlags )
 		
 		
-		Discarded+=texture.Release
-		
 		Init( texture,shader )
 		Init( texture,shader )
 	End
 	End
 
 
-	Method New( width:Int,height:Int,format:PixelFormat,textureFlags:TextureFlags=Null,shader:Shader=Null )
+	Method New( width:Int,height:Int,format:PixelFormat,textureFlags:TextureFlags=TextureFlags.FilterMipmap,shader:Shader=Null )
 		
 		
-		textureFlags=MakeTextureFlags( textureFlags )
-	
 		Local texture:=New Texture( width,height,format,textureFlags )
 		Local texture:=New Texture( width,height,format,textureFlags )
 		
 		
-		Discarded+=texture.Release
-		
 		Init( texture,shader )
 		Init( texture,shader )
 	End
 	End
 
 
-	Method New( width:Int,height:Int,textureFlags:TextureFlags=null,shader:Shader=Null )
+	Method New( width:Int,height:Int,textureFlags:TextureFlags=TextureFlags.FilterMipmap,shader:Shader=Null )
 		
 		
 		Self.New( width,height,PixelFormat.RGBA8,textureFlags,shader )
 		Self.New( width,height,PixelFormat.RGBA8,textureFlags,shader )
 	End
 	End
@@ -218,7 +208,7 @@ Class Image Extends Resource
 	
 	
 		_color=color
 		_color=color
 		
 		
-		_material.SetVec4f( "ImageColor",_color )
+		_uniforms.SetVec4f( "ImageColor",_color )
 	End
 	End
 
 
 	#rem monkeydoc The image light depth.
 	#rem monkeydoc The image light depth.
@@ -231,7 +221,7 @@ Class Image Extends Resource
 	
 	
 		_lightDepth=depth
 		_lightDepth=depth
 		
 		
-		_material.SetFloat( "LightDepth",_lightDepth )
+		_uniforms.SetFloat( "LightDepth",_lightDepth )
 	End
 	End
 
 
 	#rem monkeydoc Shadow caster attached to image.
 	#rem monkeydoc Shadow caster attached to image.
@@ -289,7 +279,7 @@ Class Image Extends Resource
 	#end
 	#end
 	Property Material:UniformBlock()
 	Property Material:UniformBlock()
 	
 	
-		Return _material
+		Return _uniforms
 	End
 	End
 
 
 	#rem monkeydoc @hidden Image vertices.
 	#rem monkeydoc @hidden Image vertices.
@@ -312,7 +302,7 @@ Class Image Extends Resource
 	
 	
 		_textures[index]=texture
 		_textures[index]=texture
 		
 		
-		_material.SetTexture( "ImageTexture"+index,texture )
+		_uniforms.SetTexture( "ImageTexture"+index,texture )
 	End
 	End
 	
 	
 	#rem monkeydoc @hidden gets an image's texture.
 	#rem monkeydoc @hidden gets an image's texture.
@@ -321,19 +311,17 @@ Class Image Extends Resource
 	
 	
 		Return _textures[index]
 		Return _textures[index]
 	End
 	End
-	
+
 	#rem monkeydoc Loads an image from file.
 	#rem monkeydoc Loads an image from file.
 	#end
 	#end
-	Function Load:Image( path:String,shader:Shader=Null )
+	Function Load:Image( path:String,shader:Shader=Null,textureFlags:TextureFlags=TextureFlags.FilterMipmap )
 		
 		
 		Local pixmap:=Pixmap.Load( path,Null,True )
 		Local pixmap:=Pixmap.Load( path,Null,True )
 		If Not pixmap Return Null
 		If Not pixmap Return Null
 
 
 		If Not shader shader=mojo.graphics.Shader.GetShader( "sprite" )
 		If Not shader shader=mojo.graphics.Shader.GetShader( "sprite" )
 		
 		
-		Local image:=New Image( pixmap,Null,shader )
-		
-		image.Discarded+=pixmap.Release
+		Local image:=New Image( pixmap,textureFlags,shader )
 		
 		
 		Return image
 		Return image
 	End
 	End
@@ -362,9 +350,6 @@ Class Image Extends Resource
 		
 		
 		Local image:=New Image( texture0,shader )
 		Local image:=New Image( texture0,shader )
 
 
-		image.Discarded+=texture0.Release
-		image.Discarded+=texture1.Release
-		
 		image.SetTexture( 1,texture1 )
 		image.SetTexture( 1,texture1 )
 		
 		
 		Return image
 		Return image
@@ -386,9 +371,7 @@ Class Image Extends Resource
 			
 			
 		Case PixelFormat.A8
 		Case PixelFormat.A8
 
 
-			Local tpixmap:=pixmap
 			pixmap=pixmap.Convert( PixelFormat.IA16 )
 			pixmap=pixmap.Convert( PixelFormat.IA16 )
-			tpixmap.Release()
 
 
 			'Copy A->I
 			'Copy A->I
 			For Local y:=0 Until pixmap.Height
 			For Local y:=0 Until pixmap.Height
@@ -401,9 +384,7 @@ Class Image Extends Resource
 
 
 		Case PixelFormat.I8
 		Case PixelFormat.I8
 		
 		
-			Local tpixmap:=pixmap
 			pixmap=pixmap.Convert( PixelFormat.IA16 )
 			pixmap=pixmap.Convert( PixelFormat.IA16 )
-			tpixmap.Release()
 			
 			
 			'Copy I->A
 			'Copy I->A
 			For Local y:=0 Until pixmap.Height
 			For Local y:=0 Until pixmap.Height
@@ -416,9 +397,7 @@ Class Image Extends Resource
 
 
 		Case PixelFormat.RGB24
 		Case PixelFormat.RGB24
 		
 		
-			Local tpixmap:=pixmap
 			pixmap=pixmap.Convert( PixelFormat.RGBA32 )
 			pixmap=pixmap.Convert( PixelFormat.RGBA32 )
-			tpixmap.Release()
 			
 			
 			'Copy Max(R,G,B)->A
 			'Copy Max(R,G,B)->A
 			For Local y:=0 Until pixmap.Height
 			For Local y:=0 Until pixmap.Height
@@ -438,10 +417,21 @@ Class Image Extends Resource
 		Return image
 		Return image
 	End
 	End
 	
 	
+	Protected
+
+	#rem monkeydoc @hidden
+	#end	
+	Method OnDiscard() Override
+
+		SafeDiscard( _uniforms )
+		_uniforms=Null
+		_textures=Null
+	End
+	
 	Private
 	Private
 	
 	
 	Field _shader:Shader
 	Field _shader:Shader
-	Field _material:UniformBlock
+	Field _uniforms:UniformBlock
 	Field _textures:=New Texture[4]
 	Field _textures:=New Texture[4]
 	Field _blendMode:BlendMode
 	Field _blendMode:BlendMode
 	Field _color:Color
 	Field _color:Color
@@ -468,7 +458,7 @@ Class Image Extends Resource
 	
 	
 		_rect=rect
 		_rect=rect
 		_shader=shader
 		_shader=shader
-		_material=New UniformBlock( 2 )
+		_uniforms=New UniformBlock( 2 )
 		
 		
 		SetTexture( 0,texture )
 		SetTexture( 0,texture )
 		
 		
@@ -505,15 +495,6 @@ Class Image Extends Resource
 		_texCoords.max.y=Float(_rect.max.y)/_textures[0].Height
 		_texCoords.max.y=Float(_rect.max.y)/_textures[0].Height
 	End
 	End
 	
 	
-	Method MakeTextureFlags:TextureFlags( textureFlags:TextureFlags )
-		
-		textureFlags|=TextureFlags.Filter
-		
-		If Not (textureFlags & TextureFlags.Dynamic) textureFlags|=textureFlags.Mipmap
-		
-		Return textureFlags
-	End
-	
 End
 End
 
 
 Class ResourceManager Extension
 Class ResourceManager Extension

+ 1 - 14
modules/mojo/graphics/rendertarget.monkey2

@@ -9,12 +9,6 @@ Class RenderTarget Extends Resource
 		
 		
 		_depthTexture=depthTexture
 		_depthTexture=depthTexture
 		
 		
-		For Local texture:=Eachin _colorTextures
-			SafeRetain( texture )
-		Next
-		
-		SafeRetain( _depthTexture )
-		
 		_drawBufs=New GLenum[_colorTextures.Length]
 		_drawBufs=New GLenum[_colorTextures.Length]
 		
 		
 		For Local i:=0 Until _colorTextures.Length
 		For Local i:=0 Until _colorTextures.Length
@@ -96,12 +90,6 @@ Class RenderTarget Extends Resource
 		
 		
 		If _glSeq=glGraphicsSeq glDeleteFramebuffers( 1,Varptr _glFramebuffer )
 		If _glSeq=glGraphicsSeq glDeleteFramebuffers( 1,Varptr _glFramebuffer )
 			
 			
-		For Local texture:=Eachin _colorTextures
-			SafeRelease( texture )
-		Next
-		
-		SafeRelease( _depthTexture )
-		
 		_colorTextures=Null
 		_colorTextures=Null
 		_depthTexture=Null
 		_depthTexture=Null
 		_glSeq=0
 		_glSeq=0
@@ -109,10 +97,9 @@ Class RenderTarget Extends Resource
 	
 	
 	#rem monkeydoc @hidden
 	#rem monkeydoc @hidden
 	#end
 	#end
-	Method Finalize() Override
+	Method OnFinalize() Override
 
 
 		If _glSeq=glGraphicsSeq glDeleteFramebuffers( 1,Varptr _glFramebuffer )
 		If _glSeq=glGraphicsSeq glDeleteFramebuffers( 1,Varptr _glFramebuffer )
-			
 	End
 	End
 	
 	
 	Private
 	Private

+ 6 - 1
modules/mojo/graphics/shader.monkey2

@@ -115,6 +115,11 @@ Class GLProgram
 			_glRetroSeq=glRetroSeq
 			_glRetroSeq=glRetroSeq
 		Endif
 		Endif
 		#end
 		#end
+		
+'		For Local i:=0 Until 8
+'			glActiveTexture( GL_TEXTURE0+i )
+'			glBindTexture( GL_TEXTURE_2D,0 )
+'		Next
 
 
 		For Local i:=0 Until 4
 		For Local i:=0 Until 4
 
 
@@ -238,7 +243,7 @@ Class Shader
 			_glSeq=glGraphicsSeq
 			_glSeq=glGraphicsSeq
 			Rebuild()
 			Rebuild()
 		Endif
 		Endif
-	
+		
 		glUseProgram( _programs[renderPass].GLProgram )
 		glUseProgram( _programs[renderPass].GLProgram )
 	End
 	End
 	
 	

+ 3 - 18
modules/mojo/graphics/texture.monkey2

@@ -113,8 +113,6 @@ Class Texture Extends Resource
 		
 		
 		If _flags & TextureFlags.Dynamic
 		If _flags & TextureFlags.Dynamic
 			PastePixmap( _managed,0,0 )
 			PastePixmap( _managed,0,0 )
-		Else
-			AddDependancy( _managed )
 		Endif
 		Endif
 	End
 	End
 	
 	
@@ -147,7 +145,6 @@ Class Texture Extends Resource
 		If Not (_flags & TextureFlags.Dynamic)
 		If Not (_flags & TextureFlags.Dynamic)
 			_managed=New Pixmap( width,height,format )
 			_managed=New Pixmap( width,height,format )
 			_managed.Clear( Color.Magenta )
 			_managed.Clear( Color.Magenta )
-			Discarded+=_managed.Release
 		Endif
 		Endif
 	End
 	End
 	
 	
@@ -220,8 +217,6 @@ Class Texture Extends Resource
 		
 		
 		Local texture:=New Texture( pixmap,flags )
 		Local texture:=New Texture( pixmap,flags )
 		
 		
-		texture.Discarded+=pixmap.Release
-		
 		Return texture
 		Return texture
 	End
 	End
 	
 	
@@ -257,12 +252,8 @@ Class Texture Extends Resource
 			Next
 			Next
 		Endif
 		Endif
 			
 			
-		If pspec pspec.Release()
-			
 		Local texture:=New Texture( pnorm,Null )
 		Local texture:=New Texture( pnorm,Null )
 		
 		
-		texture.Discarded+=pnorm.Release
-		
 		Return texture
 		Return texture
 	End
 	End
 	
 	
@@ -424,8 +415,6 @@ Class Texture Extends Resource
 	#end	
 	#end	
 	Method OnDiscard() Override
 	Method OnDiscard() Override
 		
 		
-		If _discarded Return
-	
 		If _glSeq=glGraphicsSeq glDeleteTextures( 1,Varptr _glTexture )
 		If _glSeq=glGraphicsSeq glDeleteTextures( 1,Varptr _glTexture )
 			
 			
 		_discarded=True
 		_discarded=True
@@ -436,9 +425,9 @@ Class Texture Extends Resource
 	
 	
 	#rem monkeydoc @hidden
 	#rem monkeydoc @hidden
 	#end	
 	#end	
-	Method Finalize() Override
+	Method OnFinalize() Override
 		
 		
-		If Not _discarded And _glSeq=glGraphicsSeq glDeleteTextures( 1,Varptr _glTexture )
+		If _glSeq=glGraphicsSeq glDeleteTextures( 1,Varptr _glTexture )
 	End
 	End
 	
 	
 	Private
 	Private
@@ -504,15 +493,13 @@ Class Texture Extends Resource
 			If width=1 And height=1 Exit
 			If width=1 And height=1 Exit
 			
 			
 			Local hdata:=data.MipHalve()
 			Local hdata:=data.MipHalve()
-			data.Release()
 			data=hdata
 			data=hdata
 			width/=2
 			width/=2
 			height/=2
 			height/=2
 			mip+=1
 			mip+=1
 		
 		
 		Wend
 		Wend
-		
-		data.Release()
+
 	End
 	End
 	
 	
 	Method UploadTexImage2D( glTarget:GLenum,image:Pixmap )
 	Method UploadTexImage2D( glTarget:GLenum,image:Pixmap )
@@ -553,8 +540,6 @@ Class Texture Extends Resource
 			Next
 			Next
 			
 			
 			glFlush() 'macos nvidia bug!
 			glFlush() 'macos nvidia bug!
-			
-			image.Release()
 		
 		
 		Endif
 		Endif
 		
 		

+ 4 - 7
modules/mojo/graphics/uniformblock.monkey2

@@ -15,7 +15,6 @@ Class UniformBlock Extends Resource
 		_name=uniforms._name
 		_name=uniforms._name
 		For Local i:=0 Until _uniforms.Length
 		For Local i:=0 Until _uniforms.Length
 			_uniforms[i]=uniforms._uniforms[i]
 			_uniforms[i]=uniforms._uniforms[i]
-			SafeRetain( _uniforms[i].texture )
 		Next
 		Next
 	End
 	End
 	
 	
@@ -179,9 +178,6 @@ Class UniformBlock Extends Resource
 	Method SetTexture( uniform:String,value:Texture )
 	Method SetTexture( uniform:String,value:Texture )
 		Local id:=GetUniformId( uniform )
 		Local id:=GetUniformId( uniform )
 		
 		
-		SafeRetain( value )
-		SafeRelease( _uniforms[id].texture )
-		
 		_uniforms[id].texture=value
 		_uniforms[id].texture=value
 		_uniforms[id].type=Type.Texture
 		_uniforms[id].type=Type.Texture
 		_seq=_gseq
 		_seq=_gseq
@@ -207,10 +203,11 @@ Class UniformBlock Extends Resource
 	
 	
 	Protected
 	Protected
 	
 	
+	#rem monkeydoc @hidden
+	#end	
 	Method OnDiscard() Override
 	Method OnDiscard() Override
-		For Local i:=0 Until _uniforms.Length
-			SafeRelease( _uniforms[i].texture )
-		Next
+		
+		_uniforms=null
 	End
 	End
 	
 	
 	Private
 	Private

+ 1 - 1
modules/mojo/module.json

@@ -3,6 +3,6 @@
 	"about":"Monkey2 app framework",
 	"about":"Monkey2 app framework",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["freetype","emscripten","std","sdl2","gles20","openal"]
 	"depends":["freetype","emscripten","std","sdl2","gles20","openal"]
 }
 }

+ 1 - 1
modules/mojox/module.json

@@ -3,6 +3,6 @@
 	"about":"GUI extensions for mojo",
 	"about":"GUI extensions for mojo",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["std","mojo","hoedown","litehtml"]
 	"depends":["std","mojo","hoedown","litehtml"]
 }
 }

+ 1 - 1
modules/mojox/tests/assets/about.html

@@ -38,7 +38,7 @@ div.awesome{
 
 
 <p>Monkey2 is an open-source, user-friendly, cross-platform programming language designed primarily for game programming.
 <p>Monkey2 is an open-source, user-friendly, cross-platform programming language designed primarily for game programming.
 
 
-<p>All documentation is currently hosted online at <a href="http://monkey2.monkey-x.com">monkey2.monkey-x.com</a>.
+<p>All documentation is currently hosted online at <a href="http://monkeycoder.co.nz">monkeycoder.co.nz</a>.
 
 
 <p>Several sample monkey2 apps can be found in the 'bananas' directory of the monkey2 release.
 <p>Several sample monkey2 apps can be found in the 'bananas' directory of the monkey2 release.
 
 

+ 1 - 1
modules/mojox/tests/assets/mainwindow.monkey2

@@ -347,7 +347,7 @@ Class MainWindowInstance Extends Window
 	Method OnHelpOnlineHelp()
 	Method OnHelpOnlineHelp()
 	
 	
 		App.Idle+=Lambda()
 		App.Idle+=Lambda()
-			mojo.requesters.OpenUrl( "http://monkey2.monkey-x.com/modules-reference/" )
+			mojo.requesters.OpenUrl( "http://monkeycoder.co.nz/modules-reference/" )
 		End
 		End
 		
 		
 	End
 	End

+ 1 - 1
modules/monkey/docs/sdks.md

@@ -8,7 +8,7 @@ Monkey2 target SDKs.
 
 
 Monkey2 can use either the mingw or msvc express 2015 compilers to build desktop apps.
 Monkey2 can use either the mingw or msvc express 2015 compilers to build desktop apps.
 
 
-To use mingw, you can use the mingw build tools available at [[http://monkey2.monkey-x.com/monkey2-files]]. Simply download the mingw build tools package, run it (it's a self extracting exe), and select your monkey2 'devtools' dir for installation.
+To use mingw, you can use the mingw build tools available at [[http://monkeycoder.co.nz/monkey2-files]]. Simply download the mingw build tools package, run it (it's a self extracting exe), and select your monkey2 'devtools' dir for installation.
 
 
 Note that the prebuilt binaries available from itch.io already include mingw in the 'devtools' dir.
 Note that the prebuilt binaries available from itch.io already include mingw in the 'devtools' dir.
 
 

+ 4 - 0
modules/monkey/gc.monkey2

@@ -3,6 +3,10 @@ Namespace monkey.gc
 
 
 Extern
 Extern
 
 
+#rem monkeydoc @hidden
+#end
+Function GCSetDebug( debug:Bool )="bbGC::setDebug"
+
 #rem monkeydoc Sets garbage collection trigger value.
 #rem monkeydoc Sets garbage collection trigger value.
 
 
 The GC trigger is the number of bytes of memory that must be allocated before a garbage collection is automatically performed.
 The GC trigger is the number of bytes of memory that must be allocated before a garbage collection is automatically performed.

+ 1 - 1
modules/monkey/module.json

@@ -3,6 +3,6 @@
 	"about":"Core language functionality",
 	"about":"Core language functionality",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":[]
 	"depends":[]
 }
 }

+ 58 - 11
modules/monkey/native/bbgc.cpp

@@ -8,8 +8,23 @@
 // For testing only...
 // For testing only...
 // #define BBGC_DISABLED 1
 // #define BBGC_DISABLED 1
 
 
+namespace bbDB{
+
+	void stop();
+	
+	void stopped();
+	
+	void error( bbString err );
+}
+
 namespace bbGC{
 namespace bbGC{
 
 
+	int memused;
+	
+	int malloced;
+
+	bool debug;
+	
 	size_t trigger=4*1024*1024;
 	size_t trigger=4*1024*1024;
 
 
 	int suspended=1;
 	int suspended=1;
@@ -67,6 +82,11 @@ namespace bbGC{
 		suspended=0;
 		suspended=0;
 	}
 	}
 	
 	
+	void setDebug( bool debug ){
+	
+		bbGC::debug=debug;
+	}
+	
 	void setTrigger( size_t size ){
 	void setTrigger( size_t size ){
 	
 	
 		trigger=size;
 		trigger=size;
@@ -86,6 +106,7 @@ namespace bbGC{
 	
 	
 		if( p->flags & 1 ){
 		if( p->flags & 1 ){
 			//Run finalizer
 			//Run finalizer
+			//printf( "Running finalizer\n" );fflush( stdout );
 			++suspended;
 			++suspended;
 			p->state=unmarkedBit;
 			p->state=unmarkedBit;
 			p->gcFinalize();
 			p->gcFinalize();
@@ -98,6 +119,7 @@ namespace bbGC{
 		p->state=3;
 		p->state=3;
 		p->flags=0;
 		p->flags=0;
 #else
 #else
+		
 		p->~bbGCNode();
 		p->~bbGCNode();
 			
 			
 		bbGC::free( p );
 		bbGC::free( p );
@@ -106,31 +128,33 @@ namespace bbGC{
 	
 	
 	void reclaim( size_t size=0x7fffffff ){
 	void reclaim( size_t size=0x7fffffff ){
 	
 	
+		size_t freed=0;
+	
 		while( freeList.succ!=&freeList ){
 		while( freeList.succ!=&freeList ){
 		
 		
 			bbGCNode *p=freeList.succ;
 			bbGCNode *p=freeList.succ;
 			
 			
-			size_t psize=mallocSize( p );
+			freed+=mallocSize( p );
 			
 			
 			remove( p );
 			remove( p );
 			
 			
 			destroy( p );
 			destroy( p );
-
-			if( psize>=size ) break;
-			size-=psize;
+			
+			if( freed>=size ) break;
 		}
 		}
 	}
 	}
 	
 	
 	void mark( bbGCNode *p ){
 	void mark( bbGCNode *p ){
+
 		if( !p || p->state==markedBit ) return;
 		if( !p || p->state==markedBit ) return;
 		
 		
 		remove( p );
 		remove( p );
 		insert( p,markedList );
 		insert( p,markedList );
 		
 		
-		p->state=markedBit;
-		
 		markedBytes+=mallocSize( p );
 		markedBytes+=mallocSize( p );
 
 
+		p->state=markedBit;
+		
 		p->gcMark();
 		p->gcMark();
 	}
 	}
 	
 	
@@ -257,12 +281,23 @@ namespace bbGC{
 	
 	
 		size=(size+sizeof(size_t)+7)&~7;
 		size=(size+sizeof(size_t)+7)&~7;
 		
 		
+		if( debug && size==40 ){
+			debug=false;
+			bbDB::stop();
+			bbDB::stopped();
+		}
+		
+		memused+=size;
+		
 		if( size<256 && pools[size>>3] ){
 		if( size<256 && pools[size>>3] ){
 			void *p=pools[size>>3];
 			void *p=pools[size>>3];
 			pools[size>>3]=*(void**)p;
 			pools[size>>3]=*(void**)p;
 			allocedBytes+=size;
 			allocedBytes+=size;
 			size_t *q=(size_t*)p;
 			size_t *q=(size_t*)p;
 			*q++=size;
 			*q++=size;
+			
+//			if( debug ){ printf( "bbGC::malloc %p size=%i\n",q,size );fflush( stdout ); }
+		
 			return q;
 			return q;
 		}
 		}
 		
 		
@@ -290,21 +325,22 @@ namespace bbGC{
 				}
 				}
 				poolBufSize=65536;
 				poolBufSize=65536;
 				poolBuf=(unsigned char*)::malloc( poolBufSize );
 				poolBuf=(unsigned char*)::malloc( poolBufSize );
+				malloced+=poolBufSize;
 			}
 			}
 			p=poolBuf;
 			p=poolBuf;
 			poolBuf+=size;
 			poolBuf+=size;
 			poolBufSize-=size;
 			poolBufSize-=size;
 		}else{
 		}else{
 			p=::malloc( size );
 			p=::malloc( size );
+			malloced+=size;
 		}
 		}
 		
 		
-		p=::malloc( size );
-		
-//		printf( "alloc:%p %i\n",p,size );fflush( stdout );
-		
 		allocedBytes+=size;
 		allocedBytes+=size;
 		size_t *q=(size_t*)p;
 		size_t *q=(size_t*)p;
 		*q++=size;
 		*q++=size;
+
+//		if( debug ){ printf( "bbGC::malloc %p size=%i\n",q,size );fflush( stdout ); }
+		
 		return q;
 		return q;
 	}
 	}
 	
 	
@@ -323,12 +359,17 @@ namespace bbGC{
 		
 		
 		size_t size=*q;
 		size_t size=*q;
 		
 		
-//		printf( "free:%p %i\n",q,size );fflush( stdout );
+		if( debug ){
+//			printf( "bbGC::free %p size=%i\n",q,size );fflush( stdout );
+		}
+		
+		memused-=size;
 		
 		
 		if( size<256 ){
 		if( size<256 ){
 			*(void**)q=pools[size>>3];
 			*(void**)q=pools[size>>3];
 			pools[size>>3]=q;
 			pools[size>>3]=q;
 		}else{
 		}else{
+			malloced-=size;
 			::free( q );
 			::free( q );
 		}
 		}
 	}
 	}
@@ -348,10 +389,16 @@ namespace bbGC{
 	void collect(){
 	void collect(){
 	
 	
 		if( !inited ) return;
 		if( !inited ) return;
+		
+		static size_t maxused;
 	
 	
 		sweep();
 		sweep();
 		
 		
 		reclaim();
 		reclaim();
+		
+		if( memused>maxused ) maxused=memused;
+		
+//		printf( "Collect complete: memused=%i max memused=%i\n",memused,maxused );fflush( stdout );
 	}
 	}
 }
 }
 
 

+ 2 - 0
modules/monkey/native/bbgc.h

@@ -51,6 +51,8 @@ namespace bbGC{
 	void retain( bbGCNode *p );
 	void retain( bbGCNode *p );
 	
 	
 	void release( bbGCNode *p );
 	void release( bbGCNode *p );
+	
+	void setDebug( bool debug );
 
 
 	void setTrigger( size_t trigger );
 	void setTrigger( size_t trigger );
 
 

+ 3 - 3
modules/monkey/types.monkey2

@@ -704,9 +704,9 @@ Class @Object="bbObject"
 	#end
 	#end
 	Property InstanceType:TypeInfo()="typeof"
 	Property InstanceType:TypeInfo()="typeof"
 	
 	
-	#rem monkeydoc Finalize method.
-	#end
-	Method Finalize() Virtual="gcFinalize"
+	'#rem monkeydoc Finalize method.
+	'#end
+	'Method Finalize() Virtual="gcFinalize"
 
 
 	#rem monkeydoc @hidden
 	#rem monkeydoc @hidden
 	#end
 	#end

+ 1 - 1
modules/openal/module.json

@@ -3,6 +3,6 @@
 	"about":"OpenAL library wrapper",
 	"about":"OpenAL library wrapper",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc"]
 	"depends":["libc"]
 }
 }

+ 1 - 1
modules/reflection/module.json

@@ -3,6 +3,6 @@
 	"about":"Reflection support",
 	"about":"Reflection support",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":[]
 	"depends":[]
 }
 }

+ 1 - 1
modules/sdl2-mixer/module.json

@@ -3,6 +3,6 @@
 	"about":"SDL mixer library",
 	"about":"SDL mixer library",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["sdl2"]
 	"depends":["sdl2"]
 }
 }

+ 1 - 1
modules/sdl2/module.json

@@ -3,6 +3,6 @@
 	"about":"SDL2 library wrapper",
 	"about":"SDL2 library wrapper",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc","gles20"]
 	"depends":["libc","gles20"]
 }
 }

+ 1 - 1
modules/stb-image-write/module.json

@@ -3,6 +3,6 @@
 	"about":"Minimal image saver lib",
 	"about":"Minimal image saver lib",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc"]
 	"depends":["libc"]
 }
 }

+ 1 - 1
modules/stb-image/module.json

@@ -3,6 +3,6 @@
 	"about":"Minimal image loader",
 	"about":"Minimal image loader",
 	"author":"Sean T Barret/Mark Sibly",
 	"author":"Sean T Barret/Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc"]
 	"depends":["libc"]
 }
 }

+ 1 - 1
modules/stb-truetype/module.json

@@ -3,6 +3,6 @@
 	"about":"Minimal truetype lib",
 	"about":"Minimal truetype lib",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":[]
 	"depends":[]
 }
 }

+ 9 - 9
modules/stb-vorbis/module.json

@@ -1,10 +1,10 @@
-{
-	"module":"stb-vorbis",
-	"about":"Minimal vorbis loader",
-	"author":"Sean Barret",
-	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
-	"depends":[]
-}
-
+{
+	"module":"stb-vorbis",
+	"about":"Minimal vorbis loader",
+	"author":"Sean Barret",
+	"version":"1.0.0",
+	"support":"http://monkeycoder.co.nz",
+	"depends":[]
+}
+
 	
 	

+ 24 - 25
modules/std/audio/audiodata.monkey2

@@ -3,32 +3,23 @@ Namespace std.audio
 
 
 #rem monkeydoc The AudioData class.
 #rem monkeydoc The AudioData class.
 #end
 #end
-Class AudioData
-
-	#rem monkeydoc Invoked when audio data is discarded.
-	#end
-	Field OnDiscarded:Void()
+Class AudioData Extends Resource
 
 
 	#rem monkeydoc Creates a new AudioData object
 	#rem monkeydoc Creates a new AudioData object
 	#end
 	#end
 	Method New( length:Int,format:AudioFormat,hertz:Int )
 	Method New( length:Int,format:AudioFormat,hertz:Int )
-	
-		Local data:=libc.malloc( BytesPerSample( format )*length )
-		
 		_length=length
 		_length=length
 		_format=format
 		_format=format
 		_hertz=hertz
 		_hertz=hertz
-		_data=Cast<UByte Ptr>( data )
-		
-		OnDiscarded=Lambda()
-			libc.free( data )
-		End
+		_owned=True
+		_data=Cast<UByte Ptr>( GCMalloc( BytesPerSample( format )*length ) )
 	End
 	End
 
 
 	Method New( length:Int,format:AudioFormat,hertz:Int,data:Void Ptr )
 	Method New( length:Int,format:AudioFormat,hertz:Int,data:Void Ptr )
 		_length=length
 		_length=length
 		_format=format
 		_format=format
 		_hertz=hertz
 		_hertz=hertz
+		_owned=false
 		_data=Cast<UByte Ptr>( data )
 		_data=Cast<UByte Ptr>( data )
 	End
 	End
 	
 	
@@ -99,17 +90,6 @@ Class AudioData
 		RuntimeError( "TODO!" )
 		RuntimeError( "TODO!" )
 	End
 	End
 	
 	
-	#rem monkeydoc Discards the audio data object.
-	#end
-	Method Discard()
-		If _discarded Return
-		_discarded=True
-		OnDiscarded()
-		_length=0
-		_format=Null
-		_data=Null
-	End
-	
 	#rem monkey Loads audio data from a file.
 	#rem monkey Loads audio data from a file.
 	#end
 	#end
 	Function Load:AudioData( path:String )
 	Function Load:AudioData( path:String )
@@ -122,12 +102,31 @@ Class AudioData
 		Return Null
 		Return Null
 	End
 	End
 	
 	
+	Protected
+	
+	#rem monkeydoc @hidden
+	#end
+	Method OnDiscard() Override
+		
+		If _owned GCFree( _data )
+			
+		_data=Null
+	End
+	
+	#rem monkeydoc @hidden
+	#end
+	Method OnFinalize() Override
+		
+		If _owned GCFree( _data )
+	End
+	
 	Private
 	Private
 	
 	
 	Field _length:Int
 	Field _length:Int
 	Field _format:AudioFormat
 	Field _format:AudioFormat
 	Field _hertz:Int
 	Field _hertz:Int
+	Field _owned:Bool
+
 	Field _data:UByte Ptr
 	Field _data:UByte Ptr
-	Field _discarded:Bool
 	
 	
 End
 End

+ 29 - 4
modules/std/audio/load_vorbis.monkey2

@@ -1,6 +1,35 @@
 
 
 Namespace std.audio
 Namespace std.audio
 
 
+#rem monkeydoc @hidden
+#end
+Class StbAudioData Extends AudioData
+	
+	Method New( length:Int,format:AudioFormat,hertz:Int,data:Void Ptr )
+		Super.New( length,format,hertz,data )
+		
+		_data=data
+	End
+	
+	Private
+	
+	Field _data:Void Ptr
+	
+	Method OnDiscard() Override
+		
+		libc.free( _data )
+		
+		_data=Null
+	End
+	
+	Method OnFinalize() Override
+		
+		libc.free( _data )
+	End
+	
+End
+
+
 Function LoadAudioData_OGG:AudioData( path:String )
 Function LoadAudioData_OGG:AudioData( path:String )
 
 
 	Local buf:=std.memory.DataBuffer.Load( path )
 	Local buf:=std.memory.DataBuffer.Load( path )
@@ -27,10 +56,6 @@ Function LoadAudioData_OGG:AudioData( path:String )
 	
 	
 	Local data:=New AudioData( length,format,hertz,samples )
 	Local data:=New AudioData( length,format,hertz,samples )
 	
 	
-	data.OnDiscarded+=Lambda()
-		libc.free( samples )
-	End
-	
 	Return data
 	Return data
 
 
 End
 End

+ 49 - 14
modules/std/graphics/pixmap.monkey2

@@ -37,9 +37,9 @@ Class Pixmap Extends Resource
 		_height=height
 		_height=height
 		_format=format
 		_format=format
 		_depth=depth
 		_depth=depth
-		_gcdata=data
-		_data=data
 		_pitch=pitch
 		_pitch=pitch
+		_owned=True
+		_data=data
 	End
 	End
 	
 	
 	Method New( width:Int,height:Int,format:PixelFormat,data:UByte Ptr,pitch:Int )
 	Method New( width:Int,height:Int,format:PixelFormat,data:UByte Ptr,pitch:Int )
@@ -60,6 +60,7 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Property Width:Int()
 	Property Width:Int()
+		
 		Return _width
 		Return _width
 	End
 	End
 	
 	
@@ -67,6 +68,7 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Property Height:Int()
 	Property Height:Int()
+		
 		Return _height
 		Return _height
 	End
 	End
 	
 	
@@ -74,6 +76,7 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Property Format:PixelFormat()
 	Property Format:PixelFormat()
+		
 		Return _format
 		Return _format
 	End
 	End
 	
 	
@@ -83,12 +86,14 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Property Depth:Int()
 	Property Depth:Int()
+		
 		Return _depth
 		Return _depth
 	End
 	End
 	
 	
 	#rem monkeydoc True if pixmap format includes alpha.
 	#rem monkeydoc True if pixmap format includes alpha.
 	#end
 	#end
 	Property HasAlpha:Bool()
 	Property HasAlpha:Bool()
+		
 		Select _format
 		Select _format
 		Case PixelFormat.A8,PixelFormat.IA16,PixelFormat.RGBA32
 		Case PixelFormat.A8,PixelFormat.IA16,PixelFormat.RGBA32
 			Return True
 			Return True
@@ -100,6 +105,7 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Property Data:UByte Ptr()
 	Property Data:UByte Ptr()
+		
 		Return _data
 		Return _data
 	End
 	End
 	
 	
@@ -109,6 +115,7 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Property Pitch:Int()
 	Property Pitch:Int()
+		
 		Return _pitch
 		Return _pitch
 	End
 	End
 	
 	
@@ -122,6 +129,7 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Method PixelPtr:UByte Ptr( x:Int,y:Int )
 	Method PixelPtr:UByte Ptr( x:Int,y:Int )
+		
 		Return _data + y*_pitch + x*_depth
 		Return _data + y*_pitch + x*_depth
 	End
 	End
 	
 	
@@ -282,6 +290,7 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Method Clear( color:Color )
 	Method Clear( color:Color )
+		
 		For Local y:=0 Until _height
 		For Local y:=0 Until _height
 			For Local x:=0 Until _width
 			For Local x:=0 Until _width
 				SetPixel( x,y,color )
 				SetPixel( x,y,color )
@@ -295,11 +304,14 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Method ClearARGB( color:UInt )
 	Method ClearARGB( color:UInt )
+		
 		For Local y:=0 Until _height
 		For Local y:=0 Until _height
+			
 			For Local x:=0 Until _width
 			For Local x:=0 Until _width
+				
 				SetPixelARGB( x,y,color )
 				SetPixelARGB( x,y,color )
 			Next
 			Next
-		next
+		Next
 	End
 	End
 
 
 	#rem monkeydoc Creates a copy of the pixmap.
 	#rem monkeydoc Creates a copy of the pixmap.
@@ -310,8 +322,11 @@ Class Pixmap Extends Resource
 	Method Copy:Pixmap()
 	Method Copy:Pixmap()
 	
 	
 		Local pitch:=Width * Depth
 		Local pitch:=Width * Depth
+		
 		Local data:=Cast<UByte Ptr>( libc.malloc( pitch * Height ) )
 		Local data:=Cast<UByte Ptr>( libc.malloc( pitch * Height ) )
+		
 		For Local y:=0 Until Height
 		For Local y:=0 Until Height
+			
 			memcpy( data+y*pitch,PixelPtr( 0,y ),pitch )
 			memcpy( data+y*pitch,PixelPtr( 0,y ),pitch )
 		Next
 		Next
 		
 		
@@ -335,7 +350,9 @@ Class Pixmap Extends Resource
 		DebugAssert( x>=0 And x+pixmap._width<=_width And y>=0 And y+pixmap._height<=_height )
 		DebugAssert( x>=0 And x+pixmap._width<=_width And y>=0 And y+pixmap._height<=_height )
 		
 		
 		For Local ty:=0 Until pixmap._height
 		For Local ty:=0 Until pixmap._height
+			
 			For Local tx:=0 Until pixmap._width
 			For Local tx:=0 Until pixmap._width
+				
 				SetPixel( x+tx,y+ty,pixmap.GetPixel( tx,ty ) )
 				SetPixel( x+tx,y+ty,pixmap.GetPixel( tx,ty ) )
 			Next
 			Next
 		Next
 		Next
@@ -351,9 +368,13 @@ Class Pixmap Extends Resource
 	
 	
 	#end
 	#end
 	Method Convert:Pixmap( format:PixelFormat )
 	Method Convert:Pixmap( format:PixelFormat )
+		
 		Local t:=New Pixmap( _width,_height,format )
 		Local t:=New Pixmap( _width,_height,format )
+		
 		For Local y:=0 Until _height
 		For Local y:=0 Until _height
+			
 			For Local x:=0 Until _width
 			For Local x:=0 Until _width
+				
 				t.SetPixel( x,y,GetPixel( x,y ) )
 				t.SetPixel( x,y,GetPixel( x,y ) )
 			Next
 			Next
 		Next
 		Next
@@ -365,10 +386,14 @@ Class Pixmap Extends Resource
 	#rem monkeydoc Premultiply pixmap r,g,b components by alpha.
 	#rem monkeydoc Premultiply pixmap r,g,b components by alpha.
 	#end
 	#end
 	Method PremultiplyAlpha()
 	Method PremultiplyAlpha()
+		
 		Select _format
 		Select _format
 		Case PixelFormat.IA16,PixelFormat.RGBA32
 		Case PixelFormat.IA16,PixelFormat.RGBA32
+			
 			For Local y:=0 Until _height
 			For Local y:=0 Until _height
+				
 				For Local x:=0 Until _width
 				For Local x:=0 Until _width
+					
 					Local color:=GetPixel( x,y )
 					Local color:=GetPixel( x,y )
 					color.r*=color.a
 					color.r*=color.a
 					color.g*=color.a
 					color.g*=color.a
@@ -394,6 +419,7 @@ Class Pixmap Extends Resource
 
 
 		Select _format
 		Select _format
 		Case PixelFormat.RGBA8
 		Case PixelFormat.RGBA8
+			
 			For Local y:=0 Until dst.Height
 			For Local y:=0 Until dst.Height
 				
 				
 				Local dstp:=Cast<UInt Ptr>( dst.PixelPtr( 0,y ) )
 				Local dstp:=Cast<UInt Ptr>( dst.PixelPtr( 0,y ) )
@@ -417,7 +443,9 @@ Class Pixmap Extends Resource
 			Next
 			Next
 		Default
 		Default
 			For Local y:=0 Until dst.Height
 			For Local y:=0 Until dst.Height
+				
 				For Local x:=0 Until dst.Width
 				For Local x:=0 Until dst.Width
+					
 					Local c0:=GetPixel( x*2,y*2 )
 					Local c0:=GetPixel( x*2,y*2 )
 					Local c1:=GetPixel( x*2+1,y*2 )
 					Local c1:=GetPixel( x*2+1,y*2 )
 					Local c2:=GetPixel( x*2+1,y*2+1 )
 					Local c2:=GetPixel( x*2+1,y*2+1 )
@@ -434,11 +462,16 @@ Class Pixmap Extends Resource
 	#rem monkeydoc Flips the pixmap on the Y axis.
 	#rem monkeydoc Flips the pixmap on the Y axis.
 	#end
 	#end
 	Method FlipY()
 	Method FlipY()
+		
 		Local sz:=Width*Depth
 		Local sz:=Width*Depth
+		
 		Local tmp:=New UByte[sz]
 		Local tmp:=New UByte[sz]
+		
 		For Local y:=0 Until Height/2
 		For Local y:=0 Until Height/2
+			
 			Local p1:=PixelPtr( 0,y )
 			Local p1:=PixelPtr( 0,y )
 			Local p2:=PixelPtr( 0,Height-1-y )
 			Local p2:=PixelPtr( 0,Height-1-y )
+			
 			libc.memcpy( tmp.Data,p1,sz )
 			libc.memcpy( tmp.Data,p1,sz )
 			libc.memcpy( p1,p2,sz )
 			libc.memcpy( p1,p2,sz )
 			libc.memcpy( p2,tmp.Data,sz )
 			libc.memcpy( p2,tmp.Data,sz )
@@ -488,6 +521,7 @@ Class Pixmap Extends Resource
 	Function Load:Pixmap( path:String,format:PixelFormat=Null,pmAlpha:Bool=False )
 	Function Load:Pixmap( path:String,format:PixelFormat=Null,pmAlpha:Bool=False )
 
 
 		Local pixmap:=pixmaploader.LoadPixmap( path,format )
 		Local pixmap:=pixmaploader.LoadPixmap( path,format )
+		
 		If Not pixmap And Not ExtractRootDir( path ) pixmap=pixmaploader.LoadPixmap( "image::"+path,format )
 		If Not pixmap And Not ExtractRootDir( path ) pixmap=pixmaploader.LoadPixmap( "image::"+path,format )
 		
 		
 		If pixmap And pmAlpha pixmap.PremultiplyAlpha()
 		If pixmap And pmAlpha pixmap.PremultiplyAlpha()
@@ -497,18 +531,20 @@ Class Pixmap Extends Resource
 	
 	
 	Protected
 	Protected
 	
 	
+	#rem monkeydoc @hidden
+	#end
 	Method OnDiscard() Override
 	Method OnDiscard() Override
-
-		If _gcdata		
-			GCFree( _gcdata )
-			_gcdata=Null
-			_data=null
-		Endif
+		
+		If _owned GCFree( _data )
+			
+		_data=Null
 	End
 	End
 	
 	
-	Method Finalize() Override
+	#rem monkeydoc @hidden
+	#end
+	Method OnFinalize() Override
 		
 		
-		If _gcdata GCFree( _gcdata )
+		If _owned GCFree( _data )
 	End
 	End
 
 
 	Private
 	Private
@@ -517,10 +553,9 @@ Class Pixmap Extends Resource
 	Field _height:Int
 	Field _height:Int
 	Field _format:PixelFormat
 	Field _format:PixelFormat
 	Field _depth:Int
 	Field _depth:Int
-	Field _gcdata:UByte Ptr
-	Field _data:UByte Ptr
 	Field _pitch:Int
 	Field _pitch:Int
-
+	Field _owned:Bool
+	Field _data:UByte Ptr
 End
 End
 
 
 Class ResourceManager Extension
 Class ResourceManager Extension

+ 12 - 8
modules/std/graphics/pixmaploader.monkey2

@@ -25,7 +25,8 @@ Function stbi_eof:Int( user:Void Ptr )
 	Return stream.Eof
 	Return stream.Eof
 End
 End
 
 
-'this is a bit nasty but meh...
+#rem monkeydoc @hidden
+#end
 Class StbPixmap Extends Pixmap
 Class StbPixmap Extends Pixmap
 	
 	
 	Method New( width:Int,height:Int,format:PixelFormat,data:UByte Ptr,pitch:Int )
 	Method New( width:Int,height:Int,format:PixelFormat,data:UByte Ptr,pitch:Int )
@@ -34,20 +35,23 @@ Class StbPixmap Extends Pixmap
 		_data=data
 		_data=data
 	End
 	End
 	
 	
-	Protected
+	Private
+	
+	Field _data:UByte Ptr
 	
 	
 	Method OnDiscard() Override
 	Method OnDiscard() Override
+		
+		Super.OnDiscard()
+		
 		stbi_image_free( _data )
 		stbi_image_free( _data )
+		
 		_data=Null
 		_data=Null
 	End
 	End
 	
 	
-	Method Finalize() Override
-		stbi_image_free( _data )
+	Method OnFinalize() Override
+		
+	 	stbi_image_free( _data )
 	End
 	End
-	
-	Private
-	
-	Field _data:UByte Ptr
 End
 End
 
 
 Public
 Public

+ 10 - 7
modules/std/memory/databuffer.monkey2

@@ -520,18 +520,21 @@ Class DataBuffer Extends std.resource.Resource
 	End
 	End
 	
 	
 	Protected
 	Protected
-	
+
+	#rem monkeydoc @hidden
+	#end	
 	Method OnDiscard() Override
 	Method OnDiscard() Override
 		
 		
-		If _data
-			GCFree( _data )
-			_data=Null
-		Endif
+		GCFree( _data )
+		
+		_data=Null
 	End
 	End
 
 
-	Method Finalize() Override
+	#rem monkeydoc @hidden
+	#end	
+	Method OnFinalize() Override
 		
 		
-		If _data GCFree( _data )
+		GCFree( _data )
 	End
 	End
 	
 	
 	Private
 	Private

+ 1 - 1
modules/std/module.json

@@ -3,6 +3,6 @@
 	"about":"Standard monkey2 library",
 	"about":"Standard monkey2 library",
 	"author":"Mark Sibly",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"depends":["libc","jni","sdl2","miniz","stb-image","stb-image-write","stb-vorbis"]
 	"depends":["libc","jni","sdl2","miniz","stb-image","stb-image-write","stb-vorbis"]
 }
 }

+ 60 - 79
modules/std/resource/resource.monkey2

@@ -1,86 +1,93 @@
 
 
 Namespace std.resource
 Namespace std.resource
 
 
-#Rem monkeydoc The Resource class.
+#Import "native/bbresource.cpp"
 
 
-Currently WIP!
+#Import "native/bbresource.h"
 
 
-#end
-Class Resource
+Extern Private
+
+Class BBResource="bbResource"
 	
 	
-	#rem monkeydoc Invoked when a resource is dscarded.
-	#end
-	Field Discarded:Void()
+	Protected
 	
 	
-	#rem monkeyoc @hidden
-	#end
-	Property Refs:Int()
+	Method InternalDiscard()="discard"
 		
 		
-		Return _refs
-	End
+	Method OnDiscard() Virtual="onDiscard"
 	
 	
-	#rem monkeyoc @hidden
-	#end
-	Method Retain()
-		
-		If Not _refs Return
-		
-		_refs+=1
-	End
+	Method OnFinalize() Virtual="onFinalize"
 	
 	
-	#rem monkeyoc @hidden
-	#end
-	Method Release()
+End
+
+Public
+
+#Rem monkeydoc The Resource class.
+
+The resource class helps with managing finite OS resources in a garbage collected environment.
+
+To implement a resource object, you should extend the Resource class and override the OnDiscard and/or OnFinalize methods.
+
+Code to actually discard the resource should be placed in [[OnDiscard]]. Discarding a resource might involve closing a file, deleting 
+a texture handle or other similar actions. 'Last chance' cleanup code should be placed in [[OnFinalize]].
+
+IMPORTANT! There are a number of restrictions on code that may be placed in OnFinalize, please refer to the documentation for [[OnFinalize]]
+for more information.
+	
+#end
+Class Resource Extends BBResource
+	
+	#rem monkeyoc Discards the resource.
 		
 		
-		If Not _refs Return
+	If the resource has not yet been discarded, calling this method will cause any internally managed OS resources to be cleaned up.
+	
+	If the resource has already been discarded, this method does nothing.
 		
 		
-		If _refs=1 Discard() Else _refs-=1
-	End
+	Once discarded, a resource should be consider invalid.
 	
 	
-	#rem monkeyoc @hidden
 	#end
 	#end
-	Method AddDependancy( r:Resource )
-		
-		If Not r Return
+	Method Discard()
 		
 		
-		r.Retain()
-
-		Discarded+=r.Release
+		InternalDiscard()
 	End
 	End
 	
 	
-	#rem monkeyoc Discards the resource.
+	Protected
 	
 	
-	Calling this will cause the resource's internal [[OnDiscard]] method to be invoked, followed by the [[Discarded]] signal.
+	#rem monkeyoc The OnDiscard method.
+	
+	This is where subclasses should place their actual discard code.
 	
 	
-	A resource can only be discarded once. Once discarded a resource should be consider invalid.
+	This method will be invoked the first time Resource.Discard() is invoked.
+	
+	This method will only ever be invoked at most once during the lifetime of a resource.
 	
 	
 	#end
 	#end
-	Method Discard()
-		
-		If Not _refs Return
-		
-		_refs=0
-		
-		OnDiscard()
-		
-		Discarded()
+	Method OnDiscard() Override
 	End
 	End
 	
 	
-	Protected
+	#rem monkeydoc The OnFinalize method.
 	
 	
-	#rem monkeyoc @hidden
+	This method will be invoked when a resource object's memory is about to be reclaimed and if the resource's Discard() method has
+	never been called during the lifetime of the object.
 	
 	
-	This method is invoked when the resource is discarded.
+	This method is intended to be used for the 'last chance' cleanup of criticial OS resources, such as file handles, texture objects etc.
 	
 	
-	This is where subclasses should place their actual discard code.
+	***** WARNING *****
+	
+	Code inside this method executes at a critical point in the garbage collection process, and should be kept short and sweet.
+	
+	Code inside OnFinalize MUST obey the following rules:
+	
+	* Code MUST NOT read or write any fields of Self containing objects, arrays, or function pointers as there is no guarantee that such fields
+	 are still valid when the finalizer executes.
+	
+	* Code MUST NOT assign Self to any variable.
+	
+	Failure to follow these rules *will* lead to eventual disaster!
 	
 	
 	#end
 	#end
-	Method OnDiscard() Virtual
+	Method OnFinalize() Override
 	End
 	End
 	
 	
-	Private
-	
-	Field _refs:=1
 End
 End
 
 
 #rem monkeydoc @hidden
 #rem monkeydoc @hidden
@@ -121,13 +128,6 @@ Class ResourceManager Extends Resource
 	
 	
 		_managers.Remove( Self )
 		_managers.Remove( Self )
 		
 		
-		For Local it:=Eachin _retained
-			
-			it.Value.Release()
-				
-			it.Value=Null
-		Next
-		
 		_retained=Null
 		_retained=Null
 	End
 	End
 	
 	
@@ -135,29 +135,10 @@ Class ResourceManager Extends Resource
 	
 	
 	Global _managers:=New Stack<ResourceManager>
 	Global _managers:=New Stack<ResourceManager>
 	
 	
-	Global _refs:=New StringMap<Int>
-	
 	Field _retained:=New StringMap<Resource>
 	Field _retained:=New StringMap<Resource>
-
 End
 End
 
 
-#rem monkeydoc Releases a resource unless it's null.
-#end
 Function SafeDiscard( r:Resource )
 Function SafeDiscard( r:Resource )
 	
 	
 	If r r.Discard()
 	If r r.Discard()
 End
 End
-
-#rem monkeydoc @hidden
-#end
-Function SafeRetain( r:Resource )
-	
-	If r r.Retain()
-End
-
-#rem monkeydoc @hidden
-#end
-Function SafeRelease( r:Resource )
-	
-	If r r.Release()
-End

+ 23 - 7
modules/std/socket/socket.monkey2

@@ -8,7 +8,7 @@ Namespace std.socket
 #Import "native/socket.cpp"
 #Import "native/socket.cpp"
 #Import "native/socket.h"
 #Import "native/socket.h"
 
 
-Extern
+Extern private
 
 
 #rem monkeydoc @hidden
 #rem monkeydoc @hidden
 #end
 #end
@@ -209,7 +209,7 @@ Sockets support asynchronous programming through the use of fibers. To connect,
 Sockets are ipv4/ipv6 compatible.
 Sockets are ipv4/ipv6 compatible.
 
 
 #end
 #end
-Class Socket
+Class Socket Extends std.resource.Resource
 
 
 	#rem Not on Windows...
 	#rem Not on Windows...
 	
 	
@@ -288,11 +288,8 @@ Class Socket
 	
 	
 	#end	
 	#end	
 	Method Close()
 	Method Close()
-		If _socket=-1 Return
-		socket_close( _socket )
-		_socket=-1
-		_addr=Null
-		_peer=null
+		
+		Discard()
 	End
 	End
 	
 	
 	#rem monkeydoc Sends data on a connected socket.
 	#rem monkeydoc Sends data on a connected socket.
@@ -429,6 +426,25 @@ Class Socket
 		Return New Socket( socket )
 		Return New Socket( socket )
 	End
 	End
 	
 	
+	Protected
+
+	#rem monkeydoc @hidden
+	#end	
+	Method OnDiscard() Override
+		
+		socket_close( _socket )
+		_socket=-1
+		_addr=Null
+		_peer=null
+	End
+	
+	#rem  monkeydoc @hidden
+	#end
+	Method OnFinalize() Override
+		
+		socket_close( _socket )
+	End
+	
 	Private
 	Private
 	
 	
 	Field _socket:Int=-1
 	Field _socket:Int=-1

+ 10 - 15
modules/std/stream/filestream.monkey2

@@ -36,19 +36,6 @@ Class FileStream Extends Stream
 		Return _end
 		Return _end
 	End
 	End
 	
 	
-	#rem monkeydoc Closes the filestream.
-	
-	Closing the filestream also sets its position and length to 0.
-	
-	#end
-	Method OnClose() Override
-		If Not _file Return	
-		fclose( _file )
-		_file=Null
-		_pos=0
-		_end=0
-	End
-	
 	#rem monkeydoc Seeks to a position in the filestream.
 	#rem monkeydoc Seeks to a position in the filestream.
 	
 	
 	@param offset The position to seek to.
 	@param offset The position to seek to.
@@ -129,9 +116,17 @@ Class FileStream Extends Stream
 	
 	
 	Protected
 	Protected
 	
 	
-	Method Finalize() Override
+	Method OnDiscard() Override
+		
+		fclose( _file )
+		_file=Null
+		_pos=0
+		_end=0
+	end
+	
+	Method OnFinalize() Override
 		
 		
-		If _file fclose( _file )
+		fclose( _file )
 	End
 	End
 	
 	
 	Private
 	Private

+ 24 - 5
modules/std/stream/stream.monkey2

@@ -7,7 +7,7 @@ Using std.collections
 
 
 #rem monkeydoc Stream class.
 #rem monkeydoc Stream class.
 #end
 #end
-Class Stream
+Class Stream Extends std.resource.Resource
 
 
 	#rem monkeydoc True if no more data can be read from the stream.
 	#rem monkeydoc True if no more data can be read from the stream.
 	#end
 	#end
@@ -30,8 +30,8 @@ Class Stream
 	#rem monkeydoc Closes the stream.
 	#rem monkeydoc Closes the stream.
 	#end
 	#end
 	Method Close:Void()
 	Method Close:Void()
+		
 		OnClose()
 		OnClose()
-		_tmpbuf.Discard()
 	End
 	End
 
 
 	#rem monkeydoc Seeks to a position in the stream.
 	#rem monkeydoc Seeks to a position in the stream.
@@ -95,9 +95,12 @@ Class Stream
 	
 	
 	#end
 	#end
 	Property ByteOrder:ByteOrder()
 	Property ByteOrder:ByteOrder()
+		
 		Return _tmpbuf.ByteOrder
 		Return _tmpbuf.ByteOrder
+		
 	Setter( byteOrder:ByteOrder )
 	Setter( byteOrder:ByteOrder )
-		_tmpbuf.ByteOrder=byteOrder
+		
+		_tmpbuf=byteOrder=ByteOrder.BigEndian ? _BEbuf Else _LEbuf
 	End
 	End
 	
 	
 	#rem monkeydoc Reads as many bytes as possible from a stream into memory.
 	#rem monkeydoc Reads as many bytes as possible from a stream into memory.
@@ -195,6 +198,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadByte:Byte()
 	Method ReadByte:Byte()
+		
 		If Read( _tmpbuf.Data,1 )=1 Return _tmpbuf.PeekByte( 0 )
 		If Read( _tmpbuf.Data,1 )=1 Return _tmpbuf.PeekByte( 0 )
 		
 		
 		Return 0
 		Return 0
@@ -206,6 +210,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadUByte:UByte()
 	Method ReadUByte:UByte()
+		
 		If Read( _tmpbuf.Data,1 )=1 Return _tmpbuf.PeekUByte( 0 )
 		If Read( _tmpbuf.Data,1 )=1 Return _tmpbuf.PeekUByte( 0 )
 		
 		
 		Return 0
 		Return 0
@@ -217,6 +222,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadShort:Short()
 	Method ReadShort:Short()
+		
 		If ReadAll( _tmpbuf.Data,2 )=2 Return _tmpbuf.PeekShort( 0 )
 		If ReadAll( _tmpbuf.Data,2 )=2 Return _tmpbuf.PeekShort( 0 )
 		
 		
 		Return 0
 		Return 0
@@ -228,6 +234,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadUShort:UShort()
 	Method ReadUShort:UShort()
+		
 		If ReadAll( _tmpbuf.Data,2 )=2 Return _tmpbuf.PeekUShort( 0 )
 		If ReadAll( _tmpbuf.Data,2 )=2 Return _tmpbuf.PeekUShort( 0 )
 		
 		
 		Return 0
 		Return 0
@@ -239,6 +246,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadInt:Int()
 	Method ReadInt:Int()
+		
 		If ReadAll( _tmpbuf.Data,4 )=4 Return _tmpbuf.PeekInt( 0 )
 		If ReadAll( _tmpbuf.Data,4 )=4 Return _tmpbuf.PeekInt( 0 )
 		
 		
 		Return 0
 		Return 0
@@ -250,6 +258,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadUInt:UInt()
 	Method ReadUInt:UInt()
+		
 		If ReadAll( _tmpbuf.Data,4 )=4 Return _tmpbuf.PeekUInt( 0 )
 		If ReadAll( _tmpbuf.Data,4 )=4 Return _tmpbuf.PeekUInt( 0 )
 		
 		
 		Return 0
 		Return 0
@@ -261,6 +270,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadLong:Long()
 	Method ReadLong:Long()
+		
 		If ReadAll( _tmpbuf.Data,8 )=8 Return _tmpbuf.PeekLong( 0 )
 		If ReadAll( _tmpbuf.Data,8 )=8 Return _tmpbuf.PeekLong( 0 )
 
 
 		Return 0
 		Return 0
@@ -272,6 +282,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadULong:ULong()
 	Method ReadULong:ULong()
+		
 		If ReadAll( _tmpbuf.Data,8 )=8 Return _tmpbuf.PeekULong( 0 )
 		If ReadAll( _tmpbuf.Data,8 )=8 Return _tmpbuf.PeekULong( 0 )
 
 
 		Return 0
 		Return 0
@@ -283,6 +294,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadFloat:Float()
 	Method ReadFloat:Float()
+		
 		If ReadAll( _tmpbuf.Data,4 )=4 Return _tmpbuf.PeekFloat( 0 )
 		If ReadAll( _tmpbuf.Data,4 )=4 Return _tmpbuf.PeekFloat( 0 )
 
 
 		Return 0
 		Return 0
@@ -294,6 +306,7 @@ Class Stream
 	
 	
 	#end
 	#end
 	Method ReadDouble:Double()
 	Method ReadDouble:Double()
+		
 		If ReadAll( _tmpbuf.Data,8 )=8 Return _tmpbuf.PeekDouble( 0 )
 		If ReadAll( _tmpbuf.Data,8 )=8 Return _tmpbuf.PeekDouble( 0 )
 
 
 		Return 0
 		Return 0
@@ -530,13 +543,19 @@ Class Stream
 	Protected
 	Protected
 	
 	
 	Method New()
 	Method New()
-		_tmpbuf=New DataBuffer( 8,ByteOrder.LittleEndian )
+		_tmpbuf=_LEbuf
 	End
 	End
 	
 	
-	Method OnClose() Abstract
+	Method OnClose() Virtual
+		
+		Discard()
+	End
 	
 	
 	Private
 	Private
 	
 	
 	Field _tmpbuf:DataBuffer
 	Field _tmpbuf:DataBuffer
+	
+	Global _BEbuf:=New DataBuffer( 8,std.memory.ByteOrder.LittleEndian )
+	Global _LEbuf:=New DataBuffer( 8,std.memory.ByteOrder.BigEndian )
 
 
 End
 End

+ 8 - 8
modules/theoraplayer/module.json

@@ -1,8 +1,8 @@
-{
-	"module":"theoraplayer",
-	"about":"Minimal theora player",
-	"author":"Kresimir Spes",
-	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
-	"depends":["openal","libc"]
-}
+{
+	"module":"theoraplayer",
+	"about":"Minimal theora player",
+	"author":"Kresimir Spes",
+	"version":"1.0.0",
+	"support":"http://monkeycoder.co.nz",
+	"depends":["openal","libc"]
+}

+ 3 - 3
src/ted2/helpactions.monkey2

@@ -13,7 +13,7 @@ Class HelpActions
 		onlineHelp=New Action( "Online help" )
 		onlineHelp=New Action( "Online help" )
 		onlineHelp.Triggered=lambda()
 		onlineHelp.Triggered=lambda()
 		
 		
-			OpenUrl( "http://monkey2.monkey-x.com/modules-reference/" )
+			OpenUrl( "http://monkeycoder.co.nz/modules-reference/" )
 		End
 		End
 		
 		
 		viewManuals=New Action( "Browse manuals" )
 		viewManuals=New Action( "Browse manuals" )
@@ -25,9 +25,9 @@ Class HelpActions
 		uploadModules=New Action( "Upload module" )
 		uploadModules=New Action( "Upload module" )
 		uploadModules.Triggered=Lambda()
 		uploadModules.Triggered=Lambda()
 		
 		
-			Alert( "Now taking you to the module manager page at monkey2.monkey-x.com~n~nNote: You must have an account at monkey2.monkey-x.com and be logged in to upload modules" )
+			Alert( "Now taking you to the module manager page at monkeycoder.co.nz~n~nNote: You must have an account at monkeycoder.co.nz and be logged in to upload modules" )
 		
 		
-			OpenUrl( RealPath( "http://monkey2.monkey-x.com/module-manager/" ) )
+			OpenUrl( RealPath( "http://monkeycoder.co.nz/module-manager/" ) )
 		End
 		End
 
 
 		about=New Action( "About monkey2" )
 		about=New Action( "About monkey2" )

+ 1 - 4
src/ted2/modulemanager.monkey2

@@ -99,8 +99,6 @@ Class ModuleManager Extends Dialog
 	
 	
 	Private
 	Private
 	
 	
-'	Const downloadUrl:="http://monkey2.monkey-x.com/wp-content/uploads/mx2-modules/public/"
-'	Const downloadUrl:="http://monkey2.monkey-x.com/send-file?file="
 	Const downloadUrl:="http://"+MONKEY2_DOMAIN+"/send-file?file="
 	Const downloadUrl:="http://"+MONKEY2_DOMAIN+"/send-file?file="
 	
 	
 	Const downloadDir:="modules/module-manager/downloads/"
 	Const downloadDir:="modules/module-manager/downloads/"
@@ -414,8 +412,7 @@ Class ModuleManager Extends Dialog
 	
 	
 	Method EnumRemoteModules:Bool()
 	Method EnumRemoteModules:Bool()
 	
 	
-'		Local src:="http://localhost/monkey2/module-manager/?modules=1"
-		Local src:="http://monkey2.monkey-x.com/module-manager/?modules=1"
+		Local src:="http://monkeycoder.co.nz/module-manager/?modules=1"
 		
 		
 		Local tmp:="tmp/modules.json"
 		Local tmp:="tmp/modules.json"