delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/18/21:30:02

From: "Steve Chalkley" <sjc AT conceptii DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
References: <A34D5D3BF0DFD2119E3D0008C70840FA04FD90 AT TWZNT11>
Subject: Re: Global variables and structs?
Lines: 57
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Message-ID: <Fijr4.155$_L2.5279@news2-win.server.ntlworld.com>
Date: Fri, 18 Feb 2000 22:02:07 -0000
NNTP-Posting-Host: 194.168.10.116
X-Complaints-To: abuse AT net DOT ntl DOT com
X-Trace: news2-win.server.ntlworld.com 950911269 194.168.10.116 (Fri, 18 Feb 2000 22:01:09 GMT)
NNTP-Posting-Date: Fri, 18 Feb 2000 22:01:09 GMT
Organization: ntl News Service
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I'm currently reading "Game Design -Secrets of the Sages" (quite good intro
to the games industry) and one of the contributors comments on this specific
point. Basically, today you only have one map in your game, tomorrow you
might have two or a dozen. Adding the second map will be _really_ unpleasant
once the global has spread itself around your code. Do it right from the
start, passing parameters is no problem at all, especially if you use
classes or structures properly.

Post a link to the game when it's done ;-)



Nigel Atkinson <Nigel DOT Atkinson AT MeridianEnergy DOT co DOT nz> wrote in message
news:A34D5D3BF0DFD2119E3D0008C70840FA04FD90 AT TWZNT11...
> I think it depends on the type of data your are talking about.\
> I have in one program for instance a global instance of a class
representing
> the map in my game.
>
> There will only every be one instance of this class, and the WHOLE program
> is build around it so it makes sence to be global.  However use of global
> variables should be carefuly considard.  Usally the pros. outweigh the
cons.
>
> Nigel Atkinson
>
> -----Original Message-----
> From: Prashant TR [mailto:prashant_tr AT yahoo DOT com]
> Sent: Friday, 18 February 2000 07:09
> To: Kalum Somaratna aka Grendel
> Cc: djgpp AT Delorie DOT com
> Subject: Re: Global variables and structs?
>
>
> On Thu, 17 Feb 2000, Kalum Somaratna aka Grendel wrote:
>
> > This is true but the calculated use of global variables can help to
avoid
> > passing many arguments to functions. So using global variables can help
to
> > simplify the code and also make it easier to understand. But IMHO this
> > should be done if you are confident with C/C++.
>
> Doesn't help most of the times, but creates a nuisance instead. It's a bad
> practice to do this. Things like this can be used only for a single
> program, certainly not for a large project.
>
> > > Do it with structs.  Then you can pass a pointer to the struct and to
> > > the screen and be done with it.
> >
> > Or better still use a global struct. That way you won't have to pass
> > anything at all and it will make writing the code easier.
>
> Don't think this is a good idea. What Damian has said would get you a
> better program. If the array is too large, consider using malloc.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019