POV-Ray : Newsgroups : povray.programming : POV-Ray C++? : Re: POV-Ray C++? Server Time
24 Apr 2024 20:46:25 EDT (-0400)
  Re: POV-Ray C++?  
From: MiB
Date: 4 Jan 2012 19:40:01
Message: <web.4f04f005c9ae25fcb154c30@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> MiB <nomail@nomail> wrote:
> > However, a quick survey reveals POV-Ray itself is not written in a contemporary
> > object-oriented style; a lot of pointers to structs are handed around, functions
> > manipulating data structures are on a global level and not members of classes.
>
>   Could you give some clarifying examples of this, as well as a suggestion
> of how it should be done better?

Pretty much the first file I touched was
povwin-src-3.7-RC3\source\backend\scene\objects.h

Here, object types and properties are defined by flag values, operations on
flags are preprocessor macros, operations on objects (including
copy-construction and destructors!) are global functions instead of members of
the Object class.

To focus on a single example, the function
void Translate_Object( ObjectPtr Object, const VECTOR Vector, const TRANSFORM
*Trans )
looks like a good candidate for a member function of Object - it is already set
up like one, the first parameter "Object" would become implicit as "this".
I'd prefer to set up a base class Object like this

class Object {
/* ... */
public:
   virtual void Translate( const VECTOR& Vector, const TRANSFORM* Trans );
}

Derived classes of Object may override the method to take care of their
specifics.

The flag system could be completely replaced by a class hierarchy, where each
type of object implements its own version of functionality that now needs to be
singled out by "if" or "switch" constructs.

I wrote programs in this style, too, until around 1992 :-) ... in a funny kind
of revelation I "invented" object orientation for C (using function pointers as
struct members). When I proudly presented this "novel" approach to a friend, I
was devastated to learn that this idea was a normal feature of OO languages for
years already. C++ became a friend after that.

>   (This is not an objection to your claim. I'm just being lazy and don't want
> to wade through the code to see examples, so I'm hoping you could provide
> some.)

Actually, I need to relativise my statement somewhat. A lot of POV-Ray code
already is organized in classes, I just happened to stumble upon older code
parts first.

 kind regards,

   MiB.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.