//---------- void KinectV2::init() { RULR_NODE_UPDATE_LISTENER; RULR_NODE_SERIALIZATION_LISTENERS; RULR_NODE_INSPECTOR_LISTENER; auto view = MAKE(ofxCvGui::Panels::Groups::Grid); this->view = view; this->device = MAKE(ofxKinectForWindows2::Device); this->device->open(); if (this->device->isOpen()) { this->device->initDepthSource(); this->device->initColorSource(); this->device->initBodySource(); auto rgbView = make_shared<ofxCvGui::Panels::Draws>(this->device->getColorSource()->getTexture()); auto depthView = make_shared<ofxCvGui::Panels::Draws>(this->device->getDepthSource()->getTexture()); rgbView->setCaption("RGB"); depthView->setCaption("Depth"); this->view->add(rgbView); this->view->add(depthView); } else { throw(Exception("Cannot initialise Kinect device. We should find a way to fail elegantly here (and retry later).")); } this->playState.set("Play state", 0, 0, 1); this->viewType.set("View type", 3, 0, 3); }
void MAKE_st_NAME_gt_() // MAKE<NAME> { SETFCB(); // SETFCB W43C1(); // W43C1 MAKE(); // MAKE ABORT("Can't create.", 13);// (ABORT") }
//---------- void Board::init() { RULR_NODE_INSPECTOR_LISTENER; RULR_NODE_SERIALIZATION_LISTENERS; this->boardType.set("Board Type", 0, 0, 1); this->sizeX.set("Size X", 10.0f, 2.0f, 20.0f); this->sizeY.set("Size Y", 7.0f, 2.0f, 20.0f); this->spacing.set("Spacing [m]", 0.05f, 0.001f, 1.0f); this->updatePreviewMesh(); auto view = MAKE(ofxCvGui::Panels::World); view->onDrawWorld += [this](ofCamera &) { this->previewMesh.draw(); }; view->setGridEnabled(false); #ifdef OFXCVGUI_USE_OFXGRABCAM view->getCamera().setCursorDrawEnabled(true); view->getCamera().setCursorDrawSize(this->spacing / 5.0f); #endif auto & camera = view->getCamera(); auto distance = this->spacing * MAX(this->sizeX, this->sizeY); camera.setPosition(0, 0, -distance); camera.lookAt(ofVec3f(), ofVec3f(0, -1, 0)); camera.setNearClip(distance / 100.0f); camera.setFarClip(distance * 100.0f); this->view = view; }
/* ********************** Monster_type flags things *********************** */ monster_type *monster_type_new() { monster_type *m_ptr; MAKE(m_ptr, monster_type); return m_ptr; }
substdes *make_substdes(void) {substdes *sd; sd = MAKE(substdes); if (sd != NULL) memset(sd, 0, sizeof(substdes)); return(sd);}
/* ********************** Monster_blow things *********************** */ monster_blow *monster_blow_new() { monster_blow *blow; MAKE(blow, monster_blow); return blow; }
EXPORTED int vparse_parse(struct vparse_state *state, int only_one) { MAKE(state->card, vparse_card); state->p = state->base; /* don't parse trailing non-whitespace */ return _parse_vcard(state, state->card, only_one); }
store_type *store_type_new() { store_type *store; MAKE(store, store_type); flag_init(&store->stock, 2); flag_set(&store->stock, INVEN_LIMIT_KEY, 0); return store; }
/* * Allocate an object * NOTE: this is the only allowed way to create an object */ object_type *new_object() { object_type *o_ptr; MAKE(o_ptr, object_type); flag_init(&o_ptr->flags, 2); object_wipe(o_ptr); return o_ptr; }
static void predicate_tests() { IntervalScope scope; typedef Vector<double,2> TV2; typedef Vector<Quantized,2> QV2; // Compare triangle_oriented and incircle against approximate floating point versions struct F { static inline double triangle_oriented(const TV2 p0, const TV2 p1, const TV2 p2) { return edet(p1-p0,p2-p0); }; static inline double incircle(const TV2 p0, const TV2 p1, const TV2 p2, const TV2 p3) { const auto d0 = p0-p3, d1 = p1-p3, d2 = p2-p3; return edet(ROW(d0),ROW(d1),ROW(d2)); } }; const auto random = new_<Random>(9817241); for (int step=0;step<100;step++) { #define MAKE(i) \ const auto p##i = tuple(i,QV2(random->uniform<Vector<ExactInt,2>>(-exact::bound,exact::bound))); \ const TV2 x##i(p##i.y); MAKE(0) MAKE(1) MAKE(2) MAKE(3) GEODE_ASSERT(triangle_oriented(p0,p1,p2)==(F::triangle_oriented(x0,x1,x2)>0)); GEODE_ASSERT(incircle(p0,p1,p2,p3)==(F::incircle(x0,x1,x2,x3)>0)); } // Test behavior for large numbers, using the scale invariance and antisymmetry of incircle. for (const int i : range(exact::log_bound)) { const auto bound = ExactInt(1)<<i; const auto p0 = tuple(0,QV2(-bound,-bound)), // Four points on a circle of radius sqrt(2)*bound p1 = tuple(1,QV2( bound,-bound)), p2 = tuple(2,QV2( bound, bound)), p3 = tuple(3,QV2(-bound, bound)); GEODE_ASSERT(!incircle(p0,p1,p2,p3)); GEODE_ASSERT( incircle(p0,p1,p3,p2)); } }
int accept_console(int data1, data data2) { eptr new_connection; eptr new_console; bool old = (data1 == -1 ? TRUE : FALSE); connection_type *ct = NULL; console_connection *cn = NULL; /* Add connection */ if (!old) { new_connection = add_connection(first_connection, data1, console_read, console_close); if (!first_connection) first_connection = new_connection; ct = new_connection->data2; } /* Update connection */ else { ct = (connection_type *)data2; ct->receive_cb = console_read; ct->close_cb = console_close; } /* Add console */ MAKE(cn, console_connection); WIPE(cn, console_connection); new_console = e_add(first_console, ct, cn); if (!first_console) first_console = new_console; /* save pointer to console in connection */ ct->uptr = (data)cn; /* Initial states */ cn->auth = cn->listen = FALSE; /* Inform */ cq_printf(&ct->wbuf, "%T", "Connected\n"); return 0; }
/* * Read hostility information * * Note that this function is responsible for deleting stale entries */ static errr rd_hostilities(player_type *p_ptr) { hostile_type *h_ptr; int i; s32b id; u16b tmp16u; start_section_read("hostilities"); /* Read number */ tmp16u = read_int("num"); /* Read available ID's */ for (i = 0; i < tmp16u; i++) { /* Read next ID */ id = read_int("id"); /* Check for stale player */ if (id > 0 && !lookup_player_name(id)) continue; /* Check for stale party */ if (id < 0 && !parties[0 - id].num) continue; /* Create node */ MAKE(h_ptr, hostile_type); h_ptr->id = id; /* Add to chain */ h_ptr->next = p_ptr->hostile; p_ptr->hostile = h_ptr; } end_section_read("hostilities"); /* Success */ return (0); }
shared_ptr<SourceType> Device::initSource(bool initReader) { CHECK_OPEN; //first check if it already exists { auto source = this->getSource<SourceType>(); if (source) { OFXKINECTFORWINDOWS2_WARNING << "Source of type " << typeid(SourceType).name() << " already initialised."; return source; } } //if not then open it try { auto source = MAKE(SourceType); source->init(this->sensor, initReader); this->sources.push_back(source); return source; } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); return shared_ptr<SourceType>(); } }
/* * Actually read the savefile * */ static errr rd_savefile_new_aux(player_type *p_ptr) { int i; u16b tmp16u; u32b tmp32u; bool clear = FALSE; bool had_header = FALSE; char stat_order_hack[6]; start_section_read("mangband_player_save"); start_section_read("version"); read_int("major"); read_int("minor"); read_int("patch"); end_section_read("version"); if (section_exists("header")) { start_section_read("header"); had_header = TRUE; read_str("playername",p_ptr->name); /* 32 */ skip_value("pass"); p_ptr->prace = read_int("prace"); p_ptr->pclass = read_int("pclass"); p_ptr->male = read_int("male"); read_binary("stat_order", stat_order_hack, 6); for (i = 0; i < 6; i++) p_ptr->stat_order[i] = stat_order_hack[i]; end_section_read("header"); } /* Operating system info */ sf_xtra = read_uint("sf_xtra"); /* Time of savefile creation */ sf_when = read_uint("sf_when"); /* Number of resurrections */ sf_lives = read_int("sf_lives"); /* Number of times played */ sf_saves = read_int("sf_saves"); /* Skip the turn info - if present */ skip_value("turn"); /* Turn this character was born on */ if(value_exists("birth_turn")) read_hturn("birth_turn", &p_ptr->birth_turn); else /* Disable character event logging if no birth turn */ ht_clr(&p_ptr->birth_turn); /* Player turns (actually time spent playing) */ if(value_exists("player_turn")) read_hturn("player_turn", &p_ptr->turn); else ht_clr(&p_ptr->turn); /* Read birth options */ if (rd_birthoptions(p_ptr)) { return (28); } /* Monster Memory */ if (section_exists("monster_lore")) { start_section_read("monster_lore"); tmp16u = read_int("max_r_idx"); /* Incompatible save files */ if (tmp16u > z_info->r_max) { note(format("Too many (%u) monster races!", tmp16u)); return (21); } /* Read the available records */ for (i = 0; i < tmp16u; i++) { /* Read the lore */ rd_lore(p_ptr, i); } end_section_read("monster_lore"); } /* Object Memory */ start_section_read("object_memory"); tmp16u = read_int("max_k_idx"); /* Incompatible save files */ if (tmp16u > z_info->k_max) { note(format("Too many (%u) object kinds!", tmp16u)); return (22); } /* Read the object memory */ for (i = 0; i < tmp16u; i++) { byte tmp8u; tmp8u = read_int("flags"); p_ptr->obj_aware[i] = (tmp8u & 0x01) ? TRUE : FALSE; p_ptr->obj_tried[i] = (tmp8u & 0x02) ? TRUE : FALSE; } end_section_read("object_memory"); /*if (arg_fiddle) note("Loaded Object Memory");*/ /* Read the extra stuff */ rd_extra(p_ptr, had_header); /*if (arg_fiddle) note("Loaded extra information");*/ /* Read the player_hp array */ start_section_read("hp"); tmp16u = read_int("py_max_level"); /* Read the player_hp array */ for (i = 0; i < tmp16u; i++) { p_ptr->player_hp[i] = read_int("hp"); } end_section_read("hp"); /* Important -- Initialize the race/class */ p_ptr->rp_ptr = &p_info[p_ptr->prace]; p_ptr->cp_ptr = &c_info[p_ptr->pclass]; /* Important -- Choose the magic info */ p_ptr->mp_ptr = &c_info[p_ptr->pclass].spells; /* Read spell info */ if (section_exists("spell_flags")) { start_section_read("spell_flags"); for (i = 0; i < PY_MAX_SPELLS; i++) { p_ptr->spell_flags[i] = read_int("flag"); } end_section_read("spell_flags"); } else { /* Port spell flags from old format */ u32b spell_learned1, spell_learned2; u32b spell_worked1, spell_worked2; u32b spell_forgotten1, spell_forgotten2; spell_learned1 = read_uint("spell_learned1"); spell_learned2 = read_uint("spell_learned2"); spell_worked1 = read_uint("spell_worked1"); spell_worked2 = read_uint("spell_worked2"); spell_forgotten1 = read_uint("spell_forgotten1"); spell_forgotten2 = read_uint("spell_forgotten2"); for (i = 0; i < PY_MAX_SPELLS; i++) { if ((i < 32) ? (spell_forgotten1 & (1L << i)) : (spell_forgotten2 & (1L << (i - 32)))) { p_ptr->spell_flags[i] |= PY_SPELL_FORGOTTEN; } if ((i < 32) ? (spell_learned1 & (1L << i)) : (spell_learned2 & (1L << (i - 32)))) { p_ptr->spell_flags[i] |= PY_SPELL_LEARNED; } if ((i < 32) ? (spell_worked1 & (1L << i)) : (spell_worked2 & (1L << (i - 32)))) { p_ptr->spell_flags[i] |= PY_SPELL_WORKED; } } } start_section_read("spell_order"); for (i = 0; i < PY_MAX_SPELLS; i++) { p_ptr->spell_order[i] = read_int("order"); } end_section_read("spell_order"); /* Read the inventory */ if (rd_inventory(p_ptr)) { /*note("Unable to read inventory");*/ return (21); } /* Read hostility information if new enough */ if (rd_hostilities(p_ptr)) { return (22); } rd_cave_memory(p_ptr); /* read the wilderness map */ start_section_read("wilderness"); /* get the map size */ tmp32u = read_int("max_wild"); /* if too many map entries */ if (tmp32u > MAX_WILD) { return 23; } /* read in the map */ for (i = 0; i < tmp32u; i++) { p_ptr->wild_map[i] = read_int("wild_map"); } end_section_read("wilderness"); /* Read the character event history */ if(section_exists("event_history")) { char buf[160]; cptr msg; history_event evt; history_event *last = NULL; start_section_read("event_history"); while(value_exists("hist")) { int depth, level; history_event *n_evt = NULL; read_str("hist", buf); if (sscanf(buf, "%02i:%02i:%02i %4ift %2i ", &evt.days, &evt.hours, &evt.mins, &depth, &level) == 5) { msg = &buf[25];/* skip 25 characters ^ */ evt.depth = depth / 50; evt.message = quark_add(msg); } /* Allocate */ MAKE(n_evt, history_event); n_evt->days = evt.days; n_evt->hours = evt.hours; n_evt->mins = evt.mins; n_evt->depth = evt.depth; n_evt->level = level; n_evt->message = evt.message; /* Add to chain */ if (!last) { p_ptr->charhist = n_evt; last = n_evt; } else { last->next = n_evt; last = n_evt; } } end_section_read("event_history"); } /* Read the characters quest list */ if(section_exists("quests")) { start_section_read("quests"); tmp16u = read_int("max_q_idx"); for(i = 0; i < MAX_Q_IDX; i++) { tmp16u = read_int("level"); p_ptr->q_list[i].level = tmp16u; } end_section_read("quests"); } /* Read the characters sold artifact list */ if(section_exists("found_artifacts")) { start_section_read("found_artifacts"); tmp16u = read_int("max_a_idx"); tmp32u = tmp16u; /* If we have an unexpected number of arts, just reset our list * of sold artifacts. It's not so important we want to break * save file compatability for it. */ if( tmp16u != z_info->a_max ) { clear = TRUE; tmp16u = 0; } for(i = 0; i < z_info->a_max; i++) { if(i < tmp32u) { if(!clear) tmp16u = read_int("a_info"); } p_ptr->a_info[i] = tmp16u; } end_section_read("found_artifacts"); } /* Hack -- no ghosts */ /* r_info[z_info->r_max - 1].max_num = 0; */ end_section_read("mangband_player_save"); /* Success */ return (0); }
void Init_Huffman_Encoder_SV7 ( void ) { // Splitting of the 36 Samples MAKE ( HuffSCFI, HuffSCFI_src ); // Differential Scalefactors MAKE ( HuffDSCF, HuffDSCF_src ); // resolution, differential quantizer indizes MAKE ( HuffHdr, HuffHdr_src ); // 3-step quantizer, 3 bundled samples MAKE ( HuffQ1[0], HuffQ1_src[0] ); // less shaped, book 0 MAKE ( HuffQ1[1], HuffQ1_src[1] ); // more shaped, book 1 // 5-step quantizer, 2 bundled samples MAKE ( HuffQ2[0], HuffQ2_src[0] ); // less shaped, book 0 MAKE ( HuffQ2[1], HuffQ2_src[1] ); // more shaped, book 1 // 7-step quantizer, single samples MAKE ( HuffQ3[0], HuffQ3_src[0] ); // less shaped, book 0 MAKE ( HuffQ3[1], HuffQ3_src[1] ); // more shaped, book 1 #ifdef USE_SV8 // 7-step quantizer, 2 bundled samples MAKE ( HuffN3[0], HuffN3_src[0] ); // less shaped, book 0 MAKE ( HuffN3[1], HuffN3_src[1] ); // more shaped, book 1 #endif // 9-step quantizer, single samples MAKE ( HuffQ4[0], HuffQ4_src[0] ); // less shaped, book 0 MAKE ( HuffQ4[1], HuffQ4_src[1] ); // more shaped, book 1 // 15-step quantizer, single samples MAKE ( HuffQ5[0], HuffQ5_src[0] ); // less shaped, book 0 MAKE ( HuffQ5[1], HuffQ5_src[1] ); // more shaped, book 1 // 31-step quantizer, single samples MAKE ( HuffQ6[0], HuffQ6_src[0] ); // less shaped, book 0 MAKE ( HuffQ6[1], HuffQ6_src[1] ); // more shaped, book 1 // 63-step quantizer, single samples MAKE ( HuffQ7[0], HuffQ7_src[0] ); // less shaped, book 0 MAKE ( HuffQ7[1], HuffQ7_src[1] ); // more shaped, book 1 #ifdef USE_SV8 // 127-step quantizer, single samples MAKE ( HuffN8[0], HuffN8_src[0] ); // book 0 MAKE ( HuffN8[1], HuffN8_src[1] ); // book 1 #endif }
static int _parse_vcard(struct vparse_state *state, struct vparse_card *card, int only_one) { struct vparse_card **subp = &card->objects; struct vparse_entry **entryp = &card->properties; struct vparse_card *sub; const char *cardstart = state->p; const char *entrystart; int r; while (*state->p) { /* whitespace is very skippable before AND afterwards */ if (*state->p == '\r' || *state->p == '\n' || *state->p == ' ' || *state->p == '\t') { INC(1); continue; } entrystart = state->p; MAKE(state->entry, vparse_entry); r = _parse_entry(state); if (r) return r; if (!strcasecmp(state->entry->name, "begin")) { /* shouldn't be any params */ if (state->entry->params) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } /* only possible if some idiot passes 'begin' as * multivalue field name */ if (state->entry->multivalue) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } MAKE(sub, vparse_card); sub->type = strdup(state->entry->v.value); _free_entry(state->entry); state->entry = NULL; /* we must stitch it in first, because state won't hold it */ *subp = sub; subp = &sub->next; r = _parse_vcard(state, sub, /*only_one*/0); if (r) return r; if (only_one) return 0; } else if (!strcasecmp(state->entry->name, "end")) { /* shouldn't be any params */ if (state->entry->params) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } /* only possible if some idiot passes 'end' as * multivalue field name */ if (state->entry->multivalue) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } if (!card->type) { /* no type means we're at the top level, haven't seen a BEGIN! */ state->itemstart = cardstart; return PE_MISMATCHED_CARD; } if (strcasecmp(state->entry->v.value, card->type)) { /* special case mismatched card, the "start" was the start of * the card */ state->itemstart = cardstart; return PE_MISMATCHED_CARD; } _free_entry(state->entry); state->entry = NULL; return 0; } else { /* it's a parameter on this one */ *entryp = state->entry; entryp = &state->entry->next; state->entry = NULL; } } if (card->type) return PE_FINISHED_EARLY; return 0; }
static int _parse_entry_params(struct vparse_state *state) { struct vparse_param **paramp = &state->entry->params; int multiparam = 0; int haseq = 0; int r; repeat: multiparam = 0; haseq = 0; MAKE(state->param, vparse_param); NOTESTART(); r = _parse_param_key(state, &haseq); if (r) return r; if (state->multiparam && strarray_find(state->multiparam, state->param->name, 0)) multiparam = 1; /* now get the value */ while (*state->p) { switch (*state->p) { case '\\': /* normal backslash quoting */ /* seen in the wild - \n split by line wrapping */ if (state->p[1] == '\r') INC(1); if (state->p[1] == '\n') { if (state->p[2] != ' ' && state->p[2] != '\t') return PE_PARAMVALUE_EOL; INC(2); } if (!state->p[1]) return PE_BACKQUOTE_EOF; if (state->p[1] == 'n' || state->p[1] == 'N') PUTC('\n'); else PUTC(state->p[1]); INC(2); break; case '^': /* special value quoting for doublequote (RFC 6868) */ /* seen in the wild - \n split by line wrapping */ if (state->p[1] == '\r') INC(1); if (state->p[1] == '\n') { if (state->p[2] != ' ' && state->p[2] != '\t') return PE_PARAMVALUE_EOL; INC(2); } if (state->p[1] == '\'') { PUTC('"'); INC(2); } else if (state->p[1] == 'n') { PUTC('\n'); INC(2); } else if (state->p[1] == '^') { PUTC('^'); INC(2); } else { PUTC('^'); INC(1); /* treat next char normally */ } break; case '"': INC(1); loop: r = _parse_param_quoted(state, multiparam); if (r == PE_QSTRING_COMMA) { char *name = strdup(state->param->name); state->param->value = buf_dup_cstring(&state->buf); *paramp = state->param; paramp = &state->param->next; MAKE(state->param, vparse_param); state->param->name = name; INC(1); goto loop; } if (r) return r; break; case ':': /* done - all parameters parsed */ if (haseq) state->param->value = buf_dup_cstring(&state->buf); *paramp = state->param; state->param = NULL; INC(1); return 0; case ';': /* another parameter to parse */ if (haseq) state->param->value = buf_dup_cstring(&state->buf); *paramp = state->param; paramp = &state->param->next; INC(1); goto repeat; case '\r': INC(1); break; /* just skip */ case '\n': if (state->p[1] != ' ' && state->p[1] != '\t') return PE_PARAMVALUE_EOL; INC(2); break; case ',': if (multiparam) { char *name = strdup(state->param->name); if (haseq) state->param->value = buf_dup_cstring(&state->buf); *paramp = state->param; paramp = &state->param->next; MAKE(state->param, vparse_param); state->param->name = name; INC(1); break; } /* or fall through, comma isn't special */ default: PUTC(*state->p); INC(1); break; } } return PE_PARAMVALUE_EOF; }
/* * Initialize this file */ void borg_init_1(void) { /* Allocate the "keypress queue" */ C_MAKE(borg_key_queue, KEY_SIZE, char); /* Prepare a local random number seed */ if (!borg_rand_local) borg_rand_local = randint0(0x10000000); /*** Special "tracking" arrays ***/ /* Track "up" stairs */ C_MAKE(track_less_x, track_less_size, int); C_MAKE(track_less_y, track_less_size, int); /* Track "down" stairs */ C_MAKE(track_more_x, track_more_size, int); C_MAKE(track_more_y, track_more_size, int); /* Track glyphs */ C_MAKE(track_glyph_x, track_glyph_size, int); C_MAKE(track_glyph_y, track_glyph_size, int); /* Track Steps */ C_MAKE(track_step_x, track_step_size, int); C_MAKE(track_step_y, track_step_size, int); /* Track closed doors */ C_MAKE(track_door_x, track_door_size, int); C_MAKE(track_door_y, track_door_size, int); /* Array of objects */ C_MAKE(borg_takes, BORG_TAKES_MAX, borg_take); /* Array of monsters */ C_MAKE(borg_kills, BORG_KILLS_MAX, borg_kill); /* Array of views */ C_MAKE(borg_view_x, AUTO_VIEW_MAX, s16b); C_MAKE(borg_view_y, AUTO_VIEW_MAX, s16b); /* Array of temporary coordinates */ C_MAKE(borg_temp_x, BORG_TEMP_MAX, s16b); C_MAKE(borg_temp_y, BORG_TEMP_MAX, s16b); /* Array of temporary coordinates */ C_MAKE(borg_next_x, BORG_NEXT_MAX, s16b); C_MAKE(borg_next_y, BORG_NEXT_MAX, s16b); /* Array of temporary coordinates */ C_MAKE(borg_bolt_x, BORG_TEMP_MAX, s16b); C_MAKE(borg_bolt_y, BORG_TEMP_MAX, s16b); /* Array of temporary coordinates */ C_MAKE(borg_beam_x, BORG_TEMP_MAX, s16b); C_MAKE(borg_beam_y, BORG_TEMP_MAX, s16b); /* Array of temporary coordinates */ C_MAKE(borg_ball_x, BORG_TEMP_MAX, s16b); C_MAKE(borg_ball_y, BORG_TEMP_MAX, s16b); /* Array of temporary coordinates */ C_MAKE(borg_flow_x, BORG_FLOW_MAX, s16b); C_MAKE(borg_flow_y, BORG_FLOW_MAX, s16b); /* Struct for the player information */ MAKE(bp_ptr, borg_player); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND msgwnd = CreateWindow(L"STATIC", L"Shiftfocus window", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, GetModuleHandle(NULL), 0); # define MAKE(x) (RegisterHotKey(msgwnd, x, MOD_CONTROL | MOD_WIN, x) == 0) if ((msgwnd == NULL) || MAKE(VK_LEFT) || MAKE(VK_RIGHT) || MAKE(VK_UP) || MAKE(VK_DOWN)) { MessageBox(msgwnd, L"Unable to register hotkeys, exiting.", L"Error", MB_ICONERROR | MB_OK); DestroyWindow(msgwnd); return 1; } MSG msg; BOOL ret; while (0 != (ret = GetMessage(&msg, msgwnd, 0, 0))) { if (-1 == ret) return 1; switch (msg.message) { case WM_DESTROY: PostQuitMessage(0); break; case WM_HOTKEY: { RECT loc = {}; HWND fg = GetForegroundWindow(); HWND desktop = getDesktopWindow(); GetWindowRect(fg, &loc); POINT p = {}; for ( int distance = 10; MonitorFromPoint(p, MONITOR_DEFAULTTONULL); distance += 10) { switch (msg.wParam) { # define HALF(x,y) (((y)-(x))/2+(x)) case VK_LEFT: p.x=loc.left-distance; p.y=HALF(loc.top,loc.bottom); break; case VK_RIGHT: p.x=loc.right+distance; p.y=HALF(loc.top,loc.bottom); break; case VK_UP: p.y=loc.top-distance; p.x=HALF(loc.left,loc.right); break; case VK_DOWN: p.y=loc.bottom+distance; p.x=HALF(loc.left,loc.right); break; default: MessageBeep(MB_ICONERROR); } HWND n = ChildWindowFromPoint(GetDesktopWindow(), p); if (NULL == n) MessageBeep(MB_ICONASTERISK); else { if (desktop == n) continue; if (!SetForegroundWindow(n)) MessageBeep(MB_ICONERROR); break; } } } break; } TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
/* * Initialization function for an "X11" module to Angband */ errr init_x11(int argc, char **argv) { int i; cptr dpy_name = ""; int num_term = 1; #ifdef USE_GRAPHICS cptr bitmap_file = ""; char filename[1024]; int pict_wid = 0; int pict_hgt = 0; char *TmpData; #endif /* USE_GRAPHICS */ /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-d")) { dpy_name = &argv[i][2]; continue; } #ifdef USE_GRAPHICS if (prefix(argv[i], "-s")) { smoothRescaling = FALSE; continue; } if (prefix(argv[i], "-o")) { arg_graphics = GRAPHICS_ORIGINAL; continue; } if (prefix(argv[i], "-a")) { arg_graphics = GRAPHICS_ADAM_BOLT; continue; } if (prefix(argv[i], "-g")) { smoothRescaling = FALSE; arg_graphics = GRAPHICS_DAVID_GERVAIS; continue; } if (prefix(argv[i], "-b")) { use_bigtile = TRUE; continue; } #endif /* USE_GRAPHICS */ if (prefix(argv[i], "-n")) { num_term = atoi(&argv[i][2]); if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA; else if (num_term < 1) num_term = 1; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Init the Metadpy if possible */ if (Metadpy_init_name(dpy_name)) return (-1); /* Prepare cursor color */ MAKE(xor, infoclr); Infoclr_set(xor); Infoclr_init_ppn(Metadpy->fg, Metadpy->bg, "xor", 0); /* Prepare normal colors */ for (i = 0; i < 256; ++i) { Pixell pixel; MAKE(clr[i], infoclr); Infoclr_set(clr[i]); /* Acquire Angband colors */ color_table[i][0] = angband_color_table[i][0]; color_table[i][1] = angband_color_table[i][1]; color_table[i][2] = angband_color_table[i][2]; color_table[i][3] = angband_color_table[i][3]; /* Default to monochrome */ pixel = ((i == 0) ? Metadpy->bg : Metadpy->fg); /* Handle color */ if (Metadpy->color) { /* Create pixel */ pixel = create_pixel(Metadpy->dpy, color_table[i][1], color_table[i][2], color_table[i][3]); } /* Initialize the color */ Infoclr_init_ppn(pixel, Metadpy->bg, "cpy", 0); } /* Initialize the windows */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; /* Initialize the term_data */ term_data_init(td, i); /* Save global entry */ angband_term[i] = Term; } /* Raise the "Angband" window */ Infowin_set(data[0].win); Infowin_raise(); /* Activate the "Angband" window screen */ Term_activate(&data[0].t); #ifdef USE_GRAPHICS /* Try graphics */ switch (arg_graphics) { case GRAPHICS_ADAM_BOLT: /* Use tile graphics of Adam Bolt */ bitmap_file = "16x16.bmp"; /* Try the "16x16.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "16x16.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; use_transparency = TRUE; pict_wid = pict_hgt = 16; ANGBAND_GRAF = "new"; break; } /* Fall through */ case GRAPHICS_ORIGINAL: /* Use original tile graphics */ bitmap_file = "8x8.bmp"; /* Try the "8x8.bmp" file */ path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Use the "8x8.bmp" file if it exists */ if (0 == fd_close(fd_open(filename, O_RDONLY))) { /* Use graphics */ use_graphics = TRUE; pict_wid = pict_hgt = 8; ANGBAND_GRAF = "old"; break; } break; case GRAPHICS_DAVID_GERVAIS: /* Use tile graphics of David Gervais */ bitmap_file = "32x32.bmp"; /* Use graphics */ use_graphics = TRUE; use_transparency = TRUE; pict_wid = pict_hgt = 32; ANGBAND_GRAF = "david"; break; } /* Load graphics */ if (use_graphics) { Display *dpy = Metadpy->dpy; XImage *tiles_raw; /* Initialize */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; td->tiles = NULL; } path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file)); /* Load the graphical tiles */ tiles_raw = ReadBMP(dpy, filename); if (tiles_raw) { /* Initialize the windows */ for (i = 0; i < num_term; i++) { int j; bool same = FALSE; term_data *td = &data[i]; term_data *o_td = NULL; term *t = &td->t; /* Graphics hook */ t->pict_hook = Term_pict_x11; /* Use graphics sometimes */ t->higher_pict = TRUE; /* Look for another term with same font size */ for (j = 0; j < i; j++) { o_td = &data[j]; if ((td->fnt->twid == o_td->fnt->twid) && (td->fnt->hgt == o_td->fnt->hgt)) { same = TRUE; break; } } if (!same) { /* Resize tiles */ td->tiles = ResizeImage(dpy, tiles_raw, pict_wid, pict_hgt, td->fnt->twid, td->fnt->hgt); } else { /* Use same graphics */ td->tiles = o_td->tiles; } } /* Free tiles_raw */ FREE(tiles_raw); } /* Initialize the transparency masks */ for (i = 0; i < num_term; i++) { term_data *td = &data[i]; int ii, jj; int depth = DefaultDepth(dpy, DefaultScreen(dpy)); Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy)); int total; /* Determine total bytes needed for image */ ii = 1; jj = (depth - 1) >> 2; while (jj >>= 1) ii <<= 1; total = td->fnt->twid * td->fnt->hgt * ii; TmpData = (char *)malloc(total); td->TmpImage = XCreateImage(dpy,visual,depth, ZPixmap, 0, TmpData, td->fnt->twid, td->fnt->hgt, 32, 0); } } #endif /* USE_GRAPHICS */ /* Success */ return (0); }
/* * Initialize a term_data */ static errr term_data_init(term_data *td, int i) { term *t = &td->t; cptr name = angband_term_name[i]; cptr font; int x = 0; int y = 0; int cols = 80; int rows = 24; int ox = 1; int oy = 1; int wid, hgt, num; char buf[80]; cptr str; int val; XClassHint *ch; char res_name[20]; char res_class[20]; XSizeHints *sh; /* Get default font for this term */ font = get_default_font(i); /* Window specific location (x) */ sprintf(buf, "ANGBAND_X11_AT_X_%d", i); str = getenv(buf); x = (str != NULL) ? atoi(str) : -1; /* Window specific location (y) */ sprintf(buf, "ANGBAND_X11_AT_Y_%d", i); str = getenv(buf); y = (str != NULL) ? atoi(str) : -1; /* Window specific cols */ sprintf(buf, "ANGBAND_X11_COLS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) cols = val; /* Window specific rows */ sprintf(buf, "ANGBAND_X11_ROWS_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) rows = val; /* Hack the main window must be at least 80x24 */ if (!i) { if (cols < 80) cols = 80; if (rows < 24) rows = 24; } /* Window specific inner border offset (ox) */ sprintf(buf, "ANGBAND_X11_IBOX_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) ox = val; /* Window specific inner border offset (oy) */ sprintf(buf, "ANGBAND_X11_IBOY_%d", i); str = getenv(buf); val = (str != NULL) ? atoi(str) : -1; if (val > 0) oy = val; /* Prepare the standard font */ MAKE(td->fnt, infofnt); Infofnt_set(td->fnt); if (Infofnt_init_data(font)) quit_fmt("Couldn't load the requested font. (%s)", font); /* Hack -- key buffer size */ num = ((i == 0) ? 1024 : 16); /* Assume full size windows */ wid = cols * td->fnt->wid + (ox + ox); hgt = rows * td->fnt->hgt + (oy + oy); /* Create a top-window */ MAKE(td->win, infowin); Infowin_set(td->win); Infowin_init_top(x, y, wid, hgt, 0, Metadpy->fg, Metadpy->bg); /* Ask for certain events */ Infowin_set_mask(ExposureMask | StructureNotifyMask | KeyPressMask); /* Set the window name */ Infowin_set_name(name); /* Save the inner border */ Infowin->ox = ox; Infowin->oy = oy; /* Make Class Hints */ ch = XAllocClassHint(); if (ch == NULL) quit("XAllocClassHint failed"); my_strcpy(res_name, name, sizeof(res_name)); res_name[0] = FORCELOWER(res_name[0]); ch->res_name = res_name; strcpy(res_class, "Angband"); ch->res_class = res_class; XSetClassHint(Metadpy->dpy, Infowin->win, ch); /* Make Size Hints */ sh = XAllocSizeHints(); /* Oops */ if (sh == NULL) quit("XAllocSizeHints failed"); /* Main window has a differing minimum size */ if (i == 0) { /* Main window min size is 80x24 */ sh->flags = PMinSize | PMaxSize; sh->min_width = 80 * td->fnt->wid + (ox + ox); sh->min_height = 24 * td->fnt->hgt + (oy + oy); sh->max_width = 255 * td->fnt->wid + (ox + ox); sh->max_height = 255 * td->fnt->hgt + (oy + oy); } /* Other windows can be shrunk to 1x1 */ else { /* Other windows */ sh->flags = PMinSize | PMaxSize; sh->min_width = td->fnt->wid + (ox + ox); sh->min_height = td->fnt->hgt + (oy + oy); sh->max_width = 255 * td->fnt->wid + (ox + ox); sh->max_height = 255 * td->fnt->hgt + (oy + oy); } /* Resize increment */ sh->flags |= PResizeInc; sh->width_inc = td->fnt->wid; sh->height_inc = td->fnt->hgt; /* Base window size */ sh->flags |= PBaseSize; sh->base_width = (ox + ox); sh->base_height = (oy + oy); /* Use the size hints */ XSetWMNormalHints(Metadpy->dpy, Infowin->win, sh); /* Map the window */ Infowin_map(); /* Move the window to requested location */ if ((x >= 0) && (y >= 0)) Infowin_impell(x, y); /* Initialize the term */ term_init(t, cols, rows, num); /* Use a "soft" cursor */ t->soft_cursor = TRUE; /* Erase with "white space" */ t->attr_blank = TERM_WHITE; t->char_blank = ' '; /* Hooks */ t->xtra_hook = Term_xtra_x11; t->curs_hook = Term_curs_x11; t->bigcurs_hook = Term_bigcurs_x11; t->wipe_hook = Term_wipe_x11; t->text_hook = Term_text_x11; /* Save the data */ t->data = td; /* Activate (important) */ Term_activate(t); /* Success */ return (0); }
static void init_c(statedes *st, bindes *bd) {int i; char fn[BFLRG], upck[BFLRG], s[BFMG]; char *p, **el, **sl, **ul, **hl; const char *pck; FILE *fc, *fh, *fp; cmeta *cm; pck = st->pck; snprintf(upck, BFLRG, pck, -1); upcase(upck); /* make the C metadata from the derivedc file */ hl = NULL; el = NULL; sl = NULL; ul = NULL; fp = open_file("r", "%s.derivedc", pck); if (fp != NULL) {for (i = 0; TRUE; i++) {p = fgets(s, BFMG, fp); if (p == NULL) break; LAST_CHAR(p) = '\0'; if (blank_line(p) == TRUE) continue; else if (strncmp(p, "include = ", 10) == 0) hl = tokenize(p+10, " \t", 0); else if (strncmp(p, "enum e_", 7) == 0) el = lst_add(el, p); else if (strncmp(p, "struct s_", 9) == 0) sl = lst_add(sl, p); else if (strncmp(p, "union u_", 8) == 0) ul = lst_add(ul, p);}; el = lst_add(el, NULL); sl = lst_add(sl, NULL); ul = lst_add(ul, NULL); fclose(fp);}; cm = MAKE(cmeta); cm->hdrs = hl; cm->enums = el; cm->structs = sl; cm->unions = ul; bd->data = cm; /* open C file */ if ((st->path == NULL) || (strcmp(st->path, ".") == 0)) snprintf(fn, BFLRG, "gc-%s.c", pck); else snprintf(fn, BFLRG, "%s/gc-%s.c", st->path, pck); fc = open_file("w", fn); bd->fp[0] = fc; fprintf(fc, "/*\n"); fprintf(fc, " * GC-%s.C - support routines for %s\n", upck, upck); fprintf(fc, " * NOTE: this file was automatically generated by blang\n"); fprintf(fc, " * any manual changes will not be effective\n"); fprintf(fc, " *\n"); fprintf(fc, " */\n"); fprintf(fc, "\n"); fprintf(fc, "#include \"cpyright.h\"\n"); if (hl != NULL) {for (i = 0; hl[i] != NULL; i++) fprintf(fc, "#include \"%s\"\n", hl[i]);}; /* fprintf(fc, "#include \"%s_int.h\"\n", pck); */ fprintf(fc, "#include \"%s_gen.h\"\n", pck); fprintf(fc, "\n"); /* open header file */ if ((st->path == NULL) || (strcmp(st->path, ".") == 0)) snprintf(fn, BFLRG, "gc-%s.h", pck); else snprintf(fn, BFLRG, "%s/gc-%s.h", st->path, pck); fh = open_file("w", fn); bd->fp[1] = fh; fprintf(fh, "/*\n"); fprintf(fh, " * GC-%s.H - header containing support for %s\n", upck, upck); fprintf(fh, " * NOTE: this file was automatically generated by blang\n"); fprintf(fh, " * any manual changes will not be effective\n"); fprintf(fh, " *\n"); fprintf(fh, " */\n"); fprintf(fh, "\n"); fprintf(fh, "#include \"cpyright.h\"\n"); fprintf(fh, "\n"); fprintf(fh, "#ifndef GEN_%s_H\n", upck); fprintf(fh, "#define GEN_%s_H\n", upck); fprintf(fh, "\n"); return;}