|
From: Pier D. <cy...@us...> - 2001-07-12 19:22:42
|
Update of /cvsroot/bzflag/bzflag/src/bzflag
In directory usw-pr-cvs1:/tmp/cvs-serv12671/src/bzflag
Modified Files:
LocalPlayer.cxx LocalPlayer.h bzflag.cxx playing.cxx playing.h
Log Message:
Added keyboard moving
Index: LocalPlayer.cxx
===================================================================
RCS file: /cvsroot/bzflag/bzflag/src/bzflag/LocalPlayer.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LocalPlayer.cxx 2001/07/11 08:42:50 1.6
+++ LocalPlayer.cxx 2001/07/12 19:22:39 1.7
@@ -16,6 +16,7 @@
#include "ServerLink.h"
#include "sound.h"
#include "Flag.h"
+#include "BzfEvent.h"
#include <stdlib.h>
#include <math.h>
@@ -662,6 +663,9 @@
move(pos, _azimuth);
setVelocity(zero);
setAngularVelocity(0.0f);
+ setKeyboardSpeed(0.0f);
+ setKeyboardAngVel(0.0f);
+ keyButton = BzfKeyEvent::NoButton;
doUpdateMotion(0.0f);
// make me alive now
Index: LocalPlayer.h
===================================================================
RCS file: /cvsroot/bzflag/bzflag/src/bzflag/LocalPlayer.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LocalPlayer.h 2001/07/11 08:42:50 1.5
+++ LocalPlayer.h 2001/07/12 19:22:39 1.6
@@ -108,6 +108,14 @@
void addAntidote(SceneDatabase*);
+ void setKeyboardSpeed(float speed);
+ void setKeyboardAngVel(float angVel);
+ float getKeyboardSpeed() const;
+ float getKeyboardAngVel() const;
+ void setKey(int button, boolean pressed);
+ boolean getKeyPressed() const;
+ int getKeyButton() const;
+
static LocalPlayer* getMyTank();
static void setMyTank(LocalPlayer*);
@@ -142,6 +150,10 @@
const Player* target;
const Player* nemesis;
static LocalPlayer* mainPlayer;
+ float keyboardSpeed;
+ float keyboardAngVel;
+ int keyButton;
+ boolean keyPressed;
};
//
@@ -176,6 +188,42 @@
inline const Obstacle* LocalPlayer::getContainingBuilding() const
{
return insideBuilding;
+}
+
+inline void LocalPlayer::setKeyboardSpeed(float speed)
+{
+ keyboardSpeed = speed;
+}
+
+inline void LocalPlayer::setKeyboardAngVel(float angVel)
+{
+ keyboardAngVel = angVel;
+}
+
+inline float LocalPlayer::getKeyboardSpeed() const
+{
+ return keyboardSpeed;
+}
+
+inline float LocalPlayer::getKeyboardAngVel() const
+{
+ return keyboardAngVel;
+}
+
+inline void LocalPlayer::setKey(int button, boolean pressed)
+{
+ keyButton = button;
+ keyPressed = pressed;
+}
+
+inline boolean LocalPlayer::getKeyPressed() const
+{
+ return keyPressed;
+}
+
+inline int LocalPlayer::getKeyButton() const
+{
+ return keyButton;
}
#endif // BZF_LOCAL_PLAYER_H
Index: bzflag.cxx
===================================================================
RCS file: /cvsroot/bzflag/bzflag/src/bzflag/bzflag.cxx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- bzflag.cxx 2001/04/03 02:38:13 1.14
+++ bzflag.cxx 2001/07/12 19:22:39 1.15
@@ -612,6 +612,7 @@
{
// collect new configuration
+ db.addValue("keyboardmoving", startupInfo.keyboardMoving ? "yes" : "no");
db.addValue("udpnet", startupInfo.useUDPconnection ? "yes" : "no");
db.addValue("callsign", startupInfo.callsign);
db.addValue("team", Team::getName(startupInfo.team));
@@ -878,6 +879,8 @@
startupInfo.useUDPconnection=false;
}
}
+
+
// ignore window name in config file (it's used internally)
db.removeValue("window");
db.removeValue("multisample");
@@ -1132,6 +1135,10 @@
// set server list URL
if (db.hasValue("list"))
startupInfo.listServerURL = db.getValue("list");
+
+ // keyboard moving
+ if (db.hasValue("keyboardmoving"))
+ startupInfo.keyboardMoving = db.getValue("keyboardmoving") == "yes";
// start playing
startPlaying(display, renderer, db, &startupInfo);
Index: playing.cxx
===================================================================
RCS file: /cvsroot/bzflag/bzflag/src/bzflag/playing.cxx,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- playing.cxx 2001/07/11 09:13:53 1.33
+++ playing.cxx 2001/07/12 19:22:39 1.34
@@ -428,6 +428,22 @@
else {
// built-in unchangeable keys. only perform if not masked.
switch (key.ascii) {
+ case 'K':
+ case 'k':
+ if (keymap.isMapped(key.ascii) == BzfKeyMap::LastKey) {
+ if (pressed) {
+ if (!startupInfo.keyboardMoving)
+ controlPanel->addMessage("Keyboard movement");
+ else if (mainWindow->joystick())
+ controlPanel->addMessage("Joystick movement");
+ else
+ controlPanel->addMessage("Mouse movement");
+ startupInfo.keyboardMoving = !startupInfo.keyboardMoving;
+ }
+ return True;
+ }
+ break;
+
case 'T':
case 't':
// toggle frames-per-second display
@@ -545,6 +561,7 @@
// toggle motion freeze
motionFreeze = !motionFreeze;
}
+ // else
#endif
#if defined(ROAMING)
if (key.ascii == '~' && pressed) {
@@ -606,6 +623,7 @@
break;
}
}
+ // else
#endif
if (keymap.isMappedTo(BzfKeyMap::FireShot, key)) {
@@ -803,6 +821,16 @@
}
}
}
+ // Might be a direction key. Save it for later.
+ else if (myTank->isAlive() && startupInfo.keyboardMoving)
+ myTank->setKey(key.button, pressed);
+}
+
+static float getKeyValue(bool pressed)
+{
+ if (pressed)
+ return 1;
+ return 0;
}
static void doMotion()
@@ -811,12 +839,40 @@
if (motionFreeze) return;
#endif
- // get mouse position
- int mx, my;
- if (mainWindow->joystick()) {
- mainWindow->getJoyPosition(mx, my);
+ float rotation, speed, rotationModifier = 1.0f;
- static const BzfKeyEvent::Button button_map[] = { BzfKeyEvent::LeftMouse,
+ if (startupInfo.keyboardMoving) {
+ rotation = myTank->getKeyboardAngVel();
+ speed = myTank->getKeyboardSpeed();
+ switch (myTank->getKeyButton())
+ {
+ case BzfKeyEvent::Left:
+ rotation = getKeyValue(myTank->getKeyPressed());
+ break;
+ case BzfKeyEvent::Right:
+ rotation = - getKeyValue(myTank->getKeyPressed());
+ break;
+ case BzfKeyEvent::Up:
+ speed = getKeyValue(myTank->getKeyPressed());
+ break;
+ case BzfKeyEvent::Down:
+ speed = - getKeyValue(myTank->getKeyPressed()) / 2.0;
+ break;
+ }
+ if (myTank->getMagnify())
+ rotationModifier = 0.2;
+
+ myTank->setKeyboardAngVel(rotation);
+ myTank->setKeyboardSpeed(speed);
+ myTank->setKey(BzfKeyEvent::NoButton, false);
+ }
+ else {
+ // get mouse position
+ int mx, my;
+ if (mainWindow->joystick()) {
+ mainWindow->getJoyPosition(mx, my);
+
+ static const BzfKeyEvent::Button button_map[] = { BzfKeyEvent::LeftMouse,
BzfKeyEvent::MiddleMouse,
BzfKeyEvent::RightMouse,
BzfKeyEvent::F1,
@@ -828,47 +884,48 @@
BzfKeyEvent::F7,
BzfKeyEvent::F8,
BzfKeyEvent::F9
- };
+ };
- static unsigned long old_buttons = 0;
- unsigned long new_buttons = mainWindow->getJoyButtonSet();
- if (old_buttons != new_buttons)
- for (int j = 0; j<12; j++)
- if ((old_buttons & (1<<j)) != (new_buttons & (1<<j))) {
- BzfKeyEvent ev;
- ev.button = button_map[j];
- ev.ascii = 0;
- ev.shift = 0;
- doKeyPlaying(ev, new_buttons&(1<<j));
- }
- old_buttons = new_buttons;
- } else
- mainWindow->getMousePosition(mx, my);
-
- // calculate desired rotation
- const int noMotionSize = hud->getNoMotionSize();
- const int maxMotionSize = hud->getMaxMotionSize();
- float rotation = 0.0f;
- if (mx < -noMotionSize) {
- rotation = float(-mx - noMotionSize) / float(maxMotionSize);
- if (rotation > 1.0f) rotation = 1.0f;
- }
- else if (mx > noMotionSize) {
- rotation = -float(mx - noMotionSize) / float(maxMotionSize);
- if (rotation < -1.0f) rotation = -1.0f;
- }
- myTank->setDesiredAngVel(rotation);
-
- // calculate desired speed
- float speed = 0.0f;
- if (my < -noMotionSize) {
- speed = float(-my - noMotionSize) / float(maxMotionSize);
- if (speed > 1.0f) speed = 1.0f;
- }
- else if (my > noMotionSize) {
- speed = -float(my - noMotionSize) / float(maxMotionSize);
- if (speed < -0.5f) speed = -0.5f;
+ static unsigned long old_buttons = 0;
+ unsigned long new_buttons = mainWindow->getJoyButtonSet();
+ if (old_buttons != new_buttons)
+ for (int j = 0; j<12; j++)
+ if ((old_buttons & (1<<j)) != (new_buttons & (1<<j))) {
+ BzfKeyEvent ev;
+ ev.button = button_map[j];
+ ev.ascii = 0;
+ ev.shift = 0;
+ doKeyPlaying(ev, new_buttons&(1<<j));
+ }
+ old_buttons = new_buttons;
+ } else
+ mainWindow->getMousePosition(mx, my);
+
+ // calculate desired rotation
+ const int noMotionSize = hud->getNoMotionSize();
+ const int maxMotionSize = hud->getMaxMotionSize();
+ rotation = 0.0f;
+ if (mx < -noMotionSize) {
+ rotation = float(-mx - noMotionSize) / float(maxMotionSize);
+ if (rotation > 1.0f) rotation = 1.0f;
+ }
+ else if (mx > noMotionSize) {
+ rotation = -float(mx - noMotionSize) / float(maxMotionSize);
+ if (rotation < -1.0f) rotation = -1.0f;
+ }
+
+ // calculate desired speed
+ speed = 0.0f;
+ if (my < -noMotionSize) {
+ speed = float(-my - noMotionSize) / float(maxMotionSize);
+ if (speed > 1.0f) speed = 1.0f;
+ }
+ else if (my > noMotionSize) {
+ speed = -float(my - noMotionSize) / float(maxMotionSize);
+ if (speed < -0.5f) speed = -0.5f;
+ }
}
+ myTank->setDesiredAngVel(rotation * rotationModifier);
myTank->setDesiredSpeed(speed);
}
Index: playing.h
===================================================================
RCS file: /cvsroot/bzflag/bzflag/src/bzflag/playing.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- playing.h 2001/03/09 02:38:24 1.7
+++ playing.h 2001/07/12 19:22:39 1.8
@@ -44,6 +44,7 @@
int listServerPort;
boolean joystick;
BzfString joystickName;
+ boolean keyboardMoving;
};
typedef void (*JoinGameCallback)(boolean success, void* data);
|