static void bi_Menu_Pic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); menu_pic (x, y, name, 0, 0, -1, -1); }
int Menu_KeyEvent (knum_t key, short unicode, qboolean down) { menu_item_t *item; int ret; if (!menu) return 0; if (menu->keyevent) { run_menu_pre (); PR_RESET_PARAMS (&menu_pr_state); P_INT (&menu_pr_state, 0) = key; P_INT (&menu_pr_state, 1) = unicode; P_INT (&menu_pr_state, 2) = down; PR_ExecuteProgram (&menu_pr_state, menu->keyevent); ret = R_INT (&menu_pr_state); run_menu_post (); if (ret) return 1; } else if (menu->items && menu->items[menu->cur_item]->func && menu->items[menu->cur_item]->allkeys) { run_menu_pre (); PR_PushFrame (&menu_pr_state); item = menu->items[menu->cur_item]; PR_RESET_PARAMS (&menu_pr_state); P_STRING (&menu_pr_state, 0) = PR_SetTempString (&menu_pr_state, item->text); P_INT (&menu_pr_state, 1) = key; PR_ExecuteProgram (&menu_pr_state, item->func); PR_PopFrame (&menu_pr_state); ret = R_INT (&menu_pr_state); run_menu_post (); if (ret) return 1; } if (!menu || !menu->items) return 0; switch (key) { case QFK_DOWN: case QFM_WHEEL_DOWN: bi_Menu_Next (&menu_pr_state); return 1; case QFK_UP: case QFM_WHEEL_UP: bi_Menu_Prev (&menu_pr_state); return 1; case QFK_RETURN: case QFM_BUTTON1: bi_Menu_Enter (&menu_pr_state); return 1; default: return 0; } }
/* Search the frame for suitable guide star * Return 0 if found, -1 for an error. update x & y * with the star's coordinates if found. */ struct gui_star *detect_guide_star(struct ccd_frame *fr, struct region *reg) { struct gui_star *gs; struct sources *src; double score, max_score = 0; int gsi = 0, i = 0; double xc, yc, ds; //rf // double ref_flux = 0.0, ref_fwhm = 0.0; src = new_sources(P_INT(SD_MAX_STARS)); if (src == NULL) { err_printf("detect_guide_star: cannot create sources\n"); return NULL; } // rf = (fr->w * fr->w + fr->h * fr->h) / PI / 2; xc = fr->w / 2; yc = fr->h / 2; extract_stars(fr, reg, 0, P_DBL(SD_SNR), src); if (src->ns <= 0) return NULL; for (i = 0; i < src->ns; i++) { if (src->s[i].peak > P_DBL(AP_SATURATION)) continue; // ref_flux = src->s[i].flux; // ref_fwhm = src->s[i].fwhm; break; } for (i = 0; i < src->ns; i++) { if (src->s[i].peak > P_DBL(AP_SATURATION)) continue; xc = cos((src->s[i].x - fr->w / 2) / fr->w * PI); yc = cos((src->s[i].y - fr->h / 2) / fr->h * PI); ds = sqr(xc * yc); score = src->s[i].flux * ds; d3_printf("%5.1f %5.1f ds: %.3f score: %.1f\n", src->s[i].x, src->s[i].y, ds, score); if (score > max_score) { max_score = score; gsi = i; } } gs = gui_star_new(); gs->x = src->s[gsi].x; gs->y = src->s[gsi].y; gs->size = 1.0 * P_INT(DO_DEFAULT_STAR_SZ); gs->flags = STAR_TYPE_ALIGN; gs->s = (struct star *)g_malloc(sizeof(struct star)); *STAR(gs->s) = src->s[gsi]; STAR(gs->s)->ref_count = 1; release_sources(src); return gs; }
static void bi_Menu_CenterPic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); qpic_t *qpic = r_funcs->Draw_CachePic (name, 1); if (!qpic) return; menu_pic (x - qpic->width / 2, y, name, 0, 0, -1, -1); }
int call_progs_main (progs_t *pr, int argc, const char **argv) { int i; dfunction_t *dfunc; func_t progs_main = 0; string_t *pr_argv; if ((dfunc = PR_FindFunction (pr, "main"))) { progs_main = dfunc - pr->pr_functions; } else { PR_Undefined (pr, "function", "main"); return -1; } PR_PushFrame (pr); pr_argv = PR_Zone_Malloc (pr, (argc + 1) * 4); for (i = 0; i < argc; i++) pr_argv[i] = PR_SetTempString (pr, argv[1 + i]); pr_argv[i] = 0; PR_RESET_PARAMS (pr); P_INT (pr, 0) = argc; P_POINTER (pr, 1) = PR_SetPointer (pr, pr_argv); PR_ExecuteProgram (pr, progs_main); PR_PopFrame (pr); PR_Zone_Free (pr, pr_argv); return R_INT (pr); }
static void bi_Menu_Enter (progs_t *pr) { menu_item_t *item; if (!menu) return; item = menu->items[menu->cur_item]; if (item->func) { run_menu_pre (); PR_PushFrame (&menu_pr_state); PR_RESET_PARAMS (&menu_pr_state); P_STRING (&menu_pr_state, 0) = PR_SetTempString (&menu_pr_state, item->text); P_INT (&menu_pr_state, 1) = 0; PR_ExecuteProgram (&menu_pr_state, item->func); PR_PopFrame (&menu_pr_state); run_menu_post (); } else { menu = item; if (menu->enter_hook) { run_menu_pre (); PR_ExecuteProgram (&menu_pr_state, menu->enter_hook); run_menu_post (); } } }
static void bi_Menu_Begin (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *text = P_GSTRING (pr, 2); menu_item_t *m = calloc (sizeof (menu_item_t), 1); m->x = x; m->y = y; m->text = text && text[0] ? strdup (text) : 0; if (menu) menu_add_item (menu, m); menu = m; if (m->text) Hash_Add (menu_hash, m); }
static void bi_Menu_Item (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *text = P_GSTRING (pr, 2); func_t func = P_FUNCTION (pr, 3); int allkeys = P_INT (pr, 4); menu_item_t *mi = calloc (sizeof (menu_item_t), 1); mi->x = x; mi->y = y; mi->text = text && text[0] ? strdup (text) : 0; mi->func = func; mi->parent = menu; mi->allkeys = allkeys; menu_add_item (menu, mi); }
int guide_star_position_centroid(struct ccd_frame *fr, double x, double y, double *dx, double *dy, double *derr) { struct star s; double d, snr; int ret; ret = get_star_near(fr, x, y, 10.0, &s); if (ret) { *dx = 0; *dy = 0; *derr = 0; return -1; } d = sqrt(sqr(x - s.x) + sqr(y - s.y)); if (d > 0.7 * P_INT(GUIDE_CENTROID_AREA)) { /* we just use the position from get_star, as * it's not possible to use the same area for * centroiding */ *dx = s.x - x; *dy = s.y - y; snr = fabs(s.flux) / sqrt((fabs(s.flux)) / (fr->exp.scale) + s.npix * sqr(fr->exp.rdnoise)); *derr = 4 * 0.42 * s.fwhm / snr; /* we quadruple the error to account for the fact that the star * does not use the same centroid area as the ref position */ return 1; } else { /* we recalculate the centroid using a fixed area around the * target */ double cx, cy, flux; int npix; star_first_moments(fr, x, y, P_INT(GUIDE_CENTROID_AREA), &cx, &cy, &flux, &npix); *dx = cx - x; *dy = cy - y; snr = fabs(flux - s.sky * npix) / sqrt((fabs(s.flux - s.sky * npix)) / (fr->exp.scale) + npix * sqr(fr->exp.rdnoise)); *derr = 0.42 * s.fwhm / snr; return 0; } }
int main (int argc, char **argv) { dfunction_t *dfunc; func_t main_func = 0; const char *name = "progs.dat"; string_t *pr_argv; int pr_argc = 1, i; i = parse_options (argc, argv); argc -= i; argv += i; init_qf (); if (argc > 0) name = argv[0]; if (!load_progs (name)) Sys_Error ("couldn't load %s", name); PR_PushFrame (&pr); if (argc > 2) pr_argc = argc - 1; pr_argv = PR_Zone_Malloc (&pr, (pr_argc + 1) * 4); pr_argv[0] = PR_SetTempString (&pr, name); for (i = 1; i < pr_argc; i++) pr_argv[i] = PR_SetTempString (&pr, argv[1 + i]); pr_argv[i] = 0; if ((dfunc = PR_FindFunction (&pr, ".main")) || (dfunc = PR_FindFunction (&pr, "main"))) main_func = dfunc - pr.pr_functions; else PR_Undefined (&pr, "function", "main"); PR_RESET_PARAMS (&pr); P_INT (&pr, 0) = pr_argc; P_POINTER (&pr, 1) = PR_SetPointer (&pr, pr_argv); PR_ExecuteProgram (&pr, main_func); PR_PopFrame (&pr); if (options.flote) return R_FLOAT (&pr); return R_INT (&pr); }
static void bi_Menu_SubPic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); int srcx = P_INT (pr, 3); int srcy = P_INT (pr, 4); int width = P_INT (pr, 5); int height = P_INT (pr, 6); menu_pic (x, y, name, srcx, srcy, width, height); }
static void bi_Menu_CenterSubPic (progs_t *pr) { int x = P_INT (pr, 0); int y = P_INT (pr, 1); const char *name = P_GSTRING (pr, 2); qpic_t *qpic = r_funcs->Draw_CachePic (name, 1); int srcx = P_INT (pr, 3); int srcy = P_INT (pr, 4); int width = P_INT (pr, 5); int height = P_INT (pr, 6); if (!qpic) return; menu_pic (x - qpic->width / 2, y, name, srcx, srcy, width, height); }
/** Setup the stackframe prior to calling a progs function. Saves all local data the called function will trample on and copies the parameters used by the function into the function's local data space. \param pr pointer to progs_t VM struct \param f pointer to the descriptor for the called function \note Passing a descriptor for a builtin function will result in undefined behavior. */ static void PR_EnterFunction (progs_t *pr, bfunction_t *f) { pr_int_t i, j, c, o; pr_int_t k; pr_int_t count = 0; int size[2] = {0, 0}; long paramofs = 0; long offs; PR_PushFrame (pr); if (f->numparms > 0) { for (i = 0; i < 2 && i < f->numparms; i++) { paramofs += f->parm_size[i]; size[i] = f->parm_size[i]; } count = i; } else if (f->numparms < 0) { for (i = 0; i < 2 && i < -f->numparms - 1; i++) { paramofs += f->parm_size[i]; size[i] = f->parm_size[i]; } for (; i < 2; i++) { paramofs += pr->pr_param_size; size[i] = pr->pr_param_size; } count = i; } for (i = 0; i < count && i < pr->pr_argc; i++) { offs = (pr->pr_params[i] - pr->pr_globals) - f->parm_start; if (offs >= 0 && offs < paramofs) { memcpy (pr->pr_real_params[i], pr->pr_params[i], size[i] * sizeof (pr_type_t)); pr->pr_params[i] = pr->pr_real_params[i]; } } //Sys_Printf("%s:\n", PR_GetString(pr,f->s_name)); pr->pr_xfunction = f; pr->pr_xstatement = f->first_statement - 1; // offset the st++ // save off any locals that the new function steps on c = f->locals; if (pr->localstack_used + c > LOCALSTACK_SIZE) PR_RunError (pr, "PR_EnterFunction: locals stack overflow"); memcpy (&pr->localstack[pr->localstack_used], &pr->pr_globals[f->parm_start], sizeof (pr_type_t) * c); pr->localstack_used += c; if (pr_deadbeef_locals->int_val) for (k = f->parm_start; k < f->parm_start + c; k++) pr->pr_globals[k].integer_var = 0xdeadbeef; // copy parameters o = f->parm_start; if (f->numparms >= 0) { for (i = 0; i < f->numparms; i++) { for (j = 0; j < f->parm_size[i]; j++) { memcpy (&pr->pr_globals[o], &P_INT (pr, i) + j, sizeof (pr_type_t)); o++; } } } else { pr_type_t *argc = &pr->pr_globals[o++]; pr_type_t *argv = &pr->pr_globals[o++]; for (i = 0; i < -f->numparms - 1; i++) { for (j = 0; j < f->parm_size[i]; j++) { memcpy (&pr->pr_globals[o], &P_INT (pr, i) + j, sizeof (pr_type_t)); o++; } } argc->integer_var = pr->pr_argc - i; argv->integer_var = o; if (i < MAX_PARMS) { memcpy (&pr->pr_globals[o], &P_INT (pr, i), (MAX_PARMS - i) * pr->pr_param_size * sizeof (pr_type_t)); } } }
void Menu_Draw (view_t *view) { menu_pic_t *m_pic; int i, x, y; menu_item_t *item; if (!menu) return; x = view->xabs; y = view->yabs; if (menu->fadescreen) r_funcs->Draw_FadeScreen (); *menu_pr_state.globals.time = *con_data.realtime; if (menu->draw) { int ret; run_menu_pre (); PR_RESET_PARAMS (&menu_pr_state); P_INT (&menu_pr_state, 0) = x; P_INT (&menu_pr_state, 1) = y; PR_ExecuteProgram (&menu_pr_state, menu->draw); ret = R_INT (&menu_pr_state); run_menu_post (); if (!ret) return; } for (m_pic = menu->pics; m_pic; m_pic = m_pic->next) { qpic_t *pic = r_funcs->Draw_CachePic (m_pic->name, 1); if (!pic) continue; if (m_pic->width > 0 && m_pic->height > 0) r_funcs->Draw_SubPic (x + m_pic->x, y + m_pic->y, pic, m_pic->srcx, m_pic->srcy, m_pic->width, m_pic->height); else r_funcs->Draw_Pic (x + m_pic->x, y + m_pic->y, pic); } for (i = 0; i < menu->num_items; i++) { if (menu->items[i]->text) { r_funcs->Draw_String (x + menu->items[i]->x + 8, y + menu->items[i]->y, menu->items[i]->text); } } if (!menu->items) return; item = menu->items[menu->cur_item]; if (menu->cursor) { run_menu_pre (); PR_RESET_PARAMS (&menu_pr_state); P_INT (&menu_pr_state, 0) = x + item->x; P_INT (&menu_pr_state, 1) = y + item->y; PR_ExecuteProgram (&menu_pr_state, menu->cursor); run_menu_post (); } else { r_funcs->Draw_Character (x + item->x, y + item->y, 12 + ((int) (*con_data.realtime * 4) & 1)); } }
static void bi_Menu_FadeScreen (progs_t *pr) { menu->fadescreen = P_INT (pr, 0); }