Info print from lua and new hash function in hashtable
This commit is contained in:
parent
9550840a7a
commit
0564f6c3a2
|
@ -42,7 +42,7 @@ local function generate_path ()
|
|||
|
||||
local cx, cy = 1, 1
|
||||
local seed = time();
|
||||
print("[**] Map generation seed: " .. seed)
|
||||
info("Map generation seed: " .. seed)
|
||||
randomseed(seed)
|
||||
local direction = 0
|
||||
local lastDirection = 0
|
||||
|
|
|
@ -26,20 +26,17 @@ ht_create(unsigned int size)
|
|||
return table;
|
||||
}
|
||||
|
||||
/* D. J. Bernstein hash function */
|
||||
static unsigned int
|
||||
hash(Hashtable *table, const char *key)
|
||||
{
|
||||
unsigned long int hashval = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int hash = 5381;
|
||||
|
||||
// TODO(Linus): This isn't very good,
|
||||
// bad distribution on similar strings
|
||||
while (hashval < ULONG_MAX && i < strlen(key)) {
|
||||
hashval += key[i++];
|
||||
hashval = hashval << 8;
|
||||
while (*key) {
|
||||
hash = 33 * hash ^ (unsigned char) *key++;
|
||||
}
|
||||
|
||||
return hashval % table->size;
|
||||
return hash % table->size;
|
||||
}
|
||||
|
||||
static Entry*
|
||||
|
|
|
@ -27,6 +27,14 @@ int l_create_map(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
l_print_info(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
info(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
Map* luaL_checkmap(lua_State *L, int index)
|
||||
{
|
||||
|
@ -238,6 +246,9 @@ Map* map_lua_generator_run(unsigned int level, SDL_Renderer *renderer)
|
|||
lua_pushcfunction(L, l_create_map);
|
||||
lua_setglobal(L, "create_map");
|
||||
|
||||
lua_pushcfunction(L, l_print_info);
|
||||
lua_setglobal(L, "info");
|
||||
|
||||
lua_pushcfunction(L, l_add_tile);
|
||||
lua_setglobal(L, "add_tile");
|
||||
|
||||
|
|
Loading…
Reference in New Issue