Skip to content

Commit 18fe8a5

Browse files
Darxealsamuelpmish
authored andcommitted
Add 'read_flatbuffer_packet' to the Game class for C++ bots (#20)
* fix python stubs * Add 'read_flatbuffer_packet' to the Game class for C++ bots
1 parent a01e66c commit 18fe8a5

17 files changed

Lines changed: 13251 additions & 0 deletions

File tree

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
#ifndef FLATBUFFERS_BASE_H_
2+
#define FLATBUFFERS_BASE_H_
3+
4+
// clang-format off
5+
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
6+
defined(_MSC_VER) && defined(_DEBUG)
7+
#define _CRTDBG_MAP_ALLOC
8+
#endif
9+
10+
#include <assert.h>
11+
12+
#ifndef ARDUINO
13+
#include <cstdint>
14+
#endif
15+
16+
#include <cstddef>
17+
#include <cstdlib>
18+
#include <cstring>
19+
20+
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
21+
defined(_MSC_VER) && defined(_DEBUG)
22+
#include <crtdbg.h>
23+
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
24+
#define new DEBUG_NEW
25+
#endif
26+
27+
#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H)
28+
#include <utility.h>
29+
#else
30+
#include <utility>
31+
#endif
32+
33+
#include <string>
34+
#include <type_traits>
35+
#include <vector>
36+
#include <set>
37+
#include <algorithm>
38+
#include <iterator>
39+
#include <memory>
40+
41+
#ifdef _STLPORT_VERSION
42+
#define FLATBUFFERS_CPP98_STL
43+
#endif
44+
#ifndef FLATBUFFERS_CPP98_STL
45+
#include <functional>
46+
#endif
47+
48+
#include "flatbuffers/stl_emulation.h"
49+
50+
/// @cond FLATBUFFERS_INTERNAL
51+
#if __cplusplus <= 199711L && \
52+
(!defined(_MSC_VER) || _MSC_VER < 1600) && \
53+
(!defined(__GNUC__) || \
54+
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400))
55+
#error A C++11 compatible compiler with support for the auto typing is \
56+
required for FlatBuffers.
57+
#error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__
58+
#endif
59+
60+
#if !defined(__clang__) && \
61+
defined(__GNUC__) && \
62+
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600)
63+
// Backwards compatability for g++ 4.4, and 4.5 which don't have the nullptr
64+
// and constexpr keywords. Note the __clang__ check is needed, because clang
65+
// presents itself as an older GNUC compiler.
66+
#ifndef nullptr_t
67+
const class nullptr_t {
68+
public:
69+
template<class T> inline operator T*() const { return 0; }
70+
private:
71+
void operator&() const;
72+
} nullptr = {};
73+
#endif
74+
#ifndef constexpr
75+
#define constexpr const
76+
#endif
77+
#endif
78+
79+
// The wire format uses a little endian encoding (since that's efficient for
80+
// the common platforms).
81+
#if defined(__s390x__)
82+
#define FLATBUFFERS_LITTLEENDIAN 0
83+
#endif // __s390x__
84+
#if !defined(FLATBUFFERS_LITTLEENDIAN)
85+
#if defined(__GNUC__) || defined(__clang__)
86+
#ifdef __BIG_ENDIAN__
87+
#define FLATBUFFERS_LITTLEENDIAN 0
88+
#else
89+
#define FLATBUFFERS_LITTLEENDIAN 1
90+
#endif // __BIG_ENDIAN__
91+
#elif defined(_MSC_VER)
92+
#if defined(_M_PPC)
93+
#define FLATBUFFERS_LITTLEENDIAN 0
94+
#else
95+
#define FLATBUFFERS_LITTLEENDIAN 1
96+
#endif
97+
#else
98+
#error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN.
99+
#endif
100+
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
101+
102+
#define FLATBUFFERS_VERSION_MAJOR 1
103+
#define FLATBUFFERS_VERSION_MINOR 9
104+
#define FLATBUFFERS_VERSION_REVISION 0
105+
#define FLATBUFFERS_STRING_EXPAND(X) #X
106+
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
107+
108+
#if (!defined(_MSC_VER) || _MSC_VER > 1600) && \
109+
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407))
110+
#define FLATBUFFERS_FINAL_CLASS final
111+
#define FLATBUFFERS_OVERRIDE override
112+
#else
113+
#define FLATBUFFERS_FINAL_CLASS
114+
#define FLATBUFFERS_OVERRIDE
115+
#endif
116+
117+
#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \
118+
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406))
119+
#define FLATBUFFERS_CONSTEXPR constexpr
120+
#else
121+
#define FLATBUFFERS_CONSTEXPR
122+
#endif
123+
124+
#if (defined(__cplusplus) && __cplusplus >= 201402L) || \
125+
(defined(__cpp_constexpr) && __cpp_constexpr >= 201304)
126+
#define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR
127+
#else
128+
#define FLATBUFFERS_CONSTEXPR_CPP14
129+
#endif
130+
131+
#if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \
132+
defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026
133+
#define FLATBUFFERS_NOEXCEPT noexcept
134+
#else
135+
#define FLATBUFFERS_NOEXCEPT
136+
#endif
137+
138+
// NOTE: the FLATBUFFERS_DELETE_FUNC macro may change the access mode to
139+
// private, so be sure to put it at the end or reset access mode explicitly.
140+
#if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \
141+
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404))
142+
#define FLATBUFFERS_DELETE_FUNC(func) func = delete;
143+
#else
144+
#define FLATBUFFERS_DELETE_FUNC(func) private: func;
145+
#endif
146+
147+
#if defined(_MSC_VER)
148+
#pragma warning(push)
149+
#pragma warning(disable: 4127) // C4127: conditional expression is constant
150+
#endif
151+
152+
/// @endcond
153+
154+
/// @file
155+
namespace flatbuffers {
156+
157+
/// @cond FLATBUFFERS_INTERNAL
158+
// Our default offset / size type, 32bit on purpose on 64bit systems.
159+
// Also, using a consistent offset type maintains compatibility of serialized
160+
// offset values between 32bit and 64bit systems.
161+
typedef uint32_t uoffset_t;
162+
163+
// Signed offsets for references that can go in both directions.
164+
typedef int32_t soffset_t;
165+
166+
// Offset/index used in v-tables, can be changed to uint8_t in
167+
// format forks to save a bit of space if desired.
168+
typedef uint16_t voffset_t;
169+
170+
typedef uintmax_t largest_scalar_t;
171+
172+
// In 32bits, this evaluates to 2GB - 1
173+
#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(soffset_t) * 8 - 1)) - 1)
174+
175+
// We support aligning the contents of buffers up to this size.
176+
#define FLATBUFFERS_MAX_ALIGNMENT 16
177+
178+
template<typename T> T EndianSwap(T t) {
179+
#if defined(_MSC_VER)
180+
#define FLATBUFFERS_BYTESWAP16 _byteswap_ushort
181+
#define FLATBUFFERS_BYTESWAP32 _byteswap_ulong
182+
#define FLATBUFFERS_BYTESWAP64 _byteswap_uint64
183+
#else
184+
#if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__)
185+
// __builtin_bswap16 was missing prior to GCC 4.8.
186+
#define FLATBUFFERS_BYTESWAP16(x) \
187+
static_cast<uint16_t>(__builtin_bswap32(static_cast<uint32_t>(x) << 16))
188+
#else
189+
#define FLATBUFFERS_BYTESWAP16 __builtin_bswap16
190+
#endif
191+
#define FLATBUFFERS_BYTESWAP32 __builtin_bswap32
192+
#define FLATBUFFERS_BYTESWAP64 __builtin_bswap64
193+
#endif
194+
if (sizeof(T) == 1) { // Compile-time if-then's.
195+
return t;
196+
} else if (sizeof(T) == 2) {
197+
union { T t; uint16_t i; } u;
198+
u.t = t;
199+
u.i = FLATBUFFERS_BYTESWAP16(u.i);
200+
return u.t;
201+
} else if (sizeof(T) == 4) {
202+
union { T t; uint32_t i; } u;
203+
u.t = t;
204+
u.i = FLATBUFFERS_BYTESWAP32(u.i);
205+
return u.t;
206+
} else if (sizeof(T) == 8) {
207+
union { T t; uint64_t i; } u;
208+
u.t = t;
209+
u.i = FLATBUFFERS_BYTESWAP64(u.i);
210+
return u.t;
211+
} else {
212+
assert(0);
213+
}
214+
}
215+
216+
217+
template<typename T> T EndianScalar(T t) {
218+
#if FLATBUFFERS_LITTLEENDIAN
219+
return t;
220+
#else
221+
return EndianSwap(t);
222+
#endif
223+
}
224+
225+
template<typename T> T ReadScalar(const void *p) {
226+
return EndianScalar(*reinterpret_cast<const T *>(p));
227+
}
228+
229+
template<typename T> void WriteScalar(void *p, T t) {
230+
*reinterpret_cast<T *>(p) = EndianScalar(t);
231+
}
232+
233+
// Computes how many bytes you'd have to pad to be able to write an
234+
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
235+
// memory).
236+
inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
237+
return ((~buf_size) + 1) & (scalar_size - 1);
238+
}
239+
240+
} // namespace flatbuffers
241+
#endif // FLATBUFFERS_BASE_H_
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright 2014 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FLATBUFFERS_CODE_GENERATORS_H_
18+
#define FLATBUFFERS_CODE_GENERATORS_H_
19+
20+
#include <map>
21+
#include <sstream>
22+
#include "flatbuffers/idl.h"
23+
24+
namespace flatbuffers {
25+
26+
// Utility class to assist in generating code through use of text templates.
27+
//
28+
// Example code:
29+
// CodeWriter code;
30+
// code.SetValue("NAME", "Foo");
31+
// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }";
32+
// code.SetValue("NAME", "Bar");
33+
// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }";
34+
// std::cout << code.ToString() << std::endl;
35+
//
36+
// Output:
37+
// void Foo() { printf("%s", "Foo"); }
38+
// void Bar() { printf("%s", "Bar"); }
39+
class CodeWriter {
40+
public:
41+
CodeWriter() {}
42+
43+
// Clears the current "written" code.
44+
void Clear() {
45+
stream_.str("");
46+
stream_.clear();
47+
}
48+
49+
// Associates a key with a value. All subsequent calls to operator+=, where
50+
// the specified key is contained in {{ and }} delimiters will be replaced by
51+
// the given value.
52+
void SetValue(const std::string &key, const std::string &value) {
53+
value_map_[key] = value;
54+
}
55+
56+
// Appends the given text to the generated code as well as a newline
57+
// character. Any text within {{ and }} delimeters is replaced by values
58+
// previously stored in the CodeWriter by calling SetValue above. The newline
59+
// will be suppressed if the text ends with the \\ character.
60+
void operator+=(std::string text);
61+
62+
// Returns the current contents of the CodeWriter as a std::string.
63+
std::string ToString() const { return stream_.str(); }
64+
65+
private:
66+
std::map<std::string, std::string> value_map_;
67+
std::stringstream stream_;
68+
};
69+
70+
class BaseGenerator {
71+
public:
72+
virtual bool generate() = 0;
73+
74+
static std::string NamespaceDir(const Parser &parser, const std::string &path,
75+
const Namespace &ns);
76+
77+
protected:
78+
BaseGenerator(const Parser &parser, const std::string &path,
79+
const std::string &file_name,
80+
const std::string qualifying_start,
81+
const std::string qualifying_separator)
82+
: parser_(parser),
83+
path_(path),
84+
file_name_(file_name),
85+
qualifying_start_(qualifying_start),
86+
qualifying_separator_(qualifying_separator) {}
87+
virtual ~BaseGenerator() {}
88+
89+
// No copy/assign.
90+
BaseGenerator &operator=(const BaseGenerator &);
91+
BaseGenerator(const BaseGenerator &);
92+
93+
std::string NamespaceDir(const Namespace &ns) const;
94+
95+
static const char *FlatBuffersGeneratedWarning();
96+
97+
static std::string FullNamespace(const char *separator, const Namespace &ns);
98+
99+
static std::string LastNamespacePart(const Namespace &ns);
100+
101+
// tracks the current namespace for early exit in WrapInNameSpace
102+
// c++, java and csharp returns a different namespace from
103+
// the following default (no early exit, always fully qualify),
104+
// which works for js and php
105+
virtual const Namespace *CurrentNameSpace() const { return nullptr; }
106+
107+
// Ensure that a type is prefixed with its namespace whenever it is used
108+
// outside of its namespace.
109+
std::string WrapInNameSpace(const Namespace *ns,
110+
const std::string &name) const;
111+
112+
std::string WrapInNameSpace(const Definition &def) const;
113+
114+
std::string GetNameSpace(const Definition &def) const;
115+
116+
const Parser &parser_;
117+
const std::string &path_;
118+
const std::string &file_name_;
119+
const std::string qualifying_start_;
120+
const std::string qualifying_separator_;
121+
};
122+
123+
struct CommentConfig {
124+
const char *first_line;
125+
const char *content_line_prefix;
126+
const char *last_line;
127+
};
128+
129+
extern void GenComment(const std::vector<std::string> &dc,
130+
std::string *code_ptr, const CommentConfig *config,
131+
const char *prefix = "");
132+
133+
} // namespace flatbuffers
134+
135+
#endif // FLATBUFFERS_CODE_GENERATORS_H_

0 commit comments

Comments
 (0)