From: Matze B. <mat...@us...> - 2002-02-08 10:34:05
|
Update of /cvsroot/planeshift/planeshift/src/common/psbehave In directory usw-pr-cvs1:/tmp/cvs-serv5758/src/common/psbehave Added Files: .cvsignore Makefile.am psbehave.cpp psbehave.h psbl.cpp psbl.h Log Message: added a behaviour layer (not used yet) --- NEW FILE: .cvsignore --- .deps .libs Makefile Makefile.in *.la *.lo --- NEW FILE: Makefile.am --- COMMONSRC = $(top_srcdir)/src/common INCFLAGS = -I$(COMMONSRC) CFLAGS += $(INCFLAGS) @CS_CXXFLAGS@ CXXFLAGS += $(INCFLAGS) @CS_CXXFLAGS@ LIBS = @CS_LIBS@ lib_LTLIBRARIES = psbehave.la psbehave_la_LDFLAGS = -module -avoid-version -no-undefined @CS_LIBS@ psbehave_la_SOURCES = psbl.h psbl.cpp psbehave.h psbehave.cpp --- NEW FILE: psbehave.cpp --- #include "config.h" #include <iutil/objreg.h> #include <csutil/util.h> #include <csgeom/vector3.h> #include <pl/entity.h> #include <pl/propclas.h> #include <pf/gravity.h> #include <pf/camera.h> #include "psbehave.h" //--------------------------------------------------------------------------- SCF_IMPLEMENT_IBASE (psBehaviourGeneral) SCF_IMPLEMENTS_INTERFACE (iCelBehaviour) SCF_IMPLEMENT_IBASE_END psBehaviourGeneral::psBehaviourGeneral (iCelEntity* entity, iObjectRegistry* object_reg) { SCF_CONSTRUCT_IBASE (NULL); psBehaviourGeneral::entity = entity; psBehaviourGeneral::object_reg = object_reg; name = NULL; } psBehaviourGeneral::~psBehaviourGeneral () { delete[] name; } void psBehaviourGeneral::SetName(const char* n) { if (name) delete[] name; name = csStrNew (n); } void psBehaviourGeneral::SetBehaviourLayer (iCelBlLayer* bl) { psBehaviourGeneral::bl = bl; } bool psBehaviourGeneral::SendMessage (const char* msg_id, iBase* msg_info, ...) { va_list arg; va_start (arg, msg_info); bool rc = SendMessageV (msg_id, msg_info, arg); va_end (arg); return rc; } //--------------------------------------------------------------------------- psBehaviourActor::psBehaviourActor (iCelEntity* entity, iObjectRegistry* object_reg) : psBehaviourGeneral (entity, object_reg) { fpscam=0; speed=1; } psBehaviourActor::~psBehaviourActor() { } bool psBehaviourActor::SendMessageV (const char* msg_id, iBase* msg_info, va_list arg) { bool pcinput_msg = strncmp (msg_id, "pckeyinput_", 11) == 0; if (pcinput_msg) { iPcGravity *pcgravity = CEL_QUERY_PROPCLASS (entity->GetPropertyClassList(), iPcGravity); if (!pcgravity) return false; if (!strcmp (msg_id+11, "forward1")) { pcgravity->ApplyForce(csVector3(0,0,-1*speed), 100000); } else if (!strcmp (msg_id+11, "forward0")) { pcgravity->ResetSpeed(); pcgravity->ClearForces(); } else if (!strcmp (msg_id+11, "backward1")) { pcgravity->ApplyForce(csVector3(0,0,1*speed), 1000000); } else if (!strcmp (msg_id+11, "backward0")) { pcgravity->ResetSpeed(); pcgravity->ClearForces(); } else if (!strcmp (msg_id+11, "strafeleft1")) { pcgravity->ApplyForce(csVector3(-1*speed,0,0), 100000); } else if (!strcmp (msg_id+11, "strafeleft0")) { pcgravity->ResetSpeed(); pcgravity->ClearForces(); } else if (!strcmp (msg_id+11, "straferight1")) { pcgravity->ApplyForce(csVector3(1*speed,0,0), 100000); } else if (!strcmp (msg_id+11, "straferight0")) { pcgravity->ResetSpeed(); pcgravity->ClearForces(); } else if (!strcmp (msg_id+11, "run1")) { speed=2.5; } else if (!strcmp (msg_id+11, "run0")) { speed=1; } else if (!strcmp (msg_id+11, "cammode1")) { fpscam = fpscam ? 0 : 1; iPcCamera* pccam; pccam = CEL_QUERY_PROPCLASS(entity->GetPropertyClassList(), iPcCamera); if (!pccam) { pcgravity->DecRef (); return false; } if (fpscam) { printf ("Switching to 3rd person view!\n"); pccam->SetMode (iPcCamera::follow, true); } else { printf ("Free look mode\n"); pccam->SetMode (iPcCamera::freelook, false); } pccam->DecRef(); } pcgravity->DecRef (); } return true; } --- NEW FILE: psbehave.h --- /* * psbehave.h - author Matze Braun <Mat...@gm...> * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program 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 General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __PSBEHAVE_H__ #define __PSBEHAVE_H__ #include <bl/behave.h> struct iCelEntity; struct iObjectRegistry; /** * General behaviour class. */ class psBehaviourGeneral : public iCelBehaviour { protected: iCelEntity* entity; iCelBlLayer* bl; iObjectRegistry* object_reg; char* name; public: psBehaviourGeneral (iCelEntity* entity, iObjectRegistry* object_reg); virtual ~psBehaviourGeneral (); void SetName (const char* n); void SetBehaviourLayer (iCelBlLayer* bl); SCF_DECLARE_IBASE; virtual const char* GetName () const { return name; } virtual iCelBlLayer* GetBehaviourLayer () const { return bl; } virtual bool SendMessage (const char* msg_id, iBase* msg_info, ...); }; class psBehaviourActor : public psBehaviourGeneral { public: psBehaviourActor (iCelEntity* entity, iObjectRegistry* object_reg); virtual ~psBehaviourActor(); virtual bool SendMessageV (const char* msg_id, iBase* msg_info, va_list args); protected: float speed; int fpscam; }; #endif --- NEW FILE: psbl.cpp --- /* * psbl.cpp - author Matze Braun <Mat...@gm...> * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program 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 General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include "psbl.h" #include "psbehave.h" //--------------------------------------------------------------------------- CS_IMPLEMENT_PLUGIN SCF_IMPLEMENT_FACTORY (psBehaviourLayer) SCF_EXPORT_CLASS_TABLE (blps) SCF_EXPORT_CLASS (psBehaviourLayer, "planeshift.behaviourlayer.standard", "Planeshift Behaviour Layer") SCF_EXPORT_CLASS_TABLE_END SCF_IMPLEMENT_IBASE (psBehaviourLayer) SCF_IMPLEMENTS_INTERFACE (iCelBlLayer) SCF_IMPLEMENTS_EMBEDDED_INTERFACE (iComponent) SCF_IMPLEMENT_IBASE_END SCF_IMPLEMENT_EMBEDDED_IBASE (psBehaviourLayer::Component) SCF_IMPLEMENTS_INTERFACE (iComponent) SCF_IMPLEMENT_EMBEDDED_IBASE_END psBehaviourLayer::psBehaviourLayer (iBase* parent) { SCF_CONSTRUCT_IBASE (parent); SCF_CONSTRUCT_EMBEDDED_IBASE (scfiComponent); } psBehaviourLayer::~psBehaviourLayer () { } bool psBehaviourLayer::Initialize (iObjectRegistry* object_reg) { psBehaviourLayer::object_reg = object_reg; return true; } iCelBehaviour* psBehaviourLayer::CreateBehaviour (iCelEntity* entity, const char* name) { psBehaviourGeneral* ent = NULL; if (!strcmp (name, "actor")) ent = new psBehaviourActor (entity, object_reg); if (ent) { ent->SetName (name); ent->SetBehaviourLayer (this); } #ifdef DEBUG else { printf ("Tried to use unknown behaviour: '%s'.", name); } #endif return ent; } --- NEW FILE: psbl.h --- /* * psbl.h - author Matze Braun <Mat...@gm...> * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program 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 General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __PSBL_H__ #define __PSBL_H__ #include <iutil/comp.h> #include <bl/bl.h> struct iObjectRegistry; struct iCelEntity; /** * This is the Playneshift behaviour layer. It's basically a registry for the * single behaviours */ class psBehaviourLayer : public iCelBlLayer { public: SCF_DECLARE_IBASE; psBehaviourLayer(iBase* parent); virtual ~psBehaviourLayer (); bool Initialize (iObjectRegistry* object_reg); virtual const char* GetName () const { return "psbl"; } virtual iCelBehaviour* CreateBehaviour (iCelEntity* entity, const char* name); struct Component : public iComponent { SCF_DECLARE_EMBEDDED_IBASE (psBehaviourLayer); virtual bool Initialize (iObjectRegistry* p) { return scfParent->Initialize (p); } } scfiComponent; protected: iObjectRegistry* object_reg; }; #endif |