Browse Source

merged develop.

Mark Sibly 7 năm trước cách đây
mục cha
commit
85b84f047c
35 tập tin đã thay đổi với 1313 bổ sung1502 xóa
  1. 8 0
      VERSIONS.TXT
  2. 164 164
      ducks-scene.mojo3d
  3. 182 182
      hingechain-scene.mojo3d
  4. 182 182
      jointchain-scene.mojo3d
  5. 2 2
      modules/mojo3d/assets/shaders/imports/pbr.glsl
  6. 1 0
      modules/mojo3d/assets/shaders/imports/std.glsl
  7. 2 0
      modules/mojo3d/assets/shaders/misc/skybox.glsl
  8. 2 1
      modules/mojo3d/render/renderer.monkey2
  9. 23 9
      modules/mojo3d/scene/entities/model.monkey2
  10. 50 29
      modules/mojo3d/scene/jsonifier/jsonifier.monkey2
  11. 8 0
      modules/mojo3d/scene/materials/pbrmaterial.monkey2
  12. 8 4
      modules/mojo3d/scene/meshprims.monkey2
  13. 21 0
      modules/mojo3d/scene/scene.monkey2
  14. 0 2
      modules/mojox/assets/themes/filetype_icons/filetypes.txt
  15. 0 0
      modules/mojox/assets/themes/filetype_icons/index.html
  16. 0 5
      modules/mojox/assets/themes/filetype_icons/readme.url
  17. 1 0
      modules/monkey/monkey.monkey2
  18. 18 0
      modules/monkey/native/bbgc.cpp
  19. 1 0
      modules/monkey/native/bbmonkey.h
  20. 54 0
      modules/monkey/native/bbweakref.cpp
  21. 26 0
      modules/monkey/native/bbweakref.h
  22. 20 0
      modules/monkey/types.monkey2
  23. 16 0
      modules/stb-image/stb-image.monkey2
  24. 27 19
      modules/std/graphics/pixelformat.monkey2
  25. 85 16
      modules/std/graphics/pixmaploader.monkey2
  26. 0 413
      modules/std/graphics/rgbe/rgbe.c
  27. 0 61
      modules/std/graphics/rgbe/rgbe.h
  28. 0 61
      modules/std/graphics/rgbe/rgbe.txt
  29. 42 0
      modules/std/stream/stream.monkey2
  30. 166 165
      shapes-scene.mojo3d
  31. 23 19
      spotlight-scene.mojo3d
  32. 143 143
      sprites-scene.mojo3d
  33. 0 2
      src/mx2cc/mx2cc.monkey2
  34. 23 8
      src/mx2cc/test.monkey2
  35. 15 15
      test-scene.mojo3d

+ 8 - 0
VERSIONS.TXT

@@ -1,6 +1,14 @@
 
 ***** Monkey-v2018.06 *****
 
+Added WeakRef class. Must be constructed with an Object, and has a single Target property that returns Null if object has been GC'd. Really needs this for arrays too I guess.
+
+Added Stream.SharedPath property for obtaining a path to an open stream.
+
+Changed to stb-image for hdr support.
+
+Added Cancel() method to HttpRequest.
+
 Added Timeout property to HttpRequest.
 
 Implemented HttpRequest on all targets - only GET tested.

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 164 - 164
ducks-scene.mojo3d


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 182 - 182
hingechain-scene.mojo3d


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 182 - 182
jointchain-scene.mojo3d


+ 2 - 2
modules/mojo3d/assets/shaders/imports/pbr.glsl

