Skip to main content

Experimental integration Glean with Unity applications

The relative order of initialization of non-local static objects

Refer to Effective C++ 3rd item 4.

The Relative order of initialization of non-local static objects defined in different translation units is undefined.

main.cpp
--------------------------
testVar var;

int _tmain(int argc, _TCHAR* argv[])
{

     int t[16];
   
    memcpy( t, var.getVar(), 16 * sizeof(int) );
    return 0;
}


The t will be set [ 0, 0, 0,...... ]. It is wrong, I have set the t to g_identity. I must occur the relative order problem.  Below is the original source code.

testVar.h
--------------------------
template
class testVar
{
private:
    Type var[16];
    static const testVar g_identity;
};


testVar.inl
-----------------------
template const testVar testVar::g_identity( 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 );

template
testVar::testVar()
{
    setIdentity();
}

template
void testVar::setIdentity()
{
    memcpy( var, g_identity.getVar(), 16 * sizeof(Type) );
}


I replaced direct access non-local static variable - g_identity with call to function

testVar.h
--------------------------
template
class testVar
{


private:
    Type var[16];
     const testVar& getIdentity();
};

testVar.inl
-----------------------
template
 const testVar& testVar::getIdentity()
{
    static testVar g_identity( 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 );

    return g_identity;
}


template
void testVar::setIdentity()
{
   // testVar t;

    memcpy( var, getIdentity().getVar(), 16 * sizeof(Type) );
}

main.cpp
--------------------------
testVar var;
{

     int t[16];
   
    memcpy( t, var.getVar(), 16 * sizeof(int) );
    return 0;
}

Finally, The t will return [ 0,1,2,3,4,....]. It is good!!


* Avoid initialization order problems across translation units by replacing non-local static objects with local static objects.
Translation: the source file includes the used header files.

Reference:
http://fcamel-life.blogspot.com/2011/10/c-non-static.html

Comments

Popular posts from this blog

tex2D vs. tex2Dproj

texCoord(  texX, texY, texZ , texW ) means texture coordinate after transforming from the texture matrix [ position goes through world, view, projection, and texture ] . We can use texCoord to fetch texture: 1.  float4 color = tex2D( sampler,  float2( texX / texW, texY/texW ); 2.  float4 color = tex2Dporj( sampler, float4( texX, texY, texZ, texW ) ); The top-two methods will have the same result. Because tex2Dproj operator supports divide w in its interface. http://www.gamedev.net/community/forums/topic.asp?topic_id=408894 http://bbs.gameres.com/showthread.asp?threadid=104316

Fast subsurface scattering

Fig.1 - Fast Subsurface scattering of Stanford Bunny Based on the implementation of three.js . It provides a cheap, fast, and convincing approach to do ray-tracing in translucent surfaces. It refers the sharing in GDC 2011  [1], and the approach is used by Frostbite 2 and Unity engines [1][2][3]. Traditionally, when a ray intersects with surfaces, it needs to calculate the bouncing result after intersections. Materials can be divided into three types roughly.  Opaque , lights can't go through its geometry and the ray will be bounced back.  Transparency , the ray passes and allow it through the surface totally, it probably would loose a little energy after leaving.  Translucency , the ray after entering the surface will be bounced internally like below Fig. 2. Fig.2 - BSSRDF [1] In the case of translucency, we have several subsurface scattering approaches to solve our problem. When a light is traveling inside the shape, that needs to consider the diffuse value influe

Bringing Large Scale Console Game to iOS

Y8ObbsOsNQEhMCEhMCEt The Bard's Tale Why? Device are fast enough Market segment is not as crowded Hugh potential user base Rich back data log of content Potentially very low cost Session1: port process - application framework  - development workflow Session 2 port-port - performance/memory opt. OpenGL Cocoa Touch App Bring it all together Workflow: Data deployment OpenAL limit 32 active sources, DirectSound 256 channels on XBOX -Sluggish -5.8G -> 2Glimited on iOS 60Hz?    - terriable for battery life 30 Hz   - Game may depend on 60Hz Hybrid    -   60hz, functionsliity intact   - 30hz : low GPU/ save energy    -60hz, at 5th device is optional VFP?? Candidate for NEON SIMD SGX GPUs: a few stats Render opt. -minimal vertex format size -texture size and mipmapping Alpha test and SGX - Fragment discard expensive -huge impact on fill rate -use alpha blend at all costs Eliminating Alpha blend