POSITIVE-MENTAL-ATTITUDE 8 years ago
parent
commit
07df40ba63
7 changed files with 99 additions and 61 deletions
  1. 60 37
      src/IngameState.cpp
  2. 3 1
      src/IngameState.hpp
  3. 11 14
      src/MenuState.cpp
  4. 1 1
      src/MenuState.hpp
  5. 1 1
      src/State.hpp
  6. 21 7
      src/Triangles.cpp
  7. 2 0
      src/main.cpp

+ 60 - 37
src/IngameState.cpp

@@ -73,18 +73,22 @@ void IngameState::init()
 	_context->foreground = &_foreground;
 	_context->foreground = &_foreground;
 	
 	
 	_background.setTextureRect(sf::IntRect(0, 0, _foreground.getSize().x, _foreground.getSize().y));
 	_background.setTextureRect(sf::IntRect(0, 0, _foreground.getSize().x, _foreground.getSize().y));
+	_noshaders.setTextureRect(sf::IntRect(0, 0, _foreground.getSize().x, _foreground.getSize().y));
 	
 	
 	_pauseFrame.setFillColor(sf::Color(0, 0, 0, 155));
 	_pauseFrame.setFillColor(sf::Color(0, 0, 0, 155));
 	_pauseFrame.setPosition(0, 0);
 	_pauseFrame.setPosition(0, 0);
 	
 	
-	_unshadowShader.loadFromFile("data/light/unshadowShader.frag", sf::Shader::Fragment);
-    _lightOverShapeShader.loadFromFile("data/light/lightOverShapeShader.frag", sf::Shader::Fragment);
-    _normalsShader.loadFromFile("data/light/normalsShader.frag", sf::Shader::Fragment);
-	_penumbraTexture.loadFromFile("data/light/penumbraTexture.png");
-	_penumbraTexture.setSmooth(true);
+	if(sf::Shader::isAvailable())
+	{
+		_unshadowShader.loadFromFile("data/light/unshadowShader.frag", sf::Shader::Fragment);
+		_lightOverShapeShader.loadFromFile("data/light/lightOverShapeShader.frag", sf::Shader::Fragment);
+		_normalsShader.loadFromFile("data/light/normalsShader.frag", sf::Shader::Fragment);
+		_penumbraTexture.loadFromFile("data/light/penumbraTexture.png");
+		_penumbraTexture.setSmooth(true);
 	
 	
-	_blurV.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-v.frag");
-	_blurH.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-h.frag");
+		_blurV.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-v.frag");
+		_blurH.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-h.frag");
+	}
 	
 	
 	_marioSound.setBuffer(_context->assets->loadSound("data/audio/Mario.ogg"));
 	_marioSound.setBuffer(_context->assets->loadSound("data/audio/Mario.ogg"));
 	_dotaSound.setBuffer(_context->assets->loadSound("data/audio/Victory.ogg"));
 	_dotaSound.setBuffer(_context->assets->loadSound("data/audio/Victory.ogg"));
