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 / AGK2 T2 C++ code

Author
Message
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 05:42
Hi all,

anyone good at Tier 2 with C++ that could give me a quick hand?
I am trying to do a line by line conversion of an AGK2 program and am a bit stuck as it has been a loooong time since I have done any C stuff.

This is the AppGameKit code:



This is what I have done in C++ so far but is not correct because of the function calls which I know wont work like they are, I just cut and pasted to convert.



These are the 2 functions I am trying to add, I guess I will have to try and put them in a class however I can't remember how to do it!



Oh and by the way my images won't load in either to display a sprite as it just has the square box image.

Thanks if you can help.

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
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Feb 2015 07:23
1. The Sync() command only works in the app::Loop() method.

The app::Start() and app::End() methods only execute once each, at the start and end.

Quote: "agk:rint(pixelcheck);"

The variable 'pixelcheck' is not defined anywhere. You assign a value to it, but it isn't declared as an int or float or anything.

In C and C++ (in most compilers), you cannot use undeclared variables.

And, variables with different cases are not the same variable as they are in Basic. E.g. 'varI' and 'vari' are two different variables.

And, in Tier 2, the pointer press, clicks, all user interactions are checked once each time the app::Loop() method is executed (I don't know if it at the start or the end).

So, the loop waiting for the pointer to be released never ends. (I discovered this one early on after a bit of frustration.)

This page might help you start understanding how functions are done in C and C++. And this is another that might help.

A function does not necessarily have to return a value, either.

Cheers,
Ancient Lady
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 4th Feb 2015 09:10
Basically, you cannot do it.

AGK T1 is pretty much unique amongst cross platform development kits in that it is 'sequential' code (or it seems to be). So you can write code like



on most other environments you cannot do this. You have a timer driven or event driven systems (have a look at Corona's 'composer' library) with messages flying all over the place. To do anything much in these involves defining an event that is called every frame, say.

With T2 you are back at this - a setup and a close down, and a function called at regular intervals.

I think !
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 13:49
Thanks for the links they seem quite helpful.
I probably didn't word the post correctly because it was past 4am when I sent it and then realised the time! Lol

I know the variable is not set yet and there are some parts which are not valid and won't work. What I did when starting this was cut the code from AGK2 and pasted it to C++ and then started converting so not all parts are converted yet ☺
I wasn't aware of the Sync() command only working in the loop.

Will have another look later as I am at work and only have access to my tablet at the minute but going to try and read up on those functions.
Got a lot of reading to do today with this project lol

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
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 4th Feb 2015 17:55
You can use a Sync() in the code, but you need to be careful.
For example you can use it in loops or to refresh after a loop.

What you wanna do with your code?

SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 18:22
Hi,

well I have just got back from work and am looking at it again now after getting help re the Functions.

This is the AppGameKit code which I want to convert to C++ AppGameKit to see the dif in speed.
You will have to bear with me here because the C++ code is not finished and it has been a long long time since I did a bit of coding in C/C++.



This is now where I am up to with the code in C++ and I think I am nearly there but still have some errors.

Some of the code is still in the AppGameKit basic format as I haven't converted it yet, just started implementing the functions.
What I have done is a straight cut and past from AppGameKit basic to C++ and am working through it line by line to convert it to work with C++ AGK.

I am using Visual C++ 2010.



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: 4th Feb 2015 19:37
Okay I have converted as far as I can with this now and I can't compile because I think it is something to do with the agk::GetMemBlockByte() command but I am not sure what.

Any ideas on how to correct this code of mine?

Cheers.

The first post has a download file with 2 images which needs to go in Apps/media/pages folder.



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
ThrOtherJoJo
12
Years of Service
User Offline
Joined: 24th Mar 2012
Location: California
Posted: 4th Feb 2015 21:29 Edited at: 4th Feb 2015 21:35
Hi!
Quote: "
Okay I have converted as far as I can with this now and I can't compile because I think it is something to do with the agk::GetMemBlockByte() command but I am not sure what.
"

...This is just a spelling error. The Block in the function is lower case.
agk::GetMemblockByte.

I looked over your code and was able to get it working. There were a few syntax errors, and some function declaration errors.
The do..while loop I took out because that created an infinite loop.
If you are trying to create a slow fill effect you can't do it using a while loop.
For some reason AppGameKit doesn't like while loops inside the main loop. That has been my experience anyway

Anyway, here is the code.


Prove Your Worthiness
KG2Entertainment.com
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 21:52
Hey ThrOtherJoJo,

thanks for your help with that, I said it was a long time since I had done anything in C/C++ lol

Like how you commented my code with the errors I made, very helpful, like the Function I put void instead of a return type int.

Yes Ancient Lady above mention the while loop checking for pointer being unpressed and I forgot to change that bit.

I am not trying for a slow fill but what I was doing was to not fill the section in until the pointer was released.

Eg,
pointer pressed, wait until pointer released before filling

I did this in tier 1 so that it wouldn't go into a fill loop whilst still holding down the pointer.

I now have code which will compile and run, however for some reason it is not loading the pictures in.
Did you actually get the picture up to colour?
Just wondering why I have the icon with a cross in it to say no image loaded in.

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: 4th Feb 2015 21:58
Forget the last about the pictures not working lol

Just realised I didn't have the media folder in the final folder with the build.
It works now.

Thanks again ThrOtherJoJo for helping with my errors

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
ThrOtherJoJo
12
Years of Service
User Offline
Joined: 24th Mar 2012
Location: California
Posted: 4th Feb 2015 22:58
Quote: "Thanks again ThrOtherJoJo for helping with my errors"

Not a problem.

After looking at your code, It got me curious about the memblock commands.
I wonder if I would see a speed increase in fps using those?

Do you know if drawing images to screen would be faster using those commands?

Prove Your Worthiness
KG2Entertainment.com
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 4th Feb 2015 23:04
It would appear that memblocks are quite fast for some parts of the coding but there are limits. I have had some problems with them also but you can also use them as an array.

I would have a look at this other post where I have been getting assistance from other members of the community but this program in C++ is much faster than the tier one version so they could help you.

I would read through the full post because other members have included links to other areas to assist regarding them, quite interesting.

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

Thanks again.

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
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Feb 2015 04:01
You can use Sync() anywhere to update the display.

But, physics and user/device interactions are only processed once each time app::Loop() is called by the AppGameKit core.

And, as you have discovered (and I had the same problem a few times), C++ is case sensitive for everything, including function names.

Quote: "I know the variable is not set yet and there are some parts which are not valid and won't work."

I suspected that you hadn't quite finished, yet. But it never hurts to point something out, just in case it wasn't noticed.

Happy Programming!

Cheers,
Ancient Lady
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 5th Feb 2015 07:18
Quote: "You can use Sync() anywhere to update the display."


Yes you can, but you have to yield as well. You don't have to do this in Tier 1 because the VM interpreter does it for you ; it's one of the things that makes AppGameKit easy, no faffing around with FSMs and so on.
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 5th Feb 2015 09:24
Well got it working and it wasn't too hard, thanks for the advice.

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-11-25 16:54:55
Your offset time is: 2024-11-25 16:54:55