Planeshift
|
00001 /* 00002 * Copyright (C) 2006 Atomic Blue ([email protected], http://www.atomicblue.org) 00003 * 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation (version 2 of the License) 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * You should have received a copy of the GNU General Public License 00013 * along with this program; if not, write to the Free Software 00014 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00015 * 00016 */ 00017 00018 #ifndef __PSMOVEMENT_H__ 00019 #define __PSMOVEMENT_H__ 00020 00021 #include <csutil/parray.h> 00022 #include <csutil/csstring.h> 00023 #include <csgeom/vector3.h> 00024 00025 #include "pscelclient.h" 00026 #include "net/cmdbase.h" 00027 00028 class psControlManager; 00029 struct psPoint; 00030 00036 struct psVelocity 00037 { 00038 psVelocity() : move(0.0f), rotate(0.0f) {} 00039 psVelocity(csVector3 m, csVector3 r) : move(m), rotate(r) {} 00040 00041 csVector3 move; 00042 csVector3 rotate; 00043 00044 psVelocity& operator = (const psVelocity& v); 00045 psVelocity& operator += (const psVelocity& v); 00046 psVelocity& operator -= (const psVelocity& v); 00047 psVelocity& operator *= (const psVelocity& v); 00048 psVelocity& operator /= (const psVelocity& v); 00049 }; 00050 00051 00053 struct psCharMode 00054 { 00055 uint32 id; 00056 csString name; 00057 psVelocity modifier; 00058 csString idle_anim; 00059 }; 00060 00062 struct psMovement 00063 { 00064 uint32 id; 00065 csString name; 00066 psVelocity motion; 00067 }; 00068 00070 struct psMoveState 00071 { 00072 uint activeMoves; 00073 bool autoMove; 00074 bool sneaking; 00075 }; 00076 00084 class psMovementManager : public psClientNetSubscriber 00085 { 00086 protected: 00087 csPDelArray<psCharMode> modes; 00088 csPDelArray<psMovement> moves; 00089 00090 const psCharMode* defaultmode; 00091 00092 GEMClientActor* actor; 00093 00094 const psCharMode* actormode; 00095 bool onGround; 00096 uint activeMoves; 00097 psVelocity move_total; 00098 00099 void SetupMovements(psMovementInfoMessage& msg); 00100 void SetupControls(); 00101 bool ready; 00102 bool locked; 00103 00104 psControlManager* controls; 00105 00106 void UpdateVelocity(); 00107 00108 void SetActorMode(const psCharMode* mode); 00109 00110 // Movement modifier handling 00111 void HandleMod(psMoveModMsg& msg); 00112 void ApplyMod(psVelocity& vel); 00113 psMoveModMsg::ModType activeModType; 00114 psVelocity activeMod; 00115 00116 bool autoMove; 00117 bool toggleRun; 00118 bool mouseLook; 00119 bool mouseLookCanAct; 00120 bool mouseZoom; 00121 bool mouseMove; 00122 bool sneaking; 00123 int mouseAutoMove; 00124 int runToMarkerID; 00125 float lastDist; 00126 csVector3 runToDiff; 00127 00128 // Mouse settings 00129 float sensY; 00130 float sensX; 00131 bool invertedMouse; 00132 float lastDeltaX; 00133 float lastDeltaY; 00134 00135 csEventID event_frame; 00136 csEventID event_mousemove; 00137 00138 const psMovement* forward; 00139 const psMovement* backward; 00140 const psCharMode* run; 00141 const psCharMode* walk; 00142 00143 uint kbdRotate; 00144 00145 public: 00146 psMovementManager(iEventNameRegistry* eventname_reg, psControlManager* controls); 00147 ~psMovementManager(); 00148 00149 void HandleMessage(MsgEntry* me); 00150 bool HandleEvent(iEvent& event); 00151 00152 void SetActor(GEMClientActor* actor); 00153 GEMClientActor* ControlledActor() { return actor; } 00154 00155 // Functions to find movement and mode info 00156 const char* GetModeIdleAnim(size_t id) const { return modes[id]->idle_anim; } 00157 const psCharMode* FindCharMode(size_t id) const { return modes[id]; } 00158 const psCharMode* FindCharMode(const char* name) const; 00159 const psMovement* FindMovement(const char* name) const; 00160 00161 bool IsReady() { return ready; } 00162 bool IsLocked() { return locked; } 00163 void LockMoves(bool v); 00164 00165 // Movements 00166 void Start(const psCharMode* mode); 00167 void Stop(const psCharMode* mode); 00168 void Start(const psMovement* move); 00169 void Stop(const psMovement* move); 00170 void Push(const psMovement* move); 00171 00173 void StopAllMovement(); 00174 00176 void StopControlledMovement(); 00177 00178 // Mouse settings 00179 void SetMouseSensX(float v) { sensX = v; } 00180 void SetMouseSensY(float v) { sensY = v; } 00181 void SetInvertedMouse(bool v) { invertedMouse = v; } 00182 bool GetInvertedMouse() { return invertedMouse; } 00183 void LoadMouseSettings(); 00184 00185 void MouseLookCanAct(bool v); 00186 bool MouseLookCanAct(){ return mouseLookCanAct; } 00187 00188 void MouseLook(bool v); 00189 bool MouseLook() { return mouseLook; } 00190 void MouseLook(iEvent& ev); 00191 void UpdateMouseLook(); 00192 00193 void MouseZoom(bool v) { mouseZoom = v; } 00194 bool MouseZoom() { return mouseZoom; } 00195 void MouseZoom(iEvent& ev); 00196 00197 void SetMouseMove(bool v) { mouseMove = v; } 00198 bool MouseMove() { return mouseMove; } 00199 void SetRunToPos(psPoint& mouse); 00200 void CancelRunTo(); 00201 void UpdateRunTo(); 00202 00203 void ToggleAutoMove(); 00204 00209 bool ToggleRun(); 00210 00217 bool SetRun(bool runState); 00218 00219 void SetSneaking(bool v) { sneaking = v; } 00220 bool Sneaking() { return sneaking; } 00221 00222 void SaveMoveState(psMoveState& state) 00223 { 00224 state.activeMoves = activeMoves; 00225 state.autoMove = autoMove; 00226 state.sneaking = sneaking; 00227 } 00228 00229 bool MoveStateChanged(psMoveState& state) 00230 { 00231 return state.activeMoves != activeMoves || 00232 state.autoMove != autoMove || 00233 state.sneaking != sneaking; 00234 } 00235 }; 00236 00237 #endif 00238