
#include <blitz.h>
#include "include/irrlicht.h"

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace quake3;

extern "C" 
{

	IrrlichtDevice* Irr_createDevice(E_DRIVER_TYPE driver,dimension2d<s32>* size, u32 bits=16, bool fullscreen=false, bool stencilbuffer=false, bool vsync=false,IEventReceiver* evt=0)
	{
		return createDevice(driver, dimension2du(*size), bits,fullscreen,stencilbuffer,vsync,evt);
	};
	
	IrrlichtDevice* Irr_createDeviceEx(SIrrlichtCreationParameters* cp)
	{
		return createDeviceEx(*cp);
	};
	
	void Irr_ptrarray_delete(u32** ptr)
	{
		if (*ptr) delete *ptr;
	}		

	void Irr_ptrarray_allocate(u32** ptr,u32 arr_size)
	{		
		Irr_ptrarray_delete(ptr);
		
		*ptr=(u32*)malloc(sizeof(u32)*arr_size);
	}

	u32 Irr_MAKE_IRR_ID(c8 c0, c8 c1, c8 c2, c8 c3) 
	{
		return MAKE_IRR_ID(c0,c1,c2,c3);
	}
			
}

#include "bound/bmxbinder.h"
#include "bound/bmxbinder_wrap.h"
#include "bound/bmxiscenenode_wrap.h"
#include "bound/bmxiscenenodeanimator_wrap.h"
#include "bound/bmxiparticleaffector_wrap.h"
#include "bound/bmximeshloader_wrap.h"
#include "bound/bmxiimagewriter_wrap.h"
#include "bound/bmxisceneuserdataserializer_wrap.h"
#include "bound/bmxiimageloader_wrap.h"
#include "bound/bmxilightmanager_wrap.h"
#include "bound/bmxicollisioncallback_wrap.h"
#include "bound/bmxivertexmanipulator_wrap.h"

//----------------------------------------
// irr wrappers
//----------------------------------------

#include "irr/ieventreceiver_wrap.h"
#include "irr/irrlichtdevice_wrap.h"
#include "irr/ilogger_wrap.h"
#include "irr/iosoperator_wrap.h"
#include "irr/itimer_wrap.h"
#include "irr/sjoystickinfo_wrap.h"
#include "irr/skeymap_wrap.h"
#include "irr/sevent_wrap.h"
#include "irr/ireferencecounted_wrap.h"
#include "irr/sirrcreationparameters_wrap.h"

//----------------------------------------
// irr::core wrappers
//----------------------------------------

// arrays of objects
#include "core/array_s32_wrap.h"
#include "core/array_u16_wrap.h"
#include "core/array_u32_wrap.h"
#include "core/array_vector3df_wrap.h"
#include "core/array_triangle3df_wrap.h"
#include "core/array_S3DVertex_wrap.h"
#include "core/array_S3DVertex2TCoords_wrap.h"
#include "core/array_S3DVertexTangents_wrap.h"
#include "core/array_SParticle_wrap.h"

// arrays of pointers
#include "core/array_SParticle_ptr_wrap.h"

#include "core/recti_wrap.h"
#include "core/position2df_wrap.h"
#include "core/position2di_wrap.h"
#include "core/dimension2df_wrap.h"
#include "core/dimension2di_wrap.h"
#include "core/vector2df_wrap.h"
#include "core/vector2di_wrap.h"
#include "core/vector3df_wrap.h"
#include "core/triangle3df_wrap.h"
#include "core/triangle3di_wrap.h"
#include "core/plane3df_wrap.h"
#include "core/plane3di_wrap.h"
#include "core/quaternion_wrap.h"
#include "core/matrix4_wrap.h"
#include "core/stringc_wrap.h"
#include "core/stringw_wrap.h"
#include "core/line2di_wrap.h"
#include "core/line2df_wrap.h"
#include "core/line3di_wrap.h"
#include "core/line3df_wrap.h"
#include "core/aabbox3df_wrap.h"

//----------------------------------------
// problematic
//----------------------------------------
#include "core/rectf_wrap.h"	// causes warnings due to float to int conversion
#include "core/vector3di_wrap.h" // causes warnings due to float to int conversion
#include "core/aabbox3di_wrap.h" // causes warnings due to float to int conversion

//----------------------------------------
// irr::video wrappers
//----------------------------------------
#include "video/ivideodriver_wrap.h"
#include "video/scolor_wrap.h"
#include "video/slight_wrap.h"
#include "video/smaterial_wrap.h"
#include "video/smateriallayer_wrap.h"
#include "video/s3dvertex_wrap.h"
#include "video/ivideomodelist_wrap.h"
#include "video/sexposedvideodata_wrap.h"
#include "video/itexture_wrap.h"
#include "video/iimage_wrap.h"
#include "video/imaterialrendererservices_wrap.h"
#include "video/imaterialrenderer_wrap.h"
#include "video/ishaderconstantsetcallback_wrap.h"
#include "video/igpuprogrammingservices_wrap.h"
#include "video/iimagewriter_wrap.h"
#include "video/iimageloader_wrap.h"
#include "video/igeometrycreator_wrap.h"

//----------------------------------------
// irr::gui wrappers
//----------------------------------------

#include "gui/iguienvironment_wrap.h"
#include "gui/icursorcontrol_wrap.h"
#include "gui/iguibutton_wrap.h"
#include "gui/iguicheckbox_wrap.h"
#include "gui/iguicolorselectdialog_wrap.h"
#include "gui/iguicontextmenu_wrap.h"
#include "gui/iguicombobox_wrap.h"
#include "gui/iguieditbox_wrap.h"
#include "gui/iguielement_wrap.h"
#include "gui/iguifileopendialog_wrap.h"
#include "gui/iguifont_wrap.h"
#include "gui/iguifontbitmap_wrap.h"
#include "gui/iguiimage_wrap.h"
#include "gui/iguiimagelist_wrap.h"
#include "gui/iguiinoutfader_wrap.h"
#include "gui/iguilistbox_wrap.h"
#include "gui/iguimeshviewer_wrap.h"
#include "gui/iguiscrollbar_wrap.h"
#include "gui/iguiskin_wrap.h"
#include "gui/iguispinbox_wrap.h"
#include "gui/iguistatictext_wrap.h"
#include "gui/iguitab_wrap.h"
#include "gui/iguitabcontrol_wrap.h"
#include "gui/iguitable_wrap.h"
#include "gui/iguitoolbar_wrap.h"
#include "gui/iguitreeview_wrap.h"
#include "gui/iguiwindow_wrap.h"
#include "gui/iguispritebank_wrap.h"
#include "gui/iguielementfactory_wrap.h"

//----------------------------------------
// irr::scene wrappers
//----------------------------------------

#include "scene/cdynamicmeshbuffer_wrap.h"
#include "scene/cindexbuffer_wrap.h"
#include "scene/cvertexbuffer_wrap.h"
#include "scene/iscenemanager_wrap.h"
#include "scene/ianimatedmesh_wrap.h"
#include "scene/ianimatedmeshmd2_wrap.h"
#include "scene/ianimatedmeshscenenode_wrap.h"
#include "scene/ianimationendcallback_wrap.h"
#include "scene/iq3levelmesh_wrap.h"
#include "scene/ibillboardscenenode_wrap.h"
#include "scene/ibillboardtextscenenode_wrap.h"
#include "scene/ibonescenenode_wrap.h"
#include "scene/icamerascenenode_wrap.h"
#include "scene/idummytransformationscenenode_wrap.h"
#include "scene/idynamicmeshbuffer_wrap.h"
#include "scene/iindexbuffer_wrap.h"
#include "scene/ilightscenenode_wrap.h"
#include "scene/imesh_wrap.h"
#include "scene/imeshbuffer_wrap.h"
#include "scene/imeshcache_wrap.h"
#include "scene/imeshloader_wrap.h"
#include "scene/imeshmanipulator_wrap.h"
#include "scene/imeshscenenode_wrap.h"
#include "scene/imetatriangleselector_wrap.h"
#include "scene/iparticleaffector_wrap.h"
#include "scene/iparticleattractionaffector_wrap.h"
#include "scene/iparticlefadeoutaffector_wrap.h"
#include "scene/iparticlegravityaffector_wrap.h"
#include "scene/iparticlerotationaffector_wrap.h"
#include "scene/iparticleemitter_wrap.h"
#include "scene/iparticleanimatedmeshscenenodeemitter_wrap.h"
#include "scene/iparticleboxemitter_wrap.h"
#include "scene/iparticlemeshemitter_wrap.h"
#include "scene/iparticlecylinderemitter_wrap.h"
#include "scene/iparticleringemitter_wrap.h"
#include "scene/iparticlesphereemitter_wrap.h"
#include "scene/iparticlesystemscenenode_wrap.h"
#include "scene/iscenecollisionmanager_wrap.h"
#include "scene/iscenenode_wrap.h"
#include "scene/iscenenodefactory_wrap.h"
#include "scene/iscenenodeanimator_wrap.h"
#include "scene/iscenenodeanimatorcamerafps_wrap.h"
#include "scene/iscenenodeanimatorcameramaya_wrap.h"
#include "scene/iscenenodeanimatorfactory_wrap.h"
#include "scene/iscenenodeanimatorcollisionresponse_wrap.h"
#include "scene/ishadowvolumescenenode_wrap.h"
#include "scene/iskinnedmesh_wrap.h"
#include "scene/iterrainscenenode_wrap.h"
#include "scene/itextscenenode_wrap.h"
#include "scene/itriangleselector_wrap.h"
#include "scene/ivertexbuffer_wrap.h"
#include "scene/ivolumelightscenenode_wrap.h"
#include "scene/sanimatedmesh_wrap.h"
#include "scene/smesh_wrap.h"
#include "scene/sparticle_wrap.h"
#include "scene/sviewfrustum_wrap.h"
#include "scene/ianimatedmeshmd3_wrap.h"
#include "scene/iq3shader_wrap.h"
#include "scene/smeshbuffer_wrap.h"
#include "scene/smeshbufferlightmap_wrap.h"
#include "scene/smeshbuffertangents_wrap.h"
#include "scene/ssharedmeshbuffer_wrap.h"
#include "scene/sskinmeshbuffer_wrap.h"

//----------------------------------------
// irr::io wrappers
//----------------------------------------

#include "io/ifilesystem_wrap.h"
#include "io/ifilelist_wrap.h"
#include "io/ireadfile_wrap.h"
#include "io/iwritefile_wrap.h"
#include "io/ixmlreader_wrap.h"
#include "io/ixmlreaderutf8_wrap.h"
#include "io/ixmlwriter_wrap.h"
#include "io/sattributereadwriteoptions_wrap.h"
#include "io/iattributeexchangingobject_wrap.h"
#include "io/iattributes_wrap.h"
#include "io/ifilearchive_wrap.h"
#include "io/path_wrap.h"

//----------------------------------------
//----------------------------------------

/*
// from => http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=19855
//! Names for scene node types 
const c8* const types[] = 
{ 
  "cube", 
  "sphere", 
  "text", 
  "waterSurface", 
  "terrain", 
  "skyBox", 
  "shadowVolume", 
  "octTree", 
  "mesh", 
  "light", 
  "empty", 
  "dummyTransformation", 
  "camera", 
  "cameraMaya", 
  "cameraFPS", 
  "billBoard", 
  "animatedMesh", 
  "particleSystem", 
  0, 
  "unknown", 
  0 
}; 

u32 depth = 0; 

void ISceneNode_dumpSceneGraph(scene::ISceneNode* node) 
{ 
  u32 nodeType = node->getType(); 
  if (scene::ESNT_COUNT < nodeType) 
    nodeType = scene::ESNT_UNKNOWN; // unknown 

  const char* nodeName = node->getName(); 
  if (!nodeName || !*nodeName) 
    nodeName = "<unknown>"; 

  fprintf(stderr, "%*.s [id=%d] type=%s name='%s'\n", depth*3, "", node->getID(), types[nodeType], nodeName); 

  ++depth; 

  core::list<scene::ISceneNode*>::Iterator b = node->getChildren().begin(); 
  core::list<scene::ISceneNode*>::Iterator e = node->getChildren().end(); 

  for (; b != e; ++b) 
    ISceneNode_dumpSceneGraph(*b); 

  --depth; 
} 

// when a key is pressed, dump the graph... 
ISceneNode_dumpSceneGraph(smgr->getRootSceneNode());
*/