Cocos2d-x version number defines

With the future release of Cocos2d-x v4, it will break compilation of game code written for v3 of the engine. This would mean maintaining different branches of the game for each version of the engine, yet this can be avoided if version number preprocessor defines were introduced into Cocos2d-x. It would enable us to have a single code-base with support for both versions of the engine, since we would be able to check for the version number information and selectively include sections of code.

Adding the version defines would not impact the engine code, since it’s purely for the game code and any other extensions written for the engine (like Spine) to maintain a single code base.

I’ve created a github issue for this. If anyone has concerns regarding it, then please provide your input, and if you actually agree that this would help in some way, then please help push it along so it’s implemented before version 4 of Cocos2d-x is released.

4 Likes

Thank you.

I’ve discovered a few things:

If you need to know which version Cocos2d-x is in code, then you can use the following define which already exists in the current codebase, in cocos2d.h:

// 0x00 HI ME LO
// 00   03 08 00
#define COCOS2D_VERSION 0x00040001

So, to use it, just do something this:

#if COCOS2D_VERSION >= 0x0040000
#else
#endif

If you need to check for a version number in CMakeLists.txt, then there is COCOS2D_X_VERSION which is defined in the Cocos2d-x CMakeLists.txt, but it’s not accessible from the game CMakeLists.txt. Luckily, it’s applied as a property of the cocos2d library, so in order to find out what it is, just use this line in your game’s CMakeLists.txt:

get_target_property(COCOS2D_X_VERSION cocos2d VERSION)

COCOS2D_X_VERSION should now contain the correct version number (such as 3.17.1).

To check for this, you can use CMake’s own version checks as defined here. For example:

get_target_property(COCOS2D_X_VERSION cocos2d VERSION)

if(COCOS2D_X_VERSION VERSION_GREATER_EQUAL 3.18)
else()
endif()
1 Like

Why not just call cocos2dVersion(); ?

Example:
const char *version = cocos2dVersion();

The result of that function call is not particularly useful for much of anything besides perhaps displaying it, and requires further processing in order to actually check for the version value.

It is implemented like this:

CC_DLL const char* cocos2dVersion()
{
    return "cocos2d-x-3.17.1";
}

Aside from that, having so many places where the version code is defined seems like a very error prone way of handing it. The version number should be sourced from one location, and used everywhere else. From what I see in the code base, there’s that method you mentioned, there’s a define in cocos2d.h, and yet another define in a CMakeLists.txt file. So, for each release all 3 locations need to be manually updated, and I’m sure you can see how this can result in issues if one of those locations is forgotten.

Thanks for your advise. @minggo please take a look at this issue, and unify the API where developers can get the correct engine version.

But to be honest, I still have no idea on “what’s cocos2d-x v4”.

Now we already have metal support, we have rewrote a solid 3D renderer and many reliable 3D features in our internal repository which is compatible with 2D features. The new 3D editor is ready to use, and we are testing it with a partner who has got the license of MU Online from Webzen.

To be frank, I still haven’t made the idea yet. I stayed in Asia many years since the failure of Cocos Studio, and lost the contacts / requirements from western game studios. Today, Cocos Creator focuses more in the requirements of Chinese domestic game industry. Although we are very close to “back to global”, I still need more info to adjust the product to fit the global needs.

Uploading videos onto youtube is troublesome for me due to the government firewall. So I just show some screenshots of the 3D Cocos Creator.

Yes, merge cocos2d-x-lite

No, I would remove Lua but not c++. So many developers use c++ in the western world. Javascript isn’t as popular.

Yes, I think promoting the 3D upgrades would be good.

I think developers would want more bugs fixed and less new features starting in v4.01, etc. I think if v4 had some new features and then extreme polish afterwards would be amazing.

Perhaps I will make a new topic out of these questions?

Sure. Sorry that my reply is not very related with R101’s topic.
I learned from the history of cocos2d-x and cocos studio. Today I only publish the big version when the team have fully polished it with our beta-test partners in the actual game projects.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.