Example #1
0
int setFileLoggerDirectory(const char *logfileDirectory) {
	int error = EINVAL;

	if (logfileDirectory != NULL) {
		if (logfileDirectory[0] != '$') {
			error = checkDirectory(logfileDirectory);
		} else {
			char *envVar = getenv(logfileDirectory+1);
			if (envVar != NULL) {
				error = checkDirectory(logfileDirectory);
			} else {
				error = ENOENT;
				ERROR_MSG("environment variable %s is not found",logfileDirectory);
			}
		} /* !(logfileDirectory[0] != '$') */
		if (EXIT_SUCCESS == error) {
			strcpy(directory, logfileDirectory);
			DEBUG_VAR(directory, "%s");
			fileDirectory = directory;
		}
	} /* (logfileDirectory != NULL) */

	return error;
}
Example #2
0
  // -------------------------------------------------------------------------
  string SgeGridMonitor::submitJob(const string & sgePath,
                                   const string & jobFilename,
                                   const string & params,
                                   const string & gridType)
  {
    string command(sgePath);
    if (!command.empty())
    {
      command += "/";
    }
    command += "qsub ";
    command += params;
    command += " ";
    command += jobFilename;
    command += " > qstat.tmp";
    DEBUG_VAR(command);
    system(command.c_str());

    ifstream ifs("qstat.tmp", ios::binary);
    char buf[256];
    int linecount = 0;
    if (ifs.good() && !ifs.eof())
    {
      ifs.getline(buf, 256);
      DEBUG_VAR(buf);

      string jobId;
      if (gridType == "pbs") {
        jobId = buf;
        if (jobId.empty()) {
          ERROR_MSG("Unable to parse qsub output.");
          ERROR_MSG("qstat.tmp is empty?.");
          return "";
        }
        DEBUG_VAR(jobId);
        return jobId;
      } else if (gridType == "sge") {
        list<string> listString;
        splitText(buf, listString, " \t");
        list<string>::iterator itr = listString.begin();
        list<string>::iterator itr_end = listString.end();
        //DEBUG_VAR(listString.size());
        if (listString.size() < 5) {
          ERROR_MSG("Unable to parse qsub output.");
          ERROR_MSG("Not enough [" << listString.size() << "] entries in file.");
          return "";
        }
        for (int count = 0; itr != itr_end; itr++,count++) {
          if (count == 2) {
            jobId = *itr;
            return jobId;
          }
        }
      } else {
        ERROR_MSG("Unknown grid type");
        return "";
      }

    } // if (ifs.good() && !ifs.eof())

    return "";
  }
Example #3
0
  // -------------------------------------------------------------------------
  bool SgeGridMonitor::refreshInfo(const string & sgePath)
  {
    //DEBUG_TRACE;
    jobs.clear();

    string command(sgePath);
    if (!command.empty())
    {
      command += "/";
    }
    command += "qstat > qstat.tmp";
    DEBUG_VAR(command);
    system(command.c_str());

    ifstream ifs("qstat.tmp", ios::binary);
    char buf[256];
    int linecount = 0;
    while (ifs.good() && !ifs.eof())
    {
      ifs.getline(buf, 256);
      // Skip the first two lines.. they are headed info
      linecount++;
      if (linecount < 3)
      {
        continue;
      }
      if (strlen(buf) == 0)
      {
        continue;
      }
      DEBUG_VAR(buf);
      list<string> listString;
      splitText(buf, listString, " \t");
      //DEBUG_VAR(listString.size());

      if (listString.size() < 5)
      {
        ERROR_MSG("Unable to parse qstat output");
        return false;
      }
      list<string>::iterator itr = listString.begin();
      list<string>::iterator itr_end = listString.end();
      string jobId;
      string status;
      for (int count = 0; itr != itr_end; itr++,count++)
      {
        if (count == 0)
        {
          jobId = *itr;
          //DEBUG_VAR(jobId);
        }
        if (count == 4)
        {
          status = *itr;
          //DEBUG_VAR(status);
        }
      }

      SgeGridMonitor::JobStatus js = JS_UNKNOWN;
      if (status == "d")
      {
        js = JS_DELETION;
      }
      else if (status == "E")
      {
        js = JS_ERROR;
      }
      else if (status == "h")
      {
        js = JS_HOLD;
      }
      else if (status == "r" || status == "R" || status == "t" )
      {
        js = JS_RUNNING;
      }
      else if (status == "R")
      {
        js = JS_RESTARTED;
      }
      else if (status == "s" || status == "S"|| status == "T")
      {
        js = JS_SUSPENDED;
      }
      else if (status == "w" || status == "qw")
      {
        js = JS_WAITING;
      }

      jobs[jobId] = js;
    }

    return false;
  }
