Diddy - An Open Source Framework - Part 7

Monkey Programming Forums/User Modules/Diddy - An Open Source Framework - Part 7

therevills(Posted 2013) [#1]
Thread continued from here...

An Open Source Framework that includes a set of extra functions and APIs for the Monkey language.

Diddy includes the following modules:

* Easy to use Screen based framework
* Sprite class
* Resource managers for sounds and images
* A* Path finding
* XML parser
* Asserts
* Serialization
* Particles
* Collections
* Tweening
* GUI (Buttons, Sliders, Windows)
* Base64 encoding/decoding
* Tile Engine (Using the Tiled Map Editor)



I have uploaded the final version of Diddy which will work on v66b to Google Code.

And I have started work on the changes required to get Diddy working with v67(a,b,c,d,e,f) ;)

The first major change for Diddy is that the global "game" variable has been renamed to "diddyGame" to avoid any future conflicts.




Samah(Posted 2013) [#2]
My 3g quota thanks you for creating a new thread :-)


Auburn(Posted 2013) [#3]
So moving my question to this thread as I still haven't found a fix.

Auburn (Posted 3 weeks ago) Edit #119
Hi, I am having a problem with the tiling engine in diddy; if i change a tile using any of the set methods it will update that information for collision detection, but it will not render the map with any changes, it just renders the original map that was loaded. When i check the tile data with get method it returns the tile it set previously.

Is this something I am doing wrong or is it a bug?

This is my code:
SetTile ( mouseX, mouseY, 2, layerName )

This is inside a method in my tilemap class.

Edit: I know it is updating the correct tile as collisions work on the updated tile.


Samah (Posted 3 weeks ago) #120
Given that tile collision and image are on different layers, you need to update both of them. This is a side-effect of the fact that collision detection in the tile engine is a bit of a hack given that (last time I used it) Tiled does not initially support the concept of "collisions". They must be handled manually by the engine that reads the Tiled map files.

Auburn (Posted 2 weeks ago) Edit #121
Ok, but how do I update the image for the map then?

I have spent a while looking through the tile module but could find nothing on updating the image from the map data.

Would really appreciate some guidance with this issue as I current using a simple rendering method I made, but it is only a temporary fix.

Summary: How do I update the rendered map image with any edits I made to the map data?


Belimoth(Posted 2013) [#4]
The first major change for Diddy is that the global "game" variable has been renamed to "diddyGame" to avoid any future conflicts.


Very glad to see this.


Rushino(Posted 2013) [#5]
I am glad also. +1


therevills(Posted 2013) [#6]
HTML5, Android and Flash now fully work with Diddy using v67f.


Rushino(Posted 2013) [#7]
Thanks a lots therevills!


therevills(Posted 2013) [#8]
GLFW and XNA now works with v67f.

I've added the fixes to iOS, but cant test them at the moment. But I think they should work.

So I believe Diddy has been fully updated to v67 :)


Beaker(Posted 2013) [#9]
Great stuff.


Tibit(Posted 2013) [#10]
Looking forward to getting diddy to work. Have a bunch of projects I haven't been able to compile for many weeks now! Your work is greatly appreciated!

If you have this:[monkeycode]
Import diddy

Function Main:Int()
Local game:MyGame = New MyGame()
End

Class MyGame Extends DiddyApp

End[/monkeycode]

I get the runtime error "cannot set Delegate of Undefined". It only seems to happen in diddy apps, but I could not figure out why, because the crash itself is from app.monkey row 103.

Maybe using Monkey or Mojo Commands before OnCreate?

I'm using the diddy verion found on bitbucket :)


ziggy(Posted 2013) [#11]
have you deleted your build folder?


therevills(Posted 2013) [#12]
@Tibit - As Ziggy asked - "Have you deleted your build folder?"
Also the framework only needs to be initialised like this:
format_code('Import diddy

Function Main:Int()
New MyGame()
Return 0
End

Class MyGame Extends DiddyApp
')

@ALL - We have moved our main code base back to Google Code but this time we will be using Hg there. This means there is no need to maintain (take snapshots) between two sites.


Tibit(Posted 2013) [#13]
No I haven't haha.

Thanks for reminding me! Works now:)


Zwer99(Posted 2013) [#14]
Thanks for the update, but Flash isn't working...

format_code('For obj = EachIn Self.updateList 'This line causes an error
obj.Update()
Next')

updateList is an ArrayList<OEObject>

Error:
format_code('Monkey Runtime Error : TypeError: Error #1009')

I don't know if it's a diddy bug. Sorry if it isn't ;)

My Versions:
- diddy_v67
- MonkeyPro 68b
- Flex v4.9

And yep, I deleted my build-dir ;)

Zwer99


therevills(Posted 2013) [#15]
Strange... works fine here.

Can you try running this:
format_codebox('Strict

Import diddy
Import mojo

Function Main:Int()
New Game()
Return 0
End

Class Game Extends App
Field boneMap:ArrayList<SpriterBone> = New ArrayList<SpriterBone>

Method OnCreate:Int()
SetUpdateRate(60)
For Local i% = 0 To 9
Local b:SpriterBone = New SpriterBone
b.x = Rnd(0, 640)
b.y = Rnd(0, 480)
boneMap.Add(b)
Next
Return 0
End

Method OnUpdate:Int()
Return 0
End

Method OnRender:Int()
Cls
Local obj:SpriterBone
For obj = Eachin boneMap
obj.Draw()
End
Return 0
End
End

Class SpriterBone
Field x:Float, y:Float

Method Draw:Void()
DrawOval x, y, 10, 10
End
End')


Zwer99(Posted 2013) [#16]
Got it! The problem was that I fill the "Self.updateList" on different places in the code depending on the used platform, because in Monkey 66b Flash executes Draw before Update and in HTML5 it executes Update before Draw. The objects to update and to draw are always the same. That's why I didn't want to fill the objects list twice.
To solve that, I used the pre-processor commands to get the used TARGET. But with Monkey 68b Flash ALSO executes Update before Draw - the result is that the objects list in Update is empty because I just fill it in Draw. Now I just deleted the target distinction.

Thank you so much for your help, therevills!


frank(Posted 2013) [#17]
Is there any way to keep one sample (looped) playing across screens? So not stop/starting?


therevills(Posted 2013) [#18]
@Zwer99 - glad you figured it out, sounds pretty nasty!

@frank - how are you changing screens?


frank(Posted 2013) [#19]
I'm using FadeToScreen(); so basically I want the same loop to play from intro screen, menu, all in between, help screens and the game itself. I know I can probably do that 'manually' by using LoadSound and some such, but is there a 'diddy way'?

Edit also some transparency code bug thing; in Flash it DOES continue playing with exactly the same code while in HTML5 it stops after every screen...


therevills(Posted 2013) [#20]
Strange, works here. Open up the Music example (diddy/examples/Music/music.example), and comment out "diddyGame.MusicPlay("SplitInSynapse"+musicExt, 1)" in the GameScreen Start method.

When you run the app, you will hear the music on the Title Screen and it will continue playing when you click the mouse, if you click the mouse on the GameScreen the music will start again when the Title Screen is displayed.


frank(Posted 2013) [#21]
Hmmm. Here it works with the same code only in flash but not html5... I ll make a little demo of that as well as it is the case always with looped play.


frank(Posted 2013) [#22]
Is there somewhere I could reach you and others faster than here? I have a deadline tomorrow which needs to have this solved. Is there an IRC channel or something for monkey?


therevills(Posted 2013) [#23]
Music and sound in Monkey in general is very dodgy to say the least due to different targets/browsers.

I live in Australia and I am currently at work so I wouldn't be available for contact... I do recall that some of the Monkey guys do hang around in an IRC channel: http://www.monkeycoder.co.nz/Community/posts.php?topic=3762#40252


Nobuyuki(Posted 2013) [#24]
That entire network is pretty much on life support, and #monkey is empty as a ghost town :(


Paul - Taiphoz(Posted 2013) [#25]
2 days late but I'm on IRC most days just not in there 24/7 as I dont run a bnc/bot for when im offline.

Anyway on topic. Therevills, does diddy use that new async loading stuff to creating a loading screen and bar for diddy apps yet ? if not do you have any plans to implement it ?

Seem like it would make a really good addition to the framework.

OH yeah while I am here, your now using git will you maintain the google code svn or should I switch to using the new one.


therevills(Posted 2013) [#26]
does diddy use that new async loading stuff to creating a loading screen and bar for diddy apps yet ? if not do you have any plans to implement it ?

Nope it doesn't use the async loading "stuff"... I haven't looked at how it works, but we should have a loading screen. It shouldn't be too hard to do, even with the current code.

OH yeah while I am here, your now using git will you maintain the google code svn or should I switch to using the new one.

We aren't using GIT, we are using Mercurial (Hg). A few weeks ago we converted the Google Code SVN to Hg and this its the place you should use.


Paul - Taiphoz(Posted 2013) [#27]
Ah yeah my mistake, so http://code.google.com/p/diddy/ is still the right place but it just uses Hg now yeah ?

cool.. I'm sure I just used svn to update from it like half an hour ago is that possible or did I just update something else lol


Paul - Taiphoz(Posted 2013) [#28]
I am trying this.. can this not be done ? with svn I was only pulling down the diddy module and not all the other stuff. would like to do that again but it seems to not like it now.

hg clone --verbose -- https://code.google.com/p/diddy/hg/src/diddy D:\Code\MonkeyPro69\modules\diddy


Shinkiro1(Posted 2013) [#29]
try hg pull


therevills(Posted 2013) [#30]
Try: hg clone https://code.google.com/p/diddy/


Paul - Taiphoz(Posted 2013) [#31]
clone does the full repo which has diddy in the src folder, I know its probably not a good idea but I have my local diddy repo in the modules folder so I normally just update it and go..

Looks like I will need to make a full clone and then copy paste the diddy folder into the modules folder.

kinda not used to hg, using the windows context menu controls, and its got clone in there but not pull.


Shinkiro1(Posted 2013) [#32]
> kinda not used to hg, using the windows context menu controls, and its got clone in there but not pull.

Then use the command line.


therevills(Posted 2013) [#33]
Using TortoiseHg:

Right click on your folder and select TortoiseHg > Clone


Input the source as https://code.google.com/p/diddy/ and click Clone


Wait for the files to download...



Samah(Posted 2013) [#34]
Maybe use the new MODPATH stuff to point to your Diddy clone?


Paul - Taiphoz(Posted 2013) [#35]
Therevills mate thanks for that, but I can already do that, as I pointed out before that will result in a full copy of everything, and not what I was trying to do.

What I was trying to do is simply have mercurial clone down the module diddy and module threading folder and not all the extra stuff that's in the repo, I can do this with Subversion easily by pointing the repo path at the trunk and appropriate folder, but Hg does not like it when you try this.

What made you move over anyway I'm not really experienced enough with VCS's to really know why Hg is better , for me Subversion has been really cool and I'v only used Hg for 1 other project, well now 2 with diddy.


Samah(Posted 2013) [#36]
Is your hard drive space at that much of a premium that you can't afford to get the whole repository?


frank(Posted 2013) [#37]
In HTML5 on touch devices (tried iPad and Samsung s2), without any resizing, game.mouseX gives me back the wrong coordinates (always off by 100 px or something) while TouchX / SCREENX_RATIO works fine. Is that normal? :) Seems the latter works on any device (including desktop) so i'm using that now only.


therevills(Posted 2013) [#38]
@Frank - Strange...

diddyGame.mouseX is just MouseX() / SCREENX_RATIO unless aspectRatio is switched on. And I thought MouseX was the same as TouchX....


frank(Posted 2013) [#39]
Yeah that's what I thought... But i'm getting very different results and I didn't change anything in the Diddy code related to that. So not sure what's going on there. I'll debug a bit later to see where that difference comes from, but deadline to make :) You'll be happy to know Diddy played a very large part in the creation of a game for one of the biggest ZOOs in the Netherlands (links follow upon launch).


Rushino(Posted 2013) [#40]
externfunctions.monkey aren't compatible with Win8 target.


therevills(Posted 2013) [#41]
I'll debug a bit later

Me too when I get time, seems very strange.

externfunctions.monkey aren't compatible with Win8 target.

I added a native win 8 stub file the other day and compiled fine.


therevills(Posted 2013) [#42]
Just copied across (and slightly updated) the wiki pages from SVN to Hg:

http://code.google.com/p/diddy/w/list


Redbeer(Posted 2013) [#43]
Thank you for putting the old information back up. :D


StoneFaceEXE(Posted 2013) [#44]
Excuse me, I just tried to work around the diddy's framework and when I try to compile framework.monkey.html example code I get and error
" Error : Identifier 'game' not found. "

I guess I'm doing something wrong.

I tried last diddy build and both 67f and 69 versions of monkey


Paul - Taiphoz(Posted 2013) [#45]
you have an older version, update to the newest versions of diddy and monkey.

there was a conflict with a recent patch from monkey that used the variable game, and since diddy used to use it as well you get the error.

just update you will be fine.


StoneFaceEXE(Posted 2013) [#46]
Yeah I thought v67 was final version, it appears that v66 final is more final )


therevills(Posted 2013) [#47]
@StoneFaceEXE - please used "diddyGame" now instead of "game".


StoneFaceEXE(Posted 2013) [#48]
You'll need to update .docs then ^_^


therevills(Posted 2013) [#49]
Done :P


Ben(Posted 2013) [#50]
So I noticed a problem with your sprite drawing code.
[monkeycode]If x - offsetx + image.w < 0 Or x - offsetx - image.w >= SCREEN_WIDTH
Or y - offsety + image.h < 0 Or y - offsety - image.h >= SCREEN_HEIGHT Then Return[/monkeycode]
The reason why this is an issue is because it doesn't account for rotation. So for example, if I rotate a sprite by 90 degrees and move it in from out of the screen, the object suddenly appears part of the way through which is not nice.

To expound upon that, since it does drawing based upon the width and if the width is less then the height then it waits to draw it. This could be a solution if you don't have anything more automated available. Basically integrate a way to do it manually.
format_codebox('If (drawBoundsW <> 0 And drawBoundsH <> 0) Then
If x - offsetx + drawBoundsW < 0 Or x - offsetx - drawBoundsW >= SCREEN_WIDTH
Or y - offsety + drawBoundsH < 0 Or y - offsety - drawBoundsH >= SCREEN_HEIGHT Then Return
Else
If x - offsetx + image.w < 0 Or x - offsetx - image.w >= SCREEN_WIDTH
Or y - offsety + image.h < 0 Or y - offsety - image.h >= SCREEN_HEIGHT Then Return
End')


therevills(Posted 2013) [#51]
Thanks for that Ben - added a fix which will work for rotated and scaled sprites.


samowitsch(Posted 2013) [#52]
Hi, i am getting an error on Xcode with iOS Target (Xcode Screenshot).

Native function seekMusic?

html and glfw are working fine.

Regards
samowitsch


therevills(Posted 2013) [#53]
Hi Samowitch, thanks for that, could you please try changing the native function to the following and try again:

format_code('static int seekMusic(int timeMillis)
{
if(bb_audio_device->musicPlayer)
{
bb_audio_device->musicPlayer.currentTime = timeMillis/1000.0;
}
// TODO: check it worked
return 1;
}')

In otherwords change "music" to "musicPlayer".


samowitsch(Posted 2013) [#54]
Hi therevills, this changes fix it. Thanks samowitsch


therevills(Posted 2013) [#55]
Excellent, thanks for testing samowitsch, I've committed the fix to the repo.


frank(Posted 2013) [#56]
Seems you are using GetColorPixel now, but in 70b this function seems to not exist? I cannot compile anymore after updating Diddy to the latest :)


therevills(Posted 2013) [#57]
We've removed GetColorPixel as Mojo now has its own Pixel commands. Convert your code to use ReadPixels / WritePixels.


frank(Posted 2013) [#58]
I'm not using ReadPixels / WritePixels :) I just dropped the latest hg clone of diddy into modules of MonkeyPro70b, compiled and get the error that GetColorPixel cannot be found.

Edit: https://code.google.com/p/diddy/source/browse/src/diddy/functions.monkey#84 here it is, it fails to compile on that.

Edit: I'm actually unsure why it compiles that GetPixel; I grepped the entire tree for it and it's not used anywhere. Then it shouldn't compile it right?

Edit: Just to try I removed GetPixel from functions.monkey, then I get;

/Applications/MonkeyPro69/modules/diddy/sortutil.monkey<48> : Error : Objects can only be compared for equality.

Seems this change broke it, but then you should've seen that right? So what could be wrong on my side that I get errors?

https://code.google.com/p/diddy/source/detail?spec=svndc906c28c1e011972f2cb1379509400dfac12096&r=dc906c28c1e011972f2cb1379509400dfac12096


therevills(Posted 2013) [#59]
Are you using GetPixel or are you using reflection? I missed removing it due to Monkey's dead code stuff - thanks!


frank(Posted 2013) [#60]
Ah. Reflection. That's it.

Any idea about the other issue? I'm kind of stuck on that one; because mojo<>diddy are so dependent I cannot get anything compiled :)

Edit: I mean diddy on mojo :) Not the other way around. The problem i'm having is that all worked fine for Monkey66 however, then Diddy misses some mojo things. For Monkey69 iOS is not reporting screen dimensions for me (works in 66); other targets work. So my 'lets compile on iOS' hour of work turns into days I guess...


therevills(Posted 2013) [#61]
Looks like Samah changed quite a bit with the quick sort... I've told him about it and hes looking into it.


Samah(Posted 2013) [#62]
Basically the change I made should have been fine as long as you didn't misuse the SortUtil class and try to mix primitive and Object comparisons. Monkey's aggressive code stripping means that it would ignore it. The problem is that when you have your REFLECTION_FILTER set to "*", it forces it to compile the invalid functions.

I've backed it out for now. I'll bring it back in if and when Mark does something with trans that will let me compile the Object comparison. Feel free to keep it if you're not using a REFLECTION_FILTER of "*".

Sorry. :(


frank(Posted 2013) [#63]
I'm don't have my reflection filter to "*", but I did include diddy* in them because when I was playing around with GetClasses I noticed diddy adds Exceptions as reflected classes and they are gone if you add your own REFLECTION_FILTER on top. I will see if removing that resolves the issue :)

Thanks for the quick reaction and keep up the good work! Diddy is excellent!


frank(Posted 2013) [#64]
Btw, please note this ; http://monkeycoder.co.nz/Community/posts.php?topic=5082 ; because Diddy updates SCREEN_WIDTH/HEIGHT on OnCreate and then later when you SetScreenSize, SCREEN_WIDTH(2)/HEIGHT(2) are wrong until you manually fix them by calling SetScreenSize(DeviceWidth(), DeviceHeight()) from (On)Update. All games I have using Diddy are broken on iOS now after compile.


therevills(Posted 2013) [#65]
Yeah seen that, its a Monkey/Mojo issue and Mike thinks its already been fixed so I'm reluctant to add a "fix" to Diddy.


frank(Posted 2013) [#66]
Yeah I wouldn't do that because I do believe it's a bug.

I noticed as well that if reflection filter is set to * or diddy* that iOS builds crash immediately. No idea why and it's probably not a good idea anyway, but I thought I would just say it here if someone else runs into this issue.


Raph(Posted 2013) [#67]
I see a 4/14 RAR up for download, but don't know what version of Monkey it is compatible with. The other ZIP files all say what version of Monkey are are compatible with. I read through the threads here but didn't find this info. Anyone know?


therevills(Posted 2013) [#68]
@Raph, Diddy is designed to work with the latest version of Monkey. We only added the Monkey versions to the previous downloads as there was a major change to Monkey.


Amon(Posted 2013) [#69]
Hi! Mark made a post here regarding a few errors I was having with Win8.

http://www.monkeycoder.co.nz/Community/post.php?topic=5149&post=57068

I'm using the latest version of diddy and it seems not to follow marks recommendation as it still causes errors for me when I exit my app.

Can someone have a look in to this?

Ta!


therevills(Posted 2013) [#70]
Hmmmm....

So when ExitScreen is called for Win8 we need to call OnBack with EndApp...

Currently ExitScreen looks like this:
[edit - removed code]

Amon, could you try changing it to look like this:
[edit - removed code]


Amon(Posted 2013) [#71]
I've modified it to what you've posted but I still get the same errors exiting the app.

I'll double check everything is modified properly, it should be.


therevills(Posted 2013) [#72]
Please try:
[edit - removed code]

It shouldnt quit, but you should get a trace statement saying "WIN8 quitting!".


Amon(Posted 2013) [#73]
Well, it didn't say Win8 quitting, instead I got a a screen that changed colour 3-4 times a second.

No errors though!


therevills(Posted 2013) [#74]
Okay... looks like we are going to have to set a flag in the main DiddyApp.

I've just pushed a change which I hope will help - tested on HTML5 and it works, so if you could test Amon that would be great :)


therevills(Posted 2013) [#75]
The Win8 changes worked fine, once I managed to enter in the bloody license key for VS2013!!

And I've just pushed a couple of new commands for GLFW (Win Only): SaveFileName:String() and OpenFileName:String()

They open a native file requester dialog.


Gerry Quinn(Posted 2013) [#76]
Hi guys, just wanted to say I found it useful to add a simple OK/Cancel dialog to diddy.externfunctions. I won't bother with the code as it is basically a clone of ShowAlertDialog only with no text input. It sets an integer value in diddy when a button is clicked, same concept as the current inputString. When the value changes from 0, one of the buttons has been clicked. I use it for ExitApp->Are you sure? messages on Android.

Just thought I would mention it as such a dialog without the extraneous text input option might be useful for diddy users in general.


Zwer99(Posted 2013) [#77]
Hey guys!

I just implemented the particle engine successfully, but I had problems with the tilemap scrolling in my game. I had to change the particleSystem.Render() to:
format_code(' Method Render:Void(scrollX:Float, scrollY:Float)
Local rgb:Float[] = GetColor()
Local alpha:Float = GetAlpha()
For Local i:Int = 0 Until groups.Size
groups.Get(i).Render(scrollX, scrollY)
Next
SetAlpha(alpha)
SetColor(rgb[0], rgb[1], rgb[2])
End')

And the particleGroup.Render() to:
format_code(' Method Render:Void(scrollX:Float, scrollY:Float)
For Local i:Int = 0 Until aliveParticles
Local index:Int = alivePointers[i]
SetColor(red[index], green[index], blue[index])
SetAlpha(alpha[index])

' scale should never be <=0, so we'll fix it here
If scale[index] <= 0 Then scale[index] = 1

If particleImage[index] <> Null Then
If scale[index] <> 1 Or rotation[index] <> 0 Then
DrawImage(particleImage[index], x[index] - scrollX, y[index] - scrollY,
rotation[index] * R2D, scale[index], scale[index])

Else
DrawImage(particleImage[index], x[index] - scrollX, y[index] - scrollY)
End
Else
If scale[index] <> 1 Or rotation[index] <> 0 Then
PushMatrix
Translate(x[index] - 1 - scrollX, y[index] - 1 - scrollY)
If scale[index] <> 1 Then Scale(scale[index], scale[index])
If rotation[index] <> 0 Then Rotate(rotation[index] * R2D)
DrawRect(0, 0, 3, 3)
PopMatrix
Else
DrawRect(x[index] - 1 - scrollX, y[index] - 1 - scrollY, 3, 3)
End
End
Next
End')

to render the particles on the right position.
Didn't you mention scrolling in your implementation, or is there another solution I didn't see? It would be nice, if you could add it in one of your further Releases :)

Thank you and have a nice day, Zwer99


therevills(Posted 2013) [#78]
@Gerry - Do you have a cross-platform solution or is it just for Android?

@Zwer99 - Thanks for that, I've just committed your changes, with a slight difference that the scroll parameters are defaulted to zero (for backwards compatibility).


Gerry Quinn(Posted 2013) [#79]
Just Android. I don't even know the Android OS, so what I have is a near clone of your original ShowAlertDialog. Here is what I added to diddy.android.java:

format_codebox('
public static AlertDialog.Builder dlg; // my dialog
public static int dlgResult = 0; // and its output

// My dialog
static void showOkCancelDialog( String title, String message )
{
dlg = new AlertDialog.Builder(BBAndroidGame._androidGame._activity);
dlg.setTitle( title );
dlg.setMessage( message );
dlgResult = 0;
dlg.setPositiveButton( "Ok", new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog, int whichButton ) {
dlgResult = 1;
}
});

dlg.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog, int whichButton ) {
dlgResult = 2;
}
});

dlg.show();
}

// And its output
static int getDialogResult()
{
return dlgResult;
}

')

I would expect the same would be easy to implement on any target, though, as really all I am doing is removing the text input option. You could even make it an option on ShowAlertDialog, and have it return an appropriate string in ShowMessageString.

An indefinite number of named option buttons would be a potentially useful alternative too, though that runs into layout issues if there are more than a few.


Amon(Posted 2013) [#80]
There's a bug, and a pretty nasty one in Diddy when navigating screens.

format_code('
Method Create:Void()
LoadImages()
titleScreen = New TitleScreen
gameScreen = new GameScreen
Start(gameScreen)
End
')

Running the standard Framework example will show you what I mean but first you have to modify it so that when the app starts it starts with the gameScreen. When the App is started press escape or back button and you'll see it will crash.

The console shows that when you try to go back to the 'titleScreen' it tries to find a screen named "TITLE" but the stock Framework has the titleScreen name as "Title".

Somewhere, too tired to sift through the diddy source, there may be a hard-coded 'name' value for the titleScreen... That's my guess anyway...


therevills(Posted 2013) [#81]
Within the framework example the Gamescreen class has the backScreenName set to "Title", which is automatically converted to uppercase.

Currently the screens has to be run in order i.e. TitleScreen then GameScreen. We did it this way so we didn't break anyone's code.

To go from GameScreen to Titlescreen you need to add TitleScreen to the DiddyGame Screens StringMap:

format_code('Class TitleScreen Extends Screen
Method New()
name = "Title"
backScreenName = "exit"
diddyGame.screens.Set(name, Self)
End')


Amon(Posted 2013) [#82]
Hi therevills,

I know it's been a while and I've not updated you regarding the crashing on exit on the Win8 target, I gave up to be honest. Not your fault but mine. I would appreciate it if we could revisit the problem as even with the latest version of Monkey and the latest HG clone of the Diddy framework I still get a crash when exiting a Win8 app when the app is using the Diddy Framework.


therevills(Posted 2013) [#83]
What type of crash are you getting now?

If its this one: http://www.monkeycoder.co.nz/Community/post.php?topic=5417&post=60496

Its a Monkey issue not Diddy.


Amon(Posted 2013) [#84]
Oh! What in Monkey is causing this? Is Mark the only one that can fix it?


therevills(Posted 2013) [#85]
I've just committed a change for Win8. Now if your application calls ExitApp() or a screen calls ExitScreen, Diddy will no longer attempt to quit the Win8 application.


therevills(Posted 2013) [#86]
Simple Loading Screen added, please refer to example: http://code.google.com/p/diddy/source/browse/examples/LoadingScreen/loading.monkey

format_code('' inits the loadingscreen graphics and steps
' params:
' 1: image which will be displayed in the center of the screen
' 2: full loading bar image
' 3: empty loading bar image
' 4: number of resources (steps)
' 5: X position of the loading bar (optional, if not supplied or -1 it will be centered)
' 6: Y position of the loading bar (optional, if not supplied or -1 it will be centered)

diddyGame.loadingScreen.Init("graphics/loadingScreen.png", "graphics/loadingbar.png", "graphics/loadingbarempty.png", 4, -1, 400)
diddyGame.loadingScreen.destination = gameScreen
Start(diddyGame.loadingScreen)
')

Let me know how it works for your projects.


zoqfotpik(Posted 2013) [#87]
Reposted by suggestion from Taiphoz...

Diddy guys, is there a canonical way to override the Diddy fadetoscreen to allow somewhat more complex fade actions? I would like to add a little bit of pizazz there.

If this is not easy, I could just do my fancy wipe manually and then fadetoscreen with a duration of 0.


therevills(Posted 2013) [#88]
FadeToScreen is a convenience method to move between screens, it basically wraps the screenFade actions.

If you want to create your own, just make sure that you call diddyGame.currentScreen.PostFadeOut() when leaving the current screen and
diddyGame.currentScreen.PostFadeIn() when entering the next screen.


zoqfotpik(Posted 2013) [#89]
I see.

You really do have a ton of stuff in that framework, you should be proud of it.


Paul - Taiphoz(Posted 2013) [#90]
So basically, do our fade routine, then let diddy know that weve faded out the current screen, do our fade in and then let diddy know we have faded in.

I'm wondering what if we need to render the screen in full so that we can do something to it, lets say for example I want to do one of those explosion style fades where the screen blasts into little squares or pixels, and then the fade in would be little squares or pixels coming together.


zoqfotpik(Posted 2013) [#91]
It would be really nice to be able to override the fade function. The other way works just as well too, I am just going to do something at the same time as the screen fades to black.

I am all about low hanging fruit. The fact is, what the vast majority of us make is borderline or outright shovelware (I certainly do) and if one thing is hard you are probably doing the wrong thing.


Samah(Posted 2013) [#92]
I could probably put something in where you customise/extend your own "Fader" instance, which defaults to "boring linear".


zoqfotpik(Posted 2013) [#93]
It would be nice to see that. Seems like fades are widely used and nice looking for graphical juiciness.


Paul - Taiphoz(Posted 2013) [#94]
Samah how about putting the current fade code out into a single file call it fade, and then give the user the option to set the name/style of the transition to use, if we say for example diddyGame.setFadeStyle(Fade) it would then use the update/render from fade.monkey

Would allow people to use the current fade.monkey as a temaplte and simple code their own update and render, would make it possibly to have tons of themed/styled/transitions in a folder that the user could pick from.

might be a bit of work but worth an bash.


Samah(Posted 2013) [#95]
Why another file? You want to use it for non Diddy-framework stuff? I s'pose...
It'll have to wait for a bit though. I'm flying to Melbourne tomorrow in preparation for PAX. :D


Paul - Taiphoz(Posted 2013) [#96]
if the transision template part, not the whole fadeclass class, but rather an extended class used to create a fade style.

so for example I might take the template default fade.monkey file, copy it, call it slidein.monkey and edit its extended update/render methods to slide something in over the screen and then out again.

I could then share that slide.monkey file with other diddy users, they drop it into their transitions folder and can / could then easily use it in their own diddy projects.

there is probably a lot simpler way of doing this if you make transitions using lua or xml but I think giving people the freedom to code their own via a simple setup like that might be better.

not to mention people could post their transition code here and if you like it you could add it to the repo..

just a though tho, not sure if im making what im thinking about clear I tend to muddle my words some times.


zoqfotpik(Posted 2013) [#97]
I tend to agree. I am sure whatever method is used will be fairly easy whether it's extend or a separate file.


Amon(Posted 2013) [#98]
I like Taiphoz's idea.


zoqfotpik(Posted 2013) [#99]
Maybe we could come up with a library of fades. There are quite a number that I would like to do and that sort of graphics programming is a nice break.


Samah(Posted 2013) [#100]
Coding Diddy on the plane to Melbourne. Dedication. :)


zoqfotpik(Posted 2013) [#101]
It would also be interesting if we could use faders for different purposes in the framework, like fading a sprite.

Also taking a screenshot of the current screen, plonking in the new screen beneath it and using a fade to blend between the old screenshot and the new screen. If that makes sense.


therevills(Posted 2013) [#102]
Dedication. :)

LOL! It's dedication when works rings you when you are on leave and you answer!!

like fading a sprite.

Do you mean alpha fade? You can do that already... or do you mean fading it to black? Again you can do that too (change the colour slowly to 0,0,0 via SetColor).

Also taking a screenshot of the current screen, plonking in the new screen beneath it and using a fade to blend between the old screenshot and the new screen. If that makes sense.

I think you mean a crossfade effect, that would be nice... but the "taking a screenshot" would be slow! Unless we just keep drawing the first screen and draw the new screen on top by slowly fading it in.


zoqfotpik(Posted 2013) [#103]
Do you mean alpha fade? You can do that already... or do you mean fading it to black? Again you can do that too (change the colour slowly to 0,0,0 via SetColor).


I mean using one of these "fader" algorithms we are talking about to fade out a sprite instead of fading a screen to black.

Unless we just keep drawing the first screen and draw the new screen on top by slowly fading it in.

That would be a good idea and would not necessarily have to be slow-- the new screen might be an "in between levels" screen that would not necessarily have much graphics.

Did you see the "juice" presentation?

http://www.youtube.com/watch?v=Fy0aCDmgnxg

On another note, can you explain exactly why taking screenshots is so slow? It seems to be slow on every platform, even PC, and I never understood that.


CGV(Posted 2013) [#104]
Sorry to change topics but how do you use Diddy's SimpleButtons with touch events?

There doesn't seem to be any code in the SimpleButton class to handle that.

If I have to manually determine it with a RectsOverlap function that's fine but how do I get the button to respond?


therevills(Posted 2013) [#105]
can you explain exactly why taking screenshots is so slow?

Because (in Monkey at least) you have to save each pixel... and then redraw it back on the screen.


There doesn't seem to be any code in the SimpleButton class to handle that.

A button has to be assigned to a menu, have a look at the SimpleGUI example: http://code.google.com/p/diddy/source/browse/examples/SimpleGUI/testSimpleGUI.monkey


CGV(Posted 2013) [#106]
Silly me, it turned out it was working but I had useVirtualRes set to false so it was throwing off the coords.

On an unrelated note; is it possible to grab the button images from an atlas? When I tried it it didn't work.


therevills(Posted 2013) [#107]
is it possible to grab the button images from an atlas

Not out of the box, no.

What you could do is load an atlas image at the start of the app, then grab the images separately and add it to the image bank. Then create your menu and add the buttons with a temp image and replace the button image with the one stored in the image bank...

How did you try?


CGV(Posted 2013) [#108]
How did you try?

the standard way:
format_code('...AddButton(diddyGame.images.Find("button.png"), diddyGame.images.Find("buttonMO.png"), "button1")')but of course I got the "can't find overloaded function error".


What you could do is load an atlas image at the start of the app, then grab the images separately and add it to the image bank. Then create your menu and add the buttons with a temp image and replace the button image with the one stored in the image bank...

LOL, I think I'll just not include the button images in the atlas.


therevills(Posted 2013) [#109]
but of course I got the "can't find overloaded function error".

I'll add an overload tonight... looks like a nice simple solution - sometimes I over think too much ;)

LOL, I think I'll just not include the button images in the atlas.

Well it would have worked... but yeah a bit over the top eh!? :P


therevills(Posted 2013) [#110]
Committed the change for the override for SimpleButton to accept GameImages.


CGV(Posted 2013) [#111]
Thanks for taking the time for this therevills but are you sure you committed the changes?

TortoiseHG is telling me there are no changes and I even created a new directory and cloned it anew and no changes there either.

I'm still getting the overloaded function error.


EDIT: I was able to get the changes off of google code. It works great, thanks.


Whiteball(Posted 2013) [#112]
Been using diddy for my tilemap needs and its been a great help so far so big thanks to all involved.

I've currently hit a bit of a problem where I'm trying to replace a tile in the tilemap with a different one.
I'm using:
format_code('gameScreen.tilemap.SetTile(xx, yy, 4, "Foreground Layer") ')to change from tile id 24 to id 4, but it doesnt update the visual aspect of the tile as the old one remains.

If I then use something like:
format_code('If gameScreen.tilemap.CollisionTile(xx, yy, "Foreground Layer") = 24 Then')This doesnt trigger as the tile is indeed changed to '4' as set previous. It only appears to change the underlying tile id and not the visual tile displayed.

Am I doing something wrong here?


therevills(Posted 2013) [#113]
The Tile system is pretty complex, glad Samah wrote it ;)

Could you try this:
format_code('' find the layer
Local layer:TileMapTileLayer = FindLayerByName(layerName)
' get the TileMapCell
Local tmc:TileMapCell = layer.mapData.GetCell(xx, yy)
' set the image frame
tmc.gid = 4')


Whiteball(Posted 2013) [#114]
Thanks therevills, I've got it working now using your info plus a little trial and error.

I had to convert my x,y to tile co-ords because the GetCell one doesn't do that like the SetTile one does.
I also had to then use SetTile afterwards as well to set the underlying tile type otherwise I had the reverse of my original problem.

All working now, but I'm not sure that is how it was meant to be??
format_code('
Method ChangeTile(layerName:String, x:Int, y:Int, gid:Int)
Local layer:TileMapTileLayer = tilemap.FindLayerByName(layerName)
' get the TileMapCell
Local xx:Int = (Floor(x / gameScreen.tilemap.tileWidth))
Local yy:Int = (Floor(y / gameScreen.tilemap.tileHeight))
Local tmc:TileMapCell = layer.mapData.GetCell(Floor(xx), Floor(yy))
' set the image frame
tmc.gid = gid
gameScreen.tilemap.SetTile(x, y, 4, layerName)
End Method
')

Thanks again.


Paul - Taiphoz(Posted 2013) [#115]
Is there a way to make the autofit implementation diddy uses not keep aspect ratio ? for example if I want to make sure the game takes up 100% of the screen and not use black borders?


therevills(Posted 2013) [#116]
@Whiteball - I'll add a convenience method, one which sets the image frame and the tile type too - as the SetTile is useful on its own.
Edit: Added:
format_code('tilemap.ChangeTile(diddyGame.mouseX + offsetX, diddyGame.mouseY + offsetY, 4, "Tile Layer 1")')

@Taiphoz, yep when you call "SetScreenSize", there is a 3rd parameter "useAspectRatio" which is defaulted to False, so you must be setting it to True ;)


Paul - Taiphoz(Posted 2013) [#117]
Ah didn't even notice that.


Whiteball(Posted 2013) [#118]
Thanks again therevills, thats excellent. I'm off to do some more Monkeying around now...


Paul - Taiphoz(Posted 2013) [#119]
Having some problems with some code at the moment, dont have an example but the offending error presents this

format_code('
Loading configuration file C:\monkey_sdks\flex_sdk_4.6\frameworks\flex-config.xml
D:\Source\Monkey\StickRun\stickrun.build\flash\MonkeyGame.as(1938): col: 60
Error: Implicit coercion of a value of type Boolean to an unrelated type int.

chan.channel = chan.sample.sound.play(timeMillis, chan.loops, chan.transform);
')

Checking the source and eventually opening the file in flashdev I realized that it was in fact this diddy function that was causing the problem, when I comment out the offendng line my code builds and runs, with the line in I get the above error.

format_code('
static public function seekMusic(timeMillis:int):int {
if(bb_audio_device) {
var chan:gxtkChannel = bb_audio_device.channels[32];
if(chan.channel) {
chan.channel.stop();
chan.channel = chan.sample.sound.play(timeMillis, chan.loops, chan.transform);
}
}
// TODO: check it worked
return 1;
}
')


therevills(Posted 2013) [#120]
You haven't updated to the latest version. The new version changes "chan.loops" parameter to a "0":
http://code.google.com/p/diddy/source/detail?r=dee646d62d6bfd90480dda3f6cc49dd6a2578b17


Paul - Taiphoz(Posted 2013) [#121]
yeah just read your other post, sorry about that, not sure how my version went of of sync, fixing it now.


Arabia(Posted 2013) [#122]
Just downloaded Diddy and trying to get one of the examples (aspectTest) to work, and I get an error while compiling for Android:

BUILD FAILED
C:\diddy\diddyhg\examples\VirtualRes\aspectTest.build\android\build.xml:83: Cannot find C:\adt\android-sdk-windows\tools\ant\build.xml imported from C:\diddy\diddyhg\examples\VirtualRes\aspectTest.build\android\build.xml

Total time: 1 second
TRANS FAILED: Android build failed.


I've obviously done something wrong? Any idea what it is? Going by this error message, I am missing something that I should have downloaded for the Android SDK.


therevills(Posted 2013) [#123]
Looks like you haven't set up Monkey to use Android...


Arabia(Posted 2013) [#124]
Looks like you haven't set up Monkey to use Android...


Yep, no idea what I've done wrong. Got it set up fine on my Desktop, and tried putting it on the laptop a week later and can't get it working.

Double & triple checked the paths in the config.winnt.txt files, Android shows up in JungleIDE as a target.

In Android SDK Manager I have installed:
Tools - Android SDK Tools, SDK Platform-Tools, Build-Tools

Android 4.3 (API 18) SDK Platform & ARM EABI V7a only

Android 3.2 (API 13) All items

Android Repository SDK Platform 3.2 & Samples for SDK API 13 Installed

Android System Images

Google Inc - Google API's Google TV Addon, Google USB Driver installed


Don't have access to my desktop PC atm, I'm positive that is all I have installed on it. Off my Android SDK directory (C:\adt\android-sdk-windows\ I however do not have a Tools directory that the compiler is looking for and throwing up the error.

No idea what I've done wrong, might have to wait until I get home tomorrow to work out whats going on.

EDIT: All fixed, had the path wrong even though I thought if it wasn't right Android wouldn't show up as a target.

Now to have a look at some of the examples, stand by for lots of stupid questions :)


Arabia(Posted 2013) [#125]
Still getting an error on the aspectTest example:

BUILD FAILED
C:\adt\android-sdk-windows\sdk\tools\ant\build.xml:712: The following error occurred while executing this line:
C:\adt\android-sdk-windows\sdk\tools\ant\build.xml:726: Compile failed; see the compiler error output for details.

Total time: 3 seconds
TRANS FAILED: Android build failed.
Abnormal program termination. Exit code: -1

But all other examples seem to be working now


therevills(Posted 2013) [#126]
Tried deleting your build folder?


Raul(Posted 2013) [#127]
Hey, just wanted to ask:
the last version of diddy is from april as I can see here: https://code.google.com/p/diddy/downloads/list

I am using it and now I am updading my Monkey to 73. I wanted to download your last module version. I still that one?


rIKmAN(Posted 2013) [#128]
I'm using v73b and updated from the diddy repo a few days ago and everything seemed to work fine.

I was only using the xml parser though so not sure if there are issues elsewhere, but I was getting music/sound related errors until I updated.


therevills(Posted 2013) [#129]
@Raul - Google code is stopping the download section shortly, please use Hg to get the latest code from the repo itself.


rIKmAN(Posted 2013) [#130]
Raul, I've put a .rar of the latest repo version on my DropBox for you to save the hassle of Hg in case you don't use it.

https://dl.dropboxusercontent.com/u/26955697/diddy.rar

Extract it to your modules directory.


therevills(Posted 2013) [#131]
Just found out that GoogleCode was updated to generate zips from the source code (like bitbucket and GitHub).

To get the latest version:
* Navigate to https://code.google.com/p/diddy/source/browse/
* Click on the "zip" hyperlink
* Extract the zip
* Done :)


Raul(Posted 2013) [#132]
I see. Thank you guys!


Rhodesy(Posted 2013) [#133]
Hello,

I was just wondering if there are plans to add any more components to the GUI set? For example.. text input?


therevills(Posted 2013) [#134]
Because of Ziggy's wonderful work on the JungleGUI we kind of stopped Diddy's GUI... you can use Diddy and JungleGUI together.


Goodlookinguy(Posted 2013) [#135]
I used your stand-alone PathFinder code during the recent Ludum Dare. After using it, I feel like I need to say that it's possibly a tad buggy.

Two strange things I saw it do
- Sometimes would walk backwards once and then forward to get to a location
- Sometimes it would randomly walk off into a solid path then would come back down and continue on the normal path

Now, I won't say that it's definitely Diddy's implementation. For all I know, I could have done something wrong unknowingly. However, I messed with my code a lot and was unable to resolve it completely. The best I could do was checking for the path the entity was headed and remove the walking backwards path if it existed.

Also, I should probably mention that it walked backwards even when on a perfectly placed location sometimes. So the issue wasn't just subject to strange inbetween tile locations.

As a last note, thanks for the path finder. I was gonna write my own during the LD, but it saved me time just using this.


therevills(Posted 2013) [#136]
@GLG... any chance you get reproduce it with a small bit of code? Normally you would see that behavior if the "item" hasn't reached its node correctly.


Goodlookinguy(Posted 2013) [#137]
I can try and replicate it in a smaller amount of code later (when I'm home). If you want though, I could send you all of the source code from the game if you have somewhere I can send it.


CGV(Posted 2013) [#138]
What would be the best way to change the images of a SimpleButton after the button is created?


therevills(Posted 2013) [#139]
@GLG - a small version would be great.

@CGV - Hmmmm something like this at the moment would change the main image:
format_code('Local b:SimpleButton = menu.FindButton("options")
Local gi:GameImage = New GameImage
gi.Load(diddyGame.images.path + "newButton.png", False)
b.SetImage(gi)')

Or send in a GameImage to the SetImage method from the ImageBank.

And of course if would wanted to change the mouse over too you would do something similar:
format_code('b.SetImage(gi) ' Main button image
b.imageMouseOver = gi ' Mouse over image')
These images must not be auto-midhandled...


CGV(Posted 2013) [#140]
Thanks, I was trying to do it without creating a new GameImage. DOH!


CGV(Posted 2013) [#141]
I have a general program design question.

Lets say you use the same background image in your titlescreen, gamescreen, etc.

Would it be more efficient, memory wise, to create a global instance of that GameImage to be used by all your screens or just let each screen have it's own instance?


therevills(Posted 2013) [#142]
I think that would depend on the target. If you are targeting a low end Android device having the global image would take up memory throughout your game.

Personally I would have an instance per screen and just release them when moving screens. This would give you flexibility if you decide later that each screen has a different background image in the future.

And if you want to reuse your code in future projects it should be just a simple copy and paste, without worrying about globals.


CGV(Posted 2013) [#143]
Thanks, I guess I had it backwards.

New question:

Is there a way to tell if the music is already playing?

EDIT: In the Flash target in case it matters.


richb(Posted 2013) [#144]
I took a little break our from my main project to put together a quick project to test out Diddy as there's a few things fantomengine doesnt do well and I was interested in using the autofit module used in diddy to avoid black lines on the outside of the screen. I love the simplemenu gui and liked the way the screens works. Only thing I'm stuck with is fonts, Ive used hiero to make bitmap fonts and it works very easily in fantomengine however I'm struggling to use these fonts in diddy. Any idea how I can use these fonts with diddy?


Paul - Taiphoz(Posted 2013) [#145]
For anything font realted you need to look at Ziggy's FontMachine it's perfect and just about everything you need it to do.

It's what I use with all my stuff.


CGV(Posted 2013) [#146]
I use angelcode/bmfont. You'll find an extensive example of usage in bananas.


richb(Posted 2013) [#147]
Yeah, I struggled to use angelfont at first but managed to get it working!


therevills(Posted 2013) [#148]
@CGV
Is there a way to tell if the music is already playing?

Just use the pure Mojo command: MusicState

format_code('Function MusicState : Int ()
Returns 1 if music is currently playing, 0 if music is currently not playing or -1 if music state cannot be determined.')

@richb - I normally use the Ziggy's Font Machine:
http://www.jungleide.com/?page_id=515


Whiteball(Posted 2013) [#149]
Wondering what the best practice is regarding diddy and Tiled tile properties.

Is it possible to set multiple properties on a tile in Tiled map editor and use them within diddy?

If so, whats the best approach code wise to read/use them?

I'm thinking along the lines of storing a 'tile type' and 'trigger' value in the tile and then using them in my player update somewhere. Is that a good idea?


Whiteball(Posted 2013) [#150]
Looking through the diddy tile file and can't really understand why there is tiles and cells. What's the difference?


Samah(Posted 2013) [#151]
A "tile" is the information in the tileset, which allows for custom properties and mapping tiles to a global ID (necessary if tilesets are added and removed).
A "cell" is the information in the map layer, which refers to the tile by its global ID.
This is the way Tiled works.


Whiteball(Posted 2013) [#152]
ok, thanks.
I'll see if I can get something worked out for what I have in mind.


programmer(Posted 2013) [#153]
@therevills
It'll be awesome if you move Diddy to github.com.


Landon(Posted 2013) [#154]
I've added some Object properties loading and fetching to the Diddy tile loader. Just curious if you plan on adding this so i can phase out the bandaid i wrote?


therevills(Posted 2013) [#155]
if you move Diddy to github.com.

We moved to BitBucket the other year and a lot of people were not happy about it so we moved back to Google Code... which I think we will stay.

I've added some Object properties loading and fetching to the Diddy tile loader. Just curious if you plan on adding this so i can phase out the bandaid i wrote?

If you share your code, I code quickly look over it and add it.


programmer(Posted 2013) [#156]
(deleted)


Samah(Posted 2013) [#157]
@Landon: I've added some Object properties loading and fetching to the Diddy tile loader. Just curious if you plan on adding this so i can phase out the bandaid i wrote?

Clone, pull request. :)


rIKmAN(Posted 2013) [#158]
I have just started working on getting z-ordering of sprites working my game, and with the help in this thread I have a basic system using Interfaces.

However, it seems sorting is a little tricky, and after readin around the forum I found quite a few posts regarding IComparator from diddy to do just this, however I can't seem to get my head around it (although in my defence it is 3am here lol!)

I have the following code, using a diddy ArrayList, but I know I am missing something to do with the Compare() Method, and how it should be implemented and used.

The code compiles fine, but the objects flicker continuously when the Sort() Method is called on the list, I think because I haven't defined my own Compare() Methods so it doesn't know what to compare.

I'm a bit stumped also as to how to get this working with Interfaces as I have only tonight (from my linked thread above) started using them.

Here is the code, no graphics required, just diddy.collections.

I am trying to get the zlist sorted by it's y value, which I could then use to draw things in the correct order, but as I said I am unsure as to how to get that working.

The white rect at MouseX()/MouseY() was going to be for me to test the z-ordering working (or not) as I moved the mouse around the screen, and you may need to refresh the page a few times see the flickering between rects/ovals as the x/y positions are random each time but if you move the mouse over any of them you will see it straight away.
format_code('
Strict

Import mojo
Import diddy.collections

' ################################

' Main Function
Function Main:Int()
New myApp
Return True
End

' ################################

' myApp Class
Class myApp Extends App

Field zlist:ArrayList<DrawZ>

' --------------------------------

Method OnCreate:Int()

' create ArrayList
Self.zlist = New ArrayList<DrawZ>

' random seed
Local date:= GetDate()
Seed = date[5] * 1000 + date[6]

' create rects and add to list
For Local a:Int = 0 To 9
Local rect:Rect = New Rect(Rnd(0, 900), Rnd(0, 600),Rnd(50,100))
Self.zlist.AddLast(rect)
Next
DebugLog "ListCount after Rects: " + zlist.Size()

' create ovals and add to list
For Local a:Int = 0 To 9
Local oval:Oval = New Oval(Rnd(0, 900), Rnd(0, 600), Rnd(50, 100))
Self.zlist.AddLast(oval)
Next
DebugLog "ListCount after Ovals: " + Self.zlist.Size()

' create mouseObj and add to list
Local mo:MouseObj = New MouseObj
Self.zlist.AddLast(mo)
DebugLog "ListCount after MouseObj: " + Self.zlist.Size()

SetUpdateRate(60)
Return True
End

' --------------------------------

Method OnUpdate:Int()

' Update all objects
For Local obj:= EachIn Self.zlist
obj.Update()
Next

'
'##############

' Sorting here makes them flicker.
' I'm also not sure what is being sorted?

Self.zlist.Sort()

'#############

Return True
End Method

' --------------------------------

Method OnRender:Int()
Cls

' draw objects from list
For Local o:DrawZ = EachIn Self.zlist
o.Draw()
Next

Return True
End Method

End

' ################################

' Interface
Interface DrawZ
Method GetName:String()
Method Update:Void()
Method Draw:Void()
End

' ################################

' MouseObj Class
Class MouseObj Implements DrawZ

Field name:String
Field x:Int
Field y:Int

' --------------------------------

Method New()
Self.name = "MouseObj"
Self.x = MouseX()
Self.y = MouseY()
End

' --------------------------------

Method Update:Void()
Self.x = MouseX()
Self.y = MouseY()
End

' --------------------------------

Method Draw:Void()
SetColor 255, 255, 255
DrawRect Self.x, Self.y, 50, 50
End

' --------------------------------

Method GetName:String()
Return Self.name
End

' --------------------------------

End

' ################################

' Rect Class
Class Rect Implements DrawZ

Field name:String
Field x:Int
Field y:Int
Field size:Int

' --------------------------------

Method New(x:Int, y:Int, size:Int)

Self.name = "Rect"
Self.x = x
Self.y = y
Self.size = size

End Method

' --------------------------------

Method Update:Void()

End Method

' --------------------------------

Method Draw:Void()
SetColor 200, 0, 0
DrawRect Self.x, Self.y, Self.size, Self.size
End

' --------------------------------

Method GetName:String()
Return Self.name
End

End

' ################################

' Oval Class
Class Oval Implements DrawZ

Field name:String
Field x:Int
Field y:Int
Field radius:Int

' --------------------------------

Method New(x:Int, y:Int, radius:Int)

Self.name = "Oval"
Self.x = x
Self.y = y
Self.radius = radius
End

' --------------------------------

Method Update:Void()

End

' --------------------------------

Method Draw:Void()
SetColor 0, 200, 0
DrawOval Self.x, Self.y, Self.radius, Self.radius
End

' --------------------------------

Method GetName:String()
Return Self.name
End

End
')
Where would I Implement IComparator in this code, and where would the associated Compare() Methods go to allow me to sort by y value?
I can't seem to get it working so I took all references out in the above code to make it easier for anyone to spot where I should be putting them.

Thanks in advance.


Samah(Posted 2013) [#159]
I've modified your example to sort by Y value. Note that I had to make the Y value available in the DrawZ interface. I think you'd be better off making DrawZ an abstract class and put your Y value in there along with the comparison methods.

format_codebox('Strict

Import mojo
Import diddy.collections

' ################################

' Main Function
Function Main:Int()
New myApp
Return True
End

' ################################

' myApp Class
Class myApp Extends App

Field zlist:ArrayList<DrawZ>

' --------------------------------

Method OnCreate:Int()

' create ArrayList
Self.zlist = New ArrayList<DrawZ>

' random seed
Local date:= GetDate()
Seed = date[5] * 1000 + date[6]

' create rects and add to list
For Local a:Int = 0 To 9
Local rect:Rect = New Rect(Rnd(0, 900), Rnd(0, 600),Rnd(50,100))
Self.zlist.AddLast(rect)
Next
DebugLog "ListCount after Rects: " + zlist.Size()

' create ovals and add to list
For Local a:Int = 0 To 9
Local oval:Oval = New Oval(Rnd(0, 900), Rnd(0, 600), Rnd(50, 100))
Self.zlist.AddLast(oval)
Next
DebugLog "ListCount after Ovals: " + Self.zlist.Size()

' create mouseObj and add to list
Local mo:MouseObj = New MouseObj
Self.zlist.AddLast(mo)
DebugLog "ListCount after MouseObj: " + Self.zlist.Size()

SetUpdateRate(60)
Return True
End

' --------------------------------

Method OnUpdate:Int()

' Update all objects
For Local obj:= EachIn Self.zlist
obj.Update()
Next

'
'##############

' Sorting here makes them flicker.
' I'm also not sure what is being sorted?

Self.zlist.Sort()

'#############

Return True
End Method

' --------------------------------

Method OnRender:Int()
Cls

' draw objects from list
For Local o:DrawZ = EachIn Self.zlist
o.Draw()
Next

Return True
End Method

End

' ################################

' Interface
Interface DrawZ Extends IComparable
Method GetY:Int()
Method GetName:String()
Method Update:Void()
Method Draw:Void()
End

' ################################

' MouseObj Class
Class MouseObj Implements DrawZ

Field name:String
Field x:Int
Field y:Int

' --------------------------------

Method New()
Self.name = "MouseObj"
Self.x = MouseX()
Self.y = MouseY()
End

' --------------------------------

Method Update:Void()
Self.x = MouseX()
Self.y = MouseY()
End

' --------------------------------

Method Draw:Void()
SetColor 255, 255, 255
DrawRect Self.x, Self.y, 50, 50
End

' --------------------------------

Method GetName:String()
Return Self.name
End

Method GetY:Int()
Return y
End

' --------------------------------
Method Compare:Int(o:Object)
Local d:DrawZ = DrawZ(o)
Return y - d.GetY()
End

Method Equals:Bool(o:Object)
Return Compare(o) = 0
End
End

' ################################

' Rect Class
Class Rect Implements DrawZ

Field name:String
Field x:Int
Field y:Int
Field size:Int

' --------------------------------

Method New(x:Int, y:Int, size:Int)

Self.name = "Rect"
Self.x = x
Self.y = y
Self.size = size

End Method

' --------------------------------

Method Update:Void()

End Method

' --------------------------------

Method Draw:Void()
SetColor 200, 0, 0
DrawRect Self.x, Self.y, Self.size, Self.size
End

' --------------------------------

Method GetName:String()
Return Self.name
End

Method GetY:Int()
Return y
End

' --------------------------------
Method Compare:Int(o:Object)
Local d:DrawZ = DrawZ(o)
Return y - d.GetY()
End

Method Equals:Bool(o:Object)
Return Compare(o) = 0
End
End

' ################################

' Oval Class
Class Oval Implements DrawZ

Field name:String
Field x:Int
Field y:Int
Field radius:Int

' --------------------------------

Method New(x:Int, y:Int, radius:Int)

Self.name = "Oval"
Self.x = x
Self.y = y
Self.radius = radius
End

' --------------------------------

Method Update:Void()

End

' --------------------------------

Method Draw:Void()
SetColor 0, 200, 0
DrawOval Self.x, Self.y, Self.radius, Self.radius
End

' --------------------------------

Method GetName:String()
Return Self.name
End

Method GetY:Int()
Return y
End

' --------------------------------
Method Compare:Int(o:Object)
Local d:DrawZ = DrawZ(o)
Return y - d.GetY()
End

Method Equals:Bool(o:Object)
Return Compare(o) = 0
End
End')


rIKmAN(Posted 2013) [#160]
Samah thank you!

I was banging my head last night with this trying all sorts and couldn't seem to get it working - your modified code makes it very clear.

I'm not sure how I'd go about the abstract class thing along with interfaces, as I have only just started using interfaces last night and am still learning as I go with the more advanced concepts.

I think as it is working as-is right now I will stick with it and do some homework about the things you mention.

Thanks again for the help, most appreciated :)


Samah(Posted 2013) [#161]
Here's another version using a Comparator instead of implementing IComparable. It means less duplication of code.

format_codebox('Strict

Import mojo
Import diddy.collections

' ################################

' Main Function
Function Main:Int()
New myApp
Return True
End

' ################################

' myApp Class
Class myApp Extends App

Field zlist:ArrayList<DrawZ>

' --------------------------------

Method OnCreate:Int()

' create ArrayList
Self.zlist = New ArrayList<DrawZ>
Self.zlist.Comparator = New ZOrderComparator

' random seed
Local date:= GetDate()
Seed = date[5] * 1000 + date[6]

' create rects and add to list
For Local a:Int = 0 To 9
Local rect:Rect = New Rect(Rnd(0, 900), Rnd(0, 600),Rnd(50,100))
Self.zlist.AddLast(rect)
Next
DebugLog "ListCount after Rects: " + zlist.Size()

' create ovals and add to list
For Local a:Int = 0 To 9
Local oval:Oval = New Oval(Rnd(0, 900), Rnd(0, 600), Rnd(50, 100))
Self.zlist.AddLast(oval)
Next
DebugLog "ListCount after Ovals: " + Self.zlist.Size()

' create mouseObj and add to list
Local mo:MouseObj = New MouseObj
Self.zlist.AddLast(mo)
DebugLog "ListCount after MouseObj: " + Self.zlist.Size()

SetUpdateRate(60)
Return True
End

' --------------------------------

Method OnUpdate:Int()

' Update all objects
For Local obj:= EachIn Self.zlist
obj.Update()
Next

'
'##############

' Sorting here makes them flicker.
' I'm also not sure what is being sorted?


Self.zlist.Sort()

'#############

Return True
End Method

' --------------------------------

Method OnRender:Int()
Cls

' draw objects from list
For Local o:DrawZ = EachIn Self.zlist
o.Draw()
Next

Return True
End Method

End

' ################################

' Interface
Interface DrawZ
Method GetY:Int()
Method GetName:String()
Method Update:Void()
Method Draw:Void()
End

' ################################

' MouseObj Class
Class MouseObj Implements DrawZ

Field name:String
Field x:Int
Field y:Int

' --------------------------------

Method New()
Self.name = "MouseObj"
Self.x = MouseX()
Self.y = MouseY()
End

' --------------------------------

Method Update:Void()
Self.x = MouseX()
Self.y = MouseY()
End

' --------------------------------

Method Draw:Void()
SetColor 255, 255, 255
DrawRect Self.x, Self.y, 50, 50
End

' --------------------------------

Method GetName:String()
Return Self.name
End

Method GetY:Int()
Return y
End
End

' ################################

' Rect Class
Class Rect Implements DrawZ

Field name:String
Field x:Int
Field y:Int
Field size:Int

' --------------------------------

Method New(x:Int, y:Int, size:Int)

Self.name = "Rect"
Self.x = x
Self.y = y
Self.size = size

End Method

' --------------------------------

Method Update:Void()

End Method

' --------------------------------

Method Draw:Void()
SetColor 200, 0, 0
DrawRect Self.x, Self.y, Self.size, Self.size
End

' --------------------------------

Method GetName:String()
Return Self.name
End

Method GetY:Int()
Return y
End
End

' ################################

' Oval Class
Class Oval Implements DrawZ

Field name:String
Field x:Int
Field y:Int
Field radius:Int

' --------------------------------

Method New(x:Int, y:Int, radius:Int)

Self.name = "Oval"
Self.x = x
Self.y = y
Self.radius = radius
End

' --------------------------------

Method Update:Void()

End

' --------------------------------

Method Draw:Void()
SetColor 0, 200, 0
DrawOval Self.x, Self.y, Self.radius, Self.radius
End

' --------------------------------

Method GetName:String()
Return Self.name
End

Method GetY:Int()
Return y
End
End

Class ZOrderComparator Extends IComparator
Method Compare:Int(o1:Object, o2:Object)
If Not DrawZ(o1) Or Not DrawZ(o2) Then Return 0
Return DrawZ(o1).GetY() - DrawZ(o2).GetY()
End
End')


therevills(Posted 2013) [#162]
And for completeness, plus I'd prefer using a base object as it would save a lot of duplicate fields and methods:

format_codebox('Strict

Import mojo
Import diddy.collections

Function Main:Int()
New Game
Return True
End

Class Game Extends App
Method OnCreate:Int()
Local date:= GetDate()
Seed = date[5] * 1000 + date[6]

For Local a:Int = 0 To 9
GameObject.list.AddLast(New Rect(Rnd(0, 900), Rnd(0, 600),Rnd(50,100)))
Next

For Local a:Int = 0 To 9
GameObject.list.AddLast(New Oval(Rnd(0, 900), Rnd(0, 600), Rnd(50, 100)))
Next

GameObject.list.AddLast(New MouseObj)
GameObject.list.AddLast(New CursorObj)

SetUpdateRate(60)
Return True
End

Method OnUpdate:Int()
GameObject.UpdateAll()
GameObject.list.Sort()
Return True
End

Method OnRender:Int()
Cls
GameObject.DrawAll()
Return True
End
End

Class GameObject Implements IComparable Abstract
Global list:ArrayList<GameObject> = New ArrayList<GameObject>
Field name:String
Field x:Int, y:Int

Method Draw:Void() Abstract
Method Update:Void() Abstract

Method GetName:String()
Return Self.name
End

Method Compare:Int(o:Object)
Local d:GameObject = GameObject(o)
Return y - d.y
End

Method Equals:Bool(o:Object)
Return Compare(o) = 0
End

Function UpdateAll:Void()
For Local o:GameObject = Eachin GameObject.list
o.Update()
Next
End

Function DrawAll:Void()
For Local o:GameObject = Eachin GameObject.list
o.Draw()
Next
End
End

Class MouseObj Extends GameObject
Method Update:Void()
Self.x = MouseX()
Self.y = MouseY()
End

Method New()
Self.name = "Mouse"
End

Method Draw:Void()
SetColor 255, 255, 255
DrawRect Self.x, Self.y, 50, 50
End
End

Class CursorObj Extends GameObject
Method Update:Void()
Local speed:Int = 1
If KeyDown(KEY_SHIFT)
speed = 10
End
If KeyHit(KEY_UP)
y -= speed
End
If KeyHit(KEY_DOWN)
y += speed
End
If KeyHit(KEY_LEFT)
x -= speed
End
If KeyHit(KEY_RIGHT)
x += speed
End
End

Method New()
Self.name = "CursorObj"
End

Method Draw:Void()
SetColor 255, 0, 255
DrawRect Self.x, Self.y, 50, 50
End
End

Class Rect Extends GameObject
Field size:Int

Method New(x:Int, y:Int, size:Int)
Self.name = "Rect"
Self.x = x
Self.y = y
Self.size = size
End

Method Update:Void()
End

Method Draw:Void()
SetColor 200, 0, 0
DrawRect Self.x, Self.y, Self.size, Self.size
End
End

Class Oval Extends GameObject
Field radius:Int

Method New(x:Int, y:Int, radius:Int)
Self.name = "Oval"
Self.x = x
Self.y = y
Self.radius = radius
End

Method Update:Void()
End

Method Draw:Void()
SetColor 0, 200, 0
DrawOval Self.x, Self.y, Self.radius, Self.radius
End
End')


rIKmAN(Posted 2013) [#163]
Ahh awesome thanks Samah & therevills!

The abstract stuff is a little over my head at the moment, but I will do some homework and study the code you kindly posted and get my head around it.

Thanks again :)


therevills(Posted 2013) [#164]
To help people download the latest version I have added a screenshot showing where the zip link can be located on Google Code:




Paul - Taiphoz(Posted 2013) [#165]
Not gotten an update in a while, gona go grab one now, has there been anything interesting added over the last 3 months?

and have you made the debug renderer take on the scaling from auto fit yet?


Paul - Taiphoz(Posted 2014) [#166]
Samah, has anyone reported any issues with playing Music ?

I'm currently having some issues with playing music on html5, I have ogg, wav, and mp3 versions to try with and it just does not want to play, MusicState reports its playing but zero sound.

Also I seem to have a problem with FileSystem, it's saving fine on html5 and I think if I recall it saved on my phone as well, but it does not seem to be saving possibly or loading on flash..

in the mean time I will grab the very latest build just to be sure, if you don't hear from me assume I still have the above issues.

EDIT : adding my load and save methods in case its something there.

format_code('
Method Load:Void()
Local filein:FileStream
Local filehandler:FileSystem
filehandler = FileSystem.Create()

If filehandler.FileExists("options.dat")
filein = filehandler.ReadFile("options.dat")
if filein
Self.musicVolume = filein.ReadInt()
Self.soundVolume = filein.ReadInt()
Self.graphicsDetail = filein.ReadInt()
Self.graphicsGlow = filein.ReadInt()
End If

Else
Self.Save()
EndIf
End Method



Method Save:Void()
Local fileout:FileStream
Local filehandler:FileSystem
filehandler = FileSystem.Create()

fileout = filehandler.WriteFile("options.dat")
'Self.PrintVolumes()
fileout.WriteInt(Self.musicVolume)
fileout.WriteInt(Self.soundVolume)
fileout.WriteInt(Self.graphicsDetail)
fileout.WriteInt(Self.graphicsGlow)
'Self.PrintVolumes()
filehandler.SaveAll()
End Method
')


therevills(Posted 2014) [#167]
Paul any change of having runnable examples of your issues?


Paul - Taiphoz(Posted 2014) [#168]
Here is the really annoying thing, I cant. with a pure clean diddy template it works, whats even more annoying is that my project's had Zero sound for a month, I have literally only just added a few sounds, and then tried to add this first music track so I should have no code at all thats doing anything with sound other than about 5 lines in total and I cant figure out why its not playing the audio.

I was thinking it might be something with channel volumes so I have removed my 3 lines where I set the current volume equal to whats in my options. no joy!.
I was then thinking that it was diddy or its playmusic wrapper so I switched to mojo playmusic and the results the same, channelstate reports it is playing tho which is just wierd.

not sure what to try next, I am sure its something with diddy tho just cant put my finger on what.

Also any thoughts on why the save data isnt saving in flash ? it could be related.


Paul - Taiphoz(Posted 2014) [#169]
sometimes I really hate trying to debug crap in monkey, really does my tits in.

Ok wrap your head around this little conundrum.

My Project Code works on [ flash , glfw, android ] --- music plays from IE but not Chrome in Html5.
My Test Code works on EVERYTHING.. including Chrome.

WTF is up with that, the code is the same, so why the hell wont chrome play the damn music from my big project but it will from my skeleton code, whats really fekking me off is that it works on everything else, even IE has no issues with playing the song but chrome... oh no its to good to play my music ..

lol can you detect my frustration ?


Paul - Taiphoz(Posted 2014) [#170]
EDIT :: The problem is caused by Chrome + AdBlock , even telling AdBlock that localhost is cool it still causes issues, so this was not a diddy issue as I first had thought.


therevills(Posted 2014) [#171]
Well that's good to know :)

With you flash file saving issue, how much data are you saving? The FileSystem just wraps SaveState... I do remember people having issues using SaveState and having different results per platform.


Paul - Taiphoz(Posted 2014) [#172]
It looks like AdBlock could have been the cause there as well, as Flash saving is working fine now that I have made exceptions for the test page, its odd tho for sure.

At least now I am confident that diddy is not the cause which is cool :)


therevills(Posted 2014) [#173]
Wow that totally messed you up! I still don't get why a skeleton code played the music though O_o


Paul - Taiphoz(Posted 2014) [#174]
Ah yeah it didn't, lol I just didn't notice it was building flash and not html5.


therevills(Posted 2014) [#175]
Just committed a few changes:

* Added a "Load" method to Screen, so now you can do all your loading for your screens in this method. This is called internally within PreStart so it happens after the FadeOut of the last screen and before the FadeIn of the next.
* Added a safety for delta timing, if it ever goes over 5 Diddy now will reset it back to 1 - I found when loading resources the delta timing was flying out of control due to the IO


Timber(Posted 2014) [#176]
Quick question, if I have a few tile sheets that I then Pack via LibDGX and I want to load them into diddy what would be the best way to go about it.
I was told that I should load the atlas and then take any of those smaller animstrips and use grabimage on them to put them into a frame format, is that the best way or does diddy have a way of doing it that's better.


rIKmAN(Posted 2014) [#177]
deleted, apologies.


therevills(Posted 2014) [#178]
@Timber, Diddy supports the following texture packager formats:
* Sparrow
* LibDGX
* JSON (HASH)

So if you have got the LibDGX file you should be able to do something like this:
format_code('images.LoadAtlas("libgdx_sprites.txt", images.LIBGDX_ATLAS)')
Diddy will then grab the images from the file and store them into the image bank for future reference.


Paul - Taiphoz(Posted 2014) [#179]
Timber's my son, what he was trying to ask is, if he packs 4 images into an Atlas each being a strip of 32*32 frames, once he uses the diddy loadatlas method how does he render the frames from say image1.

I told him to have a look at GrabImage, with the intention being to load the Atlas, find the Image and then GrabImage the tileset out of it, but being my son he does not listen to me, AT ALL!. he seems to be convinced that its something diddy might do.


therevills(Posted 2014) [#180]
Keeping it in the family :) Good job!

Just so I've got this straight, Timber has 4 image files which contains multiple images (basically AnimImages) and he has packed them into one atlas file?

If so, when Diddy loads the atlas it will store the name of each image based off the file name stored in the atlas and when you need to get them you would get the whole anim image - but Diddy does have a FindSet command which should work.

Heres a quick example:
format_codebox('Strict

Import diddy

Function Main:Int()
New MyGame()
Return True
End

Global scr:Screen1

Class MyGame Extends DiddyApp
Method Create:Void()
LoadImages()
scr = New Screen1
Start(scr)
End

Method LoadImages:Void()
images.LoadAtlas("test.xml", images.SPARROW_ATLAS)
End
End

Class Screen1 Extends Screen
Field img1:GameImage
Field img2:GameImage
Field img3:GameImage

Field set:GameImage
Field rotation:Int
Field scaleX:Int = 1
Field scaleY:Int = 1
Field frame:Int
Field maxFrame:Int = 3
Field delay:float
Field maxDelay:Int = 15

Method New()
name = "Screen1"
backScreenName = "exit"
End

Method Load:Void()
End

Method Start:Void()
img1 = diddyGame.images.Find("1")
img2 = diddyGame.images.Find("2")
img3 = diddyGame.images.Find("3")

' grab the "3" animimage from the atlas, 32 x 32 with 4 frames
set = diddyGame.images.FindSet("3", 32, 32, 4)
End

Method Render:Void()
Cls
img1.Draw(100,20)
img2.Draw(100,50)
img3.Draw(100,80)

set.Draw(200, 200, rotation, scaleX, scaleY, frame)
End

Method Update:Void()
' quick crappy animation
delay += 1 * dt.delta
If delay > maxDelay
frame += 1
If frame > maxFrame
frame = 0
End
delay = 0
End

If KeyHit(KEY_ESCAPE)
Self.Back()
End
End
End')

https://dl.dropboxusercontent.com/u/35103024/monkey/atlastest/html5/MonkeyGame.html


Derron(Posted 2014) [#181]
I did not read all 7 parts of this thread - but I just tried the current Diddy-revision with Monkey-X 77a for Linux.

format_code('
../main.cpp:3998:21: fatal error: windows.h: No such file or directory
#include <windows.h>
^
compilation terminated.
make: *** [../main.o] Error 1
TRANS FAILED: Error executing 'make CCOPTS="-Wno-free-nonheap-object -O3 -DNDEBUG" OUT="Release/MonkeyGame"', return code=512
')

Normal Monkey-Samples don't have this error (but other warnings) - is Diddy using windows-specific stuff when compiling for GLFW?


bye
Ron


therevills(Posted 2014) [#182]
Hey Ron - Diddy was created before MonkeyX officially support Linux and I'm not a Linux guy ;)

Anyway I've just committed a change which will hopefully allow you to compile in Linux, could you please let me know:
http://code.google.com/p/diddy/source/list


Derron(Posted 2014) [#183]
Thanks for the fast response.

Copied the changed file. Result is now:

format_codebox('
"/home/ronny/Arbeit/Programmieren/MonkeyX77a/bin/transcc_linux" -target=Desktop_Game -config=Release -run "/home/ronny/Arbeit/Programmieren/MonkeyX77a/modules/diddy/examples/Storyboard/storyboardTest.monkey"
TRANS monkey compiler V1.62
Parsing...
Semanting...
Translating...
Building...
g++ -Wno-free-nonheap-object -O3 -DNDEBUG -I../glfw/include -I../glfw/lib -I../glfw/lib/x11 -I../openal/include -I../stb -D_GLFW_HAS_GLXGETPROCADDRESS -D_GLFW_USE_LINUX_JOYSTICKS -pthread -c -o ../main.o ../main.cpp
../main.cpp: In static member function ‘static int diddy::getDayOfMonth()’:
../main.cpp:4145:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4145:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4146:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4146:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In static member function ‘static int diddy::getDayOfWeek()’:
../main.cpp:4152:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4152:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4153:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4153:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In static member function ‘static int diddy::getMonth()’:
../main.cpp:4159:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4159:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4160:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4160:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In static member function ‘static int diddy::getYear()’:
../main.cpp:4166:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4166:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4167:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4167:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In static member function ‘static int diddy::getHours()’:
../main.cpp:4173:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4173:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4174:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4174:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In static member function ‘static int diddy::getMinutes()’:
../main.cpp:4180:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4180:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4181:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4181:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In static member function ‘static int diddy::getSeconds()’:
../main.cpp:4187:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4187:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4188:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4188:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In static member function ‘static int diddy::getMilliSeconds()’:
../main.cpp:4194:3: error: ‘SYSTEMTIME’ was not declared in this scope
SYSTEMTIME st;
^
../main.cpp:4194:14: error: expected ‘;’ before ‘st’
SYSTEMTIME st;
^
../main.cpp:4195:18: error: ‘st’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp:4195:20: error: ‘GetSystemTime’ was not declared in this scope
GetSystemTime(&st);
^
../main.cpp: In function ‘void skipBytes(int, FILE*)’:
../main.cpp:2104:18: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
fread( p,n,1,f );
^
../main.cpp: In member function ‘virtual void BBGlfwGame::OpenUrl(String)’:
../main.cpp:2359:66: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
system( ( String( "xdg-open \"" )+url+"\"" ).ToCString<char>() );
^
make: *** [../main.o] Error 1
TRANS FAILED: Error executing 'make CCOPTS="-Wno-free-nonheap-object -O3 -DNDEBUG" OUT="Release/MonkeyGame"', return code=512
Done.
')


edit: SYSTEMTIME is windows-only too ... so this i also a showstopper atm.

bye
Ron


therevills(Posted 2014) [#184]
Thanks Ron - This actually reminded me to remove the date/time functions from the native code in Diddy, since Monkey now has its own date/time functions.

I've pushed another version, could you try again :)


Derron(Posted 2014) [#185]
Hmmm how to say it without making you crying...

...it....

...it works now :D

Sure, there are some warnings left (because of the unused-warning-flag) but they are in the main.cpp so it is a flaw in Monkey-X I think.


bye
Ron


therevills(Posted 2014) [#186]
Excellent - thanks again for testing this Ron :)


Raz(Posted 2014) [#187]
Not looked at Diddy in a while but crumbs, it's impressive these days! (not that it wasn't before!)


therevills(Posted 2014) [#188]
Question regarding animations... would you expect that a ping pong animation display the last frame twice?

For example if there was a 4 frame animation looping ping pong would be in the following sequence:
1 2 3 4 4 3 2 1 1 2 3 4 4 3 2 1 etc

Or just once:
1 2 3 4 3 2 1 2 3 4 3 2 1 etc

Or should I add a flag so the user can decide?

BTW I committed the Admob Interstitial (Android only) module to Diddy too.


Raz(Posted 2014) [#189]
I would expect

1 2 3 4 3 2 1 2 3 4 3 2 1

instead of

1 2 3 4 4 3 2 1 1 2 3 4 4

personally. But if it's doable, I would say letting the user decide would be best.


Paul - Taiphoz(Posted 2014) [#190]
For a Ping Pong animation I would say that it needs to be the same frame as the first so [ 1 2 3 4 3 2 1 ] I would not double up frames at the start or the end.


Paul - Taiphoz(Posted 2014) [#191]
Also therevills this thread is epic I think it's time you slay it and spawn a new one. 190 posts is a bit much for people to troll through.


Hotshot(Posted 2014) [#192]
Where the Diddy Document where I can look at the commands?


therevills(Posted 2014) [#193]
I would say letting the user decide would be best.

Yeah I thinking the same, just wanted to see what other people thought :)

190 posts is a bit much for people to troll through.

Yep! I nearly did start a Part 8... but thought it wasnt needed now since MonkeyX site has pages...

Where the Diddy Document where I can look at the commands?

You can find some here:
http://code.google.com/p/diddy/w/list
And here:
http://diddy.googlecode.com/hg/src/diddy/.docs/index.html


Samah(Posted 2014) [#194]
Just removed the requirement for "tmpImage" when using the LoadAnim method; it's now optional and defaults to Null.


Paul - Taiphoz(Posted 2014) [#195]
The pageation is that a word?, is fine for small threads but to be honest it's poorly designed, it's only showing 3 pages at a time, if you start at post one your still needing to click a few times to flick through all the pages, the arrows jump to the start and end but if your looking for something in the middle its far less functional, the deeper the thread gets in terms of pages the worse this will get.


Samah(Posted 2014) [#196]
Need some opinions here.

I made some cool classes that extend Stack/List/Set that all implement a common interface and provide pretty much the same functionality as ArrayList. Should I include this into Diddy? (as an optional import, not necessarily as a replacement for ArrayList)

Pros:
They're mostly interchangeable with the default Monkey Stack/List/Set classes.
Has most of the functionality of ArrayList, including all the Comparable/Comparator magic.
The classes all share one set of methods, so you don't have to remember which Monkey class uses Count(), which uses Size(), etc. (standards, Mark?)
Nowhere near as heavy as ArrayList (think 20% of the codebase).

Cons:
The rest of Diddy would still use ArrayList (for now), unless I retroactively changed them all. Ultimately it would make your code way cleaner, but when you first update Diddy, anywhere you're pulling ArrayLists from the Diddy modules (think XML, storyboards, etc.) is going to break. Trivial to fix though.

If I push it, I'll probably branch it and leave the "default" branch clean. If it becomes popular and stable I might look at merging it back into the mainline (far down the track).

Thoughts?


Paul - Taiphoz(Posted 2014) [#197]
What is it that the arraylists are doing that your new hero class does not, if you can do some helper methods that handle what ever that extra thing is, and make them 100% interchangeable then it would be a lot easier for you to just find replace all your arraylists into this new thing, and then just make the arraylist a helper for the new class, that way no ones code breaks, their all using the new class behind the scenes and can when their ready switch on their own ?


Samah(Posted 2014) [#198]
The main point of the new class is that because it extends Stack, you can plug it into any other frameworks that expect a Stack argument or field. Also smaller codebase, since it uses Monkey's own Stack implementation (which works essentially the same way as ArrayList). It still provides all the extra functionality ArrayList has (such as AddAll to add everything from one Stack).
It's possible that I could retrofit ArrayList to use the new class as its internal implementation, and only keep references to ArrayList in public methods/fields (the beauty of encapsulation). I don't really see the point in it though, because any ArrayList overhead would still be there.
What I might do is create all the new classes on the default branch (in a separate module file), but do the integration on another branch. That way the new classes are immediately available for developers, and when they're ready they can switch to the other branch and migrate their code to strip out all references to ArrayList (since the rest of the framework would no longer use it).

Edit:
Having a lot of name clashes trying to import it, since it reuses the names of things like IEnumerator (an interface in the new one, an abstract class in the old one). I had to rename the new ICollection to IContainer. Not sure if I'm happy with that one.
It's looking more and more like I should just branch the whole enhancement and make a wiki page on how to migrate. I can put in a #Error if you try to import collections, outputting a link to the wiki. Again, this is all (for now) optional, if you just stay on the default branch.


Samah(Posted 2014) [#199]
Alright, code is pushed as branch "containers". Do your worst. :)
The library itself compiles alright (tested using #REFLECTION_FILTER="*") and I'm pretty sure all the functionality is correct.
I haven't finished testing all of the examples yet, so there's a possibility they might not compile. Converting your code is pretty simple though. I'll put up a wiki page at some point.

http://code.google.com/p/diddy/source/browse/?name=containers
http://diddy.googlecode.com/archive/containers.zip

Edit:
Important changes:
* Importing either of the collections or comparator modules will now throw a compile #Error
* DiddyDataLayers and DiddyDataObjects now extend DiddyStack instead of ArrayList.
* DiddyDataLayers.Find and DiddyDataObjects.Find have been renamed to FindLayer and FindObject respectively due to a naming conflict with Find.
* QuickSort has changed to use the new IComparator and IComparable interfaces.
* IEnumerator does not currently support the HasPrevious/PreviousObject methods that the old one did.
* Some public fields that were ArrayLists are now DiddyStacks: GameSound.loopChannelList, TileMap.layers, TileMapTileset.tileNodes, TileMapObjectLayer.objects
* Some public methods and properties that returned ArrayLists now return DiddyStacks:
gui: Component.Children, Component.ChildrenZOrder, RadioGroup.RadioButtons
psystem: ParticleSystem.Groups, ParticleSystem.Emitters, Emitter.DeathEmitterLinks, ParticleGroup.Forces
storyboard: Storyboard.Sprites, Storyboard.Effects, Storyboard.Sounds, Storyboard.Musics
tile: TileMap.GetAllObjects
xml: XMLDocument.Prologs, XMLDocument.ProcessingInstructions, XMLElement.GetChildrenByName, XMLElement.Children


therevills(Posted 2014) [#200]
Work-In-Progress True Type Font Loader for Android has been pushed... More info in the Monkey Code forum.

http://www.monkeycoder.co.nz/Community/posts.php?topic=8190


Htbaa(Posted 2014) [#201]
I just mailed this to therevills and then found this topic. So maybe it's better to ask here. It's about using diddydata.

I tried to compile the diddydata example, but after a while it just stops compiling due to some memory issue (what's with the compiling time in Monkey anyway? Even on a fast i7 it takes a long time to compile something).

Anyway, the Wiki page is very straightforward on how to use diddydata.xml and how to setup screens. However, I've located my screens in a subfolder called screen/, e.g. screen/titlescreen.monkey. When trying to load the screen I get a memory access violation because the ClassInfo object is empty.

In my xml file I've tried setting the class to TitleScreen (name of the class) and screen.TitleScreen, but it doesn't make any difference. Is there a way to support screens located in subfolders? I've already imported the files in my main app.

PS: I just tried it with moving the TitleScreen class to my main app source file and even then I ran into the issue that the ClassInfo object was empty.


therevills(Posted 2014) [#202]
Due to the way Monkey generates the code for reflections, we are thinking about removing the screen part from DiddyData and only using DiddyData for resources. So for the time being it is recommended to only use DiddyData for images and sounds.


Paul - Taiphoz(Posted 2014) [#203]
What was the screen part used for, just trying to think if I ever used it.


therevills(Posted 2014) [#204]
What was the screen part used for, just trying to think if I ever used it.


The idea was that you could setup your screens as well as resources within XML:
format_code('<diddy screenWidth="800" screenHeight="600" useAspectRatio="true">
<global>
<resources>
<images>
<image path="sprites/Ship1.png" name="Ship" width="64" height="64" frames="7" />
</images>
<sounds>
<sound path="Firelaser" name="fire" soundDelay="100" ignoreCache="false" />
</sounds>
</resources>
</global>
<screens>
<screen class="TitleScreen" name="Title">
<resources>
<images>
<image path="sprites/sword.png" />
</images>
<music path="NewsTheme.ogg" />
</resources>
</screen>
<screens>
')

So this would create the TitleScreen for you via XML, but the amount of reflection which is needed kills compile time. It was a nice idea, but I havent used it myself since we created it ;)


Htbaa(Posted 2014) [#205]
Thanks, I'll stay clear from it then :-). Does defining resources in screen sections still make sense then or should it all be in the global section?


therevills(Posted 2014) [#206]
I've decided to have another go at Diddy Data... in your code did you have the #REFLECTION_FILTER?

I have just pushed a small update which fixes drawing negative layers - could you try the example?


Htbaa(Posted 2014) [#207]
Where do I put this #REFLECTION_FILTER? I don't know what it is.


therevills(Posted 2014) [#208]
Where do I put this #REFLECTION_FILTER? I don't know what it is.


I've updated the wiki:
http://code.google.com/p/diddy/wiki/DiddyData

and the example code:
http://diddy.googlecode.com/hg-history/14a0d37cedb323f3ff4241174fc83ebb7f1a2f3e/examples/DiddyData/diddydata_example.monkey

Check out the docs for reflection:
http://www.monkeycoder.co.nz/docs/html/Modules_reflection.html

In addition, you must provide a 'reflection filter' to specify which modules are to be reflected. This is done using the REFLECTION_FILTER app config setting, which should contain the set of modules you want to be reflected. In addition, the reflection filter may use the '*' wildcard character to match 'any text' in a module path.



Htbaa(Posted 2014) [#209]
Ah thanks. I decided to not define the screens inside the diddydata.xml file. By the way, an exception is thrown if the XML file misses the <screens /> element. Also, in the example on that wiki page you refer to 'game'. Shouldn't that be diddyGame?


ziggy(Posted 2014) [#210]
In the reflection docs it is not mentioned than you can reflect "current" file by just adding this reflection filter to the file:
format_code('#REFLECTION_FILTER+="${MODPATH}"')
That's a good way to set the file reflection filter, so it is consisten no matter in what path the file is saved and no mather if the file is renamed in the futere. It's a sort of "reflect me" directive.
So any file containing code that needs to be reflected, should be good by adding the aforementioned compiler directive.


Samah(Posted 2014) [#211]
Turns out the layer rendering problem was due to a performance change I made with QuickSort/ArrayList which broke sorting. I backed out those changesets and it seems all good now.

Samah


therevills(Posted 2014) [#212]
By the way, an exception is thrown if the XML file misses the <screens /> element.

Fixed - thanks for letting us know. It is now optional.
Also, in the example on that wiki page you refer to 'game'. Shouldn't that be diddyGame?

Yep, we updated the main "game" object awhile ago and haven't updated all of the docs.

In the reflection docs it is not mentioned than you can reflect "current" file by just adding this reflection filter to the file:
#REFLECTION_FILTER+="${MODPATH}"


Thanks Ziggy - I didn't know that... the reflection filter seems a little off sometimes (for example I have to import the framework since the screens extends Screen). Do you know if $(MODPATH) reflects everything in the mod path or just the current file?


ziggy(Posted 2014) [#213]
Just current file, but the problem you're having was also mentioned here http://www.monkeycoder.co.nz/Community/posts.php?topic=8140


SGEM(Posted 2014) [#214]
Great work on Diddy, I keep finding new features hidden in it...

However I think I have stumbled across a bug in the virtual resolution handling when not using aspect ratio. In my case I wish to use a specific x (or y) dimension and handle the other variation within the app. The expectation was that I should just be able to call SetScreenSize() in OnResize(), however this caused some very odd problems with stretched graphics etc. I tracked the culprit down to the following two lines in SetScreenSize().

format_codebox(' SCREENX_RATIO = DEVICE_WIDTH/SCREEN_WIDTH
SCREENY_RATIO = DEVICE_HEIGHT/SCREEN_HEIGHT')

If AspectRatio is on then the DEVICE_WIDTH and HEIGHT values are reset during Render, but this never happens if you're not using AspectRatio. My work around was to set DEVICE_WIDTH / DEVICE_HEIGHT within the call to SetScreenSize() as below
format_codebox('
'summary: Sets up the virtual resolution
Method SetScreenSize:Void(w:Float, h:Float, useAspectRatio:Bool = False)
SCREEN_WIDTH = w
SCREEN_HEIGHT = h
SCREEN_WIDTH2 = SCREEN_WIDTH / 2
SCREEN_HEIGHT2 = SCREEN_HEIGHT / 2

DEVICE_WIDTH = DeviceWidth()
DEVICE_HEIGHT = DeviceHeight()

SCREENX_RATIO = DEVICE_WIDTH / SCREEN_WIDTH
SCREENY_RATIO = DEVICE_HEIGHT / SCREEN_HEIGHT

If SCREENX_RATIO <> 1 Or SCREENY_RATIO <> 1
virtualResOn = True
aspectRatioOn = useAspectRatio
aspectRatio = h / w
End
If DeviceWidth() <> SCREEN_WIDTH Or DeviceHeight() <> SCREEN_HEIGHT Then
deviceChanged = True
End
End
')

This works fine for my use, but I wonder if a better solution might be to override OnResize() in DidyApp and update the values there along with setting deviceChanged, but I am by no means a Diddy or Monkey expert.


Samah(Posted 2014) [#215]
Added some predicate magic to the container classes last night (and some other cool methods).
format_code('Class TestPredicate Implements IPredicate<String>
Method Evaluate:Bool(val:String)
Return val.Contains("e")
End
End

Function Main()
Local ds:DiddyStringStack = New DiddyStringStack
ds.AddItem("the")
ds.AddItem("cake")
ds.AddItem("is")
ds.AddItem("a")
ds.AddItem("lie")

Print "all items containing an e..."
For Local s:String = EachIn ds.Items(New TestPredicate)
Print s
Next
End')
Prints:
format_code('the
cake
lie')
And of course it's still just a Stack, so you can use it in any other non-Diddy framework that expects Stack.

Also added:
Shuffle() ' shuffles the items into a random order
Reverse() ' reverses the order of the items
SwapItems(index1:Int, index2:Int) ' swaps two items in the stack/list


Samah(Posted 2014) [#216]
After some discussion with therevills, I'm going to have a go at merging containers into default. ArrayList is still available but is deprecated. Due to naming conflicts with some of the new interfaces, there are some minor code changes you may have to make if you currently use custom sorting.
* Old IComparable interface renamed to IDepComparable
* Old IComparator abstract class renamed to IDepComparator
* Old IEnumerator abstract class renamed to IDepEnumerator


V. Lehtinen(Posted 2014) [#217]
Is the Threading module working? I can't seem to get examples compiled... I get this:

format_code('g++ -Wno-free-nonheap-object -O3 -DNDEBUG -I../glfw/include -I../glfw/lib -I../glfw/lib/win32 -I../openal/include -I../stb -c -o ../main.o ../main.cpp
../main.cpp:4015:24: fatal error: tinythread.h: No such file or directory
#include "tinythread.h"
^
compilation terminated.
mingw32-make: *** [../main.o] Error 1
<builtin>: recipe for target '../main.o' failed
TRANS FAILED: Error executing 'mingw32-make CCOPTS="-Wno-free-nonheap-object -O3 -DNDEBUG" OUT="Release/MonkeyGame"', return code=2
Abnormal program termination. Exit code: -1
')


Lugato(Posted 2014) [#218]
Question transferred to "DIDDY - AN OPEN SOURCE FRAMEWORK - PART 8"