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

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

View file

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

View file

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

View file

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

View file

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

View file

@ -150,7 +150,7 @@ void KeyframeAnim::animate(Model::HierNode *nodes, float time, int priority1, in
frame = _numFrames; frame = _numFrames;
for (int i = 0; i < _numJoints; i++) { 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)); _nodes[i]->animate(nodes[i], frame, ((_type & nodes[i]._type) != 0 ? priority2 : priority1));
} }
} }

View file

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

View file

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

View file

@ -215,11 +215,11 @@ static Costume *get_costume(Actor *a, int param, const char *called_from) {
Costume *result; Costume *result;
if (lua_isnil(lua_getparam(param))) { if (lua_isnil(lua_getparam(param))) {
result = a->currentCostume(); 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); warning("Actor %s has no costume [%s]\n", a->name(), called_from);
} else { } else {
result = a->findCostume(luaL_check_string(param)); 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); warning("Actor %s has no costume %s [%s]\n", a->name(), lua_getstring(lua_getparam(param)), called_from);
} }
return result; return result;
@ -494,7 +494,7 @@ static void SetActorWalkChore() {
warning("SetActorWalkChore() could not find the requested costume, attempting to load..."); warning("SetActorWalkChore() could not find the requested costume, attempting to load...");
act->pushCostume(lua_getstring(lua_getparam(3))); act->pushCostume(lua_getstring(lua_getparam(3)));
costume = get_costume(act, 3, "SetActorWalkChore"); costume = get_costume(act, 3, "SetActorWalkChore");
if (costume == NULL) { if (!costume) {
if (debugLevel == DEBUG_CHORES || debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL) if (debugLevel == DEBUG_CHORES || debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL)
error("SetActorWalkChore() could not find the requested costume!"); error("SetActorWalkChore() could not find the requested costume!");
return; return;
@ -826,7 +826,7 @@ static void GetActorNodeLocation() {
act = check_actor(1); act = check_actor(1);
node = check_int(2); node = check_int(2);
c = act->currentCostume(); c = act->currentCostume();
if (c == NULL) { if (!c) {
lua_pushnil(); lua_pushnil();
lua_pushnil(); lua_pushnil();
lua_pushnil(); lua_pushnil();
@ -835,7 +835,7 @@ static void GetActorNodeLocation() {
return; return;
} }
allNodes = c->getModelNodes(); allNodes = c->getModelNodes();
if (allNodes == NULL) { if (!allNodes) {
lua_pushnil(); lua_pushnil();
lua_pushnil(); lua_pushnil();
lua_pushnil(); lua_pushnil();
@ -935,7 +935,7 @@ static void GetActorCostume() {
DEBUG_FUNCTION(); DEBUG_FUNCTION();
act = check_actor(1); act = check_actor(1);
c = act->currentCostume(); c = act->currentCostume();
if (c == NULL) { if (!c) {
lua_pushnil(); lua_pushnil();
if (debugLevel == DEBUG_NORMAL || debugLevel == DEBUG_ALL) if (debugLevel == DEBUG_NORMAL || debugLevel == DEBUG_ALL)
printf("GetActorCostume() on '%s' when actor has no costume!\n", act->name()); printf("GetActorCostume() on '%s' when actor has no costume!\n", act->name());
@ -1504,9 +1504,9 @@ std::string parseMsgText(const char *msg, char *msgId) {
std::string translation = g_localizer->localize(msg); std::string translation = g_localizer->localize(msg);
const char *secondSlash = NULL; const char *secondSlash = NULL;
if ((msg[0] == '/') && (msgId)) { if (msg[0] == '/' && msgId) {
secondSlash = std::strchr(msg + 1, '/'); secondSlash = std::strchr(msg + 1, '/');
if (secondSlash != NULL) { if (secondSlash) {
strncpy(msgId, msg + 1, secondSlash - msg - 1); strncpy(msgId, msg + 1, secondSlash - msg - 1);
msgId[secondSlash - msg - 1] = 0; msgId[secondSlash - msg - 1] = 0;
} else { } else {
@ -1692,7 +1692,7 @@ static void GetPointSector(void) {
} else { } else {
result = NULL; result = NULL;
} }
if (result == NULL) { if (!result) {
if (debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL) if (debugLevel == DEBUG_ERROR || debugLevel == DEBUG_ALL)
error("GetPointSector() passed an unhandled type or failed to find any matching sector!"); error("GetPointSector() passed an unhandled type or failed to find any matching sector!");
lua_pushnil(); lua_pushnil();
@ -1713,7 +1713,7 @@ static void GetActorSector(void) {
act = check_actor(1); act = check_actor(1);
sectorType = check_int(2); sectorType = check_int(2);
Sector *result = g_engine->currScene()->findPointSector(act->pos(), sectorType); Sector *result = g_engine->currScene()->findPointSector(act->pos(), sectorType);
if (result != NULL) { if (result) {
lua_pushnumber(result->id()); lua_pushnumber(result->id());
lua_pushstring(const_cast<char *>(result->name())); lua_pushstring(const_cast<char *>(result->name()));
lua_pushnumber(result->type()); lua_pushnumber(result->type());
@ -2121,16 +2121,12 @@ static void PlaySoundAt() {
static void FileFindDispose() { static void FileFindDispose() {
DEBUG_FUNCTION(); DEBUG_FUNCTION();
if (g_fslist) {
delete g_fslist; delete g_fslist;
g_fslist = NULL; g_fslist = NULL;
}
if (g_fsdir) {
delete g_fsdir; delete g_fsdir;
g_fsdir = NULL; g_fsdir = NULL;
} }
}
static void luaFileFindNext() { static void luaFileFindNext() {
if (g_findfile != g_fslist->end()) { if (g_findfile != g_fslist->end()) {
@ -2234,8 +2230,7 @@ void GetControlState() {
pushbool(g_driver->getControlState(num)); 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++) { for (Engine::PrimitiveListType::const_iterator i = g_engine->primitivesBegin(); i != g_engine->primitivesEnd(); i++) {
PrimitiveObject *p = *i; PrimitiveObject *p = *i;
if (p->isBitmap() && p->getBitmapHandle() == bitmap) { if (p->isBitmap() && p->getBitmapHandle() == bitmap) {
@ -2447,7 +2442,7 @@ static void MakeTextObject() {
if (lua_istable(tableObj)) if (lua_istable(tableObj))
getTextObjectParams(textObject, tableObj); getTextObjectParams(textObject, tableObj);
while (TextObjectExists((char *)text.c_str()) != NULL) while (TextObjectExists((char *)text.c_str()))
text += TEXT_NULL; text += TEXT_NULL;
//printf("Make: %s\n", (char *)text.c_str()); //printf("Make: %s\n", (char *)text.c_str());
@ -3117,11 +3112,11 @@ static void SetAmbientLight() {
DEBUG_FUNCTION(); DEBUG_FUNCTION();
mode = check_int(1); mode = check_int(1);
if (mode == 0) { if (mode == 0) {
if (g_engine->currScene() != NULL) { if (g_engine->currScene()) {
g_engine->currScene()->setLightEnableState(true); g_engine->currScene()->setLightEnableState(true);
} }
} else if (mode == 1) { } else if (mode == 1) {
if (g_engine->currScene() != NULL) { if (g_engine->currScene()) {
g_engine->currScene()->setLightEnableState(false); g_engine->currScene()->setLightEnableState(false);
} }
} else { } else {
@ -3842,7 +3837,7 @@ void register_lua() {
int bundle_dofile(const char *filename) { int bundle_dofile(const char *filename) {
Block *b = g_resourceloader->getFileBlock(filename); Block *b = g_resourceloader->getFileBlock(filename);
if (b == NULL) { if (!b) {
delete b; delete b;
// Don't print warnings on Scripts\foo.lua, // Don't print warnings on Scripts\foo.lua,
// d:\grimFandango\Scripts\foo.lua // d:\grimFandango\Scripts\foo.lua

View file

@ -51,7 +51,7 @@ static bool g_lua_initialized = false;
Driver *g_driver = NULL; Driver *g_driver = NULL;
static bool parseBoolStr(const char *val) { static bool parseBoolStr(const char *val) {
if (val == NULL || val[0] == 0) if (!val || val[0] == 0)
return false; return false;
switch (val[0]) { 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); _width = READ_LE_UINT32(data + 76 + _numImages * 40);
_height = READ_LE_UINT32(data + 80 + _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) if (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("skip load texture: bad texture size (%dx%d) for texture %s\n", _width, _height, filename); warning("skip load texture: bad texture size (%dx%d) for texture %s\n", _width, _height, filename);
return; return;
@ -53,13 +53,13 @@ Material::Material(const char *filename, const char *data, int len, const CMap &
} }
void Material::select() const { void Material::select() const {
if ((_width == 0) || (_height == 0)) if (_width == 0 || _height == 0)
return; return;
g_driver->selectMaterial(this); g_driver->selectMaterial(this);
} }
Material::~Material() { Material::~Material() {
if ((_width == 0) || (_height == 0)) if (_width == 0 || _height == 0)
return; return;
g_driver->destroyMaterial(this); g_driver->destroyMaterial(this);
} }

View file

@ -459,7 +459,7 @@ void Model::HierNode::draw() const {
void Model::HierNode::addChild(HierNode *child) { void Model::HierNode::addChild(HierNode *child) {
HierNode **childPos = &_child; HierNode **childPos = &_child;
while (*childPos != NULL) while (*childPos)
childPos = &(*childPos)->_sibling; childPos = &(*childPos)->_sibling;
*childPos = child; *childPos = child;
child->_parent = this; child->_parent = this;
@ -467,9 +467,9 @@ void Model::HierNode::addChild(HierNode *child) {
void Model::HierNode::removeChild(HierNode *child) { void Model::HierNode::removeChild(HierNode *child) {
HierNode **childPos = &_child; HierNode **childPos = &_child;
while (*childPos != NULL && *childPos != child) while (*childPos && *childPos != child)
childPos = &(*childPos)->_sibling; childPos = &(*childPos)->_sibling;
if (*childPos != NULL) { if (*childPos) {
*childPos = child->_sibling; *childPos = child->_sibling;
child->_parent = NULL; child->_parent = NULL;
} }
@ -492,11 +492,11 @@ void Model::HierNode::update() {
_pivotMatrix.translate(_pivot.x(), _pivot.y(), _pivot.z()); _pivotMatrix.translate(_pivot.x(), _pivot.y(), _pivot.z());
if (_mesh != NULL ) { if (_mesh) {
_mesh->_matrix = _pivotMatrix; _mesh->_matrix = _pivotMatrix;
} }
if (_child != NULL) { if (_child) {
_child->setMatrix(_matrix); _child->setMatrix(_matrix);
_child->update(); _child->update();
} }

View file

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

View file

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

View file

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

View file

@ -73,9 +73,9 @@ TextSplitter::TextSplitter(const char *data, int len) {
// Find out how many lines of text there are // Find out how many lines of text there are
_numLines = _lineIndex = 0; _numLines = _lineIndex = 0;
line = (char *) tmpData; line = (char *) tmpData;
while (line != NULL) { while (line) {
line = std::strchr(line, '\n'); line = std::strchr(line, '\n');
if (line != NULL) { if (line) {
_numLines++; _numLines++;
line++; line++;
} }
@ -98,7 +98,7 @@ TextSplitter::TextSplitter(const char *data, int len) {
bool TextSplitter::checkString(const char *needle) { bool TextSplitter::checkString(const char *needle) {
// checkString also needs to check for extremely optional // checkString also needs to check for extremely optional
// components like "object_art" which can be missing entirely // components like "object_art" which can be missing entirely
if (currentLine() == NULL) if (!currentLine())
return false; return false;
else if (std::strstr(currentLine(), needle)) else if (std::strstr(currentLine(), needle))
return true; return true;
@ -107,7 +107,7 @@ bool TextSplitter::checkString(const char *needle) {
} }
void TextSplitter::expectString(const char *expected) { void TextSplitter::expectString(const char *expected) {
if (_currLine == NULL) if (!_currLine)
error("Expected `%s', got EOF\n", expected); error("Expected `%s', got EOF\n", expected);
if (std::strcmp(currentLine(), expected) != 0) if (std::strcmp(currentLine(), expected) != 0)
error("Expected `%s', got `%s'\n", expected, currentLine()); 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, ...) { void TextSplitter::scanString(const char *fmt, int field_count, ...) {
if (_currLine == NULL) if (!_currLine)
error("Expected line of format `%s', got EOF\n", fmt); error("Expected line of format `%s', got EOF\n", fmt);
std::va_list va; std::va_list va;
@ -141,7 +141,7 @@ void TextSplitter::processLine() {
// Cut off comments // Cut off comments
char *comment_start = std::strchr(_currLine, '#'); char *comment_start = std::strchr(_currLine, '#');
if (comment_start != NULL) if (comment_start)
*comment_start = '\0'; *comment_start = '\0';
// Cut off trailing whitespace (including '\r') // 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 edge = _vertices[i + 1] - _vertices[i];
Vector3d delta = point - _vertices[i]; Vector3d delta = point - _vertices[i];
float scalar = dot(delta, edge) / dot(edge, edge); float scalar = dot(delta, edge) / dot(edge, edge);
if (scalar >= 0 && scalar <= 1 && if (scalar >= 0 && scalar <= 1 && delta.x() * edge.y() > delta.y() * edge.x())
delta.x() * edge.y() > delta.y() * edge.x())
// That last test is just whether the z-component // That last test is just whether the z-component
// of delta cross edge is positive; we don't // of delta cross edge is positive; we don't
// want to return opposite edges. // want to return opposite edges.
@ -226,6 +225,5 @@ void Sector::getExitInfo(Vector3d start, Vector3d dir,
result->angleWithEdge = angle(dir, result->edgeDir); result->angleWithEdge = angle(dir, result->edgeDir);
Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0); Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0);
result->exitPoint = start + (dot(_vertices[i] - start, edgeNormal) / result->exitPoint = start + (dot(_vertices[i] - start, edgeNormal) / dot(dir, edgeNormal)) * dir;
dot(dir, edgeNormal)) * dir;
} }