Difference between revisions of "C plus plus version"

From WikiManual
Jump to: navigation, search
m (See also)
(Totally reorganized and rewritten)
Line 1: Line 1:
Original document (and comments)  by Taldor in black, comments by Numsgil in <font color="Red">Red</font> and comments by Griz in <font color="green">green</font>.
+
==News and Updates==
  
We discuss the C++ design and coding standards in here. A wiki is much handier then a forum or PM's for this.
+
(05 Feb 2006) The C++ version is nearing completion. It might even be possible to have a beta done by the end of the month, but it means Numsgil needs to really put some effort in, and he's sort of tired of programming. If you know any C++ and want to help, I assure you we'll welcome you with open arms!
  
== Language switch ==
+
== Reasons for Language switch ==
  
You wonder why we're switching? Because VB is for simple, gui based programs. Darwinbots is nor a simple program, nor gui based. In contrary C++ is a powerfull language, but it has a higher development cost.  
+
#You wonder why we're switching? Because VB is for simple, gui based programs. Darwinbots is nor a simple program, nor gui based. In contrary C++ is a powerfull language, but it has a higher development cost.  [http://en.wikipedia.org/wiki/Visual_basic#Controversy Visual Basic controvercy]
 +
#Visual Basic does not intrinsically support pointers.  As such, complex data structures become something of a chore to try and make.
 +
#Numsgil knows more about C++ than he knows about Visual Basic.
 +
#C++ can be made to be portable (say, we could make a Linux version).  And presently the code is being developed with portability in mind  (though as yet untested).
  