@@ -7,9 +7,9 @@
 
 float pointAtten( float d,float r ){
 
-	float atten=1.0-min( (d*d)/(r*r),1.0 );atten*=atten;
+//	float atten=1.0-min( (d*d)/(r*r),1.0 );atten*=atten;
 
-//	float atten=1.0-min( d/r,1.0 );atten*=atten;
+	float atten=1.0-min( d/r,1.0 );atten*=atten;
 	
 //	float atten=1.0/(1.0+d*d);
 

+ 1 - 0
modules/mojo3d/assets/shaders/imports/std.glsl

@@ -68,6 +68,7 @@ uniform vec4 r_AmbientDiffuse;
 uniform samplerCube r_SkyTextureCube;
 uniform sampler2D r_SkyTexture2D;
 uniform bool r_SkyCube;
+uniform vec4 r_SkyColor;
 
 uniform samplerCube r_EnvTextureCube;
 uniform sampler2D r_EnvTexture2D;

+ 2 - 0
modules/mojo3d/assets/shaders/misc/skybox.glsl

@@ -33,6 +33,8 @@ void main(){
 		frag=pow( texture2D( r_SkyTexture2D,vec2( y,p ) ).rgb,vec3( 2.2 ) );
 	}
 	
+	frag*=r_SkyColor.rgb;
+	
 #if MX2_DEFERREDRENDERER
 	gl_FragData[0]=vec4( frag,1.0 );					//accum
 	gl_FragData[1]=vec4( 0.0,0.0,0.0,1.0 );				//color_m

+ 2 - 1
modules/mojo3d/render/renderer.monkey2

@@ -137,7 +137,7 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 	Method RenderBackground()
 	
 		If _scene.SkyTexture
-		
+			
 			_gdevice.ColorMask=ColorMask.None
 			_gdevice.DepthMask=True
 			
@@ -1024,6 +1024,7 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 		Local sky:=_scene.SkyTexture
 		
 		If sky
+			_runiforms.SetColor( "SkyColor",_scene.SkyColor )
 			If sky.Flags & TextureFlags.Cubemap
 				_runiforms.SetTexture( "SkyTextureCube",sky )
 				_runiforms.SetTexture( "SkyTexture2D",_whiteTexture )

+ 23 - 9
modules/mojo3d/scene/entities/model.monkey2

@@ -124,9 +124,9 @@ Class Model Extends Renderable
 		
 		Local scene:=mojo3d.Scene.GetCurrent()
 		
-		Local editing:=scene.Editing
-		
-		If editing scene.Jsonifier.BeginLoading()
+		If scene.Editing
+			scene.Jsonifier.BeginLoading()
+		Endif
 		
 		Local model:Model
 		
@@ -137,9 +137,10 @@ Class Model Extends Renderable
 			If model Exit
 		Next
 		
-		If editing scene.Jsonifier.EndLoading()
-		
-		If editing scene.Jsonifier.AddInstance( model,"mojo3d.Model.Load",New Variant[]( path )  )
+		If scene.Editing
+			scene.Jsonifier.EndLoading()
+			If model scene.Jsonifier.AddInstance( model,"mojo3d.Model.Load",New Variant[]( path )  )
+		Endif
 		
 		Return model
 	End
@@ -161,15 +162,28 @@ Class Model Extends Renderable
 	
 	#end
 	Function LoadBoned:Model( path:String )
+		
+		Local scene:=mojo3d.Scene.GetCurrent()
+		
+		If scene.Editing
+			scene.Jsonifier.BeginLoading()
+		Endif
+		
+		Local model:Model		
 	
 		For Local loader:=Eachin Mojo3dLoader.Instances
 		
-			Local model:=loader.LoadBonedModel( path )
+			model=loader.LoadBonedModel( path )
 			
-			If model Return model
+			If model Exit
 		Next
 		
-		Return Null
+		If scene.Editing
+			scene.Jsonifier.EndLoading()
+			If model scene.Jsonifier.AddInstance( model,"mojo3d.Model.LoadBoned",New Variant[]( path )  )
+		Endif
+		
+		Return model
 	End
 	
 	Protected

+ 50 - 29
modules/mojo3d/scene/jsonifier/jsonifier.monkey2

@@ -5,7 +5,7 @@ Class Jsonifier
 Private
 	
 	Class Instance
-		Field id:Int
+		Field id:String
 		Field obj:Variant
 		Field ctor:Invocation
 		Field initialState:JsonObject
@@ -18,6 +18,7 @@ Private
 	Field _loading:Int
 	Field _instLoading:Int
 	Field _instsByObj:=New Map<Object,Instance>
+	Field _instsById:=New StringMap<Instance>
 	Field _insts:=New Stack<Instance>
 	
 Public
@@ -54,13 +55,16 @@ Public
 			inst.ctor=ctor
 			Return
 		Endif
+		
+		Local id:="#"+_insts.Length
 			
 		inst=New Instance
-		inst.id=_insts.Length
+		inst.id=id
 		inst.obj=obj
 		
-		_insts.Add( inst )
 		_instsByObj[tobj]=inst
+		_instsById[id]=inst
+		_insts.Add( inst )
 		
 		If _loading Return
 
@@ -80,8 +84,6 @@ Public
 		
 		For Local i:=0 Until _insts.Length
 			
-'			Print "Jsonifying "+i
-			
 			Local inst:=_insts[i]
 			Local tobj:=Cast<Object>( inst.obj )
 
@@ -98,13 +100,17 @@ Public
 				If CompareJson( x,y )<>0 dstate[it.Key]=x
 			Next
 			
+			'skip objects with no ctor and no delta state...
 			If Not inst.ctor And dstate.Empty Continue
 			
 			Local jobj:=New JsonObject
+			
 			jobj["type"]=New JsonString( tobj.DynamicType.Name )	'not actually used, cool for debug
 			
-			jobj["id"]=New JsonNumber( inst.id )
+			jobj["id"]=New JsonString( inst.id )
+			
 			If inst.ctor jobj["ctor"]=Jsonify( inst.ctor )
+				
 			If Not dstate.Empty jobj["state"]=dstate
 				
 			jinsts.Add( jobj )
@@ -123,51 +129,65 @@ Public
 		
 		Local jinsts:=jobj.GetArray( "instances" )
 
-		Local jobjsById:=New IntMap<JsonObject>
+		Local jobjsById:=New StringMap<JsonObject>
 		
 		For Local i:=0 Until jinsts.Length
 			
 			Local jobj:=jinsts.GetObject( i )
 			Assert( jobj.Contains( "id" ) )
 			
-			Local id:=jobj.GetNumber( "id" )
+			Local id:=jobj.GetString( "id" )
 			Assert( Not jobjsById.Contains( id ) )
 			
 			jobjsById[id]=jobj
 		Next
 		
-		Local id:=0
+		Local n:=0,ninsts:=_insts.Length
 		
 		For Local i:=0 Until jinsts.Length
 			
 			Local jobj:=jinsts.GetObject( i )
-			If Not jobj.Contains( "ctor" ) Continue
 			
-			If jobj.GetNumber( "id" )>=_insts.Length
+			Local inst:Instance
+			
+			If jobj.Contains( "ctor" ) And i>=ninsts
 				Local ctor:=Cast<Invocation>( Dejsonify( jobj["ctor"],Typeof<Invocation> ) )
-				ctor.Execute()
+				Local tobj:=Cast<Object>( ctor.Execute() )
+				inst=_instsByObj[tobj]
+			Else
+				inst=_insts[i]
 			Endif
 			
-			For Local j:=id Until _insts.Length
-				
-				If Not jobjsById.Contains( j ) Continue
+			Local id:=jobj.GetString( "id" )
+			_instsById[id]=inst
+			inst.id=id
 
-				Local jobj:=jobjsById[j]
+			For Local j:=n Until _insts.Length
+				
+				Local id:=_insts[j].id
+				
+				Local jobj:=jobjsById[id]
+				If Not jobj Or Not jobj.Contains( "state" ) Continue
+				
 				Local tobj:=Cast<Object>( _insts[j].obj )
-				If jobj.Contains( "state" ) DejsonifyState( tobj,jobj.GetObject( "state" ),tobj.DynamicType,False )
+				
+				DejsonifyState( tobj,jobj.GetObject( "state" ),tobj.DynamicType,False )
 			Next
 			
-			id=_insts.Length
+			n=_insts.Length
 		Next
 		
 		'set reference type state - do this on a second pass 'coz of forward refs. Probably wont always work?
-		For Local i:=0 Until _insts.Length
+		For Local j:=0 Until _insts.Length
+			
+			Local id:=_insts[j].id
+			
+			Local jobj:=jobjsById[id]
+			If Not jobj Or Not jobj.Contains( "state" ) Continue
 			
-			If Not jobjsById.Contains( i ) Continue
+			Local tobj:=Cast<Object>( _insts[j].obj )
 			
-			Local jobj:=jobjsById[i]
-			Local tobj:=Cast<Object>( _insts[i].obj )
-			If jobj.Contains( "state" ) DejsonifyState( tobj,jobj.GetObject( "state" ),tobj.DynamicType,True )
+			DejsonifyState( tobj,jobj.GetObject( "state" ),tobj.DynamicType,True )
 		Next
 		
 		SetAssetsDir( assetsDir )
@@ -226,9 +246,10 @@ Public
 			Local obj:=Cast<Object>( value )
 			If Not obj Return JsonValue.NullValue
 			Local inst:=_instsByObj[obj]
-			If inst Return New JsonString( "@"+inst.id )
-			Return JsonValue.NullValue	'for objects that weren't added using AddInstance - should really never happen.
-'			RuntimeError( "Can't jsonify instance of type '"+type+"'" )
+			If inst Return New JsonString( inst.id )
+			'For objects that weren't added using AddInstance, eg: textures loaded via Texture.Load instead of Scene.LoadTexture.
+			Return JsonValue.NullValue	
+'			RuntimeError( "Jsonifier can't find instance of type '"+type+"'" )
 		Endif
 		
 		'try custom jsonifiers
@@ -279,9 +300,9 @@ Public
 			If jvalue.IsNull
 				Return type.NullValue
 			Elseif jvalue.IsString
-				Local id:=Int( jvalue.ToString().Slice( 1 ) )
-				Assert( id>=0 And id<_insts.Length,"Dejsonify error" )
-				Return _insts[id].obj
+				Local id:=jvalue.ToString()
+				Assert( _instsById.Contains( id ),"Dejsonify error" )
+				Return _instsById[id].obj
 			Endif
 		Endif
 		

+ 8 - 0
modules/mojo3d/scene/materials/pbrmaterial.monkey2

@@ -54,6 +54,7 @@ Class PbrMaterial Extends Material
 	
 	'***** textures *****
 	
+	[jsonify=1]
 	Property Boned:Bool()
 		
 		Return (AttribMask & 192)=192
@@ -63,6 +64,7 @@ Class PbrMaterial Extends Material
 		If boned AttribMask|=192 Else AttribMask&=~192
 	End
 	
+	[jsonify=1]
 	Property ColorTexture:Texture()
 	
 		Return Uniforms.GetTexture( "ColorTexture" )
@@ -74,6 +76,7 @@ Class PbrMaterial Extends Material
 		UpdateAttribMask()
 	End
 	
+	[jsonify=1]
 	Property AmbientTexture:Texture()
 		
 		Return Uniforms.GetTexture( "AmbientTexture" )
@@ -85,6 +88,7 @@ Class PbrMaterial Extends Material
 		UpdateAttribMask()
 	End
 	
+	[jsonify=1]
 	Property EmissiveTexture:Texture()
 	
 		Return Uniforms.GetTexture( "EmissiveTexture" )
@@ -96,6 +100,7 @@ Class PbrMaterial Extends Material
 		UpdateAttribMask()
 	End
 	
+	[jsonify=1]
 	Property MetalnessTexture:Texture()
 	
 		Return Uniforms.GetTexture( "MetalnessTexture" )
@@ -107,6 +112,7 @@ Class PbrMaterial Extends Material
 		UpdateAttribMask()
 	End
 
+	[jsonify=1]
 	Property RoughnessTexture:Texture()
 	
 		Return Uniforms.GetTexture( "RoughnessTexture" )
@@ -118,6 +124,7 @@ Class PbrMaterial Extends Material
 		UpdateAttribMask()
 	End
 	
+	[jsonify=1]
 	Property OcclusionTexture:Texture()
 	
 		Return Uniforms.GetTexture( "OcclusionTexture" )
@@ -129,6 +136,7 @@ Class PbrMaterial Extends Material
 		UpdateAttribMask()
 	End
 	
+	[jsonify=1]
 	Property NormalTexture:Texture()
 	
 		Return Uniforms.GetTexture( "NormalTexture" )

+ 8 - 4
modules/mojo3d/scene/meshprims.monkey2

@@ -96,7 +96,8 @@ Class Mesh Extension
 				For Local x:=0 To xsegs
 					Local vx:=box.Width*x/xsegs+box.min.x
 					Local vy:=box.Height*y/ysegs+box.min.y
-					vp[0]=New Vertex3f( vx,vy,q>0 ? box.max.z Else box.min.z, Float(x)/xsegs,Float(y)/ysegs, 0,0,q )
+					Local u:=Float(x)/xsegs,v:=Float(y)/ysegs
+					vp[0]=New Vertex3f( vx,vy,q>0 ? box.max.z Else box.min.z, q=1 ? 1-u Else u,1-v, 0,0,q )
 					vp+=1
 				Next
 			Next
@@ -104,7 +105,8 @@ Class Mesh Extension
 				For Local x:=0 To xsegs
 					Local vx:=box.Width*x/xsegs+box.min.x
 					Local vz:=box.Depth*z/zsegs+box.min.z
-					vp[0]=New Vertex3f( vx,q>0 ? box.max.y Else box.min.y,vz, Float(x)/xsegs,Float(z)/zsegs, 0,q,0 )
+					Local u:=Float(x)/xsegs,v:=Float(z)/zsegs
+					vp[0]=New Vertex3f( vx,q>0 ? box.max.y Else box.min.y,vz, u,q=1 ? 1-v Else v, 0,q,0 )
 					vp+=1
 				Next
 			Next
@@ -112,7 +114,8 @@ Class Mesh Extension
 				For Local z:=0 To zsegs
 					Local vy:=box.Height*y/ysegs+box.min.y
 					Local vz:=box.Depth*z/zsegs+box.min.z
-					vp[0]=New Vertex3f( q>0 ? box.max.x Else box.min.x,vy,vz, Float(z)/zsegs,Float(y)/ysegs, q,0,0 )
+					Local u:=Float(z)/zsegs,v:=Float(y)/ysegs
+					vp[0]=New Vertex3f( q>0 ? box.max.x Else box.min.x,vy,vz, q=-1 ? 1-u Else u,1-v, q,0,0 )
 					vp+=1
 				Next
 			Next
@@ -302,10 +305,11 @@ Class Mesh Extension
 			Local yaw:=i * TwoPi / segs
 			Local v:=New Vec3f( Cos( yaw ) * radius,hlength,Sin( yaw ) * radius )
 			Local n:=New Vec3f( 0,1,0 )
-			Local tc:=New Vec2f( v.x*.5+.5,v.z*.5+.5 )
+			Local tc:=New Vec2f( v.x*.5+.5,1-(v.z*.5+.5) )
 			vertices.Add( New Vertex3f( v,tc,n ) )
 			v.y=-v.y
 			n.y=-n.y
+			tc.y=1-tc.y
 			vertices.Add( New Vertex3f( v,tc,n ) )
 		Next
 		For Local i:=1 Until segs-1

+ 21 - 0
modules/mojo3d/scene/scene.monkey2

@@ -18,6 +18,8 @@ Class Scene
 		
 		_clearColor=Color.Sky
 
+		_skyColor=Color.White
+
 		_ambientDiffuse=Color.DarkGrey
 		
 		_envColor=Color.White
@@ -55,6 +57,23 @@ Class Scene
 		_skyTexture=texture
 	End
 	
+	#rem monkeydoc The sky color.
+	
+	The sky color is used to modulate the sky texture.
+	
+	Sky color is only used if there is also a sky texture.
+	
+	#end
+	[jsonify=1]
+	Property SkyColor:Color()
+		
+		Return _skyColor
+	
+	Setter( color:Color )
+		
+		_skyColor=color
+	End
+	
 	#rem monkeydoc The environment texture.
 	
 	The environment textures is used to render specular reflections within the scene.
@@ -407,6 +426,8 @@ Class Scene
 	Global _defaultEnv:Texture
 	
 	Field _skyTexture:Texture
+	Field _skyColor:Color
+	
 	Field _envTexture:Texture
 	Field _envColor:Color
 	

+ 0 - 2
modules/mojox/assets/themes/filetype_icons/filetypes.txt

@@ -42,7 +42,6 @@ htm.png
 html.png
 ics.png
 image.png
-index.html
 iso.png
 jar.png
 java.png
@@ -77,7 +76,6 @@ py.png
 ram.png
 rar.png
 rb.png
-readme.url
 rm.png
 rpm.png
 rtf.png

+ 0 - 0
modules/mojox/assets/themes/filetype_icons/index.html


+ 0 - 5
modules/mojox/assets/themes/filetype_icons/readme.url

@@ -1,5 +0,0 @@
-[{000214A0-0000-0000-C000-000000000046}]
-Prop3=19,2
-[InternetShortcut]
-URL=http://fileicons.chromefans.org/?ref=zip_fi
-IDList=

+ 1 - 0
modules/monkey/monkey.monkey2

@@ -10,6 +10,7 @@ Namespace monkey
 #Import "native/bbgc.cpp"
 #Import "native/bbobject.cpp"
 #Import "native/bbdebug.cpp"
+#Import "native/bbweakref.cpp"
 #Import "native/bbvariant.cpp"
 #Import "native/bbtypeinfo.cpp"
 #Import "native/bbdeclinfo.cpp"

+ 18 - 0
modules/monkey/native/bbgc.cpp

@@ -1,4 +1,6 @@
+
 #include "bbgc.h"
+#include "bbweakref.h"
 
 namespace bbDB{
 
@@ -99,6 +101,22 @@ namespace bbGC{
 			
 			remove( p );
 			
+			if( p->flags & 2 ){
+
+				//printf( "deleting weak refs for: %s %p\n",p->typeName(),p );fflush( stdout );
+				
+				bbGCWeakRef **pred=&bbGC::weakRefs,*curr;
+				
+				while( curr=*pred ){
+					if( curr->target==p ){
+						curr->target=0;
+						*pred=curr->succ;
+					}else{
+						pred=&curr->succ;
+					}
+				}
+			}
+			
 			if( p->flags & 1 ){
 				
 				//printf( "finalizing: %s %p\n",p->typeName(),p );fflush( stdout );

+ 1 - 0
modules/monkey/native/bbmonkey.h

@@ -11,6 +11,7 @@
 #include "bbarray.h"
 #include "bbfunction.h"
 #include "bbobject.h"
+#include "bbweakref.h"
 #include "bbvariant.h"
 #include "bbtypeinfo_t.h"
 #include "bbdeclinfo.h"

+ 54 - 0
modules/monkey/native/bbweakref.cpp

@@ -0,0 +1,54 @@
+
+#include "bbweakref.h"
+
+bbGCWeakRef *bbGC::weakRefs;
+
+bbGCWeakRef::bbGCWeakRef( bbObject *target ):target( target ){
+
+	if( !target) return;
+	
+	succ=bbGC::weakRefs;
+	bbGC::weakRefs=this;
+	target->flags|=2;
+}
+
+bbGCWeakRef::~bbGCWeakRef(){
+
+	if( !target ) return;
+	
+	bbAssert( target->flags & 2,"internal bbGCWeakRef error 1" );
+	
+	bbGCWeakRef **pred=&bbGC::weakRefs,*curr;
+	
+	target->flags&=~2;
+
+	while( curr=*pred ){
+		
+		if( curr==this ){
+			
+			*pred=succ;
+			
+			if( target->flags & 2 ) return;
+			
+			while( curr=*pred ){
+				if( curr->target==target ){
+					target->flags|=2;
+					return;
+				}
+				pred=&curr->succ;
+			}
+			return;
+		}
+		
+		if( curr->target==target ) target->flags|=2;
+			
+		pred=&curr->succ;
+	}
+		
+}
+
+bbObject *bbGCWeakRef::getTarget(){
+
+	return target;
+}
+

+ 26 - 0
modules/monkey/native/bbweakref.h

@@ -0,0 +1,26 @@
+
+
+#ifndef BB_WEAKREF_H
+#define BB_WEAKREF_H
+
+#include "bbobject.h"
+
+struct bbGCWeakRef;
+
+namespace bbGC{
+
+	extern bbGCWeakRef *weakRefs;
+}
+
+struct bbGCWeakRef : public bbObject{
+
+	bbGCWeakRef *succ;	
+	bbObject *target;
+	
+	bbGCWeakRef( bbObject *target );
+	~bbGCWeakRef();
+	
+	bbObject *getTarget();
+};
+
+#endif

+ 20 - 0
modules/monkey/types.monkey2

@@ -777,3 +777,23 @@ Class DeclInfo Extends Void="bbDeclInfo"
 	Method Invoke:Variant( instance:Variant,params:Variant[] )="invoke"
 End
 
+#rem monkeydoc Weak reference class.
+
+A weak reference is an object that contains a reference to another object, but without preventing the other object from being garbage collected.
+
+The [[Target]] property returns the object being referenced, or null if the object has been garbage collected.
+
+A weak reference must be contructed with the object it references.
+
+#end
+Class WeakRef="bbGCWeakRef"
+	
+	Method New( target:Object )
+		
+	Property Target:Object()="getTarget"
+End
+
+	
+
+
+

+ 16 - 0
modules/stb-image/stb-image.monkey2

@@ -21,4 +21,20 @@ Function stbi_load:UByte Ptr( filename:CString,x:Int Ptr,y:Int Ptr,comp:Int Ptr,
 Function stbi_load_from_memory:UByte Ptr( buffer:UByte Ptr,len:Int,x:Int Ptr,y:Int Ptr,comp:Int Ptr,req_comp:Int )
 Function stbi_load_from_callbacks:UByte Ptr( clbk:stbi_io_callbacks Ptr,user:Void Ptr,x:Int Ptr,y:Int Ptr,comp:Int Ptr,req_comp:Int )
 Function stbi_load_from_file:UByte Ptr( f:libc.FILE Ptr,x:Int Ptr,y:Int Ptr,comp:Int Ptr,req_comp:Int )
+Function stbi_loadf:Float Ptr( filename:CString,x:Int Ptr,y:Int Ptr,comp:Int Ptr,req_comp:Int )
+Function stbi_loadf_from_memory:Float Ptr( buffer:UByte Ptr,len:Int,x:Int Ptr,y:Int Ptr,comp:Int Ptr,req_comp:Int )
+Function stbi_loadf_from_callbacks:Float Ptr( clbk:stbi_io_callbacks Ptr,user:Void Ptr,x:Int Ptr,y:Int Ptr,comp:Int Ptr,req_comp:Int )
+Function stbi_loadf_from_file:float Ptr( f:libc.FILE Ptr,x:Int Ptr,y:Int Ptr,comp:Int Ptr,req_comp:Int )
+	
 Function stbi_image_free( data:Void Ptr )
+
+Function stbi_is_hdr_from_callbacks:Int( clbk:stbi_io_callbacks Ptr,user:Void Ptr )
+Function stbi_is_hdr_from_memory:Int( buffer:UByte Ptr,len:Int )
+Function stbi_is_hdr:Int( filename:CString )
+Function stbi_is_hdr_from_file:Int( f:libc.FILE Ptr )
+
+Function stbi_ldr_to_hdr_gamma( gamma:Float )
+Function stbi_ldr_to_hdr_scale( scale:Float )
+Function stbi_hdr_to_ldr_gamma( gamma:Float )
+Function stbi_hdr_to_ldr_scale( scale:Float )
+

+ 27 - 19
modules/std/graphics/pixelformat.monkey2

@@ -25,16 +25,22 @@ Enum PixelFormat
 	RGB8
 	RGBA8
 
+	I16F
+	A16F
+	IA16F
+	RGB16F
 	RGBA16F
+	
+	I32F
+	A32F
+	IA32F
+	RGB32F
 	RGBA32F
 	
 	Depth16
 	Depth24
 	Depth32
 	
-	RGB16F
-	RGB32F
-	
 	RGBE8
 	
 	'deprecated
@@ -46,23 +52,19 @@ End
 
 Function IsAlphaPixelFormat:Bool( format:PixelFormat )
 	Select format
-	Case PixelFormat.A8,PixelFormat.IA8,PixelFormat.RGBA8,PixelFormat.RGBA16F,PixelFormat.RGBA32F Return True
+	Case PixelFormat.A8,PixelFormat.IA8,PixelFormat.RGBA8 Return True
+	Case PixelFormat.A16F,PixelFormat.IA16F,PixelFormat.RGBA16F Return True
+	Case PixelFormat.A32F,PixelFormat.IA32F,PixelFormat.RGBA32F Return True
 	End
 	Return False
 End
 
 Function IsDepthPixelFormat:Bool( format:PixelFormat )
-	Select format
-	Case PixelFormat.Depth16,PixelFormat.Depth24,PixelFormat.Depth32 Return True
-	End
-	Return False
+	Return Int( format )>=Int( PixelFormat.Depth16 ) And Int( format )<=Int( PixelFormat.Depth32 )
 End
 
 Function IsFloatPixelFormat:Bool( format:PixelFormat )
-	Select format
-	Case PixelFormat.RGBA16F,PixelFormat.RGBA32F,PixelFormat.RGB16F,PixelFormat.RGB32F Return True
-	End
-	Return False
+	Return Int( format )>=Int( PixelFormat.I16F ) And Int( format )<=Int( PixelFormat.RGBA32F )
 End
 
 #rem monkeydoc Gets the number of bytes per pixel for a particular pixel format.
@@ -70,25 +72,31 @@ End
 Function PixelFormatDepth:Int( format:PixelFormat )
 
 	Select format
+		
 	Case PixelFormat.I8 Return 1
 	Case PixelFormat.A8 Return 1
 	Case PixelFormat.IA8 Return 2
 	Case PixelFormat.RGB8 Return 3
 	Case PixelFormat.RGBA8 Return 4
+		
+	Case PixelFormat.I16F Return 2
+	Case PixelFormat.A16F Return 2
+	Case PixelFormat.IA16F Return 4
+	Case PixelFormat.RGB16F Return 6
 	Case PixelFormat.RGBA16F Return 8
+		
+	Case PixelFormat.I32F Return 4
+	Case PixelFormat.A32F Return 4
+	Case PixelFormat.IA32F Return 8
+	Case PixelFormat.RGB32F Return 12
 	Case PixelFormat.RGBA32F Return 16
+
 	Case PixelFormat.Depth16 Return 2
 	Case PixelFormat.Depth24 Return 4
 	Case PixelFormat.Depth32 Return 4
-	Case PixelFormat.RGB16F Return 6
-	Case PixelFormat.RGB32F Return 12
+
 	Case PixelFormat.RGBE8 Return 4
 		
-	'deprecated
-	Case PixelFormat.IA16 Return 2
-	Case PixelFormat.RGB24 Return 3
-	Case PixelFormat.RGBA32 Return 4
-		
 	End
 	
 	Return 0

+ 85 - 16
modules/std/graphics/pixmaploader.monkey2

@@ -1,21 +1,10 @@
 
 Namespace std.graphics.pixmaploader
 
-#Import "rgbe/rgbe.c"
-#Import "rgbe/rgbe.h"
-
 Using stb.image
 Using std.stream
 
-Extern Private
-
-Struct rgbe_header_info
-End
-
-Function RGBE_ReadHeader:Int( fp:FILE Ptr,width:Int Ptr,height:Int Ptr,info:rgbe_header_info Ptr )
-Function RGBE_ReadPixels_RLE:Int( fp:FILE Ptr,data:Float Ptr,scanline_width:Int,num_scanlines:Int )
-
-Private
+Internal
 
 Struct stbi_user
 	Field stream:Stream
@@ -36,8 +25,6 @@ Function stbi_eof:Int( user:Void Ptr )
 	Return stream.Eof
 End
 
-#rem monkeydoc @hidden
-#end
 Class StbPixmap Extends Pixmap
 	
 	Method New( width:Int,height:Int,format:PixelFormat,data:UByte Ptr,pitch:Int )
@@ -52,10 +39,12 @@ Class StbPixmap Extends Pixmap
 	
 	Method OnDiscard() Override
 		
-		Super.OnDiscard()
+		If Not _data Return
 		
 		stbi_image_free( _data )
 		
+		Super.OnDiscard()
+		
 		_data=Null
 	End
 	
@@ -65,7 +54,85 @@ Class StbPixmap Extends Pixmap
 	End
 End
 
-Public
+Function LoadPixmap:Pixmap( path:String,format:PixelFormat )
+	
+	Local stream:=Stream.Open( path,"r" )
+	If Not stream Return Null
+
+	Local user:stbi_user
+	user.stream=stream
+	
+	Local clbks:stbi_io_callbacks
+	clbks.read=stbi_read
+	clbks.skip=stbi_skip
+	clbks.eof=stbi_eof
+
+	Local req_comp:Int,isfloat:Bool
+	
+	Select format
+	Case PixelFormat.I8,PixelFormat.IA8,PixelFormat.RGB8,PixelFormat.RGBA8
+		isfloat=False
+		req_comp=PixelFormatDepth( format )
+	Case PixelFormat.RGB32F
+		isfloat=True
+		req_comp=3
+	Case PixelFormat.RGBA32F
+		isfloat=True
+		req_comp=4
+	Case PixelFormat.Unknown
+		Local pos:=stream.Position
+		isfloat=stbi_is_hdr_from_callbacks( Varptr clbks,Varptr user )
+		stream.Seek( pos )
+		req_comp=0
+	Default
+		stream.Close()
+		Return Null
+	End
+	
+	Local x:Int,y:Int,comp:Int,data:UByte Ptr
+	
+	If isfloat
+		
+		stbi_ldr_to_hdr_gamma( 1.0 )
+		stbi_hdr_to_ldr_gamma( 1.0 )
+		
+		data=Cast<UByte Ptr>( stbi_loadf_from_callbacks( Varptr clbks,Varptr user,Varptr x,Varptr y,Varptr comp,req_comp ) )
+		
+		If format=PixelFormat.Unknown
+			Select comp
+			Case 1 format=PixelFormat.I32F
+			Case 2 format=PixelFormat.IA32F
+			Case 3 format=PixelFormat.RGB32F
+			Case 4 format=PixelFormat.RGBA32F
+			End
+		Endif
+	Else
+		
+		data=stbi_load_from_callbacks( Varptr clbks,Varptr user,Varptr x,Varptr y,Varptr comp,req_comp )
+		
+		If format=PixelFormat.Unknown
+			Select comp
+			Case 1 format=PixelFormat.I8
+			Case 2 format=PixelFormat.IA8
+			Case 3 format=PixelFormat.RGB8
+			Case 4 format=PixelFormat.RGBA8
+			End
+		Endif
+	Endif
+	
+	stream.Close()
+	
+	If format=PixelFormat.Unknown
+		Print "Unknown format for image at '"+path+"'"
+		Return Null
+	endif
+	
+	Local pixmap:=New StbPixmap( x,y,format,data,x*PixelFormatDepth( format ) )
+	
+	Return pixmap
+End
+
+#rem
 
 #rem monkeydoc @hidden
 #end
@@ -130,3 +197,5 @@ Function LoadPixmap:Pixmap( path:String,format:PixelFormat )
 	
 	Return pixmap
 End
+
+#End

+ 0 - 413
modules/std/graphics/rgbe/rgbe.c

@@ -1,413 +0,0 @@
-/* THIS CODE CARRIES NO GUARANTEE OF USABILITY OR FITNESS FOR ANY PURPOSE.
- * WHILE THE AUTHORS HAVE TRIED TO ENSURE THE PROGRAM WORKS CORRECTLY,
- * IT IS STRICTLY USE AT YOUR OWN RISK.  */
-
-#include "rgbe.h"
-#include <math.h>
-#include <stdlib.h>	//<malloc.h>
-#include <string.h>
-#include <ctype.h>
-
-/* This file contains code to read and write four byte rgbe file format
- developed by Greg Ward.  It handles the conversions between rgbe and
- pixels consisting of floats.  The data is assumed to be an array of floats.
- By default there are three floats per pixel in the order red, green, blue.
- (RGBE_DATA_??? values control this.)  Only the mimimal header reading and 
- writing is implemented.  Each routine does error checking and will return
- a status value as defined below.  This code is intended as a skeleton so
- feel free to modify it to suit your needs.
-
- (Place notice here if you modified the code.)
- posted to http://www.graphics.cornell.edu/~bjw/
- written by Bruce Walter  ([email protected])  5/26/95
- based on code written by Greg Ward
-*/
-
-#ifdef _CPLUSPLUS
-/* define if your compiler understands inline commands */
-#define INLINE inline
-#else
-#define INLINE
-#endif
-
-/* offsets to red, green, and blue components in a data (float) pixel */
-#define RGBE_DATA_RED    0
-#define RGBE_DATA_GREEN  1
-#define RGBE_DATA_BLUE   2
-/* number of floats per pixel */
-#define RGBE_DATA_SIZE   3
-
-enum rgbe_error_codes {
-  rgbe_read_error,
-  rgbe_write_error,
-  rgbe_format_error,
-  rgbe_memory_error,
-};
-
-/* default error routine.  change this to change error handling */
-static int rgbe_error(int rgbe_error_code, char *msg)
-{
-  switch (rgbe_error_code) {
-  case rgbe_read_error:
-    perror("RGBE read error");
-    break;
-  case rgbe_write_error:
-    perror("RGBE write error");
-    break;
-  case rgbe_format_error:
-    fprintf(stderr,"RGBE bad file format: %s\n",msg);
-    break;
-  default:
-  case rgbe_memory_error:
-    fprintf(stderr,"RGBE error: %s\n",msg);
-  }
-  return RGBE_RETURN_FAILURE;
-}
-
-/* standard conversion from float pixels to rgbe pixels */
-/* note: you can remove the "inline"s if your compiler complains about it */
-static INLINE void 
-float2rgbe(unsigned char rgbe[4], float red, float green, float blue)
-{
-  float v;
-  int e;
-
-  v = red;
-  if (green > v) v = green;
-  if (blue > v) v = blue;
-  if (v < 1e-32) {
-    rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
-  }
-  else {
-    v = frexp(v,&e) * 256.0/v;
-    rgbe[0] = (unsigned char) (red * v);
-    rgbe[1] = (unsigned char) (green * v);
-    rgbe[2] = (unsigned char) (blue * v);
-    rgbe[3] = (unsigned char) (e + 128);
-  }
-}
-
-/* standard conversion from rgbe to float pixels */
-/* note: Ward uses ldexp(col+0.5,exp-(128+8)).  However we wanted pixels */
-/*       in the range [0,1] to map back into the range [0,1].            */
-static INLINE void 
-rgbe2float(float *red, float *green, float *blue, unsigned char rgbe[4])
-{
-  float f;
-
-  if (rgbe[3]) {   /*nonzero pixel*/
-    f = ldexp(1.0,rgbe[3]-(int)(128+8));
-    *red = rgbe[0] * f;
-    *green = rgbe[1] * f;
-    *blue = rgbe[2] * f;
-  }
-  else
-    *red = *green = *blue = 0.0;
-}
-
-/* default minimal header. modify if you want more information in header */
-int RGBE_WriteHeader(FILE *fp, int width, int height, rgbe_header_info *info)
-{
-  char *programtype = "RGBE";
-
-  if (info && (info->valid & RGBE_VALID_PROGRAMTYPE))
-    programtype = info->programtype;
-  if (fprintf(fp,"#?%s\n",programtype) < 0)
-    return rgbe_error(rgbe_write_error,NULL);
-  /* The #? is to identify file type, the programtype is optional. */
-  if (info && (info->valid & RGBE_VALID_GAMMA)) {
-    if (fprintf(fp,"GAMMA=%g\n",info->gamma) < 0)
-      return rgbe_error(rgbe_write_error,NULL);
-  }
-  if (info && (info->valid & RGBE_VALID_EXPOSURE)) {
-    if (fprintf(fp,"EXPOSURE=%g\n",info->exposure) < 0)
-      return rgbe_error(rgbe_write_error,NULL);
-  }
-  if (fprintf(fp,"FORMAT=32-bit_rle_rgbe\n\n") < 0)
-    return rgbe_error(rgbe_write_error,NULL);
-  if (fprintf(fp, "-Y %d +X %d\n", height, width) < 0)
-    return rgbe_error(rgbe_write_error,NULL);
-  return RGBE_RETURN_SUCCESS;
-}
-
-/* minimal header reading.  modify if you want to parse more information */
-int RGBE_ReadHeader(FILE *fp, int *width, int *height, rgbe_header_info *info)
-{
-  char buf[128];
-  int found_format;
-  float tempf;
-  int i;
-
-  found_format = 0;
-  if (info) {
-    info->valid = 0;
-    info->programtype[0] = 0;
-    info->gamma = info->exposure = 1.0;
-  }
-  if (fgets(buf,sizeof(buf)/sizeof(buf[0]),fp) == NULL)
-    return rgbe_error(rgbe_read_error,NULL);
-  if ((buf[0] != '#')||(buf[1] != '?')) {
-    /* if you want to require the magic token then uncomment the next line */
-    /*return rgbe_error(rgbe_format_error,"bad initial token"); */
-  }
-  else if (info) {
-    info->valid |= RGBE_VALID_PROGRAMTYPE;
-    for(i=0;i<sizeof(info->programtype)-1;i++) {
-      if ((buf[i+2] == 0) || isspace(buf[i+2]))
-	break;
-      info->programtype[i] = buf[i+2];
-    }
-    info->programtype[i] = 0;
-    if (fgets(buf,sizeof(buf)/sizeof(buf[0]),fp) == 0)
-      return rgbe_error(rgbe_read_error,NULL);
-  }
-  for(;;) {
-    if ((buf[0] == 0)||(buf[0] == '\n'))
-      return rgbe_error(rgbe_format_error,"no FORMAT specifier found");
-    else if (strcmp(buf,"FORMAT=32-bit_rle_rgbe\n") == 0)
-      break;       /* format found so break out of loop */
-    else if (info && (sscanf(buf,"GAMMA=%g",&tempf) == 1)) {
-      info->gamma = tempf;
-      info->valid |= RGBE_VALID_GAMMA;
-    }
-    else if (info && (sscanf(buf,"EXPOSURE=%g",&tempf) == 1)) {
-      info->exposure = tempf;
-      info->valid |= RGBE_VALID_EXPOSURE;
-    }
-    if (fgets(buf,sizeof(buf)/sizeof(buf[0]),fp) == 0)
-      return rgbe_error(rgbe_read_error,NULL);
-  }
-  if (fgets(buf,sizeof(buf)/sizeof(buf[0]),fp) == 0)
-    return rgbe_error(rgbe_read_error,NULL);
-  if (strcmp(buf,"\n") != 0)
-    return rgbe_error(rgbe_format_error,
-		      "missing blank line after FORMAT specifier");
-  if (fgets(buf,sizeof(buf)/sizeof(buf[0]),fp) == 0)
-    return rgbe_error(rgbe_read_error,NULL);
-  if (sscanf(buf,"-Y %d +X %d",height,width) < 2)
-    return rgbe_error(rgbe_format_error,"missing image size specifier");
-  return RGBE_RETURN_SUCCESS;
-}
-
-/* simple write routine that does not use run length encoding */
-/* These routines can be made faster by allocating a larger buffer and
-   fread-ing and fwrite-ing the data in larger chunks */
-int RGBE_WritePixels(FILE *fp, float *data, int numpixels)
-{
-  unsigned char rgbe[4];
-
-  while (numpixels-- > 0) {
-    float2rgbe(rgbe,data[RGBE_DATA_RED],
-	       data[RGBE_DATA_GREEN],data[RGBE_DATA_BLUE]);
-    data += RGBE_DATA_SIZE;
-    if (fwrite(rgbe, sizeof(rgbe), 1, fp) < 1)
-      return rgbe_error(rgbe_write_error,NULL);
-  }
-  return RGBE_RETURN_SUCCESS;
-}
-
-/* simple read routine.  will not correctly handle run length encoding */
-int RGBE_ReadPixels(FILE *fp, float *data, int numpixels)
-{
-  unsigned char rgbe[4];
-
-  while(numpixels-- > 0) {
-    if (fread(rgbe, sizeof(rgbe), 1, fp) < 1)
-      return rgbe_error(rgbe_read_error,NULL);
-    rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],
-	       &data[RGBE_DATA_BLUE],rgbe);
-    data += RGBE_DATA_SIZE;
-  }
-  return RGBE_RETURN_SUCCESS;
-}
-
-/* The code below is only needed for the run-length encoded files. */
-/* Run length encoding adds considerable complexity but does */
-/* save some space.  For each scanline, each channel (r,g,b,e) is */
-/* encoded separately for better compression. */
-
-static int RGBE_WriteBytes_RLE(FILE *fp, unsigned char *data, int numbytes)
-{
-#define MINRUNLENGTH 4
-  int cur, beg_run, run_count, old_run_count, nonrun_count;
-  unsigned char buf[2];
-
-  cur = 0;
-  while(cur < numbytes) {
-    beg_run = cur;
-    /* find next run of length at least 4 if one exists */
-    run_count = old_run_count = 0;
-    while((run_count < MINRUNLENGTH) && (beg_run < numbytes)) {
-      beg_run += run_count;
-      old_run_count = run_count;
-      run_count = 1;
-      while( (beg_run + run_count < numbytes) && (run_count < 127)
-             && (data[beg_run] == data[beg_run + run_count]))
-	run_count++;
-    }
-    /* if data before next big run is a short run then write it as such */
-    if ((old_run_count > 1)&&(old_run_count == beg_run - cur)) {
-      buf[0] = 128 + old_run_count;   /*write short run*/
-      buf[1] = data[cur];
-      if (fwrite(buf,sizeof(buf[0])*2,1,fp) < 1)
-	return rgbe_error(rgbe_write_error,NULL);
-      cur = beg_run;
-    }
-    /* write out bytes until we reach the start of the next run */
-    while(cur < beg_run) {
-      nonrun_count = beg_run - cur;
-      if (nonrun_count > 128) 
-	nonrun_count = 128;
-      buf[0] = nonrun_count;
-      if (fwrite(buf,sizeof(buf[0]),1,fp) < 1)
-	return rgbe_error(rgbe_write_error,NULL);
-      if (fwrite(&data[cur],sizeof(data[0])*nonrun_count,1,fp) < 1)
-	return rgbe_error(rgbe_write_error,NULL);
-      cur += nonrun_count;
-    }
-    /* write out next run if one was found */
-    if (run_count >= MINRUNLENGTH) {
-      buf[0] = 128 + run_count;
-      buf[1] = data[beg_run];
-      if (fwrite(buf,sizeof(buf[0])*2,1,fp) < 1)
-	return rgbe_error(rgbe_write_error,NULL);
-      cur += run_count;
-    }
-  }
-  return RGBE_RETURN_SUCCESS;
-#undef MINRUNLENGTH
-}
-
-int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
-			 int num_scanlines)
-{
-  unsigned char rgbe[4];
-  unsigned char *buffer;
-  int i, err;
-
-  if ((scanline_width < 8)||(scanline_width > 0x7fff))
-    /* run length encoding is not allowed so write flat*/
-    return RGBE_WritePixels(fp,data,scanline_width*num_scanlines);
-  buffer = (unsigned char *)malloc(sizeof(unsigned char)*4*scanline_width);
-  if (buffer == NULL) 
-    /* no buffer space so write flat */
-    return RGBE_WritePixels(fp,data,scanline_width*num_scanlines);
-  while(num_scanlines-- > 0) {
-    rgbe[0] = 2;
-    rgbe[1] = 2;
-    rgbe[2] = scanline_width >> 8;
-    rgbe[3] = scanline_width & 0xFF;
-    if (fwrite(rgbe, sizeof(rgbe), 1, fp) < 1) {
-      free(buffer);
-      return rgbe_error(rgbe_write_error,NULL);
-    }
-    for(i=0;i<scanline_width;i++) {
-      float2rgbe(rgbe,data[RGBE_DATA_RED],
-		 data[RGBE_DATA_GREEN],data[RGBE_DATA_BLUE]);
-      buffer[i] = rgbe[0];
-      buffer[i+scanline_width] = rgbe[1];
-      buffer[i+2*scanline_width] = rgbe[2];
-      buffer[i+3*scanline_width] = rgbe[3];
-      data += RGBE_DATA_SIZE;
-    }
-    /* write out each of the four channels separately run length encoded */
-    /* first red, then green, then blue, then exponent */
-    for(i=0;i<4;i++) {
-      if ((err = RGBE_WriteBytes_RLE(fp,&buffer[i*scanline_width],
-				     scanline_width)) != RGBE_RETURN_SUCCESS) {
-	free(buffer);
-	return err;
-      }
-    }
-  }
-  free(buffer);
-  return RGBE_RETURN_SUCCESS;
-}
-      
-int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
-			int num_scanlines)
-{
-  unsigned char rgbe[4], *scanline_buffer, *ptr, *ptr_end;
-  int i, count;
-  unsigned char buf[2];
-
-  if ((scanline_width < 8)||(scanline_width > 0x7fff))
-    /* run length encoding is not allowed so read flat*/
-    return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines);
-  scanline_buffer = NULL;
-  /* read in each successive scanline */
-  while(num_scanlines > 0) {
-    if (fread(rgbe,sizeof(rgbe),1,fp) < 1) {
-      free(scanline_buffer);
-      return rgbe_error(rgbe_read_error,NULL);
-    }
-    if ((rgbe[0] != 2)||(rgbe[1] != 2)||(rgbe[2] & 0x80)) {
-      /* this file is not run length encoded */
-      rgbe2float(&data[0],&data[1],&data[2],rgbe);
-      data += RGBE_DATA_SIZE;
-      free(scanline_buffer);
-      return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines-1);
-    }
-    if ((((int)rgbe[2])<<8 | rgbe[3]) != scanline_width) {
-      free(scanline_buffer);
-      return rgbe_error(rgbe_format_error,"wrong scanline width");
-    }
-    if (scanline_buffer == NULL)
-      scanline_buffer = (unsigned char *)
-	malloc(sizeof(unsigned char)*4*scanline_width);
-    if (scanline_buffer == NULL) 
-      return rgbe_error(rgbe_memory_error,"unable to allocate buffer space");
-    
-    ptr = &scanline_buffer[0];
-    /* read each of the four channels for the scanline into the buffer */
-    for(i=0;i<4;i++) {
-      ptr_end = &scanline_buffer[(i+1)*scanline_width];
-      while(ptr < ptr_end) {
-	if (fread(buf,sizeof(buf[0])*2,1,fp) < 1) {
-	  free(scanline_buffer);
-	  return rgbe_error(rgbe_read_error,NULL);
-	}
-	if (buf[0] > 128) {
-	  /* a run of the same value */
-	  count = buf[0]-128;
-	  if ((count == 0)||(count > ptr_end - ptr)) {
-	    free(scanline_buffer);
-	    return rgbe_error(rgbe_format_error,"bad scanline data");
-	  }
-	  while(count-- > 0)
-	    *ptr++ = buf[1];
-	}
-	else {
-	  /* a non-run */
-	  count = buf[0];
-	  if ((count == 0)||(count > ptr_end - ptr)) {
-	    free(scanline_buffer);
-	    return rgbe_error(rgbe_format_error,"bad scanline data");
-	  }
-	  *ptr++ = buf[1];
-	  if (--count > 0) {
-	    if (fread(ptr,sizeof(*ptr)*count,1,fp) < 1) {
-	      free(scanline_buffer);
-	      return rgbe_error(rgbe_read_error,NULL);
-	    }
-	    ptr += count;
-	  }
-	}
-      }
-    }
-    /* now convert data from buffer into floats */
-    for(i=0;i<scanline_width;i++) {
-      rgbe[0] = scanline_buffer[i];
-      rgbe[1] = scanline_buffer[i+scanline_width];
-      rgbe[2] = scanline_buffer[i+2*scanline_width];
-      rgbe[3] = scanline_buffer[i+3*scanline_width];
-      rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],
-		 &data[RGBE_DATA_BLUE],rgbe);
-      data += RGBE_DATA_SIZE;
-    }
-    num_scanlines--;
-  }
-  free(scanline_buffer);
-  return RGBE_RETURN_SUCCESS;
-}
-

