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 / bullet class

Author
Message
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 1st Oct 2008 01:42 Edited at: 1st Oct 2008 01:43
I have a bullet class defined in a header file as such:



and the code for the fire_bullet function is:



I call it in my main program like so:



It keeps triggering a breakpoint at the line where i try to determine the free objects using dbObjectExist (). It says
"Unhandled exception at 0x004a7e2b in program.exe: 0xC0000005: Access violation reading location 0xccdfc564." Can anyone tell me what the problem is?

If you need to see the rest of the class to get more info, please let me know. this is a real pain.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 1st Oct 2008 01:56
Bravo. Well done.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 1st Oct 2008 04:47
well, i did have a lot of help designing it, but i am totally mystified at this exception. Could it possibly be a problem with my installation of Visual C++?
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 1st Oct 2008 14:14
I am a little confused at what you are doing.

Why are you creating the bullet spheres as you use the bullets.
It looks like a waste of valuable game loop time.

Why not make a table of "BULLET" data structures the size of the maximum number of bullets allowed.
Pre-create each bullet when game initializes, and hide them all.

When you use a bullet item, then just position it at its start point and un-hide it.
When a bullet item has reached its expire time, then hide it again, ready for next use.

Just cycle through the table from bottom to top and then fold back to bottom. This way as you are progressively cycling through the table, if a situation occurs where you have no free bullet objects left over, then the game will use the oldest bullet first, so that all that happens is the oldest bullet life gets prematurily terminated, and that is all.
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 1st Oct 2008 14:37
Well, actually, that's exactly what i was going to do. I was going to make it so that you would "load" the class with an array of integers which would hold the bullet numbers. that way, you know exactly what each number is and can work around it. I just never got around to that part...
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 1st Oct 2008 14:50
AHHHHHH..... fine.

I basically just finished a similar exercise for my WW2 Flight sim a few hours ago.

Only difference was I did it in structured C rather than C++ OOP.

And likewise had to integrate gun convergence into it at the same time.
Still have to optimise the code, but am having no problems running 128 real bullets, and 256 phantom bullets.

I used backwards facing cones as the bullet trails, rather than actually having the bullet visiable.

Have fun
xix psycho xix
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 1st Oct 2008 14:59 Edited at: 1st Oct 2008 15:05
Well, the bullets were actually gonna eventually be invisible anyways, so thats fine. What i did was make a separate class weapon that took care of ammunition counters and the name of the current weapon. As many bullet lists as needed would be added, and then each weapon would be modified independently of each other.

By the way, i want to clear something up. If a function returns a pointer, can you assign that return value to another pointer and get the array there, or does the pointer you assign to it need to be allocated? Say:



would this code work, or does my_ptr have to be allocated first? That is one thing about pointers that always confuses me
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd Oct 2008 07:48 Edited at: 2nd Oct 2008 07:50
Quote: "well, i did have a lot of help designing it, but i am totally mystified at this exception. Could it possibly be a problem with my installation of Visual C++? "


Oops. I missed the error part.

Quote: "would this code work, or does my_ptr have to be allocated first? That is one thing about pointers that always confuses me "


I believe it would, assuming FillArray uses new to return a pointer value of the array. But, don't always trust me at 12:00.

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

Login to post a reply

Server time is: 2024-11-25 03:42:13
Your offset time is: 2024-11-25 03:42:13