diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cb38bd..5582d1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ set(MAIN_HEADERS src/flashable.h src/font.h src/input.h + src/iniconfig.h src/plane.h src/scene.h src/sprite.h @@ -87,6 +88,7 @@ set(MAIN_SOURCE src/filesystem.cpp src/font.cpp src/input.cpp + src/iniconfig.cpp src/plane.cpp src/scene.cpp src/sprite.cpp diff --git a/mkxp.pro b/mkxp.pro index c4d52d3..b749a24 100644 --- a/mkxp.pro +++ b/mkxp.pro @@ -1,298 +1,300 @@ - - -TEMPLATE = app -QT = -TARGET = OneShot -DEPENDPATH += src shader assets -INCLUDEPATH += . src - -CONFIG -= qt -CONFIG += link_pkgconfig - -CONFIG(release, debug|release): DEFINES += NDEBUG STEAM - -isEmpty(BINDING) { - BINDING = MRI -} - -contains(BINDING, MRI) { - contains(_HAVE_BINDING, YES) { - error("Only one binding may be selected") - } - _HAVE_BINDING = YES - - CONFIG += BINDING_MRI -} - -contains(BINDING, NULL) { - contains(_HAVE_BINDING, YES) { - error("Only one binding may be selected") - } - _HAVE_BINDING = YES - - CONFIG += BINDING_NULL -} - -PKGCONFIG = sigc++-2.0 pixman-1 zlib sdl2 SDL2_image SDL2_ttf openal SDL_sound vorbisfile - -unix { - CONFIG += c++11 - PKGCONFIG += physfs - LIBS += -ldl - macx: { - INCLUDEPATH += $$QMAKE_MAC_SDK_PATH/System/Library/Frameworks/OpenAL.framework/Versions/A/Headers /usr/local/include - LIBS += -framework OpenAL -framework AppKit - QMAKE_LFLAGS += -L/usr/local/lib -L/usr/local/opt/ruby/lib -L/usr/local/opt/openal-soft/lib - HEADERS += src/mac-desktop.h - SOURCES += src/mac-desktop.mm - } - !macx: { - QMAKE_CXXFLAGS += -g - PKGCONFIG += gtk+-3.0 gdk-3.0 libxfconf-0 - INCLUDEPATH += /usr/include/AL /usr/local/include/AL - LIBS += -lX11 - } -} - -win32 { - QMAKE_CXXFLAGS += -std=gnu++11 - QMAKE_LFLAGS += -std=gnu++11 - - PKGCONFIG += freetype2 - LIBS += -lphysfs -lsecur32 -lwinmm - - release { - RC_FILE = assets/resources.rc - } -} - -# Deal with boost paths... -isEmpty(BOOST_I) { - BOOST_I = $$(BOOST_I) -} -isEmpty(BOOST_I) {} -else { - INCLUDEPATH += $$BOOST_I -} - -isEmpty(BOOST_L) { - BOOST_L = $$(BOOST_L) -} -isEmpty(BOOST_L) {} -else { - LIBS += -L$$BOOST_L -} - -isEmpty(BOOST_LIB_SUFFIX) { - BOOST_LIB_SUFFIX = $$(BOOST_LIB_SUFFIX) -} - -LIBS += -lboost_program_options$$BOOST_LIB_SUFFIX - -# Input -HEADERS += \ - src/quadarray.h \ - src/audio.h \ - src/binding.h \ - src/bitmap.h \ - src/disposable.h \ - src/etc.h \ - src/etc-internal.h \ - src/eventthread.h \ - src/flashable.h \ - src/font.h \ - src/input.h \ - src/plane.h \ - src/scene.h \ - src/sprite.h \ - src/table.h \ - src/texpool.h \ - src/tilequad.h \ - src/transform.h \ - src/viewport.h \ - src/window.h \ - src/serializable.h \ - src/shader.h \ - src/glstate.h \ - src/quad.h \ - src/tilemap.h \ - src/tilemap-common.h \ - src/graphics.h \ - src/gl-debug.h \ - src/global-ibo.h \ - src/exception.h \ - src/filesystem.h \ - src/serial-util.h \ - src/intrulist.h \ - src/binding.h \ - src/gl-util.h \ - src/util.h \ - src/config.h \ - src/settingsmenu.h \ - src/keybindings.h \ - src/tileatlas.h \ - src/sharedstate.h \ - src/al-util.h \ - src/boost-hash.h \ - src/debugwriter.h \ - src/gl-fun.h \ - src/gl-meta.h \ - src/vertex.h \ - src/soundemitter.h \ - src/aldatasource.h \ - src/alstream.h \ - src/audiostream.h \ - src/rgssad.h \ - src/sdl-util.h \ - src/oneshot.h \ - src/pipe.h \ - chromasdk/RzChromaSDKDefines.h \ - chromasdk/RzChromaSDKTypes.h \ - chromasdk/RzErrors.h \ - chromasdk/ChromaApi.h \ - src/i18n.h - -SOURCES += \ - src/main.cpp \ - src/audio.cpp \ - src/bitmap.cpp \ - src/eventthread.cpp \ - src/filesystem.cpp \ - src/font.cpp \ - src/input.cpp \ - src/plane.cpp \ - src/scene.cpp \ - src/sprite.cpp \ - src/table.cpp \ - src/tilequad.cpp \ - src/viewport.cpp \ - src/window.cpp \ - src/texpool.cpp \ - src/shader.cpp \ - src/glstate.cpp \ - src/tilemap.cpp \ - src/autotiles.cpp \ - src/graphics.cpp \ - src/gl-debug.cpp \ - src/etc.cpp \ - src/config.cpp \ - src/settingsmenu.cpp \ - src/keybindings.cpp \ - src/tileatlas.cpp \ - src/sharedstate.cpp \ - src/gl-fun.cpp \ - src/gl-meta.cpp \ - src/vertex.cpp \ - src/soundemitter.cpp \ - src/sdlsoundsource.cpp \ - src/alstream.cpp \ - src/audiostream.cpp \ - src/rgssad.cpp \ - src/vorbissource.cpp \ - src/oneshot.cpp \ - src/screen.cpp \ - src/i18n.cpp - -CONFIG(release, debug|release): { - HEADERS += src/steam.h steamshim/steamshim_child.h - SOURCES += src/steam.cpp steamshim/steamshim_child.c -} - -EMBED = \ - shader/common.h \ - shader/transSimple.frag \ - shader/trans.frag \ - shader/hue.frag \ - shader/sprite.frag \ - shader/plane.frag \ - shader/gray.frag \ - shader/bitmapBlit.frag \ - shader/flatColor.frag \ - shader/simple.frag \ - shader/simpleColor.frag \ - shader/simpleAlpha.frag \ - shader/simpleAlphaUni.frag \ - shader/flashMap.frag \ - shader/obscured.frag \ - shader/minimal.vert \ - shader/simple.vert \ - shader/simpleColor.vert \ - shader/sprite.vert \ - shader/tilemap.vert \ - shader/blur.frag \ - shader/blurH.vert \ - shader/blurV.vert \ - shader/simpleMatrix.vert \ - assets/icon.png \ - assets/gamecontrollerdb.txt - -defineReplace(xxdOutput) { - return($$basename(1).xxd) -} - -# xxd -xxd.output_function = xxdOutput -xxd.commands = xxd -i ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT} -xxd.depends = $$EMBED -xxd.input = EMBED -xxd.variable_out = HEADERS - -QMAKE_EXTRA_COMPILERS += xxd - - -BINDING_NULL { - SOURCES += binding-null/binding-null.cpp -} - -BINDING_MRI { - isEmpty(MRIVERSION) { - MRIVERSION = 2.3 - } - - PKGCONFIG += ruby-$$MRIVERSION - DEFINES += BINDING_MRI - -# EMBED2 = binding-mri/module_rpg.rb -# xxdp.output = ${QMAKE_FILE_NAME}.xxd -# xxdp.commands = xxd+/xxd+ ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} --string -# xxdp.depends = $$EMBED2 -# xxdp.input = EMBED2 -# xxdp.variable_out = HEADERS -# QMAKE_EXTRA_COMPILERS += xxdp - - HEADERS += \ - binding-mri/binding-util.h \ - binding-mri/binding-types.h \ - binding-mri/serializable-binding.h \ - binding-mri/disposable-binding.h \ - binding-mri/sceneelement-binding.h \ - binding-mri/viewportelement-binding.h \ - binding-mri/flashable-binding.h \ - binding-mri/journal-binding.h - - SOURCES += \ - binding-mri/binding-mri.cpp \ - binding-mri/binding-util.cpp \ - binding-mri/table-binding.cpp \ - binding-mri/etc-binding.cpp \ - binding-mri/bitmap-binding.cpp \ - binding-mri/font-binding.cpp \ - binding-mri/graphics-binding.cpp \ - binding-mri/input-binding.cpp \ - binding-mri/sprite-binding.cpp \ - binding-mri/viewport-binding.cpp \ - binding-mri/plane-binding.cpp \ - binding-mri/window-binding.cpp \ - binding-mri/tilemap-binding.cpp \ - binding-mri/audio-binding.cpp \ - binding-mri/module_rpg.cpp \ - binding-mri/filesystem-binding.cpp \ - binding-mri/oneshot-binding.cpp \ - binding-mri/steam-binding.cpp \ - binding-mri/wallpaper-binding.cpp \ - binding-mri/journal-binding.cpp \ - binding-mri/chroma-binding.cpp \ - binding-mri/niko-binding.cpp -} - -OTHER_FILES += $$EMBED + + +TEMPLATE = app +QT = +TARGET = OneShot +DEPENDPATH += src shader assets +INCLUDEPATH += . src + +CONFIG -= qt +CONFIG += link_pkgconfig + +CONFIG(release, debug|release): DEFINES += NDEBUG STEAM + +isEmpty(BINDING) { + BINDING = MRI +} + +contains(BINDING, MRI) { + contains(_HAVE_BINDING, YES) { + error("Only one binding may be selected") + } + _HAVE_BINDING = YES + + CONFIG += BINDING_MRI +} + +contains(BINDING, NULL) { + contains(_HAVE_BINDING, YES) { + error("Only one binding may be selected") + } + _HAVE_BINDING = YES + + CONFIG += BINDING_NULL +} + +PKGCONFIG = sigc++-2.0 pixman-1 zlib sdl2 SDL2_image SDL2_ttf openal SDL_sound vorbisfile + +unix { + CONFIG += c++11 + PKGCONFIG += physfs + LIBS += -ldl + macx: { + INCLUDEPATH += $$QMAKE_MAC_SDK_PATH/System/Library/Frameworks/OpenAL.framework/Versions/A/Headers /usr/local/include + LIBS += -framework OpenAL -framework AppKit + QMAKE_LFLAGS += -L/usr/local/lib -L/usr/local/opt/ruby/lib -L/usr/local/opt/openal-soft/lib + HEADERS += src/mac-desktop.h + SOURCES += src/mac-desktop.mm + } + !macx: { + QMAKE_CXXFLAGS += -g + PKGCONFIG += gtk+-3.0 gdk-3.0 libxfconf-0 + INCLUDEPATH += /usr/include/AL /usr/local/include/AL + LIBS += -lX11 + } +} + +win32 { + QMAKE_CXXFLAGS += -std=gnu++11 + QMAKE_LFLAGS += -std=gnu++11 + + PKGCONFIG += freetype2 + LIBS += -lphysfs -lsecur32 -lwinmm + + release { + RC_FILE = assets/resources.rc + } +} + +# Deal with boost paths... +isEmpty(BOOST_I) { + BOOST_I = $$(BOOST_I) +} +isEmpty(BOOST_I) {} +else { + INCLUDEPATH += $$BOOST_I +} + +isEmpty(BOOST_L) { + BOOST_L = $$(BOOST_L) +} +isEmpty(BOOST_L) {} +else { + LIBS += -L$$BOOST_L +} + +isEmpty(BOOST_LIB_SUFFIX) { + BOOST_LIB_SUFFIX = $$(BOOST_LIB_SUFFIX) +} + +LIBS += -lboost_program_options$$BOOST_LIB_SUFFIX + +# Input +HEADERS += \ + src/quadarray.h \ + src/audio.h \ + src/binding.h \ + src/bitmap.h \ + src/disposable.h \ + src/etc.h \ + src/etc-internal.h \ + src/eventthread.h \ + src/flashable.h \ + src/font.h \ + src/input.h \ + src/iniconfig.h \ + src/plane.h \ + src/scene.h \ + src/sprite.h \ + src/table.h \ + src/texpool.h \ + src/tilequad.h \ + src/transform.h \ + src/viewport.h \ + src/window.h \ + src/serializable.h \ + src/shader.h \ + src/glstate.h \ + src/quad.h \ + src/tilemap.h \ + src/tilemap-common.h \ + src/graphics.h \ + src/gl-debug.h \ + src/global-ibo.h \ + src/exception.h \ + src/filesystem.h \ + src/serial-util.h \ + src/intrulist.h \ + src/binding.h \ + src/gl-util.h \ + src/util.h \ + src/config.h \ + src/settingsmenu.h \ + src/keybindings.h \ + src/tileatlas.h \ + src/sharedstate.h \ + src/al-util.h \ + src/boost-hash.h \ + src/debugwriter.h \ + src/gl-fun.h \ + src/gl-meta.h \ + src/vertex.h \ + src/soundemitter.h \ + src/aldatasource.h \ + src/alstream.h \ + src/audiostream.h \ + src/rgssad.h \ + src/sdl-util.h \ + src/oneshot.h \ + src/pipe.h \ + chromasdk/RzChromaSDKDefines.h \ + chromasdk/RzChromaSDKTypes.h \ + chromasdk/RzErrors.h \ + chromasdk/ChromaApi.h \ + src/i18n.h + +SOURCES += \ + src/main.cpp \ + src/audio.cpp \ + src/bitmap.cpp \ + src/eventthread.cpp \ + src/filesystem.cpp \ + src/font.cpp \ + src/input.cpp \ + src/iniconfig.cpp \ + src/plane.cpp \ + src/scene.cpp \ + src/sprite.cpp \ + src/table.cpp \ + src/tilequad.cpp \ + src/viewport.cpp \ + src/window.cpp \ + src/texpool.cpp \ + src/shader.cpp \ + src/glstate.cpp \ + src/tilemap.cpp \ + src/autotiles.cpp \ + src/graphics.cpp \ + src/gl-debug.cpp \ + src/etc.cpp \ + src/config.cpp \ + src/settingsmenu.cpp \ + src/keybindings.cpp \ + src/tileatlas.cpp \ + src/sharedstate.cpp \ + src/gl-fun.cpp \ + src/gl-meta.cpp \ + src/vertex.cpp \ + src/soundemitter.cpp \ + src/sdlsoundsource.cpp \ + src/alstream.cpp \ + src/audiostream.cpp \ + src/rgssad.cpp \ + src/vorbissource.cpp \ + src/oneshot.cpp \ + src/screen.cpp \ + src/i18n.cpp + +CONFIG(release, debug|release): { + HEADERS += src/steam.h steamshim/steamshim_child.h + SOURCES += src/steam.cpp steamshim/steamshim_child.c +} + +EMBED = \ + shader/common.h \ + shader/transSimple.frag \ + shader/trans.frag \ + shader/hue.frag \ + shader/sprite.frag \ + shader/plane.frag \ + shader/gray.frag \ + shader/bitmapBlit.frag \ + shader/flatColor.frag \ + shader/simple.frag \ + shader/simpleColor.frag \ + shader/simpleAlpha.frag \ + shader/simpleAlphaUni.frag \ + shader/flashMap.frag \ + shader/obscured.frag \ + shader/minimal.vert \ + shader/simple.vert \ + shader/simpleColor.vert \ + shader/sprite.vert \ + shader/tilemap.vert \ + shader/blur.frag \ + shader/blurH.vert \ + shader/blurV.vert \ + shader/simpleMatrix.vert \ + assets/icon.png \ + assets/gamecontrollerdb.txt + +defineReplace(xxdOutput) { + return($$basename(1).xxd) +} + +# xxd +xxd.output_function = xxdOutput +xxd.commands = xxd -i ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT} +xxd.depends = $$EMBED +xxd.input = EMBED +xxd.variable_out = HEADERS + +QMAKE_EXTRA_COMPILERS += xxd + + +BINDING_NULL { + SOURCES += binding-null/binding-null.cpp +} + +BINDING_MRI { + isEmpty(MRIVERSION) { + MRIVERSION = 2.3 + } + + PKGCONFIG += ruby-$$MRIVERSION + DEFINES += BINDING_MRI + +# EMBED2 = binding-mri/module_rpg.rb +# xxdp.output = ${QMAKE_FILE_NAME}.xxd +# xxdp.commands = xxd+/xxd+ ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} --string +# xxdp.depends = $$EMBED2 +# xxdp.input = EMBED2 +# xxdp.variable_out = HEADERS +# QMAKE_EXTRA_COMPILERS += xxdp + + HEADERS += \ + binding-mri/binding-util.h \ + binding-mri/binding-types.h \ + binding-mri/serializable-binding.h \ + binding-mri/disposable-binding.h \ + binding-mri/sceneelement-binding.h \ + binding-mri/viewportelement-binding.h \ + binding-mri/flashable-binding.h \ + binding-mri/journal-binding.h + + SOURCES += \ + binding-mri/binding-mri.cpp \ + binding-mri/binding-util.cpp \ + binding-mri/table-binding.cpp \ + binding-mri/etc-binding.cpp \ + binding-mri/bitmap-binding.cpp \ + binding-mri/font-binding.cpp \ + binding-mri/graphics-binding.cpp \ + binding-mri/input-binding.cpp \ + binding-mri/sprite-binding.cpp \ + binding-mri/viewport-binding.cpp \ + binding-mri/plane-binding.cpp \ + binding-mri/window-binding.cpp \ + binding-mri/tilemap-binding.cpp \ + binding-mri/audio-binding.cpp \ + binding-mri/module_rpg.cpp \ + binding-mri/filesystem-binding.cpp \ + binding-mri/oneshot-binding.cpp \ + binding-mri/steam-binding.cpp \ + binding-mri/wallpaper-binding.cpp \ + binding-mri/journal-binding.cpp \ + binding-mri/chroma-binding.cpp \ + binding-mri/niko-binding.cpp +} + +OTHER_FILES += $$EMBED diff --git a/src/config.cpp b/src/config.cpp index 2a27175..7631602 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -34,6 +34,7 @@ #include "debugwriter.h" #include "util.h" #include "sdl-util.h" +#include "iniconfig.h" namespace std { diff --git a/src/iniconfig.cpp b/src/iniconfig.cpp new file mode 100644 index 0000000..f3c0485 --- /dev/null +++ b/src/iniconfig.cpp @@ -0,0 +1,114 @@ +#include "iniconfig.h" + +#include + +std::string toLowerCase(const std::string& str) +{ + std::string lower = str; + std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + return lower; +} + +std::string trim(const std::string& str, const std::string& chars = "\t\n\v\f\r ") +{ + std::string trimmed = str; + trimmed.erase(trimmed.find_last_not_of(chars) + 1); + trimmed.erase(0, trimmed.find_first_not_of(chars)); + return trimmed; +} + +INIConfiguration::Section::Section (const std::string& sname) : m_Name (sname), m_PropertyMap() +{ +} + +bool INIConfiguration::Section::getStringProperty (const std::string& name, std::string& outPropStr) const +{ + try + { + outPropStr = m_PropertyMap.at(toLowerCase(name)).m_Value; + return true; + } + catch (std::out_of_range& oorexcept) + { + return false; + } +} + +bool INIConfiguration::load (std::istream& is) +{ + if (!is.good()) + { + return false; + } + + std::string currSectionName; + + std::string line; + std::getline (is, line); + + while (!is.eof() && !is.bad()) + { + if (line[0] == '[') + { + currSectionName = line.substr (1, line.find_last_of (']') - 1); + } + else if (line[0] != '#' && line.length() > 2) + { + int crloc = line.length() - 1; + + if (crloc >= 0 && line[crloc] == '\r') //check for Windows-style newline + line.resize (crloc); //and correct + + size_t equalsPos = line.find_first_of ("="); + + if (equalsPos != std::string::npos) + { + std::string key = line.substr (0, equalsPos); + std::string val = line.substr (equalsPos + 1); + + addProperty (currSectionName, key , val); + } + } + + std::getline (is, line); + } + + if (is.bad()) + { + return false; + } + + return true; +} + + +std::string INIConfiguration::getStringProperty(const std::string& sname, const std::string& name, const std::string& def) const +{ + auto sectionIt = m_SectionMap.find(toLowerCase(sname)); + + if (sectionIt != m_SectionMap.end()) + { + std::string prop; + + if(sectionIt->second.getStringProperty(name, prop)) + { + return prop; + } + } + + return def; +} + +void INIConfiguration::addProperty (const std::string& sname, const std::string& name, const std::string& val) +{ + if (m_SectionMap.find (toLowerCase(sname)) == m_SectionMap.end()) + { + m_SectionMap.emplace (toLowerCase(sname), Section (sname)); + } + + Section::Property p; + p.m_Name = trim(name); + p.m_Value = trim(val); + + m_SectionMap.at (toLowerCase(sname)).m_PropertyMap[toLowerCase(p.m_Name)] = p; +} diff --git a/src/iniconfig.h b/src/iniconfig.h new file mode 100644 index 0000000..2907df5 --- /dev/null +++ b/src/iniconfig.h @@ -0,0 +1,46 @@ +#ifndef INICONFIG_H +#define INICONFIG_H + +#include +#include + +class INIConfiguration +{ + class Section + { + friend class INIConfiguration; + + struct Property + { + std::string m_Name; + std::string m_Value; + }; + + typedef std::map property_map; + public: + Section (const Section& s) = default; + Section (Section&& s) = default; + + bool getStringProperty (const std::string& name, std::string& outPropStr) const; + + private: + explicit Section (const std::string& name); + + std::string m_Name; + property_map m_PropertyMap; + }; + + typedef std::map section_map; +public: + bool load (std::istream& inStream); + + std::string getStringProperty(const std::string& sname, const std::string& name, const std::string& def = "") const; + +protected: + void addProperty (const std::string& sname, const std::string& name, const std::string& val); + +private: + section_map m_SectionMap; +}; + +#endif // INICONFIG_H