| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For support and more information about Cafu, visit us at <http://www.cafu.de>. |
|---|
| 19 | ================================================================================= |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | /**********************/ |
|---|
| 23 | /*** Player Command ***/ |
|---|
| 24 | /**********************/ |
|---|
| 25 | |
|---|
| 26 | #ifndef CAFU_PLAYERCOMMAND_HPP_INCLUDED |
|---|
| 27 | #define CAFU_PLAYERCOMMAND_HPP_INCLUDED |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | // Player command key flags |
|---|
| 31 | const unsigned long PCK_MoveForward =0x00000001; |
|---|
| 32 | const unsigned long PCK_MoveBackward=0x00000002; |
|---|
| 33 | const unsigned long PCK_TurnLeft =0x00000004; |
|---|
| 34 | const unsigned long PCK_TurnRight =0x00000008; |
|---|
| 35 | const unsigned long PCK_StrafeLeft =0x00000010; |
|---|
| 36 | const unsigned long PCK_StrafeRight =0x00000020; |
|---|
| 37 | const unsigned long PCK_LookUp =0x00000040; |
|---|
| 38 | const unsigned long PCK_LookDown =0x00000080; |
|---|
| 39 | const unsigned long PCK_CenterView =0x00000100; |
|---|
| 40 | const unsigned long PCK_Jump =0x00000200; // Jump |
|---|
| 41 | const unsigned long PCK_Duck =0x00000400; // Duck |
|---|
| 42 | const unsigned long PCK_Walk =0x00000800; // Walk (slower than normal) |
|---|
| 43 | const unsigned long PCK_Fire1 =0x00001000; // Primary Fire (also used e.g. for "Respawn") |
|---|
| 44 | const unsigned long PCK_Fire2 =0x00002000; // Secondary Fire |
|---|
| 45 | const unsigned long PCK_Use =0x00004000; // Use |
|---|
| 46 | // Bits 28-31 are reserved for selecting the weapon slot! |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | // Commonly used data structure to store and pass around player commands. |
|---|
| 50 | // Shared among the game DLLs, the client and the server code. |
|---|
| 51 | struct PlayerCommandT |
|---|
| 52 | { |
|---|
| 53 | // 'Nr' is the consecutive number of this 'PlayerCommandT'. |
|---|
| 54 | // It can be thought of as the clients frame number, or the sequence number of the packet with which this |
|---|
| 55 | // 'PlayerCommandT' is sent to the server. |
|---|
| 56 | // The main property is that a human player entity never sees the same number twice ('Nr' is counted up). |
|---|
| 57 | // (However, 'PlayerCommandT's arriving at the server from *different* human player entites can well contain the same |
|---|
| 58 | // numbers at a time. In such cases, even the enitre sequence of 'Nr's in consecutive 'PlayerCommandT's is identical, |
|---|
| 59 | // because they are all treated likewise. Fortunately, that's not a problem: |
|---|
| 60 | // Clients usually join the game at different times (yielding different starting numbers), |
|---|
| 61 | // they have different FPS (the sequence of 'PlayerCommandT's advances at a different pace), |
|---|
| 62 | // and finally different human player entities use the numbers entirely different.) |
|---|
| 63 | // The main purpose is to give the human player entity in the game DLL a way to derive pseudo random numbers |
|---|
| 64 | // (by using 'Nr' as table index) that also work in the presence of "client prediction". |
|---|
| 65 | float FrameTime; |
|---|
| 66 | unsigned long Keys; |
|---|
| 67 | unsigned short DeltaHeading; |
|---|
| 68 | unsigned short DeltaPitch; |
|---|
| 69 | unsigned short DeltaBank; |
|---|
| 70 | unsigned long Nr; |
|---|
| 71 | |
|---|
| 72 | PlayerCommandT(float FrameTime_=0, unsigned long Keys_=0, unsigned short DeltaHeading_=0, unsigned short DeltaPitch_=0, unsigned short DeltaBank_=0, unsigned long Nr_=0) |
|---|
| 73 | : FrameTime(FrameTime_), Keys(Keys_), DeltaHeading(DeltaHeading_), DeltaPitch(DeltaPitch_), DeltaBank(DeltaBank_), Nr(Nr_) {} |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | #endif |
|---|