Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 27 Apr 2011
Offline Last Active Sep 30 2015 07:34 PM

#5244780 Questions before I start solo on a basic 3D RTS...

Posted by AzureBlaze on 06 August 2015 - 02:55 AM

In my opinion by gameplay RTS is the second hardest genre, with MMO being the hardest (harder by several order). So it would probably be better if you forget about the 3D part for a while. If you really want to learn about 3D programming, try make a FPS or TPS instead. RTS has too many stuff to hit your toe with before it can barely become a "game".


Start with a flat, 2D world, model everything as simple circles and rectangles.


Make a tiny circle as your "unit".

Make it move around.

Make a rectangle wall.

Stop the circle from going into that wall.

Make other circles.

Stop circles from going into each other.

Make circles fight.

Make circles die.

Make a map format so it can contain many walls and probably a basic map editor.

Make circle figure out how to get from A to B (pathfinding).

Make circle actually go from A to B (steering).

Make a lot of circle go from A to B together without traffic jam (boids or other techniques).

Make simple AI for circle auto attack, etc.

Make UI.


Steps above had took me 4 week solo for a prototype our studio was investigating, and another 2 week for LAN multiplayer. Definitely doable but some of the subjects are hard, especially for beginners.


And you have a full model for your RTS world, then you can try to render it in 3D. Make your tank go up and down, pretending it was following a ramp while it was actually in a 2D world.

#5244446 C++ Operator Overloading: Bitwise Operators & If-Check

Posted by AzureBlaze on 04 August 2015 - 01:13 AM

1. Wouldn't that be quite heavy for performance? Since every single of those instances has it's own list, and is used only shortly anyway..



If you do care about performance, you should revert to normal flags. Your linear search through the deque will already be too slow if you check a billion time through a billion flags.


But I guess this is not the case you're going to use it with. For these non performance critical part you should always choose the easier way. Easier to code, understand, maintain, less chance of misusing. Those 2 microseconds you saved from the user's CPU which you're not paying for is not worth a week of debugging hell.


Your method have severe flaw in it: people don't expect normal operators other than assignments or ++/-- to modify their operand. If you write y = x+5, you'll expect only y will change, not x and certainly not 5.


If you write

