Esempio n. 1
0
int BecherConfig::Arg(int argc, char *argv[])
{
	if (strcmp(argv[0],"-h") == 0)
	{
		ShowUsage("Becher [-conf] [-c <config>] [-d <root>]");
		m_continue = false;
		return argc;
	}

    if (strcmp(argv[0],"-conf") == 0)
    {
        m_showdlg = true;
        // nastaveni na konfig
        return 2;
    }

    if (strcmp(argv[0],"-c") == 0)
    {
        // nastaveni konfigu
        if (argc < 2)
        {
            HoeGame::BaseConsole::Printf("Config file requied.");
            return -1;
        }
        v_config.Set(argv[1]); 
        // nastaveni na konfig
        return 2;
    }

    if (strcmp(argv[0],"-d") == 0)
    {
        // nastaveni konfigu
        if (argc < 2)
        {
            HoeGame::BaseConsole::Printf("Directory requied.");
            return -1;
        }
        HoeGame::BaseConsole::Printf("Changing directory to '%s'", argv[1]);
        // nastaveni cesty
        HoeGame::SetRootDir(argv[1]);
        return 2;
    }
    
	// posledni
	if (argc == 1)
	{
		v_level.Set(argv[0]);
	}
	return 1;
}
Esempio n. 2
0
void RabidEngine::OnIdle()
{
  g_timer.Update();
  const float dt = g_timer.GetTimeChange();

  g_console->Update(dt);




  Transformation view;
  view.Rotate().FromEulerXYZ(cl_camrotx.GetFloat(),
                             cl_camroty.GetFloat(),
                             cl_camrotz.GetFloat());

  // move
  const Vector3f forward = -view.Rotate().GetColumn(2);
  const Vector3f right   =  view.Rotate().GetColumn(0);

  const float vel = 50.0 * dt;
  if(keyState[B_FORWARD])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + forward.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + forward.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + forward.z * vel);
  }
  if(keyState[B_BACKWARD])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + -forward.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + -forward.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + -forward.z * vel);
  }
  if(keyState[B_RIGHT])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + right.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + right.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + right.z * vel);
  }
  if(keyState[B_LEFT])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + -right.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + -right.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + -right.z * vel);
  }
  if(keyState[B_RENDER])
  {
    done.Set("0");
    keyState[B_RENDER] = 0;
  }
  if(keyState[B_LIGHT_MODE])
  {
    if(r_resid.GetBool())
      r_resid.Set("0");
    else
      r_resid.Set("1");
    keyState[B_LIGHT_MODE] = 0;
  }
  if(keyState[B_TOGGLE_BRIGHTEST])
  {
    if(r_showbrightest.GetBool())
      r_showbrightest.Set("0");
    else
      r_showbrightest.Set("1");
    keyState[B_TOGGLE_BRIGHTEST] = 0;
  }






  static int pass;
  static int surf = -1;
  static int brightest;
  static int patches;
  if(done.GetBool())
  {
  }
  else
  {
    if(pass == 0)
    {
      // clear accumulation buffers
      for(unsigned int i = 0; i < surfaces.Size(); i++)
      {
//          if(surfaces[i]->GetType() != S_LIGHT)
//            surfaces[i]->ClearAccum();
      }
    }


    if(surf >= (int)surfaces.Size())
    {
      surf = -2;
      pass++;
      done.Set("1");
    }
    else if(surf == -1)
    {
      // Find Brightest Surface
      float maxPower = 0.0;
      for(unsigned int i = 0; i < surfaces.Size(); i++)
      {
        float p = surfaces[i]->GetPower();
        if(p > maxPower)
        {
          brightest = i;
          maxPower = p;
        }
      }

      for(int i = 0; i < lights.Size(); i++)
        delete lights[i];
      lights.Resize(0);

      surfaces[brightest]->CreateLights(lights);
    }
    else
    {
      Surface* lsurf = surfaces[surf];

      bool skip = false;
      // lights can't receive light
      if(lsurf->GetType() == S_LIGHT)
        skip = true;

      // surface can light itself
      if(!skip && surf == brightest)
      {
        if(r_resid.GetBool())
          lsurf->CopyResidualToLightMap();
        skip = true;
      }



      if(!skip)
      {
        // Render each sub-light's contribution
        for(unsigned int l = 0; l < lights.Size(); l++)
        {
          Vector3f& p = lights[l]->p;
          Vector3f& d = lights[l]->d;
          float     I = lights[l]->I;

          // light is on wrong side of surface
          if(Dot(p - lsurf->c, lsurf->N) < 0.1)
            continue;

          g_renderer->SetLight(0, p.x, p.y, p.z);
          g_renderer->SetLightDir(0, d.x, d.y, d.z);
          g_renderer->SetLightIntensity(0, I);
          g_renderer->SetLightFraction(0, 1.0 / (float)lights.Size());

          lsurf->Frame(p);
          lsurf->CreateLightMap(p, d, surfaces);
          lsurf->AccumulateResidualLight();
          lsurf->AccumulateLight();
          g_renderer->SetViewMatrix(0);
          patches += lsurf->GetNumPatches();
        }

        r_resid.Set(r_resid.GetBool() ? "1" : "0");
      }
    }
    surf++;
  }


  if(r_resid.Changed())
  {
    for(int i = 0; i < surfaces.Size(); i++)
    {
      Surface* lsurf = surfaces[i];
      lsurf->Frame(lsurf->c + lsurf->N*10.0);

      if(r_resid.GetBool())
        lsurf->CopyResidualToLightMap();
      else
        lsurf->CopyAccumToLightMap();
    }
  }






  // Render normal view
  view.Translate() = Vector3f(cl_camx.GetFloat(),
                              cl_camy.GetFloat(),
                              cl_camz.GetFloat());

  view = view.Inverse();
  g_renderer->SetViewport(0,0, GetWidth(),GetHeight());
  g_renderer->SetViewMatrix(view);
  g_renderer->SetProjectionMatrix(0);
  g_renderer->SetClearColor(0.25f, 0.25f, 0.35f, 1.0f);
  g_renderer->BindMaterial(0);
  g_renderer->Clear(R_COLOR_BUFFER | R_DEPTH_BUFFER);
  g_renderer->SetColor(1,1,1);


  int bsurf = 0;
  float maxPower = 0.0;
  for(unsigned int i = 0; i < surfaces.Size(); i++)
  {
    float p = surfaces[i]->GetPower();
    if(p > maxPower)
    {
      bsurf = i;
      maxPower = p;
    }
  }


  // draw all surfaces normally
  for(unsigned int i = 0; i < surfaces.Size(); i++)
  {
    if(r_showbrightest.GetBool())
    {
      if(i == bsurf)
        g_renderDevice->SetColor(1.0, 1.0, 0.7);
      else
        g_renderDevice->SetColor(1,1,1);
    }
    surfaces[i]->Render();
  }

  g_console->Draw(g_renderer);

  g_renderer->DrawTextP(15, 50, 16, r_resid.GetBool() ? "Residual" : "Accumulation");
  g_renderer->DrawTextP(15, 30, 16, "Step: %d", pass);
  g_renderer->DrawTextP(15, 10, 16, "Patches: %d", patches);
  g_materialSystem->BindMaterial(logo);
  g_renderer->DrawRect(GetWidth()-200, 0, 200, 50, 0,0,1,1);

  g_renderer->Flip();
}
Esempio n. 3
0
int Console::OnKeyPress(int key)
{
  if(key >= ' ' && key < 127)
  {
    if(lshift || rshift)
      cmd[cmdPos++] = (char)shiftTable[key-32];
    else
      cmd[cmdPos++] = (char)key;
  }
  else if(key == K_BACKSPACE)
  {
    cmdPos--;
    if(cmdPos < 2)
      cmdPos = 2;

    cmd[cmdPos] = 0;
  }
  else if(key == K_ENTER)
  {
    if(cmd[2] == 0)
      return true;

    //exec
    char lcmd[256];
    cmd[cmdPos] = '\0';
    strcpy(lcmd, &cmd[2]);
    char* name = strtok(lcmd, " ");
    char* args;
    if ( (&cmd[2])[strlen(name)] == 0 )
      args = NULL;
    else
      args = lcmd + strlen(name) + 1;
    if(!g_commandSystem->Execute(name, args))
    {
      CVar* cvar = g_cvarSystem->Find(name);
      // cvar
      if(args)
      {
        if(cvar)
          cvar->Set(args);
      }

      if(cvar)
        g_common->Print("%s = %s", name, cvar->GetString());
    }
    else
    {
    }

    memset(cmd, 0, 256);
    cmd[0] = '>';
    cmd[1] = ' ';
    cmdPos = 2;
  }

  else if(key == K_LSHIFT)
  {
    lshift = 1;
  }
  else if(key == K_RSHIFT)
  {
    rshift = 1;
  }
  else if(key == K_TAB)
  {
    const char* txt = 0;
    const char* cCmd  = g_commandSystem->Complete(&cmd[2]);
    const char* cCvar = g_cvarSystem->Complete(&cmd[2]);

    if(cCmd)
      txt = cCmd;
    else if(cCvar)
      txt = cCvar;

    if(txt)
    {
      memset(cmd, 0, 256);
      cmd[0] = '>';
      cmd[1] = ' ';

      strcpy(&cmd[2], txt);
      cmd[strlen(txt)+2] = ' ';
      cmdPos = (int)(strlen(txt)+3);
    }
  }

  // command cycling
  else if(key == K_UP)
  {
    cmdIdx--;
    if(cmdIdx < 0)
      cmdIdx = 0;
    
    memset(cmd, 0, 256);
    cmd[0] = '>';
    cmd[1] = ' ';
  }
  else if(key == K_DOWN)
  {
  }


  return 1;
}