From 383a7b716aff2af7f5f85278e6df49f908a8bdbf Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 15 Jun 2016 08:44:34 -0400 Subject: identation fix --- Changelog | 10 ++++++++++ brice.dat | 6 ++++-- main.cpp | 6 +++--- src/entities.cpp | 32 +++++++++++++++++++------------- xml/000.xml | 6 ++++-- xml/playerSpawnHill1.xml | 2 +- xml/playerSpawnHill1_Building1.xml | 6 +++--- 7 files changed, 44 insertions(+), 24 deletions(-) diff --git a/Changelog b/Changelog index 0f6c748..d0c136a 100644 --- a/Changelog +++ b/Changelog @@ -1052,3 +1052,13 @@ - worked on better inventory / general ui ~ more than 10800 lines of code (just counting .hpp's and .cpp's) + +6/15/2016: +========== + + - fixed major indentation problem with tinyxml + - windows build actually works first try..??? + - everybody's pushed and merged and stuff + - item rendering stuff + "I'm also trying to make it so that other entities can use items.. if that makes sense." + - Andy diff --git a/brice.dat b/brice.dat index 3b090ad..8c8c697 100644 --- a/brice.dat +++ b/brice.dat @@ -1,7 +1,9 @@ -3 +4 + + canSprint 0 canJump 0 Slow -1 +0 diff --git a/main.cpp b/main.cpp index 52841c6..f4f8e9c 100644 --- a/main.cpp +++ b/main.cpp @@ -264,8 +264,8 @@ int main(int argc, char *argv[]) for (const auto &xf : xmlFiles) { if (xf[0] != '.') { XMLDocument xmld; - auto file = xmlFolder + xf; - xmld.LoadFile(file.c_str()); + auto file = (xmlFolder + xf).c_str(); + xmld.LoadFile(file); auto xmle = xmld.FirstChildElement("World"); @@ -285,7 +285,7 @@ int main(int argc, char *argv[]) xmle->DeleteAttribute("dindex"); xmle = xmle->NextSiblingElement(); } - xmld.SaveFile(file.c_str(), false); + xmld.SaveFile(file, false); } } diff --git a/src/entities.cpp b/src/entities.cpp index 90e03eb..a711fc9 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -631,7 +631,7 @@ extern int commonAIFunc(NPC *speaker); void NPC::interact() { //have the npc's interact back to the player std::thread([this]{ std::vector dopt; - XMLDocument xml; + XMLDocument *xml; XMLElement *exml,*oxml; static unsigned int oldidx = 9999; @@ -644,22 +644,27 @@ void NPC::interact() { //have the npc's interact back to the player loc.y += 5; - canMove=false; - left = (player->loc.x < loc.x); - right = !left; + // freeze the npc, face the player + canMove = false; + left = (player->loc.x < loc.x); + right = !left; + // if there's actual scripted stuff to do, do it if (dialogCount && dialogIndex != 9999) { // load the XML file and find the dialog tags - if (outnabout == 0) - xml.LoadFile(currentXML.c_str()); - else if (outnabout < 0) - xml.LoadFile((xmlFolder + currentWorld->getToLeft()).c_str()); - else - xml.LoadFile((xmlFolder + currentWorld->getToRight()).c_str()); + if (outnabout == 0) { + xml = ¤tXMLDoc; + } else if (outnabout < 0) { + xml = new XMLDocument(); + xml->LoadFile((xmlFolder + currentWorld->getToLeft()).c_str()); + } else { + xml = new XMLDocument(); + xml->LoadFile((xmlFolder + currentWorld->getToRight()).c_str()); + } COMMONAIFUNC: idx = 0; stop = false; - exml = xml.FirstChildElement("Dialog"); + exml = xml->FirstChildElement("Dialog"); // search for the dialog block associated with this npc while (exml->StrAttribute("name") != name) @@ -726,10 +731,11 @@ COMMONAIFUNC: } // asdlfkj - if (exml->GetText() == nullptr) + auto txml = exml->FirstChildElement("content"); + if (txml == nullptr) goto OTHERSTUFF; - ptr = exml->GetText() - 1; + ptr = txml->GetText() - 1; while (*++ptr && isspace(*ptr)); // handle dialog options diff --git a/xml/000.xml b/xml/000.xml index 1806332..de079ca 100644 --- a/xml/000.xml +++ b/xml/000.xml @@ -18,8 +18,10 @@ -600 - ... - 700 + 700 + + ... + diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index f997b4d..06a27c4 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -19,7 +19,7 @@ ... - 1000 + 1000 diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml index d5c07b3..0977b8f 100644 --- a/xml/playerSpawnHill1_Building1.xml +++ b/xml/playerSpawnHill1_Building1.xml @@ -10,17 +10,17 @@ Hey. Have a Dank MayMay :) - + What? You want another Dank MayMay? K. - + Well... I'm out of Dank MayMays. Have a sword though. - + -- cgit v1.2.3 From 23da7a70ce840c3b8ce4c04401c604f588ef452a Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 16 Jun 2016 08:03:50 -0400 Subject: documentation, better readme --- README.md | 49 ++++++++++++- include/common.hpp | 198 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 170 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 40ed2e8..a39d789 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,49 @@ -# gamedev - +gamedev +======= gamedev is a high school project between drumsetmonkey and tcsullivan written in C++ and using SDL2/OpenGL. The goal of this project is to have a completed commercial-grade video game available to Linux and Windows users. We plan on profiting off of the game once we finish it, so once the game reaches its final stages it may become closed source (however, what was uploaded will stay for others to use as a resource). + + +Build Requirements +------------------ + +The 'gamedev' project can be build on both Linux-based and Windows operating systems. The game has been verified to work on Debian, Arch Linux, +Fedora, FreeBSD, and Windows 7, 8 and 10. The following libraries are required to build 'gamedev': + +* SDL2, including SDL2_image and SDL2_mixer +* FreeType (2? libfreetype6? who knows...) +* GLEW + +You will also need the GNU GCC compiler collection, including the programs 'g++' and 'ld'. + + +Building +-------- + +To build 'gamedev', first create a directory named 'out' and then run make: + +``` +make +``` + +This command may be multithreaded using the -j argument. + +To run on not-Windows, once built: + +``` +./main +``` + +To run on Windows: + +``` +win32/main.exe +``` + +The executable may take the following arguments: + +* -r, which will reset XML and player data +* -d, which will kill the game once initialization has been done + +-d is mainly used in conjunction with -r, to reset the XML files and then exit the game before they can be overwritten. + diff --git a/include/common.hpp b/include/common.hpp index f7507cb..12a7a50 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -1,14 +1,12 @@ -/** @file common.h - * @brief Common items needed by most other files. - * - * This file contains headers, variables and functions that are needed in - * most other files included in this project. - */ - #ifndef COMMON_H #define COMMON_H -// holy moly +/** + * @file common.h + * @brief Common items needed by most other files. + */ + +// standard library includes #include #include #include @@ -17,14 +15,14 @@ #include #include +// alternative windows thread library #ifndef __WIN32__ -# include +#include #else -# include +#include #endif // __WIN32__ -#include - +// local library includes #define GLEW_STATIC #include @@ -33,110 +31,115 @@ #include #include +#include + #define GLM_FORCE_RADIANS #include #include #include #include +// game library includes #include + + +// windows stuff #ifdef __WIN32__ typedef unsigned int uint; #undef near #endif -// the number of ticks that should occur in one second -const unsigned int TICKS_PER_SEC = 20; - -// the number of milliseconds inbetween each tick -const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC; - -// segfault-debugging output +// Enables special message printing in the case of segfault debugging (unnecessary?) //#define SEGFAULT #ifdef SEGFAULT -#define C(x) std::cout << x << std::endl +#define C(x) std::cout << x << '\n' #else #define C(x) #endif -// printf's a message to the console with file/line info -#define DEBUG_printf(message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__) - -extern GLuint colorIndex; // Texture.cpp? - /** - * This separates xml strings with + * Prints a formatted string to the terminal with file and line number, for debugging */ -std::vector StringTokenizer(const std::string& str, char delim); +#define DEBUG_printf(message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__) /** - * This structure contains a set of coordinates for ease of coding. + * Creates a coordinate of integers. */ - typedef struct { - int x; - int y; + int x; /**< The x coordinate */ + int y; /**< The y coordinate */ } ivec2; +/** + * A pair of x and y for dimensions (i.e. width and height). + */ typedef ivec2 dim2; +/** + * Creates a coordinate out of floating point integers. + */ class vec2 { public: - float x; - float y; + float x; /**< The x coordinate */ + float y; /**< The y coordinate */ - vec2 () - { + /** + * Constructs an empty vec2. + */ + vec2(){ x = y = 0.0f; } - vec2 (float _x, float _y) - { + /** + * Constructs a vec2 with the specified coordinates. + */ + vec2(float _x, float _y) { x = _x; y = _y; } - bool operator==(const vec2 &v) { + bool operator==(const vec2 &v) const { return (x == v.x) && (y == v.y); } + template const vec2 operator=(const T &n) { x = y = n; return *this; } + template const vec2 operator+(const T &n) { return vec2 (x + n, y + n); } }; +/** + * A structure for three-dimensional points. + */ class vec3{ public: - float x; - float y; - float z; + float x; /**< The x coordinate */ + float y; /**< The y coordinate */ + float z; /**< The z coordinate */ - vec3 () - { + vec3() { x = y = z = 0.0f; } - vec3 (float _x, float _y, float _z) - { + vec3(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } - vec3 (float _x, float _y) - { + vec3(float _x, float _y) { x = _x; y = _y; z = 1.0f; } - }; /** @@ -144,38 +147,42 @@ public: */ typedef struct { - vec2 start; - vec2 end; + vec2 start; /**< The start coordinate of the ray */ + vec2 end; /**< The end coordinate of the ray */ } Ray; +/** + * Keeps track of an RGBA color. + */ class Color{ public: - float red; - float green; - float blue; - float alpha; - Color() - { - red = green = blue = alpha = 0; + float red; /**< The amount of red, 0-255 or 0.0-1.0 depending on usage */ + float green; /**< The amount of green */ + float blue; /**< The amount of blue */ + float alpha; /**< Transparency */ + + Color() { + red = green = blue = alpha = 0.0f; } - Color(float r, float g ,float b) - { + + Color(float r, float g ,float b) { red = r; green = g; blue = b; alpha = 255; } - Color(float r, float g, float b, float a) - { + + Color(float r, float g, float b, float a) { red = r; green = g; blue = b; alpha = a; } + Color operator-=(float a) { - red-=a; - green-=a; - blue-=a; + red -= a; + green -= a; + blue -= a; return{red+a,green+a,blue+a}; } Color operator+=(float a) { @@ -186,31 +193,72 @@ public: } }; -/* +extern GLuint colorIndex; + +/** + * The amount of game ticks that should occur each second. + */ +constexpr const unsigned int TICKS_PER_SEC = 20; + +/** + * The amount of milliseconds it takes for a game tick to fire. + */ +constexpr const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC; + +/** + * Separates a string into tokens using the given delimiter. + * + * @param the string to parse + * @param the delimiting character + * @return a vector of the tokens + */ +std::vector StringTokenizer(const std::string& str, char delim); + +/** * A function used to tell the program what shader, attributes, and uniforms - * we want to draw our rectangles to. See below | - * \|/ + * we want to draw our rectangles to. + * + * @see drawRect + * @param the shader + * @param the 'texture uniform' + * @param the 'coord attribute' + * @param the 'texture coord attribute' */ void useShader(GLuint *sh, GLint *tu, GLint *ca, GLint *ta); -/* - * A function to draw a colored box for opengl - * To use it, the lower left hand and upper right hand coords are passed along +/** + * A function to draw a colored box for OpenGL. + * To use it, the lower left hand and upper right hand coords are given. + * + * @param the lower left coordinate + * @param the upper right coordinate + * @param the z coordinate */ void drawRect(vec2 ll, vec2 ur, float z); -// gets the length of `n` HLINEs +/** + * Returns a measurement in HLINEs + * + * @param the number of HLINEs, integer or decimal + * @return the number in HLINEs + */ template inline T HLINES(const T &n) { return (static_cast(game::HLINE) * n); } -// random number generator initializer (TODO decide how to random gen. numbers) -#define randInit srand +/** + * A generically-named function to start the random number generator. + * This currently redirects to the library's default, but allows for + * a custom generator to be easily implemented. + */ +#define randInit srand -// gets random number -#define randGet rand +/** + * Gets a random number (is a function). + */ +#define randGet rand // defines pi for calculations that need it. constexpr const float PI = 3.1415926535f; -- cgit v1.2.3