Revision: 2483
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2483&view=rev
Author: ulteq
Date: 2012-04-28 18:17:06 +0000 (Sat, 28 Apr 2012)
Log Message:
-----------
-Feature: Vehicle name now part of the packet
Modified Paths:
--------------
trunk/source/main/gameplay/OutProtocol.cpp
trunk/source/main/gameplay/OutProtocol.h
Modified: trunk/source/main/gameplay/OutProtocol.cpp
===================================================================
--- trunk/source/main/gameplay/OutProtocol.cpp 2012-04-27 17:09:16 UTC (rev
2482)
+++ trunk/source/main/gameplay/OutProtocol.cpp 2012-04-28 18:17:06 UTC (rev
2483)
@@ -20,83 +20,22 @@
#include "BeamEngine.h"
#include "BeamFactory.h"
-#include "OutProtocol.h"
#include "RoRVersion.h"
#include "Settings.h"
+#include "OutProtocol.h"
-#ifdef WIN32
-#include <Ws2tcpip.h>
-#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__
__pragma( pack(pop) )
-#else
-#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
-#endif //WIN32
-
-using namespace std;
-
-// from LFS/doc/insim.txt
-enum
-{
- OG_SHIFT = 1, // key
- OG_CTRL = 2, // key
- OG_TURBO = 8192, // show turbo gauge
- OG_KM = 16384, // if not set - user prefers MILES
- OG_BAR = 32768, // if not set - user prefers PSI
-};
-
-enum
-{
- DL_SHIFT = BITMASK(1), // bit 0 - shift light
- DL_FULLBEAM = BITMASK(2), // bit 1 - full beam
- DL_HANDBRAKE = BITMASK(3), // bit 2 - handbrake
- DL_PITSPEED = BITMASK(4), // bit 3 - pit speed limiter
- DL_TC = BITMASK(5), // bit 4 - TC active or switched
off
- DL_SIGNAL_L = BITMASK(6), // bit 5 - left turn signal
- DL_SIGNAL_R = BITMASK(7), // bit 6 - right turn signal
- DL_SIGNAL_ANY = BITMASK(8), // bit 7 - shared turn signal
- DL_OILWARN = BITMASK(9), // bit 8 - oil pressure warning
- DL_BATTERY = BITMASK(10), // bit 9 - battery warning
- DL_ABS = BITMASK(11), // bit 10 - ABS active or switched off
- DL_SPARE = BITMASK(12), // bit 11
- DL_NUM = BITMASK(13) // bit 14 - end
-};
-
-PACK (struct OutGaugePack
-{
- unsigned int Time; // time in milliseconds (to check order)
- char Car[4]; // Car name
- unsigned short Flags; // Info (see OG_x below)
- unsigned char Gear; // Reverse:0, Neutral:1, First:2...
- unsigned char PLID; // Unique ID of viewed player (0 = none)
- float Speed; // M/S
- float RPM; // RPM
- float Turbo; // BAR
- float EngTemp; // C
- float Fuel; // 0 to 1
- float OilPressure; // BAR
- float OilTemp; // C
- unsigned int DashLights; // Dash lights available (see DL_x below)
- unsigned int ShowLights; // Dash lights currently switched on
- float Throttle; // 0 to 1
- float Brake; // 0 to 1
- float Clutch; // 0 to 1
- char Display1[16]; // Usually Fuel
- char Display2[16]; // Usually Settings
- int ID; // optional - only if OutGauge
ID is specified
-});
-
OutProtocol::OutProtocol(void) :
- counter(0)
- , delay(0.1)
+ delay(0.1f)
, id(0)
, mode(0)
, sockfd(-1)
, timer(0)
, working(false)
{
- delay = FSETTING("OutGauge Delay", 10) * 0.1f;
- mode = ISETTING("OutGauge Mode", 0);
- id = ISETTING("OutGauge ID", 0);
+ delay *= FSETTING("OutGauge Delay", 10);
+ mode = ISETTING("OutGauge Mode", 0);
+ id = ISETTING("OutGauge ID", 0);
if ( mode > 0 )
{
@@ -123,7 +62,7 @@
SWBaseSocket::SWBaseError error;
// get some settings
- string ipstr = SSETTING("OutGauge IP", "192.168.1.100");
+ String ipstr = SSETTING("OutGauge IP", "192.168.1.100");
int port = ISETTING("OutGauge Port", 1337);
// startup winsock
@@ -152,7 +91,7 @@
sendaddr.sin_addr.s_addr = inet_addr(ip);
sendaddr.sin_port = htons(port);
- // then connect
+ // connect
if( connect(sockfd, (struct sockaddr *) &sendaddr, sizeof(sendaddr)) ==
SOCKET_ERROR )
{
LOG(String("error connecting socket for OutGauge:
").append(strerror(errno)));
@@ -161,7 +100,9 @@
LOG("OutGauge connected successfully");
working = true;
-#endif // WIN32
+#else
+ // TODO: fix linux
+#endif //WIN32
}
bool OutProtocol::update(float dt)
@@ -185,11 +126,10 @@
memset(&gd, 0, sizeof(gd));
// set some common things
- gd.Time = counter++;
- sprintf(gd.Display1, "RoR v %s", ROR_VERSION_STRING);
- gd.ID = id;
- sprintf(gd.Car, "RoR");
+ gd.Time = Ogre::Root::getSingleton().getTimer()->getMilliseconds();
+ gd.ID = id;
gd.Flags = 0 | OG_KM;
+ sprintf(gd.Car, "RoR");
Beam *truck = BeamFactory::getSingleton().getCurrentTruck();
if ( !truck )
@@ -200,28 +140,24 @@
{
// no engine?
sprintf(gd.Display2, "no engine");
- } else if( truck && truck->engine )
+ } else if ( truck && truck->engine )
{
// truck and engine valid
if ( truck->engine->hasturbo )
{
gd.Flags |= OG_TURBO;
}
- gd.Gear = truck->engine->getGear() + 1;
- if ( gd.Gear < 0 )
- {
- gd.Gear = 0; // we only support one reverse gear
- }
- gd.PLID = 0;
- gd.Speed = fabs(truck->WheelSpeed);
- gd.RPM = truck->engine->getRPM();
- gd.Turbo = truck->engine->getTurboPSI();
- gd.EngTemp = 0; // TODO
- gd.Fuel = 0; // TODO
+ gd.Gear = std::max(0, truck->engine->getGear() + 1); //
we only support one reverse gear
+ gd.PLID = 0;
+ gd.Speed = fabs(truck->WheelSpeed);
+ gd.RPM = truck->engine->getRPM();
+ gd.Turbo = truck->engine->getTurboPSI();
+ gd.EngTemp = 0; // TODO
+ gd.Fuel = 0; // TODO
gd.OilPressure = 0; // TODO
- gd.OilTemp = 0; // TODO
+ gd.OilTemp = 0; // TODO
- gd.DashLights = 0;
+ gd.DashLights = 0;
gd.DashLights |= DL_HANDBRAKE;
gd.DashLights |= DL_BATTERY;
gd.DashLights |= DL_SIGNAL_L;
@@ -244,7 +180,11 @@
gd.Brake = truck->brake / truck->brakeforce;
gd.Clutch = truck->engine->getClutch(); // 0-1
- strncpy(gd.Display2, truck->realtruckname.c_str(), 15);
+ strncpy(gd.Display1, truck->realtruckname.c_str(), 15);
+ if ( truck->realtruckname.length() > 15 )
+ {
+ strncpy(gd.Display2, truck->realtruckname.c_str() + 15,
15);
+ }
}
// send the package
send(sockfd, (const char*)&gd, sizeof(gd), NULL);
Modified: trunk/source/main/gameplay/OutProtocol.h
===================================================================
--- trunk/source/main/gameplay/OutProtocol.h 2012-04-27 17:09:16 UTC (rev
2482)
+++ trunk/source/main/gameplay/OutProtocol.h 2012-04-28 18:17:06 UTC (rev
2483)
@@ -20,8 +20,8 @@
// created by Thomas Fischer thomas{AT}thomasfischer{DOT}biz, 17th of July 2011
-#ifndef OUTPROTCOL_H__
-#define OUTPROTCOL_H__
+#ifndef _OUTPROTCOL_H__
+#define _OUTPROTCOL_H__
#include "RoRPrerequisites.h"
#include "Singleton.h"
@@ -30,22 +30,82 @@
#include "SocketW.h"
#endif //USE_SOCKETW
+#ifdef WIN32
+#include <Ws2tcpip.h>
+#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__
__pragma( pack(pop) )
+#else
+#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
+#endif //WIN32
+
class OutProtocol : public RoRSingleton< OutProtocol >
{
public:
+
OutProtocol(void);
~OutProtocol(void);
bool update(float dt);
-protected:
- int sockfd;
+
+private:
+
+ bool working;
float delay, timer;
+ int id;
int mode;
- int id;
- bool working;
- unsigned counter;
+ int sockfd;
void startup();
+
+ // from LFS/doc/insim.txt
+ enum
+ {
+ OG_SHIFT = 1, // key
+ OG_CTRL = 2, // key
+ OG_TURBO = 8192, // show turbo gauge
+ OG_KM = 16384, // if not set - user prefers MILES
+ OG_BAR = 32768, // if not set - user prefers PSI
+ };
+
+ enum
+ {
+ DL_SHIFT = BITMASK(1), // bit 0 - shift light
+ DL_FULLBEAM = BITMASK(2), // bit 1 - full beam
+ DL_HANDBRAKE = BITMASK(3), // bit 2 - handbrake
+ DL_PITSPEED = BITMASK(4), // bit 3 - pit speed
limiter
+ DL_TC = BITMASK(5), // bit 4 - TC active or
switched off
+ DL_SIGNAL_L = BITMASK(6), // bit 5 - left turn
signal
+ DL_SIGNAL_R = BITMASK(7), // bit 6 - right turn
signal
+ DL_SIGNAL_ANY = BITMASK(8), // bit 7 - shared turn signal
+ DL_OILWARN = BITMASK(9), // bit 8 - oil pressure warning
+ DL_BATTERY = BITMASK(10), // bit 9 - battery warning
+ DL_ABS = BITMASK(11), // bit 10 - ABS active or
switched off
+ DL_SPARE = BITMASK(12), // bit 11
+ DL_NUM = BITMASK(13) // bit 14 - end
+ };
+
+ PACK (struct OutGaugePack
+ {
+ unsigned int Time; // time in milliseconds (to check
order)
+ char Car[4]; // Car name
+ unsigned short Flags; // Info (see OG_x below)
+ unsigned char Gear; // Reverse:0, Neutral:1, First:2...
+ unsigned char PLID; // Unique ID of viewed player (0 =
none)
+ float Speed; // M/S
+ float RPM; // RPM
+ float Turbo; // BAR
+ float EngTemp; // C
+ float Fuel; // 0 to 1
+ float OilPressure; // BAR
+ float OilTemp; // C
+ unsigned int DashLights; // Dash lights available (see DL_x
below)
+ unsigned int ShowLights; // Dash lights currently switched
on
+ float Throttle; // 0 to 1
+ float Brake; // 0 to 1
+ float Clutch; // 0 to 1
+ char Display1[16]; // Usually Fuel
+ char Display2[16]; // Usually Settings
+ int ID; // optional - only if
OutGauge ID is specified
+ });
};
-#endif // OUTPROTCOL_H__
+#endif // _OUTPROTCOL_H__
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel