remove some ugly == NULL

This commit is contained in:
UnknownShadow200 2018-10-08 23:57:47 +11:00
parent 911e77b725
commit b2dccae86e
14 changed files with 32 additions and 30 deletions

View File

@ -141,7 +141,7 @@ static void Soundboard_Init(struct Soundboard* board, const String* boardName, S
name = String_UNSAFE_Substring(&name, 0, name.length - 1); name = String_UNSAFE_Substring(&name, 0, name.length - 1);
struct SoundGroup* group = Soundboard_Find(board, &name); struct SoundGroup* group = Soundboard_Find(board, &name);
if (group == NULL) { if (!group) {
if (board->Count == Array_Elems(board->Groups)) { if (board->Count == Array_Elems(board->Groups)) {
Chat_AddRaw("&cCannot have more than 10 sound groups"); return; 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]); String name = String_FromReadonly(Sound_Names[type]);
struct SoundGroup* group = Soundboard_Find(board, &name); 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); int idx = Random_Range(&board->Rnd, 0, group->Count);
return &group->Sounds[idx]; 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; if (type == SOUND_NONE || Game_SoundsVolume == 0) return;
struct Sound* snd = Soundboard_PickRandom(board, type); struct Sound* snd = Soundboard_PickRandom(board, type);
if (snd == NULL) return; if (!snd) return;
struct AudioFormat fmt = snd->Format; struct AudioFormat fmt = snd->Format;
int volume = Game_SoundsVolume; int volume = Game_SoundsVolume;

View File

@ -69,7 +69,9 @@ typedef struct Bitmap_ { uint8_t* Scan0; int Width, Height; } Bitmap;
#ifdef CC_BUILD_D3D9 #ifdef CC_BUILD_D3D9
typedef void* GfxResourceID; typedef void* GfxResourceID;
#define GFX_NULL NULL
#else #else
typedef uint32_t GfxResourceID; typedef uint32_t GfxResourceID;
#define GFX_NULL 0
#endif #endif
#endif #endif

View File

@ -47,10 +47,10 @@ static void D3D9_SetDefaultRenderStates(void);
static void D3D9_RestoreRenderStates(void); static void D3D9_RestoreRenderStates(void);
static void D3D9_FreeResource(GfxResourceID* resource) { static void D3D9_FreeResource(GfxResourceID* resource) {
if (resource == NULL || *resource == NULL) return; if (!resource || *resource == GFX_NULL) return;
IUnknown* unk = (IUnknown*)(*resource); IUnknown* unk = (IUnknown*)(*resource);
ULONG refCount = unk->lpVtbl->Release(unk); ULONG refCount = unk->lpVtbl->Release(unk);
*resource = NULL; *resource = GFX_NULL;
if (refCount <= 0) return; if (refCount <= 0) return;
uintptr_t addr = (uintptr_t)unk; uintptr_t addr = (uintptr_t)unk;

View File

@ -131,7 +131,7 @@ int Drawer2D_FontHeight(FontDesc* font, bool useShadow) {
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, int X, int Y) { void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, int X, int Y) {
Size2D size = Drawer2D_MeasureText(args); Size2D size = Drawer2D_MeasureText(args);
if (size.Width == 0 && size.Height == 0) { 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; *tex = empty; return;
} }

View File

@ -480,7 +480,7 @@ static void Player_MakeNameTexture(struct Player* player) {
Size2D size = Drawer2D_MeasureText(&args); Size2D size = Drawer2D_MeasureText(&args);
if (size.Width == 0) { if (size.Width == 0) {
player->NameTex.ID = NULL; player->NameTex.ID = GFX_NULL;
player->NameTex.X = PLAYER_NAME_EMPTY_TEX; player->NameTex.X = PLAYER_NAME_EMPTY_TEX;
} else { } else {
char buffer[STRING_SIZE]; char buffer[STRING_SIZE];
@ -589,7 +589,7 @@ static void Player_ApplySkin(struct Player* player, struct Player* from) {
dst->vScale = src->vScale; dst->vScale = src->vScale;
/* Custom mob textures */ /* Custom mob textures */
dst->MobTextureId = NULL; dst->MobTextureId = GFX_NULL;
String skin = String_FromRawArray(dst->SkinNameRaw); String skin = String_FromRawArray(dst->SkinNameRaw);
if (Utils_IsUrlPrefix(&skin, 0)) { dst->MobTextureId = dst->TextureId; } 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) { void Player_ResetSkin(struct Player* player) {
struct Entity* entity = &player->Base; struct Entity* entity = &player->Base;
entity->uScale = 1.0f; entity->vScale = 1.0f; entity->uScale = 1.0f; entity->vScale = 1.0f;
entity->MobTextureId = NULL; entity->MobTextureId = GFX_NULL;
entity->TextureId = NULL; entity->TextureId = GFX_NULL;
entity->SkinType = SKIN_64x32; entity->SkinType = SKIN_64x32;
} }

View File

@ -215,7 +215,7 @@ bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String*
bool success = !res && Game_ValidateBitmap(file, &bmp); bool success = !res && Game_ValidateBitmap(file, &bmp);
if (success) { if (success) {
Gfx_DeleteTexture(texId); Gfx_DeleteTexture(texId);
if (skinType != NULL) { *skinType = Utils_GetSkinType(&bmp); } if (skinType) { *skinType = Utils_GetSkinType(&bmp); }
*texId = Gfx_CreateTexture(&bmp, true, false); *texId = Gfx_CreateTexture(&bmp, true, false);
} }
@ -679,7 +679,7 @@ static void Game_RenderFrame(double delta) {
Gui_SetActive(PauseScreen_MakeInstance()); 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)) { if (allowZoom && KeyBind_IsPressed(KeyBind_ZoomScrolling)) {
InputHandler_SetFOV(Game_ZoomFov, false); InputHandler_SetFOV(Game_ZoomFov, false);
} }
@ -693,7 +693,7 @@ static void Game_RenderFrame(double delta) {
Game_CurrentCameraPos = Camera_Active->GetPosition(t); Game_CurrentCameraPos = Camera_Active->GetPosition(t);
Game_UpdateViewMatrix(); Game_UpdateViewMatrix();
bool visible = Gui_Active == NULL || !Gui_Active->BlocksWorld; bool visible = !Gui_Active || !Gui_Active->BlocksWorld;
if (!World_Blocks) visible = false; if (!World_Blocks) visible = false;
if (visible) { if (visible) {
Game_Render3D(delta, t); Game_Render3D(delta, t);

View File

@ -129,7 +129,7 @@ struct Screen* Gui_GetActiveScreen(void) {
} }
struct Screen* Gui_GetUnderlyingScreen(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) { void Gui_FreeActive(void) {

View File

@ -141,7 +141,7 @@ void Model_UpdateVB(void) {
void Model_ApplyTexture(struct Entity* entity) { void Model_ApplyTexture(struct Entity* entity) {
struct Model* model = Model_ActiveModel; struct Model* model = Model_ActiveModel;
GfxResourceID tex = model->UsesHumanSkin ? entity->TextureId : entity->MobTextureId; GfxResourceID tex = model->UsesHumanSkin ? entity->TextureId : entity->MobTextureId;
if (tex != NULL) { if (tex) {
Model_skinType = entity->SkinType; Model_skinType = entity->SkinType;
} else { } else {
struct CachedTexture* data = &ModelCache_Textures[model->defaultTexIndex]; struct CachedTexture* data = &ModelCache_Textures[model->defaultTexIndex];
@ -150,7 +150,7 @@ void Model_ApplyTexture(struct Entity* entity) {
} }
Gfx_BindTexture(tex); Gfx_BindTexture(tex);
bool _64x64 = Model_skinType != SKIN_64x32; bool _64x64 = Model_skinType != SKIN_64x32;
Model_uScale = entity->uScale * 0.015625f; Model_uScale = entity->uScale * 0.015625f;
Model_vScale = entity->vScale * (_64x64 ? 0.015625f : 0.03125f); Model_vScale = entity->vScale * (_64x64 ? 0.015625f : 0.03125f);
} }

View File

@ -88,7 +88,7 @@ void ModelCache_RegisterTexture(STRING_REF const char* texName) {
if (ModelCache_texCount < MODELCACHE_MAX_MODELS) { if (ModelCache_texCount < MODELCACHE_MAX_MODELS) {
struct CachedTexture tex; struct CachedTexture tex;
tex.Name = String_FromReadonly(texName); tex.Name = String_FromReadonly(texName);
tex.TexID = NULL; tex.TexID = GFX_NULL;
ModelCache_Textures[ModelCache_texCount++] = tex; ModelCache_Textures[ModelCache_texCount++] = tex;
} else { } else {
ErrorHandler_Fail("ModelCache_RegisterTexture - hit max textures"); ErrorHandler_Fail("ModelCache_RegisterTexture - hit max textures");

View File

@ -178,9 +178,9 @@ void Gfx_BindTexture(GfxResourceID texId) {
} }
void Gfx_DeleteTexture(GfxResourceID* texId) { void Gfx_DeleteTexture(GfxResourceID* texId) {
if (texId == NULL || *texId == NULL) return; if (!texId || *texId == GFX_NULL) return;
glDeleteTextures(1, texId); glDeleteTextures(1, texId);
*texId = NULL; *texId = GFX_NULL;
} }
void Gfx_SetTexturing(bool enabled) { gl_Toggle(GL_TEXTURE_2D); } void Gfx_SetTexturing(bool enabled) { gl_Toggle(GL_TEXTURE_2D); }
@ -342,20 +342,20 @@ void Gfx_BindIb(GfxResourceID ib) {
} }
void Gfx_DeleteVb(GfxResourceID* vb) { void Gfx_DeleteVb(GfxResourceID* vb) {
if (vb == NULL || *vb == NULL) return; if (!vb || *vb == GFX_NULL) return;
#ifndef CC_BUILD_GL11 #ifndef CC_BUILD_GL11
glDeleteBuffers(1, vb); glDeleteBuffers(1, vb);
#else #else
if (*vb != gl_DYNAMICLISTID) glDeleteLists(*vb, 1); if (*vb != gl_DYNAMICLISTID) glDeleteLists(*vb, 1);
#endif #endif
*vb = NULL; *vb = GFX_NULL;
} }
void Gfx_DeleteIb(GfxResourceID* ib) { void Gfx_DeleteIb(GfxResourceID* ib) {
#ifndef CC_BUILD_GL11 #ifndef CC_BUILD_GL11
if (ib == NULL || *ib == NULL) return; if (!ib || *ib == GFX_NULL) return;
glDeleteBuffers(1, ib); glDeleteBuffers(1, ib);
*ib = NULL; *ib = GFX_NULL;
#else #else
return; return;
#endif #endif

View File

@ -142,7 +142,7 @@ void Options_Set(const char* keyRaw, const String* value) {
void Options_SetString(const String* key, const String* value) { void Options_SetString(const String* key, const String* value) {
int i; int i;
if (value == NULL || value->buffer == NULL) { if (!value || !value->length) {
i = Options_Find(key); i = Options_Find(key);
if (i >= 0) Options_Remove(i); if (i >= 0) Options_Remove(i);
} else { } else {

View File

@ -522,7 +522,7 @@ static void LoadingScreen_DrawBackground(void) {
TextureRec rec = Atlas1D_TexRec(texLoc, 1, &atlasIndex); TextureRec rec = Atlas1D_TexRec(texLoc, 1, &atlasIndex);
float u2 = (float)Game_Width / (float)LOADING_TILE_SIZE; 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; bool bound = false;
while (y < Game_Height) { while (y < Game_Height) {

View File

@ -17,7 +17,7 @@ void Atlas2D_UpdateState(Bitmap* bmp) {
static GfxResourceID Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, Bitmap* element) { static GfxResourceID Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, Bitmap* element) {
int size = Atlas2D_TileSize; int size = Atlas2D_TileSize;
int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc); 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); Bitmap_CopyBlock(x * size, y * size, 0, 0, &Atlas2D_Bitmap, element, size);
return Gfx_CreateTexture(element, false, Gfx_Mipmaps); return Gfx_CreateTexture(element, false, Gfx_Mipmaps);

View File

@ -95,9 +95,9 @@ void TextWidget_Set(struct TextWidget* w, const String* text, FontDesc* font) {
#define BUTTON_uWIDTH (200.0f / 256.0f) #define BUTTON_uWIDTH (200.0f / 256.0f)
#define BUTTON_MIN_WIDTH 40 #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_ShadowTex = { GFX_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_SelectedTex = { GFX_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_DisabledTex = { GFX_NULL, TEX_RECT(0,0, 0,0), WIDGET_UV(0,46, 200,66) };
static void ButtonWidget_Free(void* widget) { static void ButtonWidget_Free(void* widget) {
struct ButtonWidget* w = widget; struct ButtonWidget* w = widget;