Skip to content

Commit 962b18c

Browse files
committed
windows: support dll library for oopertis-graphics, part1
add export or import declarations, to be able to build libraries as dll
1 parent b153979 commit 962b18c

40 files changed

+519
-368
lines changed

src/discord/core.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <core/helper/expected.hpp>
66

7+
#include "../helper/windows.hpp"
8+
79
#include <chrono>
810
#ifdef _WIN32
911
#ifndef NOMINMAX
@@ -38,8 +40,7 @@ namespace constants::discord {
3840
// manually synchronized to https://discord.com/developers/applications/1220147916371394650/rich-presence/assets
3941
enum class ArtAsset { logo };
4042

41-
[[nodiscard]] std::string get_asset_key(ArtAsset asset);
42-
43+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::string get_asset_key(ArtAsset asset);
4344

4445
} // namespace constants::discord
4546

@@ -51,11 +52,15 @@ struct DiscordActivityWrapper {
5152
public:
5253
//TODO(Totto): Add support for party and invites / join / invitations / spectate
5354

54-
DiscordActivityWrapper(const std::string& details, discord::ActivityType type);
55+
OOPETRIS_GRAPHICS_EXPORTED DiscordActivityWrapper(const std::string& details, discord::ActivityType type);
56+
57+
OOPETRIS_GRAPHICS_EXPORTED DiscordActivityWrapper&
58+
set_large_image(const std::string& text, constants::discord::ArtAsset asset);
5559

56-
DiscordActivityWrapper& set_large_image(const std::string& text, constants::discord::ArtAsset asset);
57-
DiscordActivityWrapper& set_small_image(const std::string& text, constants::discord::ArtAsset asset);
58-
DiscordActivityWrapper& set_details(const std::string& text);
60+
OOPETRIS_GRAPHICS_EXPORTED DiscordActivityWrapper&
61+
set_small_image(const std::string& text, constants::discord::ArtAsset asset);
62+
63+
OOPETRIS_GRAPHICS_EXPORTED DiscordActivityWrapper& set_details(const std::string& text);
5964

6065
template<typename T>
6166
DiscordActivityWrapper& set_start_timestamp(const std::chrono::time_point<T>& point) {
@@ -82,7 +87,7 @@ struct DiscordActivityWrapper {
8287
}
8388

8489

85-
[[nodiscard]] const discord::Activity& get_raw() const;
90+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] const discord::Activity& get_raw() const;
8691
};
8792

