Home - Forums - Documentation - Gallery - Bugs

$NAME$ should be replaced by name of the plugin. Needs only different capitalizing sometimes. You can use it manually or as snippet in KDevelop.

Interface


/*
    Crystal Space Entity Layer
    Copyright (C) 2007 by XXX

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __CEL_PF_$NAME$__
#define __CEL_PF_$NAME$__

#include "cstypes.h"
#include "csutil/scf.h"

/**
 * $NAME$ property class.
 *
 * This property class supports the following actions (add prefix
 * 'cel.action.' to get the ID of the action and add prefix 'cel.parameter.'
 * to get the ID of the parameter):
 *
 * This property class supports the following properties (add prefix
 * 'cel.property.' to get the ID of the property:
 */

struct iPc$NAME$ : public virtual iBase
{
  SCF_INTERFACE (iPc$NAME$, 0, 0, 1);
};

#endif // __CEL_PF_$NAME$__

Header


/*
    Crystal Space Entity Layer
    Copyright (C) 2007 by XXX

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __CEL_PF_$NAME$FACT__
#define __CEL_PF_$NAME$FACT__

#include "cstypes.h"
#include "csutil/scf.h"
#include "physicallayer/propclas.h"
#include "physicallayer/propfact.h"
#include "physicallayer/facttmpl.h"
#include "celtool/stdpcimp.h"
#include "celtool/stdparams.h"

struct iObjectRegistry;

/**
 * Factory for $NAME$.
 */
CEL_DECLARE_FACTORY($NAME$)

/**
 * This is a $NAME$ property class.
 */
class celPc$NAME$ : public scfImplementationExt1<
	celPc$NAME$, celPcCommon, iPc$NAME$>
{
private:
  // parameters
  static csStringID id_a;
  static csStringID id_b;
  static csStringID id_c;
  celOneParameterBlock* params;

  // actions
  enum actionids
  {
    action_a = 0,
    action_b,
    action_c
  };

  // properties
  enum propids
  {
    propid_a = 0,
    propid_b,
    propid_c
  };
  static PropertyHolder propinfo;

public:
  celPc$NAME$ (iObjectRegistry* object_reg);
  virtual ~celPc$NAME$ ();
  virtual const char* GetName () const { return "pc$NAME$"; }
  virtual csPtr<iCelDataBuffer> Save ();
  virtual bool Load (iCelDataBuffer* databuf);
  virtual bool PerformActionIndexed (int, iCelParameterBlock* params,
      celData& ret);
  virtual bool GetPropertyIndexed (int, const char*&);
};

#endif // __CEL_PF_$NAME$FACT__

Code


/*
    Crystal Space Entity Layer
    Copyright (C) 2007 by XXX

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "cssysdef.h"
#include "plugins/propclass/$NAME$/$NAME$.h"
#include "physicallayer/pl.h"
#include "physicallayer/entity.h"
#include "physicallayer/persist.h"
#include "physicallayer/datatype.h"
#include "behaviourlayer/behave.h"
#include "celtool/stdparams.h"
#include "ivaria/reporter.h"

CS_IMPLEMENT_PLUGIN

CEL_IMPLEMENT_FACTORY ($NAME$, "pc$NAME$")

static bool Report (iObjectRegistry* object_reg, const char* msg, ...)
{
  va_list arg;
  va_start (arg, msg);

  csRef<iReporter> rep (csQueryRegistry<iReporter> (object_reg));
  if (rep)
    rep->ReportV (CS_REPORTER_SEVERITY_ERROR, "cel.propclass.$NAME$",
    	msg, arg);
  else
  {
    csPrintfV (msg, arg);
    csPrintf ("\n");
    fflush (stdout);
  }

  va_end (arg);
  return false;
}

csStringID celPc$NAME$::id_a = csInvalidStringID;
csStringID celPc$NAME$::id_b = csInvalidStringID;
csStringID celPc$NAME$::id_c = csInvalidStringID;

PropertyHolder celPc$NAME$::propinfo;

celPc$NAME$::celPc$NAME$ (iObjectRegistry* object_reg)
	: scfImplementationType (this, object_reg)
{
  if (id_a == csInvalidStringID)
  {
    id_a = pl->FetchStringID ("cel.parameter.a");
    id_b = pl->FetchStringID ("cel.parameter.b");
    id_c = pl->FetchStringID ("cel.parameter.c");
  }
  params = new celOneParameterBlock ();
  params->SetParameterDef (id_a, "a");

  propholder = &propinfo;
  if (!propinfo.actions_done)
  {
    AddAction (action_a, "cel.action.A");
    AddAction (action_b, "cel.action.B");
    AddAction (action_c, "cel.action.C");
  }
}

celPc$NAME$::~celPc$NAME$ ()
{
  delete params;
}

#define $DEFNAME$_SERIAL 1

csPtr<iCelDataBuffer> celPc$NAME$::Save ()
{
  csRef<iCelDataBuffer> databuf = pl->CreateDataBuffer ($DEFNAME$_SERIAL);
  return csPtr<iCelDataBuffer> (databuf);
}

bool celPc$NAME$::Load (iCelDataBuffer* databuf)
{
  int serialnr = databuf->GetSerialNumber ();
  if (serialnr != $DEFNAME$_SERIAL)
    return Report (object_reg, "Serialnr != $DEFNAME$_SERIAL. Cannot load.");

  return true;
}

bool celPc#NAME$::PerformActionIndexed (int idx,
	iCelParameterBlock* params,
	celData& ret)
{
  switch (idx)
  {
    case action_a:
      {
        return true;
      }
    case action_b:
      {
        return true;
      }
    case action_c:
      {
        return true;
      }
    default:
      return false;
  }
}

| Article | Discussion | View source | History |