Main Page   Class Hierarchy   Compound List   File List   Compound Members  

csEngine Class Reference

The 3D engine. More...

#include <engine.h>

Inheritance diagram for csEngine:

iEngine iBase List of all members.

Public Methods

 csEngine (iBase *iParent)
 Initialize an empty engine. More...

virtual ~csEngine ()
 Delete the engine and all entities it contains. More...

void Report (const char *description,...)
 Report a notification message.

void Warn (const char *description,...)
 Report a warning.

void ReportBug (const char *description,...)
 Report a bug.

bool CheckConsistency ()
 Check consistency of the loaded elements which comprise the world. More...

void PrepareTextures ()
 Prepare the textures. More...

void PrepareMeshes ()
 Calls UpdateMove for all meshes to initialise bsp bounding boxes. More...

virtual void ShineLights (iRegion *region=NULL, iProgressMeter *meter=NULL)
 Calculate all lighting information. More...

virtual iObjectQueryObject ()
 Query the iObject for the engine.

csObjectQueryCsObject ()
 Query the csObject for the engine.

virtual bool Prepare (iProgressMeter *meter=NULL)
 Prepare the engine. More...

csRadiosityGetRadiosity () const
 Get the pointer to the radiosity object (used with step-by-step debugging).

void InvalidateLightmaps ()
 Invalidate all lightmaps. More...

virtual void SetEngineMode (int mode)
 Set the desired engine mode. More...

virtual int GetEngineMode () const
 Get the current engine mode. More...

virtual int GetBeginDrawFlags () const
 Get the required flags for 3D->BeginDraw() which should be called from the application. More...

csTicks GetLastAnimationTime () const
 Get the last animation time.

void InitCuller ()
 Initialize the culler.

csCBufferGetCBuffer () const
 Return c-buffer (or NULL if not used).

csCBufferCubeGetCBufCube () const
 Return cbuffer cube.

void EnablePVS ()
 Enable PVS.

void DisablePVS ()
 Disable PVS.

virtual bool IsPVS () const
 Is PVS enabled?

void EnablePVSOnly ()
 Use only PVS for culling. More...

void DisablePVSOnly ()
 Don't use only PVS for culling.

bool IsPVSOnly ()
 Is PVS only enabled?

void FreezePVS (const csVector3 &pos)
 Freeze the PVS for some position.

void UnfreezePVS ()
 Unfreeze the PVS.

bool IsPVSFrozen ()
 Is the PVS frozen?

const csVector3GetFrozenPosition () const
 Return the frozen position for the PVS.

virtual void SetLightingCacheMode (int mode)
 Set the mode for the lighting cache (combination of CS_ENGINE_CACHE_???). More...

virtual int GetLightingCacheMode ()
 Get the mode for the lighting cache.

virtual int GetLightmapCellSize () const
 Return current lightmap cell size.

virtual void SetLightmapCellSize (int Size)
 Set lightmap cell size.

void ReadConfig (iConfigFile *)
 Read configuration file (using the system driver) for all engine specific values. More...

void StartEngine ()
 Prepare for creation of a world. More...

csTextureListGetTextures () const
 Return the object managing all loaded textures.

csMaterialListGetMaterials () const
 Return the object managing all loaded materials.

virtual iMaterialCreateBaseMaterial (iTextureWrapper *txt)
 Create a base material.

virtual iMaterialCreateBaseMaterial (iTextureWrapper *txt, int num_layers, iTextureWrapper **wrappers, csTextureLayer *layers)
 Create a base material that can be used to give to the texture manager. More...

virtual iMaterialListGetMaterialList () const
 Get the list of all materials.

virtual iTextureListGetTextureList () const
 Get the list of all textures.

iMeshWrapperCreateSectorWallsMesh (csSector *sector, const char *name)
 Conveniance function to create the thing containing the convex outline of a sector. More...

virtual iMeshWrapperCreateSectorWallsMesh (iSector *sector, const char *name)
 Conveniance function to create the thing containing the convex outline of a sector. More...