8893
struct DiscordInstance {
@@ -93,17 +98,18 @@ struct DiscordInstance {
9398
DiscordInstance(discord::Core* core);
9499

95100
public:
96-
[[nodiscard]] static helper::expected<DiscordInstance, std::string> initialize();
101+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] static helper::expected<DiscordInstance, std::string> initialize();
102+
103+
OOPETRIS_GRAPHICS_EXPORTED void after_setup();
97104

98-
void after_setup();
105+
OOPETRIS_GRAPHICS_EXPORTED DiscordInstance(DiscordInstance&& old) noexcept;
99106

100-
DiscordInstance(DiscordInstance&& old) noexcept;
101-
DiscordInstance& operator=(DiscordInstance&& other) noexcept;
107+
OOPETRIS_GRAPHICS_EXPORTED DiscordInstance& operator=(DiscordInstance&& other) noexcept;
102108

103-
~DiscordInstance();
109+
OOPETRIS_GRAPHICS_EXPORTED ~DiscordInstance();
104110

105-
void update();
106-
void set_activity(const DiscordActivityWrapper& activity);
111+
OOPETRIS_GRAPHICS_EXPORTED void update();
112+
OOPETRIS_GRAPHICS_EXPORTED void set_activity(const DiscordActivityWrapper& activity);
107113

108114
private:
109115
void clear_activity(bool wait = true);

src/game/bag.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
#include <core/game/tetromino_type.hpp>
44
#include <core/helper/random.hpp>
55

6+
#include "../helper/windows.hpp"
67
#include <array>
78

89
struct Bag final {
910
private:
1011
std::array<helper::TetrominoType, static_cast<int>(helper::TetrominoType::LastType) + 1> m_tetromino_sequence;
1112

1213
public:
13-
explicit Bag(Random& random);
14+
OOPETRIS_GRAPHICS_EXPORTED explicit Bag(Random& random);
1415

1516
static constexpr int size() {
1617
return static_cast<int>(helper::TetrominoType::LastType) + 1;
1718
}
1819

19-
const helper::TetrominoType& operator[](int index) const;
20+
OOPETRIS_GRAPHICS_EXPORTED const helper::TetrominoType& operator[](int index) const;
2021

2122
private:
2223
static helper::TetrominoType get_random_tetromino_type(Random& random);

src/game/command_line_arguments.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <core/helper/types.hpp>
77
#include <core/helper/utils.hpp>
88

9+
#include "../helper/windows.hpp"
10+
911
#include <filesystem>
1012
#include <optional>
1113

@@ -20,7 +22,7 @@ struct CommandLineArguments final {
2022
Level starting_level;
2123
bool silent;
2224

23-
CommandLineArguments(
25+
OOPETRIS_GRAPHICS_EXPORTED CommandLineArguments(
2426
std::optional<std::filesystem::path> recording_path,
2527
std::optional<u32> target_fps,
2628
Level starting_level = default_starting_level,

src/game/game.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "input/input_creator.hpp"
77
#include "tetrion.hpp"
88
#include "ui/widget.hpp"
9+
#include "helper/windows.hpp"
910

1011
struct Game : public ui::Widget {
1112
private:
@@ -18,7 +19,7 @@ struct Game : public ui::Widget {
1819
bool m_is_paused{ false };
1920

2021
public:
21-
explicit Game(
22+
OOPETRIS_GRAPHICS_EXPORTED explicit Game(
2223
ServiceProvider* service_provider,
2324
const std::shared_ptr<input::GameInput>& input,
2425
const tetrion::StartingParameters& starting_parameters,
@@ -27,17 +28,18 @@ struct Game : public ui::Widget {
2728
bool is_top_level
2829
);
2930

30-
void update() override;
31+
OOPETRIS_GRAPHICS_EXPORTED void update() override;
3132

32-
void render(const ServiceProvider& service_provider) const override;
33-
[[nodiscard]] Widget::EventHandleResult
33+
OOPETRIS_GRAPHICS_EXPORTED void render(const ServiceProvider& service_provider) const override;
3434

35+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] Widget::EventHandleResult
3536
handle_event(const std::shared_ptr<input::InputManager>& input_manager, const SDL_Event& event) override;
3637

37-
void set_paused(bool paused);
38-
[[nodiscard]] bool is_paused() const;
38+
OOPETRIS_GRAPHICS_EXPORTED void set_paused(bool paused);
3939

40-
[[nodiscard]] bool is_game_finished() const;
40+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] bool is_paused() const;
4141

42-
[[nodiscard]] const std::shared_ptr<input::GameInput>& game_input() const;
42+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] bool is_game_finished() const;
43+
44+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] const std::shared_ptr<input::GameInput>& game_input() const;
4345
};

src/game/graphic_helpers.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <core/core.hpp>
44

55
#include "manager/service_provider.hpp"
6-
6+
#include "helper/windows.hpp"
77

88
enum class MinoTransparency : u8 {
99
// here the enum value is used as index into the preview alpha array
@@ -21,7 +21,7 @@ enum class MinoTransparency : u8 {
2121
namespace helper::graphics {
2222
static constexpr int mino_original_inset = 3;
2323

24-
void render_mino(
24+
OOPETRIS_GRAPHICS_EXPORTED void render_mino(
2525
const Mino& mino,
2626
const ServiceProvider& service_provider,
2727
MinoTransparency transparency,
@@ -32,7 +32,7 @@ namespace helper::graphics {
3232
);
3333

3434

35-
void render_minos(
35+
OOPETRIS_GRAPHICS_EXPORTED void render_minos(
3636
const MinoStack& mino_stack,
3737
const ServiceProvider& service_provider,
3838
double original_scale,

src/game/grid.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "manager/service_provider.hpp"
88
#include "ui/layout.hpp"
99
#include "ui/widget.hpp"
10+
#include "helper/windows.hpp"
1011

1112
struct Grid final : public ui::Widget {
1213
public:
@@ -23,12 +24,17 @@ struct Grid final : public ui::Widget {
2324
u32 m_tile_size;
2425

2526
public:
26-
Grid(const ui::Layout& layout, bool is_top_level);
27+
OOPETRIS_GRAPHICS_EXPORTED Grid(const ui::Layout& layout, bool is_top_level);
28+
2729
[[nodiscard]] shapes::UPoint tile_size() const;
28-
[[nodiscard]] double scale_to_original() const;
29-
[[nodiscard]] shapes::UPoint to_screen_coords(GridPoint grid_coords) const;
30-
void render(const ServiceProvider& service_provider) const override;
31-
[[nodiscard]] helper::BoolWrapper<std::pair<ui::EventHandleType, ui::Widget*>>
30+
31+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] double scale_to_original() const;
32+
33+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] shapes::UPoint to_screen_coords(GridPoint grid_coords) const;
34+
35+
OOPETRIS_GRAPHICS_EXPORTED void render(const ServiceProvider& service_provider) const override;
36+
37+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] helper::BoolWrapper<std::pair<ui::EventHandleType, ui::Widget*>>
3238
handle_event(const std::shared_ptr<input::InputManager>& input_manager, const SDL_Event& event) override;
3339

3440
private:

src/game/rotation.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <core/helper/types.hpp>
44

5+
#include "../helper/windows.hpp"
6+
57
enum class Rotation : u8 {
68
North = 0,
79
East,
@@ -10,10 +12,10 @@ enum class Rotation : u8 {
1012
LastRotation = West,
1113
};
1214

13-
Rotation& operator++(Rotation& rotation);
15+
OOPETRIS_GRAPHICS_EXPORTED Rotation& operator++(Rotation& rotation);
1416

15-
Rotation& operator--(Rotation& rotation);
17+
OOPETRIS_GRAPHICS_EXPORTED Rotation& operator--(Rotation& rotation);
1618

17-
Rotation operator+(Rotation rotation, i8 offset);
19+
OOPETRIS_GRAPHICS_EXPORTED Rotation operator+(Rotation rotation, i8 offset);
1820

19-
Rotation operator-(Rotation rotation, i8 offset);
21+
OOPETRIS_GRAPHICS_EXPORTED Rotation operator-(Rotation rotation, i8 offset);

src/game/simulated_tetrion.hpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "tetromino.hpp"
1414
#include "ui/layouts/grid_layout.hpp"
1515
#include "ui/widget.hpp"
16+
#include "helper/windows.hpp"
1617

1718
#include <array>
1819

@@ -90,44 +91,44 @@ struct SimulatedTetrion {
9091
m_service_provider; // NOLINT(misc-non-private-member-variables-in-classes,cppcoreguidelines-non-private-member-variables-in-classes)
9192

9293
public:
93-
SimulatedTetrion(
94+
OOPETRIS_GRAPHICS_EXPORTED SimulatedTetrion(
9495
u8 tetrion_index,
9596
Random::Seed random_seed,
9697
u32 starting_level,
9798
ServiceProvider* service_provider,
9899
std::optional<std::shared_ptr<recorder::RecordingWriter>> recording_writer
99100
);
100101

101-
virtual ~SimulatedTetrion();
102+
OOPETRIS_GRAPHICS_EXPORTED virtual ~SimulatedTetrion();
102103

103-
SimulatedTetrion(const SimulatedTetrion& other);
104-
SimulatedTetrion& operator=(const SimulatedTetrion& other) = delete;
104+
OOPETRIS_GRAPHICS_EXPORTED SimulatedTetrion(const SimulatedTetrion& other);
105+
OOPETRIS_GRAPHICS_EXPORTED SimulatedTetrion& operator=(const SimulatedTetrion& other) = delete;
105106

106-
SimulatedTetrion(SimulatedTetrion&& other) noexcept;
107-
SimulatedTetrion& operator=(SimulatedTetrion&& other) noexcept = delete;
107+
OOPETRIS_GRAPHICS_EXPORTED SimulatedTetrion(SimulatedTetrion&& other) noexcept;
108+
OOPETRIS_GRAPHICS_EXPORTED SimulatedTetrion& operator=(SimulatedTetrion&& other) noexcept = delete;
108109

109-
void update_step(SimulationStep simulation_step_index);
110+
OOPETRIS_GRAPHICS_EXPORTED void update_step(SimulationStep simulation_step_index);
110111

111112
// returns if the input event lead to a movement
112-
bool handle_input_command(input::GameInputCommand command, SimulationStep simulation_step_index);
113-
void spawn_next_tetromino(SimulationStep simulation_step_index);
114-
void spawn_next_tetromino(helper::TetrominoType type, SimulationStep simulation_step_index);
115-
bool rotate_tetromino_right();
116-
bool rotate_tetromino_left();
117-
bool move_tetromino_down(MovementType movement_type, SimulationStep simulation_step_index);
118-
bool move_tetromino_left();
119-
bool move_tetromino_right();
120-
bool drop_tetromino(SimulationStep simulation_step_index);
121-
void hold_tetromino(SimulationStep simulation_step_index);
122-
123-
[[nodiscard]] u8 tetrion_index() const;
124-
[[nodiscard]] u32 level() const;
125-
[[nodiscard]] u64 score() const;
126-
[[nodiscard]] u32 lines_cleared() const;
127-
[[nodiscard]] const MinoStack& mino_stack() const;
128-
[[nodiscard]] std::unique_ptr<TetrionCoreInformation> core_information() const;
129-
130-
[[nodiscard]] bool is_game_over() const;
113+
OOPETRIS_GRAPHICS_EXPORTED bool handle_input_command(input::GameInputCommand command, SimulationStep simulation_step_index);
114+
OOPETRIS_GRAPHICS_EXPORTED void spawn_next_tetromino(SimulationStep simulation_step_index);
115+
OOPETRIS_GRAPHICS_EXPORTED void spawn_next_tetromino(helper::TetrominoType type, SimulationStep simulation_step_index);
116+
OOPETRIS_GRAPHICS_EXPORTED bool rotate_tetromino_right();
117+
OOPETRIS_GRAPHICS_EXPORTED bool rotate_tetromino_left();
118+
OOPETRIS_GRAPHICS_EXPORTED bool move_tetromino_down(MovementType movement_type, SimulationStep simulation_step_index);
119+
OOPETRIS_GRAPHICS_EXPORTED bool move_tetromino_left();
120+
OOPETRIS_GRAPHICS_EXPORTED bool move_tetromino_right();
121+
OOPETRIS_GRAPHICS_EXPORTED bool drop_tetromino(SimulationStep simulation_step_index);
122+
OOPETRIS_GRAPHICS_EXPORTED void hold_tetromino(SimulationStep simulation_step_index);
123+
124+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] u8 tetrion_index() const;
125+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] u32 level() const;
126+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] u64 score() const;
127+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] u32 lines_cleared() const;
128+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] const MinoStack& mino_stack() const;
129+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::unique_ptr<TetrionCoreInformation> core_information() const;
130+
131+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] bool is_game_over() const;
131132

132133
private:
133134
template<typename Callable>

src/game/simulation.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "input/input_creator.hpp"
77
#include "input/replay_input.hpp"
88
#include "simulated_tetrion.hpp"
9+
#include "helper/windows.hpp"
910

1011
struct Simulation {
1112
private:
@@ -16,16 +17,16 @@ struct Simulation {
1617
std::shared_ptr<input::ReplayGameInput> m_input;
1718

1819
public:
19-
explicit Simulation(
20+
OOPETRIS_GRAPHICS_EXPORTED explicit Simulation(
2021
const std::shared_ptr<input::ReplayGameInput>& input,
2122
const tetrion::StartingParameters& starting_parameters
2223
);
2324

25+
OOPETRIS_GRAPHICS_EXPORTED static helper::expected<Simulation, std::string> get_replay_simulation(
26+
std::filesystem::path& recording_path
27+
);
2428

25-
static helper::expected<Simulation, std::string> get_replay_simulation(std::filesystem::path& recording_path);
26-
27-
void update();
28-
29+
OOPETRIS_GRAPHICS_EXPORTED void update();
2930

30-
[[nodiscard]] bool is_game_finished() const;
31+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] bool is_game_finished() const;
3132
};

0 commit comments

Comments
 (0)