.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Raging Tiger- Save $9.00
winSPMBT: Main Battle Tank- Save $6.00

   







Go Back   .com.unity Forums > Shrapnel Community > Space Empires: IV & V

Reply
 
Thread Tools Display Modes
  #1  
Old August 16th, 2006, 01:07 AM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default Re: OT: Stupid c++

Thanks.

Somehow, my pointer item vector is getting messed up between its setup and the function to display it.

The thing is, those are the only two points which have anything to do with items at all.

How is this modifying a vector?!?!
Quote:
void text ( std:ring tstring, int x, int y, short int Colour ) {
COORD Position; Position.X = x; Position.Y = y;
SetConsoleTextAttribute( hOut, Colour );
SetConsoleCursorPosition( hOut, Position );
std::cout << tstring;
};
Apparently, inputting too large of a block of characters (Between twenty and thirty) somehow affects the vector. Help, anyone?
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
Reply With Quote
  #2  
Old August 16th, 2006, 02:09 AM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default Re: OT: Stupid c++

Can anybody see a problem with this:
Quote:
void setupItems () {
srand ( time(NULL) );
// NewWeapon.initialize (); NewPotion.initialize ();
// WeaponList.push_back ( NewWeapon ); PotionList.push_back ( NewPotion );
for ( t = 0; t < 40; ++t ) {
t2 = rand () % 2;
if ( t2 = 0 ) {
NewWeapon.initialize (); WeaponList.push_back ( NewWeapon );
WeaponList[WeaponList.size () - 1].initialize ();
ItemList.push_back ( &WeaponList [WeaponList.size () - 1] );
};
if ( t2 = 1 ) {
NewPotion.initialize (); PotionList.push_back ( NewPotion );
PotionList[PotionList.size () - 1].initialize ();
ItemList.push_back ( &PotionList [PotionList.size () - 1] );
};
};
for ( t = 0; t < ItemList.size (); ++t ) {
ItemList[t]->initialize ();
std::cout << t << " " << ItemList [t]->XPos << " " << ItemList [t]->YPos << " " << ItemList[t]->Colour << " ";
};
std::cin >> wait;
};
It doesn't seem to work right - It seems like all the slots still reference as the base Item class.
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
Reply With Quote
  #3  
Old August 16th, 2006, 04:00 AM
AngleWyrm's Avatar

AngleWyrm AngleWyrm is offline
Second Lieutenant
 
Join Date: Mar 2005
Location: Seattle, WA
Posts: 417
Thanks: 0
Thanked 0 Times in 0 Posts
AngleWyrm is on a distinguished road
Default Re: OT: Stupid c++

Bug: if(t2 = 0) // assign zero to t2, return true (successful assignment)
You probably meant: if(t2==0) // test for equality

Happens so often that some compilers even have a warning for it.
Reply With Quote
  #4  
Old August 16th, 2006, 04:18 AM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default Re: OT: Stupid c++

Thanks. We're whacking it into shape on IRC.
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
Reply With Quote
  #5  
Old August 17th, 2006, 05:49 PM
PvK's Avatar

PvK PvK is offline
National Security Advisor
 
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
PvK is on a distinguished road
Default Re: OT: Stupid c++

Classes should define a destructor if something needs to happen every time one gets destroyed (either by delete or by a non-static member going out of scope). It is important to prevent memory leaks if the class has any heap-allocated memory that it maintains the only pointer to and should remove when it dies.

If an object has no heap-allocated memory (i.e. it doesn't create anything with "new" or "malloc"), and if nothing needs to happen when it gets deleted, then it doesn't need a destructor.

However, I really doubt any worthwhile C++ compiler is going to have a fundamental problem with destructors or with delete. If it did, it would be seriously crippled. I expect probably you are seeing some other bug.

What are you deleting when you see problems? Objects with destructors that do things like use objects that are already destroyed?
Reply With Quote
  #6  
Old August 17th, 2006, 10:12 PM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default Re: OT: Stupid c++

Huh?

No, I use data types like 'int' and 'char'. Never new.

I just had a vague memory of someone saying the 'delete' command was unreliable.

Not using delete. I have, in fact, no destructors at all and a vague feeling that this might be bad.
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
Reply With Quote
  #7  
Old August 17th, 2006, 11:53 PM
PvK's Avatar

PvK PvK is offline
National Security Advisor
 
Join Date: Dec 1999
Posts: 8,806
Thanks: 54
Thanked 33 Times in 31 Posts
PvK is on a distinguished road
Default Re: OT: Stupid c++

Destructors are simply functions that get called when an object is deleted. If you never use new or malloc, then you probably never use delete nor free either, and your objects will only be deleted automatically - i.e. if they are local to a function and that function exits, or when the program exits. In other words, it sounds like you probably don't need to worry about destructors at all.

What are you going to do about creating new things during play, though, like new monsters, items, levels, etc.? Are you using STL lists of objects (not of pointers to objects) and just adding them and removing them from those? If so, then imagining how your code probably looks, STL should be doing the cleanup for you, and you shouldn't need to define destructors...

... well, ok, as long as you don't start using pointers or references to items in those lists, and expecting them to always be there after other events have happened that might have removed them from the lists. That could lead to a nice invalid pointer or reference and crash.

Example:

Say you have a list of all monsters in the world called MonsterList. Then say you have a Quest object to slay a particular monster, which when it gets launched, adds a monster to MonsterList and then keeps a pointer or reference to that monster object, to refer to the monster to slay. Now, if something in the game can remove the monster from MonsterList, causing its object to be automatically deleted by STL, then referring to a reference or pointer to it will be an access violation and boom. So if you want to avoid that, you could give monsters also a unique ID, and when you refer to them, always go search the list.

Of course, that's a fairly slow operation, but you probably don't care too much until you have thousands of things going on at once in your gameworld. To be faster, you could have a destructor that announces when something gets deleted, and causes everything that might refer to it to drop their pointers and references to it. Sounds like you'd probably be better off keeping things simple and reliable for now, though.
Reply With Quote
  #8  
Old August 18th, 2006, 12:19 AM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default Re: OT: Stupid c++

Currently I'm using vectors for items and an array for the map.

I'm using pointers for characters, but that's the next thing I'm going to replace. In the meantime, the number of characters never changes; dead characters are simply re-randomized.

Thanks.
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
Reply With Quote
  #9  
Old August 18th, 2006, 02:05 AM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default Re: OT: Stupid c++

Update: Simple Roguelike v0.1.4

It's been extensivly tested for all of two or three minutes, but everything should work. No cosmetic changes, but a lot of code was fixed so as to result in less heart attacks on IRC. Also, it's nearly 2MB, so I stuck it in a .rar
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
Reply With Quote
  #10  
Old August 18th, 2006, 05:25 AM
narf poit chez BOOM's Avatar

narf poit chez BOOM narf poit chez BOOM is offline
Shrapnel Fanatic
 
Join Date: Mar 2003
Location: CHEESE!
Posts: 10,009
Thanks: 0
Thanked 7 Times in 1 Post
narf poit chez BOOM is on a distinguished road
Default Re: OT: Stupid c++

Readme's are good. I added one, just in case people hadn't found the help key.
__________________
If I only could remember half the things I'd forgot, that would be a lot of stuff, I think - I don't know; I forgot!
A* E* Se! Gd! $-- C-^- Ai** M-- S? Ss---- RA Pw? Fq Bb++@ Tcp? L++++
Some of my webcomics. I've got 400+ webcomics at Last count, some dead.
Sig updated to remove non-working links.
Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 04:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2024, Shrapnel Games, Inc. - All Rights Reserved.