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 / Resizing a vector?

Author
Message
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 8th Mar 2008 05:45 Edited at: 8th Mar 2008 06:03
Wow, first night on the town with DarkGDK and already things are complicated lol.

All I want to do is make an array that will carry numbers that will change over time. In DBP it looks like this: dim test(size_x,size_z) as float.

I thought I could just use test[size_x][size_z];, but apparently that won't work? (or so I was told).

So... anyone here now I would make this: 'dim test(size_x,size_z) as float' into c++? I think it needs to be a vector then right?

EDIT: Let's just get it all out on the table. I'm trying to covert this:



So far, porting it over, I have:


I'm 99% sure that's correct so far. Also, how would I add "dim GUI(128) as gui_type" in? I can't just go "gui_type GUI[128];" can I? Keep in mind the gui_type struct (or type in DBP) was already made above it.

"If I have seen a little further it is by standing on the shoulders of Giants" - Isaac Newton
-Computer Animation Major @Baker.edu-
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Mar 2008 06:05
Yeah - so you need to link in this but they'll be a link error you need to comb this forum for to fix.


In that OOP for DarkGDK thread, started by AndrewT, I released a swath of code, and in there there is a class called jfc_ar.

It doesn't allow multi-dimentioned arrays, but you could emulate one. It's basically a dynamic Array - but the Array you use itself, unlike vector, is not a template class. The array is of the INT data type. But I chose INT becuase... well for ints but you can type cast it to a pointer because its 32 bits. (If you want to go 64bit this would need to be changed - easy enough) but you can also type cast it to a float seeing how it is 32 bits.

Need a double array? Then I would personally start with an instance of the calss. Then in each:


I would create another MyArray class like this:


I know its a little funky, but I don't personally mind because the code is so lean its pretty dang fast. It looks funky maybe, but it pretty much compiles down to the same memory address pointer math as a regular array... in fact.. it is. An Array of Arrays is not much different.

However to learn proper C++ - meaning mainstream - you're correct the vector.h class is what you probably want. All the stuff you'll run into is the same stuff I ran into most likely... NEED dynamic Arrays! Need to manage objects, need to write strings to the screen... etc etc.

AndrewT has a OOP library that is rather well coded and less a headache than trying to sort through my 90+ source files.

Also I think Diggsey is releasing some OOP library also - I think he mentioned he's charging for it... like $5.00US or 5 pounds euro or whatever they use.

Also learn the difference between the double linked lists and vectors because there is a time and place for both... though let me start by saying (as I was reminded) that arrays are usually what in a game because you load em up - thenn play. For CONSTANT deleting/adding... you either use the array and try to manage whats empty and what's not yourself, or let the array class you're using do it - but I recommend the former as the array classes - mine included, need to allocate more memory, copy all the data, then free the old data when the size change exceeds the "Allocation Chunk"... or you may ask for one array element but the class may allocate 10. when you try to add the 11th, thats when it allocates TWO chunks, copies what ya have, then deletes the old memory chunk that had your values. These can cause a slight hiccup in smooth gameplay. Depends how much data etc.

No - nothing is simple - you should hit the www.cplusplus.com website, welcome to DarkGDK... note it took me awhile before I started getting results like I could in DarkBasic. Now I'm glad I hunkered down and learned it.

Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 8th Mar 2008 06:20
Jesus H. Christ...

Okay...

*cries* All I wanted to do was create a damn 2D Array! LMFAO! I swear DarkGDK God! I'll never complain about DBP again! I won't! I swear!

*sigh*. Give me a week to translate everything you just said. Better yet, maybe porting over Tersculpt to DarkGDK can wait It's probably better I do other things with it first. There I go again, biting off more than I can chew . Speaking of Tersculpt...

"If I have seen a little further it is by standing on the shoulders of Giants" - Isaac Newton
-Computer Animation Major @Baker.edu-
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Mar 2008 06:41
Sorry man - didn't mean to make your eyes glaze over. Was just trying to dump info I thought you'd understand and save ya time I spent hunting... new terrain you know... (Pun Intended )

Seriously you might want to finish the mouse object placing etc etc in Terscupt first. Because when you come to DarkGDK... it puts hair on your chest! ... and ears... back... ENOUGH ENOUGH you get it

I first came in thinking I could just convert everything and be happy. there is a program out around somewhere that converts DBPro to C++ - a little buggy but pretty darn close to dead on.

Well.. after learning a bit.. seeing automatically translated code, and a lot of tinkering.... the more I learned just porting verbatum wouldn't utilize what C++ is all about.

So it is a bit of work to do anything useful... but only getting started. Once you start getting it.. the C++ language, some basic system calls.. or libs, or whatever...standard stuff.... strings, arrays whatever... then all of a sudden a light goes on and you start seeing how much more you can do in C++.... once you get a little cumfy... I doubt you'll go back much... but you need to hunker down and really pound on it.

Just wait until you can devote some real time to it... practice siomple hello world stuff, make strings, delete them, allocate ram, make a class or two...etc.

Why? You already know DarkGDK.... What you don't know well is C++!
(I'm guessing from your posts)

Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 8th Mar 2008 06:47
Lol, you didn't really make me cry... just getting that out on the table haha

Yeah, no problem. I guess I'll take it back a lot of notches and start small.

As for that mouse menu thing, it gets my blood pressure up just thinking about it. I seriously wasted my whole day on that damned code and I don't really look forward to returning to it again lol.

"If I have seen a little further it is by standing on the shoulders of Giants" - Isaac Newton
-Computer Animation Major @Baker.edu-
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 8th Mar 2008 06:55
GUI_type GUI[128];

should work

Codger

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 8th Mar 2008 12:54 Edited at: 8th Mar 2008 13:21
Hi Sid, the problem is that C++ doesn't inherently support dynamic arrays where more than one element is not defined at compile time.

So you can have float MyArray(x, 10) where x is only known at run time

but not MyArray(x,y) where both elements are only known at run time

One way of getting round this is to use the following, I've used it and it works really well



Don't forget that C++ does not initialise any variables, so if this is important to you then loop through the array initialising first!

Otherwise you can use vectors as suggested, at least they tidy up after themselves but have more overhead

[EDIT] If you really need to re-dimension the array in real time then I guess using the vector class is a good way to go as the push_back function will simply grow the array as required. [EDIT]

No matter how good your code is, someone will improve on it
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Mar 2008 13:29
Well said guys. It's not that C++ DOESN'T do it... its just that C++ doesn't manage memory for you in a way you're used to.

1: TOUGHER AT FIRST

2: USE THE FORCE LUKE! (One you get it... its hard to go back when you start leveraging the POWER!)

Codger is tight - you could make FIXED Array NOW, use it love it, and get by... then you'll come back to it and change it up so its less "Fixed".

I Actually had fun making my Dynamic Array class. I was happier still when it worked whether you made arrays bigger, smaller or collapsed to ZERO Elements(100% Empty). It was a good exercise in understanding pointers and stuff using C++ Syntax. I knew how to similiar thing in FreePascal - but so do you really... but in DBPro and Memblocks.

Sure - I didn't use templates blah blah but now when I look at vector code and other STDLIB stuff... I understand it all faster reading the code or documentation.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Mar 2008 13:58
Here's a class I wrote a year or so ago - I've just quickly hacked in the resizing stuff. Also includes a simple main function to show how it can be used:


Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 9th Mar 2008 04:55
Thanks guys for all the information. I think I'm going to go through more C++ tutorials than I have so far, because I'm honestly and obviously not understanding everything up to this point. If I don't get it now, there is nothing to build off of so... I have to start somewhere

I think I'm going to go through this:
http://www.cplusplus.com/doc/tutorial/

This a good tutorial? Any others you recommend?

"If I have seen a little further it is by standing on the shoulders of Giants" - Isaac Newton
-Computer Animation Major @Baker.edu-

Login to post a reply

Server time is: 2024-09-29 15:29:22
Your offset time is: 2024-09-29 15:29:22