ape-position-nodes.patch

position nodes patch - Aperion, 08/04/2010 06:12 am

Download (11.4 kB)

source/main/Beam.h (working copy)
37 37

  
38 38
// system includes
39 39
#include <vector>
40
#include <map>
40 41
#include <pthread.h>
41 42

  
42 43
class Beam : 
......
226 227
	void setReplayMode(bool rm);
227 228
	int savePosition(int position);
228 229
	int loadPosition(int position);
230
	void updateTruckPosition();
229 231
	//! @}
230 232

  
231 233
	//! @{ camera related functions
......
691 693
	// RAIL GROUPS /////////////////////////////////////////////////////////////
692 694
	//! Stores all the available RailGroups for this truck
693 695
	std::vector< RailGroup* > mRailGroups;
694

  
696
	
695 697
	/**
696 698
	 * @param line line in configuration file
697 699
	 * @return true if line was successfully parsed, false if not
698 700
	 */
699 701
	bool parseRailGroupLine(const Ogre::String& line);
700 702

  
703
	// Position Nodes //////////////////////////////////////////////////////////
704
public:
705
	typedef unsigned int pos_node_loc;
706
	
707
	//! array helper for nodes types 
708
	typedef std::vector<pos_node_loc> pos_node_arr;
709
	
710
	//! use a map to ensure there are no duplicate entries 
711
	typedef std::map<pos_node_loc, pos_node_loc> pos_node_map;
712
	
713
	//! adds a list of nodes to remove from the list
714
	void addPositionNodes(pos_node_arr nodes);
715
	void addPositionNode(pos_node_loc node);
716

  
717
	//! removes a list of nodes to remove from the list
718
	void removePositionNodes(pos_node_arr nodes);
719
	void removePositionNode(pos_node_loc node);
720
	
721
private:
722
	//! stores a list of node positions used for calculating a trucks position
723
	pos_node_map mPositionNodes;
724
	/**
725
	 * @param line line in configuration file
726
	 * @return true if line was successfully parsed, false if not
727
	 */
728
	bool parsePositionNodeLine(const Ogre::String& line);
729
	
730

  
701 731
	// utility methods /////////////////////////////////////////////////////////
702 732

  
703 733
	/**
......
738 768
	beam_t* getBeam(node_t* node1, node_t* node2);
739 769

  
740 770
	/**
741
	 * Find node instance baed on the id
771
	 * Find node instance based on the id
742 772
	 * @param id of the node we are looking for
743 773
	 * @return pointer to node instance, NULL if no beam is found
744 774
	 */
745 775
	node_t* getNode(unsigned int id);
776

  
777
	/**
778
	 * Find a group of nodes from a string
779
	 * @param list of comma separated node values and ranges 
780
	 * @return a vector of node pointers
781
	 */
782
	std::vector<unsigned int> getNodeList(std::string list);
783
	std::vector<unsigned int> getNodeList(const Ogre::vector<Ogre::String>::type & railStrings);
784
	 ;
746 785
};
747 786

  
748 787

  
source/main/RoR.list (working copy)
118 118
  ShadowManager.h
119 119
)
120 120
set (SOURCE_FILES
121
  Beam/BeamPositionNodes.cpp
121 122
  gui_friction.cpp
122 123
  gui_mp.cpp
123 124
  gui_inputmanager.cpp
......
337 338
  angelscript/scriptstdstring/scriptstdstring.h
338 339
)
339 340
SOURCE_GROUP("Beam Engine" FILES
341
  Beam/BeamPositionNodes.cpp
340 342
  aeroengine.h
341 343
  airbrake.cpp
342 344
  airbrake.h
source/main/Beam.cpp (working copy)
1500 1500
		if (!strcmp("slidenodes",line)) {mode=64;continue;}
1501 1501
		if (!strcmp("flares2",line)) {mode=65;continue;};
1502 1502
		if (!strcmp("animators",line)) {mode=66;continue;};
1503
		if (!strcmp("position_nodes",line)) {mode=67;continue;};
1503 1504
		if (!strncmp("enable_advanced_deformation", line, 27))
1504 1505
		{
1505 1506
			// parse the optional threshold value
......
4946 4947

  
4947 4948
		else if (mode==63) parseRailGroupLine(line);
4948 4949
		else if (mode==64) parseSlideNodeLine(line);
4950
		else if (mode==67) parsePositionNodeLine(line);
4949 4951

  
4950 4952
	};
4951 4953
	if(!loading_finished) {
......
4963 4965
			if (revroll[i]) LogManager::getSingleton().logMessage("Warning: camera definition is probably invalid and has been corrected. It should be center, back, left");
4964 4966
		}
4965 4967
	}
4968
	//
4969
	if( mPositionNodes.empty() )
4970
	{
4971
		addPositionNodes(getNodeList(Ogre::String("0-") + Ogre::StringConverter::toString(free_node)));
4972
	}
