Skip to content

Commit

Permalink
Merge pull request #28 from FWGS/lowmemory
Browse files Browse the repository at this point in the history
Lowmemory for mainui
  • Loading branch information
a1batross committed Nov 4, 2019
2 parents 163a5ef + 61b35c3 commit 2c3d5a0
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 27 deletions.
5 changes: 5 additions & 0 deletions BaseMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ GNU General Public License for more details.

#define UI_OUTLINE_WIDTH uiStatic.outlineWidth // outline thickness


#if XASH_LOW_MEMORY
#define UI_MAXGAMES 32
#else
#define UI_MAXGAMES 1024 // slots for savegame/demos
#endif
#define UI_MAX_BGMAPS 32

#define MAX_HINT_TEXT 512
Expand Down
3 changes: 3 additions & 0 deletions Btns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ void UI_LoadBmpButtons( void )
{
memset( uiStatic.buttonsPics, 0, sizeof( uiStatic.buttonsPics ));

#if XASH_LOW_MEMORY
return;
#endif
int bmp_filesize, palette_sz = 0;
byte *bmp_buffer = EngFuncs::COM_LoadFile( ART_BUTTONS_MAIN, &bmp_filesize );

Expand Down
3 changes: 3 additions & 0 deletions controls/BackgroundBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ void CMenuBackgroundBitmap::LoadBackground()
if( s_iBackgroundCount != 0 )
return;

#if XASH_LOW_MEMORY
return;
#endif
// try to load backgrounds from mod
if( LoadBackgroundImage( true ) )
{
Expand Down
78 changes: 53 additions & 25 deletions font/BitmapFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ GNU General Public License for more details.

#include "BaseMenu.h"
#include "BaseFontBackend.h"
#include "menufont.h"
#include "BitmapFont.h"

CBitmapFont::CBitmapFont() : CBaseFont(), hImage( 0 ) { }
CBitmapFont::~CBitmapFont() { }
#ifndef MAINUI_FORCE_CONSOLE_BITMAP_FONT
#include "menufont.h"
#endif

#ifndef MAINUI_CONSOLE_FONT_HEIGHT
// redefine in specific ports
#define MAINUI_CONSOLE_FONT_HEIGHT 10
#endif
bool CBitmapFont::Create(const char *name, int tall, int weight, int blur, float brighten, int outlineSize, int scanlineOffset, float scanlineScale, int flags)
{
Q_strncpy( m_szName, name, sizeof( m_szName ) );
Expand All @@ -37,15 +43,21 @@ bool CBitmapFont::Create(const char *name, int tall, int weight, int blur, float
m_fScanlineScale = scanlineScale;
m_iAscent = 0;
m_iMaxCharWidth = 0;

hImage = EngFuncs::PIC_Load( "#XASH_SYSTEMFONT_001.bmp", menufont_bmp, sizeof( menufont_bmp ), 0 );
iImageWidth = EngFuncs::PIC_Width( hImage );
iImageHeight = EngFuncs::PIC_Height( hImage );
#ifndef MAINUI_FORCE_CONSOLE_BITMAP_FONT
if( tall > UI_CONSOLE_CHAR_HEIGHT * uiStatic.scaleY )
{
hImage = EngFuncs::PIC_Load( "#XASH_SYSTEMFONT_001.bmp", menufont_bmp, sizeof( menufont_bmp ), 0 );
iImageWidth = EngFuncs::PIC_Width( hImage );
iImageHeight = EngFuncs::PIC_Height( hImage );
}
else
#endif
m_iHeight = m_iTall = MAINUI_CONSOLE_FONT_HEIGHT;
int a, c;
GetCharABCWidths( '.', a, m_iEllipsisWide, c );
m_iEllipsisWide *= 3;

return hImage != 0;
return true;
}

void CBitmapFont::GetCharRGBA(int ch, Point pt, Size sz, byte *rgba, Size &drawSize)
Expand All @@ -58,8 +70,12 @@ void CBitmapFont::GetCharABCWidths(int ch, int &a, int &b, int &c)
{
a = c = 0;
if( hImage )
b = m_iHeight/2;
else b = 0;
b = m_iHeight/2-1;
else
{
char str[2] = {ch, 0};
EngFuncs::engfuncs.pfnDrawConsoleStringLen( str, &b, NULL );
}
}

bool CBitmapFont::HasChar(int ch) const
Expand Down Expand Up @@ -95,27 +111,39 @@ int CBitmapFont::DrawCharacter(int ch, Point pt, int charH, const unsigned int c
// Draw character doesn't works with alpha override
// EngFuncs::DrawCharacter( pt.x, pt.y, sz.h / 2, sz.h, ch, (int)iColor, hImage );

EngFuncs::PIC_Set( hImage, Red( color ), Green( color ), Blue( color ), Alpha( color ));
if( hImage )
{
EngFuncs::PIC_Set( hImage, Red( color ), Green( color ), Blue( color ), Alpha( color ));

float row, col, size;
col = (ch & 15) * 0.0625f + (0.5f / 256.0f);
row = (ch >> 4) * 0.0625f + (0.5f / 256.0f);
size = 0.0625f - (1.0f / 256.0f);


float row, col, size;
col = (ch & 15) * 0.0625f + (0.5f / 256.0f);
row = (ch >> 4) * 0.0625f + (0.5f / 256.0f);
size = 0.0625f - (1.0f / 256.0f);
wrect_t rc;
int w, h;
w = iImageWidth;
h = iImageHeight;

wrect_t rc;
int w, h;
w = iImageWidth;
h = iImageHeight;
rc.top = h * row;
rc.left = w * col;
rc.bottom = rc.top + h * size;
rc.right = rc.left + w * size;

rc.top = h * row;
rc.left = w * col;
rc.bottom = rc.top + h * size;
rc.right = rc.left + w * size;
if( forceAdditive )
EngFuncs::PIC_DrawAdditive( pt.x, pt.y, charH/2, charH, &rc );
else
EngFuncs::PIC_DrawTrans( pt.x, pt.y, charH/2, charH, &rc );

if( forceAdditive )
EngFuncs::PIC_DrawAdditive( pt.x, pt.y, charH / 2, charH, &rc );
return charH/2-1;

}
else
EngFuncs::PIC_DrawTrans( pt.x, pt.y, charH / 2, charH, &rc );
{
char str[2] = {ch, 0};
EngFuncs::engfuncs.pfnDrawSetTextColor( Red( color ), Green( color ), Blue( color ), Alpha( color ) );

return charH / 2;
return EngFuncs::engfuncs.pfnDrawConsoleString( pt.x, pt.y, str ) - pt.x;
}
}
17 changes: 16 additions & 1 deletion font/FontRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum EFontFlags
FONT_UNDERLINE = 1 << 1,
FONT_STRIKEOUT = 1 << 2
};

#ifndef MAINUI_SMALL_SCREEN
#define UI_CONSOLE_CHAR_WIDTH 9
#define UI_CONSOLE_CHAR_HEIGHT 18

Expand All @@ -27,8 +27,23 @@ enum EFontFlags
#else
#define UI_BIG_CHAR_WIDTH 20
#define UI_BIG_CHAR_HEIGHT 40
#endif // CS16CLIENT
#else // MAINUI_SMALL_SCREEN

#define UI_CONSOLE_CHAR_WIDTH 30
#define UI_CONSOLE_CHAR_HEIGHT 60

#define UI_SMALL_CHAR_WIDTH 30
#define UI_SMALL_CHAR_HEIGHT 60

#define UI_MED_CHAR_WIDTH 35
#define UI_MED_CHAR_HEIGHT 70

#define UI_BIG_CHAR_WIDTH 35
#define UI_BIG_CHAR_HEIGHT 70
#endif


enum EFontSizes
{
#ifdef CLIENT_DLL // hack!
Expand Down
5 changes: 4 additions & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def options(opt):
def configure(conf):
# conf.env.CXX11_MANDATORY = False
conf.load('fwgslib cxx11')

if not conf.env.HAVE_CXX11:
conf.define('MY_COMPILER_SUCKS', 1)

Expand All @@ -74,10 +75,11 @@ def configure(conf):
conf.env.append_unique('CXXFLAGS', '-fno-exceptions')

if conf.env.DEST_OS != 'win32':
if not conf.env.USE_STBTT:
if not conf.env.USE_STBTT and not conf.options.LOW_MEMORY:
conf.check_pkg('freetype2', 'FT2', FT2_CHECK)
conf.check_pkg('fontconfig', 'FC', FC_CHECK)
conf.define('MAINUI_USE_FREETYPE', 1)
conf.check_cc(lib='rt')

def build(bld):
libs = []
Expand All @@ -86,6 +88,7 @@ def build(bld):
if bld.env.DEST_OS != 'win32':
if not bld.env.USE_STBTT:
libs += ['FT2', 'FC']
libs += ['RT']
else:
libs += ['GDI32', 'USER32']

Expand Down

0 comments on commit 2c3d5a0

Please sign in to comment.