Map Editor

RD Core / Commit #3

Commit Map Editor

Alex Alex committed 18/10/2026 23:40 main Patch
436 files +250,791 -0
A RD_Map_Editor/source/json/json_spirit_stream_reader.h +70-0 View file
@@ -0,0 +1,70 @@
1+#ifndef JSON_SPIRIT_READ_STREAM
2+#define JSON_SPIRIT_READ_STREAM
3+
4+// Copyright John W. Wilkinson 2007 - 2009.
5+// Distributed under the MIT License, see accompanying file LICENSE.txt
6+
7+// json spirit version 4.03
8+
9+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
10+# pragma once
11+#endif
12+
13+#include "json_spirit_reader_template.h"
14+
15+namespace json_spirit
16+{
17+ // these classes allows you to read multiple top level contiguous values from a stream,
18+ // the normal stream read functions have a bug that prevent multiple top level values
19+ // from being read unless they are separated by spaces
20+
21+ template< class Istream_type, class Value_type >
22+ class Stream_reader
23+ {
24+ public:
25+
26+ Stream_reader( Istream_type& is )
27+ : iters_( is )
28+ {
29+ }
30+
31+ bool read_next( Value_type& value )
32+ {
33+ return read_range( iters_.begin_, iters_.end_, value );
34+ }
35+
36+ private:
37+
38+ typedef Multi_pass_iters< Istream_type > Mp_iters;
39+
40+ Mp_iters iters_;
41+ };
42+
43+ template< class Istream_type, class Value_type >
44+ class Stream_reader_thrower
45+ {
46+ public:
47+
48+ Stream_reader_thrower( Istream_type& is )
49+ : iters_( is )
50+ , posn_begin_( iters_.begin_, iters_.end_ )
51+ , posn_end_( iters_.end_, iters_.end_ )
52+ {
53+ }
54+
55+ void read_next( Value_type& value )
56+ {
57+ posn_begin_ = read_range_or_throw( posn_begin_, posn_end_, value );
58+ }
59+
60+ private:
61+
62+ typedef Multi_pass_iters< Istream_type > Mp_iters;
63+ typedef spirit_namespace::position_iterator< typename Mp_iters::Mp_iter > Posn_iter_t;
64+
65+ Mp_iters iters_;
66+ Posn_iter_t posn_begin_, posn_end_;
67+ };
68+}
69+
70+#endif
A RD_Map_Editor/source/json/json_spirit_utils.h +61-0 View file
@@ -0,0 +1,61 @@
1+#ifndef JSON_SPIRIT_UTILS
2+#define JSON_SPIRIT_UTILS
3+
4+// Copyright John W. Wilkinson 2007 - 2009.
5+// Distributed under the MIT License, see accompanying file LICENSE.txt
6+
7+// json spirit version 4.03
8+
9+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
10+# pragma once
11+#endif
12+
13+#include "json_spirit_value.h"
14+#include <map>
15+
16+namespace json_spirit
17+{
18+ template< class Obj_t, class Map_t >
19+ void obj_to_map( const Obj_t& obj, Map_t& mp_obj )
20+ {
21+ mp_obj.clear();
22+
23+ for( typename Obj_t::const_iterator i = obj.begin(); i != obj.end(); ++i )
24+ {
25+ mp_obj[ i->name_ ] = i->value_;
26+ }
27+ }
28+
29+ template< class Obj_t, class Map_t >
30+ void map_to_obj( const Map_t& mp_obj, Obj_t& obj )
31+ {
32+ obj.clear();
33+
34+ for( typename Map_t::const_iterator i = mp_obj.begin(); i != mp_obj.end(); ++i )
35+ {
36+ obj.push_back( typename Obj_t::value_type( i->first, i->second ) );
37+ }
38+ }
39+
40+ typedef std::map< std::string, Value > Mapped_obj;
41+
42+#ifndef BOOST_NO_STD_WSTRING
43+ typedef std::map< std::wstring, wValue > wMapped_obj;
44+#endif
45+
46+ template< class Object_type, class String_type >
47+ const typename Object_type::value_type::Value_type& find_value( const Object_type& obj, const String_type& name )
48+ {
49+ for( typename Object_type::const_iterator i = obj.begin(); i != obj.end(); ++i )
50+ {
51+ if( i->name_ == name )
52+ {
53+ return i->value_;
54+ }
55+ }
56+
57+ return Object_type::value_type::Value_type::null;
58+ }
59+}
60+
61+#endif
A RD_Map_Editor/source/json/json_spirit_value.cpp +8-0 View file
@@ -0,0 +1,8 @@
1+/* Copyright (c) 2007 John W Wilkinson
2+
3+ This source code can be used for any purpose as long as
4+ this comment is retained. */
5+
6+// json spirit version 2.00
7+
8+#include "json_spirit_value.h"
A RD_Map_Editor/source/json/json_spirit_value.h +532-0 View file
@@ -0,0 +1,532 @@
1+#ifndef JSON_SPIRIT_VALUE
2+#define JSON_SPIRIT_VALUE
3+
4+// Copyright John W. Wilkinson 2007 - 2009.
5+// Distributed under the MIT License, see accompanying file LICENSE.txt
6+
7+// json spirit version 4.03
8+
9+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
10+# pragma once
11+#endif
12+
13+#include <vector>
14+#include <map>
15+#include <string>
16+#include <cassert>
17+#include <sstream>
18+#include <stdexcept>
19+#include <boost/config.hpp>
20+#include <boost/cstdint.hpp>
21+#include <boost/shared_ptr.hpp>
22+#include <boost/variant.hpp>
23+
24+namespace json_spirit
25+{
26+ enum Value_type{ obj_type, array_type, str_type, bool_type, int_type, real_type, null_type };
27+
28+ template< class Config > // Config determines whether the value uses std::string or std::wstring and
29+ // whether JSON Objects are represented as vectors or maps
30+ class Value_impl
31+ {
32+ public:
33+
34+ typedef Config Config_type;
35+ typedef typename Config::String_type String_type;
36+ typedef typename Config::Object_type Object;
37+ typedef typename Config::Array_type Array;
38+ typedef typename String_type::const_pointer Const_str_ptr; // eg const char*
39+
40+ Value_impl(); // creates null value
41+ Value_impl( Const_str_ptr value );
42+ Value_impl( const String_type& value );
43+ Value_impl( const Object& value );
44+ Value_impl( const Array& value );
45+ Value_impl( bool value );
46+ Value_impl( int value );
47+ Value_impl( boost::int64_t value );
48+ Value_impl( boost::uint64_t value );
49+ Value_impl( double value );
50+
51+ Value_impl( const Value_impl& other );
52+
53+ bool operator==( const Value_impl& lhs ) const;
54+
55+ Value_impl& operator=( const Value_impl& lhs );
56+
57+ Value_type type() const;
58+
59+ bool is_uint64() const;
60+ bool is_null() const;
61+
62+ const String_type& get_str() const;
63+ const Object& get_obj() const;
64+ const Array& get_array() const;
65+ bool get_bool() const;
66+ int get_int() const;
67+ boost::int64_t get_int64() const;
68+ boost::uint64_t get_uint64() const;
69+ double get_real() const;
70+
71+ Object& get_obj();
72+ Array& get_array();
73+
74+ template< typename T > T get_value() const; // example usage: int i = value.get_value< int >();
75+ // or double d = value.get_value< double >();
76+
77+ static const Value_impl null;
78+
79+ private:
80+
81+ void check_type( const Value_type vtype ) const;
82+
83+ typedef boost::variant< String_type,
84+ boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >,
85+ bool, boost::int64_t, double > Variant;
86+
87+ Value_type type_;
88+ Variant v_;
89+ bool is_uint64_;
90+ };
91+
92+ // vector objects
93+
94+ template< class Config >
95+ struct Pair_impl
96+ {
97+ typedef typename Config::String_type String_type;
98+ typedef typename Config::Value_type Value_type;
99+
100+ Pair_impl( const String_type& name, const Value_type& value );
101+
102+ bool operator==( const Pair_impl& lhs ) const;
103+
104+ String_type name_;
105+ Value_type value_;
106+ };
107+
108+ template< class String >
109+ struct Config_vector
110+ {
111+ typedef String String_type;
112+ typedef Value_impl< Config_vector > Value_type;
113+ typedef Pair_impl < Config_vector > Pair_type;
114+ typedef std::vector< Value_type > Array_type;
115+ typedef std::vector< Pair_type > Object_type;
116+
117+ static Value_type& add( Object_type& obj, const String_type& name, const Value_type& value )
118+ {
119+ obj.push_back( Pair_type( name , value ) );
120+
121+ return obj.back().value_;
122+ }
123+
124+ static String_type get_name( const Pair_type& pair )
125+ {
126+ return pair.name_;
127+ }
128+
129+ static Value_type get_value( const Pair_type& pair )
130+ {
131+ return pair.value_;
132+ }
133+ };
134+
135+ // typedefs for ASCII
136+
137+ typedef Config_vector< std::string > Config;
138+
139+ typedef Config::Value_type Value;
140+ typedef Config::Pair_type Pair;
141+ typedef Config::Object_type Object;
142+ typedef Config::Array_type Array;
143+
144+ // typedefs for Unicode
145+
146+#ifndef BOOST_NO_STD_WSTRING
147+
148+ typedef Config_vector< std::wstring > wConfig;
149+
150+ typedef wConfig::Value_type wValue;
151+ typedef wConfig::Pair_type wPair;
152+ typedef wConfig::Object_type wObject;
153+ typedef wConfig::Array_type wArray;
154+#endif
155+
156+ // map objects
157+
158+ template< class String >
159+ struct Config_map
160+ {
161+ typedef String String_type;
162+ typedef Value_impl< Config_map > Value_type;
163+ typedef std::vector< Value_type > Array_type;
164+ typedef std::map< String_type, Value_type > Object_type;
165+ typedef typename Object_type::value_type Pair_type;
166+
167+ static Value_type& add( Object_type& obj, const String_type& name, const Value_type& value )
168+ {
169+ return obj[ name ] = value;
170+ }
171+
172+ static String_type get_name( const Pair_type& pair )
173+ {
174+ return pair.first;
175+ }
176+
177+ static Value_type get_value( const Pair_type& pair )
178+ {
179+ return pair.second;
180+ }
181+ };
182+
183+ // typedefs for ASCII
184+
185+ typedef Config_map< std::string > mConfig;
186+
187+ typedef mConfig::Value_type mValue;
188+ typedef mConfig::Object_type mObject;
189+ typedef mConfig::Array_type mArray;
190+
191+ // typedefs for Unicode
192+
193+#ifndef BOOST_NO_STD_WSTRING
194+
195+ typedef Config_map< std::wstring > wmConfig;
196+
197+ typedef wmConfig::Value_type wmValue;
198+ typedef wmConfig::Object_type wmObject;
199+ typedef wmConfig::Array_type wmArray;
200+
201+#endif
202+
203+ ///////////////////////////////////////////////////////////////////////////////////////////////
204+ //
205+ // implementation
206+
207+ template< class Config >
208+ const Value_impl< Config > Value_impl< Config >::null;
209+
210+ template< class Config >
211+ Value_impl< Config >::Value_impl()
212+ : type_( null_type )
213+ , is_uint64_( false )
214+ {
215+ }
216+
217+ template< class Config >
218+ Value_impl< Config >::Value_impl( const Const_str_ptr value )
219+ : type_( str_type )
220+ , v_( String_type( value ) )
221+ , is_uint64_( false )
222+ {
223+ }
224+
225+ template< class Config >
226+ Value_impl< Config >::Value_impl( const String_type& value )
227+ : type_( str_type )
228+ , v_( value )
229+ , is_uint64_( false )
230+ {
231+ }
232+
233+ template< class Config >
234+ Value_impl< Config >::Value_impl( const Object& value )
235+ : type_( obj_type )
236+ , v_( value )
237+ , is_uint64_( false )
238+ {
239+ }
240+
241+ template< class Config >
242+ Value_impl< Config >::Value_impl( const Array& value )
243+ : type_( array_type )
244+ , v_( value )
245+ , is_uint64_( false )
246+ {
247+ }
248+
249+ template< class Config >
250+ Value_impl< Config >::Value_impl( bool value )
251+ : type_( bool_type )
252+ , v_( value )
253+ , is_uint64_( false )
254+ {
255+ }
256+
257+ template< class Config >
258+ Value_impl< Config >::Value_impl( int value )
259+ : type_( int_type )
260+ , v_( static_cast< boost::int64_t >( value ) )
261+ , is_uint64_( false )
262+ {
263+ }
264+
265+ template< class Config >
266+ Value_impl< Config >::Value_impl( boost::int64_t value )
267+ : type_( int_type )
268+ , v_( value )
269+ , is_uint64_( false )
270+ {
271+ }
272+
273+ template< class Config >
274+ Value_impl< Config >::Value_impl( boost::uint64_t value )
275+ : type_( int_type )
276+ , v_( static_cast< boost::int64_t >( value ) )
277+ , is_uint64_( true )
278+ {
279+ }
280+
281+ template< class Config >
282+ Value_impl< Config >::Value_impl( double value )
283+ : type_( real_type )
284+ , v_( value )
285+ , is_uint64_( false )
286+ {
287+ }
288+
289+ template< class Config >
290+ Value_impl< Config >::Value_impl( const Value_impl< Config >& other )
291+ : type_( other.type() )
292+ , v_( other.v_ )
293+ , is_uint64_( other.is_uint64_ )
294+ {
295+ }
296+
297+ template< class Config >
298+ Value_impl< Config >& Value_impl< Config >::operator=( const Value_impl& lhs )
299+ {
300+ Value_impl tmp( lhs );
301+
302+ std::swap( type_, tmp.type_ );
303+ std::swap( v_, tmp.v_ );
304+ std::swap( is_uint64_, tmp.is_uint64_ );
305+
306+ return *this;
307+ }
308+
309+ template< class Config >
310+ bool Value_impl< Config >::operator==( const Value_impl& lhs ) const
311+ {
312+ if( this == &lhs ) return true;
313+
314+ if( type() != lhs.type() ) return false;
315+
316+ return v_ == lhs.v_;
317+ }
318+
319+ template< class Config >
320+ Value_type Value_impl< Config >::type() const
321+ {
322+ return type_;
323+ }
324+
325+ template< class Config >
326+ bool Value_impl< Config >::is_uint64() const
327+ {
328+ return is_uint64_;
329+ }
330+
331+ template< class Config >
332+ bool Value_impl< Config >::is_null() const
333+ {
334+ return type() == null_type;
335+ }
336+
337+ template< class Config >
338+ void Value_impl< Config >::check_type( const Value_type vtype ) const
339+ {
340+ if( type() != vtype )
341+ {
342+ std::ostringstream os;
343+
344+ os << "value type is " << type() << " not " << vtype;
345+
346+ throw std::runtime_error( os.str() );
347+ }
348+ }
349+
350+ template< class Config >
351+ const typename Config::String_type& Value_impl< Config >::get_str() const
352+ {
353+ check_type( str_type );
354+
355+ return *boost::get< String_type >( &v_ );
356+ }
357+
358+ template< class Config >
359+ const typename Value_impl< Config >::Object& Value_impl< Config >::get_obj() const
360+ {
361+ check_type( obj_type );
362+
363+ return *boost::get< Object >( &v_ );
364+ }
365+
366+ template< class Config >
367+ const typename Value_impl< Config >::Array& Value_impl< Config >::get_array() const
368+ {
369+ check_type( array_type );
370+
371+ return *boost::get< Array >( &v_ );
372+ }
373+
374+ template< class Config >
375+ bool Value_impl< Config >::get_bool() const
376+ {
377+ check_type( bool_type );
378+
379+ return boost::get< bool >( v_ );
380+ }
381+
382+ template< class Config >
383+ int Value_impl< Config >::get_int() const
384+ {
385+ check_type( int_type );
386+
387+ return static_cast< int >( get_int64() );
388+ }
389+
390+ template< class Config >
391+ boost::int64_t Value_impl< Config >::get_int64() const
392+ {
393+ check_type( int_type );
394+
395+ return boost::get< boost::int64_t >( v_ );
396+ }
397+
398+ template< class Config >
399+ boost::uint64_t Value_impl< Config >::get_uint64() const
400+ {
401+ check_type( int_type );
402+
403+ return static_cast< boost::uint64_t >( get_int64() );
404+ }
405+
406+ template< class Config >
407+ double Value_impl< Config >::get_real() const
408+ {
409+ if( type() == int_type )
410+ {
411+ return is_uint64() ? static_cast< double >( get_uint64() )
412+ : static_cast< double >( get_int64() );
413+ }
414+
415+ check_type( real_type );
416+
417+ return boost::get< double >( v_ );
418+ }
419+
420+ template< class Config >
421+ typename Value_impl< Config >::Object& Value_impl< Config >::get_obj()
422+ {
423+ check_type( obj_type );
424+
425+ return *boost::get< Object >( &v_ );
426+ }
427+
428+ template< class Config >
429+ typename Value_impl< Config >::Array& Value_impl< Config >::get_array()
430+ {
431+ check_type( array_type );
432+
433+ return *boost::get< Array >( &v_ );
434+ }
435+
436+ template< class Config >
437+ Pair_impl< Config >::Pair_impl( const String_type& name, const Value_type& value )
438+ : name_( name )
439+ , value_( value )
440+ {
441+ }
442+
443+ template< class Config >
444+ bool Pair_impl< Config >::operator==( const Pair_impl< Config >& lhs ) const
445+ {
446+ if( this == &lhs ) return true;
447+
448+ return ( name_ == lhs.name_ ) && ( value_ == lhs.value_ );
449+ }
450+
451+ // converts a C string, ie. 8 bit char array, to a string object
452+ //
453+ template < class String_type >
454+ String_type to_str( const char* c_str )
455+ {
456+ String_type result;
457+
458+ for( const char* p = c_str; *p != 0; ++p )
459+ {
460+ result += *p;
461+ }
462+
463+ return result;
464+ }
465+
466+ //
467+
468+ namespace internal_
469+ {
470+ template< typename T >
471+ struct Type_to_type
472+ {
473+ };
474+
475+ template< class Value >
476+ int get_value( const Value& value, Type_to_type< int > )
477+ {
478+ return value.get_int();
479+ }
480+
481+ template< class Value >
482+ boost::int64_t get_value( const Value& value, Type_to_type< boost::int64_t > )
483+ {
484+ return value.get_int64();
485+ }
486+
487+ template< class Value >
488+ boost::uint64_t get_value( const Value& value, Type_to_type< boost::uint64_t > )
489+ {
490+ return value.get_uint64();
491+ }
492+
493+ template< class Value >
494+ double get_value( const Value& value, Type_to_type< double > )
495+ {
496+ return value.get_real();
497+ }
498+
499+ template< class Value >
500+ typename Value::String_type get_value( const Value& value, Type_to_type< typename Value::String_type > )
501+ {
502+ return value.get_str();
503+ }
504+
505+ template< class Value >
506+ typename Value::Array get_value( const Value& value, Type_to_type< typename Value::Array > )
507+ {
508+ return value.get_array();
509+ }
510+
511+ template< class Value >
512+ typename Value::Object get_value( const Value& value, Type_to_type< typename Value::Object > )
513+ {
514+ return value.get_obj();
515+ }
516+
517+ template< class Value >
518+ bool get_value( const Value& value, Type_to_type< bool > )
519+ {
520+ return value.get_bool();
521+ }
522+ }
523+
524+ template< class Config >
525+ template< typename T >
526+ T Value_impl< Config >::get_value() const
527+ {
528+ return internal_::get_value( *this, internal_::Type_to_type< T >() );
529+ }
530+}
531+
532+#endif
A RD_Map_Editor/source/json/json_spirit_writer.cpp +95-0 View file
@@ -0,0 +1,95 @@
1+// Copyright John W. Wilkinson 2007 - 2009.
2+// Distributed under the MIT License, see accompanying file LICENSE.txt
3+
4+// json spirit version 4.03
5+
6+#include "json_spirit_writer.h"
7+#include "json_spirit_writer_template.h"
8+
9+void json_spirit::write( const Value& value, std::ostream& os )
10+{
11+ write_stream( value, os, false );
12+}
13+
14+void json_spirit::write_formatted( const Value& value, std::ostream& os )
15+{
16+ write_stream( value, os, true );
17+}
18+
19+std::string json_spirit::write( const Value& value )
20+{
21+ return write_string( value, false );
22+}
23+
24+std::string json_spirit::write_formatted( const Value& value )
25+{
26+ return write_string( value, true );
27+}
28+
29+#ifndef BOOST_NO_STD_WSTRING
30+
31+void json_spirit::write( const wValue& value, std::wostream& os )
32+{
33+ write_stream( value, os, false );
34+}
35+
36+void json_spirit::write_formatted( const wValue& value, std::wostream& os )
37+{
38+ write_stream( value, os, true );
39+}
40+
41+std::wstring json_spirit::write( const wValue& value )
42+{
43+ return write_string( value, false );
44+}
45+
46+std::wstring json_spirit::write_formatted( const wValue& value )
47+{
48+ return write_string( value, true );
49+}
50+
51+#endif
52+
53+void json_spirit::write( const mValue& value, std::ostream& os )
54+{
55+ write_stream( value, os, false );
56+}
57+
58+void json_spirit::write_formatted( const mValue& value, std::ostream& os )
59+{
60+ write_stream( value, os, true );
61+}
62+
63+std::string json_spirit::write( const mValue& value )
64+{
65+ return write_string( value, false );
66+}
67+
68+std::string json_spirit::write_formatted( const mValue& value )
69+{
70+ return write_string( value, true );
71+}
72+
73+#ifndef BOOST_NO_STD_WSTRING
74+
75+void json_spirit::write( const wmValue& value, std::wostream& os )
76+{
77+ write_stream( value, os, false );
78+}
79+
80+void json_spirit::write_formatted( const wmValue& value, std::wostream& os )
81+{
82+ write_stream( value, os, true );
83+}
84+
85+std::wstring json_spirit::write( const wmValue& value )
86+{
87+ return write_string( value, false );
88+}
89+
90+std::wstring json_spirit::write_formatted( const wmValue& value )
91+{
92+ return write_string( value, true );
93+}
94+
95+#endif
A RD_Map_Editor/source/json/json_spirit_writer.h +50-0 View file
@@ -0,0 +1,50 @@
1+#ifndef JSON_SPIRIT_WRITER
2+#define JSON_SPIRIT_WRITER
3+
4+// Copyright John W. Wilkinson 2007 - 2009.
5+// Distributed under the MIT License, see accompanying file LICENSE.txt
6+
7+// json spirit version 4.03
8+
9+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
10+# pragma once
11+#endif
12+
13+#include "json_spirit_value.h"
14+#include <iostream>
15+
16+namespace json_spirit
17+{
18+ // functions to convert JSON Values to text,
19+ // the "formatted" versions add whitespace to format the output nicely
20+
21+ void write ( const Value& value, std::ostream& os );
22+ void write_formatted( const Value& value, std::ostream& os );
23+ std::string write ( const Value& value );
24+ std::string write_formatted( const Value& value );
25+
26+#ifndef BOOST_NO_STD_WSTRING
27+
28+ void write ( const wValue& value, std::wostream& os );
29+ void write_formatted( const wValue& value, std::wostream& os );
30+ std::wstring write ( const wValue& value );
31+ std::wstring write_formatted( const wValue& value );
32+
33+#endif
34+
35+ void write ( const mValue& value, std::ostream& os );
36+ void write_formatted( const mValue& value, std::ostream& os );
37+ std::string write ( const mValue& value );
38+ std::string write_formatted( const mValue& value );
39+
40+#ifndef BOOST_NO_STD_WSTRING
41+
42+ void write ( const wmValue& value, std::wostream& os );
43+ void write_formatted( const wmValue& value, std::wostream& os );
44+ std::wstring write ( const wmValue& value );
45+ std::wstring write_formatted( const wmValue& value );
46+
47+#endif
48+}
49+
50+#endif
A RD_Map_Editor/source/json/json_spirit_writer_template.h +243-0 View file
@@ -0,0 +1,243 @@
1+#ifndef JSON_SPIRIT_WRITER_TEMPLATE
2+#define JSON_SPIRIT_WRITER_TEMPLATE
3+
4+// Copyright John W. Wilkinson 2007 - 2009.
5+// Distributed under the MIT License, see accompanying file LICENSE.txt
6+
7+// json spirit version 4.03
8+
9+#include "json_spirit_value.h"
10+
11+#include <cassert>
12+#include <sstream>
13+#include <iomanip>
14+
15+namespace json_spirit
16+{
17+ inline char to_hex_char( unsigned int c )
18+ {
19+ assert( c <= 0xF );
20+
21+ const char ch = static_cast< char >( c );
22+
23+ if( ch < 10 ) return '0' + ch;
24+
25+ return 'A' - 10 + ch;
26+ }
27+
28+ template< class String_type >
29+ String_type non_printable_to_string( unsigned int c )
30+ {
31+ String_type result( 6, '\\' );
32+
33+ result[1] = 'u';
34+
35+ result[ 5 ] = to_hex_char( c & 0x000F ); c >>= 4;
36+ result[ 4 ] = to_hex_char( c & 0x000F ); c >>= 4;
37+ result[ 3 ] = to_hex_char( c & 0x000F ); c >>= 4;
38+ result[ 2 ] = to_hex_char( c & 0x000F );
39+
40+ return result;
41+ }
42+
43+ template< typename Char_type, class String_type >
44+ bool add_esc_char( Char_type c, String_type& s )
45+ {
46+ switch( c )
47+ {
48+ case '"': s += to_str< String_type >( "\\\"" ); return true;
49+ case '\\': s += to_str< String_type >( "\\\\" ); return true;
50+ case '\b': s += to_str< String_type >( "\\b" ); return true;
51+ case '\f': s += to_str< String_type >( "\\f" ); return true;
52+ case '\n': s += to_str< String_type >( "\\n" ); return true;
53+ case '\r': s += to_str< String_type >( "\\r" ); return true;
54+ case '\t': s += to_str< String_type >( "\\t" ); return true;
55+ }
56+
57+ return false;
58+ }
59+
60+ template< class String_type >
61+ String_type add_esc_chars( const String_type& s )
62+ {
63+ typedef typename String_type::const_iterator Iter_type;
64+ typedef typename String_type::value_type Char_type;
65+
66+ String_type result;
67+
68+ const Iter_type end( s.end() );
69+
70+ for( Iter_type i = s.begin(); i != end; ++i )
71+ {
72+ const Char_type c( *i );
73+
74+ if( add_esc_char( c, result ) ) continue;
75+
76+ const wint_t unsigned_c( ( c >= 0 ) ? c : 256 + c );
77+
78+ if( iswprint( unsigned_c ) )
79+ {
80+ result += c;
81+ }
82+ else
83+ {
84+ result += non_printable_to_string< String_type >( unsigned_c );
85+ }
86+ }
87+
88+ return result;
89+ }
90+
91+ // this class generates the JSON text,
92+ // it keeps track of the indentation level etc.
93+ //
94+ template< class Value_type, class Ostream_type >
95+ class Generator
96+ {
97+ typedef typename Value_type::Config_type Config_type;
98+ typedef typename Config_type::String_type String_type;
99+ typedef typename Config_type::Object_type Object_type;
100+ typedef typename Config_type::Array_type Array_type;
101+ typedef typename String_type::value_type Char_type;
102+ typedef typename Object_type::value_type Obj_member_type;
103+
104+ public:
105+
106+ Generator( const Value_type& value, Ostream_type& os, bool pretty )
107+ : os_( os )
108+ , indentation_level_( 0 )
109+ , pretty_( pretty )
110+ {
111+ output( value );
112+ }
113+
114+ private:
115+
116+ void output( const Value_type& value )
117+ {
118+ switch( value.type() )
119+ {
120+ case obj_type: output( value.get_obj() ); break;
121+ case array_type: output( value.get_array() ); break;
122+ case str_type: output( value.get_str() ); break;
123+ case bool_type: output( value.get_bool() ); break;
124+ case int_type: output_int( value ); break;
125+ case real_type: os_ << std::showpoint << std::setprecision( 16 )
126+ << value.get_real(); break;
127+ case null_type: os_ << "null"; break;
128+ default: assert( false );
129+ }
130+ }
131+
132+ void output( const Object_type& obj )
133+ {
134+ output_array_or_obj( obj, '{', '}' );
135+ }
136+
137+ void output( const Array_type& arr )
138+ {
139+ output_array_or_obj( arr, '[', ']' );
140+ }
141+
142+ void output( const Obj_member_type& member )
143+ {
144+ output( Config_type::get_name( member ) ); space();
145+ os_ << ':'; space();
146+ output( Config_type::get_value( member ) );
147+ }
148+
149+ void output_int( const Value_type& value )
150+ {
151+ if( value.is_uint64() )
152+ {
153+ os_ << value.get_uint64();
154+ }
155+ else
156+ {
157+ os_ << value.get_int64();
158+ }
159+ }
160+
161+ void output( const String_type& s )
162+ {
163+ os_ << '"' << add_esc_chars( s ) << '"';
164+ }
165+
166+ void output( bool b )
167+ {
168+ os_ << to_str< String_type >( b ? "true" : "false" );
169+ }
170+
171+ template< class T >
172+ void output_array_or_obj( const T& t, Char_type start_char, Char_type end_char )
173+ {
174+ os_ << start_char; new_line();
175+
176+ ++indentation_level_;
177+
178+ for( typename T::const_iterator i = t.begin(); i != t.end(); ++i )
179+ {
180+ indent(); output( *i );
181+
182+ typename T::const_iterator next = i;
183+
184+ if( ++next != t.end())
185+ {
186+ os_ << ',';
187+ }
188+
189+ new_line();
190+ }
191+
192+ --indentation_level_;
193+
194+ indent(); os_ << end_char;
195+ }
196+
197+ void indent()
198+ {
199+ if( !pretty_ ) return;
200+
201+ for( int i = 0; i < indentation_level_; ++i )
202+ {
203+ os_ << " ";
204+ }
205+ }
206+
207+ void space()
208+ {
209+ if( pretty_ ) os_ << ' ';
210+ }
211+
212+ void new_line()
213+ {
214+ if( pretty_ ) os_ << '\n';
215+ }
216+
217+ Generator& operator=( const Generator& ); // to prevent "assignment operator could not be generated" warning
218+
219+ Ostream_type& os_;
220+ int indentation_level_;
221+ bool pretty_;
222+ };
223+
224+ template< class Value_type, class Ostream_type >
225+ void write_stream( const Value_type& value, Ostream_type& os, bool pretty )
226+ {
227+ Generator< Value_type, Ostream_type >( value, os, pretty );
228+ }
229+
230+ template< class Value_type >
231+ typename Value_type::String_type write_string( const Value_type& value, bool pretty )
232+ {
233+ typedef typename Value_type::String_type::value_type Char_type;
234+
235+ std::basic_ostringstream< Char_type > os;
236+
237+ write_stream( value, os, pretty );
238+
239+ return os.str();
240+ }
241+}
242+
243+#endif
A RD_Map_Editor/source/light_drawer.cpp +154-0 View file
@@ -0,0 +1,154 @@
1+//////////////////////////////////////////////////////////////////////
2+// This file is part of Remere's Map Editor
3+//////////////////////////////////////////////////////////////////////
4+// Remere's Map Editor is free software: you can redistribute it and/or modify
5+// it under the terms of the GNU General Public License as published by
6+// the Free Software Foundation, either version 3 of the License, or
7+// (at your option) any later version.
8+//
9+// Remere's Map Editor is distributed in the hope that it will be useful,
10+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+// GNU General Public License for more details.
13+//
14+// You should have received a copy of the GNU General Public License
15+// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+//////////////////////////////////////////////////////////////////////
17+
18+#include "main.h"
19+#include "light_drawer.h"
20+
21+LightDrawer::LightDrawer() {
22+ texture = 0;
23+ global_color = wxColor(50, 50, 50, 255);
24+}
25+
26+LightDrawer::~LightDrawer() {
27+ unloadGLTexture();
28+
29+ lights.clear();
30+}
31+
32+void LightDrawer::draw(int map_x, int map_y, int end_x, int end_y, int scroll_x, int scroll_y, bool fog) {
33+ if (texture == 0) {
34+ createGLTexture();
35+ }
36+
37+ int w = end_x - map_x;
38+ int h = end_y - map_y;
39+
40+ buffer.resize(static_cast<size_t>(w * h * PixelFormatRGBA));
41+
42+ for (int x = 0; x < w; ++x) {
43+ for (int y = 0; y < h; ++y) {
44+ int mx = (map_x + x);
45+ int my = (map_y + y);
46+ int index = (y * w + x);
47+ int color_index = index * PixelFormatRGBA;
48+
49+ buffer[color_index] = global_color.Red();
50+ buffer[color_index + 1] = global_color.Green();
51+ buffer[color_index + 2] = global_color.Blue();
52+ buffer[color_index + 3] = 140; // global_color.Alpha();
53+
54+ for (auto& light : lights) {
55+ float intensity = calculateIntensity(mx, my, light);
56+ if (intensity == 0.f) {
57+ continue;
58+ }
59+ wxColor light_color = colorFromEightBit(light.color);
60+ uint8_t red = static_cast<uint8_t>(light_color.Red() * intensity);
61+ uint8_t green = static_cast<uint8_t>(light_color.Green() * intensity);
62+ uint8_t blue = static_cast<uint8_t>(light_color.Blue() * intensity);
63+ buffer[color_index] = std::max(buffer[color_index], red);
64+ buffer[color_index + 1] = std::max(buffer[color_index + 1], green);
65+ buffer[color_index + 2] = std::max(buffer[color_index + 2], blue);
66+ }
67+ }
68+ }
69+
70+ const int draw_x = map_x * TileSize - scroll_x;
71+ const int draw_y = map_y * TileSize - scroll_y;
72+ int draw_width = w * TileSize;
73+ int draw_height = h * TileSize;
74+
75+ glBindTexture(GL_TEXTURE_2D, texture);
76+
77+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
79+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 0x812F);
80+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 0x812F);
81+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer.data());
82+
83+ if (!fog) {
84+ glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
85+ }
86+
87+ glColor4ub(255, 255, 255, 255); // reset color
88+ glEnable(GL_TEXTURE_2D);
89+ glBegin(GL_QUADS);
90+ glTexCoord2f(0.f, 0.f);
91+ glVertex2f(draw_x, draw_y);
92+ glTexCoord2f(1.f, 0.f);
93+ glVertex2f(draw_x + draw_width, draw_y);
94+ glTexCoord2f(1.f, 1.f);
95+ glVertex2f(draw_x + draw_width, draw_y + draw_height);
96+ glTexCoord2f(0.f, 1.f);
97+ glVertex2f(draw_x, draw_y + draw_height);
98+ glEnd();
99+ glDisable(GL_TEXTURE_2D);
100+
101+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
102+
103+ if (fog) {
104+ glColor4ub(10, 10, 10, 80);
105+ glBegin(GL_QUADS);
106+ glVertex2f(draw_x, draw_y);
107+ glVertex2f(draw_x + draw_width, draw_y);
108+ glVertex2f(draw_x + draw_width, draw_y + draw_height);
109+ glVertex2f(draw_x, draw_y + draw_height);
110+ glEnd();
111+ }
112+}
113+
114+void LightDrawer::setGlobalLightColor(uint8_t color) {
115+ global_color = colorFromEightBit(color);
116+}
117+
118+void LightDrawer::addLight(int map_x, int map_y, int map_z, const SpriteLight& light) {
119+ if (map_z <= GROUND_LAYER) {
120+ map_x -= (GROUND_LAYER - map_z);
121+ map_y -= (GROUND_LAYER - map_z);
122+ }
123+
124+ if (map_x <= 0 || map_x >= MAP_MAX_WIDTH || map_y <= 0 || map_y >= MAP_MAX_HEIGHT) {
125+ return;
126+ }
127+
128+ uint8_t intensity = std::min(light.intensity, static_cast<uint8_t>(MaxLightIntensity));
129+
130+ if (!lights.empty()) {
131+ Light& previous = lights.back();
132+ if (previous.map_x == map_x && previous.map_y == map_y && previous.color == light.color) {
133+ previous.intensity = std::max(previous.intensity, intensity);
134+ return;
135+ }
136+ }
137+
138+ lights.push_back(Light { static_cast<uint16_t>(map_x), static_cast<uint16_t>(map_y), light.color, intensity });
139+}
140+
141+void LightDrawer::clear() noexcept {
142+ lights.clear();
143+}
144+
145+void LightDrawer::createGLTexture() {
146+ glGenTextures(1, &texture);
147+ ASSERT(texture == 0);
148+}
149+
150+void LightDrawer::unloadGLTexture() {
151+ if (texture != 0) {
152+ glDeleteTextures(1, &texture);
153+ }
154+}
A RD_Map_Editor/source/light_drawer.h +66-0 View file
@@ -0,0 +1,66 @@
1+//////////////////////////////////////////////////////////////////////
2+// This file is part of Remere's Map Editor
3+//////////////////////////////////////////////////////////////////////
4+// Remere's Map Editor is free software: you can redistribute it and/or modify
5+// it under the terms of the GNU General Public License as published by
6+// the Free Software Foundation, either version 3 of the License, or
7+// (at your option) any later version.
8+//
9+// Remere's Map Editor is distributed in the hope that it will be useful,
10+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+// GNU General Public License for more details.
13+//
14+// You should have received a copy of the GNU General Public License
15+// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+//////////////////////////////////////////////////////////////////////
17+
18+#ifndef RME_LIGHDRAWER_H
19+#define RME_LIGHDRAWER_H
20+
21+#include "graphics.h"
22+#include "position.h"
23+
24+class LightDrawer {
25+ struct Light {
26+ uint16_t map_x = 0;
27+ uint16_t map_y = 0;
28+ uint8_t color = 0;
29+ uint8_t intensity = 0;
30+ };
31+
32+public:
33+ LightDrawer();
34+ virtual ~LightDrawer();
35+
36+ void draw(int map_x, int map_y, int end_x, int end_y, int scroll_x, int scroll_y, bool fog);
37+
38+ void setGlobalLightColor(uint8_t color);
39+ void addLight(int map_x, int map_y, int map_z, const SpriteLight& light);
40+ void clear() noexcept;
41+
42+private:
43+ void createGLTexture();
44+ void unloadGLTexture();
45+
46+ inline float calculateIntensity(int map_x, int map_y, const Light& light) {
47+ int dx = map_x - light.map_x;
48+ int dy = map_y - light.map_y;
49+ float distance = std::sqrt(dx * dx + dy * dy);
50+ if (distance > MaxLightIntensity) {
51+ return 0.f;
52+ }
53+ float intensity = (-distance + light.intensity) * 0.2f;
54+ if (intensity < 0.01f) {
55+ return 0.f;
56+ }
57+ return std::min(intensity, 1.f);
58+ }
59+
60+ GLuint texture;
61+ std::vector<Light> lights;
62+ std::vector<uint8_t> buffer;
63+ wxColor global_color;
64+};
65+
66+#endif
A RD_Map_Editor/source/live_action.cpp +118-0 View file
@@ -0,0 +1,118 @@
1+//////////////////////////////////////////////////////////////////////
2+// This file is part of Remere's Map Editor
3+//////////////////////////////////////////////////////////////////////
4+// Remere's Map Editor is free software: you can redistribute it and/or modify
5+// it under the terms of the GNU General Public License as published by
6+// the Free Software Foundation, either version 3 of the License, or
7+// (at your option) any later version.
8+//
9+// Remere's Map Editor is distributed in the hope that it will be useful,
10+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+// GNU General Public License for more details.
13+//
14+// You should have received a copy of the GNU General Public License
15+// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+//////////////////////////////////////////////////////////////////////
17+
18+#include "main.h"
19+
20+#include "live_action.h"
21+#include "editor.h"
22+
23+NetworkedAction::NetworkedAction(Editor& editor, ActionIdentifier ident) :
24+ Action(editor, ident),
25+ owner(0) {
26+ ;
27+}
28+
29+NetworkedAction::~NetworkedAction() {
30+ ;
31+}
32+
33+NetworkedBatchAction::NetworkedBatchAction(Editor& editor, NetworkedActionQueue& queue, ActionIdentifier ident) :
34+ BatchAction(editor, ident),
35+ queue(queue) {
36+ ;
37+}
38+
39+NetworkedBatchAction::~NetworkedBatchAction() {
40+ ;
41+}
42+
43+void NetworkedBatchAction::addAndCommitAction(Action* action) {
44+ // If empty, do nothing.
45+ if (action->size() == 0) {
46+ delete action;
47+ return;
48+ }
49+
50+ // Track changed nodes...
51+ DirtyList dirty_list;
52+ NetworkedAction* netact = dynamic_cast<NetworkedAction*>(action);
53+ if (netact) {
54+ dirty_list.owner = netact->owner;
55+ }
56+
57+ // Add it!
58+ action->commit(type != ACTION_SELECT ? &dirty_list : nullptr);
59+ batch.push_back(action);
60+ timestamp = time(nullptr);
61+
62+ // Broadcast changes!
63+ queue.broadcast(dirty_list);
64+}
65+
66+void NetworkedBatchAction::commit() {
67+ // Track changed nodes...
68+ DirtyList dirty_list;
69+
70+ for (ActionVector::iterator it = batch.begin(); it != batch.end(); ++it) {
71+ NetworkedAction* action = static_cast<NetworkedAction*>(*it);
72+ if (!action->isCommited()) {
73+ action->commit(type != ACTION_SELECT ? &dirty_list : nullptr);
74+ if (action->owner != 0) {
75+ dirty_list.owner = action->owner;
76+ }
77+ }
78+ }
79+ // Broadcast changes!
80+ queue.broadcast(dirty_list);
81+}
82+
83+void NetworkedBatchAction::undo() {
84+ // Track changed nodes...
85+ DirtyList dirty_list;
86+
87+ for (ActionVector::reverse_iterator it = batch.rbegin(); it != batch.rend(); ++it) {
88+ (*it)->undo(type != ACTION_SELECT ? &dirty_list : nullptr);
89+ }
90+ // Broadcast changes!
91+ queue.broadcast(dirty_list);
92+}
93+
94+void NetworkedBatchAction::redo() {
95+ commit();
96+}
97+
98+//===================
99+// Action queue
100+
101+NetworkedActionQueue::NetworkedActionQueue(Editor& editor) :
102+ ActionQueue(editor) {
103+}
104+
105+NetworkedActionQueue::~NetworkedActionQueue() {
106+}
107+
108+Action* NetworkedActionQueue::createAction(ActionIdentifier ident) {
109+ return newd NetworkedAction(editor, ident);
110+}
111+
112+BatchAction* NetworkedActionQueue::createBatch(ActionIdentifier ident) {
113+ return newd NetworkedBatchAction(editor, *this, ident);
114+}
115+
116+void NetworkedActionQueue::broadcast(DirtyList& dirty_list) {
117+ editor.BroadcastNodes(dirty_list);
118+}
A RD_Map_Editor/source/live_action.h +68-0 View file
@@ -0,0 +1,68 @@
1+//////////////////////////////////////////////////////////////////////
2+// This file is part of Remere's Map Editor
3+//////////////////////////////////////////////////////////////////////
4+// Remere's Map Editor is free software: you can redistribute it and/or modify
5+// it under the terms of the GNU General Public License as published by
6+// the Free Software Foundation, either version 3 of the License, or
7+// (at your option) any later version.
8+//
9+// Remere's Map Editor is distributed in the hope that it will be useful,
10+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+// GNU General Public License for more details.
13+//
14+// You should have received a copy of the GNU General Public License
15+// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+//////////////////////////////////////////////////////////////////////
17+
18+#ifndef _RME_NETWORK_ACTION_H_
19+#define _RME_NETWORK_ACTION_H_
20+
21+#include "action.h"
22+
23+class NetworkedActionQueue;
24+
25+class NetworkedAction : public Action {
26+protected:
27+ NetworkedAction(Editor& editor, ActionIdentifier ident);
28+ ~NetworkedAction();
29+
30+public:
31+ uint32_t owner;
32+
33+ friend class NetworkedActionQueue;
34+};
35+
36+class NetworkedBatchAction : public BatchAction {
37+ NetworkedActionQueue& queue;
38+
39+protected:
40+ NetworkedBatchAction(Editor& editor, NetworkedActionQueue& queue, ActionIdentifier ident);
41+ ~NetworkedBatchAction();
42+
43+public:
44+ void addAndCommitAction(Action* action);
45+
46+protected:
47+ void commit();
48+ void undo();
49+ void redo();
50+
51+ friend class NetworkedActionQueue;
52+};
53+
54+class NetworkedActionQueue : public ActionQueue {
55+public:
56+ NetworkedActionQueue(Editor& editor);
57+ ~NetworkedActionQueue();
58+
59+ Action* createAction(ActionIdentifier ident);
60+ BatchAction* createBatch(ActionIdentifier ident);
61+
62+protected:
63+ void broadcast(DirtyList& dirty_list);
64+
65+ friend class NetworkedBatchAction;
66+};
67+
68+#endif
A RD_Map_Editor/source/live_client.h +103-0 View file
@@ -0,0 +1,103 @@
1+//////////////////////////////////////////////////////////////////////
2+// This file is part of Remere's Map Editor
3+//////////////////////////////////////////////////////////////////////
4+// Remere's Map Editor is free software: you can redistribute it and/or modify
5+// it under the terms of the GNU General Public License as published by
6+// the Free Software Foundation, either version 3 of the License, or
7+// (at your option) any later version.
8+//
9+// Remere's Map Editor is distributed in the hope that it will be useful,
10+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+// GNU General Public License for more details.
13+//
14+// You should have received a copy of the GNU General Public License
15+// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+//////////////////////////////////////////////////////////////////////
17+
18+#ifndef _RME_LIVE_CLIENT_H_
19+#define _RME_LIVE_CLIENT_H_
20+
21+#include "live_socket.h"
22+#include "net_connection.h"
23+
24+#include <set>
25+
26+class DirtyList;
27+class MapTab;
28+
29+class LiveClient : public LiveSocket {
30+public:
31+ LiveClient();
32+ ~LiveClient();
33+
34+ //
35+ bool connect(const std::string& address, uint16_t port);
36+ void tryConnect(boost::asio::ip::tcp::resolver::results_type::iterator endpoint);
37+
38+ void close();
39+ bool handleError(const boost::system::error_code& error);
40+
41+ //
42+ std::string getHostName() const;
43+
44+ //
45+ void receiveHeader() override;
46+ void receive(uint32_t packetSize) override;
47+ void send(NetworkMessage& message) override;
48+ void sendWithoutLogging(NetworkMessage& message); // For cursor updates and other high-frequency events
49+
50+ //
51+ void updateCursor(const Position& position) override;
52+
53+ LiveLogTab* createLogWindow(wxWindow* parent);
54+
55+
56+ MapTab* createEditorWindow();
57+
58+ // Override socket type check
59+ bool IsClient() const override { return true; }
60+
61+
62+ // send packets
63+ void sendHello();
64+ void sendNodeRequests();
65+ void sendChanges(DirtyList& dirtyList);
66+ void sendChat(const wxString& chatMessage) override;
67+ void sendReady();
68+ void sendColorUpdate(uint32_t targetClientId, const wxColor& color);
69+
70+ // Flags a node as queried and stores it, need to call SendNodeRequest to send it to server
71+ void queryNode(int32_t ndx, int32_t ndy, bool underground);
72+
73+protected:
74+ void parsePacket(NetworkMessage message);
75+
76+ // parse packets
77+ void parseHello(NetworkMessage& message);
78+ void parseKick(NetworkMessage& message);
79+ void parseClientAccepted(NetworkMessage& message);
80+ void parseChangeClientVersion(NetworkMessage& message);
81+ void parseServerTalk(NetworkMessage& message);
82+ void parseNode(NetworkMessage& message);
83+ void parseCursorUpdate(NetworkMessage& message);
84+ void parseStartOperation(NetworkMessage& message);
85+ void parseUpdateOperation(NetworkMessage& message);
86+ void parseColorUpdate(NetworkMessage& message);
87+
88+ //
89+ NetworkMessage readMessage;
90+
91+ std::set<uint32_t> queryNodeList;
92+ wxString currentOperation;
93+
94+ std::shared_ptr<boost::asio::ip::tcp::resolver> resolver;
95+ std::shared_ptr<boost::asio::ip::tcp::socket> socket;
96+
97+ Editor* editor;
98+
99+ bool stopped;
100+ bool isDrawingReady; // Flag indicating client is ready to handle drawing operations
101+};
102+
103+#endif
A RD_Map_Editor/source/live_packets.h +49-0 View file
@@ -0,0 +1,49 @@
1+//////////////////////////////////////////////////////////////////////
2+// This file is part of Remere's Map Editor
3+//////////////////////////////////////////////////////////////////////
4+// Remere's Map Editor is free software: you can redistribute it and/or modify
5+// it under the terms of the GNU General Public License as published by
6+// the Free Software Foundation, either version 3 of the License, or
7+// (at your option) any later version.
8+//
9+// Remere's Map Editor is distributed in the hope that it will be useful,
10+// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+// GNU General Public License for more details.
13+//
14+// You should have received a copy of the GNU General Public License
15+// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+//////////////////////////////////////////////////////////////////////
17+
18+#ifndef LIVE_PACKETS_H
19+#define LIVE_PACKETS_H
20+
21+enum LivePacketType {
22+ PACKET_HELLO_FROM_CLIENT = 0x10,
23+ PACKET_READY_CLIENT = 0x11,
24+
25+ PACKET_REQUEST_NODES = 0x20,
26+ PACKET_CHANGE_LIST = 0x21,
27+ PACKET_ADD_HOUSE = 0x23,
28+ PACKET_EDIT_HOUSE = 0x24,
29+ PACKET_REMOVE_HOUSE = 0x25,
30+
31+ PACKET_CLIENT_TALK = 0x30,
32+ PACKET_CLIENT_UPDATE_CURSOR = 0x31,
33+ PACKET_CLIENT_COLOR_UPDATE = 0x32,
34+
35+ PACKET_HELLO_FROM_SERVER = 0x80,
36+ PACKET_KICK = 0x81,
37+ PACKET_ACCEPTED_CLIENT = 0x82,
38+ PACKET_CHANGE_CLIENT_VERSION = 0x83,
39+ PACKET_SERVER_TALK = 0x84,
40+ PACKET_COLOR_UPDATE = 0x85,
41+
42+ PACKET_NODE = 0x90,
43+ PACKET_CURSOR_UPDATE = 0x91,
44+ PACKET_START_OPERATION = 0x92,
45+ PACKET_UPDATE_OPERATION = 0x93,
46+ PACKET_CHAT_MESSAGE = 0x94,
47+};
48+
49+#endif
Top