Example #4
0
int main(int argc, char **argv)
{
#else
int __entry_menu(int argc, char **argv)
{
   InitFunctionPointers();
#endif
#if 1
   setup_os_exceptions();
#else
   InstallExceptionHandler();
#endif
   socket_lib_init();
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT);
#endif
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   memoryInitialize();
   mount_sd_fat("sd");
   VPADInit();

   verbosity_enable();
   DEBUG_VAR(argc);
   DEBUG_STR(argv[0]);
   DEBUG_STR(argv[1]);
#if 0
   int argc_ = 2;
//   char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.nes", NULL};
   char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.sfc", NULL};

   rarch_main(argc_, argv_, NULL);
#else
   rarch_main(argc, argv, NULL);
#endif
//   int frames = 0;
   do
   {
      unsigned sleep_ms = 0;
      int ret = runloop_iterate(&sleep_ms);

      if (ret == 1 && sleep_ms > 0)
       retro_sleep(sleep_ms);
      task_queue_ctl(TASK_QUEUE_CTL_WAIT, NULL);
      if (ret == -1)
       break;

   }while(1);
//   }while(frames++ < 300);

   main_exit(NULL);
   unmount_sd_fat("sd");
   memoryRelease();
   fflush(stdout);
   fflush(stderr);
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_deinit();
#endif

   return 0;
}
  bool ExecParallelAssembly::invoke(void)
  {
    float peakTol = (float)m_params.getValueDouble("TOLERANCE_PEAK");
    float pmTol = (float)m_params.getValueDouble("TOLERANCE_PM");

    abruijn::AbruijnGraph2::REVERSE_STARS = m_params.getValueInt("REVERSE_STARS", 1) > 0;

    abruijn::AbruijnGraph2::ENFORCE_B_ENDPTS = m_params.getValueInt("ENFORCE_B_ENDPTS", 0) > 0;

    abruijn::AbruijnGraph2::PEAK_TOLERANCE = (float)m_params.getValueDouble("TOLERANCE_PEAK");

    DEBUG_VAR(abruijn::AbruijnGraph2::MAX_NUM_JUMPS);

    if (!AAJumps::globalJumpsInitialized())
    {
      AAJumps::initializeGlobalJumps(abruijn::AbruijnGraph2::MAX_NUM_JUMPS,
                                     0.01,
                                     0);
    }

    const int debugIdx = -1;

    for (abinfo_t::iterator abIt = m_inputAbruijn->begin(); abIt
        != m_inputAbruijn->end(); abIt++)
    {
      unsigned int i = abIt->first;

      if (i >= m_contigShifts->consensus.size())
      {
        m_contigShifts->consensus.resize(i + 1);
      }

      if (m_inputAbruijn->count(i) == 0)
      {
        DEBUG_MSG("Skipping component " << i);
        continue;
      }

      if (debugIdx >= 0 && debugIdx != i)
      {
        continue;
      }
      pair<pair<vector<int> , vector<int> > , vector<pair<vector<int> , vector<
          double> > > > outAbinfo;

      DEBUG_MSG("Recomputing consensus for component " << i << " ...");

      abruijn::AbruijnGraph2::DEBUG_EXPANSION = false;//= i == debugIdx;

      abruijn::AbruijnGraph2 abGraph(m_inputAbruijn->at(i),
                                    *m_stars,
                                    &outAbinfo);

      if (outAbinfo.second.size() == 0)
      {
        m_contigShifts->consensus[i].resize(0);
        continue;
      }

      (*m_outputAbruijn)[i] = outAbinfo;

      abGraph.outputConsensusSpectrum(m_contigShifts->consensus[i]);

      m_contigShifts->consensus[i].setPeakTolerance(peakTol);

      if (i == debugIdx)
      {
        abGraph.saveGraphviz("postExpand.dot");
        DEBUG_MSG("Consensus spectrum for component " << i << ":");
        m_contigShifts->consensus[i].output(cerr);
        DEBUG_MSG("Abinfo for component " << i << ":");
        stringstream logMsg;
        logMsg << "Spectra: ";
        for (unsigned int j = 0; j < outAbinfo.first.first.size(); j++)
        {
          logMsg << outAbinfo.first.first[j] << "("
              << outAbinfo.first.second[j] << "), ";
        }
        DEBUG_VAR(logMsg.str());
        for (unsigned int j = 0; j < outAbinfo.second.size(); j++)
        {
          stringstream logMsg2;
          logMsg2 << "Vertex " << j << ": ";
          for (unsigned int k = 0; k < outAbinfo.second[j].first.size(); k++)
          {
            logMsg2 << outAbinfo.second[j].first[k] << "("
                << outAbinfo.second[j].second[k] << "), ";
          }
          DEBUG_VAR(logMsg2.str());
        }
      }
    }

    m_contigShifts->initializeFromAbinfo(m_contigShifts->consensus,
                                         *m_outputAbruijn,
                                         *m_stars,
                                         peakTol,
                                         peakTol);
    return true;
  }
