Revision: 1614
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1614&view=rev
Author: rorthomas
Date: 2011-01-30 22:37:46 +0000 (Sun, 30 Jan 2011)
Log Message:
-----------
fixed lots of multiplayer problems
Modified Paths:
--------------
trunk/source/main/Beam.cpp
trunk/source/main/BeamData.h
trunk/source/main/Character.cpp
trunk/source/main/Character.h
trunk/source/main/ChatSystem.cpp
trunk/source/main/RoRFrameListener.cpp
trunk/source/main/utils.cpp
trunk/source/main/utils.h
Modified: trunk/source/main/Beam.cpp
===================================================================
--- trunk/source/main/Beam.cpp 2011-01-30 21:14:29 UTC (rev 1613)
+++ trunk/source/main/Beam.cpp 2011-01-30 22:37:46 UTC (rev 1614)
@@ -305,6 +305,51 @@
Beam::Beam(int tnum, SceneManager *manager, SceneNode *parent, RenderWindow*
win, Network *_net, float *_mapsizex, float *_mapsizez, Real px, Real py, Real
pz, Quaternion rot, const char* fname, Collisions *icollisions, HeightFinder
*mfinder, Water *w, Camera *pcam, Mirrors *mmirror, bool networked, bool
networking, collision_box_t *spawnbox, bool ismachine, int _flaresMode,
std::vector<Ogre::String> *_truckconfig, Skin *skin, bool freeposition) : \
deleting(false)
{
+
+ // clear rig parent structure
+ // this is important, since we might check if we need to delete stuff
and then it crashes if not initialized with zero ...
+ // this is surely ugly as hell!
+ memset(this->nodes, 0, sizeof(node_t) * MAX_NODES); free_node = 0;
+ memset(this->beams, 0, sizeof(beam_t) * MAX_BEAMS); free_beam = 0;
+ memset(this->contacters, 0, sizeof(contacter_t) * MAX_CONTACTERS);
free_contacter = 0;
+ memset(this->rigidifiers, 0, sizeof(rigidifier_t) * MAX_RIGIDIFIERS);
free_rigidifier = 0;
+ memset(this->wheels, 0, sizeof(wheel_t) * MAX_WHEELS); free_wheel = 0;
+ memset(this->vwheels, 0, sizeof(vwheel_t) * MAX_WHEELS);
+ ropes.clear();
+ ropables.clear();
+ ties.clear();
+ hooks.clear();
+ memset(this->wings, 0, sizeof(wing_t) * MAX_WINGS); free_wing = 0;
+ memset(this->commandkey, 0, sizeof(command_t) * (MAX_COMMANDS + 1));
+ memset(this->rotators, 0, sizeof(rotator_t) * MAX_ROTATORS);
free_rotator = 0;
+ flares.clear(); free_flare = 0;
+ memset(this->props, 0, sizeof(prop_t) * MAX_PROPS); free_prop = 0;
+ driverSeat=0;
+ memset(this->shocks, 0, sizeof(shock_t) * MAX_SHOCKS); free_shock = 0;
free_active_shock = 0;
+ exhausts.clear();
+ memset(this->cparticles, 0, sizeof(cparticle_t) * MAX_CPARTICLES);
free_cparticle = 0;
+ nodes_debug.clear();
+ beams_debug.clear();
+ memset(this->soundsources, 0, sizeof(soundsource_t) *
MAX_SOUNDSCRIPTS_PER_TRUCK); free_soundsource = 0;
+ memset(this->pressure_beams, 0, sizeof(int) * MAX_PRESSURE_BEAMS);
free_pressure_beam = 0;
+ memset(this->aeroengines, 0, sizeof(AeroEngine *) * MAX_AEROENGINES);
free_aeroengine = 0;
+ memset(this->cabs, 0, sizeof(int) * (MAX_CABS*3)); free_cab = 0;
+ memset(this->subisback, 0, sizeof(int) * MAX_SUBMESHES);
+ memset(this->hydro, 0, sizeof(int) * MAX_HYDROS); free_hydro = 0;
+ for(int i=0;i<MAX_TEXCOORDS;i++) this->texcoords[i] = Vector3::ZERO;
+ free_texcoord=0;
+ memset(this->subtexcoords, 0, sizeof(int) * MAX_SUBMESHES); free_sub =
0;
+ memset(this->subcabs, 0, sizeof(int) * MAX_SUBMESHES);
+ memset(this->collcabs, 0, sizeof(int) * MAX_CABS);
+ memset(this->collcabstype, 0, sizeof(int) * MAX_CABS);
+ memset(this->collcabrate, 0, sizeof(collcab_rate_t) * MAX_CABS);
free_collcab = 0;
+ memset(this->buoycabs, 0, sizeof(int) * MAX_CABS); free_buoycab = 0;
+ memset(this->buoycabtypes, 0, sizeof(int) * MAX_CABS);
+ memset(this->airbrakes, 0, sizeof(Airbrake *) * MAX_AIRBRAKES);
free_airbrake = 0;
+ memset(this->skidtrails, 0, sizeof(Skidmark *) * (MAX_WHEELS*2));
useSkidmarks = false;
+ memset(this->flexbodies, 0, sizeof(FlexBody *) * MAX_FLEXBODIES);
free_flexbody = 0;
+ // clearing done
+
net=_net;
if(net && !networking) networking = true; // enable networking if some
network class is existing
Modified: trunk/source/main/BeamData.h
===================================================================
--- trunk/source/main/BeamData.h 2011-01-30 21:14:29 UTC (rev 1613)
+++ trunk/source/main/BeamData.h 2011-01-30 22:37:46 UTC (rev 1614)
@@ -655,11 +655,11 @@
int pressure_beams[MAX_PRESSURE_BEAMS];
int free_pressure_beam;
+ AeroEngine *aeroengines[MAX_AEROENGINES];
int free_aeroengine;
- AeroEngine *aeroengines[MAX_AEROENGINES];
+ Screwprop *screwprops[MAX_SCREWPROPS];
int free_screwprop;
- Screwprop *screwprops[MAX_SCREWPROPS];
int cabs[MAX_CABS*3];
int subisback[MAX_SUBMESHES];
@@ -684,8 +684,8 @@
int buoycabtypes[MAX_CABS];
int free_buoycab;
+ Airbrake *airbrakes[MAX_AIRBRAKES];
int free_airbrake;
- Airbrake *airbrakes[MAX_AIRBRAKES];
Skidmark *skidtrails[MAX_WHEELS*2];
bool useSkidmarks;
Modified: trunk/source/main/Character.cpp
===================================================================
--- trunk/source/main/Character.cpp 2011-01-30 21:14:29 UTC (rev 1613)
+++ trunk/source/main/Character.cpp 2011-01-30 22:37:46 UTC (rev 1614)
@@ -32,6 +32,8 @@
#include "ColoredTextAreaOverlayElement.h"
#include "PlayerColours.h"
+#include "utils.h"
+
using namespace Ogre;
unsigned int Character::characterCounter=0;
@@ -562,9 +564,14 @@
pos_netdata_t data;
data.command = CHARCMD_POSITION;
- data.pos = personode->getPosition();
- data.rot = personode->getOrientation();
- data.animationMode = lastmode;
+ data.posx = personode->getPosition().x;
+ data.posy = personode->getPosition().y;
+ data.posz = personode->getPosition().z;
+ data.rotx = personode->getOrientation().x;
+ data.roty = personode->getOrientation().y;
+ data.rotz = personode->getOrientation().z;
+ data.rotw = personode->getOrientation().w;
+ strncpy(data.animationMode, lastmode.c_str(), 254);
data.animationTime =
persoanim->getAnimationState(lastmode)->getTimePosition();
//LogManager::getSingleton().logMessage("sending character stream data:
" + StringConverter::toString(net->getUserID()) + ":"+
StringConverter::toString(streamid));
@@ -580,9 +587,11 @@
{
// position
pos_netdata_t *data = (pos_netdata_t *)buffer;
- this->setPosition(data->pos);
- this->setOrientation(data->rot);
- setAnimationMode(data->animationMode,
data->animationTime);
+ Vector3 pos(data->posx, data->posy, data->posz);
+ this->setPosition(pos);
+ Quaternion rot(data->rotw, data->rotx, data->roty,
data->rotz);
+ this->setOrientation(rot);
+
setAnimationMode(getASCIIFromCharString(data->animationMode, 255),
data->animationTime);
} else if (header->command == CHARCMD_ATTACH)
{
// attach
Modified: trunk/source/main/Character.h
===================================================================
--- trunk/source/main/Character.h 2011-01-30 21:14:29 UTC (rev 1613)
+++ trunk/source/main/Character.h 2011-01-30 22:37:46 UTC (rev 1614)
@@ -119,10 +119,10 @@
typedef struct pos_netdata_t
{
int command;
- Ogre::Vector3 pos;
- Ogre::Quaternion rot;
- Ogre::String animationMode;
- Ogre::Real animationTime;
+ float posx, posy, posz;
+ float rotx, roty, rotz, rotw;
+ char animationMode[255];
+ float animationTime;
} pos_netdata_t;
typedef struct attach_netdata_t
Modified: trunk/source/main/ChatSystem.cpp
===================================================================
--- trunk/source/main/ChatSystem.cpp 2011-01-30 21:14:29 UTC (rev 1613)
+++ trunk/source/main/ChatSystem.cpp 2011-01-30 22:37:46 UTC (rev 1614)
@@ -163,7 +163,7 @@
if(source == -1)
{
// server said something
- NETCHAT.addText(String(buffer));
+ NETCHAT.addText(getASCIIFromCharString(buffer, 255));
} else if(source == (int)this->source && (int)streamid ==
this->streamid)
{
UTFString text = tryConvertUTF(buffer);
Modified: trunk/source/main/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/RoRFrameListener.cpp 2011-01-30 21:14:29 UTC (rev
1613)
+++ trunk/source/main/RoRFrameListener.cpp 2011-01-30 22:37:46 UTC (rev
1614)
@@ -1218,7 +1218,7 @@
// so show the terrain selection
preselected_map = "";
else
- preselected_map = String(terrn);
+ preselected_map = getASCIIFromCharString(terrn, 255);
// show chat in MP
NETCHAT.setMode(this, NETCHAT_LEFT_SMALL, true);
@@ -1260,9 +1260,14 @@
{
if(!CACHE.checkResourceLoaded(preselected_map))
{
- LogManager::getSingleton().logMessage("Terrain not
found: " + preselected_map);
- showError(_L("Terrain loading error"), _L("Terrain not
found: ") + preselected_map);
- exit(123);
+ // fallback to old terrain name with .terrn
+ if(!CACHE.checkResourceLoaded(preselected_map +
".terrn"))
+ {
+ LogManager::getSingleton().logMessage("Terrain
not found: " + preselected_map);
+ showError(_L("Terrain loading error"),
_L("Terrain not found: ") + preselected_map);
+ exit(123);
+ } else
+ preselected_map = preselected_map + ".terrn";
}
// set the terrain cache entry
@@ -1395,6 +1400,7 @@
{
// load preselected map
char mapname[1024];
+ String group="";
sprintf(mapname, "%s.terrn", preselected_map);
loadTerrain(mapname);
//miniature map stuff
@@ -1402,7 +1408,7 @@
//search if mini picture exists
char ppname[1024];
sprintf(ppname, "%s-mini.dds", preselected_map);
- String group="";
+ group="";
if(group == "")
{
sprintf(ppname, "%s-mini.png", preselected_map);
@@ -4703,9 +4709,15 @@
// check if the resource is loaded
if(!CACHE.checkResourceLoaded(terrainfile))
{
- LogManager::getSingleton().logMessage("Terrain not found: " +
terrainfile);
- showError(_L("Terrain loading error"), _L("Terrain not found:
") + terrainfile);
- exit(123);
+ // fallback for terrains, add .terrn if not found and retry
+ if(!CACHE.checkResourceLoaded(terrainfile+".terrn"))
+ {
+ LogManager::getSingleton().logMessage("Terrain not
found: " + terrainfile);
+ showError(_L("Terrain loading error"), _L("Terrain not
found: ") + terrainfile);
+ exit(123);
+ } else
+ terrainfile = terrainfile + ".terrn";
+
}
loadedTerrain = terrainfile;
Modified: trunk/source/main/utils.cpp
===================================================================
--- trunk/source/main/utils.cpp 2011-01-30 21:14:29 UTC (rev 1613)
+++ trunk/source/main/utils.cpp 2011-01-30 22:37:46 UTC (rev 1614)
@@ -109,4 +109,38 @@
//else if(bytes > 1099511627776)
// sprintf(res, "%0.2f TB", bytes / 1024.0f / 1024.0f / 1024.0f /
1024.0f);
return Ogre::String(tmp);
-}
\ No newline at end of file
+}
+
+// replace non-ASCII characters with underscores to prevent std::string
problems
+Ogre::String getASCIIFromCharString(char *str, int maxlen)
+{
+ char *ptr = str;
+ for(int i=0; i < maxlen; i++, ptr++)
+ {
+ if(*ptr == 0) break;
+ if(*ptr < 32 || *ptr > 126)
+ {
+ *ptr = 95;
+ }
+ }
+ str[maxlen] = 0;
+ return std::string(str);
+}
+
+// replace non-ASCII characters with underscores to prevent std::string
problems
+Ogre::String getASCIIFromOgreString(Ogre::String s, int maxlen)
+{
+ char str[1024] = "";
+ strncpy(str, s.c_str(), 1023);
+ char *ptr = str;
+ for(int i=0; i < maxlen; i++, ptr++)
+ {
+ if(*ptr == 0) break;
+ if(*ptr < 32 || *ptr > 126)
+ {
+ *ptr = 95;
+ }
+ }
+ str[maxlen] = 0;
+ return std::string(str);
+}
Modified: trunk/source/main/utils.h
===================================================================
--- trunk/source/main/utils.h 2011-01-30 21:14:29 UTC (rev 1613)
+++ trunk/source/main/utils.h 2011-01-30 22:37:46 UTC (rev 1614)
@@ -33,4 +33,8 @@
Ogre::String formatBytes(double bytes);
+
+Ogre::String getASCIIFromCharString(char *str, int maxlen);
+Ogre::String getASCIIFromOgreString(Ogre::String s, int maxlen);
+
#endif //UTILS_H_
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel