Mark Sibly преди 9 години
родител
ревизия
f1071e4c32

+ 3 - 30
modules/mojo2/graphics.monkey2

@@ -1232,6 +1232,7 @@ Class Font
 	
 	Function LoadTTF:Font( path:String,height:Int,firstChar:Int,numChars:Int )
 	
+		#rem
 		'scale height DPI...
 		Local ddpi:Float,hdpi:Float,vdpi:Float
 		If sdl2.SDL_GetDisplayDPI( 0,Varptr ddpi,Varptr hdpi,Varptr vdpi )=0
@@ -1244,6 +1245,7 @@ Class Font
 			
 '			Print "height0="+height0+", height="+height
 		Endif
+		#end
 		
 		Local data:=DataBuffer.Load( path )
 		If Not data Return Null
@@ -1299,7 +1301,7 @@ Class Font
 	End
 	
 	Function Load:Font( path:String,firstChar:Int,numChars:Int,padded:Bool )
-
+	
 		Local image:=Image.Load( path )
 		If Not image Return Null
 		
@@ -1768,13 +1770,6 @@ Class DrawList
 		Translate( tx,ty )
 		DrawImage( image )
 		PopMatrix()
-		#rem
-		BeginPrim image._material,4
-		PrimVert image._x0 + tx,image._y0 + ty,image._s0,image._t0
-		PrimVert image._x1 + tx,image._y0 + ty,image._s1,image._t0
-		PrimVert image._x1 + tx,image._y1 + ty,image._s1,image._t1
-		PrimVert image._x0 + tx,image._y1 + ty,image._s0,image._t1
-		#end
 	End
 
 	Method DrawImage:Void( image:Image,tx:Float,ty:Float,rz:Float )
@@ -1782,17 +1777,6 @@ Class DrawList
 		TranslateRotate( tx,ty,rz )
 		DrawImage( image )
 		PopMatrix()
-		#rem
-		Local ix:=Cos( rz ),iy:=-Sin( rz )
-		Local jx:=Sin( rz ),jy:= Cos( rz )
-		Local x0:=image._x0,y0:=image._y0
-		Local x1:=image._x1,y1:=image._y1
-		BeginPrim image._material,4
-		PrimVert x0 * ix + y0 * jx + tx,x0 * iy + y0 * jy + ty,image._s0,image._t0
-		PrimVert x1 * ix + y0 * jx + tx,x1 * iy + y0 * jy + ty,image._s1,image._t0
-		PrimVert x1 * ix + y1 * jx + tx,x1 * iy + y1 * jy + ty,image._s1,image._t1
-		PrimVert x0 * ix + y1 * jx + tx,x0 * iy + y1 * jy + ty,image._s0,image._t1
-		#end
 	End
 	
 	Method DrawImage:Void( image:Image,tx:Float,ty:Float,rz:Float,sx:Float,sy:Float )
@@ -1800,17 +1784,6 @@ Class DrawList
 		TranslateRotateScale( tx,ty,rz,sx,sy )
 		DrawImage( image )
 		PopMatrix()
-		#rem		
-		Local ix:=Cos( rz ),iy:=-Sin( rz )
-		Local jx:=Sin( rz ),jy:= Cos( rz )
-		Local x0:=image._x0 * sx,y0:=image._y0 * sy
-		Local x1:=image._x1 * sx,y1:=image._y1 * sy
-		BeginPrim image._material,4
-		PrimVert x0 * ix + y0 * jx + tx,x0 * iy + y0 * jy + ty,image._s0,image._t0
-		PrimVert x1 * ix + y0 * jx + tx,x1 * iy + y0 * jy + ty,image._s1,image._t0
-		PrimVert x1 * ix + y1 * jx + tx,x1 * iy + y1 * jy + ty,image._s1,image._t1
-		PrimVert x0 * ix + y1 * jx + tx,x0 * iy + y1 * jy + ty,image._s0,image._t1
-		#end
 	End
 	
 	Method DrawText:Void( text:String,x:Float,y:Float,xhandle:Float=0,yhandle:Float=0 )

+ 1 - 1
modules/monkey/debug.monkey2

@@ -20,7 +20,7 @@ Function Assert( condition:Bool,message:String )="bbAssert"
 
 #rem monkeydoc Generates a runtime error if a boolean expression is false (Debug builds only).
 
