void RemapClass::Item::remap(RemapConsumerParams& remapParams) { if (remapParams.params.ex_iskeydown) { if (isblocked()) return; } else { // We ignore filters_ if active_ is set at KeyDown. if (isblocked() && ! active_) return; } #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { \ if ((POINTER)->remap(remapParams)) { \ if (remapParams.params.ex_iskeydown) { \ active_ = true; \ } else { \ active_ = false; \ } \ } \ } \ } switch (type_) { case BRIDGE_REMAPTYPE_CONSUMERTOCONSUMER: CALL_UNION_FUNCTION(p_.consumerToConsumer); break; case BRIDGE_REMAPTYPE_CONSUMERTOKEY: CALL_UNION_FUNCTION(p_.consumerToKey); break; case BRIDGE_REMAPTYPE_HOLDINGKEYTOKEY: CALL_UNION_FUNCTION(p_.holdingKeyToKey); break; case BRIDGE_REMAPTYPE_KEYOVERLAIDMODIFIER: CALL_UNION_FUNCTION(p_.keyOverlaidModifier); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
void RemapClass::Item::remap(RemapParams& remapParams) { if (isblocked()) return; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { (POINTER)->remap(remapParams); } \ } switch (type_) { case BRIDGE_REMAPTYPE_KEYTOKEY: CALL_UNION_FUNCTION(p_.keyToKey); break; case BRIDGE_REMAPTYPE_KEYTOCONSUMER: CALL_UNION_FUNCTION(p_.keyToConsumer); break; case BRIDGE_REMAPTYPE_KEYTOPOINTINGBUTTON: CALL_UNION_FUNCTION(p_.keyToPointingButton); break; case BRIDGE_REMAPTYPE_DOUBLEPRESSMODIFIER: CALL_UNION_FUNCTION(p_.doublePressModifier); break; case BRIDGE_REMAPTYPE_HOLDINGKEYTOKEY: CALL_UNION_FUNCTION(p_.holdingKeyToKey); break; case BRIDGE_REMAPTYPE_IGNOREMULTIPLESAMEKEYPRESS: CALL_UNION_FUNCTION(p_.ignoreMultipleSameKeyPress); break; case BRIDGE_REMAPTYPE_KEYOVERLAIDMODIFIER: CALL_UNION_FUNCTION(p_.keyOverlaidModifier); break; case BRIDGE_REMAPTYPE_SIMULTANEOUSKEYPRESSES: CALL_UNION_FUNCTION(p_.simultaneousKeyPresses); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
void RemapClass::Item::remap(RemapPointingParams_relative& remapParams) { if (remapParams.params.ex_isbuttondown) { if (isblocked()) return; } else { // We ignore filters_ if active_ is set at ButtonDown. if (isblocked() && ! active_) return; } #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { \ if ((POINTER)->remap(remapParams)) { \ if (remapParams.params.ex_isbuttondown) { \ active_ = true; \ } else { \ active_ = false; \ } \ } \ } \ } switch (type_) { case BRIDGE_REMAPTYPE_DROPPOINTINGRELATIVECURSORMOVE: CALL_UNION_FUNCTION(p_.dropPointingRelativeCursorMove); break; case BRIDGE_REMAPTYPE_POINTINGBUTTONTOKEY: CALL_UNION_FUNCTION(p_.pointingButtonToKey); break; case BRIDGE_REMAPTYPE_POINTINGBUTTONTOPOINTINGBUTTON: CALL_UNION_FUNCTION(p_.pointingButtonToPointingButton); break; case BRIDGE_REMAPTYPE_POINTINGRELATIVETOSCROLL: CALL_UNION_FUNCTION(p_.pointingRelativeToScroll); break; case BRIDGE_REMAPTYPE_HOLDINGKEYTOKEY: CALL_UNION_FUNCTION(p_.holdingKeyToKey); break; case BRIDGE_REMAPTYPE_KEYOVERLAIDMODIFIER: CALL_UNION_FUNCTION(p_.keyOverlaidModifier); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
void RemapClass::Item::remap_forcenumlockon(ListHookedKeyboard::Item* item) { if (isblocked()) return; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { (POINTER)->remap(item); } \ } switch (type_) { case BRIDGE_REMAPTYPE_FORCENUMLOCKON: CALL_UNION_FUNCTION(p_.forceNumLockOn); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
void RemapClass::Item::remap_setkeyboardtype(KeyboardType& keyboardType) { if (isblocked()) return; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { (POINTER)->remap(keyboardType); } \ } switch (type_) { case BRIDGE_REMAPTYPE_SETKEYBOARDTYPE: CALL_UNION_FUNCTION(p_.setKeyboardType); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
void RemapClass::Item::remap(RemapPointingParams_scroll& remapParams) { if (isblocked()) return; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { (POINTER)->remap(remapParams); } \ } switch (type_) { case BRIDGE_REMAPTYPE_DROPSCROLLWHEEL: CALL_UNION_FUNCTION(p_.dropScrollWheel); break; case BRIDGE_REMAPTYPE_STRIPMODIFIERFROMSCROLLWHEEL: CALL_UNION_FUNCTION(p_.stripModifierFromScrollWheel); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
void RemapClass::Item::remap(RemapConsumerParams& remapParams) { if (isblocked()) return; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { (POINTER)->remap(remapParams); } \ } switch (type_) { case BRIDGE_REMAPTYPE_CONSUMERTOCONSUMER: CALL_UNION_FUNCTION(p_.consumerToConsumer); break; case BRIDGE_REMAPTYPE_CONSUMERTOKEY: CALL_UNION_FUNCTION(p_.consumerToKey); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
bool RemapClass::Item::remap_SimultaneousKeyPresses(void) { if (isblocked()) return false; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { return (POINTER)->remap(); } \ } switch (type_) { case BRIDGE_REMAPTYPE_SIMULTANEOUSKEYPRESSES: CALL_UNION_FUNCTION(p_.simultaneousKeyPresses); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION return false; }
bool RemapClass::Item::drop(const Params_KeyboardEventCallBack& params) { if (isblocked()) return false; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { return (POINTER)->drop(params); } \ } switch (type_) { case BRIDGE_REMAPTYPE_DROPKEYAFTERREMAP: CALL_UNION_FUNCTION(p_.dropKeyAfterRemap); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION return false; }
void RemapClass::Item::remap(RemapPointingParams_relative& remapParams) { if (isblocked()) return; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { (POINTER)->remap(remapParams); } \ } switch (type_) { case BRIDGE_REMAPTYPE_DROPPOINTINGRELATIVECURSORMOVE: CALL_UNION_FUNCTION(p_.dropPointingRelativeCursorMove); break; case BRIDGE_REMAPTYPE_POINTINGBUTTONTOKEY: CALL_UNION_FUNCTION(p_.pointingButtonToKey); break; case BRIDGE_REMAPTYPE_POINTINGBUTTONTOPOINTINGBUTTON: CALL_UNION_FUNCTION(p_.pointingButtonToPointingButton); break; case BRIDGE_REMAPTYPE_POINTINGRELATIVETOSCROLL: CALL_UNION_FUNCTION(p_.pointingRelativeToScroll); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
void RemapClass::Item::remap(RemapPointingParams_scroll& remapParams) { if (isblocked()) return; #define CALL_UNION_FUNCTION(POINTER) { \ if (POINTER) { (POINTER)->remap(remapParams); } \ } switch (type_) { case BRIDGE_REMAPTYPE_DROPSCROLLWHEEL: CALL_UNION_FUNCTION(p_.dropScrollWheel); break; case BRIDGE_REMAPTYPE_SCROLLWHEELTOSCROLLWHEEL: CALL_UNION_FUNCTION(p_.scrollWheelToScrollWheel); break; case BRIDGE_REMAPTYPE_SCROLLWHEELTOKEY: CALL_UNION_FUNCTION(p_.scrollWheelToKey); break; case BRIDGE_REMAPTYPE_HOLDINGKEYTOKEY: CALL_UNION_FUNCTION(p_.holdingKeyToKey); break; case BRIDGE_REMAPTYPE_KEYOVERLAIDMODIFIER: CALL_UNION_FUNCTION(p_.keyOverlaidModifier); break; default: // do nothing. (Do not call IOLOG_ERROR) break; } #undef CALL_UNION_FUNCTION }
bool isblocked_keyup(void) override { return isblocked(); }
void RenderableChunk::update() { changed = false; lights.clear(); has_lights = false; // 6 faces per cube, plus 3+3 vertices on each triangle of quad // but half will not be visible for some reason...don't render? GLbyte vertex[CX * CY * CZ * 18][3]; // I use 2 bytes to denote block type, then 1 byte for flags GLbyte texture[CX * CY * CZ * 18][3]; int i = 0; int merged = 0; bool vis = false; model_vertices.clear(); model_normals.clear(); model_uvs.clear(); // View from negative x for(int x = CX - 1; x >= 0; x--) { for(int y = 0; y < CY; y++) { for(int z = 0; z < CZ; z++) { if (get_block_info(blk[x][y][z].type)->is_model) { // add to fill_game_models(model_vertices, model_normals, model_uvs, blk[x][y][z], x, y, z); } RenderableLight* light = &(get_block_info(blk[x][y][z].type)->light); if (light->should_render()) { LightAndPosition light_and_pos; light_and_pos.light = light; // want to render the light at the center of our block light_and_pos.pos = fvec3(x + 0.5f, y + 0.5f, z + 0.5f); lights.push_back(light_and_pos); has_lights = true; } // Line of sight blocked? if(isblocked(x, y, z, x - 1, y, z)) { vis = false; continue; } block_type type = blk[x][y][z]; BlockOrientation flags = BlockOrientation::BACK; // Same block as previous one? Extend it. if(vis && z != 0 && blk[x][y][z].equals(blk[x][y][z - 1])) { set_coord_and_texture(vertex, texture, i - 5, x, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 2, x, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 1, x, y + 1, z + 1, type, flags); merged++; // Otherwise, add a new quad. } else { set_coord_and_texture(vertex, texture, i++, x, y, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z + 1, type, flags); } vis = true; } } } // View from positive x for(int x = 0; x < CX; x++) { for(int y = 0; y < CY; y++) { for(int z = 0; z < CZ; z++) { if(isblocked(x, y, z, x + 1, y, z)) { vis = false; continue; } block_type type = blk[x][y][z]; BlockOrientation flags = BlockOrientation::FRONT; if(vis && z != 0 && blk[x][y][z].equals(blk[x][y][z - 1])) { set_coord_and_texture(vertex, texture, i - 4, x + 1, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 2, x + 1, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 1, x + 1, y, z + 1, type, flags); merged++; } else { set_coord_and_texture(vertex, texture, i++, x + 1, y, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z + 1, type, flags); } vis = true; } } } // View from negative y for(int x = 0; x < CX; x++) { for(int y = CY - 1; y >= 0; y--) { for(int z = 0; z < CZ; z++) { if(isblocked(x, y, z, x, y - 1, z)) { vis = false; continue; } block_type type = blk[x][y][z]; BlockOrientation flags = BlockOrientation::BOTTOM; if(vis && z != 0 && blk[x][y][z].equals(blk[x][y][z - 1])) { set_coord_and_texture(vertex, texture, i - 4, x, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 2, x + 1, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 1, x, y, z + 1, type, flags); merged++; } else { set_coord_and_texture(vertex, texture, i++, x, y, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x, y, z + 1, type, flags); } vis = true; } } } // View from positive y for(int x = 0; x < CX; x++) { for(int y = 0; y < CY; y++) { for(int z = 0; z < CZ; z++) { if(isblocked(x, y, z, x, y + 1, z)) { vis = false; continue; } block_type type = blk[x][y][z]; BlockOrientation flags = BlockOrientation::TOP; if(vis && z != 0 && blk[x][y][z].equals(blk[x][y][z - 1])) { set_coord_and_texture(vertex, texture, i - 5, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 2, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 1, x + 1, y + 1, z + 1, type, flags); merged++; } else { set_coord_and_texture(vertex, texture, i++, x, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z + 1, type, flags); } vis = true; } } } // View from negative z for(int x = 0; x < CX; x++) { for(int z = CZ - 1; z >= 0; z--) { for(int y = 0; y < CY; y++) { if(isblocked(x, y, z, x, y, z - 1)) { vis = false; continue; } block_type type = blk[x][y][z]; BlockOrientation flags = BlockOrientation::RIGHT; if(vis && y != 0 && blk[x][y][z].equals(blk[x][y - 1][z])) { set_coord_and_texture(vertex, texture, i - 5, x, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i - 3, x, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i - 2, x + 1, y + 1, z, type, flags); merged++; } else { set_coord_and_texture(vertex, texture, i++, x, y, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z, type, flags); } vis = true; } } } // View from positive z for(int x = 0; x < CX; x++) { for(int z = 0; z < CZ; z++) { for(int y = 0; y < CY; y++) { if(isblocked(x, y, z, x, y, z + 1)) { vis = false; continue; } block_type type = blk[x][y][z]; BlockOrientation flags = BlockOrientation::LEFT; if(vis && y != 0 && blk[x][y][z].equals(blk[x][y - 1][z])) { set_coord_and_texture(vertex, texture, i - 4, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 3, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i - 1, x + 1, y + 1, z + 1, type, flags); merged++; } else { set_coord_and_texture(vertex, texture, i++, x, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x, y + 1, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y, z + 1, type, flags); set_coord_and_texture(vertex, texture, i++, x + 1, y + 1, z + 1, type, flags); } vis = true; } } } changed = false; elements = i; //printf("Finished generating %d elements\n", elements); // If this chunk is empty, no need to allocate a chunk slot. if(!elements) return; // If we don't have an active slot, find one if(chunk_slot[slot].owner != this) { int lru = 0; for(int i = 0; i < CHUNKSLOTS; i++) { // If there is an empty slot, use it if(!chunk_slot[i].owner) { lru = i; break; } // Otherwise try to find the least recently used slot if(chunk_slot[i].owner->lastused < chunk_slot[lru].owner->lastused) lru = i; } // If the slot is empty, create a new VBO if(!chunk_slot[lru].owner) { if (!(chunk_slot[lru].coord_vbo) || !(chunk_slot[lru].texture_vbo)) { glGenBuffers(1, &chunk_slot[lru].texture_vbo); glGenBuffers(1, &chunk_slot[lru].coord_vbo); } } else { // Otherwise, steal it from the previous slot owner chunk_slot[lru].owner->changed = true; } coord_vbo = chunk_slot[lru].coord_vbo; texture_vbo = chunk_slot[lru].texture_vbo; slot = lru; chunk_slot[slot].owner = this; } glBindBuffer(GL_ARRAY_BUFFER, coord_vbo); glBufferData(GL_ARRAY_BUFFER, elements * sizeof *vertex, vertex, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, texture_vbo); glBufferData(GL_ARRAY_BUFFER, elements * sizeof *texture, texture, GL_STATIC_DRAW); }