void AddDynLight (csDynLight *dyn)
 Add a dynamic light to the engine.

void RemoveDynLight (csDynLight *dyn)
 Remove a dynamic light from the engine.

csDynLightGetFirstDynLight () const
 Return the first dynamic light in this engine.

int GetNearbyLights (csSector *sector, const csVector3 &pos, ULong flags, iLight **lights, int max_num_lights)
 This routine returns all lights which might affect an object at some position according to the following flags:
.
More...


csSectorItGetNearbySectors (csSector *sector, const csVector3 &pos, float radius)
 This routine returns an iterator to iterate over all nearby sectors. More...

csObjectItGetNearbyObjects (csSector *sector, const csVector3 &pos, float radius)
 This routine returns an iterator to iterate over all objects of a given type that are within a radius of a given position. More...

void AddHalo (csLight *Light)
 Add a halo attached to given light to the engine.

void RemoveHalo (csLight *Light)
 Remove halo attached to given light from the engine.

virtual void Draw (iCamera *c, iClipper2D *clipper)
 Draw the 3D world given a camera and a clipper. More...

virtual void DrawFunc (iCamera *c, iClipper2D *clipper, iDrawFuncCallback *callback)
 This function is similar to Draw. More...

csStatLightFindCsLight (float x, float y, float z, float dist) const
 Locate the first static light which is closer than 'dist' to the given position. More...

csStatLightFindCsLight (unsigned long id) const
 Find the light with the given light id.

csStatLightFindCsLight (const char *name, bool regionOnly=false) const
 Find the light with the given name.

csLightIt* NewLightIterator (iRegion *region=NULL)
 Create an iterator to iterate over all static lights of the engine.

void AddToCurrentRegion (csObject *obj)
 Add an object to the current region.

virtual void RegisterRenderPriority (const char *name, long priority)
 Register a new render priority.

virtual long GetRenderPriority (const char *name) const
 Get a render priority by name.

virtual long GetSkyRenderPriority () const
 Get the render priority for sky objects (attached to 'sky' name).

virtual long GetWallRenderPriority () const
 Get the render priority for wall objects (attached to 'wall' name).

virtual long GetObjectRenderPriority () const
 Get the render priority for general objects (attached to 'object' name).

virtual long GetAlphaRenderPriority () const
 Get the render priority for alpha objects (attached to 'alpha' name).

virtual void ClearRenderPriorities ()
 Clear all render priorities.

virtual iMeshObjectTypeGetThingType () const
 @ Temporary function until things are moved to a plugin. More...

virtual bool Initialize (iObjectRegistry *object_reg)
 Initialize the engine. More...

virtual bool HandleEvent (iEvent &Event)
 We need to handle some events.

virtual csEngine* GetCsEngine ()
 @@KLUDGE: This will no longer be needed once the iEngine interface is complete.

virtual int GetTextureFormat () const
 Query the format to load textures (usually this depends on texture manager).

virtual void SelectRegion (const char *iName)
 Create or select a new region (name can be NULL for the default main region). More...

virtual void SelectRegion (iRegion *region)
 Create or select a new region (region can be NULL for the default main region). More...

virtual iRegionGetCurrentRegion () const
 Get a reference to the current region (or NULL if the default main region is selected).

virtual iRegionFindRegion (const char *name) const
 find a region by name.

virtual void DeleteAll ()
 Clear the entire engine.

virtual iTextureWrapperCreateTexture (const char *iName, const char *iFileName, csColor *iTransp, int iFlags)
 Register a texture to be loaded during Prepare().

virtual iMaterialWrapperCreateMaterial (const char *iName, iTextureWrapper *texture)
 Register a material to be loaded during Prepare().

virtual iSectorCreateSector (const char *iName, bool link=true)
 Create a empty sector with given name.

virtual iSectorList* GetSectors ()
 Return the list of sectors.

virtual iMeshFactoryListGetMeshFactories ()
 Return the list of mesh factories.

virtual iMeshListGetMeshes ()
 Return the list of meshes.

virtual iCollectionList* GetCollections ()
 Return the list of collections.

virtual iCameraPositionList* GetCameraPositions ()
 Return the list of camera positions.

virtual iCameraCreateCamera ()
 Create a new camera.

virtual iStatLightCreateLight (const char *name, const csVector3 &pos, float radius, const csColor &color, bool pseudoDyn)
 Create a static/pseudo-dynamic light.

virtual iStatLightFindLight (const char *Name, bool RegionOnly=false) const
 Find a static/pseudo-dynamic light by name.

virtual iDynLightCreateDynLight (const csVector3 &pos, float radius, const csColor &color)
 Create a dynamic light.

virtual void RemoveDynLight (iDynLight *)
 Remove a dynamic light.

virtual iMeshFactoryWrapperCreateMeshFactory (const char *classId, const char *name)
 Create a mesh factory wrapper from a mesh plugin.

virtual iMeshFactoryWrapperCreateMeshFactory (iMeshObjectFactory *, const char *name)
 Create a mesh factory wrapper for an existing mesh factory.

virtual iMeshFactoryWrapperCreateMeshFactory (const char *name)
 Create an uninitialized mesh factory wrapper.

virtual iMeshFactoryWrapperLoadMeshFactory (const char *classId, const char *name, const char *loaderClassId, iDataBuffer *input)
 Load mesh factory.

virtual iMeshWrapperCreateMeshWrapper (iMeshFactoryWrapper *factory, const char *name, iSector *sector=NULL, const csVector3 &pos=csVector3(0, 0, 0))
 Create a mesh wrapper from a mesh factory wrapper.

virtual iMeshWrapperCreateMeshWrapper (iMeshObject *, const char *name, iSector *sector=NULL, const csVector3 &pos=csVector3(0, 0, 0))
 Create a mesh wrapper for an existing mesh object.

virtual iMeshWrapperCreateMeshWrapper (const char *name)
 Create an uninitialized mesh wrapper.

virtual iMeshWrapperLoadMeshWrapper (const char *classId, const char *name, const char *loaderClassId, iDataBuffer *input, iSector *sector, const csVector3 &pos)
 Load mesh object.

virtual iClipper2DGetTopLevelClipper () const
 Get the top-level clipper.

virtual void SetAmbientLight (const csColor &c)
 Set the amount of ambient light.

virtual void GetAmbientLight (csColor &c) const
 Return the amount of ambient light.

virtual void SetContext (iGraphics3D *g3d)
 Point engine to rendering context.

virtual iGraphics3DGetContext () const
 Return the current drawing context.


Public Attributes

iVFSVFS
 This is the Virtual File System object where all the files used by the engine live. More...

iReporterReporter
 Pointer to an optional reporter that will be used for notification and warning messages.

csObjVector cleanup
 This is a vector which holds objects of type 'csCleanable'. More...

csSectorList sectors
 List of sectors in the engine. More...

csCollectionList collections
 List of all collections in the engine. More...

csMeshFactoryList mesh_factories
 List of mesh object factories. More...

csEngineMeshList meshes
 List of all meshes in the engine. More...

csCameraPositionList camera_positions
 The list of all camera position objects.

csPoly2DPoolrender_pol2d_pool
 An object pool for 2D polygons used by the rendering process.

csLightPatchPoollightpatch_pool
 An object pool for lightpatches.

iGraphics3DG3D
 The 3D driver.

iGraphics2DG2D
 The 2D driver.

iImageIO* ImageLoader
 The graphics loader.

G3D_FOGMETHOD fogmethod
 The fog mode this G3D implements.

bool NeedPO2Maps
 Does the 3D driver require power-of-two lightmaps?

int MaxAspectRatio
 Maximum texture aspect ratio.

iRegionregion
 A pointer to the current region.

