.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 18th, 2006, 10:15 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++

Thanks again.

For syntax, I tend to go with the needs of the moment.

So, you mean make a handler class for the Character class?

How do you declare something 'extern'?
__________________
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 18th, 2006, 10:24 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++

I don't really know what you're doing, so NarfClass was just an example. NarfClass would be any class that wants to be able to use some external object, without requiring the external object to actually be defined as a global with a certain name in the class definition.

Actually, the classic approach to doing what I think you probably really want to do is to make the Character Vector into a singleton class - a class designed to ensure there is only one of something, and provide access to it to other classes.

I don't really know what your class design is like - that is, how you've decided to divide up the things in your game into classes.

extern is a keyword for referring to objects or variables defined in other files, which would be how you can refer to globals created in other files. The syntax is, for example:

extern int X9B;

This lets you use X9B, but in one and only one other file you need to have the actual declaration:

int X9B;

So you can see that can make your code hard to read and use the more you do that, because it means you have to remember where that global is actually defined, etc.

PvK
Reply With Quote
  #3  
Old August 18th, 2006, 10:33 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++

If you want, I can send you the source code. Right now, the character stuff is mostly in one character class, with a vector for the list of characters and some external functions that deal with that vector class.

Yeah, I think I'll stay away from multiple cpp files if it means externs. 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
  #4  
Old August 18th, 2006, 11:05 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++

Multiple cpp files means externs if you use globals to share info between them.

But for an object-oriented design, you have a class definition file (Foo.h) and a class implementation file (Foo.cpp) for each class, and then you use them in the context of other classes. This way, almost all the code you write solves problems for general cases, and the specific application implementation (e.g. the actual Main function of an application) can then be something more general, simple and high-level.

So Character defines a character object in so general a way, that its .h and .cpp files don't need to refer to the instance of them at all - they refer only to the definition of other related classes, but never to a specific object (or else they'd be usable only with that specific object).

So your list of classes might be something like:

GameState
Level
Character
Item
Potion
Weapon
Armor

Each would have two files, a .h and a .cpp. All would be generic implementations.

Then you'd have a Main.cpp file where the entry point and specific objects are declared. In it you'd have maybe just one GameState object, and just a few calls to its methods, like:

GameState.CreateNewGame();
GameState.Load( SavedGame );
GameState.Play();

GameState itself might have a protected Initialize() method which would be called by both CreateNewGame() and Load(), and GameState would have the only Vectors storing all the objects representing stuff that exists in the game universe.

Etc.

PvK
Reply With Quote
  #5  
Old August 18th, 2006, 11:18 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. Thanks.

That is a radical departure in thinking. I'll have to think about it.

Right now, I'm wanting to do some visible content. Too much code maintenance makes Narf wonder if he's making progress.
__________________
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
  #6  
Old August 18th, 2006, 11:36 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++

Ya. You might want to spend more time having fun making things work, and think about a more O.O. architecture for your next project.
Reply With Quote
  #7  
Old August 19th, 2006, 12:34 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++

Heh. I added armor. Now I'm making it work. Just have to fix the load routine (Again).

Everythings fixed, and armor is now available. Just check the floor in your nearest dungeon.
__________________
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
  #8  
Old August 19th, 2006, 12:50 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++

Anyone know how to turn off the generation of debugging information in Dev c++? I think it's padding my program.
__________________
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 19th, 2006, 02:23 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++

Updated. A couple of weapons with actual names. Savegames should still work.

On the downside, characters aren't properly re-located after descending stairs. Not a game-breaker.
__________________
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 22nd, 2006, 06:24 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.5.0

Breaks savegames. A few different item properties. Items are now more of a trade-off.
__________________
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 07:01 AM.


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