mirror of
https://github.com/blawar/ooot.git
synced 2024-06-25 22:09:34 +00:00
laying groundwork for video options in main config
This commit is contained in:
parent
0bec38a09a
commit
f5256eabb4
|
@ -12,11 +12,13 @@ namespace oot::json
|
|||
void set(rapidjson::Value& document, const char* key, rapidjson::Value& value, rapidjson::Document::AllocatorType& alloc);
|
||||
void set(rapidjson::Value& document, const char* key, int value, rapidjson::Document::AllocatorType& alloc);
|
||||
void setU64(rapidjson::Value& document, const char* key, u64 value, rapidjson::Document::AllocatorType& alloc);
|
||||
void setS64(rapidjson::Value& document, const char* key, s64 value, rapidjson::Document::AllocatorType& alloc);
|
||||
void setBool(rapidjson::Value& document, const char* key, bool value, rapidjson::Document::AllocatorType& alloc);
|
||||
void setFloat(rapidjson::Value& document, const char* key, float value, rapidjson::Document::AllocatorType& alloc);
|
||||
|
||||
bool get(rapidjson::Value& document, const char* key, std::string& value);
|
||||
bool getU64(rapidjson::Value& document, const char* key, u64& value);
|
||||
bool getS64(rapidjson::Value& document, const char* key, s64& value);
|
||||
bool getBool(rapidjson::Value& document, const char* key, bool& value);
|
||||
bool getFloat(rapidjson::Value& document, const char* key, float& value);
|
||||
} // namespace oot::json
|
||||
|
|
32
src/json.cpp
32
src/json.cpp
|
@ -34,6 +34,15 @@ namespace oot::json
|
|||
document.AddMember(_key, v, alloc);
|
||||
}
|
||||
|
||||
void setS64(rapidjson::Value& document, const char* key, s64 value, rapidjson::Document::AllocatorType& alloc)
|
||||
{
|
||||
rapidjson::Value v;
|
||||
v.SetInt64(value);
|
||||
|
||||
rapidjson::Value _key(key, alloc);
|
||||
document.AddMember(_key, v, alloc);
|
||||
}
|
||||
|
||||
void setFloat(rapidjson::Value& document, const char* key, float value, rapidjson::Document::AllocatorType& alloc)
|
||||
{
|
||||
rapidjson::Value v;
|
||||
|
@ -98,6 +107,29 @@ namespace oot::json
|
|||
return true;
|
||||
}
|
||||
|
||||
bool getS64(rapidjson::Value& document, const char* key, s64& value)
|
||||
{
|
||||
if(!document.IsObject())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!document.HasMember(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& v = document[key];
|
||||
|
||||
if(!v.IsInt64())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = v.GetInt64();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getBool(rapidjson::Value& document, const char* key, bool& value)
|
||||
{
|
||||
if(!document.IsObject())
|
||||
|
|
|
@ -97,6 +97,7 @@ namespace oot
|
|||
cheats().load(d);
|
||||
controls().load(d);
|
||||
game().load(d);
|
||||
//video().load(d);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
@ -133,6 +134,7 @@ namespace oot
|
|||
cheats().save(d, allocator);
|
||||
controls().save(d, allocator);
|
||||
game().save(d, allocator);
|
||||
//video().save(d, allocator);
|
||||
|
||||
if(!json::save(d, CONFIG_JSON_FILE))
|
||||
{
|
||||
|
@ -149,6 +151,31 @@ namespace oot
|
|||
return true;
|
||||
}
|
||||
|
||||
Video::Video()
|
||||
{
|
||||
}
|
||||
|
||||
void Video::save(rapidjson::Document& doc, rapidjson::Document::AllocatorType& allocator)
|
||||
{
|
||||
rapidjson::Value container(rapidjson::Type::kObjectType);
|
||||
|
||||
json::setS64(container, "vsync", vsync(), allocator);
|
||||
json::setBool(container, "doubleBuffer", doubleBuffer(), allocator);
|
||||
|
||||
doc.AddMember(rapidjson::Value("Video", allocator), container, allocator);
|
||||
}
|
||||
|
||||
void Video::load(rapidjson::Document& doc)
|
||||
{
|
||||
if(doc.HasMember("Video"))
|
||||
{
|
||||
auto& container = doc["Video"];
|
||||
|
||||
json::getS64(container, "vsync", vsync());
|
||||
json::getBool(container, "doubleBuffer", doubleBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
Game::Game()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -226,6 +226,39 @@ namespace oot
|
|||
bool m_blindGerudoGuards = false;
|
||||
};
|
||||
|
||||
class Video : public Section
|
||||
{
|
||||
public:
|
||||
Video();
|
||||
|
||||
void save(rapidjson::Document& doc, rapidjson::Document::AllocatorType& allocator) override;
|
||||
void load(rapidjson::Document& doc) override;
|
||||
|
||||
const s64& vsync() const
|
||||
{
|
||||
return m_vsync;
|
||||
}
|
||||
|
||||
s64& vsync()
|
||||
{
|
||||
return m_vsync;
|
||||
}
|
||||
|
||||
const bool& doubleBuffer() const
|
||||
{
|
||||
return m_doubleBuffer;
|
||||
}
|
||||
|
||||
bool& doubleBuffer()
|
||||
{
|
||||
return m_doubleBuffer;
|
||||
}
|
||||
|
||||
protected:
|
||||
s64 m_vsync = 0;
|
||||
bool m_doubleBuffer = 0;
|
||||
};
|
||||
|
||||
class Game : public Section
|
||||
{
|
||||
public:
|
||||
|
@ -419,10 +452,21 @@ namespace oot
|
|||
return m_game;
|
||||
}
|
||||
|
||||
const Video& video() const
|
||||
{
|
||||
return m_video;
|
||||
}
|
||||
|
||||
Video& video()
|
||||
{
|
||||
return m_video;
|
||||
}
|
||||
|
||||
protected:
|
||||
Camera m_camera;
|
||||
Cheats m_cheats;
|
||||
Controls m_controls;
|
||||
Video m_video;
|
||||
Game m_game;
|
||||
};
|
||||
} // namespace options
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace platform::window
|
|||
virtual void swap_buffers_begin() = 0;
|
||||
virtual void swap_buffers_end() = 0;
|
||||
virtual void resize(long width, long height) = 0;
|
||||
virtual void set_vsync(long setting) = 0;
|
||||
|
||||
void calc_sizes();
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "port/window.h"
|
||||
#include "ultra64/types.h"
|
||||
#include "z64message.h"
|
||||
#include "port/options.h"
|
||||
#include "port/debug.h"
|
||||
|
||||
void quit();
|
||||
void Set_Language(u8 language_id);
|
||||
|
@ -228,6 +230,7 @@ namespace platform::window
|
|||
#ifdef __SWITCH__
|
||||
wnd = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
|
||||
#else
|
||||
//SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, oot::config().video().doubleBuffer());
|
||||
wnd = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width(), height(), SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
|
||||
if(start_in_fullscreen)
|
||||
|
@ -235,7 +238,12 @@ namespace platform::window
|
|||
set_fullscreen(true, false);
|
||||
}
|
||||
#endif
|
||||
set_vsync();
|
||||
/*if(oot::config().video().vsync())
|
||||
{
|
||||
set_vsync(oot::config().video().vsync());
|
||||
}*/
|
||||
|
||||
set_refresh_interval();
|
||||
resize(width(), height());
|
||||
|
||||
auto locale = SDL_GetPreferredLocales();
|
||||
|
@ -300,7 +308,17 @@ namespace platform::window
|
|||
#endif
|
||||
}
|
||||
|
||||
void set_vsync()
|
||||
void set_vsync(long setting)
|
||||
{
|
||||
auto result = SDL_GL_SetSwapInterval(setting);
|
||||
|
||||
if(result == -1)
|
||||
{
|
||||
oot::log("vsync failed %d, tried %d, %s\n", result, setting, SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
void set_refresh_interval()
|
||||
{
|
||||
if(SDL_GetNumVideoDisplays() > 0)
|
||||
{
|
||||
|
|
|
@ -83,6 +83,7 @@ namespace platform::window
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
return !dropped_frame;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user