csNamedObjVector regions
 The list of all regions currently loaded.

csVector render_priorities
 The list of all named render priorities.

long render_priority_sky
 The engine knows about the following render priorities and keeps them here:. More...

long render_priority_wall
long render_priority_object
long render_priority_alpha
iCameracurrent_camera
 The current camera for drawing the world.

iClipper2Dtop_clipper
 The top-level clipper we are currently using for drawing.

csThingObjectTypething_type
 @ Temporary until things move to their own mesh plugin system. More...

 SCF_DECLARE_IBASE
csEngine::eiComponent  scfiComponent
csEngine::eiEventHandler  scfiEventHandler
csEngineConfig scfiConfig

Static Public Methods

void SetMaxProcessPolygons (int m)
 Set the maximum number of polygons to process in one frame. More...

int GetMaxProcessPolygons ()
 Get the maximum number of polygons to process in one frame.

bool ProcessPolygon ()
 Indicate that we will process another polygon. More...

bool ProcessLastPolygon ()
 Return true if we are processing the last polygon.


Static Public Attributes

int frame_width
 Remember dimensions of display.

int frame_height
 Remember dimensions of display.

iObjectRegistryobject_reg
 Remember iObjectRegistry.

iPluginManagerplugin_mgr
 Remember iPluginManager.

csEngine* current_engine
 The shared engine instance.

iEnginecurrent_iengine
 The shared engine instance.

bool use_new_radiosity
 Need to render using newradiosity?

int lightcache_mode
 Option variable: force lightmap recalculation?

int lightmap_quality
 Option variable: quality for lightmap calculation.

bool do_force_revis
 Option variable: force visibility recalculation?

bool do_rad_debug
 Option variable: radiosity debugging (step by step)?


Friends

class  csEngineState

Detailed Description

The 3D engine.

This class manages all components which comprise a 3D world including sectors, polygons, curves, mesh objects, etc.


Constructor & Destructor Documentation

csEngine::csEngine ( iBase * iParent )
 

Initialize an empty engine.

The only thing that is valid just after creating the engine is the configurator object which you can use to configure the engine before continuing (see GetEngineConfig()).

csEngine::~csEngine ( ) [virtual]
 

Delete the engine and all entities it contains.

All objects added to this engine by the user (like Things, Sectors, ...) will be deleted as well. If you don't want this then you should unlink them manually before destroying the engine.


Member Function Documentation

bool csEngine::CheckConsistency ( )
 

Check consistency of the loaded elements which comprise the world.

Currently this function only checks if polygons have three or more vertices and if the vertices are coplanar (if more than three). This function prints out warnings for all found errors. Returns true if everything is in order.

virtual iMaterial* csEngine::CreateBaseMaterial ( iTextureWrapper * txt,
int num_layers,
iTextureWrapper ** wrappers,
csTextureLayer * layers ) [virtual]
 

Create a base material that can be used to give to the texture manager.

This version also supports texture layers.

Reimplemented from iEngine.

iMeshWrapper * csEngine::CreateSectorWallsMesh ( iSector * sector,
const char * name ) [virtual]
 

Conveniance function to create the thing containing the convex outline of a sector.

The thing will be empty but it will have CS_ZBUF_FILL set. This version creates a mesh wrapper.

Reimplemented from iEngine.

iMeshWrapper * csEngine::CreateSectorWallsMesh ( csSector * sector,
const char * name )
 

Conveniance function to create the thing containing the convex outline of a sector.

The thing will be empty but it will have CS_ZBUF_FILL set. This version creates a mesh wrapper.

void csEngine::Draw ( iCamera * c,
iClipper2D * clipper ) [virtual]
 

Draw the 3D world given a camera and a clipper.

Note that in order to be able to draw using the given 3D driver all textures must have been registered to that driver (using Prepare()). Note that you need to call Prepare() again if you switch to another 3D driver.

Reimplemented from iEngine.

