Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

util.cpp File Reference

#include <vector>
#include <fstream>
#include <string>
#include <SDL/SDL.h>
#include "graphics.h"
#include "sprite.h"
#include "util.h"

Go to the source code of this file.

Functions

nnctime Util_GetTime ()
 Gets the current time.

nnctime Util_DiffTime (nnctime *old, nnctime *now)
 Does a difference between an old time and a new time.

nnctime operator- (nnctime &a, nnctime &b)
 difference operator between ncctimes

int Util_TimePassed (nnctime *old, Uint32 ms)
 Use to find how many times over a time has elapsed.

Rect Util_BuildRect (int x, int y, int w, int h)
 Quick method to build a rect.

Velocity Util_BuildVelocity (double dx, double dy, nnctime *old, nnctime *now)
 Function build a velocity based on time samples.

int Util_Random (int max)
 Return a random number.

bool Util_Intersect (Rect &R1, Rect &R2)
 Determine if two rectangles intersect.

vector< Surface * > Util_parseImage (string filename)
 Load surfaces from a file description.

int Util_FindBestSurfaceSize (int w, int h)
 Finds a good size for a texture.


Function Documentation

nnctime operator- nnctime   a,
nnctime   b
 

difference operator between ncctimes

deduces the difference between time a and b.

Returns:
the difference in time between a and b.

Definition at line 42 of file util.cpp.

References nnctime::msecs, and nnctime::secs.

Rect Util_BuildRect int   ,
int   ,
int   ,
int   
 

Quick method to build a rect.

Returns:
a rect with the four parameters of the call.

Definition at line 75 of file util.cpp.

References Rect.

Referenced by Graphics::blitclip(), Background::Draw(), GameObject::GetBoundingRect(), and ExplodeObject::think().

Velocity Util_BuildVelocity double    dx,
double    dy,
nnctime   old,
nnctime   now = NULL
 

Function build a velocity based on time samples.

Todo:
finish Util_BuildVelocity
Parameters:
dx change in x
dy change in y
old before dx,dy occured
now after dx,dy occured
Returns:
velocity structure describing the change in distance

Definition at line 85 of file util.cpp.

References Velocity::dx, Velocity::dy, nnctime::msecs, Velocity::pertime, nnctime::secs, and Util_DiffTime().

nnctime Util_DiffTime nnctime   old,
nnctime   now = NULL
 

Does a difference between an old time and a new time.

Parameters:
old nnctime of earlier event
now nnctime of later event or NULL for "now"
Returns:
a nnctime structure as the difference in time between old and now.

Definition at line 20 of file util.cpp.

References nnctime::msecs, nnctime::secs, and Util_GetTime().

Referenced by Application::Run(), Crosshair::think(), Util_BuildVelocity(), and Util_TimePassed().

int Util_FindBestSurfaceSize int    w,
int    h
 

Finds a good size for a texture.

Returns an integer in the power of 2 that will cover the width and height provided

Definition at line 169 of file util.cpp.

Referenced by Graphics::TexturizeSurface().

nnctime Util_GetTime  
 

Gets the current time.

This function uses SDL_GetTicks to determine the current clock.

Returns:
a nnctime struct of the current time

Definition at line 9 of file util.cpp.

References nnctime::msecs, and nnctime::secs.

Referenced by Bear::Bear(), BearSpawnPoint::BearSpawnPoint(), Sprite::EnableAnimation(), ExplodeObject::ExplodeObject(), MainChar::FireWeapon(), Application::Run(), MainChar::setWalking(), UFO::think(), Crosshair::think(), UFO::UFO(), Util_DiffTime(), Util_Random(), and Util_TimePassed().

bool Util_Intersect Rect   R1,
Rect   R2
 

Determine if two rectangles intersect.

  • Rectangles that share an edge don't intersect; only when the two rectangles share some area do they intersect.
    Parameters:
    R1 rectangle 1
    R2 rectangle 2
    Returns:
    true if R1 and R2 intersect.

Definition at line 110 of file util.cpp.

References Rect.

Referenced by ObjectManager::FindFirstCollision().

vector<Surface *> Util_parseImage string    filename
 

Load surfaces from a file description.

This function will read in from a file and create a vector of surfaces to pass to a sprite (or other) class for future use.

Todo:
instead of Surfaces, return a vector of structures that describe not only the sprite frame, but it's bounding box and central location, etc.
Parameters:
filename the name of the file to open and read from.
Returns:
a vector of Surface pointers. The vector is empty if the file cannot be opened.

Definition at line 145 of file util.cpp.

References Sprite::cache, and SpriteCache::Find().

Referenced by Bear::Bear(), Crosshair::Crosshair(), MainChar::MainChar(), and UFO::UFO().

int Util_Random int    max
 

Return a random number.

Parameters:
max the high end of the random number
Returns:
an integer between [0, max)

Definition at line 96 of file util.cpp.

References nnctime::secs, and Util_GetTime().

Referenced by MainChar::FireWeapon(), BearSpawnPoint::think(), UFO::think(), and UFO::UFO().

int Util_TimePassed nnctime   old,
Uint32    ms
 

Use to find how many times over a time has elapsed.

Parameters:
old the last update time
ms the time in milliseconds
Returns:
a number defining how many times ms has elapsed since old. If greater than 0, old is set to Util_GetTime().

Definition at line 56 of file util.cpp.

References nnctime::msecs, nnctime::secs, Util_DiffTime(), and Util_GetTime().

Referenced by Sprite::animate(), Bear::think(), BearSpawnPoint::think(), Crosshair::think(), ExplodeObject::think(), MainChar::think(), and UFO::think().


Generated on Sun Dec 8 12:02:20 2002 for nnc by doxygen1.3-rc1