// holy moly
#include <iostream>
-#include <cstdlib>
#include <string>
#include <vector>
-#include <string>
-#include <fstream>
#include <thread>
-#include <mutex>
-#include <future>
#include <cmath>
#include <algorithm>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
+#include <config.hpp>
+
#ifdef __WIN32__
typedef unsigned int uint;
#undef near
#endif
-/**
- * Defines how many game ticks should occur in one second, affecting how often
- * game logic is handled.
- */
-
-#define TICKS_PER_SEC 20
+// the number of ticks that should occur in one second
+constexpr const unsigned int TICKS_PER_SEC = 20;
-/**
- * Defines how many milliseconds each game tick will take.
- */
-
-#define MSEC_PER_TICK (1000 / TICKS_PER_SEC)
-
-/**
- * This flag lets the compuler know that we are testing for segfault locations.
- * If this flag is enabled, the function C(x) will print 'x' to terminal
- */
+// the number of milliseconds inbetween each tick
+constexpr const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
+// segfault-debugging output
//#define SEGFAULT
-/**
- * This flag lets the compiler know that we want to use shaders.
- */
-
-#define SHADERS
-
-template<typename N>
-N abso(N v) {
- if (v < 0) {
- return v * -1;
- }else
- return v;
-}
-
-template<class A>
-float averagef(A v) {
- float avg = 0;
- for(auto &a : v) {
- avg += a;
- }
- avg /= v.size();
- return avg;
-}
+#ifdef SEGFAULT
+#define C(x) std::cout << x << std::endl
+#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?
int y;
} ivec2;
+typedef ivec2 dim2;
+
struct _vec2 {
float x;
float y;
float z;
} vec3;
-typedef ivec2 dim2;
-
/**
* This structure contains two sets of coordinates for ray drawing.
*/
vec2 end;
} Ray;
-struct col {
+struct _color {
float red;
float green;
float blue;
- col operator-=(float a) {
+ _color operator-=(float a) {
red-=a;
green-=a;
blue-=a;
return{red+a,green+a,blue+a};
}
- col operator+=(float a) {
+ _color operator+=(float a) {
return{red+a,green+a,blue+a};
}
- col operator=(float a) {
+ _color operator=(float a) {
return{red=a,green=a,blue=a};
}
};
-typedef col Color;
-
-/**
- * Define the game's name (displayed in the window title).
- */
-
-#define GAME_NAME "Independent Study v0.7 alpha - NOW WITH lights and snow and stuff"
-
-extern bool uiLoop;
-extern std::mutex mtx;
-
-/**
- * Define the length of a single HLINE.
- * The game has a great amount of elements that need to be drawn or detected, and having each
- * of them use specific hard-coded numbers would be painful to debug. As a solution, this
- * definition was made. Every item being drawn to the screen and most object detection/physic
- * handling is done based off of this number. Increasing it will give the game a zoomed-in
- * feel, while decreasing it will do the opposite.
- *
- */
-
-#define HLINES(n) (static_cast<int>(game::HLINE * n))
-
-/**
- * A 'wrapper' for libc's srand(), as we hope to eventually have our own random number
- * generator.
- */
-
-#define initRand(s) srand(s)
-
-
-
-/**
- * A 'wrapper' for libc's rand(), as we hope to eventually have our own random number
- * generator.
- */
+typedef struct _color Color;
-#define getRand() rand()
+// gets the length of `n` HLINEs
+template<typename T>
+inline T HLINES(const T &n)
+{
+ return (static_cast<T>(game::HLINE) * n);
+}
-#define randGet rand
+// random number generator initializer (TODO decide how to random gen. numbers)
#define randInit srand
-/**
- * Included in common.h is a prototype for DEBUG_prints, which writes a formatted
- * string to the console containing the callee's file and line number. This macro simplifies
- * it to a simple printf call.
- *
- * DEBUG must be defined for this macro to function.
- */
-
-#define DEBUG_printf(message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__)
-
-#ifdef SEGFAULT
-#define C(x) std::cout << x << std::endl
-#else
-#define C(x)
-#endif
-
-/**
- * Defines pi for calculations that need it.
- */
-
-#define PI 3.1415926535
+// gets random number
+#define randGet rand
+// defines pi for calculations that need it.
+constexpr const float PI = 3.1415926535f;
// references the variable in main.cpp, used for drawing with the player
extern vec2 offset;
-// counts the number of times logic() (see main.cpp) has been called, for animating sprites
-extern unsigned int loops;
-
+// the shader program created in main.cpp
extern GLuint shaderProgram;
/**
* Prints a formatted debug message to the console, along with the callee's file and line
* number.
*/
-
void DEBUG_prints(const char* file, int line, const char *s,...);
/**
* Sets color using glColor3ub(), but handles potential overflow.
*/
-
void safeSetColor(int r,int g,int b);
/**
* Sets color using glColor4ub(), but handles potential overflow.
*/
-
void safeSetColorA(int r,int g,int b,int a);
-/**
- * We've encountered many problems when attempting to create delays for triggering
- * the logic function. As a result, we decided on using the timing libraries given
- * by <chrono> in the standard C++ library. This function simply returns the amount
- * of milliseconds that have passed since the epoch.
- */
-
+// use our own millis function if we can, windows doesn't like <chrono> at the moment...
#ifdef __WIN32__
-#define millis() SDL_GetTicks()
+#define millis() SDL_GetTicks()
#else
unsigned int millis(void);
#endif // __WIN32__
+// reads the names of files in a directory into the given string vector
int getdir(std::string dir, std::vector<std::string> &files);
+
+// sorts a vector of strings alphabetically
void strVectorSortAlpha(std::vector<std::string> *v);
+// reads the given file into a buffer and returns a pointer to the buffer
const char *readFile(const char *path);
-int strCreateFunc(const char *equ);
-
-template<typename N, size_t s>
-size_t arrAmt(N (&)[s]) {return s;}
-
+// aborts the program, printing the given error
void UserError(std::string reason);
#endif // COMMON_H
GENDER gender;
// a texture handler for the entity
- Texturec *tex;
-
- // TODO
- Texturec *ntex;
+ TextureIterator tex;
// draws the entity to the screen
void draw(void);
dim2 imageDim(std::string fileName);
}
+/**
+ * DRAFT texture iterator?
+ */
+class TextureIterator {
+private:
+ std::vector<std::pair<GLuint, std::string>> textures;
+ std::vector<std::pair<GLuint, std::string>>::iterator position;
+public:
+ TextureIterator(void) {
+ position = std::begin(textures);
+ }
+ TextureIterator(const std::vector<std::string> &l) {
+ for (const auto &s : l)
+ textures.emplace_back(Texture::loadTexture(s), s);
+ position = std::begin(textures);
+ }
+ void operator++(int) noexcept {
+ if (++position < std::end(textures))
+ glBindTexture(GL_TEXTURE_2D, (*position).first);
+ else
+ position = std::end(textures) - 1;
+ }
+ void operator--(int) noexcept {
+ if (--position >= std::begin(textures))
+ glBindTexture(GL_TEXTURE_2D, (*position).first);
+ else
+ position = std::begin(textures);
+ }
+ void operator()(const int &index) {
+ if (index < 0 || index > static_cast<int>(textures.size()))
+ throw std::invalid_argument("texture index out of range");
+
+ position = std::begin(textures) + index;
+ glBindTexture(GL_TEXTURE_2D, (*position).first);
+ }
+ const std::string& getTexturePath(const int &index) {
+ if (index < 0 || index > static_cast<int>(textures.size()))
+ throw std::invalid_argument("texture index out of range");
+
+ return textures[index].second;
+ }
+};
+
/**
* The Texturec class.
*
extern std::string currentXML;
// defines how many game ticks it takes for a day to elapse
-extern const unsigned int DAY_CYCLE;
+constexpr const unsigned int DAY_CYCLE = 12000;
// velocity of player when moved by user
-extern const float PLAYER_SPEED_CONSTANT;
+constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
// maximum pull of gravity in one game tick
-extern const float GRAVITY_CONSTANT;
+constexpr const float GRAVITY_CONSTANT = 0.001f;
// height of the floor in an indoor world
-extern const unsigned int INDOOR_FLOOR_HEIGHT;
+constexpr const unsigned int INDOOR_FLOOR_THICKNESS = 50;
+constexpr const unsigned int INDOOR_FLOOR_HEIGHTT = 400;
+constexpr const unsigned int INDOOR_FLOOR_HEIGHT = (INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS);
/* ----------------------------------------------------------------------------
** Classes / function prototypes section
int worldStart;
// holds / handles textures for background elements
- Texturec *bgTex;
+ TextureIterator bgTex;
// defines what type of background is being used
WorldBGType bgType;
** Variables section
** --------------------------------------------------------------------------*/
+// the game's window title name
+constexpr const char *GAME_NAME = "Independent Study v0.7 alpha - NOW WITH lights and snow and stuff";
+
// the current weather, declared in world.cpp
extern WorldWeather weather;
UserError(std::string("GLEW was not able to initialize! Error: ") + reinterpret_cast<const char *>(glewGetErrorString(err)));
// start the random number generator
- initRand(millis());
+ randInit(millis());
// 'basic' OpenGL setup
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
strVectorSortAlpha(&xmlFiles);
// load the first valid XML file for the world
- for (xf : xmlFiles) {
+ for (const auto &xf : xmlFiles) {
if (xf[0] != '.' && strcmp(&xf[xf.size() - 3], "dat")){
// read it in
std::cout << "File to load: " << xf << '\n';
+++ /dev/null
-# Target OS, can be either 'linux' or 'win32'
-TARGET_OS = linux
-
-# Bits setting, 32 or 64
-TARGET_BITS = 32
#include <cstring>
#include <cstdio>
#include <chrono>
+#include <fstream>
#ifndef __WIN32__
#include <istream>
#include <sstream>
+#include <fstream>
#include <ui.hpp>
#include <world.hpp>
"What's a bagel? I don't know because I'm mormon"
};
-void getRandomName(Entity *e)
+void randGetomName(Entity *e)
{
unsigned int tempNum,max=0;
char *bufs;
if (type == MOBT)
name[0] = '\0';
else
- getRandomName(this);
+ randGetomName(this);
}
void Entity::takeHit(unsigned int _health, unsigned int cooldown)
speed = 1;
canMove = true;
- tex = new Texturec(9, "assets/player/playerk.png",
- "assets/player/playerk1.png",
- "assets/player/playerk2.png",
- "assets/player/playerk3.png",
- "assets/player/playerk4.png",
- "assets/player/playerk5.png",
- "assets/player/playerk6.png",
- "assets/player/playerk7.png",
- "assets/player/playerk8.png");
-
+ tex = TextureIterator({"assets/player/playerk.png",
+ "assets/player/playerk1.png",
+ "assets/player/playerk2.png",
+ "assets/player/playerk3.png",
+ "assets/player/playerk4.png",
+ "assets/player/playerk5.png",
+ "assets/player/playerk6.png",
+ "assets/player/playerk7.png",
+ "assets/player/playerk8.png"
+ });
+
inv = new Inventory(PLAYER_INV_SIZE);
}
Player::~Player() {
delete inv;
- delete tex;
delete[] name;
}
maxHealth = health = 100;
canMove = true;
- tex = new Texturec(1,"assets/NPC.png");
+ tex = TextureIterator({"assets/NPC.png"});
inv = new Inventory(NPC_INV_SIZE);
randDialog = rand() % RAND_DIALOG_COUNT - 1;
NPC::~NPC()
{
delete inv;
- delete tex;
delete[] name;
}
}
Merchant::~Merchant() {
- /*while(!aiFunc.empty()) {
- aiFunc.pop_back();
- }*/
delete inside;
//delete inv;
- //delete tex;
//delete[] name;
}
canMove = false;
}
Structures::~Structures() {
- delete tex;
-
if (name)
delete[] name;
}
canMove = false;
maxHealth = health = 1;
-
- tex = NULL;
+
inv = NULL;
}
height = getItemHeight(in);
maxHealth = health = 1;
- tex = new Texturec(1,getItemTexturePath(in));
+ tex = TextureIterator({getItemTexturePath(in)});
inv = NULL;
}
Object::~Object() {
- delete tex;
delete[] name;
}
void Object::reloadTexture(void) {
- if (tex)
- delete tex;
-
- tex = new Texturec(1,getItemTexturePath(iname));
+ tex = TextureIterator({getItemTexturePath(iname)});
width = getItemWidth(iname);
height = getItemHeight(iname);
}
if (speed && !(game::time::getTickCount() % ((2.0f/speed) < 1 ? 1 : (int)((float)2.0f/(float)speed)))) {
if (++texState==9)texState=1;
glActiveTexture(GL_TEXTURE0);
- tex->bind(texState);
+ tex(texState);
}
if (!ground) {
glActiveTexture(GL_TEXTURE0 + 0);
- tex->bind(0);
+ tex(0);
}else if (vel.x) {
glActiveTexture(GL_TEXTURE0 + 0);
- tex->bind(texState);
+ tex(texState);
}else{
glActiveTexture(GL_TEXTURE0 + 0);
- tex->bind(0);
+ tex(0);
}
break;
case MOBT:
/* fall through */
default:
glActiveTexture(GL_TEXTURE0);
- tex->bind(0);
+ tex(0);
break;
}
ticksToUse = timeRun;
vel.x = HLINES(0.008);
- direction = (getRand() % 3 - 1);
+ direction = (randGet() % 3 - 1);
if (direction == 0)
ticksToUse *= 2;
ticksToUse = timeRun;
vel.x = HLINES(0.008);
- direction = (getRand() % 3 - 1);
+ direction = (randGet() % 3 - 1);
if (direction == 0)
ticksToUse *= 2;
* will spawn bewteen 2 and 7 villagers for the starting hut.
*/
- //unsigned int tempN = (getRand() % 5 + 2);
+ //unsigned int tempN = (randGet() % 5 + 2);
if (textureLoc.empty())
textureLoc = inWorld->getSTextureLocation(sub);
switch(sub) {
case STALL_MARKET:
- tex = new Texturec({ textureLoc });
+ tex = TextureIterator({ textureLoc });
dim = Texture::imageDim(textureLoc);
width = dim.x;
height = dim.y;
break;
default:
- tex = new Texturec({ textureLoc });
+ tex = TextureIterator({ textureLoc });
dim = Texture::imageDim(textureLoc);
width = dim.x;
height = dim.y;
#include <inventory.hpp>
+
+#include <numeric>
+
#include <entities.hpp>
#include <ui.hpp>
#include <gametime.hpp>
}
} a = 0;
+ auto averagef = [](const std::vector<int> &v) {
+ auto sum = std::accumulate(std::begin(v), std::end(v), 0);
+ return sum / v.size();
+ };
+
ui::fontTransInv = 255 * (averagef(dfp) / range);
if (ui::fontTransInv > 255)
ui::fontTransInv = 255;
maxHealth = health = 50;
width = HLINES(6);
height = HLINES(4);
- tex = new Texturec({"assets/items/ITEM_PAGE.png"});
+ tex = TextureIterator({"assets/items/ITEM_PAGE.png"});
}
void Page::act(void)
bool Page::bindTex(void)
{
glActiveTexture(GL_TEXTURE0);
- tex->bind(0);
+ tex(0);
return true;
}
maxHealth = health = 50;
width = HLINES(12);
height = HLINES(20);
- tex = new Texturec({"assets/door.png"});
+ tex = TextureIterator({"assets/door.png"});
}
void Door::act(void)
bool Door::bindTex(void)
{
glActiveTexture(GL_TEXTURE0);
- tex->bind(0);
+ tex(0);
return true;
}
maxHealth = health = 1000;
width = HLINES(19);
height = HLINES(15);
- tex = new Texturec({"assets/cat.png"});
+ tex = TextureIterator({"assets/cat.png"});
actCounterInitial = 0;
actCounter = 1;
}
bool Cat::bindTex(void)
{
glActiveTexture(GL_TEXTURE0);
- tex->bind(0);
+ tex(0);
return true;
}
maxHealth = health = 50;
width = HLINES(10);
height = HLINES(8);
- tex = new Texturec({"assets/rabbit.png", "assets/rabbit1.png"});
- actCounterInitial = getRand() % 240 + 15;
+ tex = TextureIterator({"assets/rabbit.png", "assets/rabbit1.png"});
+ actCounterInitial = randGet() % 240 + 15;
actCounter = 1;
}
static int direction = 0;
if (!--actCounter) {
actCounter = actCounterInitial;
- direction = (getRand() % 3 - 1); //sets the direction to either -1, 0, 1
+ direction = (randGet() % 3 - 1); //sets the direction to either -1, 0, 1
if (direction == 0)
ticksToUse /= 2;
vel.x *= direction;
bool Rabbit::bindTex(void)
{
glActiveTexture(GL_TEXTURE0);
- tex->bind(!ground);
+ tex(!ground);
return true;
}
maxHealth = health = 50;
width = HLINES(8);
height = HLINES(8);
- tex = new Texturec({"assets/robin.png"});
+ tex = TextureIterator({"assets/robin.png"});
actCounterInitial = actCounter = 200;
}
bool Bird::bindTex(void)
{
glActiveTexture(GL_TEXTURE0);
- tex->bind(0);
+ tex(0);
return true;
}
maxHealth = health = 50;
width = HLINES(20);
height = 2000;
- tex = new Texturec(0);
+ //tex = TextureIterator();
triggered = false;
}
Mob::~Mob()
{
delete inv;
- delete tex;
delete[] name;
}
// standard library headers
#include <algorithm>
#include <sstream>
+#include <fstream>
// local game headers
#include <ui.hpp>
extern std::string xmlFolder;
// externally referenced in main.cpp
-const unsigned int DAY_CYCLE = 12000;
int worldShade = 0;
-// externally referenced in entities.cpp
-const float PLAYER_SPEED_CONSTANT = 0.150f;
-const float GRAVITY_CONSTANT = 0.001f;
-
// ground-generating constants
-static const float GROUND_HEIGHT_INITIAL = 80.0f;
-static const float GROUND_HEIGHT_MINIMUM = 60.0f;
-static const float GROUND_HEIGHT_MAXIMUM = 110.0f;
-static const float GROUND_HILLINESS = 10.0f;
+constexpr const float GROUND_HEIGHT_INITIAL = 80.0f;
+constexpr const float GROUND_HEIGHT_MINIMUM = 60.0f;
+constexpr const float GROUND_HEIGHT_MAXIMUM = 110.0f;
+constexpr const float GROUND_HILLINESS = 10.0f;
// defines grass height in HLINEs
-static const unsigned int GRASS_HEIGHT = 4;
-
-// indoor world constants
-static const unsigned int INDOOR_FLOOR_THICKNESS = 50;
-static const unsigned int INDOOR_FLOOR_HEIGHTT = 400;
-const unsigned int INDOOR_FLOOR_HEIGHT = INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS;
+constexpr const unsigned int GRASS_HEIGHT = 4;
// the path of the currently loaded XML file, externally referenced in places
std::string currentXML;
static std::vector<WorldSwitchInfo> arenaNest;
// pathnames of images for world themes
-static const unsigned int BG_PATHS_ENTRY_SIZE = 9;
+constexpr const unsigned int BG_PATHS_ENTRY_SIZE = 9;
static const std::string bgPaths[][BG_PATHS_ENTRY_SIZE] = {
{"bg.png", // Daytime background
"bgn.png", // Nighttime background
** Functions section
** --------------------------------------------------------------------------*/
-// externs
-extern int commonAIFunc(NPC *); // gameplay.cpp
-extern void commonTriggerFunc(Mob *); // gameplay.cpp
-extern void commonPageFunc(Mob *); // gameplay.cpp
-
/**
* Creates a world object.
* Note that all this does is nullify a pointer...
if (bgmObj != nullptr)
Mix_FreeMusic(bgmObj);
- delete bgTex;
deleteEntities();
}
* This function will free all memory used by all entities, and then empty the
* vectors they were stored in.
*/
+template<class T>
+void clearPointerVector(T &vec)
+{
+ while (!vec.empty()) {
+ delete vec.back();
+ vec.pop_back();
+ }
+}
+
void World::
deleteEntities(void)
{
// free mobs
- while (!mob.empty()) {
- delete mob.back();
- mob.pop_back();
- }
+ clearPointerVector(mob);
// free npcs
merchant.clear(); // TODO
- while (!npc.empty()) {
- delete npc.back();
- npc.pop_back();
- }
+ clearPointerVector(npc);
// free structures
- while (!build.empty()) {
- delete build.back();
- build.pop_back();
- }
+ clearPointerVector(build);
// free objects
object.clear();
// give every GROUND_HILLINESSth entry a groundHeight value
for (; wditer < std::end(worldData); wditer += GROUND_HILLINESS)
- (*(wditer - GROUND_HILLINESS)).groundHeight = (*wditer).groundHeight + (getRand() % 8 - 4);
+ (*(wditer - GROUND_HILLINESS)).groundHeight = (*wditer).groundHeight + (randGet() % 8 - 4);
// create slopes from the points that were just defined, populate the rest of the WorldData structure
for (wditer = std::begin(worldData) + 1; wditer < std::end(worldData); wditer++){
geninc = ((w + static_cast<int>(GROUND_HILLINESS))->groundHeight - w->groundHeight) / GROUND_HILLINESS;
w->groundHeight = fmin(fmax((w - 1)->groundHeight + geninc, GROUND_HEIGHT_MINIMUM), GROUND_HEIGHT_MAXIMUM);
- w->groundColor = getRand() % 32 / 8;
+ w->groundColor = randGet() % 32 / 8;
w->grassUnpressed = true;
- w->grassHeight[0] = (getRand() % 16) / 3 + 2;
- w->grassHeight[1] = (getRand() % 16) / 3 + 2;
+ w->grassHeight[0] = (randGet() % 16) / 3 + 2;
+ w->grassHeight[1] = (randGet() % 16) / 3 + 2;
}
// define x-coordinate of world's leftmost 'line'
// create empty star array, should be filled here as well...
star = std::vector<vec2> (100, vec2 { 0, 400 });
for (auto &s : star) {
- s.x = (getRand() % (-worldStart * 2)) + worldStart;
- s.y = (getRand() % game::SCREEN_HEIGHT) + 100;
+ s.x = (randGet() % (-worldStart * 2)) + worldStart;
+ s.y = (randGet() % game::SCREEN_HEIGHT) + 100;
}
}
glEnable(GL_TEXTURE_2D);
// the sunny wallpaper is faded with the night depending on tickCount
- bgTex->bind(0);
+ bgTex(0);
switch (weather) {
case WorldWeather::Snowy:
alpha = 150;
glTexCoord2i(0, 1); glVertex2i(offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y);
glEnd();
- bgTex->bindNext();
+ bgTex++;
safeSetColorA(255, 255, 255, !alpha ? 255 : worldShade * 4);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y);
// draw the stars if the time deems it appropriate
if (worldShade > 0) {
- safeSetColorA(255, 255, 255, 255 - (getRand() % 30 - 15));
+ safeSetColorA(255, 255, 255, 255 - (randGet() % 30 - 15));
auto xcoord = offset.x * 0.9f;
for (auto &s : star)
// draw remaining background items
glEnable(GL_TEXTURE_2D);
- bgTex->bindNext();
+ bgTex++;
safeSetColorA(150 + shadeBackground * 2, 150 + shadeBackground * 2, 150 + shadeBackground * 2, 255);
glBegin(GL_QUADS); {
auto xcoord = width / 2 * -1 + offset.x * 0.85f;
} glEnd();
for (unsigned int i = 0; i < 4; i++) {
- bgTex->bindNext();
+ bgTex++;
safeSetColorA(bgDraw[i][0] + shadeBackground * 2,
bgDraw[i][0] + shadeBackground * 2,
bgDraw[i][0] + shadeBackground * 2,
// draw light elements
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
- bgTex->bindNext();
+ bgTex++;
std::unique_ptr<GLfloat[]> pointArrayBuf = std::make_unique<GLfloat[]> (2 * (light.size()));
auto pointArray = pointArrayBuf.get();
}
}
- for (unsigned int i = 0; i < light.size(); i++)
+ for (unsigned int i = 0; i < light.size(); i++) {
flameArray[i] = light[i].fireFlicker;
+ }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// draw the grass
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
- bgTex->bindNext();
+ bgTex++;
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
safeSetColorA(255, 255, 255, 255);
(*part).loc.y += pa.vel.y * delta;
(*part).loc.x += pa.vel.x * delta;
- if (std::any_of(std::begin(build), std::end(build), [pa](Structures *s) {
+ if (std::any_of(std::begin(build), std::end(build), [pa](const Structures *s) {
return (s->bsubtype == FOUNTAIN) &&
(pa.loc.x >= s->loc.x) && (pa.loc.x <= s->loc.x + s->width) &&
(pa.loc.y <= s->loc.y + s->height * 0.25f);
// load textures with a limit check
switch ((bgType = bgt)) {
case WorldBGType::Forest:
- bgTex = new Texturec(bgFiles);
+ bgTex = TextureIterator(bgFiles);
break;
case WorldBGType::WoodHouse:
- bgTex = new Texturec(bgFilesIndoors);
+ bgTex = TextureIterator(bgFilesIndoors);
break;
default:
UserError("Invalid world background type");
// get folder prefix
std::string prefix = pre.empty() ? "assets/style/classic/" : pre;
- for (s : buildPaths)
+ for (const auto &s : buildPaths)
sTexLoc.push_back(prefix + s);
prefix += "bg/";
- for (s : bgPaths[0])
+ for (const auto &s : bgPaths[0])
bgFiles.push_back(prefix + s);
- for (s : bgPaths[1])
+ for (const auto &s : bgPaths[1])
bgFilesIndoors.push_back(prefix + s);
}
merchant.push_back(new Merchant());
merchant.back()->spawn(x, y);
- if (housed)
+ if (housed) {
merchant.back()->inside = build.back();
+ }
npc.push_back(merchant.back());
entity.push_back(npc.back());
addLight(vec2 loc, Color color)
{
if (light.size() < 64)
- light.push_back(Light(loc, color, 1));
+ light.emplace_back(loc, color, 1);
}
void World::
addHole(unsigned int start, unsigned int end)
{
- if (end > worldData.size())
- end = worldData.size();
+ end = fmin(worldData.size(), end);
for (unsigned int i = start; i < end; i++)
worldData[i].groundHeight = 0;
start = 0;
}
- if (end > (signed)worldData.size())
- end = worldData.size();
+ end = fmin(worldData.size(), end);
for (int i = start; i < end; i++) {
worldData[i].groundHeight += thing * sin((i - start + offset) * period);
}
IndoorWorld::~IndoorWorld(void) {
- delete bgTex;
-
deleteEntities();
}
{
if (floor.empty())
generate(width);
- floor.emplace_back(width, floor.size() * INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS);
+
+ floor.emplace_back(width, floor.size() * INDOOR_FLOOR_HEIGHT);
fstart.push_back(0);
}
{
if (floor.empty())
generate(width);
- floor.emplace_back(width, floor.size() * INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS);
+
+ floor.emplace_back(width, floor.size() * INDOOR_FLOOR_HEIGHT);
fstart.push_back(start);
}
}
}
- for(i = 0; i < light.size(); i++)
+ for(i = 0; i < light.size(); i++) {
flameArray[i] = light[i].fireFlicker;
+ }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glUniform1fv(glGetUniformLocation(shaderProgram, "fireFlicker"), light.size(), flameArray);
}
- bgTex->bind(0);
+ bgTex(0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
glColor4ub(255,255,255,255);
safeSetColor(150, 100, 50);
for (f = 0; f < floor.size(); f++) {
i = 0;
- for (h : floor[f]) {
+ for (const auto &h : floor[f]) {
x = worldStart + fstart[f] * HLINE + HLINES(i);
glVertex2i(x , h );
glVertex2i(x + HLINE, h );
else if (name == "structure") {
tmp->addStructure((BUILD_SUB) wxml->UnsignedAttribute("type"),
wxml->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ?
- getRand() % tmp->getTheWidth() / 2.0f : spawnx,
+ randGet() % tmp->getTheWidth() / 2.0f : spawnx,
100,
wxml->StrAttribute("texture"),
wxml->StrAttribute("inside")