Sfoglia il codice sorgente

Merge pull request #55 from blitz-research/develop

Develop up
abakobo 8 anni fa
parent
commit
292e4a169e
52 ha cambiato i file con 508 aggiunte e 397 eliminazioni
  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:
 
-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'.
 
@@ -44,10 +44,8 @@ When installing, you should select 'i686' for 'architecture', 'posix' for 'threa
 
 ***** 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
 	'-----------------------------------------------------------------------------------------------------------
 	Method OnRender( canvas:Canvas ) Override
-		GCCollect()
 		PmapDest.Clear(Color.Black)
 		App.RequestRender()
 		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.Texture.Flags|=TextureFlags.Filter
+		
 		image.Handle=New Vec2f( .5,.5 )
 		
 		icanvas=New Canvas( image )

+ 22 - 12
bananas/spacechimps/spacechimps.monkey2

@@ -38,18 +38,10 @@ Class MyWindow Extends Window
 		'		
 		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
 		'
 		pos=New Vec2f( VirtualWidth/2,VirtualHeight/2 )
@@ -63,6 +55,21 @@ Class MyWindow Extends Window
 		SwapInterval=1
 	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
 		Select event.Type
 		Case EventType.KeyDown
@@ -109,6 +116,10 @@ Class MyWindow Extends Window
 	
 		RequestRender()
 		
+		'give GC a bit of a thrash....
+		'
+		'LoadResources()
+		
 		'rotate
 		'
 		If Keyboard.KeyDown( Key.Left )
@@ -194,7 +205,6 @@ Class MyWindow Extends Window
 	Method OnMeasure:Vec2i() Override
 	
 		Return New Vec2i( VirtualWidth,VirtualHeight )
-		
 	End
 	
 End

+ 1 - 1
bin/env_windows.txt

@@ -8,7 +8,7 @@ MX2_WHOLE_ARCHIVE=0
 
 '***** 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)
 '

+ 1 - 1
modules/jni/module.json

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

+ 1 - 1
modules/libc/module.json

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

+ 1 - 1
modules/litehtml/module.json

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

+ 1 - 1
modules/miniz/module.json

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

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

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

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

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

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

@@ -259,7 +259,7 @@ Class Window Extends View
 		Case EventType.WindowMoved,EventType.WindowResized
 			_frame=GetFrame()
 			Frame=_frame
-			_weirdHack=true
+			_weirdHack=True
 		End
 		
 		OnWindowEvent( event )
@@ -342,20 +342,6 @@ Class Window Extends View
 	Global _visibleWindows:=New Stack<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 )
 		size/=_mouseScale
 		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
 	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()
-
+		
 		'All this polling is a bit ugly...fixme.
 		'		
 #If __DESKTOP_TARGET__
@@ -415,6 +415,12 @@ Class Window Extends View
 			_frame=Frame
 			_weirdHack=True
 		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
 		_frame=GetFrame()
 		Frame=_frame

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

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

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

@@ -36,25 +36,17 @@ Class FreeTypeFont Extends Font
 		
 		Local face:FT_Face
 		If FT_New_Memory_Face( FreeType,data.Data,data.Length,0,Varptr face ) 
-			data.Release()
+			data.Discard()
 			Return Null
 		Endif
 		
 		Local font:=New FreeTypeFont( data,face,fheight,shader )
-		font.Discarded+=data.Discard
 		
 		Return font
 	End
 	
 	Protected
 	
-	Method OnDiscard() Override
-	
-		FT_Done_Face( _face )
-	
-		Super.OnDiscard()
-	End
-	
 	Method OnLoadGlyphPage( page:Int,gpage:GlyphPage ) Override
 	
 		Const MaxTexWidth:=1024
@@ -130,7 +122,7 @@ Class FreeTypeFont Extends Font
 			
 			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 )
 	
@@ -143,11 +135,21 @@ Class FreeTypeFont Extends Font
 		gpage.image=New Image( pixmap,TextureFlags.Filter|TextureFlags.Mipmap,_shader )
 		gpage.glyphs=glyphs
 		
-		pixmap.Release()
-		
 '		Print "Loading glyph page "+page+", image size="+gpage.image.Rect.Size
 	End
-
+	
+	Method OnDiscard() Override
+	
+		FT_Done_Face( _face )
+		
+		_data.Discard()
+		
+		_data=Null
+		_face=Null
+		_shader=Null
+		
+	End
+	
 	Private
 	
 	Field _data:DataBuffer
@@ -157,6 +159,7 @@ Class FreeTypeFont Extends Font
 	Field _ascent:Int
 	
 	Method New( data:DataBuffer,face:FT_Face,fheight:Float,shader:Shader )
+		
 		_data=data
 		_face=face
 		_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.
 	
-	Note: `textureFlags` should be null for static images or TextureFlags.Dynamic for dynamic images.
-
 	@param pixmap Source image.
 	
 	@param textureFlags Image texture flags. 
@@ -52,29 +50,21 @@ Class Image Extends Resource
 	@param width,height Image size.
 	
 	#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 )
 		
