Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Oct 2013
Offline Last Active Today, 07:11 AM

#5146281 Static as substitute of private members.

Posted by TheComet on 11 April 2014 - 08:52 AM

[never mind]

#5146248 Static as substitute of private members.

Posted by TheComet on 11 April 2014 - 07:38 AM



Static is not a replacement for private in C. Declaring and defining them only in the .C file is.


Don't they need to be declared static inside the .C file so that they only visible from within that compilation unit.



No, each compilation unit is compiled individually, a variable has to be declared as extern to become accessible across compilation units.



To expand on what people are saying with a few examples:







extern int x;
void foo(void);


int x;
void foo(void) { x = 1; }


#include "test.h"
int main(void)
    foo(); /* ok */
    x = 6; /* ok */
    return 0;

x and foo() are both visible in external modules.






/* extern int x removed */
void foo(void);


int x;
void foo(void) { x = 1; }


#include "test.h"
int main(void)
    foo(); /* ok */
    x = 6; /* ERROR, x undeclared */
    return 0;

x wasn't declared as extern in the header file and is therefore invisible to external modules.






extern int x;
static void foo(void);


int x;
static void foo(void) { x = 1; }


#include "test.h"
int main(void)
    foo(); /* ERROR: foo() undeclared */
    x = 6; /* ok */
    return 0;

foo() was declared static and therefore is invisible to external modules.

#5145479 What it's like to be a software engineer (video)

Posted by TheComet on 08 April 2014 - 03:00 PM

It's interesting, because the issue here is not it being impossible, the issue here is communication.


What the engineer is doing wrong is he's saying things like "it won't work because <reason>", instead of trying to wrap his head around what the customer really wants by saying something like "Splendid idea, I am capable of implementing it. Could you demonstrate to me how you expect the end result to look like?".


The customer obviously doesn't exactly know the implications of her request down to the last detail. The customer and the engineer speak two entirely different languages, and it is the engineer's job to translate the customer's language into their own language without rejecting the customer's ideas.

#5144988 Problem with vignette shader on PC

Posted by TheComet on 07 April 2014 - 05:17 AM

Good job on finding the core of the issue. I hope all goes well!

#5144697 Amusing glitch gallery

Posted by TheComet on 06 April 2014 - 05:43 AM

Stumbled across this one on tumblr. How on earth does something like this even happen?!



#5144319 Problem with vignette shader on PC

Posted by TheComet on 04 April 2014 - 06:03 AM

Maybe try using gl_TexCoord[0].xy instead of gl_FragCoord.xy. I remember having a similar issue where gl_FragCoord would return the correct value in GLES, but in GL it would always be 0.

#5142254 Javascript Memory leak

Posted by TheComet on 26 March 2014 - 03:44 AM

For the record, the correct term is "sawtooth" and not "zig zag pattern"

(sorry for being a jackass)

#5141993 Program Stopped Working (MinGW)

Posted by TheComet on 25 March 2014 - 08:25 AM

There is a multitude of possible problems but I would probably start with ensuring all runtime dependencies of the program (starting with the C++ runtime) are available when using the command line.

Yes, this was indeed the issue. libstdc++-6 was trying to be loaded, but was not in the path of the executable.


Thanks! I knew it was something simple.

#5141732 Best way of volume selection

Posted by TheComet on 24 March 2014 - 10:59 AM

The game Cosmo Bots demonstrated a 2D version of what you're after. It could accurately figure out your intentions through a combination of mouse movement and ray-tracing (I think it would prefer to rotate towards the nearest wall). If you weren't happy with its orientation, you could right-click the mouse to manually rotate it.


I think the most intuitive method would be to rotate the volume on the 2D surface of the currently selected block, according to an average mouse direction. This would be done as follows:

  1. Determine the surface normal the mouse cursor is over. For instance, if the mouse is on the top side of a block, the normal would be [0,1,0], where as if the mouse were on the side of a block, the normal would be [1,0,0] etc.
  2. Calculate a normalised directional mouse movement vector in 3D. This could be done by storing, say, the last 30 3D mouse positions in a ring buffer, and calculating the difference between the first and last point.
  3. The normal from step 1) is the axis around which you should rotate the volume selection. Using the mouse direction, you are able to calculate an optimal angle for the volume selection. You'd of course round the angle to 90° steps.
  4. Make sure the volume doesn't intersect with any other blocks, adjust position and angle accordingly.

