Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Oct 2013
Offline Last Active Aug 25 2014 09:37 AM

#5109403 Using a Notepad in Industry to keep track of modified code

Posted by TheComet on 15 November 2013 - 04:47 AM

What about Mercurial?


...And it begins.


Git vs. Mercurial: Please Relax (Git is MacGyver and Mercurial is James Bond)

The Differences Between Mercurial and Git

Git is Wesley Snipes, Mercurial is Denzel Washington


My honest opinion on Mercurial: To me it feels like Mercurial is just unnecessary. It does everything git does, only slower, and it's missing a few features. Plus the name "Mercurial" is unfortunate. Not catchy and doesn't "feel" good. That's just my opinion. I'm not denying Mercurial is a good VCS; quite the contrary, it does what it's designed to do and it does it well.


If you tell me to use Mercurial over Git, though, the reason I wouldn't switch is not because I prefer git, but because the time it would take to learn how to use Mercurial would outweigh the supposed benefit you claim it has.


I'll quote the first article. The bottom line is:


  1. Evaluate your workflow and decide which tool suits you best.
  2. Learn how to use your chosen tool as well as you possibly can.
  3. Help newbies to make the transition.
  4. Shut up about the tools you use and write some code.



#5108739 How to do starcraft 2 pathfinding?

Posted by TheComet on 12 November 2013 - 11:50 AM

@ankhd - Grids are memory expensive and don't deliver accurate results when compared to a navigation mesh.




What exactly are the nodes of A* on navmesh?


Let me shed some more light on this question.


The nodes of A* on a navigation mesh are the vertices of the navigation mesh. When searching with A*, you assume the navigation mesh is a waypoint graph, because due to the convexity of each polygon, you know that each node is directly connected to every other node within the polygon, so there's absolutely no difference between a search on a navigation mesh and a search on a waypoint graph.


This article explains it very well.



The only difference between a navigation mesh and a waypoint graph is the vertices of a navigation mesh hold information about an area rather than a single passable point. After the path has been found, the next step is to apply a funnel algorithm to simplify the found nodes into a more direct path.



I recommend reading through the documentation of the two libraries recastnavigation and detour. They are documented on CritterAI's website: http://www.critterai.org

#5107133 Such code. Wow. So Shibe. Very doge.

Posted by TheComet on 05 November 2013 - 05:28 AM


such compile


very code

shibe doge wow


Did you run it on this?


#5103819 How to write a undertemined size array to a txt file?

Posted by TheComet on 23 October 2013 - 12:24 PM

but how do i assign those values into my variables? and how do i do it if it's, for example, an array?

That's basically what my code is demonstrating. It's reading an arbitrary amount of data from a text file and pushing them into an std::vector<T> (remember, that's an "array").


Maybe I'm not quite understanding what you're asking. Could you elaborate more? What arrays are you using now? Are you using std::vector<T>? Please post your declaration of playerItem[] again so we're on the same page.


Can you also provide the code you're using to write to the file?

#5103816 How can I gain a deeper understanding of C/C++?

Posted by TheComet on 23 October 2013 - 12:18 PM

Ouch, after going through all of those slides I've suddenly become depressed about my knowledge.

#5103783 How to write a undertemined size array to a txt file?

Posted by TheComet on 23 October 2013 - 10:48 AM

The first thing you should do is think about how you want to structure your save file. XML might be a bit of an overkill for a text RPG, especially if the programmer is new to the language. I suggest doing an "INI" approach, where you tag different sections of your file using square brackets. Example:

John McCarter
The Dark One
Margret Baxter

The Skull crusher
Frilly Underwear (Pink)

The tags are there so you can detect them later in the code. Your approach is pretty solid so far, but you have to expand it to something like this:

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

int main()

    std::vector<std::string> playerNames;
    std::vector<std::string> weapons;

    std::string line;
    int state = 0; // state 1 is playerNames, state 2 is weapons, and so on

    std::ifstream myfile("data/checkpoint01.txt");


            // switch states
            if( line[0] == '[' ){
                if( line.compare("[playernames]") == 0 ) state = 1;
                if( line.compare("[weapons]") == 0 ) state = 2;

                // skip to next line


                // player names
                case 1 :
                    if( line.size() > 0 ) playerNames.push_back( line );

                // weapons
                case 2 :
                    if( line.size() > 0 ) weapons.push_back( line );

                default: break;

        std::cout << "error opening file" << std::endl;

    // now print data to the screen
    std::cout << "player names:" << std::endl;
    for( std::vector<std::string>::iterator it = playerNames.begin(); it != playerNames.end(); ++it )
        std::cout << *it << std::endl;

    std::cout << std::endl << "weapons:" << std::endl;
    for( std::vector<std::string>::iterator it = weapons.begin(); it != weapons.end(); ++it )
        std::cout << *it << std::endl;

    return 0;

Note to the more experienced: I know you could refactor this into a class with read/write methods, and should make separate classes for players, weapons etc. etc. and should probably define constants for states instead of numbers, but that's not the point.

#5103504 How to write a undertemined size array to a txt file?

Posted by TheComet on 22 October 2013 - 02:59 PM

He's saying to use std::vector<T> instead of C arrays. Here, check this out:
#include <iostream>
#include <string>
#include <vector>

int main()

    // this is a dynamic array
    std::vector<std::string> enemyNames;
    // add as many names to the array as needed
    enemyNames.push_back( "Cubert Cumberdale" );
    enemyNames.push_back( "The Dark Lord" );
    enemyNames.push_back( "ponies" );

    // this will loop through all elements in the array
    for( std::size_t i = 0; i != enemyNames.size(); ++i )

        // you could change this to write to a file
        std::cout << enemyNames[i] << std::endl;

    return 0;

#5103407 Unmaintainable code

Posted by TheComet on 22 October 2013 - 10:10 AM

This section is also very awesome: http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/Terrain.cpp#l132

void Terrain::Update​Transparency(in​t whichx, int whichy){ /*...*/ }
void Terrain::Update​Transparencyoth​er(int whichx, int whichy){ /*...*/ }
void Terrain::Update​Transparencyoth​erother(int whichx, int whichy){ /*...*/ }



#5103243 Unmaintainable code

Posted by TheComet on 21 October 2013 - 03:53 PM


using namespace std;

#5103241 How can I avoid exposing thirdparty types in my API classes?

Posted by TheComet on 21 October 2013 - 03:44 PM

I was reading "Effective C++ 2nd Edition" and in "Item 34: Minimize compilation dependencies between files" it says a good way to reduce dependencies is to have 2 physical classes (to name them someway) for each logical class, one to expose the public part of the class, and another with the private part of the class, having the public class a pointer to an object of the private class as a member.

Quite correct, that's the PIMPL Idiom (pointer to implementation). It's the best way to hide your implementation and reduce dependencies.

#5103066 Animation theading

Posted by TheComet on 21 October 2013 - 03:23 AM

What graphics library are you using?


I would recommend implementing GPU accelerated animation rather than messing around with CPU threading. This way, the transformations of animation frames are offloaded to the GPU using vertex programs and immensly increase performance.


Ogre3D supports this, for instance: http://www.ogre3d.org/docs/manual/manual_76.html

#5103065 "Forwarding" iterators without losing const?

Posted by TheComet on 21 October 2013 - 03:16 AM

Thanks! This fixed it:

class Bar {};

class Foo
    typedef std::vector<Bar*>::iterator iterator;
    typedef std::vector<Bar*>::const_iterator const_iterator;
    iterator begin(){ return m_List.begin(); }
    iterator end(){ return m_List.end(); }
    const const_iterator begin() const { return m_List.begin(); }
    const const_iterator end() const { return m_List.end(); }
    std::vector<Bar*> m_List;

void doStuff( const Foo& foo )
    for( Foo::const_iterator it = foo.begin(); it != foo.end(); ++it )
        // do something here with "it"

#5102370 "built-in loop" question

Posted by TheComet on 18 October 2013 - 05:56 AM

I personally think it's a good idea to make videos. I would howeover not recommend stamping these videos as "tutorials" and telling everyone that your way to write Java is the right way (I think this is what everyone in the thread has gathered from your motives). Instead, you could make them a series of "diary entries" labeled "Learning Java the hard way - Part <x>" or something. Be careful with the way you speak in the videos (i.e. always use personal phrases such as "I would do it this way" or "From my understanding, <whatever>", not "This is how you do it" or "You should not do <whatever>").


This way people can give you legitimate, constructive feedback on your videos, and not bash you for doing things wrong, and the videos will have a very positive influence on your learning curve.

#5102348 Are you sure it's alive?

Posted by TheComet on 18 October 2013 - 04:04 AM

I'm also wondering how often you will get a null this pointer in practice.


It seems quite likely that you would instead receive an arbitrary (but still incorrect) pointer value...


You should never get a null or incorrect "this" pointer. The fact that you have access to "this" already means the object exists in memory and is valid.

#5102174 Are you sure it's alive?

Posted by TheComet on 17 October 2013 - 10:55 AM

Was reviewing some code in a project, and found a file where a developer had inserted the following in every single method:

class EventMapper {

    * constructor
   EventMapper() {
      if( !this ) return;
      /* --SNIP--*/

    * destructor
   ~EventMapper() {
      if( !this ) return;
      /* --SNIP-- */

    * initialises the event mapper
   void initialise() {
      if( !this ) return;
      /* --SNIP-- */