formating code

This commit is contained in:
Pawel Kolodziejski 2008-07-30 07:04:32 +00:00
parent 7142787995
commit 2d81a8fe7a
18 changed files with 170 additions and 181 deletions

View File

@ -228,7 +228,7 @@ void DriverGL::drawShadowPlanes() {
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, (GLuint) ~0);
glStencilFunc(GL_ALWAYS, 1, (GLuint)~0);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE);
@ -243,7 +243,7 @@ void DriverGL::drawShadowPlanes() {
}
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glStencilFunc(GL_EQUAL, 1, (GLuint) ~0);
glStencilFunc(GL_EQUAL, 1, (GLuint)~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
}
@ -276,7 +276,7 @@ void DriverGL::drawModelFace(const Model::Face *face, float *vertices, float *ve
for (int i = 0; i < face->_numVertices; i++) {
glNormal3fv(vertNormals + 3 * face->_vertices[i]);
if (face->_texVertices != NULL)
if (face->_texVertices)
glTexCoord2fv(textureVerts + 2 * face->_texVertices[i]);
glVertex3fv(vertices + 3 * face->_vertices[i]);
@ -303,7 +303,7 @@ void DriverGL::translateViewpoint() {
void DriverGL::drawHierachyNode(const Model::HierNode *node) {
translateViewpoint(node->_animPos / node->_totalWeight, node->_animPitch / node->_totalWeight, node->_animYaw / node->_totalWeight, node->_animRoll / node->_totalWeight);
if (node->_hierVisible) {
if (node->_mesh != NULL && node->_meshVisible) {
if (node->_mesh && node->_meshVisible) {
glPushMatrix();
glTranslatef(node->_pivot.x(), node->_pivot.y(), node->_pivot.z());
node->_mesh->draw();
@ -311,14 +311,14 @@ void DriverGL::drawHierachyNode(const Model::HierNode *node) {
glPopMatrix();
}
if (node->_child != NULL) {
if (node->_child) {
node->_child->draw();
glMatrixMode(GL_MODELVIEW);
}
}
translateViewpoint();
if (node->_sibling != NULL)
if (node->_sibling)
node->_sibling->draw();
}
@ -739,7 +739,6 @@ void DriverGL::drawEmergString(int x, int y, const char *text, const Color &fgCo
glRasterPos2i(x, y);
glListBase(_emergFont);
//glCallLists(strlen(strrchr(text, '/')) - 1, GL_UNSIGNED_BYTE, strrchr(text, '/') + 1);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text);
glEnable(GL_LIGHTING);

View File

@ -388,8 +388,7 @@ bool DriverSDL::pollEvent(Event &event) {
event.kbd.flags = SDLModToDriverKeyFlags(SDL_GetModState());
// Alt-Return and Alt-Enter toggle full screen mode
if (b == KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN
|| ev.key.keysym.sym == SDLK_KP_ENTER)) {
if (b == KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_KP_ENTER)) {
toggleFullscreenMode();
break;
}

View File

@ -629,8 +629,7 @@ Driver::TextObjectHandle *DriverTinyGL::createTextBitmap(uint8 *data, int width,
} else if (pixel == 0x80) {
*texDataPtr = 0;
} else if (pixel == 0xFF) {
WRITE_LE_UINT16(texDataPtr, ((r & 0xF8) << 8) |
((g & 0xFC) << 3) | (b >> 3));
WRITE_LE_UINT16(texDataPtr, ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3));
}
}

View File

@ -157,7 +157,7 @@ public:
void init();
CMap *cmap() {
ModelComponent *mc = dynamic_cast<ModelComponent *>(_parent);
if (mc == NULL)
if (!mc)
return NULL;
return mc->cmap();
}
@ -185,7 +185,7 @@ void BitmapComponent::setKey(int val) {
const char *bitmap = _filename.c_str();
ObjectState *state = g_engine->currScene()->findState(bitmap);
if (state != NULL) {
if (state) {
state->setNumber(val);
return;
}
@ -219,16 +219,16 @@ ModelComponent::ModelComponent(Costume::Component *parent, int parentID, const c
// the use for this parameter is currently unknown
// Example: At the "scrimshaw parlor" in Rubacava the object
// "manny_cafe.3do,1" is requested
if (comma != NULL) {
if (comma) {
_filename = std::string(filename, comma);
warning("Comma in model components not supported: %s", filename);
} else {
_filename = filename;
}
if (prevComponent != NULL) {
if (prevComponent) {
MainModelComponent *mmc = dynamic_cast<MainModelComponent *>(prevComponent);
if (mmc != NULL)
if (mmc)
_previousCmap = mmc->cmap();
}
}
@ -237,7 +237,7 @@ void ModelComponent::init() {
// Skip loading if it was initialized
// by the sharing MainModelComponent
// constructor before
if (_obj == NULL) {
if (!_obj) {
CMap *cmap = this->cmap();
// Get the default colormap if we haven't found
@ -252,7 +252,7 @@ void ModelComponent::init() {
_hier = _obj->copyHierarchy();
// Use parent availablity to decide whether to default the
// component to being visible
if (_parent == NULL || !_parent->visible())
if (!_parent || !_parent->visible())
setKey(1);
else
setKey(0);
@ -260,10 +260,10 @@ void ModelComponent::init() {
// If we're the child of a mesh component, put our nodes in the
// parent object's tree.
if (_parent != NULL) {
if (_parent) {
MeshComponent *mc = dynamic_cast<MeshComponent *>(_parent);
if (mc != NULL)
if (mc)
mc->node()->addChild(_hier);
else if (debugLevel == DEBUG_MODEL || debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("Parent of model %s wasn't a mesh\n", _filename.c_str());
@ -297,22 +297,22 @@ void ModelComponent::resetColormap() {
CMap *cmap;
cmap = this->cmap();
if (_obj != NULL && cmap != NULL)
if (_obj && cmap)
_obj->reload(*cmap);
}
ModelComponent::~ModelComponent() {
if (_hier != NULL && _hier->_parent != NULL)
if (_hier && _hier->_parent)
_hier->_parent->removeChild(_hier);
delete[] _hier;
}
void translateObject(Model::HierNode *node, bool reset) {
if (node->_parent != NULL)
if (node->_parent)
translateObject(node->_parent, reset);
if(reset)
if (reset)
g_driver->translateViewpoint();
else
g_driver->translateViewpoint(node->_animPos / node->_totalWeight, node->_animPitch / node->_totalWeight, node->_animYaw / node->_totalWeight, node->_animRoll / node->_totalWeight);
@ -321,24 +321,24 @@ void translateObject(Model::HierNode *node, bool reset) {
void ModelComponent::draw() {
// If the object was drawn by being a component
// of it's parent then don't draw it
if (_parent != NULL && _parent->visible())
if (_parent && _parent->visible())
return;
// Need to translate object to be in accordance
// with the setup of the parent
if (_hier->_parent != NULL)
if (_hier->_parent)
translateObject(_hier->_parent, false);
_hier->draw();
// Need to un-translate when done
if (_hier->_parent != NULL)
if (_hier->_parent)
translateObject(_hier->_parent, true);
}
MainModelComponent::MainModelComponent(Costume::Component *parent, int parentID, const char *filename, Costume::Component *prevComponent, tag32 tag) :
ModelComponent(parent, parentID, filename, prevComponent, tag), _hierShared(false) {
if (parentID == -2 && prevComponent != NULL) {
if (parentID == -2 && prevComponent) {
MainModelComponent *mmc = dynamic_cast<MainModelComponent *>(prevComponent);
if (mmc != NULL && mmc->_filename == filename) {
if (mmc && mmc->_filename == filename) {
_obj = mmc->_obj;
_hier = mmc->_hier;
_hierShared = true;
@ -390,7 +390,7 @@ ColormapComponent::ColormapComponent(Costume::Component *parent, int parentID, c
Costume::Component(parent, parentID, tag) {
_cmap = g_resourceloader->loadColormap(filename);
if (parent != NULL)
if (parent)
parent->setColormap(_cmap);
else
warning("No parent to apply colormap object on.");
@ -420,7 +420,7 @@ private:
KeyframeComponent::KeyframeComponent(Costume::Component *parent, int parentID, const char *filename, tag32 tag) :
Costume::Component(parent, parentID, tag), _priority1(1), _priority2(5), _hier(NULL), _active(false) {
const char *comma = std::strchr(filename, ',');
if (comma != NULL) {
if (comma) {
std::string realName(filename, comma);
_keyf = g_resourceloader->loadKeyframe(realName.c_str());
std::sscanf(comma + 1, "%d,%d", &_priority1, &_priority2);
@ -488,7 +488,7 @@ void KeyframeComponent::update() {
void KeyframeComponent::init() {
ModelComponent *mc = dynamic_cast<ModelComponent *>(_parent);
if (mc != NULL)
if (mc)
_hier = mc->hierarchy();
else {
if (debugLevel == DEBUG_MODEL || debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
@ -506,7 +506,7 @@ MeshComponent::MeshComponent(Costume::Component *parent, int parentID, const cha
void MeshComponent::init() {
ModelComponent *mc = dynamic_cast<ModelComponent *>(_parent);
if (mc != NULL)
if (mc)
_node = mc->hierarchy() + _num;
else {
if (debugLevel == DEBUG_MODEL || debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
@ -539,7 +539,7 @@ MaterialComponent::MaterialComponent(Costume::Component *parent, int parentID, c
void MaterialComponent::init() {
CMap *cmap = this->cmap();
if (cmap == NULL) {
if (!cmap) {
// Use the default colormap if we're still drawing a blank
if (debugLevel == DEBUG_MODEL || debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("MaterialComponent::init on %s\n", _filename.c_str());
@ -597,7 +597,7 @@ private:
SoundComponent::SoundComponent(Costume::Component *parent, int parentID, const char *filename, tag32 tag) :
Costume::Component(parent, parentID, tag) {
const char *comma = std::strchr(filename, ',');
if (comma != NULL) {
if (comma) {
_soundName = std::string(filename, comma);
} else {
_soundName = filename;
@ -629,7 +629,7 @@ void SoundComponent::setKey(int val) {
void SoundComponent::reset() {
// A lot of the sound components this gets called against aren't actually running
if(g_imuse->getSoundStatus(_soundName.c_str()))
if (g_imuse->getSoundStatus(_soundName.c_str()))
g_imuse->stopSound(_soundName.c_str());
}
@ -668,7 +668,7 @@ Costume::Costume(const char *filename, const char *data, int len, Costume *prevC
// A Parent ID of "-1" indicates that the component should
// use the properties of the previous costume as a base
if (parentID == -1 && prevCost != NULL) {
if (parentID == -1 && prevCost) {
MainModelComponent *mmc;
// However, only the first item can actually share the
@ -679,7 +679,7 @@ Costume::Costume(const char *filename, const char *data, int len, Costume *prevC
prevComponent = prevCost->_components[0];
mmc = dynamic_cast<MainModelComponent *>(prevComponent);
// Make sure that the component is valid
if (mmc == NULL)
if (!mmc)
prevComponent = NULL;
}
// Actually load the appropriate component
@ -687,14 +687,14 @@ Costume::Costume(const char *filename, const char *data, int len, Costume *prevC
}
for (int i = 0; i < _numComponents; i++) {
if (_components[i] != NULL)
if (_components[i])
_components[i]->setCostume(this);
}
delete[] tags;
for (int i = 0; i < _numComponents; i++)
if (_components[i] != NULL)
if (_components[i])
_components[i]->init();
ts.expectString("section chores");
@ -723,7 +723,7 @@ Costume::~Costume() {
stopChores();
for (int i = _numComponents - 1; i >= 0; i--) {
// The "Sprite" component can be NULL
if (_components[i] != NULL)
if (_components[i])
delete _components[i];
}
delete[] _chores;
@ -743,24 +743,24 @@ Costume::Component::Component(Component *parent, int parentID, tag32 tag) {
void Costume::Component::setColormap(CMap *c) {
ModelComponent *mc = dynamic_cast<ModelComponent *>(this);
if (c != NULL)
if (c)
_cmap = c;
if (mc != NULL && this->cmap() != NULL)
if (mc && this->cmap())
mc->resetColormap();
}
bool Costume::Component::visible() {
if (_visible && _parent != NULL)
if (_visible && _parent)
return _parent->visible();
return _visible;
}
CMap *Costume::Component::cmap() {
if (_cmap == NULL && _previousCmap != NULL)
if (!_cmap && _previousCmap)
return _previousCmap;
else if (_cmap == NULL && _parent != NULL)
else if (!_cmap && _parent)
return _parent->cmap();
else if (_cmap == NULL && _parent == NULL && _cost != NULL)
else if (!_cmap && !_parent && _cost)
return _cost->_cmap;
else
return _cmap;
@ -770,9 +770,9 @@ void Costume::Component::setParent(Component *newParent) {
_parent = newParent;
_child = NULL;
_sibling = NULL;
if (_parent != NULL) {
if (_parent) {
Component **lastChildPos = &_parent->_child;
while (*lastChildPos != NULL)
while (*lastChildPos)
lastChildPos = &((*lastChildPos)->_sibling);
*lastChildPos = this;
}
@ -821,7 +821,7 @@ void Costume::Chore::stop() {
for (int i = 0; i < _numTracks; i++) {
Component *comp = _owner->_components[_tracks[i].compID];
if (comp != NULL)
if (comp)
comp->reset();
}
}
@ -829,7 +829,7 @@ void Costume::Chore::stop() {
void Costume::Chore::setKeys(int startTime, int stopTime) {
for (int i = 0; i < _numTracks; i++) {
Component *comp = _owner->_components[_tracks[i].compID];
if (comp == NULL)
if (!comp)
continue;
for (int j = 0; j < _tracks[i].numKeys; j++) {
@ -910,15 +910,15 @@ Costume::Component *Costume::loadComponent (tag32 tag, Costume::Component *paren
Model::HierNode *Costume::getModelNodes()
{
for(int i=0;i<_numComponents;i++) {
if (_components[i] == NULL)
continue;
// Needs to handle Main Models (pigeons) and normal Models
// (when Manny climbs the rope)
if (FROM_BE_32(_components[i]->tag()) == MKID_BE('MMDL'))
return dynamic_cast<ModelComponent *>(_components[i])->hierarchy();
}
return NULL;
for(int i = 0; i < _numComponents; i++) {
if (!_components[i])
continue;
// Needs to handle Main Models (pigeons) and normal Models
// (when Manny climbs the rope)
if (FROM_BE_32(_components[i]->tag()) == MKID_BE('MMDL'))
return dynamic_cast<ModelComponent *>(_components[i])->hierarchy();
}
return NULL;
}
void Costume::playChoreLooping(int num) {
@ -942,7 +942,8 @@ void Costume::playChore(int num) {
void Costume::setColormap(char *map) {
// Sometimes setColormap is called on a null costume,
// see where raoul is gone in hh.set
if (this == NULL || map == NULL)
// ??? this == null - aquadran
if (this == NULL || !map)
return;
_cmap = g_resourceloader->loadColormap(map);
for (int i = 0; i < _numComponents; i++)
@ -979,13 +980,13 @@ int Costume::isChoring(bool excludeLooping) {
void Costume::setupTextures() {
for (int i = 0; i < _numComponents; i++)
if (_components[i] != NULL)
if (_components[i])
_components[i]->setupTexture();
}
void Costume::draw() {
for (int i = 0; i < _numComponents; i++)
if (_components[i] != NULL)
if (_components[i])
_components[i]->draw();
}
@ -994,7 +995,7 @@ void Costume::update() {
_chores[i].update();
for (int i = 0; i < _numComponents; i++) {
if (_components[i] != NULL) {
if (_components[i]) {
_components[i]->setMatrix(_matrix);
_components[i]->update();
}

View File

@ -206,7 +206,7 @@ void Engine::handleDebugLoadResource() {
} else {
warning("Resource type not understood!");
}
if (resource == NULL)
if (!resource)
warning("Requested resouce (%s) not found!");
}
@ -287,7 +287,7 @@ void Engine::updateDisplayScene() {
}
drawPrimitives();
} else if (_mode == ENGINE_MODE_NORMAL) {
if (_currScene == NULL)
if (!_currScene)
return;
// Update actor costumes & sets
@ -483,7 +483,7 @@ void Engine::savegameRestore() {
printf("Engine::savegameRestore() started.\n");
_savegameLoadRequest = false;
char filename[200];
if (_savegameFileName == NULL) {
if (!_savegameFileName) {
strcpy(filename, "grim.sav");
} else {
strcpy(filename, _savegameFileName);
@ -549,7 +549,7 @@ void Engine::savegameSave() {
printf("Engine::savegameSave() started.\n");
_savegameSaveRequest = false;
char filename[200];
if (_savegameFileName == NULL) {
if (!_savegameFileName) {
strcpy(filename, "grim.sav");
} else {
strcpy(filename, _savegameFileName);
@ -632,7 +632,7 @@ Scene *Engine::findScene(const char *name) {
void Engine::setSceneLock(const char *name, bool lockStatus) {
Scene *scene = findScene(name);
if (scene == NULL) {
if (!scene) {
if (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("Scene object '%s' not found in list!", name);
return;
@ -646,18 +646,18 @@ void Engine::setScene(const char *name) {
Scene *lastScene = _currScene;
// If the scene already exists then use the existing data
if (scene != NULL) {
if (scene) {
setScene(scene);
return;
}
Block *b = g_resourceloader->getFileBlock(name);
if (b == NULL)
if (!b)
warning("Could not find scene file %s\n", name);
_currScene = new Scene(name, b->data(), b->len());
registerScene(_currScene);
_currScene->setSoundParameters(20, 127);
// should delete the old scene after creating the new one
if (lastScene != NULL && !lastScene->_locked) {
if (lastScene && !lastScene->_locked) {
removeScene(lastScene);
delete lastScene;
}
@ -670,7 +670,7 @@ void Engine::setScene(Scene *scene) {
_currScene = scene;
_currScene->setSoundParameters(20, 127);
// should delete the old scene after setting the new one
if (lastScene != NULL && !lastScene->_locked) {
if (lastScene && !lastScene->_locked) {
removeScene(lastScene);
delete lastScene;
}

View File

@ -150,7 +150,7 @@ void KeyframeAnim::animate(Model::HierNode *nodes, float time, int priority1, in
frame = _numFrames;
for (int i = 0; i < _numJoints; i++) {
if (_nodes[i] != NULL)
if (_nodes[i])
_nodes[i]->animate(nodes[i], frame, ((_type & nodes[i]._type) != 0 ? priority2 : priority1));
}
}
@ -253,5 +253,5 @@ void KeyframeAnim::KeyframeNode::animate(Model::HierNode &node, float frame, int
node._animRoll += roll;
}
// node
// node
}

View File

@ -126,7 +126,7 @@ Lab::FileMapType::const_iterator Lab::findFilename(const char *filename) const {
}
void Lab::close() {
if (_f != NULL)
if (_f)
std::fclose(_f);
_f = NULL;
_fileMap.clear();

View File

@ -47,10 +47,10 @@ Localizer::Localizer() {
std::string fname = (datadir != NULL ? datadir : ".");
fname += namesToTry[i];
f = std::fopen(fname.c_str(), "rb");
if (f != NULL)
if (f)
break;
}
if (f == NULL) {
if (!f) {
error("Localizer::Localizer: Unable to find localization information (grim.tab)!");
return;
}
@ -77,14 +77,14 @@ Localizer::Localizer() {
for (char *line = data + 4; line != NULL && *line != '\0'; line = nextline) {
nextline = std::strchr(line, '\n');
if (nextline != NULL) {
if (nextline) {
if (nextline[-1] == '\r')
nextline[-1] = '\0';
nextline++;
}
char *tab = std::strchr(line, '\t');
if (tab == NULL)
if (!tab)
continue;
std::string key(line, tab - line);
@ -102,7 +102,7 @@ std::string Localizer::localize(const char *str) const {
return str;
const char *slash2 = std::strchr(str + 1, '/');
if (slash2 == NULL)
if (!slash2)
return str;
std::string key(str + 1, slash2 - str - 1);

View File

@ -67,8 +67,8 @@ extern FilesystemNode *g_fsdir;
extern FSList *g_fslist;
extern FSList::const_iterator g_findfile;
#define strmatch(src, dst) (strlen(src) == strlen(dst) && strcmp(src, dst) == 0)
#define DEBUG_FUNCTION() debugFunction("Function", __FUNCTION__)
#define strmatch(src, dst) (strlen(src) == strlen(dst) && strcmp(src, dst) == 0)
#define DEBUG_FUNCTION() debugFunction("Function", __FUNCTION__)
static void debugFunction(const char *debugMessage, const char *funcName);
static void stubWarning(const char *funcName);
@ -201,7 +201,7 @@ static inline ObjectState::Position check_objstate_pos(int num) {
}
static inline bool getbool(int num) {
return ! lua_isnil(lua_getparam(num));
return !lua_isnil(lua_getparam(num));
}
static inline void pushbool(bool val) {
@ -215,11 +215,11 @@ static Costume *get_costume(Actor *a, int param, const char *called_from) {
Costume *result;
if (lua_isnil(lua_getparam(param))) {
result = a->currentCostume();
if (result == NULL && (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL))
if (!result && (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL))
warning("Actor %s has no costume [%s]\n", a->name(), called_from);
} else {
result = a->findCostume(luaL_check_string(param));
if (result == NULL && (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL))
if (!result && (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL))
warning("Actor %s has no costume %s [%s]\n", a->name(), lua_getstring(lua_getparam(param)), called_from);
}
return result;
@ -494,7 +494,7 @@ static void SetActorWalkChore() {
warning("SetActorWalkChore() could not find the requested costume, attempting to load...");
act->pushCostume(lua_getstring(lua_getparam(3)));
costume = get_costume(act, 3, "SetActorWalkChore");
if (costume == NULL) {
if (!costume) {
if (debugLevel == DEBUG_CHORES || debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL)
error("SetActorWalkChore() could not find the requested costume!");
return;
@ -826,7 +826,7 @@ static void GetActorNodeLocation() {
act = check_actor(1);
node = check_int(2);
c = act->currentCostume();
if (c == NULL) {
if (!c) {
lua_pushnil();
lua_pushnil();
lua_pushnil();
@ -835,7 +835,7 @@ static void GetActorNodeLocation() {
return;
}
allNodes = c->getModelNodes();
if (allNodes == NULL) {
if (!allNodes) {
lua_pushnil();
lua_pushnil();
lua_pushnil();
@ -935,7 +935,7 @@ static void GetActorCostume() {
DEBUG_FUNCTION();
act = check_actor(1);
c = act->currentCostume();
if (c == NULL) {
if (!c) {
lua_pushnil();
if (debugLevel == DEBUG_NORMAL || debugLevel == DEBUG_ALL)
printf("GetActorCostume() on '%s' when actor has no costume!\n", act->name());
@ -985,9 +985,9 @@ static void CompleteActorChore() {
// CompleteActorChore appears to be an alias for PlayActorChore
// Except that we should jump to the last frame of the chore
//
// Example: When Manny puts the message tube back in his office
// the animation automatically puts the tube back into place
// and then calls this function to show the closed graphic
// Example: When Manny puts the message tube back in his office
// the animation automatically puts the tube back into place
// and then calls this function to show the closed graphic
//
// Note: This does not appear to function entirely as it should
// TODO: Make this operation work better
@ -1246,7 +1246,7 @@ static void WalkActorVector() {
if (yaw >= 360.0f)
yaw -= 360.0f;
// set the new direction or walk forward
if (act->yaw() != yaw)
if (act->yaw() != yaw)
act->turnTo(0, yaw, 0);
else
act->walkForward();
@ -1504,9 +1504,9 @@ std::string parseMsgText(const char *msg, char *msgId) {
std::string translation = g_localizer->localize(msg);
const char *secondSlash = NULL;
if ((msg[0] == '/') && (msgId)) {
if (msg[0] == '/' && msgId) {
secondSlash = std::strchr(msg + 1, '/');
if (secondSlash != NULL) {
if (secondSlash) {
strncpy(msgId, msg + 1, secondSlash - msg - 1);
msgId[secondSlash - msg - 1] = 0;
} else {
@ -1692,7 +1692,7 @@ static void GetPointSector(void) {
} else {
result = NULL;
}
if (result == NULL) {
if (!result) {
if (debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL)
error("GetPointSector() passed an unhandled type or failed to find any matching sector!");
lua_pushnil();
@ -1713,7 +1713,7 @@ static void GetActorSector(void) {
act = check_actor(1);
sectorType = check_int(2);
Sector *result = g_engine->currScene()->findPointSector(act->pos(), sectorType);
if (result != NULL) {
if (result) {
lua_pushnumber(result->id());
lua_pushstring(const_cast<char *>(result->name()));
lua_pushnumber(result->type());
@ -2121,15 +2121,11 @@ static void PlaySoundAt() {
static void FileFindDispose() {
DEBUG_FUNCTION();
if (g_fslist) {
delete g_fslist;
g_fslist = NULL;
}
delete g_fslist;
g_fslist = NULL;
if (g_fsdir) {
delete g_fsdir;
g_fsdir = NULL;
}
delete g_fsdir;
g_fsdir = NULL;
}
static void luaFileFindNext() {
@ -2234,8 +2230,7 @@ void GetControlState() {
pushbool(g_driver->getControlState(num));
}
static void killBitmapPrimitives(Bitmap *bitmap)
{
static void killBitmapPrimitives(Bitmap *bitmap) {
for (Engine::PrimitiveListType::const_iterator i = g_engine->primitivesBegin(); i != g_engine->primitivesEnd(); i++) {
PrimitiveObject *p = *i;
if (p->isBitmap() && p->getBitmapHandle() == bitmap) {
@ -2365,7 +2360,7 @@ TextObject *TextObjectExists(char *name) {
*/
static void KillTextObject() {
TextObject *textObjectParm, *delText;
DEBUG_FUNCTION();
if (lua_isnil(lua_getparam(1))) {
if (debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL)
@ -2375,7 +2370,7 @@ static void KillTextObject() {
textObjectParm = check_textobject(1);
delText = TextObjectExists((char *) textObjectParm->name());
delText = TextObjectExists((char *) textObjectParm->name());
if (delText != NULL)
g_engine->killTextObject(delText);
}
@ -2443,11 +2438,11 @@ static void MakeTextObject() {
std::string text = line;
tableObj = lua_getparam(2);
textObject->setDefaults(&textObjectDefaults);
if (lua_istable(tableObj))
getTextObjectParams(textObject, tableObj);
while (TextObjectExists((char *)text.c_str()) != NULL)
while (TextObjectExists((char *)text.c_str()))
text += TEXT_NULL;
//printf("Make: %s\n", (char *)text.c_str());
@ -2455,7 +2450,7 @@ static void MakeTextObject() {
textObject->setText((char *)text.c_str());
textObject->createBitmap();
g_engine->registerTextObject(textObject);
lua_pushusertag(textObject, MKID_BE('TEXT'));
lua_pushnumber(textObject->getBitmapWidth());
lua_pushnumber(textObject->getBitmapHeight());
@ -2500,7 +2495,7 @@ static void BlastText() {
std::string text = line;
tableObj = lua_getparam(2);
textObject->setDefaults(&textObjectDefaults);
if (lua_istable(tableObj))
getTextObjectParams(textObject, tableObj);
@ -2523,15 +2518,15 @@ static void SetSpeechMode() {
DEBUG_FUNCTION();
mode = check_int(1);
if ((mode >= 1) && (mode <= 3))
g_engine->setSpeechMode(mode);
g_engine->setSpeechMode(mode);
}
static void GetSpeechMode() {
int mode;
DEBUG_FUNCTION();
mode = g_engine->getSpeechMode();
lua_pushnumber(mode);
lua_pushnumber(mode);
}
static void StartFullscreenMovie() {
@ -3000,7 +2995,7 @@ static void GetSaveGameData() {
lua_Object result;
const char *filename;
int dataSize;
printf("GetSaveGameData() started.\n");
DEBUG_FUNCTION();
filename = luaL_check_string(1);
@ -3071,7 +3066,7 @@ static void lua_remove() {
if (g_saveFileMan->removeSavefile(luaL_check_string(1)))
lua_pushuserdata(NULL);
else {
lua_pushnil();
lua_pushnil();
lua_pushstring(g_saveFileMan->getErrorDesc().c_str());
}
}
@ -3088,7 +3083,7 @@ static PointerId restoreCallback(int32 /*tag*/, PointerId ptr, RestoreSint32 /*s
static void LockFont() {
lua_Object param1;
DEBUG_FUNCTION();
param1 = lua_getparam(1);
if (lua_isstring(param1)) {
@ -3113,15 +3108,15 @@ static void LightMgrSetChange() {
static void SetAmbientLight() {
int mode;
DEBUG_FUNCTION();
mode = check_int(1);
if (mode == 0) {
if (g_engine->currScene() != NULL) {
if (g_engine->currScene()) {
g_engine->currScene()->setLightEnableState(true);
}
} else if (mode == 1) {
if (g_engine->currScene() != NULL) {
if (g_engine->currScene()) {
g_engine->currScene()->setLightEnableState(false);
}
} else {
@ -3211,7 +3206,7 @@ static void LoadBundle() {
static void debugFunction(const char *debugMessage, const char *funcName) {
bool stubFn = strcmp(debugMessage, "WARNING: Stub function") == 0;
FILE *output;
if (!stubFn && debugLevel != DEBUG_FUNC && debugLevel != DEBUG_ALL)
return;
@ -3842,7 +3837,7 @@ void register_lua() {
int bundle_dofile(const char *filename) {
Block *b = g_resourceloader->getFileBlock(filename);
if (b == NULL) {
if (!b) {
delete b;
// Don't print warnings on Scripts\foo.lua,
// d:\grimFandango\Scripts\foo.lua
@ -3902,7 +3897,7 @@ lua_Object getTableValue(lua_Object table, const char *name) {
// If getTableValue is called against a bad value
// that it doesn't understand then an infinite loop
// will be set up repeating the same error.
if(lua_call("next") != 0) {
if (lua_call("next") != 0) {
error("getTableValue could not find the next key!\n");
return 0;
}
@ -3922,7 +3917,7 @@ lua_Object getTableValue(lua_Object table, const char *name) {
if (strmatch(key_text, name))
return lua_getresult(2);
}
return 0;
}

View File

@ -51,7 +51,7 @@ static bool g_lua_initialized = false;
Driver *g_driver = NULL;
static bool parseBoolStr(const char *val) {
if (val == NULL || val[0] == 0)
if (!val || val[0] == 0)
return false;
switch (val[0]) {

View File

@ -41,7 +41,7 @@ Material::Material(const char *filename, const char *data, int len, const CMap &
_width = READ_LE_UINT32(data + 76 + _numImages * 40);
_height = READ_LE_UINT32(data + 80 + _numImages * 40);
if ((_width == 0) || (_height == 0)) {
if (_width == 0 || _height == 0) {
if (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("skip load texture: bad texture size (%dx%d) for texture %s\n", _width, _height, filename);
return;
@ -53,13 +53,13 @@ Material::Material(const char *filename, const char *data, int len, const CMap &
}
void Material::select() const {
if ((_width == 0) || (_height == 0))
return;
if (_width == 0 || _height == 0)
return;
g_driver->selectMaterial(this);
}
Material::~Material() {
if ((_width == 0) || (_height == 0))
return;
if (_width == 0 || _height == 0)
return;
g_driver->destroyMaterial(this);
}

View File

@ -36,7 +36,7 @@
#include <cstring>
Model::Model(const char *filename, const char *data, int len, const CMap &cmap) :
Resource(filename), _numMaterials(0), _numGeosets(0) {
Resource(filename), _numMaterials(0), _numGeosets(0) {
if (len >= 4 && std::memcmp(data, "LDOM", 4) == 0)
loadBinary(data, cmap);
@ -274,7 +274,7 @@ void Model::loadText(TextSplitter &ts, const CMap &cmap) {
for (int i = 0; i < _numMaterials; i++) {
char materialName[32];
int num;
ts.scanString("%d: %32s", 2, &num, materialName);
_materials[num] = g_resourceloader->loadMaterial(materialName, cmap);
strcpy(_materialNames[num], materialName);
@ -459,7 +459,7 @@ void Model::HierNode::draw() const {
void Model::HierNode::addChild(HierNode *child) {
HierNode **childPos = &_child;
while (*childPos != NULL)
while (*childPos)
childPos = &(*childPos)->_sibling;
*childPos = child;
child->_parent = this;
@ -467,9 +467,9 @@ void Model::HierNode::addChild(HierNode *child) {
void Model::HierNode::removeChild(HierNode *child) {
HierNode **childPos = &_child;
while (*childPos != NULL && *childPos != child)
while (*childPos && *childPos != child)
childPos = &(*childPos)->_sibling;
if (*childPos != NULL) {
if (*childPos) {
*childPos = child->_sibling;
child->_parent = NULL;
}
@ -492,11 +492,11 @@ void Model::HierNode::update() {
_pivotMatrix.translate(_pivot.x(), _pivot.y(), _pivot.z());
if (_mesh != NULL ) {
if (_mesh) {
_mesh->_matrix = _pivotMatrix;
}
if (_child != NULL) {
if (_child) {
_child->setMatrix(_matrix);
_child->update();
}

View File

@ -41,7 +41,7 @@ public:
OBJSTATE_UNDERLAY = 1,
OBJSTATE_OVERLAY = 2,
OBJSTATE_STATE = 3
// TODO: Find out what ObjectState 6 is supposed to be
// TODO: Find out what ObjectState 6 is supposed to be
// OBJSTATE_UNKNOWN = 6
};

View File

@ -67,10 +67,10 @@ ResourceLoader::ResourceLoader() {
DIR *d = opendir(dir_str.c_str());
#endif
if (directory == NULL)
if (!directory)
error("Cannot find DataDir registry entry - check configuration file");
if (d == NULL)
if (!d)
error("Cannot open DataDir (%s)- check configuration file", dir_str.c_str());
#ifdef _WIN32
@ -95,7 +95,7 @@ ResourceLoader::ResourceLoader() {
FindClose(d);
#else
dirent *de;
while ((de = readdir(d)) != NULL) {
while ((de = readdir(d))) {
int namelen = strlen(de->d_name);
if (namelen > 4 && ((strcasecmp(de->d_name + namelen - 4, ".lab") == 0) || (strcasecmp(de->d_name + namelen - 4, ".mus") == 0))) {
std::string fullname = dir_str + de->d_name;
@ -141,7 +141,7 @@ bool ResourceLoader::fileExists(const char *filename) const {
Block *ResourceLoader::getFileBlock(const char *filename) const {
const Lab *l = findFile(filename);
if (l == NULL)
if (!l)
return NULL;
else
return l->getFileBlock(filename);
@ -150,7 +150,7 @@ Block *ResourceLoader::getFileBlock(const char *filename) const {
Common::File *ResourceLoader::openNewStream(const char *filename) const {
const Lab *l = findFile(filename);
if (l == NULL)
if (!l)
return NULL;
else
return l->openNewStream(filename);
@ -173,7 +173,7 @@ Bitmap *ResourceLoader::loadBitmap(const char *filename) {
}
Block *b = getFileBlock(filename);
if (b == NULL) { // Grim sometimes asks for non-existant bitmaps (eg, ha_overhead)
if (!b) { // Grim sometimes asks for non-existant bitmaps (eg, ha_overhead)
if (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("Could not find bitmap %s\n", filename);
return NULL;
@ -195,7 +195,7 @@ CMap *ResourceLoader::loadColormap(const char *filename) {
}
Block *b = getFileBlock(filename);
if (b == NULL)
if (!b)
error("Could not find colormap %s\n", filename);
CMap *result = new CMap(filename, b->data(), b->len());
delete b;
@ -207,7 +207,7 @@ Costume *ResourceLoader::loadCostume(const char *filename, Costume *prevCost) {
std::string fname = filename;
makeLower(fname);
Block *b = getFileBlock(filename);
if (b == NULL)
if (!b)
error("Could not find costume %s\n", filename);
Costume *result = new Costume(filename, b->data(), b->len(), prevCost);
delete b;
@ -223,7 +223,7 @@ Font *ResourceLoader::loadFont(const char *filename) {
}
Block *b = getFileBlock(filename);
if (b == NULL)
if (!b)
error("Could not find font file %s\n", filename);
Font *result = new Font(filename, b->data(), b->len());
delete b;
@ -240,7 +240,7 @@ KeyframeAnim *ResourceLoader::loadKeyframe(const char *filename) {
}
Block *b = getFileBlock(filename);
if (b == NULL)
if (!b)
error("Could not find keyframe file %s\n", filename);
KeyframeAnim *result = new KeyframeAnim(filename, b->data(), b->len());
delete b;
@ -259,7 +259,7 @@ LipSynch *ResourceLoader::loadLipSynch(const char *filename) {
}
Block *b = getFileBlock(filename);
if (b == NULL) {
if (!b) {
if (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("Could not find lipsynch file %s\n", filename);
result = NULL;
@ -288,7 +288,7 @@ Material *ResourceLoader::loadMaterial(const char *filename, const CMap &c) {
}
Block *b = getFileBlock(filename);
if (b == NULL)
if (!b)
error("Could not find material %s\n", filename);
Material *result = new Material(fname.c_str(), b->data(), b->len(), c);
delete b;
@ -305,7 +305,7 @@ Model *ResourceLoader::loadModel(const char *filename, const CMap &c) {
}
Block *b = getFileBlock(filename);
if (b == NULL)
if (!b)
error("Could not find model %s\n", filename);
Model *result = new Model(filename, b->data(), b->len(), c);
delete b;
@ -317,7 +317,7 @@ bool ResourceLoader::exportResource(const char *filename) {
FILE *myFile = fopen(filename, "w");
Block *b = getFileBlock(filename);
if (b == NULL)
if (!b)
return false;
fwrite(b->data(), b->len(), 1, myFile);
fclose(myFile);

View File

@ -64,8 +64,8 @@ template <class T>
class ResPtr {
public:
ResPtr() { _ptr = NULL; }
ResPtr(const ResPtr &p) { _ptr = p._ptr; if (_ptr != NULL) _ptr->ref(); }
ResPtr(T* ptr) { _ptr = ptr; if (_ptr != NULL) _ptr->ref(); }
ResPtr(const ResPtr &p) { _ptr = p._ptr; if (_ptr) _ptr->ref(); }
ResPtr(T* ptr) { _ptr = ptr; if (_ptr) _ptr->ref(); }
operator T*() { return _ptr; }
operator const T*() const { return _ptr; }
T& operator *() { return *_ptr; }
@ -74,19 +74,19 @@ public:
const T* operator ->() const { return _ptr; }
ResPtr& operator =(T* ptr) {
if (_ptr == ptr) return *this;
if (_ptr != NULL) _ptr->deref();
if (_ptr) _ptr->deref();
_ptr = ptr;
if (_ptr != NULL) _ptr->ref();
if (_ptr) _ptr->ref();
return *this;
}
ResPtr& operator =(const ResPtr& p) {
if (this == &p || _ptr == p._ptr) return *this;
if (_ptr != NULL) _ptr->deref();
if (_ptr) _ptr->deref();
_ptr = p._ptr;
if (_ptr != NULL) _ptr->ref();
if (_ptr) _ptr->ref();
return *this;
}
~ResPtr() { if (_ptr != NULL) _ptr->deref(); }
~ResPtr() { if (_ptr) _ptr->deref(); }
private:
T* _ptr;
@ -119,8 +119,6 @@ private:
typedef std::list<Lab *> LabList;
LabList _labs;
// const Lab *findFile(const char *filename) const;
typedef std::map<std::string, Resource *> CacheType;
CacheType _cache;

View File

@ -128,7 +128,7 @@ void Scene::Setup::load(TextSplitter &ts) {
ts.scanString(" background %256s", 1, buf);
_bkgndBm = g_resourceloader->loadBitmap(buf);
if (_bkgndBm == NULL) {
if (!_bkgndBm) {
if (debugLevel == DEBUG_BITMAPS || debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL)
printf("Unable to load scene bitmap: %s\n", buf);
} else {
@ -257,10 +257,10 @@ void Scene::findClosestSector(Vector3d p, Sector **sect, Vector3d *closestPt) {
}
}
if (sect != NULL)
if (sect)
*sect = resultSect;
if (closestPt != NULL)
if (closestPt)
*closestPt = resultPt;
}

View File

@ -67,15 +67,15 @@ TextSplitter::TextSplitter(const char *data, int len) {
char *line, *tmpData;
int i;
tmpData = new char[len+1];
tmpData = new char[len + 1];
std::memcpy(tmpData, data, len);
tmpData[len] = '\0';
// Find out how many lines of text there are
_numLines = _lineIndex = 0;
line = (char *) tmpData;
while (line != NULL) {
while (line) {
line = std::strchr(line, '\n');
if (line != NULL) {
if (line) {
_numLines++;
line++;
}
@ -83,7 +83,7 @@ TextSplitter::TextSplitter(const char *data, int len) {
// Allocate an array of the lines
_lines = new TextLines[_numLines];
line = (char *) tmpData;
for (i=0;i<_numLines;i++) {
for (i = 0; i < _numLines;i++) {
char *lastLine = line;
line = std::strchr(lastLine, '\n');
@ -98,7 +98,7 @@ TextSplitter::TextSplitter(const char *data, int len) {
bool TextSplitter::checkString(const char *needle) {
// checkString also needs to check for extremely optional
// components like "object_art" which can be missing entirely
if (currentLine() == NULL)
if (!currentLine())
return false;
else if (std::strstr(currentLine(), needle))
return true;
@ -107,7 +107,7 @@ bool TextSplitter::checkString(const char *needle) {
}
void TextSplitter::expectString(const char *expected) {
if (_currLine == NULL)
if (!_currLine)
error("Expected `%s', got EOF\n", expected);
if (std::strcmp(currentLine(), expected) != 0)
error("Expected `%s', got `%s'\n", expected, currentLine());
@ -115,7 +115,7 @@ void TextSplitter::expectString(const char *expected) {
}
void TextSplitter::scanString(const char *fmt, int field_count, ...) {
if (_currLine == NULL)
if (!_currLine)
error("Expected line of format `%s', got EOF\n", fmt);
std::va_list va;
@ -141,7 +141,7 @@ void TextSplitter::processLine() {
// Cut off comments
char *comment_start = std::strchr(_currLine, '#');
if (comment_start != NULL)
if (comment_start)
*comment_start = '\0';
// Cut off trailing whitespace (including '\r')

View File

@ -174,8 +174,7 @@ Vector3d Sector::closestPoint(Vector3d point) const {
Vector3d edge = _vertices[i + 1] - _vertices[i];
Vector3d delta = point - _vertices[i];
float scalar = dot(delta, edge) / dot(edge, edge);
if (scalar >= 0 && scalar <= 1 &&
delta.x() * edge.y() > delta.y() * edge.x())
if (scalar >= 0 && scalar <= 1 && delta.x() * edge.y() > delta.y() * edge.x())
// That last test is just whether the z-component
// of delta cross edge is positive; we don't
// want to return opposite edges.
@ -196,7 +195,7 @@ Vector3d Sector::closestPoint(Vector3d point) const {
}
void Sector::getExitInfo(Vector3d start, Vector3d dir,
struct ExitInfo *result) {
struct ExitInfo *result) {
start = projectToPlane(start);
dir = projectToPuckVector(dir);
@ -226,6 +225,5 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
result->angleWithEdge = angle(dir, result->edgeDir);
Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0);
result->exitPoint = start + (dot(_vertices[i] - start, edgeNormal) /
dot(dir, edgeNormal)) * dir;
result->exitPoint = start + (dot(_vertices[i] - start, edgeNormal) / dot(dir, edgeNormal)) * dir;
}