Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ur_scene_view.hpp
Go to the documentation of this file.
1
11
12#ifndef ZOAPPURSCENEVIEW_H
13#define ZOAPPURSCENEVIEW_H
14
15#include <toymaker/engine/sim_system.hpp>
16#include <toymaker/engine/signals.hpp>
17#include <toymaker/engine/text_render.hpp>
18
19#include "board_locations.hpp"
21
23
24bool operator<(const UrPieceAnimationKey& one, const UrPieceAnimationKey& two);
25
35class UrSceneView: public ToyMaker::SimObjectAspect<UrSceneView> {
36public:
37 UrSceneView(): ToyMaker::SimObjectAspect<UrSceneView>{0} {}
38
39 inline static std::string getSimObjectAspectTypeName() { return "UrSceneView"; }
40 static std::shared_ptr<BaseSimObjectAspect> create(const nlohmann::json& jsonAspectProperties);
41 std::shared_ptr<BaseSimObjectAspect> clone() const override;
42
43 const GameOfUrModel& getModel() const;
44 const BoardLocations& getBoard() const;
45
46private:
47 static const glm::u8vec2 kGridUnfocused;
48
49 enum class Mode {
50 GENERAL,
51 LAUNCH_POSITION_SELECTION,
52 TRANSITION,
53 };
54
55 std::map<PieceIdentity, std::string> mPieceModelMap {};
56 std::map<PieceIdentity, std::shared_ptr<ToyMaker::SceneNode>> mPieceNodeMap {};
57 std::weak_ptr<ToyMaker::SimObject> mGameOfUrController {};
58 std::weak_ptr<ToyMaker::SimObject> mGameOfUrBoard {};
59 std::priority_queue<UrPieceAnimationKey> mAnimationKeys {};
60 uint32_t mAnimationTimeMillis {};
61
62 std::string mControllerPath {};
63 Mode mMode { Mode::GENERAL };
64 PlayerID mControlledBy {};
65 glm::u8vec2 mFocusedGridCell {};
66
67 void onControllerReady();
68
69 void onBoardClicked(glm::u8vec2 boardLocation);
70 void onBoardHovered(glm::u8vec2 boardLocation);
71 void onLaunchPieceInitiated(PieceTypeID piece);
72 void onLaunchPieceHovered(PieceTypeID piece);
73 void onLaunchPieceCanceled();
74 void onMoveMade(const MoveResultData& moveResultData);
75
76 void onViewUpdateStarted();
77 void onControlInterface(PlayerID player);
78
79 void onActivated() override;
80 void variableUpdate(uint32_t variableStepMillis) override;
81
82 void addLight(glm::u8vec2 boardPosition, const ToyMaker::LightEmissionData& light);
83 void addLights(const std::vector<glm::u8vec2>& boardPositions);
84 void clearLights();
85
86public:
87 ToyMaker::SignalObserver<glm::u8vec2> mObserveBoardClicked {
88 *this, "BoardClickedObserved",
89 [this](glm::u8vec2 boardLocation) { this->onBoardClicked(boardLocation); }
90 };
91 ToyMaker::SignalObserver<glm::u8vec2> mObserveBoardHovered {
92 *this, "BoardHoveredObserved",
93 [this](glm::u8vec2 boardLocation) { this->onBoardHovered(boardLocation); }
94 };
95 ToyMaker::SignalObserver<PieceTypeID> mObserveLaunchPieceInitiated {
96 *this, "LaunchPieceInitiatedObserved",
97 [this](PieceTypeID pieceType) { this->onLaunchPieceInitiated(pieceType); }
98 };
99 ToyMaker::SignalObserver<PieceTypeID> mObserveLaunchPieceHovered {
100 *this, "LaunchPieceHoveredObserved",
101 [this](PieceTypeID pieceType) { this->onLaunchPieceHovered(pieceType); }
102 };
103 ToyMaker::SignalObserver<> mObserveLaunchPieceCancelled {
104 *this, "LaunchPieceCanceledObserved",
105 [this]() { this->onLaunchPieceCanceled(); }
106 };
107 ToyMaker::SignalObserver<MoveResultData> mObserveMoveMade {
108 *this, "MoveMadeObserved",
109 [this](const MoveResultData& moveResultData) { this->onMoveMade(moveResultData); }
110 };
111 ToyMaker::SignalObserver<PlayerID> mObserveControlInterface {
112 *this, "ControlInterfaceObserved",
113 [this](PlayerID playerID) { this->onControlInterface(playerID); }
114 };
115
116 ToyMaker::Signal<PieceTypeID, glm::u8vec2> mSigLaunchPieceAttempted {
117 *this, "LaunchPieceAttempted"
118 };
119 ToyMaker::Signal<PieceIdentity> mSigMovePieceAttempted {
120 *this, "MovePieceAttempted"
121 };
122
123 ToyMaker::SignalObserver<> mObserveControllerReady {
124 *this, "ControllerReadyObserved",
125 [this]() {this->onControllerReady();}
126 };
127 ToyMaker::Signal<std::string> mSigViewSubscribed {*this, "ViewSubscribed"};
128
129 ToyMaker::SignalObserver<> mObserveViewUpdateStarted {
130 *this, "ViewUpdateStartedObserved",
131 [this](){ this->onViewUpdateStarted(); }
132 };
133 ToyMaker::Signal<std::string> mSigViewUpdateCompleted {
134 *this, "ViewUpdateCompleted"
135 };
136};
137
140 uint32_t mTime;
141 PieceIdentity mPieceIdentity;
142 ToyMaker::Placement mPlacement;
143 bool mRemove { false };
144};
145
146inline const glm::u8vec2 UrSceneView::kGridUnfocused { 255, 255 };
147
148#endif
Contains the class responsible for mapping locations on the 3D game board model to their equivalent c...
The aspect responsible for mapping points on the 3D game board to their equivalent coordinates on the...
Definition board_locations.hpp:24
The data model representing one instance of Game of Ur.
Definition model.hpp:343
PieceTypeID
Enum listing the different types of pieces present in the game.
Definition piece_type_id.hpp:22
PlayerID
The two players playing the game, as known to GameOfUrModel.
Definition model.hpp:40
The class containing the interface to the data model for the whole game (Game of Ur).
Data returned by the GameOfUrModel when making a move, or querying possible moves.
Definition model.hpp:278
Data uniquely identifying a piece used in the game.
Definition piece.hpp:29
Definition ur_scene_view.hpp:139