/*****************************************************************************
 * $Id: eng_stats.cc,v 1.2 2006/11/02 05:26:06 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Engine statistics.
 *          Most stats incur some overhead.
 *//*
 * LEGAL:	COPYRIGHT (C) 2006 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#if STATS

#define ENG_STATS_CC 1
#include "eng.hh"
#include "eng_init.hh"
#include "eng_stats.hh"
#include "gfx_stream.hh"

ostream* gStreamStats = &cout;

/*****************************************************************************
 * Stats constructor.
 *****************************************************************************/
EngineStats::EngineStats( void )
{
	mPolygonAttribs			= 0;
	mCacheMissVertexs		= 0;
	mCacheMissNormals		= 0;
	mObjectGroupVisible		= 0;
	mObjectGroupInvisible	= 0;
    mBillboards             = 0;
    mBillboardSlicesDrawn   = 0;
    mSortingDone            = 0;
    mSortingSkip            = 0;
    mObjectsDrawn           = 0;
}

/*****************************************************************************
 * Reset some stats prior to drawing views.
 *****************************************************************************/
void
EngineStats::PreDrawViews( void )
{
	mObjectGroupVisible		= 0;
	mObjectGroupInvisible	= 0;
    mBillboardSlicesDrawn   = 0;
    mObjectsDrawn           = 0;
}

/*****************************************************************************
 * operator<<(EngineStats)
 *****************************************************************************/
ostream&
operator<<( ostream& strm, const EngineStats& o )
{
	extern uint DebugSharedPolygonAttribsCnt( void );

    strm << "Statistics: \n"
         << "  sorting (skip)             = " << o.mSortingDone << " (" << o.mSortingSkip << ")\n"
         << "  shared PolygonAttribs      = " << DebugSharedPolygonAttribsCnt() << '\n'
         << "  PolygonAttribs [1]         = " << o.mPolygonAttribs				<< '\n'
         << "  cache miss vertexs         = " << o.mCacheMissVertexs			<< '\n'
         << "  cache miss normals         = " << o.mCacheMissNormals			<< '\n'
         << "  total texture mem          = " << Texture2::GetTotalMemoryUsed() << '\n'
         << "  billboards, slices drawn   = " << o.mBillboards << ',' << o.mBillboardSlicesDrawn << '\n'
         << "[1] Count is inflated by SharedVal storing two copies (key,val)"; // << '\n'
    return strm;
}

#endif // STATS
