From 7b021bc99daceee61633b14d7d36100e0471ffb3 Mon Sep 17 00:00:00 2001 From: orng Date: Thu, 26 Mar 2026 01:10:27 -0500 Subject: [PATCH] wip: removing vec3 tls --- Minecraft.Client/Minecraft.cpp | 4 +- Minecraft.Client/Network/PlayerConnection.cpp | 3 +- .../spirit/home/lex/lexer/lexertl/lexer.hpp | 658 +++++++------- .../PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp | 802 +++++++++--------- Minecraft.Client/Player/LocalPlayer.cpp | 2 +- .../Rendering/Culling/DirtyChunkSorter.cpp | 2 +- .../EntityRenderers/LivingEntityRenderer.cpp | 2 +- .../EntityRenderers/MinecartRenderer.cpp | 7 +- Minecraft.Client/Rendering/GameRenderer.cpp | 9 +- Minecraft.Client/Rendering/Lighting.cpp | 8 +- Minecraft.Client/Rendering/Polygon.cpp | 12 +- Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp | 2 +- Minecraft.World/AI/Goals/BegGoal.cpp | 2 +- Minecraft.World/AI/Goals/FollowOwnerGoal.cpp | 2 +- Minecraft.World/AI/Goals/LeapAtTargetGoal.cpp | 2 +- Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp | 2 +- Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp | 2 +- .../AI/Goals/MoveTowardsTargetGoal.cpp | 2 +- .../AI/Goals/NearestAttackableTargetGoal.cpp | 2 +- Minecraft.World/AI/Goals/OcelotAttackGoal.cpp | 2 +- Minecraft.World/AI/Goals/SitGoal.cpp | 2 +- Minecraft.World/AI/Goals/TakeFlowerGoal.cpp | 2 +- Minecraft.World/AI/Goals/TargetGoal.cpp | 2 +- Minecraft.World/AI/Goals/TemptGoal.cpp | 2 +- .../AI/Goals/TradeWithPlayerGoal.cpp | 2 +- Minecraft.World/AI/Navigation/PathFinder.cpp | 2 +- .../AI/Navigation/PathNavigation.cpp | 6 +- Minecraft.World/Blocks/LiquidTile.cpp | 10 +- Minecraft.World/Blocks/StairTile.cpp | 2 +- Minecraft.World/Blocks/Tile.cpp | 82 +- .../Containers/HorseInventoryMenu.cpp | 2 +- Minecraft.World/Entities/Entity.cpp | 2 +- Minecraft.World/Entities/Entity.h | 1 + Minecraft.World/Entities/LivingEntity.cpp | 6 +- .../Entities/MinecartContainer.cpp | 2 +- Minecraft.World/Entities/Mobs/Arrow.cpp | 8 +- .../Entities/Mobs/DragonFireball.cpp | 2 +- Minecraft.World/Entities/Mobs/EnderDragon.cpp | 47 +- Minecraft.World/Entities/Mobs/EnderMan.cpp | 12 +- .../Entities/Mobs/ExperienceOrb.cpp | 2 +- Minecraft.World/Entities/Mobs/Fireball.cpp | 4 +- Minecraft.World/Entities/Mobs/FishingHook.cpp | 4 +- Minecraft.World/Entities/Mobs/Ghast.cpp | 2 +- Minecraft.World/Entities/Mobs/Minecart.cpp | 37 +- Minecraft.World/Entities/Mobs/Ocelot.cpp | 2 +- Minecraft.World/Entities/Mobs/Slime.cpp | 2 +- .../Entities/Mobs/ThrownPotion.cpp | 2 +- Minecraft.World/Entities/Mobs/Witch.cpp | 2 +- Minecraft.World/Entities/Mobs/WitherBoss.cpp | 2 +- Minecraft.World/Entities/PathfinderMob.cpp | 2 +- Minecraft.World/Entities/Throwable.cpp | 4 +- Minecraft.World/Items/BoatItem.cpp | 9 +- Minecraft.World/Items/Item.cpp | 4 +- Minecraft.World/Level/ChunkPos.h | 2 +- Minecraft.World/Level/Level.cpp | 2 +- Minecraft.World/Level/RandomLevelSource.cpp | 8 +- Minecraft.World/Player/Player.cpp | 4 +- Minecraft.World/Util/AABB.cpp | 89 +- Minecraft.World/Util/HitResult.cpp | 14 +- Minecraft.World/Util/HitResult.h | 6 +- Minecraft.World/Util/Vec3.cpp | 146 ++-- Minecraft.World/Util/Vec3.h | 45 +- 62 files changed, 1070 insertions(+), 1045 deletions(-) diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 1e9a1c954..c8d90e7db 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -2750,7 +2750,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) { // 4J-PB - Call the useItemOn with the TestOnly flag set bool bUseItemOn = gameMode->useItemOn( player, level, itemInstance, x, y, z, face, - hitResult->pos, true); + &hitResult->pos, true); /* 4J-Jev: * Moved this here so we have item tooltips to @@ -3900,7 +3900,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) { bool usedItem = false; gameMode->useItemOn(player, level, nullptr, hitResult->x, hitResult->y, hitResult->z, 0, - hitResult->pos, false, &usedItem); + &hitResult->pos, false, &usedItem); } else { ui.PlayUISFX(eSFX_Press); app.LoadCrafting2x2Menu(iPad, player); diff --git a/Minecraft.Client/Network/PlayerConnection.cpp b/Minecraft.Client/Network/PlayerConnection.cpp index 0e5038d86..9f5e861e8 100644 --- a/Minecraft.Client/Network/PlayerConnection.cpp +++ b/Minecraft.Client/Network/PlayerConnection.cpp @@ -1551,7 +1551,8 @@ void PlayerConnection::handlePlayerAbilities( // StringBuilder result = new StringBuilder(); // for (String candidate : server.getAutoCompletions(player, -//packet.getMessage())) { if (result.length() > 0) result.append("\0"); +// packet.getMessage())) { if (result.length() > 0) +// result.append("\0"); // result.append(candidate); // } diff --git a/Minecraft.Client/Platform/PS3/PS3Extras/boost_1_53_0/boost/spirit/home/lex/lexer/lexertl/lexer.hpp b/Minecraft.Client/Platform/PS3/PS3Extras/boost_1_53_0/boost/spirit/home/lex/lexer/lexertl/lexer.hpp index 0f8af55d0..f73cb4e09 100644 --- a/Minecraft.Client/Platform/PS3/PS3Extras/boost_1_53_0/boost/spirit/home/lex/lexer/lexertl/lexer.hpp +++ b/Minecraft.Client/Platform/PS3/PS3Extras/boost_1_53_0/boost/spirit/home/lex/lexer/lexertl/lexer.hpp @@ -27,373 +27,359 @@ #include -namespace boost { namespace spirit { namespace lex { namespace lexertl -{ - /////////////////////////////////////////////////////////////////////////// - namespace detail - { - /////////////////////////////////////////////////////////////////////// - // The must_escape function checks if the given character value needs - // to be preceded by a backslash character to disable its special - // meaning in the context of a regular expression - /////////////////////////////////////////////////////////////////////// - template - inline bool must_escape(Char c) - { - // FIXME: more needed? - switch (c) { - case '+': case '/': case '*': case '?': - case '|': - case '(': case ')': - case '[': case ']': - case '{': case '}': - case '.': - case '^': case '$': - case '\\': - case '"': - return true; +namespace boost { +namespace spirit { +namespace lex { +namespace lexertl { +/////////////////////////////////////////////////////////////////////////// +namespace detail { +/////////////////////////////////////////////////////////////////////// +// The must_escape function checks if the given character value needs +// to be preceded by a backslash character to disable its special +// meaning in the context of a regular expression +/////////////////////////////////////////////////////////////////////// +template +inline bool must_escape(Char c) { + // FIXME: more needed? + switch (c) { + case '+': + case '/': + case '*': + case '?': + case '|': + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + case '.': + case '^': + case '$': + case '\\': + case '"': + return true; - default: - break; - } - return false; - } + default: + break; + } + return false; +} - /////////////////////////////////////////////////////////////////////// - // The escape function returns the string representation of the given - // character value, possibly escaped with a backslash character, to - // allow it being safely used in a regular expression definition. - /////////////////////////////////////////////////////////////////////// - template - inline std::basic_string escape(Char ch) - { - std::basic_string result(1, ch); - if (detail::must_escape(ch)) - { - typedef typename std::basic_string::size_type size_type; - result.insert((size_type)0, 1, '\\'); - } - return result; - } +/////////////////////////////////////////////////////////////////////// +// The escape function returns the string representation of the given +// character value, possibly escaped with a backslash character, to +// allow it being safely used in a regular expression definition. +/////////////////////////////////////////////////////////////////////// +template +inline std::basic_string escape(Char ch) { + std::basic_string result(1, ch); + if (detail::must_escape(ch)) { + typedef typename std::basic_string::size_type size_type; + result.insert((size_type)0, 1, '\\'); + } + return result; +} - /////////////////////////////////////////////////////////////////////// - // - /////////////////////////////////////////////////////////////////////// - inline boost::lexer::regex_flags map_flags(unsigned int flags) - { - unsigned int retval = boost::lexer::none; - if (flags & match_flags::match_not_dot_newline) - retval |= boost::lexer::dot_not_newline; - if (flags & match_flags::match_icase) - retval |= boost::lexer::icase; +/////////////////////////////////////////////////////////////////////// +// +/////////////////////////////////////////////////////////////////////// +inline boost::lexer::regex_flags map_flags(unsigned int flags) { + unsigned int retval = boost::lexer::none; + if (flags & match_flags::match_not_dot_newline) + retval |= boost::lexer::dot_not_newline; + if (flags & match_flags::match_icase) retval |= boost::lexer::icase; - return boost::lexer::regex_flags(retval); - } + return boost::lexer::regex_flags(retval); +} +} // namespace detail + +/////////////////////////////////////////////////////////////////////////// +template +bool generate_static(Lexer const&, + std::basic_ostream&, + typename Lexer::char_type const*, F); + +/////////////////////////////////////////////////////////////////////////// +// +// Every lexer type to be used as a lexer for Spirit has to conform to +// the following public interface: +// +// typedefs: +// iterator_type The type of the iterator exposed by this lexer. +// token_type The type of the tokens returned from the exposed +// iterators. +// +// functions: +// default constructor +// Since lexers are instantiated as base classes +// only it might be a good idea to make this +// constructor protected. +// begin, end Return a pair of iterators, when dereferenced +// returning the sequence of tokens recognized in +// the input stream given as the parameters to the +// begin() function. +// add_token Should add the definition of a token to be +// recognized by this lexer. +// clear Should delete all current token definitions +// associated with the given state of this lexer +// object. +// +// template parameters: +// Iterator The type of the iterator used to access the +// underlying character stream. +// Token The type of the tokens to be returned from the +// exposed token iterator. +// Functor The type of the InputPolicy to use to instantiate +// the multi_pass iterator type to be used as the +// token iterator (returned from begin()/end()). +// +/////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// +// The lexer class is a implementation of a Spirit.Lex lexer on +// top of Ben Hanson's lexertl library as outlined above (For more +// information about lexertl go here: http://www.benhanson.net/lexertl.html). +// +// This class is supposed to be used as the first and only template +// parameter while instantiating instances of a lex::lexer class. +// +/////////////////////////////////////////////////////////////////////////// +template , + typename Iterator = typename Token::iterator_type, + typename Functor = functor > +class lexer { +private: + struct dummy { + void true_() {} + }; + typedef void (dummy::*safe_bool)(); + + static std::size_t const all_states_id = static_cast(-2); + +public: + operator safe_bool() const { return initialized_dfa_ ? &dummy::true_ : 0; } + + typedef + typename boost::detail::iterator_traits::value_type char_type; + typedef std::basic_string string_type; + + typedef boost::lexer::basic_rules basic_rules_type; + + // Every lexer type to be used as a lexer for Spirit has to conform to + // a public interface . + typedef Token token_type; + typedef typename Token::id_type id_type; + typedef iterator iterator_type; + +private: + // this type is purely used for the iterator_type construction below + struct iterator_data_type { + typedef typename Functor::semantic_actions_type semantic_actions_type; + + iterator_data_type( + boost::lexer::basic_state_machine const& sm, + boost::lexer::basic_rules const& rules, + semantic_actions_type const& actions) + : state_machine_(sm), rules_(rules), actions_(actions) {} + + boost::lexer::basic_state_machine const& state_machine_; + boost::lexer::basic_rules const& rules_; + semantic_actions_type const& actions_; + + private: + // silence MSVC warning C4512: assignment operator could not be + // generated + iterator_data_type& operator=(iterator_data_type const&); + }; + +public: + // Return the start iterator usable for iterating over the generated + // tokens. + iterator_type begin(Iterator& first, Iterator const& last, + char_type const* initial_state = 0) const { + if (!init_dfa()) // never minimize DFA for dynamic lexers + return iterator_type(); + + iterator_data_type iterator_data(state_machine_, rules_, actions_); + return iterator_type(iterator_data, first, last, initial_state); } - /////////////////////////////////////////////////////////////////////////// - template - bool generate_static(Lexer const& - , std::basic_ostream& - , typename Lexer::char_type const*, F); + // Return the end iterator usable to stop iterating over the generated + // tokens. + iterator_type end() const { return iterator_type(); } - /////////////////////////////////////////////////////////////////////////// - // - // Every lexer type to be used as a lexer for Spirit has to conform to - // the following public interface: - // - // typedefs: - // iterator_type The type of the iterator exposed by this lexer. - // token_type The type of the tokens returned from the exposed - // iterators. - // - // functions: - // default constructor - // Since lexers are instantiated as base classes - // only it might be a good idea to make this - // constructor protected. - // begin, end Return a pair of iterators, when dereferenced - // returning the sequence of tokens recognized in - // the input stream given as the parameters to the - // begin() function. - // add_token Should add the definition of a token to be - // recognized by this lexer. - // clear Should delete all current token definitions - // associated with the given state of this lexer - // object. - // - // template parameters: - // Iterator The type of the iterator used to access the - // underlying character stream. - // Token The type of the tokens to be returned from the - // exposed token iterator. - // Functor The type of the InputPolicy to use to instantiate - // the multi_pass iterator type to be used as the - // token iterator (returned from begin()/end()). - // - /////////////////////////////////////////////////////////////////////////// +protected: + // Lexer instances can be created by means of a derived class only. + lexer(unsigned int flags) + : flags_(detail::map_flags(flags)), + rules_(flags_), + initialized_dfa_(false) {} - /////////////////////////////////////////////////////////////////////////// - // - // The lexer class is a implementation of a Spirit.Lex lexer on - // top of Ben Hanson's lexertl library as outlined above (For more - // information about lexertl go here: http://www.benhanson.net/lexertl.html). - // - // This class is supposed to be used as the first and only template - // parameter while instantiating instances of a lex::lexer class. - // - /////////////////////////////////////////////////////////////////////////// - template - , typename Iterator = typename Token::iterator_type - , typename Functor = functor > - class lexer - { - private: - struct dummy { void true_() {} }; - typedef void (dummy::*safe_bool)(); +public: + // interface for token definition management + std::size_t add_token(char_type const* state, char_type tokendef, + std::size_t token_id, char_type const* targetstate) { + add_state(state); + initialized_dfa_ = false; + if (state == all_states()) + return rules_.add(state, detail::escape(tokendef), token_id, + rules_.dot()); - static std::size_t const all_states_id = static_cast(-2); + if (0 == targetstate) + targetstate = state; + else + add_state(targetstate); + return rules_.add(state, detail::escape(tokendef), token_id, + targetstate); + } + std::size_t add_token(char_type const* state, string_type const& tokendef, + std::size_t token_id, char_type const* targetstate) { + add_state(state); + initialized_dfa_ = false; + if (state == all_states()) + return rules_.add(state, tokendef, token_id, rules_.dot()); - public: - operator safe_bool() const - { return initialized_dfa_ ? &dummy::true_ : 0; } + if (0 == targetstate) + targetstate = state; + else + add_state(targetstate); + return rules_.add(state, tokendef, token_id, targetstate); + } - typedef typename boost::detail::iterator_traits::value_type - char_type; - typedef std::basic_string string_type; + // interface for pattern definition management + void add_pattern(char_type const* state, string_type const& name, + string_type const& patterndef) { + add_state(state); + rules_.add_macro(name.c_str(), patterndef); + initialized_dfa_ = false; + } - typedef boost::lexer::basic_rules basic_rules_type; + boost::lexer::rules const& get_rules() const { return rules_; } - // Every lexer type to be used as a lexer for Spirit has to conform to - // a public interface . - typedef Token token_type; - typedef typename Token::id_type id_type; - typedef iterator iterator_type; + void clear(char_type const* state) { + std::size_t s = rules_.state(state); + if (boost::lexer::npos != s) rules_.clear(state); + initialized_dfa_ = false; + } + std::size_t add_state(char_type const* state) { + if (state == all_states()) return all_states_id; - private: - // this type is purely used for the iterator_type construction below - struct iterator_data_type - { - typedef typename Functor::semantic_actions_type semantic_actions_type; - - iterator_data_type( - boost::lexer::basic_state_machine const& sm - , boost::lexer::basic_rules const& rules - , semantic_actions_type const& actions) - : state_machine_(sm), rules_(rules), actions_(actions) - {} - - boost::lexer::basic_state_machine const& state_machine_; - boost::lexer::basic_rules const& rules_; - semantic_actions_type const& actions_; - - private: - // silence MSVC warning C4512: assignment operator could not be generated - iterator_data_type& operator= (iterator_data_type const&); - }; - - public: - // Return the start iterator usable for iterating over the generated - // tokens. - iterator_type begin(Iterator& first, Iterator const& last - , char_type const* initial_state = 0) const - { - if (!init_dfa()) // never minimize DFA for dynamic lexers - return iterator_type(); - - iterator_data_type iterator_data(state_machine_, rules_, actions_); - return iterator_type(iterator_data, first, last, initial_state); - } - - // Return the end iterator usable to stop iterating over the generated - // tokens. - iterator_type end() const - { - return iterator_type(); - } - - protected: - // Lexer instances can be created by means of a derived class only. - lexer(unsigned int flags) - : flags_(detail::map_flags(flags)) - , rules_(flags_) - , initialized_dfa_(false) - {} - - public: - // interface for token definition management - std::size_t add_token(char_type const* state, char_type tokendef, - std::size_t token_id, char_type const* targetstate) - { - add_state(state); - initialized_dfa_ = false; - if (state == all_states()) - return rules_.add(state, detail::escape(tokendef), token_id, rules_.dot()); - - if (0 == targetstate) - targetstate = state; - else - add_state(targetstate); - return rules_.add(state, detail::escape(tokendef), token_id, targetstate); - } - std::size_t add_token(char_type const* state, string_type const& tokendef, - std::size_t token_id, char_type const* targetstate) - { - add_state(state); - initialized_dfa_ = false; - if (state == all_states()) - return rules_.add(state, tokendef, token_id, rules_.dot()); - - if (0 == targetstate) - targetstate = state; - else - add_state(targetstate); - return rules_.add(state, tokendef, token_id, targetstate); - } - - // interface for pattern definition management - void add_pattern (char_type const* state, string_type const& name, - string_type const& patterndef) - { - add_state(state); - rules_.add_macro(name.c_str(), patterndef); + std::size_t stateid = rules_.state(state); + if (boost::lexer::npos == stateid) { + stateid = rules_.add_state(state); initialized_dfa_ = false; } + return stateid; + } + string_type initial_state() const { return string_type(rules_.initial()); } + string_type all_states() const { return string_type(rules_.all_states()); } - boost::lexer::rules const& get_rules() const { return rules_; } - - void clear(char_type const* state) - { - std::size_t s = rules_.state(state); - if (boost::lexer::npos != s) - rules_.clear(state); - initialized_dfa_ = false; - } - std::size_t add_state(char_type const* state) - { - if (state == all_states()) - return all_states_id; - - std::size_t stateid = rules_.state(state); - if (boost::lexer::npos == stateid) { - stateid = rules_.add_state(state); - initialized_dfa_ = false; - } - return stateid; - } - string_type initial_state() const - { - return string_type(rules_.initial()); - } - string_type all_states() const - { - return string_type(rules_.all_states()); - } - - // Register a semantic action with the given id - template - void add_action(std::size_t unique_id, std::size_t state, F act) - { - // If you see an error here stating add_action is not a member of - // fusion::unused_type then you are probably having semantic actions - // attached to at least one token in the lexer definition without - // using the lex::lexertl::actor_lexer<> as its base class. - typedef typename Functor::wrap_action_type wrapper_type; - if (state == all_states_id) { - // add the action to all known states - typedef typename - basic_rules_type::string_size_t_map::value_type + // Register a semantic action with the given id + template + void add_action(std::size_t unique_id, std::size_t state, F act) { + // If you see an error here stating add_action is not a member of + // fusion::unused_type then you are probably having semantic actions + // attached to at least one token in the lexer definition without + // using the lex::lexertl::actor_lexer<> as its base class. + typedef typename Functor::wrap_action_type wrapper_type; + if (state == all_states_id) { + // add the action to all known states + typedef typename basic_rules_type::string_size_t_map::value_type state_type; - std::size_t states = rules_.statemap().size(); - BOOST_FOREACH(state_type const& s, rules_.statemap()) { - for (std::size_t j = 0; j < states; ++j) - actions_.add_action(unique_id + j, s.second, wrapper_type::call(act)); - } - } - else { - actions_.add_action(unique_id, state, wrapper_type::call(act)); + std::size_t states = rules_.statemap().size(); + BOOST_FOREACH (state_type const& s, rules_.statemap()) { + for (std::size_t j = 0; j < states; ++j) + actions_.add_action(unique_id + j, s.second, + wrapper_type::call(act)); } + } else { + actions_.add_action(unique_id, state, wrapper_type::call(act)); } -// template -// void add_action(std::size_t unique_id, char_type const* state, F act) -// { -// typedef typename Functor::wrap_action_type wrapper_type; -// actions_.add_action(unique_id, add_state(state), wrapper_type::call(act)); -// } + } + // template + // void add_action(std::size_t unique_id, char_type const* state, F + // act) + // { + // typedef typename Functor::wrap_action_type wrapper_type; + // actions_.add_action(unique_id, add_state(state), + // wrapper_type::call(act)); + // } - // We do not minimize the state machine by default anymore because - // Ben said: "If you can afford to generate a lexer at runtime, there - // is little point in calling minimise." - // Go figure. - bool init_dfa(bool minimize = false) const - { - if (!initialized_dfa_) { - state_machine_.clear(); - typedef boost::lexer::basic_generator generator; - generator::build (rules_, state_machine_); - if (minimize) - generator::minimise (state_machine_); + // We do not minimize the state machine by default anymore because + // Ben said: "If you can afford to generate a lexer at runtime, there + // is little point in calling minimise." + // Go figure. + bool init_dfa(bool minimize = false) const { + if (!initialized_dfa_) { + state_machine_.clear(); + typedef boost::lexer::basic_generator generator; + generator::build(rules_, state_machine_); + if (minimize) generator::minimise(state_machine_); #if defined(BOOST_SPIRIT_LEXERTL_DEBUG) - boost::lexer::debug::dump(state_machine_, std::cerr); + boost::lexer::debug::dump(state_machine_, std::cerr); #endif - initialized_dfa_ = true; + initialized_dfa_ = true; -// // release memory held by rules description -// basic_rules_type rules; -// rules.init_state_info(rules_); // preserve states -// std::swap(rules, rules_); - } - return true; + // // release memory held by rules description + // basic_rules_type rules; + // rules.init_state_info(rules_); // preserve + // states std::swap(rules, rules_); } + return true; + } - private: - // lexertl specific data - mutable boost::lexer::basic_state_machine state_machine_; - boost::lexer::regex_flags flags_; - /*mutable*/ basic_rules_type rules_; +private: + // lexertl specific data + mutable boost::lexer::basic_state_machine state_machine_; + boost::lexer::regex_flags flags_; + /*mutable*/ basic_rules_type rules_; - typename Functor::semantic_actions_type actions_; - mutable bool initialized_dfa_; + typename Functor::semantic_actions_type actions_; + mutable bool initialized_dfa_; - // generator functions must be able to access members directly - template - friend bool generate_static(Lexer const& - , std::basic_ostream& - , typename Lexer::char_type const*, F); - }; + // generator functions must be able to access members directly + template + friend bool generate_static(Lexer const&, + std::basic_ostream&, + typename Lexer::char_type const*, F); +}; - /////////////////////////////////////////////////////////////////////////// - // - // The actor_lexer class is another implementation of a Spirit.Lex - // lexer on top of Ben Hanson's lexertl library as outlined above (For - // more information about lexertl go here: - // http://www.benhanson.net/lexertl.html). - // - // The only difference to the lexer class above is that token_def - // definitions may have semantic (lexer) actions attached while being - // defined: - // - // int w; - // token_def word = "[^ \t\n]+"; - // self = word[++ref(w)]; // see example: word_count_lexer - // - // This class is supposed to be used as the first and only template - // parameter while instantiating instances of a lex::lexer class. - // - /////////////////////////////////////////////////////////////////////////// - template - , typename Iterator = typename Token::iterator_type - , typename Functor = functor > - class actor_lexer : public lexer - { - protected: - // Lexer instances can be created by means of a derived class only. - actor_lexer(unsigned int flags) - : lexer(flags) {} - }; +/////////////////////////////////////////////////////////////////////////// +// +// The actor_lexer class is another implementation of a Spirit.Lex +// lexer on top of Ben Hanson's lexertl library as outlined above (For +// more information about lexertl go here: +// http://www.benhanson.net/lexertl.html). +// +// The only difference to the lexer class above is that token_def +// definitions may have semantic (lexer) actions attached while being +// defined: +// +// int w; +// token_def word = "[^ \t\n]+"; +// self = word[++ref(w)]; // see example: word_count_lexer +// +// This class is supposed to be used as the first and only template +// parameter while instantiating instances of a lex::lexer class. +// +/////////////////////////////////////////////////////////////////////////// +template , + typename Iterator = typename Token::iterator_type, + typename Functor = + functor > +class actor_lexer : public lexer { +protected: + // Lexer instances can be created by means of a derived class only. + actor_lexer(unsigned int flags) : lexer(flags) {} +}; -}}}} +} // namespace lexertl +} // namespace lex +} // namespace spirit +} // namespace boost #endif diff --git a/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp b/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp index eb768ac4c..9da02ae9f 100644 --- a/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp +++ b/Minecraft.Client/Platform/PS3/SPU_Tasks/ChunkUpdate/Tile_SPU.cpp @@ -96,36 +96,28 @@ TileData_SPU* Tile_SPU::ms_pTileData = NULL; Tile_SPU Tile_SPU::m_tiles[256]; +int Tile_SPU::getRenderShape() { return SHAPE_BLOCK; } - -int Tile_SPU::getRenderShape() -{ - return SHAPE_BLOCK; +void Tile_SPU::setShape(float x0, float y0, float z0, float x1, float y1, + float z1) { + ms_pTileData->xx0[id] = x0; + ms_pTileData->yy0[id] = y0; + ms_pTileData->zz0[id] = z0; + ms_pTileData->xx1[id] = x1; + ms_pTileData->yy1[id] = y1; + ms_pTileData->zz1[id] = z1; } - -void Tile_SPU::setShape(float x0, float y0, float z0, float x1, float y1, float z1) -{ - ms_pTileData->xx0[id] = x0; - ms_pTileData->yy0[id] = y0; - ms_pTileData->zz0[id] = z0; - ms_pTileData->xx1[id] = x1; - ms_pTileData->yy1[id] = y1; - ms_pTileData->zz1[id] = z1; +float Tile_SPU::getBrightness(ChunkRebuildData* level, int x, int y, int z) { + return level->getBrightness(x, y, z, ms_pTileData->lightEmission[id]); } - -float Tile_SPU::getBrightness(ChunkRebuildData *level, int x, int y, int z) -{ - return level->getBrightness(x, y, z, ms_pTileData->lightEmission[id]); -} -// +// // // 4J - brought forward from 1.8.2 -int Tile_SPU::getLightColor(ChunkRebuildData *level, int x, int y, int z) -{ - int tileID = level->getTile(x, y, z); - return level->getLightColor(x, y, z, ms_pTileData->lightEmission[tileID]); +int Tile_SPU::getLightColor(ChunkRebuildData* level, int x, int y, int z) { + int tileID = level->getTile(x, y, z); + return level->getLightColor(x, y, z, ms_pTileData->lightEmission[tileID]); } -// +// // bool Tile_SPU::isFaceVisible(Level *level, int x, int y, int z, int f) // { // if (f == 0) y--; @@ -136,197 +128,198 @@ int Tile_SPU::getLightColor(ChunkRebuildData *level, int x, int y, int z) // if (f == 5) x++; // return !level->isSolidRenderTile(x, y, z); // } -// -bool Tile_SPU::shouldRenderFace(ChunkRebuildData *level, int x, int y, int z, int face) -{ - if (face == 0 && getShapeY0() > 0) return true; - if (face == 1 && getShapeY1() < 1) return true; - if (face == 2 && getShapeZ0() > 0) return true; - if (face == 3 && getShapeZ1() < 1) return true; - if (face == 4 && getShapeX0() > 0) return true; - if (face == 5 && getShapeX1() < 1) return true; - return (!level->isSolidRenderTile(x, y, z)); +// +bool Tile_SPU::shouldRenderFace(ChunkRebuildData* level, int x, int y, int z, + int face) { + if (face == 0 && getShapeY0() > 0) return true; + if (face == 1 && getShapeY1() < 1) return true; + if (face == 2 && getShapeZ0() > 0) return true; + if (face == 3 && getShapeZ1() < 1) return true; + if (face == 4 && getShapeX0() > 0) return true; + if (face == 5 && getShapeX1() < 1) return true; + return (!level->isSolidRenderTile(x, y, z)); } -// -bool Tile_SPU::isSolidFace(ChunkRebuildData *level, int x, int y, int z, int face) -{ - return (level->getMaterial(x, y, z)->isSolid()); +// +bool Tile_SPU::isSolidFace(ChunkRebuildData* level, int x, int y, int z, + int face) { + return (level->getMaterial(x, y, z)->isSolid()); } -Icon_SPU *Tile_SPU::getTexture(ChunkRebuildData *level, int x, int y, int z, int face) -{ - // 4J - addition here to make rendering big blocks of leaves more efficient. Normally leaves never consider themselves as solid, so - // blocks of leaves will have all sides of each block completely visible. Changing to consider as solid if this block is surrounded by - // other leaves. This is paired with another change in Level::isSolidRenderTile/Region::isSolidRenderTile which makes things solid - // code-wise (ie for determining visible sides of neighbouring blocks). This change just makes the texture a solid one (tex + 1) which - // we already have in the texture map for doing non-fancy graphics. Note: this tile-specific code is here rather than making some new virtual - // method in the tiles, for the sake of efficiency - I don't imagine we'll be doing much more of this sort of thing +Icon_SPU* Tile_SPU::getTexture(ChunkRebuildData* level, int x, int y, int z, + int face) { + // 4J - addition here to make rendering big blocks of leaves more efficient. + // Normally leaves never consider themselves as solid, so blocks of leaves + // will have all sides of each block completely visible. Changing to + // consider as solid if this block is surrounded by other leaves. This is + // paired with another change in + // Level::isSolidRenderTile/Region::isSolidRenderTile which makes things + // solid code-wise (ie for determining visible sides of neighbouring + // blocks). This change just makes the texture a solid one (tex + 1) which + // we already have in the texture map for doing non-fancy graphics. Note: + // this tile-specific code is here rather than making some new virtual + // method in the tiles, for the sake of efficiency - I don't imagine we'll + // be doing much more of this sort of thing - int tileId = level->getTile(x, y, z); - int tileData = level->getData(x, y, z); + int tileId = level->getTile(x, y, z); + int tileData = level->getData(x, y, z); - if( tileId == Tile_SPU::leaves_Id ) - { - bool opaque = true; - int axo[6] = { 1,-1, 0, 0, 0, 0}; - int ayo[6] = { 0, 0, 1,-1, 0, 0}; - int azo[6] = { 0, 0, 0, 0, 1,-1}; - for( int i = 0; (i < 6) && opaque; i++ ) - { - int t = level->getTile(x + axo[i], y + ayo[i] , z + azo[i]); - if( ( t != Tile_SPU::leaves_Id ) && ( ( Tile_SPU::m_tiles[t].id == -1) || !Tile_SPU::m_tiles[t].isSolidRender() ) ) - { - opaque = false; - } - } + if (tileId == Tile_SPU::leaves_Id) { + bool opaque = true; + int axo[6] = {1, -1, 0, 0, 0, 0}; + int ayo[6] = {0, 0, 1, -1, 0, 0}; + int azo[6] = {0, 0, 0, 0, 1, -1}; + for (int i = 0; (i < 6) && opaque; i++) { + int t = level->getTile(x + axo[i], y + ayo[i], z + azo[i]); + if ((t != Tile_SPU::leaves_Id) && + ((Tile_SPU::m_tiles[t].id == -1) || + !Tile_SPU::m_tiles[t].isSolidRender())) { + opaque = false; + } + } - - Icon_SPU *icon = NULL; - if(opaque) - { - LeafTile_SPU::setFancy(false); - icon = getTexture(face, tileData); - LeafTile_SPU::setFancy(true); - } - else - { - icon = getTexture(face, tileData); - } - return icon; - } - return getTexture(face, tileData); + Icon_SPU* icon = NULL; + if (opaque) { + LeafTile_SPU::setFancy(false); + icon = getTexture(face, tileData); + LeafTile_SPU::setFancy(true); + } else { + icon = getTexture(face, tileData); + } + return icon; + } + return getTexture(face, tileData); } -// -Icon_SPU *Tile_SPU::getTexture(int face, int data) -{ - return &ms_pTileData->iconData[id]; +// +Icon_SPU* Tile_SPU::getTexture(int face, int data) { + return &ms_pTileData->iconData[id]; } -// -Icon_SPU *Tile_SPU::getTexture(int face) -{ - return getTexture(face, 0); -} -// +// +Icon_SPU* Tile_SPU::getTexture(int face) { return getTexture(face, 0); } +// // AABB *Tile_SPU::getTileAABB(Level *level, int x, int y, int z) // { -// return AABB::newTemp(x + xx0, y + yy0, z + zz0, x + xx1, y + yy1, z + zz1); +// return AABB::newTemp(x + xx0, y + yy0, z + zz0, x + xx1, y + yy1, z + +// zz1); // } -// -// void Tile_SPU::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, Entity *source) +// +// void Tile_SPU::addAABBs(Level *level, int x, int y, int z, AABB *box, +// AABBList *boxes, Entity *source) // { // AABB *aabb = getAABB(level, x, y, z); // if (aabb != NULL && box->intersects(aabb)) boxes->push_back(aabb); // } -// -// void Tile_SPU::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes) +// +// void Tile_SPU::addAABBs(Level *level, int x, int y, int z, AABB *box, +// AABBList *boxes) // { // AABB *aabb = getAABB(level, x, y, z); // if (aabb != NULL && box->intersects(aabb)) boxes->push_back(aabb); // } -// +// // AABB *Tile_SPU::getAABB(Level *level, int x, int y, int z) // { -// return AABB::newTemp(x + xx0, y + yy0, z + zz0, x + xx1, y + yy1, z + zz1); +// return AABB::newTemp(x + xx0, y + yy0, z + zz0, x + xx1, y + yy1, z + +// zz1); // } -// - bool Tile_SPU::isSolidRender(bool isServerLevel) - { - return true; - } - +// +bool Tile_SPU::isSolidRender(bool isServerLevel) { return true; } // bool Tile_SPU::mayPick(int data, bool liquid) // { // return mayPick(); // } -// +// // bool Tile_SPU::mayPick() // { // return true; // } -// +// // void Tile_SPU::tick(Level *level, int x, int y, int z, Random *random) // { // } -// +// // void Tile_SPU::animateTick(Level *level, int x, int y, int z, Random *random) // { // } -// +// // void Tile_SPU::destroy(Level *level, int x, int y, int z, int data) // { // } -// +// // void Tile_SPU::neighborChanged(Level *level, int x, int y, int z, int type) // { // } -// +// // void Tile_SPU::addLights(Level *level, int x, int y, int z) // { // } -// +// // int Tile_SPU::getTickDelay() // { // return 10; // } -// +// // void Tile_SPU::onPlace(Level *level, int x, int y, int z) // { // } -// +// // void Tile_SPU::onRemove(Level *level, int x, int y, int z) // { // } -// +// // int Tile_SPU::getResourceCount(Random *random) // { // return 1; // } -// +// // int Tile_SPU::getResource(int data, Random *random, int playerBonusLevel) // { // return id; // } -// +// // float Tile_SPU::getDestroyProgress(std::shared_ptr player) // { // if (destroySpeed < 0) return 0; // if (!player->canDestroy(this)) return 1 / destroySpeed / 100.0f; // return (player->getDestroySpeed(this) / destroySpeed) / 30; // } -// -// void Tile_SPU::spawnResources(Level *level, int x, int y, int z, int data, int playerBonusLevel) +// +// void Tile_SPU::spawnResources(Level *level, int x, int y, int z, int data, +// int playerBonusLevel) // { // spawnResources(level, x, y, z, data, 1, playerBonusLevel); // } -// -// void Tile_SPU::spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonusLevel) +// +// void Tile_SPU::spawnResources(Level *level, int x, int y, int z, int data, +// float odds, int playerBonusLevel) // { // if (level->isClientSide) return; -// int count = getResourceCountForLootBonus(playerBonusLevel, level->random); -// for (int i = 0; i < count; i++) +// int count = getResourceCountForLootBonus(playerBonusLevel, +// level->random); for (int i = 0; i < count; i++) // { // if (level->random->nextFloat() > odds) continue; // int type = getResource(data, level->random, playerBonusLevel); // if (type <= 0) continue; -// -// popResource(level, x, y, z, std::shared_ptr( new ItemInstance(type, 1, getSpawnResourcesAuxValue(data) ) ) ); +// +// popResource(level, x, y, z, std::shared_ptr( new +// ItemInstance(type, 1, getSpawnResourcesAuxValue(data) ) ) ); // } // } -// -// void Tile_SPU::popResource(Level *level, int x, int y, int z, std::shared_ptr itemInstance) +// +// void Tile_SPU::popResource(Level *level, int x, int y, int z, +// std::shared_ptr itemInstance) // { // if( level->isClientSide ) return; -// +// // float s = 0.7f; // double xo = level->random->nextFloat() * s + (1 - s) * 0.5; // double yo = level->random->nextFloat() * s + (1 - s) * 0.5; // double zo = level->random->nextFloat() * s + (1 - s) * 0.5; -// std::shared_ptr item = std::shared_ptr( new ItemEntity(level, x + xo, y + yo, z + zo, itemInstance ) ); -// item->throwTime = 10; -// level->addEntity(item); +// std::shared_ptr item = std::shared_ptr( new +// ItemEntity(level, x + xo, y + yo, z + zo, itemInstance ) ); item->throwTime = +// 10; level->addEntity(item); // } -// +// // // Brought forward for TU7 // void Tile_SPU::popExperience(Level *level, int x, int y, int z, int amount) // { @@ -334,184 +327,192 @@ Icon_SPU *Tile_SPU::getTexture(int face) // { // while (amount > 0) // { -// int newCount = ExperienceOrb::getExperienceValue(amount); -// amount -= newCount; -// level->addEntity(std::shared_ptr( new ExperienceOrb(level, x + .5, y + .5, z + .5, newCount))); +// int newCount = +// ExperienceOrb::getExperienceValue(amount); amount -= newCount; +// level->addEntity(std::shared_ptr( new +// ExperienceOrb(level, x + .5, y + .5, z + .5, newCount))); // } // } // } -// +// // int Tile_SPU::getSpawnResourcesAuxValue(int data) // { // return 0; // } -// +// // float Tile_SPU::getExplosionResistance(std::shared_ptr source) // { // return explosionResistance / 5.0f; // } -// -// HitResult *Tile_SPU::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 *b) +// +// HitResult *Tile_SPU::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 +// *b) // { // EnterCriticalSection(&m_csShape); // updateShape(level, xt, yt, zt); -// +// // a = a->add(-xt, -yt, -zt); // b = b->add(-xt, -yt, -zt); -// +// // Vec3 *xh0 = a->clipX(b, xx0); // Vec3 *xh1 = a->clipX(b, xx1); -// +// // Vec3 *yh0 = a->clipY(b, yy0); // Vec3 *yh1 = a->clipY(b, yy1); -// +// // Vec3 *zh0 = a->clipZ(b, zz0); // Vec3 *zh1 = a->clipZ(b, zz1); -// +// // Vec3 *closest = NULL; -// -// if (containsX(xh0) && (closest == NULL || a->distanceTo(xh0) < a->distanceTo(closest))) closest = xh0; -// if (containsX(xh1) && (closest == NULL || a->distanceTo(xh1) < a->distanceTo(closest))) closest = xh1; -// if (containsY(yh0) && (closest == NULL || a->distanceTo(yh0) < a->distanceTo(closest))) closest = yh0; -// if (containsY(yh1) && (closest == NULL || a->distanceTo(yh1) < a->distanceTo(closest))) closest = yh1; -// if (containsZ(zh0) && (closest == NULL || a->distanceTo(zh0) < a->distanceTo(closest))) closest = zh0; -// if (containsZ(zh1) && (closest == NULL || a->distanceTo(zh1) < a->distanceTo(closest))) closest = zh1; -// +// +// if (containsX(xh0) && (closest == NULL || a->distanceTo(xh0) < +// a->distanceTo(closest))) closest = xh0; if (containsX(xh1) && (closest == +// NULL || a->distanceTo(xh1) < a->distanceTo(closest))) closest = xh1; if +// (containsY(yh0) && (closest == NULL || a->distanceTo(yh0) < +// a->distanceTo(closest))) closest = yh0; if (containsY(yh1) && (closest == +// NULL || a->distanceTo(yh1) < a->distanceTo(closest))) closest = yh1; if +// (containsZ(zh0) && (closest == NULL || a->distanceTo(zh0) < +// a->distanceTo(closest))) closest = zh0; if (containsZ(zh1) && (closest == +// NULL || a->distanceTo(zh1) < a->distanceTo(closest))) closest = zh1; +// // LeaveCriticalSection(&m_csShape); -// +// // if (closest == NULL) return NULL; -// +// // int face = -1; -// +// // if (closest == xh0) face = 4; // if (closest == xh1) face = 5; // if (closest == yh0) face = 0; // if (closest == yh1) face = 1; // if (closest == zh0) face = 2; // if (closest == zh1) face = 3; -// +// // return new HitResult(xt, yt, zt, face, closest->add(xt, yt, zt)); // } -// +// // bool Tile_SPU::containsX(Vec3 *v) // { // if( v == NULL) return false; // return v->y >= yy0 && v->y <= yy1 && v->z >= zz0 && v->z <= zz1; // } -// +// // bool Tile_SPU::containsY(Vec3 *v) // { // if( v == NULL) return false; // return v->x >= xx0 && v->x <= xx1 && v->z >= zz0 && v->z <= zz1; // } -// +// // bool Tile_SPU::containsZ(Vec3 *v) // { // if( v == NULL) return false; // return v->x >= xx0 && v->x <= xx1 && v->y >= yy0 && v->y <= yy1; // } -// +// // void Tile_SPU::wasExploded(Level *level, int x, int y, int z) // { // } -// -int Tile_SPU::getRenderLayer() -{ - return 0; -} -// +// +int Tile_SPU::getRenderLayer() { return 0; } +// // bool Tile_SPU::mayPlace(Level *level, int x, int y, int z, int face) // { // return mayPlace(level, x, y, z); // } -// +// // bool Tile_SPU::mayPlace(Level *level, int x, int y, int z) // { // int t = level->getTile(x, y, z); // return t == 0 || Tile_SPU::tiles[t]->material->isReplaceable(); // } -// +// // // 4J-PB - Adding a TestUse for tooltip display // bool Tile_SPU::TestUse() // { // return false; // } -// -// bool Tile_SPU::TestUse(Level *level, int x, int y, int z, std::shared_ptr player) +// +// bool Tile_SPU::TestUse(Level *level, int x, int y, int z, +// std::shared_ptr player) // { // return false; // } -// -// bool Tile_SPU::use(Level *level, int x, int y, int z, std::shared_ptr player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param +// +// bool Tile_SPU::use(Level *level, int x, int y, int z, std::shared_ptr +// player, int clickedFace, float clickX, float clickY, float clickZ, bool +// soundOnly/*=false*/) // 4J added soundOnly param // { // return false; // } -// -// void Tile_SPU::stepOn(Level *level, int x, int y, int z, std::shared_ptr entity) +// +// void Tile_SPU::stepOn(Level *level, int x, int y, int z, +// std::shared_ptr entity) // { // } -// +// // void Tile_SPU::setPlacedOnFace(Level *level, int x, int y, int z, int face) // { // } -// +// // void Tile_SPU::prepareRender(Level *level, int x, int y, int z) // { // } -// -// void Tile_SPU::attack(Level *level, int x, int y, int z, std::shared_ptr player) +// +// void Tile_SPU::attack(Level *level, int x, int y, int z, +// std::shared_ptr player) // { // } -// -// void Tile_SPU::handleEntityInside(Level *level, int x, int y, int z, std::shared_ptr e, Vec3 *current) +// +// void Tile_SPU::handleEntityInside(Level *level, int x, int y, int z, +// std::shared_ptr e, Vec3 *current) // { // } -// -void Tile_SPU::updateShape(ChunkRebuildData *level, int x, int y, int z, int forceData, TileEntity* forceEntity) // 4J added forceData, forceEntity param -{ -} -// +// +void Tile_SPU::updateShape( + ChunkRebuildData* level, int x, int y, int z, int forceData, + TileEntity* forceEntity) // 4J added forceData, forceEntity param +{} +// -int Tile_SPU::getColor(ChunkRebuildData *level, int x, int y, int z) -{ - return 0xffffff; +int Tile_SPU::getColor(ChunkRebuildData* level, int x, int y, int z) { + return 0xffffff; } -// +// // int Tile_SPU::getColor(LevelSource *level, int x, int y, int z, int data) // { // return 0xffffff; // } -// +// // bool Tile_SPU::getSignal(LevelSource *level, int x, int y, int z) // { // return false; // } -// +// // bool Tile_SPU::getSignal(LevelSource *level, int x, int y, int z, int dir) // { // return false; // } -// +// // bool Tile_SPU::isSignalSource() // { // return false; // } -// -// void Tile_SPU::entityInside(Level *level, int x, int y, int z, std::shared_ptr entity) +// +// void Tile_SPU::entityInside(Level *level, int x, int y, int z, +// std::shared_ptr entity) // { // } -// +// // bool Tile_SPU::getDirectSignal(Level *level, int x, int y, int z, int dir) // { // return false; // } -// -void Tile_SPU::updateDefaultShape() -{ -} -// -// void Tile_SPU::playerDestroy(Level *level, std::shared_ptr player, int x, int y, int z, int data) +// +void Tile_SPU::updateDefaultShape() {} +// +// void Tile_SPU::playerDestroy(Level *level, std::shared_ptr player, +// int x, int y, int z, int data) // { // // 4J Stu - Special case - only record a crop destroy if is fully grown // if(id==Tile_SPU::crops_Id) @@ -523,14 +524,15 @@ void Tile_SPU::updateDefaultShape() // { // player->awardStat(Stats::blocksMined[id], 1); // } -// player->awardStat(Stats::totalBlocksMined, 1); // 4J : WESTY : Added for other award. -// player->causeFoodExhaustion(FoodConstants::EXHAUSTION_MINE); -// +// player->awardStat(Stats::totalBlocksMined, 1); // 4J : WESTY : Added +// for other award. player->causeFoodExhaustion(FoodConstants::EXHAUSTION_MINE); +// // if( id == Tile_SPU::treeTrunk_Id ) // player->awardStat(Achievements::mineWood); -// -// -// if (isCubeShaped() && !isEntityTile[id] && EnchantmentHelper::hasSilkTouch(player->inventory)) +// +// +// if (isCubeShaped() && !isEntityTile[id] && +// EnchantmentHelper::hasSilkTouch(player->inventory)) // { // std::shared_ptr item = getSilkTouchItemInstance(data); // if (item != NULL) @@ -540,360 +542,354 @@ void Tile_SPU::updateDefaultShape() // } // else // { -// int playerBonusLevel = EnchantmentHelper::getDiggingLootBonus(player->inventory); +// int playerBonusLevel = +// EnchantmentHelper::getDiggingLootBonus(player->inventory); // spawnResources(level, x, y, z, data, playerBonusLevel); // } // } -// +// // std::shared_ptr Tile_SPU::getSilkTouchItemInstance(int data) // { // int popData = 0; -// if (id >= 0 && id < Item::items.length && Item::items[id]->isStackedByData()) +// if (id >= 0 && id < Item::items.length && +// Item::items[id]->isStackedByData()) // { // popData = data; // } // return std::shared_ptr(new ItemInstance(id, 1, popData)); // } -// +// // int Tile_SPU::getResourceCountForLootBonus(int bonusLevel, Random *random) // { // return getResourceCount(random); // } -// +// // bool Tile_SPU::canSurvive(Level *level, int x, int y, int z) // { // return true; // } -// -// void Tile_SPU::setPlacedBy(Level *level, int x, int y, int z, std::shared_ptr by) +// +// void Tile_SPU::setPlacedBy(Level *level, int x, int y, int z, +// std::shared_ptr by) // { // } -// +// // Tile *Tile_SPU::setDescriptionId(unsigned int id) // { // this->descriptionId = id; // return this; // } -// +// // std::wstring Tile_SPU::getName() // { // return I18n::get(getDescriptionId() + L".name"); // } -// +// // unsigned int Tile_SPU::getDescriptionId(int iData /*= -1*/) // { // return descriptionId; // } -// +// // Tile *Tile_SPU::setUseDescriptionId(unsigned int id) // { // this->useDescriptionId = id; // return this; // } -// +// // unsigned int Tile_SPU::getUseDescriptionId() // { // return useDescriptionId; // } -// -// void Tile_SPU::triggerEvent(Level *level, int x, int y, int z, int b0, int b1) +// +// void Tile_SPU::triggerEvent(Level *level, int x, int y, int z, int b0, int +// b1) // { // } -// +// // bool Tile_SPU::isCollectStatistics() // { // return collectStatistics; // } -// +// // Tile *Tile_SPU::setNotCollectStatistics() // { // collectStatistics = false; // return this; // } -// +// // int Tile_SPU::getPistonPushReaction() // { // return material->getPushReaction(); // } -// +// // // 4J - brought forward from 1.8.2 -float Tile_SPU::getShadeBrightness(ChunkRebuildData *level, int x, int y, int z) -{ - return level->isSolidBlockingTile(x, y, z) ? 0.2f : 1.0f; +float Tile_SPU::getShadeBrightness(ChunkRebuildData* level, int x, int y, + int z) { + return level->isSolidBlockingTile(x, y, z) ? 0.2f : 1.0f; } -Tile_SPU* Tile_SPU::createFromID( int tileID ) -{ - if(tileID == 0) - return NULL; +Tile_SPU* Tile_SPU::createFromID(int tileID) { + if (tileID == 0) return NULL; + + if (m_tiles[tileID].id != -1) return &m_tiles[tileID]; - if(m_tiles[tileID].id != -1) - return &m_tiles[tileID]; - #ifndef SN_TARGET_PS3_SPU - app.DebugPrintf("missing tile ID %d\n", tileID); + app.DebugPrintf("missing tile ID %d\n", tileID); #else - spu_print("missing tile ID %d\n", tileID); -#endif - return &m_tiles[1]; - + spu_print("missing tile ID %d\n", tileID); +#endif + return &m_tiles[1]; } -Material_SPU* Tile_SPU::getMaterial() -{ - int matID = ms_pTileData->materialIDs[id]; - return &ms_pTileData->materials[matID]; +Material_SPU* Tile_SPU::getMaterial() { + int matID = ms_pTileData->materialIDs[id]; + return &ms_pTileData->materials[matID]; } -// -// void Tile_SPU::fallOn(Level *level, int x, int y, int z, std::shared_ptr entity, float fallDistance) +// +// void Tile_SPU::fallOn(Level *level, int x, int y, int z, +// std::shared_ptr entity, float fallDistance) // { // } -// +// // void Tile_SPU::registerIcons(IconRegister *iconRegister) // { // icon = iconRegister->registerIcon(m_textureName); // } -// +// // std::wstring Tile_SPU::getTileItemIconName() // { // return L""; // } -// +// // Tile *Tile_SPU::setTextureName(const std::wstring &name) // { // m_textureName = name; // return this; // } +void Tile_SPU::initTilePointers() { +#define CREATE_TILE_TYPE(index, className) \ + new (&m_tiles[index]) className(index); + CREATE_TILE_TYPE(grass_Id, GrassTile_SPU); + CREATE_TILE_TYPE(stoneSlab_Id, StoneSlabTile_SPU); + CREATE_TILE_TYPE(stoneSlabHalf_Id, StoneSlabTile_SPU); + CREATE_TILE_TYPE(woodSlab_Id, WoodSlabTile_SPU); + CREATE_TILE_TYPE(woodSlabHalf_Id, WoodSlabTile_SPU); -void Tile_SPU::initTilePointers() -{ + CREATE_TILE_TYPE(chest_Id, ChestTile_SPU); -#define CREATE_TILE_TYPE(index, className) new (&m_tiles[index]) className(index); + CREATE_TILE_TYPE(ironFence_Id, ThinFenceTile_SPU); + CREATE_TILE_TYPE(thinGlass_Id, ThinFenceTile_SPU); + CREATE_TILE_TYPE(fence_Id, FenceTile_SPU); + CREATE_TILE_TYPE(netherFence_Id, FenceTile_SPU); - CREATE_TILE_TYPE(grass_Id, GrassTile_SPU); - CREATE_TILE_TYPE(stoneSlab_Id, StoneSlabTile_SPU); - CREATE_TILE_TYPE(stoneSlabHalf_Id, StoneSlabTile_SPU); - CREATE_TILE_TYPE(woodSlab_Id, WoodSlabTile_SPU); - CREATE_TILE_TYPE(woodSlabHalf_Id, WoodSlabTile_SPU); + CREATE_TILE_TYPE(stairs_wood_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_stone_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_bricks_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_stoneBrickSmooth_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_netherBricks_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_sandstone_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_sprucewood_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_birchwood_Id, StairTile_SPU); + CREATE_TILE_TYPE(stairs_junglewood_Id, StairTile_SPU); - CREATE_TILE_TYPE(chest_Id, ChestTile_SPU); + CREATE_TILE_TYPE(dirt_Id, DirtTile_SPU); - CREATE_TILE_TYPE(ironFence_Id, ThinFenceTile_SPU); - CREATE_TILE_TYPE(thinGlass_Id, ThinFenceTile_SPU); + CREATE_TILE_TYPE(door_iron_Id, DoorTile_SPU); + CREATE_TILE_TYPE(door_wood_Id, DoorTile_SPU); - CREATE_TILE_TYPE(fence_Id, FenceTile_SPU); - CREATE_TILE_TYPE(netherFence_Id, FenceTile_SPU); + CREATE_TILE_TYPE(pressurePlate_stone_Id, PressurePlateTile_SPU); + CREATE_TILE_TYPE(pressurePlate_wood_Id, PressurePlateTile_SPU); - CREATE_TILE_TYPE(stairs_wood_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_stone_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_bricks_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_stoneBrickSmooth_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_netherBricks_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_sandstone_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_sprucewood_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_birchwood_Id, StairTile_SPU); - CREATE_TILE_TYPE(stairs_junglewood_Id, StairTile_SPU); + CREATE_TILE_TYPE(farmland_Id, FarmTile_SPU); - CREATE_TILE_TYPE(dirt_Id, DirtTile_SPU); + CREATE_TILE_TYPE(flower_Id, Bush_SPU); + CREATE_TILE_TYPE(rose_Id, Bush_SPU); + CREATE_TILE_TYPE(deadBush_Id, Bush_SPU); // DeadBushTile - CREATE_TILE_TYPE(door_iron_Id, DoorTile_SPU); - CREATE_TILE_TYPE(door_wood_Id, DoorTile_SPU); + CREATE_TILE_TYPE(tallgrass_Id, TallGrass_SPU); - CREATE_TILE_TYPE(pressurePlate_stone_Id, PressurePlateTile_SPU); - CREATE_TILE_TYPE(pressurePlate_wood_Id, PressurePlateTile_SPU); + CREATE_TILE_TYPE(sandStone_Id, SandStoneTile_SPU); - CREATE_TILE_TYPE(farmland_Id, FarmTile_SPU); + CREATE_TILE_TYPE(wood_Id, WoodTile_SPU); - CREATE_TILE_TYPE(flower_Id, Bush_SPU); - CREATE_TILE_TYPE(rose_Id, Bush_SPU); - CREATE_TILE_TYPE(deadBush_Id, Bush_SPU); // DeadBushTile + CREATE_TILE_TYPE(treeTrunk_Id, TreeTile_SPU); - CREATE_TILE_TYPE(tallgrass_Id, TallGrass_SPU); + CREATE_TILE_TYPE(leaves_Id, LeafTile_SPU); - CREATE_TILE_TYPE(sandStone_Id, SandStoneTile_SPU); + CREATE_TILE_TYPE(crops_Id, CropTile_SPU); - CREATE_TILE_TYPE(wood_Id, WoodTile_SPU); + CREATE_TILE_TYPE(reeds_Id, ReedTile_SPU); - CREATE_TILE_TYPE(treeTrunk_Id, TreeTile_SPU); + CREATE_TILE_TYPE(torch_Id, TorchTile_SPU); + CREATE_TILE_TYPE(notGate_off_Id, TorchTile_SPU); // TorchTile->NotGateTile + CREATE_TILE_TYPE(notGate_on_Id, TorchTile_SPU); // TorchTile->NotGateTile - CREATE_TILE_TYPE(leaves_Id, LeafTile_SPU); + CREATE_TILE_TYPE(mushroom1_Id, Mushroom_SPU); + CREATE_TILE_TYPE(mushroom2_Id, Mushroom_SPU); - CREATE_TILE_TYPE(crops_Id, CropTile_SPU); + CREATE_TILE_TYPE(mobSpawner_Id, MobSpawnerTile_SPU); + CREATE_TILE_TYPE(musicBlock_Id, EntityTile_SPU); // MusicTile->EntityTile - CREATE_TILE_TYPE(reeds_Id, ReedTile_SPU); + CREATE_TILE_TYPE(furnace_Id, FurnaceTile_SPU); + CREATE_TILE_TYPE(furnace_lit_Id, FurnaceTile_SPU); - CREATE_TILE_TYPE(torch_Id, TorchTile_SPU); - CREATE_TILE_TYPE(notGate_off_Id, TorchTile_SPU); // TorchTile->NotGateTile - CREATE_TILE_TYPE(notGate_on_Id, TorchTile_SPU); // TorchTile->NotGateTile + CREATE_TILE_TYPE(web_Id, WebTile_SPU); - CREATE_TILE_TYPE(mushroom1_Id, Mushroom_SPU); - CREATE_TILE_TYPE(mushroom2_Id, Mushroom_SPU); + CREATE_TILE_TYPE(water_Id, LiquidTile_SPU); + CREATE_TILE_TYPE(lava_Id, LiquidTile_SPU); + CREATE_TILE_TYPE(calmLava_Id, LiquidTile_SPU); // LiquidTileStatic + CREATE_TILE_TYPE(calmWater_Id, LiquidTile_SPU); // LiquidTileStatic - CREATE_TILE_TYPE(mobSpawner_Id, MobSpawnerTile_SPU); - CREATE_TILE_TYPE(musicBlock_Id, EntityTile_SPU); // MusicTile->EntityTile + CREATE_TILE_TYPE(fire_Id, FireTile_SPU); - CREATE_TILE_TYPE(furnace_Id, FurnaceTile_SPU); - CREATE_TILE_TYPE(furnace_lit_Id, FurnaceTile_SPU); + CREATE_TILE_TYPE(sapling_Id, Sapling_SPU); - CREATE_TILE_TYPE(web_Id, WebTile_SPU); + CREATE_TILE_TYPE(glass_Id, GlassTile_SPU); - CREATE_TILE_TYPE(water_Id, LiquidTile_SPU); - CREATE_TILE_TYPE(lava_Id, LiquidTile_SPU); - CREATE_TILE_TYPE(calmLava_Id, LiquidTile_SPU); // LiquidTileStatic - CREATE_TILE_TYPE(calmWater_Id, LiquidTile_SPU); // LiquidTileStatic + CREATE_TILE_TYPE(ice_Id, IceTile_SPU); - CREATE_TILE_TYPE(fire_Id, FireTile_SPU); + CREATE_TILE_TYPE(portalTile_Id, PortalTile_SPU); - CREATE_TILE_TYPE(sapling_Id, Sapling_SPU); + CREATE_TILE_TYPE(dispenser_Id, DispenserTile_SPU); - CREATE_TILE_TYPE(glass_Id, GlassTile_SPU); + CREATE_TILE_TYPE(rail_Id, RailTile_SPU); + CREATE_TILE_TYPE(goldenRail_Id, RailTile_SPU); - CREATE_TILE_TYPE(ice_Id, IceTile_SPU); + CREATE_TILE_TYPE(detectorRail_Id, DetectorRailTile_SPU); - CREATE_TILE_TYPE(portalTile_Id, PortalTile_SPU); + CREATE_TILE_TYPE(tnt_Id, TntTile_SPU); - CREATE_TILE_TYPE(dispenser_Id, DispenserTile_SPU); + CREATE_TILE_TYPE(bookshelf_Id, BookshelfTile_SPU); - CREATE_TILE_TYPE(rail_Id, RailTile_SPU); - CREATE_TILE_TYPE(goldenRail_Id, RailTile_SPU); + CREATE_TILE_TYPE(workBench_Id, WorkbenchTile_SPU); - CREATE_TILE_TYPE(detectorRail_Id, DetectorRailTile_SPU); + CREATE_TILE_TYPE(sign_Id, SignTile_SPU); + CREATE_TILE_TYPE(wallSign_Id, SignTile_SPU); - CREATE_TILE_TYPE(tnt_Id, TntTile_SPU); + CREATE_TILE_TYPE(ladder_Id, LadderTile_SPU); - CREATE_TILE_TYPE(bookshelf_Id, BookshelfTile_SPU); + CREATE_TILE_TYPE(button_stone_Id, ButtonTile_SPU); + CREATE_TILE_TYPE(button_wood_Id, ButtonTile_SPU); - CREATE_TILE_TYPE(workBench_Id, WorkbenchTile_SPU); + CREATE_TILE_TYPE(topSnow_Id, TopSnowTile_SPU); - CREATE_TILE_TYPE(sign_Id, SignTile_SPU); - CREATE_TILE_TYPE(wallSign_Id, SignTile_SPU); + CREATE_TILE_TYPE(cactus_Id, CactusTile_SPU); - CREATE_TILE_TYPE(ladder_Id, LadderTile_SPU); + CREATE_TILE_TYPE(recordPlayer_Id, RecordPlayerTile_SPU); - CREATE_TILE_TYPE(button_stone_Id, ButtonTile_SPU); - CREATE_TILE_TYPE(button_wood_Id, ButtonTile_SPU); + CREATE_TILE_TYPE(pumpkin_Id, PumpkinTile_SPU); + CREATE_TILE_TYPE(litPumpkin_Id, PumpkinTile_SPU); - CREATE_TILE_TYPE(topSnow_Id, TopSnowTile_SPU); + CREATE_TILE_TYPE(cake_Id, CakeTile_SPU); - CREATE_TILE_TYPE(cactus_Id, CactusTile_SPU); + CREATE_TILE_TYPE(trapdoor_Id, TrapDoorTile_SPU); - CREATE_TILE_TYPE(recordPlayer_Id, RecordPlayerTile_SPU); + CREATE_TILE_TYPE(monsterStoneEgg_Id, StoneMonsterTile_SPU); - CREATE_TILE_TYPE(pumpkin_Id, PumpkinTile_SPU); - CREATE_TILE_TYPE(litPumpkin_Id, PumpkinTile_SPU); + CREATE_TILE_TYPE(stoneBrickSmooth_Id, SmoothStoneBrickTile_SPU); - CREATE_TILE_TYPE(cake_Id, CakeTile_SPU); + CREATE_TILE_TYPE(hugeMushroom1_Id, HugeMushroomTile_SPU); + CREATE_TILE_TYPE(hugeMushroom2_Id, HugeMushroomTile_SPU); - CREATE_TILE_TYPE(trapdoor_Id, TrapDoorTile_SPU); + CREATE_TILE_TYPE(melon_Id, MelonTile_SPU); - CREATE_TILE_TYPE(monsterStoneEgg_Id, StoneMonsterTile_SPU); + CREATE_TILE_TYPE(melonStem_Id, StemTile_SPU); + CREATE_TILE_TYPE(pumpkinStem_Id, StemTile_SPU); - CREATE_TILE_TYPE(stoneBrickSmooth_Id, SmoothStoneBrickTile_SPU); + CREATE_TILE_TYPE(vine_Id, VineTile_SPU); - CREATE_TILE_TYPE(hugeMushroom1_Id, HugeMushroomTile_SPU); - CREATE_TILE_TYPE(hugeMushroom2_Id, HugeMushroomTile_SPU); + CREATE_TILE_TYPE(mycel_Id, MycelTile_SPU); - CREATE_TILE_TYPE(melon_Id, MelonTile_SPU); + CREATE_TILE_TYPE(waterLily_Id, WaterlilyTile_SPU); - CREATE_TILE_TYPE(melonStem_Id, StemTile_SPU); - CREATE_TILE_TYPE(pumpkinStem_Id, StemTile_SPU); + CREATE_TILE_TYPE(netherStalk_Id, NetherStalkTile_SPU); - CREATE_TILE_TYPE(vine_Id, VineTile_SPU); + CREATE_TILE_TYPE(enchantTable_Id, EnchantmentTableTile_SPU); - CREATE_TILE_TYPE(mycel_Id, MycelTile_SPU); + CREATE_TILE_TYPE(brewingStand_Id, BrewingStandTile_SPU); - CREATE_TILE_TYPE(waterLily_Id, WaterlilyTile_SPU); + CREATE_TILE_TYPE(diode_on_Id, DiodeTile_SPU); + CREATE_TILE_TYPE(diode_off_Id, DiodeTile_SPU); - CREATE_TILE_TYPE(netherStalk_Id, NetherStalkTile_SPU); + CREATE_TILE_TYPE(redStoneDust_Id, RedStoneDustTile_SPU); - CREATE_TILE_TYPE(enchantTable_Id, EnchantmentTableTile_SPU); + CREATE_TILE_TYPE(fenceGate_Id, FenceGateTile_SPU); - CREATE_TILE_TYPE(brewingStand_Id, BrewingStandTile_SPU); + CREATE_TILE_TYPE(bed_Id, BedTile_SPU); - CREATE_TILE_TYPE(diode_on_Id, DiodeTile_SPU); - CREATE_TILE_TYPE(diode_off_Id, DiodeTile_SPU); + CREATE_TILE_TYPE(pistonBase_Id, PistonBaseTile_SPU); + CREATE_TILE_TYPE(pistonStickyBase_Id, PistonBaseTile_SPU); - CREATE_TILE_TYPE(redStoneDust_Id, RedStoneDustTile_SPU); + CREATE_TILE_TYPE(pistonExtensionPiece_Id, PistonExtensionTile_SPU); - CREATE_TILE_TYPE(fenceGate_Id, FenceGateTile_SPU); + CREATE_TILE_TYPE(pistonMovingPiece_Id, PistonMovingPiece_SPU); - CREATE_TILE_TYPE(bed_Id, BedTile_SPU); + CREATE_TILE_TYPE(lever_Id, LeverTile_SPU); - CREATE_TILE_TYPE(pistonBase_Id, PistonBaseTile_SPU); - CREATE_TILE_TYPE(pistonStickyBase_Id, PistonBaseTile_SPU); + CREATE_TILE_TYPE(cauldron_Id, CauldronTile_SPU); - CREATE_TILE_TYPE(pistonExtensionPiece_Id, PistonExtensionTile_SPU); + CREATE_TILE_TYPE(endPortalTile_Id, TheEndPortal_SPU); - CREATE_TILE_TYPE(pistonMovingPiece_Id, PistonMovingPiece_SPU); + CREATE_TILE_TYPE(endPortalFrameTile_Id, TheEndPortalFrameTile_SPU); - CREATE_TILE_TYPE(lever_Id, LeverTile_SPU); + CREATE_TILE_TYPE(dragonEgg_Id, EggTile_SPU); - CREATE_TILE_TYPE(cauldron_Id, CauldronTile_SPU); + CREATE_TILE_TYPE(cocoa_Id, CocoaTile_SPU); - CREATE_TILE_TYPE(endPortalTile_Id, TheEndPortal_SPU); + CREATE_TILE_TYPE(redstoneLight_Id, RedlightTile_SPU); + CREATE_TILE_TYPE(redstoneLight_lit_Id, RedlightTile_SPU); - CREATE_TILE_TYPE(endPortalFrameTile_Id, TheEndPortalFrameTile_SPU); + CREATE_TILE_TYPE(skull_Id, SkullTile_SPU); - CREATE_TILE_TYPE(dragonEgg_Id, EggTile_SPU); + // these tile types don't have any additional code that we need. + CREATE_TILE_TYPE(stoneBrick_Id, Tile_SPU); // Tile + CREATE_TILE_TYPE(lapisBlock_Id, Tile_SPU); + CREATE_TILE_TYPE(redBrick_Id, Tile_SPU); + CREATE_TILE_TYPE(mossStone_Id, Tile_SPU); + CREATE_TILE_TYPE(netherBrick_Id, Tile_SPU); + CREATE_TILE_TYPE(whiteStone_Id, Tile_SPU); + CREATE_TILE_TYPE(unbreakable_Id, Tile_SPU); + CREATE_TILE_TYPE(sponge_Id, Tile_SPU); + CREATE_TILE_TYPE(rock_Id, Tile_SPU); // StoneTile + CREATE_TILE_TYPE(obsidian_Id, Tile_SPU); // StoneTile->ObsidianTile + CREATE_TILE_TYPE(sand_Id, Tile_SPU); // HeavyTile + CREATE_TILE_TYPE(gravel_Id, Tile_SPU); // GravelTile + CREATE_TILE_TYPE(goldOre_Id, Tile_SPU); // OreTile + CREATE_TILE_TYPE(ironOre_Id, Tile_SPU); // OreTile + CREATE_TILE_TYPE(coalOre_Id, Tile_SPU); // OreTile + CREATE_TILE_TYPE(lapisOre_Id, Tile_SPU); // OreTile + CREATE_TILE_TYPE(diamondOre_Id, Tile_SPU); // OreTile + CREATE_TILE_TYPE(clay_Id, Tile_SPU); // ClayTile + CREATE_TILE_TYPE(redStoneOre_Id, Tile_SPU); // RedStoneOreTile + CREATE_TILE_TYPE(redStoneOre_lit_Id, Tile_SPU); // RedStoneOreTile + CREATE_TILE_TYPE(goldBlock_Id, Tile_SPU); // MetalTile + CREATE_TILE_TYPE(ironBlock_Id, Tile_SPU); // MetalTile + CREATE_TILE_TYPE(diamondBlock_Id, Tile_SPU); // MetalTile + CREATE_TILE_TYPE(snow_Id, Tile_SPU); // SnowTile + CREATE_TILE_TYPE(hellRock_Id, Tile_SPU); // HellStoneTile + CREATE_TILE_TYPE(hellSand_Id, Tile_SPU); // HellSandTile + CREATE_TILE_TYPE(lightGem_Id, Tile_SPU); // LightGemTile + CREATE_TILE_TYPE(aprilFoolsJoke_Id, Tile_SPU); // LockedChestTile - CREATE_TILE_TYPE(cocoa_Id, CocoaTile_SPU); + CREATE_TILE_TYPE(cloth_Id, ClothTile_SPU); // wool - CREATE_TILE_TYPE(redstoneLight_Id, RedlightTile_SPU); - CREATE_TILE_TYPE(redstoneLight_lit_Id, RedlightTile_SPU); - - CREATE_TILE_TYPE(skull_Id, SkullTile_SPU); - - // these tile types don't have any additional code that we need. - CREATE_TILE_TYPE(stoneBrick_Id, Tile_SPU); // Tile - CREATE_TILE_TYPE(lapisBlock_Id, Tile_SPU); - CREATE_TILE_TYPE(redBrick_Id, Tile_SPU); - CREATE_TILE_TYPE(mossStone_Id, Tile_SPU); - CREATE_TILE_TYPE(netherBrick_Id, Tile_SPU); - CREATE_TILE_TYPE(whiteStone_Id, Tile_SPU); - CREATE_TILE_TYPE(unbreakable_Id, Tile_SPU); - CREATE_TILE_TYPE(sponge_Id, Tile_SPU); - CREATE_TILE_TYPE(rock_Id, Tile_SPU); // StoneTile - CREATE_TILE_TYPE(obsidian_Id, Tile_SPU); // StoneTile->ObsidianTile - CREATE_TILE_TYPE(sand_Id, Tile_SPU); // HeavyTile - CREATE_TILE_TYPE(gravel_Id, Tile_SPU); // GravelTile - CREATE_TILE_TYPE(goldOre_Id, Tile_SPU); // OreTile - CREATE_TILE_TYPE(ironOre_Id, Tile_SPU); // OreTile - CREATE_TILE_TYPE(coalOre_Id, Tile_SPU); // OreTile - CREATE_TILE_TYPE(lapisOre_Id, Tile_SPU); // OreTile - CREATE_TILE_TYPE(diamondOre_Id, Tile_SPU); // OreTile - CREATE_TILE_TYPE(clay_Id, Tile_SPU); // ClayTile - CREATE_TILE_TYPE(redStoneOre_Id, Tile_SPU); // RedStoneOreTile - CREATE_TILE_TYPE(redStoneOre_lit_Id, Tile_SPU); // RedStoneOreTile - CREATE_TILE_TYPE(goldBlock_Id, Tile_SPU); // MetalTile - CREATE_TILE_TYPE(ironBlock_Id, Tile_SPU); // MetalTile - CREATE_TILE_TYPE(diamondBlock_Id, Tile_SPU); // MetalTile - CREATE_TILE_TYPE(snow_Id, Tile_SPU); // SnowTile - CREATE_TILE_TYPE(hellRock_Id, Tile_SPU); // HellStoneTile - CREATE_TILE_TYPE(hellSand_Id, Tile_SPU); // HellSandTile - CREATE_TILE_TYPE(lightGem_Id, Tile_SPU); // LightGemTile - CREATE_TILE_TYPE(aprilFoolsJoke_Id, Tile_SPU); // LockedChestTile - - CREATE_TILE_TYPE(cloth_Id, ClothTile_SPU); // wool - - - CREATE_TILE_TYPE(emeraldOre_Id, Tile_SPU); // OreTile - CREATE_TILE_TYPE(enderChest_Id, EnderChestTile_SPU); - CREATE_TILE_TYPE(tripWireSource_Id, TripWireSourceTile_SPU); - CREATE_TILE_TYPE(tripWire_Id, TripWireTile_SPU); -// - CREATE_TILE_TYPE(emeraldBlock_Id, Tile_SPU); // MetalTile - CREATE_TILE_TYPE(cobbleWall_Id, WallTile_SPU); - CREATE_TILE_TYPE(flowerPot_Id, FlowerPotTile_SPU); - CREATE_TILE_TYPE(carrots_Id, CarrotTile_SPU); - CREATE_TILE_TYPE(potatoes_Id, PotatoTile_SPU); - CREATE_TILE_TYPE(anvil_Id, AnvilTile_SPU); - CREATE_TILE_TYPE(netherQuartz_Id, Tile_SPU); // OreTile - CREATE_TILE_TYPE(quartzBlock_Id, QuartzBlockTile_SPU); - CREATE_TILE_TYPE(stairs_quartz_Id, StairTile_SPU); - CREATE_TILE_TYPE(woolCarpet_Id, WoolCarpetTile_SPU); - -}; \ No newline at end of file + CREATE_TILE_TYPE(emeraldOre_Id, Tile_SPU); // OreTile + CREATE_TILE_TYPE(enderChest_Id, EnderChestTile_SPU); + CREATE_TILE_TYPE(tripWireSource_Id, TripWireSourceTile_SPU); + CREATE_TILE_TYPE(tripWire_Id, TripWireTile_SPU); + // + CREATE_TILE_TYPE(emeraldBlock_Id, Tile_SPU); // MetalTile + CREATE_TILE_TYPE(cobbleWall_Id, WallTile_SPU); + CREATE_TILE_TYPE(flowerPot_Id, FlowerPotTile_SPU); + CREATE_TILE_TYPE(carrots_Id, CarrotTile_SPU); + CREATE_TILE_TYPE(potatoes_Id, PotatoTile_SPU); + CREATE_TILE_TYPE(anvil_Id, AnvilTile_SPU); + CREATE_TILE_TYPE(netherQuartz_Id, Tile_SPU); // OreTile + CREATE_TILE_TYPE(quartzBlock_Id, QuartzBlockTile_SPU); + CREATE_TILE_TYPE(stairs_quartz_Id, StairTile_SPU); + CREATE_TILE_TYPE(woolCarpet_Id, WoolCarpetTile_SPU); +}; diff --git a/Minecraft.Client/Player/LocalPlayer.cpp b/Minecraft.Client/Player/LocalPlayer.cpp index dbb47eaf1..f264a55af 100644 --- a/Minecraft.Client/Player/LocalPlayer.cpp +++ b/Minecraft.Client/Player/LocalPlayer.cpp @@ -1506,7 +1506,7 @@ bool LocalPlayer::handleMouseClick(int button) { bool usedItem = false; if (minecraft->gameMode->useItemOn( minecraft->localplayers[GetXboxPad()], level, item, x, y, z, - face, minecraft->hitResult->pos, false, &usedItem)) { + face, &minecraft->hitResult->pos, false, &usedItem)) { // Presume that if we actually used the held item, then we've // placed it if (usedItem) { diff --git a/Minecraft.Client/Rendering/Culling/DirtyChunkSorter.cpp b/Minecraft.Client/Rendering/Culling/DirtyChunkSorter.cpp index 9901135a6..ed12da6ef 100644 --- a/Minecraft.Client/Rendering/Culling/DirtyChunkSorter.cpp +++ b/Minecraft.Client/Rendering/Culling/DirtyChunkSorter.cpp @@ -23,4 +23,4 @@ bool DirtyChunkSorter::operator()(const Chunk* c0, const Chunk* c1) const { if (d0 > d1) return true; return c0->id >= c1->id; // 4J - was c0.id < c1.id ? 1 : -1 -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/EntityRenderers/LivingEntityRenderer.cpp b/Minecraft.Client/Rendering/EntityRenderers/LivingEntityRenderer.cpp index d2183890e..6be119c1b 100644 --- a/Minecraft.Client/Rendering/EntityRenderers/LivingEntityRenderer.cpp +++ b/Minecraft.Client/Rendering/EntityRenderers/LivingEntityRenderer.cpp @@ -613,4 +613,4 @@ void LivingEntityRenderer::renderNameTag(std::shared_ptr mob, glDisable(GL_BLEND); glColor4f(1, 1, 1, 1); glPopMatrix(); -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp b/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp index f1d7cd569..83f81f10a 100644 --- a/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp +++ b/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp @@ -54,10 +54,11 @@ void MinecartRenderer::render(std::shared_ptr _cart, double x, double y, y += (p0->y + p1->y) / 2 - yy; z += p->z - zz; - Vec3* dir = p1->add(-p0->x, -p0->y, -p0->z); + Vec3* dir = Vec3::newTemp(-p0->x, -p0->y, -p0->z); + *dir = dir->add(p1->x, p1->y, p1->z); if (dir->length() == 0) { } else { - dir = dir->normalize(); + *dir = dir->normalize(); rot = (float)(atan2(dir->z, dir->x) * 180 / PI); xRot = (float)(atan(dir->y) * 73); } @@ -146,4 +147,4 @@ void MinecartRenderer::renderMinecartContents(std::shared_ptr cart, glPushMatrix(); renderer->renderTile(tile, tileData, brightness); glPopMatrix(); -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index 9455cc252..0946c50b9 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -301,11 +301,12 @@ void GameRenderer::pick(float a) { } if (mc->hitResult != NULL) { - dist = mc->hitResult->pos->distanceTo(from); + dist = mc->hitResult->pos.distanceTo(*from); } Vec3* b = mc->cameraTargetPlayer->getViewVector(a); - Vec3* to = from->add(b->x * range, b->y * range, b->z * range); + Vec3* to = Vec3::newTemp(b->x * range, b->y * range, b->z * range); + *to = to->add(from->x, from->y, from->z); hovered = nullptr; float overlap = 1; std::vector >* objects = mc->level->getEntities( @@ -527,7 +528,7 @@ void GameRenderer::moveCameraToPlayer(float a) { Vec3::newTemp(x + xo, y + yo, z + zo), Vec3::newTemp(x - xd + xo, y - yd + yo, z - zd + zo)); if (hr != NULL) { - double dist = hr->pos->distanceTo(Vec3::newTemp(x, y, z)); + double dist = hr->pos.distanceTo(*Vec3::newTemp(x, y, z)); if (dist < cameraDist) cameraDist = dist; delete hr; } @@ -1867,7 +1868,7 @@ void GameRenderer::setupClearColor(float a) { Vec3* sunAngle = Mth::sin(level->getSunAngle(a)) > 0 ? Vec3::newTemp(-1, 0, 0) : Vec3::newTemp(1, 0, 0); - float d = (float)player->getViewVector(a)->dot(sunAngle); + float d = (float)player->getViewVector(a)->dot(*sunAngle); if (d < 0) d = 0; if (d > 0) { float* c = diff --git a/Minecraft.Client/Rendering/Lighting.cpp b/Minecraft.Client/Rendering/Lighting.cpp index c0eb8e562..73e700837 100644 --- a/Minecraft.Client/Rendering/Lighting.cpp +++ b/Minecraft.Client/Rendering/Lighting.cpp @@ -22,13 +22,15 @@ void Lighting::turnOn() { float d = 0.6f; float s = 0.0f; - Vec3* l = Vec3::newTemp(0.2f, 1.0f, -0.7f)->normalize(); + Vec3* l = Vec3::newTemp(0.2f, 1.0f, -0.7f); + *l = l->normalize(); glLight(GL_LIGHT0, GL_POSITION, getBuffer(l->x, l->y, l->z, 0)); glLight(GL_LIGHT0, GL_DIFFUSE, getBuffer(d, d, d, 1)); glLight(GL_LIGHT0, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f)); glLight(GL_LIGHT0, GL_SPECULAR, getBuffer(s, s, s, 1.0f)); - l = Vec3::newTemp(-0.2f, 1.0f, 0.7f)->normalize(); + l = Vec3::newTemp(-0.2f, 1.0f, 0.7f); + *l = l->normalize(); glLight(GL_LIGHT1, GL_POSITION, getBuffer(l->x, l->y, l->z, 0)); glLight(GL_LIGHT1, GL_DIFFUSE, getBuffer(d, d, d, 1)); glLight(GL_LIGHT1, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f)); @@ -55,4 +57,4 @@ void Lighting::turnOnGui() { glRotatef(165, 1, 0, 0); turnOn(); glPopMatrix(); -} \ No newline at end of file +} diff --git a/Minecraft.Client/Rendering/Polygon.cpp b/Minecraft.Client/Rendering/Polygon.cpp index 28c37260e..6e5dd3d5f 100644 --- a/Minecraft.Client/Rendering/Polygon.cpp +++ b/Minecraft.Client/Rendering/Polygon.cpp @@ -45,15 +45,15 @@ void _Polygon::mirror() { } void _Polygon::render(Tesselator* t, float scale) { - Vec3* v0 = vertices[1]->pos->vectorTo(vertices[0]->pos); - Vec3* v1 = vertices[1]->pos->vectorTo(vertices[2]->pos); - Vec3* n = v1->cross(v0)->normalize(); + Vec3 v0 = vertices[1]->pos->vectorTo(*vertices[0]->pos); + Vec3 v1 = vertices[1]->pos->vectorTo(*vertices[2]->pos); + Vec3 n = v1.cross(v0).normalize(); t->begin(); if (_flipNormal) { - t->normal(-(float)n->x, -(float)n->y, -(float)n->z); + t->normal(-(float)n.x, -(float)n.y, -(float)n.z); } else { - t->normal((float)n->x, (float)n->y, (float)n->z); + t->normal((float)n.x, (float)n.y, (float)n.z); } for (int i = 0; i < 4; i++) { @@ -67,4 +67,4 @@ void _Polygon::render(Tesselator* t, float scale) { _Polygon* _Polygon::flipNormal() { _flipNormal = true; return this; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp index 1e2d3cb1d..59a6e84f4 100644 --- a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp @@ -95,4 +95,4 @@ void AvoidPlayerGoal::tick() { mob->getNavigation()->setSpeedModifier(sprintSpeedModifier); else mob->getNavigation()->setSpeedModifier(walkSpeedModifier); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/BegGoal.cpp b/Minecraft.World/AI/Goals/BegGoal.cpp index de7992e6a..4c8c2bd28 100644 --- a/Minecraft.World/AI/Goals/BegGoal.cpp +++ b/Minecraft.World/AI/Goals/BegGoal.cpp @@ -54,4 +54,4 @@ bool BegGoal::playerHoldingInteresting(std::shared_ptr player) { if (item == NULL) return false; if (!wolf->isTame() && item->id == Item::bone_Id) return true; return wolf->isFood(item); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp b/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp index 928f7e8ef..a0ddb3ccb 100644 --- a/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp +++ b/Minecraft.World/AI/Goals/FollowOwnerGoal.cpp @@ -85,4 +85,4 @@ void FollowOwnerGoal::tick() { } } } -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/LeapAtTargetGoal.cpp b/Minecraft.World/AI/Goals/LeapAtTargetGoal.cpp index 9779984dd..fc59fda1f 100644 --- a/Minecraft.World/AI/Goals/LeapAtTargetGoal.cpp +++ b/Minecraft.World/AI/Goals/LeapAtTargetGoal.cpp @@ -34,4 +34,4 @@ void LeapAtTargetGoal::start() { mob->xd += (xdd / dd * 0.5f) * 0.8f + mob->xd * 0.2f; mob->zd += (zdd / dd * 0.5f) * 0.8f + mob->zd * 0.2f; mob->yd = yd; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp b/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp index 631362809..32cd4d1d6 100644 --- a/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/LookAtPlayerGoal.cpp @@ -62,4 +62,4 @@ void LookAtPlayerGoal::tick() { lookAt.lock()->x, lookAt.lock()->y + lookAt.lock()->getHeadHeight(), lookAt.lock()->z, 10, mob->getMaxHeadXRot()); --lookTime; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp b/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp index db570665d..01b7b6cba 100644 --- a/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp +++ b/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp @@ -68,4 +68,4 @@ void MoveIndoorsGoal::stop() { insideX = _doorInfo->getIndoorX(); insideZ = _doorInfo->getIndoorZ(); doorInfo = std::weak_ptr(); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp b/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp index d00147b38..a218b78f3 100644 --- a/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp +++ b/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp @@ -41,4 +41,4 @@ void MoveTowardsTargetGoal::stop() { target = std::weak_ptr(); } void MoveTowardsTargetGoal::start() { mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp b/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp index bdb2d72e2..a67f91cf9 100644 --- a/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp +++ b/Minecraft.World/AI/Goals/NearestAttackableTargetGoal.cpp @@ -74,4 +74,4 @@ bool NearestAttackableTargetGoal::canUse() { void NearestAttackableTargetGoal::start() { mob->setTarget(target.lock()); TargetGoal::start(); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp b/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp index 5f56a3712..d14d3bc9d 100644 --- a/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp +++ b/Minecraft.World/AI/Goals/OcelotAttackGoal.cpp @@ -57,4 +57,4 @@ void OcelotAttackGoal::tick() { if (attackTime > 0) return; attackTime = 20; mob->doHurtTarget(target.lock()); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/SitGoal.cpp b/Minecraft.World/AI/Goals/SitGoal.cpp index 6a7a3fa14..2ec85aff7 100644 --- a/Minecraft.World/AI/Goals/SitGoal.cpp +++ b/Minecraft.World/AI/Goals/SitGoal.cpp @@ -38,4 +38,4 @@ void SitGoal::start() { void SitGoal::stop() { mob->setSitting(false); } -void SitGoal::wantToSit(bool _wantToSit) { this->_wantToSit = _wantToSit; } \ No newline at end of file +void SitGoal::wantToSit(bool _wantToSit) { this->_wantToSit = _wantToSit; } diff --git a/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp b/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp index 455c84c8b..e7c5410c4 100644 --- a/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp +++ b/Minecraft.World/AI/Goals/TakeFlowerGoal.cpp @@ -72,4 +72,4 @@ void TakeFlowerGoal::tick() { villager->getNavigation()->stop(); } } -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/TargetGoal.cpp b/Minecraft.World/AI/Goals/TargetGoal.cpp index 4c424e03e..5d7751ee7 100644 --- a/Minecraft.World/AI/Goals/TargetGoal.cpp +++ b/Minecraft.World/AI/Goals/TargetGoal.cpp @@ -115,4 +115,4 @@ bool TargetGoal::canReach(std::shared_ptr target) { int zz = last->z - Mth::floor(target->z); delete path; return xx * xx + zz * zz <= 1.5 * 1.5; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/TemptGoal.cpp b/Minecraft.World/AI/Goals/TemptGoal.cpp index 82738d257..c0b06eb93 100644 --- a/Minecraft.World/AI/Goals/TemptGoal.cpp +++ b/Minecraft.World/AI/Goals/TemptGoal.cpp @@ -84,4 +84,4 @@ void TemptGoal::tick() { mob->getNavigation()->moveTo(player.lock(), speedModifier); } -bool TemptGoal::isRunning() { return _isRunning; } \ No newline at end of file +bool TemptGoal::isRunning() { return _isRunning; } diff --git a/Minecraft.World/AI/Goals/TradeWithPlayerGoal.cpp b/Minecraft.World/AI/Goals/TradeWithPlayerGoal.cpp index cfb14d6e0..61219b4d5 100644 --- a/Minecraft.World/AI/Goals/TradeWithPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/TradeWithPlayerGoal.cpp @@ -38,4 +38,4 @@ bool TradeWithPlayerGoal::canUse() { void TradeWithPlayerGoal::start() { mob->getNavigation()->stop(); } -void TradeWithPlayerGoal::stop() { mob->setTradingPlayer(nullptr); } \ No newline at end of file +void TradeWithPlayerGoal::stop() { mob->setTradingPlayer(nullptr); } diff --git a/Minecraft.World/AI/Navigation/PathFinder.cpp b/Minecraft.World/AI/Navigation/PathFinder.cpp index 0fe650e3b..20a730c4a 100644 --- a/Minecraft.World/AI/Navigation/PathFinder.cpp +++ b/Minecraft.World/AI/Navigation/PathFinder.cpp @@ -283,4 +283,4 @@ Path* PathFinder::reconstruct_path(Node* from, Node* to) { Path* ret = new Path(nodes); delete[] nodes.data; return ret; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Navigation/PathNavigation.cpp b/Minecraft.World/AI/Navigation/PathNavigation.cpp index a80e4d4ef..0160d92f0 100644 --- a/Minecraft.World/AI/Navigation/PathNavigation.cpp +++ b/Minecraft.World/AI/Navigation/PathNavigation.cpp @@ -151,7 +151,7 @@ void PathNavigation::updatePath() { float waypointRadiusSqr = mob->bbWidth * mob->bbWidth; for (int i = path->getIndex(); i < firstElevation; ++i) { Vec3* pathPos = path->getPos(mob->shared_from_this(), i); - if (mobPos->distanceToSqr(pathPos) < waypointRadiusSqr) { + if (mobPos->distanceToSqr(*pathPos) < waypointRadiusSqr) { path->setIndex(i + 1); } } @@ -170,7 +170,7 @@ void PathNavigation::updatePath() { // stuck detection (probably pushed off path) if (_tick - lastStuckCheck > 100) { - if (mobPos->distanceToSqr(lastStuckCheckPos) < 1.5 * 1.5) stop(); + if (mobPos->distanceToSqr(*lastStuckCheckPos) < 1.5 * 1.5) stop(); lastStuckCheck = _tick; lastStuckCheckPos->x = mobPos->x; lastStuckCheckPos->y = mobPos->y; @@ -329,4 +329,4 @@ bool PathNavigation::canWalkAbove(int startX, int startY, int startZ, int sx, return true; } -void PathNavigation::setLevel(Level* level) { this->level = level; } \ No newline at end of file +void PathNavigation::setLevel(Level* level) { this->level = level; } diff --git a/Minecraft.World/Blocks/LiquidTile.cpp b/Minecraft.World/Blocks/LiquidTile.cpp index e307e2125..348982c5f 100644 --- a/Minecraft.World/Blocks/LiquidTile.cpp +++ b/Minecraft.World/Blocks/LiquidTile.cpp @@ -135,14 +135,14 @@ Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) { t = getRenderedDepth(level, xt, yt - 1, zt); if (t >= 0) { int dir = t - (mid - 8); - flow = flow->add((xt - x) * dir, (yt - y) * dir, - (zt - z) * dir); + *flow = flow->add((xt - x) * dir, (yt - y) * dir, + (zt - z) * dir); } } } else { if (t >= 0) { int dir = t - mid; - flow = + *flow = flow->add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir); } } @@ -157,9 +157,9 @@ Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) { if (ok || isSolidFace(level, x, y + 1, z + 1, 3)) ok = true; if (ok || isSolidFace(level, x - 1, y + 1, z, 4)) ok = true; if (ok || isSolidFace(level, x + 1, y + 1, z, 5)) ok = true; - if (ok) flow = flow->normalize()->add(0, -6, 0); + if (ok) *flow = flow->normalize().add(0, -6, 0); } - flow = flow->normalize(); + *flow = flow->normalize(); return flow; } diff --git a/Minecraft.World/Blocks/StairTile.cpp b/Minecraft.World/Blocks/StairTile.cpp index f03aa9a08..2990ada14 100644 --- a/Minecraft.World/Blocks/StairTile.cpp +++ b/Minecraft.World/Blocks/StairTile.cpp @@ -443,7 +443,7 @@ HitResult* StairTile::clip(Level* level, int xt, int yt, int zt, Vec3* a, for (unsigned int i = 0; i < 8; ++i) { HitResult* result = results[i]; if (result != NULL) { - double dist = result->pos->distanceToSqr(b); + double dist = result->pos.distanceToSqr(*b); if (dist > closestDist) { closest = result; diff --git a/Minecraft.World/Blocks/Tile.cpp b/Minecraft.World/Blocks/Tile.cpp index 73dc4a523..67457536c 100644 --- a/Minecraft.World/Blocks/Tile.cpp +++ b/Minecraft.World/Blocks/Tile.cpp @@ -15,6 +15,7 @@ #include "../Headers/net.minecraft.world.food.h" #include "../Headers/net.minecraft.world.h" #include "../Headers/net.minecraft.h" +#include "Util/Vec3.h" #include "Tile.h" std::wstring Tile::TILE_DESCRIPTION_PREFIX = L"Tile."; @@ -2120,52 +2121,65 @@ float Tile::getExplosionResistance(std::shared_ptr source) { HitResult* Tile::clip(Level* level, int xt, int yt, int zt, Vec3* a, Vec3* b) { updateShape(level, xt, yt, zt); - a = a->add(-xt, -yt, -zt); - b = b->add(-xt, -yt, -zt); + *a = a->add(-xt, -yt, -zt); + *b = b->add(-xt, -yt, -zt); ThreadStorage* tls = m_tlsShape; - Vec3* xh0 = a->clipX(b, tls->xx0); - Vec3* xh1 = a->clipX(b, tls->xx1); + auto xh0 = a->clipX(*b, tls->xx0); + auto xh1 = a->clipX(*b, tls->xx1); - Vec3* yh0 = a->clipY(b, tls->yy0); - Vec3* yh1 = a->clipY(b, tls->yy1); + auto yh0 = a->clipY(*b, tls->yy0); + auto yh1 = a->clipY(*b, tls->yy1); - Vec3* zh0 = a->clipZ(b, tls->zz0); - Vec3* zh1 = a->clipZ(b, tls->zz1); + auto zh0 = a->clipZ(*b, tls->zz0); + auto zh1 = a->clipZ(*b, tls->zz1); - Vec3* closest = NULL; + Vec3* closest = nullptr; - if (containsX(xh0) && - (closest == NULL || a->distanceToSqr(xh0) < a->distanceToSqr(closest))) - closest = xh0; - if (containsX(xh1) && - (closest == NULL || a->distanceToSqr(xh1) < a->distanceToSqr(closest))) - closest = xh1; - if (containsY(yh0) && - (closest == NULL || a->distanceToSqr(yh0) < a->distanceToSqr(closest))) - closest = yh0; - if (containsY(yh1) && - (closest == NULL || a->distanceToSqr(yh1) < a->distanceToSqr(closest))) - closest = yh1; - if (containsZ(zh0) && - (closest == NULL || a->distanceToSqr(zh0) < a->distanceToSqr(closest))) - closest = zh0; - if (containsZ(zh1) && - (closest == NULL || a->distanceToSqr(zh1) < a->distanceToSqr(closest))) - closest = zh1; + if (xh0.has_value() and containsX(&*xh0) and + (closest == nullptr or + a->distanceToSqr(*xh0) < a->distanceToSqr(*closest))) + *closest = *xh0; + + if (xh1.has_value() and containsX(&*xh1) and + (closest == nullptr or + a->distanceToSqr(*xh1) < a->distanceToSqr(*closest))) + *closest = *xh1; + + if (yh0.has_value() and containsY(&*yh0) and + (closest == nullptr or + a->distanceToSqr(*yh0) < a->distanceToSqr(*closest))) + *closest = *yh0; + + if (yh1.has_value() and containsY(&*yh1) and + (closest == nullptr or + a->distanceToSqr(*yh1) < a->distanceToSqr(*closest))) + *closest = *yh1; + + if (zh0.has_value() and containsZ(&*zh0) and + (closest == nullptr or + a->distanceToSqr(*zh0) < a->distanceToSqr(*closest))) + *closest = *zh0; + + if (zh1.has_value() and containsZ(&*zh1) and + (closest == nullptr or + a->distanceToSqr(*zh1) < a->distanceToSqr(*closest))) + *closest = *zh1; if (closest == NULL) return NULL; int face = -1; - if (closest == xh0) face = Facing::WEST; - if (closest == xh1) face = Facing::EAST; - if (closest == yh0) face = Facing::DOWN; - if (closest == yh1) face = Facing::UP; - if (closest == zh0) face = Facing::NORTH; - if (closest == zh1) face = Facing::SOUTH; + if (*closest == xh0) face = Facing::WEST; + if (*closest == xh1) face = Facing::EAST; + if (*closest == yh0) face = Facing::DOWN; + if (*closest == yh1) face = Facing::UP; + if (*closest == zh0) face = Facing::NORTH; + if (*closest == zh1) face = Facing::SOUTH; - return new HitResult(xt, yt, zt, face, closest->add(xt, yt, zt)); + *closest = closest->add(xt, yt, zt); + + return new HitResult(xt, yt, zt, face, *closest); } bool Tile::containsX(Vec3* v) { diff --git a/Minecraft.World/Containers/HorseInventoryMenu.cpp b/Minecraft.World/Containers/HorseInventoryMenu.cpp index e4766aaef..a492bb442 100644 --- a/Minecraft.World/Containers/HorseInventoryMenu.cpp +++ b/Minecraft.World/Containers/HorseInventoryMenu.cpp @@ -113,4 +113,4 @@ void HorseInventoryMenu::removed(std::shared_ptr player) { std::shared_ptr HorseInventoryMenu::getContainer() { return horseContainer; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Entity.cpp b/Minecraft.World/Entities/Entity.cpp index 1c4170040..dc3ee4dd7 100644 --- a/Minecraft.World/Entities/Entity.cpp +++ b/Minecraft.World/Entities/Entity.cpp @@ -1874,4 +1874,4 @@ unsigned int Entity::getAnimOverrideBitmask() { } return m_uiAnimOverrideBitmask; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Entity.h b/Minecraft.World/Entities/Entity.h index ea827e28f..bc7d0a4dc 100644 --- a/Minecraft.World/Entities/Entity.h +++ b/Minecraft.World/Entities/Entity.h @@ -424,6 +424,7 @@ private: static int extraWanderTicks; static thread_local bool m_tlsUseSmallIds; + public: static void tickExtraWandering(); static void countFlagsForPIX(); diff --git a/Minecraft.World/Entities/LivingEntity.cpp b/Minecraft.World/Entities/LivingEntity.cpp index e795f18cf..571f69273 100644 --- a/Minecraft.World/Entities/LivingEntity.cpp +++ b/Minecraft.World/Entities/LivingEntity.cpp @@ -31,6 +31,7 @@ #include "../Util/ParticleTypes.h" #include "../Stats/GenericStats.h" #include "ItemEntity.h" +#include "Util/Vec3.h" const double LivingEntity::MIN_MOVEMENT_DISTANCE = 0.005; @@ -800,7 +801,7 @@ void LivingEntity::breakItem(std::shared_ptr itemInstance) { -random->nextFloat() * 0.6 - 0.3, 0.6); p->xRot(-xRot * PI / 180); p->yRot(-yRot * PI / 180); - p = p->add(x, y + getHeadHeight(), z); + *p = p->add(x, y + getHeadHeight(), z); level->addParticle(PARTICLE_ICONCRACK(itemInstance->getItem()->id, 0), p->x, p->y, p->z, d->x, d->y + 0.05, d->z); } @@ -1691,7 +1692,8 @@ Vec3* LivingEntity::getPos(float a) { HitResult* LivingEntity::pick(double range, float a) { Vec3* from = getPos(a); Vec3* b = getViewVector(a); - Vec3* to = from->add(b->x * range, b->y * range, b->z * range); + Vec3* to = Vec3::newTemp(b->x * range, b->y * range, b->z * range); + *to = to->add(from->x, from->y, from->z); return level->clip(from, to); } diff --git a/Minecraft.World/Entities/MinecartContainer.cpp b/Minecraft.World/Entities/MinecartContainer.cpp index 63364c434..ca25f81df 100644 --- a/Minecraft.World/Entities/MinecartContainer.cpp +++ b/Minecraft.World/Entities/MinecartContainer.cpp @@ -210,4 +210,4 @@ void MinecartContainer::applyNaturalSlowdown() { xd *= keep; yd *= 0; zd *= keep; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Arrow.cpp b/Minecraft.World/Entities/Mobs/Arrow.cpp index fc6562f26..1a5db2c82 100644 --- a/Minecraft.World/Entities/Mobs/Arrow.cpp +++ b/Minecraft.World/Entities/Mobs/Arrow.cpp @@ -224,7 +224,7 @@ void Arrow::tick() { from = Vec3::newTemp(x, y, z); to = Vec3::newTemp(x + xd, y + yd, z + zd); if (res != NULL) { - to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z); + to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z); } std::shared_ptr hitEntity = nullptr; std::vector >* objects = level->getEntities( @@ -359,9 +359,9 @@ void Arrow::tick() { zTile = res->z; lastTile = level->getTile(xTile, yTile, zTile); lastData = level->getData(xTile, yTile, zTile); - xd = (float)(res->pos->x - x); - yd = (float)(res->pos->y - y); - zd = (float)(res->pos->z - z); + xd = (float)(res->pos.x - x); + yd = (float)(res->pos.y - y); + zd = (float)(res->pos.z - z); float dd = (float)sqrt(xd * xd + yd * yd + zd * zd); // 4J added check - zero dd here was creating NaNs if (dd > 0.0001f) { diff --git a/Minecraft.World/Entities/Mobs/DragonFireball.cpp b/Minecraft.World/Entities/Mobs/DragonFireball.cpp index 29fa582d0..62f4a067c 100644 --- a/Minecraft.World/Entities/Mobs/DragonFireball.cpp +++ b/Minecraft.World/Entities/Mobs/DragonFireball.cpp @@ -67,4 +67,4 @@ ePARTICLE_TYPE DragonFireball::getTrailParticleType() { return eParticleType_dragonbreath; } -bool DragonFireball::shouldBurn() { return false; } \ No newline at end of file +bool DragonFireball::shouldBurn() { return false; } diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.cpp b/Minecraft.World/Entities/Mobs/EnderDragon.cpp index 582bda987..b2726950b 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.cpp +++ b/Minecraft.World/Entities/Mobs/EnderDragon.cpp @@ -314,7 +314,8 @@ void EnderDragon::aiStep() { // v->y, v->z, lSteps); unsigned int d = 0; for(unsigned int d = 1; // d < 3; ++d) { - Vec3* vN = v->normalize(); + Vec3* vN = Vec3::newTemp(v->x, v->y, v->z); + *vN = v->normalize(); vN->yRot(-PI / 4); for (unsigned int i = 0; i < 8; ++i) { if (getSynchedAction() == e_EnderdragonAction_Landing) { @@ -478,12 +479,14 @@ void EnderDragon::aiStep() { } else if (getSynchedAction() == e_EnderdragonAction_Sitting_Scanning) { if (attackTarget != NULL) { Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0, - (attackTarget->z - z)) - ->normalize(); + (attackTarget->z - z)); + *aim = aim->normalize(); + Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0, - -cos(yRot * PI / 180)) - ->normalize(); - float dot = (float)dir->dot(aim); + -cos(yRot * PI / 180)); + + *dir = dir->normalize(); + float dot = (float)dir->dot(*aim); float angleDegs = acos(dot) * 180 / PI; angleDegs = angleDegs + 0.5f; @@ -562,12 +565,13 @@ void EnderDragon::aiStep() { if (yRotD < -50) yRotD = -50; Vec3* aim = - Vec3::newTemp((xTarget - x), (yTarget - y), (zTarget - z)) - ->normalize(); + Vec3::newTemp((xTarget - x), (yTarget - y), (zTarget - z)); + *aim = aim->normalize(); + Vec3* dir = - Vec3::newTemp(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180)) - ->normalize(); - float dot = (float)(dir->dot(aim) + 0.5f) / 1.5f; + Vec3::newTemp(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180)); + *dir = dir->normalize(); + float dot = (float)(dir->dot(*aim) + 0.5f) / 1.5f; if (dot < 0) dot = 0; yRotA *= 0.80f; @@ -591,8 +595,9 @@ void EnderDragon::aiStep() { move(xd, yd, zd); } - Vec3* actual = Vec3::newTemp(xd, yd, zd)->normalize(); - float slide = (float)(actual->dot(dir) + 1) / 2.0f; + Vec3* actual = Vec3::newTemp(xd, yd, zd); + *actual = actual->normalize(); + float slide = (float)(actual->dot(*dir) + 1) / 2.0f; slide = 0.8f + 0.15f * slide; xd *= slide; @@ -734,12 +739,14 @@ void EnderDragon::aiStep() { if (this->canSee(attackTarget)) { m_fireballCharge++; Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0, - (attackTarget->z - z)) - ->normalize(); + (attackTarget->z - z)); + *aim = aim->normalize(); + Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0, - -cos(yRot * PI / 180)) - ->normalize(); - float dot = (float)dir->dot(aim); + -cos(yRot * PI / 180)); + *dir = dir->normalize(); + + float dot = (float)dir->dot(*aim); float angleDegs = acos(dot) * 180 / PI; angleDegs = angleDegs + 0.5f; @@ -979,8 +986,8 @@ void EnderDragon::findNewTarget() { int targetNodeIndex = 0; if (playerNearestToEgg != NULL) { Vec3* aim = Vec3::newTemp(playerNearestToEgg->x, 0, - playerNearestToEgg->z) - ->normalize(); + playerNearestToEgg->z); + *aim = aim->normalize(); // app.DebugPrintf("Final marker node near (%f,%d,%f)\n", // -aim->x*40,105,-aim->z*40 ); targetNodeIndex = diff --git a/Minecraft.World/Entities/Mobs/EnderMan.cpp b/Minecraft.World/Entities/Mobs/EnderMan.cpp index 986143ab9..3e2586874 100644 --- a/Minecraft.World/Entities/Mobs/EnderMan.cpp +++ b/Minecraft.World/Entities/Mobs/EnderMan.cpp @@ -114,14 +114,16 @@ bool EnderMan::isLookingAtMe(std::shared_ptr player) { std::shared_ptr helmet = player->inventory->armor[3]; if (helmet != NULL && helmet->id == Tile::pumpkin_Id) return false; - Vec3* look = player->getViewVector(1)->normalize(); + Vec3* look = player->getViewVector(1); + *look = look->normalize(); + Vec3* dir = Vec3::newTemp( x - player->x, (bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()), z - player->z); double dist = dir->length(); - dir = dir->normalize(); - double dot = look->dot(dir); + *dir = dir->normalize(); + double dot = look->dot(*dir); if (dot > 1 - 0.025 / dist) { return player->canSee(shared_from_this()); } @@ -251,7 +253,7 @@ bool EnderMan::teleport() { bool EnderMan::teleportTowards(std::shared_ptr e) { Vec3* dir = Vec3::newTemp( x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(), z - e->z); - dir = dir->normalize(); + *dir = dir->normalize(); double d = 16; double xx = x + (random->nextDouble() - 0.5) * 8 - dir->x * d; double yy = y + (random->nextInt(16) - 8) - dir->y * d; @@ -378,4 +380,4 @@ bool EnderMan::isCreepy() { return entityData->getByte(DATA_CREEPY) > 0; } void EnderMan::setCreepy(bool creepy) { entityData->set(DATA_CREEPY, (uint8_t)(creepy ? 1 : 0)); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp b/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp index 83aa925af..26418c28e 100644 --- a/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp +++ b/Minecraft.World/Entities/Mobs/ExperienceOrb.cpp @@ -265,4 +265,4 @@ bool ExperienceOrb::shouldRender(Vec3* c) { if (distance < 4) return false; return Entity::shouldRender(c); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Fireball.cpp b/Minecraft.World/Entities/Mobs/Fireball.cpp index 1bf7bf6df..c7e1a805d 100644 --- a/Minecraft.World/Entities/Mobs/Fireball.cpp +++ b/Minecraft.World/Entities/Mobs/Fireball.cpp @@ -173,7 +173,7 @@ void Fireball::tick() { from = Vec3::newTemp(x, y, z); to = Vec3::newTemp(x + xd, y + yd, z + zd); if (res != NULL) { - to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z); + *to = Vec3{res->pos.x, res->pos.y, res->pos.z}; } std::shared_ptr hitEntity = nullptr; std::vector >* objects = level->getEntities( @@ -326,4 +326,4 @@ int Fireball::getLightColor(float a) { return 15 << 20 | 15 << 4; } ePARTICLE_TYPE Fireball::getTrailParticleType() { return eParticleType_smoke; } -bool Fireball::shouldBurn() { return true; } \ No newline at end of file +bool Fireball::shouldBurn() { return true; } diff --git a/Minecraft.World/Entities/Mobs/FishingHook.cpp b/Minecraft.World/Entities/Mobs/FishingHook.cpp index f5bbb74d7..74351cc06 100644 --- a/Minecraft.World/Entities/Mobs/FishingHook.cpp +++ b/Minecraft.World/Entities/Mobs/FishingHook.cpp @@ -210,7 +210,7 @@ void FishingHook::tick() { from = Vec3::newTemp(x, y, z); to = Vec3::newTemp(x + xd, y + yd, z + zd); if (res != NULL) { - to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z); + to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z); } std::shared_ptr hitEntity = nullptr; std::vector >* objects = level->getEntities( @@ -412,4 +412,4 @@ int FishingHook::retrieve() { void FishingHook::remove() { Entity::remove(); if (owner != NULL) owner->fishing = nullptr; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Ghast.cpp b/Minecraft.World/Entities/Mobs/Ghast.cpp index c170a0f66..a44e29e60 100644 --- a/Minecraft.World/Entities/Mobs/Ghast.cpp +++ b/Minecraft.World/Entities/Mobs/Ghast.cpp @@ -217,4 +217,4 @@ void Ghast::readAdditionalSaveData(CompoundTag* tag) { FlyingMob::readAdditionalSaveData(tag); if (tag->contains(L"ExplosionPower")) explosionPower = tag->getInt(L"ExplosionPower"); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Minecart.cpp b/Minecraft.World/Entities/Mobs/Minecart.cpp index 4351c4ad8..182a7c5dd 100644 --- a/Minecraft.World/Entities/Mobs/Minecart.cpp +++ b/Minecraft.World/Entities/Mobs/Minecart.cpp @@ -129,10 +129,9 @@ bool Minecart::hurt(DamageSource* source, float hurtDamage) { if (dynamic_cast(source) != NULL) { std::shared_ptr attacker = source->getDirectEntity(); - if (attacker->instanceof - (eTYPE_PLAYER) && - !std::dynamic_pointer_cast(attacker) - ->isAllowedToHurtEntity(shared_from_this())) { + if (attacker->instanceof(eTYPE_PLAYER) && + !std::dynamic_pointer_cast(attacker)->isAllowedToHurtEntity( + shared_from_this())) { return false; } } @@ -149,9 +148,9 @@ bool Minecart::hurt(DamageSource* source, float hurtDamage) { if (rider.lock() != NULL && rider.lock() == source->getEntity()) hurtDamage += 1; - bool creativePlayer = - source->getEntity() != NULL && source->getEntity()->instanceof - (eTYPE_PLAYER) && std::dynamic_pointer_cast(source->getEntity()) + bool creativePlayer = source->getEntity() != NULL && + source->getEntity()->instanceof(eTYPE_PLAYER) && + std::dynamic_pointer_cast(source->getEntity()) ->abilities.instabuild; if (creativePlayer || getDamage() > 20 * 2) { @@ -310,8 +309,8 @@ void Minecart::tick() { AUTO_VAR(itEnd, entities->end()); for (AUTO_VAR(it, entities->begin()); it != itEnd; it++) { std::shared_ptr e = (*it); // entities->at(i); - if (e != rider.lock() && e->isPushable() && e->instanceof - (eTYPE_MINECART)) { + if (e != rider.lock() && e->isPushable() && + e->instanceof(eTYPE_MINECART)) { std::shared_ptr cart = std::dynamic_pointer_cast(e); cart->m_bHasPushedCartThisTick = false; @@ -405,7 +404,7 @@ void Minecart::moveAlongTrack(int xt, int yt, int zt, double maxSpeed, xd = pow * xD / dd; zd = pow * zD / dd; - if (rider.lock() != NULL && rider.lock()->instanceof (eTYPE_LIVINGENTITY)) { + if (rider.lock() != NULL && rider.lock()->instanceof(eTYPE_LIVINGENTITY)) { std::shared_ptr living = std::dynamic_pointer_cast(rider.lock()); @@ -689,10 +688,9 @@ void Minecart::push(std::shared_ptr e) { if (level->isClientSide) return; if (e == rider.lock()) return; - if (e->instanceof (eTYPE_LIVINGENTITY) && !e->instanceof - (eTYPE_PLAYER) && !e->instanceof - (eTYPE_VILLAGERGOLEM) && (getType() == TYPE_RIDEABLE) && - (xd * xd + zd * zd > 0.01)) { + if (e->instanceof(eTYPE_LIVINGENTITY) && !e->instanceof(eTYPE_PLAYER) && + !e->instanceof(eTYPE_VILLAGERGOLEM) && (getType() == TYPE_RIDEABLE) && + (xd * xd + zd * zd > 0.01)) { if ((rider.lock() == NULL) && (e->riding == NULL)) { e->ride(shared_from_this()); } @@ -718,7 +716,7 @@ void Minecart::push(std::shared_ptr e) { xa *= 0.5; za *= 0.5; - if (e->instanceof (eTYPE_MINECART)) { + if (e->instanceof(eTYPE_MINECART)) { double xo = e->x - x; double zo = e->z - z; @@ -726,12 +724,13 @@ void Minecart::push(std::shared_ptr e) { // other // Fix for #38882 - TU5: Gameplay: Minecart with furnace is not // able to move another minecart on the rail. - Vec3* dir = Vec3::newTemp(xo, 0, zo)->normalize(); + Vec3* dir = Vec3::newTemp(xo, 0, zo); + *dir = dir->normalize(); Vec3* facing = - Vec3::newTemp(cos(yRot * PI / 180), 0, sin(yRot * PI / 180)) - ->normalize(); + Vec3::newTemp(cos(yRot * PI / 180), 0, sin(yRot * PI / 180)); + *facing = facing->normalize(); - double dot = abs(dir->dot(facing)); + double dot = abs(dir->dot(*facing)); if (dot < 0.8f) { return; diff --git a/Minecraft.World/Entities/Mobs/Ocelot.cpp b/Minecraft.World/Entities/Mobs/Ocelot.cpp index f9a0e1bdc..b31798af2 100644 --- a/Minecraft.World/Entities/Mobs/Ocelot.cpp +++ b/Minecraft.World/Entities/Mobs/Ocelot.cpp @@ -305,4 +305,4 @@ void Ocelot::setSittingOnTile(bool val) { bool Ocelot::isSittingOnTile() { uint8_t current = entityData->getByte(DATA_FLAGS_ID); return (current & 0x02) > 0; -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Slime.cpp b/Minecraft.World/Entities/Mobs/Slime.cpp index a504db841..6db5e5c4b 100644 --- a/Minecraft.World/Entities/Mobs/Slime.cpp +++ b/Minecraft.World/Entities/Mobs/Slime.cpp @@ -248,4 +248,4 @@ int Slime::getMaxHeadXRot() { return 0; } bool Slime::doPlayJumpSound() { return getSize() > 0; } -bool Slime::doPlayLandSound() { return getSize() > 2; } \ No newline at end of file +bool Slime::doPlayLandSound() { return getSize() > 2; } diff --git a/Minecraft.World/Entities/Mobs/ThrownPotion.cpp b/Minecraft.World/Entities/Mobs/ThrownPotion.cpp index 3ed57fa98..7bfc9cf6a 100644 --- a/Minecraft.World/Entities/Mobs/ThrownPotion.cpp +++ b/Minecraft.World/Entities/Mobs/ThrownPotion.cpp @@ -151,4 +151,4 @@ void ThrownPotion::addAdditonalSaveData(CompoundTag* tag) { if (potionItem != NULL) tag->putCompound(L"Potion", potionItem->save(new CompoundTag())); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/Witch.cpp b/Minecraft.World/Entities/Mobs/Witch.cpp index 4099d1f95..50950d57f 100644 --- a/Minecraft.World/Entities/Mobs/Witch.cpp +++ b/Minecraft.World/Entities/Mobs/Witch.cpp @@ -212,4 +212,4 @@ void Witch::performRangedAttack(std::shared_ptr target, potion->shoot(xd, yd + dist * 0.2f, zd, 0.75f, 8); level->addEntity(potion); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Mobs/WitherBoss.cpp b/Minecraft.World/Entities/Mobs/WitherBoss.cpp index 2c6a0d849..092e810ea 100644 --- a/Minecraft.World/Entities/Mobs/WitherBoss.cpp +++ b/Minecraft.World/Entities/Mobs/WitherBoss.cpp @@ -506,4 +506,4 @@ bool WitherBoss::isPowered() { return getHealth() <= getMaxHealth() / 2; } MobType WitherBoss::getMobType() { return UNDEAD; } -void WitherBoss::ride(std::shared_ptr e) { riding = nullptr; } \ No newline at end of file +void WitherBoss::ride(std::shared_ptr e) { riding = nullptr; } diff --git a/Minecraft.World/Entities/PathfinderMob.cpp b/Minecraft.World/Entities/PathfinderMob.cpp index 8b30f6fb8..6abf6a2ac 100644 --- a/Minecraft.World/Entities/PathfinderMob.cpp +++ b/Minecraft.World/Entities/PathfinderMob.cpp @@ -328,4 +328,4 @@ void PathfinderMob::onLeashDistance(float distanceToLeashHolder) {} bool PathfinderMob::couldWander() { return (noActionTime < SharedConstants::TICKS_PER_SECOND * 5) || (isExtraWanderingEnabled()); -} \ No newline at end of file +} diff --git a/Minecraft.World/Entities/Throwable.cpp b/Minecraft.World/Entities/Throwable.cpp index 5e0165b8e..316b08313 100644 --- a/Minecraft.World/Entities/Throwable.cpp +++ b/Minecraft.World/Entities/Throwable.cpp @@ -142,7 +142,7 @@ void Throwable::tick() { from = Vec3::newTemp(x, y, z); to = Vec3::newTemp(x + xd, y + yd, z + zd); if (res != NULL) { - to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z); + to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z); } if (!level->isClientSide) { @@ -256,4 +256,4 @@ std::shared_ptr Throwable::getOwner() { owner = level->getPlayerByName(ownerName); } return owner; -} \ No newline at end of file +} diff --git a/Minecraft.World/Items/BoatItem.cpp b/Minecraft.World/Items/BoatItem.cpp index 90f9b7f32..b7ed93864 100644 --- a/Minecraft.World/Items/BoatItem.cpp +++ b/Minecraft.World/Items/BoatItem.cpp @@ -5,6 +5,7 @@ #include "../Headers/net.minecraft.world.level.tile.h" #include "../Headers/net.minecraft.world.phys.h" #include "ItemInstance.h" +#include "Util/Vec3.h" #include "BoatItem.h" BoatItem::BoatItem(int id) : Item(id) { maxStackSize = 1; } @@ -36,7 +37,8 @@ bool BoatItem::TestUse(std::shared_ptr itemInstance, Level* level, float za = yCos * xCos; double range = 5; - Vec3* to = from->add(xa * range, ya * range, za * range); + Vec3* to = Vec3::newTemp(xa * range, ya * range, za * range); + *to = to->add(from->x, from->y, from->z); HitResult* hr = level->clip(from, to, true); if (hr == NULL) return false; @@ -72,7 +74,8 @@ std::shared_ptr BoatItem::use( float za = yCos * xCos; double range = 5; - Vec3* to = from->add(xa * range, ya * range, za * range); + Vec3* to = Vec3::newTemp(xa * range, ya * range, za * range); + *to = to->add(from->x, from->y, from->z); HitResult* hr = level->clip(from, to, true); if (hr == NULL) return itemInstance; @@ -131,4 +134,4 @@ std::shared_ptr BoatItem::use( delete hr; return itemInstance; -} \ No newline at end of file +} diff --git a/Minecraft.World/Items/Item.cpp b/Minecraft.World/Items/Item.cpp index 401aa4e1e..85124b3fa 100644 --- a/Minecraft.World/Items/Item.cpp +++ b/Minecraft.World/Items/Item.cpp @@ -15,6 +15,7 @@ #include "Item.h" #include "HangingEntityItem.h" #include "../Util/HtmlString.h" +#include "Util/Vec3.h" typedef Item::Tier _Tier; @@ -1614,7 +1615,8 @@ HitResult* Item::getPlayerPOVHitResult(Level* level, float za = yCos * xCos; double range = 5; - Vec3* to = from->add(xa * range, ya * range, za * range); + Vec3* to = Vec3::newTemp(xa * range, ya * range, za * range); + *to = to->add(from->x, from->y, from->z); return level->clip(from, to, alsoPickLiquid, !alsoPickLiquid); } diff --git a/Minecraft.World/Level/ChunkPos.h b/Minecraft.World/Level/ChunkPos.h index 9a2eabca4..e38a551a5 100644 --- a/Minecraft.World/Level/ChunkPos.h +++ b/Minecraft.World/Level/ChunkPos.h @@ -44,4 +44,4 @@ struct ChunkPosKeyEq { bool operator()(const ChunkPos& x, const ChunkPos& y) const { return ChunkPos::eq_test(x, y); } -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Level/Level.cpp b/Minecraft.World/Level/Level.cpp index 4c8862d2d..8e72c6f05 100644 --- a/Minecraft.World/Level/Level.cpp +++ b/Minecraft.World/Level/Level.cpp @@ -2490,7 +2490,7 @@ bool Level::checkAndHandleWater(AABB* box, Material* material, } } if (current->length() > 0 && e->isPushedByWater()) { - current = current->normalize(); + *current = current->normalize(); double pow = 0.014; e->xd += current->x * pow; e->yd += current->y * pow; diff --git a/Minecraft.World/Level/RandomLevelSource.cpp b/Minecraft.World/Level/RandomLevelSource.cpp index 62c72926a..6db10eaea 100644 --- a/Minecraft.World/Level/RandomLevelSource.cpp +++ b/Minecraft.World/Level/RandomLevelSource.cpp @@ -121,9 +121,9 @@ int RandomLevelSource::getMinDistanceToEdge(int xxx, int zzz, int worldSize, (xxx > (max - falloffStart) && xxx < (max + falloffStart))) { Vec3* point = Vec3::newTemp(xxx, 0, zzz); if (xxx > 0) - dist = point->distanceFromLine(topRight, bottomRight); + dist = point->distanceFromLine(*topRight, *bottomRight); else - dist = point->distanceFromLine(topLeft, bottomLeft); + dist = point->distanceFromLine(*topLeft, *bottomLeft); closest = dist; } @@ -132,9 +132,9 @@ int RandomLevelSource::getMinDistanceToEdge(int xxx, int zzz, int worldSize, (zzz > (max - falloffStart) && zzz < (max + falloffStart))) { Vec3* point = Vec3::newTemp(xxx, 0, zzz); if (zzz > 0) - dist = point->distanceFromLine(bottomLeft, bottomRight); + dist = point->distanceFromLine(*bottomLeft, *bottomRight); else - dist = point->distanceFromLine(topLeft, topRight); + dist = point->distanceFromLine(*topLeft, *topRight); if (dist < closest) closest = dist; } diff --git a/Minecraft.World/Player/Player.cpp b/Minecraft.World/Player/Player.cpp index f7b8e9b85..7253d1633 100644 --- a/Minecraft.World/Player/Player.cpp +++ b/Minecraft.World/Player/Player.cpp @@ -435,7 +435,7 @@ void Player::tick() { // minecart. For some reason some of the torches come off so it will also need some fixing along the way. static bool madeTrack = false; if( !madeTrack ) - { + { this->drop( std::shared_ptr( new ItemInstance( Item::minecart, 1 ) ) ); this->drop( std::shared_ptr( new ItemInstance( Tile::goldenRail, 10 ) ) ); this->drop( std::shared_ptr( new ItemInstance( Tile::lever, 10 ) ) ); @@ -537,7 +537,7 @@ void Player::spawnEatParticles(std::shared_ptr useItem, -random->nextFloat() * 0.6 - 0.3, 0.6); p->xRot(-xRot * PI / 180); p->yRot(-yRot * PI / 180); - p = p->add(x, y + getHeadHeight(), z); + *p = p->add(x, y + getHeadHeight(), z); level->addParticle(PARTICLE_ICONCRACK(useItem->getItem()->id, 0), p->x, p->y, p->z, d->x, d->y + 0.05, d->z); diff --git a/Minecraft.World/Util/AABB.cpp b/Minecraft.World/Util/AABB.cpp index c4a8bff2e..b5f98c1a9 100644 --- a/Minecraft.World/Util/AABB.cpp +++ b/Minecraft.World/Util/AABB.cpp @@ -5,7 +5,9 @@ #include "../Platform/stdafx.h" #include "AABB.h" +#include #include "HitResult.h" +#include "Util/Vec3.h" unsigned int AABB::tlsIdx = 0; AABB::ThreadStorage* AABB::tlsDefault = NULL; @@ -238,55 +240,62 @@ AABB* AABB::shrink(double xa, double ya, double za) { AABB* AABB::copy() { return AABB::newTemp(x0, y0, z0, x1, y1, z1); } HitResult* AABB::clip(Vec3* a, Vec3* b) { - Vec3* xh0 = a->clipX(b, x0); - Vec3* xh1 = a->clipX(b, x1); + auto xh0 = a->clipX(*b, x0); + auto xh1 = a->clipX(*b, x1); - Vec3* yh0 = a->clipY(b, y0); - Vec3* yh1 = a->clipY(b, y1); + auto yh0 = a->clipY(*b, y0); + auto yh1 = a->clipY(*b, y1); - Vec3* zh0 = a->clipZ(b, z0); - Vec3* zh1 = a->clipZ(b, z1); + auto zh0 = a->clipZ(*b, z0); + auto zh1 = a->clipZ(*b, z1); - if (!containsX(xh0)) xh0 = NULL; - if (!containsX(xh1)) xh1 = NULL; - if (!containsY(yh0)) yh0 = NULL; - if (!containsY(yh1)) yh1 = NULL; - if (!containsZ(zh0)) zh0 = NULL; - if (!containsZ(zh1)) zh1 = NULL; + if (!(xh0.has_value() and containsX(&*xh0))) xh0 = std::nullopt; + if (!(xh1.has_value() and containsX(&*xh1))) xh1 = std::nullopt; + if (!(yh0.has_value() and containsY(&*yh0))) yh0 = std::nullopt; + if (!(yh1.has_value() and containsY(&*yh1))) yh1 = std::nullopt; + if (!(zh0.has_value() and containsZ(&*zh0))) zh0 = std::nullopt; + if (!(zh1.has_value() and containsZ(&*zh1))) zh1 = std::nullopt; + Vec3* closest = nullptr; - Vec3* closest = NULL; + if (xh0.has_value() and + (closest == nullptr or + a->distanceToSqr(*xh0) < a->distanceToSqr(*closest))) + *closest = *xh0; + if (xh1.has_value() and + (closest == nullptr or + a->distanceToSqr(*xh1) < a->distanceToSqr(*closest))) + *closest = *xh1; + if (yh0.has_value() and + (closest == nullptr or + a->distanceToSqr(*yh0) < a->distanceToSqr(*closest))) + *closest = *yh0; + if (yh1.has_value() and + (closest == nullptr or + a->distanceToSqr(*yh1) < a->distanceToSqr(*closest))) + *closest = *yh1; + if (zh0.has_value() and + (closest == nullptr or + a->distanceToSqr(*zh0) < a->distanceToSqr(*closest))) + *closest = *zh0; + if (zh1.has_value() and + (closest == nullptr or + a->distanceToSqr(*zh1) < a->distanceToSqr(*closest))) + *closest = *zh1; - if (xh0 != NULL && - (closest == NULL || a->distanceToSqr(xh0) < a->distanceToSqr(closest))) - closest = xh0; - if (xh1 != NULL && - (closest == NULL || a->distanceToSqr(xh1) < a->distanceToSqr(closest))) - closest = xh1; - if (yh0 != NULL && - (closest == NULL || a->distanceToSqr(yh0) < a->distanceToSqr(closest))) - closest = yh0; - if (yh1 != NULL && - (closest == NULL || a->distanceToSqr(yh1) < a->distanceToSqr(closest))) - closest = yh1; - if (zh0 != NULL && - (closest == NULL || a->distanceToSqr(zh0) < a->distanceToSqr(closest))) - closest = zh0; - if (zh1 != NULL && - (closest == NULL || a->distanceToSqr(zh1) < a->distanceToSqr(closest))) - closest = zh1; - - if (closest == NULL) return NULL; + if (closest == nullptr) return nullptr; int face = -1; - if (closest == xh0) face = 4; - if (closest == xh1) face = 5; - if (closest == yh0) face = 0; - if (closest == yh1) face = 1; - if (closest == zh0) face = 2; - if (closest == zh1) face = 3; + if (*closest == xh0) face = 4; + if (*closest == xh1) face = 5; + if (*closest == yh0) face = 0; + if (*closest == yh1) face = 1; + if (*closest == zh0) face = 2; + if (*closest == zh1) face = 3; - return new HitResult(0, 0, 0, face, closest); + closest = Vec3::newTemp(closest->x, closest->y, closest->z); + + return new HitResult(0, 0, 0, face, *closest); } bool AABB::containsX(Vec3* v) { diff --git a/Minecraft.World/Util/HitResult.cpp b/Minecraft.World/Util/HitResult.cpp index dfa52bf72..e6f49dbac 100644 --- a/Minecraft.World/Util/HitResult.cpp +++ b/Minecraft.World/Util/HitResult.cpp @@ -3,13 +3,13 @@ #include "../Headers/net.minecraft.world.entity.h" #include "HitResult.h" -HitResult::HitResult(int x, int y, int z, int f, Vec3* pos) { +HitResult::HitResult(int x, int y, int z, int f, const Vec3& pos) { type = TILE; this->x = x; this->y = y; this->z = z; this->f = f; - this->pos = Vec3::newTemp(pos->x, pos->y, pos->z); + this->pos = pos; this->entity = nullptr; } @@ -17,14 +17,14 @@ HitResult::HitResult(int x, int y, int z, int f, Vec3* pos) { HitResult::HitResult(std::shared_ptr entity) { type = ENTITY; this->entity = entity; - pos = Vec3::newTemp(entity->x, entity->y, entity->z); + pos = {entity->x, entity->y, entity->z}; x = y = z = f = 0; } double HitResult::distanceTo(std::shared_ptr e) { - double xd = pos->x - e->x; - double yd = pos->y - e->y; - double zd = pos->z - e->z; + double xd = pos.x - e->x; + double yd = pos.y - e->y; + double zd = pos.z - e->z; return xd * xd + yd * yd + zd * zd; -} \ No newline at end of file +} diff --git a/Minecraft.World/Util/HitResult.h b/Minecraft.World/Util/HitResult.h index ee4121d52..83934fc6f 100644 --- a/Minecraft.World/Util/HitResult.h +++ b/Minecraft.World/Util/HitResult.h @@ -7,12 +7,12 @@ public: Type type; int x, y, z, f; - Vec3* pos; + Vec3 pos; std::shared_ptr entity; - HitResult(int x, int y, int z, int f, Vec3* pos); + HitResult(int x, int y, int z, int f, const Vec3& pos); HitResult(std::shared_ptr entity); double distanceTo(std::shared_ptr e); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Util/Vec3.cpp b/Minecraft.World/Util/Vec3.cpp index 4e42b99a3..0262d2e17 100644 --- a/Minecraft.World/Util/Vec3.cpp +++ b/Minecraft.World/Util/Vec3.cpp @@ -1,5 +1,7 @@ #include "../Platform/stdafx.h" #include "Vec3.h" +#include +#include #include "AABB.h" unsigned int Vec3::tlsIdx = 0; @@ -62,108 +64,99 @@ Vec3* Vec3::set(double x, double y, double z) { return this; } -Vec3* Vec3::interpolateTo(Vec3* t, double p) { - double xt = x + (t->x - x) * p; - double yt = y + (t->y - y) * p; - double zt = z + (t->z - z) * p; +Vec3 Vec3::vectorTo(const Vec3& p) const { return {p.x - x, p.y - y, p.z - z}; } - return Vec3::newTemp(xt, yt, zt); +Vec3 Vec3::normalize() const { + double dist = std::sqrt(x * x + y * y + z * z); + if (dist < 0.0001) return {0, 0, 0}; + + return {x / dist, y / dist, z / dist}; } -Vec3* Vec3::vectorTo(Vec3* p) { - return Vec3::newTemp(p->x - x, p->y - y, p->z - z); +double Vec3::dot(const Vec3& p) const { return x * p.x + y * p.y + z * p.z; } + +Vec3 Vec3::cross(const Vec3& p) const { + return {y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x}; } -Vec3* Vec3::normalize() { - double dist = (double)(sqrt(x * x + y * y + z * z)); - if (dist < 0.0001) return Vec3::newTemp(0, 0, 0); - return Vec3::newTemp(x / dist, y / dist, z / dist); +Vec3 Vec3::add(double x, double y, double z) const { + return {this->x + x, this->y + y, this->z + z}; } -double Vec3::dot(Vec3* p) { return x * p->x + y * p->y + z * p->z; } - -Vec3* Vec3::cross(Vec3* p) { - return Vec3::newTemp(y * p->z - z * p->y, z * p->x - x * p->z, - x * p->y - y * p->x); +double Vec3::distanceTo(const Vec3& p) const { + double xd = p.x - x; + double yd = p.y - y; + double zd = p.z - z; + return std::sqrt(xd * xd + yd * yd + zd * zd); } -Vec3* Vec3::add(double x, double y, double z) { - return Vec3::newTemp(this->x + x, this->y + y, this->z + z); -} - -double Vec3::distanceTo(Vec3* p) { - double xd = p->x - x; - double yd = p->y - y; - double zd = p->z - z; - return (double)sqrt(xd * xd + yd * yd + zd * zd); -} - -double Vec3::distanceToSqr(Vec3* p) { - double xd = p->x - x; - double yd = p->y - y; - double zd = p->z - z; +double Vec3::distanceToSqr(const Vec3& p) { + double xd = p.x - x; + double yd = p.y - y; + double zd = p.z - z; return xd * xd + yd * yd + zd * zd; } -double Vec3::distanceToSqr(double x2, double y2, double z2) { +double Vec3::distanceToSqr(const double x2, const double y2, + const double z2) const { double xd = x2 - x; double yd = y2 - y; double zd = z2 - z; return xd * xd + yd * yd + zd * zd; } -Vec3* Vec3::scale(double l) { return Vec3::newTemp(x * l, y * l, z * l); } +Vec3 Vec3::scale(const double l) const { return {x * l, y * l, z * l}; } -double Vec3::length() { return sqrt(x * x + y * y + z * z); } +double Vec3::length() const { return sqrt(x * x + y * y + z * z); } -Vec3* Vec3::clipX(Vec3* b, double xt) { - double xd = b->x - x; - double yd = b->y - y; - double zd = b->z - z; +std::optional Vec3::clipX(const Vec3& b, const double xt) const { + double xd = b.x - x; + double yd = b.y - y; + double zd = b.z - z; - if (xd * xd < 0.0000001f) return NULL; + if (xd * xd < 0.0000001f) return std::nullopt; double d = (xt - x) / xd; - if (d < 0 || d > 1) return NULL; - return Vec3::newTemp(x + xd * d, y + yd * d, z + zd * d); + if (d < 0 || d > 1) return std::nullopt; + + return Vec3{x + xd * d, y + yd * d, z + zd * d}; } -Vec3* Vec3::clipY(Vec3* b, double yt) { - double xd = b->x - x; - double yd = b->y - y; - double zd = b->z - z; +std::optional Vec3::clipY(const Vec3& b, const double yt) const { + double xd = b.x - x; + double yd = b.y - y; + double zd = b.z - z; - if (yd * yd < 0.0000001f) return NULL; + if (yd * yd < 0.0000001f) return std::nullopt; double d = (yt - y) / yd; - if (d < 0 || d > 1) return NULL; - return Vec3::newTemp(x + xd * d, y + yd * d, z + zd * d); + if (d < 0 || d > 1) return std::nullopt; + + return Vec3{x + xd * d, y + yd * d, z + zd * d}; } -Vec3* Vec3::clipZ(Vec3* b, double zt) { - double xd = b->x - x; - double yd = b->y - y; - double zd = b->z - z; +std::optional Vec3::clipZ(const Vec3& b, const double zt) const { + double xd = b.x - x; + double yd = b.y - y; + double zd = b.z - z; - if (zd * zd < 0.0000001f) return NULL; + if (zd * zd < 0.0000001f) return std::nullopt; double d = (zt - z) / zd; - if (d < 0 || d > 1) return NULL; - return Vec3::newTemp(x + xd * d, y + yd * d, z + zd * d); + if (d < 0 || d > 1) return std::nullopt; + + return Vec3{x + xd * d, y + yd * d, z + zd * d}; } -std::wstring Vec3::toString() { - static wchar_t buf[128]; - swprintf(buf, 128, L"(%f,%f,%f)", x, y, z); - return std::wstring(buf); +std::wstring Vec3::toString() const { + return std::format(L"({},{},{})", x, y, z); } -Vec3* Vec3::lerp(Vec3* v, double a) { - return Vec3::newTemp(x + (v->x - x) * a, y + (v->y - y) * a, - z + (v->z - z) * a); +Vec3 Vec3::lerp(const Vec3& v, const double a) const { + return {x + (v.x - x) * a, y + (v.y - y) * a, z + (v.z - z) * a}; } -void Vec3::xRot(float degs) { +void Vec3::xRot(const float degs) { double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless // wasting precision here double _sin = sin(degs); @@ -177,7 +170,7 @@ void Vec3::xRot(float degs) { z = zz; } -void Vec3::yRot(float degs) { +void Vec3::yRot(const float degs) { double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless // wasting precision here double _sin = sin(degs); @@ -191,7 +184,7 @@ void Vec3::yRot(float degs) { z = zz; } -void Vec3::zRot(float degs) { +void Vec3::zRot(const float degs) { double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless // wasting precision here double _sin = sin(degs); @@ -230,23 +223,24 @@ double Vec3::distanceTo(AABB* box) { return sqrt(xd * xd + yd * yd + zd * zd); } -Vec3* Vec3::closestPointOnLine(Vec3* p1, Vec3* p2) { - Vec3* diff = newTemp(x - p1->x, y - p1->y, z - p1->z); - Vec3* dir = newTemp(p2->x - p1->x, p2->y - p1->y, p2->z - p1->z); - float dot1 = diff->dot(dir); +Vec3 Vec3::closestPointOnLine(const Vec3& p1, const Vec3& p2) const { + Vec3 diff = {x - p1.x, y - p1.y, z - p1.z}; + Vec3 dir = {p2.x - p1.x, p2.y - p1.y, p2.z - p1.z}; + float dot1 = diff.dot(dir); + if (dot1 <= 0.0f) return p1; - float dot2 = dir->dot(dir); + float dot2 = dir.dot(dir); if (dot2 <= dot1) return p2; float t = dot1 / dot2; - return newTemp(p1->x + t * dir->x, p1->y + t * dir->y, p1->z + t * dir->z); + + return {p1.x + t * dir.x, p1.y + t * dir.y, p1.z + t * dir.z}; } -double Vec3::distanceFromLine(Vec3* p1, Vec3* p2) { - Vec3* closestPoint = closestPointOnLine(p1, p2); - Vec3* diff = - newTemp(x - closestPoint->x, y - closestPoint->y, z - closestPoint->z); - return diff->length(); +double Vec3::distanceFromLine(const Vec3& p1, const Vec3& p2) const { + Vec3 closestPoint = closestPointOnLine(p1, p2); + Vec3 diff{x - closestPoint.x, y - closestPoint.y, z - closestPoint.z}; + return diff.length(); } diff --git a/Minecraft.World/Util/Vec3.h b/Minecraft.World/Util/Vec3.h index bc1239d81..9b424305a 100644 --- a/Minecraft.World/Util/Vec3.h +++ b/Minecraft.World/Util/Vec3.h @@ -1,5 +1,6 @@ #pragma once +#include class AABB; class Vec3 { @@ -29,28 +30,28 @@ public: static Vec3* newTemp(double x, double y, double z); double x, y, z; -private: Vec3() {} Vec3(double x, double y, double z); + +private: Vec3* set(double x, double y, double z); public: - Vec3* interpolateTo(Vec3* t, double p); - Vec3* vectorTo(Vec3* p); - Vec3* normalize(); - double dot(Vec3* p); - Vec3* cross(Vec3* p); - Vec3* add(double x, double y, double z); - double distanceTo(Vec3* p); - double distanceToSqr(Vec3* p); - double distanceToSqr(double x2, double y2, double z2); - Vec3* scale(double l); - double length(); - Vec3* clipX(Vec3* b, double xt); - Vec3* clipY(Vec3* b, double yt); - Vec3* clipZ(Vec3* b, double zt); - std::wstring toString(); - Vec3* lerp(Vec3* v, double a); + Vec3 vectorTo(const Vec3& p) const; + Vec3 normalize() const; + double dot(const Vec3& p) const; + Vec3 cross(const Vec3& p) const; + Vec3 add(double x, double y, double z) const; + double distanceTo(const Vec3& p) const; + double distanceToSqr(const Vec3& p); + double distanceToSqr(double x2, double y2, double z2) const; + Vec3 scale(double l) const; + double length() const; + std::optional clipX(const Vec3& b, double xt) const; + std::optional clipY(const Vec3& b, double yt) const; + std::optional clipZ(const Vec3& b, double zt) const; + std::wstring toString() const; + Vec3 lerp(const Vec3& v, double a) const; void xRot(float degs); void yRot(float degs); void zRot(float degs); @@ -58,6 +59,10 @@ public: // 4J Added double distanceTo(AABB* box); - Vec3* closestPointOnLine(Vec3* p1, Vec3* p2); - double distanceFromLine(Vec3* p1, Vec3* p2); -}; \ No newline at end of file + Vec3 closestPointOnLine(const Vec3& p1, const Vec3& p2) const; + double distanceFromLine(const Vec3& p1, const Vec3& p2) const; + + constexpr bool operator==(const Vec3& rhs) const { + return x == rhs.x and y == rhs.y and z == rhs.z; + } +};