@@ -116,10 +120,8 @@ void IngameState::init()
 void IngameState::refresh()
 void IngameState::refresh()
 {
 {
 	sf::Vector2u res = _context->window->getSize();
 	sf::Vector2u res = _context->window->getSize();
-	//_background.setTextureRect(sf::IntRect(0, 0, _context->window->getSize().x, _context->window->getSize().y));
 	_camera.setSize(static_cast<sf::Vector2f>(_context->window->getSize()));
 	_camera.setSize(static_cast<sf::Vector2f>(_context->window->getSize()));
 	_camera.setTwilightViewport(_context->window->getSize().x / 2.f - 240.f/* * (bool) _czyWOgóleTwilightViewportMaByć*/, _context->window->getSize().y / 2.f - 240.f);
 	_camera.setTwilightViewport(_context->window->getSize().x / 2.f - 240.f/* * (bool) _czyWOgóleTwilightViewportMaByć*/, _context->window->getSize().y / 2.f - 240.f);
-	//_camera.setTwilightViewport(0, 0);
 	_camera.setCenter(_player.getPosition());
 	_camera.setCenter(_player.getPosition());
 	_foreground.setResolution(res);
 	_foreground.setResolution(res);
 	
 	
@@ -134,13 +136,16 @@ void IngameState::refresh()
 	_backgroundH.create(_context->window->getSize().x, _context->window->getSize().y);
 	_backgroundH.create(_context->window->getSize().x, _context->window->getSize().y);
 	_backgroundV.create(_context->window->getSize().x, _context->window->getSize().y);
 	_backgroundV.create(_context->window->getSize().x, _context->window->getSize().y);
 
 
-	_lightSystem.create(sf::FloatRect{{0.f, 0.f}, {0.f, 0.f}}, {_context->window->getSize().x, _context->window->getSize().y}, _penumbraTexture, _unshadowShader, _lightOverShapeShader, _normalsShader);
-	_lightSystem.normalsEnabled(true);
-	_lightSystem.addLight(_player.light());
-	_lightSystem.addLight(_wormhole.light());
-	unsigned k = _star.size();
-	for(unsigned i = 0; i < k; ++i)
-		_lightSystem.addLight(_star[i].light());
+	if(sf::Shader::isAvailable())
+	{
+		_lightSystem.create(sf::FloatRect{{0.f, 0.f}, {0.f, 0.f}}, {_context->window->getSize().x, _context->window->getSize().y}, _penumbraTexture, _unshadowShader, _lightOverShapeShader, _normalsShader);
+		_lightSystem.normalsEnabled(true);
+		_lightSystem.addLight(_player.light());
+		_lightSystem.addLight(_wormhole.light());
+		unsigned k = _star.size();
+		for(unsigned i = 0; i < k; ++i)
+			_lightSystem.addLight(_star[i].light());
+	}
 }
 }
 
 
 void IngameState::coreThink(const sf::Event& event)
 void IngameState::coreThink(const sf::Event& event)
@@ -179,8 +184,11 @@ void IngameState::coreUpdate(sf::Time delta)
 		color.a = (int)_frameAlpha;
 		color.a = (int)_frameAlpha;
 		_pauseFrame.setFillColor(color);
 		_pauseFrame.setFillColor(color);
 		
 		
-		_blurH.setParameter("blurSize", _blurSize / _context->window->getSize().x);
-		_blurV.setParameter("blurSize", _blurSize / _context->window->getSize().y);
+		if(_context->shaders)
+		{
+			_blurH.setParameter("blurSize", _blurSize / _context->window->getSize().x);
+			_blurV.setParameter("blurSize", _blurSize / _context->window->getSize().y);
+		}
 		
 		
 		if((_wasted.getPosition().y > _context->window->getSize().y / 2.f) 
 		if((_wasted.getPosition().y > _context->window->getSize().y / 2.f) 
 		|| (_wasted.getPosition().y > -int(_context->window->getSize().y) / 2.f 
 		|| (_wasted.getPosition().y > -int(_context->window->getSize().y) / 2.f 
@@ -285,25 +293,29 @@ void IngameState::coreUpdate(sf::Time delta)
 			direction = false;
 			direction = false;
 	}
 	}
 }
 }
