Horde3D

Next-Generation Graphics Engine
It is currently 27.04.2024, 12:32

All times are UTC + 1 hour




Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Namespaces
PostPosted: 03.06.2009, 00:25 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
I wonder if we should use old-school namespaces for functions and enums in the external interface. This would make the syntax and usage more consistent across different programming languages. Furthermore, it would solve the drawback that enums like ResourceTypes that have a quite common name are currently not in any namespace.

I would propose the prefix ho for all function names (e.g. hoAddResource) and Ho for enums (HoSceneNodeParams). Are there any better ideas?


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 03.06.2009, 01:02 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
marciano wrote:
This would make the syntax and usage more consistent across different programming languages.
Yeah that makes sense. I would prefer the prefix of h3d though.

In English, 'ho' is an old word meaning something like "look over here" (e.g. land ho!), but in modern American slang it means "prostitute" :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 03.06.2009, 08:10 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Hehe, now that you say it I recall some song texts...in that case h3d is the preferred alternative :lol:
Thanks DarkAngel for saving us from that!


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 03.06.2009, 16:42 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
Sounds like a good idea - will make the C interface much more user friendly.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 04.06.2009, 12:13 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Can you add a code sample here? Just wanted to know the changes should be performed on the code. [Perhaps this will be problematic]


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 05.06.2009, 00:36 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Siavash wrote:
Can you add a code sample here? Just wanted to know the changes should be performed on the code. [Perhaps this will be problematic]
I'm guessing the changes on Horde users would be fairly straight foward, even as simple as:

Find: "Horde3D::"
Replace with: "h3d"


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 05.06.2009, 05:05 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
IMHO replacing the enums with namespaces would cause some performance penalties. If I get you right, this piece of code :
Code:
Horde3D::findNodes(StartNode, NodeName, 3);

Should be changed to this :
Code:
H3DfindNodes(StartNode, NodeName, SceneNodeType::Mesh);
And we can't use the first code anymore.

Assume that we are sending the SceneNodeType from Lua to the C. Now we must add an extra if/switch to the C code to decide which SceneNodeType must we use.

IMHO the current structure of engine is more straight forward. We just need to send the SceneNodeType as int to C and there is no need to any if/switch statements.


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 05.06.2009, 06:05 
Offline

Joined: 22.01.2009, 19:49
Posts: 14
Location: Germany
Siavash wrote:
IMHO replacing the enums with namespaces would cause some performance penalties.


If I understood the suggestion correctly, the point is to remove all C++ namespaces and make the interface entirely pure C compatible. So the Horde3D namespace is removed, and all functions and enums are prefixed with "H3D" or "h3D" (I'd prefer the latter).


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 05.06.2009, 10:20 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Thanks 8)


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 06.06.2009, 06:28 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
IMHO using namespaces is more comfortable [auto code completion] :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 06.06.2009, 11:30 
Offline

Joined: 22.01.2009, 19:49
Posts: 14
Location: Germany
Siavash wrote:
IMHO using namespaces is more comfortable [auto code completion] :wink:


Hmm, I don't know about other IDEs, but Visual Studio makes no difference between auto-completing namespaces and identifiers. The only difference is, though, that you can import the namespace using the "using"-keyword and get rid of it all together. On the other hand, I really like the OpenGL's "gl" prefix. In my opinion, the "h3d"-prefix is the way to go.


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 07.06.2009, 00:56 
Offline

Joined: 06.06.2009, 23:13
Posts: 7
Regarding naming of things, is there anything that can be done to make enum names shorter?
I don't know how do other people feel, but for me things like "emitter-node-params::particle-effect-res" or "particle-effect-res-params::move-vel-endrate" are a pain to see in the code (consider 80-column limit).

Here's a proposal. Along with moving everything under h3d prefix, also move constants into a single namespace, eliminating prefixes like "EmitterNodeParams::".

I'm thinking about how OpenGL does that: all constants are simply GL_SOMETHING. In the same spirit AnimationResParams::FrameCount becomes h3dAnimationFrameCount, H3D_ANIMATION_FRAME_COUNT, or anything similar.

This could also benefit bindings to the languages without namespaces (C?).

So, does anyone think it's worth the effort?


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 07.06.2009, 10:04 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
magv wrote:
Regarding naming of things, is there anything that can be done to make enum names shorter?

Yes, that's something I found not so nice myself as well. It is especially obvious for the resource data interface which takes two enums that are rather long. The advantage of having the enums wrapped in a struct is that you can easily see what enum values are available for a given parameter. If you just have the enums as in GL, you need to look at the documentation to see which enums are allowed. Hmm, maybe someone has another idea how to make that nicer.


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 07.06.2009, 10:55 
Offline

Joined: 22.01.2009, 19:49
Posts: 14
Location: Germany
Enums in OpenGL are just #defines, aren't they?

Anyway, why not just use enums the standard C++-way? That would make the notation shorter and you'd still know which enums you're allowed to use. So instead of

Code:
// Enum definition
struct EngineOptions
{
     enum List { Opt1, Opt2 };
};
// Function definition
void func(EngineOptions::List e);
// Function call
func(EngineOptions::Opt1);

just use
Code:
// Enum definition
enum EngineOptions { Opt1, Opt2}
// Function definition - shorter and less ugly, and even preserves type information
void func(EngineOptions e);
// Function call - shorter
func(Opt1);

Or am I missing the point?


Top
 Profile  
Reply with quote  
 Post subject: Re: Namespaces
PostPosted: 07.06.2009, 12:57 
Offline

Joined: 06.06.2009, 23:13
Posts: 7
marciano wrote:
The advantage of having the enums wrapped in a struct is that you can easily see what enum values are available for a given parameter.
Yes, that is one of the annoyances of the OpenGL approach. Autocompletion for such constants is not very useful, and once you have similar names like GL_TEXTURE and GL_TEXTURE_2D, you really need documentation opened at all times (which I do anyway for various reasons -- but that's just me).

Anyway, I don't insist on the proposed way. If there's any other way to shorten the names, then I'm all for it.

Expandable wrote:
Enums in OpenGL are just #defines, aren't they?
Yeah, that part should not be copied; for constants enums look better than defines.

Expandable wrote:
Anyway, why not just use enums the standard C++-way?
That actually was my first impulse also, but unfortunately there are conflicts: MeshNodeParams::MaterialRes is 300, while LightNodeParams::MaterialRes is 500, so you can't just use MaterialRes everywhere, you have to use the prefix.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 40 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group