Diddy (part 4)
Monkey Forums/Monkey Programming/Diddy (part 4)
| ||
Thread continued from here... From the original post by therevills: [Diddy is] an open-source code base which adds extra functions to Monkey. http://code.google.com/p/diddy/ Diddy features: APIs: Collections (ArrayList, etc.); Tweening; Screen-Based Framework; Sprites / Particles; GUI (Buttons, Sliders, Windows); Serialization; XML reader/writer; Base64 encoding/decoding; Tile Engine (Using the Tiled Map Editor). Commands: RealMillisecs(); FlushKeys(); HideMouse() - GLFW, HTML5 and Flash; ShowMouse() - GLFW, HTML5 and Flash; GetUpdateRate(); SetMouse(x, y) - GLFW; ShowKeyboard() - Android (WIP); LaunchBrowser(address) - HTML5, Flash, Android and GLFW(Windows); LaunchEmail(email, subject, text) - HTML5, Flash, Android and GLFW(Windows); SetGraphics(w, h) - HTML5 and GLFW; RealMod(value, amount); StartVibrate(millisecs) - Android; StopVibrate() - Android ... with more being added all the time! The last few comments in the previous thread relate to the addition of aspect ratio correction, ArrayList/enumeration and asserts. |
| ||
Part 4, cor! :D This thing is gonna have more sequels then the Friday the 13th movies! :D Dabz |
| ||
So, is a for eachin with ArrayList of particles is squeezing the GC? On the Assert side, it is better the way it is now! Especially with JungleIDE's autocomplete at hand. I like AssertError on empty New(). |
| ||
@TheRedFox: So, is a for eachin with ArrayList of particles is squeezing the GC? When you use EachIn, it instantiates a new ArrayListEnumerator. Creating an object won't always instantly kick off the GC though. It's harder than it sounds to get the GC to fire from simple things. If you're instantiating hundreds of objects per frame, I would expect the GC to go nuts. If it's only one or two objects, it might not fire until it reaches a threshold. I'd have to read more about the Dalvik GC to fully answer your question. @TheRedFox: I like AssertError on empty New(). Yeah but we shouldn't have to do that anyway.... :) |
| ||
As I am using the iOS target, I think I'll have to profile to make my mind. Monkey is interesting in that respect because we can study a lot of things of various target platforms and learn an awesome lot. Question: where is the help for this board markup code? Can't find it. |
| ||
Question: where is the help for this board markup code? Can't find it. Have a look here: http://www.blitzbasic.com/faq/faq_entry.php?id=2 The Monkey forum software is the same as the Blitz's site... |
| ||
Question: where is the help for this board markup code? Can't find it. Question: where is the preview button? ;) |
| ||
Question: Where is the toilets.... I'm busting! :D Dabz |
| ||
Any chance of LaunchBrowser being implemented for iOS? |
| ||
LaunchBrowser is already implemented for iOS...class diddy { public: .. static void launchBrowser(String address) { NSString *NSstrURL = address.ToNSString(); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSstrURL]]; } |
| ||
Ah cool. It wasn't listed on your google page that's all: http://code.google.com/p/diddy/wiki/NewCommands |
| ||
@siread, yeah I really need to keep updating that page... you can see all the new native files by looking here: http://code.google.com/p/diddy/source/browse/trunk/src/diddy/functions.monkey The ones in the Extern are the new native commands (of course not all work in all targets). [Edit - BTW it is on that page!?] LOL - Merry Christmas from Diddy - Nice icon Samah! |
| ||
I was wondering how long it would take you to notice the change in your signature. :) If only it didn't show up as a new revision in SVN... |
| ||
Just added an array utility module similar to the Java Arrays class. You can slice/join/copy/fill arrays using Monkey's new generic system. Arrays<Int>.Join([1,2,3], [4,5])Returns Int[] of [1,2,3,4,5]. Arrays<String>.Fill(["a","b","c"], "d")Fills the passed array with "d" and returns a self reference for chaining. Arrays<Int>.Slice([1,2,3,4,5], 1, 3)Accepts start of 1 and length of 3, then returns a new Int[] containing [2,3,4]. Arrays<Float>.Copy([1.0,2.5,3.1])Returns a new Float[] with the same contents as the argument. |
| ||
Hey guys, I'm new to Monkey and I'm trying to compile a couple of the examples to Android, but I'm getting a couple errors: Any idea how to fix this? |
| ||
Hey Paul, You need to update to the latest version v331, the only fix was for this issue so you can just replace your diddy.android.java file with this one: http://diddy.googlecode.com/svn-history/r331/trunk/src/diddy/native/diddy.android.java Mark changed the internals of Android Monkey on us ;) |
| ||
Cool, thanks! |
| ||
hows progress on adding atlas's to diddy ? |
| ||
hows progress on adding atlas's to diddy ? We are both pretty busy with our own projects at the moment, but it will get added sooner or later. |
| ||
Hi therevills. Which bitmap fontgenerator format uses diddy? I tried several generators, but all of them had a different xml format? |
| ||
hmmmmmm.... I've actually forgotten, Samah did tell me - hes the one who coded it... Samah? |
| ||
Yeah it's a custom one I wrote... I'll have to see if I can find it. If not, it's not too hard to rewrite. Edit: Okay, I found it. I never bothered to write a GUI for it, so for now you'll have to just add as many writeFont() lines as you need. At some stage I'll write one. :) http://code.google.com/p/diddy/source/browse/trunk/utils/fontbuilder/FontBuilder.java |
| ||
Many thanks. I will take a look at it. |
| ||
Have a small sound issue. I gave my player class a field, ShootSound:GameSound On new player I then do the game.sound.Find("shot1") and then when I want to play it I do Player.ShootSound.Play() but in chrome , I am getting no sound at all, or in firefox. any ideas? |
| ||
html5 will run just not play anything. xna will boot then die with no errors, glfw is the same. flash gives me this. Error loading sound sounds/shot1.mp3 Monkey runtime error: Error loading sound sounds/shot1.mp3 E:/Code/MonkeyPro/modules/diddy/assert.monkey<106> E:/Code/MonkeyPro/modules/diddy/assert.monkey<20> E:/Code/MonkeyPro/modules/diddy/functions.monkey<180> E:/Code/MonkeyPro/modules/diddy/framework.monkey<912> E:/Code/MonkeyPro/modules/diddy/framework.monkey<876> E:/Source/Monkey/Invaders/iTerm.monkey<151> E:/Source/Monkey/Invaders/iTerm.monkey<93> E:/Code/MonkeyPro/modules/mojo/app.monkey<53> The example in the diddy folder for sound works, so I'm a little confused here. |
| ||
I just switched from didy sound to normal loadsound and playsound and its now telling me AudioError1 WTF!. |
| ||
The good ol' HTML5 sound issues - please read the Monkey doco: Note that not all targets have equivalent audio capabilities. In particular: HTML5 : ChannelPan and ChannelRate do nothing. Flash : ChannelRate does nothing. ChannelState and MusicState always returns -1, ie: 'unknown'. Android : ChannelState always returns -1, ie: 'unknown'. Sounds to be used with PlaySound must be less than 1MB in length. Longer sounds can be played using the music commands. Also, not all audio formats are supported by all targets: wav : glfw, android, ios, xna (sounds) mp3 : flash, android, ios, xna (music) m4a : flash, android (music), ios wma : xna (music) ogg : android And from the example for sounds: #If TARGET="glfw" ' 'GLFW supports WAV only ' soundFmt="wav" musicFmt="wav" ' #Elseif TARGET="html5" ' 'HTML5 supports WAV, OGG, MP3, M4A. However... ' 'IE wont play WAV/OGG 'FF wont play MP3/M4A ' 'So this wont work on IE... ' soundFmt="wav" musicFmt="ogg" ' #Elseif TARGET="flash" ' 'Flash supports MP3, M4A online, but only MP3 embedded. ' soundFmt="mp3" musicFmt="mp3" ' #Elseif TARGET="android" ' 'Android supports WAV, OGG, MP3, M4A ' soundFmt="wav" musicFmt="ogg" ' #Elseif TARGET="xna" ' 'XNA supports WAV, MP3, WMA ' soundFmt="wav" musicFmt="wma" ' #Elseif TARGET="ios" ' 'iOS supports WAV, MP3, M4A, CAF, AIFF ' soundFmt="wav" musicFmt="m4a" ' #End |
| ||
Now that Mark has given us String.FromChars, I've added a "StringBuilder" class that will let you manipulate strings without creating a lot of intermediate objects. Instead, it uses a dynamically resizing array of ints. Instead of: Local str:String str += "foo" str += "bar" str += somevariable str += somethingelse You can now do: Local sb:StringBuilder = New StringBuilder sb.Append("foo") sb.Append("bar") sb.Append(somevariable) sb.Append(somethingelse) Local str:String = sb.ToString() The beauty is that every operation returns itself, so you can chain up commands like so: Local sb:StringBuilder = New StringBuilder sb.Append("foo").Append("bar").Append(somevariable).Append(somethingelse) Local str:String = sb.ToString() It has methods to append, replace, insert, delete, find, and substring. If you have any problems with it, please raise an issue on the Google Code project. |
| ||
This is beautiful. |
| ||
You might want to update the zip file at the downloads section. The source in diddy-r325.zip doesn't compile for Android with Monkeyv54, the source taken from the SVN does though :) |
| ||
http://code.google.com/p/diddy/wiki/HowToInstall To download the latest source (as the zip files will almost always be out of date) ;) But, yeah, its been awhile since the zip was updated and Samah has added/fixed a few things, so I'll quickly put one together :) |
| ||
@therevills - Here is the simpleGUI.monkey module based on r325 that adds an parameter to simpleMenu to change the orientation of the menu from vertical to horizontal. The implementation is not quite right IMO, because the original design did not anticipate a horizontal menu. However it does work for my purposes. Please consider adding this capability to the next official release, here is my version of simpleGUI.monkey: |
| ||
Cool! Just added it now :) Yeah the design isnt perfect... I just quickly create the menu, add the buttons and then move the buttons around via the MoveBy or MoveTo methods, because I'm lazy :P |
| ||
We really need more access to the damn doc's so we can add stuff like this to them.. |
| ||
I'm working on networking (as I need it for a game I'm creating); any chance you can add that to Diddy? It seems a gaping hole from Monkey anyway... Also; the tile demo is not smooth; only when I put FPS high (over 300) it starts to look smooth; below that you can see the edges being drawn and the entire tile surface being jerky. I have an i7 2.66 ghz and I tested under GLFW + HTML5. Is that normal? I'm making a platformer with multiplayer (hence the networking) and I noticed this so I thought I was doing something wrong, but the Diddy tile demo has the same issue. And this is when nothing is moving on the screen yet; the idea is to have many moving enemies, so i'm a bit concerned that an under utilized i7 with 16 gb and a modern GPU would be more jerky scrolling than my 20 year old Amiga 500 here :) |
| ||
We really need more access to the damn doc's Which docs? I'm working on networking ... any chance you can add that to Diddy? Theres already MNet, check there is you need help - I actually "hate" networking a lot of it seems like black magic to me ;) It seems a gaping hole from Monkey anyway... I agree. Also; the tile demo is not smooth It's pretty smooth on my machine... are you running in debug mode? |
| ||
@therevills - Thanks for adding the feature to simpleMenu, I agree the MoveBy or MoveTo methods are the shortcut, didn't see that until I got to the very last step of addding the code :) Cheers! |
| ||
@therevills, @Taiphoz - I think maybe the elusive "docs" could be the wiki associated with the google code project? For example: http://code.google.com/p/diddy/wiki/VirtualResolution looks like if you log in you can add comments to the wiki? Do the comments get added straight away, or do they have to be approved by the "Diddy Master"? |
| ||
@therevills - While I am in diddy thread, I am curious if there is some sort of bug in the sound playing associated with simpleMenu/simpleButton? These are the only sounds I have in my app, and on an Android device I suddenly get random "cannot play sound" error and the app locks up! I also remember hearing a similar thing from Aman (I think) over on the blackberry thread when he said his app was rejected because it wasn't playing the sound (that could have been another issue). Anything special about how sound is played through the simpleButton implementation? |
| ||
Re: The wiki It looks like non-members can only add comments not alter pages, its not an open-wiki like wikipedia. If you guys want to alter the wiki pages, we can add you as Project committers or Project contributors. Re: Sounds The sounds for SimpleButton uses the same framework in the main Diddy system. Do you get any sounds with Android? And you do know that sound is one of the major issues with Monkey itself and certain targets only support certain sound types? |
| ||
Hey, therevills! I noticed that the date classes only work for Android and HTML5 - here are some additions: Flash: import Date; ... static public function getDayOfMonth():int { var d:Date = new Date(); return d.getDate(); } static public function getDayOfWeek():int { var d:Date = new Date(); return d.getDay(); } static public function getMonth():int { var d:Date = new Date(); return d.getMonth(); } static public function getYear():int { var d:Date = new Date(); return d.getFullYear(); } static public function getHours():int { var d:Date = new Date(); return d.getHours(); } static public function getMinutes():int { var d:Date = new Date(); return d.getMinutes(); } static public function getSeconds():int { var d:Date = new Date(); return d.getSeconds(); } static public function getMilliSeconds():int { var d:Date = new Date(); return d.getMilliseconds(); } GLFW Windows: static int getDayOfMonth() { SYSTEMTIME st; GetSystemTime(&st); return st.wDay; } static int getDayOfWeek() { SYSTEMTIME st; GetSystemTime(&st); return st.wDayOfWeek; } static int getMonth() { SYSTEMTIME st; GetSystemTime(&st); return st.wMonth; } static int getYear() { SYSTEMTIME st; GetSystemTime(&st); return st.wYear; } static int getHours() { SYSTEMTIME st; GetSystemTime(&st); return st.wHour; } static int getMinutes() { SYSTEMTIME st; GetSystemTime(&st); return st.wMinute; } static int getSeconds() { SYSTEMTIME st; GetSystemTime(&st); return st.wSecond; } static int getMilliSeconds() { SYSTEMTIME st; GetSystemTime(&st); return st.wMilliseconds; } XNA: public static int getDayOfMonth() { DateTime d = DateTime.Now; return d.Day; } public static int getDayOfWeek() { DateTime d = DateTime.Now; return (int)(d.DayOfWeek); } public static int getMonth() { DateTime d = DateTime.Now; return d.Month; } public static int getYear() { DateTime d = DateTime.Now; return d.Year; } public static int getHours() { DateTime d = DateTime.Now; return d.Hour; } public static int getMinutes() { DateTime d = DateTime.Now; return d.Minute; } public static int getSeconds() { DateTime d = DateTime.Now; return d.Second; } public static int getMilliSeconds() { DateTime d = DateTime.Now; return d.Millisecond; } |
| ||
@therevills - It would be nice to alter the wiki, that beats keeping all notes to myself, I vote you open it up and see how it goes, how do we get setup as a Project committer or contributor? I did get sound on several Android devices, had the compiler directive to use ogg format as the preferred Android sound type. What do you mean when you say, "sound is one of the major issues with Monkey itself and certain targets only"? I know that certain targets support certain types, but does it go deeper than that? So maybe there is some issue with the sound handling in the main Diddy framework? I can't reproduce the problem consistently, but it was one of those "Blue Screen of Death" moments albeit on an Android device, when a message came up "cannot play soundfile" and then the device was trashed for a while, maybe until GC kicked in? But regardless, the app was locked and did not respond after that. I will see if I can reproduce it consistently to narrow down the possible sources, but curious about your comment "sound is one of the major issues with Monkey". Cheers! |
| ||
@Karja - thanks, I've be meaning to add these :_ @Andy - yeah thats what I meant with the sounds, only certain targets support certain types. Thats strange with the "cannot play soundfile", I havent seen that one and I've got a couple of apps on the market and havent received any issues like that from over 19k installs. To get added to the project we need your email address which is linked to an existing Google Account. |
| ||
Hi, I am trying to compile reflection and Diddy together and it is causing problems. I tried fixing it myself, but I am very new to Monkey and Diddy, and I am not sure whether my fix are correct. Using: diddy_r339 MonkeyPro56b The code to test is Import mojo Import reflection Import diddy Function Main:Int() End Problems: 1. File: arrays.monkey Line: 115 111 Function Slice:T[](arr:T[], startIndex:Int, endIndex:Int) 112 Local length:Int = endIndex-startIndex 113 Local rv:T[] = New T[length] 114 For Local i:Int = 0 Until length 115 rv[i] = arr[start+i] 116 Next 117 Return rv 118 End Should the variable start be startIndex? 2. File: collections.monkey Line: 606 604 ' Overrides IList 605 Method RemoveFirst:E() 606 Return Remove(0) 607 End Should Remove be RemoveAt? 3. File: serialization.monkey Line: 67, 77, 87, 112 Added "Return 0" or "Return Null" Thanks. |
| ||
Ah yet another victim of the "compile error doesn't show up until it's used". I believe those fixes are correct. I'll fix and check in later today. Edit: Done. Be aware that I'm going to be completely rewriting that serialization module now that we have reflection. |
| ||
Ah yet another victim of the "Samah doesnt test all his code before check in". FTFY ;) |
| ||
FTFY ;) Go make me a decent unit testing framework then. ;) Also it must be almost time for a part 5... |
| ||
Thanks for looking into it Samah. |
| ||
Do you keep a todo list somewhere of things that would be desired in Diddy, or things that need to be looked into? I'm pretty focused on just making my game work, but there might be some overlap in functionality that could be useful in Diddy too. Things that might be on my radar in the future include: * Investigating why reloading assets won't work when switching between fullscreen/windowed in GLFW - However, I'm considering skipping this and aiming for a new target instead * Breathe some life into the BlitzMax target, or possibly make a LWJGL/other target - Proper Windows and Mac support is my prime reason. GLFW and XNA is "meh" * Maybe look into render to texture on Android/Windows/Mac/(iOS) But there might be other things you're considering that I've overlooked. It'd be nice to pitch in if it fits with my plans. |
| ||
* Breathe some life into the BlitzMax target, or possibly make a LWJGL/other target I made a (mostly) working libGDX target to compare Android performance vs Mark's. Turns out they were about the same, so I put it on hold. |
| ||
Hi everyone :) I wonder, how to retrieve collisions with tiles or graphics when we use Diddy's code to load a map ? |
| ||
re wiki - @therevills add me as contributor pls, philippeback@... will do for email. |
| ||
@DarkyCrystal - its been awhile since I have used Tiled, but I think you would need to code this yourself at the moment. @TheRedFox - Added, let me know if you have any issues :) |
| ||
Rewrote the XML parser from scratch, performance improved like 100-fold or something. A couple of minor gotchas to fix on it, but feel free to give it a shot. |
| ||
Great job, Samah! The old parser parsed the hero xml for Spriter in around 12 seconds, now it does it in 13 millisecs!!!!! |
| ||
:D If only all my code were that fast... orz |
| ||
Nice! As I've been programming a bit in Pharo/Smalltalk lately, it would be interesting to have things like collect:, do:, and other things like that into ArrayList Well, wishful thinking :-) But reflection could help. Not sure it is good to put more weight there still. Thanks for the XML parser new version! (Learning Spriter...) |
| ||
I have a code snippet for you. If you want to launch the market in WP7 platform, do this:public static void launchBrowser( String address, String windowName ) { MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask(); marketplaceDetailTask.ContentIdentifier = address; marketplaceDetailTask.ContentType = MarketplaceContentType.Applications; marketplaceDetailTask.Show(); } |
| ||
Cheers Xaron, just added it :) |
| ||
Cool. But maybe it would be a good idea to change the name. Because the code above does not launch the browser but the market because that's what I use this code for. ;) |
| ||
Ahh, you've could have told me that before :P It doesnt matter though, I use the launchbrowser to open the Android market too.... |
| ||
- woops! wrong thread - |
| ||
Diddy now supports the pss target (kind of) ;) Also we are up to R400 \o/ |
| ||
Congratulations on R400! And kind of pss support! <3 |
| ||
Firstly, congrats on R400. One of the test I do for my game is to set the FPS to 5 frames, just to see if it is still responsive, just incase. In OnCreate I do the following: FPS = 5 Super.OnCreate() ' Calls Diddy's Framework OnCreate I notice ScreenFade was going really slow, even though I set fadeTime to 50ms. Shouldn't it frameskip? In framework.monkey line 423 counter += dt.delta My understanding from the code, delta should be roughly 1 (plus or minus 0.01 - hopefully) In this case, you want the frametime, since counter is checked against fadeTime. Is framework.monkey line 423 should be: counter += dt.frametime or did I mis-understand how the timing system should work? |
| ||
The timing is slightly messed up there. The screen fading "fadeTime" isnt really in ms at the moment, its just an arbitrary value. I'm a bit scared changing it as it would mess up a lot of other people's code, but it should either as you said use dt.frametime or in the "start" method calculate the game time: Method Start:Void(fadeTime:Float, fadeOut:Bool, fadeSound:Bool = False, fadeMusic:Bool = False) If active Then Return active = True Self.fadeTime = game.CalcAnimLength(fadeTime) ' <- Calc game time Self.fadeOut = fadeOut Self.fadeMusic = fadeMusic Self.fadeSound = fadeSound If fadeOut Then ratio = 1 Else ratio = 0 ' set the music volume to zero if fading in the music If Self.fadeMusic game.SetMojoMusicVolume(0) End End counter = 0 End |
| ||
When using Diddy, I noticed that whenever the MouseHide() is called in GLFW, and move past outside the game window, it stays hidden. This doesn't occur in XNA or Blitzmax targets. Is there anyway we can get it to do the same in GLFW? I've tried calling ShowMouse() when it passes the edge but it just resets the mouse coords back to center of the game window. |
| ||
Yeah thats an issue with GLFW, I've tried doing this "hack":if (MouseX() < 0 or MouseX() > DEVICE_WIDTH or MouseY()< 0 or MouseY() > DEVICE_HEIGHT) ShowMouse() SetMouse(MouseX(), MouseY()) Else HideMouse() End But its not 100%. |
| ||
Odd...thats basically the same "hack" i did but yours actually worked and mine didn't :). Thanks therevills! |
| ||
Ok yep ... I understand. I know what to do in my game. Thank you for the explanation therevills. |
| ||
I added some convenience methods to make screen transitions a little more concise. Instead of manually setting game.nextScreen and calling game.screenFade.Start() you can just use the FadeToScreen() method in the Screen class. To fade in the first screen, you call game.Start(screen). Ive updated the testFramework.monkey example to show how to use it. If you're going to use the convenience methods, make sure to remove screenFade.Start() from your screens' PreStart() methods. Fading to null by calling FadeToScreen(Null) is the same as fading to game.exitScreen. Also, you no longer need to use the "game =" assignment, because the DiddyApp constructor now does that for you. Instead of: [monkeycode]game = New MyGame[/monkeycode] You can just do: [monkeycode]New MyGame[/monkeycode] |
| ||
Oi! Use this thread now: http://www.monkeycoder.co.nz/Community/posts.php?topic=2995 ;) |