Example #6
0
int main(int argc, char **argv)
{
#if 1
   setup_os_exceptions();
#else
   InstallExceptionHandler();
#endif
   ProcUIInit(&SaveCallback);

   socket_lib_init();
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT);
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
#endif
#ifndef IS_SALAMANDER
   VPADInit();
   WPADEnableURCC(true);
   WPADEnableWiiRemote(true);
   KPADInit();
#endif
   verbosity_enable();

   printf("starting\n");
   fflush(stdout);
   DEBUG_VAR(ARGV_PTR);
   if(ARGV_PTR && ((u32)ARGV_PTR < 0x01000000))
   {
      struct
      {
         u32 magic;
         u32 argc;
         char * argv[3];
      }*param = ARGV_PTR;
      if(param->magic == ARGV_MAGIC)
      {
         argc = param->argc;
         argv = param->argv;
      }
      ARGV_PTR = NULL;
   }

   DEBUG_VAR(argc);
   DEBUG_STR(argv[0]);
   DEBUG_STR(argv[1]);
   fflush(stdout);
#ifdef IS_SALAMANDER
   int salamander_main(int, char **);
   salamander_main(argc, argv);
#else
#if 1
#if 0
   int argc_ = 2;
//   char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.nes", NULL};
   char *argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.sfc", NULL};

   rarch_main(argc_, argv_, NULL);
#else
   rarch_main(argc, argv, NULL);
#endif
   do
   {
      unsigned sleep_ms = 0;
      int ret = runloop_iterate(&sleep_ms);

      if (ret == 1 && sleep_ms > 0)
         retro_sleep(sleep_ms);

      task_queue_ctl(TASK_QUEUE_CTL_WAIT, NULL);

      if (ret == -1)
         break;

   }
   while (1);

   main_exit(NULL);
#endif
#endif
   fflush(stdout);
   fflush(stderr);
   ProcUIShutdown();

