Page 5 of 6 FirstFirst ... 3456 LastLast
Results 61 to 75 of 80

Thread: C++ SDK - When?

  1. #61
    Ach, Mein thirsten! Anti-Distinctly's Avatar
    Join Date
    Sep 2005
    Location
    Kent, UK
    Posts
    1,152
    Hell, I can't recall what the code that I wrote a few weeks ago does. If I didn't comment my code, I'd end up in a world of pain, not to mention anyone else who tried to decypher it.
    "Oww! Owwwwwww! They're defending themselves somehow" - Homer J. Simpson

    www.lukewhitehorn.com
    www.euriskostudios.com

  2. #62
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,900
    Quote Originally Posted by Anti-Distinctly
    Hell, I can't recall what the code that I wrote a few weeks ago does. If I didn't comment my code, I'd end up in a world of pain, not to mention anyone else who tried to decypher it.
    Split up code to small parts. If function, method or class is not self explanatory, split it again more..
    Don't use short names, they're confusing and impossible to remember even though you have less to type.. But in longer period of time, they make code unreadable..

    If you see my code, you would know what exactly is doing class or method just by name..
    f.e. from VirtualRender:
    void CVRCompositeRequester::GetOutputFormatExtension( char *extension, size_t size );
    it's settings window that's opened after pressing VirtualRender Composite generic tool, and it fills supplied buffer by file extension of currently choosed by user output file format..

    Code:
    void CVRCompositeRequester::GetOutputFormatExtension(
     char *extension,
     size_t size )
    {
     ENTER( "CVRCompositeRequester::GetOutputFormatExtension()" );
    
     if( ( extension != NULL ) && ( size > 0 ) )
     {
      memset( (void *) extension, 0, size );
    
      int output_format = GetOutputFormat();
      if( output_format == 0 )
      {
       strncpy( extension, "raw", size );
      }
      else if( output_format >= 1 )
      {
       m_ImageUtil.GetSaverExtension( output_format - 1, extension, size );
      }
     }
    
     LEAVE( "CVRCompositeRequester::GetOutputFormatExtension()" );
    }
    Then what are doing method used in this example? You know already.. But here they're:

    Code:
    void TACImageUtil::GetSaverExtension(
     int saver_index,
     char *buffer,
     size_t size )
    {
     ENTER( "TACImageUtil::GetSaverExtension()" );
    
     if( ( buffer != NULL ) && ( size > 0 ) )
     {
      memset( (void *) buffer, 0, size );
    
      const char *name;
      name = SaverName( saver_index );
      if( name != NULL )
      {
       int length = (int) strlen( name );
       if( name[ length - 1 ] == ')' )
       {
        for( int i = length - 2; i >= 0; i-- )
        {
         if( name[ i ] == '(' )
         {
          if( name[ i + 1 ] == '.' )
          {
           int len = ( length - 1 ) - ( i + 2 );
           for( int j = 0; j < len; j++ )
           {
            buffer[ j ] = name[ j + i + 2 ];
           }
          }
          break;
         }
        }
       }
      }
     }
    
     LEAVE( "TACImageUtil::GetSaverExtension()" );
    }
    Code:
    int CVRCompositeRequester::GetOutputFormat( void ) const
    {
     ENTER( "CVRCompositeRequester::GetOutputFormat()" );
    
     int output_format = m_Output_Format;
    
     LEAVE( "CVRCompositeRequester::GetOutputFormat()" );
     return( output_format );
    }

  3. #63
    inSPIRAL jay3d's Avatar
    Join Date
    Jul 2003
    Location
    Wavers World
    Posts
    902
    Hi,

    Sorry for breaking through ,

    but anyone notice that wonderful language http://www.digitalmars.com/d

    i wonder if we can code the core algorithms with that in a separate source compiled as .obj or .lib and link it with the plugin main file, so we can call those functions in other language from out main plugin source file

    any ideas?

  4. #64
    Banned
    Join Date
    Apr 2005
    Location
    Valencia
    Posts
    3,145
    Hi,

    I vote for not complicate things more!

    Aside I didn't found the have a x64 bits, UB or Mac versions, so if you want your plugin compiled for those platforms I think you will be out of luck and with a bunch of users complaining why you do not have your plugin for those platforms!

    Best regards,
    David

  5. #65
    inSPIRAL jay3d's Avatar
    Join Date
    Jul 2003
    Location
    Wavers World
    Posts
    902
    Quote Originally Posted by dballesg
    Hi,

    I vote for not complicate things more!

    Aside I didn't found the have a x64 bits, UB or Mac versions, so if you want your plugin compiled for those platforms I think you will be out of luck and with a bunch of users complaining why you do not have your plugin for those platforms!

    Best regards,
    David
    as for the complications it seems from the comparisons that this language tries to simplify things more ...

    and for the support of other platforms , there's an implementation here : http://dgcc.sourceforge.net/ that supports 64 bit targets

    and here : http://gdcwin.sourceforge.net/ for Window$

    and here : http://gdcmac.sourceforge.net/ for Mac OS X


  6. #66
    Banned
    Join Date
    Apr 2005
    Location
    Valencia
    Posts
    3,145
    Hi Jay3D

    Then I suppose you only need to do a wrapper in D around the .h and .c files of the SDK!

    But it is a HUGE task!

    Look to LightWolf wrapper, even when now I am trying to put my humble help on it, it is far to be finished!

  7. #67
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,613
    Quote Originally Posted by jay3d
    Hi,

    Sorry for breaking through ,

    but anyone notice that wonderful language http://www.digitalmars.com/d
    I actually had a quick look at it and quite liked it when I first saw it (a few months ago).... IT does have a nice, simple clean and concise design. However, I really miss multiple inheritance, which I actually use a lot in C++.
    Quote Originally Posted by jay3d
    i wonder if we can code the core algorithms with that in a separate source compiled as .obj or .lib and link it with the plugin main file, so we can call those functions in other language from out main plugin source file
    That would be a plugin to a plugin, and could probably be written as a DLL/shared library.

    Cheers,
    Mike

  8. #68
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,613
    Quote Originally Posted by jay3d
    and for the support of other platforms , there's an implementation here :
    Unfortunately, these are all front-ends for GCC (not the best choice on windows) - which also means you won't get any native code optimization as you do with C++.

    Give it a few years and it might start to get interesting, right know I see it more as an academic project (albeit an interesting one).

    Cheers,
    Mike

  9. #69
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,613
    Quote Originally Posted by dballesg
    Look to LightWolf wrapper, even when now I am trying to put my humble help on it, it is far to be finished!
    Oh yeah... well, I only tend to add the bits I need, but any help is appreciated.
    Then again it is a wrapper and not just an interface. But what would be the point of using D if you're still stuck with a C based API that hasn't been wrapped to D?

    Cheers,
    Mike

  10. #70
    Valiant NewTeKnight Matt's Avatar
    Join Date
    Feb 2003
    Location
    San Antonio, Texas, USA
    Posts
    13,055

    Post I am not a coder!

    My wonderful code writing skills! I HAVE to comment, otherwise I forget how/why I did stuff, plus I was giving these scripts away, so hopefully someone else might find them useful.

    Clearly this is probably going too far, but I think a few comments help out other people working on your code in a BIG way, it is a GOOD idea in my opinion!

    Code:
    	// Grab user selection, if nothing is selected it will use the 'everything is selected' rule
    	selmode( USER );
    
    
    	// Work out the rotate angle based on the number of copies the user requested
    
        radial_angle = number( 360 / copies );
    
    
    
    	// Start undo grouping so we only use one undo for the whole cloning process
        undogroupbegin() ;
    
    
    
    	// Loop until we reach the number of copies requested
    
    	for(LOOP = 1;LOOP < copies;++LOOP)
    	{
    		// Copy selected object
    		copy();
    
    		// Rotate the selected object based on the angle, axis and axis centre
    		rotate( radial_angle, selected_axis, radial_centre );
    
    		// Paste the copied object in the position before it was rotated
    		paste();
    	}
    
    
    
    	// Turn off undo grouping
    
    	undogroupend() ;
    UI / UX Designer @ NewTek
    __________________________________________________
    www.pixsim.co.uk : LightWave Video Tutorials & Tools


  11. #71
    Registered User
    Join Date
    Feb 2003
    Location
    Finland
    Posts
    75
    Just few comments on things mentioned on this thread:

    Commenting
    In my honest opinion no code can ever be self-explanatory enough that comments wouldn't be helpful. Never. Anyone who has ever programmed in Java and has read the JDK Javadocs should get a good revelation of how any re-usable code should be commented. Any code which isn't trivial (meaning longer than ten lines) should be somewhat commented. Agreed, I don't follow this rule all the time myself either, but it IS a very good habit.

    Multiple inheritance
    There is a reason why many languages haven't brought support for multiple inheritance into them (actually can't really think of any other than C++ right now). 99.9% of times if you need to use multiple inheritance you've done the architectural design wrong. When using multiple inheritance you need to be very very careful. For example how should the language/compiler behave when there is a diamond shaped inheritance tree? In C++ multiple inheritance should be used only for interface classes without any functionality, in other languages there is usually a special Interface class type.

    And for those who don't know what is a diamond shaped inheritance tree I added an attachment of a very dirty class diagram (made quickly in Inkscape, don't have a proper UML drawing software on this computer).

    -----------------------------

    There are so many things lacking in C++ code I see due to people using C way of doing things. Like usage of #define, printf() and so on. #define should never be used (with the exception of #ifndef #define #endif -"trick"), printf is lacking many things provided by cout/cerr etc. List could go on.

    I read that post by Stuart when it was originally posted and was actually astounded. Virtually all of the things he mentioned in his post were wrong. For example the mention about not able to do a +4 operation for an object - has he ever heard about operator-keyword?

    And about Modo renderer being faster than Lightwave and if it is due to them using C instead of C++: the answer is no. C++ code is just as fast as C if you don't use some of C++ bonus things like dynamic binding which needs virtual tables and those cause some overhead (tests have shown a performance loss from 2% to 5% in some extreme cases with a lot of function calls). And in my opinion a 2% performance loss is very much acceptable if one gets cleaner, more modular code with less bugs by using it.

    ps. I'm still interested about that C++ wrapper but I've got way too much work to start playing around with it currently so I'll be delaying the application for the wrapper for a while

    pps. Another rant. This is getting serious...
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	multiple_inheritance.png 
Views:	93 
Size:	2.5 KB 
ID:	47057  
    Last edited by Ember; 06-11-2007 at 03:03 PM.
    Niklas Collin - Finnish Lightwaver

  12. #72
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,613
    Quote Originally Posted by Ember
    Multiple inheritance
    There is a reason why many languages haven't brought support for multiple inheritance into them (actually can't really think of any other than C++ right now). 99.9% of times if you need to use multiple inheritance you've done the architectural design wrong. When using multiple inheritance you need to be very very careful. For example how should the language/compiler behave when there is a diamond shaped inheritance tree? In C++ multiple inheritance should be used only for interface classes without any functionality, in other languages there is usually a special Interface class type.
    We could argue this point for ages I suppose. I just find it to be very, very convenient indeed to have it in C++. An example would be a Node with an XPanel Interface that at the same time uses the ComRing (or is a ComRing Communicator in this case).

    Code:
    class myPlugin : public lwpp::Node, lwpp::XPanelInterface, lwpp::ComRingCommunicator
    {
    };
    Sure, there are other ways to handle it, but I found multiple inheritance to be a good solution when needed.
    Diamind shaped? Look up virtual base classes... They can be a problem if not handled properly, no doubt, and should be used rarely (I've had to use them once or twice).

    The funny thing is, I've been hacking away in C++ for three years yet... and I'm not even close to having achieved the level that I could... which is good, ample space to improve and so far the language has only limited me in one case. (Exceptions are the big thing I need to give more attention too, I've covered just about everything else).
    Quote Originally Posted by Ember
    There are so many things lacking in C++ code I see due to people using C way of doing things. Like usage of #define, printf() and so on. #define should never be used (with the exception of #ifndef #define #endif -"trick"), printf is lacking many things provided by cout/cerr etc. List could go on.
    I basically agree... but not with the samples you provide.
    Try cross platform code without #defines, or try to localize cout code (something I'll probably have to do soon, and I'll go back to sprintfs() I think)...
    It is good to have a choice, but you must use it wisely (not that I always do, mind you, I blunder just as much as anybody else).
    Quote Originally Posted by Ember
    I read that post by Stuart when it was originally posted and was actually astounded. Virtually all of the things he mentioned in his post were wrong. For example the mention about not able to do a +4 operation for an object - has he ever heard about operator-keyword?
    He mentioned implicit types. You can't override operator+() for an int for example, since int is not a real object.
    Quote Originally Posted by Ember
    ps. I'm still interested about that C++ wrapper but I've got way too much work to start playing around with it currently so I'll be delaying the application for the wrapper for a while
    I do agree on the other points. And please do join in the development whenever you like to.
    Especially if you like discussing things (and follow that up with code )

    Cheers,
    Mike

  13. #73
    Banned
    Join Date
    Apr 2005
    Location
    Valencia
    Posts
    3,145
    Quote Originally Posted by Lightwolf
    An example would be a Node with an XPanel Interface that at the same time uses the ComRing (or is a ComRing Communicator in this case).
    Ok, NOW that is scary I am influencing you so much Mike? LOL

    (BTW the plugin sample compiles but doesn't work, I think is due to something applying a Custom Object to a Camera!)

    On the past I needed to teach a few simple programming languages. And something I ALWAYS insisted was COMMENT your code. A couple of lines of comments can save you of future headaches!

    And as Matt pointed it would help others to understand your code.

    Best regards,
    David

  14. #74
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,613
    Quote Originally Posted by dballesg
    Ok, NOW that is scary I am influencing you so much Mike? LOL
    Actually you are. ComRing is something I wanted to tackle anyhow, and now you do

    Cheers,
    Mike

  15. #75
    inSPIRAL jay3d's Avatar
    Join Date
    Jul 2003
    Location
    Wavers World
    Posts
    902
    Hi,

    I found that comment in the D paper:

    Retains investment in existing C code
    Rather than trying to compile existing C code, which would require D to carry on with all the legacy decisions of C, instead D assumes existing C code will be compiled with a C compiler, and connects directly to it at the object code level. D supports all C types (more than C++ does!), common calling conventions (including printf's), and runtime library functions, so C code need never realize it is interfacing to D code.

    There's no need to convert C code to D; new functionality can be written in D and linked in to the existing C object code. Indeed, some parts of the standard library - e.g. std.zlib, std.recls - are widely used C and C++ libraries that have been incorporated with no changes, only D declaration files were created for the libraries' C interfaces.
    It would be useful at the start before building D wrappers around the SDK code, to make the programmer gets familiar with D first

    hehe, sorry to annoy you guys everytime, but simply i cannot resist begining programming with that

    maybe we can co-operate to make two language wrappers one for C++ and one for D in the future;

    any ideas would be great though!

    best regards!

Page 5 of 6 FirstFirst ... 3456 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •