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

AEngine.h

Go to the documentation of this file.
00001 /*
00002 CS Senior Project 2003
00003 Team : Leftfield
00004 Project : ModernWarfare
00005 Members :
00006 - Russ Christensen              <rchriste@cs.utah.edu>
00007 - Todd Smith                    <tcsmith@cs.utah.edu>
00008 - Usit Duongsaa                 <duongsaa@cs.utah.edu>
00009 Copyright 2003 Russ Christensen, Usit Duongsaa, and Todd Smith. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00012 
00013 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
00014 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
00015 THIS SOFTWARE IS PROVIDED BY RUSS CHRISTENSEN, USIT DUONGSAA, AND TODD SMITH ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RUSS, USIT, TODD OR OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00016 */
00017 
00018 
00031 #ifndef INCLUDE_AENGINE
00032 #define INCLUDE_AENGINE
00033 
00034 //------------------------------------------------------------------------------------
00035 
00036 #include "ExternalLibs.h"
00037 #include "ATypes.h"
00038 #include "AConstants.h"
00039 #include "AUtil.h"
00040 
00041 //For memory leak detection when in debug mode
00042 #ifdef _DEBUG
00043    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
00044 #else
00045    #define DEBUG_CLIENTBLOCK
00046 #endif // _DEBUG
00047 #include <stdlib.h>
00048 #include <crtdbg.h>
00049 #ifdef _DEBUG
00050 #define new DEBUG_CLIENTBLOCK
00051 #endif
00052 
00053 
00054 //------------------------------------------------------------------------------------
00055 // System-Level
00056 //------------------------------------------------------------------------------------
00061 void sys_init( HINSTANCE hInst, int width, int height, int colorDepth, bool fullScreen );
00062 
00064 // rate=2 means render once, skip twice, render once and skip two more and so on
00065 void sys_setSkipRate( int rate );
00066 
00068 void sys_setInitFunc(   AierraInitFunc   f );
00069 void sys_setUpdateFunc( AierraUpdateFunc f );
00070 void sys_setRenderFunc( AierraRenderFunc f );
00071 void sys_setShutdownFunc( AierraShutdownFunc f );
00072 
00074 void sys_go();
00075 
00077 void sys_terminate();
00078 
00080 void sys_showFPS(bool show=true);
00081 
00083 void sys_showConsole(bool show=true);
00084 
00087 void sys_enableConsoleLog(string filename="console.log");
00088 
00091 ostream& sys_console();
00092 
00095 void sys_fastForwardUpdate( int times );
00096 
00098 void sys_flushConsole();
00099 
00101 DWORD sys_getMilliSec();
00102 
00105 void  sys_setRandSeed(int seed);
00106 int   sys_randInt();                    // returns 0..32767
00107 FLOAT sys_randFloat();                  // returns -1.000 .. +1.000
00108 
00109 int   sys_localRandInt();               // this returns 0..255 from a LOCAL & INDEPENDENT src
00110                                                                 // has no side effect/dependency to sys_rand***
00111 FLOAT sys_localRandFloat();             // same as localRandInt, but returns float in -1..+1
00112 
00113 HWND sys_getWindowHandle();
00114 
00115 //------------------------------------------------------------------------------------
00116 // Input
00117 //------------------------------------------------------------------------------------
00125 bool input_isKeyDown    ( int key );
00126 bool input_isKeyPressed ( int key );
00127 bool input_isKeyReleased( int key );
00128 
00130         
00132 void input_resetVKeyMapping();
00133 
00134 // this maps the 'VKey' to 'key'
00135 // i.e. if the absolute key 'key' is pressed,  a call to isVKeyPressed(VKey) will return true
00136 void input_mapVKey( int key, int VKey );
00137 
00138 bool input_isVKeyDown      ( int VKey );
00139 bool input_isVKeyPressed ( int VKey );
00140 bool input_isVKeyReleased( int VKey );
00141 
00143 bool input_isMouseLBDown();
00144 bool input_isMouseMBDown();
00145 bool input_isMouseRBDown();
00146 bool input_isMouseLBClicked();
00147 bool input_isMouseMBClicked();
00148 bool input_isMouseRBClicked();
00149 bool input_isMouseLBDblClicked();
00150 bool input_isMouseMBDblClicked();
00151 bool input_isMouseRBDblClicked();
00152 
00153 // get the mouse cursor's x,y coordinate
00154 // coordinate system :  (0,0)=top-left (1,1)=bottom-right   (same for all 2D stuffs)
00155 // note : you need to draw the cursor yourself if you want to let the user sees it
00156 float input_getMouseX();
00157 float input_getMouseY();
00158 
00159 // range 0..1 (0 means the wheel was rotated all the way forward, and 1 means backward)
00160 float input_getMouseWheel();
00161 
00162 // returns how long (in seconds) has the mouse cursor been idle (not moving)
00163 float input_mouseIdleTime();
00164 
00165 //------------------------------------------------------------------------------------
00166 // Resource Control
00167 //------------------------------------------------------------------------------------
00168 AFont           load_font( string fontName, string filename="" );
00169 AMesh           load_mesh( string filename );
00170 ATexture        load_texture( string filename );
00171 ATerrain        load_terrain( string filename, FLOAT sizeX, FLOAT sizeY, FLOAT sizeZ, FLOAT offsetZ );
00172 
00173 //------------------------------------------------------------------------------------
00174 // Overlay
00175 //------------------------------------------------------------------------------------
00176 // a 2D overlay this is drawn on top of all the 3D renderings
00177 // coordinate system :  (0,0)=top-left (1,1)=bottom-right
00178 // use these functions to draw 2D shapes.  note that a lot of parameters come with default values
00179 // just make sure you specify where to draw!
00180 // Also, note that it doesn't make much sense to use BlendModes::KEY
00181 // *PRIORITY* should be between 0..9  with 9 being the front most
00182 void overlay_point( const Vec2D pt, const FLOAT size=1.0f, const Vec3D rgb=Colors::white,
00183                                     const int blendMode=BlendModes::NONE, const FLOAT alpha=1.0f, const int priority=0  );
00184 
00185 // lines can have patternss 0,1,2  0_______   1-------    2........
00186 void overlay_line(  const Vec2D pt1, const Vec2D pt2,   const Vec3D rgb=Colors::white, 
00187                                         const int blendMode=BlendModes::NONE, const FLOAT alpha=1.0f, const int priority=0,
00188                                         const int pattern=0 );
00189 void overlay_rect(  const Vec2D pt1, const Vec2D pt2, const bool fill=true, 
00190                                         const Vec3D rgb=Colors::white, const int blendMode=BlendModes::NONE, 
00191                                         const FLOAT alpha=1.0f, const int priority=0   );
00192 
00193 // these functions are for drawing text
00194 // just call overlay_text to get an output stream and dump stuffs into it
00195 // call textOut() to display all the stuffs that you put into the stream
00196 // note that calling textOut() will empty the stream
00197 // you can also manually disregard the stuffs inside the stream by calling clearText()
00198 ostream& overlay_text();
00199 void overlay_textOut( const Vec2D pos, const FLOAT scale=1.0f, const Vec3D rgb=Colors::white, const AFont font=NULL, const int priority=6 );
00200 void overlay_clearText();
00201 
00202 // used to draw image flatly on to the screen
00203 void overlay_image( const ATexture image, const Vec2D center, const Vec2D size, 
00204                                     const int blendMode=BlendModes::NONE, const FLOAT alpha=1.0f, const int priority=0 );
00205 
00206 //------------------------------------------------------------------------------------
00207 // Camera Control
00208 // move the camera to the specified 'pos' and look at 'target'
00209 // smoothness indicates whether you want the camera to go there instantly (0.0)
00210 // or slowly move to the specified position (0.9)
00211 // 0 <= smoothness < 1
00212 void camera_set( const Vec3D pos,  const Vec3D target, const FLOAT smoothness=0.0f );
00213 
00217 void camera_setScreenSize( FLOAT size );
00218 
00220 Vec3D camera_getPos();
00221 
00223 Vec3D camera_getVec();
00224 
00225 void camera_addVibration(float amount);
00226 
00227 //------------------------------------------------------------------------------------
00228 // 3D mesh
00229 // use these functions to render 3d objects (like tanks and missiles)
00230 // dir is a direction vector of three components { theta, phi, roll }
00231 //    theta is the heading ( 0=head north, 90=head east, etc )
00232 //    phi   is whether the mesh is pointing upward or downward ( 0=straight up, 90=horizontal, 180=straight down)
00233 //    roll  is whether the mesh 'head' is pointing up(0), 90degress CW(90), 90 degrees CCW(-90)
00234 // ***NOTE** currently, phi&roll are ignored.  only theta for now.
00235 void mesh_render( const AMesh mesh, const Vec3D pos, const Vec3D size, const Vec3D dir,
00236                                   const ATexture texture, const ATexture bumpmap=NULL,
00237                                   const Vec3D stripColor=Colors::red );
00238 //------------------------------------------------------------------------------------
00239 // render the specified terrain using 3 textures (low,high,normal)
00240 // 'low' is how the ground looks like at low altitude (maybe lush green grass)
00241 // 'high' is how it looks at high altitude (maybe dry rock)
00242 // 'normal' describes the roughness of the surface.  just use a regular dot3 normal map
00243 // note : you should only render one terrain each frame
00244 void terrain_render( ATerrain terrain, ATexture texLow, ATexture texHigh, ATexture texNormal );
00245 
00246 // get the height at a specific point of the terrain
00247 FLOAT terrain_getHeight( ATerrain terrain, FLOAT x, FLOAT y );
00248 //------------------------------------------------------------------------------------
00249 //------------------------------------------------------------------------------------
00250 // linearly-interpolated flare particles
00251 // to use : call lerp_begin, specify the texture and max# of particles in this frame
00252 // keep adding particles (final position will be along the line (pos1,pos2)
00253 // at 'dist' away from pos1
00254 // once all particles are added, call lerp_end()
00255 // should do begin-end only once per frame
00256 // multiplier ==> per-pixel color&alpha multiplier
00257 void flare_begin( ATexture texture, int maxParticles );
00258 void flare_addParticle( const Vec3D &pos1, const Vec3D &pos2, const Vec4D multiplier,
00259                                                 FLOAT dist, FLOAT size );
00260 void flare_end();
00261 //------------------------------------------------------------------------------------
00262 //------------------------------------------------------------------------------------
00263 // general-purpose point sprites
00264 // slightly slower than the specialized lerp-flare
00265 void sprite_add( ATexture tex, int blendMode, Vec3D pos, Vec4D multiplier, FLOAT size );
00266 
00267 //------------------------------------------------------------------------------------
00268 //------------------------------------------------------------------------------------
00269 // given a 2D point in screen coordinate (such as mouse cursor location), calculates
00270 // the 3D location in the world on a flat plane with height z.
00271 Vec3D math_translateScreenToWorldPlane( const Vec2D pt, FLOAT z );
00272 
00273 // translate a 3D point in world-space to 2D screen coordinates
00274 Vec2D math_translateWorldToScreen( const Vec3D pt );
00275 
00279 Vec3D math_translateObjectToWorld( const Vec3D objPos, const Vec3D objDir, const Vec3D objPt );
00280 
00281 // distance between two points
00282 FLOAT math_dist2D( const Vec2D &a, const Vec2D &b );
00283 FLOAT math_dist3D( const Vec3D &a, const Vec3D &b );
00284 FLOAT math_distPlanar3D( const Vec3D &a, const Vec3D &b );              // if nore the z coordinate
00285 
00286 // clip to 0..360 degrees
00287 FLOAT math_clipAngle( FLOAT angle );
00288 
00289 // the absolute direction from pt. 'from' to pt. 'to'
00290 FLOAT math_getDir( const Vec3D &from, const Vec3D &to );
00291 
00292 // how much we need to turn from current direction to new direction.  returnValue is between -180 .. +180
00293 FLOAT math_deltaDir( const FLOAT currentDir, const FLOAT newDir );
00294 
00295 //------------------------------------------------------------------------------------
00296 // For profiling how much time a section of code takes.
00297 // 
00298 #define PROFILER_FUNCTION(s) AProfilerBlock funcProfBlock(s);
00299 void profiler_begin(string s);
00300 void profiler_end(string s);
00301 
00302 //------------------------------------------------------------------------------------
00303 // Networking
00304 
00305 // server-only functions
00306 void net_runAsServer(string myIP, string myName, int maxNumPlayers);
00307 void net_acceptMorePlayers();
00308 void net_finalizeGame();                        // no more joining.  Assigns everyone a number.
00309 
00312 void net_runAsFakeServer(string myName, int maxNumPlayers);
00313 
00314 // client-only functions
00315 bool net_connectToServer(string ip, string myName);                     // returns true iff succeed
00316 
00317 // both-side functions
00318 string net_getSelfIP();
00319 bool net_amIServer();
00320 vector<string> net_getAllPlayers();             // get players' names
00321 void net_send( string msg );
00322 
00323 string net_getPlayerName();                             // get my own name
00324 
00325 int net_getPlayerNumber();                              // will be -1 if server didn't net_finalizeGame() yet
00326                                                                                 // otherwise, returns the number the server assigned for you
00327 
00328 int net_getPlayerNumUsingName(string playerName);
00329 string net_getPlayerNameUsingNum(int num);
00330 
00331 void net_disconnect();
00332 
00333 string net_recv();                                              // if no incoming message, returns empty string
00334 
00335 //------------------------------------------------------------------------------------
00336 
00337 #endif

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