static void hexadrop_reshape (Display *dpy, Window window, void *closure, unsigned int w, unsigned int h) { state *st = (state *) closure; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); make_cells (st); }
static int data_size_proc(struct menu_item *item, enum menu_callback_reason reason, void *data) { if (reason == MENU_CALLBACK_DEACTIVATE) { int v = (1 << menu_option_get(item)); if (view_data_size != v) { view_data_size = v; make_cells(item->owner); update_view(); } } return 0; }
void mem_menu_create(struct menu *menu) { /* initialize data */ vector_init(&domains, sizeof(struct mem_domain)); add_domain(0x80000000, 0x00C00000, "k0 rdram"); add_domain(0xA0000000, 0x00C00000, "k1 rdram"); add_domain(0xA3F00000, 0x00100000, "rdram regs"); add_domain(0xA4000000, 0x00100000, "sp regs"); add_domain(0xA4100000, 0x00100000, "dp com"); add_domain(0xA4200000, 0x00100000, "dp span"); add_domain(0xA4300000, 0x00100000, "mi regs"); add_domain(0xA4400000, 0x00100000, "vi regs"); add_domain(0xA4500000, 0x00100000, "ai regs"); add_domain(0xA4600000, 0x00100000, "pi regs"); add_domain(0xA4800000, 0x00100000, "si regs"); add_domain(0xA8000000, 0x08000000, "cart dom2"); add_domain(0xB0000000, 0x0FC00000, "cart dom1"); add_domain(0xBFC00000, 0x000007C0, "pif rom"); add_domain(0xBFC007C0, 0x00000040, "pif ram"); /* initialize menus */ menu_init(menu, MENU_NOVALUE, MENU_NOVALUE, MENU_NOVALUE); menu->selector = menu_add_submenu(menu, 0, 0, NULL, "return"); { view_address = menu_add_intinput(menu, 0, 1, 16, 8, address_proc, NULL); struct menu_item *data_size = menu_add_option(menu, 9, 1, "byte\0""halfword\0""word\0", data_size_proc, NULL); menu_option_set(data_size, 2); view_data_size = 4; menu_add_button(menu, 18, 1, "<", prev_domain_proc, NULL); menu_add_button(menu, 20, 1, ">", next_domain_proc, NULL); view_domain_name = menu_add_static(menu, 22, 1, NULL, 0xC0C0C0); view_domain_name->text = malloc(32); struct gfx_texture *t_arrow = resource_get(RES_ICON_ARROW); view_pageup = menu_add_button_icon(menu, 0, 2, t_arrow, 0, 0xFFFFFF, page_up_proc, NULL); view_pagedown = menu_add_button_icon(menu, 2, 2, t_arrow, 1, 0xFFFFFF, page_down_proc, NULL); menu_add_static(menu, 9, 2, "0 1 2 3 4 5 6 7", 0xC0C0C0); for (int y = 0; y < MEM_VIEW_ROWS; ++y) { view_rows[y] = menu_add_static(menu, 0, 3 + y, NULL, 0xC0C0C0); view_rows[y]->text = malloc(9); } make_cells(menu); goto_domain(0); } }
void generate_initial_positions(double** state, int Nc) { // Generate the initial position of all particles in the lattice double**** cells = make_cells(Nc); // Define mapping from cell origin to particles double** cell2atom = new double*[4]; cell2atom[0] = new double[3]{0 , 0 , 0 }; cell2atom[1] = new double[3]{b/2, b/2, 0 }; cell2atom[2] = new double[3]{b/2, 0 , b/2}; cell2atom[3] = new double[3]{0 , b/2, b/2}; // Generate 4 particles per cell for (int i=0; i<Nc; i++) for (int j=0; j<Nc; j++) for (int k=0; k<Nc; k++) for (int p=0; p<4; p++) for (int d=0; d<3; d++) state[4*(i*Nc*Nc+Nc*j+k)+p][d] = cells[i][j][k][d] + cell2atom[p][d]; }
static void hexadrop_init_1 (Display *dpy, Window window, state *st) { XGCValues gcv; char *s1, *s2; st->dpy = dpy; st->window = window; st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->speed = get_float_resource (st->dpy, "speed", "Speed"); if (st->speed < 0) st->speed = 0; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); if (st->ncolors < 2) st->ncolors = 2; st->colors = (XColor *) calloc (sizeof(*st->colors), st->ncolors); if (st->ncolors < 10) make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, False, True, 0, True); else make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, 0, True); XSetWindowBackground (dpy, window, st->colors[0].pixel); s1 = get_string_resource (st->dpy, "uniform", "Uniform"); s2 = get_string_resource (st->dpy, "lockstep", "Lockstep"); if ((!s1 || !*s1 || !strcasecmp(s1, "maybe")) && (!s2 || !*s2 || !strcasecmp(s2, "maybe"))) { /* When being random, don't do both. */ st->uniform_p = random() & 1; st->lockstep_p = st->uniform_p ? 0 : random() & 1; } else { if (!s1 || !*s1 || !strcasecmp(s1, "maybe")) st->uniform_p = random() & 1; else st->uniform_p = get_boolean_resource (st->dpy, "uniform", "Uniform"); if (!s2 || !*s2 || !strcasecmp(s2, "maybe")) st->lockstep_p = random() & 1; else st->lockstep_p = get_boolean_resource (st->dpy, "lockstep","Lockstep"); } st->sides = get_integer_resource (st->dpy, "sides", "Sides"); if (! (st->sides == 0 || st->sides == 3 || st->sides == 4 || st->sides == 6 || st->sides == 8)) { printf ("%s: invalid number of sides: %d\n", progname, st->sides); st->sides = 0; } if (! st->sides) { static int defs[] = { 3, 3, 3, 4, 6, 6, 6, 6, 8, 8, 8 }; st->sides = defs[random() % countof(defs)]; } make_cells (st); gcv.foreground = st->colors[0].pixel; st->gc = XCreateGC (dpy, window, GCForeground, &gcv); }