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 / constants

Author
Message
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 21st Jun 2008 09:01
what's the point? why not just keep the normal data type?
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 21st Jun 2008 09:23
They look purdy.

If you can do any models for FW, reply to the FleetWars thread.

Click here!
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 21st Jun 2008 10:43
To stop anything modifying them?

Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 21st Jun 2008 17:45
One reason is that if something in your program should be a contant for example Pi =3.142 you or other programmers in your team will not be allowed to change the value within your program.

System
MacBook Pro
Windows XP Home on Boot Camp
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jun 2008 18:03
Multiple programmers is definitely a reason. Also, it makes sure you don't try changing it forgetting it needs to be a constant.
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 21st Jun 2008 19:27
Quote: "what's the point?"


I tend to agree.
If a member of a team does change the value of a variable that should be constant, then they should be sacked or at least shot.

I never did like people assigning a value to a variable and then using that variable throughout their code. the overheads in having to look up the value for the variable is a total waste.

The "# define" directive is so much better and hell of a lot faster.


EG:
# define Pi 3.142

Will replace any area in your code where the text Pi happens to be.

There is therefor no runtime lookup overheads.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 21st Jun 2008 23:48
Why such low precision? Boo. Pi = 3.14159265. Heh, I memorized that.

If you can do any models for FW, reply to the FleetWars thread.

Click here!
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 22nd Jun 2008 03:28
i like #defines and i've used them before. a lot.

which leads to my next question.

how do you coordinate multiple programmers working on a project?

how do you make sure the functions and such line up?
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 22nd Jun 2008 04:11 Edited at: 22nd Jun 2008 06:09
Quote: "how do you coordinate multiple programmers working on a project?"


One way is to break up the project into different functional parts.

a simple example:
1)Menu subsystem.
2)Game subsystem.
3)networking subsystem.

Each one of these will have a particular function to enter the respective code.

Define what the function will be called and what the parameters will be called that pass data into and out of these functions.

Any Data Structures that will have data that has to be accessed from more than one of the above mentioned subsystems will now also have to be defined and given fixed names so that all relevant programmers will be calling shared data by the same name and in the same data structure.

At this point each of the separate members can now got on with the code for their respective subsystem.

Mind you this was just a very simplistic guideline.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 22nd Jun 2008 04:43
i recently went through all of my functions and started beefing up on the parameters, so that they could all be put together seperately, even in different files.

a good practice, i'd say.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 22nd Jun 2008 13:51
in my mind their most useful application is in pointers and strings. But for an indepth look at const:

http://www.possibility.com/Cpp/const.html

MACRO
21
Years of Service
User Offline
Joined: 10th Jun 2003
Location:
Posted: 22nd Jun 2008 18:51
Constants and #defines are both very useful if used appropriately and very destructive if used inappropriately. The same goes for everything in C++

The trick is to pick a style that suits you and your project (unless there are specific design constraints or well known "best practice" ways of doing a particular thing).

With regard to teamwork on projects...

