fix user config merge; clear screen to black; reset to single box on sprite unload
This commit is contained in:
parent
ca44bc4b3a
commit
a8948bca73
76
README
76
README
|
@ -1,44 +1,72 @@
|
|||
SFW (SDL Framework)
|
||||
===================
|
||||
++~~~~~~~~~~~~~~~~~~~~~~~++
|
||||
:: ::
|
||||
:: SFW (SDL Framework) ::
|
||||
:: ::
|
||||
++~~~~~~~~~~~~~~~~~~~~~~~++
|
||||
|
||||
SFW is a C++ library that facilitates the creation of SDL projects and adds
|
||||
useful game graphics oriented classes and functions. It is modeled after PGFW, a
|
||||
Pygame framework, which simplifies the set up of Pygame projects and enhances
|
||||
and adds some features to Pygame.
|
||||
SFW is a C++ framework that facilitates the creation of SDL projects. It
|
||||
provides generic game objects that can be used, extended or overwritten. Games
|
||||
written using this framework can be exported to PC, Mac, Linux, Web GL,
|
||||
Raspberry Pi, and Android.
|
||||
|
||||
It is currently in an early untested stage. It comes with a simple program that
|
||||
demonstrates how the framework can help set up a project in both SDL and OpenGL
|
||||
It is in an early untested state. It comes with a simple program that
|
||||
demonstrates how to use it for a project that can switch between SDL and OpenGL
|
||||
contexts.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
````````````
|
||||
The SFW source includes some external libraries in lib/, but there are other
|
||||
libraries that must also be present in order to compile a project which uses the
|
||||
framework
|
||||
|
||||
The SFW source includes some external libraries in the lib/ folder, but there
|
||||
are also other libraries that must be present in order to compile a project
|
||||
which uses the framework
|
||||
|
||||
* libSDL2 (developed against v2.0.12)
|
||||
* libSDL2 (developed against v2.0.14)
|
||||
* libSDL2-image
|
||||
* libSDL2-ttf
|
||||
* libSDL2-mixer
|
||||
* OpenGL
|
||||
* OpenGL/GLES/GLES2
|
||||
* compiler that supports C++17
|
||||
|
||||
Demo
|
||||
----
|
||||
Installing Requirements
|
||||
```````````````````````
|
||||
libSDL2, libSDL2-image, libSDL2-ttf, and libSDL2-mixer must be available to
|
||||
link with your project, so you can try your package manager's libSDL2 dev
|
||||
packages or build from source. The included sdl2-config utility program can be
|
||||
used to generate flags for linking to SDL2 when it is installed outside of
|
||||
your platform's usual library location.
|
||||
|
||||
The demo/ folder contains a simple cube demo. The main purpose of the demo is
|
||||
to demonstrate switching between 3D and 2D contexts. In order to compile the
|
||||
libSDL2:
|
||||
|
||||
- Download from http://libsdl.org/download-2.0.php
|
||||
- Run ./configure --prefix=[YOUR LIBRARIES PATH] (I'm using ~/local/sdl)
|
||||
- Run make && make install
|
||||
|
||||
libSDL2-image, libSDL2-ttf, libSDL2-mixer:
|
||||
|
||||
- Download from:
|
||||
- https://www.libsdl.org/projects/SDL_image/
|
||||
- https://www.libsdl.org/projects/SDL_ttf/
|
||||
- https://www.libsdl.org/projects/SDL_mixer/
|
||||
- Run ./configure --prefix=[YOUR LIB PATH] --with-sdl-prefix=[YOUR SDL PATH]
|
||||
- In my case, prefix and SDL prefix are both ~/local/sdl
|
||||
|
||||
OpenGL/GLES/GLES2:
|
||||
|
||||
- Install GL/GLES according to your platform and link to it during compilation.
|
||||
GLEW is included in the lib/ folder of this framework and should find GL on
|
||||
your platform if it is installed.
|
||||
|
||||
Demo
|
||||
````
|
||||
The `demo/` folder contains a simple cube demo. The main purpose of the demo is
|
||||
to demonstrate switching between 3D and 2D contexts. In order to compile the
|
||||
demo, you will have to edit the paths in the Makefile to point to the locations
|
||||
of the necessary libraries on your system.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
```````
|
||||
This software is dedicated to the public domain. See
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ for details.
|
||||
|
||||
Author
|
||||
------
|
||||
|
||||
420 at shampoo dot ooo
|
||||
``````
|
||||
420 [AT] shampoo.ooo
|
||||
|
|
|
@ -98,15 +98,11 @@ void Configuration::merge()
|
|||
config = sys_config;
|
||||
if (not game_config.empty())
|
||||
{
|
||||
for (auto& section: config.items())
|
||||
for (auto& section: game_config.items())
|
||||
{
|
||||
if (game_config.contains(section.key()))
|
||||
{
|
||||
config[section.key()].update(game_config[section.key()]);
|
||||
}
|
||||
config[section.key()].update(game_config[section.key()]);
|
||||
}
|
||||
}
|
||||
std::cout << std::setw(4) << config << std::endl;
|
||||
}
|
||||
|
||||
void Configuration::write()
|
||||
|
|
|
@ -41,6 +41,7 @@ void FramerateIndicator::refresh()
|
|||
|
||||
Game::Game()
|
||||
{
|
||||
std::cout << std::setw(4) << get_configuration() << std::endl;
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, get_configuration()["display"]["render driver"].get<std::string>().c_str());
|
||||
frame_length_history.reserve(5000);
|
||||
set_framerate(get_configuration()["display"]["framerate"]);
|
||||
|
@ -94,13 +95,6 @@ Game::Game()
|
|||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
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);
|
||||
|
|
|
@ -236,10 +236,7 @@ void Sprite::unload()
|
|||
}
|
||||
frames.pop_back();
|
||||
}
|
||||
for (Box& box : boxes)
|
||||
{
|
||||
box.clear();
|
||||
}
|
||||
boxes = {{{0, 0}, {0, 0}}};
|
||||
}
|
||||
|
||||
void Sprite::advance_frame()
|
||||
|
|
Loading…
Reference in New Issue