Greetings,
I have been fiddling around with SFML recently, and I wrote the following program:
#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\Audio.hpp>
#include <SFML\System.hpp>
using namespace std;
struct main_variables{
public:
sf::Sound main_variables::clock_ticking_1;
sf::RenderWindow main_variables::application;
int main_variables::seconds;
};
bool timer(main_variables& m_1);
bool sound_player(main_variables& m_1);
int main(){
// main variables
main_variables m;
m.seconds = 0;
// icon
sf::Image icon;
if(!icon.loadFromFile("data/clock_icon.png"))
return 1;
m.application.setIcon(32, 32, icon.getPixelsPtr());
m.application.create(sf::VideoMode(300, 300, 64), "Clock", sf::Style::Close);
m.application.setFramerateLimit(30);
// clock_t
sf::Texture clock_t;
if(!clock_t.loadFromFile("data/clock.png"))
return 1;
// long_pointer_t
sf::Texture long_pointer_t;
if(!long_pointer_t.loadFromFile("data/clock_long_pointer.png"))
return 1;
// short_pointer_t
sf::Texture short_pointer_t;
if(!short_pointer_t.loadFromFile("data/clock_short_pointer.png"))
return 1;
// longest pointer_t
sf::Texture longest_pointer_t;
if(!longest_pointer_t.loadFromFile("data/clock_longest_pointer.png"))
return 1;
short_pointer_t.setSmooth(1);
// clock
sf::RectangleShape clock(sf::Vector2f(300,300));
clock.setTexture(&clock_t);
clock.setPosition(0, 0);
// long_pointer
sf::RectangleShape long_pointer(sf::Vector2f(125,20));
long_pointer.setTexture(&long_pointer_t);
long_pointer.setOrigin(5,10);
long_pointer.setPosition(150, 150);
// short pointer
sf::RectangleShape short_pointer(sf::Vector2f(100,20));
short_pointer.setTexture(&short_pointer_t);
short_pointer.setOrigin(5,10);
short_pointer.setPosition(150, 150);
// longest pointer
sf::RectangleShape longest_pointer(sf::Vector2f(125,20));
longest_pointer.setTexture(&longest_pointer_t);
longest_pointer.setOrigin(5,10);
longest_pointer.setPosition(150, 150);
// sound
sf::SoundBuffer clock_ticking_1_b;
if(!clock_ticking_1_b.loadFromFile("data/clock_ticking_2.wav"));
sf::Sound clock_ticking_1;
clock_ticking_1.setBuffer(clock_ticking_1_b);
// event
sf::Event event;
// threads
sf::Thread timer_thread(&timer, m);
timer_thread.launch();
sf::Thread sound_player_thread(&sound_player, m);
sound_player_thread.launch();
while(m.application.isOpen()){
while(m.application.pollEvent(event)){
if (event.type == sf::Event::Closed ||(event.KeyPressed && event.key.code == sf::Keyboard::Escape)){
goto exit;
}
}
if(m.seconds == (60*60*12))
m.seconds = 0;
longest_pointer.setRotation(static_cast<float>(m.seconds*6-90));
long_pointer.setRotation(static_cast<float>(m.seconds*6/60-90));
short_pointer.setRotation(static_cast<float>(m.seconds*6/60/60-90));
m.application.clear(sf::Color::Black);
m.application.draw(clock);
m.application.draw(short_pointer);
m.application.draw(long_pointer);
m.application.draw(longest_pointer);
m.application.display();
}
exit:
m.application.close();
cout << "exiting program..." << endl;
return 0;
}
bool timer( main_variables& m_1){
while( m_1.application.isOpen()){
sf::sleep(sf::seconds(1));
m_1.seconds++;
}
return 0;
}
bool sound_player( main_variables& m_1){
while( m_1.application.isOpen()){
m_1.clock_ticking_1.play();
sf::sleep(sf::seconds(10));
}
return 0;
}
The output:
1>------ Build started: Project: CppApplication_2, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\frank\documents\visual studio 2010\projects\cppapplication_2\main.cpp(68): warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\sfml\include\sfml\window\window.hpp(476): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'
1>c:\sfml\include\sfml\graphics\rendertarget.hpp(419): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\sfml\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::RenderTarget::RenderTarget(const sf::RenderTarget &)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========I have no idea why the compiler gives me these errors. As far as I can see, there are no copies being made of m.application or of m.clock_ticking_1, they are only being passed as a reference.