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/sim_system.hpp"
16#include "toymaker/signals.hpp"
17#include "toymaker/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:
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 enum class Mode {
48 GENERAL,
49 LAUNCH_POSITION_SELECTION,
50 TRANSITION,
51 };
52
53 std::map<PieceIdentity, std::string> mPieceModelMap {};
54 std::map<PieceIdentity, std::shared_ptr<ToyMaker::SceneNode>> mPieceNodeMap {};
55 std::weak_ptr<ToyMaker::SimObject> mGameOfUrController {};
56 std::weak_ptr<ToyMaker::SimObject> mGameOfUrBoard {};
57 std::priority_queue<UrPieceAnimationKey> mAnimationKeys {};
58 uint32_t mAnimationTimeMillis {};
59
60 std::string mControllerPath {};
61 Mode mMode { Mode::GENERAL };
62 PlayerID mControlledBy {};
63
64 void onControllerReady();
65
66 void onBoardClicked(glm::u8vec2 boardLocation);
67 void onLaunchPieceInitiated(PieceTypeID piece);
68 void onLaunchPieceCanceled();
69 void onMoveMade(const MoveResultData& moveResultData);
70
71 void onViewUpdateStarted();
72 void onControlInterface(PlayerID player);
73
74 void onActivated() override;
75 void variableUpdate(uint32_t variableStepMillis) override;
76
77public:
78 ToyMaker::SignalObserver<glm::u8vec2> mObserveBoardClicked {
79 *this, "BoardClickedObserved",
80 [this](glm::u8vec2 boardLocation) { this->onBoardClicked(boardLocation); }
81 };
82 ToyMaker::SignalObserver<PieceTypeID> mObserveLaunchPieceInitiated {
83 *this, "LaunchPieceInitiatedObserved",
84 [this](PieceTypeID pieceType) { this->onLaunchPieceInitiated(pieceType); }
85 };
86 ToyMaker::SignalObserver<> mObserveLaunchPieceCancelled {
87 *this, "LaunchPieceCanceledObserved",
88 [this]() { this->onLaunchPieceCanceled(); }
89 };
91 *this, "MoveMadeObserved",
92 [this](const MoveResultData& moveResultData) { this->onMoveMade(moveResultData); }
93 };
94 ToyMaker::SignalObserver<PlayerID> mObserveControlInterface {
95 *this, "ControlInterfaceObserved",
96 [this](PlayerID playerID) { this->onControlInterface(playerID); }
97 };
98
99 ToyMaker::Signal<PieceTypeID, glm::u8vec2> mSigLaunchPieceAttempted {
100 *this, "LaunchPieceAttempted"
101 };
102 ToyMaker::Signal<PieceIdentity> mSigMovePieceAttempted {
103 *this, "MovePieceAttempted"
104 };
105
106 ToyMaker::SignalObserver<> mObserveControllerReady {
107 *this, "ControllerReadyObserved",
108 [this]() {this->onControllerReady();}
109 };
110 ToyMaker::Signal<std::string> mSigViewSubscribed {*this, "ViewSubscribed"};
111
112 ToyMaker::SignalObserver<> mObserveViewUpdateStarted {
113 *this, "ViewUpdateStartedObserved",
114 [this](){ this->onViewUpdateStarted(); }
115 };
116 ToyMaker::Signal<std::string> mSigViewUpdateCompleted {
117 *this, "ViewUpdateCompleted"
118 };
119};
120
123 uint32_t mTime;
124 PieceIdentity mPieceIdentity;
125 ToyMaker::Placement mPlacement;
126 bool mRemove { false };
127};
128
129#endif
The class containing the interface to the data model for the whole game (Game of Ur).
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:26
The data model representing one instance of Game of Ur.
Definition model.hpp:337
A SignalObserver object, which can subscribe to Signals matching its data signature and receive signa...
Definition signals.hpp:412
A Signal object, designed to emit signals matching some data signature to be received by all the Sign...
Definition signals.hpp:323
An object containing closely related methods and data, and exposing object lifecycle and application ...
Definition sim_system.hpp:956
std::shared_ptr< BaseSimObjectAspect > clone() const override
A method which must be overridden to specify how a new aspect should be constructed as a copy of this...
Definition ur_scene_view.cpp:18
void variableUpdate(uint32_t variableStepMillis) override
Overriding this allows an aspect to respond to variable updates.
Definition ur_scene_view.cpp:239
void onActivated() override
Callback for when the aspect is activated (after it is attached to an active SimObject,...
Definition ur_scene_view.cpp:49
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
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
A component representing the position, rotation, and scale of an entity.
Definition scene_components.hpp:30
Definition ur_scene_view.hpp:122