Jump to content

  • Log In with Google      Sign In   
  • Create Account

Bregma

Member Since 09 Dec 2005
Offline Last Active Yesterday, 08:52 AM

#5293575 Do you usually prefix your classes with the letter 'C' or something e...

Posted by Bregma on 26 May 2016 - 07:21 AM

You write code for humans to read, it's a work of literature.  To that end, semantics and readability are paramount.

 

Pyou vshould pnot vprefix nwords pwith aartificial aencoded pplanguage pconstructs aany amore cthan pyou vshould vdo pso pwith ahuman nspeech.  Pit vdoes pnot venhance nreadability.




#5292600 My C++ gotcha of the day

Posted by Bregma on 20 May 2016 - 04:32 AM

I expected for SFINEA to eigther give some compilation error that the class was not defined at this point, but not just silently tread it as if it was an empty class the whole time.


Huh. Any idea what SFINAE stands for? It should be a clue as to why it's unreasonable to expect an error in that situation.


#5291536 What book to start from

Posted by Bregma on 14 May 2016 - 05:33 AM

The book you should start with is your netbook.  By that, I mean start writing code.  It doesn't have to be good code, it doesn't have to work perfectly, but it's gotta be code and you have to write it.

 

Passive learning from a paper book is not nearly as effective as JFDI and see what happens.  Bits are cheap, use as many as you want.




#5290397 Is it real?

Posted by Bregma on 06 May 2016 - 06:07 AM

How long would it take to make something at the scale of Dragon Age Origins, if i already have all the assets (models, audio, arts etc.) and i'm using unreal engine? How long would the coding and uniting everything part take?

About the same time as it would take to make a movie like Star Wars VII: The Force Awakens if you already have a couple dozen actors lined up, a beach ball, and a really nice prosumer DSLR camera.




#5290395 I doubt I understand RAII just yet

Posted by Bregma on 06 May 2016 - 05:55 AM

You have it backwards.

 

RAII is a technique in which the lifetime of an object is identical to the acquisition of that resource.  When the object is created, the resource is acquired, and when the object is destroyed, the resource is released.  That's it.

 

You need to keep track of the lifetime of the object (and in fact all objects), but C++ is designed with several way to do that.  That's what makes RAII so powerful and useful:  it leverages technology built into the language and widely and easily understood and uses it to do an error-prone task outside the domain of the language itself.

 

Object lifetime control is a topic independent of RAII.  You need to master that first before worrying about RAII or pretty much anything else.  Hint: avoid pointers until it's really clear you need them.  Hint: put print statements in the constructors (all of them), copy operators, and destructors of your objects to help understand object lifetimes.




#5290276 how good is rand() ?

Posted by Bregma on 05 May 2016 - 11:59 AM

>>  It also has a tendency to have very poor randomness in the least significant bits, in particular it tends to alternate odd and even numbers so dont just use % to constrain the range, try >> it a couple of bits first.

 

i basically lerp from 0 thru 32767 (inclusive)  to 1 thru N (inclusive) for an N sided die roll.  i don't use mod.  so that low order lack of randomness should not affect me, correct?

 

Correct.  With N being significantly less than 32767 (like say, a d20 or a pair of percentile dice) you should also not be affected by the striping by using a lerp function.




#5290176 how good is rand() ?

Posted by Bregma on 04 May 2016 - 07:18 PM

how good is rand()  ?

 
Truth be told, modern implementations of rand() use a linear congruential generator with well-chosen parameters so that it's got a maximal sequence length and good apparent randomness so it's more than good enough for most applications.
 
Historically, there have been some implementations with notoriously bad chosen parameters and through the miracle of internet cargo culting, it has earned a poor but undeserved reputation.
 
As someone who implemented <random> for a widely used and well-known C++ standard library, I can tell you a few things about rand() vs. the std:: random number generators available since C++03/TR1.
 
The equivalent to rand() in C++ is std::minstd_rand, a small and fast LCG.  The main difference is that rand() uses hidden global state whereas std::minstd_rand is a stateful object.  An LCG can be implemented using one single multiplication instruction and one memory word, so it's very fast and takes very little memory.  It has the disadvantage of having a harmonic characteristic, ie you plot it on a graph you sill see stripes start to appear.  It also has a tendency to have very poor randomness in the least significant bits, in particular it tends to alternate odd and even numbers so dont just use % to constrain the range, try >> it a couple of bits first.

 

