Esempio n. 1
0
/* int(value) */
int DuckInt(int argument_count, void* data)
{
    int error = 0;

    VALUE argument = GetRecord("value", gCurrentContext);

    gLastExpression.type = VAL_PRIMITIVE;
    gLastExpression.data.primitive = TypeInt(argument);
    
    return error;
}
Esempio n. 2
0
int MakeWindow(int argument_count, void* data)
{
    int error = 0;
    //if (argument_count != 3) return 1;

    int width, height;
    const char* szClassName;

    VALUE r_width = GetRecord("width", gCurrentContext);
    VALUE r_height = GetRecord("height", gCurrentContext);
    VALUE r_title = GetRecord("name", gCurrentContext);
    VALUE r_fullscreen = GetRecord("fullscreen", gCurrentContext);

    width = TypeInt(r_width);
    height = TypeInt(r_height);
    szClassName = (r_title.type == VAL_STRING) ? r_title.data.string : "Untitled";

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
    SDL_ShowCursor(0);
    SDL_SetVideoMode(width, height, 24, SDL_OPENGL |
        SDL_GL_DOUBLEBUFFER |
        SDL_HWPALETTE |
        SDL_HWSURFACE |
        SDL_HWACCEL |
        (TypeInt(r_fullscreen) ? SDL_FULLSCREEN : 0)
/* | SDL_FULLSCREEN */
        );
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_WM_SetCaption(szClassName, szClassName);
    SetupGL(width, height);

    game_is_running = 1;

    gLastExpression.type = VAL_NIL;
    gLastExpression.data.primitive = 0;
    return error;
}
Esempio n. 3
0
void MinDistance(Ph_Object self, Ph_Member query,
		 Ph_Member *test, int count)
{
  int m,i, length;
  double *va, *vb, distance;
  struct MinData *data = (struct MinData *)self->data;

  PhGetField(query, data->field, va);
  length = TypeInt(TypeType(
	       Ph_ObjField(query, data->field)->type, 0), 0);

  for(m=0;m < count;m++) {
    PhGetField(test[m], data->field, vb);
    distance = 0.0;
    for(i = 0; i < length; i++) {
      if(va[i] > vb[i]) distance += (va[i] - vb[i]);
    }
    Ph_MemDistance(test[m]) = distance;
  }
}
Esempio n. 4
0
Ph_Image ViewBar_Image(Ph_Object self, Ph_Member m)
{
  PhImageFunc *func;
  Ph_Image image;
  struct ViewImageData *sdata = (struct ViewImageData *)self->super->data;
  struct ViewBarData *data = (struct ViewBarData *)self->data;
  int bar_width, vec_length, space, x, i, inc;
  double *vector, factor;

  if(sdata->field[0]) {
    /* call the superclass (image) to initialize the image */
    func = (PhImageFunc*)PhObjFunc(self->super, "image");
    assert(func);
    image = func(self->super, m);
  }
  if(!sdata->field[0] || !image) {
    /* call the super-superclass (view) to initialize the image */
    func = (PhImageFunc*)PhObjFunc(self->super->super, "image");
    assert(func);
    image = func(self->super->super, m);
    assert(image);
    /* clear to black */
    memset(image->data[0], 0, image->width*image->height*image->channels);
  }

  if(Ph_ObjGet(m, data->vector_field, &vector) == PH_ERROR) {
    fprintf(stderr, "Error getting %s field for %s\n", 
	    data->vector_field, Ph_MemName(m));
    Ph_ImageFree(image);
    return NULL;
  }
  vec_length = TypeInt(TypeType(
		 Ph_ObjField(m, data->vector_field)->type, 0), 0);

  /* determine the bar_width and space */
  x = 0;
  inc = 1;
  bar_width = image->width / vec_length;
  if(bar_width == 0) {
    bar_width = 1;
    space = 0;
    inc = (int)ceil((double)vec_length / image->width);
  }
  else {
    bar_width /= data->spacing + 1;
    if(bar_width == 0) {
      space = image->width / vec_length / 2;
      bar_width = space;
      if(bar_width == 0) {
	bar_width = 1;
	x = (image->width - vec_length) / 2;
      }
    }
    else 
      space = bar_width * data->spacing;
  }

  factor = image->height / (data->maximum - data->minimum);
  for(i=0;i<vec_length;i+=inc,x+=bar_width+space) {
    int j, height;
    double sum = 0.0;
    /* average together inc elements */
    for(j=0;j<inc;j++) sum += vector[i+j];
    sum /= inc;
    height = (int)((sum - data->minimum) * factor + 0.5);
    if(height <= 0) continue;
    if(height > image->height) height = image->height;
    Ph_ImagePutBlock(image, image->height-height, x, height, bar_width, 
		     data->color[0],
		     data->color[1],
		     data->color[2]);
  }

  return image;
}