-void IngameState::coreRender(const bool shaders)
+void IngameState::coreRender()
 {
 {
-	if(_player.isDead())
+	if(_player.isDead() && _context->shaders)
 	{
 	{
 		_backgroundH.draw(_background);
 		_backgroundH.draw(_background);
 		_backgroundH.setView(*_camera.getView());
 		_backgroundH.setView(*_camera.getView());
 		_backgroundH.draw(_foreground);
 		_backgroundH.draw(_foreground);
+		for(unsigned i = 0; i < _star.size(); ++i)
+			_backgroundH.draw(_star[i]);
 		_backgroundH.draw(_wormhole);
 		_backgroundH.draw(_wormhole);
 		_backgroundH.draw(_player);
 		_backgroundH.draw(_player);
 		sf::Sprite sprite3(_lightSystem.getLightingTexture());
 		sf::Sprite sprite3(_lightSystem.getLightingTexture());
+		
 		sf::RenderStates lightRenderStates;
 		sf::RenderStates lightRenderStates;
 		lightRenderStates.blendMode = sf::BlendMultiply;
 		lightRenderStates.blendMode = sf::BlendMultiply;
 		_backgroundH.setView(_context->window->getDefaultView());
 		_backgroundH.setView(_context->window->getDefaultView());
 		_backgroundH.draw(sprite3, lightRenderStates); 
 		_backgroundH.draw(sprite3, lightRenderStates); 
-
+		
 		sf::Sprite sprite(_backgroundH.getTexture());
 		sf::Sprite sprite(_backgroundH.getTexture());
 		sprite.setScale(1.f, -1.f);
 		sprite.setScale(1.f, -1.f);
 		sprite.setOrigin(0, _context->window->getSize().y);
 		sprite.setOrigin(0, _context->window->getSize().y);
 		sprite.setPosition(0.f, 0.f);
 		sprite.setPosition(0.f, 0.f);
+
 		_backgroundV.draw(sprite, &_blurH);
 		_backgroundV.draw(sprite, &_blurH);
 
 
 		sf::Sprite sprite2(_backgroundV.getTexture());
 		sf::Sprite sprite2(_backgroundV.getTexture());
@@ -312,6 +324,7 @@ void IngameState::coreRender(const bool shaders)
 		sprite2.setPosition(0.f, 0.f);
 		sprite2.setPosition(0.f, 0.f);
 		_context->window->draw(sprite2, &_blurH);
 		_context->window->draw(sprite2, &_blurH);
 		_context->window->draw(_pauseFrame);
 		_context->window->draw(_pauseFrame);
+		
 		_context->window->draw(_wasted);
 		_context->window->draw(_wasted);
 		_context->window->draw(_statsTime);
 		_context->window->draw(_statsTime);
 		_context->window->draw(_statsHull);
 		_context->window->draw(_statsHull);
@@ -322,14 +335,15 @@ void IngameState::coreRender(const bool shaders)
 		_context->window->setView(_camera.getView());
 		_context->window->setView(_camera.getView());
 		_context->window->draw(_background);
 		_context->window->draw(_background);
 		
 		
-		
-		_foreground.renderNormals(true);
-		_lightSystem.normalsTargetSetView(*_camera.getView());
-		_lightSystem.normalsTargetClear();
-		_lightSystem.normalsTargetDraw(_foreground);
-		_lightSystem.normalsTargetDisplay();
-		_lightSystem.render(*_camera.getView(), _unshadowShader, _lightOverShapeShader, _normalsShader);
-		
+		if(_context->shaders)
+		{
+			_foreground.renderNormals(true);
+			_lightSystem.normalsTargetSetView(*_camera.getView());
+			_lightSystem.normalsTargetClear();
+			_lightSystem.normalsTargetDraw(_foreground);
+			_lightSystem.normalsTargetDisplay();
+			_lightSystem.render(*_camera.getView(), _unshadowShader, _lightOverShapeShader, _normalsShader);
+		}
 		
 		
 		_foreground.renderNormals(false);
 		_foreground.renderNormals(false);
 		_context->window->draw(_foreground);
 		_context->window->draw(_foreground);
@@ -337,15 +351,24 @@ void IngameState::coreRender(const bool shaders)
 			_context->window->draw(_star[i]);
 			_context->window->draw(_star[i]);
 		_context->window->draw(_wormhole);
 		_context->window->draw(_wormhole);
 		_context->window->draw(_player);
 		_context->window->draw(_player);
-		
-		
 		_context->window->setView();
 		_context->window->setView();
-		sf::Sprite sprite(_lightSystem.getLightingTexture());
-		sf::RenderStates lightRenderStates;
-		lightRenderStates.blendMode = sf::BlendMultiply;
-		_context->window->draw(sprite, lightRenderStates); 
-		
-		if(_paused)
+
+		if(_context->shaders)
+		{
+			sf::Sprite sprite(_lightSystem.getLightingTexture());
+			sf::RenderStates lightRenderStates;
+			lightRenderStates.blendMode = sf::BlendMultiply;
+			_context->window->draw(sprite, lightRenderStates); 
+		}
+		if(_player.isDead())
+		{
+			_context->window->draw(_pauseFrame);
+			_context->window->draw(_wasted);
+			_context->window->draw(_statsTime);
+			_context->window->draw(_statsHull);
+			_context->window->draw(_statsStars);
+		}
+		else if(_paused)
 			_context->window->draw(_pauseFrame);
 			_context->window->draw(_pauseFrame);
 	}
 	}
 }
 }

