Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AUtil.h File Reference


Detailed Description

Util Functions to be used privately by the engine.

Definition in file AUtil.h.

#include "AEngine.h"
#include "AState.h"
#include "ADevice.h"
#include "AConstants.h"

Include dependency graph for AUtil.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Defines

#define absf(f)   (f>=0? (f) : (-f))

Functions

TCHAR * util_stringToTChar (string s)
 converts STL string to TCHAR*. NOTE*** that this function stores the TCHAR data in static variable. The return value must be used immediately and not stored for later consumption. Also, don't use this in a multi-threaded program.

DWORD util_loadVertexShader (string filename, DWORD *dwDecl)
DWORD util_loadPixelShader (string filename)
CD3DFont * util_loadFont (string fontName, string filename, int size)
FLOAT clipAngle (FLOAT degree)
 perform wrap-around to make sure 0 <= degree < 360


Define Documentation

#define absf      (f>=0? (f) : (-f))
 

Definition at line 32 of file AUtil.h.

Referenced by BattleGroup::acquireGroupTargets(), bridgeFunc(), camera_addVibration(), MilitaryUnit::move(), BattleGroup::moveBattleGroup(), and BattleGroup::moveUnits().


Function Documentation

FLOAT clipAngle FLOAT    degree
 

perform wrap-around to make sure 0 <= degree < 360

Definition at line 148 of file AUtil.cpp.

Referenced by BattleGroup::acquireGroupTargets(), BattleBullet::BattleBullet(), BattleJets::flyTo(), MilitaryUnit::move(), BattleGroup::moveBattleGroup(), BattleGroup::moveUnits(), BattleJets::orderToBomb(), and BattleJets::orderToGuard().

00149 {
00150         if( degree < 0.0f )             return degree + 360.0f;
00151         if( degree >= 360.0f )  return degree - 360.0f;
00152         return degree;
00153 }

CD3DFont* util_loadFont string    fontName,
string    filename,
int    size
 

Definition at line 134 of file AUtil.cpp.

References util_stringToTChar().

Referenced by load_font(), and overlay_init().

00135 {
00136         if(filename!="")
00137                 if( 0==AddFontResource( filename.c_str() ) )
00138                         throw Error("Can't load Font File : " + filename );
00139         
00140         CD3DFont *font = new CD3DFont( util_stringToTChar(fontName), size );
00141         
00142         if( font==NULL )                  throw Error("Can't Create Font : " + fontName );      
00143         font->InitDeviceObjects(AS.pDevice);
00144         font->RestoreDeviceObjects();
00145         return font;
00146 }

DWORD util_loadPixelShader string    filename
 

Definition at line 84 of file AUtil.cpp.

References DWORD, and util_stringToTChar().

Referenced by flare_init(), mesh_init(), overlay_init(), sprite_init(), and terrain_create().

00085 {
00086         TCHAR *strPSPath = util_stringToTChar(filename);
00087         DWORD resultShader;
00088 
00089         char szBuffer[128];                     // debug output
00090         DWORD*  pdwPS;                          // pointer to address space of the calling process
00091         HANDLE hFile, hMap;                     // handle file and handle mapped file
00092     TCHAR tchTempVSPath[512];   // temporary file path
00093         HRESULT hr;                                     // error 
00094 
00095     if( FAILED( hr = DXUtil_FindMediaFile( tchTempVSPath, strPSPath ) ) )
00096                 throw Error("Media file not found : " + filename);
00097         
00098         hFile = CreateFile(tchTempVSPath, GENERIC_READ,0,0,OPEN_EXISTING,
00099                 FILE_ATTRIBUTE_NORMAL,0);
00100 
00101         if(hFile != INVALID_HANDLE_VALUE) 
00102         {
00103                 if(GetFileSize(hFile,0) > 0) 
00104                         hMap = CreateFileMapping(hFile,0,PAGE_READONLY,0,0,0);
00105                 else
00106                 {
00107                         CloseHandle(hFile);
00108                         throw Error("Error file size is <= 0");
00109                 }
00110         }       
00111         else
00112                 throw Error("Unable to create file.");
00113         
00114         // maps a view of a file into the address space of the calling process
00115         pdwPS = (DWORD *)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
00116                 
00117         // Create the pixel shader
00118         hr = AS.pDevice->CreatePixelShader(pdwPS, &resultShader);
00119         if ( FAILED(hr) )
00120         {
00121                 OutputDebugString( "Failed to create Pixel Shader, errors:\n" );
00122                 D3DXGetErrorStringA(hr,szBuffer,sizeof(szBuffer));
00123                 OutputDebugString( szBuffer );
00124                 OutputDebugString( "\n" );
00125                 throw Error("Error creating pixel shader : " + filename );
00126         }
00127         
00128         UnmapViewOfFile(pdwPS);
00129         CloseHandle(hMap);
00130         CloseHandle(hFile);
00131         return resultShader;
00132 }

DWORD util_loadVertexShader string    filename,
DWORD   dwDecl
 

Definition at line 34 of file AUtil.cpp.

References DWORD, and util_stringToTChar().

Referenced by flare_init(), mesh_init(), overlay_init(), sprite_init(), and terrain_create().

00035 {
00036         TCHAR *strVSPath = util_stringToTChar(filename);
00037         DWORD resultShader;
00038 
00039         char szBuffer[128];                     // debug output
00040         DWORD*  pdwVS;                          // pointer to address space of the calling process
00041         HANDLE hFile, hMap;                     // handle file and handle mapped file
00042     TCHAR tchTempVSPath[512];   // temporary file path
00043         HRESULT hr;                                     // error 
00044 
00045     if( FAILED( hr = DXUtil_FindMediaFile( tchTempVSPath, strVSPath ) ) )
00046                 throw Error("Media file not found : "+filename);
00047         
00048         hFile = CreateFile(tchTempVSPath, GENERIC_READ,0,0,OPEN_EXISTING,
00049                 FILE_ATTRIBUTE_NORMAL,0);
00050 
00051         if(hFile != INVALID_HANDLE_VALUE) 
00052         {
00053                 if(GetFileSize(hFile,0) > 0) 
00054                         hMap = CreateFileMapping(hFile,0,PAGE_READONLY,0,0,0);
00055                 else
00056                 {
00057                         CloseHandle(hFile);
00058                         throw Error("Error file size is <= 0");
00059                 }
00060         }       
00061         else
00062                 throw Error("Unable to create file.");
00063         
00064         // maps a view of a file into the address space of the calling process
00065         pdwVS = (DWORD *)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
00066                 
00067         // Create the pixel shader
00068         hr = AS.pDevice->CreateVertexShader( dwDecl, pdwVS, &resultShader, 0 ); 
00069         if ( FAILED(hr) )
00070         {
00071                 OutputDebugString( "Failed to create Vertex Shader, errors:\n" );
00072                 D3DXGetErrorStringA(hr,szBuffer,sizeof(szBuffer));
00073                 OutputDebugString( szBuffer );
00074                 OutputDebugString( "\n" );
00075                 throw Error("Error creating Vertex shader : "+filename);
00076         }
00077         
00078         UnmapViewOfFile(pdwVS);
00079         CloseHandle(hMap);
00080         CloseHandle(hFile);     
00081         return resultShader;
00082 }

TCHAR* util_stringToTChar string    s
 

converts STL string to TCHAR*. NOTE*** that this function stores the TCHAR data in static variable. The return value must be used immediately and not stored for later consumption. Also, don't use this in a multi-threaded program.

Definition at line 27 of file AUtil.cpp.

Referenced by overlay_render(), util_loadFont(), util_loadPixelShader(), and util_loadVertexShader().

00028 {
00029         static TCHAR t[512];
00030         lstrcpy( t, s.c_str() );
00031         return t;
00032 }


Generated on Wed Apr 23 05:50:43 2003 for Modern Warfare by doxygen1.3-rc2