POSITIVE-MENTAL-ATTITUDE 9 years ago
parent
commit
177fb2c996
8 changed files with 70 additions and 60 deletions
  1. 3 3
      src/Assets.cpp
  2. 4 0
      src/Context.hpp
  3. 6 4
      src/Player.cpp
  4. 31 13
      src/Triangles.cpp
  5. 10 4
      src/TrianglesWindow.cpp
  6. 3 3
      src/TrianglesWindow.hpp
  7. 6 13
      src/Utility.cpp
  8. 7 20
      src/Utility.hpp

+ 3 - 3
src/Assets.cpp

@@ -31,7 +31,7 @@ sf::Texture& Assets::loadTexture(std::string file)
 	{
 		sf::Texture texture;
 		if(!texture.loadFromFile(file))
-			Echo::out(Echo::Error, "Unable to load texture file: ", file, "\nExpect a segfault!");
+			Echo::error("Unable to load texture file: ", file, "\nExpect a segfault!");
 		texture.setSmooth(true);
 		textures.emplace(file, texture);
 	}
@@ -44,7 +44,7 @@ sf::SoundBuffer& Assets::loadSound(std::string file)
 	{
 		sf::SoundBuffer sound;
 		if(!sound.loadFromFile(file))
-			Echo::out(Echo::Error, "Unable to load sound file: ", file, "\nExpect a segfault!");
+			Echo::error("Unable to load sound file: ", file, "\nExpect a segfault!");
 		sound.loadFromFile(file);
 		sounds.emplace(file, sound);
 	}
@@ -57,7 +57,7 @@ sf::Font& Assets::loadFont(std::string file)
 	{
 		sf::Font font;
 		if(!font.loadFromFile(file))
-			Echo::out(Echo::Error, "Unable to load font file: ", file, "\nExpect a segfault!");
+			Echo::error("Unable to load font file: ", file, "\nExpect a segfault!");
 		fonts.emplace(file, font);
 	}
 	return fonts.at(file);

+ 4 - 0
src/Context.hpp

@@ -33,6 +33,10 @@ struct Context
 	bool nevermore;
 	bool mustRecreate;
 	
+	int versionMajor;
+	int versionMinor;
+	int versionBuild;
+	
 	Assets* assets;
 	TrianglesWindow* window;
 	Triangles* core;

+ 6 - 4
src/Player.cpp

@@ -25,9 +25,9 @@ Player::Player():
 	Collidable(),
 	Lantern(),
 	_movement(0.f), 
-	_movementSpeed(0.6f), 
+	_movementSpeed(0.8f), 
 	_movementMomentum(0.f),
-	_movementAcceleration(7.f),
+	_movementAcceleration(10.f),
 	_movementSuppresion(10.f),
 	_rotation(0.f), 
 	_rotationSpeed(0.6f), 
