long -> intptr_t for casts. WIP: mingw cross-compilation for Windows (see #162)
This commit is contained in:
parent
2f4ebf3420
commit
1f002e820c
15 changed files with 188 additions and 102 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -16,6 +16,7 @@ CMakeFiles/
|
||||||
Makefile
|
Makefile
|
||||||
*.zip
|
*.zip
|
||||||
__lib/
|
__lib/
|
||||||
|
__lib_windows/
|
||||||
_oldscripts/
|
_oldscripts/
|
||||||
assets/
|
assets/
|
||||||
cellular_automata_fire/
|
cellular_automata_fire/
|
||||||
|
|
|
||||||
166
CMakeLists.txt
166
CMakeLists.txt
|
|
@ -8,14 +8,33 @@ project(McRogueFace)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
# Detect cross-compilation for Windows (MinGW)
|
||||||
|
if(CMAKE_CROSSCOMPILING AND WIN32)
|
||||||
|
set(MCRF_CROSS_WINDOWS TRUE)
|
||||||
|
message(STATUS "Cross-compiling for Windows using MinGW")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Add include directories
|
# Add include directories
|
||||||
#include_directories(${CMAKE_SOURCE_DIR}/deps_linux)
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps)
|
include_directories(${CMAKE_SOURCE_DIR}/deps)
|
||||||
#include_directories(${CMAKE_SOURCE_DIR}/deps_linux/Python-3.11.1)
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/libtcod)
|
include_directories(${CMAKE_SOURCE_DIR}/deps/libtcod)
|
||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython)
|
# Python includes: use different paths for Windows vs Linux
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/Python)
|
if(MCRF_CROSS_WINDOWS)
|
||||||
|
# Windows cross-compilation: use cpython headers with PC/pyconfig.h
|
||||||
|
# Problem: Python.h uses #include "pyconfig.h" which finds Include/pyconfig.h (Linux) first
|
||||||
|
# Solution: Use -include to force Windows pyconfig.h to be included first
|
||||||
|
# This defines MS_WINDOWS before Python.h is processed, ensuring correct struct layouts
|
||||||
|
add_compile_options(-include ${CMAKE_SOURCE_DIR}/deps/cpython/PC/pyconfig.h)
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython/Include)
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython/PC) # For other Windows-specific headers
|
||||||
|
# Also include SFML and libtcod Windows headers
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/__lib_windows/sfml/include)
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/include)
|
||||||
|
else()
|
||||||
|
# Native builds (Linux/Windows): use existing Python setup
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython)
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/deps/Python)
|
||||||
|
endif()
|
||||||
|
|
||||||
# ImGui and ImGui-SFML include directories
|
# ImGui and ImGui-SFML include directories
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/modules/imgui)
|
include_directories(${CMAKE_SOURCE_DIR}/modules/imgui)
|
||||||
|
|
@ -37,35 +56,71 @@ file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||||
list(APPEND SOURCES ${IMGUI_SOURCES})
|
list(APPEND SOURCES ${IMGUI_SOURCES})
|
||||||
|
|
||||||
# Find OpenGL (required by ImGui-SFML)
|
# Find OpenGL (required by ImGui-SFML)
|
||||||
find_package(OpenGL REQUIRED)
|
if(MCRF_CROSS_WINDOWS)
|
||||||
|
# For cross-compilation, OpenGL is provided by MinGW
|
||||||
# Create a list of libraries to link against
|
set(OPENGL_LIBRARIES opengl32)
|
||||||
set(LINK_LIBS
|
|
||||||
sfml-graphics
|
|
||||||
sfml-window
|
|
||||||
sfml-system
|
|
||||||
sfml-audio
|
|
||||||
tcod
|
|
||||||
OpenGL::GL)
|
|
||||||
|
|
||||||
# On Windows, add any additional libs and include directories
|
|
||||||
if(WIN32)
|
|
||||||
# Windows-specific Python library name (no dots)
|
|
||||||
list(APPEND LINK_LIBS python314)
|
|
||||||
# Add the necessary Windows-specific libraries and include directories
|
|
||||||
# include_directories(path_to_additional_includes)
|
|
||||||
# link_directories(path_to_additional_libs)
|
|
||||||
# list(APPEND LINK_LIBS additional_windows_libs)
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/windows)
|
|
||||||
else()
|
else()
|
||||||
# Unix/Linux specific libraries
|
find_package(OpenGL REQUIRED)
|
||||||
list(APPEND LINK_LIBS python3.14 m dl util pthread)
|
set(OPENGL_LIBRARIES OpenGL::GL)
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/linux)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Add the directory where the linker should look for the libraries
|
# Create a list of libraries to link against
|
||||||
#link_directories(${CMAKE_SOURCE_DIR}/deps_linux)
|
if(MCRF_CROSS_WINDOWS)
|
||||||
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
# MinGW cross-compilation: use full library names
|
||||||
|
set(LINK_LIBS
|
||||||
|
sfml-graphics
|
||||||
|
sfml-window
|
||||||
|
sfml-system
|
||||||
|
sfml-audio
|
||||||
|
libtcod
|
||||||
|
python314
|
||||||
|
${OPENGL_LIBRARIES})
|
||||||
|
|
||||||
|
# Add Windows system libraries needed by SFML and MinGW
|
||||||
|
list(APPEND LINK_LIBS
|
||||||
|
winmm # Windows multimedia (for audio)
|
||||||
|
gdi32 # Graphics Device Interface
|
||||||
|
ws2_32 # Winsock (networking, used by some deps)
|
||||||
|
ole32 # OLE support
|
||||||
|
oleaut32 # OLE automation
|
||||||
|
uuid # UUID library
|
||||||
|
comdlg32 # Common dialogs
|
||||||
|
imm32 # Input Method Manager
|
||||||
|
version # Version info
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/windows)
|
||||||
|
|
||||||
|
# Link directories for cross-compiled Windows libs
|
||||||
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows/sfml/lib)
|
||||||
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/lib)
|
||||||
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows)
|
||||||
|
elseif(WIN32)
|
||||||
|
# Native Windows build (MSVC)
|
||||||
|
set(LINK_LIBS
|
||||||
|
sfml-graphics
|
||||||
|
sfml-window
|
||||||
|
sfml-system
|
||||||
|
sfml-audio
|
||||||
|
tcod
|
||||||
|
python314
|
||||||
|
${OPENGL_LIBRARIES})
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/windows)
|
||||||
|
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
||||||
|
else()
|
||||||
|
# Unix/Linux build
|
||||||
|
set(LINK_LIBS
|
||||||
|
sfml-graphics
|
||||||
|
sfml-window
|
||||||
|
sfml-system
|
||||||
|
sfml-audio
|
||||||
|
tcod
|
||||||
|
python3.14
|
||||||
|
m dl util pthread
|
||||||
|
${OPENGL_LIBRARIES})
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/linux)
|
||||||
|
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Define the executable target before linking libraries
|
# Define the executable target before linking libraries
|
||||||
add_executable(mcrogueface ${SOURCES})
|
add_executable(mcrogueface ${SOURCES})
|
||||||
|
|
@ -73,11 +128,24 @@ add_executable(mcrogueface ${SOURCES})
|
||||||
# Define NO_SDL for libtcod-headless headers (excludes SDL-dependent code)
|
# Define NO_SDL for libtcod-headless headers (excludes SDL-dependent code)
|
||||||
target_compile_definitions(mcrogueface PRIVATE NO_SDL)
|
target_compile_definitions(mcrogueface PRIVATE NO_SDL)
|
||||||
|
|
||||||
|
# On Windows, define Py_ENABLE_SHARED for proper Python DLL imports
|
||||||
|
# Py_PYCONFIG_H prevents Include/pyconfig.h (Linux config) from being included
|
||||||
|
# (PC/pyconfig.h already defines HAVE_DECLSPEC_DLL and MS_WINDOWS)
|
||||||
|
if(WIN32 OR MCRF_CROSS_WINDOWS)
|
||||||
|
target_compile_definitions(mcrogueface PRIVATE Py_ENABLE_SHARED Py_PYCONFIG_H)
|
||||||
|
endif()
|
||||||
|
|
||||||
# On Windows, set subsystem to WINDOWS to hide console
|
# On Windows, set subsystem to WINDOWS to hide console
|
||||||
if(WIN32)
|
if(WIN32 AND NOT MCRF_CROSS_WINDOWS)
|
||||||
|
# MSVC-specific flags
|
||||||
set_target_properties(mcrogueface PROPERTIES
|
set_target_properties(mcrogueface PROPERTIES
|
||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE TRUE
|
||||||
LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
|
LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
|
||||||
|
elseif(MCRF_CROSS_WINDOWS)
|
||||||
|
# MinGW cross-compilation: use -mwindows to hide console
|
||||||
|
set_target_properties(mcrogueface PROPERTIES
|
||||||
|
WIN32_EXECUTABLE TRUE
|
||||||
|
LINK_FLAGS "-mwindows")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Now the linker will find the libraries in the specified directory
|
# Now the linker will find the libraries in the specified directory
|
||||||
|
|
@ -99,20 +167,36 @@ add_custom_command(TARGET mcrogueface POST_BUILD
|
||||||
${CMAKE_SOURCE_DIR}/__lib $<TARGET_FILE_DIR:mcrogueface>/lib)
|
${CMAKE_SOURCE_DIR}/__lib $<TARGET_FILE_DIR:mcrogueface>/lib)
|
||||||
|
|
||||||
# On Windows, copy DLLs to executable directory
|
# On Windows, copy DLLs to executable directory
|
||||||
if(WIN32)
|
if(MCRF_CROSS_WINDOWS)
|
||||||
# Copy all DLL files from lib to the executable directory
|
# Cross-compilation: copy DLLs from __lib_windows
|
||||||
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
${CMAKE_SOURCE_DIR}/__lib_windows/sfml/bin $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/bin $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_SOURCE_DIR}/__lib_windows/python314.dll $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_SOURCE_DIR}/__lib_windows/python3.dll $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_SOURCE_DIR}/__lib_windows/vcruntime140.dll $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_SOURCE_DIR}/__lib_windows/vcruntime140_1.dll $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
/usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Copied Windows DLLs to executable directory")
|
||||||
|
|
||||||
|
# Copy Python standard library zip
|
||||||
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_SOURCE_DIR}/__lib_windows/python314.zip $<TARGET_FILE_DIR:mcrogueface>
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Copied Python stdlib")
|
||||||
|
elseif(WIN32)
|
||||||
|
# Native Windows build: copy DLLs from __lib
|
||||||
add_custom_command(TARGET mcrogueface POST_BUILD
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
${CMAKE_SOURCE_DIR}/__lib $<TARGET_FILE_DIR:mcrogueface>
|
${CMAKE_SOURCE_DIR}/__lib $<TARGET_FILE_DIR:mcrogueface>
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "Copied DLLs to executable directory")
|
COMMAND ${CMAKE_COMMAND} -E echo "Copied DLLs to executable directory")
|
||||||
|
|
||||||
# Alternative: Copy specific DLLs if you want more control
|
|
||||||
# file(GLOB DLLS "${CMAKE_SOURCE_DIR}/__lib/*.dll")
|
|
||||||
# foreach(DLL ${DLLS})
|
|
||||||
# add_custom_command(TARGET mcrogueface POST_BUILD
|
|
||||||
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
# ${DLL} $<TARGET_FILE_DIR:mcrogueface>)
|
|
||||||
# endforeach()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# rpath for including shared libraries (Linux/Unix only)
|
# rpath for including shared libraries (Linux/Unix only)
|
||||||
|
|
|
||||||
6
deps/platform/windows/platform.h
vendored
6
deps/platform/windows/platform.h
vendored
|
|
@ -1,12 +1,12 @@
|
||||||
#ifndef __PLATFORM
|
#ifndef __PLATFORM
|
||||||
#define __PLATFORM
|
#define __PLATFORM
|
||||||
#define __PLATFORM_SET_PYTHON_SEARCH_PATHS 0
|
#define __PLATFORM_SET_PYTHON_SEARCH_PATHS 0
|
||||||
#include <Windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
std::wstring executable_path()
|
std::wstring executable_path()
|
||||||
{
|
{
|
||||||
wchar_t buffer[MAX_PATH];
|
wchar_t buffer[MAX_PATH];
|
||||||
GetModuleFileName(NULL, buffer, MAX_PATH);
|
GetModuleFileNameW(NULL, buffer, MAX_PATH); // Use explicit Unicode version
|
||||||
std::wstring exec_path = buffer;
|
std::wstring exec_path = buffer;
|
||||||
size_t path_index = exec_path.find_last_of(L"\\/");
|
size_t path_index = exec_path.find_last_of(L"\\/");
|
||||||
return exec_path.substr(0, path_index);
|
return exec_path.substr(0, path_index);
|
||||||
|
|
@ -15,7 +15,7 @@ std::wstring executable_path()
|
||||||
std::wstring executable_filename()
|
std::wstring executable_filename()
|
||||||
{
|
{
|
||||||
wchar_t buffer[MAX_PATH];
|
wchar_t buffer[MAX_PATH];
|
||||||
GetModuleFileName(NULL, buffer, MAX_PATH);
|
GetModuleFileNameW(NULL, buffer, MAX_PATH); // Use explicit Unicode version
|
||||||
std::wstring exec_path = buffer;
|
std::wstring exec_path = buffer;
|
||||||
return exec_path;
|
return exec_path;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -767,7 +767,7 @@ void AnimationManager::addAnimation(std::shared_ptr<Animation> animation,
|
||||||
}
|
}
|
||||||
return; // Don't add to active animations yet
|
return; // Don't add to active animations yet
|
||||||
|
|
||||||
case AnimationConflictMode::ERROR:
|
case AnimationConflictMode::RAISE_ERROR:
|
||||||
// Raise Python exception
|
// Raise Python exception
|
||||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||||
PyErr_Format(PyExc_RuntimeError,
|
PyErr_Format(PyExc_RuntimeError,
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,10 @@ class UIEntity;
|
||||||
* ConflictMode - How to handle multiple animations on the same property (#120)
|
* ConflictMode - How to handle multiple animations on the same property (#120)
|
||||||
*/
|
*/
|
||||||
enum class AnimationConflictMode {
|
enum class AnimationConflictMode {
|
||||||
REPLACE, // Stop/complete existing animation, start new one (default)
|
REPLACE, // Stop/complete existing animation, start new one (default)
|
||||||
QUEUE, // Queue new animation to run after existing one completes
|
QUEUE, // Queue new animation to run after existing one completes
|
||||||
ERROR // Raise an error if property is already being animated
|
RAISE_ERROR // Raise an error if property is already being animated
|
||||||
|
// Note: Can't use ERROR as it conflicts with Windows macro
|
||||||
};
|
};
|
||||||
|
|
||||||
// Forward declare namespace
|
// Forward declare namespace
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ static bool parseConflictMode(const char* mode_str, AnimationConflictMode& mode)
|
||||||
} else if (strcmp(mode_str, "queue") == 0) {
|
} else if (strcmp(mode_str, "queue") == 0) {
|
||||||
mode = AnimationConflictMode::QUEUE;
|
mode = AnimationConflictMode::QUEUE;
|
||||||
} else if (strcmp(mode_str, "error") == 0) {
|
} else if (strcmp(mode_str, "error") == 0) {
|
||||||
mode = AnimationConflictMode::ERROR;
|
mode = AnimationConflictMode::RAISE_ERROR;
|
||||||
} else {
|
} else {
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"Invalid conflict_mode '%s'. Must be 'replace', 'queue', or 'error'.", mode_str);
|
"Invalid conflict_mode '%s'. Must be 'replace', 'queue', or 'error'.", mode_str);
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ PyObject* PyColor::pynew(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
PyObject* PyColor::get_member(PyObject* obj, void* closure)
|
PyObject* PyColor::get_member(PyObject* obj, void* closure)
|
||||||
{
|
{
|
||||||
PyColorObject* self = (PyColorObject*)obj;
|
PyColorObject* self = (PyColorObject*)obj;
|
||||||
long member = (long)closure;
|
intptr_t member = (intptr_t)closure;
|
||||||
|
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case 0: // r
|
case 0: // r
|
||||||
|
|
@ -192,7 +192,7 @@ PyObject* PyColor::get_member(PyObject* obj, void* closure)
|
||||||
int PyColor::set_member(PyObject* obj, PyObject* value, void* closure)
|
int PyColor::set_member(PyObject* obj, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
PyColorObject* self = (PyColorObject*)obj;
|
PyColorObject* self = (PyColorObject*)obj;
|
||||||
long member = (long)closure;
|
intptr_t member = (intptr_t)closure;
|
||||||
|
|
||||||
if (!PyLong_Check(value)) {
|
if (!PyLong_Check(value)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "Color values must be integers");
|
PyErr_SetString(PyExc_TypeError, "Color values must be integers");
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ PyObject* PyVector::pynew(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||||
PyObject* PyVector::get_member(PyObject* obj, void* closure)
|
PyObject* PyVector::get_member(PyObject* obj, void* closure)
|
||||||
{
|
{
|
||||||
PyVectorObject* self = (PyVectorObject*)obj;
|
PyVectorObject* self = (PyVectorObject*)obj;
|
||||||
if (reinterpret_cast<long>(closure) == 0) {
|
if (reinterpret_cast<intptr_t>(closure) == 0) {
|
||||||
// x
|
// x
|
||||||
return PyFloat_FromDouble(self->data.x);
|
return PyFloat_FromDouble(self->data.x);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -250,7 +250,7 @@ int PyVector::set_member(PyObject* obj, PyObject* value, void* closure)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reinterpret_cast<long>(closure) == 0) {
|
if (reinterpret_cast<intptr_t>(closure) == 0) {
|
||||||
// x
|
// x
|
||||||
self->data.x = val;
|
self->data.x = val;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ void UICaption::onPositionChanged()
|
||||||
|
|
||||||
PyObject* UICaption::get_float_member(PyUICaptionObject* self, void* closure)
|
PyObject* UICaption::get_float_member(PyUICaptionObject* self, void* closure)
|
||||||
{
|
{
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0)
|
if (member_ptr == 0)
|
||||||
return PyFloat_FromDouble(self->data->text.getPosition().x);
|
return PyFloat_FromDouble(self->data->text.getPosition().x);
|
||||||
else if (member_ptr == 1)
|
else if (member_ptr == 1)
|
||||||
|
|
@ -115,7 +115,7 @@ PyObject* UICaption::get_float_member(PyUICaptionObject* self, void* closure)
|
||||||
int UICaption::set_float_member(PyUICaptionObject* self, PyObject* value, void* closure)
|
int UICaption::set_float_member(PyUICaptionObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
float val;
|
float val;
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (PyFloat_Check(value))
|
if (PyFloat_Check(value))
|
||||||
{
|
{
|
||||||
val = PyFloat_AsDouble(value);
|
val = PyFloat_AsDouble(value);
|
||||||
|
|
@ -156,7 +156,7 @@ PyObject* UICaption::get_color_member(PyUICaptionObject* self, void* closure)
|
||||||
// TODO: migrate this code to a switch statement - validate closure & return values in one tighter, more extensible structure
|
// TODO: migrate this code to a switch statement - validate closure & return values in one tighter, more extensible structure
|
||||||
|
|
||||||
// validate closure (should be impossible to be wrong, but it's thorough)
|
// validate closure (should be impossible to be wrong, but it's thorough)
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr != 0 && member_ptr != 1)
|
if (member_ptr != 0 && member_ptr != 1)
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_AttributeError, "Invalid attribute");
|
PyErr_SetString(PyExc_AttributeError, "Invalid attribute");
|
||||||
|
|
@ -181,7 +181,7 @@ PyObject* UICaption::get_color_member(PyUICaptionObject* self, void* closure)
|
||||||
|
|
||||||
int UICaption::set_color_member(PyUICaptionObject* self, PyObject* value, void* closure)
|
int UICaption::set_color_member(PyUICaptionObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
//TODO: this logic of (PyColor instance OR tuple -> sf::color) should be encapsulated for reuse
|
//TODO: this logic of (PyColor instance OR tuple -> sf::color) should be encapsulated for reuse
|
||||||
int r, g, b, a;
|
int r, g, b, a;
|
||||||
if (PyObject_IsInstance(value, PyObject_GetAttrString(McRFPy_API::mcrf_module, "Color") /*(PyObject*)&mcrfpydef::PyColorType)*/))
|
if (PyObject_IsInstance(value, PyObject_GetAttrString(McRFPy_API::mcrf_module, "Color") /*(PyObject*)&mcrfpydef::PyColorType)*/))
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ void UIDrawable::render()
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIDrawable::get_click(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_click(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure)); // trust me bro, it's an Enum
|
||||||
PyObject* ptr;
|
PyObject* ptr;
|
||||||
|
|
||||||
switch (objtype)
|
switch (objtype)
|
||||||
|
|
@ -228,7 +228,7 @@ PyObject* UIDrawable::get_click(PyObject* self, void* closure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIDrawable::set_click(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_click(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure)); // trust me bro, it's an Enum
|
||||||
UIDrawable* target;
|
UIDrawable* target;
|
||||||
switch (objtype)
|
switch (objtype)
|
||||||
{
|
{
|
||||||
|
|
@ -305,7 +305,7 @@ void UIDrawable::on_move_unregister()
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIDrawable::get_int(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_int(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -339,7 +339,7 @@ PyObject* UIDrawable::get_int(PyObject* self, void* closure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIDrawable::set_int(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_int(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -405,7 +405,7 @@ void UIDrawable::notifyZIndexChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIDrawable::get_name(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_name(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -439,7 +439,7 @@ PyObject* UIDrawable::get_name(PyObject* self, void* closure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIDrawable::set_name(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_name(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -639,7 +639,7 @@ int UIDrawable::set_float_member(PyObject* self, PyObject* value, void* closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIDrawable::get_pos(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_pos(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -686,7 +686,7 @@ PyObject* UIDrawable::get_pos(PyObject* self, void* closure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIDrawable::set_pos(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_pos(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -892,7 +892,7 @@ void UIDrawable::markDirty() {
|
||||||
|
|
||||||
// Python API - get parent drawable
|
// Python API - get parent drawable
|
||||||
PyObject* UIDrawable::get_parent(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_parent(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1003,7 +1003,7 @@ PyObject* UIDrawable::get_parent(PyObject* self, void* closure) {
|
||||||
|
|
||||||
// Python API - set parent drawable (or None to remove from parent)
|
// Python API - set parent drawable (or None to remove from parent)
|
||||||
int UIDrawable::set_parent(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_parent(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
std::shared_ptr<UIDrawable> drawable = nullptr;
|
std::shared_ptr<UIDrawable> drawable = nullptr;
|
||||||
|
|
||||||
// Get the shared_ptr for self
|
// Get the shared_ptr for self
|
||||||
|
|
@ -1125,7 +1125,7 @@ int UIDrawable::set_parent(PyObject* self, PyObject* value, void* closure) {
|
||||||
|
|
||||||
// Python API - get global position (read-only)
|
// Python API - get global position (read-only)
|
||||||
PyObject* UIDrawable::get_global_pos(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_global_pos(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1175,7 +1175,7 @@ PyObject* UIDrawable::get_global_pos(PyObject* self, void* closure) {
|
||||||
|
|
||||||
// #138, #188 - Python API for bounds property - returns (pos, size) as pair of Vectors
|
// #138, #188 - Python API for bounds property - returns (pos, size) as pair of Vectors
|
||||||
PyObject* UIDrawable::get_bounds_py(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_bounds_py(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1236,7 +1236,7 @@ PyObject* UIDrawable::get_bounds_py(PyObject* self, void* closure) {
|
||||||
|
|
||||||
// #138, #188 - Python API for global_bounds property - returns (pos, size) as pair of Vectors
|
// #138, #188 - Python API for global_bounds property - returns (pos, size) as pair of Vectors
|
||||||
PyObject* UIDrawable::get_global_bounds_py(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_global_bounds_py(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1297,7 +1297,7 @@ PyObject* UIDrawable::get_global_bounds_py(PyObject* self, void* closure) {
|
||||||
|
|
||||||
// #140 - Python API for on_enter property
|
// #140 - Python API for on_enter property
|
||||||
PyObject* UIDrawable::get_on_enter(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_on_enter(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
PyObject* ptr = nullptr;
|
PyObject* ptr = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1340,7 +1340,7 @@ PyObject* UIDrawable::get_on_enter(PyObject* self, void* closure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIDrawable::set_on_enter(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_on_enter(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* target = nullptr;
|
UIDrawable* target = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1380,7 +1380,7 @@ int UIDrawable::set_on_enter(PyObject* self, PyObject* value, void* closure) {
|
||||||
|
|
||||||
// #140 - Python API for on_exit property
|
// #140 - Python API for on_exit property
|
||||||
PyObject* UIDrawable::get_on_exit(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_on_exit(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
PyObject* ptr = nullptr;
|
PyObject* ptr = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1423,7 +1423,7 @@ PyObject* UIDrawable::get_on_exit(PyObject* self, void* closure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIDrawable::set_on_exit(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_on_exit(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* target = nullptr;
|
UIDrawable* target = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1463,7 +1463,7 @@ int UIDrawable::set_on_exit(PyObject* self, PyObject* value, void* closure) {
|
||||||
|
|
||||||
// #140 - Python API for hovered property (read-only)
|
// #140 - Python API for hovered property (read-only)
|
||||||
PyObject* UIDrawable::get_hovered(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_hovered(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* drawable = nullptr;
|
UIDrawable* drawable = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1498,7 +1498,7 @@ PyObject* UIDrawable::get_hovered(PyObject* self, void* closure) {
|
||||||
|
|
||||||
// #141 - Python API for on_move property
|
// #141 - Python API for on_move property
|
||||||
PyObject* UIDrawable::get_on_move(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_on_move(PyObject* self, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
PyObject* ptr = nullptr;
|
PyObject* ptr = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1541,7 +1541,7 @@ PyObject* UIDrawable::get_on_move(PyObject* self, void* closure) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UIDrawable::set_on_move(PyObject* self, PyObject* value, void* closure) {
|
int UIDrawable::set_on_move(PyObject* self, PyObject* value, void* closure) {
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<intptr_t>(closure));
|
||||||
UIDrawable* target = nullptr;
|
UIDrawable* target = nullptr;
|
||||||
|
|
||||||
switch (objtype) {
|
switch (objtype) {
|
||||||
|
|
@ -1689,7 +1689,7 @@ PyObject* UIDrawable_animate_impl(std::shared_ptr<UIDrawable> self, PyObject* ar
|
||||||
} else if (strcmp(conflict_mode_str, "queue") == 0) {
|
} else if (strcmp(conflict_mode_str, "queue") == 0) {
|
||||||
conflict_mode = AnimationConflictMode::QUEUE;
|
conflict_mode = AnimationConflictMode::QUEUE;
|
||||||
} else if (strcmp(conflict_mode_str, "error") == 0) {
|
} else if (strcmp(conflict_mode_str, "error") == 0) {
|
||||||
conflict_mode = AnimationConflictMode::ERROR;
|
conflict_mode = AnimationConflictMode::RAISE_ERROR;
|
||||||
} else {
|
} else {
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"Invalid conflict_mode '%s'. Must be 'replace', 'queue', or 'error'.", conflict_mode_str);
|
"Invalid conflict_mode '%s'. Must be 'replace', 'queue', or 'error'.", conflict_mode_str);
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,7 @@ PyObject* UIGridPointStateVector_to_PyList(const std::vector<UIGridPointState>&
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIEntity::get_position(PyUIEntityObject* self, void* closure) {
|
PyObject* UIEntity::get_position(PyUIEntityObject* self, void* closure) {
|
||||||
if (reinterpret_cast<long>(closure) == 0) {
|
if (reinterpret_cast<intptr_t>(closure) == 0) {
|
||||||
return sfVector2f_to_PyObject(self->data->position);
|
return sfVector2f_to_PyObject(self->data->position);
|
||||||
} else {
|
} else {
|
||||||
// Return integer-cast position for grid coordinates
|
// Return integer-cast position for grid coordinates
|
||||||
|
|
@ -373,7 +373,7 @@ int UIEntity::set_position(PyUIEntityObject* self, PyObject* value, void* closur
|
||||||
float old_x = self->data->position.x;
|
float old_x = self->data->position.x;
|
||||||
float old_y = self->data->position.y;
|
float old_y = self->data->position.y;
|
||||||
|
|
||||||
if (reinterpret_cast<long>(closure) == 0) {
|
if (reinterpret_cast<intptr_t>(closure) == 0) {
|
||||||
sf::Vector2f vec = PyObject_to_sfVector2f(value);
|
sf::Vector2f vec = PyObject_to_sfVector2f(value);
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
return -1; // Error already set by PyObject_to_sfVector2f
|
return -1; // Error already set by PyObject_to_sfVector2f
|
||||||
|
|
@ -418,7 +418,7 @@ int UIEntity::set_spritenumber(PyUIEntityObject* self, PyObject* value, void* cl
|
||||||
|
|
||||||
PyObject* UIEntity::get_float_member(PyUIEntityObject* self, void* closure)
|
PyObject* UIEntity::get_float_member(PyUIEntityObject* self, void* closure)
|
||||||
{
|
{
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0) // x
|
if (member_ptr == 0) // x
|
||||||
return PyFloat_FromDouble(self->data->position.x);
|
return PyFloat_FromDouble(self->data->position.x);
|
||||||
else if (member_ptr == 1) // y
|
else if (member_ptr == 1) // y
|
||||||
|
|
@ -433,7 +433,7 @@ PyObject* UIEntity::get_float_member(PyUIEntityObject* self, void* closure)
|
||||||
int UIEntity::set_float_member(PyUIEntityObject* self, PyObject* value, void* closure)
|
int UIEntity::set_float_member(PyUIEntityObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
float val;
|
float val;
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (PyFloat_Check(value))
|
if (PyFloat_Check(value))
|
||||||
{
|
{
|
||||||
val = PyFloat_AsDouble(value);
|
val = PyFloat_AsDouble(value);
|
||||||
|
|
@ -540,7 +540,7 @@ PyObject* UIEntity::get_pixel_member(PyUIEntityObject* self, void* closure) {
|
||||||
float cell_width, cell_height;
|
float cell_width, cell_height;
|
||||||
get_cell_dimensions(self->data.get(), cell_width, cell_height);
|
get_cell_dimensions(self->data.get(), cell_width, cell_height);
|
||||||
|
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0) // x
|
if (member_ptr == 0) // x
|
||||||
return PyFloat_FromDouble(self->data->position.x * cell_width);
|
return PyFloat_FromDouble(self->data->position.x * cell_width);
|
||||||
else // y
|
else // y
|
||||||
|
|
@ -570,7 +570,7 @@ int UIEntity::set_pixel_member(PyUIEntityObject* self, PyObject* value, void* cl
|
||||||
float old_x = self->data->position.x;
|
float old_x = self->data->position.x;
|
||||||
float old_y = self->data->position.y;
|
float old_y = self->data->position.y;
|
||||||
|
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0) // x
|
if (member_ptr == 0) // x
|
||||||
self->data->position.x = val / cell_width;
|
self->data->position.x = val / cell_width;
|
||||||
else // y
|
else // y
|
||||||
|
|
@ -584,7 +584,7 @@ int UIEntity::set_pixel_member(PyUIEntityObject* self, PyObject* value, void* cl
|
||||||
|
|
||||||
// #176 - Integer grid position (grid_x, grid_y)
|
// #176 - Integer grid position (grid_x, grid_y)
|
||||||
PyObject* UIEntity::get_grid_int_member(PyUIEntityObject* self, void* closure) {
|
PyObject* UIEntity::get_grid_int_member(PyUIEntityObject* self, void* closure) {
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0) // grid_x
|
if (member_ptr == 0) // grid_x
|
||||||
return PyLong_FromLong(static_cast<int>(self->data->position.x));
|
return PyLong_FromLong(static_cast<int>(self->data->position.x));
|
||||||
else // grid_y
|
else // grid_y
|
||||||
|
|
@ -606,7 +606,7 @@ int UIEntity::set_grid_int_member(PyUIEntityObject* self, PyObject* value, void*
|
||||||
float old_x = self->data->position.x;
|
float old_x = self->data->position.x;
|
||||||
float old_y = self->data->position.y;
|
float old_y = self->data->position.y;
|
||||||
|
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0) // grid_x
|
if (member_ptr == 0) // grid_x
|
||||||
self->data->position.x = static_cast<float>(val);
|
self->data->position.x = static_cast<float>(val);
|
||||||
else // grid_y
|
else // grid_y
|
||||||
|
|
@ -1172,7 +1172,7 @@ PyObject* UIEntity::animate(PyUIEntityObject* self, PyObject* args, PyObject* kw
|
||||||
} else if (strcmp(conflict_mode_str, "queue") == 0) {
|
} else if (strcmp(conflict_mode_str, "queue") == 0) {
|
||||||
conflict_mode = AnimationConflictMode::QUEUE;
|
conflict_mode = AnimationConflictMode::QUEUE;
|
||||||
} else if (strcmp(conflict_mode_str, "error") == 0) {
|
} else if (strcmp(conflict_mode_str, "error") == 0) {
|
||||||
conflict_mode = AnimationConflictMode::ERROR;
|
conflict_mode = AnimationConflictMode::RAISE_ERROR;
|
||||||
} else {
|
} else {
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"Invalid conflict_mode '%s'. Must be 'replace', 'queue', or 'error'.", conflict_mode_str);
|
"Invalid conflict_mode '%s'. Must be 'replace', 'queue', or 'error'.", conflict_mode_str);
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ PyObject* UIFrame::get_children(PyUIFrameObject* self, void* closure)
|
||||||
|
|
||||||
PyObject* UIFrame::get_float_member(PyUIFrameObject* self, void* closure)
|
PyObject* UIFrame::get_float_member(PyUIFrameObject* self, void* closure)
|
||||||
{
|
{
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0)
|
if (member_ptr == 0)
|
||||||
return PyFloat_FromDouble(self->data->box.getPosition().x);
|
return PyFloat_FromDouble(self->data->box.getPosition().x);
|
||||||
else if (member_ptr == 1)
|
else if (member_ptr == 1)
|
||||||
|
|
@ -208,7 +208,7 @@ PyObject* UIFrame::get_float_member(PyUIFrameObject* self, void* closure)
|
||||||
int UIFrame::set_float_member(PyUIFrameObject* self, PyObject* value, void* closure)
|
int UIFrame::set_float_member(PyUIFrameObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
float val;
|
float val;
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (PyFloat_Check(value))
|
if (PyFloat_Check(value))
|
||||||
{
|
{
|
||||||
val = PyFloat_AsDouble(value);
|
val = PyFloat_AsDouble(value);
|
||||||
|
|
@ -258,7 +258,7 @@ int UIFrame::set_float_member(PyUIFrameObject* self, PyObject* value, void* clos
|
||||||
PyObject* UIFrame::get_color_member(PyUIFrameObject* self, void* closure)
|
PyObject* UIFrame::get_color_member(PyUIFrameObject* self, void* closure)
|
||||||
{
|
{
|
||||||
// validate closure (should be impossible to be wrong, but it's thorough)
|
// validate closure (should be impossible to be wrong, but it's thorough)
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr != 0 && member_ptr != 1)
|
if (member_ptr != 0 && member_ptr != 1)
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_AttributeError, "Invalid attribute");
|
PyErr_SetString(PyExc_AttributeError, "Invalid attribute");
|
||||||
|
|
@ -293,7 +293,7 @@ PyObject* UIFrame::get_color_member(PyUIFrameObject* self, void* closure)
|
||||||
int UIFrame::set_color_member(PyUIFrameObject* self, PyObject* value, void* closure)
|
int UIFrame::set_color_member(PyUIFrameObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
//TODO: this logic of (PyColor instance OR tuple -> sf::color) should be encapsulated for reuse
|
//TODO: this logic of (PyColor instance OR tuple -> sf::color) should be encapsulated for reuse
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
int r, g, b, a;
|
int r, g, b, a;
|
||||||
if (PyObject_IsInstance(value, PyObject_GetAttrString(McRFPy_API::mcrf_module, "Color")))
|
if (PyObject_IsInstance(value, PyObject_GetAttrString(McRFPy_API::mcrf_module, "Color")))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1076,7 +1076,7 @@ int UIGrid::set_center(PyUIGridObject* self, PyObject* value, void* closure) {
|
||||||
|
|
||||||
PyObject* UIGrid::get_float_member(PyUIGridObject* self, void* closure)
|
PyObject* UIGrid::get_float_member(PyUIGridObject* self, void* closure)
|
||||||
{
|
{
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0) // x
|
if (member_ptr == 0) // x
|
||||||
return PyFloat_FromDouble(self->data->box.getPosition().x);
|
return PyFloat_FromDouble(self->data->box.getPosition().x);
|
||||||
else if (member_ptr == 1) // y
|
else if (member_ptr == 1) // y
|
||||||
|
|
@ -1101,7 +1101,7 @@ PyObject* UIGrid::get_float_member(PyUIGridObject* self, void* closure)
|
||||||
int UIGrid::set_float_member(PyUIGridObject* self, PyObject* value, void* closure)
|
int UIGrid::set_float_member(PyUIGridObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
float val;
|
float val;
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (PyFloat_Check(value))
|
if (PyFloat_Check(value))
|
||||||
{
|
{
|
||||||
val = PyFloat_AsDouble(value);
|
val = PyFloat_AsDouble(value);
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ sf::Color PyObject_to_sfColor(PyObject* obj) {
|
||||||
// #150 - Removed get_color/set_color - now handled by layers
|
// #150 - Removed get_color/set_color - now handled by layers
|
||||||
|
|
||||||
PyObject* UIGridPoint::get_bool_member(PyUIGridPointObject* self, void* closure) {
|
PyObject* UIGridPoint::get_bool_member(PyUIGridPointObject* self, void* closure) {
|
||||||
if (reinterpret_cast<long>(closure) == 0) { // walkable
|
if (reinterpret_cast<intptr_t>(closure) == 0) { // walkable
|
||||||
return PyBool_FromLong(self->data->walkable);
|
return PyBool_FromLong(self->data->walkable);
|
||||||
} else { // transparent
|
} else { // transparent
|
||||||
return PyBool_FromLong(self->data->transparent);
|
return PyBool_FromLong(self->data->transparent);
|
||||||
|
|
@ -66,13 +66,13 @@ PyObject* UIGridPoint::get_bool_member(PyUIGridPointObject* self, void* closure)
|
||||||
|
|
||||||
int UIGridPoint::set_bool_member(PyUIGridPointObject* self, PyObject* value, void* closure) {
|
int UIGridPoint::set_bool_member(PyUIGridPointObject* self, PyObject* value, void* closure) {
|
||||||
if (value == Py_True) {
|
if (value == Py_True) {
|
||||||
if (reinterpret_cast<long>(closure) == 0) { // walkable
|
if (reinterpret_cast<intptr_t>(closure) == 0) { // walkable
|
||||||
self->data->walkable = true;
|
self->data->walkable = true;
|
||||||
} else { // transparent
|
} else { // transparent
|
||||||
self->data->transparent = true;
|
self->data->transparent = true;
|
||||||
}
|
}
|
||||||
} else if (value == Py_False) {
|
} else if (value == Py_False) {
|
||||||
if (reinterpret_cast<long>(closure) == 0) { // walkable
|
if (reinterpret_cast<intptr_t>(closure) == 0) { // walkable
|
||||||
self->data->walkable = false;
|
self->data->walkable = false;
|
||||||
} else { // transparent
|
} else { // transparent
|
||||||
self->data->transparent = false;
|
self->data->transparent = false;
|
||||||
|
|
@ -162,7 +162,7 @@ PyObject* UIGridPoint::repr(PyUIGridPointObject* self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIGridPointState::get_bool_member(PyUIGridPointStateObject* self, void* closure) {
|
PyObject* UIGridPointState::get_bool_member(PyUIGridPointStateObject* self, void* closure) {
|
||||||
if (reinterpret_cast<long>(closure) == 0) { // visible
|
if (reinterpret_cast<intptr_t>(closure) == 0) { // visible
|
||||||
return PyBool_FromLong(self->data->visible);
|
return PyBool_FromLong(self->data->visible);
|
||||||
} else { // discovered
|
} else { // discovered
|
||||||
return PyBool_FromLong(self->data->discovered);
|
return PyBool_FromLong(self->data->discovered);
|
||||||
|
|
@ -180,7 +180,7 @@ int UIGridPointState::set_bool_member(PyUIGridPointStateObject* self, PyObject*
|
||||||
return -1; // PyObject_IsTrue returns -1 on error
|
return -1; // PyObject_IsTrue returns -1 on error
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reinterpret_cast<long>(closure) == 0) { // visible
|
if (reinterpret_cast<intptr_t>(closure) == 0) { // visible
|
||||||
self->data->visible = truthValue;
|
self->data->visible = truthValue;
|
||||||
} else { // discovered
|
} else { // discovered
|
||||||
self->data->discovered = truthValue;
|
self->data->discovered = truthValue;
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ void UISprite::onPositionChanged()
|
||||||
|
|
||||||
PyObject* UISprite::get_float_member(PyUISpriteObject* self, void* closure)
|
PyObject* UISprite::get_float_member(PyUISpriteObject* self, void* closure)
|
||||||
{
|
{
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (member_ptr == 0)
|
if (member_ptr == 0)
|
||||||
return PyFloat_FromDouble(self->data->getPosition().x);
|
return PyFloat_FromDouble(self->data->getPosition().x);
|
||||||
else if (member_ptr == 1)
|
else if (member_ptr == 1)
|
||||||
|
|
@ -203,7 +203,7 @@ PyObject* UISprite::get_float_member(PyUISpriteObject* self, void* closure)
|
||||||
int UISprite::set_float_member(PyUISpriteObject* self, PyObject* value, void* closure)
|
int UISprite::set_float_member(PyUISpriteObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
float val;
|
float val;
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (PyFloat_Check(value))
|
if (PyFloat_Check(value))
|
||||||
{
|
{
|
||||||
val = PyFloat_AsDouble(value);
|
val = PyFloat_AsDouble(value);
|
||||||
|
|
@ -232,7 +232,7 @@ int UISprite::set_float_member(PyUISpriteObject* self, PyObject* value, void* cl
|
||||||
|
|
||||||
PyObject* UISprite::get_int_member(PyUISpriteObject* self, void* closure)
|
PyObject* UISprite::get_int_member(PyUISpriteObject* self, void* closure)
|
||||||
{
|
{
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (true) {}
|
if (true) {}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -246,7 +246,7 @@ PyObject* UISprite::get_int_member(PyUISpriteObject* self, void* closure)
|
||||||
int UISprite::set_int_member(PyUISpriteObject* self, PyObject* value, void* closure)
|
int UISprite::set_int_member(PyUISpriteObject* self, PyObject* value, void* closure)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
auto member_ptr = reinterpret_cast<long>(closure);
|
auto member_ptr = reinterpret_cast<intptr_t>(closure);
|
||||||
if (PyLong_Check(value))
|
if (PyLong_Check(value))
|
||||||
{
|
{
|
||||||
val = PyLong_AsLong(value);
|
val = PyLong_AsLong(value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue