示例#1
0
void CacheList::preload_cache_object(int type)
{
  if (type<0xffff)
  {
    if (!figures[type]->get_cflag(CFLAG_NEED_CACHE_IN))  // see if it's already marked
    {
      figures[type]->set_cflag(CFLAG_NEED_CACHE_IN,1);
      void *cache_fun=figures[type]->get_fun(OFUN_GET_CACHE_LIST);

      if (cache_fun)
      {
    LSpace *sp = LSpace::Current;
    LSpace::Current = &LSpace::Perm;

    void *call_with=NULL;
    push_onto_list(LNumber::Create(type),call_with);

    void *CacheList = ((LSymbol *)cache_fun)->EvalFunction(call_with);
    PtrRef r1(CacheList);

    if (CacheList && lcar(CacheList))
    {
      void *obj_list=lcar(CacheList);
      while (obj_list)
      {
        int t=lnumber_value(CAR(obj_list));
        if (t<0 || t>=total_objects)
          lbreak("Get cache list returned a bad object number %d\n",t);
        else
          preload_cache_object(t);
        obj_list=CDR(obj_list);
      }
    }
    if (CacheList && lcdr(CacheList))
    {
      void *id_list=lcar(lcdr(CacheList));
      while (id_list)
      {
        int id=lnumber_value(CAR(id_list));
        if (id<0 || id>=total)
          lbreak("Get cache list returned a bad id number %d\n",id);
        else if (list[id].last_access<0)
          list[id].last_access=-2;
        else list[id].last_access=2;

        id_list=CDR(id_list);
      }
    }
    LSpace::Current=sp;

      }
    }
  }
}
示例#2
0
文件: menu.c 项目: spippolatore/abuse
int menu(void *args, JCFont *font)             // reurns -1 on esc
{
  main_menu();
  char *title=NULL;
  if (!NILP(CAR(args)))
    title=lstring_value(CAR(args));
  Cell *def=lcar(lcdr(lcdr(args)));
  args=CAR(CDR(args));

  int options=list_length(args);
  int mh=(font->height()+1)*options+10,maxw=0;

  Cell *c=(Cell *)args;
  for (;!NILP(c);c=CDR(c))
  {
    if (strlen(men_str(CAR(c)))>maxw)
      maxw=strlen(men_str(CAR(c)));
  }
  
  int mw=(font->width())*maxw+20;
  int mx=screen->width()/2-mw/2,
      my=screen->height()/2-mh/2;
  

  screen->add_dirty(mx,my,mx+mw-1,my+mh-1);

  if (title)
  {
    int tl=strlen(title)*font->width();
    int tx=screen->width()/2-tl/2;
    dark_wiget(tx-2,my-font->height()-4,tx+tl+2,my-2,eh->medium_color(),eh->dark_color(),180);
    font->put_string(screen,tx+1,my-font->height()-2,title,eh->bright_color());
  }
  
  dark_wiget(mx,my,mx+mw-1,my+mh-1,eh->medium_color(),eh->dark_color(),200);


  int y=my+5;
  for (c=(Cell *)args;!NILP(c);c=CDR(c))
  {
    char *ms=men_str(CAR(c));
    font->put_string(screen,mx+10+1,y+1,ms,eh->black());
    font->put_string(screen,mx+10,y,ms,eh->bright_color());
    y+=font->height()+1;
  }
  

  eh->flush_screen();
  event ev;
  int choice=0,done=0;
  int bh=font->height()+3;
  image *save=new image(mw-2,bh);
  int color=128,cdir=50;
  
  time_marker *last_color_time=NULL; 
  if (!NILP(def))
    choice=lnumber_value(def);
  do
  {
    eh->flush_screen();
    if (eh->event_waiting())
    {
      eh->get_event(ev);
      if (ev.type==EV_KEY)
      {
				switch (ev.key)
				{
				  case JK_ESC : 
				  { choice=-1; done=1; } break;
				  case JK_ENTER :
				  { done=1; } break;
				  case JK_DOWN : 
				  { if (choice<options-1) 
				    choice++;
				  else choice=0;
				  } break;
				  case JK_UP :
				  {
				    if (choice>0)
				    choice--;
				    else choice=options-1;
				  } break;		      
				}
      } else if (ev.type==EV_MOUSE_BUTTON && ev.mouse_button)
      {
				if (ev.mouse_move.x>mx && ev.mouse_move.x<mx+mw && ev.mouse_move.y>my &&
				    ev.mouse_move.y<my+mh)
				{
				  int msel=(ev.mouse_move.y-my)/(font->height()+1);
				  if (msel>=options) msel=options-1;
				  if (msel==choice)                    // clicked on already selected item, return it
				    done=1;
				  else choice=msel;                    // selects an item
				}
      }
    }

    time_marker cur_time;
    if (!last_color_time || (int)(cur_time.diff_time(last_color_time)*1000)>120)
    {       
      if (last_color_time)
        delete last_color_time;
      last_color_time=new time_marker;

      int by1=(font->height()+1)*choice+my+5-2;
      int by2=by1+bh-1;

      screen->put_part(save,0,0,mx+1,by1,mx+mw-2,by2);
      tint_area(mx+1,by1,mx+mw-2,by2,63,63,63,color);

      char *cur=men_str(nth(choice,args));
      font->put_string(screen,mx+10+1,by1+3,cur,eh->black());
      font->put_string(screen,mx+10,by1+2,cur,eh->bright_color());
      screen->rectangle(mx+1,by1,mx+mw-2,by2,eh->bright_color());

      color+=cdir;

      if (color<12 || color>256)
      {
				cdir=-cdir;
				color+=cdir;
      }
      eh->flush_screen();
      save->put_image(screen,mx+1,by1);
    } else milli_wait(10);

  } while (!done);
  if (last_color_time)
    delete last_color_time;
  delete save;
  the_game->draw(the_game->state==SCENE_STATE);

  if (choice!=-1)
  {
    void *val=nth(choice,args);
    if (item_type(val)==L_CONS_CELL)   // is there another value that the user want us to return?
      return lnumber_value(lcdr(val));  
  }
  return choice;
}
示例#3
0
void gamma_correct(palette *&pal, int force_menu)
{
    long dg=0,old_dg=0;
    int abort=0;

    // see if user has already done this routine
    LSymbol *gs = LSymbol::Find("darkest_gray");

    if(old_pal)
    {
        delete pal;
        pal = old_pal;
        old_pal = NULL;
    }

    if(gs && DEFINEDP(gs->GetValue()) && !force_menu)
    {
        dg = lnumber_value(gs->GetValue());
    }
#ifdef __QNXNTO__
    else if (!force_menu)
    {
    	dg = 36;
    }
#endif // __QNXNTO__
    else
    {
        if(gs && DEFINEDP(gs->GetValue()))
        {
            dg = old_dg = lnumber_value(gs->GetValue());
        }
        // load in a fine gray palette they can chose from
        palette *gray_pal = pal->copy();
        int i = 0;
        int tc = 32;

        for(; i < tc; i++)
        {
            gray_pal->set(i, i * 4, i * 4, i * 4);
        }

        gray_pal->load();

        int wm_bc = wm->bright_color(), wm_mc = wm->medium_color(), wm_dc = wm->dark_color();

        int br_r = pal->red(wm_bc) + 20;
        if(br_r > 255)
            br_r = 255;
        int br_g = pal->green(wm_bc) + 20;
        if(br_g > 255)
            br_g = 255;
        int br_b = pal->blue(wm_bc) + 20;
        if(br_b > 255)
            br_b = 255;

        int md_r = pal->red(wm_mc) - 20;
        if(md_r < 0)
            md_r = 0;
        int md_g = pal->green(wm_mc) - 20;
        if(md_g < 0)
            md_g = 0;
        int md_b = pal->blue(wm_mc) - 20;
        if(md_b < 0)
            md_b = 0;

        int dr_r = pal->red(wm_dc) - 40;
        if(dr_r < 0)
            dr_r = 0;
        int dr_g = pal->green(wm_dc) - 40;
        if(dr_g < 0)
            dr_g = 0;
        int dr_b = pal->blue(wm_dc) - 40;
        if(dr_b < 0)
            dr_b = 0;

        wm->set_colors(gray_pal->find_closest(br_r, br_g, br_b),
            gray_pal->find_closest(md_r, md_g, md_b),
            gray_pal->find_closest(dr_r, dr_g, dr_b));

        int sh = wm->font()->Size().y + 35;
        button *but = new button(5, 5 + sh * 3, ID_GAMMA_OK, cache.img(ok_button),
            new info_field(35, 10 + sh * 3, ID_NULL, lang_string("gamma_msg"), 0));

        gray_picker *gp = new gray_picker(2, 5 + sh, ID_GREEN_PICKER, 0, dg / 4, but);
        gp->set_pos(dg / 4);

        Jwindow *gw = wm->CreateWindow(ivec2(xres / 2 - 190,
                                             yres / 2 - 90), ivec2(-1), gp);

        Event ev;
        wm->flush_screen();
        do
        {
            do
            {
                wm->get_event(ev);
            } while(ev.type == EV_MOUSE_MOVE && wm->IsPending());
            wm->flush_screen();
            if(ev.type == EV_CLOSE_WINDOW)
                abort = 1;
            if(ev.type == EV_KEY && ev.key == JK_ESC)
                abort = 1;
        } while(!abort && (ev.type != EV_MESSAGE || ev.message.id != ID_GAMMA_OK));

        dg = ((spicker *)gw->inm->get(ID_GREEN_PICKER))->first_selected() * 4;

        wm->close_window(gw);
        wm->flush_screen();

        wm->set_colors(wm_bc, wm_mc, wm_dc);
        delete gray_pal;

        if(!abort)
        {
            char *gammapath;
            FILE *fp;

            gammapath = (char *)malloc(strlen(get_save_filename_prefix()) + 10);
            sprintf(gammapath, "%sgamma.lsp", get_save_filename_prefix());
            fp = open_FILE(gammapath, "wb");
            if(fp)
            {
                fprintf(fp, "(setq darkest_gray %ld)\n", dg);
                fclose(fp);
                LSpace *sp = LSpace::Current;
                LSpace::Current = &LSpace::Perm;
                LSymbol::FindOrCreate("darkest_gray")->SetNumber(dg);

                LSpace::Current = sp;
            }
            else
            {
                dprintf("Unable to write to file gamma.lsp\n");
            }
            free(gammapath);
        }
    }

    if(abort)
        dg = old_dg;

    if(dg < 1)
        dg = 1;
    else if(dg > 128)
        dg = 128;

    double gamma = log(dg / 255.0) / log(16.0 / 255.0);

    old_pal = pal;
    pal = new palette;
    for(int i = 0; i < 256; i++)
    {
        uint8_t oldr, oldg, oldb;
        old_pal->get(i, oldr, oldg, oldb);
        pal->set(i, (int)(pow(oldr / 255.0, gamma) * 255),
            (int)(pow(oldg / 255.0, gamma) * 255),
            (int)(pow(oldb / 255.0, gamma) * 255));
    }

    pal->load();
}
示例#4
0
void main_menu()
{
  image *Earth=cash.img(earth);
  image *Emap=cash.img(earth_mask);
	
  char name[20];
  ico_button *buts[MENU_TICONS];

  long maxx=0,maxy=0;
  int i=0;
  for (;i<MENU_TICONS;i++)
  {
    sprintf(name,"icon%04d.pcx",i*3+1);
    menu_icons[i*3]=cash.reg("art/icons.spe",name,SPEC_IMAGE,1);
    sprintf(name,"icon%04d.pcx",i*3+2);
    menu_icons[i*3+1]=cash.reg("art/icons.spe",name,SPEC_IMAGE,1);
    sprintf(name,"icon%04d.pcx",i*3+2);
    menu_icons[i*3+2]=cash.reg("art/icons.spe",name,SPEC_IMAGE,1);

    long x=WINDOW_FRAME_LEFT+(i%9)*cash.img(menu_icons[0])->width();
    long y=WINDOW_FRAME_TOP+(i/9)*cash.img(menu_icons[0])->height();
    if (x>maxx) maxx=x;
    if (y>maxy) maxy=y;
    buts[i]=new ico_button(x,y,menu_icons_ids[i],
			   menu_icons[i*3],menu_icons[i*3],
			   menu_icons[i*3+1],menu_icons[i*3+2],NULL);
  }

  buts[0]->next=buts[1];

  int b1,b2,b3,b4;
  
  if (DEFINEDP(symbol_value))
  {
    if (symbol_value(l_difficulty)==l_extreme)
    { b1=18; b2=10;  b3=12; b4=14;  }
    else if (symbol_value(l_difficulty)==l_hard)
    { b1=14; b2=18;  b3=10; b4=12;  }
    else if (symbol_value(l_difficulty)==l_easy)
    { b1=10; b2=12; b3=14; b4=18; }
    else 
    { b1=12; b2=14; b3=18; b4=10; }
  } else  
  { b1=12; b2=14; b3=18; b4=10; }
  

  buts[b1]->next=buts[b2];
  buts[b2]->next=buts[b3];
  buts[b3]->next=buts[b4];


  buts[1]->next=new ico_switch_button(buts[0]->X(),
				      buts[0]->Y()+cash.img(menu_icons[0])->height()*2,
				      ID_NULL, 
				      buts[b1],buts[17]);

 

  
  buts[17]->next=buts[8];

  buts[1]->set_xy(buts[0]->X(),
		  buts[0]->Y()+cash.img(menu_icons[0])->height()*1);
  buts[12]->set_xy(buts[0]->X(),
		  buts[0]->Y()+cash.img(menu_icons[0])->height()*2);
  buts[17]->set_xy(buts[0]->X(),
		  buts[0]->Y()+cash.img(menu_icons[0])->height()*3);
  buts[8]->set_xy(buts[0]->X(),
		  buts[0]->Y()+cash.img(menu_icons[0])->height()*4);



  ico_win=eh->new_window(-1,yres/2-80,-1,-1,buts[0],"Menu");
  
  
//  pmenu *main_pm=new pmenu(0,0,game_sub,screen,eh);
  time_marker old_time;

  screen->add_dirty(0,0,319,199);

  
  // create sphere map
  mask_line *p=make_mask_lines(Emap,Earth->width());

  int eoff=0,coff=0;
  event ev;
//  main_pm->draw(screen,eh,1);
  long x=84,y=60;
  Cell *v=find_symbol("earth_x");
  if (v && DEFINEDP(v)) x=lnumber_value(symbol_value(v));

  v=find_symbol("earth_y");
  if (v && DEFINEDP(v)) y=lnumber_value(symbol_value(v));
  int state=0,stop_menu=0;
  time_marker start;
  do
  {
    time_marker new_time;
    if (state || new_time.diff_time(&old_time)>0.15)
    {
      old_time.get_time();
      scan_map(screen,x,y,Earth,NULL,p,Emap->height(),eoff,coff);      
      if (state)
      { eoff+=8; coff+=4; }
      else
      {
        eoff+=2; coff+=1;
      }

      if (eoff>=320) eoff-=320;
      if (coff>=320) coff-=320;      
      eh->flush_screen();
    }

    if (eh->event_waiting())
    {
      eh->get_event(ev);    
      start.get_time();      // reset time till demo starts up

      menu_handler(ev,ico_win);
      if (ev.type==EV_MOUSE_BUTTON && ev.mouse_button && ev.mouse_move.x>=x && ev.mouse_move.y>=y && 
	  ev.mouse_move.x<=x+Emap->width() && ev.mouse_move.y<=y+Emap->height())
      {
	state=1;
      } else if (ev.type==EV_MOUSE_BUTTON && !ev.mouse_button) state=0;

	
      
      eh->flush_screen();
    }

    if (new_time.diff_time(&start)>10)
    {
      if (!current_demo)
      {
	void *d=make_find_symbol("demos");
	if (DEFINEDP(d))	
	  current_demo=symbol_value(d);
      }
      if (current_demo)
      {
	if (set_demo_mode(DEMO_PLAY,lstring_value(CAR(current_demo)),eh))
	  stop_menu=1;
	current_demo=CDR(current_demo);
      }
    }
   
  } while (!stop_menu && 
	   (ev.type!=EV_MESSAGE || (ev.message.id!=ID_START_GAME && ev.message.id!=ID_QUIT)));

  for (i=0;i<MENU_TICONS;i++)
  {
    ifield *ic=ico_win->inm->unlink(menu_icons_ids[i]);
    if (i) delete ic;
    else delete buts[i];
  }
  
  eh->close_window(ico_win);
  for (int xx=0;xx<Emap->height();xx++)
    jfree(p[xx].remap);
  jfree(p);

  if (ev.message.id==ID_QUIT)   // propogate the quit message
    the_game->end_session();

//  delete main_pm;
}