-This function does not execute at all in release builds, so make sure that @condition doesn't inadvertantly execute
+This function does not execute at all in release builds, so make sure that `condition` doesn't inadvertantly execute
 any critical code.
 
 @param condition The boolean condition to check.

+ 1 - 1
modules/monkey/gc.monkey2

@@ -3,4 +3,4 @@ Namespace monkey.gc
 
 Extern
 
-Function Collect:Void()="bbGC::collect"
+Function GCCollect:Void()="bbGC::collect"

+ 1 - 0
modules/monkey/monkey.monkey2

@@ -4,6 +4,7 @@ Namespace monkey
 #Import "types.monkey2"
 #Import "math.monkey2"
 #Import "debug.monkey2"
+#Import "gc.monkey2"
 
 #Import "native/bbtypes.cpp"
 #Import "native/bbmemory.cpp"

+ 0 - 189
modules/monkey/native/bbarray.h

@@ -171,193 +171,4 @@ template<class T,int D> class bbArray : public bbGCNode{
 	}
 };
 
-// ***** OLD *****
-
-/*
-template<class T,int D=1> class bbArray{
-
-	struct Rep : public bbGCNode{
-
-		int _sizes[D];
-		T _data[0];
-		
-		Rep(){
-			memset( _sizes,0,sizeof(_sizes) );
-		}
-		
-		Rep( int sizes[] ){
-			bbGC::beginCtor( this );
-			
-			memcpy( _sizes,sizes,D*sizeof(int) );
-			
-			for( int i=0;i<_sizes[D-1];++i ) new( &_data[i] ) T();
-		}
-		
-		~Rep(){
-			for( int i=0;i<_sizes[D-1];++i ) _data[i].~T();
-		}
-		
-		virtual void gcMark(){
-			for( int i=0;i<_sizes[D-1];++i ) bbGCMark( _data[i] );	
-		}
-		
-		const char *typeName(){
-			return "bbArray";
-		}
-		
-	};
-	
-	Rep *_rep=nullptr;
-	
-	friend void bbGCMark( bbArray &t ){
-
-		bbGC::enqueue( t._rep );
-	}
-	
-	void enqueue(){
-	
-#if BBGC_INCREMENTAL
-		bbGC::enqueue( _rep );
-#endif
-	}
-
-	public:
-	
-	bbArray(){
-	}
-	
-	bbArray( const bbArray &p ):_rep( p._rep ){
-
-		enqueue();
-	}
-	
-	template<class...Args> bbArray( Args...args ){
-	
-		int sizes[]{ args... };
-		for( int i=1;i<D;++i ) sizes[i]*=sizes[i-1];
-		
-		if( !sizes[D-1] ) return;
-		
-		bbGCNode *p=bbGC::alloc( sizeof( Rep )+sizes[D-1]*sizeof(T) );
-		
-		_rep=new( p ) Rep( sizes );
-		
-		bbGC::endCtor( _rep );
-	}
-	
-	template<class C,class...Args> bbArray( const C *init,Args...args ){
-	
-		int sizes[]{ args... };
-		for( int i=1;i<D;++i ) sizes[i]*=sizes[i-1];
-		
-		if( !sizes[D-1] ) return;
-		
-		bbGCNode *p=bbGC::alloc( sizeof( Rep )+sizes[D-1]*sizeof(T) );
-		
-		_rep=new( p ) Rep( sizes );
-		
-		for( int i=0;i<sizes[D-1];++i ) _rep->_data[i]=*init++;
-		
-		bbGC::endCtor( _rep );
-	}
-	
-	template<class C,class...Args> bbArray( std::initializer_list<C> init,Args...args ){
-	
-		int sizes[]{ args... };
-		for( int i=1;i<D;++i ) sizes[i]*=sizes[i-1];
-		
-		if( !sizes[D-1] ) return;
-		
-		bbGCNode *p=bbGC::alloc( sizeof( Rep )+sizes[D-1]*sizeof(T) );
-		
-		_rep=new( p ) Rep( sizes );
-		
-		int i=0;
-		for( auto it=init.begin();it!=init.end();++it ) _rep->_data[i++]=*it;
-		
-		bbGC::endCtor( _rep );
-	}
-	
-	bbArray &operator=( const bbArray &p ){
-		_rep=p._rep;
-		
-		enqueue();
-		
-		return *this;
-	}
-	
-	T *data(){
-		return _rep->_data;
-	}
-	
-	const T *data()const{
-		return _rep->_data;
-	}
-	
-	int length()const{
-		return _rep ? _rep->_sizes[D-1] : 0;
-	}
-	
-	int size( int q )const{
-		return _rep ? (q ? _rep->_sizes[q]/_rep->_sizes[q-1] : _rep->_sizes[0]) : 0;
-	}
-	
-	bbArray<T,1> slice( int from )const{
-		return slice( from,length() );
-	}
-	
-	bbArray<T,1> slice( int from,int term )const{
-		int length=this->length();
-		if( from<0 ){
-			from+=length;
-			if( from<0 ) from=0;
-		}else if( from>length ){
-			from=length;
-		}
-		if( term<0 ){
-			term+=length;
-			if( term<from ) term=from;
-		}else if( term<from ){
-			term=from;
-		}else if( term>length ){
-			term=length;
-		}
-		int newlen=term-from;
-		bbArray<T,1> p( newlen );
-		for( int i=0;i<newlen;++i ) p.data()[i]=data()[from+i];
-		return p;
-	}
-
-	T &operator[]( int index ){
-		bbDebugAssert( index>=0 && index<length(),"Array index out of range" );
-		return data()[index];
-	}
-	
-	const T &operator[]( int index )const{
-		bbDebugAssert( index>=0 && index<length(),"Array index out of range" );
-		return data()[index];
-	}
-	
-	template <class...Args> T &at( Args...args ){
-		int indices[]{args...};
-		int index=indices[0];
-		for( int i=1;i<D;++i ){
-			if( index>=_rep->_sizes[i-1] ) puts( "Out of range!" );
-			index+=indices[i]*_rep->_sizes[i-1];
-		}
-		if( index>=length() ) puts( "Out of range" );
-		return data()[index];
-	}
-	
-	T &get( int index ){
-		if( index<0 || index>=length() ) puts( "Out of range" );
-		return data()[index];
-	}
-	
-	operator bool()const{
-		return length();
-	}
-};
-*/
-
 #endif