[http://en.wikipedia.org/wiki/Visual_basic#Controversy Visual Basic controvercy]
+
== Accessing the Current Code ==
 +
The code is in an online version control system called [http://en.wikipedia.org/wiki/Subversion_%28software%29 SVN]
  
== C++ design ==
+
To access the SVN, you should download a SVN client.  The one I found that I like the most is called [http://www.smartsvn.com/smartsvn/index.html Smart SVN].  It's basic (and more than adequate) version is free.
  
=== General concepts ===
+
The SVN for Darwinbots is located at:
  
* Class based approach. <font color="Red"> In some cases, procedural in others. It's a value decision I'll make as I port the code. </font>
+
* [http://opensvn.csie.org/Darwinbots http://opensvn.csie.org/Darwinbots]
* Portable code. <font color="Red"> Where possible. Preferably in house or free library wrappers for non portable functions, such as multithreading and OS timers. </font>
+
* [https://opensvn.csie.org/Darwinbots https://opensvn.csie.org/Darwinbots] secure server
  
=== Structure ===
+
'''Read only access is open to everyone.  If you want to contribute to the code, you'll need Numsgil to give you a username and password.'''  He can be reached at Numsgil2002@yahoo.com
<font color="Red"> See the present VB code </font>
 
  
: The VB stucture is not a good C++ structure. VB and C++ are totally diffrent languages.
+
== Code Dependencies ==
 +
To get the code to compile and work, you'll need the following:
  
:: <font color="Red">Only in the microscopic sense.</font>
+
#A C++ compiler.  [http://www.bloodshed.net/devcpp.html Dev-C++] is free, but there have been some issues with it conflicting with Microsoft Visual C++ 6.0 (which Numsgil uses, and hence is the officially supported environment).  If you don't have MSVC++ 6.0 and would like it, contact Numsgil at Numsgil2002@yahoo.com
 +
#OpenGL libraries.  Specifically, the code must link to glut32.lib, opengl32.lib, and glu32.lib.  You probably have these on your computer somewhere, but if you don't, [http://www.opengl.org/resources/faq/getting_started.html this site will help you]
 +
#Fox GUI Toolkit.  This is the library which allows Darwinbots to have a GUI at all.  [http://www.fox-toolkit.org/ FOX GUI Homepage].
 +
#The STLport for MSVC++ 6.0 if you have MSVC.  Dev-C++ won't need this.  It can be found at [http://www.ogre3d.org/index.php?option=com_remository&Itemid=57&func=selectcat&cat=1 The Ogre 3D engine download page].  It should be listed at the bottom of the page.  This makes MSVC a bit more ANSI compliant, among other things.
 +
#I don't know how it works for Dev-C++, but if you run MSVC you must be sure that you select the Multithreaded libraries or you'll probably get an error.  To set this, inside MSVC in your project go to project->settings.  Go to the C/C++ tab, change category "General" to category "Code Generation". The new upper right hand corner drop box will let you set if you're using multithreaded/singlethreaded libraries.
  
::: Could you please explain? To me they seem totally diffrent.
+
If you have any problems at all with any of the above steps, or want to help Numsgil make the process a bit smoother and have some ideas, contact him at Numsgil2002@yahoo.com.
  
:: <font color="Red">When you view the way in which the VB modules interact, that's exactly the same way the C++ modules will interact. Wether you paint in black and white or in color, shapes are going to be the same. </font>
+
== Coding Style ==
 +
The official policy is that as long as Numsgil understands what's going on in your code, your style is fine. If you want to have a more uniform coding style throughout the code, this is the style Numsgil uses:
  
::: Shapes and colors have very little to do with the structure of a program.
+
for(unsigned int x = 0; x < 10; x++)
 
+
  {
:::: <font color=#008800>That was a metaphor ... Nums is trying to say, if i may interpret here ... that both VB and C++ utilize 'moduals' in much the same way. The code within a modual may be quite different ... but the 'structure' of how moduals and routines are called up ... is similar. So i take him as saying the 'infrastructure', the outline, the 'overview' ... is already there.
+
    cout << x; //notice the 4 space tab
:::: but then ... perhaps i haven't a clue. ;) that's always a possibility as well. {{User:Griz/sig}} 19:10, 1 Nov 2005 (MST)</font>
+
}
 
 
::::: <font color="Red">That's exactly what I meant. ;)</font>
 
 
 
:::::: You could make the Darwin engine (the part of the engine that takes care of the robots, vegs, senses, etc.) the same as it was in VB. There are a lot of things that I would change (like not using friend classes), but it's acceptable for C++. The other part of the program (the GUI and the graphics) is totally diffrent in VB and in C++.
 
 
 
:::::::<font color = "Red">Yep, but GUI and graphics aren't ranking very high on my list of concerns. I mean, look at the program we have as it stands right now.  It's always been somewhat of an afterthought.  Now if you'd like to change that and add some killer graphics...  ;)</font>
 
 
 
:::::::: I didn't mean the implementation, but the structure of that part of the program. (read: the design)
 
 
 
 
 
* User Interface ([http://www.fox-toolkit.org Fox Toolkit])
 
** Simulation sub window (3D - [http://www.opengl.org OpenGL])
 
** Darwin (the simulation engine)
 
*** Tie
 
**** Robot
 
***** Sense
 
**** Veg
 
 
 
To be used everywhere:
 
* Vector_4 (using [http://www.boost.org/libs/numeric/ublas/doc uBLAS]) <font color="Red"> Present vector class is from [http://www.gamedev.net/reference/articles/article605.asp this gamedev.net article]. I'll use whichever is fastest, feel free to perfrom benchamrks </font>
 
* Matrix_4 (also using uBLAS) <font color="Red"> See above </font>
 
* Random (using 'srand()' and 'rand()') <font color="Red"> See [http://library.lanl.gov/numerical/ the chapter on random numbers]</font>
 
* Object (the base class) <font color="Red"> Depends on the class </font>
 
  
Ahem! This doesn't seem very conclusive nor very detailed. I suggest we discuss this on [[/Structure|another page]]. [[User:Sprotiel|Sprotiel]] 11:45, 6 Jan 2006 (MST)
+
You are welcome to follow it.
  
== C++ coding standards ==
+
== Coding Doctrine ==
 +
The goal of the code is two things:
  
# C++ <font color="Red"> C++ libraries where such libraries do what I want them to do, C libraries otherwise.  Another value decision. </font> All C librairies are included in C++. Mixing C and C++ isn't the easiest task, however OO C++ and procedural C++ can be mixed easily. <font color = "Red"> I agree, but I've been having some trouble with various C++ libraries that immediatly goes away when I switch to the C versions. Might just be my compiler MSVC++ 6.0</font> Prolly, it's crap. :-P Try the MinGW version of the gcc compiler.
+
#Speed
# Four spaced tabs - <font color="Red"> Aye. </font>
+
#Readability
# External librairies when possible (ie. [http://www.boost.org/ Boost]) <font color="Red"> Internal libraries where possible, to decrease the number of code dependancies, except where external libraries perform the job faster/more comoprehensively than internal libraries can. </font>
 
# Use the 80 character line <font color="Red">If you insist...</font> Yup, I do. ;-)
 
# [http://www.fox-toolkit.org Fox Toolkit]
 
# [http://www.opengl.org OpenGL]
 
  
=== Coding style ===
+
Wherever speed is not an issue (as in 97% of the code) coders are encouraged to make the code as readable to newbies as possible. Imagine your mother's life depends on her deciphering your code and you won't be around to help. That means no clever programming tricks, and sparing use of any standard libraries and especially templates and inheritance and polymorphism and other "advanced" concepts.
 
 
This is how I code:
 
 
 
void function(parameter 1, parameter 2)
 
  {
 
    for(some; things; inside)
 
    {
 
        blah;
 
    }
 
  }
 
  
Notice the 4 space indentation.
+
== To Do List (updated sparringly) ==
 +
Feb 05 2006
 +
Presently, the following needs to be finished before a "BETA" can be achieved:
  
I don't care how you write code, so long as I can read it and understand it. When we edit each other's code, we should endeavor to maintain the same style as the rest of the function we're editingThat is, don't mix styles in the same function.
+
*The GUI needs to be finished and integrated with the options data structure
 +
*Physics for robots needs to be finished (specifically, velocity limiting code and non-in-elastic collisions)
 +
*-3, -4, -5, and -6 shots need to be finished, as well as viruses (though viruses may be disabled in the initial release depending)
 +
*Ties need to be coded using the new Tie paradigm discussed [http://forum.darwinbots.com/index.php?showtopic=560 here]
 +
*The Robot Debugging window and robot mouse selection need to be finished.
 +
*The graphics and engine need to be made thread safe.
 +
*Mutations code needs to be finished (currently Sprotiel is working on this)
 +
*Forward and backward compatible save/load routines for Simulation Settings, Simulations, and RobotsPreferably ascii over binary, except where size is an issue (as in Simulation settings), where some sort of file compression would be nice.
  
If you don't like the idea of mixing styles at all in the whole project, feel free to adopt my style. ;)
+
These would be nice, but aren't 100% necessary for the "Beta" label
  
If you're adding a line that isn't very reader friendly, please comment in thoroughlyWrite the code as if a bunch of non-savvy beginning programers are going to read and edit itNo fancy programming tricks pleaseDo in 8 lines what you can cram into 2 if 8 lines makes it more readableUse lots of white spaceThis code needs to be maintainable by anyone and everyone.
+
*Scripts.  PY was working on the idea of what they should be, so he should be consulted.
 +
*Error DatabaseBasically, on an error an automatic report could be sent to one of the MYSQL databases available through our webspace and a notification sent to anyone working on the code automatically.  Also, some sort of error viewer inside Darwinbots would be nice, so users could see how many other users reproted the error they recieved and wether or not it's been addressed by the coders yet.
 +
*Bot Database.  A way to upload and download bots from a central database from inside Darwinbots itselfAlso using a Database as described above (we have 10 of the things, we won't run out :P)
 +
*Statistical toolsThis would involve everything from collecting data from the sim (and analyzing it according to proper statistical tests) to building a graph form and deciding how to draw it to exporting the data as per user specs into a spreadsheet program (like Excel)It is prefered that whoever works on this have some statistics background so they know what sort of stats users would want to collect and test.
 +
*The vision testing algorithm is presently O(n^2), as it uses the "brute force" methodIt can be made nearly linear O(n) by using uniform grid cells. see:
  
My compiler is MSVC++ 6.0, and so that's the official compiler of the rest of the project.  If you use a different compiler, I will endeavor to let it compile for you. But the privelege of compiling to the nice sight of 0 errors, 0 warnings is reserved for me and others using MSVC++ 6.0. I can supply versions of MSVC++ 6.0 to some who'd like it. [[User:Numsgil|Numsgil]]
+
:[http://yallara.cs.rmit.edu.au/~mawurm/cosc1224/asst1/index.xhtml This resource which exmines the issue]
  
== Quotes ==
+
:[http://www.harveycartel.org/metanet/tutorials/tutorialB.html This resource which describes the implementation and problems associated with it]
  
# "There must be something terribly wrong with your code. Please fix it." -- [http://www.bloodshed.net/dev/devcpp.html Dev-C++]
+
:Collision detection could use a similar technique, though its gains would be complicated by the fact that bots are not uniform in size.
  
== See also ==
+
:This would mean an absolutely insane boost in speed for large sims, but also would take some work.
  
# [[RoundTable]]
+
==Contact==
# [http://www.cppreference.com C/C++ Reference]
+
If you would like to help with the code, and any of the above sound interesting or do able, feel free to contact Numsgil at Numsgil2002@yahoo.com to discuss your ideas.
# [http://www.parashift.com/c++-faq-lite C++ FAQ Lite]
 
# [[Current events]] <!---orphaned page--->
 
Paul is still alive , he will be back to see the c++ virsion bau2005
 

Revision as of 16:04, 5 February 2006

News and Updates

(05 Feb 2006) The C++ version is nearing completion. It might even be possible to have a beta done by the end of the month, but it means Numsgil needs to really put some effort in, and he's sort of tired of programming. If you know any C++ and want to help, I assure you we'll welcome you with open arms!

Reasons for Language switch

  1. You wonder why we're switching? Because VB is for simple, gui based programs. Darwinbots is nor a simple program, nor gui based. In contrary C++ is a powerfull language, but it has a higher development cost. Visual Basic controvercy
  2. Visual Basic does not intrinsically support pointers. As such, complex data structures become something of a chore to try and make.
  3. Numsgil knows more about C++ than he knows about Visual Basic.
  4. C++ can be made to be portable (say, we could make a Linux version). And presently the code is being developed with portability in mind (though as yet untested).

Accessing the Current Code

The code is in an online version control system called SVN

To access the SVN, you should download a SVN client. The one I found that I like the most is called Smart SVN. It's basic (and more than adequate) version is free.

The SVN for Darwinbots is located at:

Read only access is open to everyone. If you want to contribute to the code, you'll need Numsgil to give you a username and password. He can be reached at Numsgil2002@yahoo.com

Code Dependencies

To get the code to compile and work, you'll need the following:

  1. A C++ compiler. Dev-C++ is free, but there have been some issues with it conflicting with Microsoft Visual C++ 6.0 (which Numsgil uses, and hence is the officially supported environment). If you don't have MSVC++ 6.0 and would like it, contact Numsgil at Numsgil2002@yahoo.com
  2. OpenGL libraries. Specifically, the code must link to glut32.lib, opengl32.lib, and glu32.lib. You probably have these on your computer somewhere, but if you don't, this site will help you
  3. Fox GUI Toolkit. This is the library which allows Darwinbots to have a GUI at all. FOX GUI Homepage.
  4. The STLport for MSVC++ 6.0 if you have MSVC. Dev-C++ won't need this. It can be found at The Ogre 3D engine download page. It should be listed at the bottom of the page. This makes MSVC a bit more ANSI compliant, among other things.
  5. I don't know how it works for Dev-C++, but if you run MSVC you must be sure that you select the Multithreaded libraries or you'll probably get an error. To set this, inside MSVC in your project go to project->settings. Go to the C/C++ tab, change category "General" to category "Code Generation". The new upper right hand corner drop box will let you set if you're using multithreaded/singlethreaded libraries.

If you have any problems at all with any of the above steps, or want to help Numsgil make the process a bit smoother and have some ideas, contact him at Numsgil2002@yahoo.com.

Coding Style

The official policy is that as long as Numsgil understands what's going on in your code, your style is fine. If you want to have a more uniform coding style throughout the code, this is the style Numsgil uses:

for(unsigned int x = 0; x < 10; x++)
{
    cout << x; //notice the 4 space tab
}

You are welcome to follow it.

Coding Doctrine

The goal of the code is two things:

  1. Speed
  2. Readability

Wherever speed is not an issue (as in 97% of the code) coders are encouraged to make the code as readable to newbies as possible. Imagine your mother's life depends on her deciphering your code and you won't be around to help. That means no clever programming tricks, and sparing use of any standard libraries and especially templates and inheritance and polymorphism and other "advanced" concepts.

To Do List (updated sparringly)

Feb 05 2006 Presently, the following needs to be finished before a "BETA" can be achieved:

  • The GUI needs to be finished and integrated with the options data structure
  • Physics for robots needs to be finished (specifically, velocity limiting code and non-in-elastic collisions)
  • -3, -4, -5, and -6 shots need to be finished, as well as viruses (though viruses may be disabled in the initial release depending)
  • Ties need to be coded using the new Tie paradigm discussed here
  • The Robot Debugging window and robot mouse selection need to be finished.
  • The graphics and engine need to be made thread safe.
  • Mutations code needs to be finished (currently Sprotiel is working on this)
  • Forward and backward compatible save/load routines for Simulation Settings, Simulations, and Robots. Preferably ascii over binary, except where size is an issue (as in Simulation settings), where some sort of file compression would be nice.

These would be nice, but aren't 100% necessary for the "Beta" label

  • Scripts. PY was working on the idea of what they should be, so he should be consulted.
  • Error Database. Basically, on an error an automatic report could be sent to one of the MYSQL databases available through our webspace and a notification sent to anyone working on the code automatically. Also, some sort of error viewer inside Darwinbots would be nice, so users could see how many other users reproted the error they recieved and wether or not it's been addressed by the coders yet.
  • Bot Database. A way to upload and download bots from a central database from inside Darwinbots itself. Also using a Database as described above (we have 10 of the things, we won't run out :P)
  • Statistical tools. This would involve everything from collecting data from the sim (and analyzing it according to proper statistical tests) to building a graph form and deciding how to draw it to exporting the data as per user specs into a spreadsheet program (like Excel). It is prefered that whoever works on this have some statistics background so they know what sort of stats users would want to collect and test.
  • The vision testing algorithm is presently O(n^2), as it uses the "brute force" method. It can be made nearly linear O(n) by using uniform grid cells. see:
This resource which exmines the issue
This resource which describes the implementation and problems associated with it
Collision detection could use a similar technique, though its gains would be complicated by the fact that bots are not uniform in size.
This would mean an absolutely insane boost in speed for large sims, but also would take some work.

Contact

If you would like to help with the code, and any of the above sound interesting or do able, feel free to contact Numsgil at Numsgil2002@yahoo.com to discuss your ideas.