.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
  #41  
Old August 16th, 2006, 11:55 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++

Update: Simple Roguelike v0.1.2.5
Features one type of weapon and one type of potion (healing).

There are few glitches, but nothing game-breaking, I think.

Fixed a few game-breakers. Now, to make it generate new items with a new level.
__________________
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
  #42  
Old August 17th, 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.3

Should all work.
__________________
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
  #43  
Old August 17th, 2006, 04:23 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++

How important is it that an object has a destructor? As far as I know, the 'delete' command is unstable.
__________________
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
  #44  
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
  #45  
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
  #46  
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
  #47  
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
  #48  
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
  #49  
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
  #50  
Old August 18th, 2006, 05:48 PM
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++

// my.h header file, using a vector
#ifndef MY_H
#define MY_H
#include <vector>
using namespace std;

class test{
public:
test(){};
int insert(int in){ number_list.push_back(in); return number_list.size();};
private:
vector<int> number_list;
};

#endif
//eof


// main.cpp
#include <iostream>
#include "my.h"
int main(){
test t;
int result = t.insert(42);
cout << result << endl;

system("pause");
}
// eof

===========
Missing some white space and sequencing in the grave marker:
Strength: Dexterity: 94122 Constitution: 83 Damage: 6Defence: 94.2308 HP: -1/8 XP: 0/0
Looks like stream flushing between numbers and strings.
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 06:37 PM.


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