Skip to content

Commit

Permalink
refactor: move headers
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed May 27, 2024
1 parent bf38fb7 commit d7f614d
Show file tree
Hide file tree
Showing 96 changed files with 204 additions and 186 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <optional>

#include "bedrock/bedrock_log.h"
#include "bedrock/core/bedrock_log.h"

namespace Bedrock {

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <system_error>

#include "bedrock/bedrock.h"
#include "bedrock/callstack.h"
#include "bedrock/core/callstack.h"

namespace Bedrock {
template <typename E = std::error_code>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@

#pragma once

#include <cstdint>
#include <string>

class IDataOutput {
namespace mce {
class Color {
public:
virtual ~IDataOutput() = default;
virtual void writeString(std::string_view v) = 0;
virtual void writeLongString(std::string_view v) = 0;
virtual void writeFloat(float v) = 0;
virtual void writeDouble(double v) = 0;
virtual void writeByte(std::uint8_t v) = 0;
virtual void writeShort(std::int16_t v) = 0;
virtual void writeInt(std::int32_t v) = 0;
virtual void writeLongLong(std::int64_t v) = 0;
virtual void writeBytes(void const *data, std::uint64_t bytes) = 0;
float r;
float g;
float b;
float a;
};

} // namespace mce
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions include/bedrock/core/memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <memory>

template <typename T>
class OwnerPtr;

template <typename T>
class WeakRef {
public:
T &operator*() const
{
if (auto lock = ref_.lock()) {
return *lock;
}
throw std::bad_weak_ptr();
}

T *operator->() const noexcept
{
return ref_.lock().get();
}

private:
std::weak_ptr<T> ref_;
};

template <typename T>
class WeakPtr {
void *rep_; // reference counter block
};
2 changes: 1 addition & 1 deletion include/bedrock/result.h → include/bedrock/core/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <nonstd/expected.hpp>

#include "bedrock/bedrock.h"
#include "bedrock/error_info.h"
#include "bedrock/core/error_info.h"

namespace Bedrock {

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <cstdint>
#include <string>

#include "bedrock/result.h"
#include "bedrock/core/result.h"

class IDataInput {
public:
Expand All @@ -33,3 +33,17 @@ class IDataInput {
virtual Bedrock::Result<void> readBytesResult(void *, std::uint64_t) = 0;
[[nodiscard]] virtual std::uint64_t numBytesLeft() const = 0;
};

class IDataOutput {
public:
virtual ~IDataOutput() = default;
virtual void writeString(std::string_view v) = 0;
virtual void writeLongString(std::string_view v) = 0;
virtual void writeFloat(float v) = 0;
virtual void writeDouble(double v) = 0;
virtual void writeByte(std::uint8_t v) = 0;
virtual void writeShort(std::int16_t v) = 0;
virtual void writeInt(std::int32_t v) = 0;
virtual void writeLongLong(std::int64_t v) = 0;
virtual void writeBytes(void const *data, std::uint64_t bytes) = 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@

#include <memory>

template <typename T>
class OwnerPtr;

template <typename T>
class WeakRef {
public:
T &operator*() const
{
if (auto lock = ref_.lock()) {
return *lock;
}
throw std::bad_weak_ptr();
}

T *operator->() const noexcept
{
return ref_.lock().get();
}

private:
std::weak_ptr<T> ref_;
};

namespace Bedrock {

template <class T>
Expand Down Expand Up @@ -82,11 +59,6 @@ class EnableNonOwnerReferences {

} // namespace Bedrock

template <typename T>
class WeakPtr {
void *rep_; // reference counter block
};

namespace std {
template <class T1, class T2>
[[nodiscard]] Bedrock::NonOwnerPointer<T1> static_pointer_cast(const Bedrock::NonOwnerPointer<T2> &other) noexcept
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 0 additions & 8 deletions include/bedrock/mce.h → include/bedrock/core/utility/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,4 @@ class UUID {
};
BEDROCK_STATIC_ASSERT_SIZE(UUID, 16, 16);

class Color {
public:
float r;
float g;
float b;
float a;
};

} // namespace mce
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#pragma once

#include "bedrock/bedrock.h"
#include "bedrock/world/math/aabb.h"
#include "bedrock/world/math/vec2.h"
#include "bedrock/world/math/vec3.h"
#include "bedrock/core/math/vec2.h"
#include "bedrock/core/math/vec3.h"
#include "bedrock/world/phys/aabb.h"

struct StateVectorComponent {
Vec3 position; // +0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#pragma once

#include "bedrock/entity/strict_entity_context.h"
#include "bedrock/world/actor/actor_unique_id.h"
#include "bedrock/world/actor/registry/strict_entity_context.h"

struct PassengerComponent : public StrictEntityContext {
ActorUniqueID vehicle_id; // +8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

#pragma once

#include "bedrock/world/actor/components/vec3_component.h"
#include "bedrock/entity/components/vec3_component.h"

struct PostTickPositionDeltaComponent : public Vec3Component {};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <entt/entt.hpp>

#include "bedrock/certificates/certificate.h"
#include "bedrock/mce.h"
#include "bedrock/core/utility/uuid.h"
#include "bedrock/network/network_identifier.h"
#include "bedrock/network/sub_client_id.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include "bedrock/world/math/vec3.h"
#include "bedrock/core/math/vec3.h"

struct Vec3Component {
Vec3 value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <entt/entt.hpp>

#include "bedrock/bedrock.h"
#include "bedrock/memory.h"
#include "bedrock/world/actor/registry/entity_registry.h"
#include "bedrock/core/memory.h"
#include "bedrock/entity/entity_registry.h"

class EntityContext {
public:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include "bedrock/world/actor/registry/entity_registry.h"
#include "bedrock/entity/entity_registry.h"

class StrictEntityContext {
public:
Expand Down
4 changes: 0 additions & 4 deletions include/bedrock/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#pragma once

// Classes
class Abilities;
class ActorAnimationControllerGroup;
class ActorAnimationGroup;
class ActorChunkTransferEntry;
Expand Down Expand Up @@ -45,7 +44,6 @@ class BlockClimberDefinition;
class BlockComponentFactory;
class BlockDefinitionGroup;
class BlockLegacy;
class BlockPos;
class BlockPalette;
class BlockReducer;
class BlockSource;
Expand Down Expand Up @@ -101,11 +99,9 @@ class ItemInstance;
class ItemRegistryRef;
class ItemUseMethod;
class JigsawStructureRegistry;
class LayeredAbilities;
class LevelChunk;
class LevelData;
class LevelEventListener;
class LevelSettings;
class LevelSoundManager;
class LevelStorage;
class Localization;
Expand Down
3 changes: 2 additions & 1 deletion include/bedrock/i18n.h → include/bedrock/locale/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#include <gsl/gsl>

#include "bedrock/bedrock.h"
#include "bedrock/core/memory.h"
#include "bedrock/core/utility/non_owner_pointer.h"
#include "bedrock/forward.h"
#include "bedrock/memory.h"

class I18n {
public:
Expand Down
7 changes: 3 additions & 4 deletions include/bedrock/nbt/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

#pragma once

#include "bedrock/io/data_input.h"
#include "bedrock/io/data_output.h"
#include "bedrock/io/print_stream.h"
#include "bedrock/result.h"
#include "bedrock/core/result.h"
#include "bedrock/core/utility/data_io.h"
#include "bedrock/core/utility/print_stream.h"

class Tag {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/bedrock/network/net_event_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

#pragma once

#include "bedrock/memory.h"
#include "bedrock/core/utility/non_owner_pointer.h"

class NetEventCallback : public Bedrock::EnableNonOwnerReferences {};
2 changes: 1 addition & 1 deletion include/bedrock/network/packet/move_actor_absolute_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <cstdint>

#include "bedrock/bedrock.h"
#include "bedrock/core/math/vec3.h"
#include "bedrock/world/actor/actor_runtime_id.h"
#include "bedrock/world/math/vec3.h"

class MoveActorAbsoluteData {
public:
Expand Down
8 changes: 4 additions & 4 deletions include/bedrock/network/packet/start_game_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
#include <vector>

#include "bedrock/bedrock.h"
#include "bedrock/core/math/vec2.h"
#include "bedrock/core/math/vec3.h"
#include "bedrock/core/utility/uuid.h"
#include "bedrock/forward.h"
#include "bedrock/mce.h"
#include "bedrock/nbt/compound_tag.h"
#include "bedrock/network/packet.h"
#include "bedrock/server/packs/content_identity.h"
#include "bedrock/world/actor/actor_runtime_id.h"
#include "bedrock/world/actor/actor_unique_id.h"
#include "bedrock/world/actor/player/synced_player_movement_settings.h"
#include "bedrock/world/level/game_type.h"
#include "bedrock/world/level/storage/level_settings.h"
#include "bedrock/world/math/vec2.h"
#include "bedrock/world/math/vec3.h"
#include "bedrock/world/level/level_settings.h"

class NetworkPermissions {
public:
Expand Down
8 changes: 4 additions & 4 deletions include/bedrock/network/server_network_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#pragma once

#include "bedrock/bedrock.h"
#include "bedrock/memory.h"
#include "bedrock/core/memory.h"
#include "bedrock/core/threading.h"
#include "bedrock/core/utility/observer.h"
#include "bedrock/network/connection.h"
#include "bedrock/network/net_event_callback.h"
#include "bedrock/server/server_player.h"
#include "bedrock/social.h"
#include "bedrock/threading.h"
#include "bedrock/world/actor/player/player.h"
#include "bedrock/world/level/event/server_event.h"
#include "bedrock/world/events/server_event.h"
#include "bedrock/world/level/level_listener.h"

class ServerNetworkHandler : public Bedrock::Threading::EnableQueueForMainThread,
Expand Down
9 changes: 5 additions & 4 deletions include/bedrock/server/commands/command_origin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@

#include <json/json.h>

#include "bedrock/mce.h"
#include "bedrock/memory.h"
#include "bedrock/core/math/vec2.h"
#include "bedrock/core/math/vec3.h"
#include "bedrock/core/memory.h"
#include "bedrock/core/utility/uuid.h"
#include "bedrock/network/network_identifier.h"
#include "bedrock/network/sub_client_id.h"
#include "bedrock/server/commands/command_origin_data.h"
#include "bedrock/server/commands/command_origin_identity.h"
#include "bedrock/server/commands/command_origin_type.h"
#include "bedrock/server/commands/command_permission_level.h"
#include "bedrock/world/actor/player/abilities/abilities_index.h"
#include "bedrock/world/level/block_pos.h"
#include "bedrock/world/level/dimension/dimension.h"
#include "bedrock/world/math/vec2.h"
#include "bedrock/world/math/vec3.h"

class Actor;
class Level;
Expand Down
2 changes: 1 addition & 1 deletion include/bedrock/server/commands/command_origin_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <cstdint>
#include <string>

#include "bedrock/mce.h"
#include "bedrock/core/utility/uuid.h"
#include "bedrock/server/commands/command_origin_type.h"

struct CommandOriginData {
Expand Down
Loading

0 comments on commit d7f614d

Please sign in to comment.