aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/brice.hpp39
-rw-r--r--include/common.hpp5
-rw-r--r--include/components.hpp23
-rw-r--r--include/config.hpp49
-rw-r--r--include/engine.hpp58
-rw-r--r--include/gametime.hpp36
-rw-r--r--include/player.hpp44
-rw-r--r--include/save_util.hpp36
-rw-r--r--include/shader_utils.hpp3
-rw-r--r--include/ui.hpp8
-rw-r--r--include/ui_quest.hpp19
-rw-r--r--src/components.cpp175
-rw-r--r--src/ui.cpp361
-rw-r--r--src/ui_menu.cpp20
-rw-r--r--src/world.cpp47
-rw-r--r--xml/entities.xml30
16 files changed, 563 insertions, 390 deletions
diff --git a/include/brice.hpp b/include/brice.hpp
index dc3ea96..1c4eccf 100644
--- a/include/brice.hpp
+++ b/include/brice.hpp
@@ -1,20 +1,59 @@
+/**
+ * @file brice.hpp
+ * @brief A system for saving player information.
+ */
+
#ifndef BRICE_H_
#define BRICE_H_
#include <string>
namespace game {
+
+ /**
+ * Allows the player to jump, if set to true.
+ */
extern bool canJump;
+
+ /**
+ * Allows the player to sprint, if set to true.
+ */
extern bool canSprint;
+ /**
+ * Gets a value from the saved brice and returns it.
+ * @param id the id of the value
+ * @return the string value
+ */
std::string getValue(const std::string& id);
+ /**
+ * Sets a value in the brice, creating it if it doesn't exist.
+ * @param id the id of the value
+ * @param value the value
+ * @return true if the value was updated, not created
+ */
bool setValue(const std::string& id, const std::string& value);
+ /**
+ * Resets the brice to it's default values.
+ * Note: these are hardcoded into the program.
+ */
void briceClear(void);
+
+ /**
+ * Saves the brice to it's file (brice.dat).
+ */
void briceSave(void);
+
+ /**
+ * Loads the brice from it's file (brice.dat).
+ */
void briceLoad(void);
+ /**
+ * Reloads the brice.
+ */
void briceUpdate(void);
}
diff --git a/include/common.hpp b/include/common.hpp
index df41aa1..7028296 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -58,10 +58,7 @@ typedef unsigned int uint;
#define BREAKPOINT __asm__("int $3")
-inline const char* coalesce(const char * p1, const char * p2)
-{
- return ((p1 == nullptr) ? p2 : p1);
-}
+#define coalesce(v1, v2) ((v1 != nullptr) ? v1 : v2)
/**
* Creates a coordinate of integers.
diff --git a/include/components.hpp b/include/components.hpp
index f6521f8..bbf153a 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -147,7 +147,7 @@ struct Sprite {
Sprite(bool left = false)
: faceLeft(left) {}
- std::vector<std::pair<SpriteData, vec2>> getSprite() {
+ Frame getSprite() {
return sprite;
}
@@ -214,21 +214,24 @@ struct Animate {
// COMMENT
std::vector<Frame> frame;
// COMMENT
- std::vector<Frame>::iterator currentFrame;
+ uint index;
Animate(){
- currentFrame = std::begin(frame);
+ index = 0;
}
// COMMENT
Frame nextFrame() {
- std::rotate(frame.begin(), frame.begin()+1, frame.end());
- return frame[0];
- /*if (currentFrame < std::end(frame))
- return (*currentFrame++);
- else
- currentFrame = std::begin(frame);
- return (*currentFrame);*/
+ if (index < frame.size() - 1) {
+ index++;
+ } else {
+ index = 0;
+ }
+ return frame.at(index);
+ }
+
+ Frame firstFrame() {
+ return frame.front();
}
};
diff --git a/include/config.hpp b/include/config.hpp
index bc9d052..908c376 100644
--- a/include/config.hpp
+++ b/include/config.hpp
@@ -1,23 +1,72 @@
+/**
+ * @file config.hpp
+ * @brief Functions for loading/saving game settings.
+ */
+
#ifndef CONFIG_H
#define CONFIG_H
#include <string>
namespace game {
+ /**
+ * The size of an HLINE, according to the save file.
+ * This is the default "unit of measurement" in the game. Drawing scales to
+ * this, and it is used in game logic.
+ */
extern unsigned int HLINE;
+
+ /**
+ * The width of the screen, in pixels.
+ */
extern unsigned int SCREEN_WIDTH;
+
+ /**
+ * The height of the screen, in pixels.
+ */
extern unsigned int SCREEN_HEIGHT;
+
+ /**
+ * The window is fullscreen if this is true.
+ */
extern bool FULLSCREEN;
namespace config {
+ /**
+ * The current volume level of the master channel.
+ * Volumes are percentages, 0 to 100.
+ */
extern float VOLUME_MASTER;
+
+ /**
+ * Volume level of the background music (BGM).
+ */
extern float VOLUME_MUSIC;
+
+ /**
+ * Volume level of game sound effects.
+ */
extern float VOLUME_SFX;
+ /**
+ * The path of the folder to load world XML files from.
+ */
extern std::string xmlFolder;
+ /**
+ * Reads the settings file (config/settings.xml) into the game.
+ * Default values are hardcoded in (see src/config.cpp).
+ */
void read(void);
+
+ /**
+ * Updates settings with the current values.
+ */
void update(void);
+
+ /**
+ * Saves the current settings to the settings file.
+ */
void save(void);
}
}
diff --git a/include/engine.hpp b/include/engine.hpp
index 6e0c5a0..52569e7 100644
--- a/include/engine.hpp
+++ b/include/engine.hpp
@@ -1,8 +1,13 @@
+/**
+ * @file engine.hpp
+ * @brief The main game engine, and functions to assist it.
+ */
+
#ifndef ENGINE_HPP_
#define ENGINE_HPP_
#include <entityx/entityx.h>
-#include "entityx/deps/Dependencies.h"
+#include <entityx/deps/Dependencies.h>
#include <texture.hpp>
#include <components.hpp>
@@ -10,27 +15,55 @@
//game::engine::Systems->add<entityx::deps::Dependency<Visible, Sprite>>();
+/**
+ * @class Engine
+ * The main game engine class. Only one instance of this should be created, it
+ * handles everything game-related.
+ */
class Engine : public entityx::Receiver<Engine> {
public:
+ /**
+ * A flag to indicate if a thread should continue to run.
+ */
bool shouldRun;
+ /**
+ * Handles game systems.
+ */
entityx::SystemManager systems;
explicit Engine(void);
+ /**
+ * Initializes the game engine, and all systems used within it.
+ */
void init(void);
+
+ /**
+ * Updates all rendering systems.
+ * @param dt the delta time
+ */
void render(entityx::TimeDelta dt);
+
+ /**
+ * Updates all logic systems.
+ * @param dt the delta time
+ */
void update(entityx::TimeDelta dt);
+ /**
+ * A shortcut to get a system, for calling system-specific functions.
+ * Takes the type of the desired system.
+ */
template<typename T>
inline T* getSystem(void) {
return dynamic_cast<T*>(systems.system<T>().get());
}
- /*void configure(entityx::EventManager &ev) {
- (void)ev;
- }*/
-
+ /**
+ * A handler for the game ending event.
+ * @param gee game end event data
+ */
inline void receive(const GameEndEvent &gee) {
shouldRun = !(gee.really);
}
@@ -38,16 +71,27 @@ public:
namespace game {
+ /**
+ * Handles all game events.
+ */
extern entityx::EventManager events;
+
+ /**
+ * Handles entity data.
+ */
extern entityx::EntityManager entities;
+ /**
+ * An instance of the main game engine.
+ */
extern Engine engine;
+ /**
+ * Ends the game.
+ */
inline void endGame(void) {
events.emit<GameEndEvent>();
}
-
- //extern SpriteLoader sprite_l;
}
diff --git a/include/gametime.hpp b/include/gametime.hpp
index a809ef9..988533a 100644
--- a/include/gametime.hpp
+++ b/include/gametime.hpp
@@ -1,16 +1,52 @@
+/**
+ * @file gametime.hpp
+ * @brief Handles time related operations
+ */
+
#ifndef GAMETIME_H_
#define GAMETIME_H_
namespace game {
namespace time {
+ /**
+ * Sets the game's tick count to the desired amount.
+ * @param t desired tick count
+ */
void setTickCount(unsigned int t);
+
+ /**
+ * Gets the current tick count.
+ * @return the tick count
+ */
unsigned int getTickCount(void);
+
+ /**
+ * Calculates and returns the delta time.
+ * @return the delta time
+ */
unsigned int getDeltaTime(void);
+ /**
+ * Increments the game's tick count.
+ */
void tick(void);
+
+ /**
+ * Increments the game's tick count by the given amount of ticks.
+ * @param ticks the number of ticks to add
+ */
void tick(unsigned int ticks);
+
+ /**
+ * Determines if a tick has passed since the last call to this function.
+ * @return if a tick has passed
+ */
bool tickHasPassed(void);
+ /**
+ * Handles time updating.
+ * This should be called from the game's main loop.
+ */
void mainLoopHandler(void);
}
}
diff --git a/include/player.hpp b/include/player.hpp
index 59d6368..85dc821 100644
--- a/include/player.hpp
+++ b/include/player.hpp
@@ -1,3 +1,8 @@
+/**
+ * @file player.hpp
+ * @brief The player system
+ */
+
#ifndef PLAYER_HPP_
#define PLAYER_HPP_
@@ -8,8 +13,15 @@
#include <components.hpp>
#include <common.hpp>
+/**
+ * The constant velocity the player is given when moved with the arrow keys.
+ */
constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
+/**
+ * @class PlayerSystem
+ * Controls a player, with keyboard and stuff.
+ */
class PlayerSystem : public entityx::System<PlayerSystem>, public entityx::Receiver<PlayerSystem> {
private:
entityx::Entity player;
@@ -23,18 +35,50 @@ public:
PlayerSystem(void)
: moveLeft(false), moveRight(false), speed(1.0f) {}
+ /**
+ * Creates the player, adding it to the entity system.
+ */
void create(void);
+ /**
+ * Configures events for use with the entity system.
+ */
void configure(entityx::EventManager&);
+ /**
+ * Updates the player, mainly the player's velocity.
+ */
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
+ /**
+ * Handles key up events for the player.
+ * @param kue key up event data
+ */
void receive(const KeyUpEvent&);
+
+ /**
+ * Handles key down events for the player.
+ * @param kde key down event data
+ */
void receive(const KeyDownEvent&);
+ /**
+ * Gets the player's position.
+ * @return the player's position
+ */
vec2 getPosition(void) const;
+
+ /**
+ * Sets the player's X coordinate.
+ * @param x the x coordinate to give the player
+ */
inline void setX(const float& x)
{ player.component<Position>().get()->x = x; }
+
+ /**
+ * Gets the width of the player.
+ * @return the player's width, according to its sprite
+ */
inline float getWidth(void) const
{ return game::entities.component<Solid>(player.id())->width; }
};
diff --git a/include/save_util.hpp b/include/save_util.hpp
deleted file mode 100644
index 3d5cf54..0000000
--- a/include/save_util.hpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef SAVE_UTIL_H_
-#define SAVE_UTIL_H_
-
-/*
- * Save macros.
- */
-
-#define E_SAVE_COORDS { xmle->SetAttribute("x", loc.x); xmle->SetAttribute("y", loc.y); }
-
-#define E_SAVE_HEALTH xmle->SetAttribute("health", health);
-
-/*
- * Load macos.
- */
-
-#define E_LOAD_COORDS(yy) { float n; \
- if (xmle->QueryFloatAttribute("x", &n) == XML_NO_ERROR) \
- spawn(n, yy); \
- else \
- spawn(xmle->FloatAttribute("spawnx"), 100); \
- \
- if (xmle->QueryFloatAttribute("y", &n) == XML_NO_ERROR) \
- loc.y = n; }
-
-#define E_LOAD_HEALTH { float n; \
- \
- if (xmle->QueryFloatAttribute("maxHealth", &n) != XML_NO_ERROR) \
- maxHealth = 1; \
- \
- if (xmle->QueryFloatAttribute("health", &n) == XML_NO_ERROR) \
- health = n; \
- else \
- health = maxHealth; }
-
-
-#endif // SAVE_UTIL_H_
diff --git a/include/shader_utils.hpp b/include/shader_utils.hpp
index 243b3d4..08ca7b3 100644
--- a/include/shader_utils.hpp
+++ b/include/shader_utils.hpp
@@ -1,8 +1,11 @@
/**
+ * @file shader_utils.hpp
+ * @brief Utilities to use to handle GLSL shaders.
* From the OpenGL Programming wikibook: http://en.wikibooks.org/wiki/OpenGL_Programming
* This file is in the public domain.
* Contributors: Sylvain Beucler, Guus Sliepen
*/
+
#ifndef _CREATE_SHADER_H
#define _CREATE_SHADER_H
diff --git a/include/ui.hpp b/include/ui.hpp
index 8d517c7..519d259 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -39,8 +39,8 @@
** The UI namespace
** --------------------------------------------------------------------------*/
-void setControl(unsigned int index, SDL_Keycode key);
-SDL_Keycode getControl(unsigned int index);
+void setControl(int index, SDL_Keycode key);
+SDL_Keycode getControl(int index);
#include <entityx/entityx.h>
@@ -92,7 +92,7 @@ namespace ui {
void setFontFace(const char *ttf);
void setFontSize(unsigned int size);
- void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a);
+ void setFontColor(int r, int g, int b, int a);
void setFontZ(float z);
/*
@@ -145,8 +145,6 @@ namespace ui {
void drawFade(void);
void fadeUpdate(void);
- void quitGame();
-
/*
* Toggle the black overlay thing.
*/
diff --git a/include/ui_quest.hpp b/include/ui_quest.hpp
index 8582b67..d770011 100644
--- a/include/ui_quest.hpp
+++ b/include/ui_quest.hpp
@@ -1,3 +1,8 @@
+/**
+ * @file ui_quest.hpp
+ * @brief Handles UI elements related to quests.
+ */
+
#ifndef UI_QUEST_HPP_
#define UI_QUEST_HPP_
@@ -6,12 +11,20 @@
namespace ui {
namespace quest {
+ /**
+ * A flag to determine if the UI should be drawn.
+ */
bool _toggle = false;
- void toggle(void) {
- _toggle ^= true;
- }
+ /**
+ * Toggles displaying of the UI.
+ */
+ inline void toggle(void)
+ { _toggle ^= true; }
+ /**
+ * Draws the quest UI to the screen, if enabled.
+ */
void draw(void) {
static unsigned int textWrap = 40;
diff --git a/src/components.cpp b/src/components.cpp
index 8a66f80..f95f46f 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -10,6 +10,8 @@
#include <brice.hpp>
#include <quest.hpp>
+#include <atomic>
+
static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us"));
void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -19,6 +21,11 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
position.x += direction.x * dt;
position.y += direction.y * dt;
+ if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
+ auto animate = entity.component<Animate>();
+ entity.component<Sprite>()->sprite =
+ (direction.x != 0) ? animate->nextFrame() : animate->firstFrame();
+ }
if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
direction.x = 0;
} else {
@@ -73,6 +80,7 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
Render::worldShader.use();
en.each<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
+ (void)entity;
// Verticies and shit
GLfloat tex_coord[] = {0.0, 0.0,
1.0, 0.0,
@@ -90,10 +98,6 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
1.0, 1.0,
1.0, 0.0};
- if (entity.has_component<Animate>()) {
- sprite.sprite = entity.component<Animate>().get()->nextFrame();
- }
-
for (auto &S : sprite.sprite) {
const auto& size = S.first.tex.getDim() * game::HLINE;
@@ -151,97 +155,100 @@ void DialogSystem::receive(const MouseClickEvent &mce)
{
game::entities.each<Position, Solid, Dialog, Name>(
[&](entityx::Entity e, Position &pos, Solid &dim, Dialog &d, Name &name) {
+ static std::atomic_bool dialogRun;
(void)e;
(void)d;
if (((mce.position.x > pos.x) & (mce.position.x < pos.x + dim.width)) &&
((mce.position.y > pos.y) & (mce.position.y < pos.y + dim.height))) {
- std::thread([&] {
- std::string questAssignedText;
- int newIndex;
-
- auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog");
-
- if (e.has_component<Direction>())
- d.talking = true;
-
- if (d.index == 9999) {
- ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]);
- ui::waitForDialog();
- } else if (exml != nullptr) {
- while (exml->StrAttribute("name") != name.name)
- exml = exml->NextSiblingElement();
-
- exml = exml->FirstChildElement("text");
- while (exml->IntAttribute("id") != d.index)
- exml = exml->NextSiblingElement();
-
- auto oxml = exml->FirstChildElement("set");
- if (oxml != nullptr) {
- do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value"));
- while ((oxml = oxml->NextSiblingElement()));
- game::briceUpdate();
- }
-
- auto qxml = exml->FirstChildElement("quest");
- if (qxml != nullptr) {
- const char *qname;
- auto qsys = game::engine.getSystem<QuestSystem>();
-
- do {
- // assign quest
- qname = qxml->Attribute("assign");
- if (qname != nullptr) {
- questAssignedText = qname;
- auto req = qxml->GetText();
- qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : "");
- }
-
- // check / finish quest
- else {
- qname = qxml->Attribute("check");
+ if (!dialogRun.load()) {
+ std::thread([&] {
+ std::string questAssignedText;
+ int newIndex;
+
+ auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog");
+ dialogRun.store(true);
+
+ if (e.has_component<Direction>())
+ d.talking = true;
+
+ if (d.index == 9999) {
+ ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]);
+ ui::waitForDialog();
+ } else if (exml != nullptr) {
+ while (exml->StrAttribute("name") != name.name)
+ exml = exml->NextSiblingElement();
+
+ exml = exml->FirstChildElement("text");
+ while (exml->IntAttribute("id") != d.index)
+ exml = exml->NextSiblingElement();
+
+ auto oxml = exml->FirstChildElement("set");
+ if (oxml != nullptr) {
+ do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value"));
+ while ((oxml = oxml->NextSiblingElement()));
+ game::briceUpdate();
+ }
+
+ auto qxml = exml->FirstChildElement("quest");
+ if (qxml != nullptr) {
+ const char *qname;
+ auto qsys = game::engine.getSystem<QuestSystem>();
+
+ do {
+ // assign quest
+ qname = qxml->Attribute("assign");
if (qname != nullptr) {
- if (qname != nullptr && qsys->hasQuest(qname) && qsys->finish(qname) == 0) {
- d.index = 9999;
- } else {
- ui::dialogBox(name.name, "", false, "Finish my quest u nug");
- ui::waitForDialog();
- return;
- }
- // oldidx = d.index;
- // d.index = qxml->UnsignedAttribute("fail");
- // goto COMMONAIFUNC;
+ questAssignedText = qname;
+ auto req = qxml->GetText();
+ qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : "");
}
- }
- } while((qxml = qxml->NextSiblingElement()));
- }
- auto cxml = exml->FirstChildElement("content");
- const char *content;
- if (cxml == nullptr) {
- content = randomDialog[d.rindex % randomDialog.size()].c_str();
- } else {
- content = cxml->GetText() - 1;
- while (*++content && isspace(*content));
+ // check / finish quest
+ else {
+ qname = qxml->Attribute("check");
+ if (qname != nullptr) {
+ if (qname != nullptr && qsys->hasQuest(qname) && qsys->finish(qname) == 0) {
+ d.index = 9999;
+ } else {
+ ui::dialogBox(name.name, "", false, "Finish my quest u nug");
+ ui::waitForDialog();
+ return;
+ }
+ // oldidx = d.index;
+ // d.index = qxml->UnsignedAttribute("fail");
+ // goto COMMONAIFUNC;
+ }
+ }
+ } while((qxml = qxml->NextSiblingElement()));
+ }
+
+ auto cxml = exml->FirstChildElement("content");
+ const char *content;
+ if (cxml == nullptr) {
+ content = randomDialog[d.rindex % randomDialog.size()].c_str();
+ } else {
+ content = cxml->GetText() - 1;
+ while (*++content && isspace(*content));
+ }
+
+ ui::dialogBox(name.name, "", false, content);
+ ui::waitForDialog();
+
+ if (!questAssignedText.empty())
+ ui::passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str());
+
+ if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
+ d.index = newIndex;
}
- ui::dialogBox(name.name, "", false, content);
- ui::waitForDialog();
-
- if (!questAssignedText.empty())
- ui::passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str());
-
- if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
- d.index = newIndex;
- }
-
- d.talking = false;
- }).detach();
-
+ d.talking = false;
+ dialogRun.store(false);
+ }).detach();
}
}
- );
+ });
}
void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -267,10 +274,8 @@ std::vector<Frame> developFrame(XMLElement* xml)
auto sxml = framexml->FirstChildElement();
while (sxml) {
std::string sname = sxml->Name();
- if (sname == "src") {
+ if (sname == "src")
tmpf.push_back(std::make_pair(SpriteData(sxml->GetText(), vec2(0,0)), vec2(0,0)));
- //std::cout << tmpf.back().first.pic << std::endl;
- }
sxml = sxml->NextSiblingElement();
}
tmp.push_back(tmpf);
diff --git a/src/ui.cpp b/src/ui.cpp
index e87c74a..a154d7e 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -20,14 +20,14 @@ std::array<SDL_Keycode, 6> controlMap = {
SDLK_w, SDLK_a, SDLK_d, SDLK_LSHIFT, SDLK_LCTRL, SDLK_e
};
-void setControl(unsigned int index, SDL_Keycode key)
+void setControl(int index, SDL_Keycode key)
{
controlMap[index] = key;
}
-SDL_Keycode getControl(unsigned int index)
+SDL_Keycode getControl(int index)
{
- if (index >= controlMap.size())
+ if (index >= static_cast<int>(controlMap.size()))
return 0;
return controlMap[index];
@@ -57,7 +57,7 @@ static bool ft24loaded = false;
static auto *ftdat = &ftdat16;
static auto *ftex = &ftex16;
-static unsigned char fontColor[4] = {255,255,255,255};
+static Color fontColor (255, 255, 255, 255);
/*
* Variables for dialog boxes / options.
@@ -87,57 +87,45 @@ Mix_Chunk *sanic;
static GLuint pageTex = 0;
static bool pageTexReady = false;
-void loadFontSize(unsigned int size, std::vector<GLuint> &tex, std::vector<FT_Info> &dat)
+void loadFontSize(int size, std::vector<GLuint> &tex, std::vector<FT_Info> &dat)
{
FT_Set_Pixel_Sizes(ftf,0,size);
- /*
- * Pre-render 'all' the characters.
- */
-
+ // pre-render 'all' the characters
glDeleteTextures(93, tex.data());
glGenTextures(93, tex.data()); // Generate new texture name/locations?
- for(char i=33;i<126;i++) {
-
- /*
- * Load the character from the font family file.
- */
-
- if (FT_Load_Char (ftf, i, FT_LOAD_RENDER))
+ for (char i = 33; i < 126; i++) {
+ // load the character from the font family file
+ if (FT_Load_Char(ftf, i, FT_LOAD_RENDER))
UserError("Error! Unsupported character " + i);
- /*
- * Transfer the character's bitmap (?) to a texture for rendering.
- */
-
- glBindTexture(GL_TEXTURE_2D,tex[i-33]);
- glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S ,GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T ,GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER ,GL_LINEAR );
- glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER ,GL_LINEAR );
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
-
- /*
- * The just-created texture will render red-on-black if we don't do anything to it, so
- * here we create a buffer 4 times the size and transform the texture into an RGBA array,
- * making it white-on-black.
- */
-
-
- std::vector<uint32_t> buf (ftf->glyph->bitmap.width * ftf->glyph->bitmap.rows, 0xFFFFFFFF);
-
- for(unsigned int j = buf.size(); j--;)
- buf[j] ^= !ftf->glyph->bitmap.buffer[j] ? buf[j] : 0;
-
- dat[i - 33].wh.x = ftf->glyph->bitmap.width;
- dat[i - 33].wh.y = ftf->glyph->bitmap.rows;
- dat[i - 33].bl.x = ftf->glyph->bitmap_left;
- dat[i - 33].bl.y = ftf->glyph->bitmap_top;
- dat[i - 33].ad.x = ftf->glyph->advance.x >> 6;
- dat[i - 33].ad.y = ftf->glyph->advance.y >> 6;
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ftf->glyph->bitmap.width, ftf->glyph->bitmap.rows,
+ // transfer the character's bitmap (?) to a texture for rendering
+ glBindTexture(GL_TEXTURE_2D, tex[i - 33]);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ /**
+ * The just-created texture will render red-on-black if we don't do anything to it, so
+ * here we create a buffer 4 times the size and transform the texture into an RGBA array,
+ * making it white-on-black.
+ */
+ auto& g = ftf->glyph;
+ std::vector<uint32_t> buf (g->bitmap.width * g->bitmap.rows, 0xFFFFFFFF);
+ for (auto j = buf.size(); j--;)
+ buf[j] ^= !g->bitmap.buffer[j] ? buf[j] : 0;
+
+ auto& d = dat[i - 33];
+ d.wh.x = g->bitmap.width;
+ d.wh.y = g->bitmap.rows;
+ d.bl.x = g->bitmap_left;
+ d.bl.y = g->bitmap_top;
+ d.ad.x = g->advance.x >> 6;
+ d.ad.y = g->advance.y >> 6;
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g->bitmap.width, g->bitmap.rows,
0, GL_RGBA, GL_UNSIGNED_BYTE, buf.data());
}
}
@@ -200,7 +188,7 @@ namespace ui {
UserError("Couldn't initialize freetype.");
#ifdef DEBUG
- DEBUG_printf("Initialized FreeType2.\n",NULL);
+ DEBUG_printf("Initialized FreeType2.\n", nullptr);
#endif // DEBUG
fontSize = 0;
@@ -232,6 +220,7 @@ namespace ui {
#ifdef DEBUG
DEBUG_printf("Using font %s\n",ttf);
#endif // DEBUG
+
ft16loaded = false;
ft24loaded = false;
}
@@ -241,42 +230,24 @@ namespace ui {
*/
void setFontSize(unsigned int size) {
- (void)size;
- if (size == 16) {
- if (!ft16loaded) {
- loadFontSize(fontSize = size, ftex16, ftdat16);
- ft16loaded = true;
- }
- ftex = &ftex16;
- ftdat = &ftdat16;
- fontSize = 16;
- } else if (size == 24) {
- if (!ft24loaded) {
- loadFontSize(fontSize = size, ftex24, ftdat24);
- ft24loaded = true;
- }
- ftex = &ftex24;
- ftdat = &ftdat24;
- fontSize = 24;
+ auto& loaded = (size == 16) ? ft16loaded : ft24loaded;
+ auto& tex = (size == 16) ? ftex16 : ftex24;
+ auto& dat = (size == 16) ? ftdat16 : ftdat24;
+
+ if (!loaded) {
+ loadFontSize(fontSize = size, tex, dat);
+ loaded = true;
}
+ ftex = &tex;
+ ftdat = &dat;
+ fontSize = size;
}
/*
* Set a color for font rendering (default: white).
- */
-
- void setFontColor(unsigned char r,unsigned char g,unsigned char b) {
- fontColor[0]=r;
- fontColor[1]=g;
- fontColor[2]=b;
- fontColor[3]=255;
- }
-
- void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a) {
- fontColor[0]=r;
- fontColor[1]=g;
- fontColor[2]=b;
- fontColor[3]=a;
+ */
+ void setFontColor(int r, int g, int b, int a = 255) {
+ fontColor = Color(r, g, b, a);
}
/*
@@ -288,65 +259,53 @@ namespace ui {
/*
* Draws a character at the specified coordinates, aborting if the character is unknown.
- */
-
+ */
vec2 putChar(float xx,float yy,char c){
- vec2 c1,c2;
-
+ const auto& ch = (*ftdat)[c - 33];
int x = xx, y = yy;
- /*
- * Get the width and height of the rendered character.
- */
-
- c1={(float)floor(x)+(*ftdat)[c-33].bl.x,
- (float)floor(y)+(*ftdat)[c-33].bl.y};
- c2=(*ftdat)[c-33].wh;
-
- /*
- * Draw the character:
- */
+ // get dimensions of the rendered character
+ vec2 c1 = {
+ static_cast<float>(floor(x) + ch.bl.x),
+ static_cast<float>(floor(y) + ch.bl.y)
+ };
+ const auto& c2 = ch.wh;
+ // draw the character
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,(*ftex)[c-33]);
+ glBindTexture(GL_TEXTURE_2D, (*ftex)[c - 33]);
glUniform1i(Render::textShader.uniform[WU_texture], 0);
glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, 1.0f);
- //glDisable(GL_DEPTH_TEST);
-
Render::textShader.use();
Render::textShader.enable();
-
GLfloat tex_coord[] = {
0.0, 1.0, //bottom left
1.0, 1.0, //bottom right
1.0, 0.0, //top right
-
1.0, 0.0, //top right
0.0, 0.0, //top left
0.0, 1.0, //bottom left
-
};
GLfloat text_vert[] = {
c1.x, c1.y -c2.y, fontZ, //bottom left
c1.x+c2.x, c1.y -c2.y, fontZ, //bottom right
c1.x+c2.x, c1.y+c2.y-c2.y, fontZ, //top right
-
c1.x+c2.x, c1.y+c2.y-c2.y, fontZ, //top right
c1.x, c1.y+c2.y-c2.y, fontZ, //top left
c1.x, c1.y -c2.y, fontZ //bottom left
};
glUniform4f(Render::textShader.uniform[WU_tex_color],
- static_cast<float>(fontColor[0]/255),
- static_cast<float>(fontColor[1]/255),
- static_cast<float>(fontColor[2]/255),
- static_cast<float>(fontColor[3]/255));
+ static_cast<float>(fontColor.red / 255),
+ static_cast<float>(fontColor.green / 255),
+ static_cast<float>(fontColor.blue / 255),
+ static_cast<float>(fontColor.alpha / 255));
glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, text_vert);
- glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
+ glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
glDrawArrays(GL_TRIANGLES, 0, 6);
glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
@@ -354,10 +313,8 @@ namespace ui {
Render::textShader.disable();
Render::textShader.unuse();
- //glEnable(GL_DEPTH_TEST);
-
// return the width.
- return (*ftdat)[c-33].ad;
+ return ch.ad;
}
/*
@@ -368,13 +325,9 @@ namespace ui {
unsigned int i = 0, nl = 1;
vec2 add, o = {x, y};
- /*
- * Loop on each character:
- */
-
+ // loop on each character
do {
if (dialogBoxExists && i > textWrapLimit * nl) {
-
o.y -= fontSize * 1.05f;
o.x = x;
++nl;
@@ -385,14 +338,13 @@ namespace ui {
}
switch (s[i]) {
+ case '\r':
+ case '\t':
+ break;
case '\n':
o.y -= fontSize * 1.05f;
o.x = x;
break;
- case '\r':
- break;
- case '\t':
- break;
case '\b':
o.x -= add.x;
break;
@@ -407,7 +359,7 @@ namespace ui {
}
} while (s[++i]);
- return o.x; // i.e. the string width
+ return o.x; // the string width
}
float putStringCentered(const float x, const float y, std::string s) {
@@ -505,40 +457,36 @@ namespace ui {
* Draw a formatted string to the specified coordinates.
*/
- float putText(const float x, const float y, const char *str, ...) {
- va_list args;
+ std::string uisprintf(const char *s, va_list args) {
std::unique_ptr<char[]> buf (new char[512]);
+ vsnprintf(buf.get(), 512, s, args);
+ std::string ret (buf.get());
+ return ret;
+ }
- // zero out the buffer
- memset(buf.get(),0,512*sizeof(char));
-
- /*
- * Handle the formatted string, printing it to the buffer.
- */
-
+ float putText(const float x, const float y, const char *str, ...) {
+ va_list args;
+
va_start(args,str);
- vsnprintf(buf.get(),512,str,args);
+ auto s = uisprintf(str, args);
va_end(args);
// draw the string and return the width
- return putString(x, y, buf.get());
+ return putString(x, y, s);
}
void putTextL(vec2 c, const char *str, ...) {
va_list args;
- std::unique_ptr<char[]> buf (new char[512]);
- memset(buf.get(), 0, 512 * sizeof(char));
va_start(args, str);
- vsnprintf(buf.get(), 512, str, args);
+ auto s = uisprintf(str, args);
va_end(args);
- textToDraw.push_back(std::make_pair(c, buf.get()));
+ textToDraw.push_back(std::make_pair(c, s));
}
void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...) {
- va_list dialogArgs;
- std::unique_ptr<char[]> printfbuf (new char[512]);
+ va_list args;
dialogPassive = passive;
@@ -546,14 +494,14 @@ namespace ui {
dialogBoxText = name + ": ";
// handle the formatted string
- va_start(dialogArgs, text);
- vsnprintf(printfbuf.get(), 512, text.c_str(), dialogArgs);
- va_end(dialogArgs);
- dialogBoxText += printfbuf.get();
+ va_start(args, text);
+ auto s = uisprintf(text.c_str(), args);
+ va_end(args);
+
+ dialogBoxText += s;
// setup option text
dialogOptText.clear();
-
dialogOptChosen = 0;
if (!opt.empty()) {
@@ -562,14 +510,11 @@ namespace ui {
// cycle through options
while (sopt) {
dialogOptText.push_back(std::make_pair((std::string)sopt, vec3 {0,0,0}));
- sopt = strtok(NULL,":");
+ sopt = strtok(nullptr, ":");
}
}
- /*
- * Tell draw() that the box is ready.
- */
-
+ // tell draw() that the box is ready
dialogBoxExists = true;
dialogImportant = false;
@@ -599,21 +544,16 @@ namespace ui {
fadeIntensity = 0;
}
- void waitForNothing(unsigned int ms) {
- unsigned int target = millis() + ms;
- while (millis() < target);
- }
-
- void importantText(const char *text,...) {
- va_list textArgs;
- std::unique_ptr<char[]> printfbuf (new char[512]);
+ void importantText(const char *text, ...) {
+ va_list args;
dialogBoxText.clear();
- va_start(textArgs,text);
- vsnprintf(printfbuf.get(),512,text,textArgs);
- va_end(textArgs);
- dialogBoxText = printfbuf.get();
+ va_start(args, text);
+ auto s = uisprintf(text, args);
+ va_end(args);
+
+ dialogBoxText = s;
dialogBoxExists = true;
dialogImportant = true;
@@ -622,15 +562,15 @@ namespace ui {
}
void passiveImportantText(int duration, const char *text, ...) {
- va_list textArgs;
- std::unique_ptr<char[]> printfbuf (new char[512]);
+ va_list args;
dialogBoxText.clear();
- va_start(textArgs,text);
- vsnprintf(printfbuf.get(),512,text,textArgs);
- va_end(textArgs);
- dialogBoxText = printfbuf.get();
+ va_start(args, text);
+ auto s = uisprintf(text, args);
+ va_end(args);
+
+ dialogBoxText = s;
dialogBoxExists = true;
dialogImportant = true;
@@ -867,13 +807,14 @@ namespace ui {
offset.x - 300, SCREEN_HEIGHT - 600, -6.0,
offset.x - 300, SCREEN_HEIGHT - 100, -6.0};
- GLfloat page_tex[] = {0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
-
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0};
+ static const GLfloat page_tex[] = {
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0
+ };
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, pageTex);
@@ -893,7 +834,7 @@ namespace ui {
rtext = typeOut(dialogBoxText);
if (dialogImportant) {
- setFontColor(255,255,255);
+ setFontColor(255, 255, 255);
if (dialogPassive) {
dialogPassiveTime -= game::time::getDeltaTime() * 12;
if (dialogPassiveTime < 0) {
@@ -920,21 +861,21 @@ namespace ui {
putString(x + HLINES(2), y - fontSize - game::HLINE, rtext);
for (i = 0; i < dialogOptText.size(); i++) {
- float tmp;
- setFontColor(255,255,255);
- tmp = putStringCentered(offset.x,dialogOptText[i].second.y,dialogOptText[i].first);
- dialogOptText[i].second.z = offset.x + tmp;
- dialogOptText[i].second.x = offset.x - tmp;
- dialogOptText[i].second.y = y - SCREEN_HEIGHT / 4 + (fontSize + game::HLINE) * (i + 1);
- if (mouse.x > dialogOptText[i].second.x &&
- mouse.x < dialogOptText[i].second.z &&
- mouse.y > dialogOptText[i].second.y &&
- mouse.y < dialogOptText[i].second.y + 16) { // fontSize
- setFontColor(255,255,0);
- putStringCentered(offset.x,dialogOptText[i].second.y,dialogOptText[i].first);
+ auto& sec = dialogOptText[i].second;
+
+ setFontColor(255, 255, 255);
+ auto tmp = putStringCentered(offset.x, sec.y,dialogOptText[i].first);
+ sec.z = offset.x + tmp;
+ sec.x = offset.x - tmp;
+ sec.y = y - SCREEN_HEIGHT / 4 + (fontSize + game::HLINE) * (i + 1);
+ if (mouse.x > sec.x && mouse.x < sec.z &&
+ mouse.y > sec.y && mouse.y < sec.y + 16) { // fontSize
+ setFontColor(255, 255, 0);
+ putStringCentered(offset.x, sec.y, dialogOptText[i].first);
}
}
- setFontColor(255,255,255);
+
+ setFontColor(255, 255, 255);
}
static unsigned int rtext_oldsize = 0;
@@ -1031,22 +972,12 @@ namespace ui {
}
}
- void quitGame() {
- dialogBoxExists = false;
- currentMenu = NULL;
- game::config::update();
- game::config::save();
- game::endGame();
- }
-
void closeBox() {
dialogBoxExists = false;
dialogMerchant = false;
}
void dialogAdvance(void) {
- unsigned char i;
-
dialogPassive = false;
dialogPassiveTime = 0;
@@ -1063,17 +994,16 @@ namespace ui {
return;
}
- for(i=0;i<dialogOptText.size();i++) {
- if (mouse.x > dialogOptText[i].second.x &&
- mouse.x < dialogOptText[i].second.z &&
- mouse.y > dialogOptText[i].second.y &&
- mouse.y < dialogOptText[i].second.y + 16) { // fontSize
+ for (int i = 0; i < static_cast<int>(dialogOptText.size()); i++) {
+ const auto& dot = dialogOptText[i].second;
+
+ if (mouse.x > dot.x && mouse.x < dot.z &&
+ mouse.y > dot.y && mouse.y < dot.y + 16) { // fontSize
dialogOptChosen = i + 1;
- goto EXIT;
+ break;
}
}
-EXIT:
dialogBoxExists = false;
// handle important text
@@ -1084,8 +1014,8 @@ EXIT:
}
void drawFade(void) {
- auto SCREEN_WIDTH = game::SCREEN_WIDTH;
- auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+ auto SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2;
+ auto SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2;
if (!fadeIntensity) {
if (fontSize != 16)
@@ -1096,16 +1026,19 @@ EXIT:
ColorTex fadeTex (fadeWhite ? Color(255, 255, 255, fadeIntensity) :
Color(0, 0, 0, fadeIntensity));
+ static const GLfloat tex[] = {
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 0.0, 1.0,
+ 1.0, 1.0
+ };
- GLfloat tex[] = {0.0, 0.0,
- 1.0, 0.0,
- 0.0, 1.0,
- 1.0, 1.0};
-
- GLfloat backdrop[] = {offset.x - SCREEN_WIDTH / 2 - 1, offset.y - SCREEN_HEIGHT / 2, -7.9,
- offset.x + SCREEN_WIDTH / 2, offset.y - SCREEN_HEIGHT / 2, -7.9,
- offset.x - SCREEN_WIDTH / 2 - 1, offset.y + SCREEN_HEIGHT / 2, -7.9,
- offset.x + SCREEN_WIDTH / 2, offset.y + SCREEN_HEIGHT / 2, -7.9};
+ GLfloat backdrop[] = {
+ offset.x - SCREEN_WIDTH2 - 1, offset.y - SCREEN_HEIGHT2, -7.9,
+ offset.x + SCREEN_WIDTH2, offset.y - SCREEN_HEIGHT2, -7.9,
+ offset.x - SCREEN_WIDTH2 - 1, offset.y + SCREEN_HEIGHT2, -7.9,
+ offset.x + SCREEN_WIDTH2, offset.y + SCREEN_HEIGHT2, -7.9
+ };
setFontZ(-8.2);
glUniform1i(Render::textShader.uniform[WU_texture], 0);
@@ -1179,7 +1112,7 @@ EXIT:
bgr[x+2] = pixels[x];
}
- time_t epoch = time(NULL);
+ time_t epoch = time(nullptr);
struct tm* timen = localtime(&epoch);
std::string name = "screenshots/";
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index 779feda..cbf30be 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -22,8 +22,16 @@ void Menu::gotoParent(void)
}
}
-inline void segFault() {
- (*((int *)NULL))++;
+inline void segFault(void)
+{
+ ++*((int *)0);
+}
+
+void quitGame(void)
+{
+ game::config::update();
+ game::config::save();
+ game::endGame();
}
std::string& deleteWord(std::string& s)
@@ -120,7 +128,7 @@ namespace ui {
temp.button.dim = d;
temp.button.color = c;
temp.button.text = t;
- temp.button.func = NULL;
+ temp.button.func = nullptr;
temp.child = _child;
return temp;
@@ -134,7 +142,7 @@ namespace ui {
temp.button.dim = d;
temp.button.color = c;
temp.button.text = t;
- temp.button.func = NULL;
+ temp.button.func = nullptr;
temp.child = nullptr;
return temp;
@@ -162,7 +170,7 @@ namespace ui {
pauseMenu.items.push_back(ui::menu::createParentButton({-128,100},{256,75},{0.0f,0.0f,0.0f}, "Resume"));
pauseMenu.items.push_back(ui::menu::createChildButton({-128, 0},{256,75},{0.0f,0.0f,0.0f}, "Options", &optionsMenu));
pauseMenu.items.push_back(ui::menu::createChildButton({-128,-100},{256,75},{0.0f,0.0f,0.0f}, "Controls", &controlsMenu));
- pauseMenu.items.push_back(ui::menu::createButton({-128,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame));
+ pauseMenu.items.push_back(ui::menu::createButton({-128,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", quitGame));
pauseMenu.items.push_back(ui::menu::createButton({-128,-300},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault));
// Create the options (sound) menu
@@ -319,7 +327,7 @@ namespace ui {
cMult = 0.75f;
//if we are inside the slider and click it will set the slider to that point
- if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
+ if (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
//change handle location
if (m.slider.dim.y > m.slider.dim.x) {
*m.slider.var = (((mouse.y-offset.y) - m.slider.loc.y)/m.slider.dim.y)*100;
diff --git a/src/world.cpp b/src/world.cpp
index 059b6c7..c458ab0 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -190,17 +190,14 @@ void WorldSystem::load(const std::string& file)
entityx::Entity entity;
- std::string xmlRaw;
- std::string xmlPath;
-
// check for empty file name
if (file.empty())
return;
// load file data to string
- xmlPath = xmlFolder + file;
+ auto xmlPath = xmlFolder + file;
auto xmlRawData = readFile(xmlPath.c_str());
- xmlRaw = xmlRawData;
+ std::string xmlRaw = xmlRawData;
delete[] xmlRawData;
// let tinyxml parse the file
@@ -209,18 +206,23 @@ void WorldSystem::load(const std::string& file)
// include headers
auto ixml = xmlDoc.FirstChildElement("include");
- while (ixml) {
+ while (ixml != nullptr) {
auto file = ixml->Attribute("file");
+
if (file != nullptr) {
DEBUG_printf("Including file: %s\n", file);
auto include = readFile((xmlFolder + file).c_str());
xmlRaw.append(include);
delete[] include;
+ } else {
+ UserError("XML Error: <include> tag file not given");
}
- ixml = ixml->NextSiblingElement();
+
+ break;//ixml = ixml->NextSiblingElement();
}
- xmlDoc.Parse(xmlRaw.data());
+ if (xmlDoc.Parse(xmlRaw.data()) != XML_NO_ERROR)
+ UserError("XML Error:");
// look for an opening world tag
auto wxml = xmlDoc.FirstChildElement("World");
@@ -1043,19 +1045,22 @@ void WorldSystem::render(void)
static const float e = static_cast<float>(SCREEN_WIDTH) / 2.0f;
static const float sheight = static_cast<float>(SCREEN_HEIGHT);
+
if (offset.x + world.startX > s) {
Colors::black.use();
glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f);
+ auto off = offset.y - static_cast<float>(SCREEN_HEIGHT) / 2.0f;
+
GLfloat blackBarLeft[] = {
- s, 0.0f, -3.5f, 0.0f, 0.0f,
- world.startX, 0.0f, -3.5f, 1.0f, 0.0f,
- world.startX, sheight, -3.5f, 1.0f, 1.0f,
+ s, 0.0f + off, -3.5f, 0.0f, 0.0f,
+ world.startX, 0.0f + off, -3.5f, 1.0f, 0.0f,
+ world.startX, sheight + off, -3.5f, 1.0f, 1.0f,
- world.startX, sheight, -3.5f, 1.0f, 1.0f,
- s, sheight, -3.5f, 0.0f, 1.0f,
- s, 0.0f, -3.5f, 0.0f, 0.0f
+ world.startX, sheight + off, -3.5f, 1.0f, 1.0f,
+ s, sheight + off, -3.5f, 0.0f, 1.0f,
+ s, 0.0f + off, -3.5f, 0.0f, 0.0f
};
glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, &blackBarLeft[0]);
@@ -1066,15 +1071,17 @@ void WorldSystem::render(void)
if (offset.x - world.startX < e) {
Colors::black.use();
glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f);
+
+ auto off = offset.y - static_cast<float>(SCREEN_HEIGHT) / 2.0f;
GLfloat blackBarRight[] = {
- -(world.startX), 0.0f, -3.5f, 0.0f, 0.0f,
- e, 0.0f, -3.5f, 1.0f, 0.0f,
- e, sheight, -3.5f, 1.0f, 1.0f,
+ -(world.startX), 0.0f + off, -3.5f, 0.0f, 0.0f,
+ e, 0.0f + off, -3.5f, 1.0f, 0.0f,
+ e, sheight + off, -3.5f, 1.0f, 1.0f,
- e, sheight, -3.5f, 1.0f, 1.0f,
- -(world.startX), sheight, -3.5f, 0.0f, 1.0f,
- -(world.startX), 0.0f, -3.5f, 0.0f, 0.0f
+ e, sheight + off, -3.5f, 1.0f, 1.0f,
+ -(world.startX), sheight + off, -3.5f, 0.0f, 1.0f,
+ -(world.startX), 0.0f + off, -3.5f, 0.0f, 0.0f
};
glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, &blackBarRight[0]);
diff --git a/xml/entities.xml b/xml/entities.xml
index 0d2a519..b447dc3 100644
--- a/xml/entities.xml
+++ b/xml/entities.xml
@@ -39,6 +39,36 @@
<frame>
<src>assets/NPC_Walk0.png</src>
</frame>
+ <frame>
+ <src>assets/NPC_Walk9.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk8.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk7.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk6.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk5.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk4.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk3.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk2.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC_Walk.png</src>
+ </frame>
+ <frame>
+ <src>assets/NPC.png</src>
+ </frame>
</movement>
</Animation>
<Direction />