Exemplo n.º 1
0
void CMainFrame::OnStart ()
{
	if (PopulationExists())
	{
		CreateLists();
		m_curGeneration = 1;
		SetTimer(1, 2010 - m_speed * 200, NULL);
	}
}
void Object3DParser::CreateLists(object3d *o)
{
	o->displist=glGenLists(1);
	PUSH_CODE_MODE;
	ENTER_MIXED;
	glNewList(o->displist,GL_COMPILE);
	DrawSub(o);
	glEndList();
	POP_CODE_MODE;

	for(std::vector<object3d*>::iterator bs=o->childs.begin();bs!=o->childs.end();bs++){
		CreateLists(*bs);
	}
}
Exemplo n.º 3
0
int TextPlane::Draw(const string & newText, int offset,bool startlower, bool force_highquality, bool automatte)
{
  int retval=1;
  bool drawbg = (bgcol.a!=0);
  static unsigned int * display_lists=CreateLists ();
	// some stuff to draw the text stuff
  string::const_iterator text_it = newText.begin();
  static bool use_bit = force_highquality||XMLSupport::parse_bool(vs_config->getVariable ("graphics","high_quality_font","false"));
  static float font_point = XMLSupport::parse_float (vs_config->getVariable ("graphics","font_point","16"));
  static bool font_antialias = XMLSupport::parse_bool (vs_config->getVariable ("graphics","font_antialias","true"));
  void * fnt = getFont();
  static float std_wid=glutStrokeWidth (GLUT_STROKE_ROMAN,'W');
  myFontMetrics.i=font_point*std_wid/(119.05+33.33);
  if (use_bit)
	  myFontMetrics.i=glutBitmapWidth(fnt,'W');
  myFontMetrics.j=font_point;
  myFontMetrics.i/=.5*g_game.x_resolution;
  myFontMetrics.j/=.5*g_game.y_resolution;
  float tmp,row, col;
  float origcol,origrow;
  GetPos (row,col);
  GetPos(row,origcol);
  float rowheight=use_bit?getFontHeight():myFontMetrics.j;
  myFontMetrics.j=rowheight;
  
	  
  if (startlower) {
      row -= rowheight;

  }
  GFXPushBlendMode();
  glLineWidth (1);
  if (!use_bit&&font_antialias) {
    GFXBlendMode (SRCALPHA,INVSRCALPHA);
	if(gl_options.smooth_lines)
	{
		glEnable(GL_LINE_SMOOTH);
	}
  }else {
	GFXBlendMode (SRCALPHA,INVSRCALPHA);
	if(gl_options.smooth_lines)
	{
		glDisable(GL_LINE_SMOOTH);
	}
  }
  GFXColorf(this->col);

  GFXDisable (DEPTHTEST);
  GFXDisable (CULLFACE);

  GFXDisable (LIGHTING);

  GFXDisable (TEXTURE0);
  GFXDisable (TEXTURE1);

  glPushMatrix();
  glLoadIdentity();
  if (!automatte&&drawbg) {
	GFXColorf(this->bgcol);
	DrawSquare(col,this->myDims.i,row-rowheight*.25,row+rowheight);
  }
  GFXColorf(this->col);

  int entercount=0;
  for (;entercount<offset&&text_it!=newText.end();text_it++) {
    if (*text_it=='\n')
      entercount++;
  }
  glTranslatef(col,row,0);  
  //  glRasterPos2f (g_game.x_resolution*(1-(col+1)/2),g_game.y_resolution*(row+1)/2);
  glRasterPos2f (0,0);
  float scalex=1;
  float scaley=1;
  int potentialincrease=0;
  if (!use_bit) {
    int numplayers=1;
    if (_Universe) // _Universe can be NULL during bootstrap.
      numplayers = (_Universe->numPlayers()>3?_Universe->numPlayers()/2:
                    _Universe->numPlayers());
    scalex=numplayers*myFontMetrics.i/std_wid;
    scaley=myFontMetrics.j/(119.05+33.33);
  }
  glScalef (scalex,scaley,1);
  bool firstThroughLoop=true;
  GFXColor currentCol (this->col);
  while(text_it != newText.end() && (firstThroughLoop||row>myDims.j-rowheight*.25)) {
    unsigned char myc = *text_it;
    if (myc=='_') {
      myc = ' ';
    }
    float shadowlen = 0;
    if(myc=='\t') {
      shadowlen=glutBitmapWidth(fnt,' ')*5./(.5*g_game.x_resolution);
    } else {
      if (use_bit) {
        shadowlen = glutBitmapWidth (fnt,myc)/(float)(.5*g_game.x_resolution); // need to use myc -- could have transformed '_' to ' '
      } else {
        shadowlen = myFontMetrics.i*glutStrokeWidth(GLUT_STROKE_ROMAN,myc)/std_wid;
      }
    }
    
    if (*text_it=='#') {
      if (newText.end()-text_it>6) {
	float r,g,b;
	r = TwoCharToFloat (*(text_it+1),*(text_it+2));
	g = TwoCharToFloat (*(text_it+3),*(text_it+4));
	b = TwoCharToFloat (*(text_it+5),*(text_it+6));
	if (r==0&&g==0&&b==0) {
		currentCol = this->col;
	}else {
		currentCol = GFXColor(r, g, b, this->col.a);
	}
	GFXColorf(currentCol);
        static bool setRasterPos= XMLSupport::parse_bool(vs_config->getVariable("graphics","set_raster_text_color","true"));
        if (use_bit&&setRasterPos)
          glRasterPos2f(col-origcol,0);
	text_it = text_it+6;
      } else {
        break;
      }
      text_it++;
      continue;
    }else if(*text_it>=32) {//always true
	  if(automatte){
		GFXColorf(this->bgcol);
		DrawSquare(col-origcol,col-origcol+shadowlen/scalex,-rowheight*.25/scaley,rowheight*.75/scaley);
		GFXColorf(currentCol);
	  }
      //glutStrokeCharacter (GLUT_STROKE_ROMAN,*text_it);
      retval+=potentialincrease;
      potentialincrease=0;
      int lists = display_lists[myc+(isInside()?128:0)];
      if (lists) {
	    GFXCallList(lists);
	  }else{
		 if (use_bit){
	        glutBitmapCharacter (fnt,myc);
		  }
		 else{
           glutStrokeCharacter (GLUT_STROKE_ROMAN,myc);
		 }
      }
	}
    if(*text_it=='\t') {
	  if(automatte){
		GFXColorf(this->bgcol);
		DrawSquare(col-origcol,col-origcol+shadowlen*5/(.5*g_game.x_resolution),-rowheight*.25/scaley,rowheight*.75/scaley);
		GFXColorf(currentCol);
	  }
      col+=shadowlen;
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
    } else {
      col+=shadowlen;
    }
    if(doNewLine(text_it,newText.end(),col,myDims.i, myFontMetrics.i,row-rowheight<=myDims.j)){
      GetPos (tmp,col);
      firstThroughLoop=false;
      row -= rowheight;
      glPopMatrix();
      glPushMatrix ();
      glLoadIdentity();
	  if (!automatte&&drawbg) {
		GFXColorf(this->bgcol);
		DrawSquare(col,this->myDims.i,row-rowheight*.25,row+rowheight*.75);
	  }
      if (*text_it=='\n') {
	    currentCol = this->col;
      }
	  GFXColorf(currentCol);
      glTranslatef (col,row,0);
      glScalef(scalex,scaley,1);
      glRasterPos2f(0,0);
      potentialincrease++;
	}
    text_it++;
  }
  if(gl_options.smooth_lines)
  {
	  glDisable(GL_LINE_SMOOTH);
  }
  glPopMatrix();

  
  GFXPopBlendMode();
  GFXColorf(this->col);
  return retval;
}
Exemplo n.º 4
0
S3DOModel* CS3OParser::LoadS3O(std::string name,float scale,int side)
{
	GML_STDMUTEX_LOCK(model); // LoadS3O

	if(name.find(".")==std::string::npos)
		name+=".s3o";

	StringToLowerInPlace(name);

	std::map<std::string,S3DOModel*>::iterator ui;
	if((ui=units.find(name))!=units.end()){
		return ui->second;
	}

	PUSH_CODE_MODE;
	ENTER_SYNCED;

	CFileHandler file(name);
	if(!file.FileExists()){
		POP_CODE_MODE;
		throw content_error("File not found: "+name);
	}
	unsigned char* fileBuf=SAFE_NEW unsigned char[file.FileSize()];
	file.Read(fileBuf, file.FileSize());
	S3OHeader header;
	memcpy(&header,fileBuf,sizeof(header));
	header.swap();

	S3DOModel *model = SAFE_NEW S3DOModel;
	model->numobjects=0;
	SS3O* object=LoadPiece(fileBuf,header.rootPiece,model);
	model->rootobjects3o=object;
	model->rootobject3do=0;
	object->isEmpty=true;
	model->name=name;
	model->tex1=(char*)&fileBuf[header.texture1];
	model->tex2=(char*)&fileBuf[header.texture2];
	texturehandler->LoadS3OTexture(model);

	FindMinMax(object);

	units[name]=model;

	CreateLists(object);

	// this is a hack to make aircrafts less likely to collide and get hit by nontracking weapons
	// note: does not apply anymore, unit <--> projectile coldet no longer depends on model->radius
	model->radius = header.radius * scale;
	model->height = header.height;
	model->relMidPos.x=header.midx;
	model->relMidPos.y=header.midy;
	model->relMidPos.z=header.midz;
	if(model->relMidPos.y<1)
		model->relMidPos.y=1;

//	logOutput.Print("%s has height %f",name,model->height);
	fartextureHandler->CreateFarTexture(model);

	model->maxx=model->rootobjects3o->maxx;
	model->maxy=model->rootobjects3o->maxy;
	model->maxz=model->rootobjects3o->maxz;

	model->minx=model->rootobjects3o->minx;
	model->miny=model->rootobjects3o->miny;
	model->minz=model->rootobjects3o->minz;

	delete[] fileBuf;
	POP_CODE_MODE;
	return model;
}
Exemplo n.º 5
0
S3DModel* C3DModelLoader::Load3DModel(std::string modelName)
{
	GML_RECMUTEX_LOCK(model); // Load3DModel

	StringToLowerInPlace(modelName);

	// search in cache first
	ModelMap::iterator ci;
	ParserMap::iterator pi;

	if ((ci = cache.find(modelName)) != cache.end()) {
		return models[ci->second];
	}

	const std::string modelPath = FindModelPath(modelName);

	if ((ci = cache.find(modelPath)) != cache.end()) {
		return models[ci->second];
	}


	// not found in cache, create the model and cache it
	const std::string& fileExt = StringToLower(FileSystem::GetExtension(modelPath));

	if ((pi = parsers.find(fileExt)) != parsers.end()) {
		IModelParser* p = pi->second;
		S3DModel* model = NULL;
		S3DModelPiece* root = NULL;

		try {
			model = p->Load(modelPath);
		} catch (const content_error& ex) {
			LOG_L(L_WARNING, "could not load model \"%s\" (reason: %s)", modelName.c_str(), ex.what());
			goto dummy;
		}

		if ((root = model->GetRootPiece()) != NULL) {
			CreateLists(root);
		}

		AddModelToCache(model, modelName, modelPath);
		CheckModelNormals(model);
		return model;
	}

	LOG_L(L_ERROR, "could not find a parser for model \"%s\" (unknown format?)", modelName.c_str());

dummy:
	// crash-dummy
	S3DModel* model = new S3DModel();
	model->type = MODELTYPE_3DO;
	model->numPieces = 1;
	// give it one dummy piece
	model->SetRootPiece(ModelTypeToModelPiece(MODELTYPE_3DO));
	model->GetRootPiece()->SetCollisionVolume(new CollisionVolume("box", -UpVector, ZeroVector));

	if (model->GetRootPiece() != NULL) {
		CreateLists(model->GetRootPiece());
	}

	AddModelToCache(model, modelName, modelPath);
	return model;
}
Exemplo n.º 6
0
CModel* CS3OParser::Load3DO(string name,float scale,int side)
{
	if(name.find(".")==string::npos)
		name+=".s3o";

	StringToLowerInPlace(name);

	map<string,CModel*>::iterator ui;
	if((ui=units.find(name))!=units.end()){
		return ui->second;
	}

	PUSH_CODE_MODE;
	ENTER_SYNCED;

	CFileHandler file(name);
	if(!file.FileExists()){
		POP_CODE_MODE;
		throw content_error("File not found: "+name);
	}
	unsigned char* fileBuf=new unsigned char[file.FileSize()];
	file.Read(fileBuf, file.FileSize());
	S3OHeader header;
	memcpy(&header,fileBuf,sizeof(header));
	
	CModel *model = new CModel;
	model->numobjects=0;
	SS3O* object=LoadPiece(fileBuf,header.rootPiece,model,-1);
	model->rootobjects3o=object;
	model->rootobject3do=0;
	object->isEmpty=true;
	model->name=name;
	model->textureType=texturehandler->LoadS3OTexture((char*)&fileBuf[header.texture1],(char*)&fileBuf[header.texture2]);

	FindMinMax(object);

	units[name]=model;

	CreateLists(object);

	model->radius = header.radius*scale;		//this is a hack to make aircrafts less likely to collide and get hit by nontracking weapons
	model->height = header.height;
	model->relMidPos.x=header.midx;
	model->relMidPos.y=header.midy;
	model->relMidPos.z=header.midz;
	if(model->relMidPos.y<1)
		model->relMidPos.y=1;

//	info->AddLine("%s has height %f",name,model->height);
	fartextureHandler->CreateFarTexture(model);

	model->maxx=model->rootobjects3o->maxx;
	model->maxy=model->rootobjects3o->maxy;
	model->maxz=model->rootobjects3o->maxz;

	model->minx=model->rootobjects3o->minx;
	model->miny=model->rootobjects3o->miny;
	model->minz=model->rootobjects3o->minz;

	delete[] fileBuf;
	POP_CODE_MODE;
	return model;
}
Exemplo n.º 7
0
/* 
 * Begin pre-calculations:
 * The following should be located at the beginning of the code and
 * calculated once.
 * The arrays 
 *   ind1Re,ind2Re,
 *   ind1Im,ind2Im,
 *   ReFqout,ImFqout,
 *   sizeReFq, sizeImFq,
 * are filled in the then used to compute the derivative of the Green's function
 */
