fix root lookup; add vec2 to json types; render test image when window is created
This commit is contained in:
parent
bab8c778ca
commit
14afcef0ce
|
@ -12,7 +12,8 @@
|
||||||
changed, gradients, level select code input, logging, variable screen
|
changed, gradients, level select code input, logging, variable screen
|
||||||
resolution, debug display, loading wheel animation, shadowed sprite, separate
|
resolution, debug display, loading wheel animation, shadowed sprite, separate
|
||||||
update and draw, sprite movement cage, multiple windows, multiple renderers,
|
update and draw, sprite movement cage, multiple windows, multiple renderers,
|
||||||
node children list, node animations list
|
node children list, node animations list, copy constructor for node, private
|
||||||
|
and public class members
|
||||||
|
|
||||||
:) SWEATY HANDS :) OILY SNACKS :) AND BAD HYGIENE :)
|
:) SWEATY HANDS :) OILY SNACKS :) AND BAD HYGIENE :)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct Color
|
||||||
std::uint8_t r, g, b, a;
|
std::uint8_t r, g, b, a;
|
||||||
|
|
||||||
Color();
|
Color();
|
||||||
Color(std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t);
|
Color(std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t = 255);
|
||||||
Color(const SDL_Color&);
|
Color(const SDL_Color&);
|
||||||
void set_rgb_float(const float&, const float&, const float&);
|
void set_rgb_float(const float&, const float&, const float&);
|
||||||
void set_hsv(const float&, const float& = 1.0f, const float& = 1.0f);
|
void set_hsv(const float&, const float& = 1.0f, const float& = 1.0f);
|
||||||
|
|
|
@ -42,7 +42,9 @@ void Configuration::set_defaults()
|
||||||
{"dimensions", {640, 480}},
|
{"dimensions", {640, 480}},
|
||||||
{"framerate", 60},
|
{"framerate", 60},
|
||||||
{"title", "sfw"},
|
{"title", "sfw"},
|
||||||
{"debug", false}
|
{"debug", false},
|
||||||
|
{"show-cursor", false},
|
||||||
|
{"render-test-spacing", 2}
|
||||||
};
|
};
|
||||||
sys_config["recording"] = {
|
sys_config["recording"] = {
|
||||||
{"enabled", false},
|
{"enabled", false},
|
||||||
|
|
29
src/Game.cpp
29
src/Game.cpp
|
@ -44,7 +44,7 @@ void FramerateIndicator::refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Game() : Node()
|
Game::Game()
|
||||||
{
|
{
|
||||||
frame_length_history.reserve(5000);
|
frame_length_history.reserve(5000);
|
||||||
set_framerate(get_configuration()["display"]["framerate"]);
|
set_framerate(get_configuration()["display"]["framerate"]);
|
||||||
|
@ -75,16 +75,37 @@ Game::Game() : Node()
|
||||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
|
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
|
||||||
print_gl_attributes();
|
print_gl_attributes();
|
||||||
std::vector<int> window_size = get_configuration()["display"]["dimensions"];
|
auto window_size = get_configuration()["display"]["dimensions"].get<glm::ivec2>();
|
||||||
window = SDL_CreateWindow(
|
window = SDL_CreateWindow(
|
||||||
get_configuration()["display"]["title"].get_ref<const std::string&>().c_str(), SDL_WINDOWPOS_CENTERED,
|
get_configuration()["display"]["title"].get_ref<const std::string&>().c_str(), SDL_WINDOWPOS_CENTERED,
|
||||||
SDL_WINDOWPOS_CENTERED, window_size[0], window_size[1], SDL_WINDOW_OPENGL);
|
SDL_WINDOWPOS_CENTERED, window_size.x, window_size.y, SDL_WINDOW_OPENGL);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
print_sdl_error("Could not create window");
|
print_sdl_error("Could not create window");
|
||||||
flag_to_end();
|
flag_to_end();
|
||||||
}
|
}
|
||||||
SDL_ShowCursor(0);
|
if ((renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE)) == NULL)
|
||||||
|
{
|
||||||
|
print_sdl_error("Could not create renderer");
|
||||||
|
flag_to_end();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_SetRenderTarget(renderer, NULL);
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
int step = get_configuration()["display"]["render-test-spacing"];
|
||||||
|
for (int x = 0, r = 1, g = 0, b = 2; x < window_size.x; x += step)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(renderer, (r++ % 3 == 0) * 255, (g++ % 3 == 0) * 255, (b++ % 3 == 0) * 255, 255);
|
||||||
|
const SDL_Rect rect = {x, 0, step, window_size.y};
|
||||||
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
}
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
SDL_RenderFlush(renderer);
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
}
|
||||||
|
SDL_ShowCursor(get_configuration()["display"]["show-cursor"]);
|
||||||
if (TTF_Init() < 0)
|
if (TTF_Init() < 0)
|
||||||
{
|
{
|
||||||
print_sdl_error("Could not initialize SDL ttf");
|
print_sdl_error("Could not initialize SDL ttf");
|
||||||
|
|
|
@ -13,23 +13,19 @@
|
||||||
|
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#define GLEW_STATIC
|
#define GLEW_STATIC
|
||||||
|
|
||||||
#if defined(__EMSCRIPTEN__)
|
#if defined(__EMSCRIPTEN__)
|
||||||
|
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#include <emscripten/html5.h>
|
#include <emscripten/html5.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
#include "Input.hpp"
|
#include "Input.hpp"
|
||||||
#include "Recorder.hpp"
|
#include "Recorder.hpp"
|
||||||
#include "Sprite.hpp"
|
#include "Sprite.hpp"
|
||||||
|
#include "extension.hpp"
|
||||||
|
|
||||||
struct FramerateIndicator : Sprite
|
struct FramerateIndicator : Sprite
|
||||||
{
|
{
|
||||||
|
|
10
src/Node.cpp
10
src/Node.cpp
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
Node::Node() : Node(NULL) {}
|
Node::Node() : Node(NULL) {}
|
||||||
|
|
||||||
Node::Node(Node *parent) : parent(parent)
|
Node::Node(Node* parent) : parent(parent)
|
||||||
{
|
{
|
||||||
std::cout << "Constructing ";
|
std::cout << "Constructing ";
|
||||||
print_branch();
|
print_branch();
|
||||||
|
@ -61,12 +61,12 @@ const Input& Node::get_input() const
|
||||||
|
|
||||||
const Game* Node::get_root() const
|
const Game* Node::get_root() const
|
||||||
{
|
{
|
||||||
const Node* root = this;
|
const Node* r = this;
|
||||||
while (root->parent != NULL)
|
while (r->parent != NULL)
|
||||||
{
|
{
|
||||||
root = parent;
|
r = r->parent;
|
||||||
}
|
}
|
||||||
return dynamic_cast<const Game*>(root);
|
return dynamic_cast<const Game*>(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
Box Node::get_window_box()
|
Box Node::get_window_box()
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "glm/trigonometric.hpp"
|
#include "glm/trigonometric.hpp"
|
||||||
#include "glm/vec2.hpp"
|
#include "glm/vec2.hpp"
|
||||||
#include "glm/gtx/vector_angle.hpp"
|
#include "glm/gtx/vector_angle.hpp"
|
||||||
|
#include "json/json.hpp"
|
||||||
|
|
||||||
#include "Box.hpp"
|
#include "Box.hpp"
|
||||||
#include "Segment.hpp"
|
#include "Segment.hpp"
|
||||||
|
@ -158,6 +159,22 @@ bool operator<(const SDL_Color& color_1, const SDL_Color& color_2);
|
||||||
bool operator==(const SDL_Color& color_1, const SDL_Color& color_2);
|
bool operator==(const SDL_Color& color_1, const SDL_Color& color_2);
|
||||||
std::ostream& operator<<(std::ostream&, const SDL_Color&);
|
std::ostream& operator<<(std::ostream&, const SDL_Color&);
|
||||||
|
|
||||||
|
namespace glm
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
void to_json(nlohmann::json& j, const vec<2, T, defaultp>& v)
|
||||||
|
{
|
||||||
|
j = nlohmann::json{{"x", v.x}, {"y", v.y}};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void from_json(const nlohmann::json& j, vec<2, T, defaultp>& v)
|
||||||
|
{
|
||||||
|
j.at(0).get_to(v.x);
|
||||||
|
j.at(1).get_to(v.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue