commit e94af580
Start running astyle on "sago" lib
Changed files
diff --git a/source/code/sago/GameStateInterface.hpp b/source/code/sago/GameStateInterface.hpp
index 3cb0067..2e86782 100644
--- a/source/code/sago/GameStateInterface.hpp
+++ b/source/code/sago/GameStateInterface.hpp
@@ -36,17 +36,17 @@ public:
* @return true if active
*/
virtual bool IsActive() = 0;
-
+
/**
* Tells the state to draw itself to target
* @param target The RenderWindow to draw to
*/
virtual void Draw(SDL_Renderer* target) = 0;
-
- virtual void ProcessInput(const SDL_Event& event, bool &processed) = 0;
-
+
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) = 0;
+
virtual void Update() {}
-
+
virtual ~GameStateInterface() {}
};
diff --git a/source/code/sago/SagoDataHolder.cpp b/source/code/sago/SagoDataHolder.cpp
index 9fc5a5f..cb2ce7f 100644
--- a/source/code/sago/SagoDataHolder.cpp
+++ b/source/code/sago/SagoDataHolder.cpp
@@ -245,7 +245,7 @@ Uint64 SagoDataHolder::getVersion() const {
return data->version;
}
-TextureHandler::TextureHandler(const SagoDataHolder* holder, const std::string &textureName) {
+TextureHandler::TextureHandler(const SagoDataHolder* holder, const std::string& textureName) {
this->holder = holder;
this->version = 0;
this->textureName = textureName;
@@ -292,15 +292,15 @@ Mix_Chunk* SoundHandler::get() {
}
-TextureHandler SagoDataHolder::getTextureHandler(const std::string &textureName) const {
+TextureHandler SagoDataHolder::getTextureHandler(const std::string& textureName) const {
return TextureHandler(this, textureName);
}
-MusicHandler SagoDataHolder::getMusicHandler(const std::string &musicName) const {
+MusicHandler SagoDataHolder::getMusicHandler(const std::string& musicName) const {
return MusicHandler(this, musicName);
}
-SoundHandler SagoDataHolder::getSoundHandler(const std::string &soundName) const {
+SoundHandler SagoDataHolder::getSoundHandler(const std::string& soundName) const {
return SoundHandler(this, soundName);
}
diff --git a/source/code/sago/SagoDataHolder.hpp b/source/code/sago/SagoDataHolder.hpp
index 9fbd9cd..377b51b 100644
--- a/source/code/sago/SagoDataHolder.hpp
+++ b/source/code/sago/SagoDataHolder.hpp
@@ -30,7 +30,7 @@ SOFTWARE.
#include <string>
#ifndef TEXTUREHOLDER_HPP
-#define TEXTUREHOLDER_HPP
+#define TEXTUREHOLDER_HPP
namespace sago {
@@ -39,7 +39,7 @@ class SagoDataHolder;
class TextureHandler {
public:
TextureHandler() {};
- TextureHandler(const SagoDataHolder* holder, const std::string &textureName);
+ TextureHandler(const SagoDataHolder* holder, const std::string& textureName);
SDL_Texture* get();
private:
std::string textureName;
@@ -52,7 +52,7 @@ private:
class MusicHandler final {
public:
MusicHandler() {};
- MusicHandler(const SagoDataHolder* holder, const std::string &musicName);
+ MusicHandler(const SagoDataHolder* holder, const std::string& musicName);
Mix_Music* get();
private:
std::string musicName;
@@ -65,7 +65,7 @@ private:
class SoundHandler final {
public:
SoundHandler() {};
- SoundHandler(const SagoDataHolder* holder, const std::string &soundName);
+ SoundHandler(const SagoDataHolder* holder, const std::string& soundName);
Mix_Chunk* get();
private:
std::string soundName;
@@ -88,14 +88,14 @@ public:
* @param textureName Name of the texture
* @return Pointer to the loaded texture
*/
- SDL_Texture* getTexturePtr(const std::string &textureName) const;
-
- TextureHandler getTextureHandler(const std::string &textureName) const;
- TTF_Font* getFontPtr(const std::string &fontName, int ptsize) const;
- Mix_Music* getMusicPtr(const std::string &musicName) const;
- MusicHandler getMusicHandler(const std::string &musicName) const;
- Mix_Chunk* getSoundPtr(const std::string &soundName) const;
- SoundHandler getSoundHandler(const std::string &soundName) const;
+ SDL_Texture* getTexturePtr(const std::string& textureName) const;
+
+ TextureHandler getTextureHandler(const std::string& textureName) const;
+ TTF_Font* getFontPtr(const std::string& fontName, int ptsize) const;
+ Mix_Music* getMusicPtr(const std::string& musicName) const;
+ MusicHandler getMusicHandler(const std::string& musicName) const;
+ Mix_Chunk* getSoundPtr(const std::string& soundName) const;
+ SoundHandler getSoundHandler(const std::string& soundName) const;
void setVerbose(bool value);
/**
@@ -123,10 +123,10 @@ private:
SagoDataHolder(const SagoDataHolder& base) = delete;
SagoDataHolder& operator=(const SagoDataHolder& base) = delete;
struct SagoDataHolderData;
- mutable SagoDataHolderData *data;
+ mutable SagoDataHolderData* data;
};
} //namespace sago
-#endif /* TEXTUREHOLDER_HPP */
+#endif /* TEXTUREHOLDER_HPP */
diff --git a/source/code/sago/SagoMisc.hpp b/source/code/sago/SagoMisc.hpp
index 347bc75..89a75e9 100644
--- a/source/code/sago/SagoMisc.hpp
+++ b/source/code/sago/SagoMisc.hpp
@@ -23,7 +23,7 @@ SOFTWARE.
*/
#ifndef SAGOMISC_HPP
-#define SAGOMISC_HPP
+#define SAGOMISC_HPP
#include <vector>
#include <string>
@@ -31,53 +31,55 @@ SOFTWARE.
namespace sago {
- /**
- * Returns a vector with all filenames in a given directory.
- * PHYSFS must be setup before hand. The directory is relative to the PHYSFS base
- * @param dir The directory to list
- * @return A vector with the filenames in the given directory. If empty the directory was empty or did not exist
- */
- std::vector<std::string> GetFileList(const char* dir);
-
- /**
- * Reads an entire file into memory.
- * PHYSFS must be setup before hand
- * @param filename The file to read
- * @param dest The unique pointer in which the bytes will be written
- * @param bytes Number of bytes written
- * @return The content of the file. If empty either the file was empty, did not exist or could not be opened
- */
- void ReadBytesFromFile(const char* filename, std::unique_ptr<char[]>& dest, unsigned int& bytes);
-
- /**
- * Reads an entire file into memory.
- * PHYSFS must be setup before hand
- * @param filename The file to read
- * @return The content of the file. If empty either the file was empty, did not exist or could not be opened
- */
- std::string GetFileContent(const char* filename);
-
- /**
- * Reads an entire file into memory.
- * PHYSFS must be setup before hand
- * @param filename The file to read
- * @return The content of the file. If empty either the file was empty, did not exist or could not be opened
- */
- inline std::string GetFileContent(const std::string& filename) { return GetFileContent(filename.c_str()); };
-
- bool FileExists(const char* filename);
-
- void WriteFileContent(const char* filename, const std::string& content);
-
- /**
- * This functions converts a string on a best effort basis
- * Unlike atol this does NOT cause undefined behavior if out of range
- * @param c_string A string that may contain a number
- * @return A number between LONG_MIN and LONG_MAX (both inclusive)
- */
- long int StrToLong(const char* c_string);
+/**
+ * Returns a vector with all filenames in a given directory.
+ * PHYSFS must be setup before hand. The directory is relative to the PHYSFS base
+ * @param dir The directory to list
+ * @return A vector with the filenames in the given directory. If empty the directory was empty or did not exist
+ */
+std::vector<std::string> GetFileList(const char* dir);
+
+/**
+ * Reads an entire file into memory.
+ * PHYSFS must be setup before hand
+ * @param filename The file to read
+ * @param dest The unique pointer in which the bytes will be written
+ * @param bytes Number of bytes written
+ * @return The content of the file. If empty either the file was empty, did not exist or could not be opened
+ */
+void ReadBytesFromFile(const char* filename, std::unique_ptr<char[]>& dest, unsigned int& bytes);
+
+/**
+ * Reads an entire file into memory.
+ * PHYSFS must be setup before hand
+ * @param filename The file to read
+ * @return The content of the file. If empty either the file was empty, did not exist or could not be opened
+ */
+std::string GetFileContent(const char* filename);
+
+/**
+ * Reads an entire file into memory.
+ * PHYSFS must be setup before hand
+ * @param filename The file to read
+ * @return The content of the file. If empty either the file was empty, did not exist or could not be opened
+ */
+inline std::string GetFileContent(const std::string& filename) {
+ return GetFileContent(filename.c_str());
+};
+
+bool FileExists(const char* filename);
+
+void WriteFileContent(const char* filename, const std::string& content);
+
+/**
+ * This functions converts a string on a best effort basis
+ * Unlike atol this does NOT cause undefined behavior if out of range
+ * @param c_string A string that may contain a number
+ * @return A number between LONG_MIN and LONG_MAX (both inclusive)
+ */
+long int StrToLong(const char* c_string);
} //namespace sago
-#endif /* SAGOMISC_HPP */
+#endif /* SAGOMISC_HPP */
diff --git a/source/code/sago/SagoMiscSdl2.hpp b/source/code/sago/SagoMiscSdl2.hpp
index 1bc115b..c2d700b 100644
--- a/source/code/sago/SagoMiscSdl2.hpp
+++ b/source/code/sago/SagoMiscSdl2.hpp
@@ -26,20 +26,20 @@ SOFTWARE.
#define SAGOMISCSDL2_HPP
namespace sago {
-
- /**
- * Writes an error message to the screen and aborts the program
- * @param errorMsg The message displayed in a pop-up box to the user.
- */
- void SagoFatalError(const char* errorMsg);
-
- /**
- * Writes an error message to the screen and aborts the program
- * @param fmt A printf-style format string
- * @param ... Parameters to the format string
- */
- void SagoFatalErrorF(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
-
+
+/**
+ * Writes an error message to the screen and aborts the program
+ * @param errorMsg The message displayed in a pop-up box to the user.
+ */
+void SagoFatalError(const char* errorMsg);
+
+/**
+ * Writes an error message to the screen and aborts the program
+ * @param fmt A printf-style format string
+ * @param ... Parameters to the format string
+ */
+void SagoFatalErrorF(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
+
}
#endif /* SAGOMISCSDL2_HPP */
diff --git a/source/code/sago/SagoSprite.hpp b/source/code/sago/SagoSprite.hpp
index 742cf76..57c4e17 100644
--- a/source/code/sago/SagoSprite.hpp
+++ b/source/code/sago/SagoSprite.hpp
@@ -23,7 +23,7 @@ SOFTWARE.
*/
#ifndef SAGOSPRITE_HPP
-#define SAGOSPRITE_HPP
+#define SAGOSPRITE_HPP
#include "SagoDataHolder.hpp"
@@ -32,7 +32,7 @@ namespace sago {
class SagoSprite final {
public:
SagoSprite();
- SagoSprite(const SagoDataHolder &texHolder, const std::string &texture,const SDL_Rect& initImage,const int animationFrames, const int animationFrameLength);
+ SagoSprite(const SagoDataHolder& texHolder, const std::string& texture,const SDL_Rect& initImage,const int animationFrames, const int animationFrameLength);
/**
* Draws the sprite to a given render window
@@ -59,7 +59,7 @@ public:
* @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
* @param x Place to draw the sprite
* @param y Place to draw the sprite
- * @param part the part of the sprite that should be drawn.
+ * @param part the part of the sprite that should be drawn.
*/
void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& part) const;
@@ -72,7 +72,7 @@ public:
* @param bounds A recagular area that we must not draw outside.
*/
void DrawBounded(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& bounds) const;
-
+
/**
* Draws the sprite to a given render window
* @param target The render window to draw on
@@ -84,11 +84,11 @@ public:
void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h) const;
void DrawScaledAndRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h,
- const double angleRadian, const SDL_Point* center, const SDL_RendererFlip flip) const;
+ const double angleRadian, const SDL_Point* center, const SDL_RendererFlip flip) const;
/**
* Set a different origin. Normally it is the top left cornor. But in some cases you might want to center the origin or tranform it for other reasons
- * @param newOrigin the coordinates that should be the new origin. Call with {0,0} to reset to default
+ * @param newOrigin the coordinates that should be the new origin. Call with {0,0} to reset to default
*/
void SetOrigin(const SDL_Rect& newOrigin);
SagoSprite(const SagoSprite& base);
@@ -98,10 +98,10 @@ public:
~SagoSprite();
private:
struct SagoSpriteData;
- SagoSpriteData *data;
+ SagoSpriteData* data;
};
}
-#endif /* SAGOSPRITE_HPP */
+#endif /* SAGOSPRITE_HPP */
diff --git a/source/code/sago/SagoSpriteHolder.hpp b/source/code/sago/SagoSpriteHolder.hpp
index be76b51..830ca81 100644
--- a/source/code/sago/SagoSpriteHolder.hpp
+++ b/source/code/sago/SagoSpriteHolder.hpp
@@ -23,7 +23,7 @@ SOFTWARE.
*/
#ifndef SAGOSPRITEHOLDER_HPP
-#define SAGOSPRITEHOLDER_HPP
+#define SAGOSPRITEHOLDER_HPP
#include "SagoDataHolder.hpp"
#include "SagoSprite.hpp"
@@ -33,7 +33,7 @@ namespace sago {
class SagoSpriteHolder final {
public:
- explicit SagoSpriteHolder(const SagoDataHolder &texHolder);
+ explicit SagoSpriteHolder(const SagoDataHolder& texHolder);
~SagoSpriteHolder();
/**
* Reads all the sprites from the "sprites" directory in alphabetical order
@@ -43,17 +43,17 @@ public:
* Reads an additional sprites. Used to append mod data.
**/
void ReadSprites(const std::vector<std::string>& extra_sprites);
- const sago::SagoSprite& GetSprite(const std::string &spritename) const;
+ const sago::SagoSprite& GetSprite(const std::string& spritename) const;
const SagoDataHolder& GetDataHolder() const;
private:
SagoSpriteHolder(const SagoSpriteHolder& base) = delete;
SagoSpriteHolder& operator=(const SagoSpriteHolder& base) = delete;
- void ReadSpriteFile(const std::string &filename);
+ void ReadSpriteFile(const std::string& filename);
struct SagoSpriteHolderData;
- SagoSpriteHolderData *data;
+ SagoSpriteHolderData* data;
};
}
-#endif /* SAGOSPRITEHOLDER_HPP */
+#endif /* SAGOSPRITEHOLDER_HPP */
diff --git a/source/code/sago/SagoTextBox.cpp b/source/code/sago/SagoTextBox.cpp
index 2f98a20..8ad56fb 100644
--- a/source/code/sago/SagoTextBox.cpp
+++ b/source/code/sago/SagoTextBox.cpp
@@ -161,14 +161,13 @@ void SagoTextBox::UpdateCache() {
std::cerr << "FATAL: SagoTextBox::UpdateCache - DataHolder not set!\n";
abort();
}
- TTF_Font *font = data->tex->getFontPtr(data->fontName, data->fontSize);
+ TTF_Font* font = data->tex->getFontPtr(data->fontName, data->fontSize);
const char delim = '\n';
const std::string& s = data->text;
auto start = 0U;
auto end = s.find(delim);
data->lines.clear();
- while (end != std::string::npos)
- {
+ while (end != std::string::npos) {
const std::string& theSubString = s.substr(start, end - start);
SplitAndAppendLineToCache(font, theSubString);
start = end + 1;
@@ -182,7 +181,7 @@ void SagoTextBox::Draw(SDL_Renderer* target, int x, int y, SagoTextField::Alignm
if (data->text != data->renderedText) {
UpdateCache();
}
- TTF_Font *font = data->tex->getFontPtr(data->fontName, data->fontSize);
+ TTF_Font* font = data->tex->getFontPtr(data->fontName, data->fontSize);
int lineSkip = TTF_FontLineSkip(font);
for (size_t i = 0; i < data->lines.size(); ++i) {
data->lines[i].Draw(target, x, y+i*lineSkip, alignment);
diff --git a/source/code/sago/SagoTextBox.hpp b/source/code/sago/SagoTextBox.hpp
index c1df5cc..6882006 100644
--- a/source/code/sago/SagoTextBox.hpp
+++ b/source/code/sago/SagoTextBox.hpp
@@ -38,7 +38,7 @@ public:
void SetText(const char* text);
void SetText(const std::string& text);
void SetColor(const SDL_Color& color);
-
+
/**
* Set the name of the font. Must be known to the data holder.
* The name could for instance be "freeserif".
@@ -47,7 +47,7 @@ public:
void SetFont(const char* fontName);
void SetFontSize(int fontSize);
void SetOutline(int outlineSize, const SDL_Color& color);
-
+
/**
* Sets the max width to generate. SagoTextBox will insert line breaks to keep the width below this number.
* Outline is not included in the width: If you have a 2 pixels outline the rendere may go 2 pixels beyond.
@@ -65,7 +65,7 @@ private:
SagoTextBox(const SagoTextBox& orig) = delete;
SagoTextBox& operator=(const SagoTextBox& base) = delete;
struct SagoTextBoxData;
- SagoTextBoxData *data;
+ SagoTextBoxData* data;
};
} //namespace sago
diff --git a/source/code/sago/SagoTextField.cpp b/source/code/sago/SagoTextField.cpp
index 666de12..85e63fa 100644
--- a/source/code/sago/SagoTextField.cpp
+++ b/source/code/sago/SagoTextField.cpp
@@ -28,36 +28,36 @@ SOFTWARE.
namespace sago {
- class OutlineHandler {
- TTF_Font* font;
- int originalOutline = 0;
- int targetOutline;
- bool doChange = false;
- public:
- OutlineHandler(TTF_Font* font, int outline) : font{font}, targetOutline{outline} {
- originalOutline = TTF_GetFontOutline(font);
- if (originalOutline == targetOutline) {
- return;
- }
- doChange = true;
- TTF_SetFontOutline(font, targetOutline);
- };
-
- void reset() {
- if (doChange) {
- TTF_SetFontOutline(font,originalOutline);
- doChange = false;
- }
+class OutlineHandler {
+ TTF_Font* font;
+ int originalOutline = 0;
+ int targetOutline;
+ bool doChange = false;
+public:
+ OutlineHandler(TTF_Font* font, int outline) : font{font}, targetOutline{outline} {
+ originalOutline = TTF_GetFontOutline(font);
+ if (originalOutline == targetOutline) {
+ return;
}
-
- ~OutlineHandler() {
- reset();
- }
- private:
- OutlineHandler(const OutlineHandler& orig) = delete;
- OutlineHandler& operator=(const OutlineHandler& base) = delete;
+ doChange = true;
+ TTF_SetFontOutline(font, targetOutline);
};
-
+
+ void reset() {
+ if (doChange) {
+ TTF_SetFontOutline(font,originalOutline);
+ doChange = false;
+ }
+ }
+
+ ~OutlineHandler() {
+ reset();
+ }
+private:
+ OutlineHandler(const OutlineHandler& orig) = delete;
+ OutlineHandler& operator=(const OutlineHandler& base) = delete;
+};
+
struct SagoTextField::SagoTextFieldData {
const sago::SagoDataHolder* tex = nullptr;
SDL_Surface* textSurface = nullptr;
@@ -73,7 +73,7 @@ struct SagoTextField::SagoTextFieldData {
std::string renderedText = "";
Uint64 renderedVersion = 0;
};
-
+
SagoTextField::SagoTextField() {
data = new SagoTextFieldData();
}
@@ -93,14 +93,15 @@ SagoTextField& SagoTextField::CopyFrom(const SagoTextField& base) {
data->textSurface = nullptr;
data->texture = nullptr;
return *this;
- } catch (...) {
+ }
+ catch (...) {
delete data;
throw;
}
}
SagoTextField::~SagoTextField() {
- if(!data) {
+ if (!data) {
return;
}
ClearCache();
@@ -165,7 +166,7 @@ void SagoTextField::UpdateCache(SDL_Renderer* target) {
abort();
}
ClearCache();
- TTF_Font *font = data->tex->getFontPtr(data->fontName, data->fontSize);
+ TTF_Font* font = data->tex->getFontPtr(data->fontName, data->fontSize);
data->textSurface = TTF_RenderUTF8_Blended (font, data->text.c_str(), data->color);
data->texture = SDL_CreateTextureFromSurface(target, data->textSurface);
if (data->outline > 0) {
@@ -179,7 +180,7 @@ void SagoTextField::UpdateCache(SDL_Renderer* target) {
}
void SagoTextField::GetRenderedSize(const char* text, int* w, int* h) {
- TTF_Font *font = data->tex->getFontPtr(data->fontName, data->fontSize);
+ TTF_Font* font = data->tex->getFontPtr(data->fontName, data->fontSize);
int ret = TTF_SizeUTF8(font, text, w, h);
if (ret) {
if (w) {
diff --git a/source/code/sago/SagoTextField.hpp b/source/code/sago/SagoTextField.hpp
index d28114c..c97846f 100644
--- a/source/code/sago/SagoTextField.hpp
+++ b/source/code/sago/SagoTextField.hpp
@@ -33,7 +33,7 @@ namespace sago {
* This is a text field.
* It represents a line of text to be drawn on screen. It is not possible to have line breaks.
* If line breaks are needed use SagoTextBox instead.
- *
+ *
* This object renderes to a texture and cahces the texture. The texture will be automatically refreshed if the text changes, the SagoDataHolder is invalidated or ClearCache is called.
* Normally all values will be set at the beginning before text is drawn.
* SetHolder MUST be called before the field is drawn!
@@ -49,7 +49,7 @@ public:
/**
* This method creates a copy of a given font.
* The cache will not be copied.
- * This is ALMOST like the "= operator" but given its own name to prevent implicit calling.
+ * This is ALMOST like the "= operator" but given its own name to prevent implicit calling.
* @param base The object to copy from
* @return A reference to this object.
*/
@@ -128,7 +128,7 @@ public:
private:
SagoTextField(const SagoTextField& orig) = delete;
struct SagoTextFieldData;
- SagoTextFieldData *data;
+ SagoTextFieldData* data;
};
} //namespace sago
diff --git a/source/misc/astyle/runAstyle.sh b/source/misc/astyle/runAstyle.sh
index 00e1bf7..91eb459 100755
--- a/source/misc/astyle/runAstyle.sh
+++ b/source/misc/astyle/runAstyle.sh
@@ -1,2 +1,4 @@
#! /bin/bash
astyle -t -j -y -c -k1 -z2 -A2 --pad-header ../../code/*.cpp
+astyle -t -j -y -c -k1 -z2 -A2 --pad-header ../../code/sago/*.cpp
+astyle -t -j -y -c -k1 -z2 -A2 --pad-header ../../code/sago/*.hpp