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!


AzureBlaze

Member Since 27 Apr 2011
Offline Last Active Yesterday, 06:33 AM

#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

http://devblog.phillipspiess.com/better%20know%20an%20algorithm/2010/02/23/better-know-marching-squares.html




#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:

http://uguu.org/sources.html

 

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;
	}else{
	
		lua_pushstring(L, "Error: file not found");
		return 1;
	}
}

// when you initialize your lua state...

//locate the package.loaders table
lua_getfield(state,LUA_GLOBALSINDEX,"package");
lua_getfield(state,-1,"loaders");
lua_remove(state,-2);


//for convienice, we just replace the first one with our loader
//package.loaders[1] = MyLoader
lua_pushinteger(state,1);
lua_pushcfunction(state,MyLoader);
lua_rawset(state,-3);
//balance the stack.
lua_pop(state,1);

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

http://pgl.yoyo.org/luai/i/package.loaders

 

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

http://www.lua.org/pil/26.html




#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;

instead




#5146450 Inline for clone() function

Posted by AzureBlaze on 11 April 2014 - 10:02 PM

inline still have its' uses. Just not much for optimization

 

Consider if you are writing a header only library:

#pragma once
class bar;

class foo{
public:
	foo();
	bar *b;
};

class bar{
public:
	bar(foo *_f):
		f(f)
	{
	}
	foo *f;
};

inline foo::foo()
	:b(new bar(this))
{}


inline on foo::foo() is mandatory. it ensures the compiler and liker that no matter how many times it see the definition of foo::foo(), it will refer to a completely same function. Remove inline and you'll get a linker error because of multiple definitions.




#5146346 DRM protection

Posted by AzureBlaze on 11 April 2014 - 11:41 AM

Story: Back when I was in college we have a legit 500 user license for some expensive CAD software (donated, I think for tax reasons). But we, including the computer room, all use a cracked version which is given by the dealer. Setting up and maintaining a key server is simply too much trouble.

 

Some DRM cause so much trouble even legal users have to use cracked ones.




#5146244 Intellua - a Lua Editor with auto-complete support

Posted by AzureBlaze on 11 April 2014 - 07:26 AM

Recently my Lua scripts started to get out of hand because I'm adding more and more common utility functions and custom Lua classes. Remembering function signatures became more difficult and using classes without auto-complete is pure pain. I decided to improve my original Lua editor (was designed originally only to auto-complete APIs exposed from my game), and I think more people could benefit from it. I present Intellua:

 

example.png

 

Intellua is a open source (although the code is still messy and undocumented now so it is not recommended to look at it now.) C# project base on scintilla and scintillaNET that provides auto-complete via static code analysis.

 

Features are:

  • Auto-completion and brief document for functions, variables, class and class members.
  • Game APIs and classes can be documented with Doxygen and import into Intellua (specifically designed for those binded by luabind, but others might also apply)
  • Lua functions and classes can be declared and documented with special lua comments.
  • Object type deduction through assignments and function return type.
  • Manually assigning type for objects.
  • Independent from execution environment.

Most other Lua editors seems to support auto-complete via dynamically inspecting tables. From my past experience (might be wrong since years has past and it could improve.) the result might be messy(unneeded private stuff appears) or inacurrate(inherited members through meta-table missing). By using static analysis Intellua believe a object is what you told Intellua it is, this gives more control over the result.

 

Here's a demo of writing and using a simple class in Intellua

 

The Intellua project is hosted at http://code.google.com/p/intellua/




#5144676 Documenting scripting language in application

Posted by AzureBlaze on 06 April 2014 - 12:12 AM

I was searching for something similar, but my final solution write a documented header for Doxygen to parse. Doxygen is quite forgiving about grammar rules such as missing return type for functions so I think it should work with most scripts by writing the document similar to c++ style.

 

for example:

#ifdef LUA_TABLE
//! Provides generic functions for table manipulation.
class table{
	
	//! Given an array where all elements are strings or numbers, returns table[i]..sep..table[i+1] ... sep..table[j].
	static concat (table [, sep [, i [, j]]]);

	//! Inserts element value at position pos in table, shifting up other elements to open space, if necessary.
	static insert (table, [pos,] value);

	//! Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices.
	static maxn (table);

	//! Removes from table the element at position pos, shifting down other elements to close the space, if necessary.
	static remove (table [, pos]);

	//!Sorts table elements in a given order, in-place, from table[1] to table[n], where n is the length of the table.
	static sort (table [, comp]);

};
#endif

results in:

Hk1XAGA.png

 

 

I also use the generated XML for autocomplete in my script editor

iI8sY1Z.png






PARTNERS