Does that make any sense? I can create some illustrative images with MineCraft if not...

#5139309 Help name a game.

Posted by TheComet on 15 March 2014 - 02:50 PM

  • Unstoppable Shark Slaughter
  • Vegetarian Pirate Gladiator
  • A Pirate's Bible Cover up
  • Super Sexy Pirate
  • Jack Sparrow's Tricycle Crash
  • In search of Davy Jones' Vibrator
  • Hillbilly Pirate Force of Doom
  • Pirate Plays Enraged Chess
  • Flamboyant Voyage of The Sunken Quantum Summoner
  • The Ship From Outer Space
  • Fabulous Pirates Enrage Gay Activists
  • Black Beard Was Actually Black
  • The Penguin Conflict
  • Haunted Walrus in Funkytown
  • No One Can Stop The Yak Domination

#5139257 Need help: a vector of different extended classes

Posted by TheComet on 15 March 2014 - 10:45 AM

No, because that way, arrow will be destroyed as soon as it goes out of scope, and your list of entities will be holding an invalid pointer pointing somewhere above the stack. You have to use new and delete.
[EDIT] As SiCrane points out below, delete the element before removing it from the list.
// adding entities
Entity* arrow = new EntityArrow();

// removing entities
delete *it; // make sure to delete the entity being removed from the list
Better yet, use smart pointers, so you don't have to manually delete the entities you remove from the list:
std::vector< std::shared_ptr<Entity> > entities;

// adding entities
std::shared_ptr<Entity> arrow = new EntityArrow();

// removing entities
// entity is automatically deleted when you remove it

#5138924 Amusing glitch gallery

Posted by TheComet on 14 March 2014 - 05:52 AM

On an RTS game I was developing, I had a similar issue to what DekuTree64 described (see quote below). If you chained a lot of "move" commands very close to each other, the unit would never be able to reach its destination because the steering code had a minimum radius, and so the unit began orbiting around itself:



The greatest bug I've ever witnessed was when I was working on Sims 2 DS. We had this thief character whose getaway vehicle is a shopping cart, which is spawned some distance away from him and races toward him, he jumps in, and rides off. But due to a combination of steering code, obstacle avoidance, and high speed, the cart ended up orbiting him at a long distance, trying to turn toward him but then moving forward so it needed to turn more. Every few seconds, you'd see the cart zip past on the horizon.

#5138674 Industrial Strength Hash Table

Posted by TheComet on 13 March 2014 - 06:23 AM


Using braces instead of brackets for trying to call the constructor of an object


That's actually valid in C++11 and called uniform initialization syntax.


Thanks for the clarification. I learned something new today!

#5138565 Ugh! Your shorthand is too short!

Posted by TheComet on 12 March 2014 - 05:59 PM

I've found that a lot of code is written by mathematicians or physicists, and on paper the formulas all have one-letter-variables, so they will copy that one-to-one when they implement it in code.


For instance, an electronic engineer will know that the formula for calculating a charging voltage of a capacitor in an RC circuit is:

U = U0 * (1-e^(-t/(R*C)))


So in code, I will reflect exactly that:

double U = U0 * 1-pow(e, 0.0-t/(R*C));

Every non-electronic engineer is going to look at that and go "WTF IS THIS CRAP".


I've had moments where I've done the same thing at first glance, but as soon as I research the algorithms being used, the variable names begin to make a lot of sense.



I mean, when you are writing hundreds and hundreds of lines of code, it gets annoying typing in long names.

One word: auto-complete.

#5138486 Industrial Strength Hash Table

Posted by TheComet on 12 March 2014 - 01:08 PM

So let's see what the WTFs basically are...

  • Assigning a pointer generated from new to a type that is not a pointer
  • Using delete[] on objects created with new and not new[]
  • Using braces instead of brackets for trying to call the constructor of an object
  • Returning a pointer pointing to what is supposed to be an array of pointers pointing to pointers (given the new[] and delete[]), even though the value being returned isn't of type pointer (which is a double-WTF because if it were to compile, that would still be retarded)
  • using a lookup method of complexity O(n)
  • Attempting to declare a return type without template arguments.
  • Returning a nullptr in the case of not finding an entry, implying that the templated type is always a pointer.
  • Method names begin with a capital letter
  • not using std::map
  • code doesn't even compile