Jump to content

  • Log In with Google      Sign In   
  • Create Account

Bregma

Member Since 09 Dec 2005
Offline Last Active Today, 05:42 AM

#5297045 Object created in one class, needs to use variables in the class it was creat...

Posted by on 17 June 2016 - 05:15 PM

Have the MainGame update itself based on state reported by the Input object?

 

Have the MainGame register callbacks on the Input object so the Input object can ask the MainGame to update itself?

 

Use a message-passing protocol to communicate state between object?




#5296213 Trivially trivial?

Posted by on 12 June 2016 - 07:23 AM

The way the standard library was designed, and I would suggest trying to fight against the way it was designed will send you on an increasingly downward spiral, is to overload std::copy() for your class.

 

You should rely on std::copy() being used in an algorithm or container, knowing that it will call std::memcpy() for trivially-copyable objects and the copy constructor/move constructor/operator=() for non-trvially copyable objects, and your override of std::copy() can just call std::memcpy() if you have an object that you know is trivially copyable but the compiler can not deduce it on its own.  Most times, the compiler will do the right thing (even if you think you know better), and making it explicit that you're overriding the default compiler behaviour by supplying a std::copy() overload documents you decision, just like using a cast.  You are after all trying to communicate to the human reader that you're doing something unexpected and that you know better in this particular case, as opposed to just telling the compiler to do something.

 

You are explicitly allowed to overload std::copy() for just that reason.  In the std:: namespace no less.  Just like the big boys.




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

Posted by 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.




#5293192 Is there a way to change initialisation order while keeping object layout ?

Posted by on 24 May 2016 - 06:39 AM

The committee had to choose some rule for initialization order.  The chose the one that will work reliably under all situations:  with the presence of explicit initialization or without.    I suppose the could have gone with "in the order of explicit initialization except when some explicit initializers are missing in which case you fall back to member declaration order and except when there is non-virtual multiple inheritance with differing base class constructor calls and also not in plain-old-data copy constructors or any classes derived from them and, well, there is no guarantee about default copy operators ever doing the right thing any more" but my guess is they thought that might be a little more error-prone and liable to unexpected behaviour.




#5292600 My C++ gotcha of the day

Posted by 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 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 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 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 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 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 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 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 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 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 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.






PARTNERS