+ 3 - 1
src/IngameState.hpp

@@ -38,7 +38,7 @@ class IngameState: public State
 		void coreThink(const sf::Event& event) final;
 		void coreThink(const sf::Event& event) final;
 		void coreInput() final;
 		void coreInput() final;
 		void coreUpdate(sf::Time delta) final;
 		void coreUpdate(sf::Time delta) final;
-		void coreRender(const bool shaders) final;
+		void coreRender() final;
 
 
 	private:
 	private:
 		Player _player;
 		Player _player;
@@ -59,6 +59,8 @@ class IngameState: public State
 		sf::Shader _blurV;
 		sf::Shader _blurV;
 		sf::Shader _blurH;
 		sf::Shader _blurH;
 		
 		
+		sf::Sprite _noshaders;
+		
 		sf::Music _music;
 		sf::Music _music;
 		
 		
 		float _blurSize;
 		float _blurSize;

+ 11 - 14
src/MenuState.cpp

@@ -46,11 +46,14 @@ void MenuState::init()
 	_music.setLoop(true);
 	_music.setLoop(true);
 	_music.play();
 	_music.play();
 	
 	
-	_waterSine.loadFromFile("data/shaders/water.vs", sf::Shader::Fragment);
-	_waterMap.create(1920, 1080);
+	if(sf::Shader::isAvailable())
+	{
+		_waterSine.loadFromFile("data/shaders/water.vs", sf::Shader::Fragment);
+		_waterMap.create(1920, 1080);
 
 
-	_waterFrag.loadFromFile("data/shaders/water.frag", sf::Shader::Fragment);
-	_waterFrag.setParameter("heightmap", _waterMap.getTexture());
+		_waterFrag.loadFromFile("data/shaders/water.frag", sf::Shader::Fragment);
+		_waterFrag.setParameter("heightmap", _waterMap.getTexture());
+	}
 	
 	
 	_subStatus = Main;
 	_subStatus = Main;
 	
 	
@@ -100,6 +103,7 @@ void MenuState::init()
 
 
 void MenuState::refresh()
 void MenuState::refresh()
 {
 {
+	Echo::debug("Refreshing Menu.");
 	_crazy.create(_context->window->getSize().x, _context->window->getSize().y);
 	_crazy.create(_context->window->getSize().x, _context->window->getSize().y);
 	
 	
 	for(unsigned int i = 0; i < 30; ++i)
 	for(unsigned int i = 0; i < 30; ++i)
@@ -324,7 +328,7 @@ void MenuState::coreUpdate(sf::Time delta)
 	_quit.update(_context->window->getMousePosition(), delta);
 	_quit.update(_context->window->getMousePosition(), delta);
 }
 }
 
 
