-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontrol.h
More file actions
91 lines (81 loc) · 2.78 KB
/
Copy pathcontrol.h
File metadata and controls
91 lines (81 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**************************************************************************
* 3to4++ - https://github.com/rayzchen/3to4++
*-------------------------------------------------------------------------
* Copyright 2024 Ray Chen
*
* 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.
*
**************************************************************************/
#ifndef CONTROL_H
#define CONTROL_H
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <string>
#include <random>
#include "render.h"
#include "puzzle.h"
void showError(std::string text);
class MoveHistory {
public:
MoveHistory();
void reset();
void insertMove(MoveEntry entry);
bool isOpposite(MoveEntry entry1, MoveEntry entry2);
MoveEntry getOpposite(MoveEntry entry);
bool undoMove(MoveEntry* entry);
bool redoMove(MoveEntry* entry);
bool canUndo();
bool canRedo();
int getTurnCount();
private:
int turnCount;
std::vector<MoveEntry> history;
std::vector<MoveEntry> redoList;
bool undoing;
bool redoing;
};
class PuzzleController {
public:
friend class GuiRenderer;
PuzzleController(PuzzleRenderer* renderer);
~PuzzleController();
bool updatePuzzle(GLFWwindow* window, double dt);
bool checkMiddleGyro(int key, bool flip);
bool checkDirectionalMove(GLFWwindow* window, int key, bool flip);
void startGyro(CellLocation cell);
bool checkCellKeys(GLFWwindow* window, CellLocation* cell, bool flip);
bool checkDirectionKey(int key, RotateDirection* direction, bool flip);
void startCellMove(CellLocation cell, RotateDirection direction);
void keyCallback(GLFWwindow* window, int key, int action, int mods, bool flip);
std::string getStatus();
bool checkOutline(GLFWwindow *window, Shader *shader, bool flip);
void performMove(MoveEntry entry);
void performScramble();
void getScrambleTwists();
void resetPuzzle();
void scramblePuzzle(int scrambleLength);
void undoMove();
void redoMove();
void openFile(std::string filename);
static int cellKeys[];
static int directionKeys[];
private:
PuzzleRenderer *renderer;
Puzzle *puzzle;
MoveHistory *history;
std::string status;
std::mt19937 rng;
int scrambleIndex;
std::vector<MoveEntry> scramble;
};
#endif // control.h