It is currently Fri Oct 20, 2017 3:51 am

All times are UTC - 5 hours




 Page 1 of 1 [ 8 posts ] 
Author Message
 Post subject:
PostPosted: Sun Jul 08, 2007 8:58 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
VMK 33A/B shows you how to modify the Font, Material, Light, Texture, TextureTransform, Geometry, GeometryBox, GeometryCylinder, GeometryFlatGrid, GeometryCompiled, Node, NodeShape, NodeLight and NodeTransform classes so that all the scenegraph data can be output to the log file for viewing.


Offline
 Profile  
 
 Post subject: Second thoughts about VMK33 Scene Graph Logger
PostPosted: Fri Apr 03, 2009 4:17 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
I. ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

Some antecedent discussions shown that the people prone to use ErrorHander as an unique global object available disregarding the scopes of any specific class. (I even suspect that Marek has changed his mind as well). This means that we can define the ErrorHander as a global object (singleton alike, but not exactly).
// in ErrorHandler.cpp - a single unique instance of this object
ErrorHandler g_errorHanler;


// in ErrorHandler.h
inline ErrorHander & EH() {              // EH() or GetErrorHandler() - as you wish
    extern ErrorHandler g_errorHandler;
    return g_errorHandler;
}


// initialize error handler in Main.cpp
EH().Initialize();


// from now it is possible to use error handler anywhere w/o any additional static pointers
#include "ErrorHandler.h"
(...)
EH().SetErrorCode( EC_None, "Hi there" );



II. ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

In this Visual Module one can every so often observe following pattern:
char szOutput[1024];
(...)
sprintf(szOutput, "%s some_param %f", szOutput, m_some_param);
(...)

This is a pretty smart way to concatenate strings without direct invocation of strcat(). There is however another way, a little bit faster. (However it's beyound any question that speed is not important for Scene Graph logging). The idea is to use the fact that sprintf()-family functions return the number of symbols that were stored in the buffer.

char szOutput[1024];
int count = 0;
(...)
count += sprintf(szOutput + count, " SomeParam %f", m_someParam);
(...)

So, the sprintf() does not have to recopy the previous parts to concatenate a new stuff to the end.


My code is similar except that the range control is used via snprintf() family, i.e.
void ShapeBox::Dump( bool all )
{
    const int BUF_SIZE = 1023;
    TCHAR buf[ BUF_SIZE + 1 ];
    buf[ BUF_SIZE ] = _T( '\0' );
    int count = 0;

    if ( all || 1 )
        count += _sntprintf( buf + count, BUF_SIZE - count, _T( "Box geoID_ %u" ), this );
    if ( all || DefWidth() != m_width )
        count += _sntprintf( buf + count, BUF_SIZE - count, _T( " Wid_ %f" ), m_width );
    if ( all || DefDepth() != m_depth )
        count += _sntprintf( buf + count, BUF_SIZE - count, _T( " Dep_ %f" ), m_depth );
    if ( all || DefHeight() != m_height )
        count += _sntprintf( buf + count, BUF_SIZE - count, _T( " Hei_ %f" ), m_height );

    LOG()( Log::Verbose, _T( "%s" ), buf );   
}


Last edited by BugHunter on Sun Apr 05, 2009 5:27 am, edited 1 time in total.

Offline
 Profile  
 
 Post subject: Defaults for simple types
PostPosted: Fri Apr 03, 2009 5:00 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
Another interesting moment is that we can supply any appropriate class with (static inline) functions that return default values.

//------------------------------------------------------------------------------
// Simple Material container
//------------------------------------------------------------------------------
struct Material
{
    explicit Material( size_t id );
    void Dump( bool all = true );

    static Color DefAmbient  () { return Color( 0.2f, 0.2f, 0.2f, 1.0f ); } // <-- default value
    static Color DefDiffuse  () { return Color( 0.8f, 0.8f, 0.8f, 1.0f ); } // <-- default value
    static Color DefSpecular () { return Color( 0.0f, 0.0f, 0.0f, 1.0f ); } // <-- default value
    static Color DefEmission () { return Color( 0.0f, 0.0f, 0.0f, 1.0f ); } // <-- default value
    static float DefShininess() { return ( 0.0f ); }                        // <-- default value

    Color           ambient;
    Color           diffuse;
    Color           specular;
    Color           emission;
    float           shininess;
    const size_t    ID;
};

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
inline Material::Material( size_t id )
:   ID( id )
,   ambient  ( DefAmbient  () )
,   diffuse  ( DefDiffuse  () )
,   specular ( DefSpecular () )
,   emission ( DefEmission () )
,   shininess( DefShininess() )
{
}


As you can see I chose the prefix Def- for the functions that return default values. Their static attribute allows to use such functions without having an object, i.e. Material::DefAmbient().

Thus, if someone want to figure out whether current Material mat.ambient has default value, one can write:
Material mat;
(...)
if ( Material::DefAmbient() != mat.ambient ) {
   // do something ie print current mat.ambient values
}


I added Def-class functions to all simple types: Material, Texture, TexTransform, LightPoint, etc...
Additionally some simple types such as Vector3, Color etc should be extended with comparison operator:
// these operators might be either global or member functions

inline bool operator== ( const Vector3 & a, const Vector3 & b )
{
    return a[0]==b[0] && a[1]==b[1] && a[2]==b[2];
}

inline bool operator!= ( const Vector3 & a, const Vector3 & b )
{
    return !operator==( a, b );
}

//  inline bool operator!= ( const Vector3 & a, const Vector3 & b )
//  {
//      return a[0]!=b[0] || a[1]!=b[1] || a[2]!=b[2];
//  }



The rationale behind this solution is that architecturally it is much better to keep default values in one place, in our case inside class definition, than scatter them across all code. Remember, we need default values in several quite different places, i.e. in constructor, in LVL loader (and any other loaders), and from now inside scene-graph-logger.
It is important that defaults, defined in the way I proposed do not reduce performance since the compiler can inline the functions, and secondly, the temporary objects have (or at least theoretically should have) overloaded comparison operator, e.g.
bool operator== () and bool operator!= ().
This also reduces the amount of the code one have to write comparing current value with default one (the comparison is an important constituent of logger code).


Last edited by BugHunter on Sun Apr 05, 2009 5:31 am, edited 1 time in total.


_________________
«Computer scientists deal with algorithms that you may call practical in theory but unpractical in practice.» © Timothy Gowers
Offline
 Profile  
 
 Post subject: Re: Second thoughts about VMK33 Scene Graph Logger
PostPosted: Fri Apr 03, 2009 6:21 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
BugHunter wrote:
Some antecedent discussions shown that the people prone to use ErrorHander as an unique global object available disregarding the scopes of any specific class. (I even suspect that Marek has changed his mind as well)


You are correct. In the Ghost Toast series you will see that I have changed the interface to a number of core classes developed in the game engine.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 33 - Scenegraph Logger
PostPosted: Wed Nov 27, 2013 12:00 pm 

Joined: Sun Jul 21, 2013 5:17 pm
Posts: 17
Hi marek. Thanks a lot for the great tutorials!

I can not download the first part :-( I have downloaded it 6 times with two different computer and 3 different browser, but when I try to open the rar I get this error:

! C:\Users\Davide\Downloads\GameDev-VMK033A-ScenegraphLog (1).rar: Unexpected end of archive


:-(


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 33 - Scenegraph Logger
PostPosted: Wed Nov 27, 2013 1:06 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
davidemo89 wrote:
I can not download the first part :-( I have downloaded it 6 times with two different computer and 3 different browser, but when I try to open the rar I get this error:
! C:\Users\Davide\Downloads\GameDev-VMK033A-ScenegraphLog (1).rar: Unexpected end of archive


How many MB's is the downloaded file that you are trying to uncompress? Also, what program (and version number) are you using to open the RAR file with?

I just downloaded VMK33a and VMK33b and was able to open the file with no problems on my end.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 33 - Scenegraph Logger
PostPosted: Thu Nov 28, 2013 2:39 am 

Joined: Sun Jul 21, 2013 5:17 pm
Posts: 17
Hi, thank you for the help marek.
In this computer the 3 times I have downloaded the file it's 3 time's different D=

7.151.616 byte
7.081.984 byte
9.510.321 byte


Just lol


And today it's magicaly working again!


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 33 - Scenegraph Logger
PostPosted: Thu Nov 28, 2013 8:53 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
davidemo89 wrote:
And today it's magicaly working again!


I'm glad to hear that it is working again for you.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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

Jump to:  

cron