#ifndef _RT_LOG_H
#define _RT_LOG_H

#include "log.h"
#include "workrec.h"

#ifdef DISABLE_RT_LOG
#define RTLOG(event, entry)
#else
#define RTLOG(event, entry) LOG(RT_LOG_ON, event,entry)
#endif

#include "logentry.h"
#include "vec4.h"

class RT_NewFrame_Entry {
public:
  int _frame_num;
  Vec4 _R, _D;
  
  RT_NewFrame_Entry (const Vec4 &R, const Vec4 &D, int framenum) : _frame_num (framenum), _R(R), _D(D) {}
};

const int NUM_STATS = 38;

const char *statnames[] = {"# frusta that clipped around their 4 edges",
		       "# cells touched",
		       "# times a ray/frustum entered a cell",
		       "# times a frustum was requested from the cf cache",
		       "# times the cf cache hit",
		       "# objs distributed into kid frusta",
		       "# objs returned from cf cache",
		       "# quick subdivides in cf cache",
		       "# objs that straddled a plane",
		       "# objs that were on one side of a plane",
		       "# intersects overruled by later hits",
		       "# intersects done by old-school k-d algorithm",
		       "# objs hit by old-school k-d algorithm",
		       "# rays that missed bboxes in old-school k-d algorithm",
		       "# intersects done by frusta",
		       "# objs hit by frusta",
		       "# rays of frusta that missed bboxes",
		       "unknown - worstcase intersect count?",
		       "# findpoint calls",
		       "# kdtraversal cache hits",
		       "# objs culled by ray lists",
		       "# objs not culled by ray lists",
		       "# screen-space conversions",
		       "# objs touched",
		       "# objs touched double-counted",
		       "# axis checks",
		       "# axis check successes",
		     "# axis checks that had to fail",
		     "# intersections",
		     "# pixels that required >1 intersection",
		     "# pixels that required only 1 intersection",
		     "# pixels that used the k-d tree",
		     "# visible objs",
		     "# visible objs double-counted",
		     "# rays that missed bboxes",
		     "# rays that were tested against bboxes",
		     "# bboxes that were quick-rejected by eye pt",
		     "# objs that were quick-rejected by k-d tree sorted lists",
  };

char *statYlabels[] = {"# frusta",
		       "# cells",
		       "# entered",
		       "# requests",
		       "# hits",
		       "# objs",
		       "# objs",
		       "# subdivides",
		       "# straddlers",
		       "# objs",
		       "# intersects",
		       "# intersects",
		       "# objs hit",
		       "# rays missed",
		       "# intersects",
		       "# objs hit",
		       "# rays missed",
		       "# worstcase intersects?",
		       "# calls",
		       "# hits",
		       "# objs culled",
		       "# objs not culled",
		       "# conversions",
		       "# objs touched",
		       "# objs touched x2",
		       "# axis checks",
		       "# successes",
		       "# fails",
		       "# intersections",
		       "# pixels",
		       "# pixels",
		       "# pixels",
		       "# visible objs",
		       "# visible objs x2",
		       "# rays missed",
		       "# rays tested",
		       "# bboxes",
		       "# objs rejected",
  };

class RT_Stats_Entry {
public:
  int _frame_num;
  int *_stats;
  
  RT_Stats_Entry (int framenum, int *stats) : _frame_num (framenum) {
    _stats = new int [NUM_STATS];
    for (int i = 0; i < NUM_STATS; i++) _stats[i] = stats[i]; }
};
  
class RT_NewRootFrustum_Start_Entry {
public:
  WorkRec *_root;
  RT_NewRootFrustum_Start_Entry (WorkRec *root) : _root (root) {}
};

class RT_NewRootFrustum_End_Entry {
public:
  WorkRec *_root;
  RT_NewRootFrustum_End_Entry (WorkRec *root) : _root (root) {}
};

class RT_SampleFourCorners_Start_Entry {
public:
  WorkRec *_root;
  RT_SampleFourCorners_Start_Entry (WorkRec *root) : _root (root) {}
};

class RT_SampleFourCorners_End_Entry {
public:
  RT_SampleFourCorners_End_Entry (void) {}
};

class RT_Rendering_Start_Entry {
public:
  int _frame_id, _sub_frame_id, _age;
  RT_Rendering_Start_Entry (int frameid, int subframeid, int age) : _frame_id (frameid), _sub_frame_id (subframeid), _age (age) {}
};

class RT_Rendering_End_Entry {
public:
  int _frame_id, _sub_frame_id, _age;
  RT_Rendering_End_Entry (int frameid, int subframeid, int age) : _frame_id (frameid), _sub_frame_id (subframeid), _age (age) {}
};

#endif
