aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-11-27 16:28:51 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-11-27 16:28:51 -0500
commit3437e928e978939aa4c85369ab597e08f00ab93b (patch)
tree761f06a34bd8de78440c31026cf2c96df1ccad4f /src
parent21ce3f06312a02c23d6b3c89f64f84222f54fe6d (diff)
world draw fix; offset fix
Diffstat (limited to 'src')
-rw-r--r--src/player.cpp26
-rw-r--r--src/texture.cpp7
-rw-r--r--src/ui.cpp4
-rw-r--r--src/ui_action.cpp.bak143
-rw-r--r--src/world.cpp26
5 files changed, 29 insertions, 177 deletions
diff --git a/src/player.cpp b/src/player.cpp
index 2694a54..a88734a 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -1,7 +1,6 @@
#include <player.hpp>
#include <brice.hpp>
-#include <engine.hpp>
#include <ui.hpp>
#include <gametime.hpp>
#include <world.hpp>
@@ -71,10 +70,7 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
p->inv->selected = false;
p->inv->mouseSel = false;
- }
-
- // disable action ui
- ui::action::disable();*/
+ }*/
}
}
@@ -114,23 +110,17 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
} else if (kc == getControl(4)) {
speed = .5;
} else if (kc == getControl(5)) {
- /*static int heyOhLetsGo = 0;
-
+ //static int heyOhLetsGo = 0;
//edown = true;
-
// start hover counter?
- if (!heyOhLetsGo) {
- heyOhLetsGo = game::time::getTickCount();
- p->inv->mouseSel = false;
- }
+ //if (!heyOhLetsGo) {
+ // heyOhLetsGo = game::time::getTickCount();
+ // p->inv->mouseSel = false;
+ //}
// run hover thing
- if (game::time::getTickCount() - heyOhLetsGo >= 2 && !(p->inv->invOpen) && !(p->inv->selected)) {
- p->inv->invHover = true;
-
- // enable action ui
- ui::action::enable();
- }*/
+ //if (game::time::getTickCount() - heyOhLetsGo >= 2 && !(p->inv->invOpen) && !(p->inv->selected))
+ // p->inv->invHover = true;
}
} else if (kc == SDLK_DELETE) {
game::endGame();
diff --git a/src/texture.cpp b/src/texture.cpp
index 3a2f071..a232e0e 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -46,7 +46,6 @@ namespace Texture{
GLuint loadTexture(std::string fileName) {
SDL_Surface *image;
- static GLuint object = 0;
// check if texture is already loaded
for(auto &t : LoadedTexture) {
@@ -67,11 +66,13 @@ namespace Texture{
#ifdef DEBUG
DEBUG_printf("Loaded image file: %s\n", fileName.c_str());
#endif // DEBUG
+
/*
* Load texture through OpenGL.
*/
- //glGenTextures(1,&object); // Turns "object" into a texture
- glBindTexture(GL_TEXTURE_2D,++object); // Binds "object" to the top of the stack
+ GLuint object;
+ glGenTextures(1, &object); // Turns "object" into a texture
+ glBindTexture(GL_TEXTURE_2D, object); // Binds "object" to the top of the stack
glPixelStoref(GL_UNPACK_ALIGNMENT,1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Sets the "min" filter
diff --git a/src/ui.cpp b/src/ui.cpp
index 94100e4..9439e30 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -9,6 +9,7 @@
#include <engine.hpp>
#include <events.hpp>
#include <window.hpp>
+#include <player.hpp>
#include <chrono>
using namespace std::literals::chrono_literals;
@@ -851,9 +852,6 @@ namespace ui {
auto SCREEN_HEIGHT = static_cast<float>(game::SCREEN_HEIGHT);
// will return if not toggled
- //action::draw(vec2 {player->loc.x + player->width / 2, player->loc.y + player->height + game::HLINE});
-
- // will return if not toggled
quest::draw();
if (pageTexReady) {
diff --git a/src/ui_action.cpp.bak b/src/ui_action.cpp.bak
deleted file mode 100644
index 9029907..0000000
--- a/src/ui_action.cpp.bak
+++ /dev/null
@@ -1,143 +0,0 @@
-#include <ui_action.hpp>
-#include <world.hpp>
-
-#define ACTION_PROLOUGE { actioning = true; }
-#define ACTION_EPILOUGE { actioning = false; actionHover = 0; }
-
-extern World *currentWorld;
-extern Arena *arena;
-extern Player *player;
-extern bool inBattle;
-
-static std::vector<std::pair<std::string, vec3>> actionText = {
- {"Attack", vec3 {0, 0, 0}},
- {"Action", vec3 {0, 0, 0}},
- {"Umm" , vec3 {0, 0, 0}}
-};
-
-void actionAttack(void);
-void actionAction(void);
-
-static std::vector<void (*)(void)> actionFunc = {
- actionAttack,
- actionAction,
- nullptr,
-};
-
-static bool actionToggle = false, actioning = false;
-static unsigned int actionHover = 0;
-static Entity *nearEntity = nullptr, *lastEntity = nullptr;
-
-namespace ui {
- namespace action {
- bool make = false;
-
- // enables action ui
- void enable(void) {
- actionToggle = true;
- }
-
- // disables action ui
- void disable(void) {
- actionToggle = false;
-
- if (lastEntity != nullptr)
- lastEntity->canMove = true;
- }
-
- // draws the action ui
- void draw(vec2 loc) {
- unsigned int i = 1;
- float y = loc.y;
-
- if (!actionToggle)
- return;
-
- nearEntity = currentWorld->getNearInteractable(*player);
-
- if (nearEntity == nullptr) {
- if (lastEntity != nullptr) {
- lastEntity->canMove = true;
- lastEntity = nullptr;
- }
- return;
- } else if (nearEntity != lastEntity) {
- if (lastEntity != nullptr)
- lastEntity->canMove = true;
- lastEntity = nearEntity;
- }
-
- if (make) {
- while(actioning);
-
- if (!actionHover) {
- make = false;
- return;
- }
-
- if (actionFunc[actionHover - 1] != nullptr)
- std::thread(actionFunc[actionHover - 1]).detach();
-
- actionHover = 0;
- } else {
- nearEntity->canMove = false;
- ui::drawBox(vec2 {loc.x - HLINES(11), loc.y}, vec2 {loc.x + HLINES(12), loc.y + actionText.size() * HLINES(8)});
-
- for (auto &s : actionText) {
- s.second.z = ui::putStringCentered((s.second.x = loc.x), (s.second.y = (y += fontSize * 1.15f)), s.first) / 2;
-
- if (ui::mouse.x > s.second.x - s.second.z && ui::mouse.x < s.second.x + s.second.z &&
- ui::mouse.y > s.second.y && ui::mouse.y < s.second.y + ui::fontSize) {
- actionHover = i;
- ui::setFontColor(255, 100, 100, 255);
- ui::putStringCentered(s.second.x, s.second.y, s.first);
- ui::setFontColor(255, 255, 255, 255);
- }
- i++;
- }
-
- ui::putStringCentered(loc.x, y + fontSize * 1.2f, nearEntity->name);
- }
-
- if (i == actionText.size())
- actionHover = 0;
-
- ui::setFontColor(255, 255, 255, 255);
- make = false;
- }
- }
-}
-
-void actionAttack(void)
-{
- ACTION_PROLOUGE;
-
- auto m = currentWorld->getNearInteractable(*player);
-
- if (m->type == MOBT) {
- if (!inBattle && m != nullptr) {
- arena->fight(currentWorld, player, Mobp(m));
-
- ui::toggleWhiteFast();
- ui::waitForCover();
- currentWorld = arena;
- ui::toggleWhiteFast();
- }
- } else {
- ui::dialogBox(player->name, "", false, "%s doesn't appear to be in the mood for fighting...", m->name.c_str());
- }
-
- ACTION_EPILOUGE;
-}
-
-void actionAction(void)
-{
- ACTION_PROLOUGE;
-
- auto e = currentWorld->getNearInteractable(*player);
-
- if (e->type == NPCT)
- e->interact();
-
- ACTION_EPILOUGE;
-}
diff --git a/src/world.cpp b/src/world.cpp
index f4795ac..4ab8af7 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -114,7 +114,7 @@ static const float bgDraw[4][3]={
** Functions section
** --------------------------------------------------------------------------*/
-void WorldSystem::generate(unsigned int width)
+void WorldSystem::generate(int width)
{
float geninc = 0;
@@ -209,7 +209,9 @@ void WorldSystem::load(const std::string& file)
auto file = ixml->Attribute("file");
if (file != nullptr) {
DEBUG_printf("Including file: %s\n", file);
- xmlRaw.append(readFile((xmlFolder + file).c_str()));
+ auto include = readFile((xmlFolder + file).c_str());
+ xmlRaw.append(include);
+ delete[] include;
}
ixml = ixml->NextSiblingElement();
}
@@ -263,7 +265,7 @@ void WorldSystem::load(const std::string& file)
// world generation
else if (tagName == "generation") {
- generate(wxml->UnsignedAttribute("width") / game::HLINE);
+ generate(wxml->IntAttribute("width"));
}
// indoor stuff
@@ -272,7 +274,9 @@ void WorldSystem::load(const std::string& file)
UserError("<house> can only be used inside <IndoorWorld>");
world.indoorWidth = wxml->FloatAttribute("width");
- world.indoorTex = Texture::loadTexture(wxml->Attribute("texture"));
+ auto str = wxml->StrAttribute("texture");
+ auto tex = Texture::loadTexture(str);
+ world.indoorTex = tex;
}
// weather tag
@@ -649,8 +653,9 @@ void WorldSystem::render(void)
static bool ambientUpdaterStarted = false;
if (!ambientUpdaterStarted) {
ambientUpdaterStarted = true;
- std::thread([&](void) {
- while (true) {
+ thAmbient = std::thread([&](void) {
+ const bool &run = game::engine.shouldRun;
+ while (run) {
float v = 75 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
float rg = std::clamp(.5f + (-v / 100.0f), 0.01f, .9f);
float b = std::clamp(.5f + (-v / 80.0f), 0.03f, .9f);
@@ -659,7 +664,8 @@ void WorldSystem::render(void)
std::this_thread::sleep_for(1ms);
}
- }).detach();
+ });
+ thAmbient.detach();
}
@@ -883,8 +889,8 @@ void WorldSystem::render(void)
// only draw world within player vision
iStart = std::clamp(static_cast<int>(pOffset - (SCREEN_WIDTH / 2 / HLINE) - GROUND_HILLINESS),
0, static_cast<int>(world.data.size()));
- iEnd = std::clamp(static_cast<int>(pOffset + (SCREEN_WIDTH / 2 / HLINE)),
- 0, static_cast<int>(world.data.size())) + 1;
+ iEnd = std::clamp(static_cast<int>(pOffset + (SCREEN_WIDTH / 2 / HLINE) + 2),
+ 0, static_cast<int>(world.data.size()));
// draw the dirt
waitToSwap = true;
@@ -1010,7 +1016,7 @@ void WorldSystem::render(void)
// the starting pixel of the world
float s = -(static_cast<float>(SCREEN_WIDTH)/2.0f);
// the ending pixel of the world
- float e = (static_cast<float>(SCREEN_WIDTH)/2.0f);
+ float e = (static_cast<float>(SCREEN_WIDTH)/2.0f);
if (offset.x + world.startX > s) {