If you are looking at collaborative working on a game one of the most useful things you can do is get some sort of source control set up. Personally I recommend either CVS (http://www.nongnu.org/cvs/) or Subversion (http://subversion.tigris.org/). Both of which will allow you to keep tabs on who changed what in the code base and offer the ability to roll back changes if something/someone breaks the build.

They also provide basic mechanisms for resolving conflict (what happens if two people make different changes to the same file) which can be a godsend when working in a team.

Combined with a tool like winmerge (http://winmerge.org/) this type of source control is very useful.

From a more organisational point of view to get effective collaborative working you need to break down the project into clearly defined areas of responsibility. That way you know precisely who is working on net code and who is doing the GUI etc.

Perhaps the hardest thing with working in a team and one of the reasons things fail early tends to be getting everybody to agree to what the project actually is up front and what level of input they will get into its core design once it is set rolling.

When working with others especially on something as creative as games development it is essential to have a good (and as far as possible) complete design document. That way once everybody has signed up to it and agreed what they are all trying to create there are few arguments to be had.

Ideally the design document (or another document) should also specify coding standards etc. Things are a lot easier if everybody uses the same style of coding in a project. It can get confusing if one coder is using all lowercase for constants and one is using uppercase for example.

Having the projects goals clearly documented also helps to put a lid on feature creep. One person can add dangerous complexity to a project by thinking "Its cool as it is but if I add this then it will rule..." (I know, I am as guilty of this as anybody) and the more people working on something the more (normally very good) ideas will get injected which although valuable and a positive part of working in a team can lead to vapour-ware if not managed correctly.

You can also make things a lot easier on you and your team if you ensure that you design in modularity from the outset. People should be looking at delivering encapsulated classes and functions with clearly defined interfaces rather than snippets or large monolithic blocks of code. Keeping delivery to functions and classes makes things easier to test, easier to document and also means that if you loose a member of the team for whatever reason their code should be small and atomic enough to understand and continue to work with. This can help to avoid potential show-stoppers in the future.

I hope some of this is useful

Macro
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 22nd Jun 2008 20:28
Quote: "Why such low precision? Boo. Pi = 3.14159265. Heh, I memorized that."


So why didn't you remember it out to its final precision? You never know how precise you need to be if you ever have to land space craft at a specific spot on one of Io.

Back in college I used to carry an index card that had Pi to 100 decimal places. In my spare time I'd try to add another 5 digits to how many I had memorized. I never made it to 100. I topped out at 85. I can still rattle the numbers off to about 25 places but if I had to write them down I'd probably slip up somewhere.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 22nd Jun 2008 20:51
Wow. 85 places. That's a lot.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 22nd Jun 2008 21:20
I can do 45 off my head:
3.141592653589793238462643383279502884197169399
i always wanted to go for 50 but however many times i look at the last 5 i can never remember them
Going slightly off topic arent we...
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 22nd Jun 2008 22:39
That's actually how far I can currently quote. I thought it was around 25 digits but it's hard to count digits when you're rattling them off.

The trick I was taught was to type them up on a card but put a space between every group of five digits. This gives you less to concentrate on and you can ignore the confusion of the numbers around the grouping. Memorize one grouping then move on to the next while quoting the ones you've already learned.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 22nd Jun 2008 23:19
How does VC++ know where to find DarkGDK.h?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Jun 2008 00:16
When you ran the template wizard for creating the basis for the game it included the appropriate directory in the additional includes for the project.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 23rd Jun 2008 00:57
i dont use the template. i just include.
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 23rd Jun 2008 02:11
I remember reading a book on C++ a long time ago. It said:

If you use C defines, eg. "#define CONSTANT 100", the value of the constant can be changed but the program will change them back.

Eg. "CONSTANT = 50; // changes to 50 but goes back to 100"

If it is a constant, eg. "const int CONSTANT = 100;", and you try to change the value, a memory access violation exception will be thrown out. I don't know if it changed through time or not, because the book was written in 1999.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Jun 2008 08:02
If you use C defines, eg. "#define CONSTANT 100", the value of the constant can be changed but the program will change them back.

Eg. "CONSTANT = 50; // changes to 50 but goes back to 100"[quote]

That wouldn't compile. Your #define tells the preprocessor to scan the code and when it encounters the string "CONSTANT" substitute the string "100". When the compiler sees it, it should reject it because it's saying

100 = 50;

which you can't do because the lvalue can't be a constant.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 23rd Jun 2008 08:30 Edited at: 23rd Jun 2008 08:31
exactly. in this way, more complex macros can be #defined.
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 23rd Jun 2008 23:59
I was confused a bit.. Just making sure Thanks for correcting me, Lilith.

elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 24th Jun 2008 09:50
now...

why private data members?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 24th Jun 2008 15:11
Quote: "why private data members?"


Is this a whole new question?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
MACRO
21
Years of Service
User Offline
Joined: 10th Jun 2003
Location:
Posted: 25th Jun 2008 22:28
Private data members provide one of the main features of encapsulation - The ability to provide controlled access to data through a clearly defined interface.

If you have all your data public people have direct access to change it which is fine for a lot of data. If you have a data value that you need to track changes on or audit you can enforce that using private data and public access methods. For example...



That's a very trivial and to a large extent pointless example but hopefully it makes the point. This could equally be used to fire an event when data is updated facilitating easy use of design patterns like observer.

Macro

Login to post a reply

Server time is: 2024-11-20 15:25:28
Your offset time is: 2024-11-20 15:25:28