UFlag foo = getFlags();
if(foo & 1){

if(foo & 2){

you are going to run into trouble because the content of foo have changed in the first if statement. You'll have to state clearly in your documents that UFlag can't be used like this and hope people (and yourself) will remember.


Although if you have access to c++11 you can avoid some of the performance penalty by using rvalue reference

//this operator is called when the left hand side is an rvalue, which is some temp value that is going to be thrown away.
//google rvalue for more details.
UFlag &&operator&(const UFlag &rhs) && { 
	//we are not going to use "this" later, so we are free to mess with it to improve performance.
	//return as an rvalue
	return move(*this);

#5244156 C++ Operator Overloading: Bitwise Operators & If-Check

Posted by AzureBlaze on 02 August 2015 - 09:17 AM

1. Normally the only operator that will return a reference to itself is an assignment operator like = or +=. The rest should take constant parameters (including "this") and return a new object. "c = a + b" does not alter the content of a or b.


UFlag<T> operator |(const UFlag<T> &b) const


should do the trick.


2. Implement explicit operator bool() const;



#5244122 Game entity system: Interactions between Lua and C++

Posted by AzureBlaze on 02 August 2015 - 03:09 AM

Are you sure it is going to cost you too much performance? My game calls several hundred Lua scripts and a few quite complex ones per tick, and the Lua VM itself have never cause me any performance trouble.


My metric is if some operations happen less then 1 million times per second, then even considering to optimize or not is often not worth it.

#5234238 Why didn't somebody tell me?

Posted by AzureBlaze on 11 June 2015 - 02:51 AM

Learned English for more than 20 years but I recently found that:


"Expect" and "Except" are different words, spelled differently.


As a programmer they always come in the same place like "Runtime exception: foo expected after bar", and human brain only identify the first/last character and composition, so I assumed they were the same thing.

#5231685 2D Platformer: Choosing a physics engine

Posted by AzureBlaze on 29 May 2015 - 10:27 AM

Common platformer features can be implemented well with a physics engine, here's mine as an example using Box2D:


I'd admit it's quite a headache to bend a physic engine into the unrealistic nature of a platformer, but this path could be easier if you don't know how to write collision codes or many objects need realistic movements.


For engine selection, I don't think there are any competitors with Box2D. For a platformer you don't need to modify Box2D's source, but you do need a lot of extra code to make it fit the features you want.


Here are some tips:


For "non-floaty" movements, instead of applying force, calculate the impulse to reach the desired speed and then apply it. Don't directly set the speed, you'll get weird results while pushing objects.


For "one wayed platforms", those you can jump on from beneath but won't fall from above, Box2D has a contact listener that will let you disable collision on conditions. You'll need to remember the result for the whole duration of the contact. For example, if the contact began with the character coming from below, disable collision until the contact has ended.


For objects following a path, use a kinematic body. You can set its' position directly, but remember to adjust its' velocity according to the last frame or objects on it won't move with it.


I'm better with physics(majored in mechanical engineering) than physics engine (I don't understand what the hell Box2D is doing internally, and mathematically impaired to check simple collisions), so bending rules with supernatural forces at my command is easier than defining the rules of this new universe. Depending on your ability it could vary, but whichever you chose I think there are people that can help.

#5223447 inline virtual is a nonsense ?

Posted by AzureBlaze on 15 April 2015 - 09:58 AM

It has a completely different and very sensible purpose. Try putting a simple function or operator in a header used in multiple CPP files without the 'inline'.


It is still a nonsense because we only use it for its' side effect and not the original purpose. It should be something like


allow_duplicated_definition_and_assume_they_are_all_same void foo(){};


Nothing is actually inlined, why call it "inline"? The name only trick people to think it will "optymize" things, waste half a second to type and 7 bytes of precious disk space.


Newer languages don't even need the side effect of inline. Today's compilers are perfectly capable of knowing two definitions means exactly the same thing or not. They also don't use copy-and-paste based include so nothing is duplicated just because every source file must know about some source file.


Although this is the burden of an old language. It kind of surprised me that they decided the original meaning of "auto" is too silly to live in C++ anymore, but I think "inline" was used too much, and we will be stuck with it.

#5223353 inline virtual is a nonsense ?

Posted by AzureBlaze on 15 April 2015 - 01:32 AM

In some sense the "inline" keyword itself is a nonsense.


"inline" only hint the compiler something should be inlined, but does not guarantee the compiler will do so. The compiler could also inline something else without that keyword.


Today's compiler think they are better than you and might completely disregard the keyword. And most of the time they are right.

#5221992 When you realize how dumb a bug is...

Posted by AzureBlaze on 07 April 2015 - 09:55 PM

Once had a bug in my font rendering, a glyph at a certain position was malformed (something like the top-left part pointing out of 'r' is missing), looking like misaligned mesh or some glitch with FreeType. I spent hours digging all the way into the engine code, but still can't figure out what went wrong.


Turns out it was a stain on my monitor.

#5193358 is there a better way top refer to assets in a game?

Posted by AzureBlaze on 17 November 2014 - 08:40 PM

Yes using a string to refer assets is slower than integer. But it will not be "noticeably" slower. Unless you are referring it ten thousand times each frame, and that means your design is probably wrong.


Since you are doing this on a PC, time and space spent on this simply do not matter. I would say you should not waste too much time on this, it would probably give you a 0.01% performance gain with a super fast resource id;


A simple modification you can do is instead of a linear search through a array of strings, use something like map<string,asset> that can do it in log(n).

#5191044 How to create line segments from tile map outlines

Posted by AzureBlaze on 03 November 2014 - 07:35 PM

Marching squares


#5185767 Lines of code language comparisons

Posted by AzureBlaze on 08 October 2014 - 09:49 AM

You can spend time to make your code cost less line/character, and than spend even more time to make it look good.

For example:



definitely shorter than normal c code, also definitely more time coding unless you're copying it by hand.

and a day of eternity to maintain it.


I prefer longer code than shorter code, as it will be easier to read and understand. If you are doing any real programming job, you will always spend more time thinking, reading than actually typing.


Ancient Chinese literature use a different language then the spoken one. As paper was expensive, they compressed the language so they can talk about more nonsense with less money. The result is some cryptic dialect that took us years to learn and still very difficult.


If George RR Martin zip his novel in his head before writing it down and have the publisher decompress it, could he finish The Winds of Winter quicker? He'll need less finger movement. Or maybe he should learn ancient Chinese?


I think LOC is only meaningful while on logarithm scale, to help estimate the size of a project. There's definitely difference between a 1K LOC project and a 100K LOC project, but doesn't mean 200K LOC project will be always more complex than a 100K project.


Other than this, the only use of LOC is to intimidate non-programmers. Telling your designer that feature will cost 1M LOC (citation needed) will probably shut him up.

#5185707 [Solved] Lua "require" other files when loaded from memory

Posted by AzureBlaze on 08 October 2014 - 02:48 AM

Some shorter example

int MyLoader(lua_State *L){
	//load the first parameter
	//which is the name of the file, or whatever string identifier for a resource that you passed in with require()
	string filename = lua_tostring(state,1);
	if( exist_in_container(filename)){
		buffer = get_data_from_container(filename);
		//load the buffer
		luaL_loadbuffer(L,buffer.data,buffer.size, filename.c_str());
		return 1;
		lua_pushstring(L, "Error: file not found");
		return 1;

// when you initialize your lua state...

//locate the package.loaders table

//for convienice, we just replace the first one with our loader
//package.loaders[1] = MyLoader
//balance the stack.

Although I'll still recommend you to try to understand the Lua stack and interfacing with C.

#5185680 [Solved] Lua "require" other files when loaded from memory

Posted by AzureBlaze on 07 October 2014 - 10:20 PM

Lua require() uses a table called package.loaders to store functions to load modules.

The function take a file name string as parameter, and return a function (like the result of luaL_loadbuffer ) if it succeeded and a error string if failed.

require() will call these functions one by one to find a match.


you can get more info from



it will be difficult to implement such loader functions if you don't know how to write c functions for Lua

you should have a look at chapter 26 of Programming in Lua


#5177193 Font Rendering Woes (FreeType)

Posted by AzureBlaze on 31 August 2014 - 07:12 AM

I think

byte intensity = ftBitmap->buffer[y * ftBitmap->pitch + x];

should be something like

float intensity = ftBitmap->buffer[y * ftBitmap->pitch + x] / 255.0f;