Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8fee290
always eat the mouse click in the 2d window
Mar 27, 2018
98ab208
child can override update for the per-frame callback. This is the better
Apr 2, 2018
423a228
Merge branch 'v2_dev' of github.com:PhilippMuenzel/PPL into v2_dev
Apr 2, 2018
7937133
move the OSD to the VR headset if we are in VR right now.
Apr 16, 2018
8f61eb7
oops I killed bmp texture loading in v2. Fixed.
May 24, 2018
a354316
experimental CMake build on Mac.
May 25, 2018
04fb1e6
never used that, it can go away
May 25, 2018
2b52eb9
restored optional mipmap building
May 26, 2018
059afc3
more progress building PPL with CMake.
May 29, 2018
b252acb
build with CMake on Windows
PhilippMuenzel May 29, 2018
25f4035
added debug and release configurations to CMake
May 29, 2018
e9988b1
bring in XPLM 3.0.1 SDK as a git submodule
May 30, 2018
5e8862a
fixed debug and release settings for Visual Studio
PhilippMuenzel May 30, 2018
45d388b
now that we pull in the SDK via submodule, we should actually use it...
Aug 21, 2018
37867c2
updated glew, openAL
Sep 17, 2018
6155497
updated simpleini
Sep 18, 2018
cb85bbd
compile warning free with clang 6.
Dec 4, 2018
d2032eb
Merge branch 'v2_dev' of https://github.com/PhilippMuenzel/PPL into v…
Dec 4, 2018
47f7580
git-ignore compilation products
Dec 4, 2018
0a9d129
added dataref names to lookup exceptions
PhilippMuenzel Oct 25, 2022
1d4e5df
updated to XPLM 4.0.1
Oct 27, 2023
676654c
updated to Freetype 2.13.2
Oct 27, 2023
793d153
updared CMake for arm/x86 build for X-Plane 12 so you can make native…
Oct 27, 2023
d453028
Merge branch 'master' into command
judemille Nov 9, 2023
b22d61b
Commands API updated and robustified.
judemille Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.directory
Makefile
objects/
ppl.pro.user
.directory
Makefile
objects/
ppl.pro.user
lib/libppl.a
lib/libppld.a
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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

100 changes: 100 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "$<$<CONFIG:DEBUG>:${PLATFORM_DEBUG_OPTIONS}>")
target_compile_options(PPL PUBLIC "$<$<CONFIG:RELEASE>:${PLATFORM_RELEASE_OPTIONS}>")
target_compile_definitions(PPL PRIVATE ${DEFINITIONS})
1 change: 1 addition & 0 deletions include/SDK
Submodule SDK added at 7329d3
2 changes: 1 addition & 1 deletion include/freetype2
Submodule freetype2 updated from f9b187 to 920c55
2 changes: 1 addition & 1 deletion include/glew
Submodule glew updated 262 files
2 changes: 1 addition & 1 deletion include/openal-soft
Submodule openal-soft updated 150 files
2 changes: 1 addition & 1 deletion include/simpleini
Submodule simpleini updated 0 files
11 changes: 3 additions & 8 deletions ppl.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
167 changes: 120 additions & 47 deletions src/command.cpp
Original file line number Diff line number Diff line change
@@ -1,78 +1,151 @@
#include "command.h"

/* Copyright (c) 2018, Jack Deeth github@jackdeeth.org.uk
// Copyright (c) 2023, Jack Deeth <github@jackdeeth.org.uk>, Julia DeMille <me@jdemille.com>
// 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 <string>

using namespace std::string_literals;

PPL::Command::Command(XPLMCommandRef ref,
std::function<Outcome(XPLMCommandRef, Phase)> 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<Outcome(XPLMCommandRef, Phase)> callback,
bool run_before)
: Command(XPLMFindCommand(cmd_to_replace.c_str()), callback, run_before) {}
std::optional<Command> 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<Outcome(XPLMCommandRef, Phase)> 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 <typename T>
requires impl_CommandHandler<T>
RegisteredCommandHandler<T> Command::handle(bool before_xp, T handler)
{
RegisteredCommandHandler<T>(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<Command *>(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 <typename T>
requires impl_CommandHandler<T>
RegisteredCommandHandler<T>::RegisteredCommandHandler(XPLMCommandRef cmd_ref, bool before_xp, T handler_)
: cmd_ref(cmd_ref)
, before_xp(before_xp)
, handler(handler_)
{
XPLMRegisterCommandHandler(
cmd_ref,
RegisteredCommandHandler<T>::handle,
before_xp,
&handler);
}

template <typename T>
requires impl_CommandHandler<T>
int RegisteredCommandHandler<T>::handle(XPLMCommandRef _ref, XPLMCommandPhase phase, void* refcon)
{
T* handler = static_cast<T*>(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 <typename T>
requires impl_CommandHandler<T>
RegisteredCommandHandler<T>::~RegisteredCommandHandler<T>()
{
XPLMUnregisterCommandHandler(
cmd_ref,
RegisteredCommandHandler<T>::handle,
before_xp,
&handler);
}
}
Loading