void PreComputeAniso () {

  /* Pre-calculations need qMax and elastic constants. */

  int numTheta = 150;
  int numPhi = numTheta;
  int numTrapezoidal = 100;
	
  double *phi = (double *)calloc(1, numPhi * sizeof(double));
  double *theta = (double *)calloc(1, numTheta * sizeof(double));
  double *xx = (double *)malloc(numTheta * sizeof(double));
  double *ww = (double *)malloc(numTheta * sizeof(double));

  int i, j;
  for (i = 0; i < numPhi; i++) {
    phi[i] = (double)i / numPhi * 2 * M_PI;
  }

  gqwp(numTheta, xx, ww);
    
  for (i = 0; i < numTheta; i++) {
    theta[i] = acos(xx[i]);
  }
    
  /* full dimensions are dGdxgrid[numTheta][numPhi][3][3][3] */
  double (*dGdxgrid)[numPhi][3][3][3];
  double dGdx[3][3][3];

  dGdxgrid = (double (*)[numPhi][3][3][3]) 
    calloc(1, numTheta * numPhi * 27 * sizeof(double));
    
  double C66[6][6], C[3][3][3][3], C633[6][3][3];
  GetCbcc(AnisoParameters->c3[0], AnisoParameters->c3[1],
	  AnisoParameters->c3[2], C66, C, C633);
	
  /*
   *      Define derivative of the Green's function
   *      Decompose derivative of the Green's function into
   *      a grid of theta and phi angles.
   */
  for (i = 0; i < numTheta; i++) {
    for (j = 0; j < numPhi; j++) {
      int a, b, c;
      double sphericalVecNorm[3];
        
      sphericalVecNorm[0] = sin(theta[i]) * cos(phi[j]);
      sphericalVecNorm[1] = sin(theta[i]) * sin(phi[j]);
      sphericalVecNorm[2] = cos(theta[i]);
        
      GetGreensFuncDerivatives(numTrapezoidal, sphericalVecNorm,
			       C, dGdx);
        
      for (a = 0; a < 3; a++) {
	for (b = 0; b < 3; b++) {
	  for (c = 0; c < 3; c++) {
	    dGdxgrid[i][j][a][b][c] = dGdx[a][b][c];
	  }
	}
      }
    }
  }
    

  /*
   *          Compute expansion coefficients (g^{lm}_{vpg}) of the
   *          derivative of the Green's function.
   *          Compute table of binomial factorial coefficients Q^{lm}(k)
   */
  int qMax = AnisoParameters->qMax;
  real8_complex glm[2*qMax+2][2*qMax+2][3][6];
  double binomialFactCoeffs[2*qMax+2][2*qMax+2][2*qMax+2];

  GetGLMandbinom(qMax, numTheta, numPhi, phi,
		 (double*)dGdxgrid, xx, ww, glm, binomialFactCoeffs);


  /*
   *          Compute function F = Q^{lm}(k) * g^{lm}_{vpg}.
   *          This function is precalculated once and for all at the beginning 
   *          of the simulation. It does not depend on the geometry of the
   *          segments.
   */

  double maxReF, maxImF;
  double *ReFqPtr, *ImFqPtr;
  ReFqPtr = (double *)calloc(1, (qMax+2)*(qMax+1)*18*sizeof(double));
  ImFqPtr = (double *)calloc(1, (qMax+2)*(qMax+1)*18*sizeof(double));
  PreFac(qMax, (double *)binomialFactCoeffs, (real8_complex *)glm,
	 (double *)ReFqPtr, (double *)ImFqPtr, &maxReF, &maxImF);
    
    
  /* 
   *          CREATE LIST 
   *          Create lists for real and imaginary parts of F to flatten F
   *          F[i][j][l]  => ind1list for l
   *                         ind2list for 6*i + j.
   */
  int qMaxProd=(qMax+1)*(qMax+2);
  int maxA=qMaxProd*3*6;
  int sizeReFq, sizeImFq;
	    
  int *ind1Re, *ind2Re;
  double *ReFqout;
	    
  ind1Re = (int *)calloc(maxA,sizeof(int));
  ind2Re = (int *)calloc(maxA,sizeof(int));
  ReFqout = (double *)calloc(maxA,sizeof(double));
	    
  CreateLists(qMax, maxReF, (double *)ReFqPtr,
	      ind1Re, ind2Re, ReFqout, &sizeReFq);
	    
  ind1Re = (int *)realloc(ind1Re,sizeReFq*sizeof(int));
  ind2Re = (int *)realloc(ind2Re,sizeReFq*sizeof(int));
  ReFqout = (double *)realloc(ReFqout,sizeReFq*sizeof(double));
	    
  int *ind1Im, *ind2Im;
  double *ImFqout;
	    
  ind1Im = (int *)calloc(maxA,sizeof(int));
  ind2Im = (int *)calloc(maxA,sizeof(int));
  ImFqout = (double *)calloc(maxA,sizeof(double));
	    
  CreateLists(qMax, maxImF, (double *)ImFqPtr,
	      ind1Im, ind2Im, ImFqout, &sizeImFq);
	    
  ind1Im = (int *)realloc(ind1Im,sizeImFq*sizeof(int));
  ind2Im = (int *)realloc(ind2Im,sizeImFq*sizeof(int));
  ImFqout = (double *)realloc(ImFqout,sizeImFq*sizeof(double));

  AnisoParameters->sizeReFq = sizeReFq;
  AnisoParameters->sizeImFq = sizeImFq;
  AnisoParameters->ind1Re = ind1Re;
  AnisoParameters->ind2Re = ind2Re;
  AnisoParameters->ind1Im = ind1Im;
  AnisoParameters->ind2Im = ind2Im;
  AnisoParameters->ReFqout = ReFqout;
  AnisoParameters->ImFqout = ImFqout;

  FILE *ptr_file;
  ptr_file = fopen(AnisoParameters->f_ReFqout,"wb");
  fwrite(&sizeReFq, sizeof(int), 1, ptr_file);
  fwrite(ReFqout, sizeof(double), sizeReFq, ptr_file);
  fclose(ptr_file);

  ptr_file = fopen(AnisoParameters->f_ImFqout,"wb");
  assert(ptr_file != NULL);
  fwrite(&sizeImFq, sizeof(int), 1, ptr_file);
  fwrite(ImFqout, sizeof(double), sizeImFq, ptr_file);
  fclose(ptr_file);

  ptr_file = fopen(AnisoParameters->f_Ind1Re,"wb");
  fwrite(ind1Re, sizeof(int), sizeReFq, ptr_file);
  fclose(ptr_file);

  ptr_file = fopen(AnisoParameters->f_Ind2Re,"wb");
  fwrite(ind2Re, sizeof(int), sizeReFq, ptr_file);
  fclose(ptr_file);

  ptr_file = fopen(AnisoParameters->f_Ind1Im,"wb");
  fwrite(ind1Im, sizeof(int), sizeImFq, ptr_file);
  fclose(ptr_file);

  ptr_file = fopen(AnisoParameters->f_Ind2Im,"wb");
  fwrite(ind2Im, sizeof(int), sizeImFq, ptr_file);
  fclose(ptr_file);

  free(dGdxgrid);
  free(theta);
  free(phi);
  free(xx);
  free(ww);
  free(ReFqPtr);
  free(ImFqPtr);;
}