git repos / saland

commit 5cc3e502

Poul Sander · 2019-08-05 14:01
5cc3e502d8d14cc12eb54b6babd2e73fe7da3f1b patch · browse files
parent 2d655a70c0b71c7bcfa646ecdfad51f876cde7e7

Add astyle script and run it.
Based on the one from Block Attack - Rise of the blocks
Also fixed the "quit"-command by adding a return

Changed files

A extra/runAstyle.sh
M src/os.hpp before
M src/sago/GameStateInterface.hpp before
M src/sago/SagoDataHolder.cpp before
M src/sago/SagoDataHolder.hpp before
M src/sago/SagoMisc.cpp before
M src/sago/SagoMisc.hpp before
M src/sago/SagoMiscSdl2.hpp before
M src/sago/SagoSprite.hpp before
M src/sago/SagoSpriteHolder.hpp before
M src/sago/SagoTextBox.cpp before
M src/sago/SagoTextBox.hpp before
M src/sago/SagoTextField.cpp before
M src/sago/SagoTextField.hpp before
M src/sago/platform_folders.cpp before
M src/saland.cpp before
M src/saland/Game.cpp before
M src/saland/Game.hpp before
M src/saland/GameConsoleCommand.cpp before
M src/saland/GameDraw.cpp before
M src/saland/GameDraw.hpp before
M src/saland/GameRegion.cpp before
M src/saland/GameRegion.hpp before
M src/saland/GameShop.cpp before
M src/saland/GameShop.hpp before
M src/saland/GameUpdates.cpp before
M src/saland/GameUpdates.hpp before
M src/saland/console/Console.cpp before
M src/saland/console/Console.hpp before
M src/saland/model/Player.hpp before
M src/saland/model/World.cpp before
M src/saland/model/placeables.hpp before
diff --git a/extra/runAstyle.sh b/extra/runAstyle.sh new file mode 100755 index 0000000..8cc717f --- /dev/null +++ b/extra/runAstyle.sh
@@ -0,0 +1,3 @@
+#! /bin/bash
+find ../src -not \( -path ../src/Libs -prune \) -name \*.cpp | xargs astyle -t -j -y -c -k1 -z2 -A2 --pad-header
+find ../src -not \( -path ../src/Libs -prune \) -name \*.hpp | xargs astyle -t -j -y -c -k1 -z2 -A2 --pad-header
diff --git a/src/os.hpp b/src/os.hpp index d1ea43c..5a3f681 100644 --- a/src/os.hpp +++ b/src/os.hpp
@@ -21,7 +21,7 @@ https://github.com/sago007/saland
===========================================================================
*/
-#if defined(_WIN32)
+#if defined(_WIN32)
#include "windows.h"
#include "shlobj.h"
#endif
diff --git a/src/sago/GameStateInterface.hpp b/src/sago/GameStateInterface.hpp index 3cb0067..2e86782 100644 --- a/src/sago/GameStateInterface.hpp +++ b/src/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/src/sago/SagoDataHolder.cpp b/src/sago/SagoDataHolder.cpp index f24f7e4..d88f940 100644 --- a/src/sago/SagoDataHolder.cpp +++ b/src/sago/SagoDataHolder.cpp
@@ -104,7 +104,7 @@ SDL_Texture* SagoDataHolder::getTexturePtr(const std::string& textureName) const
return ret;
}
std::string path = "textures/"+textureName+".png";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -145,7 +145,7 @@ TTF_Font* SagoDataHolder::getFontPtr(const std::string& fontName, int ptsize) co
return ret;
}
std::string path = "fonts/"+fontName+".ttf";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -188,7 +188,7 @@ Mix_Music* SagoDataHolder::getMusicPtr(const std::string& musicName) const {
return ret;
}
std::string path = "music/"+musicName+".ogg";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -231,7 +231,7 @@ Mix_Chunk* SagoDataHolder::getSoundPtr(const std::string& soundName) const {
return ret;
}
std::string path = "sounds/"+soundName+".ogg";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -271,7 +271,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;
@@ -318,15 +318,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/src/sago/SagoDataHolder.hpp b/src/sago/SagoDataHolder.hpp index 3c126aa..373d12c 100644 --- a/src/sago/SagoDataHolder.hpp +++ b/src/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;
@@ -87,13 +87,13 @@ 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);
/**
* Invalidates all pointers returned by any of the get variables
@@ -117,10 +117,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/src/sago/SagoMisc.cpp b/src/sago/SagoMisc.cpp index fc0b960..3a2230b 100644 --- a/src/sago/SagoMisc.cpp +++ b/src/sago/SagoMisc.cpp
@@ -66,7 +66,7 @@ std::string GetFileContent(const char* filename) {
return ret;
}
PHYSFS_close(myfile);
- //Now create a std::string
+ //Now create a std::string
ret = string(m_data.get(), m_data.get()+m_size);
return ret;
}
diff --git a/src/sago/SagoMisc.hpp b/src/sago/SagoMisc.hpp index 4c3db91..c85de52 100644 --- a/src/sago/SagoMisc.hpp +++ b/src/sago/SagoMisc.hpp
@@ -23,50 +23,52 @@ SOFTWARE.
*/
#ifndef SAGOMISC_HPP
-#define SAGOMISC_HPP
+#define SAGOMISC_HPP
#include <vector>
#include <string>
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);
+/**
+ * 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
- * @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
+ */
+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()); };
+/**
+ * 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);
+bool FileExists(const char* filename);
- void WriteFileContent(const char* filename, const std::string& content);
+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);
+/**
+ * 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/src/sago/SagoMiscSdl2.hpp b/src/sago/SagoMiscSdl2.hpp index 1bc115b..c2d700b 100644 --- a/src/sago/SagoMiscSdl2.hpp +++ b/src/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/src/sago/SagoSprite.hpp b/src/sago/SagoSprite.hpp index 688770a..63a2feb 100644 --- a/src/sago/SagoSprite.hpp +++ b/src/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
* @param target The render window to draw on
@@ -47,7 +47,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;
/**
@@ -59,17 +59,17 @@ 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
- * @param progress A float with value from 0.0f to 1.0f. Tells how far in the animation that we got
- * @param x Place to draw the sprite
- * @param y Place to draw the sprite
- */
+ * Draws the sprite to a given render window
+ * @param target The render window to draw on
+ * @param progress A float with value from 0.0f to 1.0f. Tells how far in the animation that we got
+ * @param x Place to draw the sprite
+ * @param y Place to draw the sprite
+ */
void DrawProgressive(SDL_Renderer* target, float progress, int x, int y) const;
void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h) 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);
@@ -79,10 +79,10 @@ public:
~SagoSprite();
private:
struct SagoSpriteData;
- SagoSpriteData *data;
+ SagoSpriteData* data;
};
}
-#endif /* SAGOSPRITE_HPP */
+#endif /* SAGOSPRITE_HPP */
diff --git a/src/sago/SagoSpriteHolder.hpp b/src/sago/SagoSpriteHolder.hpp index 21b093e..8a76dcd 100644 --- a/src/sago/SagoSpriteHolder.hpp +++ b/src/sago/SagoSpriteHolder.hpp
@@ -23,7 +23,7 @@ SOFTWARE.
*/
#ifndef SAGOSPRITEHOLDER_HPP
-#define SAGOSPRITEHOLDER_HPP
+#define SAGOSPRITEHOLDER_HPP
#include "SagoDataHolder.hpp"
#include "SagoSprite.hpp"
@@ -32,20 +32,20 @@ namespace sago {
class SagoSpriteHolder final {
public:
- explicit SagoSpriteHolder(const SagoDataHolder &texHolder);
+ explicit SagoSpriteHolder(const SagoDataHolder& texHolder);
~SagoSpriteHolder();
void ReadSprites();
- 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/src/sago/SagoTextBox.cpp b/src/sago/SagoTextBox.cpp index 2f98a20..8ad56fb 100644 --- a/src/sago/SagoTextBox.cpp +++ b/src/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/src/sago/SagoTextBox.hpp b/src/sago/SagoTextBox.hpp index e0b7096..42c0d81 100644 --- a/src/sago/SagoTextBox.hpp +++ b/src/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".
@@ -64,7 +64,7 @@ private:
SagoTextBox(const SagoTextBox& orig) = delete;
SagoTextBox& operator=(const SagoTextBox& base) = delete;
struct SagoTextBoxData;
- SagoTextBoxData *data;
+ SagoTextBoxData* data;
};
} //namespace sago
diff --git a/src/sago/SagoTextField.cpp b/src/sago/SagoTextField.cpp index 666de12..85e63fa 100644 --- a/src/sago/SagoTextField.cpp +++ b/src/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/src/sago/SagoTextField.hpp b/src/sago/SagoTextField.hpp index 902ee16..cc434db 100644 --- a/src/sago/SagoTextField.hpp +++ b/src/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!
@@ -48,7 +48,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.
*/
@@ -115,7 +115,7 @@ public:
private:
SagoTextField(const SagoTextField& orig) = delete;
struct SagoTextFieldData;
- SagoTextFieldData *data;
+ SagoTextFieldData* data;
};
} //namespace sago
diff --git a/src/sago/platform_folders.cpp b/src/sago/platform_folders.cpp index c5204cd..d93db8c 100644 --- a/src/sago/platform_folders.cpp +++ b/src/sago/platform_folders.cpp
@@ -64,7 +64,7 @@ static std::string getHome() {
return res;
}
-#endif
+#endif
#ifdef _WIN32
// Make sure we don't bring in all the extra junk with windows.h
@@ -183,21 +183,21 @@ namespace sago {
#if !defined(_WIN32) && !defined(__APPLE__)
namespace internal {
- void appendExtraFoldersTokenizer(const char* envName, const char* envValue, std::vector<std::string>& folders) {
- std::stringstream ss(envValue);
- std::string value;
- while (std::getline(ss, value, ':')) {
- if (value[0] == '/') {
- folders.push_back(value);
- }
- else {
- //Unless the system is wrongly configured this should never happen... But of course some systems will be incorectly configured.
- //The XDG documentation indicates that the folder should be ignored but that the program should continue.
- std::cerr << "Skipping path \"" << value << "\" in \"" << envName << "\" because it does not start with a \"/\"\n";
- }
+void appendExtraFoldersTokenizer(const char* envName, const char* envValue, std::vector<std::string>& folders) {
+ std::stringstream ss(envValue);
+ std::string value;
+ while (std::getline(ss, value, ':')) {
+ if (value[0] == '/') {
+ folders.push_back(value);
+ }
+ else {
+ //Unless the system is wrongly configured this should never happen... But of course some systems will be incorectly configured.
+ //The XDG documentation indicates that the folder should be ignored but that the program should continue.
+ std::cerr << "Skipping path \"" << value << "\" in \"" << envName << "\" because it does not start with a \"/\"\n";
}
}
}
+}
#endif
std::string getDataHome() {
@@ -265,7 +265,8 @@ static void PlatformFoldersAddFromFile(const std::string& filename, std::map<std
std::size_t valueEnd = line.find('"', valueStart+1);
std::string value = line.substr(valueStart+1, valueEnd - valueStart - 1);
folders[key] = value;
- } catch (std::exception& e) {
+ }
+ catch (std::exception& e) {
std::cerr << "WARNING: Failed to process \"" << line << "\" from \"" << filename << "\". Error: "<< e.what() << "\n";
continue;
}
diff --git a/src/saland.cpp b/src/saland.cpp index 49f4ddf..4681359 100644 --- a/src/saland.cpp +++ b/src/saland.cpp
@@ -80,8 +80,8 @@ public:
testBox.SetMaxWidth(1);
testBox.Draw(target, 300,500);
circleRGBA(target,
- 150, 150, 75,
- 0, 0, 255, 255);
+ 150, 150, 75,
+ 0, 0, 255, 255);
const sago::SagoSprite& s = globalData.spriteHolder->GetSprite("male_walkcycle_E");
s.Draw(globalData.screen, SDL_GetTicks(), 100, 100);
const sago::SagoSprite& sc = globalData.spriteHolder->GetSprite("female_spellcast_E");
@@ -92,7 +92,7 @@ public:
bat.Draw(globalData.screen, SDL_GetTicks(), 200, 200);
}
- virtual void ProcessInput(const SDL_Event& event, bool &processed) override {
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override {
if ( event.type == SDL_KEYDOWN ) {
if (event.key.keysym.sym == SDLK_RETURN) {
isActive = false;
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 1da4c37..c77f6ab 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -56,7 +56,7 @@ typedef std::pair<float,float> SpawnPoint;
* @param rhs Right hand side
* @return true if lhs < rhs
*/
-static bool sort_placeable(const std::shared_ptr<Placeable> &lhs, const std::shared_ptr<Placeable> &rhs) {
+static bool sort_placeable(const std::shared_ptr<Placeable>& lhs, const std::shared_ptr<Placeable>& rhs) {
return lhs->Y < rhs->Y;
}
@@ -73,7 +73,8 @@ bool PlaceablesSortLowerY(const std::shared_ptr<Placeable>& i, const std::shared
static int string2int_trows(const std::string& s) {
try {
return std::stoi(s);
- } catch (std::exception&){
+ }
+ catch (std::exception&) {
std::stringstream ss;
ss << "Failed to convert \"" << s << "\" to an integer";
throw std::runtime_error(ss.str());
@@ -87,7 +88,9 @@ static int teleportY = 0;
static bool openTiled = false;
struct GotoConsoleCommand : public ConsoleCommand {
- virtual std::string getCommand() const override {return "goto";}
+ virtual std::string getCommand() const override {
+ return "goto";
+ }
virtual std::string run(const std::vector<std::string>& args) override {
if (args.size() != 3) {
return "Must be ran like \"goto X Y\"";
@@ -104,7 +107,9 @@ struct GotoConsoleCommand : public ConsoleCommand {
};
struct ResetRegionConsoleCommand : public ConsoleCommand {
- virtual std::string getCommand() const override {return "reset_region";}
+ virtual std::string getCommand() const override {
+ return "reset_region";
+ }
virtual std::string run(const std::vector<std::string>&) override {
reset_region = true;
return "Region reset queued!";
@@ -118,7 +123,9 @@ struct ResetRegionConsoleCommand : public ConsoleCommand {
void RunGameState(sago::GameStateInterface& state );
struct ShopCommand : public ConsoleCommand {
- virtual std::string getCommand() const override {return "shop";}
+ virtual std::string getCommand() const override {
+ return "shop";
+ }
virtual std::string run(const std::vector<std::string>&) override {
GameShop gs;
RunGameState(gs);
@@ -131,7 +138,9 @@ struct ShopCommand : public ConsoleCommand {
};
struct ConcoleCommandTiled : public ConsoleCommand {
- virtual std::string getCommand() const override {return "tiled";}
+ virtual std::string getCommand() const override {
+ return "tiled";
+ }
virtual std::string run(const std::vector<std::string>&) override {
openTiled = true;
return "Requesting tiled";
@@ -295,7 +304,7 @@ void Game::Draw(SDL_Renderer* target) {
int mousebox_x = data->world_mouse_x - data->world_mouse_x % 32 - data->topx;
int mousebox_y = data->world_mouse_y - data->world_mouse_y % 32 - data->topy;
rectangleRGBA(globalData.screen, mousebox_x, mousebox_y,
- mousebox_x + 32, mousebox_y + 32, 255, 255, 0, 255);
+ mousebox_x + 32, mousebox_y + 32, 255, 255, 0, 255);
//Draw
for (const auto& p : data->gameRegion.placeables) {
@@ -323,9 +332,9 @@ void Game::Draw(SDL_Renderer* target) {
}
char buffer[200];
snprintf(buffer, sizeof(buffer), "world_x = %d, world_y = %d, layer_info:%s",
- data->world_mouse_x/32, data->world_mouse_y/32,
- GetLayerInfoForTile(data->gameRegion.world, data->world_mouse_x/32, data->world_mouse_y/32).c_str()
- );
+ data->world_mouse_x/32, data->world_mouse_y/32,
+ GetLayerInfoForTile(data->gameRegion.world, data->world_mouse_x/32, data->world_mouse_y/32).c_str()
+ );
data->bottomField.SetText(buffer);
data->bottomField.Draw(target, 2, screen_height, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::bottom);
data->middleField.Draw(target, screen_width/2, screen_height/4, sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::bottom);
@@ -366,15 +375,15 @@ void Game::ProcessInput(const SDL_Event& event, bool& processed) {
int tile_x = data->world_mouse_x/32;
int tile_y = data->world_mouse_y/32;
if (event.key.keysym.sym == globalData.playerControls.block_create
- && sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y)
- && !(data->gameRegion.world.tile_protected(tile_x, tile_y)) ) {
+ && sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y)
+ && !(data->gameRegion.world.tile_protected(tile_x, tile_y)) ) {
int layer_number = 2; // Do not hardcode
uint32_t tile = data->drawTile;
sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile);
data->gameRegion.world.init_physics(data->gameRegion.physicsBox);
}
if (event.key.keysym.sym == globalData.playerControls.block_delete
- && sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y)) {
+ && sago::tiled::tileInBound(data->gameRegion.world.tm, tile_x, tile_y)) {
int layer_number = 2; // Do not hardcode
uint32_t tile = 0;
sago::tiled::setTileOnLayerNumber(data->gameRegion.world.tm, layer_number, tile_x, tile_y, tile);
@@ -414,7 +423,7 @@ void Game::Update() {
}
Uint32 nowTime = SDL_GetTicks();
Uint32 deltaTime = nowTime - data->lastUpdate;
- const Uint8 *state = SDL_GetKeyboardState(NULL);
+ const Uint8* state = SDL_GetKeyboardState(NULL);
float deltaX = 0.0f;
float deltaY = 0.0f;
if (!data->consoleActive) {
@@ -460,7 +469,9 @@ void Game::Update() {
}
}
auto& vp = data->gameRegion.placeables;
- vp.erase(std::remove_if(std::begin(vp), std::end(vp), [](std::shared_ptr<Placeable> p) { return p->removeMe; }), std::end(vp));
+ vp.erase(std::remove_if(std::begin(vp), std::end(vp), [](std::shared_ptr<Placeable> p) {
+ return p->removeMe;
+ }), std::end(vp));
data->center_x = std::round(data->human->X);
data->center_y = std::round(data->human->Y);
int mousex;
@@ -479,7 +490,7 @@ void Game::Update() {
continue;
}
if (item.x < data->human->X && item.y < data->human->Y && item.width+item.x > data->human->X
- && item.height+item.y > data->human->Y && item.type == "text") {
+ && item.height+item.y > data->human->Y && item.type == "text") {
const auto& itr = item.properties.find("text");
if (itr != item.properties.end()) {
middleText = itr->second.value;
diff --git a/src/saland/Game.hpp b/src/saland/Game.hpp index 4c96346..be5477f 100644 --- a/src/saland/Game.hpp +++ b/src/saland/Game.hpp
@@ -33,7 +33,7 @@ public:
Game();
virtual bool IsActive() override;
virtual void Draw(SDL_Renderer* target) override;
- virtual void ProcessInput(const SDL_Event& event, bool &processed) override;
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override;
virtual void Update() override;
virtual ~Game();
private:
diff --git a/src/saland/GameConsoleCommand.cpp b/src/saland/GameConsoleCommand.cpp index cca18fb..d9de7d4 100644 --- a/src/saland/GameConsoleCommand.cpp +++ b/src/saland/GameConsoleCommand.cpp
@@ -25,34 +25,37 @@ https://github.com/sago007/saland
#include "console/Console.hpp"
struct ConsoleCommandGiveItem : public ConsoleCommand {
- virtual std::string getCommand() const override {return "give";}
+ virtual std::string getCommand() const override {
+ return "give";
+ }
virtual std::string run(const std::vector<std::string>& args) override {
- if (args.size() != 3) {
- throw std::runtime_error("Must be called like: give ITEM_NAME QUANTITY");
- }
- std::string item_name = args.at(1);
- int quantity = 1;
- try {
- quantity = std::stoi(args.at(2));
- } catch (...) {
- std::string error_msg = "Failed to convert \"";
- error_msg += args.at(2)+ "\" into an integer";
- throw std::runtime_error(error_msg);
- }
- if (quantity == 0) {
- return std::string("Inventory not touched");
- }
- int prevCount = globalData.player.item_inventory[item_name];
- globalData.player.item_inventory[item_name] += quantity;
- if (quantity > 0) {
- return std::string("Added ")+std::to_string(quantity)+" of "+item_name;
- }
- else {
- if (globalData.player.item_inventory[item_name] < 0) {
- globalData.player.item_inventory[item_name] = 0;
- }
- return std::string("Removed ")+std::to_string(prevCount-globalData.player.item_inventory[item_name])+" of "+item_name;
- }
+ if (args.size() != 3) {
+ throw std::runtime_error("Must be called like: give ITEM_NAME QUANTITY");
+ }
+ std::string item_name = args.at(1);
+ int quantity = 1;
+ try {
+ quantity = std::stoi(args.at(2));
+ }
+ catch (...) {
+ std::string error_msg = "Failed to convert \"";
+ error_msg += args.at(2)+ "\" into an integer";
+ throw std::runtime_error(error_msg);
+ }
+ if (quantity == 0) {
+ return std::string("Inventory not touched");
+ }
+ int prevCount = globalData.player.item_inventory[item_name];
+ globalData.player.item_inventory[item_name] += quantity;
+ if (quantity > 0) {
+ return std::string("Added ")+std::to_string(quantity)+" of "+item_name;
+ }
+ else {
+ if (globalData.player.item_inventory[item_name] < 0) {
+ globalData.player.item_inventory[item_name] = 0;
+ }
+ return std::string("Removed ")+std::to_string(prevCount-globalData.player.item_inventory[item_name])+" of "+item_name;
+ }
}
@@ -63,12 +66,15 @@ struct ConsoleCommandGiveItem : public ConsoleCommand {
struct ConsoleCommandQuit : public ConsoleCommand {
- virtual std::string getCommand() const override {return "quit";}
- virtual std::string run(const std::vector<std::string>& args) override {
- globalData.isShuttingDown = true;
- }
+ virtual std::string getCommand() const override {
+ return "quit";
+ }
+ virtual std::string run(const std::vector<std::string>&) override {
+ globalData.isShuttingDown = true;
+ return "Exiting...";
+ }
- virtual std::string helpMessage() const override {
+ virtual std::string helpMessage() const override {
return "Exits the game";
}
};
@@ -78,6 +84,6 @@ static ConsoleCommandQuit cc_quit;
void GameConsoleCommandRegister() {
- RegisterCommand(&cc_give_item);
- RegisterCommand(&cc_quit);
+ RegisterCommand(&cc_give_item);
+ RegisterCommand(&cc_quit);
}
\ No newline at end of file
diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp index 1de90d3..8e8017e 100644 --- a/src/saland/GameDraw.cpp +++ b/src/saland/GameDraw.cpp
@@ -82,31 +82,33 @@ void DrawOjbectGroup(SDL_Renderer* renderer, const sago::tiled::TileMap& tm, siz
for (const sago::tiled::TileObject& o : group.objects) {
if (o.isEllipse) {
ellipseRGBA(renderer, (o.x + o.width / 2) - topx, (o.y + o.height / 2) - topy, o.width / 2, o.height / 2, 255, 255, 0, 255);
- } else if (o.polygon_points.size() > 0) {
+ }
+ else if (o.polygon_points.size() > 0) {
for (size_t i = 0; i < o.polygon_points.size(); ++i) {
std::pair<int, int> first = o.polygon_points.at(i);
std::pair<int, int> second = (i + 1 < o.polygon_points.size()) ? o.polygon_points.at(i + 1) : o.polygon_points.at(0);
lineRGBA(renderer, first.first + o.x - topx, first.second + o.y - topy, second.first + o.x - topx, second.second + o.y - topy, 255, 255, 0, 255);
}
- } else {
+ }
+ else {
rectangleRGBA(renderer, o.x - topx, o.y - topy,
- o.x + o.width - topx, o.y + o.height - topy, 255, 255, 0, 255);
+ o.x + o.width - topx, o.y + o.height - topy, 255, 255, 0, 255);
}
}
}
-void DrawMiscEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const MiscItem *entity, float time,
- int offsetX, int offsetY, bool drawCollision) {
+void DrawMiscEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const MiscItem* entity, float time,
+ int offsetX, int offsetY, bool drawCollision) {
if (drawCollision) {
circleRGBA(target,
- entity->X - offsetX, entity->Y - offsetY, entity->Radius,
- 255, 255, 0, 255);
+ entity->X - offsetX, entity->Y - offsetY, entity->Radius,
+ 255, 255, 0, 255);
}
- const sago::SagoSprite &mySprite = sHolder->GetSprite(entity->sprite);
+ const sago::SagoSprite& mySprite = sHolder->GetSprite(entity->sprite);
mySprite.Draw(target, time, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
}
-void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Human *entity, float time, int offsetX, int offsetY, bool drawCollision) {
+void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Human* entity, float time, int offsetX, int offsetY, bool drawCollision) {
std::string animation = "standing";
bool relativeAnimation = false;
float relativeAnimationState = 0.0f;
@@ -120,17 +122,18 @@ void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, cons
}
if (drawCollision) {
circleRGBA(target,
- entity->X - offsetX, entity->Y - offsetY, entity->Radius,
- 255, 255, 0, 255);
+ entity->X - offsetX, entity->Y - offsetY, entity->Radius,
+ 255, 255, 0, 255);
}
- const sago::SagoSprite &mySprite = sHolder->GetSprite(entity->race + "_" + animation + "_" + std::string(1, entity->direction));
+ const sago::SagoSprite& mySprite = sHolder->GetSprite(entity->race + "_" + animation + "_" + std::string(1, entity->direction));
if (relativeAnimation) {
mySprite.DrawProgressive(target, relativeAnimationState, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
- } else {
+ }
+ else {
mySprite.Draw(target, time, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
}
if (entity->pants.length() > 0) {
- const sago::SagoSprite &myPants = sHolder->GetSprite(entity->race + "_"+animation+"_"+entity->pants+"_"+std::string(1,entity->direction));
+ const sago::SagoSprite& myPants = sHolder->GetSprite(entity->race + "_"+animation+"_"+entity->pants+"_"+std::string(1,entity->direction));
if (relativeAnimation) {
myPants.DrawProgressive(target, relativeAnimationState, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
}
@@ -139,7 +142,7 @@ void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, cons
}
}
if (entity->top.length() > 0) {
- const sago::SagoSprite &myTop = sHolder->GetSprite(entity->race + "_"+animation+"_"+entity->top+"_"+std::string(1,entity->direction));
+ const sago::SagoSprite& myTop = sHolder->GetSprite(entity->race + "_"+animation+"_"+entity->top+"_"+std::string(1,entity->direction));
if (relativeAnimation) {
myTop.DrawProgressive(target, relativeAnimationState, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
}
@@ -152,29 +155,29 @@ void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, cons
if (hairAnimation == "spellcast") {
hairAnimation = "standing";
}
- const sago::SagoSprite &myHair = sHolder->GetSprite(entity->race + "_"+hairAnimation+"_"+entity->hair+"_"+std::string(1,entity->direction));
+ const sago::SagoSprite& myHair = sHolder->GetSprite(entity->race + "_"+hairAnimation+"_"+entity->hair+"_"+std::string(1,entity->direction));
myHair.Draw(target, time, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
}
}
-void DrawMonster(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Monster *entity, float time, int offsetX, int offsetY, bool drawCollision) {
+void DrawMonster(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Monster* entity, float time, int offsetX, int offsetY, bool drawCollision) {
if (drawCollision) {
circleRGBA(target,
- entity->X - offsetX, entity->Y - offsetY, entity->Radius,
- 255, 255, 0, 255);
+ entity->X - offsetX, entity->Y - offsetY, entity->Radius,
+ 255, 255, 0, 255);
}
- const sago::SagoSprite &mySprite = sHolder->GetSprite(entity->race + "_" + std::string(1, entity->direction));
+ const sago::SagoSprite& mySprite = sHolder->GetSprite(entity->race + "_" + std::string(1, entity->direction));
mySprite.Draw(target, time, std::round(entity->X) - offsetX, std::round(entity->Y) - offsetY);
}
-void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Projectile *entity, float time, int offsetX, int offsetY, bool drawCollision) {
+void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Projectile* entity, float time, int offsetX, int offsetY, bool drawCollision) {
(void)sHolder;
(void)time;
if (drawCollision) {
circleRGBA(target,
- entity->X - offsetX, entity->Y - offsetY, entity->Radius,
- 255, 255, 0, 255);
+ entity->X - offsetX, entity->Y - offsetY, entity->Radius,
+ 255, 255, 0, 255);
}
}
diff --git a/src/saland/GameDraw.hpp b/src/saland/GameDraw.hpp index b7ac9c3..d42f92f 100644 --- a/src/saland/GameDraw.hpp +++ b/src/saland/GameDraw.hpp
@@ -32,11 +32,11 @@ https://github.com/sago007/saland
void DrawOuterBorder(SDL_Renderer* renderer, SDL_Texture* texture, const sago::tiled::TileMap& tm, int topx, int topy, uint32 outerTile);
void DrawLayer(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sago::tiled::TileMap& tm, size_t layer, int topx, int topy);
void DrawOjbectGroup(SDL_Renderer* renderer, const sago::tiled::TileMap& tm, size_t object_group, int topx, int topy);
-void DrawMiscEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const MiscItem *entity, float time,
- int offsetX, int offsetY, bool drawCollision);
-void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Human *entity, float time, int offsetX, int offsetY, bool drawCollision);
-void DrawMonster(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Monster *entity, float time, int offsetX, int offsetY, bool drawCollision);
-void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Projectile *entity, float time, int offsetX, int offsetY, bool drawCollision);
+void DrawMiscEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const MiscItem* entity, float time,
+ int offsetX, int offsetY, bool drawCollision);
+void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Human* entity, float time, int offsetX, int offsetY, bool drawCollision);
+void DrawMonster(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Monster* entity, float time, int offsetX, int offsetY, bool drawCollision);
+void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Projectile* entity, float time, int offsetX, int offsetY, bool drawCollision);
void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width);
void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width);
diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index 3fb3bde..03ac58d 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp
@@ -48,7 +48,7 @@ void GameRegion::Init(int x, int y, const std::string& worldName, bool forceRese
physicsBox.reset(new b2World(gravity));
world.managed_bodies.clear();
world.init(physicsBox, loadMap);
-
+
std::shared_ptr<MiscItem> barrel = std::make_shared<MiscItem>();
barrel.get()->Radius = 16.0f;
barrel.get()->sprite = "item_barrel";
diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp index 4184ba5..784ef87 100644 --- a/src/saland/GameRegion.hpp +++ b/src/saland/GameRegion.hpp
@@ -37,9 +37,15 @@ public:
void SaveRegion();
World world;
uint32_t outerTile = 485;
- int GetRegionX() const {return region_x; }
- int GetRegionY() const {return region_y; }
- std::string GetFilename() const {return mapFileName; }
+ int GetRegionX() const {
+ return region_x;
+ }
+ int GetRegionY() const {
+ return region_y;
+ }
+ std::string GetFilename() const {
+ return mapFileName;
+ }
private:
int region_x = 0;
int region_y = 0;
diff --git a/src/saland/GameShop.cpp b/src/saland/GameShop.cpp index 085cad6..59d02b7 100644 --- a/src/saland/GameShop.cpp +++ b/src/saland/GameShop.cpp
@@ -51,7 +51,7 @@ void GameShop::Draw(SDL_Renderer* target) {
data->goldField.Draw(target, globalData.xsize-1, globalData.ysize-1, sago::SagoTextField::Alignment::right, sago::SagoTextField::VerticalAlignment::bottom);
}
-void GameShop::ProcessInput(const SDL_Event& event, bool &) {
+void GameShop::ProcessInput(const SDL_Event& event, bool&) {
if (event.type == SDL_KEYDOWN) {
data->active = false;
}
diff --git a/src/saland/GameShop.hpp b/src/saland/GameShop.hpp index 0abfb1b..551781c 100644 --- a/src/saland/GameShop.hpp +++ b/src/saland/GameShop.hpp
@@ -40,7 +40,7 @@ public:
GameShop();
virtual bool IsActive() override;
virtual void Draw(SDL_Renderer* target) override;
- virtual void ProcessInput(const SDL_Event& event, bool &processed) override;
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override;
virtual void Update() override;
GameShop(const GameShop&) = delete;
virtual ~GameShop();
diff --git a/src/saland/GameUpdates.cpp b/src/saland/GameUpdates.cpp index f469c28..aa5f3ed 100644 --- a/src/saland/GameUpdates.cpp +++ b/src/saland/GameUpdates.cpp
@@ -33,7 +33,7 @@ static void SetDesiredVelocity(b2Body* body, float x, float y) {
body->ApplyLinearImpulse(b2Vec2(impulseX, impulseY), body->GetWorldCenter(), true);
}
-static void SetCreatureMovementEntity(Creature *entity, float directionX, float directionY) {
+static void SetCreatureMovementEntity(Creature* entity, float directionX, float directionY) {
float deltaX = directionX;
float deltaY = directionY;
@@ -63,7 +63,7 @@ static void SetCreatureMovementEntity(Creature *entity, float directionX, float
SetDesiredVelocity(entity->body, deltaX*speed, deltaY * speed);
}
-void UpdateHuman(Human *entity, float fDeltaTime) {
+void UpdateHuman(Human* entity, float fDeltaTime) {
if (entity->castTimeRemaining > 0) {
entity->castTimeRemaining -= fDeltaTime;
}
@@ -80,7 +80,7 @@ void UpdateHuman(Human *entity, float fDeltaTime) {
entity->Y = place.y*pixel2unit;
}
-void UpdateMonster(Monster *entity) {
+void UpdateMonster(Monster* entity) {
SetCreatureMovementEntity(entity, entity->moveX, entity->moveY);
b2Vec2 place = entity->body->GetPosition();
entity->X = place.x*pixel2unit;
@@ -90,7 +90,7 @@ void UpdateMonster(Monster *entity) {
}
}
-void UpdateProjectile(Projectile *entity, float fDeltaTime) {
+void UpdateProjectile(Projectile* entity, float fDeltaTime) {
entity->timeToLive -= fDeltaTime;
if (entity->timeToLive < 0.0f) {
entity->removeMe = true;
diff --git a/src/saland/GameUpdates.hpp b/src/saland/GameUpdates.hpp index 007eb87..c8c5f01 100644 --- a/src/saland/GameUpdates.hpp +++ b/src/saland/GameUpdates.hpp
@@ -30,9 +30,9 @@ https://github.com/sago007/saland
void ProjectileHit(Projectile* p, Placeable* target);
-void UpdateHuman(Human *entity, float fDeltaTime);
-void UpdateMonster(Monster *entity);
-void UpdateProjectile(Projectile *entity, float fDeltaTime);
+void UpdateHuman(Human* entity, float fDeltaTime);
+void UpdateMonster(Monster* entity);
+void UpdateProjectile(Projectile* entity, float fDeltaTime);
#endif /* GAMEUPDATES_HPP */
diff --git a/src/saland/console/Console.cpp b/src/saland/console/Console.cpp index 8f708e0..04faf65 100644 --- a/src/saland/console/Console.cpp +++ b/src/saland/console/Console.cpp
@@ -43,7 +43,9 @@ void RegisterCommand(ConsoleCommand* command) {
}
struct HelpConsoleCommand : public ConsoleCommand {
- virtual std::string getCommand() const override {return "help"; }
+ virtual std::string getCommand() const override {
+ return "help";
+ }
virtual std::string run(const std::vector<std::string>& args) override {
if (args.size() > 1 && commands.find(args.at(1)) != commands.end() ) {
@@ -58,7 +60,9 @@ struct HelpConsoleCommand : public ConsoleCommand {
return helpMessage;
}
- virtual std::string helpMessage() const override { return "Displays this message"; }
+ virtual std::string helpMessage() const override {
+ return "Displays this message";
+ }
};
static HelpConsoleCommand hcc;
@@ -121,7 +125,7 @@ void Console::removeChar() {
}
}
-static std::vector<std::string> splitByWhitespace(std::string const &line) {
+static std::vector<std::string> splitByWhitespace(std::string const& line) {
std::vector<std::string> arg;
boost::escaped_list_separator<char> els('\\',' ','\"');
boost::tokenizer<boost::escaped_list_separator<char> > tok(line, els);
@@ -143,7 +147,8 @@ void Console::ProcessCommand(const std::string& command) {
try {
std::string ret = commands[commandVector[0]]->run(commandVector);
response.SetText(ret);
- } catch (std::exception& e) {
+ }
+ catch (std::exception& e) {
response.SetText(e.what());
response.SetColor(error_color);
}
@@ -197,7 +202,7 @@ bool Console::ReadKey(SDL_Keycode keyPressed) {
return false;
}
-void Console::ProcessInput(const SDL_Event& event, bool &processed) {
+void Console::ProcessInput(const SDL_Event& event, bool& processed) {
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE && event.key.keysym.mod & KMOD_LSHIFT) {
active = false;
diff --git a/src/saland/console/Console.hpp b/src/saland/console/Console.hpp index a11b271..f4cb418 100644 --- a/src/saland/console/Console.hpp +++ b/src/saland/console/Console.hpp
@@ -31,9 +31,15 @@ https://github.com/sago007/saland
#include "utf8.h"
struct ConsoleCommand {
- virtual std::string getCommand() const {return "version"; }
- virtual std::string run(const std::vector<std::string>&) { return "Not implemented"; }
- virtual std::string helpMessage() const { return "No help availeble"; }
+ virtual std::string getCommand() const {
+ return "version";
+ }
+ virtual std::string run(const std::vector<std::string>&) {
+ return "Not implemented";
+ }
+ virtual std::string helpMessage() const {
+ return "No help availeble";
+ }
};
/**
@@ -46,7 +52,7 @@ public:
Console();
virtual bool IsActive() override;
virtual void Draw(SDL_Renderer* target) override;
- virtual void ProcessInput(const SDL_Event& event, bool &processed) override;
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override;
virtual void Update() override;
void Activate();
Console(const Console& orig) = delete;
diff --git a/src/saland/model/Player.hpp b/src/saland/model/Player.hpp index 747ae2a..7475a03 100644 --- a/src/saland/model/Player.hpp +++ b/src/saland/model/Player.hpp
@@ -28,14 +28,26 @@ https://github.com/sago007/saland
#include <map>
struct Player {
- Player() {};
- std::string save_name="player1";
- std::string get_visible_race() {return "female";}
- std::string get_visible_hair() {return "standard_hair";}
- std::string get_visible_bottom() {return "pants_1";}
- std::string get_visible_top(){return "pirate_shirt_sky";}
- std::string get_visibla_hat(){ return "";}
- std::string get_visible_shoes(){ return "";}
+ Player() {};
+ std::string save_name="player1";
+ std::string get_visible_race() {
+ return "female";
+ }
+ std::string get_visible_hair() {
+ return "standard_hair";
+ }
+ std::string get_visible_bottom() {
+ return "pants_1";
+ }
+ std::string get_visible_top() {
+ return "pirate_shirt_sky";
+ }
+ std::string get_visibla_hat() {
+ return "";
+ }
+ std::string get_visible_shoes() {
+ return "";
+ }
std::map<std::string, int> item_inventory;
};
diff --git a/src/saland/model/World.cpp b/src/saland/model/World.cpp index d24c7e3..89c95b0 100644 --- a/src/saland/model/World.cpp +++ b/src/saland/model/World.cpp
@@ -47,7 +47,7 @@ static void AddRectToBody(b2Body* body, float x, float y, float width, float hig
/**
* Adds a static body to the world. Returns a pointer to the body
- * @param world The world to use for the body
+ * @param world The world to use for the body
* @param x X coordiante for the top left corner in pixels
* @param y Y coordinate for the top left corner in pixels
* @param width Width of the rectangle in pixels
@@ -155,8 +155,8 @@ void World::init(std::shared_ptr<b2World>& world, const std::string& mapFileName
}
init_physics(world);
protected_tiles.resize(tm.height*tm.width);
- for (int x=0; x < tm.width; ++x){
- for (int y=0; y < tm.height; ++y){
+ for (int x=0; x < tm.width; ++x) {
+ for (int y=0; y < tm.height; ++y) {
if (x < 2 && y > tm.layers.at(0).height/2-6 && y < tm.layers.at(0).height/2+5) {
protected_tiles[x+y*tm.width] = true;
}
diff --git a/src/saland/model/placeables.hpp b/src/saland/model/placeables.hpp index 8a2677e..8edbd2b 100644 --- a/src/saland/model/placeables.hpp +++ b/src/saland/model/placeables.hpp
@@ -36,7 +36,9 @@ public:
float Radius = 16.0;
bool removeMe = false;
b2Body* body = nullptr;
- virtual bool isStatic() {return true; }
+ virtual bool isStatic() {
+ return true;
+ }
};
class MiscItem : public Placeable {
@@ -56,7 +58,9 @@ public:
bool moving = false;
float moveX = 0.0;
float moveY = 0.0;
- virtual bool isStatic() override { return false; }
+ virtual bool isStatic() override {
+ return false;
+ }
};
class Human : public Creature {