Random()
	{
		time_t nowtime;
		struct tm* now;

		::time( &nowtime);
		now = ::localtime( &nowtime);

		m_value = uint32_hash( ((now->tm_year+1)
					* (now->tm_mon+100)
					* (now->tm_mday+1)));
	}
	unsigned int get( unsigned int min_, unsigned int max_)
	{
		if (min_ >= max_)
		{
			throw std::runtime_error("illegal range passed to pseudo random number generator");
		}
		m_value = uint32_hash( m_value + 1);
		unsigned int iv = max_ - min_;
		if (iv)
		{
			return (m_value % iv) + min_;
		}
		else
		{
			return min_;
		}
	}
Пример #3
0
bool gui::define_glyph(gui::bitmap_font_t *font, gui::bitmap_glyph_t const *glyph, size_t i)
{
    uint32_t bucket = uint32_hash(glyph->Codepoint) & (font->BucketCount - 1);
    uint32_t  count = font->GTable[bucket][FONT_SIZE_INDEX];
    uint32_t  nmax  = font->GTable[bucket][FONT_CAPACITY_INDEX];
    if (count == nmax)
    {
        size_t    n = (nmax < 256) ? nmax * 2 : nmax + 256;
        uint32_t *b = (uint32_t *) realloc(font->GTable[bucket], n * sizeof(uint32_t));
        if (b == NULL) return false;
        font->GTable[bucket] = b;
        font->GTable[bucket][FONT_CAPACITY_INDEX] = uint32_t(n);
    }
    font->GTable[bucket][FONT_SIZE_INDEX]++;
    font->GTable[bucket][count] = uint32_t(i);
    font->Glyphs[i] =*glyph;
    return true;
}
Пример #4
0
void gui::measure_string(gui::bitmap_font_t const *font, char const *str, size_t *out_w, size_t *out_h)
{
    if (str != NULL)
    {
        size_t   l = 0; // length, in characters
        size_t   w = 0; // total width, in pixels
        size_t   h = 0; // total height, in pixels
        uint32_t c = 0; // current  UTF-8 codepoint, 0xFFFFFFFFU = invalid
        uint32_t p = 0; // previous UTF-8 codepoint, 0xFFFFFFFFU = invalid
        uint32_t const  m = uint32_t(font->BucketCount - 1);
        char const     *n = next_codepoint(str, c);
        while (c != 0)
        {
            uint32_t bucket = uint32_hash(c) & m;
            uint32_t const *table = font->GTable[bucket];
            uint32_t const  count = font->GTable[bucket][FONT_SIZE_INDEX];
            for (size_t  i  = FONT_CODEPOINT_OFFSET; i < FONT_CODEPOINT_OFFSET + count; ++i)
            {
                if (table[i] == c)
                {
                    size_t gi = table[i];   // the index in into font->Glyphs.
                    w += advance_x(font, p, c, font->Glyphs[gi].AdvanceX);
                    break;
                }
            }
            if (c == '\n') h += font->LineHeight;
            p = c;
            n = next_codepoint(n, c);
            l++;
        }
        if (l > 0) h += font->LineHeight;
        if (out_w)*out_w = w;
        if (out_h)*out_h = h;
    }
    else
    {
        if (out_w) *out_w = 0;
        if (out_h) *out_h = 0;
    }
}
Пример #5
0
/*
 * Hashing function for a string
 */
unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){

        return uint32_hash((unsigned char*)(keystring), strlen(keystring)) % m->table_size;
}