+ 0 - 61
modules/std/graphics/rgbe/rgbe.h

@@ -1,61 +0,0 @@
-#ifndef _H_RGBE
-#define _H_RGBE
-/* THIS CODE CARRIES NO GUARANTEE OF USABILITY OR FITNESS FOR ANY PURPOSE.
- * WHILE THE AUTHORS HAVE TRIED TO ENSURE THE PROGRAM WORKS CORRECTLY,
- * IT IS STRICTLY USE AT YOUR OWN RISK.  */
-
-/* utility for reading and writing Ward's rgbe image format.
-   See rgbe.txt file for more details.
-*/
-
-#include <stdio.h>
-
-#ifdef __cplusplus
-extern "C"{
-#endif
-
-typedef struct {
-  int valid;            /* indicate which fields are valid */
-  char programtype[16]; /* listed at beginning of file to identify it 
-                         * after "#?".  defaults to "RGBE" */ 
-  float gamma;          /* image has already been gamma corrected with 
-                         * given gamma.  defaults to 1.0 (no correction) */
-  float exposure;       /* a value of 1.0 in an image corresponds to
-			 * <exposure> watts/steradian/m^2. 
-			 * defaults to 1.0 */
-} rgbe_header_info;
-
-/* flags indicating which fields in an rgbe_header_info are valid */
-#define RGBE_VALID_PROGRAMTYPE 0x01
-#define RGBE_VALID_GAMMA       0x02
-#define RGBE_VALID_EXPOSURE    0x04
-
-/* return codes for rgbe routines */
-#define RGBE_RETURN_SUCCESS 0
-#define RGBE_RETURN_FAILURE -1
-
-/* read or write headers */
-/* you may set rgbe_header_info to null if you want to */
-int RGBE_WriteHeader(FILE *fp, int width, int height, rgbe_header_info *info);
-int RGBE_ReadHeader(FILE *fp, int *width, int *height, rgbe_header_info *info);
-
-/* read or write pixels */
-/* can read or write pixels in chunks of any size including single pixels*/
-int RGBE_WritePixels(FILE *fp, float *data, int numpixels);
-int RGBE_ReadPixels(FILE *fp, float *data, int numpixels);
-
-/* read or write run length encoded files */
-/* must be called to read or write whole scanlines */
-int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
-			 int num_scanlines);
-int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
-			int num_scanlines);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _H_RGBE */
-
-
-

