예제 #1
0
    bool CurvedFactory::Load (iDocumentNode* node, iSyntaxService* syn)
    {
        width = node->GetAttributeValueAsFloat ("width");
        if (fabs (width) < .0001) width = 1.0;
        sideHeight = node->GetAttributeValueAsFloat ("sideheight");
        if (fabs (sideHeight) < 0.0001f) sideHeight = 0.2f;
        csString materialName = node->GetAttributeValue ("material");
        SetMaterial (materialName);
        anchorPoints.DeleteAll ();
        csRef<iDocumentNodeIterator> it = node->GetNodes ();
        while (it->HasNext ())
        {
            csRef<iDocumentNode> child = it->Next ();
            if (child->GetType () != CS_NODE_ELEMENT) continue;
            csString value = child->GetValue ();
            if (value == "p")
            {
                csVector3 pos, front (0, 0, 1), up (0, 1, 0);
                csString vector = child->GetAttributeValue ("pos");
                if (vector.Length () > 0)
                    csScanStr ((const char*)vector, "%f %f %f", &pos.x, &pos.y, &pos.z);
                vector = child->GetAttributeValue ("front");
                if (vector.Length () > 0)
                    csScanStr ((const char*)vector, "%f %f %f", &front.x, &front.y, &front.z);
                vector = child->GetAttributeValue ("up");
                if (vector.Length () > 0)
                    csScanStr ((const char*)vector, "%f %f %f", &up.x, &up.y, &up.z);
                AddPoint (pos, front, up);
            }
        }

        return true;
    }
예제 #2
0
bool RoomFactory::Load (iDocumentNode* node, iSyntaxService* syn)
{
  csString materialName = node->GetAttributeValue ("material");
  SetMaterial (materialName);
  anchorRooms.DeleteAll ();
  csRef<iDocumentNodeIterator> it = node->GetNodes ();
  while (it->HasNext ())
  {
    csRef<iDocumentNode> child = it->Next ();
    if (child->GetType () != CS_NODE_ELEMENT) continue;
    csString value = child->GetValue ();
    if (value == "r")
    {
      csVector3 tl, br;
      csString vector = child->GetAttributeValue ("tl");
      if (vector.Length () > 0)
	csScanStr ((const char*)vector, "%f %f %f", &tl.x, &tl.y, &tl.z);
      vector = child->GetAttributeValue ("br");
      if (vector.Length () > 0)
	csScanStr ((const char*)vector, "%f %f %f", &br.x, &br.y, &br.z);
      AddRoom (tl, br);
    }
  }

  return true;
}
예제 #3
0
bool DynamicWorldLoader::ParseCurve (iDocumentNode* node, iPcDynamicWorld* dynworld)
{
  csString name = node->GetAttributeValue ("name");
  float width = 1.0f;
  if (node->GetAttribute ("width"))
    width = node->GetAttributeValueAsFloat ("width");
  float sideheight = .1f;
  if (node->GetAttribute ("sideheight"))
    sideheight = node->GetAttributeValueAsFloat ("sideheight");

  iCurvedFactoryTemplate* cft = curvedMeshCreator->AddCurvedFactoryTemplate (name);
  if (!cft)
  {
    synldr->ReportError ("dynworld.loader", node,
	"Could not add curved factory template '%s'!", name.GetData ());
    return false;
  }
  cft->SetCharacteristics (width, sideheight);

  csRef<iDocumentNodeIterator> it = node->GetNodes ();
  while (it->HasNext ())
  {
    csRef<iDocumentNode> child = it->Next ();
    if (child->GetType () != CS_NODE_ELEMENT) continue;
    csStringID id = xmltokens.Request (child->GetValue ());
    switch (id)
    {
      case XMLTOKEN_ATTR:
	cft->SetAttribute (child->GetAttributeValue ("name"),
	    child->GetAttributeValue ("value"));
	break;
      case XMLTOKEN_MATERIAL:
	cft->SetMaterial (child->GetAttributeValue ("name"));
	break;
      case XMLTOKEN_POINT:
	{
	  csVector3 pos (0), front (0, 0, 1), up (0, 1, 0);
	  csString vector = child->GetAttributeValue ("pos");
	  if (vector.Length () > 0)
	    csScanStr ((const char*)vector, "%f %f %f", &pos.x, &pos.y, &pos.z);
	  vector = child->GetAttributeValue ("front");
	  if (vector.Length () > 0)
	    csScanStr ((const char*)vector, "%f %f %f", &front.x, &front.y, &front.z);
	  vector = child->GetAttributeValue ("up");
	  if (vector.Length () > 0)
	    csScanStr ((const char*)vector, "%f %f %f", &up.x, &up.y, &up.z);
	  cft->AddPoint (pos, front, up);
	}
	break;
      default:
        synldr->ReportBadToken (child);
	return false;
    }
  }
  return true;
}
예제 #4
0
파일: lights.cpp 프로젝트: Tank-D/Shards
void WalkTestLights::AddLight (const char* arg)
{
  csVector3 dir (0,0,0);
  csVector3 pos = walktest->views->GetCamera ()->GetTransform ().This2Other (dir);
  csRef<iLight> dyn;

  bool rnd;
  float r, g, b, radius;
  if (arg && csScanStr (arg, "%f,%f,%f,%f", &r, &g, &b, &radius) == 4)
  {
    dyn = walktest->Engine->CreateLight ("", pos,
      radius, csColor (r, g, b), CS_LIGHT_DYNAMICTYPE_DYNAMIC);
    rnd = false;
  }
  else
  {
    dyn = walktest->Engine->CreateLight ("", pos,
      6, csColor (1, 1, 1), CS_LIGHT_DYNAMICTYPE_DYNAMIC);
    rnd = true;
  }
  iLightList* ll = walktest->views->GetCamera ()->GetSector ()->GetLights ();
  ll->Add (dyn);
  dynamic_lights.Push (dyn);
  if (rnd)
    AttachRandomLight (dyn);
  walktest->Report (CS_REPORTER_SEVERITY_NOTIFY, "Dynamic light added.");
}
예제 #5
0
const char* csConditionEvaluator::ResolveExpValue (const csExpressionToken& value,
  CondOperand& operand)
{
  if (value.type == tokenNumber)
  {
    csString number;
    number.Append (value.tokenStart, value.tokenLen);
    bool isFloat = (strpbrk (number, ".eE") != 0);
    if (isFloat)
    {
      char dummy;
      if (csScanStr (number, "%f%c", &operand.floatVal, &dummy) != 1)
      {
	return SetLastError ("Malformed float value: %s",
	  CS::Quote::Single (number.GetData()));
      }
      operand.type = operandFloat;
    }
    else
    {
      char dummy;
      if (sscanf (number, "%d%c", &operand.intVal, &dummy) != 1)
      {
	return SetLastError ("Malformed int value: %s",
	  CS::Quote::Single (number.GetData()));
      }
      operand.type = operandInt;
    }
    return 0;
  }
  else if (value.type == tokenIdentifier)
  {
    if (TokenEquals (value.tokenStart, value.tokenLen, "true"))
    {
      operand.type = operandBoolean;
      operand.boolVal = true;
      return 0;
    }
    else if (TokenEquals (value.tokenStart, value.tokenLen, "false"))
    {
      operand.type = operandBoolean;
      operand.boolVal = false;
      return 0;
    }
    else
    {
      return SetLastError ("Unknown identifier %s",
	CS::Quote::Single (csExpressionToken::Extractor (value).Get ()));
    }
  }
  else
  {
    return SetLastError ("Value of %s of type %s",
      CS::Quote::Single (csExpressionToken::Extractor (value).Get ()),
      CS::Quote::Single (csExpressionToken::TypeDescription (value.type)));
  }

  CS_ASSERT (false);
  return 0;
}
예제 #6
0
float csXmlReadNode::GetAttributeValueAsFloat (const char* name, float defaultValue)
{
  TrDocumentAttribute* a = GetAttributeInternal (name);
  if (!a) return defaultValue;
  float f;
  csScanStr (a->Value (), "%f", &f);
  return f;
}
예제 #7
0
float csXmlReadNode::GetContentsValueAsFloat ()
{
  const char* v = GetContentsValue ();
  if (!v) return 0;
  float val = 0.0;
  csScanStr (v, "%f", &val);
  return val;
}
예제 #8
0
bool DynamicWorldLoader::ParseRoom (iDocumentNode* node, iPcDynamicWorld* dynworld)
{
  csString name = node->GetAttributeValue ("name");

  iRoomFactoryTemplate* cft = roomMeshCreator->AddRoomFactoryTemplate (name);
  if (!cft)
  {
    synldr->ReportError ("dynworld.loader", node,
	"Could not add room factory template '%s'!", name.GetData ());
    return false;
  }

  csRef<iDocumentNodeIterator> it = node->GetNodes ();
  while (it->HasNext ())
  {
    csRef<iDocumentNode> child = it->Next ();
    if (child->GetType () != CS_NODE_ELEMENT) continue;
    csStringID id = xmltokens.Request (child->GetValue ());
    switch (id)
    {
      case XMLTOKEN_ATTR:
	cft->SetAttribute (child->GetAttributeValue ("name"),
	    child->GetAttributeValue ("value"));
	break;
      case XMLTOKEN_MATERIAL:
	cft->SetMaterial (child->GetAttributeValue ("name"));
	break;
      case XMLTOKEN_ROOM:
	{
	  csVector3 tl, br;
	  csString vector = child->GetAttributeValue ("tl");
	  if (vector.Length () > 0)
	    csScanStr ((const char*)vector, "%f %f %f", &tl.x, &tl.y, &tl.z);
	  vector = child->GetAttributeValue ("br");
	  if (vector.Length () > 0)
	    csScanStr ((const char*)vector, "%f %f %f", &br.x, &br.y, &br.z);
	  cft->AddRoom (tl, br);
	}
	break;
      default:
        synldr->ReportBadToken (child);
	return false;
    }
  }
  return true;
}
예제 #9
0
파일: particles.cpp 프로젝트: garinh/cs
void WalkTestParticleDemos::Fountain (WalkTest* Sys, const char* arg)
{
  char txtname[100];
  int cnt = 0;
  int num = 0;
  if (arg) cnt = csScanStr (arg, "%s,%d", txtname, &num);
  if (cnt <= 1) num = 400;
  if (cnt <= 0) strcpy (txtname, "spark");
  add_particles_fountain (Sys, Sys->views->GetCamera ()->GetSector (),
      txtname, num, Sys->views->GetCamera ()->GetTransform ().GetOrigin ()-
      csVector3 (0, Sys->cfg_body_height, 0));
}
예제 #10
0
파일: particles.cpp 프로젝트: garinh/cs
void WalkTestParticleDemos::Explosion (WalkTest* Sys, const char* arg)
{
  char txtname[100];
  int cnt = 0;
  if (arg) cnt = csScanStr (arg, "%s", txtname);
  if (cnt != 1)
  {
    Sys->Report (CS_REPORTER_SEVERITY_NOTIFY,
      "Expected parameter 'texture'!");
  }
  else
    add_particles_explosion (Sys, Sys->views->GetCamera ()->GetSector (),
      Sys->Engine,
      Sys->views->GetCamera ()->GetTransform ().GetOrigin (), txtname);
}
예제 #11
0
파일: particles.cpp 프로젝트: garinh/cs
void WalkTestParticleDemos::Snow (WalkTest* Sys, const char* arg)
{
  char txtname[100];
  int cnt = 0;
  /* speed and num must be preset to prevent compiler warnings
   * on some systems. */
  int num = 0;
  float speed = 0;
  if (arg) cnt = csScanStr (arg, "%s,%d,%f", txtname, &num, &speed);
  if (cnt <= 2) speed = 0.3f;
  if (cnt <= 1) num = 500;
  if (cnt <= 0) strcpy (txtname, "snow");
  add_particles_snow (Sys, Sys->views->GetCamera ()->GetSector (),
      txtname, num, speed);
}
예제 #12
0
bool csShaderProgram::ProgramParamParser::ParseProgramParam (
  iDocumentNode* node, ProgramParam& param, uint types)
{
  const char* type = node->GetAttributeValue ("type");
  if (type == 0)
  {
    synsrv->Report ("crystalspace.graphics3d.shader.common",
      CS_REPORTER_SEVERITY_WARNING,
      node,
      "No %s attribute",
      CS::Quote::Single ("type"));
    return false;
  }

  // Var for static data
  csRef<csShaderVariable> var;
  var.AttachNew (new csShaderVariable (CS::InvalidShaderVarStringID));

  ProgramParamType paramType = ParamInvalid;
  if (strcmp (type, "shadervar") == 0)
  {
    const char* value = node->GetContentsValue();
    if (!value)
    {
      synsrv->Report ("crystalspace.graphics3d.shader.common",
	CS_REPORTER_SEVERITY_WARNING,
	node,
	"Node has no contents");
      return false;
    }
    
    CS::Graphics::ShaderVarNameParser nameParse (value);
    param.name = stringsSvName->Request (nameParse.GetShaderVarName());
    for (size_t n = 0; n < nameParse.GetIndexNum(); n++)
    {
      param.indices.Push (nameParse.GetIndexValue (n));
    }
    param.valid = true;
    return true;
  }
  else if (strcmp (type, "int") == 0)
  {
    paramType = ParamInt;
  }
  else if (strcmp (type, "float") == 0)
  {
    paramType = ParamFloat;
  }
  else if (strcmp (type, "vector2") == 0)
  {
    paramType = ParamVector2;
  }
  else if (strcmp (type, "vector3") == 0)
  {
    paramType = ParamVector3;
  }
  else if (strcmp (type, "vector4") == 0)
  {
    paramType = ParamVector4;
  }
  else if (strcmp (type, "matrix") == 0)
  {
    paramType = ParamMatrix;
  }
  else if (strcmp (type, "transform") == 0)
  {
    paramType = ParamTransform;
  }
  else if ((strcmp (type, "expression") == 0) || (strcmp (type, "expr") == 0))
  {
    // Parse exp and save it
    csRef<iShaderVariableAccessor> acc = synsrv->ParseShaderVarExpr (node);
    var->SetAccessor (acc);
    param.var = var;
    param.valid = true;
    return true;
  }
  else if (strcmp (type, "array") == 0)
  {
    csArray<ProgramParam> allParams;
    ProgramParam tmpParam;
    csRef<iDocumentNodeIterator> it = node->GetNodes ();
    while (it->HasNext ())
    {
      csRef<iDocumentNode> child = it->Next ();
      ParseProgramParam (child, tmpParam, types & 0x3F);
      allParams.Push (tmpParam);
    }

    //Save the params
    var->SetType (csShaderVariable::ARRAY);
    var->SetArraySize (allParams.GetSize ());

    for (uint i = 0; i < allParams.GetSize (); i++)
    {
      var->SetArrayElement (i, allParams[i].var);
    }
    paramType = ParamArray;
  }
  else 
  {
    synsrv->Report ("crystalspace.graphics3d.shader.common",
      CS_REPORTER_SEVERITY_WARNING,
      node,
      "Unknown type %s", CS::Quote::Single (type));
    return false;
  }

  if (!(types & paramType))
  {
    synsrv->Report ("crystalspace.graphics3d.shader.common",
      CS_REPORTER_SEVERITY_WARNING,
      node,
      "Type %s not supported by this parameter", CS::Quote::Single (type));
    return false;
  }

  const uint directValueTypes = ParamInt | ParamFloat | ParamVector2
    | ParamVector3 | ParamVector4 | ParamMatrix | ParamTransform;
  switch (paramType & directValueTypes)
  {
    case ParamInvalid:
      return false;
      break;
    case ParamInt:
      {
	int x = node->GetContentsValueAsInt ();
	var->SetValue (x);
      }
      break;
    case ParamFloat:
      {
	float x = node->GetContentsValueAsFloat ();
	var->SetValue (x);
      }
      break;
    case ParamVector2:
      {
	float x, y;
	const char* value = node->GetContentsValue();
	if (!value)
	{
	  synsrv->Report ("crystalspace.graphics3d.shader.common",
	    CS_REPORTER_SEVERITY_WARNING,
	    node,
	    "Node has no contents");
	  return false;
	}
	if (csScanStr (value, "%f,%f", &x, &y) != 2)
	{
	  synsrv->Report ("crystalspace.graphics3d.shader.common",
	    CS_REPORTER_SEVERITY_WARNING,
	    node,
	    "Couldn't parse vector2 %s", CS::Quote::Single (value));
	  return false;
	}
	var->SetValue (csVector2 (x,y));
      }
      break;
    case ParamVector3:
      {
	float x, y, z;
	const char* value = node->GetContentsValue();
	if (!value)
	{
	  synsrv->Report ("crystalspace.graphics3d.shader.common",
	    CS_REPORTER_SEVERITY_WARNING,
	    node,
	    "Node has no contents");
	  return false;
	}
	if (csScanStr (value, "%f,%f,%f", &x, &y, &z) != 3)
	{
	  synsrv->Report ("crystalspace.graphics3d.shader.common",
	    CS_REPORTER_SEVERITY_WARNING,
	    node,
	    "Couldn't parse vector3 %s", CS::Quote::Single (value));
	  return false;
	}
	var->SetValue (csVector3 (x,y,z));
      }
      break;
    case ParamVector4:
      {
	float x, y, z, w;
	const char* value = node->GetContentsValue();
	if (!value)
	{
	  synsrv->Report ("crystalspace.graphics3d.shader.common",
	    CS_REPORTER_SEVERITY_WARNING,
	    node,
	    "Node has no contents");
	  return false;
	}
	if (csScanStr (value, "%f,%f,%f,%f", &x, &y, &z, &w) != 4)
	{
	  synsrv->Report ("crystalspace.graphics3d.shader.common",
	    CS_REPORTER_SEVERITY_WARNING,
	    node,
	    "Couldn't parse vector4 %s", CS::Quote::Single (value));
	  return false;
	}
	var->SetValue (csVector4 (x,y,z,w));
      }
      break;
    case ParamMatrix:
      {
        csMatrix3 matrix;
	if (!synsrv->ParseMatrix (node, matrix))
	  return false;
        var->SetValue (matrix);
      }
      break;
    case ParamTransform:
      {
        csReversibleTransform t;
        csRef<iDocumentNode> matrix_node = node->GetNode ("matrix");
        if (matrix_node)
        {
          csMatrix3 m;
          if (!synsrv->ParseMatrix (matrix_node, m))
            return false;
          t.SetT2O (m);
        }
        csRef<iDocumentNode> vector_node = node->GetNode ("v");
        if (vector_node)
        {
          csVector3 v;
          if (!synsrv->ParseVector (vector_node, v))
            return false;
          t.SetOrigin (v);
        }
        var->SetValue (t);
      }
      break;
  }
  
  param.var = var;
  param.valid = true;
  return true;
}