+ 1 - 1
modules/monkey/native/bbgc.cpp

@@ -242,6 +242,6 @@ namespace bbGC{
 
 		reclaim();
 		
-		printf( "GCCollect: in use=%i\n",(int)unmarkedBytes );fflush( stdout );
+//		printf( "GCCollect: in use=%i\n",(int)unmarkedBytes );fflush( stdout );
 	}
 }

+ 16 - 8
modules/monkey/native/bbmemory.cpp

@@ -5,6 +5,8 @@
 
 static size_t malloced;
 
+static size_t max_malloced;
+
 static void *pools[256>>3];
 
 void *bbMalloc( size_t size ){
@@ -14,6 +16,7 @@ void *bbMalloc( size_t size ){
 	size=(size+7)&~7;
 	
 	size_t *p;
+	
 /*	
 	if( size<256 && pools[size>>3] ){
 		p=(size_t*)pools[size>>3];
@@ -23,15 +26,20 @@ void *bbMalloc( size_t size ){
 	}
 */
 	p=(size_t*)malloc( size );
+
+	malloced+=size;
 	
 	memset( p,0,size );
 	
 	*p=size;
-
-	malloced+=size;
 	
-//	printf( "Malloced:%p, size=%i, total=%i\n",p,size,malloced );
-//	fflush( stdout );
+	/*
+	if( malloced>max_malloced ){
+		max_malloced=malloced;
+		printf( "Max malloced:%ul\n",max_malloced );
+		fflush( stdout );
+	}
+	*/
 
 	return p+1;
 }
@@ -48,7 +56,9 @@ void bbFree( void *q ){
 	
 	size_t size=*p;
 	
-	//free( p );
+	free( p );
+	
+	malloced-=size;
 	
 	/*
 	if( size<256 ){
@@ -59,8 +69,6 @@ void bbFree( void *q ){
 	}
 	*/
 	
-	malloced-=size;
-	
 //	printf( "Freed:%p, size=%i, total=%i\n",p,size,malloced );
-//	fflush( stdout );
+	//fflush( stdout );
 }

+ 23 - 17
modules/std/collections/map.monkey2

@@ -2,7 +2,9 @@
 Namespace std.collections
 
 Alias IntMap<V>:Map<Int,V>
+
 Alias FloatMap<V>:Map<Float,V>
+
 Alias StringMap<V>:Map<String,V>
 
 #rem monkeydoc The Map class.
@@ -91,10 +93,10 @@ Class Map<K,V>
 		End
 		
 		Method Copy:Node( parent:Node )
-			Local t:=New Node( _key,_value,_color,_parent )
-			If _left t._left=_left.Copy( t )
-			If _right t._right=_right.Copy( t )
-			Return t
+			Local node:=New Node( _key,_value,_color,parent )
+			If _left node._left=_left.Copy( node )
+			If _right node._right=_right.Copy( node )
+			Return node
 		End
 	
 	End
@@ -238,6 +240,17 @@ Class Map<K,V>
 		Return New MapValues( Self )
 	End
 	
+	#rem monkeydocs Copies the map.
+	
+	@return A new map.
+	
+	#end
+	Method Copy:Map()
+		Local root:Node
+		If _root root=_root.Copy( Null )
+		Return New Map( root )
+	End
+	
 	#rem monkeydoc Removes all keys from the map.
 	#end
 	Method Clear()
@@ -440,6 +453,12 @@ Class Map<K,V>
 	
 	Private
 	
+	Field _root:Node
+	
+	Method New( root:Node )
+		_root=root
+	End
+	
 	Method FirstNode:Node()
 		If Not _root Return Null
 
@@ -516,8 +535,6 @@ Class Map<K,V>
 		Endif
 	End
 	
-	Field _root:Node
-	
 	Method RotateLeft( node:Node )
 		Local child:=node._right
 		node._right=child._left
@@ -662,14 +679,3 @@ Class Map<K,V>
 	End
 	
 End
-
-#rem
-Class IntMap<T> Extends Map<Int,T>
-End
-
-Class FloatMap<T> Extends Map<Float,T>
-End
-
-Class StringMap<T> Extends Map<String,T>
-End
-#end

+ 6 - 0
modules/std/geom/axis.monkey2

@@ -0,0 +1,6 @@
+
+Namespace std.geom
+
+Enum Axis
+	X=0,Y=1,Z=2,W=3
+End

+ 3 - 0
modules/std/geom/rect.monkey2

@@ -9,6 +9,9 @@ Struct Rect<T>
 	Field min:Vec2<T>
 	Field max:Vec2<T>
 	
+	Method New()
+	End
+	
 	Method New( min:Vec2<T>,max:Vec2<T> )
 		Self.min=min
 		Self.max=max

+ 1 - 0
modules/std/geom/vec2.monkey2

@@ -1,6 +1,7 @@
 
 Namespace std.geom
 
+Alias Vec2i:Vec2<Int>
 Alias Vec2f:Vec2<Float>
 
 Struct Vec2<T>

+ 9 - 1
modules/std/misc/native/filesystem.cpp

@@ -130,7 +130,15 @@ namespace bbFileSystem{
 		
 #elif __APPLE__
 
-		return copyfile( bbTString( srcPath ),bbTString( dstPath ),0,COPYFILE_DATA )>=0;
+		int ret=copyfile( bbTString( srcPath ),bbTString( dstPath ),0,COPYFILE_ALL );
+		
+		if( ret>=0 ) return true;
+		
+//		printf( "copyfile failed, ret=%i\n",ret );
+//		printf( "src=%s\n",srcPath.c_str() );
+//		printf( "dst=%s\n",dstPath.c_str() );
+
+		return false;
 	
 #else
 		//TODO: use sendfile() here?

+ 1 - 0
modules/std/std.monkey2

@@ -24,6 +24,7 @@ Namespace std
 #Import "geom/affinemat3.monkey2"
 '#Import "geom/affinemat4.monkey2"
 #Import "geom/rect.monkey2"
+#Import "geom/axis.monkey2"
 
 #Import "graphics/pixelformat.monkey2"
 #Import "graphics/pixmap.monkey2"