-		Discarded+=texture.Release
-		
 		Init( texture,shader )
 	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 )
 		
-		Discarded+=texture.Release
-		
 		Init( texture,shader )
 	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 )
 	End
@@ -218,7 +208,7 @@ Class Image Extends Resource
 	
 		_color=color
 		
-		_material.SetVec4f( "ImageColor",_color )
+		_uniforms.SetVec4f( "ImageColor",_color )
 	End
 
 	#rem monkeydoc The image light depth.
@@ -231,7 +221,7 @@ Class Image Extends Resource
 	
 		_lightDepth=depth
 		
-		_material.SetFloat( "LightDepth",_lightDepth )
+		_uniforms.SetFloat( "LightDepth",_lightDepth )
 	End
 
 	#rem monkeydoc Shadow caster attached to image.
@@ -289,7 +279,7 @@ Class Image Extends Resource
 	#end
 	Property Material:UniformBlock()
 	
-		Return _material
+		Return _uniforms
 	End
 
 	#rem monkeydoc @hidden Image vertices.
@@ -312,7 +302,7 @@ Class Image Extends Resource
 	
 		_textures[index]=texture
 		
-		_material.SetTexture( "ImageTexture"+index,texture )
+		_uniforms.SetTexture( "ImageTexture"+index,texture )
 	End
 	
 	#rem monkeydoc @hidden gets an image's texture.
@@ -321,19 +311,17 @@ Class Image Extends Resource
 	
 		Return _textures[index]
 	End
-	
+
 	#rem monkeydoc Loads an image from file.
 	#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 )
 		If Not pixmap Return Null
 
 		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
 	End
@@ -362,9 +350,6 @@ Class Image Extends Resource
 		
 		Local image:=New Image( texture0,shader )
 
-		image.Discarded+=texture0.Release
-		image.Discarded+=texture1.Release
-		
 		image.SetTexture( 1,texture1 )
 		
 		Return image
@@ -386,9 +371,7 @@ Class Image Extends Resource
 			
 		Case PixelFormat.A8
 
-			Local tpixmap:=pixmap
 			pixmap=pixmap.Convert( PixelFormat.IA16 )
-			tpixmap.Release()
 
 			'Copy A->I
 			For Local y:=0 Until pixmap.Height
@@ -401,9 +384,7 @@ Class Image Extends Resource
 
 		Case PixelFormat.I8
 		
-			Local tpixmap:=pixmap
 			pixmap=pixmap.Convert( PixelFormat.IA16 )
-			tpixmap.Release()
 			
 			'Copy I->A
 			For Local y:=0 Until pixmap.Height
@@ -416,9 +397,7 @@ Class Image Extends Resource
 
 		Case PixelFormat.RGB24
 		
-			Local tpixmap:=pixmap
 			pixmap=pixmap.Convert( PixelFormat.RGBA32 )
-			tpixmap.Release()
 			
 			'Copy Max(R,G,B)->A
 			For Local y:=0 Until pixmap.Height
@@ -438,10 +417,21 @@ Class Image Extends Resource
 		Return image
 	End
 	
+	Protected
+
+	#rem monkeydoc @hidden
+	#end	
+	Method OnDiscard() Override
+
+		SafeDiscard( _uniforms )
+		_uniforms=Null
+		_textures=Null
+	End
+	
 	Private
 	
 	Field _shader:Shader
-	Field _material:UniformBlock
+	Field _uniforms:UniformBlock
 	Field _textures:=New Texture[4]
 	Field _blendMode:BlendMode
 	Field _color:Color
@@ -468,7 +458,7 @@ Class Image Extends Resource
 	
 		_rect=rect
 		_shader=shader
-		_material=New UniformBlock( 2 )
+		_uniforms=New UniformBlock( 2 )
 		
 		SetTexture( 0,texture )
 		
@@ -505,15 +495,6 @@ Class Image Extends Resource
 		_texCoords.max.y=Float(_rect.max.y)/_textures[0].Height
 	End
 	
-	Method MakeTextureFlags:TextureFlags( textureFlags:TextureFlags )
-		
-		textureFlags|=TextureFlags.Filter
-		
-		If Not (textureFlags & TextureFlags.Dynamic) textureFlags|=textureFlags.Mipmap
-		
-		Return textureFlags
-	End
-	
 End
 
 Class ResourceManager Extension

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

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

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

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

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

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

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

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

+ 1 - 1
modules/mojo/module.json

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

+ 1 - 1
modules/mojox/module.json

@@ -3,6 +3,6 @@
 	"about":"GUI extensions for mojo",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"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>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.
 

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

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

+ 4 - 0
modules/monkey/gc.monkey2

@@ -3,6 +3,10 @@ Namespace monkey.gc
 
 Extern
 
+#rem monkeydoc @hidden
+#end
+Function GCSetDebug( debug:Bool )="bbGC::setDebug"
+
 #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.

+ 1 - 1
modules/monkey/module.json

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

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

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

+ 3 - 3
modules/monkey/types.monkey2