+ 0 - 61
modules/std/graphics/rgbe/rgbe.txt

@@ -1,61 +0,0 @@
-<HTML>
-The rgbe image file format was invented by Greg Ward to reduce the precision
-problems inherent in normal 24bit file formats.  Many programs including
-photorealistic renderers produce pixels with a wide range of values.  
-Internally the programs usually handle this by representing colors by
-floating point values.  However writing out the floating point values
-directly would produce very large files (~96 bits/pixel).  The rgbe format
-works by having all channels (typically red, green, and blue) share a single
-exponent.  Thus a pixel consists of three 8 bit mantissas and an 8 bit
-exponent for 32 bits per pixel.  This makes for a compact format which
-can handle wide range of pixels values (from 0 to 2^127) with reasonable
-precision.  See "Real Pixels" by Greg Ward in Graphics Gems II for more
-details.
-
-This code was written based on Greg Ward's code (available from the
-radiance home page ftp://radsite.lbl.gov/home.html) for reading and
-writing rgbe files.  I have rewritten the code as ANSI C and tried to
-clean up the code and comment it to make it easier to understand.  I've
-also tried to make the error detection a little more robust.  Here's the
-minimal code for using these files.
-
-sample minimal writing code:
-  f = fopen(image_filename,"wb");
-  RGBE_WriteHeader(f,image_width,image_height,NULL);
-  RGBE_WritePixels(f,image,image_width*image_height);
-  fclose(f);
-For run length encoding instead of RGBE_WritePixels, use 
-RGBE_WritePixels_RLE(f,image,image_width,image_height).
-
-sample minimal reading code:
-  f = fopen(image_filename,"rb");
-  RGBE_ReadHeader(f,&image_width,&image_height,NULL);
-  image = (float *)malloc(sizeof(float)*3*image_width*image_height);
-  RGBE_ReadPixels_RLE(f,image,image_width,image_height);
-  fclose(f);
-You can use RGBE_Read_Pixels instead but it will not handle run length
-encoded file correctly.  For more information see the rgbe.c file.
-(Note: these files are available at http://www.graphics.cornell.edu/~bjw/ )
-
-Please note: By definition of the rgbe format, all pixels should be in 
-units of watts/steradian/meter^2 unless otherwise noted in the header.
-If the header contains an exposure field then dividing pixels values by
-the <exposure value> should result in values in watts/steradian/meter^2.
-See the rgbe.h file for other fields in the header which are supported.
-
-The ReadPixels and WritePixels routines can read/write and entire image, or
-a single pixel, or anything in between.  The run length encoding routines
-can only handle complete scanlines, but can handle single scanlines.  No
-checking is done to see that an image contains the correct number of pixels.
-
-The return codes for routines are defined by RGBE_RETURN_SUCCESS and
-RGBE_RETURN_FAILURE and these can be modified to be compatible with whatever
-error convention you are using.  Error reporting is handled by the rgbe_error
-routine.  You can easily modify this if you want errors to be reported 
-somewhere other than STDERR.
-
-/* THIS CODE CARRIES NO GUARANTEE OF USABILITY OR FITNESS FOR ANY PURPOSE.
- * WHILE THE AUTHORS HAVE TRIED TO ENSURE THE PROGRAM WORKS CORRECTLY,
- * IT IS STRICTLY USE AT YOUR OWN RISK.  */
-</HTML>
-

+ 42 - 0
modules/std/stream/stream.monkey2

@@ -31,6 +31,14 @@ Class Stream Extends std.resource.Resource
 	#end
 	Method Close:Void()
 		
+		If Not _open Return
+		
+		_open-=1
+		
+		If _open Return
+		
+		If _sharedPath _shared.Remove( _sharedPath )
+		
 		OnClose()
 	End
 
@@ -192,6 +200,30 @@ Class Stream Extends std.resource.Resource
 		Return n
 	End
 	
+	Property SharedPath:String()
+		
+		If Not _sharedPath
+			
+			Global sharedId:=0
+			sharedId+=1
+			
+			Local path:="@"+sharedId
+			_sharedPath="stream::"+path
+			_shared[path]=Self
+		Endif
+		
+		Return _sharedPath
+	End
+	
+	#rem monkeydoc Reopens the stream.
+	#end
+	Method Reopen:Stream()
+		
+		_open+=1
+		
+		Return Self
+	End
+	
 	#rem monkeydoc Reads a byte from the stream.
 	
 	@return The byte read.
@@ -564,6 +596,8 @@ Class Stream Extends std.resource.Resource
 		Local proto:=path.Slice( 0,i )
 		Local ipath:=path.Slice( i+2 )
 		
+		If proto="stream" Return _shared[ipath].Reopen()
+		
 		Return OpenFuncs[proto]( proto,ipath,mode )
 	End
 	
@@ -580,6 +614,8 @@ Class Stream Extends std.resource.Resource
 	Method New()
 		
 		_swap=false
+		
+		_open=1
 	End
 	
 	Method OnClose() Virtual
@@ -591,6 +627,12 @@ Class Stream Extends std.resource.Resource
 	
 	Field _swap:Bool
 	
+	Field _open:Int
+	
+	Field _sharedPath:String
+	
+	Global _shared:=New StringMap<Stream>
+	
 	Function Swap2( v:Void Ptr )
 		Local t:=Cast<UShort Ptr>( v )[0]
 		Cast<UShort Ptr>( v )[0]=(t Shr 8 & $ff) | (t & $ff) Shl 8

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 166 - 165
shapes-scene.mojo3d


+ 23 - 19
spotlight-scene.mojo3d

@@ -6,7 +6,10 @@
 			"decl":"mojo3d.Scene.New",
 			"type":"Void(Bool)"
 		},
