Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Problem with memBlock

Author
Message
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 13:54
Why has the folder to this post gone red? Is this because it is about to self destruct??? Lol

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 4th Feb 2015 15:04 Edited at: 5th Feb 2015 01:20
You can detect clicks on the individual shapes by previously scan converting it, which is what i did in the example the other day.

The routine is broken up into two stages. The first stage is nothing more than an palette mapping process. Where we run through the original image looking for the white colour and ignoring the every other colour completely. When you find a white pixel, we then flood fill this area with current fill colour, starting at integer 1 (which is R=0,G=0,B=1). When the fill completes, we bump the unique fill colour rgb by one and continue on. When it finds the next white pixel, we call fill again, bump the fill colour rgb etc etc.. So each zone is being filled with a unique colour.

The second pass we scan through the coloured (palette mapped) version of the image. For each row we scan left to right (right to left would also work) and count how many times a pixel

; Psuedo code



Since the image is so simple you end with only a hand full of spans on each row. To find a click, we get the click colour from the original palette mapped coloured image, then scan through that that rows spans list looking to see if the X coordinate falls with a spans range.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Feb 2015 15:22
It sounds like a hybrid solution may be the best.
Use the memblock map to work out where you have clicked (id of the block to paint).
Then convert this ID to the corresponding sprite and use the built-in sprite colouring to complete the task. This saves a *lot* of time trying to map your sprites to clickable shapes. But you get the speed and added benefits of sprites.

Quidquid latine dictum sit, altum sonatur
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 15:42
Yes sounds like a plan

I would only need one colour mapped image loaded in per picture and converted to a memory block and then the image deleted.
I could then get the ID from the memblock when the screen is pressed instead of sprite detection and change the corresponding sprite colour when pressed.
If I change the colours then on the mapped image say red values on the ones I have been using to be from RGB 1,0,0 / 2,0,0 / etc up to 255,0,0 leaving 0,0,0 as this would be a black line. This would give me up to 255 fill areas.
I could then just read the RED byte to check the red value as the ID and then if I relate this to eg RGB 1,0,0 as Sprite1, RGB 2,0,0 as Sprite2 etc and just change the colour of the sprite to the RGB value colour selected to fill.

SetSpriteColor( iPixelREDVal, iRed, iGreen, iBlue, iAlpha )

Does this sound like what you mean then?
My head is getting mashed lol

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Feb 2015 15:59 Edited at: 4th Feb 2015 15:59
That's how I'd do it. I'd probably use the methods described earlier to condense it to one integer rather than 4 colour bytes.

Quote: "SetSpriteColor( iPixelREDVal, iRed, iGreen, iBlue, iAlpha )"


That's fine as long as you intend to hardcode your sprite IDs. You'll have to reserve your IDs (create empty sprites) before you assign any automatically generated sprite IDs.

I would make an array of 255 integers and put the auto-generated ID in that.



Quidquid latine dictum sit, altum sonatur
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Feb 2015 16:02
My solution requires no memblocks at all. You can colour sprites without memblocka. It's nearly done!

Onwards and sometimes upwards
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Feb 2015 16:10
Jim, how are you detecting the sprite under the click? That's the current tricky bit. The memblock is an alternative to creating lots of collison-detection shapes per sprite.

Quidquid latine dictum sit, altum sonatur
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 16:49
Well we have plenty of options for the sprite collision/detection to colour the sprites when the solution is sorted with the packed sprites and also for future projects to come but it seems you got it covered Jim

This idea of yours Jim is really interesting and I can't tell you all enough how great the response for help I have had.
All this knowledge will be passed on to my 15 year old lad who is learning how to code at school at the momment as we have a great many projects ongoing together.
Don't get me started on the problems we have had with the Raspberry Pi and a little robot! lol

Going to have another look at the C++ conversion later as I am really interested if the program would be faster once converted.

Here is where I am upto:


Got to say though it is a long time since I have done anything in C and I didn't do much then but I don't really like it I must admit. I am determined to convert it because it is a good learning curve. I have to try and put the functions in yet, got some advice from the other post to read up on functions for C++ so that's another little side line

http://forum.thegamecreators.com/?m=forum_view&t=213519&b=41

I think I have took the original method on AppGameKit as far as it will go really so I am not bothering adding the box areas to the code for the fill routine as it won't add anything in speed to large fill areas and is unusable on a tablet.

I still think there should be a native command for Flood Fill as it would be usefull for many projects still, especially art packages but I suppose there is not much call for it?
When you think AppGameKit has Box with fill native command it should be easy enough for the TGC team to put it in and it is debatable if it should have been there in the first place.
Even Amos back in the day had a native command for flood fill which was super fast on the Amiga where Lee Bamber "cut his teeth" learning to code as I have heard before.

For anyone thinking I am having a big moan then I am not as there has been no Flood Fill from DarkBasic onwards where I first did this project and got it working and I didn't expect AppGameKit to have it when I bought it but here we are

My head is swelling that much from how much I am learning on here though as a result lol

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Feb 2015 17:10
You need to optimise that flood fill... then you'll see a huge improvement.

Consider that your method might only be updating 4 or 5 pixels per pass, so the time it takes to fill an area is exponentially long - you need to think outside the box for a second.

If you scan in 1 direction at a time, and change direction, you can effectively cut out most of the recursion. Like, say you make a simple scan loop that checks neighboring pixels and decides if the pixel is to be filled... like

while done=0
done=1
For y=0 to hig
For x=0 to wid
If pixel[x,y]=0
If pixel[x-1,y]=1
done=0
pixel[x,y]=1
Endif
Endif
Next x
Next y
endwhile

So this would be just 1 direction, left to right - optimising pixel filling to the right - as any pixels to the left that are set, continue with the scan - you'd end up with lines across the screen.

K - so what if you then made a second loop:
while done=0
done=1
For x=0 to wid
For y=0 to hig
If pixel[x,y]=0
If pixel[x,y-1]=1
done=0
pixel[x,y]=1
Endif
Endif
Next y
Next x
endwhile

This would continue the pixel lines down - but if you scan all the way to the right in a pass, then scan all the way down, then left, then up, and just repeat that - you'd have an optimised fill. Imagine starting with that 1 pixel, the first pass from left to right, it becomes a line. The second pass, from bottom to top, it becomes a square, as the line is spread up to the area extents... then the scan left and scan down ensure that all directions get an optimized scan... that one pixel gets spread in all 4 directions, and the more pixels you can fill in a single pass, the faster the flood fill will be. Heck - this technique is fast enough to calculate AI path finding too at a fraction of the complexity of an A* system.

Doing that would be fast enough, you might find that within just 4 or 5 passes a complex shape is filled, and that wouldn't even register as a delay for most devices.

I am the one who knocks...
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Feb 2015 18:11
spectrepaul's images are 1150x800. Flood fill in AppGameKit is almost certainly not the answer!

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 18:37
See what you are saying Van B however the fill method I have been using on the 1150x800 image is not a traditional flood fill routine as it is pre-calculated areas.

I have an area on the screen to fill and every pixel in that area has the same ID value.
The program goes through the full image pixel array and just converts the pixel in the fill area and changes the pixel with the correct value.
There is no recursion and even if I narrow this down to check a boxed area around the fill area instead of going through the full image it is still slow.

Eg:-

h = 800
w = 1150

for y = 0 to h
for x = 0 to w
if point at x,y = pixel to change colour then change pixel colour
next x
next y

even if I create a box area with this idea:-

hu = 50
hd = 750
wl = 0
wr = 500

for y = hu to hd
for x = wl to wr
if point at x,y = pixel to change colour then change pixel colour
next x
next y

it is still slow on large areas.

Hope that makes sense, thats why I say I am giving up on this method for the size of the image in AppGameKit because AppGameKit just can't handle it I don't think.

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Feb 2015 18:52 Edited at: 4th Feb 2015 18:54
Okay - Only 1 tiny thing left to do later tonight.

Here's an example of a fragment PNG.

Black is the transparent colour.

Onwards and sometimes upwards

Attachments

Login to view attachments
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Feb 2015 18:56 Edited at: 4th Feb 2015 18:56
Here's the biggest in the bunch I have:

Onwards and sometimes upwards

Attachments

Login to view attachments
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 19:10
Going well Jim,

Yes that second one is the biggest fill area needed for any picture as it is also part of the title screen when you start the program.
That large fill area is one reason why the other method still wont work with a box area because it is still the full screen size.

The frog picture I was thinking of coming onto the screen in pieces as a title screen and then colouring itself in on its own before going to the first picture to colour in.

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Feb 2015 21:44
Th PNGs are pixel-perfect and I now have a lot of them! Takes about 3 seconds to generate them all.

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 22:04 Edited at: 4th Feb 2015 22:06
3 seconds is very quick!!!
Getting excited now as it is getting close to completion.

I tell you something though, I converted the fill routine to C++ to see how it is speed wise and it is much faster, don't know how it would be on Android as I would have to do a lot a messing around to get to that stage and I am not good enough in C++ yet, very rusty
I got the code working with the help of another checking my C++ syntax errors.

Here is the C++ code:
and a running version is attached.


It was a good experiment for the C++ version but I am not ready to go much further with that way yet.

Looking forward now to completing the sprite version. Cheers Jim.

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles

Attachments

Login to view attachments
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Feb 2015 22:23
I can make it a bit faster, but it's not worth the time for a tool. I have optimised the final image scan and PNG production.

There are 920,000 pixels in the image! Floodfill is not a problem on a PC - but try doing that on a slow Android tablet. I don't think so...

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 22:34
Yes it's true, it was a good side project for me to get into a bit of C++ again, it wasn't too bad converting the program, however it was slow going and I don't think I could be productive with it because it would take too long to get into it again and having said that , I was never that good at C++ back then anyway

As your signature says, onwards and sometimes upwards

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 00:58 Edited at: 5th Feb 2015 01:06
Here we go...

Please read the RTF file in the zip.

I'm not going to write the paint program! Here are the tools to do it.

When you see the output picture it's very dark. That's because the colour values for the floodfill are all red and range from 1 to 255.

Onwards and sometimes upwards

Attachments

Login to view attachments
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 02:01
Just downloaded it and read the rtf file on my tablet before bed and it seems straight forward, can't wait to have a good crack on it tomorrow now! Don't think I will get to sleep tonight because I want to get cracking on it now.
Feel like a kid on Christmas Eve lol

Will start from scratch with new code and get the base program working first before adding any fancy bits.

Cheers again Jim and watch this space for the results!!

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 09:02
Incidentally - There are no dependencies, so you can run it straight from the zip file if you wish.

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 09:27
No worries, good day of coding later

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 10:43
I've only just realised that AGK's sprite clicking handling does not take transparency into account - which strikes me as daft. It's inevitable in this program that sprites will overlap with transparency.

The simplest solution is to add a map - an array of bytes which have the image index in them. Using world coordinates it should then be easy to map a click to the active zone of a particular sprite. This map will have to go into a memblock. I'll add this this morning.

Onwards and sometimes upwards
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Feb 2015 10:50 Edited at: 5th Feb 2015 10:52
That's what we were talking about further up, here and here. You must have been in your den of creation at the time, crafting your magic.

I was really hoping you had found an ingenious solution and about to reappear with an evil laugh, Muhahahahaaa

AGK can handle transparency in convex shapes, but not concave. It also provides shapes for collison and click-detection on more complex shapes, but you have to map it yourself. I agree, a simple memblock as a reference will solve the problem in the most efficient way. You can do a direct lookup to the point clicked.

Quidquid latine dictum sit, altum sonatur
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 11:29
I don't use any graphics much, so I wasn't aware of this deficiency in AGK. My own graphics engine passes through transparent layers until it hits a non-transparent region and returns the sprite value. Surely it would be possible to add this to the engine!

It's less costly in load times to add the auto-coloured main PNG to the zip, which I've now done. This can then be loaded into a memblock.

Onwards and sometimes upwards
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 5th Feb 2015 12:18
Quote: "Surely it would be possible to add this to the engine!"


As long as it is optional ... I use the 'transparent' areas as clickable sprites intentionally... Say for example I have a 'Jump Button'. To avoid taking up a large portion of the screen I use a small image on a larger transparent surround. This makes the clickable area bigger than it looks... Perfect for 'fat fingers'

Using AppGameKit V2 Tier 1
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Feb 2015 12:21
Quote: "Surely it would be possible to add this to the engine!"


I think it's a feature rooted in Box2D, which is what AppGameKit uses for collision. There are other methods for pixel-perfect collision (the discussions on the DB forums raged for years) but again it will impact on performance on a mobile device.

Quidquid latine dictum sit, altum sonatur
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 13:25
It shouldn't be a high CPU cost to check the images down the Z-order until the hit point is not on a transparent pixel. I did this 20 years ago on crap PCs on Windows 98 with no problems.

@funnell7 - That's fine if your sprites don't overlap, but if they do it's vital to get the topmost sprite where the hit is in a visible area.

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 14:00
I am at work at the minute so can't get on the computer yet to make a start, very frustrating.
Won't be a problem with the detection as I will use the colour mapped image with a memBlock from the other code, the main area is the speed of the fill which should be super fast with this method of the sprites

I am debating between storiing the data from the x,y positions etc in data types instead of an array.
Is there any difference in speed using Types or any disadvantage?

I could have a Sprite type for the number of images and have data as:

x
y
width
height

for each sprite stored in the Sprite type.

Once I have it up and running I will start re-thinking my interface, not sure if the palette method I have been using is too simple looking or not or wether for the target audience I was thinking sometimes simple is better?

I was also thinking of making some thumb nail images of the pages to colour and display these on a sheet to select the image instead of doing screen swipes to change the image, think this method will help to disguise any load times.

By the way does anyone know if there are any commands in AppGameKit to sort screen scrolling with the finger. Like you would as standard when using a tablet interface?

Cheers.

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 14:08
That data is in the map.dat file.

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 14:53
Well I am home now and have just run your program for the first time, looks good!
I like the interface, simple and works great.
Just unpacked the zip files from the images into folders for AppGameKit with all the sprites and the map.dat file.
I can't find where it saves the colour mapped image?

Very impressed so going to start a bit of programming to get it working

Just reading through your instructions, I think this is going to work great!

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 15:59
I haven't uploaded the latest version.

Have now!!!

Onwards and sometimes upwards

Attachments

Login to view attachments
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 16:05
Quote: " looks good!"


Delphi is brilliant at doing this kind of thing

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 16:29
Got the latest version and managed to find the master image, gets better and better this program!
Would this take an image of any size or orientation?

Eg:
1150 x 800
800 x 1150
1024 x 768
640 x 800

I am getting some errors on the colour read outs in the program display when I scan the image, not sure if this matters?
Like how you have made the background transparent on this version too for each sprite

I have just started to put some code down to read and display the sprites, however I must have not read the data correctly yet as it displays incorrectly still checking though yet.



Re Delphi, yes it seems pretty good and wouldn't mind trying it but that is another story as you know

Cheers

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles

Attachments

Login to view attachments
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 17:33
Jim,

just had a momment lol

Got it working, read your instructions again and the way AppGameKit reads data into the slots is to read one at a time so I changed the code to skip 3 sets of data as the first is the number of sprites value and hey presto it worked!!



new version of code below:
going to update with changing colours next which is the whole point of it, shouldn't take too long so check back later for updated code



Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 18:31
Are you using the AppGameKit UnpackZip() function first?

If you are unpacking the the media folder this won't work on Android. You'll need to unpack to writable storage:

extractzip("PIC1.png.zip","packed")
immain as integer
immain = LoadImage("packed/master.png")

The program should work with any resolution of input image. It converts the data to 24-bit colour to work with. I'll post the project code later.

Onwards and sometimes upwards
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 18:33
Quote: "I am getting some errors on the colour read outs in the program display when I scan the image, not sure if this matters?"


Can you explain?

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 18:34


Well everyone it's working and is ----

F A N T A S T I C ! ! ! ! ! ! ! ! ! !


Jim,
you are a genius for this idea! It is working great, check out the code below and the image files are attached to this post to see it working.
Even with the biggest screen area to fill I am getting 300 FPS on the computer and on my phone and tablet 60 FPS so very good!

You wouldn't believe the size of the grin I have on my face right now!

Next thing now is to put everything together regarding the colour palette selection etc and hey presto!
Onwards and very much upwards!

If I was a Mod I would give you a badge for helping the community!



Just a couple of questions from the above post Jim:
Quote: "
Would this take an image of any size or orientation?

Eg:
1150 x 800
800 x 1150
1024 x 768
640 x 800

I am getting some errors on the colour read outs in the program display when I scan the image, not sure if this matters?
"


Even though I get some error colour read outs it still works great so not sure if that matters?

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles

Attachments

Login to view attachments
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 18:35
One min just saw your post after I typed this.

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 18:49
re the Unpacking, I unzip on the computer and put the images into a folder of it's own for each page in the media folder and then call the images from AGK.

If you see the download button on the above post that is the image folders for 4 pictures. This is a zip file just for uploading to here.
In AppGameKit this pages folder is inside the media folder unzipped already at run time.

Are you saying I can keep each set of data zipped and read the zipped file into AppGameKit?

Quote: "
extractzip("PIC1.png.zip","packed")
immain as integer
immain = LoadImage("packed/master.png")
"


I am not using these commands, have a look at the code above.

Quote: "
The program should work with any resolution of input image. It converts the data to 24-bit colour to work with. I'll post the project code later.
"


Didn't see this before as I was typing a post
That's great because if I decide to change picture size it makes it very flexible. Very good!

Quote: "
I am getting some errors on the colour read outs in the program display when I scan the image, not sure if this matters?
"


Eg if I load image 1 the frog I get the following messages after I press scan:

Dimensions 1150 x 800
Scanning key colours
Pixel format 24-bit
Colour errors = 11
Flood filling
There are 57 regions
Comuting bounds
Saving files...
Done


Great work, very pleased!

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 18:49
Maybe it's better not to have the main picture transparent? I'll make a menu option to toggle that.

Don't forget to extract the red pixel value from the colour when you read the memblock.

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 18:57
Well I am really chuffed with this and it is very good of you to do this so thanks again.

I have working code above reading from the red pixel value, works fantastic!

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 19:06
Quote: "
I'll post the project code later.
"


Hey that would be good, will give me some ideas and info for when I start looking into Pascal!

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 19:27 Edited at: 5th Feb 2015 19:28
Latest here: added menu option to not make the master image transparent.

Delphi is probably the fastest programming environment there is. For example the built-in system.zip does all the zip stuff without any need for third-party code.

Nothing exists that will do cross-platform stuff as well as Delphi XE7. As I'm slightly annoyed with TGC for not adding AppGameKit for Pascal to new AppGameKit purchasers' download area I may replicate your program using Firemonkey (FMX) and also using AppGameKit for Pascal.

baxslash may help you to add some shiny paint shaders etc to the program.

I've enjoyed messing with this as a diversion from the system I've been developing, updating and selling for the last 14 years! Shout if there's anything else it should do!

Onwards and sometimes upwards

Attachments

Login to view attachments
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Feb 2015 19:33
Just read another post above.

Each zip file is effectively a level. Use AGK's unzip rather than having the whole thing static. You can then delete the unpacked files at the end of the program run, or the end of the level. There is potentially a lot of data, so you want to clear it if possible for users with small amounts of RAM.

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 19:44
Will get on looking at them Zip commands then, good idea to delete them after also so they won't annoy people by taking up space on their tablet etc

The new version was done quick with the transparent option, cheers for that!

Shaders would be good to get into after I have perfected the main program and would add a lot to it I think with nice effects.
Will have to pester baxslash soon

Thanks again for all your help, I feel I have learnt a lot from this and I might take you up on the offer if anything comes up lol but you might regret saying that.

Check this post for further updates if you want to see how the project is going as I will update that post in future with the extra features etc

http://forum.thegamecreators.com/?m=forum_view&t=213305&b=48&p=0

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 23:30
Well guys, I know you have all helped me in this post especially Jim but I would be grateful if you could please do me a favour and spend 5 mins on checking my other post here:

http://forum.thegamecreators.com/?m=forum_view&t=213305&b=48&p=0

I have updated the program which now colours the sprites with the correct colour RGB from the palette of colours on screen. These colours can also be moved up or down to see more from the palette which are not on the screen.

The post explains what I am looking for but really it is just your opinion on the end result so far as to speed etc on any devices you can broadcast it to.
Eg was it jittery, fill work ok, what device you used etc.

Cheers.

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Feb 2015 01:20 Edited at: 6th Feb 2015 01:29
Enjoyed your tutorial blog!

On the Amiga we would have done this using the Blitter, and it would have been very fast. Sadly missed: a GPU way ahead of its time.

I'm glad it's working. My blog would be to try to decompose a problem and see which bits can be simplified. It's not always obvious, unfortunately.

Although the flood-fill is the obvious route, there are as many cons as pros. If you wanted to do smart colouring you would have to do an "enhanced" floodfill - that could take a while, so you'd have to have animated pens etc to disguise it.

