Skip to content

Commit 0fb9567

Browse files
committedApr 26, 2013
Minor hud.cpp cleanup
1 parent 43a388e commit 0fb9567

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed
 

‎src/hud.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
4545
hotbar_imagesize = 48;
4646
hotbar_itemcount = 8;
4747

48+
tsrc = gamedef->getTextureSource();
49+
4850
v3f crosshair_color = g_settings->getV3F("crosshair_color");
4951
u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255);
5052
u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255);
@@ -57,6 +59,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
5759
u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255);
5860
u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255);
5961
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
62+
63+
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
6064
}
6165

6266

@@ -175,8 +179,7 @@ void Hud::drawLuaElements() {
175179
v2s32 pos(e->pos.X * screensize.X, e->pos.Y * screensize.Y);
176180
switch (e->type) {
177181
case HUD_ELEM_IMAGE: {
178-
video::ITexture *texture =
179-
gamedef->getTextureSource()->getTextureRaw(e->text);
182+
video::ITexture *texture = tsrc->getTextureRaw(e->text);
180183
if (!texture)
181184
continue;
182185

@@ -226,8 +229,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s
226229
const video::SColor color(255, 255, 255, 255);
227230
const video::SColor colors[] = {color, color, color, color};
228231

229-
video::ITexture *stat_texture =
230-
gamedef->getTextureSource()->getTextureRaw(texture);
232+
video::ITexture *stat_texture = tsrc->getTextureRaw(texture);
231233
if (!stat_texture)
232234
return;
233235

@@ -299,9 +301,8 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) {
299301
void Hud::drawCrosshair() {
300302
if (!(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE))
301303
return;
302-
303-
ITextureSource *tsrc = gamedef->getTextureSource();
304-
if (tsrc->isKnownSourceImage("crosshair.png")) {
304+
305+
if (use_crosshair_image) {
305306
video::ITexture *crosshair = tsrc->getTextureRaw("crosshair.png");
306307
v2u32 size = crosshair->getOriginalSize();
307308
v2s32 lsize = v2s32(displaycenter.X - (size.X / 2),

‎src/hud.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ inline u32 hud_get_free_id(Player *player) {
8282

8383
#ifndef SERVER
8484

85-
#include <deque>
86-
8785
#include <IGUIFont.h>
8886

8987
#include "gamedef.h"
@@ -99,6 +97,7 @@ class Hud {
9997
IGameDef *gamedef;
10098
LocalPlayer *player;
10199
Inventory *inventory;
100+
ITextureSource *tsrc;
102101

103102
v2u32 screensize;
104103
v2s32 displaycenter;
@@ -107,6 +106,7 @@ class Hud {
107106

108107
video::SColor crosshair_argb;
109108
video::SColor selectionbox_argb;
109+
bool use_crosshair_image;
110110

111111
Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
112112
gui::IGUIFont *font, u32 text_height, IGameDef *gamedef,

0 commit comments

Comments
 (0)
Please sign in to comment.