Forum Replies Created
-
AuthorPosts
-
Think you’ve got startswith/endswith mixed up wrt: the ‘*’ filter.
Also, just added a tiny regex module called tinyregex to develop branch if that’s useful. Only one function for now: Function re_match:Int( pattern:CString,text:CString ), returns index of match or -1 for no match.
Just discovered the c++11 std library actually has a regex engine which may or may not be better, but is at least guaranteed to be bigger! I’ll look at implmenting this later if necessary.
Regex’s aren’t quite like yer standard file filters though, think I prefer plain file filters. Maybe * in filter could be replaced with .* or something before being regexed?
Also, can you let me know what you want to do with external storage?
There are a lot of directories and APIS involved and I just wanna know what to concentrate on first.
A version of this has been pushed to the develop branch of github. It will also be included in the v1.1.08 release due in a few days, so you can just wait for that if you want.
Here it is in action, hopefully pretty straightforward:
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )Print "Hello World from permissions demo!"Local permissions:=New String[]("android.permission.INTERNET","android.permission.ACCESS_NETWORK_STATE","android.permission.READ_EXTERNAL_STORAGE","android.permission.WRITE_EXTERNAL_STORAGE","com.android.vending.BILLING" )For Local i:=0 Until permissions.LengthPrint "CheckPermission(~q"+permissions[i]+"~q)="+CheckPermission( permissions[i] )NextRequestPermissions( permissions,Lambda( results:int[] )If Not resultsPrint "RequestPermissions cancelled"ReturnEndifFor Local i:=0 Until results.LengthIf results[i]Print "Permission granted for "+permissions[i]ElsePrint "Permission NOT granted for "+permissions[i]EndifNextEnd )EndMethod OnRender( canvas:Canvas ) OverrideGlobal n:Intn+=1App.RequestRender()canvas.DrawText( "Hello World! n="+n,Width/2,Height/2,.5,.5 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndYou might also want to read up on runtime permissions – was certainly news to me!
https://developer.android.com/training/permissions/requesting.html
You apparently only need to do this if targetSDK is >=23, which it is in the default manifest for monkey2 projects. So one way to avoid all this I guess is to just change targetSDK to 22!
Thanks to CopperCircle for pointing me in the right direction.
‘Self’ is a reference to the ‘current object’ inside methods and properties, much like ‘this’ in c++/java etc. Is this what you mean? You could use it like this:
Monkey123456789101112131415Class ActorGlobal AllActors:=New Stack<Actor>Method CheckCollisions()For Local actor:=Eachin AllActorsIf actor<>Self'Check for collision btween Self and actor.EndIfNextEndEndI’m probably being dim, but I don’t get why you don’t have to multiply by pitch, for the destination address.
Good question!
Like c/c++, monkey2 pointer addition/subtraction takes the size of the data actually pointed to into account. So ‘p+10’ where p is an int ptr will actually add 40 to p, as ints are 4 bytes long. Ditto p[10] will reference the memory at address ‘p+40’ (using [ ] with pointers is just a special type of pointer addition).
However, libc.memcpy doesn’t know anything about types, it just takes void ptrs and a byte size. Monkey2 ‘fixes’ the pointer params, but not the size so you need to premultiply it by pitch.
It might be an idea to add some ‘typed’ memcpys somewhere, eg:
Monkey1234Function t_memcpy:T Ptr( dst:T Ptr,src:T Ptr,count:Int )libc.memcpy( dst,src,count*libc.sizeof<T>() )EndThis way, you dont’t have to premultiply count by pitch, so the SetVertices code is even simpler.
Not currently allowed.
Very nice!
I actually meant the native target MonkeyActivity java class – my version doesn’t have the onPermissionsReply method.
Ditto it’s not supported via the delegate mechanism. It’s easy enough to add, just wondering if I missed a trick somewhere. I hate having to continually mung up the core Activity class each time we find something else that needs to be delegated out. It’s a pretty crappy design on the part of Android IMO.
Ok, just adding a permission module now.
Thanks for the sample code coppercircle. Am I correct in thinking you also has to add the permissions callback to AppDelagate and main Actitiy class?
Fixed in develop branch.
should I make a reproducable example, or is this expected?
Example please, just had a quick look and can’t see anything obviously wrong.
Ok, finally got around to doing something here.
The latest develop branch includes new versions of VertexBuffer and IndexBuffer and a new ‘Renderable’ entity class.
There’s also a ‘morpher.monkey2’ in mojo3d/tests dir that shows you how to create your own renderable entity classes. It’s hopefully quite sensible:
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768Class Morpher Extends Renderable'note: meshes must have same number of vertices and same indices.'Method New( mesh0:Mesh,mesh1:Mesh,material:Material,parent:Entity=null )Super.New( parent )'get mesh vertices - don't need entire meshes'_vertices0=mesh0.GetVertices()_vertices1=mesh1.GetVertices()_material=material'create vertexbuffer'_vbuffer=New VertexBuffer( Vertex3f.Format,_vertices0.Length )'create and initialize indexbuffer'Local indices:=mesh0.GetIndices( 0 )_ibuffer=New IndexBuffer( IndexFormat.UINT32,indices.Length )_ibuffer.SetIndices( indices.Data,0,indices.Length )EndProtectedMethod OnRender( rq:RenderQueue ) overrideLocal alpha:=Sin( Now() )*.5+.5'lock vertex bufferLocal vp:=Cast<Vertex3f Ptr>( _vbuffer.Lock() )For Local i:=0 Until _vbuffer.LengthLocal v:=_vertices0[i]'interpolate positionv.position=_vertices0[i].position.Blend( _vertices1[i].position,alpha )'interpolate normalv.normal=_vertices0[i].normal.Blend( _vertices1[i].normal,alpha ).Normalize()vp[i]=vNext'invalidate all vertices_vbuffer.Invalidate()'unlock vertices_vbuffer.Unlock()'add renderoprq.AddRenderOp( _material,Self,_vbuffer,_ibuffer,3,_ibuffer.Length/3,0 )EndPrivateField _vertices0:Vertex3f[]Field _vertices1:Vertex3f[]Field _material:MaterialField _vbuffer:VertexBufferField _ibuffer:IndexBufferField _nvertices:IntEndBasically, renderers need to implement OnRender() which is passed a ‘RenderQueue’ which you can add render ops to.
A render op is basically a combination of material,instance,vertexbuffer,indexbuffer and draw count etc.
Batching render ops like this allows for multiple render passes if necessary without having to call OnRender multiple times. It also potentially allows for ‘state sorting’ (doesn’t do that yet), better instancing using GL extensions (doesn’t do that yet either), and potentially culling. The render ops are also used to render shadow maps if Renderable.CastsShadow is true.
Renderable is now used by Model, Sprite and ParticleSystem, although there’s a big kludge in there for Sprites.
OnRender is called once per camera, and will probably get a camera param at some point. It would also be possible to have a ‘baked’ renderqueue that was camera independant and didn’t have to be rebuilt all the time.
Note that custom Renderers like this must manage vertex/index buffers themselves (as above), although ‘helper’ classes could easily be added. Renderer is as simple as possible.
I also modified/simplified vertex/index buffers quite a bit. They are now (mostly) statically sized and ‘lockable’. There’s a convience Resize() in there, but they no longer act like mini-stacks, ie: no more AddVertices. Mesh should be pretty much the same though, so as long as you’ve been using tha6t you should be OK. Didn’t have to change meshprims.monkey2 anyway.
Can you post/attach the manifest file here?
Actually, the simplelight banana shows you how to do this…it does a funky rotate/distort of the view and converts mouse coords to ‘local’.
Same idea, just transform the point directly, something like:
Monkey12345canvas.Scale(....)canvas.Rotate(...)canvas.Translate(...)...etc...Local localCoords:= -canvas.Matrix * Mouse.LocationNote the minus sign before canvas.Matrix. This negates the current canvas matrix, so gives you the inverse transform.
-
AuthorPosts