json config library
This commit is contained in:
parent
949763f5d9
commit
e40201cd11
|
@ -1,4 +1,4 @@
|
||||||
// reset, pause, auto reset
|
// reset, pause, auto reset, analog d-pad, gamepad config, any key
|
||||||
|
|
||||||
#include "Demo.hpp"
|
#include "Demo.hpp"
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
|
||||||
#include <experimental/filesystem>
|
|
||||||
namespace fs = std::experimental::filesystem;
|
|
||||||
#else
|
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include "sdl2-gfx/SDL2_gfxPrimitives.h"
|
#include "sdl2-gfx/SDL2_gfxPrimitives.h"
|
||||||
#include "sdl2-gfx/SDL2_rotozoom.h"
|
#include "sdl2-gfx/SDL2_rotozoom.h"
|
||||||
|
@ -36,6 +28,7 @@ namespace fs = std::filesystem;
|
||||||
#include "glm/gtx/transform.hpp"
|
#include "glm/gtx/transform.hpp"
|
||||||
#include "glm/gtc/matrix_transform.hpp"
|
#include "glm/gtc/matrix_transform.hpp"
|
||||||
|
|
||||||
|
#include "filesystem.hpp"
|
||||||
#include "Game.hpp"
|
#include "Game.hpp"
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
#include "Location.hpp"
|
#include "Location.hpp"
|
||||||
|
|
|
@ -36,16 +36,18 @@ $(SDLGFX2_DIR)%.o: $(SDLGFX2_DIR)%.c $(SDLGFX2_DIR)%.h
|
||||||
$(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
|
$(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
|
||||||
$(CC_LINUX) $(CFLAGS) $< -o $@
|
$(CC_LINUX) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
$(SFW_SRC_DIR)Sprite.o: $(addprefix $(SFW_SRC_DIR),Node.hpp Game.hpp Location.hpp)
|
$(SFW_SRC_DIR)Sprite.o: $(addprefix $(SFW_SRC_DIR),Node.o Game.o Location.o)
|
||||||
$(SFW_SRC_DIR)Game.o: $(SFW_SRC_DIR)Node.hpp
|
$(SFW_SRC_DIR)Game.o: $(addprefix $(SFW_SRC_DIR),Node.o Sprite.o Configuration.o)
|
||||||
$(SFW_SRC_DIR)Node.o: $(SFW_SRC_DIR)Game.hpp
|
$(SFW_SRC_DIR)Node.o: $(SFW_SRC_DIR)Game.o
|
||||||
|
$(SFW_SRC_DIR)Configuration.o: $(SFW_SRC_DIR)Node.o
|
||||||
|
$(SFW_SRC_DIR)Input.o: $(SFW_SRC_DIR)Node.o
|
||||||
$(SFW_SRC_DIR)%.o: $(addprefix $(SFW_SRC_DIR),%.cpp %.hpp)
|
$(SFW_SRC_DIR)%.o: $(addprefix $(SFW_SRC_DIR),%.cpp %.hpp)
|
||||||
$(CPPC_LINUX) $(CPP_FLAGS) $(SDL_FLAGS) $< -o $@
|
$(CPPC_LINUX) $(CPP_FLAGS) $(SDL_FLAGS) $< -o $@
|
||||||
|
|
||||||
Demo.o: Demo.cpp Demo.hpp $(addprefix $(SFW_SRC_DIR),Sprite.hpp Node.hpp Game.hpp Location.hpp)
|
Demo.o: Demo.cpp Demo.hpp $(addprefix $(SFW_SRC_DIR),Sprite.o Node.o Game.o Location.o)
|
||||||
$(CPPC_LINUX) $(CPP_FLAGS) $(SDL_FLAGS) $< -o $@
|
$(CPPC_LINUX) $(CPP_FLAGS) $(SDL_FLAGS) $< -o $@
|
||||||
|
|
||||||
linux: Demo.o $(addprefix $(SFW_SRC_DIR),Sprite.o Node.o Game.o Location.o) \
|
linux: Demo.o $(addprefix $(SFW_SRC_DIR),Sprite.o Node.o Game.o Location.o Configuration.o Input.o) \
|
||||||
$(GLEW_DIR)glew.o $(addprefix $(SDLGFX2_DIR),SDL2_rotozoom.o SDL2_gfxPrimitives.o)
|
$(GLEW_DIR)glew.o $(addprefix $(SDLGFX2_DIR),SDL2_rotozoom.o SDL2_gfxPrimitives.o)
|
||||||
$(CPPC_LINUX) $(LFLAGS) -D__LINUX__ $^ -lGL -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lstdc++fs -o demo
|
$(CPPC_LINUX) $(LFLAGS) -D__LINUX__ $^ -lGL -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lstdc++fs -o demo
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"display":
|
||||||
|
{
|
||||||
|
"dimensions": [640, 480]
|
||||||
|
},
|
||||||
|
|
||||||
|
"gamepad":
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
|
"keys":
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
The OpenGL Extension Wrangler Library
|
||||||
|
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
|
||||||
|
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
|
||||||
|
Copyright (C) 2002, Lev Povalahev
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
* The name of the author may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
Mesa 3-D graphics library
|
||||||
|
Version: 7.0
|
||||||
|
|
||||||
|
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (c) 2007 The Khronos Group Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and/or associated documentation files (the
|
||||||
|
"Materials"), to deal in the Materials without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Materials.
|
||||||
|
|
||||||
|
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
@ -0,0 +1,22 @@
|
||||||
|
### The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2005 - G-Truc Creation
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2013-2019 Niels Lohmann
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,47 @@
|
||||||
|
#include "Configuration.hpp"
|
||||||
|
|
||||||
|
Configuration::Configuration(Node *parent) : Configuration(parent, "config") {}
|
||||||
|
|
||||||
|
Configuration::Configuration(Node *parent, fs::path path) : Node(parent)
|
||||||
|
{
|
||||||
|
std::cout << "Constructing Configuration with parent " << parent <<
|
||||||
|
" and path " << path << std::endl;
|
||||||
|
config_path = path;
|
||||||
|
set_defaults();
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Configuration::set_defaults()
|
||||||
|
{
|
||||||
|
sys_config["keys"] = {
|
||||||
|
{"record", {"CTRL", "SHIFT", "F10"}},
|
||||||
|
{"screenshot", "F9"}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void Configuration::load()
|
||||||
|
{
|
||||||
|
load(config_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Configuration::load(fs::path path)
|
||||||
|
{
|
||||||
|
std::ifstream contents(path);
|
||||||
|
contents >> config;
|
||||||
|
config["blob"] = false;
|
||||||
|
config["slime"][1] = {420, 69};
|
||||||
|
config["goo"] = "yum";
|
||||||
|
std::cout << std::setw(4) << config << std::endl;
|
||||||
|
std::cout << std::setw(4) << sys_config << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Configuration::write()
|
||||||
|
{
|
||||||
|
write(config_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Configuration::write(fs::path path)
|
||||||
|
{
|
||||||
|
std::ofstream output(path);
|
||||||
|
output << std::setw(tab_width) << config << std::endl;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef Configuration_h_
|
||||||
|
#define Configuration_h_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include "json/json.hpp"
|
||||||
|
|
||||||
|
#include "Node.hpp"
|
||||||
|
|
||||||
|
struct Configuration : Node
|
||||||
|
{
|
||||||
|
nlohmann::json sys_config, config;
|
||||||
|
fs::path config_path;
|
||||||
|
int tab_width = 4;
|
||||||
|
|
||||||
|
Configuration(Node*);
|
||||||
|
Configuration(Node*, fs::path);
|
||||||
|
void set_defaults();
|
||||||
|
void load();
|
||||||
|
void load(fs::path path);
|
||||||
|
void write();
|
||||||
|
void write(fs::path path);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,6 +1,6 @@
|
||||||
#include "Game.hpp"
|
#include "Game.hpp"
|
||||||
|
|
||||||
Game::Game()
|
Game::Game() : configuration(this)
|
||||||
{
|
{
|
||||||
std::cout << "GLEW " << glewGetString(GLEW_VERSION) << std::endl;
|
std::cout << "GLEW " << glewGetString(GLEW_VERSION) << std::endl;
|
||||||
putenv("SDL_VIDEO_X11_LEGACY_FULLSCREEN=0");
|
putenv("SDL_VIDEO_X11_LEGACY_FULLSCREEN=0");
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
|
#include "Configuration.hpp"
|
||||||
|
|
||||||
struct Game : Node
|
struct Game : Node
|
||||||
{
|
{
|
||||||
|
@ -33,9 +34,9 @@ struct Game : Node
|
||||||
last_frame_length;
|
last_frame_length;
|
||||||
float frame_length = 1000.0 / framerate;
|
float frame_length = 1000.0 / framerate;
|
||||||
bool done = false, show_framerate = false, is_gl_context = true;
|
bool done = false, show_framerate = false, is_gl_context = true;
|
||||||
|
Configuration configuration;
|
||||||
|
|
||||||
Game();
|
Game();
|
||||||
|
|
||||||
void print_error(std::string);
|
void print_error(std::string);
|
||||||
void print_sdl_error(std::string);
|
void print_sdl_error(std::string);
|
||||||
void print_gl_attributes();
|
void print_gl_attributes();
|
||||||
|
|
19
src/Node.cpp
19
src/Node.cpp
|
@ -1,8 +1,25 @@
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
|
|
||||||
|
Node::Node()
|
||||||
|
{
|
||||||
|
std::cout << "Default constructing Node with parent " << parent << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node::Node(Node *parent) : parent(parent)
|
||||||
|
{
|
||||||
|
std::cout << "Constructing Node with parent " << parent << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration* Node::get_configuration()
|
||||||
|
{
|
||||||
|
Game* game = get_root();
|
||||||
|
Configuration* configuration = &game->configuration;
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
Game* Node::get_root()
|
Game* Node::get_root()
|
||||||
{
|
{
|
||||||
Node *current = parent;
|
Node *current = this;
|
||||||
while (current->parent != NULL)
|
while (current->parent != NULL)
|
||||||
{
|
{
|
||||||
current = current->parent;
|
current = current->parent;
|
||||||
|
|
13
src/Node.hpp
13
src/Node.hpp
|
@ -3,21 +3,20 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "filesystem.hpp"
|
||||||
|
|
||||||
struct Game;
|
struct Game;
|
||||||
|
struct Configuration;
|
||||||
|
|
||||||
struct Node
|
struct Node
|
||||||
{
|
{
|
||||||
|
|
||||||
Node *parent = NULL;
|
Node *parent = NULL;
|
||||||
|
|
||||||
Node() { std::cout << "Default constructing Node with parent " << parent << std::endl; }
|
Node();
|
||||||
|
Node(Node*);
|
||||||
Node(Node *parent) : parent(parent)
|
|
||||||
{
|
|
||||||
std::cout << "Constructing Node with parent " << parent << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game *get_root();
|
Game *get_root();
|
||||||
|
Configuration* get_configuration();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,6 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
|
||||||
#include <experimental/filesystem>
|
|
||||||
namespace fs = std::experimental::filesystem;
|
|
||||||
#else
|
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#include <experimental/filesystem>
|
||||||
|
namespace fs = std::experimental::filesystem;
|
||||||
|
#else
|
||||||
|
#include <filesystem>
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
#endif
|
Loading…
Reference in New Issue