#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_deinit();
#endif

   /* returning non 0 here can prevent loading a different rpx/elf in the HBL environment */
   return 0;
}
int InternalDatabaseReader::getQueryResults(CorbaClientAdaptor &adaptor) {
    int error(EXIT_SUCCESS);
    MutexMgr mutexMgr(mutex);
    const unsigned int numberOfColumns(sqlite3_column_count(SQLQueryStatement));
    adaptor.setNumberOfSubItems(numberOfColumns);

    // set Labels'name corresponding to the current query'fields
    for(unsigned int i=0;i<numberOfColumns;i++) {
        const char *label = sqlite3_column_name(SQLQueryStatement,i);
        DEBUG_MSG("label %u = %s",i,label);
        adaptor.setLabel(i,label);
    }

    // retrieve the result of the current query
    unsigned int row(0);
    std::string errorMsg;
    unsigned int nbRetries(0);
    do {
        error = sqlite3_step(SQLQueryStatement);
        DEBUG_VAR(error,"%d");
        switch(error) {
            case SQLITE_DONE:
                DEBUG_MSG("SQLITE_DONE");
                break;
            case SQLITE_ROW: {
                for(unsigned int column=0;column<numberOfColumns;column++) {
                    const int cellDataType = sqlite3_column_type(SQLQueryStatement,column);
                    DEBUG_VAR(cellDataType,"%d");
                    switch(cellDataType) {
                        case SQLITE_INTEGER: {
                            const int value = sqlite3_column_int(SQLQueryStatement,column);
                            DEBUG_VAR(value,"%d");
                            adaptor.setValue(row,column,value);
                        }
                        break;
                        case SQLITE_FLOAT: {
                            const double value = sqlite3_column_double(SQLQueryStatement,column);
                            DEBUG_VAR(value,"%f");
                            adaptor.setValue(row,column,value);
                        }
                        break;
                        case SQLITE_TEXT: {
                            const char *value = (char *)sqlite3_column_text(SQLQueryStatement,column);
                            DEBUG_VAR(value,"%s");
                            adaptor.setValue(row,column,value);
                        }
                        break;
                        case SQLITE_BLOB:
                            NOTICE_MSG("BLOB (not yet supported)");
                            break;
                        case SQLITE_NULL:
                            DEBUG_MSG("NULL");
                            // do Nothing
                            break;
                    } //switch(cellDataType)
                } //for(unsigned int column=0;column<numberOfColumns;column++)
            } //case SQLITE_ROW
            break;
            case SQLITE_BUSY:
                DEBUG_MSG("SQLITE_BUSY");
                nbRetries++;
                WARNING_MSG("error during query execution, database is lock, retrying...(%u)",nbRetries);
                break;
            case SQLITE_ERROR: {
                const char *msg = sqlite3_errmsg(database);
                ERROR_MSG("SQLITE_ERROR %s",msg);
                errorMsg = msg;
            }
            break;
            case SQLITE_MISUSE: {
                const char *msg = sqlite3_errmsg(database);
                ERROR_MSG("SQLITE_MISUSE %s",msg);
                errorMsg = msg;
            }
            break;
            default: {
                const char *msg = sqlite3_errmsg(database);
                ERROR_MSG("SQLite return code %d,  %s",msg);
                errorMsg = msg;
            }
            break;
        } // switch(error)
        ++row;
        DEBUG_MSG("new line (%u)",row);
    } while((SQLITE_ROW == error) || ((SQLITE_BUSY == error) && (nbRetries < NB_MAX_RETRIES)));
    sqlite3_reset(SQLQueryStatement);
    if (error != SQLITE_DONE) {
        throw exception(error,errorMsg);
    }
    return error;
}
Example #8
0
static inline int parseCmdLine(int argc, char *argv[],cmdLineParameters *parameters) {
    int error = EXIT_SUCCESS;
    char errorMsg[100];
    int optc;

    while (((optc = getopt_long (argc, argv, "f:o:e:hv", longopts, NULL)) != -1) && (EXIT_SUCCESS == error)) {       
       int param;
       switch (optc)
       {
       case 'f':
         param = facilityLevel(optarg);
         if (param != -1) {
            parameters->facility = param;
         } else {
           sprintf(errorMsg,"invalid facility parameter (%s)",optarg);
           printHelp(errorMsg);
           error = EINVAL;
         }
         break;
       case 'o':
         param = logLevel(optarg);
         if (param != -1) {
            parameters->stdOutLogLevel = param;
         } else {
           sprintf(errorMsg,"invalid stdout log level parameter (%s)",optarg);
           printHelp(errorMsg);
           error = EINVAL;
         }
         break;
       case 'e':
         param = logLevel(optarg);
         if (param != -1) {
            parameters->stdErrLogLevel = param;
         } else {
           sprintf(errorMsg,"invalid stdout log level parameter (%s)",optarg);
           printHelp(errorMsg);
           error = EINVAL;
         }
         break;
       case 'h':
         printHelp(NULL);
         exit(EXIT_SUCCESS);
         break;
       case 'v':
         printVersion();
         exit(EXIT_SUCCESS);
         break;
       case '?':
    	 DEBUG_VAR(optind,"%d");
         /* getopt_long already printed an error message.  */
         sprintf(errorMsg,"invalid parameter (%s) %d",optarg,optind);
         error = EINVAL;
         printHelp("");
         break;
       default: 
         sprintf(errorMsg,"invalid parameter (%s)",optarg);
         printHelp(errorMsg);
         error = EINVAL;
         break;
       } /* switch (optc) */
    } /* while (((optc = getopt_long (argc, argv, "f:o:e:hv", longopts, NULL)) != -1) && (EXIT_SUCCESS == error)) */
    DEBUG_VAR(optind,"%d");

    /*if (EXIT_SUCCESS == error) {
       error = setExternalCmdLine(argc,argv,parameters);
       if (error != EXIT_SUCCESS) {
          sprintf(errorMsg,"invalid external program parameter (%s)",optarg);
          printHelp(errorMsg);
       }
    }*/
    return error;
}
Example #9
0
void
button_press(XEvent ev)
{
  Client *c;
  int mouse_x, mouse_y;
  DEBUG_PRINT("got ButtonPress\n");
  get_mouse_x_y(&mouse_x, &mouse_y);
  if(ev.xbutton.window == root) {
    switch(ev.xbutton.button) {
      case Button2:
        system("gtk-switch &");
        break;
      default:
        system("gtk-panel &");
        break;
    }
  }
  c = find_client_by_frame(ev.xbutton.window);
  if (c) {
    Decal *decal;
    XEvent peek;

    decal = decal_at(c, ev.xbutton.x, ev.xbutton.y);
    XPeekEvent(disp, &peek);

    if (decal) {
      Decal *tmp_decal;
      XEvent tmp_ev;
      XMaskEvent(disp, ButtonReleaseMask, &tmp_ev);
      tmp_decal = decal_at(c, tmp_ev.xbutton.x, tmp_ev.xbutton.y);
      if(tmp_decal == decal)
        do_decal_fn(c, decal, ev.xbutton.button);
      return;
    }

    if (ev.xbutton.button == Button2) {
      shade_client(c);
      XSync(disp, False);
      icccm_send_configure_event(c);
      return;
    }

    if (ev.xbutton.button == Button3) {
      return;
    }

    /* the user let go immediately, so treat as click not drag */
    if (peek.type == ButtonRelease) {
      Window top;
      Client *tmp;
      char *name;

      top = x_get_top_window();
      XFetchName(disp, top, &name);
      DEBUG_VAR("top window: %s\n", name);
      XFree(name);

      tmp = find_client_by_frame(top);
      if (!tmp)
        DEBUG_PRINT("top window not found as frame\n");

      if (c->frame == top) {
        DEBUG_PRINT("client is on top\n");
        XLowerWindow(disp, c->frame);
      } else {
        DEBUG_PRINT("client is NOT on top\n");
        XRaiseWindow(disp, c->frame);
      }
    }

    /* motion before release detected, so drag and move */
    if (peek.type == MotionNotify) {
      drag_client(c, mouse_x, mouse_y);
      if (MOVE_AFTER_DRAG) {
        XMoveWindow(disp, c->frame, c->x, c->y);
      }
      XSync(disp,False);
      if (SEND_CONFIGURE_AFTER_DRAG) {
        icccm_send_configure_event(c);
      }
    }
  }
}
Example #10
0
void sc_lights_frmSun(SC_SCREEN* screen)
{
	if(screen.views.sun != NULL)
	{
		if(
		screen.settings.lights.sunPos.x == 0
		&& screen.settings.lights.sunPos.y == 0
		&& screen.settings.lights.sunPos.z == 0
		) //global sun
		{
			VECTOR distantSunPos;
			vec_for_angle(distantSunPos, sun_angle);
			vec_scale(distantSunPos, 9999999);
			screen.materials.sun.skill1 = floatv(distantSunPos.x);
			screen.materials.sun.skill2 = floatv(distantSunPos.y);
			screen.materials.sun.skill3 = floatv(distantSunPos.z);
		}
		else //local sun
		{
			screen.materials.sun.skill1 = floatv(screen.settings.lights.sunPos.x);
			screen.materials.sun.skill2 = floatv(screen.settings.lights.sunPos.y);
			screen.materials.sun.skill3 = floatv(screen.settings.lights.sunPos.z);
		}
		
		screen.materials.sun.skill4 = floatv(0); //local sun lightrange (not used)
		
		//sun color
		screen.materials.sun.skill5 = floatv(sun_color.red/255);
		screen.materials.sun.skill6 = floatv(sun_color.green/255);
		screen.materials.sun.skill7 = floatv(sun_color.blue/255);
		screen.materials.sun.skill8 = floatv(screen.views.main.clip_far);
		
		
		
		
		
		
		#ifndef SC_A7
			// PSSM main loop
			if(screen.settings.lights.sunPssmSplits>0 && screen.settings.lights.sunShadows == 1)
			{
				// update the views _after_ the camera was updated!
				//	proc_mode = PROC_LATE;
				
				// set up the split distances and the shadow view
				sc_lights_pssm_split(screen.views.main, screen.settings.lights.sunPssmSplits, screen.settings.lights.sunPssmSplitWeight, screen.settings.lights.sunShadowRange);
				//pssm_split(screen.views.main, screen.settings.lights.sunPssmSplits, screen.settings.lights.sunPssmSplitWeight);
				//pssm_viewcpy(screen.views.main, screen.views.sun);
				
				// set up the split view transformation matrices
				D3DXMATRIX matSplit[4];
				int i=0;
				for(i=0; i<screen.settings.lights.sunPssmSplits; i++) 
				{
					// look from the sun onto the scene			
					screen.views.sunShadowDepth[i]->pan = 180 + sun_angle.pan;
					screen.views.sunShadowDepth[i]->tilt = -sun_angle.tilt;
					vec_set(screen.views.sunShadowDepth[i]->x,sun_pos);
					
					// calculate the split view clipping borders and transformation matrix			
					view_to_split(screen.views.main, pssm_splitdist[i],pssm_splitdist[i+1], screen.views.sunShadowDepth[i], &matSplit[i]);
					LPD3DXEFFECT fx = screen.views.sunShadowDepth[i]->material->d3deffect;
					if(fx) fx->SetMatrix("matSplitViewProj",&matSplit[i]);
					
					// create a texture matrix from the split view proj matrix			
					D3DXMatrixMultiply(&matSplit[i],&matSplit[i],pssm_texscale(screen.settings.lights.sunShadowResolution));
					
					#ifdef DEBUG_PSSM		
						DEBUG_BMAP(screen.views.sunShadowDepth[i]->bmap,300 + i*220,0.2);
						var pssm_fps = 16/time_frame;
						DEBUG_VAR(pssm_fps,200);
						DEBUG_VAR(pssm_splitdist[i+1],220 + i*20);
					#endif
					//set depthmapshader maxDepth	
					screen.views.sunShadowDepth[i].material.skill4 = floatv(screen.views.sunShadowDepth[i].clip_far);
				}
				
				//put matrices to world space
				//mat_multiply(matSplit[0], matViewInv);
				// use a DX function to copy the 4 texture matrices to the shadow shader
				LPD3DXEFFECT fx = screen.views.sun->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				
				
				
				
				//same for shadowEdge acceleration
				LPD3DXEFFECT fx = screen.views.sunEdge->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				//and for the actual shadow view
				LPD3DXEFFECT fx = screen.views.sunShadow->material->d3deffect;
				if(fx) {
					fx->SetMatrixArray("matTex",matSplit,screen.settings.lights.sunPssmSplits);
					if(screen.views.sunShadowDepth[0] != NULL) fx->SetTexture("shadowTex1",screen.renderTargets.sunShadowDepth[0].d3dtex);
					if(screen.views.sunShadowDepth[1] != NULL) fx->SetTexture("shadowTex2",screen.renderTargets.sunShadowDepth[1].d3dtex);
					if(screen.views.sunShadowDepth[2] != NULL) fx->SetTexture("shadowTex3",screen.renderTargets.sunShadowDepth[2].d3dtex);
					if(screen.views.sunShadowDepth[3] != NULL) fx->SetTexture("shadowTex4",screen.renderTargets.sunShadowDepth[3].d3dtex);
					//fx->SetFloat("shadowBias", screen.settings.lights.sunShadowBias);
					//fx->SetInt("shadowmapSize", (screen.settings.lights.sunShadowResolution) );
				}
				
				
				
				
				screen.views.sun.material.skill4 = floatv(screen.views.sunShadowDepth[0].clip_far);
				
				#ifdef DEBUG_PSSM		
					DEBUG_BMAP(screen.views.sun->bmap,20,0.2);
				#endif
			}
		#endif
		
		
	}
}
Example #11
0
static void wiiu_font_render_line(
      video_frame_info_t *video_info,
      wiiu_font_t* font, const char* msg, unsigned msg_len,
      float scale, const unsigned int color, float pos_x,
      float pos_y, unsigned text_align)
{
   unsigned i;
   wiiu_video_t* wiiu = (wiiu_video_t*)video_driver_get_ptr(false);
   unsigned width   = video_info->width;
   unsigned height  = video_info->height;
   int x            = roundf(pos_x * width);
   int y            = roundf((1.0f - pos_y) * height);
   int delta_x      = 0;
   int delta_y      = 0;

   if(wiiu->vertex_cache.current + (msg_len * 4) > wiiu->vertex_cache.size)
      return;

   switch (text_align)
   {
      case TEXT_ALIGN_RIGHT:
         x -= wiiu_font_get_message_width(font, msg, msg_len, scale);
         break;

      case TEXT_ALIGN_CENTER:
         x -= wiiu_font_get_message_width(font, msg, msg_len, scale) / 2;
         break;
   }

   position_t* pos = wiiu->vertex_cache.positions + wiiu->vertex_cache.current;
   tex_coord_t* coord = wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current;

   for (i = 0; i < msg_len; i++)
   {
      int off_x, off_y, tex_x, tex_y, width, height;
      const char* msg_tmp            = &msg[i];
      unsigned code                  = utf8_walk(&msg_tmp);
      unsigned skip                  = msg_tmp - &msg[i];

      if (skip > 1)
         i += skip - 1;

      const struct font_glyph* glyph =
         font->font_driver->get_glyph(font->font_data, code);

      if (!glyph) /* Do something smarter here ... */
         glyph = font->font_driver->get_glyph(font->font_data, '?');

      if (!glyph)
         continue;

      off_x  = glyph->draw_offset_x;
      off_y  = glyph->draw_offset_y;
      tex_x  = glyph->atlas_offset_x;
      tex_y  = glyph->atlas_offset_y;
      width  = glyph->width;
      height = glyph->height;


      float x0 = x + off_x + delta_x * scale;
      float y0 = y + off_y + delta_y * scale + height * scale;
      float u0 = tex_x;
      float v0 = tex_y;
      float x1 = x0 + width * scale;
      float y1 = y0 - height * scale;
      float u1 = u0 + width;
      float v1 = v0 + height;

      pos[0].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;
      pos[0].y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f;
      pos[1].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
      pos[1].y = (-2.0f * y0 / wiiu->color_buffer.surface.height) + 1.0f;
      pos[2].x = (2.0f * x1 / wiiu->color_buffer.surface.width) - 1.0f;;
      pos[2].y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f;
      pos[3].x = (2.0f * x0 / wiiu->color_buffer.surface.width) - 1.0f;;
      pos[3].y = (-2.0f * y1 / wiiu->color_buffer.surface.height) + 1.0f;
      pos += 4;

      coord[0].u = u0 / font->texture.surface.width;
      coord[0].v = v1 / font->texture.surface.height;
      coord[1].u = u1 / font->texture.surface.width;
      coord[1].v = v1 / font->texture.surface.height;
      coord[2].u = u1 / font->texture.surface.width;
      coord[2].v = v0 / font->texture.surface.height;
      coord[3].u = u0 / font->texture.surface.width;
      coord[3].v = v0 / font->texture.surface.height;
      coord += 4;

      delta_x += glyph->advance_x;
      delta_y += glyph->advance_y;
   }

   int count = pos - wiiu->vertex_cache.positions - wiiu->vertex_cache.current;

   if (!count)
      return;


   GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.positions + wiiu->vertex_cache.current, count * sizeof(position_t));
   GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.tex_coords + wiiu->vertex_cache.current, count * sizeof(tex_coord_t));

   if(font->atlas->dirty)
   {
      for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++)
         memcpy(font->texture.surface.image + (i * font->texture.surface.pitch),
                font->atlas->buffer + (i * font->atlas->width), font->atlas->width);

      GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, font->texture.surface.image,
                    font->texture.surface.imageSize);
      font->atlas->dirty = false;
   }


#if 0
   printf("%s\n", msg);
   DEBUG_VAR(color);
#endif

   GX2SetPixelTexture(&font->texture, wiiu->shader->sampler.location);

   GX2SetBlendConstantColor(((color >> 0) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f,
                            ((color >> 16) & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);

   GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_BLEND_FACTOR, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD,
                      GX2_ENABLE,          GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD);

   GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, count, wiiu->vertex_cache.current, 1);

   GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD,
                      GX2_ENABLE,          GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD);

   wiiu->vertex_cache.current = pos - wiiu->vertex_cache.positions;
}