Handle<Value> HashTable::MaxLoadFactor(const Arguments& args) { HandleScope scope; HashTable *obj = ObjectWrap::Unwrap<HashTable>(args.This()); if(args.Length() > 0) { Number *num = static_cast<Number*>(*args[0]); float factor = (float)num->Value(); if(factor > 0) obj->map.max_load_factor(factor); return scope.Close(Local<Value>()); } else { float factor = obj->map.max_load_factor(); return scope.Close(Number::New((double)factor)); } }
static void HandleUpdateSettings(Object &obj) { auto UpdateHotkey = [&](HOTKEY_TYPE hotkey, const char *setting_name) { Object key_data = obj[setting_name]; if (!key_data.HasMember("keycode")) return; Boolean meta = key_data["meta"]; if (meta) return hlog("meta modifier not supported for hotkey '%s' (%s)", HotKeyTypeName(hotkey), setting_name); Boolean shift = key_data["shift"]; Boolean ctrl = key_data["ctrl"]; Boolean alt = key_data["alt"]; Number code = key_data["keycode"]; WORD mods = ((shift ? HOTKEYF_SHIFT : 0) | (ctrl ? HOTKEYF_CONTROL : 0) | (alt ? HOTKEYF_ALT : 0)) << 8; hotkeys[hotkey] = mods | static_cast<int>(code.Value()); if (!hotkeys[hotkey]) return; hlog("hotkey '%s' (%s) updated", HotKeyTypeName(hotkey), setting_name); }; { LOCK(hotkeys_mutex); //UpdateHotkey(HOTKEY_Screenshot, "...?"); UpdateHotkey(HOTKEY_Bookmark, "bookmark_key"); UpdateHotkey(HOTKEY_Overlay, "highlight_key"); UpdateHotkey(HOTKEY_Stream, "stream_key"); } }
Map::Map(Gosu::Graphics& graphics, wstring fn) { string filename(fn.begin(), fn.end()); string input; ifstream inFile; inFile.open(filename.c_str()); char buf[65536]; while (inFile.good()) { inFile.getline(buf, 65536); input += buf; } inFile.close(); stringstream stream(input); Object root; Reader::Read(root, stream); String name = root["name"]; String author = root["author"]; String url = root["url"]; String version = root["version"]; String tilesetFilename = root["tileset"]["image"]; Number tileSizeNum = root["tileset"]["tilesize"]; this->tilesize = tileSizeNum.Value(); string ts = tilesetFilename.Value(); this->tileset.assign(ts.begin(), ts.end()); this->tileset = Gosu::resourcePrefix() + this->tileset; wcout << this->tileset << endl; Array tiledefs = root["tiledefs"]; Array tiles = root["tiles"]; vector<Tile> tileDefinitions; Array::const_iterator itTiledefs(tiledefs.Begin()), itTiledefsEnd(tiledefs.End()); for (; itTiledefs != itTiledefsEnd; ++itTiledefs) { Object def = *itTiledefs; if (def.Find("offset") == def.End()) { Tile tile(graphics, this->tileset, -this->tilesize, -this->tilesize, this->tilesize, false); tileDefinitions.push_back(tile); } else { Number offX = def["offset"][0]; Number offY = def["offset"][1]; Boolean solid = def["solid"]; Tile tile(graphics, this->tileset, offX.Value(), offY.Value(), this->tilesize, solid.Value()); tileDefinitions.push_back(tile); } } int x = 0; int y = 0; Array::const_iterator itTiles(tiles.Begin()), itTilesEnd(tiles.End()); for (; itTiles != itTilesEnd; ++itTiles) { Array row = *itTiles; Array::const_iterator itRow(row.Begin()), itRowEnd(row.End()); vector<Tile> tileRow; for (; itRow != itRowEnd; ++itRow) { Number tileRef = *itRow; Tile tile(tileDefinitions[tileRef.Value()]); tile.setPosition(Vec(x * this->tilesize, y * this->tilesize)); tileRow.insert(tileRow.begin()+x, tile); x++; } this->tiles.insert(this->tiles.begin() + y, tileRow); x = 0; y++; } this->dim = Vec(this->tiles[0].size(), this->tiles.size()); }