diff --git a/.gitignore b/.gitignore index 8887ed6..9b53814 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -.directory -Makefile -objects/ -ppl.pro.user +.directory +Makefile +objects/ +ppl.pro.user +lib/libppl.a +lib/libppld.a diff --git a/.gitmodules b/.gitmodules index 442a597..a67376a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,7 @@ [submodule "include/simpleini"] path = include/simpleini url = https://github.com/brofield/simpleini.git +[submodule "include/SDK"] + path = include/SDK + url = https://github.com/PhilippMuenzel/SDK.git + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..728ffda --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,100 @@ +cmake_minimum_required (VERSION 3.0) +project(PPL VERSION 2.1.0 DESCRIPTION "Plugin Patterns Library for X-Plane 11/12") + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/lib) + +if(NOT CMAKE_DEBUG_POSTFIX) + set(CMAKE_DEBUG_POSTFIX d) +endif() + +if(UNIX AND NOT APPLE) +set(LINUX TRUE) +endif() + +if(UNIX) + set(PLATFORM_COMPILE_OPTIONS -Wall -Wextra -Wfloat-equal -pedantic) +else() + set(PLATFORM_COMPILE_OPTIONS /W3 /wd4996) +endif() + +if(APPLE) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15) + set(CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD)) + set(PLATFORM_CORE_DEFINITIONS + APL=1 + LIN=0 + IBM=0) + set(PLATFORM_INCLUDE_DIRECTORIES + include/freetype2/include) +else() +if(LINUX) + set(PLATFORM_CORE_DEFINITIONS + APL=0 + LIN=1 + IBM=0) + set(PLATFORM_INCLUDE_DIRECTORIES + /usr/include/freetype2) +else() + set(PLATFORM_CORE_DEFINITIONS + APL=0 + LIN=0 + IBM=1 + FREETYPE2_STATIC + _USE_MATH_DEFINES + NOMINMAX + WIN32_LEAN_AND_MEAN + GLEW_STATIC=1) + set(PLATFORM_INCLUDE_DIRECTORIES + include/glew/include + include/openal-soft/include + include/freetype2/include) + set(PLATFORM_DEBUG_OPTIONS "-MTd") + set(PLATFORM_RELEASE_OPTIONS "-MT") +endif() +endif() + +set(DEFINITIONS + XPLM200=1 + XPLM210=1 + XPLM300=1 + XPLM301=1 + ${PLATFORM_CORE_DEFINITIONS}) + +include_directories(${CMAKE_SOURCE_DIR}/include/SDK/CHeaders/XPLM + ${CMAKE_SOURCE_DIR}/include/SDK/CHeaders/Widgets + ${CMAKE_SOURCE_DIR}/include/simpleini + ${PLATFORM_INCLUDE_DIRECTORIES}) + + +set(SOURCES + src/pluginpath.cpp + src/settings.cpp + src/dataref.cpp + src/messagewindow.cpp + src/onscreendisplay.cpp + src/owneddata.cpp + src/logichandler.cpp + src/texture.cpp + src/overlaygauge.cpp + src/log.cpp + src/logwriter.cpp + src/menuitem.cpp + src/processor.cpp + src/vertexbuffer.cpp + src/command.cpp + src/alsoundbuffer.cpp + src/alcontextmanager.cpp + src/alcontextchanger.cpp + src/fontmgr.cpp) + + +add_library(PPL STATIC ${SOURCES}) +target_compile_options(PPL PUBLIC ${PLATFORM_COMPILE_OPTIONS}) +target_compile_options(PPL PUBLIC "$<$:${PLATFORM_DEBUG_OPTIONS}>") +target_compile_options(PPL PUBLIC "$<$:${PLATFORM_RELEASE_OPTIONS}>") +target_compile_definitions(PPL PRIVATE ${DEFINITIONS}) diff --git a/include/SDK b/include/SDK new file mode 160000 index 0000000..7329d3b --- /dev/null +++ b/include/SDK @@ -0,0 +1 @@ +Subproject commit 7329d3b3c9211192d7f231aa40300a9a592a7fc2 diff --git a/include/freetype2 b/include/freetype2 index f9b1871..920c550 160000 --- a/include/freetype2 +++ b/include/freetype2 @@ -1 +1 @@ -Subproject commit f9b1871ded4df726ed962e5eae535c9918705a3d +Subproject commit 920c5502cc3ddda88f6c7d85ee834ac611bb11cc diff --git a/include/glew b/include/glew index f0067bb..3a8eff7 160000 --- a/include/glew +++ b/include/glew @@ -1 +1 @@ -Subproject commit f0067bb1151d36b37bd43948ce5a399844afb313 +Subproject commit 3a8eff77da3658c13fbd3634c943d5251d76322c diff --git a/include/openal-soft b/include/openal-soft index ce60760..96aacac 160000 --- a/include/openal-soft +++ b/include/openal-soft @@ -1 +1 @@ -Subproject commit ce6076091bac3c00cd10803916e8911495580bd0 +Subproject commit 96aacac10ca852fc30fd7f72f3e3c6ddbe02858c diff --git a/include/simpleini b/include/simpleini index 2af65fc..fe082fa 160000 --- a/include/simpleini +++ b/include/simpleini @@ -1 +1 @@ -Subproject commit 2af65fcc504f8242752755e836709762ef7ce062 +Subproject commit fe082fa81f4a55ddceb55056622136be616b3c6f diff --git a/ppl.pro b/ppl.pro index 5569543..339786d 100644 --- a/ppl.pro +++ b/ppl.pro @@ -9,8 +9,8 @@ CONFIG -= thread qt VERSION = 2.0.0 INCLUDEPATH += include/simpleini -INCLUDEPATH += ../SDK/CHeaders/XPLM -INCLUDEPATH += ../SDK/CHeaders/Widgets +INCLUDEPATH += include/SDK/CHeaders/XPLM +INCLUDEPATH += include/SDK/CHeaders/Widgets # Defined to use X-Plane SDK 2.0, 2.1, 3.0 and 3.01 capabilities - no backward compatibility before 11.20 DEFINES += XPLM200 XPLM210 XPLM300 XPLM301 @@ -19,11 +19,6 @@ OBJECTS_DIR = objects DESTDIR = lib TARGET = ppl -standalone { - DEFINES += BUILD_FOR_STANDALONE - TARGET = pplstandalone -} - macx { DEFINES += APL=1 IBM=0 LIN=0 QMAKE_CXXFLAGS += -Wextra -Wfloat-equal -pedantic @@ -40,7 +35,7 @@ win32 { DEFINES += APL=0 IBM=1 LIN=0 #disable the deprecated warnings that make writing standards-compliant code impossible QMAKE_CXXFLAGS += -wd4996 - QMAKE_CXXFLAGS_DEBUG = -Zi -MTd + QMAKE_CXXFLAGS_DEBUG = -Zi -MTd QMAKE_CXXFLAGS_RELEASE = -MT DEFINES += _USE_MATH_DEFINES NOMINMAX WIN32_LEAN_AND_MEAN GLEW_STATIC=1 } diff --git a/src/command.cpp b/src/command.cpp index 527d2dd..8b03476 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1,78 +1,151 @@ -#include "command.h" - -/* Copyright (c) 2018, Jack Deeth github@jackdeeth.org.uk +// Copyright (c) 2023, Jack Deeth , Julia DeMille // All rights reserved // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, -this -// list of conditions and the following disclaimer. +// this list of conditions and the following disclaimer. // 2. 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. // // 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 +// 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; +// 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. // // The views and conclusions contained in the software and documentation are -those -// of the authors and should not be interpreted as representing official -policies, -// either expressed or implied, of the FreeBSD Project. -*/ +// those of the authors and should not be interpreted as representing official +// policies, either expressed or implied, of the FreeBSD Project. + +#include "command.h" +#include "XPLMDataAccess.h" +#include "XPLMUtilities.h" +#include "log.h" +#include + +using namespace std::string_literals; -PPL::Command::Command(XPLMCommandRef ref, - std::function cb, - bool run_before_sim) - : callback(cb), ref_(ref), before_(run_before_sim ? 1 : 0) { - XPLMRegisterCommandHandler(ref_, scb, before_, this); +namespace PPL { + +Command::Command(XPLMDataRef cmd_ref) + : cmd_ref(cmd_ref) +{ } -PPL::Command::Command(std::string cmd_to_replace, - std::function callback, - bool run_before) - : Command(XPLMFindCommand(cmd_to_replace.c_str()), callback, run_before) {} +std::optional Command::find(std::string& name) +{ + XPLMCommandRef cmd_ref = XPLMFindCommand(name.c_str()); + if (cmd_ref == nullptr) { + return std::nullopt; + } else { + return Command(cmd_ref); + } +} -PPL::Command::Command(std::string new_cmd, - std::string description, - std::function callback, - bool run_before) - : Command(XPLMCreateCommand(new_cmd.c_str(), description.c_str()), - callback, - run_before) {} +Command Command::create(std::string& name, std::string& description) +{ + if (Command::find(name)) { + throw CommandAlreadyExists(name); + } + XPLMCommandRef cmd_ref = XPLMCreateCommand(name.c_str(), description.c_str()); + return Command(cmd_ref); +} -PPL::Command::~Command() { - XPLMUnregisterCommandHandler(ref_, scb, before_, this); +CommandAlreadyExists::CommandAlreadyExists(const std::string& command) + : std::runtime_error("The command `"s + command + "` already exists. It cannot be created."s) +{ } -PPL::Command::Phase PPL::Command::phase() const { return phase_; } +template + requires impl_CommandHandler +RegisteredCommandHandler Command::handle(bool before_xp, T handler) +{ + RegisteredCommandHandler(cmd_ref, before_xp, handler); +} -void PPL::Command::begin() { XPLMCommandBegin(ref_); } +void Command::trigger_once() +{ + XPLMCommandOnce(cmd_ref); +} -void PPL::Command::end() { XPLMCommandEnd(ref_); } +CommandHold Command::hold_down() +{ + return CommandHold(*this); +} -void PPL::Command::once() { XPLMCommandOnce(ref_); } +CommandHold::CommandHold(Command& cmd) + : cmd(cmd) +{ + XPLMCommandBegin(cmd.cmd_ref); +} -int PPL::Command::scb(XPLMCommandRef ref, XPLMCommandPhase phase, void *vp) { - // scb = shared/static call-back - // converts C conventions with (post?)modern C++ - auto cmd = reinterpret_cast(vp); - if (phase == xplm_CommandBegin) cmd->phase_ = Phase::Begin; - if (phase == xplm_CommandContinue) cmd->phase_ = Phase::Continue; - if (phase == xplm_CommandEnd) cmd->phase_ = Phase::End; - auto outcome = cmd->callback(ref, cmd->phase_); - return outcome == Outcome::Halt ? 0 : 1; +CommandHold::~CommandHold() +{ + XPLMCommandEnd(cmd.cmd_ref); +} + +template + requires impl_CommandHandler +RegisteredCommandHandler::RegisteredCommandHandler(XPLMCommandRef cmd_ref, bool before_xp, T handler_) + : cmd_ref(cmd_ref) + , before_xp(before_xp) + , handler(handler_) +{ + XPLMRegisterCommandHandler( + cmd_ref, + RegisteredCommandHandler::handle, + before_xp, + &handler); +} + +template + requires impl_CommandHandler +int RegisteredCommandHandler::handle(XPLMCommandRef _ref, XPLMCommandPhase phase, void* refcon) +{ + T* handler = static_cast(refcon); + CommandOutcome outcome; + switch (phase) { + case xplm_CommandBegin: + outcome = handler->command_begin(); + break; + case xplm_CommandContinue: + outcome = handler->command_continue(); + break; + case xplm_CommandEnd: + outcome = handler->command_end(); + break; + default: + outcome = CommandOutcome::Continue; + Log() << Log::Error << "XPLM has called a command handler with an invalid phase!" << Log::endl; + break; + } + switch (outcome) { + case CommandOutcome::Irrelevant: + case CommandOutcome::Continue: + return 1; + break; + case CommandOutcome::Halt: + return 0; + break; + } +} + +template + requires impl_CommandHandler +RegisteredCommandHandler::~RegisteredCommandHandler() +{ + XPLMUnregisterCommandHandler( + cmd_ref, + RegisteredCommandHandler::handle, + before_xp, + &handler); +} } diff --git a/src/command.h b/src/command.h index c0b0b23..54e425f 100644 --- a/src/command.h +++ b/src/command.h @@ -1,132 +1,146 @@ -#pragma once - -/* Copyright (c) 2018, Jack Deeth github@jackdeeth.org.uk +// Copyright (c) 2023, Jack Deeth , Julia DeMille // All rights reserved // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, -this -// list of conditions and the following disclaimer. +// this list of conditions and the following disclaimer. // 2. 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. // // 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 +// 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; +// 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. // // The views and conclusions contained in the software and documentation are -those -// of the authors and should not be interpreted as representing official -policies, -// either expressed or implied, of the FreeBSD Project. -*/ - -/* Example usage: - -// disable an existing command -PPL::Command left_brake_cmd_{"sim/flight_controls/left_brake"}; - -// hijack an existing command -const auto End{PPL::Command::Phase::End}; -const auto Halt{PPL::Command::Outcome::Halt}; -PPL::Command brake_toggle_cmd_{ - "sim/flight_controls/brakes_toggle_regular", - [&](XPLMCommandRef, PPL::Command::Phase phase) { - if (phase == End) { - if (handbrake_lever_ratio_ < 0.5f) - handbrake_lever_ratio_ = 0.5f; - else - handbrake_lever_ratio_ = 0.f; - } - return Halt; - }}; - -// create a new command -class CompileMessage { -public: - CompileMessage(std::string command_name = -"YourName/YourProject/show_compile_msg", - std::string desc = "Announces compilation date/time of plugin" - : cmd_{command_name, desc, [](XPLMCommandRef, PPL::Command::Phase phase) { - if (phase == PPL::Command::Phase::Begin) - XPLMSpeakString(compile_message().c_str()); - return PPL::Command::Outcome::Halt; - }} {} - - static std::string compile_message() { - std::stringstream msg; - msg << "Compiled " << __DATE__ << " at " << __TIME__; - return msg.str(); - } -private: - PPL::Command cmd_; -}; +// those of the authors and should not be interpreted as representing official +// policies, either expressed or implied, of the FreeBSD Project. -*/ +#ifndef PPL_COMMAND_H_ +#define PPL_COMMAND_H_ #include -#include +#include +#include +#include +#include #include // RAII wrapper for X-Plane Commands API namespace PPL { +class CommandHandler; + +template +concept impl_CommandHandler = std::derived_from && (!std::same_as); + +template + requires impl_CommandHandler +class RegisteredCommandHandler; + +class CommandHold; + class Command { + friend CommandHold; + public: - enum class Outcome { Continue, Halt }; - enum class Phase { Begin, Continue, End }; + static std::optional find(std::string& name); + static Command create(std::string& name, std::string& description); + template + requires impl_CommandHandler + RegisteredCommandHandler handle(bool before_xp, T handler); + void trigger_once(); + CommandHold hold_down(); - // Finds a command by reference and attaches a new callback to it - Command(XPLMCommandRef ref, - std::function callback = - [](...) { return Outcome::Halt; }, - bool run_before = true); +private: + Command(XPLMCommandRef cmd_ref); + XPLMCommandRef cmd_ref; +}; - // Finds a command by name and attaches a new callback to it - // (useful for hijacking and/or blocking existing commands) - Command(std::string cmd_to_replace, - std::function callback = - [](...) { return Outcome::Halt; }, - bool run_before = true); +class CommandAlreadyExists : public std::runtime_error { + friend Command; - // Creates a new command and attaches a callback to it - Command(std::string new_cmd, - std::string description, - std::function callback = - [](...) { return Outcome::Halt; }, - bool run_before = true); +private: + CommandAlreadyExists(const std::string& command); +}; - ~Command(); +class CommandHold { + friend Command; - Phase phase() const; +public: + ~CommandHold(); + +private: + CommandHold(Command& cmd); + Command& cmd; +}; + +enum class CommandOutcome { + /** + * @brief Allow X-Plane to handle the command. + */ + Continue, + /** + * @brief Prevent X-Plane from handling the command. + */ + Halt, + /** + * @brief Return this if handling the command after X-Plane. + */ + Irrelevant +}; - void begin(); - void end(); - void once(); +enum class CommandPhase { + /** + * @brief The command has begun. + */ + Begin, + /** + * @brief Periodic events with this phase are sent when the command is held. + */ + Continue, + /** + * @brief The command has been released. + */ + End +}; + +class CommandHandler { +public: + CommandHandler(); + virtual ~CommandHandler() = 0; + virtual CommandOutcome command_begin() = 0; + virtual CommandOutcome command_continue() = 0; + virtual CommandOutcome command_end() = 0; +}; - std::function callback; +template + requires impl_CommandHandler +class RegisteredCommandHandler { + friend Command; - static int scb(XPLMCommandRef ref, XPLMCommandPhase phase, void *vp); +public: + ~RegisteredCommandHandler(); private: - XPLMCommandRef ref_; - int before_; - Phase phase_{Phase::End}; + RegisteredCommandHandler(XPLMCommandRef cmd_ref, bool before_xp, T handler); + XPLMCommandRef cmd_ref; + bool before_xp; + T handler; + static int handle(XPLMCommandRef ref, XPLMCommandPhase phase, void* refcon); }; -} // namespace +} // namespace + +#endif // PPL_COMMAND_H_ diff --git a/src/dataref.cpp b/src/dataref.cpp index 57785d4..d38fb7e 100644 --- a/src/dataref.cpp +++ b/src/dataref.cpp @@ -179,7 +179,7 @@ DataRef::operator double() const template <> DataRef >::operator std::vector() const { - cache_.resize(XPLMGetDatavf(m_data_ref, NULL, 0, 0)); + cache_.resize(XPLMGetDatavf(m_data_ref, nullptr, 0, 0)); XPLMGetDatavf(m_data_ref, &cache_[0], 0, cache_.size()); return cache_; } @@ -187,7 +187,7 @@ DataRef >::operator std::vector() const template <> DataRef >::operator std::vector() const { - cache_.resize(XPLMGetDatavi(m_data_ref, NULL, 0, 0)); + cache_.resize(XPLMGetDatavi(m_data_ref, nullptr, 0, 0)); XPLMGetDatavi(m_data_ref, &cache_[0], 0, cache_.size()); return cache_; } @@ -195,7 +195,7 @@ DataRef >::operator std::vector() const template <> DataRef::operator std::string() const { - cache_.resize(XPLMGetDatab(m_data_ref, NULL, 0, 0)); + cache_.resize(XPLMGetDatab(m_data_ref, nullptr, 0, 0)); XPLMGetDatab(m_data_ref, &cache_[0], 0, cache_.size()); return std::string(cache_.data(), strnlen(cache_.data(), cache_.size())); } @@ -273,7 +273,7 @@ dataref_trait >::BasicType DataRef >::operator template<> dataref_trait::BasicType DataRef::operator[](std::size_t index) const { - cache_.resize(XPLMGetDatab(m_data_ref, NULL, 0, 0)); // can't use convert to std::string method here, because we might want the raw data with embedded null bytes. + cache_.resize(XPLMGetDatab(m_data_ref, nullptr, 0, 0)); // can't use convert to std::string method here, because we might want the raw data with embedded null bytes. XPLMGetDatab(m_data_ref, &cache_[0], 0, cache_.size()); return cache_[index]; } @@ -419,7 +419,7 @@ void DataRef::reserve(std::size_t i) template<> void DataRef >::reserve() { - std::size_t i = XPLMGetDatavi(m_data_ref, NULL, 0, 0); + std::size_t i = XPLMGetDatavi(m_data_ref, nullptr, 0, 0); cache_.resize(i); m_history.resize(i); } @@ -427,14 +427,14 @@ void DataRef >::reserve() template<> void DataRef >::reserve() { - std::size_t i = XPLMGetDatavf(m_data_ref, NULL, 0, 0); + std::size_t i = XPLMGetDatavf(m_data_ref, nullptr, 0, 0); cache_.resize(i); m_history.resize(i); } template<> void DataRef::reserve() { - std::size_t i = XPLMGetDatab(m_data_ref, NULL, 0, 0); + std::size_t i = XPLMGetDatab(m_data_ref, nullptr, 0, 0); cache_.resize(i); m_history.resize(i); } diff --git a/src/dataref.h b/src/dataref.h index 69c8974..ace6b4b 100644 --- a/src/dataref.h +++ b/src/dataref.h @@ -279,14 +279,14 @@ DataRef::DataRef(const std::string& identifier, RWType writeability, bool share, bool publish_in_dre): - m_data_ref(0), + m_data_ref(nullptr), m_read_write(writeability), shared_(false), identifier_(identifier) { try { - if (share && XPLMFindDataRef(identifier.c_str()) == 0) + if (share && XPLMFindDataRef(identifier.c_str()) == nullptr) shareDataRef(identifier, publish_in_dre); lookUp(identifier); checkDataType(); @@ -435,7 +435,7 @@ void DataRef::publishInDRE() { XPLMPluginID PluginID = XPLMFindPluginBySignature(DRE_PLUGIN_SINATURE); if (PluginID != XPLM_NO_PLUGIN_ID) - XPLMSendMessageToPlugin(PluginID, DRE_MSG_ADD_DATAREF, (void*)identifier_.c_str()); + XPLMSendMessageToPlugin(PluginID, DRE_MSG_ADD_DATAREF, static_cast(const_cast(identifier_.c_str()))); } @@ -459,7 +459,7 @@ void DataRef::checkWriteabilityIsValid() { if(m_read_write == WriteOnly || m_read_write == ReadWrite) if (!XPLMCanWriteDataRef(m_data_ref)) - throw NotWriteableException("Declared to be writeable, but X-Plane says it is read-only."); + throw NotWriteableException(identifier_+ " declared to be writeable, but X-Plane says it is read-only."); } /////////////////////////////////////////////////////////////////////////////// @@ -468,7 +468,7 @@ void DataRef::checkWriteabilityIsValid() template void DataRef::checkDataType() { - throw IncompatibleTypeException("No type defined."); + throw IncompatibleTypeException(identifier_+" no type defined."); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/fontmgr.cpp b/src/fontmgr.cpp index 66e6e49..5f71d1a 100644 --- a/src/fontmgr.cpp +++ b/src/fontmgr.cpp @@ -35,10 +35,7 @@ #include #include #endif - -#ifndef BUILD_FOR_STANDALONE #include "XPLMGraphics.h" -#endif using namespace PPL; @@ -227,14 +224,8 @@ FontHandle FontMgr::loadFont(const char* inFontPath, const char * inStartMem, co unsigned char* textureData = new unsigned char[info->tex_height * info->tex_width]; // Create the texture number that we'll be tied to -#ifdef BUILD_FOR_STANDALONE - glGenTextures(1, (GLuint*)&info->tex_id); - // Now we bind to it - glBindTexture(GL_TEXTURE_2D, info->tex_id); -#else XPLMGenerateTextureNumbers(&info->tex_id, 1); XPLMBindTexture2d(info->tex_id, 0); -#endif // We have to 0 out the memory or we'll get artifacts when the glyphs are cut memset(textureData, 0, info->tex_height * info->tex_width); @@ -445,11 +436,7 @@ void FontMgr::displayTexture( if(!inFont) return; -#ifdef BUILD_FOR_STANDALONE - glBindTexture(GL_TEXTURE_2D, inFont->tex_id); -#else XPLMBindTexture2d(inFont->tex_id, 0); -#endif glColor3f(1.0, 0.0, 0.0); glBegin(GL_QUADS); glTexCoord2f(0.0, 1.0); glVertex2f(0, 0); @@ -499,11 +486,7 @@ void FontMgr::drawRange( return; float l, b, r, t, scale; -#ifdef BUILD_FOR_STANDALONE - glBindTexture(GL_TEXTURE_2D, inFont->tex_id); -#else XPLMBindTexture2d(inFont->tex_id, 0); -#endif // Determine how much to scale the font to make it right the height scale = (inTop - inBottom) / inFont->line_height; diff --git a/src/logichandler.cpp b/src/logichandler.cpp index aa90572..73085a7 100644 --- a/src/logichandler.cpp +++ b/src/logichandler.cpp @@ -34,7 +34,7 @@ using namespace PPL; -float HandlerCallbackInit(float, float, int, void* inRefCon) +float PPL::HandlerCallbackInit(float, float, int, void* inRefCon) { LogicHandler* handler = static_cast(inRefCon); handler->initializeAtStart(); @@ -44,7 +44,7 @@ float HandlerCallbackInit(float, float, int, void* inRefCon) /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -float HandlerCallbackProcess(float, float, int, void* inRefCon) +float PPL::HandlerCallbackProcess(float, float, int, void* inRefCon) { LogicHandler* handler = static_cast(inRefCon); if (!handler->isSuspended()) diff --git a/src/logichandler.h b/src/logichandler.h index 3e45964..ff9cfd7 100644 --- a/src/logichandler.h +++ b/src/logichandler.h @@ -124,6 +124,9 @@ class LogicHandler { }; +float HandlerCallbackInit(float, float, int, void* inRefCon); +float HandlerCallbackProcess(float, float, int, void* inRefCon); + } #endif diff --git a/src/menuitem.cpp b/src/menuitem.cpp index 62d7357..027ce2a 100644 --- a/src/menuitem.cpp +++ b/src/menuitem.cpp @@ -33,7 +33,7 @@ using namespace PPL; MenuItem::MenuItem(const std::string& title) { - m_item_id = XPLMAppendMenuItem(XPLMFindPluginsMenu(), title.c_str(), NULL, 1); + m_item_id = XPLMAppendMenuItem(XPLMFindPluginsMenu(), title.c_str(), nullptr, 1); m_menu_id = XPLMCreateMenu(title.c_str(), XPLMFindPluginsMenu(), m_item_id, menuHandler, this); } diff --git a/src/messagewindow.cpp b/src/messagewindow.cpp index 6176c98..41bcad8 100644 --- a/src/messagewindow.cpp +++ b/src/messagewindow.cpp @@ -201,7 +201,7 @@ int MessageWindow::processMessages(XPWidgetMessage inMessage, intptr_t, intptr_t int MessageWindow::widgetCallback(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t param1, intptr_t param2) { - MessageWindow* widget = reinterpret_cast(XPGetWidgetProperty(inWidget, xpProperty_Object, NULL)); + MessageWindow* widget = reinterpret_cast(XPGetWidgetProperty(inWidget, xpProperty_Object, nullptr)); if (widget) { return widget->processMessages(inMessage, param1, param2); @@ -250,7 +250,7 @@ void MessageWindow::createSurroundingBox() 1, m_title.c_str(), 1, - 0, + nullptr, xpWidgetClass_MainWindow); XPSetWidgetProperty(m_box_widget, xpProperty_MainWindowHasCloseBoxes, 1); XPSetWidgetProperty(m_box_widget, xpProperty_MainWindowType, xpMainWindowStyle_MainWindow); diff --git a/src/messagewindow.h b/src/messagewindow.h index d9b1a4a..8fd1df0 100644 --- a/src/messagewindow.h +++ b/src/messagewindow.h @@ -122,7 +122,7 @@ class MessageWindow * @param param1 * @param param2 */ - int processMessages(XPWidgetMessage, intptr_t, intptr_t); + int processMessages(XPWidgetMessage message, intptr_t param1, intptr_t param2); /** * static widget callback to register in X-Plane's widget logic diff --git a/src/onscreendisplay.cpp b/src/onscreendisplay.cpp index 412d308..7d33762 100644 --- a/src/onscreendisplay.cpp +++ b/src/onscreendisplay.cpp @@ -35,6 +35,7 @@ using namespace PPL; OnScreenDisplay::OnScreenDisplay(int width, int height, const std::string& title): screen_w_("sim/graphics/view/window_width"), screen_h_("sim/graphics/view/window_height"), + vr_enabled_("sim/graphics/VR/enabled"), title_(title) { left_ = (screen_w_ - width)/2; @@ -49,11 +50,16 @@ OnScreenDisplay::OnScreenDisplay(int width, int height, const std::string& title 1, title_.c_str(), 1, - 0, + nullptr, xpWidgetClass_MainWindow); XPSetWidgetProperty(widget_id_, xpProperty_MainWindowType, xpMainWindowStyle_Translucent); XPSetWidgetProperty(widget_id_, xpProperty_Object, reinterpret_cast(this)); XPAddWidgetCallback(widget_id_, widgetCallback); + window_id_ = XPGetWidgetUnderlyingWindow(widget_id_); + if (vr_enabled_ == 1) + { + XPLMSetWindowPositioningMode(window_id_, xplm_WindowVR, -1); + } } /////////////////////////////////////////////////////////////////////////////// @@ -83,7 +89,7 @@ int OnScreenDisplay::processMessages(XPWidgetMessage inMessage, intptr_t, intptr int OnScreenDisplay::widgetCallback(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t param1, intptr_t param2) { - OnScreenDisplay* display = reinterpret_cast(XPGetWidgetProperty(inWidget, xpProperty_Object, 0)); + OnScreenDisplay* display = reinterpret_cast(XPGetWidgetProperty(inWidget, xpProperty_Object, nullptr)); if (display) { return display->processMessages(inMessage, param1, param2); diff --git a/src/onscreendisplay.h b/src/onscreendisplay.h index 5b44280..ad28783 100644 --- a/src/onscreendisplay.h +++ b/src/onscreendisplay.h @@ -29,6 +29,7 @@ #define ONSCREENDISPLAY_H #include "XPWidgetDefs.h" +#include "XPLMDisplay.h" #include "dataref.h" namespace PPL { @@ -47,9 +48,10 @@ class OnScreenDisplay { static int widgetCallback(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t param1, intptr_t param2); private: - DataRef screen_w_; - DataRef screen_h_; + DataRef screen_w_, screen_h_; + DataRef vr_enabled_; XPWidgetID widget_id_; + XPLMWindowID window_id_; int top_, left_, bottom_, right_; std::string title_; }; diff --git a/src/overlaygauge.cpp b/src/overlaygauge.cpp index 968de14..24c74ab 100644 --- a/src/overlaygauge.cpp +++ b/src/overlaygauge.cpp @@ -103,7 +103,7 @@ OverlayGauge::OverlayGauge(int left2d, int top2d, int width2d, int height2d, int generateTex((int*)(&gauge_texture_), 1); bindTex(gauge_texture_, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_3d_, height_3d_, 0, - GL_RGBA, GL_UNSIGNED_BYTE, 0); + GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -179,7 +179,7 @@ void OverlayGauge::setVisible(bool b) { if (!b) { - XPLMTakeKeyboardFocus(0); + XPLMTakeKeyboardFocus(nullptr); window_has_keyboard_focus_ = false; } visible_2d_ = b; @@ -198,6 +198,7 @@ bool OverlayGauge::isVisible() const void OverlayGauge::frame() { + update(); visible_2d_ = XPLMGetWindowIsVisible(window2d_id_); if (!wantVRifAvailable()) return; @@ -249,7 +250,7 @@ void OverlayGauge::toggleKeyboardFocus() { if (window_has_keyboard_focus_) { - XPLMTakeKeyboardFocus(0); + XPLMTakeKeyboardFocus(nullptr); window_has_keyboard_focus_ = false; } else @@ -269,6 +270,10 @@ bool OverlayGauge::wantVRifAvailable() const return true; } +void OverlayGauge::update() +{ +} + void OverlayGauge::draw2dWindowCallback(XPLMWindowID) { if (visible_2d_) @@ -319,7 +324,7 @@ void OverlayGauge::draw2dWindowCallback(XPLMWindowID) { static float color[] = { 1.f, 0.5f, 0.f}; static char str[] = "K"; - XPLMDrawString(color, left + 20, top - 25, str, 0, xplmFont_Proportional); + XPLMDrawString(color, left + 20, top - 25, str, nullptr, xplmFont_Proportional); } } } @@ -406,26 +411,26 @@ int OverlayGauge::handle2dClickCallback(XPLMWindowID window_id, int x, int y, XP /// Test for the mouse in the window if (vr_enabled_ == 0) { - if (coordInRect(x, y, Left, Top, Left+40, Top-40)) - { - XPLMTakeKeyboardFocus(0); - window_has_keyboard_focus_ = false; - setVisible(false); - } - else if (coordInRect(x, y, Right-40, Top, Right, Top-40)) - { - XPLMSetWindowPositioningMode(window2d_id_, xplm_WindowPopOut, -1); - } - else if (!handleNonDragClick(x_rel, y_rel, false)) - { - dX = x - Left; - dY = y - Top; - window_is_dragging_ = true; - } + if (coordInRect(x, y, Left, Top, Left+40, Top-40)) + { + XPLMTakeKeyboardFocus(nullptr); + window_has_keyboard_focus_ = false; + setVisible(false); + } + else if (coordInRect(x, y, Right-40, Top, Right, Top-40)) + { + XPLMSetWindowPositioningMode(window2d_id_, xplm_WindowPopOut, -1); + } + else if (!handleNonDragClick(x_rel, y_rel, false)) + { + dX = x - Left; + dY = y - Top; + window_is_dragging_ = true; + } } else { - return handleNonDragClick(x_rel, y_rel, false); + handleNonDragClick(x_rel, y_rel, false); } break; case xplm_MouseDrag: diff --git a/src/overlaygauge.h b/src/overlaygauge.h index e24816c..76e4a09 100644 --- a/src/overlaygauge.h +++ b/src/overlaygauge.h @@ -88,6 +88,7 @@ class OverlayGauge virtual int handleMouseWheel(int x, int y, int wheel, int clicks); virtual float instrumentBrightness() const; virtual bool wantVRifAvailable() const; + virtual void update(); static int draw3dCallback(XPLMDrawingPhase phase, int is_before, void* refcon); diff --git a/src/owneddata.cpp b/src/owneddata.cpp index 65d41e5..bac0d33 100644 --- a/src/owneddata.cpp +++ b/src/owneddata.cpp @@ -36,10 +36,10 @@ template <> void OwnedData::registerRead() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Int, 0, - readFunc, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, this, NULL ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + readFunc, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, this, nullptr); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -49,10 +49,10 @@ template <> void OwnedData::registerRead() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Float, 0, - NULL, NULL, readFunc, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, this, NULL ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, readFunc, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, this, nullptr); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -62,10 +62,10 @@ template <> void OwnedData::registerRead() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Double, 0, - NULL, NULL, NULL, NULL, readFunc, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, this, NULL); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, readFunc, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, this, nullptr); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -75,10 +75,10 @@ template <> void OwnedData::registerRead() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Data, 0, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, readFuncStr, NULL, this, NULL ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, readFuncStr, nullptr, this, nullptr); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -88,10 +88,10 @@ template <> void OwnedData >::registerRead() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_FloatArray, 0, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - readFuncVF, NULL, NULL, NULL, this, NULL ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + readFuncVF, nullptr, nullptr, nullptr, this, nullptr); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -102,10 +102,10 @@ template <> void OwnedData::registerWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Int, 1, - NULL, writeFunc, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, writeFunc, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -115,10 +115,10 @@ template <> void OwnedData::registerWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Float, 1, - NULL, NULL, NULL, writeFunc, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, writeFunc, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -128,10 +128,10 @@ template <> void OwnedData::registerWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Double, 1, - NULL, NULL, NULL, NULL, NULL, writeFunc, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, nullptr, writeFunc, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -141,10 +141,10 @@ template <> void OwnedData::registerWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Data, 1, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, writeFuncStr, NULL, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, writeFuncStr, nullptr, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -154,10 +154,10 @@ template <> void OwnedData >::registerWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_FloatArray, 1, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, writeFuncVF, NULL, NULL, NULL, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, writeFuncVF, nullptr, nullptr, nullptr, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -168,10 +168,10 @@ template <> void OwnedData::registerReadWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Int, 1, - readFunc, writeFunc, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, this, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + readFunc, writeFunc, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, this, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -181,10 +181,10 @@ template <> void OwnedData::registerReadWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Float, 1, - NULL, NULL, readFunc, writeFunc, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, this, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, readFunc, writeFunc, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, this, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -194,10 +194,10 @@ template <> void OwnedData::registerReadWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Double, 1, - NULL, NULL, NULL, NULL, readFunc, writeFunc, NULL, NULL, - NULL, NULL, NULL, NULL, this, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, readFunc, writeFunc, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, this, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -207,10 +207,10 @@ template <> void OwnedData::registerReadWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_Data, 1, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, readFuncStr, writeFuncStr, this, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, readFuncStr, writeFuncStr, this, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -220,10 +220,10 @@ template <> void OwnedData >::registerReadWrite() { m_data_ref = XPLMRegisterDataAccessor( m_data_ref_identifier.c_str(), xplmType_FloatArray, 1, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - readFuncVF, writeFuncVF, NULL, NULL, this, this ); - if (m_data_ref == 0) - throw DataRefNotPublishedException(""); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + readFuncVF, writeFuncVF, nullptr, nullptr, this, this); + if (m_data_ref == nullptr) + throw DataRefNotPublishedException(m_data_ref_identifier); } /////////////////////////////////////////////////////////////////////////////// @@ -234,7 +234,7 @@ int PPL::readFuncStr(void* inRefCon, void* outValue, int inOffset, int inMaxLeng { OwnedData* p_owned_data = static_cast*>(inRefCon); std::size_t length = p_owned_data->value().length(); - if (outValue == NULL) + if (outValue == nullptr) return length; std::size_t maxlen = std::min(std::size_t(inMaxLength), length); strncpy(static_cast(outValue), p_owned_data->value().substr(inOffset, maxlen).c_str(), maxlen); @@ -258,7 +258,7 @@ int PPL::readFuncVF(void* inRefCon, float* outValues, int inOffset, int inMaxLen { std::size_t max_length = static_cast(inMaxLength); OwnedData >* p_owned_data = static_cast >*>(inRefCon); - if (outValues == NULL) + if (outValues == nullptr) return p_owned_data->value().size(); int end = (p_owned_data->value().size() < max_length) ? p_owned_data->value().size() : max_length; memcpy(outValues, &p_owned_data->value()[inOffset], sizeof(float)*end); diff --git a/src/owneddata.h b/src/owneddata.h index 80ce849..5483ffa 100644 --- a/src/owneddata.h +++ b/src/owneddata.h @@ -84,7 +84,7 @@ class OwnedData{ bool publish_in_dre = false, DataCallback_f callback = 0): m_data_ref_identifier(identifier), - m_data_ref(0), + m_data_ref(nullptr), m_value(T()), m_callback(callback) { diff --git a/src/pluginpath.cpp b/src/pluginpath.cpp index 69e748f..0e40d1d 100644 --- a/src/pluginpath.cpp +++ b/src/pluginpath.cpp @@ -42,37 +42,25 @@ std::string PluginPath::plugin_directory = ""; std::string PluginPath::prependXPlanePath(const std::string& file) { -#ifdef BUILD_FOR_STANDALONE - return file; -#else char path[512]; XPLMGetSystemPath(path); std::string absolute_path(path); absolute_path.append(file); return absolute_path; -#endif } std::string PluginPath::prependPluginPath(const std::string& file) { -#ifdef BUILD_FOR_STANDALONE - return file; -#else std::string path = "/Resources/plugins/"; path.append(plugin_directory).append("/").append(file); return prependXPlanePath(path); -#endif } std::string PluginPath::prependPluginResourcesPath(const std::string& file) { std::string res_path("Resources/"); res_path.append(file); -#ifdef BUILD_FOR_STANDALONE - return res_path; -#else return prependPluginPath(res_path); -#endif } /////////////////////////////////////////////////////////////////////////////// @@ -80,9 +68,6 @@ std::string PluginPath::prependPluginResourcesPath(const std::string& file) std::string PluginPath::prependPlanePath(const std::string& file) { -#ifdef BUILD_FOR_STANDALONE - return file; -#else char name[512]; char path[512]; XPLMGetNthAircraftModel(0, name, path); @@ -91,7 +76,6 @@ std::string PluginPath::prependPlanePath(const std::string& file) absolute_path = absolute_path.substr(0, pos); absolute_path.append(file); return absolute_path; -#endif } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/pluginpath.h b/src/pluginpath.h index a53ddac..f9ed96f 100644 --- a/src/pluginpath.h +++ b/src/pluginpath.h @@ -60,7 +60,7 @@ class PluginPath * @return the absolute path * @exception PathSetupError is thrown if path conversion fails */ - static std::string prependPluginPath(const std::string&); + static std::string prependPluginPath(const std::string& path); /** * prepend the absolute path to the Resources subdirectory of the @@ -69,7 +69,7 @@ class PluginPath * @return the absolute path * @exception PathSetupError is thrown if path conversion fails */ - static std::string prependPluginResourcesPath(const std::string&); + static std::string prependPluginResourcesPath(const std::string& path); /** * prepend the absolute path to the directory of the currently loaded @@ -78,7 +78,7 @@ class PluginPath * @return the absolute path * @exception PathSetupError is thrown if path conversion fails */ - static std::string prependPlanePath(const std::string&); + static std::string prependPlanePath(const std::string& path); /** * set the name of the directory where fat plugin resides diff --git a/src/texture.cpp b/src/texture.cpp index c9a7cca..39d2291 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -29,10 +29,8 @@ #include #include #include "texture.h" -#ifndef BUILD_FOR_STANDALONE #include "XPLMUtilities.h" #include "XPLMGraphics.h" -#endif #if IBM #include @@ -83,7 +81,7 @@ void SwapEndian(int32_t *){} #endif -Texture::Texture(const std::string& file_name) +Texture::Texture(const std::string& file_name, bool build_mipmaps) { if (file_name.rfind(".bmp") != std::string::npos) { @@ -143,21 +141,12 @@ Texture::Texture(const std::string& file_name) swapRedBlue(); - -#ifdef BUILD_FOR_STANDALONE - glGenTextures(1, (GLuint*)&m_id); - glBindTexture(GL_TEXTURE_2D, m_id); -#else /// Do the opengl stuff using XPLM functions for a friendly Xplane existence. XPLMGenerateTextureNumbers(&m_id, 1); XPLMBindTexture2d(m_id, 0); -#endif -#if APL - glGenerateMipmap(GL_TEXTURE_2D); -#else - gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_imagedata.Width, m_imagedata.Height, GL_RGB, GL_UNSIGNED_BYTE, &m_imagedata.pData[0]); -#endif + GLuint type = GL_RGB; // 24bit bmp only supported for now + glTexImage2D(GL_TEXTURE_2D, 0, type, m_imagedata.Width, m_imagedata.Height, 0, type, GL_UNSIGNED_BYTE, &m_imagedata.pData[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); @@ -175,12 +164,12 @@ Texture::Texture(const std::string& file_name) FILE *file = fopen(file_name.c_str(), "rb"); // Open The TGA File - if( file==NULL || // Does File Even Exist? + if( file==nullptr || // Does File Even Exist? fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || // Are There 12 Bytes To Read? memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 || // Does The Header Match What We Want? fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next 6 Header Bytes { - if (file == NULL) // Did The File Even Exist? *Added Jim Strong* + if (file == nullptr) // Did The File Even Exist? *Added Jim Strong* throw std::runtime_error("File could not be opened: "+file_name); else // Otherwise { @@ -227,14 +216,10 @@ Texture::Texture(const std::string& file_name) { type=GL_RGB; // If So Set The 'type' To GL_RGB } -#ifdef BUILD_FOR_STANDALONE - glGenTextures(1, (GLuint*)&m_id); - glBindTexture(GL_TEXTURE_2D, m_id); -#else /// Do the opengl stuff using XPLM functions for a friendly Xplane existence. XPLMGenerateTextureNumbers(&m_id, 1); XPLMBindTexture2d(m_id, 0); -#endif + glTexImage2D(GL_TEXTURE_2D, 0, type, m_imagedata.Width, m_imagedata.Height, 0, type, GL_UNSIGNED_BYTE, &m_imagedata.pData[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); @@ -244,6 +229,14 @@ Texture::Texture(const std::string& file_name) { throw std::runtime_error("The texture file is neither a BMP nor a TGA. Other fileformats are not supported."); } + if (build_mipmaps) + { +#if APL + glGenerateMipmap(GL_TEXTURE_2D); +#else + gluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, m_imagedata.Width, m_imagedata.Height, GL_ALPHA, GL_UNSIGNED_BYTE, &m_imagedata.pData[0]); +#endif + } } Texture::~Texture() diff --git a/src/texture.h b/src/texture.h index 3ac8a69..b1cbdaa 100644 --- a/src/texture.h +++ b/src/texture.h @@ -76,7 +76,7 @@ class Texture #pragma pack(pop, ident) - Texture(const std::string& file_name); + Texture(const std::string& file_name, bool build_mipmaps = false); ~Texture(); Texture(const Texture&) = delete; Texture& operator=(const Texture&) = delete; diff --git a/src/vertexbuffer.cpp b/src/vertexbuffer.cpp index a544eaa..7d89ba1 100644 --- a/src/vertexbuffer.cpp +++ b/src/vertexbuffer.cpp @@ -56,7 +56,7 @@ std::size_t VertexBuffer::beginSpecifyVerts(std::size_t num_vertices, volatile f case STATIC: usage = GL_STATIC_DRAW; break; case STREAMING: usage = GL_STREAM_DRAW; break; } - glBufferData(GL_ARRAY_BUFFER, num_vertices * stride_floats_ * sizeof(GLfloat), NULL, usage); + glBufferData(GL_ARRAY_BUFFER, num_vertices * stride_floats_ * sizeof(GLfloat), nullptr, usage); GLfloat* bp = static_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY)); *out_verts = bp; @@ -66,7 +66,7 @@ std::size_t VertexBuffer::beginSpecifyVerts(std::size_t num_vertices, volatile f if(num_nrm_) *out_normals = bp; else - *out_normals = NULL; + *out_normals = nullptr; } bp += num_nrm_; if(out_texes) @@ -74,7 +74,7 @@ std::size_t VertexBuffer::beginSpecifyVerts(std::size_t num_vertices, volatile f if(num_tx_) *out_texes = bp; else - *out_texes = NULL; + *out_texes = nullptr; } bp += num_tx_; if(out_texes2) @@ -82,7 +82,7 @@ std::size_t VertexBuffer::beginSpecifyVerts(std::size_t num_vertices, volatile f if(num_tx2_) *out_texes2 = bp; else - *out_texes2 = NULL; + *out_texes2 = nullptr; } bp += num_tx2_; if(out_colors) @@ -90,7 +90,7 @@ std::size_t VertexBuffer::beginSpecifyVerts(std::size_t num_vertices, volatile f if(num_col_) *out_colors = bp; else - *out_colors = NULL; + *out_colors = nullptr; } return stride_floats_; } @@ -111,9 +111,9 @@ void VertexBuffer::setupForDraw() glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, vbo_); - float* p = NULL; + float* p = nullptr; - int stride = stride_floats_*sizeof(GLfloat); + std::size_t stride = stride_floats_*sizeof(GLfloat); glVertexPointer(num_vrt_, GL_FLOAT, stride, p); p += num_vrt_;