Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 09 Dec 2005
Offline Last Active Yesterday, 12:22 PM

#5205290 why C++?

Posted by Bregma on 19 January 2015 - 08:29 AM

The answer is at your fingertips.

#5205012 Porting my game to Linux

Posted by Bregma on 17 January 2015 - 10:00 PM

While I'm at it, Ubuntu has an app store, and I hear that it's not working (or harder than it should be to install) on Linux Mint 17. One of my goals is to get this on that distribution channel. Do Mint users commonly have this installed?

The Ubuntu App Store only distributes Ubuntu click packages for the Ubuntu phone (it's actually pretty easy to get your app there, but not (yet) applicable to the Ubuntu desktop).  It might be you're thinking of the Ubuntu Software Center, which is just a GUI front end to the Ubuntu software archives (whence most software for Ubuntu and Mint comes).  Getting your software into the Ubuntu archives might be a little tricker:  it has to pass several technical and social challenges first.  They also prefer you get it into the Debian archives first, and that's a major challenge given the tight clique circle-jerk that is Debian.


Keep in mind most distros will build the binaries for your application from source: you only have to worry about "working on other distros" if you're distributing binaries.  If you're distributing binaries, you're not going to get in to the equivalent of an app store for a distro.


Also, Ubuntu accounts for about 80% of all installed Linux desktops out there, and Mint is just a copy of Ubuntu with the thin veneer of a different desktop shell lacquered on top.  Targeting Ubuntu 14.04 LTS is probably all you need to worry about.

#5203676 About computer instruction in relation to RAM consumption

Posted by Bregma on 12 January 2015 - 09:19 AM

Although it may look attractive to jump into the deep and quickly get a feel of moving towards your dream, it will not help you to actually become a proficient game programmer. That's why I always - sometimes against popular belief - recommend to start out with raw assembly (preferably on a 65xx emulator or DOS in real mode) and then move up to C or any other compiled language, and finally move to scripted languages. That way you can see all the way down at any stage and really know what's going on under the hood.

You have not learned to appreciate how computers work until you have smelled the rosin core of your solder.


Seriously, there are really good hands-on ways to understand the basics of a computer.  Be forewarned, this can be a (worthwhile) time an money sink.

#5202603 Silly question about classes/libraries/headers

Posted by Bregma on 07 January 2015 - 09:00 AM

The technical term in C++ is "namespace-level function".  It's often colloquially known as a free function or a non-member function, both terms implying the normal state for a function is as a member of a class.  It is an untrue assumption.


The technical term in C is "function".


The technical term introduced by FORTRAN well over 60 years ago is "subroutiune."


The technical term for moving a namespace-level function into a separate .cpp file is "separate compilation."

#5202219 Looking for a good way to make games in C/C++ on linux for cross-platform

Posted by Bregma on 06 January 2015 - 07:30 AM

what is the best way to distrubute after i make a game in C++


(1) Both libSDL2 and SFML are available on popular GNU/Linux OSes and have been ported to the Mir display server and the Weston API for Wayland, so they'll continue to be available on future iterations of those OSes.


(2) The way to distribute software on most popular GNU/Linux OSes is via software packages (generally either RPM or DEB format), and packages generally need to be targeted at a particular OS.  Some newer package formats (eg. how Steam works) are now being supported that are more cross-platform because you ship and install all the dependencies in one huge, expensive-and-slow-to-download tarball.  Generally, licensing and security issues get ignored with the latter, so be prepared for problems down the road.


I'd say first get your game working, then worry about distribution.

#5201824 Linking Words as Conditional Statments

Posted by Bregma on 04 January 2015 - 05:28 PM

I suspect you're trying to map natural language constructs into programming language constructs, because apparent some computer programming languages use tokens identical to natural language words to identify mathematical processes or operations not terribly unlike those denoted by the natural language word they mimic.


The problem is that it is not an ontological relation between the vocabulary of a natural language and the underlying mathematical concepts denoted by a programming language.


Don't be mislead by the superficial resemblance between programming languages and natural languages.  The likeness is not coincidental, but is about as meaningful as using invisible whitespace to give significant meaning to program code.


If you want to look at an attempt to give a natural-language-like semantic veneer to a programming language, read up on COBOL.  It was supposed to be so natural to use any non-engineer to whip up a bank payroll or military missile guidance system without introducing any errors at all, and be able to explain it to his pointy-haired boss..  "ADD ONE TO ACCOUNT-INDEX GIVING NEXT-ACCOUNT-INDEX.  MOVE PAYROLL-RECORD AT NEXT-ACCOUNT-INDEX FROM INPUT-FILE TO WORKING-PAYROLL-RECORD."  Go wild.

#5200989 So something's not working correctly..

Posted by Bregma on 31 December 2014 - 09:15 AM

To clarify:  the condition of the "if" statement is declaring a new variable named 'y' that hides the parameter named 'y' in the simpleDivision() function, and initializes it to zero which is an expression equivalent to 'false' so control falls through to the "else" clause.  The scope of a variable declared in a control statement is the end of the scope of the control statement, in this case that is the closing brace of the "else" clause associated with the "if" statement.  You then divide by zero, and the universe proceeds to implode in an orderly manner.


So the most important lessons learned here is to use '==' and not '=' to compare two values for equality in an expression:  if you had done that, the code would not have compiled.  Don't worry though, I still sometimes accidentally use '=' instead of '==' after more than 30 years of C programming.  Algol-based languages use ':=' for the assignment operator to avoid the problem, Fortran uses '.eq.' for the equality comparator to avoid the problem.  Sucks that the language war winner was pretty much the most undeserving candidate.

#5200131 Getting Rid of "char*"

Posted by Bregma on 26 December 2014 - 02:54 PM

Most std::string implementations keep small strings on on the stack for you automatically, and store larger strings in dynamically allocated memory.

The SSO (short string optimization) is required of any ISO standard-conforming implementation, as of the 2011 version of the C++ standard.

#5200061 Getting Rid of "char*"

Posted by Bregma on 26 December 2014 - 08:05 AM

Like Ryan_001 said, you'll either need to provide an interface for your family of String classes and program to that interface, or provide a family of function overloads for each member of your String class.  I'd recommend the interface method, since you can't overload on a return type so you'll need to explicitly instantiate such templated function overloads at the call point instead of relying on deduction, and that can quickly make you code messier.


Don't worry about all the bloat that using a separate class for every possible string length will introduce. Modern computers have more than enough memory and disk space to handle that and statistically speaking you're unlikely to have more than a few hundred such classes (or function overloads).  If it turns out all the code fragmentation blows your cache coherency noticably, get a bigger i7 with more cache.

#5199691 Converting my program to smart pointer and a bit confused

Posted by Bregma on 23 December 2014 - 06:47 AM

(1) You should always prefer references over pointers, so converting existing code that uses references to use pointers is a step backwards.  If an API requires pointers to be passed in (and many of them do), just pass in pointers to your object (or pointer to your object references).  If an API passed back pointers (ie. controls object lifetimes), treat them as if they were new/delete or open/close (see below).


(2) Your first step in using smart pointers is to locate any new/delete (or open/close, or create/release) pairs and replace them with std::unique_ptr and then use that class's get() function to obtain the raw pointer, and continue to use the raw pointer where you did before.  You can, for example, cache all your textures in a vector of unique_ptrs and dole them out to consumers without them being any the wiser.


If your new and delete are not in symmetric pairs and the lifetime control of dynamically allocated objects is not straightforward, your design is broken and needs to be fixed first.


(3) Once in a rare blue moon you will run into situations in which std::unique_ptr is not going to do the trick.  That's when std::shared_ptr (and its cracker cousin std::weak_ptr) come in to play.  If it's the tool you need, reach for it, but it should not be your tool of first choice.

#5199687 Why are abandoned, deserted areas so common in video games?

Posted by Bregma on 23 December 2014 - 06:28 AM

Realistically, if there were reports of some pimply newb with a claim to have consorted with my 80 year old mother running around my neighbourhood with fully automatic weapons and a virtually unlimited supply of ammo fragging anything that moved, I, my family, and all my neighbours would be likely to abandon the area too.

#5199456 Linking a static library to my static library

Posted by Bregma on 21 December 2014 - 06:30 PM

Problem is, a "static library" is an archive file of compiled objects, not a dynamic library.  It does not carry any sort of list of other transitive entities that will be used to satisfy its undefined references during the final link phase, because it has not gone through the final link phase.  If every separate translation unit had to have all its undefined references satisfied at compile time it would not really be possible to develop very useful software using the separate complication model.


It's not that it's frowned on to have static archives contain links to satisfy transitive dependencies, it's that static archives simply do not can not carry links to satisfy transitive dependencies.

#5199107 C++ how to declare something that isn't declared?!?

Posted by Bregma on 19 December 2014 - 09:55 AM

Can anyone explain why this would be useful?

Can any one explain the difference between these two lines?

  TSubparticle::Ptr p1, p2;
  TSubparticle* p3, p4;

#5198946 C++ how to declare something that isn't declared?!?

Posted by Bregma on 18 December 2014 - 09:23 AM

You're using C++ so write C++ code instead of C.

struct TSubparticle

  using Ptr = TSubparticle*;

  Ptr next_;

TSubparticle::Ptr particle_list = nullptr;

#5197771 is there an easy way to do this?

Posted by Bregma on 12 December 2014 - 08:00 AM

Because all your changes are context-specific, I doubt there is any way you can just do a mechanical search-and-replace operation.  Some times doing the hard work just requires doing hard work.