A popular PRNG is the Mersenne Twister, std::mt19937.  This has the advantage of a really long sequence and really good spectral characteristics, but it takes a lot of bit manipulation operations to generate the next number in sequence (ie. it's slow) and has a memory footprint of 2.5 kilobytes per instance.  It's extreme overkill for all but the most exacting of needs.

 

In between those two alternatives are the lagged Fibonacci generators (the std::ranlux* family) which use about 72 bytes of memory and no multiplications (they're very fast) but have clustering problems and show some harmonics.

 

There are also some PRNG adaptors that improve the characteristics of the above generators at cost of increased memory and CPU usage.

 

So, how good is rand()?  Not too bad really.  I don't like its use of hidden globals, which make reproduceability difficult to impossible and the harmonic traits show up sometimes when used for things like Perlin noise generation if you look really closely or use % on a small range, but it's good enough for most applications.  I use the c++ equivalent of std::minstd_rand instead.




#5289697 Hiding Company Nationality

Posted by Bregma on 02 May 2016 - 04:30 AM

I work for a company in which most developers are distributed worldwide.  We do have a bricks-and-mortar sales and support office in the USA (and one in China) because some jurisdictions are remarkably more xenophobic, but by and large you can not identify the colour of the skin or the width of the epicanthic fold of the developer when it comes to software.




#5289558 router programming

Posted by Bregma on 01 May 2016 - 06:32 AM

Well, I understand it's a learning exercise, but if you try to do everything in userspace you open up a Pandora's box of security vulnerabilities and slowdowns (several context switches per package means you won't be getting gigabit speeds).  That's why things like iptables are in the kernel in the first place.

 

That said, you can definitely do everything in userspace.  Have you read and digested the Stevens opus?  I do not believe there is a better work in the field.




#5288630 GPL wtf?

Posted by Bregma on 25 April 2016 - 12:48 PM

The controversy is not because Ubuntu is shipping the GPL-incompatible ZFS on the same ISO image as GPL software, it's because they're shipping an OS image with ZFS linked into the Linux kernel.  The GPL expressly forbids linking GPL-licensed and GPL-incompatible software in the same binary in cloud images.

 

Ubuntu has never shipped GPL-incompatible software like binary-blob drivers from nVidia or certain multimedia codecs as a part of their default installation, it's always required the user to install it on their own initiative (derivatives like Mint have their own lawyers and can do what they want).  Even on the phones and tablets shipping with Ubuntu, it's been the hardware manufacturers adding 3rd-party incompatible blobs to their images, not Canonical.  The ZFS stuff is different.  I don't know what's changed since last I spoke with all the central players at Canonical who were still fanatically pro-GPL.




#5285795 Typing skills

Posted by Bregma on 08 April 2016 - 07:58 AM

I think 30 mistakes per minute is good.




#5284243 Should I start with fixed-function-pipeline OpenGL or the newest possible?

Posted by Bregma on 30 March 2016 - 06:22 AM


Is it possible to do game-related stuff with Computer Science degree, or should I find some major in Computer Graphics or something? There are some articles on the internet, but are kind of outdated, that's why I ask here.

A proper university undergraduate degree is not job training.  A degree in computer science will give you the foundation to do many things once you enter the vocational world, and remember, you are not a career, and jobs change radically faster than you realize.

 

You can devote your spare energy to doing game development and building your own portfolio without getting formal vocational training in a post-secondary institution. Once you graduate, you can then either choose specialization in grad school (which is sort of like vocational training for academia), attend a vocational school or college for formal job training in game development, or start marketing your skills and talent using your hobby portfolio.  Your computer science degree will still serve you well in 20 years while robots program all the quantum biocomputer implants we will rely on as we relax in our autonomous flying cars.

 

But I'd recommend starting with OpenGL 2 and the Red Book because first you need to learn about the graphics pipeline, basic 3D game program structure and dataflow, vertexes drawing and transforms, colour, textures, and all the basics before you open up the engine and see how the buffers and shaders work inside.  Consider what you write using OpenGL 2 as throwaway, but what you learn is not throwaway.  Your target will be to learn OpenGL 3.5 and OpenGL ES 2 and use that for writing games that are not throwway.




#5283710 Can memory leaks only caused by using the new keyword?

Posted by Bregma on 27 March 2016 - 07:32 AM

In C++ the main ways to allocate raw memory are the new operator, the new[] operator, and ::operator new(), each with a nothrow overload.  Replacing only one of those will not overload any of the other 5.  Chances are good that if you're using the standard library, you using one of the methods other than the one new operator.




#5283158 How can I locate a memory leak?

Posted by Bregma on 24 March 2016 - 09:30 AM


There might even be problems where you honestly cannot apply RAII in a reasonable manner.

The classic example of a problem in which RAII is inappropriate is transactions with commit/rollback semantics.  Otherwise, it is Best Practice™.




#5282962 Local hash

Posted by Bregma on 23 March 2016 - 02:07 PM

std::unordered_map<> is a hash table. If you don't need to keep the items in your map sorted by key, it's very likely that you can use unordered_map instead of map, and in many cases the resulting code will be faster (e.g., if you have lots of entries (because hash tables have better asymptotic performance), or if key comparisons are expensive).

With "lots" being "several thousand." A std::map<> with a string key uses simple string comparison, so O(1) on the average length of the string keys (almost always very short) and O(log n) searches on the number of keys.  Unless you choose a custom string hash and bucket sizes very carefully, or have a huge data set you're mapping, std::map<> with std::string keys will beat std::unordered_map<> every time, in terms of speed.  It will also beat it when trying to debug, because the data is ordered making it easier to find missing or incorrect values (I calculate developer time as the most expensive resource I manage).

 

If your key is an integral value, std::unordered_map<> is sometimes a better bet because of memory allocation characteristics, but metrics are always your friend there.  Fortunately, the standard map classes are almost entirely interchangeable at the code level so switching is easy.

 

For smaller data sets (on the order of hundreds) a std::vector<> almost always beats any other collection in terms of memory and speed.  If it's created once and treated read-only it will always beat a std::map<> for lookup speed, but std::map<> usually still has simpler code for the same functionality.






PARTNERS