-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDemo.cpp
More file actions
147 lines (123 loc) · 5.19 KB
/
Copy pathDemo.cpp
File metadata and controls
147 lines (123 loc) · 5.19 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//This file contains the C++ entry main function and demonstrates
//using the Activity Controller with SFML's main loop
#include <Swoosh/ActivityController.h>
#include <Swoosh/Renderers/SimpleRenderer.h>
#include <Segues/ZoomOut.h>
#include <SFML/Window.hpp>
#include "Scenes/IntroScene.h"
#include "CustomRenderer.h"
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Swoosh Demo");
window.setFramerateLimit(60); // call this once, after creating the window
window.setVerticalSyncEnabled(true);
window.setMouseCursorVisible(false);
// 11/23/2022 (NEW BEHAVIOR!)
// Swoosh now enables custom render pipelines and
// can switch between them in real-time
sw::RenderEntries renderOptions;
renderOptions
.enroll<CustomRenderer>("custom", window.getView())
.enroll<SimpleRenderer>("simple", window.getView());
// Create an AC with the current window as our target to draw to
sw::ActivityController app(window, renderOptions);
// 10/9/2020
// For mobile devices or low-end GPU's, you can request optimized
// effects any time by setting the performance quality to
// one of the following: { realtime, reduced, mobile }
app.optimizeForPerformance(sw::quality::realtime);
// app.optimizeForPerformance(quality::mobile); // <-- uncomment me!
// 06/12/2024
// The AC needs a renderer in order to draw anything.
// This was added to allow programmers to check for platform compatibilities
// before commiting to constructing renderers which will require resources.
// After the options are build, the programmer can iterate through the list
// and check their SystemCompatibilityScores to determine which to use.
app.buildRenderEntries();
std::string errors;
if(renderOptions.built() && renderOptions.countValid() > 0) {
for(auto& iter : renderOptions.list()) {
auto score = iter.getInstance().checkSystemCompatibility();
if(score == sw::SystemCompatibilityScore::sufficient) {
app.activateRenderEntry(iter.getIndex());
continue;
}
if (score == sw::SystemCompatibilityScore::build_error) {
errors += iter.getError() + "\n";
}
// For example's sake, we will free insufficient renderers
iter.free();
}
} else {
// Running this application without a renderer is pointless.
std::cout << "Application cannot render as configured.\n";
std::cout << "Errors: " << errors << std::endl;
return -1; // Quit
}
// (DEFAULT BEHAVIOR!)
// Add the Main Menu Scene as the first and only scene in our stack
// This is our starting point for the user
// app.push<MainMenuScene>(); // <-- uncomment to see a simple push
// 10/9/2020 (NEW BEHAVIOR!)
// Swoosh now supports generating blank activities from window contents!
// The segue will copy the window at startup and use it as part of
// the screen transition as demonstrated here
app.push<sw::segue<ZoomOut>::to<IntroScene>>();
// app.push<MainMenuScene>(); // uncomment this and comment the line above for old behavior
sf::Texture* cursorTexture = loadTexture(CURSOR_PATH);
sf::Sprite cursor;
cursor.setTexture(*cursorTexture);
// run the program as long as the window is open
float elapsed = 0.0f;
sf::Clock clock;
bool pause = false;
srand((unsigned int)time(0));
while (window.isOpen())
{
clock.restart();
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed) {
window.close();
} else if (event.type == sf::Event::LostFocus) {
pause = true;
}
else if (event.type == sf::Event::GainedFocus) {
pause = false;
}
else if (event.type == sf::Event::KeyPressed) {
// Toggle to different renderers using F-keys
sf::Keyboard::Key code = event.key.code;
if (code == sf::Keyboard::F1 && app.activateRenderEntry(0)) {
const std::string& name = app.getActiveRenderEntry().getName();
window.setTitle("Swoosh Demo (renderer=" + name + ")");
}
else if (code == sf::Keyboard::F2 && app.activateRenderEntry(1)) {
const std::string& name = app.getActiveRenderEntry().getName();
window.setTitle("Swoosh Demo (renderer=" + name + ")");
}
}
}
// do not update segues when the window is frozen
if (!pause) {
app.update(elapsed);
}
// We clear after updating so that other items can copy the screen's contents
window.clear();
// Track the mouse and create a light source for this pass on the mouse!
sf::Vector2f mousepos = window.mapPixelToCoords(sf::Mouse::getPosition(window));
cursor.setPosition(mousepos);
// draw() will directly draw onto the window's render buffer
app.draw();
// Draw the mouse cursor over everything else
window.draw(cursor);
// Display to our screen
window.display();
elapsed = static_cast<float>(clock.getElapsedTime().asSeconds());
}
delete cursorTexture;
return 0;
}