void csEngine::DrawFunc ( iCamera * c,
iClipper2D * clipper,
iDrawFuncCallback * callback ) [virtual]
 

This function is similar to Draw.

It will do all the stuff that Draw would do except for one important thing: it will not draw anything. Instead it will call a callback function for every entity that it was planning to draw. This allows you to show or draw debugging information (2D egdes for example).

Reimplemented from iEngine.

void csEngine::EnablePVSOnly ( ) [inline]
 

Use only PVS for culling.

This flag only makes sense when PVS is enabled.

csStatLight * csEngine::FindCsLight ( float x,
float y,
float z,
float dist ) const
 

Locate the first static light which is closer than 'dist' to the given position.

This function scans all sectors and locates the first one which statisfies that criterium.

int csEngine::GetBeginDrawFlags ( ) const [inline, virtual]
 

Get the required flags for 3D->BeginDraw() which should be called from the application.

These flags must be or-ed with optional other flags that the application might be interested in.

Reimplemented from iEngine.

int csEngine::GetEngineMode ( ) const [inline, virtual]
 

Get the current engine mode.

If called between SetEngineMode() and the first Draw() it is possible that this mode will still be CS_ENGINE_AUTODETECT.

Reimplemented from iEngine.

int csEngine::GetNearbyLights ( csSector * sector,
const csVector3 & pos,
ULong flags,
iLight ** lights,
int max_num_lights )
 

This routine returns all lights which might affect an object at some position according to the following flags:
.

  • CS_NLIGHT_SHADOWS: detect shadows and don't return lights for which the object is shadowed (not implemented yet).
  • CS_NLIGHT_STATIC: return static lights.
  • CS_NLIGHT_DYNAMIC: return dynamic lights.
  • CS_NLIGHT_NEARBYSECTORS: Also check lights in nearby sectors (not implemented yet).

It will only return as many lights as the size that you specified for the light array. The returned lights are not guaranteed to be sorted but they are guaranteed to be the specified number of lights closest to the given position.
This function returns the actual number of lights added to the 'lights' array.

csObjectIt * csEngine::GetNearbyObjects ( csSector * sector,
const csVector3 & pos,
float radius )
 

This routine returns an iterator to iterate over all objects of a given type that are within a radius of a given position.

You can use SCF_QUERY_INTERFACE to get any interface from the returned objects.

Delete the iterator with 'delete' when ready.

csSectorIt * csEngine::GetNearbySectors ( csSector * sector,
const csVector3 & pos,
float radius )
 

This routine returns an iterator to iterate over all nearby sectors.

Delete the iterator with 'delete' when ready.

iMeshObjectType * csEngine::GetThingType ( ) const [inline, virtual]
 

@ Temporary function until things are moved to a plugin.

@

Reimplemented from iEngine.

bool csEngine::Initialize ( iObjectRegistry * object_reg ) [virtual]
 

Initialize the engine.

This is automatically called by system driver at startup so that plugin can do basic initialization stuff, register with the system driver and so on.

void csEngine::InvalidateLightmaps ( )
 

Invalidate all lightmaps.

This can be called after doing a significant change on the static lightmaps (i.e. after doing a radiosity debug function).

bool csEngine::Prepare ( iProgressMeter * meter = NULL ) [virtual]
 

Prepare the engine.

This function must be called after you loaded/created the world. It will prepare all lightmaps for use and also free all images that were loaded for the texture manager (the texture manager should have them locally now). The optional progress meter will be used to report progress.

Reimplemented from iEngine.

void csEngine::PrepareMeshes ( )
 

Calls UpdateMove for all meshes to initialise bsp bounding boxes.

Call this after creating a BSP tree. csEngine::Prepare() will call this function automatically so you normally don't have to call it.

void csEngine::PrepareTextures ( )
 

Prepare the textures.

