Skip to content

Commit

Permalink
Default map size should be customizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruxo committed May 3, 2014
1 parent 9ddd252 commit a0a41e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/tb/tb_bitmap_fragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

namespace tb {

// FIX: Make customizable, so we use 256x256 for the glyph bitmap! That should probably be enough
// and also reduce stress on the fragment calculations!
const int default_frag_map_w = 512;
const int default_frag_map_h = 512;

int TBGetNearestPowerOfTwo(int val)
{
int i;
Expand Down Expand Up @@ -356,6 +351,8 @@ void TBBitmapFragmentMap::DeleteBitmap()
TBBitmapFragmentManager::TBBitmapFragmentManager()
: m_num_maps_limit(0)
, m_add_border(false)
, m_default_map_w(512)
, m_default_map_h(512)
{
}

Expand Down Expand Up @@ -406,8 +403,8 @@ TBBitmapFragment *TBBitmapFragmentManager::CreateNewFragment(const TBID &id, boo
bool allow_another_map = (m_num_maps_limit == 0 || m_fragment_maps.GetNumItems() < m_num_maps_limit);
if (!frag && allow_another_map && m_fragment_maps.GrowIfNeeded())
{
int po2w = TBGetNearestPowerOfTwo(MAX(data_w, default_frag_map_w));
int po2h = TBGetNearestPowerOfTwo(MAX(data_h, default_frag_map_h));
int po2w = TBGetNearestPowerOfTwo(MAX(data_w, m_default_map_w));
int po2h = TBGetNearestPowerOfTwo(MAX(data_h, m_default_map_h));
if (dedicated_map)
{
po2w = TBGetNearestPowerOfTwo(data_w);
Expand Down Expand Up @@ -479,6 +476,14 @@ void TBBitmapFragmentManager::SetNumMapsLimit(int num_maps_limit)
m_num_maps_limit = num_maps_limit;
}

void TBBitmapFragmentManager::SetDefaultMapSize(int w, int h)
{
assert(TBGetNearestPowerOfTwo(w) == w);
assert(TBGetNearestPowerOfTwo(h) == h);
m_default_map_w = w;
m_default_map_h = h;
}

int TBBitmapFragmentManager::GetUseRatio() const
{
int used = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/tb/tb_bitmap_fragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ class TBBitmapFragmentManager
the fragment creation will fail. Set to 0 for unlimited (default). */
void SetNumMapsLimit(int num_maps_limit);

/** Set the default size of new fragment maps. These must be power of two. */
void SetDefaultMapSize(int w, int h);

/** Get the amount (in percent) of space that is currently occupied by all maps
in this fragment manager. */
int GetUseRatio() const;
Expand All @@ -235,6 +238,8 @@ class TBBitmapFragmentManager
TBHashTableOf<TBBitmapFragment> m_fragments;
int m_num_maps_limit;
bool m_add_border;
int m_default_map_w;
int m_default_map_h;
};

}; // namespace tb
Expand Down

0 comments on commit a0a41e2

Please sign in to comment.