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 07 Nov 2002
Offline Last Active Yesterday, 04:39 PM

#5235979 Do you comment Above or Below your code?

Posted by alnite on 21 June 2015 - 12:21 AM

Obviously above.


But, one can also perhaps write comments using the footnote system.  Using Hodgman's example:

// [1]
void FooBar()
  string fourtyTwo = "2A";// [2]

// [1] Beware: for legacy reasons, this function uses numbers that are encoded in strings as hexadecimal
// [2] 42 = 0x2a


#5234402 4 unsigned chars to float?

Posted by alnite on 12 June 2015 - 12:46 AM

I don't quite understand the original question, but if you just need the float in 4-unsigned-chars format, why not use union?

#include <stdio.h>

int main() {
  union {
    float v;
    unsigned char c[4];

  v = -9000.50f;
  printf("Float value: %f\n", v);
  printf("Byte values: ");
  for (int i = 0; i < 4; ++i) {
    printf("%02x ", c[i]);


Float value: -9000.500000
Byte values: 00 a2 0c c6 

Although, big/little endian will bite you hard in the ass. Make sure you know the endianess of your system, and anything else it sends this data to.

#5233215 What should I do now that I implemented a game mechanic that is not popular a...

Posted by alnite on 06 June 2015 - 02:18 PM

Yeah the bottom line is are you making this for yourself or other people to play.


Adding too much realism in games aren't as fun as people think.  Video games are meant to be fun.  So anything that prevents people from having fun, e.g. seeing their own entities get destroyed by their own projectiles, should be taken into consideration.


You could just brush that off and say that this is how you want your game.  That's your choice, that's your game.

#5232101 Code design/architecture

Posted by alnite on 31 May 2015 - 11:48 PM

My share; also review code of others, who didn't get that feedback.
Could be a win/ win: both better synchronized overall code and learn from the other code "ways"


+1 for code review.


Code design is a personal preference.  However, you are working on a team here.  You are not the only one working on that code base.  So, brainstorm the design/architectural choices.


Some guidelines:

  1. Consistency, even if it's bad.  It's easier to digest a consistently bad code, rather than reading a mix of good and bad practices thrown in together.  For example, it is more frustrating to see code that uses snake_case_for_its_method_names with other methods in camelCase and even lptrHungarianCase mixed in together.  If the code is already in Hungarian notation, even if you don't agree with it, keep it in Hungarian.
  2. Modularity.  Proper separation of controls between your classes and objects.  If you are following the MVC pattern, don't put controllers stuff into your views and models.  Views for rendering only, and models for that specific model-related logic only.  Even though this makes your code more verbose, it will be easier to maintain.


The team lead is also partly responsible here.  He or she should have established some common best practices when you start working there.  I would go through this for every new team member we hire.  The team lead needs to establish some process that works for the team.  For example, recently we hired an engineer who likes to commit to the master branch directly, even when his commits are partially working.  When you have automated build and testing going, this will flag a lot of errors for every commit.  The remedy to this is to NOT remain silent and unload your frustration on the yearly review.  The remedy is proper communication immediately.  Establish a code review process before every commit, and make sure team members are fluent on the git protocols (resolving conflicts, branching, merging, rebasing, etc), or whatever code versioning tools you use.


Failure to establish this communication is the fault of the team lead.

#5229883 Communication between objects and systems in Game engines.

Posted by alnite on 19 May 2015 - 12:41 PM

If you haven't gotten too far in your engine development, you really should have a generic entity that respects the physics system.  This includes all movable and collidable objects in your game.  If your player can fall and stand on the ground, bump into other objects or walls, then I presume there are other objects too that share this same functionality.  These objects should inherit from a common parent.  This is where you put your collision code.

#5228798 (Best Practice) Multithreading instantiation

Posted by alnite on 13 May 2015 - 09:44 AM

If you think about the sequence of steps, we can say that in order to fully instantiate this object, thread 1 needs to inform thread 2 that it has completed its part, and thread 2 needs to inform thread 3, and so on until thread N.  So the chain of process is sequential that the threads must wait until the previous thread completes its job.  To me, this sounds like something that you should do inside a single thread, rather than split the work into multiple threads and create unnecessary complexity.


So, I would go with the factory object idea.  If you are concerned with the performance, you actually want to initialize all objects at the loading screen.  Creating and destroying objects as your game/simulation is running and rendering is typically a bad idea, especially loading textures and accessing the hard drives.  If you have to remove objects from the scene, you want to have a flag in your object that you can toggle on and off, rather than invoking the constructor/destructor, and have an object pool to manage inactive objects.


This way, all your objects are already fully initialized and ready to use before you enter your multi-threaded environment.

#5225702 Why Does Everyone Tell Newbies To Make Games?

Posted by alnite on 26 April 2015 - 02:31 PM

So what do you recommend to newbies then?  Not make games?

#5223256 Write ToLower As Efficient, Portable As Possible

Posted by alnite on 14 April 2015 - 05:14 PM

"Portable" and "Efficient" is almost a polar opposite of each other.


Efficiency makes certain assumptions and/or optimizations based on current architecture/environment/encoding (e.g. ASCII only).

Portable means that it must be usable in as many architectures and environments as possible.

#5221739 are non sql databases better than sql databases?

Posted by alnite on 06 April 2015 - 06:44 PM

A few corrections to your misunderstanding here:


The reason why Redis is fast is not because it's a NoSQL Database, it's because it's an in-memory database.  If someone implemented an in-memory, scalable SQL database, it will be fast too.


NoSQL does not have to be a KV-driven, or document-based database as people have started to commonly refer this as.  There's also a graph database (e.g Neo4j).  It's a bucket term for any kind of database that are not using relational tables to store its data.



What is the difference between redis and C# dictionary?  Redis is a cluster of computers all dedicated to store your data in-memory, while C# dictionary only persist your data locally in one node.  If you are running your code in multiple server nodes, you can start seeing a problem where some data might exist in one node, but a request tried to retrieve it from another node.  That's what Redis is solving that it makes sure your data is available across the network.


You can put XML on redis since it isn't trying to format your data in anyway.  Set the key to your document to any string, and the value to be your XML.

#5221718 Two Questions - Willing to Trade experience on Tools and Business Side, for M...

Posted by alnite on 06 April 2015 - 04:57 PM

The best way to learn is just do it.  It seems you have done your own research in what language and platform you want to use.  Most beginners are still confused in that state.


People here can talk in length of best practices, for loops, OOP designs, etc, but without the context and experience, you won't understand why best practices are best practices.  So my advice is just get your feet wet and build something.

#5215352 Unity 5 or Unreal engine 4

Posted by alnite on 08 March 2015 - 09:54 PM

Is this going to be the new "vs" question now?  No more DirectX vs. OpenGL? :D

#5215016 Employee appraisal

Posted by alnite on 06 March 2015 - 02:39 PM

You have been with the company for a year.  That's usually more than enough for anyone to see how you work, and what you have been told is your boss' perception of your work.  He's in charge, and he's clearly not super happy with your work.  He wants you to improve, and he gives you time.  It's a good thing that he told you this upfront.  Some people will let it sit for a long time until you suddenly get the pink slip without warning whatsoever.


Here's the thing of being an engineer.  You need to figure things out yourself.  That's what makes a good engineer, when they solve problems.  Engineering problems are not math problems.  There is not one answer, but many.  The way I see it, engineering problems are the opposite of math problems.  A typical math problem asks you "what's the result of 1+1", an engineering problems is "I have 10 and 3.  What should I do to get 2?"


You need to figure out what you need to do, instead of asking people what you need to do.  If you are stuck, research things yourself, figure things out yourself.  This is part of the reason why tech forums don't want to solve people's homeworks.  Don't let the senior engineers solve problems for you.

#5214001 Drawing a city in 3D

Posted by alnite on 02 March 2015 - 01:35 PM

How much do you know about 3d modeling?  The bulk of this work will be modeling each individual houses, and putting textures on them.   5000 is quite a lot.  You could also go by creating a generic looking house that fits the architecture at that time, and apply that to all or majority of the houses, but it will not look very convincing.

#5213510 Confusion with insides of 2D games

Posted by alnite on 28 February 2015 - 11:30 AM

Sometimes people like to make things sound more complex than it actually is.  I never knew what a scene graph is when I first made my own video game.


Video game programming, in a nutshel, is really just handling logic for each object you have in the game, and draw them to the screen in the order you want them to be drawn.  At its simplest form:

for (int i = 0; i < gameObjects.length; ++i) {
    // handle logic for gameObjects[i]

for (int i = 0; i < gameObjects.length; ++i) {
    // draw gameObjects[i]

Done.  That's your game loop.  The only thing important is to separate the logic code and drawing code, and that's why I wrote two separate loops.


Then games become complicated, scrolling map, parallax scrolling, 3D, particle systems, objects attached to other objects and so on.  Some objects drawn completely, some others partially on the screen, and some others are completely out of the screen.  So people start handling these game objects into a complex tree structure which they call a scene graph.  You do not need a scene graph structure to make a game.  However, once your game start getting more complicated, and you have had solid programming background, you would naturally solve that complexity with a scene graph anyway.

#5211624 Creating a server for a mobile game and matchmaking with facebook

Posted by alnite on 19 February 2015 - 01:45 AM

The common wisdom says that if you want an online capable game, you have to write it with online capability from the beginning.  It seems that you have been writing your game in single player architecture, so it's likely that you will have to rewrite it to add the online part.  But, it depends on the game and the complexity of what you are after.