]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
doc updates
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 10 Dec 2016 23:33:40 +0000 (18:33 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 10 Dec 2016 23:33:40 +0000 (18:33 -0500)
12 files changed:
include/brice.hpp
include/components.hpp
include/config.hpp
include/engine.hpp
include/gametime.hpp
include/save_util.hpp [deleted file]
include/shader_utils.hpp
include/ui_quest.hpp
src/components.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp

index dc3ea96c795e4b6850f1cd9c70a40b9d2947f9e7..1c4eccfe0dc5397876e2c7347dd93c908646eaa2 100644 (file)
@@ -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);
 }
 
index d630f83d0c9f223e504a2069c493218617708163..2e09fc79f242b14976aba492c7cb8d17d0f1feb8 100644 (file)
@@ -151,7 +151,7 @@ struct Sprite {
        Sprite(bool left = false)
                : faceLeft(left) {}
 
-       std::vector<std::pair<SpriteData, vec2>> getSprite() {
+       Frame getSprite() {
                return sprite;
        }
 
index bc9d0525ed84d9d04393387451d7572c3905cf45..908c3766d86b9791d1063f0a5445d87fbdf76f17 100644 (file)
@@ -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);
        }
 }
index c842b599333d9cce38e0c68e64d9dbd994f20083..d4028d89b66303e71a368e7f464335ba3155b727 100644 (file)
@@ -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>
 
 //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,32 @@ public:
 
 
 namespace game {
+       /**
+        * Handles all game events.
+        */
        extern entityx::EventManager events;
+
+       /**
+        * Handles entity data.
+        */
     extern entityx::EntityManager entities;
 
+       /**
+        * Handles sprite loading, for the sprite system.
+        */
+       extern SpriteLoader sprite_l;
+
+       /**
+        * An instance of the main game engine.
+        */
     extern Engine engine;
 
+       /**
+        * Ends the game.
+        */
     inline void endGame(void) {
         events.emit<GameEndEvent>();
     }
-
-       extern SpriteLoader sprite_l;
 }
 
 
index a809ef9ea9852be0b33e8f5e5970451f11c4fd0e..988533a244f7dc6c6ed7c02ea3a73295a455d3eb 100644 (file)
@@ -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/save_util.hpp b/include/save_util.hpp
deleted file mode 100644 (file)
index 3d5cf54..0000000
+++ /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_
index 243b3d4e8dd613c6c907e3927ee9e233a36ba238..08ca7b3bda33f2c57a6f20481968b6ce095abee5 100644 (file)
@@ -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
 
index 8582b67e2fd5fcec6bbcb92fc5d99e5253cccbca..d770011ce67a4b8d9cec8da2f61e1f74a20889db 100644 (file)
@@ -1,3 +1,8 @@
+/**
+ * @file ui_quest.hpp
+ * @brief Handles UI elements related to quests.
+ */
+
 #ifndef UI_QUEST_HPP_
 #define UI_QUEST_HPP_
 
 
 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;
 
index 612e52249c2accecf41acb9814689dc12701d7ac..e85883e2e8bad41c9722857bdbddf4b0874309b2 100644 (file)
@@ -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)
@@ -20,11 +22,9 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                position.y += direction.y * dt;
 
                if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
-                       if (direction.x) {
-                               entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->nextFrame();
-                       } else {
-                               entity.component<Sprite>().get()->sprite = entity.component<Animate>().get()->firstFrame();
-                       }
+                       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;
@@ -98,9 +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>()->nextFrame();
-
                for (auto &S : sprite.sprite) {
                        float width = HLINES(S.first.size.x);
                        float height = HLINES(S.first.size.y);
@@ -159,97 +156,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)
index 1994382b3cf882baa0e4ce055b955d9460b938f2..0ddc3f271dade8229f254e835b5a972cb87ea1ab 100644 (file)
@@ -200,7 +200,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;
@@ -562,7 +562,7 @@ 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, ":");
                        }
                }
 
@@ -1037,7 +1037,7 @@ namespace ui {
 
        void quitGame() {
                dialogBoxExists = false;
-               currentMenu = NULL;
+               currentMenu = nullptr;
                game::config::update();
                game::config::save();
                game::endGame();
@@ -1183,7 +1183,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/";
index 59b44e68b6578729f05ee882a9d01276c4d659b4..d853abc68e8ca8cbd5381b416163a58a49a7020b 100644 (file)
@@ -120,7 +120,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 +134,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;
@@ -320,7 +320,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;
index 4a7e284edf5c251724ca6ab817311c770be1fae5..ea2c670a229ba0285a560d7122b0df3bba78d810 100644 (file)
@@ -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();
        }
 
-       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");