Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from Lohkdesgds/Snapshots
Browse files Browse the repository at this point in the history
V1.0.3 (V1.1.0C)
  • Loading branch information
Lohkdesgds authored Feb 1, 2019
2 parents e0d0e26 + 652e26f commit c4b9118
Show file tree
Hide file tree
Showing 18 changed files with 878 additions and 435 deletions.
3 changes: 3 additions & 0 deletions TheBlast Updated/LSW/all/enable_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@

#include "..\safer\safer.h"


#include "..\defaults\defaults.h"

#include "..\tools\tools.h"
#include "..\log_file\log.h"

#include "..\config\config.h"

#include "..\download_manager\downloader_v2.h"

#include "..\allegro\layerer\layerer.h"
Expand Down
45 changes: 23 additions & 22 deletions TheBlast Updated/LSW/allegro/display/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,6 @@ namespace LSW {
Log::gfile logg;
//Camera::camera_g cam;

bool b = al_init();
if (b) b = al_init_image_addon();
if (b) b = al_init_primitives_addon();
if (b) b = al_init_font_addon();
if (b) b = al_init_ttf_addon();
if (b) b = al_install_audio();
if (b) b = al_init_acodec_addon();
if (b) b = al_reserve_samples(4);
if (b) b = al_install_keyboard();
if (b) b = al_install_mouse();
if (!b) {
logg << Log::NEEDED_START << "[DRAW:LAUNC][ERRR] Failed to start graphics api" << Log::NEEDED_ENDL;
return false;
}

logg << Log::START << "[DRAW:LAUNC][INFO] Launching new display..." << Log::ENDL;

if (flags & ALLEGRO_FULLSCREEN)
Expand All @@ -94,13 +79,25 @@ namespace LSW {
{
for (auto& i : d_mods.modes)
{
if (i.x == x && i.y == y && i.hz >= mode_selected.hz)
{
mode_selected.x = x;
mode_selected.y = y;
mode_selected.hz = i.hz;
failed = false;
logg << Log::START << "[DRAW:LAUNC][INFO] Got a valid option for resolution: " << x << "x" << y << "@" << i.hz << Log::ENDL;
if (isFullscreen) {
if (i.x == x && i.y == y && i.hz >= mode_selected.hz)
{
mode_selected.x = x;
mode_selected.y = y;
mode_selected.hz = i.hz;
failed = false;
logg << Log::START << "[DRAW:LAUNC][INFO] Got a valid option for resolution: " << x << "x" << y << "@" << i.hz << Log::ENDL;
}
}
else {
if (i.hz >= mode_selected.hz)
{
mode_selected.x = x;
mode_selected.y = y;
mode_selected.hz = i.hz;
failed = false;
logg << Log::START << "[DRAW:LAUNC][INFO] Got a valid option for windowed option: " << x << "x" << y << "@" << i.hz << Log::ENDL;
}
}
}
}
Expand Down Expand Up @@ -302,9 +299,13 @@ namespace LSW {

void _display_raw::toggleFullscreen()
{
Config::config conf;
if (al_get_time() - lastToggleFS < Defaults::display_fullscreen_toggle_min_time) return;
lastToggleFS = al_get_time();
isFullscreen = !isFullscreen;

conf.set(Config::WAS_FULLSCREEN, isFullscreen);

al_toggle_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, isFullscreen);
al_acknowledge_resize(display);

Expand Down
10 changes: 9 additions & 1 deletion TheBlast Updated/LSW/allegro/events/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,15 @@ namespace LSW {
else if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
{
e->_setKey(CUSTOMEVENT_DISPLAY_RESIZED, true);
al_acknowledge_resize(e->_getTargD());
ALLEGRO_DISPLAY* d = e->_getTargD();
if (d) {
al_acknowledge_resize(d);

Config::config conf;

conf.set(Config::SCREEN_X, al_get_display_width(d));
conf.set(Config::SCREEN_Y, al_get_display_height(d));
}
}
else if (ev.type == ALLEGRO_EVENT_MOUSE_AXES)
{
Expand Down
2 changes: 1 addition & 1 deletion TheBlast Updated/LSW/allegro/image/imager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace LSW {
image_low::~image_low()
{
unload();
logg << Log::START << "[IMGL:CONST][INFO] Registered despawn of image_low ID#" + std::to_string((size_t)this) << ";ID=" << id << Log::ENDL;
logg << Log::START << "[IMGL:DESTR][INFO] Registered despawn of image_low ID#" + std::to_string((size_t)this) << ";ID=" << id << Log::ENDL;
}


Expand Down
23 changes: 16 additions & 7 deletions TheBlast Updated/LSW/allegro/sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,48 @@ namespace LSW {
track::~track()
{
unload();
logg << Log::START << "[IMGL:CONST][INFO] Registered despawn of image_low ID#" + std::to_string((size_t)this) << ";ID=" << id << Log::ENDL;
logg << Log::START << "[IMGL:DESTR][INFO] Registered despawn of image_low ID#" + std::to_string((size_t)this) << ";ID=" << id << Log::ENDL;
}

const bool track::load()
{
if (!vnm.voice) {
vnm.voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
if (!vnm.voice) {
throw "TRACK::LOAD - FAILED TO CREATE VOICE FOR TRACKS";
throw "at track::load [#" + std::to_string((size_t)this) + ";ID=" + id.g() + "]: Failed to create voice.";
return false;
}

vnm.mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
if (!vnm.mixer) {
throw "TRACK::LOAD - FAILED TO CREATE MIXER FOR TRACKS";
throw "at track::load [#" + std::to_string((size_t)this) + ";ID=" + id.g() + "]: Failed to create mixer.";
return false;
}

if (!al_attach_mixer_to_voice(vnm.mixer, vnm.voice)) {
throw "TRACK::LOAD - FAILED TO SET MIXER INTO VOICE";
throw "at track::load [#" + std::to_string((size_t)this) + ";ID=" + id.g() + "]: Failed to set mixer in voice.";
return false;
}

set(Sound::GLOBALVOLUME, Defaults::Sound::global_volume);
float temp_vol_get;
Config::config conf;
conf.get(Config::LAST_VOLUME, temp_vol_get, Defaults::Sound::global_volume);
set(Sound::GLOBALVOLUME, temp_vol_get);
}

if (mse) al_destroy_sample(mse);

mse = al_load_sample(path.g().c_str());
if (!mse) return false;
if (!mse) {
throw "at track::load [#" + std::to_string((size_t)this) + ";ID=" + id.g() + "]: Failed to load sample.";
return false;
}

instance = al_create_sample_instance(nullptr);
if (!instance) return false;
if (!instance) {
throw "at track::load [#" + std::to_string((size_t)this) + ";ID=" + id.g() + "]: Failed to create instance.";
return false;
}

al_set_sample(instance, mse);

Expand Down
172 changes: 172 additions & 0 deletions TheBlast Updated/LSW/config/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#include "..\all\enable_all.h"

namespace LSW {
namespace v2 {
namespace Config {

ALLEGRO_CONFIG* config::c = nullptr;
std::mutex config::m;

config::config()
{
logg << Log::START << "[CONF:CONST][INFO] Registered spawn of config ID#" + std::to_string((size_t)this) << Log::ENDL;
m.lock();
if (!c) {
Safer::safe_string temporary = Defaults::Config::config_file;
Tools::interpret_path(temporary);
Tools::createPath(temporary);

logg << Log::NEEDED_START << "[CONF:CONST][INFO] Registered loading of Config file (global)" << Log::NEEDED_ENDL;
if (!(c = al_load_config_file(temporary.g().c_str())))
{
c = al_create_config();
if (!c) throw "at config::config [#" + std::to_string((size_t)this) + "]: Cannot load/create config file!";
logg << Log::NEEDED_START << "[CONF:CONST][INFO] Is this the first time you're opening this game? Registered first Config load." << Log::NEEDED_ENDL;

// set or load first values
set(Config::HAD_ERROR, true); // then texture download starts // USED
set(Config::WAS_OSD_ON, false); // USED
set(Config::WAS_FULLSCREEN, true); // USED
set(Config::LAST_VOLUME, 0.5);
set(Config::LAST_VERSION, Defaults::version_app); // nah
set(Config::LAST_PLAYERNAME, "Player");
set(Config::LAST_COLOR, "GREEN");
set(Config::SCREEN_X, Defaults::Config::screen_siz[0]);
set(Config::SCREEN_Y, Defaults::Config::screen_siz[1]);
set(Config::_TIMES_LIT, 0LL);

if (!al_save_config_file(temporary.g().c_str(), c)) {
throw "at config::config [#" + std::to_string((size_t)this) + "]: Cannot save config file!";
}
}
else {
long long ll;
get(Config::_TIMES_LIT, ll, 0LL);
ll++;
set(Config::_TIMES_LIT, ll);
}
}
m.unlock();
}
config::~config()
{
logg << Log::START << "[CONF:DESTR][INFO] Registered despawn of config ID#" + std::to_string((size_t)this) << Log::ENDL;
if (c) {
m.lock();
Safer::safe_string temporary = Defaults::Config::config_file;
Tools::interpret_path(temporary);
Tools::createPath(temporary);
al_save_config_file(temporary.g().c_str(), c);
m.unlock();
}
}

void config::set(const Safer::safe_string e, const Safer::safe_string v)
{
if (!c) throw "at config::set [#" + std::to_string((size_t)this) + "]: Cannot set \"" + e.g() + "\" as \"" + v.g() + "\".";
al_set_config_value(c, Defaults::Config::strt_txt.g().c_str(), e.g().c_str(), v.g().c_str());
}
void config::set(const conf_b e, const bool v)
{
set(conf_b_str[e].g(), bool_s[(int)v]);
}
void config::set(const conf_f e, const float v)
{
set(conf_f_str[e].g(), std::to_string(v));
}
void config::set(const conf_i e, const int v)
{
set(conf_i_str[e].g(), std::to_string(v));
}
void config::set(const conf_ll e, const long long v)
{
set(conf_ll_str[e].g(), std::to_string(v));
}
void config::set(const conf_s e, const Safer::safe_string v)
{
set(conf_s_str[e].g(), v);
}

void config::get(const Safer::safe_string e, Safer::safe_string& v, const Safer::safe_string defaul)
{
if (!c) throw "at config::get [#" + std::to_string((size_t)this) + "]: Cannot get \"" + e.g() + "\" as \"" + v.g() + "\".";
const char* chh = al_get_config_value(c, Defaults::Config::strt_txt.g().c_str(), e.g().c_str());
if (!chh) {
logg << Log::NEEDED_START << "[CONF:GET()][WARN] There was no value to " << e << ", so the default value was set (" << defaul << ")." << Log::NEEDED_ENDL;
set(e, defaul);
v = defaul;
return;
}
v = chh;
}
void config::get(const conf_b e, bool& v, const bool defaul)
{
Safer::safe_string output;
get(conf_b_str[e], output, bool_s[(int)defaul]);
v = (output == bool_s[1 /*true*/]);
}
void config::get(const conf_f e, float& v, const float defaul)
{
Safer::safe_string output;
get(conf_f_str[e], output, std::to_string(defaul));
v = atof(output.g().c_str());
}
void config::get(const conf_i e, int& v, const int defaul)
{
Safer::safe_string output;
get(conf_i_str[e], output, std::to_string(defaul));
v = atoi(output.g().c_str());
}
void config::get(const conf_ll e, long long& v, const long long defaul)
{
Safer::safe_string output;
get(conf_ll_str[e], output, std::to_string(defaul));
v = atoll(output.g().c_str());
}
void config::get(const conf_s e, Safer::safe_string& v, const Safer::safe_string defaul)
{
Safer::safe_string output;
get(conf_s_str[e], output, defaul);
v = output;
}


const bool config::isEq(const Safer::safe_string e, const Safer::safe_string v)
{
Safer::safe_string oth;
get(e, oth, v); // meh
return oth == v;
}
const bool config::isEq(const conf_b e, const bool v)
{
bool oth;
get(e, oth, v); // meh
return oth == v;
}
const bool config::isEq(const conf_f e, const float v)
{
float oth;
get(e, oth, v); // meh
return oth == v;
}
const bool config::isEq(const conf_i e, const int v)
{
int oth;
get(e, oth, v); // meh
return oth == v;
}
const bool config::isEq(const conf_ll e, const long long v)
{
long long oth;
get(e, oth, v); // meh
return oth == v;
}
const bool config::isEq(const conf_s e, const Safer::safe_string v)
{
Safer::safe_string oth;
get(e, oth, v); // meh
return oth == v;
}
}
}
}
55 changes: 55 additions & 0 deletions TheBlast Updated/LSW/config/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include "..\all\enable_all.h"

namespace LSW {
namespace v2 {
namespace Config {

enum conf_b{HAD_ERROR,WAS_OSD_ON,WAS_FULLSCREEN};
enum conf_f{LAST_VOLUME};
enum conf_i{SCREEN_X,SCREEN_Y};
enum conf_ll{_TIMES_LIT};
enum conf_s{LAST_VERSION,LAST_PLAYERNAME,LAST_COLOR};

const Safer::safe_string conf_b_str[] = { "had_error", "was_osd_on", "fullscreen" };
const Safer::safe_string conf_f_str[] = { "last_volume" };
const Safer::safe_string conf_i_str[] = { "screen_width","screen_height" };
const Safer::safe_string conf_ll_str[] = { "times_open" };
const Safer::safe_string conf_s_str[] = { "last_version","playername","playercolor" };

// tool
const Safer::safe_string bool_s[] = { "false", "true" };

class config {
static ALLEGRO_CONFIG* c;
static std::mutex m;
Log::gfile logg;
public:
config();
~config();

void set(const Safer::safe_string, const Safer::safe_string);
void set(const conf_b, const bool);
void set(const conf_f, const float);
void set(const conf_i, const int);
void set(const conf_ll, const long long);
void set(const conf_s, const Safer::safe_string);

void get(const Safer::safe_string, Safer::safe_string&, const Safer::safe_string);
void get(const conf_b, bool&, const bool);
void get(const conf_f, float&, const float);
void get(const conf_i, int&, const int);
void get(const conf_ll, long long&, const long long);
void get(const conf_s, Safer::safe_string&, const Safer::safe_string);

const bool isEq(const Safer::safe_string, const Safer::safe_string);
const bool isEq(const conf_b, const bool);
const bool isEq(const conf_f, const float);
const bool isEq(const conf_i, const int);
const bool isEq(const conf_ll, const long long);
const bool isEq(const conf_s, const Safer::safe_string);
};
}
}
}
Loading

0 comments on commit c4b9118

Please sign in to comment.