4973
	
4966 4974
//		fclose(fd);
4967 4975
	//wing closure
4968 4976
	if (wingstart!=-1)
......
5405 5413
	return 0;
5406 5414
}
5407 5415

  
5416
void Beam::updateTruckPosition()
5417
{
5418

  
5419
	for (int n = 0; n < free_node; n++)
5420
	{
5421
		nodes[n].smoothpos = nodes[n].AbsPosition;
5422
	}
5423
	
5424
	// average position
5425
	Vector3 aposition=Vector3::ZERO;
5426
	
5427
	// do a seperate loop since there won't be as many nodes
5428
	for( pos_node_map::iterator it = mPositionNodes.begin()
5429
	; it != mPositionNodes.end()
5430
	; it++)
5431
	{
5432
		aposition += nodes[it->second].smoothpos;
5433
	}
5434
	position = aposition / mPositionNodes.size();
5435
}
5436

  
5408 5437
void Beam::resetAngle(float rot)
5409 5438
{
5410 5439
	// Set origin of rotation to camera node
......
6464 6493
				if (trucks[t]->reset_requested) trucks[t]->SyncReset();
6465 6494
				if (trucks[t]->state!=SLEEPING && trucks[t]->state!=NETWORKED && trucks[t]->state!=RECYCLE)
6466 6495
				{
6467
					// calculate average position
6468
					Vector3 aposition=Vector3::ZERO;
6469
					int nodesnum=0;
6470
					for (int n=0; n<trucks[t]->free_node; n++)
6471
					{
6472
//							trucks[t]->nodes[n].smoothpos=trucks[t]->nodes[n].tsmooth/steps;
6473
							trucks[t]->nodes[n].smoothpos = trucks[t]->nodes[n].AbsPosition;
6474
							if((trucks[t]->nodes[n].AbsPosition - trucks[t]->nodes[0].AbsPosition).squaredLength() > trucks[t]->nodes[n].iDistance * 25)
6475
							{
6476
								// loose node, ignore ...
6477
							} else
6478
							{
6479
								// valid node
6480
								aposition += trucks[t]->nodes[n].smoothpos;
6481
								nodesnum++;
6482
							}
6483
//							trucks[t]->nodes[n].tsmooth=Vector3::ZERO;
6484
					}
6485
					trucks[t]->position = aposition / nodesnum;
6496
					trucks[t]->updateTruckPosition();
6486 6497
				}
6487 6498
				if (floating_origin_enable && trucks[t]->nodes[0].RelPosition.length()>100.0)
6488 6499
				{
......
6516 6527
				if (trucks[t]->reset_requested) trucks[t]->SyncReset();
6517 6528
				if (trucks[t]->state!=SLEEPING && trucks[t]->state!=NETWORKED && trucks[t]->state!=RECYCLE)
6518 6529
				{
6519
					// average position
6520
					Vector3 aposition=Vector3::ZERO;
6521

  
6522
					// TODO Unused Varaible
6523
					//int nodesnum=0;
6524
					for (int n=0; n<trucks[t]->free_node; n++)
6525
					{
6526
						trucks[t]->nodes[n].smoothpos=trucks[t]->nodes[n].AbsPosition;
6527
						aposition += trucks[t]->nodes[n].smoothpos;
6528
					}
6529
					trucks[t]->position = aposition / free_node;
6530
					trucks[t]->updateTruckPosition();
6530 6531
				}
6531 6532
				if (floating_origin_enable && trucks[t]->nodes[0].RelPosition.length()>100.0)
6532 6533
				{
......
6559 6560

  
6560 6561
			if (state!=SLEEPING && state!=NETWORKED && state!=RECYCLE)
6561 6562
			{
6562
				// average position
6563
				Vector3 aposition=Vector3::ZERO;
6564

  
6565
				// TODO Unused Varaible
6566
				//int nodesnum=0;
6567
				for (int n=0; n<free_node; n++)
6568
				{
6569
					nodes[n].smoothpos=nodes[n].AbsPosition;
6570
					aposition += nodes[n].smoothpos;
6571
				}
6572
				position = aposition / free_node;
6563
				updateTruckPosition();
6573 6564
			}
6574 6565
			if (floating_origin_enable && nodes[0].RelPosition.length()>100.0)
6575 6566
			{
......
11147 11138

  
11148 11139
node_t* Beam::getNode(unsigned int id)
11149 11140
{
11141
	// ID is usually the same as the array location, check there first
11142
	if( id >= (unsigned int)free_node ) return NULL;
11143
	if( nodes[id].id == (int)id ) return &nodes[id];
11144
	
11150 11145
	for( unsigned int i = 0 ; i < (unsigned  int)free_node; ++i)
11151 11146
		if( nodes[i].id == (int)id )
11152 11147
			return &nodes[i];
......
11155 11150
	return NULL;
11156 11151
}
11157 11152

  
11153
std::vector<unsigned int> Beam::getNodeList(std::string list)
11154
{
11155
	return getNodeList(Ogre::StringUtil::split(list, ","));
11156
}
11157

  
11158
std::vector<unsigned  int> Beam::getNodeList(const Ogre::vector<Ogre::String>::type & nodeStrings)
11159
{
11160
	std::vector<unsigned int> nodeids;
11161
    
11162
	// convert all strings to integers
11163
	for( unsigned int i = 0; i < nodeStrings.size(); ++i )
11164
	{
11165
		const Ogre::String& node = nodeStrings[i]; 
11166
		
11167
		// check if value is a node range
11168
		if(node.find("-") == Ogre::String::npos )
11169
		{
11170
			nodeids.push_back(StringConverter::parseInt(node));
11171
			continue;
11172
		}
11173
			
11174
		size_t pos = node.find("-");
11175
		
11176
		// from start to '-'
11177
		const int start = StringConverter::parseInt( node.substr(0, pos) );
11178
		// from character after '-' to end 
11179
		const int end = StringConverter::parseInt( node.substr(++pos) );
11180
		
11181
		for(int j = start ; j <= end; ++j )
11182
		{
11183
			// if end is lower than start then 
11184
			nodeids.push_back( j );
11185
		}
11186
	}
11187
	return nodeids;
11188

  
11189
}
11190

  
11158 11191
//Returns the number of active (non bounded) beams connected to a node
11159 11192
int Beam::nodeBeamConnections(int nodeid)
11160 11193
{
source/main/Beam/BeamPositionNodes.cpp (revision 0)
1
/**
2
 @file BeamPositionNodes.cpp
3
 @author Christopher Ritchey
4
 @date 07/23/2010
5
 
6
This source file is part of Rigs of Rods
7
Copyright 2009, 2010 Christopher Ritchey
8

  
9
For more information, see http://www.rigsofrods.com/
10

  
11
Rigs of Rods is free software: you can redistribute it and/or modify
12
it under the terms of the GNU General Public License version 3, as
13
published by the Free Software Foundation.
14

  
15
Rigs of Rods is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
GNU General Public License for more details.
19

  
20
You should have received a copy of the GNU General Public License
21
along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
22
*/
23
#include "Beam.h"
24

  
25
bool Beam::parsePositionNodeLine(const Ogre::String& line)
26
{
27
	// lines start with exclude or include followed by a node range
28
	bool add_nodes = Ogre::StringUtil::startsWith(line, "include", true);
29
	if( !add_nodes && !Ogre::StringUtil::startsWith(line, "exclude", true))
30
	{
31
		LogManager::getSingleton().logMessage("PositionNode: lines need to start with Include or Exclude: " + String(line));
32
		return false;
33
	}
34
	
35
	size_t start = line.find_first_of("\t ");
36
	start = line.find_first_not_of("\t ", start);
37
	
38
	pos_node_arr nodelist = getNodeList(line.substr(start));
39
	
40
	if( add_nodes )
41
		addPositionNodes( nodelist );
42
	else
43
		removePositionNodes( nodelist );
44
	return true;
45
}
46
	
47
void Beam::addPositionNodes(pos_node_arr nodes)
48
{
49
	for(pos_node_arr::iterator it = nodes.begin()
50
	; it != nodes.end()
51
	; it++ )
52
	{
53
		addPositionNode(*it);
54
	}
55
	
56
}
57

  
58
void Beam::addPositionNode(pos_node_loc node)
59
{
60
	if( node >= free_node ) return; 
61
	mPositionNodes[node] = node;
62
}
63

  
64
void Beam::removePositionNodes(pos_node_arr nodes)
65
{
66
	for(pos_node_arr::iterator it = nodes.begin()
67
	; it != nodes.end()
68
	; it++ )
69
	{
70
		removePositionNode(*it);
71
	}
72
	
73
}
74

  
75
void Beam::removePositionNode(pos_node_loc node)
76
{
77
	if( node >= free_node ) return;
78
	mPositionNodes.erase(node);
79
}
source/main/CMakeLists.txt (working copy)
39 39
ENDIF(WIN32)
40 40

  
41 41
include_directories(${RoR_SOURCE_DIR}/source/protocol)
42
include_directories(${RoR_SOURCE_DIR}/source/main)
42 43

  
43 44
# required components
44 45
include_directories(${Ogre_INCLUDE_DIRS})
source/installer/wizard.cpp (working copy)
192 192
	// ignore auto-update function
193 193
    if(parser.Found(wxT("n"))) autoUpdateEnabled=false;
194 194
	
195

  
196
#if wxCHECK_VERSION(2, 9, 0)
195 197
	// special mode: put our hash into the clipboard
196 198
	if(parser.Found(wxT("d")))
197 199
	{
......
204 206
		}
205 207
		exit(0);
206 208
	}
209
#endif
207 210
    return true;
208 211
}
209 212