It will initialise all loaded textures for the texture manager. (Normally you shouldn't call this function directly, because it will be called by Prepare() for you. This function will also prepare all loaded materials after preparing the textures.

bool csEngine::ProcessPolygon ( ) [inline, static]
 

Indicate that we will process another polygon.

Returns false if we need to stop.

void csEngine::ReadConfig ( iConfigFile * )
 

Read configuration file (using the system driver) for all engine specific values.

This function is called by Initialize() so you normally do not need to call it yourselves.

void csEngine::SelectRegion ( iRegion * region ) [virtual]
 

Create or select a new region (region can be NULL for the default main region).

All new objects will be marked as belonging to this region.

Reimplemented from iEngine.

void csEngine::SelectRegion ( const char * iName ) [virtual]
 

Create or select a new region (name can be NULL for the default main region).

All new objects will be marked as belonging to this region.

Reimplemented from iEngine.

void csEngine::SetEngineMode ( int mode ) [inline, virtual]
 

Set the desired engine mode.

One of the CS_ENGINE_... flags. Default is CS_ENGINE_AUTODETECT. If you select CS_ENGINE_AUTODETECT then the mode will be auto-detected (depending on level and/or hardware capabilities) the first time csEngine::Draw() is called.

Reimplemented from iEngine.

void csEngine::SetLightingCacheMode ( int mode ) [inline, virtual]
 

Set the mode for the lighting cache (combination of CS_ENGINE_CACHE_???).

Default is CS_ENGINE_CACHE_READ.

Reimplemented from iEngine.

void csEngine::SetMaxProcessPolygons ( int m ) [inline, static]
 

Set the maximum number of polygons to process in one frame.

This is mainly useful for debugging.

void csEngine::ShineLights ( iRegion * region = NULL,
iProgressMeter * meter = NULL ) [virtual]
 

Calculate all lighting information.

Normally you shouldn't call this function directly, because it will be called by Prepare(). If the optional 'region' parameter is given then only lights will be recalculated for the given region.

Reimplemented from iEngine.

void csEngine::StartEngine ( )
 

Prepare for creation of a world.

This function is called by Initialize() so you normally do not need to call it yourselves.


Member Data Documentation

iVFS * csEngine::VFS
 

This is the Virtual File System object where all the files used by the engine live.

Textures, models, data, everything - reside on this virtual disk volume. You should avoid using the standard file functions (such as fopen(), fread() and so on) since they are highly system-dependent (for example, DOS uses '\' as path separator, Mac uses ':' and Unix uses '/').

csObjVector csEngine::cleanup
 

This is a vector which holds objects of type 'csCleanable'.

They will be destroyed when the engine is destroyed. That's the only special thing. This is useful for holding memory which you allocate locally in a function but you want to reuse accross function invocations. There is no general way to make sure that the memory will be freed it only exists as a static pointer in your function code. Adding a class encapsulating that memory to this array will ensure that the memory is removed once the engine is destroyed.

csCollectionList csEngine::collections
 

List of all collections in the engine.

This vector contains objects of type iCollection*.

csMeshFactoryList csEngine::mesh_factories
 

List of mesh object factories.

This vector contains objects of type csMeshFactoryWrapper*.

csEngineMeshList csEngine::meshes
 

List of all meshes in the engine.

This vector contains objects of type csMeshWrapper*. Use RemoveMesh() to remove meshes from this list. This function will take care of correctly removing the meshes from all sectors as well. Note that after you add a mesh to the list you still need to add it to all sectors that you want it to be visible in.

long csEngine::render_priority_sky
 

The engine knows about the following render priorities and keeps them here:.

  • "sky": usually rendered using ZFILL or ZNONE
  • "wall": usually rendered using ZFILL
  • "object": usually rendered using ZUSE
  • "alpha": usually rendered using ZTEST

csSectorList csEngine::sectors
 

List of sectors in the engine.

This vector contains objects of type iSector*. Use CreateSector() to add sectors to the engine.

csThingObjectType * csEngine::thing_type
 

@ Temporary until things move to their own mesh plugin system.

@


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000