I hope this demonstrates the importance of off-line tools. Anything that can be pre-computed should be. AppGameKit will probably not be the tool to do that. AppGameKit is not a tool-maker - it's a delivery system for simple games. The PaintBook program uses the highly optimised flood-fills in Windows to do the heavy-lifting off-line. In the case of PIC1.png it does 94 flood fills, works out the bounding boxes, saves the 94 generated PNG files into a zip file for each sprite image and datafile in about 3 seconds.

Here's the flood-filling function:



That uses the canvas Pixels property, which is actually very slow, though good for proof-of-concept trials. Using that, the calculation of the bounds took minutes. We then had to turn to the Scanlines property, which is very fast. The downside is that we need to know the pixels format, which can be variable. To normalise this, we ensure that the loaded picture is blitted to 24-bit pixel format.

The Scanlines are actually pointers to a structure, but we can fool them into being a pointer array and simply index them. In this code segment, fillsdone is the number of filled segements. The colours have already been computed as above to lie in the range 1..255. So we can scan this rather strange image and extract the bounding box. If we are computing minima we must start the comparison value with an impossibly large number.

The procedure Fillchar() fills any thing with what ever byte value you wish, in this case 0 (#0).

The rather poorly named MinYIndex is an array of the following type:



The TRGBTriple is a system-defined 24-bit structure with RGB bytes.

Here's how we compute the bounds for each region



Using the Scanlines is very fast. Obviously, it's not as fast as using a DirectX surface, but we're talking microseconds.

I won't go into detail on how we make the subimages apart from to say we put them in a bitmap, having created the bitmap with rectangular bounds computed above. Effectively, we read the scanline values in the primary image and poke them into the scanlines of the subimage, setting them to black or white.

Making a PNG from a bitmap in Delphi? Here's how hard it is:



Before you hit the metal, make the hammer...

End of sermon.

Onwards and sometimes upwards
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 6th Feb 2015 02:17
Quote: "Enjoyed your tutorial blog!"


The start is quite funny really because I thought I had it sorted this program before I hit the problems I did. Especially as I had already done a similar program 3 times in the past with Paint Pot, Paint Pot II and Colour Splash with DBPro so I thought I would try and help out the community whilst boxing off this game lol
Well as it has turned out I have learnt a great deal and whilst I finish this game which is really doable now thanks to you, I will update the blog along the way and hope someone else will gain from it, even if in a small way like converting a program to C++ in one of the steps.
I must admit that I am enjoying getting back into this coding game again and its slowly coming back to me I think


Quote: "On the Amiga we would have done this using the Blitter, and it would have been very fast. Sadly missed: a GPU way ahead of its time."


The Amiga was and still is a great machine and personally out of all the computers/consoles I have owned over the years, it is my favourite one. Fond memories which would now be called Retro lol
I might have to have a look in the loft for some old demos etc to convert as I have loads of routines from when I was in demo groups which is where the handle Spectre comes from
The time Paint Pot II got on the cover disk of Amiga Format I thought that was it, I had made it haha.

Quote: "Anything that can be pre-computed should be."


100% and that is something I had forgot when trying to think around the problem and it is good to get someone looking with fresh eyes at it.
In fact a lot of the old fancy gfx Amiga demos had precomputed stuff to make them look groundbreaking at the time!

I am going to have a good read through the code bits you have put on here, this Pascal looks quite readable so I think that will be another side line to look at whilst continuing with my projects.

Well until the next shout for help on the forum and hopefully I can return the favour sometime.

Cheers

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 19th Feb 2015 21:13
Hey Jim, game is going well with the paint tool you designed for the sprites, quick question re this:

I will be creating more pictures soon as the game is coming along nicely.
The tool works great but I was just wondering, does the tool you made detect for white pixel areas or the black lines when creating the areas to split into sprites? I was wondering if I put a picture through the tool which is anti aliased on the black lines, will this still make the sprite correctly? I thought it might create the sprites still and include the shaded aliased sections around the edges of the sprite, if the sprite has greyscale edges and I change the colour of the sprite then the image will have smoother lines? Not sure if this makes sense?

Cheers.

Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles

Login to post a reply

Server time is: 2024-05-03 21:56:15
Your offset time is: 2024-05-03 21:56:15