From b2dccae86ed795b61f150c21eab8731f5380072f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 8 Oct 2018 23:57:47 +1100 Subject: [PATCH] remove some ugly == NULL --- src/Audio.c | 6 +++--- src/Core.h | 2 ++ src/D3D9Api.c | 6 +++--- src/Drawer2D.c | 2 +- src/Entity.c | 8 ++++---- src/Game.c | 6 +++--- src/Gui.c | 2 +- src/Model.c | 4 ++-- src/ModelCache.c | 2 +- src/OpenGLApi.c | 12 ++++++------ src/Options.c | 2 +- src/Screens.c | 2 +- src/TerrainAtlas.c | 2 +- src/Widgets.c | 6 +++--- 14 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/Audio.c b/src/Audio.c index c2c73c3d3..f92cfe30a 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -141,7 +141,7 @@ static void Soundboard_Init(struct Soundboard* board, const String* boardName, S name = String_UNSAFE_Substring(&name, 0, name.length - 1); struct SoundGroup* group = Soundboard_Find(board, &name); - if (group == NULL) { + if (!group) { if (board->Count == Array_Elems(board->Groups)) { Chat_AddRaw("&cCannot have more than 10 sound groups"); return; } @@ -173,7 +173,7 @@ struct Sound* Soundboard_PickRandom(struct Soundboard* board, uint8_t type) { String name = String_FromReadonly(Sound_Names[type]); struct SoundGroup* group = Soundboard_Find(board, &name); - if (group == NULL) return NULL; + if (!group) return NULL; int idx = Random_Range(&board->Rnd, 0, group->Count); return &group->Sounds[idx]; } @@ -229,7 +229,7 @@ static void Sounds_Play(uint8_t type, struct Soundboard* board) { if (type == SOUND_NONE || Game_SoundsVolume == 0) return; struct Sound* snd = Soundboard_PickRandom(board, type); - if (snd == NULL) return; + if (!snd) return; struct AudioFormat fmt = snd->Format; int volume = Game_SoundsVolume; diff --git a/src/Core.h b/src/Core.h index aca943dc9..d7e86aff3 100644 --- a/src/Core.h +++ b/src/Core.h @@ -69,7 +69,9 @@ typedef struct Bitmap_ { uint8_t* Scan0; int Width, Height; } Bitmap; #ifdef CC_BUILD_D3D9 typedef void* GfxResourceID; +#define GFX_NULL NULL #else typedef uint32_t GfxResourceID; +#define GFX_NULL 0 #endif #endif diff --git a/src/D3D9Api.c b/src/D3D9Api.c index bb3174928..11b6736db 100644 --- a/src/D3D9Api.c +++ b/src/D3D9Api.c @@ -47,10 +47,10 @@ static void D3D9_SetDefaultRenderStates(void); static void D3D9_RestoreRenderStates(void); static void D3D9_FreeResource(GfxResourceID* resource) { - if (resource == NULL || *resource == NULL) return; - IUnknown* unk = (IUnknown*)(*resource); + if (!resource || *resource == GFX_NULL) return; + IUnknown* unk = (IUnknown*)(*resource); ULONG refCount = unk->lpVtbl->Release(unk); - *resource = NULL; + *resource = GFX_NULL; if (refCount <= 0) return; uintptr_t addr = (uintptr_t)unk; diff --git a/src/Drawer2D.c b/src/Drawer2D.c index 405b3c2d7..10340d3a5 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -131,7 +131,7 @@ int Drawer2D_FontHeight(FontDesc* font, bool useShadow) { void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, int X, int Y) { Size2D size = Drawer2D_MeasureText(args); if (size.Width == 0 && size.Height == 0) { - struct Texture empty = { NULL, TEX_RECT(X,Y, 0,0), TEX_UV(0,0, 1,1) }; + struct Texture empty = { GFX_NULL, TEX_RECT(X,Y, 0,0), TEX_UV(0,0, 1,1) }; *tex = empty; return; } diff --git a/src/Entity.c b/src/Entity.c index bd6eb2076..3b5e8b8ca 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -480,7 +480,7 @@ static void Player_MakeNameTexture(struct Player* player) { Size2D size = Drawer2D_MeasureText(&args); if (size.Width == 0) { - player->NameTex.ID = NULL; + player->NameTex.ID = GFX_NULL; player->NameTex.X = PLAYER_NAME_EMPTY_TEX; } else { char buffer[STRING_SIZE]; @@ -589,7 +589,7 @@ static void Player_ApplySkin(struct Player* player, struct Player* from) { dst->vScale = src->vScale; /* Custom mob textures */ - dst->MobTextureId = NULL; + dst->MobTextureId = GFX_NULL; String skin = String_FromRawArray(dst->SkinNameRaw); if (Utils_IsUrlPrefix(&skin, 0)) { dst->MobTextureId = dst->TextureId; } } @@ -597,8 +597,8 @@ static void Player_ApplySkin(struct Player* player, struct Player* from) { void Player_ResetSkin(struct Player* player) { struct Entity* entity = &player->Base; entity->uScale = 1.0f; entity->vScale = 1.0f; - entity->MobTextureId = NULL; - entity->TextureId = NULL; + entity->MobTextureId = GFX_NULL; + entity->TextureId = GFX_NULL; entity->SkinType = SKIN_64x32; } diff --git a/src/Game.c b/src/Game.c index 21f7f49e0..bf03e43cf 100644 --- a/src/Game.c +++ b/src/Game.c @@ -215,7 +215,7 @@ bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String* bool success = !res && Game_ValidateBitmap(file, &bmp); if (success) { Gfx_DeleteTexture(texId); - if (skinType != NULL) { *skinType = Utils_GetSkinType(&bmp); } + if (skinType) { *skinType = Utils_GetSkinType(&bmp); } *texId = Gfx_CreateTexture(&bmp, true, false); } @@ -679,7 +679,7 @@ static void Game_RenderFrame(double delta) { Gui_SetActive(PauseScreen_MakeInstance()); } - bool allowZoom = Gui_Active == NULL && !Gui_HUD->HandlesAllInput; + bool allowZoom = !Gui_Active && !Gui_HUD->HandlesAllInput; if (allowZoom && KeyBind_IsPressed(KeyBind_ZoomScrolling)) { InputHandler_SetFOV(Game_ZoomFov, false); } @@ -693,7 +693,7 @@ static void Game_RenderFrame(double delta) { Game_CurrentCameraPos = Camera_Active->GetPosition(t); Game_UpdateViewMatrix(); - bool visible = Gui_Active == NULL || !Gui_Active->BlocksWorld; + bool visible = !Gui_Active || !Gui_Active->BlocksWorld; if (!World_Blocks) visible = false; if (visible) { Game_Render3D(delta, t); diff --git a/src/Gui.c b/src/Gui.c index a5c1013cd..c9a918a01 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -129,7 +129,7 @@ struct Screen* Gui_GetActiveScreen(void) { } struct Screen* Gui_GetUnderlyingScreen(void) { - return Gui_Active == NULL ? Gui_HUD : Gui_Active; + return Gui_Active ? Gui_Active : Gui_HUD; } void Gui_FreeActive(void) { diff --git a/src/Model.c b/src/Model.c index 01db37623..47f0c7183 100644 --- a/src/Model.c +++ b/src/Model.c @@ -141,7 +141,7 @@ void Model_UpdateVB(void) { void Model_ApplyTexture(struct Entity* entity) { struct Model* model = Model_ActiveModel; GfxResourceID tex = model->UsesHumanSkin ? entity->TextureId : entity->MobTextureId; - if (tex != NULL) { + if (tex) { Model_skinType = entity->SkinType; } else { struct CachedTexture* data = &ModelCache_Textures[model->defaultTexIndex]; @@ -150,7 +150,7 @@ void Model_ApplyTexture(struct Entity* entity) { } Gfx_BindTexture(tex); - bool _64x64 = Model_skinType != SKIN_64x32; + bool _64x64 = Model_skinType != SKIN_64x32; Model_uScale = entity->uScale * 0.015625f; Model_vScale = entity->vScale * (_64x64 ? 0.015625f : 0.03125f); } diff --git a/src/ModelCache.c b/src/ModelCache.c index 1b62c77fd..98975780a 100644 --- a/src/ModelCache.c +++ b/src/ModelCache.c @@ -88,7 +88,7 @@ void ModelCache_RegisterTexture(STRING_REF const char* texName) { if (ModelCache_texCount < MODELCACHE_MAX_MODELS) { struct CachedTexture tex; tex.Name = String_FromReadonly(texName); - tex.TexID = NULL; + tex.TexID = GFX_NULL; ModelCache_Textures[ModelCache_texCount++] = tex; } else { ErrorHandler_Fail("ModelCache_RegisterTexture - hit max textures"); diff --git a/src/OpenGLApi.c b/src/OpenGLApi.c index da086a6fd..4dadc4492 100644 --- a/src/OpenGLApi.c +++ b/src/OpenGLApi.c @@ -178,9 +178,9 @@ void Gfx_BindTexture(GfxResourceID texId) { } void Gfx_DeleteTexture(GfxResourceID* texId) { - if (texId == NULL || *texId == NULL) return; + if (!texId || *texId == GFX_NULL) return; glDeleteTextures(1, texId); - *texId = NULL; + *texId = GFX_NULL; } void Gfx_SetTexturing(bool enabled) { gl_Toggle(GL_TEXTURE_2D); } @@ -342,20 +342,20 @@ void Gfx_BindIb(GfxResourceID ib) { } void Gfx_DeleteVb(GfxResourceID* vb) { - if (vb == NULL || *vb == NULL) return; + if (!vb || *vb == GFX_NULL) return; #ifndef CC_BUILD_GL11 glDeleteBuffers(1, vb); #else if (*vb != gl_DYNAMICLISTID) glDeleteLists(*vb, 1); #endif - *vb = NULL; + *vb = GFX_NULL; } void Gfx_DeleteIb(GfxResourceID* ib) { #ifndef CC_BUILD_GL11 - if (ib == NULL || *ib == NULL) return; + if (!ib || *ib == GFX_NULL) return; glDeleteBuffers(1, ib); - *ib = NULL; + *ib = GFX_NULL; #else return; #endif diff --git a/src/Options.c b/src/Options.c index 05489efaa..51a98f806 100644 --- a/src/Options.c +++ b/src/Options.c @@ -142,7 +142,7 @@ void Options_Set(const char* keyRaw, const String* value) { void Options_SetString(const String* key, const String* value) { int i; - if (value == NULL || value->buffer == NULL) { + if (!value || !value->length) { i = Options_Find(key); if (i >= 0) Options_Remove(i); } else { diff --git a/src/Screens.c b/src/Screens.c index 631b707e9..627f5185d 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -522,7 +522,7 @@ static void LoadingScreen_DrawBackground(void) { TextureRec rec = Atlas1D_TexRec(texLoc, 1, &atlasIndex); float u2 = (float)Game_Width / (float)LOADING_TILE_SIZE; - struct Texture tex = { NULL, TEX_RECT(0,0, Game_Width,LOADING_TILE_SIZE), TEX_UV(0,rec.V1, u2,rec.V2) }; + struct Texture tex = { GFX_NULL, TEX_RECT(0,0, Game_Width,LOADING_TILE_SIZE), TEX_UV(0,rec.V1, u2,rec.V2) }; bool bound = false; while (y < Game_Height) { diff --git a/src/TerrainAtlas.c b/src/TerrainAtlas.c index d87cb17b6..0e24ac61e 100644 --- a/src/TerrainAtlas.c +++ b/src/TerrainAtlas.c @@ -17,7 +17,7 @@ void Atlas2D_UpdateState(Bitmap* bmp) { static GfxResourceID Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, Bitmap* element) { int size = Atlas2D_TileSize; int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc); - if (y >= Atlas2D_RowsCount) return NULL; + if (y >= Atlas2D_RowsCount) return GFX_NULL; Bitmap_CopyBlock(x * size, y * size, 0, 0, &Atlas2D_Bitmap, element, size); return Gfx_CreateTexture(element, false, Gfx_Mipmaps); diff --git a/src/Widgets.c b/src/Widgets.c index f954d0a38..c6f6ebce9 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -95,9 +95,9 @@ void TextWidget_Set(struct TextWidget* w, const String* text, FontDesc* font) { #define BUTTON_uWIDTH (200.0f / 256.0f) #define BUTTON_MIN_WIDTH 40 -struct Texture Button_ShadowTex = { NULL, TEX_RECT(0,0, 0,0), WIDGET_UV(0,66, 200,86) }; -struct Texture Button_SelectedTex = { NULL, TEX_RECT(0,0, 0,0), WIDGET_UV(0,86, 200,106) }; -struct Texture Button_DisabledTex = { NULL, TEX_RECT(0,0, 0,0), WIDGET_UV(0,46, 200,66) }; +struct Texture Button_ShadowTex = { GFX_NULL, TEX_RECT(0,0, 0,0), WIDGET_UV(0,66, 200,86) }; +struct Texture Button_SelectedTex = { GFX_NULL, TEX_RECT(0,0, 0,0), WIDGET_UV(0,86, 200,106) }; +struct Texture Button_DisabledTex = { GFX_NULL, TEX_RECT(0,0, 0,0), WIDGET_UV(0,46, 200,66) }; static void ButtonWidget_Free(void* widget) { struct ButtonWidget* w = widget;