-void MenuState::coreRender(const bool shaders)
+void MenuState::coreRender()
 {
 {
 	//_crazy.clear(sf::Color(100, 150, 220));
 	//_crazy.clear(sf::Color(100, 150, 220));
 	_crazy.clear(_color);
 	_crazy.clear(_color);
@@ -334,16 +338,9 @@ void MenuState::coreRender(const bool shaders)
 
 
 	_waterMap.clear();
 	_waterMap.clear();
 	sf::RectangleShape rect(sf::Vector2f(1920.f, 1080.f));
 	sf::RectangleShape rect(sf::Vector2f(1920.f, 1080.f));
-	if(shaders)
-		_waterMap.draw(rect, &_waterSine);
-	else
-		_waterMap.draw(rect);
+	_waterMap.draw(rect, _context->shaders ? &_waterSine : sf::RenderStates::Default);
 	_waterMap.display();
 	_waterMap.display();
-
-	if(shaders)
-		_context->window->draw(crazy, &_waterFrag);
-	else
-		_context->window->draw(crazy);
+	_context->window->draw(crazy, _context->shaders ? &_waterFrag : sf::RenderStates::Default);
 		
 		
 	switch(_subStatus)
 	switch(_subStatus)
 	{
 	{

+ 1 - 1
src/MenuState.hpp

@@ -31,7 +31,7 @@ class MenuState: public State
 		void coreThink(const sf::Event& event) final;
 		void coreThink(const sf::Event& event) final;
 		void coreInput() final;
 		void coreInput() final;
 		void coreUpdate(sf::Time delta) final;
 		void coreUpdate(sf::Time delta) final;
-		void coreRender(const bool shaders) final;
+		void coreRender() final;
 
 
 	private:
 	private:
 		enum {
 		enum {

+ 1 - 1
src/State.hpp

@@ -43,7 +43,7 @@ class State
 		virtual void coreThink(const sf::Event& event) = 0;
 		virtual void coreThink(const sf::Event& event) = 0;
 		virtual void coreInput() = 0;
 		virtual void coreInput() = 0;
 		virtual void coreUpdate(sf::Time delta) = 0;
 		virtual void coreUpdate(sf::Time delta) = 0;
-		virtual void coreRender(const bool shaders) = 0;
+		virtual void coreRender() = 0;
 		const int status() const;
 		const int status() const;
 	protected:
 	protected:
 		Context* _context;
 		Context* _context;

+ 21 - 7
src/Triangles.cpp

@@ -16,10 +16,11 @@
  */
  */
 
 
 #include <sstream>
 #include <sstream>
+#ifdef __linux__
 #include <thread>
 #include <thread>
+#endif
 #include <fstream>
 #include <fstream>
 #include <iomanip>
 #include <iomanip>
-#include <codecvt>
 #include "Triangles.hpp"
 #include "Triangles.hpp"
 #include "IngameState.hpp"
 #include "IngameState.hpp"
 #include "MenuState.hpp"
 #include "MenuState.hpp"
@@ -36,7 +37,7 @@ Triangles::Triangles(int argc, char** argv):
 	_variables.vsync = false;
 	_variables.vsync = false;
 	_variables.running = true;
 	_variables.running = true;
 	_variables.needsUpdate = false;
 	_variables.needsUpdate = false;
-	_variables.shaders = true;
+	_variables.shaders = false;//true;//false;//true;//false;//sf::Shader::isAvailable();
 	_variables.nevermore = false;
 	_variables.nevermore = false;
 	_variables.window = &_window; 
 	_variables.window = &_window; 
 	_variables.assets = &_assets;
 	_variables.assets = &_assets;
@@ -79,17 +80,18 @@ void Triangles::init()
 	_loadingHints.push_back(L"There are two perfect things: chocolate and 45° isosceles triangle.");
 	_loadingHints.push_back(L"There are two perfect things: chocolate and 45° isosceles triangle.");
 	_loadingHints.push_back(L"Si les trangles faisaient un dieu, ils lui donneraient trois cótés. — Montesquieu");
 	_loadingHints.push_back(L"Si les trangles faisaient un dieu, ils lui donneraient trois cótés. — Montesquieu");
 	_loadingHints.push_back(L"Triangles do not have speed caps, but you will hit the wall eventually.");
 	_loadingHints.push_back(L"Triangles do not have speed caps, but you will hit the wall eventually.");
-	_loadingHints.push_back(L"when patafour pls owocek you lazy piece of shit");
+	_loadingHints.push_back(L"when patafour pls owocek you lazy piece of shit");
 	_loadingHints.push_back(L"Hit left control to switch light types.");
 	_loadingHints.push_back(L"Hit left control to switch light types.");
 	_loadingHints.push_back(L"S=√(p(p-a)(p-b)(p-c))");
 	_loadingHints.push_back(L"S=√(p(p-a)(p-b)(p-c))");
 	_loadingHints.push_back(L"S=12141px²");
 	_loadingHints.push_back(L"S=12141px²");
 	_loadingHints.push_back(L"Positive vibes. PMA. Positive mental attitude.");
 	_loadingHints.push_back(L"Positive vibes. PMA. Positive mental attitude.");
 	_loadingHints.push_back(L"You can lose up to 4856.4px.");
 	_loadingHints.push_back(L"You can lose up to 4856.4px.");
 	_loadingHints.push_back(L"Wasted.");
 	_loadingHints.push_back(L"Wasted.");
-	_loadingHints.push_back(L"Ah, the Scalene Triangle");
+	_loadingHints.push_back(L"Ah, the Scalene Triangle.");
 	_loadingHints.push_back(L"Δ");
 	_loadingHints.push_back(L"Δ");
 	_loadingHints.push_back(L"Δ\nΔ Δ");
 	_loadingHints.push_back(L"Δ\nΔ Δ");
-	_loadingHints.push_back(L"The stars act as consolation prizes if you go in the wrong direction.");
+	_loadingHints.push_back(L"Segmentation fault (core dumped)");
+	_loadingHints.push_back(L"The stars act as consolation prizes when you go in the wrong direction.");
 	_loadingHints.push_back(L"[](){}(); [](){}(); [](){}();");
 	_loadingHints.push_back(L"[](){}(); [](){}(); [](){}();");
 }
 }
 
 
@@ -258,15 +260,27 @@ void Triangles::load(int stateType)
 	_window.lockFramerate(true);
 	_window.lockFramerate(true);
 	_window.setActive(false);
 	_window.setActive(false);
 
 
+	#ifdef __linux__
 	std::thread t1(&Triangles::loadingRender, this);
 	std::thread t1(&Triangles::loadingRender, this);
 	std::thread t2(&State::init, _current);
 	std::thread t2(&State::init, _current);
 	
 	
 	t1.join();
 	t1.join();
 	t2.join();
 	t2.join();
+	#else 
+	sf::Thread t1(&Triangles::loadingRender, this);
+	sf::Thread t2(&State::init, _current);
+
+	t1.launch();
+	t2.launch();
+
+	t1.wait();
+	t2.wait();
+	#endif
 	
 	
 	_window.lockFramerate(false);
 	_window.lockFramerate(false);
 	
 	
 	_current->refresh();
 	_current->refresh();
+	_window.recreate();
 	
 	
 	Echo::debug("Done.");
 	Echo::debug("Done.");
 }
 }
@@ -278,7 +292,7 @@ int Triangles::run()
 	
 	
 	if(_context.running)
 	if(_context.running)
 	{
 	{
-		Echo::out(Echo::Empty, "Triangles version -0.8.8");
+		Echo::out(Echo::Empty, "Triangles version -0.7.9");
 		Echo::out(Echo::Empty, "Copyright (C) 2016 POSITIVE MENTAL ATTITUDE");
 		Echo::out(Echo::Empty, "Copyright (C) 2016 POSITIVE MENTAL ATTITUDE");
 		Echo::out(Echo::Empty, "This program comes with ABSOLUTELY NO WARRANTY;");
 		Echo::out(Echo::Empty, "This program comes with ABSOLUTELY NO WARRANTY;");
 		Echo::out(Echo::Empty, "This is free software, and you are welcome to redistribute it");
 		Echo::out(Echo::Empty, "This is free software, and you are welcome to redistribute it");
@@ -399,7 +413,7 @@ void Triangles::loadingRender()
 void Triangles::coreRender()
 void Triangles::coreRender()
 {
 {
 	_window.clear();
 	_window.clear();
-	_current->coreRender(_variables.shaders);
+	_current->coreRender();
 	#ifdef TRIANGLES_DEBUG 
 	#ifdef TRIANGLES_DEBUG 
 	_window.draw(_fpsRect);
 	_window.draw(_fpsRect);
 	_window.draw(_fps);
 	_window.draw(_fps);

+ 2 - 0
src/main.cpp

@@ -16,7 +16,9 @@
  */
  */
 
 
 #include "Triangles.hpp"
 #include "Triangles.hpp"
+#ifdef __linux__ 
 #include <X11/Xlib.h>
 #include <X11/Xlib.h>
+#endif
 
 
 /**
 /**
  * @brief The Triangles class holds everything.
  * @brief The Triangles class holds everything.