@@ -704,9 +704,9 @@ Class @Object="bbObject"
 	#end
 	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
 	#end

+ 1 - 1
modules/openal/module.json

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

+ 1 - 1
modules/reflection/module.json

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

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

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

+ 1 - 1
modules/sdl2/module.json

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

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

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

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

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

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

@@ -3,6 +3,6 @@
 	"about":"Minimal truetype lib",
 	"author":"Mark Sibly",
 	"version":"1.0.0",
-	"support":"http://monkey2.monkey-x.com",
+	"support":"http://monkeycoder.co.nz",
 	"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.
 #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
 	#end
 	Method New( length:Int,format:AudioFormat,hertz:Int )
-	
-		Local data:=libc.malloc( BytesPerSample( format )*length )
-		
 		_length=length
 		_format=format
 		_hertz=hertz
-		_data=Cast<UByte Ptr>( data )
-		
-		OnDiscarded=Lambda()
-			libc.free( data )
-		End
+		_owned=True
+		_data=Cast<UByte Ptr>( GCMalloc( BytesPerSample( format )*length ) )
 	End
 
 	Method New( length:Int,format:AudioFormat,hertz:Int,data:Void Ptr )
 		_length=length
 		_format=format
 		_hertz=hertz
+		_owned=false
 		_data=Cast<UByte Ptr>( data )
 	End
 	
@@ -99,17 +90,6 @@ Class AudioData
 		RuntimeError( "TODO!" )
 	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.
 	#end
 	Function Load:AudioData( path:String )
@@ -122,12 +102,31 @@ Class AudioData
 		Return Null
 	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
 	
 	Field _length:Int
 	Field _format:AudioFormat
 	Field _hertz:Int
+	Field _owned:Bool
+
 	Field _data:UByte Ptr
-	Field _discarded:Bool
 	
 End

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

@@ -1,6 +1,35 @@
 
 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 )
 
 	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 )
 	
-	data.OnDiscarded+=Lambda()
-		libc.free( samples )
-	End
-	
 	Return data
 
 End

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

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

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

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

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

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

+ 1 - 1
modules/std/module.json

@@ -3,6 +3,6 @@
 	"about":"Standard monkey2 library",
 	"author":"Mark Sibly",
 	"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"]
 }

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

@@ -1,86 +1,93 @@
 
 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
-	Method AddDependancy( r:Resource )
-		
-		If Not r Return
+	Method Discard()
 		
-		r.Retain()
-
-		Discarded+=r.Release
+		InternalDiscard()
 	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
-	Method Discard()
-		
-		If Not _refs Return
-		
-		_refs=0
-		
-		OnDiscard()
-		
-		Discarded()
+	Method OnDiscard() Override
 	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
-	Method OnDiscard() Virtual
+	Method OnFinalize() Override
 	End
 	
-	Private
-	
-	Field _refs:=1
 End
 
 #rem monkeydoc @hidden
@@ -121,13 +128,6 @@ Class ResourceManager Extends Resource
 	
 		_managers.Remove( Self )
 		
-		For Local it:=Eachin _retained
-			
-			it.Value.Release()
-				
-			it.Value=Null
-		Next
-		
 		_retained=Null
 	End
 	
@@ -135,29 +135,10 @@ Class ResourceManager Extends Resource
 	
 	Global _managers:=New Stack<ResourceManager>
 	
-	Global _refs:=New StringMap<Int>
-	
 	Field _retained:=New StringMap<Resource>
-
 End
 
-#rem monkeydoc Releases a resource unless it's null.
-#end
 Function SafeDiscard( r:Resource )
 	
 	If r r.Discard()
 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.h"
 
-Extern
+Extern private
 
 #rem monkeydoc @hidden
 #end
@@ -209,7 +209,7 @@ Sockets support asynchronous programming through the use of fibers. To connect,
 Sockets are ipv4/ipv6 compatible.
 
 #end
-Class Socket
+Class Socket Extends std.resource.Resource
 
 	#rem Not on Windows...
 	
@@ -288,11 +288,8 @@ Class Socket
 	
 	#end	
 	Method Close()
-		If _socket=-1 Return
-		socket_close( _socket )
-		_socket=-1
-		_addr=Null
-		_peer=null
+		
+		Discard()
 	End
 	
 	#rem monkeydoc Sends data on a connected socket.
@@ -429,6 +426,25 @@ Class Socket
 		Return New Socket( socket )
 	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
 	
 	Field _socket:Int=-1

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

@@ -36,19 +36,6 @@ Class FileStream Extends Stream
 		Return _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.
 	
 	@param offset The position to seek to.
@@ -129,9 +116,17 @@ Class FileStream Extends Stream
 	
 	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
 	
 	Private

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

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

+ 1 - 4
src/ted2/modulemanager.monkey2

@@ -99,8 +99,6 @@ Class ModuleManager Extends Dialog
 	
 	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 downloadDir:="modules/module-manager/downloads/"
@@ -414,8 +412,7 @@ Class ModuleManager Extends Dialog
 	
 	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"