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.

Dark GDK / Array difficulties

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 15th Aug 2008 01:40
I'm working on a basic tile-based side-scrolling engine. Here's the code so far. (I know there are errors in array usage. I'm trying to fix them.)

Level.h


Level Drawing.cpp


And Main.cpp


I'm not sure how to correct the errors in array logic. I'd like to use the class in this manner (passing arrays of uInt's).

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 15th Aug 2008 04:55
I'm starting to wonder about moving to C#. I don't want to use (or pay for) DBPro, as I can't stand the syntax; and I don't want to deal with the complexities of this type of thing. I'm thinking C# would be a good language to go with for now. It's a( C-like, and b( going to have the DarkGDK soon.

So, will C# greatly simplify this sort of thing? And where might I find a good tutorial for moving to it from C++?

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
pirogoth
16
Years of Service
User Offline
Joined: 6th Apr 2008
Location: Good Old California
Posted: 15th Aug 2008 06:59 Edited at: 15th Aug 2008 07:00
As for C#, you can find all the info you'll need on it and the .NET framework right here: http://msdn.microsoft.com/en-us/library/kx37x362.aspx

Unfortunately C# won't really make this sort of thing any easier. This is still pretty basic functionality of most languages. You'll just have to muddle through it with a little help.

C# does make a lot of things easier being as most of the data structures you'll use have already been implemented. In general it just has a faster workflow, but this is really user opinion and subject to change from user to user.

Also, it'd help if you told us what your errors are. =P

-Piro
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 15th Aug 2008 07:33
The errors are with passing arrays by reference. I can't get it to work. I figured C# would make using arrays much simpler in comparison to dealing with pointers.

This:



Does not work. The function is defined as:



layerOne is a two-dimensional array of uInt's. I can't figure out how to pass it to the function for use with the cLevel class.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Aug 2008 09:22
What errors are we talking about? I don't want to make a project just to test your code for errors, you should paste them here.

However when looking at it, I can see that you're passing 'layerOne' which is of type 'uInt [50][15]' and not 'uInt*' as your function expects, I'm pretty sure I told you this or someone on another thread a while back.
You can fix this by casting it to (uInt*) as you pass it to the function, or use a 1D array and calculate the offsets yourself, or dynamically allocate a uInt** array or do similar using a container.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 15th Aug 2008 09:34
*smacks forehead* I did forget that.

But, I still get errors over this line.





Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Aug 2008 09:43
look at what you defined LEVEL_SPRITE_BEGIN as.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 15th Aug 2008 09:48


You have my apologies. I feel so stupid.

Thank you for pointing that out. I knew it had to be something strange to make an invisible argument.

Well, the only other error is this:



Lines 36 and 57 being the dbSprite call we just discussed. I'm thinking I've forgotten a lot about pointers. >.<

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Aug 2008 10:12
layerArray is a uInt* thus you cannot find the array subscript of a uInt i.e. using layerArray[][], if you have layerArray[] you will be accessing a uInt at that specified index offset, a uInt isn't an address so you cannot find an index from that. To fix this you need to use [x+y*width] where and x and y are essentially the first and second dimensions you wish to access and width being the size of the first dimension, static arrays like this are stored contiguously as a 1D array remember, the language just makes your life easier in this instance by making it look as if it's a 2D array.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 15th Aug 2008 10:25
I have this. It compiles, but crashes on run.



Also, thank you for the help. 2 A.M combined with a week without any programming equals me messing up code.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 15th Aug 2008 10:44
Well, I've looked over the code for the past ten minutes, and can't find a single thing. *sigh*

So, thank you for the help. I'll figure this out in the morning. I'm tired.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 16th Aug 2008 02:55 Edited at: 16th Aug 2008 02:57
I've tried many different things, stuck dbText in all types of places, and still can't figure this out!

I've changed the drawing loop to this. It still draws the array incorrectly.



Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo

Attachments

Login to view attachments
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Aug 2008 19:38
If I were you, I'd start again and do things differently, because I think you are making things hard for yourself.

First, create a class that holds and draws a single layer. Use a vector or a vector of vectors to store the layer information, rather than a raw array. Get it working fully before moving on.
Next, write a class that holds and draws multiple layers (your level class).

You can do all this without doing any memory allocation or using pointers in any way.

Here's a class that I wrote a while back to help you - it's a 2D array class that uses vectors internally. http://forum.thegamecreators.com/?m=forum_view&t=126925&b=20

Login to post a reply

Server time is: 2024-09-30 05:35:33
Your offset time is: 2024-09-30 05:35:33