@@ -74,7 +74,9 @@ Player::Player():
 	}); 
 	bind(2, [this](const sf::Event&, float power)
 	{
-		_movement -= power * 0.8f;
+		if(_movementMomentum > 0.f)
+			_movement -= power;
+		_movement -= power * 0.75f;
 	});
 	bind(3, [this](const sf::Event&, float power)
 	{
@@ -139,7 +141,7 @@ Player::Player():
 	_bullets.reserve(10);
 	_bulletTimer.restart();
 	 
-	_durability = 0.4f;
+	_durability = 0.5f;
 
 	light()->_emissionSprite.setColor(sf::Color::White);
 }

+ 31 - 13
src/Triangles.cpp

@@ -15,6 +15,7 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <GL/gl.h>
 #include <sstream>
 #include <thread>
 #include <fstream>
@@ -23,14 +24,15 @@
 #include "IngameState.hpp"
 #include "MenuState.hpp"
 #include "Utility.hpp"
-#include <GL/gl.h>
 
 Triangles::Triangles(int argc, char** argv):
 	_returnCode(0),
-	_window("Triangles", sf::Vector2u(640u, 480u)),
 	_current(nullptr),
 	_initialState(State::Menu)
 {
+	_variables.versionMajor = 0;
+	_variables.versionMinor = 0;
+	_variables.versionBuild = 8;
 	_variables.fullscreen = false;
 	_variables.borderless = false;
 	_variables.vsync = true;
@@ -42,14 +44,19 @@ Triangles::Triangles(int argc, char** argv):
 	_variables.assets = &_assets;
 	_variables.core = this;
 	_variables.foreground = nullptr;
+
 	/**
-	 * Shintel has bugs, so we detect if the graphics card is shintel iGPU.
+	 * Shintel has bugs on windows, so we detect if the graphics card is shintel iGPU.
 	 */
 	if(glGetString(GL_VENDOR)[0] == (unsigned char)'I')
 		_variables.mustRecreate = true;
 	else
 		_variables.mustRecreate = false;
 	
+	std::ostringstream oss;
+	oss << "Triangles v" << _variables.versionMajor << '.' << _variables.versionMinor << '.' << _variables.versionBuild;
+	_window.create(oss.str(), sf::Vector2u(640, 480));
+	
 	passArguments(argc, argv);
 	
 	if(_variables.running)
@@ -105,11 +112,7 @@ void Triangles::passArguments(int argc, char** argv)
 {
 	std::string argvStr[argc];
 	for(int i = 0; i < argc; ++i)
-	{
 		argvStr[i] = argv[i];
-		if(argvStr[i].size() < 2)
-			argvStr[i] = "--kaczka";
-	}
 	searchArgument(argc, argvStr, "f", "fullscreen", [this]()
 	{
 		_variables.fullscreen = true;
@@ -130,6 +133,19 @@ void Triangles::passArguments(int argc, char** argv)
 	{
 		_initialState = State::Ingame;
 	});
+	searchArgument(argc, argvStr, "l", "loglevel", [this](std::string param)
+	{
+		if(param == "0")
+			Echo::setLogLevel(0);
+		else if(param == "2") 
+			Echo::setLogLevel(2);
+		else if(param == "3") 
+			Echo::setLogLevel(3);
+		else if(param == "4")
+			Echo::setLogLevel(4);
+		else 
+			Echo::setLogLevel(1);
+	});
 	searchArgument(argc, argvStr, "sf", "skipfullscreen", [this]()
 	{
 		_initialState = State::Ingame;
@@ -276,8 +292,10 @@ void Triangles::load(int stateType)
 	
 	_current->refresh();
 
-	if(_variables.mustRecreate)
+	#ifndef __linux__
+	if(_variables.mustRecreate || stateType == State::Menu)
 		_window.recreate();
+	#endif
 
 	Echo::debug("Done.");
 }
@@ -289,11 +307,11 @@ int Triangles::run()
 	
 	if(_context.running)
 	{
-		Echo::out(Echo::Empty, "Triangles version 0.0.6");
-		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 is free software, and you are welcome to redistribute it");
-		Echo::out(Echo::Empty, "under certain conditions; see LICENSE file");
+		Echo::out("Triangles version ", _variables.versionMajor, '.', _variables.versionMinor, '.', _variables.versionBuild);
+		Echo::out("Copyright (C) 2016 POSITIVE MENTAL ATTITUDE");
+		Echo::out("This program comes with ABSOLUTELY NO WARRANTY;");
+		Echo::out("This is free software, and you are welcome to redistribute it");
+		Echo::out("under certain conditions; see LICENSE file");
 	}
 	
 	/**

+ 10 - 4
src/TrianglesWindow.cpp

@@ -19,10 +19,10 @@
 #include "InputTarget.hpp"
 #include "Utility.hpp"
 
-TrianglesWindow::TrianglesWindow(const std::string& title, sf::Vector2u size):
+TrianglesWindow::TrianglesWindow():
 	InputTarget(_inputMap),
-	_size(size),
-	_title(title),
+	_title("Triangles"),
+	_size(sf::Vector2u(640u, 480u)),
 	_mouseLocked(false)
 {
 	_context = nullptr;
@@ -67,6 +67,12 @@ TrianglesWindow::~TrianglesWindow()
 	close();
 }
 
+void TrianglesWindow::create(const std::string& title, sf::Vector2u size)
+{
+	_size = size;
+	_title = title;
+}
+
 void TrianglesWindow::setContext(Context* context)
 {
 	_context = context;
@@ -178,7 +184,7 @@ void TrianglesWindow::open()
 	sf::ContextSettings settings;
 	settings.majorVersion = 1;
 	settings.minorVersion = 1;
-	//settings.antialiasingLevel = 8;
+	settings.antialiasingLevel = 8;
 	_window.create(sf::VideoMode(_size.x, _size.y), _title, (_context->fullscreen ? sf::Style::Fullscreen : (_context->borderless ? sf::Style::None : (sf::Style::Titlebar | sf::Style::Close))), settings);
 	_window.setKeyRepeatEnabled(false);
 	if(_context->borderless)

+ 3 - 3
src/TrianglesWindow.hpp

@@ -25,10 +25,10 @@
 class TrianglesWindow: public InputTarget<int>
 {
 	public:
-		TrianglesWindow() = delete;
-		TrianglesWindow(const std::string& title, sf::Vector2u size);
-		~TrianglesWindow();
+		TrianglesWindow();
+		virtual ~TrianglesWindow();
 		
+		void create(const std::string& title, sf::Vector2u size);
 		void clear();
 		void clear(sf::Color color);
 		void render();

+ 6 - 13
src/Utility.cpp

@@ -31,28 +31,28 @@ bool Echo::printType(int order)
 		case Error: 
 			if(_loglevel >= 1)
 			{
-				std::cerr << "Error: ";
+				std::cerr << "[Error] ";
 				return true;
 			}
 			return false;
 		case Info: 
 			if(_loglevel >= 2)
 			{
-				std::cout << "PSA: ";
+				std::cout << "[PSA] ";
 				return true;
 			}
 			return false;
 		case Load: 
 			if(_loglevel >= 3)
 			{
-				std::cout << "Loaded ";
+				std::cout << "[Loaded] ";
 				return true;
 			}
 			return false;
 		case Debug:
 			if(_loglevel >= 4)
 			{
-				std::cout << "Debug: ";
+				std::cout << "[Debug] ";
 				return true;
 			}
 			return false;
@@ -71,14 +71,7 @@ void Echo::helper(bool err, std::wstring out)
 		std::wcout << out;
 }
 
-void Echo::out(std::string debug)
+void Echo::setLogLevel(int loglevel)
 {
-	if(!printType(Debug))
-		std::printf("%s", &debug[0]);
-}
-
-void Echo::out(float debug)
-{
-	if(printType(Debug))
-		std::printf("%f\n", debug);
+	_loglevel = loglevel;
 }

+ 7 - 20
src/Utility.hpp

@@ -49,7 +49,7 @@ class Echo
 		Echo() = default;
 		
 		template<typename Type, typename... Args>
-		static void out(int prefix, Type out, Args... args);
+		static void out(Type out, Args... args);
 		
 		template<typename Type, typename... Args>
 		static void debug(Type out, Args... args);
@@ -63,9 +63,7 @@ class Echo
 		template<typename Type, typename... Args>
 		static void error(Type out, Args... args);
 
-		static void out(std::string debug);
-		static void out(float debug);
-		static void setLogLevel(int loglevel);
+		static void setLogLevel(int loglevel); static int _loglevel;
 
 	private:
 		static void helper(bool err, std::wstring out);
@@ -78,7 +76,7 @@ class Echo
 
 		static bool printType(int order);
 		
-		static int _loglevel;
+		
 };
 
 template <typename Type>
@@ -102,21 +100,10 @@ void Echo::helper(bool err, const Type out, Args... args)
 }
 
 template<typename Type, typename... Args>
-void Echo::out(int order, Type out, Args... args)
+void Echo::out(Type out, Args... args)
 {
-	if(!printType(order))
-		return;
-
-	if(order == Error)
-	{
-		helper(true, out, args...);
-		std::cerr << std::endl;
-	}
-	else
-	{
-		helper(false, out, args...);
-		std::cout << std::endl;
-	}
+	helper(false, out, args...);
+	std::cout << std::endl;
 }
 
 template<typename Type, typename... Args>
@@ -126,7 +113,7 @@ void Echo::debug(Type out, Args... args)
 		return;
 
 	helper(false, out, args...);
-	std::cout << std::endl;
+	std::putchar('\n');
 }
 
 template<typename Type, typename... Args>