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 / DarkRPG - classes

Author
Message
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 20th Sep 2008 07:10
So I\'m rewriting much of my code, implementing more class and modular structure.

I\'ve got a couple classes:


RPGImage inherits members from RPGObject. My compiler complains when I don\'t give RPGImage a constructor. Can I construct an RPGImage object using RPGObject::RPGObject(int iImageID, int iSpriteID)?

~you can call me lantz~
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 20th Sep 2008 07:31 Edited at: 20th Sep 2008 07:32
a bit of research yields that derived classes do not inherit constructors. So I write a new one.

RPGObject.h:

RPGObject.cpp:


I still get an error at line 24 though:


~you can call me lantz~
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 20th Sep 2008 07:37
Adding a default constructor to RPGObject did the trick:

RPGObject.h:


RPGObject.cpp:


~you can call me lantz~
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Sep 2008 02:27
Right, now i've got a global array of objects:


And at runtime, I fill it:


But I get an error:


~you can call me lantz~
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Sep 2008 02:36
Mmmm, I was allocating my array wrong:

And filling it wrong:


~you can call me lantz~
Lion Jin
18
Years of Service
User Offline
Joined: 24th Sep 2006
Location:
Posted: 21st Sep 2008 04:25
Its better use a dynamic "list" to track all the objects ,static array is hard for a complex game and waste memory .

You can use STL "list" or "vector" to track all the objects ,the array size is full dynamic, you can kill or recreate a object at any time, and you do not have to make a global object.
Lion Jin
18
Years of Service
User Offline
Joined: 24th Sep 2006
Location:
Posted: 21st Sep 2008 04:25
Its better to use a dynamic "list" to track all the objects ,static array is hard for a complex game and waste memory .

You can use STL "list" or "vector" to track all the objects ,the array size is full dynamic, you can kill or recreate a object at any time, and you do not have to make a global object.
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 21st Sep 2008 09:01
yes... using an array pointer(which is essentially what the array name is when you decalre an array, a constant pointer to an array of the type... the name being the pointer to it..) is not best suited to a game, as they are static, which means the amount of space you give them when you declare them, that is the largest they can be, you CANNOT grow or shrink an array(you can however, make a new array larger than the old one, and copy the contents of one to another... which is the basics of how the STL containers work, although doing this youself means understanding how to work with dynamic memory in C++ without getting leaks etc... (generally when you are inheritting a class from a base class, you want to include whats known as a copy constructor in the base, so that you can set the derived's pointers up properly, ie. pointing to the derived object not the base etc..)
Anyway, I think that you will find it alot easier to manage your arrays of objects if you were to use the STL(perhaps a vector or a list)... it will allow you to have a single array, and add/remove, insert/delete, sort/clear, iterate through etc elements as you please.... and using the STL to look after your lists of things is perfectly acceptable, however, you should know that there is a small amount of overhead involved in using the STL, as it will actually pull a whole heap of template classes into your project, to support itself and its functions, normally its not something you would need to worry about, but if the container you are using will be updated at a high rate, many many times each game loop for example, you may well notice a difference by writing you own array handler to do specifically what you need.

If it ain't broke.... DONT FIX IT !!!
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 23rd Sep 2008 04:39
So, I looked up STL and found vecor.. been looking at that.. looks really nice.

Including it into my game has been an issue though.




It worked fine in an emptyproject. Any ideas?

~you can call me lantz~
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 23rd Sep 2008 04:57
I copied the source files over into a project created using the DarkGDK - 2D template.

These are my errors:


~you can call me lantz~
Lion Jin
18
Years of Service
User Offline
Joined: 24th Sep 2006
Location:
Posted: 23rd Sep 2008 05:14
Set your project to "Multi-threaded (/MT)" in both debug and release mode ,and try again.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 23rd Sep 2008 05:26
I forgot to mention that I'd tried that too

Above was the error from /MTd, here is /MT:


~you can call me lantz~
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 23rd Sep 2008 05:32
Ignoring MSVCRTD.lib did the trick.

~you can call me lantz~
Lion Jin
18
Years of Service
User Offline
Joined: 24th Sep 2006
Location:
Posted: 23rd Sep 2008 09:10
I think you can try to start with a new project .

I have not any problem using STL ,just set project to "Multi-threaded (/MT)",and I did not Ignore any library except "libcmtd, msvcrt, atls" by the wizard.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 24th Sep 2008 17:01
@Lion Jin

I fixed it already.

Quote: "Ignoring MSVCRTD.lib did the trick."


What would be the best method for sticking some of my methods in external files, whilst avoiding #include'ing my main header for globals that they depend on?

Should i pass these globals as parameters from my main source file?

~you can call me lantz~

Login to post a reply

Server time is: 2024-09-30 07:23:09
Your offset time is: 2024-09-30 07:23:09