-		"id":0,
+		"id":"#0",
+		"state":{
+			"ShadowAlpha":0.75
+		},
 		"type":"mojo3d.Scene"
 	},{
 		"ctor":{
@@ -14,18 +17,18 @@
 			"decl":"mojo3d.Camera.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":1,
+		"id":"#1",
 		"state":{
 			"LocalMatrix":[1,0,0,0,1,0,0,0,1,0,2.5,-10]
 		},
 		"type":"mojo3d.Camera"
 	},{
 		"ctor":{
-			"args":["@1"],
+			"args":["#1"],
 			"decl":"mojo3d.FlyBehaviour.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":2,
+		"id":"#2",
 		"type":"mojo3d.FlyBehaviour"
 	},{
 		"ctor":{
@@ -33,13 +36,14 @@
 			"decl":"mojo3d.Light.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":3,
+		"id":"#3",
 		"state":{
 			"CastsShadow":true,
+			"Color":[8,8,8,8],
 			"LocalMatrix":[1,0,0,0,-4.3711388286737929e-08,1,0,-1,-4.3711388286737929e-08,0,10,0],
 			"OuterAngle":45,
-			"Range":25,
-			"Texture":"@4",
+			"Range":15,
+			"Texture":"#4",
 			"Type":3
 		},
 		"type":"mojo3d.Light"
@@ -47,10 +51,10 @@
 		"ctor":{
 			"args":["asset::monkey2-logo.png",12,false],
 			"decl":"mojo3d.Scene.LoadTexture",
-			"inst":"@0",
+			"inst":"#0",
 			"type":"mojo.graphics.Texture(String,mojo.graphics.TextureFlags,Bool)"
 		},
-		"id":4,
+		"id":"#4",
 		"type":"mojo.graphics.Texture"
 	},{
 		"ctor":{
@@ -58,7 +62,7 @@
 			"decl":"mojo3d.PbrMaterial.New",
 			"type":"Void(std.graphics.Color,Float,Float)"
 		},
-		"id":5,
+		"id":"#5",
 		"type":"mojo3d.PbrMaterial"
 	},{
 		"ctor":{
@@ -66,15 +70,15 @@
 			"decl":"mojo3d.Mesh.CreateBox",
 			"type":"mojo3d.Mesh(std.geom.Box<monkey.types.Float>,Int,Int,Int)"
 		},
-		"id":6,
+		"id":"#6",
 		"type":"mojo3d.Mesh"
 	},{
 		"ctor":{
-			"args":["@6","@5",null],
+			"args":["#6","#5",null],
 			"decl":"mojo3d.Model.New",
 			"type":"Void(mojo3d.Mesh,mojo3d.Material,mojo3d.Entity)"
 		},
-		"id":7,
+		"id":"#7",
 		"type":"mojo3d.Model"
 	},{
 		"ctor":{
@@ -82,7 +86,7 @@
 			"decl":"mojo3d.PbrMaterial.New",
 			"type":"Void(std.graphics.Color,Float,Float)"
 		},
-		"id":8,
+		"id":"#8",
 		"type":"mojo3d.PbrMaterial"
 	},{
 		"ctor":{
@@ -90,26 +94,26 @@
 			"decl":"mojo3d.Mesh.CreateTorus",
 			"type":"mojo3d.Mesh(Float,Float,Int,Int)"
 		},
-		"id":9,
+		"id":"#9",
 		"type":"mojo3d.Mesh"
 	},{
 		"ctor":{
-			"args":["@9","@8",null],
+			"args":["#9","#8",null],
 			"decl":"mojo3d.Model.New",
 			"type":"Void(mojo3d.Mesh,mojo3d.Material,mojo3d.Entity)"
 		},
-		"id":10,
+		"id":"#10",
 		"state":{
 			"LocalMatrix":[1,0,0,0,1,0,0,0,1,0,2.5,0]
 		},
 		"type":"mojo3d.Model"
 	},{
 		"ctor":{
-			"args":["@10"],
+			"args":["#10"],
 			"decl":"mojo3d.RotateBehaviour.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":11,
+		"id":"#11",
 		"state":{
 			"Speed":[0.20000000298023224,0.40000000596046448,0.60000002384185791]
 		},

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 143 - 143
sprites-scene.mojo3d


+ 0 - 2
src/mx2cc/mx2cc.monkey2

@@ -24,8 +24,6 @@ Global StartDir:String
 
 'Const TestArgs:="mx2cc makemods"
  
-'Const TestArgs:="mx2cc makeapp src/mx2cc/test.monkey2"
-
 Const TestArgs:="mx2cc geninfo src/mx2cc/test.monkey2"
 'Const TestArgs:="mx2cc geninfo modules/mojo3d/mojo3d.monkey2"
 'Const TestArgs:="mx2cc geninfo src/ted2go/Ted2.monkey2"

+ 23 - 8
src/mx2cc/test.monkey2

@@ -1,12 +1,27 @@
 
-Function Main:Void()
-	
-	Local x:=0
+Global weakRef:WeakRef
+
+Class C
+End
+
+Function Test()
 	
-	If x<10
-		Local t:=100
-	Else
-		Local t:=20
-	Endif
+	weakRef=New WeakRef( New C )
 End
 
+Function Main()
+	
+	Test()
+	
+'	Local tmp:=weakRef.Target
+	
+	Print "weakRef valid="+(weakRef.Target<>Null)
+	
+	GCCollect()
+	GCCollect()
+
+	Print "weakRef valid="+(weakRef.Target<>Null)
+	
+	Print "Hello World"
+	
+End

+ 15 - 15
test-scene.mojo3d

@@ -6,7 +6,7 @@
 			"decl":"mojo3d.Scene.New",
 			"type":"Void(Bool)"
 		},
-		"id":0,
+		"id":"#0",
 		"state":{
 			"AmbientLight":[0.05000000074505806,0.15000000596046448,0.25,0.25],
 			"ClearColor":[0.20000000298023224,0.60000002384185791,1,1],
@@ -20,18 +20,18 @@
 			"decl":"mojo3d.Camera.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":1,
+		"id":"#1",
 		"state":{
 			"LocalMatrix":[1,0,0,0,1,0,0,0,1,0,2.5,-5]
 		},
 		"type":"mojo3d.Camera"
 	},{
 		"ctor":{
-			"args":["@1"],
+			"args":["#1"],
 			"decl":"mojo3d.FlyBehaviour.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":2,
+		"id":"#2",
 		"type":"mojo3d.FlyBehaviour"
 	},{
 		"ctor":{
@@ -39,7 +39,7 @@
 			"decl":"mojo3d.Light.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":3,
+		"id":"#3",
 		"state":{
 			"CastsShadow":true,
 			"LocalMatrix":[0.70710676908493042,0,0.70710676908493042,-0.49999997019767761,0.70710676908493042,0.49999997019767761,-0.49999997019767761,-0.70710676908493042,0.49999997019767761,0,0,0]
@@ -51,7 +51,7 @@
 			"decl":"mojo3d.PbrMaterial.New",
 			"type":"Void(std.graphics.Color,Float,Float)"
 		},
-		"id":4,
+		"id":"#4",
 		"type":"mojo3d.PbrMaterial"
 	},{
 		"ctor":{
@@ -59,15 +59,15 @@
 			"decl":"mojo3d.Mesh.CreateBox",
 			"type":"mojo3d.Mesh(std.geom.Box<monkey.types.Float>,Int,Int,Int)"
 		},
-		"id":5,
+		"id":"#5",
 		"type":"mojo3d.Mesh"
 	},{
 		"ctor":{
-			"args":["@5","@4",null],
+			"args":["#5","#4",null],
 			"decl":"mojo3d.Model.New",
 			"type":"Void(mojo3d.Mesh,mojo3d.Material,mojo3d.Entity)"
 		},
-		"id":6,
+		"id":"#6",
 		"type":"mojo3d.Model"
 	},{
 		"ctor":{
@@ -75,7 +75,7 @@
 			"decl":"mojo3d.PbrMaterial.New",
 			"type":"Void(std.graphics.Color,Float,Float)"
 		},
-		"id":7,
+		"id":"#7",
 		"type":"mojo3d.PbrMaterial"
 	},{
 		"ctor":{
@@ -83,26 +83,26 @@
 			"decl":"mojo3d.Mesh.CreateTorus",
 			"type":"mojo3d.Mesh(Float,Float,Int,Int)"
 		},
-		"id":8,
+		"id":"#8",
 		"type":"mojo3d.Mesh"
 	},{
 		"ctor":{
-			"args":["@8","@7",null],
+			"args":["#8","#7",null],
 			"decl":"mojo3d.Model.New",
 			"type":"Void(mojo3d.Mesh,mojo3d.Material,mojo3d.Entity)"
 		},
-		"id":9,
+		"id":"#9",
 		"state":{
 			"LocalMatrix":[1,0,0,0,1,0,0,0,1,0,2.5,0]
 		},
 		"type":"mojo3d.Model"
 	},{
 		"ctor":{
-			"args":["@9"],
+			"args":["#9"],
 			"decl":"mojo3d.RotateBehaviour.New",
 			"type":"Void(mojo3d.Entity)"
 		},
-		"id":10,
+		"id":"#10",
 		"state":{
 			"Speed":[0.10000000149011612,0.20000000298023224,0.30000001192092896]
 		},

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác