This commit is contained in:
Sam 2017-09-28 20:07:17 +02:00
commit c4726e767a
53 changed files with 865 additions and 2050 deletions

View File

@ -250,24 +250,14 @@ if(NOT USE_GLES2 AND NOT SERVER_ONLY)
include_directories(${OPENGL_INCLUDE_DIR})
endif()
if(UNIX AND NOT APPLE AND NOT SERVER_ONLY)
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
if(NOT X11_Xrandr_FOUND)
message(FATAL_ERROR "XRANDR not found.")
endif()
if(USE_LIBBFD)
find_package(Libbfd)
if(LIBBFD_FOUND)
add_definitions(-DENABLE_LIBBFD)
include_directories(${LIBBFD_INCLUDE_DIRS})
else()
set(USE_LIBBFD OFF CACHE BOOL "Use libbfd for crash reporting and leak check" FORCE)
message(WARNING "Libbfd not found, disable integrated stack trace.")
endif()
if(USE_LIBBFD)
find_package(Libbfd)
if(LIBBFD_FOUND)
add_definitions(-DENABLE_LIBBFD)
include_directories(${LIBBFD_INCLUDE_DIRS})
else()
set(USE_LIBBFD OFF CACHE BOOL "Use libbfd for crash reporting and leak check" FORCE)
message(WARNING "Libbfd not found, disable integrated stack trace.")
endif()
endif()
@ -418,7 +408,6 @@ if(NOT SERVER_ONLY)
endif()
if(UNIX AND NOT APPLE)
target_link_libraries(supertuxkart ${X11_X11_LIB} ${X11_Xrandr_LIB})
if(USE_LIBBFD)
target_link_libraries(supertuxkart ${LIBBFD_LIBRARIES})
endif()

18
cmake/FindEGL.cmake Normal file
View File

@ -0,0 +1,18 @@
# - Find EGL
# Find the EGL includes and libraries
#
# Following variables are provided:
# EGL_FOUND
# True if EGL has been found
# EGL_INCLUDE_DIR
# The include directory of EGL
# EGL_LIBRARY
# EGL library list
find_path(EGL_INCLUDE_DIR EGL/egl.h)
find_library(EGL_LIBRARY NAMES EGL)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR)
mark_as_advanced(EGL_LIBRARY EGL_INCLUDE_DIR)

52
cmake/FindWayland.cmake Normal file
View File

@ -0,0 +1,52 @@
# - Find Wayland
# Find the Wayland includes and libraries
#
# Following variables are provided:
# WAYLAND_FOUND
# True if Wayland has been found
# WAYLAND_INCLUDE_DIRS
# The include directories of Wayland
# WAYLAND_LIBRARIES
# Wayland library list
find_path(WAYLAND_CLIENT_INCLUDE_DIR wayland-client.h)
find_path(WAYLAND_CURSOR_INCLUDE_DIR wayland-cursor.h)
find_path(WAYLAND_EGL_INCLUDE_DIR wayland-egl.h)
find_path(XKBCOMMON_INCLUDE_DIR xkbcommon/xkbcommon.h)
find_library(WAYLAND_CLIENT_LIBRARY NAMES wayland-client)
find_library(WAYLAND_CURSOR_LIBRARY NAMES wayland-cursor)
find_library(WAYLAND_EGL_LIBRARY NAMES wayland-egl)
find_library(XKBCOMMON_LIBRARY NAMES xkbcommon)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Wayland DEFAULT_MSG WAYLAND_CLIENT_LIBRARY
WAYLAND_CURSOR_LIBRARY
WAYLAND_EGL_LIBRARY
XKBCOMMON_LIBRARY
WAYLAND_CLIENT_INCLUDE_DIR
WAYLAND_CURSOR_INCLUDE_DIR
WAYLAND_EGL_INCLUDE_DIR
XKBCOMMON_INCLUDE_DIR)
set(WAYLAND_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIR}
${WAYLAND_CURSOR_INCLUDE_DIR}
${WAYLAND_EGL_INCLUDE_DIR}
${XKBCOMMON_INCLUDE_DIR})
set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARY}
${WAYLAND_CURSOR_LIBRARY}
${WAYLAND_EGL_LIBRARY}
${XKBCOMMON_LIBRARY})
list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIRS)
list(REMOVE_DUPLICATES WAYLAND_LIBRARIES)
mark_as_advanced(WAYLAND_CLIENT_LIBRARY
WAYLAND_CURSOR_LIBRARY
WAYLAND_EGL_LIBRARY
XKBCOMMON_LIBRARY
WAYLAND_CLIENT_INCLUDE_DIR
WAYLAND_CURSOR_INCLUDE_DIR
WAYLAND_EGL_INCLUDE_DIR
XKBCOMMON_INCLUDE_DIR)

View File

@ -2,7 +2,7 @@
<achievements>
<achievement id="1" check-type="all-at-least" reset-type="never"
name="Christoffel Columbus" description="Play every official track at least once." >
<city goal="1"/>
<candela_city goal="1"/>
<cocoa_temple goal="1"/>
<cornfield_crossing goal="1"/>
<fortmagma goal="1"/>
@ -22,6 +22,7 @@
<abyss goal="1"/>
<xr591 goal="1"/>
<zengarden goal="1"/>
<volcano_island goal="1"/>
</achievement>
<achievement id="2" check-type="all-at-least" reset-type="never"
name="Strike!" description="Hit 10 karts with a bowling-ball.">

View File

@ -18,8 +18,8 @@
max="1200" />
<!-- Size of the particles -->
<size min="0.65"
max="0.95"
<size min="0.60"
max="0.85"
x-increase-factor="0.6"
y-increase-factor="0.6"
/>

View File

@ -18,8 +18,8 @@
max="1200" />
<!-- Size of the particles -->
<size min="0.65"
max="0.95"
<size min="0.60"
max="0.85"
x-increase-factor="0.6"
y-increase-factor="0.6"
/>

View File

@ -18,8 +18,8 @@
max="1200" />
<!-- Size of the particles -->
<size min="0.65"
max="0.95"
<size min="0.60"
max="0.85"
x-increase-factor="0.6"
y-increase-factor="0.6"
/>

View File

@ -18,8 +18,8 @@
max="500" />
<!-- Size of the particles -->
<size min="0.6"
max="0.8" />
<size min="0.55"
max="0.75" />
<color min="255 255 255"
max="255 255 255" />

View File

@ -12,24 +12,48 @@ if(MSVC OR APPLE)
"${CMAKE_CURRENT_BINARY_DIR}/../libpng/")
endif()
if (SERVER_ONLY)
add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
add_definitions(-DNO_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
else()
if(NOT SERVER_ONLY)
if(NOT USE_GLES2)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
endif()
endif()
if(UNIX AND NOT APPLE)
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
if(NOT X11_FOUND)
message(FATAL_ERROR "X11 not found.")
endif()
if(NOT X11_Xrandr_FOUND)
message(FATAL_ERROR "XRANDR not found.")
endif()
endif()
if (UNIX AND NOT APPLE)
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
endif()
if(ENABLE_WAYLAND_DEVICE)
find_package(Wayland REQUIRED)
include_directories(${WAYLAND_INCLUDE_DIR})
if(NOT WAYLAND_FOUND)
message(FATAL_ERROR "Wayland not found.")
endif()
add_definitions(-D_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
endif()
if(ENABLE_WAYLAND_DEVICE)
add_definitions(-D_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
if(USE_GLES2 OR ENABLE_WAYLAND_DEVICE)
find_package(EGL REQUIRED)
include_directories(${EGL_INCLUDE_DIR})
if(NOT EGL_FOUND)
message(FATAL_ERROR "EGL not found.")
endif()
endif()
else()
add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
add_definitions(-DNO_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
endif()
if(APPLE)
@ -44,21 +68,18 @@ if(UNIX OR MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
endif()
if(MSVC)
add_definitions(/D_IRR_STATIC_LIB_)
add_definitions(/D_CRT_SECURE_NO_WARNINGS) # Shut up about unsafe stuff
elseif(MINGW)
add_definitions(-D_IRR_STATIC_LIB_)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Shut up about unsafe stuff
if(WIN32)
add_definitions(-D_IRR_STATIC_LIB_)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Shut up about unsafe stuff
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pipe -O3 -fno-exceptions -fstrict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pipe -O3 -fno-exceptions -fstrict-aliasing")
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexpensive-optimizations")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexpensive-optimizations")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pipe -O3 -fno-exceptions -fstrict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pipe -O3 -fno-exceptions -fstrict-aliasing")
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexpensive-optimizations")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexpensive-optimizations")
endif()
endif()
if(USE_GLES2)
@ -123,8 +144,6 @@ source/Irrlicht/CImageWriterBMP.cpp
source/Irrlicht/CImageWriterJPG.cpp
source/Irrlicht/CImageWriterPNG.cpp
source/Irrlicht/CIrrDeviceAndroid.cpp
source/Irrlicht/CIrrDeviceConsole.cpp
source/Irrlicht/CIrrDeviceFB.cpp
source/Irrlicht/CIrrDeviceLinux.cpp
source/Irrlicht/CIrrDeviceSDL.cpp
source/Irrlicht/CIrrDeviceStub.cpp
@ -257,8 +276,6 @@ source/Irrlicht/CImageWriterBMP.h
source/Irrlicht/CImageWriterJPG.h
source/Irrlicht/CImageWriterPNG.h
source/Irrlicht/CIrrDeviceAndroid.h
source/Irrlicht/CIrrDeviceConsole.h
source/Irrlicht/CIrrDeviceFB.h
source/Irrlicht/CIrrDeviceLinux.h
source/Irrlicht/CIrrDeviceSDL.h
source/Irrlicht/CIrrDeviceStub.h
@ -559,14 +576,21 @@ if(APPLE)
endif()
add_library(stkirrlicht STATIC ${IRRLICHT_SOURCES})
target_link_libraries(stkirrlicht ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARY})
if(USE_GLES2 OR ENABLE_WAYLAND_DEVICE)
target_link_libraries(stkirrlicht EGL)
endif()
if(ENABLE_WAYLAND_DEVICE)
target_link_libraries(stkirrlicht wayland-client wayland-egl wayland-cursor xkbcommon)
if(NOT SERVER_ONLY)
if(UNIX AND NOT APPLE)
target_link_libraries(stkirrlicht ${X11_X11_LIB} ${X11_Xrandr_LIB})
endif()
if(USE_GLES2 OR ENABLE_WAYLAND_DEVICE)
target_link_libraries(stkirrlicht ${EGL_LIBRARY})
endif()
if(ENABLE_WAYLAND_DEVICE)
target_link_libraries(stkirrlicht ${WAYLAND_LIBRARIES})
endif()
endif()
if(WIN32)

View File

@ -32,12 +32,9 @@
//! DEVICE is the windowing system used, several PLATFORMs support more than one DEVICE
//! Irrlicht can be compiled with more than one device
//! _IRR_COMPILE_WITH_WINDOWS_DEVICE_ for Windows API based device
//! _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_ for Windows CE API based device
//! _IRR_COMPILE_WITH_OSX_DEVICE_ for Cocoa native windowing on OSX
//! _IRR_COMPILE_WITH_X11_DEVICE_ for Linux X11 based device
//! _IRR_COMPILE_WITH_SDL_DEVICE_ for platform independent SDL framework
//! _IRR_COMPILE_WITH_CONSOLE_DEVICE_ for no windowing system, used as a fallback
//! _IRR_COMPILE_WITH_FB_DEVICE_ for framebuffer systems
//! Passing defines to the compiler which have NO in front of the _IRR definename is an alternative
//! way which can be used to disable defines (instead of outcommenting them in this header).
@ -52,11 +49,6 @@
#undef _IRR_COMPILE_WITH_SDL_DEVICE_
#endif
//! Comment this line to compile without the fallback console device.
#define _IRR_COMPILE_WITH_CONSOLE_DEVICE_
#ifdef NO_IRR_COMPILE_WITH_CONSOLE_DEVICE_
#undef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
#endif
//! WIN32 for Windows32
//! WIN64 for Windows64
@ -67,13 +59,6 @@
#define _IRR_COMPILE_WITH_WINDOWS_DEVICE_
#endif
//! WINCE is a very restricted environment for mobile devices
#if defined(_WIN32_WCE)
#define _IRR_WINDOWS_
#define _IRR_WINDOWS_API_
#define _IRR_WINDOWS_CE_PLATFORM_
#define _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1300)
# error "Only Microsoft Visual Studio 7.0 and later are supported."

View File

@ -240,6 +240,15 @@ namespace irr
//! Restore the window to normal size if possible.
virtual void restoreWindow() =0;
//! Move window to requested position
/** \return true if success */
virtual bool moveWindow(int x, int y) = 0;
//! Get current window position.
/** \return true if success */
virtual bool getWindowPosition(int* x, int* y) = 0;
//! Activate any joysticks, and generate events for them.
/** Irrlicht contains support for joysticks, but does not generate joystick events by default,
as this would consume joystick info that 3rd party libraries might rely on. Call this method to

View File

@ -262,52 +262,75 @@ bool ContextManagerEGL::chooseConfig()
bool ContextManagerEGL::createSurface()
{
if (m_creation_params.surface_type == CEGL_SURFACE_WINDOW)
{
if (m_egl_surface == EGL_NO_SURFACE)
{
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_egl_config,
m_egl_window, NULL);
}
unsigned int colorspace_attr_pos = 0;
unsigned int largest_pbuffer_attr_pos = 0;
std::vector<EGLint> attribs;
if (m_egl_surface == EGL_NO_SURFACE)
if (m_creation_params.opengl_api == CEGL_API_OPENGL)
{
if (hasEGLExtension("EGL_KHR_gl_colorspace") || m_egl_version >= 150)
{
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_egl_config,
0, NULL);
attribs.push_back(EGL_GL_COLORSPACE);
attribs.push_back(m_creation_params.handle_srgb ?
EGL_GL_COLORSPACE_SRGB : EGL_GL_COLORSPACE_LINEAR);
colorspace_attr_pos = attribs.size() - 1;
}
}
else if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER)
if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER)
{
if (m_egl_surface == EGL_NO_SURFACE)
attribs.push_back(EGL_WIDTH);
attribs.push_back(m_creation_params.pbuffer_width);
attribs.push_back(EGL_HEIGHT);
attribs.push_back(m_creation_params.pbuffer_height);
attribs.push_back(EGL_LARGEST_PBUFFER);
attribs.push_back(EGL_FALSE);
largest_pbuffer_attr_pos = attribs.size() - 1;
}
attribs.push_back(EGL_NONE);
attribs.push_back(0);
if (m_egl_surface == EGL_NO_SURFACE)
{
if (m_creation_params.surface_type == CEGL_SURFACE_WINDOW)
{
std::vector<EGLint> pbuffer_attribs;
pbuffer_attribs.push_back(EGL_WIDTH);
pbuffer_attribs.push_back(m_creation_params.pbuffer_width);
pbuffer_attribs.push_back(EGL_HEIGHT);
pbuffer_attribs.push_back(m_creation_params.pbuffer_height);
pbuffer_attribs.push_back(EGL_NONE);
pbuffer_attribs.push_back(0);
m_egl_surface = eglCreatePbufferSurface(m_egl_display,
m_egl_config,
&pbuffer_attribs[0]);
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_egl_config,
m_egl_window, &attribs[0]);
}
if (m_egl_surface == EGL_NO_SURFACE)
else if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER)
{
std::vector<EGLint> pbuffer_attribs;
pbuffer_attribs.push_back(EGL_WIDTH);
pbuffer_attribs.push_back(m_creation_params.pbuffer_width);
pbuffer_attribs.push_back(EGL_HEIGHT);
pbuffer_attribs.push_back(m_creation_params.pbuffer_height);
pbuffer_attribs.push_back(EGL_LARGEST_PBUFFER);
pbuffer_attribs.push_back(EGL_TRUE);
pbuffer_attribs.push_back(EGL_NONE);
pbuffer_attribs.push_back(0);
m_egl_surface = eglCreatePbufferSurface(m_egl_display,
m_egl_config,
&pbuffer_attribs[0]);
m_egl_surface = eglCreatePbufferSurface(m_egl_display, m_egl_config,
&attribs[0]);
}
}
if (m_egl_surface == EGL_NO_SURFACE && colorspace_attr_pos > 0 &&
m_creation_params.handle_srgb == true)
{
attribs[colorspace_attr_pos] = EGL_GL_COLORSPACE_LINEAR;
if (m_creation_params.surface_type == CEGL_SURFACE_WINDOW)
{
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_egl_config,
m_egl_window, &attribs[0]);
}
else if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER)
{
m_egl_surface = eglCreatePbufferSurface(m_egl_display, m_egl_config,
&attribs[0]);
}
}
if (m_egl_surface == EGL_NO_SURFACE && largest_pbuffer_attr_pos > 0)
{
attribs[largest_pbuffer_attr_pos] = EGL_TRUE;
if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER)
{
m_egl_surface = eglCreatePbufferSurface(m_egl_display, m_egl_config,
&attribs[0]);
}
}

View File

@ -30,6 +30,15 @@
#ifndef EGL_CONTEXT_MINOR_VERSION
#define EGL_CONTEXT_MINOR_VERSION 0x30FB
#endif
#ifndef EGL_GL_COLORSPACE
#define EGL_GL_COLORSPACE 0x309D
#endif
#ifndef EGL_GL_COLORSPACE_SRGB
#define EGL_GL_COLORSPACE_SRGB 0x3089
#endif
#ifndef EGL_GL_COLORSPACE_LINEAR
#define EGL_GL_COLORSPACE_LINEAR 0x308A
#endif
enum ContextEGLOpenGLAPI
{
@ -50,6 +59,7 @@ struct ContextEGLParams
EGLNativeWindowType window;
EGLNativeDisplayType display;
bool force_legacy_device;
bool handle_srgb;
bool with_alpha_channel;
bool vsync_enabled;
int pbuffer_width;

View File

@ -276,6 +276,18 @@ void CIrrDeviceAndroid::restoreWindow()
{
}
bool CIrrDeviceAndroid::moveWindow(int x, int y)
{
return true;
}
bool CIrrDeviceAndroid::getWindowPosition(int* x, int* y)
{
*x = 0;
*y = 0;
return true;
}
E_DEVICE_TYPE CIrrDeviceAndroid::getType() const
{
return EIDT_ANDROID;

View File

@ -47,6 +47,8 @@ namespace irr
virtual void minimizeWindow();
virtual void maximizeWindow();
virtual void restoreWindow();
virtual bool moveWindow(int x, int y);
virtual bool getWindowPosition(int* x, int* y);
virtual E_DEVICE_TYPE getType() const;
virtual bool activateAccelerometer(float updateInterval);
virtual bool deactivateAccelerometer();

View File

@ -1,477 +0,0 @@
// Copyright (C) 2009-2012 Gaz Davidson
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CIrrDeviceConsole.h"
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
#include "os.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
// to close the device on terminate signal
irr::CIrrDeviceConsole *DeviceToClose;
#ifdef _IRR_WINDOWS_NT_CONSOLE_
// Callback for Windows
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
switch(CEvent)
{
case CTRL_C_EVENT:
irr::os::Printer::log("Closing console device", "CTRL+C");
break;
case CTRL_BREAK_EVENT:
irr::os::Printer::log("Closing console device", "CTRL+Break");
break;
case CTRL_CLOSE_EVENT:
irr::os::Printer::log("Closing console device", "User closed console");
break;
case CTRL_LOGOFF_EVENT:
irr::os::Printer::log("Closing console device", "User is logging off");
break;
case CTRL_SHUTDOWN_EVENT:
irr::os::Printer::log("Closing console device", "Computer shutting down");
break;
}
DeviceToClose->closeDevice();
return TRUE;
}
#elif defined(_IRR_POSIX_API_)
// sigterm handler
#include <signal.h>
void sighandler(int sig)
{
irr::core::stringc code = "Signal ";
code += sig;
code += " received";
irr::os::Printer::log("Closing console device", code.c_str());
DeviceToClose->closeDevice();
}
#endif
namespace irr
{
const c8 ASCIIArtChars[] = " .,'~:;!+>=icopjtJY56SB8XDQKHNWM"; //MWNHKQDX8BS65YJtjpoci=+>!;:~',. ";
const u16 ASCIIArtCharsCount = 32;
//const c8 ASCIIArtChars[] = " \xb0\xb1\xf9\xb2\xdb";
//const u16 ASCIIArtCharsCount = 5;
//! constructor
CIrrDeviceConsole::CIrrDeviceConsole(const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), IsWindowFocused(true), ConsoleFont(0), OutFile(stdout)
{
DeviceToClose = this;
#ifdef _IRR_WINDOWS_NT_CONSOLE_
MouseButtonStates = 0;
WindowsSTDIn = GetStdHandle(STD_INPUT_HANDLE);
WindowsSTDOut = GetStdHandle(STD_OUTPUT_HANDLE);
PCOORD Dimensions = 0;
if (CreationParams.Fullscreen)
{
// Some mingw versions lack this define, so avoid it in case it does not exist
#if (_WIN32_WINNT >= 0x0501) && defined(CONSOLE_FULLSCREEN_MODE)
if (SetConsoleDisplayMode(WindowsSTDOut, CONSOLE_FULLSCREEN_MODE, Dimensions))
{
CreationParams.WindowSize.Width = Dimensions->X;
CreationParams.WindowSize.Width = Dimensions->Y;
}
#endif
}
else
{
COORD ConsoleSize;
ConsoleSize.X = CreationParams.WindowSize.Width;
ConsoleSize.X = CreationParams.WindowSize.Height;
SetConsoleScreenBufferSize(WindowsSTDOut, ConsoleSize);
}
// catch windows close/break signals
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#elif defined(_IRR_POSIX_API_)
// catch other signals
signal(SIGABRT, &sighandler);
signal(SIGTERM, &sighandler);
signal(SIGINT, &sighandler);
// set output stream
if (params.WindowId)
OutFile = (FILE*)(params.WindowId);
#endif
#ifdef _IRR_VT100_CONSOLE_
// reset terminal
fprintf(OutFile, "%cc", 27);
// disable line wrapping
fprintf(OutFile, "%c[7l", 27);
#endif
switch (params.DriverType)
{
case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("Software driver was not compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);
#else
os::Printer::log("Burning's Video driver was not compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_DIRECT3D8:
case video::EDT_DIRECT3D9:
case video::EDT_OPENGL:
os::Printer::log("The console device cannot use hardware drivers yet.", ELL_ERROR);
break;
case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break;
default:
break;
}
// set up output buffer
for (u32 y=0; y<CreationParams.WindowSize.Height; ++y)
{
core::stringc str;
str.reserve(CreationParams.WindowSize.Width);
for (u32 x=0; x<CreationParams.WindowSize.Width; ++x)
str += " ";
OutputBuffer.push_back(str);
}
#ifdef _IRR_WINDOWS_NT_CONSOLE_
CursorControl = new CCursorControl(CreationParams.WindowSize);
#endif
if (VideoDriver)
{
createGUIAndScene();
#ifdef _IRR_USE_CONSOLE_FONT_
if (GUIEnvironment)
{
ConsoleFont = new gui::CGUIConsoleFont(this);
gui::IGUISkin *skin = GUIEnvironment->getSkin();
if (skin)
{
for (u32 i=0; i < gui::EGDF_COUNT; ++i)
skin->setFont(ConsoleFont, gui::EGUI_DEFAULT_FONT(i));
}
}
#endif
}
}
//! destructor
CIrrDeviceConsole::~CIrrDeviceConsole()
{
// GUI and scene are dropped in the stub
if (CursorControl)
{
CursorControl->drop();
CursorControl = 0;
}
if (ConsoleFont)
{
ConsoleFont->drop();
ConsoleFont = 0;
}
#ifdef _IRR_VT100_CONSOLE_
// reset terminal
fprintf(OutFile, "%cc", 27);
#endif
}
//! runs the device. Returns false if device wants to be deleted
bool CIrrDeviceConsole::run()
{
// increment timer
os::Timer::tick();
// process Windows console input
#ifdef _IRR_WINDOWS_NT_CONSOLE_
INPUT_RECORD in;
DWORD oldMode;
DWORD count, waste;
// get old input mode
GetConsoleMode(WindowsSTDIn, &oldMode);
SetConsoleMode(WindowsSTDIn, ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT);
GetNumberOfConsoleInputEvents(WindowsSTDIn, &count);
// read keyboard and mouse input
while (count)
{
ReadConsoleInput(WindowsSTDIn, &in, 1, &waste );
switch(in.EventType)
{
case KEY_EVENT:
{
SEvent e;
e.EventType = EET_KEY_INPUT_EVENT;
e.KeyInput.PressedDown = (in.Event.KeyEvent.bKeyDown == TRUE);
e.KeyInput.Control = (in.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) != 0;
e.KeyInput.Shift = (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) != 0;
e.KeyInput.Key = EKEY_CODE(in.Event.KeyEvent.wVirtualKeyCode);
e.KeyInput.Char = in.Event.KeyEvent.uChar.UnicodeChar;
postEventFromUser(e);
break;
}
case MOUSE_EVENT:
{
SEvent e;
e.EventType = EET_MOUSE_INPUT_EVENT;
e.MouseInput.X = in.Event.MouseEvent.dwMousePosition.X;
e.MouseInput.Y = in.Event.MouseEvent.dwMousePosition.Y;
e.MouseInput.Wheel = 0.f;
e.MouseInput.ButtonStates =
( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED) ? EMBSM_LEFT : 0 ) |
( (in.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED) ? EMBSM_RIGHT : 0 ) |
( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED) ? EMBSM_MIDDLE : 0 ) |
( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_3RD_BUTTON_PRESSED) ? EMBSM_EXTRA1 : 0 ) |
( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_4TH_BUTTON_PRESSED) ? EMBSM_EXTRA2 : 0 );
if (in.Event.MouseEvent.dwEventFlags & MOUSE_MOVED)
{
CursorControl->setPosition(core::position2di(e.MouseInput.X, e.MouseInput.Y));
// create mouse moved event
e.MouseInput.Event = EMIE_MOUSE_MOVED;
postEventFromUser(e);
}
if (in.Event.MouseEvent.dwEventFlags & MOUSE_WHEELED)
{
e.MouseInput.Event = EMIE_MOUSE_WHEEL;
e.MouseInput.Wheel = (in.Event.MouseEvent.dwButtonState & 0xFF000000) ? -1.0f : 1.0f;
postEventFromUser(e);
}
if ( (MouseButtonStates & EMBSM_LEFT) != (e.MouseInput.ButtonStates & EMBSM_LEFT) )
{
e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_LEFT) ? EMIE_LMOUSE_PRESSED_DOWN : EMIE_LMOUSE_LEFT_UP;
postEventFromUser(e);
}
if ( (MouseButtonStates & EMBSM_RIGHT) != (e.MouseInput.ButtonStates & EMBSM_RIGHT) )
{
e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_RIGHT) ? EMIE_RMOUSE_PRESSED_DOWN : EMIE_RMOUSE_LEFT_UP;
postEventFromUser(e);
}
if ( (MouseButtonStates & EMBSM_MIDDLE) != (e.MouseInput.ButtonStates & EMBSM_MIDDLE) )
{
e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_MIDDLE) ? EMIE_MMOUSE_PRESSED_DOWN : EMIE_MMOUSE_LEFT_UP;
postEventFromUser(e);
}
// save current button states
MouseButtonStates = e.MouseInput.ButtonStates;
break;
}
case WINDOW_BUFFER_SIZE_EVENT:
VideoDriver->OnResize(
core::dimension2d<u32>(in.Event.WindowBufferSizeEvent.dwSize.X,
in.Event.WindowBufferSizeEvent.dwSize.Y));
break;
case FOCUS_EVENT:
IsWindowFocused = (in.Event.FocusEvent.bSetFocus == TRUE);
break;
default:
break;
}
GetNumberOfConsoleInputEvents(WindowsSTDIn, &count);
}
// set input mode
SetConsoleMode(WindowsSTDIn, oldMode);
#else
// todo: keyboard input from terminal in raw mode
#endif
return !Close;
}
//! Cause the device to temporarily pause execution and let other processes to run
// This should bring down processor usage without major performance loss for Irrlicht
void CIrrDeviceConsole::yield()
{
#ifdef _IRR_WINDOWS_API_
Sleep(1);
#else
struct timespec ts = {0,0};
nanosleep(&ts, NULL);
#endif
}
//! Pause execution and let other processes to run for a specified amount of time.
void CIrrDeviceConsole::sleep(u32 timeMs, bool pauseTimer)
{
const bool wasStopped = Timer ? Timer->isStopped() : true;
#ifdef _IRR_WINDOWS_API_
Sleep(timeMs);
#else
struct timespec ts;
ts.tv_sec = (time_t) (timeMs / 1000);
ts.tv_nsec = (long) (timeMs % 1000) * 1000000;
if (pauseTimer && !wasStopped)
Timer->stop();
nanosleep(&ts, NULL);
#endif
if (pauseTimer && !wasStopped)
Timer->start();
}
//! sets the caption of the window
void CIrrDeviceConsole::setWindowCaption(const wchar_t* text)
{
#ifdef _IRR_WINDOWS_NT_CONSOLE_
SetConsoleTitleW(text);
#endif
}
//! returns if window is active. if not, nothing need to be drawn
bool CIrrDeviceConsole::isWindowActive() const
{
// there is no window, but we always assume it is active
return true;
}
//! returns if window has focus
bool CIrrDeviceConsole::isWindowFocused() const
{
return IsWindowFocused;
}
//! returns if window is minimized
bool CIrrDeviceConsole::isWindowMinimized() const
{
return false;
}
//! presents a surface in the client area
bool CIrrDeviceConsole::present(video::IImage* surface, void* windowId, core::rect<s32>* src)
{
if (surface)
{
for (u32 y=0; y < surface->getDimension().Height; ++y)
{
for (u32 x=0; x< surface->getDimension().Width; ++x)
{
// get average pixel
u32 avg = surface->getPixel(x,y).getAverage() * (ASCIIArtCharsCount-1);
avg /= 255;
OutputBuffer[y] [x] = ASCIIArtChars[avg];
}
}
}
#ifdef _IRR_USE_CONSOLE_FONT_
for (u32 i=0; i< Text.size(); ++i)
{
s32 y = Text[i].Pos.Y;
if ( y < (s32)OutputBuffer.size() && y > 0)
for (u32 c=0; c < Text[i].Text.size() && c + Text[i].Pos.X < OutputBuffer[y].size(); ++c)
//if (Text[i].Text[c] != ' ')
OutputBuffer[y] [c+Text[i].Pos.X] = Text[i].Text[c];
}
Text.clear();
#endif
// draw output
for (u32 y=0; y<OutputBuffer.size(); ++y)
{
setTextCursorPos(0,y);
fprintf(OutFile, "%s", OutputBuffer[y].c_str());
}
return surface != 0;
}
//! notifies the device that it should close itself
void CIrrDeviceConsole::closeDevice()
{
// return false next time we run()
Close = true;
}
//! Sets if the window should be resizable in windowed mode.
void CIrrDeviceConsole::setResizable(bool resize)
{
// do nothing
}
//! Minimize the window.
void CIrrDeviceConsole::minimizeWindow()
{
// do nothing
}
//! Maximize window
void CIrrDeviceConsole::maximizeWindow()
{
// do nothing
}
//! Restore original window size
void CIrrDeviceConsole::restoreWindow()
{
// do nothing
}
void CIrrDeviceConsole::setTextCursorPos(s16 x, s16 y)
{
#ifdef _IRR_WINDOWS_NT_CONSOLE_
// move WinNT cursor
COORD Position;
Position.X = x;
Position.Y = y;
SetConsoleCursorPosition(WindowsSTDOut, Position);
#elif defined(_IRR_VT100_CONSOLE_)
// send escape code
fprintf(OutFile, "%c[%d;%dH", 27, y, x);
#else
// not implemented
#endif
}
void CIrrDeviceConsole::addPostPresentText(s16 X, s16 Y, const wchar_t *text)
{
SPostPresentText p;
p.Text = text;
p.Pos.X = X;
p.Pos.Y = Y;
Text.push_back(p);
}
} // end namespace irr
#endif // _IRR_COMPILE_WITH_CONSOLE_DEVICE_

View File

@ -1,333 +0,0 @@
// Copyright (C) 2009-2012 Gaz Davidson
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IRR_DEVICE_CONSOLE_H_INCLUDED__
#define __C_IRR_DEVICE_CONSOLE_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
//#define _IRR_USE_CONSOLE_FONT_
#include "SIrrCreationParameters.h"
#include "CIrrDeviceStub.h"
#include "IImagePresenter.h"
// for console font
#include "IGUIFont.h"
#ifdef _IRR_WINDOWS_API_
#define WIN32_LEAN_AND_MEAN
#if !defined(_IRR_XBOX_PLATFORM_)
#include <windows.h>
#endif
#if(_WIN32_WINNT >= 0x0500)
#define _IRR_WINDOWS_NT_CONSOLE_
#endif
#else
#include <time.h>
#endif
// for now we assume all other terminal types are VT100
#ifndef _IRR_WINDOWS_NT_CONSOLE_
#define _IRR_VT100_CONSOLE_
#endif
namespace irr
{
class CIrrDeviceConsole : public CIrrDeviceStub, video::IImagePresenter
{
public:
//! constructor
CIrrDeviceConsole(const SIrrlichtCreationParameters& params);
//! destructor
virtual ~CIrrDeviceConsole();
//! runs the device. Returns false if device wants to be deleted
virtual bool run();
//! Cause the device to temporarily pause execution and let other processes to run
// This should bring down processor usage without major performance loss for Irrlicht
virtual void yield();
//! Pause execution and let other processes to run for a specified amount of time.
virtual void sleep(u32 timeMs, bool pauseTimer);
//! sets the caption of the window
virtual void setWindowCaption(const wchar_t* text);
//! sets the class of the window
virtual void setWindowClass(const char* text) {}
//! returns if window is active. if not, nothing need to be drawn
virtual bool isWindowActive() const;
//! returns if window has focus
virtual bool isWindowFocused() const;
//! returns if window is minimized
virtual bool isWindowMinimized() const;
//! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0);
//! notifies the device that it should close itself
virtual void closeDevice();
//! Sets if the window should be resizable in windowed mode.
virtual void setResizable(bool resize=false);
//! Minimizes the window.
virtual void minimizeWindow();
//! Maximizes the window.
virtual void maximizeWindow();
//! Restores the window size.
virtual void restoreWindow();
//! Get the device type
virtual E_DEVICE_TYPE getType() const
{
return EIDT_CONSOLE;
}
void addPostPresentText(s16 X, s16 Y, const wchar_t *text);
//! Implementation of the win32 console mouse cursor
class CCursorControl : public gui::ICursorControl
{
public:
CCursorControl(const core::dimension2d<u32>& wsize)
: WindowSize(wsize), InvWindowSize(0.0f, 0.0f), IsVisible(true), UseReferenceRect(false)
{
if (WindowSize.Width!=0)
InvWindowSize.Width = 1.0f / WindowSize.Width;
if (WindowSize.Height!=0)
InvWindowSize.Height = 1.0f / WindowSize.Height;
}
//! Changes the visible state of the mouse cursor.
virtual void setVisible(bool visible)
{
if(visible != IsVisible)
{
IsVisible = visible;
setPosition(CursorPos.X, CursorPos.Y);
}
}
//! Returns if the cursor is currently visible.
virtual bool isVisible() const
{
return IsVisible;
}
//! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<f32> &pos)
{
setPosition(pos.X, pos.Y);
}
//! Sets the new position of the cursor.
virtual void setPosition(f32 x, f32 y)
{
if (!UseReferenceRect)
setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height));
else
setPosition((s32)(x*ReferenceRect.getWidth()), (s32)(y*ReferenceRect.getHeight()));
}
//! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<s32> &pos)
{
setPosition(pos.X, pos.Y);
}
//! Sets the new position of the cursor.
virtual void setPosition(s32 x, s32 y)
{
setInternalCursorPosition(core::position2di(x,y));
}
//! Returns the current position of the mouse cursor.
virtual const core::position2d<s32>& getPosition()
{
return CursorPos;
}
//! Returns the current position of the mouse cursor.
virtual core::position2d<f32> getRelativePosition()
{
if (!UseReferenceRect)
{
return core::position2d<f32>(CursorPos.X * InvWindowSize.Width,
CursorPos.Y * InvWindowSize.Height);
}
return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(),
CursorPos.Y / (f32)ReferenceRect.getHeight());
}
//! Sets an absolute reference rect for calculating the cursor position.
virtual void setReferenceRect(core::rect<s32>* rect=0)
{
if (rect)
{
ReferenceRect = *rect;
UseReferenceRect = true;
// prevent division through zero and uneven sizes
if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2)
ReferenceRect.LowerRightCorner.Y += 1;
if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2)
ReferenceRect.LowerRightCorner.X += 1;
}
else
UseReferenceRect = false;
}
//! Updates the internal cursor position
void setInternalCursorPosition(const core::position2di &pos)
{
CursorPos = pos;
if (UseReferenceRect)
CursorPos -= ReferenceRect.UpperLeftCorner;
}
private:
core::position2d<s32> CursorPos;
core::dimension2d<u32> WindowSize;
core::dimension2d<f32> InvWindowSize;
bool IsVisible,
UseReferenceRect;
core::rect<s32> ReferenceRect;
};
private:
//! Set the position of the text caret
void setTextCursorPos(s16 x, s16 y);
// text to be added after drawing the screen
struct SPostPresentText
{
core::position2d<s16> Pos;
core::stringc Text;
};
bool IsWindowFocused;
core::array<core::stringc> OutputBuffer;
gui::IGUIFont *ConsoleFont;
core::array<SPostPresentText> Text;
FILE *OutFile;
#ifdef _IRR_WINDOWS_NT_CONSOLE_
HANDLE WindowsSTDIn, WindowsSTDOut;
u32 MouseButtonStates;
#endif
};
#ifdef _IRR_USE_CONSOLE_FONT_
namespace gui
{
class CGUIConsoleFont : public IGUIFont
{
public:
CGUIConsoleFont(CIrrDeviceConsole* device) : Device(device) { }
//! Draws some text and clips it to the specified rectangle if wanted.
virtual void draw(const wchar_t* text, const core::rect<s32>& position,
video::SColor color, bool hcenter=false, bool vcenter=false,
const core::rect<s32>* clip=0)
{
core::rect<s32> Area = clip ? *clip : position;
if (Area.UpperLeftCorner.X < 0)
Area.UpperLeftCorner.X = 0;
if (Area.UpperLeftCorner.Y < 0)
Area.UpperLeftCorner.Y = 0;
core::position2d<s16> pos;
// centre vertically
pos.Y = vcenter ? (position.UpperLeftCorner.Y + position.LowerRightCorner.Y) / 2 : position.UpperLeftCorner.Y;
// nothing to display?
if (pos.Y < Area.UpperLeftCorner.Y || pos.Y > Area.LowerRightCorner.Y)
return;
tempText = text;
// centre horizontally
pos.X = hcenter ? position.getCenter().X - ( tempText.size() / 2) : position.UpperLeftCorner.X;
// clip
u32 xlclip = 0,
xrclip = 0;
// get right clip
if (pos.X + (s32)tempText.size() > Area.LowerRightCorner.X)
xrclip = Area.LowerRightCorner.X - pos.X;
// get left clip
if (pos.X < Area.UpperLeftCorner.X)
xlclip = Area.UpperLeftCorner.X - pos.X;
// totally clipped?
if ((s32)tempText.size() - xlclip - xrclip < 0)
return;
// null terminate the string
if (xrclip > 0)
tempText[xrclip] = L'\0';
Device->addPostPresentText(pos.X + xlclip, pos.Y, &(tempText.c_str()[xlclip]));
}
//! Calculates the dimension of some text.
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const
{
return core::dimension2d<u32>(wcslen(text),1);
}
//! Calculates the index of the character in the text which is on a specific position.
virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const { return pixel_x; };
//! No kerning
virtual void setKerningWidth (s32 kerning) { }
virtual void setKerningHeight (s32 kerning) { }
virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const {return 0;}
virtual s32 getKerningHeight() const { return 0;}
virtual void setInvisibleCharacters( const wchar_t *s ) { }
// I guess this is an OS specific font
virtual EGUI_FONT_TYPE getType() const { return EGFT_OS; }
private:
CIrrDeviceConsole* Device;
core::stringw tempText;
};
} // end namespace gui
#endif // _IRR_USE_CONSOLE_FONT_
} // end namespace irr
#endif // _IRR_COMPILE_WITH_CONSOLE_DEVICE_
#endif // __C_IRR_DEVICE_CONSOLE_H_INCLUDED__

View File

@ -1,405 +0,0 @@
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// Copyright (C) 2007-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CIrrDeviceFB.h"
#ifdef _IRR_COMPILE_WITH_FB_DEVICE_
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/utsname.h>
#include <time.h>
#include <errno.h>
#include "IEventReceiver.h"
#include "os.h"
#include "CTimer.h"
#include "irrString.h"
#include "Keycodes.h"
#include "COSOperator.h"
#include "CColorConverter.h"
#include "SIrrCreationParameters.h"
#include <linux/input.h>
namespace irr
{
//! constructor
CIrrDeviceFB::CIrrDeviceFB(const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), Framebuffer(-1), EventDevice(-1), SoftwareImage(0),
Pitch(0), FBColorFormat(video::ECF_A8R8G8B8), Close(false)
{
#ifdef _DEBUG
setDebugName("CIrrDeviceFB");
#endif
// print version, distribution etc.
// thx to LynxLuna for pointing me to the uname function
core::stringc linuxversion;
struct utsname FBInfo;
uname(&FBInfo);
linuxversion += FBInfo.sysname;
linuxversion += " ";
linuxversion += FBInfo.release;
linuxversion += " ";
linuxversion += FBInfo.version;
linuxversion += " ";
linuxversion += FBInfo.machine;
Operator = new COSOperator(linuxversion);
os::Printer::log(linuxversion.c_str(), ELL_INFORMATION);
// create window
if (params.DriverType != video::EDT_NULL)
{
// create the window, only if we do not use the null device
if (!createWindow(params.WindowSize, params.Bits))
return;
}
// create cursor control
CursorControl = new CCursorControl(this, params.DriverType == video::EDT_NULL);
// create driver
createDriver();
if (!VideoDriver)
return;
createGUIAndScene();
}
//! destructor
CIrrDeviceFB::~CIrrDeviceFB()
{
if (SoftwareImage)
munmap(SoftwareImage, CreationParams.WindowSize.Height*Pitch);
// go back to previous format
if (ioctl(Framebuffer, FBIOPUT_VSCREENINFO, &oldscreeninfo) <0)
perror("Restoring old fb mode");
if (KeyboardDevice != -1)
if (ioctl(KeyboardDevice, KDSETMODE, &KeyboardMode) <0)
perror("Restoring keyboard mode");
if (EventDevice != -1)
close(EventDevice);
if (KeyboardDevice != -1)
close(KeyboardDevice);
if (Framebuffer != -1)
close(Framebuffer);
}
bool CIrrDeviceFB::createWindow(const core::dimension2d<u32>& windowSize, u32 bits)
{
char buf[256];
CreationParams.WindowSize.Width = windowSize.Width;
CreationParams.WindowSize.Height = windowSize.Height;
KeyboardDevice = open("/dev/tty", O_RDWR);
if (KeyboardDevice == -1)
perror("Open keyboard");
if (ioctl(KeyboardDevice, KDGETMODE, &KeyboardMode) <0)
perror("Read keyboard mode");
if (ioctl(KeyboardDevice, KDSETMODE, KD_GRAPHICS) <0)
perror("Set keyboard mode");
Framebuffer=open("/dev/fb/0", O_RDWR);
if (Framebuffer == -1)
{
Framebuffer=open("/dev/fb0", O_RDWR);
if (Framebuffer == -1)
{
perror("Open framebuffer");
return false;
}
}
EventDevice = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);
if (EventDevice == -1)
perror("Open event device");
// make format settings
ioctl(Framebuffer, FBIOGET_FSCREENINFO, &fbfixscreeninfo);
ioctl(Framebuffer, FBIOGET_VSCREENINFO, &oldscreeninfo);
snprintf(buf, 256, "Original resolution: %d x %d\nARGB%d%d%d%d\n",oldscreeninfo.xres,oldscreeninfo.yres,
oldscreeninfo.transp.length,oldscreeninfo.red.length,oldscreeninfo.green.length,oldscreeninfo.blue.length);
os::Printer::log(buf);
memcpy(&fbscreeninfo, &oldscreeninfo, sizeof(struct fb_var_screeninfo));
if (CreationParams.DriverType != video::EDT_NULL)
{
fbscreeninfo.xres = fbscreeninfo.xres_virtual = CreationParams.WindowSize.Width;
fbscreeninfo.yres = fbscreeninfo.yres_virtual = CreationParams.WindowSize.Height;
fbscreeninfo.bits_per_pixel = 16;
fbscreeninfo.red.offset = 10;
fbscreeninfo.red.length = 5;
fbscreeninfo.green.offset = 5;
fbscreeninfo.green.length = 5;
fbscreeninfo.blue.offset = 0;
fbscreeninfo.blue.length = 5;
fbscreeninfo.transp.offset = 15;
fbscreeninfo.transp.length = 1;
ioctl(Framebuffer, FBIOPUT_VSCREENINFO, &fbscreeninfo);
ioctl(Framebuffer, FBIOGET_VSCREENINFO, &fbscreeninfo);
snprintf(buf, 256, "New resolution: %d x %d (%d x %d)\nARGB%d%d%d%d\n",fbscreeninfo.xres,fbscreeninfo.yres,fbscreeninfo.xres_virtual,fbscreeninfo.yres_virtual,
fbscreeninfo.transp.length,fbscreeninfo.red.length,fbscreeninfo.green.length,fbscreeninfo.blue.length);
os::Printer::log(buf);
CreationParams.WindowSize.Width = fbscreeninfo.xres;
CreationParams.WindowSize.Height = fbscreeninfo.yres;
CreationParams.Bits = fbscreeninfo.bits_per_pixel;
Pitch = fbfixscreeninfo.line_length;
if (fbscreeninfo.bits_per_pixel == 16)
{
if (fbscreeninfo.transp.length == 0)
FBColorFormat = video::ECF_R5G6B5;
else
FBColorFormat = video::ECF_A1R5G5B5;
}
else
{
if (fbscreeninfo.transp.length == 0)
FBColorFormat = video::ECF_R8G8B8;
else
FBColorFormat = video::ECF_A8R8G8B8;
}
if (MAP_FAILED==(SoftwareImage=(u8*)mmap(0, CreationParams.WindowSize.Height*Pitch, PROT_READ|PROT_WRITE, MAP_SHARED, Framebuffer, 0)))
{
perror("mmap render target");
return false;
}
}
return true;
}
//! create the driver
void CIrrDeviceFB::createDriver()
{
switch(CreationParams.DriverType)
{
case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("No Software driver support compiled in.", ELL_WARNING);
#endif
break;
case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);
#else
os::Printer::log("Burning's video driver was not compiled in.", ELL_WARNING);
#endif
break;
case video::EDT_OPENGL:
case video::EDT_DIRECT3D8:
case video::EDT_DIRECT3D9:
os::Printer::log("This driver is not available in FB. Try Software renderer.",
ELL_WARNING);
break;
default:
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break;
}
}
//! runs the device. Returns false if device wants to be deleted
bool CIrrDeviceFB::run()
{
os::Timer::tick();
struct input_event ev;
if (EventDevice>=0)
{
if ((read(EventDevice, &ev, sizeof(input_event)) < 0) &&
errno != EAGAIN)
perror("Read input event");
if (ev.type == EV_KEY)
{
irr::SEvent irrevent;
irrevent.EventType = irr::EET_KEY_INPUT_EVENT;
irrevent.KeyInput.PressedDown = true;
switch (ev.code)
{
case IRR_KEY_RIGHTCTRL:
case IRR_KEY_LEFTCTRL:
irrevent.KeyInput.Control = true;
break;
case IRR_KEY_RIGHTSHIFT:
case IRR_KEY_LEFTSHIFT:
irrevent.KeyInput.Shift = true;
break;
case IRR_KEY_ESC:
irrevent.KeyInput.Key = (EKEY_CODE)0x1B;
break;
case IRR_KEY_SPACE:
irrevent.KeyInput.Key = (EKEY_CODE)0x20;
break;
case IRR_KEY_UP:
irrevent.KeyInput.Key = (EKEY_CODE)0x26;
break;
case IRR_KEY_LEFT:
irrevent.KeyInput.Key = (EKEY_CODE)0x25;
break;
case IRR_KEY_RIGHT:
irrevent.KeyInput.Key = (EKEY_CODE)0x27;
break;
case IRR_KEY_DOWN:
irrevent.KeyInput.Key = (EKEY_CODE)0x28;
break;
default:
irrevent.KeyInput.Key = (EKEY_CODE)0;
break;
}
postEventFromUser(irrevent);
}
}
return !Close;
}
//! Pause the current process for the minimum time allowed only to allow other processes to execute
void CIrrDeviceFB::yield()
{
struct timespec ts = {0,0};
nanosleep(&ts, NULL);
}
//! Pause execution and let other processes to run for a specified amount of time.
void CIrrDeviceFB::sleep(u32 timeMs, bool pauseTimer=false)
{
bool wasStopped = Timer ? Timer->isStopped() : true;
struct timespec ts;
ts.tv_sec = (time_t) (timeMs / 1000);
ts.tv_nsec = (long) (timeMs % 1000) * 1000000;
if (pauseTimer && !wasStopped)
Timer->stop();
nanosleep(&ts, NULL);
if (pauseTimer && !wasStopped)
Timer->start();
}
//! presents a surface in the client area
bool CIrrDeviceFB::present(video::IImage* image, void* windowId, core::rect<s32>* src )
{
// this is only necessary for software drivers.
if (CreationParams.DriverType != video::EDT_SOFTWARE && CreationParams.DriverType != video::EDT_BURNINGSVIDEO)
return false;
if (!SoftwareImage)
return false;
u8* destData = SoftwareImage;
u32 srcwidth = (u32)image->getDimension().Width;
u32 srcheight = (u32)image->getDimension().Height;
// clip images
srcheight = core::min_(srcheight, CreationParams.WindowSize.Height);
srcwidth = core::min_(srcwidth, CreationParams.WindowSize.Width);
u8* srcdata = (u8*)image->lock();
for (u32 y=0; y<srcheight; ++y)
{
video::CColorConverter::convert_viaFormat(srcdata, image->getColorFormat(), srcwidth, destData, FBColorFormat);
srcdata+=image->getPitch();
destData+=Pitch;
}
image->unlock();
msync(SoftwareImage,CreationParams.WindowSize.Width*CreationParams.WindowSize.Height,MS_ASYNC);
return true;
}
//! notifies the device that it should close itself
void CIrrDeviceFB::closeDevice()
{
Close = true;
}
//! returns if window is active. if not, nothing need to be drawn
bool CIrrDeviceFB::isWindowActive() const
{
return true;
}
//! returns if window has focus
bool CIrrDeviceFB::isWindowFocused() const
{
return true;
}
//! returns if window is minimized
bool CIrrDeviceFB::isWindowMinimized() const
{
return false;
}
//! sets the caption of the window
void CIrrDeviceFB::setWindowCaption(const wchar_t* text)
{
}
//! Sets if the window should be resizeable in windowed mode.
void CIrrDeviceFB::setResizable(bool resize)
{
}
//! Minimizes window
void CIrrDeviceFB::minimizeWindow()
{
}
//! Maximizes window
void CIrrDeviceFB::maximizeWindow()
{
}
//! Restores original window size
void CIrrDeviceFB::restoreWindow()
{
}
//! Returns the type of this device
E_DEVICE_TYPE CIrrDeviceFB::getType() const
{
return EIDT_FRAMEBUFFER;
}
} // end namespace irr
#endif // _IRR_USE_FB_DEVICE_

View File

@ -1,210 +0,0 @@
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// Copyright (C) 2007-2012 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IRR_DEVICE_FB_H_INCLUDED__
#define __C_IRR_DEVICE_FB_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_FB_DEVICE_
#include "CIrrDeviceStub.h"
#include "SIrrCreationParameters.h"
#include "IrrlichtDevice.h"
#include "IImagePresenter.h"
#include "ICursorControl.h"
#define KeySym s32
#include <linux/fb.h>
#include <linux/kd.h>
namespace irr
{
class CIrrDeviceFB : public CIrrDeviceStub, public video::IImagePresenter
{
public:
//! constructor
CIrrDeviceFB(const SIrrlichtCreationParameters& params);
//! destructor
virtual ~CIrrDeviceFB();
//! runs the device. Returns false if device wants to be deleted
virtual bool run();
//! Cause the device to temporarily pause execution and let other processes to run
// This should bring down processor usage without major performance loss for Irrlicht
virtual void yield();
//! Pause execution and let other processes to run for a specified amount of time.
virtual void sleep(u32 timeMs, bool pauseTimer);
//! sets the caption of the window
virtual void setWindowCaption(const wchar_t* text);
//! sets the class of the window
virtual void setWindowClass(const char* text) {}
//! returns if window is active. if not, nothing need to be drawn
virtual bool isWindowActive() const;
//! returns if window has focus
virtual bool isWindowFocused() const;
//! returns if window is minimized
virtual bool isWindowMinimized() const;
//! Minimizes window
virtual void minimizeWindow();
//! Maximizes window
virtual void maximizeWindow();
//! Restores original window size
virtual void restoreWindow();
//! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId = 0, core::rect<s32>* src=0 );
//! notifies the device that it should close itself
virtual void closeDevice();
//! Sets if the window should be resizeable in windowed mode.
virtual void setResizable(bool resize=false);
//! Returns the type of this device
virtual E_DEVICE_TYPE getType() const;
private:
//! create the driver
void createDriver();
bool createWindow(const core::dimension2d<u32>& windowSize, u32 bits);
//! Implementation of the cursor control
class CCursorControl : public gui::ICursorControl
{
public:
CCursorControl(CIrrDeviceFB* dev, bool null)
: Device(dev), IsVisible(true), Null(null)
{
Device->grab();
}
~CCursorControl()
{
Device->drop();
}
//! Changes the visible state of the mouse cursor.
virtual void setVisible(bool visible)
{
IsVisible = visible;
}
//! Returns if the cursor is currently visible.
virtual bool isVisible() const
{
return IsVisible;
}
//! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<f32> &pos)
{
setPosition(pos.X, pos.Y);
}
//! Sets the new position of the cursor.
virtual void setPosition(f32 x, f32 y)
{
setPosition((s32)(x*Device->CreationParams.WindowSize.Width), (s32)(y*Device->CreationParams.WindowSize.Height));
}
//! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<s32> &pos)
{
setPosition(pos.X, pos.Y);
}
//! Sets the new position of the cursor.
virtual void setPosition(s32 x, s32 y)
{
}
//! Returns the current position of the mouse cursor.
virtual const core::position2d<s32>& getPosition()
{
updateCursorPos();
return CursorPos;
}
//! Returns the current position of the mouse cursor.
virtual core::position2d<f32> getRelativePosition()
{
updateCursorPos();
return core::position2d<f32>(CursorPos.X / (f32)Device->CreationParams.WindowSize.Width,
CursorPos.Y / (f32)Device->CreationParams.WindowSize.Height);
}
virtual void setReferenceRect(core::rect<s32>* rect=0)
{
}
private:
void updateCursorPos()
{
}
core::position2d<s32> CursorPos;
CIrrDeviceFB* Device;
bool IsVisible;
bool Null;
};
friend class CCursorControl;
int Framebuffer;
int EventDevice;
int KeyboardDevice;
struct fb_fix_screeninfo fbfixscreeninfo;
struct fb_var_screeninfo fbscreeninfo;
struct fb_var_screeninfo oldscreeninfo;
long KeyboardMode;
u8* SoftwareImage;
u32 Pitch;
video::ECOLOR_FORMAT FBColorFormat;
bool Close;
struct SKeyMap
{
SKeyMap() {}
SKeyMap(s32 x11, s32 win32)
: X11Key(x11), Win32Key(win32)
{
}
KeySym X11Key;
s32 Win32Key;
bool operator<(const SKeyMap& o) const
{
return X11Key<o.X11Key;
}
};
core::array<SKeyMap> KeyMap;
};
} // end namespace irr
#endif // _IRR_USE_FB_DEVICE_
#endif // __C_IRR_DEVICE_FB_H_INCLUDED__

View File

@ -277,7 +277,7 @@ bool CIrrDeviceLinux::restoreResolution()
}
#endif
#ifdef _IRR_LINUX_X11_RANDR_
if (UseXRandR && CreationParams.Fullscreen && old_mode != BadRRMode)
if (UseXRandR && CreationParams.Fullscreen && old_mode != 0)
{
XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display));
if (!res)
@ -385,7 +385,7 @@ bool CIrrDeviceLinux::changeResolution()
#ifdef _IRR_LINUX_X11_RANDR_
while (XRRQueryExtension(display, &eventbase, &errorbase))
{
if (output_id == BadRROutput)
if (output_id == 0)
break;
XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display));
@ -2057,8 +2057,8 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList()
}
#endif
#ifdef _IRR_LINUX_X11_RANDR_
output_id = BadRROutput;
old_mode = BadRRMode;
output_id = 0;
old_mode = 0;
while (XRRQueryExtension(display, &eventbase, &errorbase))
{
@ -2089,7 +2089,7 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList()
}
if (res->outputs[i] == primary_id ||
output_id == BadRROutput || crtc_tmp->x < crtc->x ||
output_id == 0 || crtc_tmp->x < crtc->x ||
(crtc_tmp->x == crtc->x && crtc_tmp->y < crtc->y))
{
XRRFreeCrtcInfo(crtc);
@ -2109,7 +2109,7 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList()
break;
}
if (output_id == BadRROutput)
if (output_id == 0)
{
os::Printer::log("Could not get video output.", ELL_WARNING);
break;
@ -2194,6 +2194,101 @@ void CIrrDeviceLinux::restoreWindow()
#endif
}
/*
Returns the parent window of "window" (i.e. the ancestor of window
that is a direct child of the root, or window itself if it is a direct child).
If window is the root window, returns window.
*/
bool get_toplevel_parent(Display* display, Window window, Window* tp_window)
{
#ifdef _IRR_COMPILE_WITH_X11_
Window current_window = window;
Window parent;
Window root;
Window* children;
unsigned int num_children;
while (true)
{
bool success = XQueryTree(display, current_window, &root,
&parent, &children, &num_children);
if (!success)
{
os::Printer::log("XQueryTree error", ELL_ERROR);
return false;
}
if (children)
{
XFree(children);
}
if (current_window == root || parent == root)
{
*tp_window = current_window;
return true;
}
else
{
current_window = parent;
}
}
#endif
return false;
}
//! Move window to requested position
bool CIrrDeviceLinux::moveWindow(int x, int y)
{
#ifdef _IRR_COMPILE_WITH_X11_
if (CreationParams.DriverType == video::EDT_NULL || CreationParams.Fullscreen)
return false;
int display_width = XDisplayWidth(display, screennr);
int display_height = XDisplayHeight(display, screennr);
core::min_(x, display_width - (int)Width);
core::min_(y, display_height - (int)Height);
XMoveWindow(display, window, x, y);
return true;
#endif
return false;
}
//! Get current window position.
bool CIrrDeviceLinux::getWindowPosition(int* x, int* y)
{
#ifdef _IRR_COMPILE_WITH_X11_
if (CreationParams.DriverType == video::EDT_NULL || CreationParams.Fullscreen)
return false;
Window tp_window;
bool success = get_toplevel_parent(display, window, &tp_window);
if (!success)
return false;
XWindowAttributes xwa;
success = XGetWindowAttributes(display, tp_window, &xwa);
if (!success)
return false;
*x = xwa.x;
*y = xwa.y;
return true;
#endif
return false;
}
void CIrrDeviceLinux::createKeyMap()
{

View File

@ -99,6 +99,12 @@ namespace irr
//! Restores the window size.
virtual void restoreWindow();
//! Move window to requested position
virtual bool moveWindow(int x, int y);
//! Get current window position.
virtual bool getWindowPosition(int* x, int* y);
//! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -761,6 +761,18 @@ void CIrrDeviceSDL::restoreWindow()
// do nothing
}
//! Move window to requested position
bool CIrrDeviceSDL::moveWindow(int x, int y)
{
return false;
}
//! Get current window position.
bool CIrrDeviceSDL::getWindowPosition(int* x, int* y)
{
return false;
}
//! returns if window is active. if not, nothing need to be drawn
bool CIrrDeviceSDL::isWindowActive() const

View File

@ -79,6 +79,12 @@ namespace irr
//! Restores the window size.
virtual void restoreWindow();
//! Move window to requested position
virtual bool moveWindow(int x, int y);
//! Get current window position.
virtual bool getWindowPosition(int* x, int* y);
//! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -794,6 +794,7 @@ bool CIrrDeviceWayland::initEGL()
egl_params.surface_type = CEGL_SURFACE_WINDOW;
egl_params.force_legacy_device = CreationParams.ForceLegacyDevice;
egl_params.handle_srgb = CreationParams.HandleSRGB;
egl_params.with_alpha_channel = CreationParams.WithAlphaChannel;
egl_params.vsync_enabled = CreationParams.Vsync;
egl_params.window = m_egl_window;
@ -1072,6 +1073,18 @@ void CIrrDeviceWayland::restoreWindow()
{
}
//! Move window to requested position
bool CIrrDeviceWayland::moveWindow(int x, int y)
{
return false;
}
//! Get current window position.
bool CIrrDeviceWayland::getWindowPosition(int* x, int* y)
{
return false;
}
//! Set the current Gamma Value for the Display
bool CIrrDeviceWayland::setGammaRamp(f32 red, f32 green, f32 blue,
f32 brightness, f32 contrast)

View File

@ -104,6 +104,12 @@ namespace irr
//! Restores the window size.
virtual void restoreWindow();
//! Move window to requested position
virtual bool moveWindow(int x, int y);
//! Get current window position.
virtual bool getWindowPosition(int* x, int* y);
//! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo);

View File

@ -2131,6 +2131,38 @@ void CIrrDeviceWin32::restoreWindow()
SetWindowPlacement(HWnd, &wndpl);
}
//! Move window to requested position
bool CIrrDeviceWin32::moveWindow(int x, int y)
{
if (CreationParams.DriverType == video::EDT_NULL || CreationParams.Fullscreen)
return false;
bool success = SetWindowPos(HWnd, HWND_TOP, x, y, -1, -1,
SWP_NOOWNERZORDER | SWP_NOSIZE);
return success;
}
//! Get current window position.
bool CIrrDeviceWin32::getWindowPosition(int* x, int* y)
{
if (CreationParams.DriverType == video::EDT_NULL || CreationParams.Fullscreen)
return false;
WINDOWPLACEMENT placement;
placement.length = sizeof(WINDOWPLACEMENT);
bool success = GetWindowPlacement(HWnd, &placement);
if (!success)
return false;
*x = (int)placement.rcNormalPosition.left;
*y = (int)placement.rcNormalPosition.top;
return true;
}
bool CIrrDeviceWin32::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
{

View File

@ -87,6 +87,12 @@ namespace irr
//! Restores the window size.
virtual void restoreWindow();
//! Move window to requested position
virtual bool moveWindow(int x, int y);
//! Get current window position.
virtual bool getWindowPosition(int* x, int* y);
//! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -69,6 +69,7 @@ namespace video
ContextEGLParams egl_params;
egl_params.opengl_api = CEGL_API_OPENGL_ES;
egl_params.surface_type = CEGL_SURFACE_WINDOW;
egl_params.handle_srgb = Params.HandleSRGB;
egl_params.force_legacy_device = Params.ForceLegacyDevice;
egl_params.with_alpha_channel = Params.WithAlphaChannel;
egl_params.vsync_enabled = Params.Vsync;
@ -2885,7 +2886,7 @@ namespace irr
namespace video
{
#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) && (defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_SDL_DEVICE_) || defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_CONSOLE_DEVICE_))
#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) && (defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_SDL_DEVICE_) || defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_))
IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params,
video::SExposedVideoData& data, io::IFileSystem* io)
{

View File

@ -59,7 +59,7 @@ namespace video
friend class COGLES2Texture;
public:
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_SDL_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_CONSOLE_DEVICE_)
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_SDL_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
COGLES2Driver(const SIrrlichtCreationParameters& params,
const SExposedVideoData& data,
io::IFileSystem* io);

View File

@ -77,7 +77,10 @@ IMesh* CSkinnedMesh::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32
{
const bool is_hw_skinning_before = HardwareSkinning;
if (is_hw_skinning_before)
{
HardwareSkinning = false;
LastAnimatedFrame = -1;
}
//animate(frame,startFrameLoop, endFrameLoop);
if (frame==-1)
return this;

View File

@ -22,10 +22,6 @@
#include "MacOSX/CIrrDeviceMacOSX.h"
#endif
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
#include "CIrrDeviceWinCE.h"
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#include "CIrrDeviceWayland.h"
#endif
@ -38,14 +34,6 @@
#include "CIrrDeviceSDL.h"
#endif
#ifdef _IRR_COMPILE_WITH_FB_DEVICE_
#include "CIrrDeviceFB.h"
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
#include "CIrrDeviceConsole.h"
#endif
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
#include "CIrrDeviceAndroid.h"
#include <android/log.h>
@ -94,12 +82,6 @@ namespace irr
device_type = EIDT_OSX;
}
#endif
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
if (strcmp(irr_device_type, "wince") == 0)
{
device_type = EIDT_WINCE;
}
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
if (strcmp(irr_device_type, "wayland") == 0)
{
@ -118,23 +100,11 @@ namespace irr
device_type = EIDT_SDL;
}
#endif
#ifdef _IRR_COMPILE_WITH_FB_DEVICE_
if (strcmp(irr_device_type, "framebuffer") == 0)
{
device_type = EIDT_FRAMEBUFFER;
}
#endif
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
if (strcmp(irr_device_type, "android") == 0)
{
device_type = EIDT_ANDROID;
}
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
if (strcmp(irr_device_type, "console") == 0)
{
device_type = EIDT_CONSOLE;
}
#endif
}
@ -156,11 +126,6 @@ namespace irr
dev = new CIrrDeviceMacOSX(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
if (creation_params.DeviceType == EIDT_WINCE || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWinCE(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
if (creation_params.DeviceType == EIDT_WAYLAND || (!dev && creation_params.DeviceType == EIDT_BEST))
{
@ -181,21 +146,11 @@ namespace irr
dev = new CIrrDeviceSDL(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_FB_DEVICE_
if (creation_params.DeviceType == EIDT_FRAMEBUFFER || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceFB(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
if (creation_params.DeviceType == EIDT_ANDROID || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceAndroid(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
if (creation_params.DeviceType == EIDT_CONSOLE || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceConsole(creation_params);
#endif
if (dev && !dev->getVideoDriver() && creation_params.DriverType != video::EDT_NULL)
{
dev->closeDevice(); // destroy window

View File

@ -83,6 +83,12 @@ namespace irr
//! Restore the window to normal size if possible.
virtual void restoreWindow();
//! Move window to requested position
virtual bool moveWindow(int x, int y);
//! Get current window position.
virtual bool getWindowPosition(int* x, int* y);
//! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);

View File

@ -1528,6 +1528,18 @@ void CIrrDeviceMacOSX::restoreWindow()
[Window deminiaturize:[NSApp self]];
}
//! Move window to requested position
bool CIrrDeviceMacOSX::moveWindow(int x, int y)
{
return false;
}
//! Get current window position.
bool CIrrDeviceMacOSX::getWindowPosition(int* x, int* y)
{
return false;
}
bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src )
{

View File

@ -23,6 +23,7 @@
#include "karts/abstract_kart.hpp"
#include "karts/explosion_animation.hpp"
#include "karts/kart.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/skidding.hpp"
#include "physics/btKart.hpp"

View File

@ -91,15 +91,6 @@ please use the included version."
using namespace irr;
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#if defined(__linux__) && !defined(ANDROID)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#endif
/** singleton */
IrrDriver *irr_driver = NULL;
@ -228,45 +219,6 @@ std::unique_ptr<RenderTarget> IrrDriver::createRenderTarget(const irr::core::dim
} // createRenderTarget
#endif // ~SERVER_ONLY
// ----------------------------------------------------------------------------
#if defined(__linux__) && !defined(ANDROID)
/*
Returns the parent window of "window" (i.e. the ancestor of window
that is a direct child of the root, or window itself if it is a direct child).
If window is the root window, returns window.
*/
Window get_toplevel_parent(Display* display, Window window)
{
#ifndef SERVER_ONLY
Window parent;
Window root;
Window * children;
unsigned int num_children;
while (true)
{
if (0 == XQueryTree(display, window, &root,
&parent, &children, &num_children))
{
Log::fatal("irr_driver", "XQueryTree error\n");
}
if (children) { //must test for null
XFree(children);
}
if (window == root || parent == root) {
return window;
}
else {
window = parent;
}
}
#else
return NULL;
#endif
}
#endif
// ----------------------------------------------------------------------------
/** If the position of the window should be remembered, store it in the config
* file.
@ -278,61 +230,26 @@ void IrrDriver::updateConfigIfRelevant()
if (!UserConfigParams::m_fullscreen &&
UserConfigParams::m_remember_window_location)
{
#ifdef WIN32
const video::SExposedVideoData& videoData = m_device->getVideoDriver()
->getExposedVideoData();
// this should work even if using DirectX in theory because the HWnd is
// always third pointer in the struct, no matter which union is used
HWND window = (HWND)videoData.OpenGLWin32.HWnd;
WINDOWPLACEMENT placement;
placement.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(window, &placement))
int x = 0;
int y = 0;
bool success = m_device->getWindowPosition(&x, &y);
if (!success)
{
int x = (int)placement.rcNormalPosition.left;
int y = (int)placement.rcNormalPosition.top;
// If the windows position is saved, it must be a non-negative
// number. So if the window is partly off screen, move it to the
// corresponding edge.
if(x<0) x = 0;
if(y<0) y = 0;
Log::verbose("irr_driver",
"Retrieved window location for config : %i %i\n", x, y);
if (UserConfigParams::m_window_x != x || UserConfigParams::m_window_y != y)
{
UserConfigParams::m_window_x = x;
UserConfigParams::m_window_y = y;
}
Log::warn("irr_driver", "Could not retrieve window location");
return;
}
else
{
Log::warn("irr_driver", "Could not retrieve window location\n");
}
#elif defined(__linux__) && !defined(ANDROID)
if (m_device->getType() == EIDT_X11)
{
const video::SExposedVideoData& videoData =
m_device->getVideoDriver()->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
XWindowAttributes xwa;
XGetWindowAttributes(display, get_toplevel_parent(display,
videoData.OpenGLLinux.X11Window), &xwa);
int wx = xwa.x;
int wy = xwa.y;
Log::verbose("irr_driver",
"Retrieved window location for config : %i %i\n", wx, wy);
if (UserConfigParams::m_window_x != wx ||
UserConfigParams::m_window_y != wy)
{
UserConfigParams::m_window_x = wx;
UserConfigParams::m_window_y = wy;
}
}
#endif
Log::verbose("irr_driver", "Retrieved window location for config: "
"%i %i", x, y);
// If the windows position is saved, it must be a non-negative
// number. So if the window is partly off screen, move it to the
// corresponding edge.
UserConfigParams::m_window_x = std::max(0, x);
UserConfigParams::m_window_y = std::max(0, y);
}
#endif // !SERVER_ONLY
} // updateConfigIfRelevant
@ -867,49 +784,13 @@ core::position2di IrrDriver::getMouseLocation()
bool IrrDriver::moveWindow(int x, int y)
{
#ifndef SERVER_ONLY
#ifdef WIN32
const video::SExposedVideoData& videoData =
m_video_driver->getExposedVideoData();
// this should work even if using DirectX in theory,
// because the HWnd is always third pointer in the struct,
// no matter which union is used
HWND window = (HWND)videoData.OpenGLWin32.HWnd;
if (SetWindowPos(window, HWND_TOP, x, y, -1, -1,
SWP_NOOWNERZORDER | SWP_NOSIZE))
{
// everything OK
return true;
}
else
bool success = m_device->moveWindow(x, y);
if (!success)
{
Log::warn("irr_driver", "Could not set window location\n");
return false;
}
#elif defined(__linux__) && !defined(ANDROID)
if (m_device->getType() == EIDT_X11)
{
const video::SExposedVideoData& videoData =
m_video_driver->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
int screen = DefaultScreen(display);
int screen_w = DisplayWidth(display, screen);
int screen_h = DisplayHeight(display, screen);
if (x + UserConfigParams::m_width > screen_w)
{
x = screen_w - UserConfigParams::m_width;
}
if (y + UserConfigParams::m_height > screen_h)
{
y = screen_h - UserConfigParams::m_height;
}
// TODO: Actually handle possible failure
XMoveWindow(display, videoData.OpenGLLinux.X11Window, x, y);
}
#endif
#endif
return true;
}

View File

@ -65,15 +65,15 @@ void IconButtonWidget::add()
// ---- Icon
if (m_texture == NULL)
{
if (m_icon_path_type == ICON_PATH_TYPE_ABSOLUTE)
// Avoid warning about missing texture in case of e.g.
// screenshot widget
if (m_properties[PROP_ICON] != "")
{
setTexture(irr_driver->getTexture(m_properties[PROP_ICON]));
}
else if (m_icon_path_type == ICON_PATH_TYPE_RELATIVE)
{
// Avoid warning about missing texture in case of e.g.
// screenshot widget
if(m_properties[PROP_ICON] != "")
if (m_icon_path_type == ICON_PATH_TYPE_ABSOLUTE)
{
setTexture(irr_driver->getTexture(m_properties[PROP_ICON]));
}
else if (m_icon_path_type == ICON_PATH_TYPE_RELATIVE)
{
std::string file = file_manager->getAsset(m_properties[PROP_ICON]);
setTexture(irr_driver->getTexture(file));

View File

@ -89,10 +89,10 @@ void ModelViewWidget::clearModels()
{
m_models.clearWithoutDeleting();
m_model_location.clear();
m_model_scale.clear();
m_model_frames.clear();
m_model_render_info_affected.clear();
m_model_animation_speed.clear();
m_bone_attached.clear();
if (m_rtt_main_node != NULL) m_rtt_main_node->remove();
if (m_light != NULL) m_light->remove();
@ -106,19 +106,21 @@ void ModelViewWidget::clearModels()
// -----------------------------------------------------------------------------
void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location,
const Vec3& scale, const int start_loop_frame,
void ModelViewWidget::addModel(irr::scene::IMesh* mesh,
const core::matrix4& location,
const int start_loop_frame,
const int end_loop_frame,
bool all_parts_colorized, float animation_speed)
bool all_parts_colorized, float animation_speed,
const std::string& bone_name)
{
if(!mesh) return;
m_models.push_back(mesh);
m_model_location.push_back(location);
m_model_scale.push_back(scale);
m_model_frames.emplace_back(start_loop_frame, end_loop_frame);
m_model_render_info_affected.push_back(all_parts_colorized);
m_model_animation_speed.push_back(animation_speed);
m_bone_attached.push_back(bone_name);
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
m_render_target = NULL;
@ -219,59 +221,69 @@ void ModelViewWidget::setupRTTScene()
m_light = NULL;
irr_driver->clearLights();
scene::IAnimatedMeshSceneNode* animated_node = NULL;
if (m_model_frames[0].first == -1)
{
scene::ISceneNode* node = irr_driver->addMesh(m_models.get(0), "rtt_mesh",
NULL, m_render_info, m_model_render_info_affected[0]);
node->setPosition(m_model_location[0].toIrrVector());
node->setScale(m_model_scale[0].toIrrVector());
node->setPosition(m_model_location[0].getTranslation());
node->setRotation(m_model_location[0].getRotationDegrees());
node->setScale(m_model_location[0].getScale());
node->setMaterialFlag(video::EMF_FOG_ENABLE, false);
m_rtt_main_node = node;
}
else
{
scene::IAnimatedMeshSceneNode* node =
animated_node =
irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)m_models.get(0), "rtt_mesh",
NULL, m_render_info, m_model_render_info_affected[0]);
node->setPosition(m_model_location[0].toIrrVector());
node->setFrameLoop(m_model_frames[0].first, m_model_frames[0].second);
node->setAnimationSpeed(m_model_animation_speed[0]);
node->setScale(m_model_scale[0].toIrrVector());
node->setMaterialFlag(video::EMF_FOG_ENABLE, false);
m_rtt_main_node = node;
animated_node->setPosition(m_model_location[0].getTranslation());
animated_node->setRotation(m_model_location[0].getRotationDegrees());
animated_node->setScale(m_model_location[0].getScale());
animated_node->setFrameLoop(m_model_frames[0].first, m_model_frames[0].second);
animated_node->setAnimationSpeed(m_model_animation_speed[0]);
animated_node->setMaterialFlag(video::EMF_FOG_ENABLE, false);
m_rtt_main_node = animated_node;
}
assert(m_rtt_main_node != NULL);
assert(m_models.size() == m_model_location.size());
assert(m_models.size() == m_model_frames.size());
assert(m_models.size() == m_model_scale.size());
assert(m_models.size() == m_model_render_info_affected.size());
assert(m_models.size() == m_model_animation_speed.size());
assert(m_models.size() == m_bone_attached.size());
const int mesh_amount = m_models.size();
for (int n = 1; n<mesh_amount; n++)
for (int n = 1; n < mesh_amount; n++)
{
const bool bone_attachment =
animated_node && !m_bone_attached[n].empty();
scene::ISceneNode* parent = bone_attachment ?
animated_node->getJointNode(m_bone_attached[n].c_str()) :
m_rtt_main_node;
assert(parent);
if (m_model_frames[n].first == -1)
{
scene::ISceneNode* node =
irr_driver->addMesh(m_models.get(n), "rtt_node", m_rtt_main_node,
irr_driver->addMesh(m_models.get(n), "rtt_node", parent,
m_render_info, m_model_render_info_affected[n]);
node->setPosition(m_model_location[n].toIrrVector());
node->setPosition(m_model_location[n].getTranslation());
node->setRotation(m_model_location[n].getRotationDegrees());
node->setScale(m_model_location[n].getScale());
node->updateAbsolutePosition();
node->setScale(m_model_scale[n].toIrrVector());
}
else
{
scene::IAnimatedMeshSceneNode* node =
irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)m_models.get(n),
"modelviewrtt", m_rtt_main_node, m_render_info,
"modelviewrtt", parent, m_render_info,
m_model_render_info_affected[n]);
node->setPosition(m_model_location[n].toIrrVector());
node->setPosition(m_model_location[n].getTranslation());
node->setRotation(m_model_location[n].getRotationDegrees());
node->setScale(m_model_location[n].getScale());
node->setFrameLoop(m_model_frames[n].first, m_model_frames[n].second);
node->setAnimationSpeed(m_model_animation_speed[n]);
node->updateAbsolutePosition();
node->setScale(m_model_scale[n].toIrrVector());
//Log::info("ModelViewWidget", "Set frame %d", m_model_frames[n]);
}
}

View File

@ -48,11 +48,11 @@ namespace GUIEngine
float m_rotation_target;
PtrVector<scene::IMesh, REF> m_models;
AlignedArray<Vec3> m_model_location;
AlignedArray<Vec3> m_model_scale;
std::vector<core::matrix4> m_model_location;
std::vector<std::pair<int, int> > m_model_frames;
std::vector<bool> m_model_render_info_affected;
std::vector<float> m_model_animation_speed;
std::vector<std::string> m_bone_attached;
std::unique_ptr<RenderTarget> m_render_target;
float m_angle;
@ -76,12 +76,12 @@ namespace GUIEngine
void add();
void clearModels();
void addModel(irr::scene::IMesh* mesh,
const Vec3& location = Vec3(0,0,0),
const Vec3& scale = Vec3(1,1,1),
const core::matrix4& location = core::matrix4(),
const int start_loop_frame=-1,
const int end_loop_frame=-1,
bool all_parts_colorized = false,
float animation_speed=0.0f);
float animation_speed = 0.0f,
const std::string& bone_name = std::string());
void update(float delta);

View File

@ -24,6 +24,7 @@
#include "guiengine/widgets/model_view_widget.hpp"
#include "guiengine/widgets/player_name_spinner.hpp"
#include "input/input_device.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "network/network_player_profile.hpp"
@ -193,6 +194,8 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
scale = 30.0f;
}
core::matrix4 model_location;
model_location.setScale(core::vector3df(scale, scale, scale));
const bool has_win_anime =
UserConfigParams::m_show_steering_animations != 0 &&
(((kart_model.getFrame(KartModel::AF_WIN_LOOP_START) > -1 ||
@ -200,8 +203,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
kart_model.getFrame(KartModel::AF_WIN_END) > -1) ||
(kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 &&
kart_model.getFrame(KartModel::AF_SELECTION_END) > -1));
m_model_view->addModel( kart_model.getModel(), Vec3(0,0,0),
Vec3(scale, scale, scale),
m_model_view->addModel( kart_model.getModel(), model_location,
has_win_anime ?
kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 ?
kart_model.getFrame(KartModel::AF_SELECTION_START) :
@ -216,18 +218,27 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
kart_model.getBaseFrame(),
false/*all_parts_colorized*/,
kart_model.getAnimationSpeed());
m_model_view->addModel( kart_model.getWheelModel(0),
kart_model.getWheelGraphicsPosition(0) );
m_model_view->addModel( kart_model.getWheelModel(1),
kart_model.getWheelGraphicsPosition(1) );
m_model_view->addModel( kart_model.getWheelModel(2),
kart_model.getWheelGraphicsPosition(2) );
m_model_view->addModel( kart_model.getWheelModel(3),
kart_model.getWheelGraphicsPosition(3) );
for(size_t i=0 ; i < kart_model.getSpeedWeightedObjectsCount() ; i++)
model_location.setScale(core::vector3df(1.0f, 1.0f, 1.0f));
for (unsigned i = 0; i < 4; i++)
{
const SpeedWeightedObject& obj = kart_model.getSpeedWeightedObject((int)i);
m_model_view->addModel(obj.m_model, obj.m_position);
model_location.setTranslation(kart_model
.getWheelGraphicsPosition(i).toIrrVector());
m_model_view->addModel(kart_model.getWheelModel(i), model_location);
}
for (unsigned i = 0; i < kart_model.getSpeedWeightedObjectsCount(); i++)
{
const SpeedWeightedObject& obj = kart_model.getSpeedWeightedObject(i);
core::matrix4 swol = obj.m_location;
if (!obj.m_bone_name.empty())
{
core::matrix4 inv =
kart_model.getInverseBoneMatrix(obj.m_bone_name);
swol = inv * obj.m_location;
}
m_model_view->addModel(obj.m_model, swol, -1, -1, false, 0.0f,
obj.m_bone_name);
}
m_model_view->setRotateContinuously( 35.0f );

View File

@ -22,6 +22,7 @@
#include "graphics/render_info.hpp"
#include "items/powerup.hpp"
#include "karts/abstract_kart_animation.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "utils/log.hpp"

View File

@ -23,6 +23,7 @@
#include "animations/three_d_animation.hpp"
#include "items/flyable.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "modes/world.hpp"

View File

@ -28,6 +28,7 @@
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
#include "karts/kart.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/skidding.hpp"
#include "physics/btKart.hpp"
@ -547,7 +548,7 @@ void KartGFX::setGFXInvisible()
m_nitro_light->setVisible(false);
m_skidding_light_1->setVisible(false);
m_skidding_light_2->setVisible(false);
m_kart->getKartModel()->turnOffHeadlights();
m_kart->getKartModel()->toggleHeadlights(false);
}
#endif
} // setGFXInvisible

View File

@ -52,14 +52,12 @@ float KartModel::UNDEFINED = -99.9f;
// ------------------------------------------------------------
// SpeedWeightedObject implementation
#define SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED -99.f
SpeedWeightedObject::Properties::Properties()
{
m_strength_factor = SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED;
m_speed_factor = SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED;
m_texture_speed.X = SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED;
m_texture_speed.Y = SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED;
m_strength_factor = -1.0f;
m_speed_factor = 0.0f;
m_texture_speed.X = 0.0f;
m_texture_speed.Y = 0.0f;
} // SpeedWeightedObject::Properties::Properties
// ----------------------------------------------------------------------------
@ -71,22 +69,6 @@ void SpeedWeightedObject::Properties::loadFromXMLNode(const XMLNode* xml_node)
xml_node->get("texture-speed-y", &m_texture_speed.Y);
} // SpeedWeightedObject::Properties::loadFromXMLNode
// ----------------------------------------------------------------------------
void SpeedWeightedObject::Properties::checkAllSet()
{
#define CHECK_NEG( a,strA) if(a<=SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED) \
{ \
Log::fatal("SpeedWeightedObject", \
"Missing default value for '%s'.", \
strA); \
}
CHECK_NEG(m_strength_factor, "speed-weighted strength-factor" );
CHECK_NEG(m_speed_factor, "speed-weighted speed-factor" );
CHECK_NEG(m_texture_speed.X, "speed-weighted texture speed X" );
CHECK_NEG(m_texture_speed.Y, "speed-weighted texture speed Y" );
#undef CHECK_NEG
} // SpeedWeightedObject::Properties::checkAllSet
// ============================================================================
/** Default constructor which initialises all variables with defaults.
* Note that the KartModel is copied, so make sure to update makeCopy
@ -114,6 +96,7 @@ void SpeedWeightedObject::Properties::checkAllSet()
*/
KartModel::KartModel(bool is_master)
{
m_version = 0;
m_is_master = is_master;
m_kart = NULL;
m_mesh = NULL;
@ -157,7 +140,6 @@ KartModel::KartModel(bool is_master)
*/
void KartModel::loadInfo(const XMLNode &node)
{
node.get("version", &m_version);
node.get("model-file", &m_model_filename);
if(const XMLNode *animation_node=node.getNode("animations"))
{
@ -177,13 +159,11 @@ void KartModel::loadInfo(const XMLNode &node)
animation_node->get("start-jump", &m_animation_frame[AF_JUMP_START]);
animation_node->get("start-jump-loop",&m_animation_frame[AF_JUMP_LOOP] );
animation_node->get("end-jump", &m_animation_frame[AF_JUMP_END] );
animation_node->get("selection-start", &m_animation_frame[AF_SELECTION_START]);
animation_node->get("selection-end", &m_animation_frame[AF_SELECTION_END] );
animation_node->get("backpedal-left", &m_animation_frame[AF_BACK_LEFT]);
animation_node->get("backpedal", &m_animation_frame[AF_BACK_STRAIGHT]);
animation_node->get("backpedal-right",&m_animation_frame[AF_BACK_RIGHT]);
animation_node->get("start-speed-weighted", &m_animation_frame[AF_SPEED_WEIGHTED_START]);
animation_node->get("end-speed-weighted", &m_animation_frame[AF_SPEED_WEIGHTED_END] );
animation_node->get("selection-start", &m_animation_frame[AF_SELECTION_START]);
animation_node->get("selection-end", &m_animation_frame[AF_SELECTION_END] );
animation_node->get("speed", &m_animation_speed );
}
@ -206,19 +186,16 @@ void KartModel::loadInfo(const XMLNode &node)
m_has_nitro_emitter = true;
}
if(const XMLNode *speed_weighted_objects_node=node.getNode("speed-weighted-objects"))
{
SpeedWeightedObject::Properties fallback_properties;
fallback_properties.loadFromXMLNode(speed_weighted_objects_node);
for(unsigned int i=0 ; i < speed_weighted_objects_node->getNumNodes() ; i++)
{
loadSpeedWeightedInfo(speed_weighted_objects_node->getNode(i), fallback_properties);
}
}
node.get("version", &m_version);
if (m_version > 2)
{
if (const XMLNode *speed_weighted_objects_node = node.getNode("speed-weighted-objects"))
{
for (unsigned int i = 0 ;i < speed_weighted_objects_node->getNumNodes() ; i++)
{
loadSpeedWeightedInfo(speed_weighted_objects_node->getNode(i));
}
}
if (const XMLNode* headlights_node = node.getNode("headlights"))
{
loadHeadlights(*headlights_node);
@ -274,26 +251,34 @@ KartModel::~KartModel()
assert(!m_is_master);
m_speed_weighted_objects[i].m_node->drop();
}
if(m_is_master && m_speed_weighted_objects[i].m_model)
if (m_is_master && m_speed_weighted_objects[i].m_model)
{
m_speed_weighted_objects[i].m_model->drop();
irr_driver->dropAllTextures(m_speed_weighted_objects[i].m_model);
irr_driver->removeMeshFromCache(m_speed_weighted_objects[i].m_model);
if (m_speed_weighted_objects[i].m_model->getReferenceCount() == 1)
{
irr_driver->removeMeshFromCache(m_speed_weighted_objects[i].m_model);
}
}
}
for (size_t i = 0; i < m_headlight_objects.size(); i++)
{
HeadlightObject& obj = m_headlight_objects[i];
if (obj.getNode())
if (obj.getLightNode())
{
// Master KartModels should never have a headlight attached.
assert(!m_is_master);
obj.getNode()->drop();
obj.getLightNode()->drop();
}
if (m_is_master && obj.getModel())
{
obj.getModel()->drop();
irr_driver->dropAllTextures(obj.getModel());
irr_driver->removeMeshFromCache(obj.getModel());
if (obj.getModel()->getReferenceCount() == 1)
{
irr_driver->removeMeshFromCache(obj.getModel());
}
}
}
@ -333,23 +318,24 @@ KartModel* KartModel::makeCopy(KartRenderType krt)
assert(m_is_master);
assert(m_render_info == NULL);
assert(!m_animated_node);
KartModel *km = new KartModel(/*is master*/ false);
km->m_version = m_version;
km->m_kart_width = m_kart_width;
km->m_kart_length = m_kart_length;
km->m_kart_height = m_kart_height;
km->m_kart_highest_point = m_kart_highest_point;
km->m_kart_lowest_point = m_kart_lowest_point;
km->m_mesh = m_mesh;
km->m_model_filename = m_model_filename;
km->m_animation_speed = m_animation_speed;
km->m_current_animation = AF_DEFAULT;
km->m_animated_node = NULL;
km->m_hat_name = m_hat_name;
km->m_hat_bone = m_hat_bone;
km->m_krt = krt;
km->m_support_colorization = m_support_colorization;
km->m_render_info = new RenderInfo();
KartModel *km = new KartModel(/*is master*/ false);
km->m_kart_width = m_kart_width;
km->m_kart_length = m_kart_length;
km->m_kart_height = m_kart_height;
km->m_kart_highest_point = m_kart_highest_point;
km->m_kart_lowest_point = m_kart_lowest_point;
km->m_mesh = m_mesh;
km->m_model_filename = m_model_filename;
km->m_animation_speed = m_animation_speed;
km->m_current_animation = AF_DEFAULT;
km->m_animated_node = NULL;
km->m_hat_name = m_hat_name;
km->m_hat_bone = m_hat_bone;
km->m_krt = krt;
km->m_support_colorization = m_support_colorization;
km->m_render_info = new RenderInfo();
km->m_inverse_bone_matrices = m_inverse_bone_matrices;
km->m_version = m_version;
km->m_render_info->setKartModelRenderInfo(krt);
km->m_nitro_emitter_position[0] = m_nitro_emitter_position[0];
@ -386,7 +372,7 @@ KartModel* KartModel::makeCopy(KartRenderType krt)
for (size_t i = 0; i<m_headlight_objects.size(); i++)
{
// Master should not have any headlight nodes.
assert(!m_headlight_objects[i].getNode());
assert(!m_headlight_objects[i].getLightNode());
km->m_headlight_objects[i] = m_headlight_objects[i];
}
@ -454,13 +440,6 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool human_playe
m_wheel_node[i]->setParent(lod_node);
}
// Become the owner of the speed weighted objects
for(size_t i=0; i<m_speed_weighted_objects.size(); i++)
{
if(!m_speed_weighted_objects[i].m_node) continue;
m_speed_weighted_objects[i].m_node->setParent(lod_node);
}
#ifndef SERVER_ONLY
// Enable rim lighting for the kart
irr_driver->applyObjectPassShader(lod_node, true);
@ -509,38 +488,54 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool human_playe
m_wheel_node[i]->grab();
((scene::IMeshSceneNode *) m_wheel_node[i])->setReadOnlyMaterials(true);
#ifdef DEBUG
#ifdef DEBUG
std::string debug_name = m_wheel_filename[i]+" (wheel)";
m_wheel_node[i]->setName(debug_name.c_str());
#endif
#endif
m_wheel_node[i]->setPosition(m_wheel_graphics_position[i].toIrrVector());
}
// Attach the speed weighted objects + set the animation state
for(size_t i=0 ; i < m_speed_weighted_objects.size() ; i++)
}
// Attach the speed weighted objects + set the animation state
for (unsigned int i = 0; i < m_speed_weighted_objects.size() ;i++)
{
SpeedWeightedObject& obj = m_speed_weighted_objects[i];
obj.m_node = NULL;
if (obj.m_model)
{
SpeedWeightedObject& obj = m_speed_weighted_objects[i];
obj.m_node = NULL;
if(obj.m_model)
const bool bone_attachment =
m_animated_node && !obj.m_bone_name.empty();
scene::ISceneNode* parent = bone_attachment ?
m_animated_node->getJointNode(obj.m_bone_name.c_str()) : node;
scene::ISceneNode* swo = NULL;
if (animated_models)
{
// Only need to keep track of animated node for speed setting
obj.m_node = irr_driver->addAnimatedMesh(obj.m_model,
"speedweighted", node, getRenderInfo(),
true/*all_parts_colorized*/);
"speedweighted", parent, getRenderInfo(),
true/*all_parts_colorized*/);
swo = obj.m_node;
obj.m_node->grab();
obj.m_node->setFrameLoop(m_animation_frame[AF_SPEED_WEIGHTED_START],
m_animation_frame[AF_SPEED_WEIGHTED_END]);
#ifdef DEBUG
std::string debug_name = obj.m_name+" (speed-weighted)";
obj.m_node->setName(debug_name.c_str());
#endif
obj.m_node->setPosition(obj.m_position.toIrrVector());
obj.m_node->setFrameLoop(0, obj.m_model->getFrameCount() - 1);
}
else
{
swo = irr_driver->addMesh(obj.m_model->getMesh(0),
"speedweighted", parent, getRenderInfo(),
true/*all_parts_colorized*/);
}
#ifdef DEBUG
std::string debug_name = obj.m_name + " (speed-weighted)";
swo->setName(debug_name.c_str());
#endif
configNode(swo, obj.m_location, bone_attachment ?
getInverseBoneMatrix(obj.m_bone_name) : core::matrix4());
}
}
const float each_energy = 0.2f / m_headlight_objects.size();
const float each_radius = 2.0f / m_headlight_objects.size();
const float each_energy = 0.5f / m_headlight_objects.size();
const float each_radius = 5.0f / m_headlight_objects.size();
for (unsigned int i = 0; i < m_headlight_objects.size(); i++)
{
HeadlightObject& obj = m_headlight_objects[i];
@ -551,20 +546,17 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool human_playe
m_animated_node && !obj.getBoneName().empty();
scene::ISceneNode* parent = bone_attachment ?
m_animated_node->getJointNode(obj.getBoneName().c_str()) : node;
scene::ISceneNode* new_node =
scene::ISceneNode* headlight_model =
irr_driver->addMesh(obj.getModel(), "kart_headlight",
parent, getRenderInfo());
#ifndef SERVER_ONLY
if (human_player && CVS->isGLSL() && CVS->isDefferedEnabled())
{
obj.setNode(irr_driver->addLight(core::vector3df
(0.0f, 0.0f, 0.0f), each_energy, each_radius,
1.0f, 1.0f, 1.0f, false, new_node));
obj.getNode()->grab();
obj.setLight(headlight_model, each_energy, each_radius);
}
#endif
configNode(new_node, obj.getLocation(), bone_attachment ?
getInverseBoneMatrix(obj.getBoneName().c_str()) : core::matrix4());
configNode(headlight_model, obj.getLocation(), bone_attachment ?
getInverseBoneMatrix(obj.getBoneName()) : core::matrix4());
}
}
@ -577,12 +569,24 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool human_playe
(file_manager->getAsset(FileManager::MODEL, m_hat_name));
scene::ISceneNode* node = irr_driver->addMesh(hat_mesh, "hat", parent);
configNode(node, *m_hat_location, bone_attachment ?
getInverseBoneMatrix(m_hat_bone.c_str()) : core::matrix4());
getInverseBoneMatrix(m_hat_bone) : core::matrix4());
}
return node;
} // attachModel
// ----------------------------------------------------------------------------
/** Add a light node emitted from the center mass the headlight.
*/
void HeadlightObject::setLight(scene::ISceneNode* parent,
float energy, float radius)
{
m_node = irr_driver->addLight(core::vector3df(0.0f, 0.0f, 0.0f),
energy, radius, m_headlight_color.getRed() / 255.f,
m_headlight_color.getGreen() / 255.f,
m_headlight_color.getBlue() / 255.f, false/*sun*/, parent);
m_node->grab();
} // setLight
// ----------------------------------------------------------------------------
/** Loads the 3d model and all wheels.
@ -644,6 +648,7 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
#endif
m_kart_highest_point = kart_max.getY();
m_kart_lowest_point = kart_min.getY();
initInverseBoneMatrices();
// Load the speed weighted object models. We need to do that now because it can affect the dimensions of the kart
for(size_t i=0 ; i < m_speed_weighted_objects.size() ; i++)
@ -663,18 +668,18 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
MeshTools::createSkinnedMeshWithTangents(sm,
&MeshTools::isNormalMap);
}
irr_driver->grabAllTextures(obj.m_model);
#endif
// Update min/max
obj.m_model->grab();
irr_driver->grabAllTextures(obj.m_model);
// Update min/max, speed weight can be scaled
Vec3 obj_min, obj_max;
int frame = m_animation_frame[AF_SPEED_WEIGHTED_START];
if (frame < 0)
frame = 0;
MeshTools::minMax3D(obj.m_model->getMesh(frame), &obj_min, &obj_max);
obj_min += obj.m_position;
obj_max += obj.m_position;
kart_min.min(obj_min);
kart_max.max(obj_max);
MeshTools::minMax3D(obj.m_model->getMesh(0), &obj_min, &obj_max);
core::vector3df transformed_min, transformed_max;
obj.m_location.transformVect(transformed_min, obj_min.toIrrVector());
obj.m_location.transformVect(transformed_max, obj_max.toIrrVector());
kart_min.min(transformed_min);
kart_max.max(transformed_max);
}
for (unsigned int i = 0; i < m_headlight_objects.size(); i++)
@ -682,6 +687,7 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
HeadlightObject& obj = m_headlight_objects[i];
std::string full_name = kart_properties.getKartDir() + obj.getFilename();
obj.setModel(irr_driver->getMesh(full_name));
obj.getModel()->grab();
irr_driver->grabAllTextures(obj.getModel());
}
@ -757,18 +763,33 @@ void KartModel::loadNitroEmitterInfo(const XMLNode &node,
// ----------------------------------------------------------------------------
/** Loads a single speed weighted node. */
void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node,
const SpeedWeightedObject::Properties& fallback_properties)
void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node)
{
SpeedWeightedObject obj;
obj.m_properties = fallback_properties;
obj.m_properties.loadFromXMLNode(speed_weighted_node);
speed_weighted_node->get("position", &obj.m_position);
speed_weighted_node->get("model", &obj.m_name);
if(!obj.m_name.empty())
if (speed_weighted_node->getName() == "object")
{
core::vector3df position, rotation, scale;
speed_weighted_node->get("position", &position);
speed_weighted_node->get("rotation", &rotation);
speed_weighted_node->get("scale", &scale);
core::matrix4 lm, sm, rm;
lm.setTranslation(position);
sm.setScale(scale);
rm.setRotationDegrees(rotation);
obj.m_location = lm * rm * sm;
speed_weighted_node->get("bone", &obj.m_bone_name);
speed_weighted_node->get("model", &obj.m_name);
obj.m_properties.loadFromXMLNode(speed_weighted_node);
}
else
{
Log::warn("KartModel",
"Unknown XML node in the speed weighted objects section");
}
if (!obj.m_name.empty())
{
m_speed_weighted_objects.push_back(obj);
}
}
// ----------------------------------------------------------------------------
@ -813,7 +834,10 @@ void KartModel::loadHeadlights(const XMLNode &node)
child->get("bone", &bone_name);
std::string model;
child->get("model", &model);
m_headlight_objects.push_back(HeadlightObject(model, location, bone_name));
video::SColor headlight_color(-1);
child->get("color", &headlight_color);
m_headlight_objects.push_back(HeadlightObject(model, location,
bone_name, headlight_color));
}
else
{
@ -846,14 +870,7 @@ void KartModel::reset()
if (lod)
lod->forceLevelOfDetail(-1);
for (unsigned int i = 0; i < m_headlight_objects.size(); i++)
{
HeadlightObject& obj = m_headlight_objects[i];
if (obj.getNode())
{
obj.getNode()->setVisible(true);
}
}
toggleHeadlights(true);
} // reset
// ----------------------------------------------------------------------------
@ -1071,20 +1088,21 @@ void KartModel::update(float dt, float distance, float steer, float speed,
{
SpeedWeightedObject& obj = m_speed_weighted_objects[i];
#define GET_VALUE(obj, value_name) \
obj.m_properties.value_name > SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED ? obj.m_properties.value_name : \
m_kart->getKartProperties()->getSpeedWeightedObjectProperties().value_name
if (obj.m_node == NULL)
{
continue;
}
// Animation strength
const float strength_factor = GET_VALUE(obj, m_strength_factor);
const float strength_factor = obj.m_properties.m_strength_factor;
if (strength_factor >= 0.0f)
{
float strength = speed * strength_factor;
btClamp<float>(strength, 0.0f, 1.0f);
obj.m_node->setAnimationStrength(strength);
}
// Animation speed
const float speed_factor = GET_VALUE(obj, m_speed_factor);
const float speed_factor = obj.m_properties.m_speed_factor;
if (speed_factor >= 0.0f)
{
float anim_speed = speed * speed_factor;
@ -1093,8 +1111,8 @@ void KartModel::update(float dt, float distance, float steer, float speed,
// Texture animation
core::vector2df tex_speed;
tex_speed.X = GET_VALUE(obj, m_texture_speed.X);
tex_speed.Y = GET_VALUE(obj, m_texture_speed.Y);
tex_speed.X = obj.m_properties.m_texture_speed.X;
tex_speed.Y = obj.m_properties.m_texture_speed.Y;
if (tex_speed != core::vector2df(0.0f, 0.0f))
{
obj.m_texture_cur_offset += speed * tex_speed * dt;
@ -1113,7 +1131,6 @@ void KartModel::update(float dt, float distance, float steer, float speed,
} // for j<MATERIAL_MAX_TEXTURES
} // for i<getMaterialCount
}
#undef GET_VALUE
}
}
@ -1176,39 +1193,67 @@ RenderInfo* KartModel::getRenderInfo()
} // getRenderInfo
//-----------------------------------------------------------------------------
void KartModel::turnOffHeadlights()
void KartModel::toggleHeadlights(bool on)
{
for (unsigned int i = 0; i < m_headlight_objects.size(); i++)
{
HeadlightObject& obj = m_headlight_objects[i];
if (obj.getNode())
if (obj.getLightNode())
{
obj.getNode()->setVisible(false);
obj.getLightNode()->setVisible(on);
}
}
} // turnOffHeadlights
} // toggleHeadlights
//-----------------------------------------------------------------------------
core::matrix4 KartModel::getInverseBoneMatrix(const char* bone_name)
void KartModel::initInverseBoneMatrices()
{
assert(m_animated_node);
scene::IBoneSceneNode* bone = m_animated_node->getJointNode(bone_name);
assert(bone);
m_animated_node->setCurrentFrame((float)m_animation_frame[AF_STRAIGHT]);
#ifndef SERVER_ONLY
STKAnimatedMesh* am = dynamic_cast<STKAnimatedMesh*>(m_animated_node);
if (am)
if (m_version < 3)
{
am->setHardwareSkinning(false);
am->OnAnimate(0);
am->setHardwareSkinning(true);
// Only need for >= 3 version of kart
return;
}
else
#endif
m_animated_node->OnAnimate(0);
bone->updateAbsolutePosition();
const core::matrix4 mat = bone->getAbsoluteTransformation();
core::matrix4 inv;
mat.getInverse(inv);
return inv;
// Due to irrlicht mesh doesn't expose bone name, we have to create a
// dummy aniamted node
// All bone matrices are configured in straight frame (as in exporting)
scene::IAnimatedMeshSceneNode* node = irr_driver->getSceneManager()
->addAnimatedMeshSceneNode(m_mesh);
float striaght_frame = (float)m_animation_frame[AF_STRAIGHT];
if (m_animation_frame[AF_STRAIGHT] == -1)
{
Log::warn("KartModel", "%s has no striaght frame defined.",
m_model_filename.c_str());
striaght_frame = 0.0f;
}
node->setCurrentFrame(striaght_frame);
const unsigned total_joint = node->getJointCount();
for (unsigned i = 0; i < total_joint; i++)
{
node->OnAnimate(0);
scene::IBoneSceneNode* bone = node->getJointNode(i);
bone->updateAbsolutePosition();
const core::matrix4 mat = bone->getAbsoluteTransformation();
core::matrix4 inv;
mat.getInverse(inv);
const std::string bone_name = bone->getName();
auto ret = m_inverse_bone_matrices.find(bone_name);
if (ret != m_inverse_bone_matrices.end())
{
Log::warn("KartModel", "%s has duplicated bone, name: %s,"
" attachment may not work correctly.",
m_model_filename.c_str(), bone_name.c_str());
}
m_inverse_bone_matrices[bone_name] = inv;
}
node->remove();
} // initInverseBoneMatrices
//-----------------------------------------------------------------------------
const core::matrix4& KartModel::getInverseBoneMatrix
(const std::string& bone_name) const
{
assert(m_version >= 3);
auto ret = m_inverse_bone_matrices.find(bone_name);
assert(ret != m_inverse_bone_matrices.end());
return ret->second;
} // getInverseBoneMatrix

View File

@ -20,6 +20,7 @@
#define HEADER_KART_MODEL_HPP
#include <string>
#include <unordered_map>
#include <vector>
#include <IAnimatedMeshSceneNode.h>
@ -59,22 +60,25 @@ struct SpeedWeightedObject
void loadFromXMLNode(const XMLNode* xml_node);
void checkAllSet();
};
SpeedWeightedObject() : m_model(NULL), m_node(NULL), m_position(), m_name() {}
SpeedWeightedObject() : m_model(NULL), m_node(NULL), m_name() {}
/** Model */
scene::IAnimatedMesh * m_model;
/** The scene node the speed weighted model is attached to */
scene::IAnimatedMeshSceneNode * m_node;
/** The position of the "speed weighted" objects relative to the kart */
Vec3 m_position;
/** The relative matrix to the parent kart scene node
* where the speed weighted object is attached to. */
core::matrix4 m_location;
/** Filename of the "speed weighted" object */
std::string m_name;
/** Attach to which bone in kart model if not empty. */
std::string m_bone_name;
/** Current uv translation in the texture matrix for speed-weighted texture animations */
core::vector2df m_texture_cur_offset;
@ -92,14 +96,21 @@ class HeadlightObject
private:
/** The filename of the headlight model. */
std::string m_filename;
/** The relative matrix to the parent kart scene node
* or bone where the headlight mesh is attached to. */
* where the headlight mesh is attached to. */
core::matrix4 m_location;
/** The mesh for the headlight. */
scene::IMesh* m_model;
/** The scene node of the headlight. */
/** The scene node of the headlight (real light). */
scene::ISceneNode* m_node;
/** The color of the real light. */
video::SColor m_headlight_color;
/** Attach to which bone in kart model if not empty. */
std::string m_bone_name;
public:
@ -111,13 +122,14 @@ public:
} // HeadlightObject
// ------------------------------------------------------------------------
HeadlightObject(const std::string& filename, const core::matrix4& location,
const std::string& bone_name)
const std::string& bone_name, const video::SColor& color)
{
m_filename = filename;
m_location = location;
m_model = NULL;
m_node = NULL;
m_bone_name = bone_name;
m_headlight_color = color;
} // HeadlightObjects
// ------------------------------------------------------------------------
const std::string& getFilename() const { return m_filename; }
@ -125,15 +137,11 @@ public:
/** Sets the mesh for this headlight object. */
void setModel(scene::IMesh *mesh) { m_model = mesh; }
// ------------------------------------------------------------------------
/** Sets the node of the headlight. */
void setNode(scene::ISceneNode *node)
{
m_node = node;
} // setNode
void setLight(scene::ISceneNode* parent, float energy, float radius);
// ------------------------------------------------------------------------
const scene::ISceneNode *getNode() const { return m_node; }
const scene::ISceneNode *getLightNode() const { return m_node; }
// ------------------------------------------------------------------------
scene::ISceneNode *getNode() { return m_node; }
scene::ISceneNode *getLightNode() { return m_node; }
// ------------------------------------------------------------------------
const scene::IMesh *getModel() const { return m_model; }
// ------------------------------------------------------------------------
@ -182,9 +190,7 @@ public:
AF_BACK_LEFT, // Going back left
AF_BACK_STRAIGHT, // Going back straight
AF_BACK_RIGHT, // Going back right
AF_SPEED_WEIGHTED_START, // Start of speed-weighted animation
AF_SPEED_WEIGHTED_END, // End of speed-weighted animation
AF_END=AF_SPEED_WEIGHTED_END, // Last animation frame
AF_END=AF_BACK_RIGHT, // Last animation frame
AF_COUNT}; // Number of entries here
private:
@ -295,8 +301,7 @@ private:
void loadNitroEmitterInfo(const XMLNode &node,
const std::string &emitter_name, int index);
void loadSpeedWeightedInfo(const XMLNode* speed_weighted_node,
const SpeedWeightedObject::Properties& fallback_properties);
void loadSpeedWeightedInfo(const XMLNode* speed_weighted_node);
void loadHeadlights(const XMLNode &node);
@ -311,10 +316,12 @@ private:
bool m_support_colorization;
std::unordered_map<std::string, core::matrix4> m_inverse_bone_matrices;
unsigned m_version;
// ------------------------------------------------------------------------
core::matrix4 getInverseBoneMatrix(const char* bone_name);
void initInverseBoneMatrices();
// ------------------------------------------------------------------------
void configNode(scene::ISceneNode* node, const core::matrix4& global_mat,
const core::matrix4& inv_mat)
@ -433,7 +440,10 @@ public:
// ------------------------------------------------------------------------
bool supportColorization() const { return m_support_colorization; }
// ------------------------------------------------------------------------
void turnOffHeadlights();
void toggleHeadlights(bool on);
// ------------------------------------------------------------------------
const core::matrix4&
getInverseBoneMatrix(const std::string& bone_name) const;
}; // KartModel
#endif

View File

@ -306,6 +306,25 @@ void KartProperties::load(const std::string &filename, const std::string &node)
} // load
// ----------------------------------------------------------------------------
/** Returns a pointer to the KartModel object.
* \param krt The KartRenderType, like default, red, blue or transparent.
* see the RenderInfo include for details
*/
KartModel* KartProperties::getKartModelCopy(KartRenderType krt) const
{
return m_kart_model->makeCopy(krt);
} // getKartModelCopy
// ----------------------------------------------------------------------------
/** Sets the name of a mesh to be used for this kart.
* \param hat_name Name of the mesh.
*/
void KartProperties::setHatMeshName(const std::string &hat_name)
{
m_kart_model->setHatMeshName(hat_name);
} // setHatMeshName
//-----------------------------------------------------------------------------
void KartProperties::combineCharacteristics()
{
@ -372,11 +391,6 @@ void KartProperties::getAllData(const XMLNode * root)
m_ai_properties[RaceManager::DIFFICULTY_BEST]->load(best);
}
if(const XMLNode *speed_weighted_objects_node = root->getNode("speed-weighted-objects"))
{
m_speed_weighted_object_properties.loadFromXMLNode(speed_weighted_objects_node);
}
if(const XMLNode *friction_node = root->getNode("friction"))
friction_node->get("slip", &m_friction_slip);
@ -480,8 +494,6 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_restitution, "collision restitution" );
CHECK_NEG(m_physical_wheel_position, "collision physical-wheel-position");
m_speed_weighted_object_properties.checkAllSet();
for(unsigned int i=0; i<RaceManager::DIFFICULTY_COUNT; i++)
m_ai_properties[i]->checkAllSet(filename);
} // checkAllSet
@ -1173,6 +1185,5 @@ bool KartProperties::getSkidEnabled() const
return m_cached_characteristic->getSkidEnabled();
} // getSkidEnabled
/* <characteristics-end kpgetter> */

View File

@ -32,7 +32,6 @@ namespace irr
using namespace irr;
#include "audio/sfx_manager.hpp"
#include "karts/kart_model.hpp"
#include "io/xml_node.hpp"
#include "race/race_manager.hpp"
#include "utils/interpolation_array.hpp"
@ -42,6 +41,7 @@ class AbstractCharacteristic;
class AIProperties;
class CachedCharacteristic;
class CombinedCharacteristic;
class KartModel;
class Material;
class XMLNode;
@ -176,9 +176,6 @@ private:
// -------------------
float m_friction_slip;
/** Parameters for the speed-weighted objects */
SpeedWeightedObject::Properties m_speed_weighted_object_properties;
/** Shift of center of gravity. */
Vec3 m_gravity_center_shift;
@ -244,26 +241,13 @@ public:
video::ITexture *getMinimapIcon () const {return m_minimap_icon; }
// ------------------------------------------------------------------------
/** Returns a pointer to the KartModel object.
* \param krt The KartRenderType, like default, red, blue or transparent.
* see the RenderInfo include for details
*/
KartModel* getKartModelCopy(KartRenderType krt) const
{return m_kart_model->makeCopy(krt); }
KartModel* getKartModelCopy(KartRenderType krt) const;
// ------------------------------------------------------------------------
/** Returns a pointer to the main KartModel object. This copy
* should not be modified, not attachModel be called on it. */
const KartModel& getMasterKartModel() const {return *m_kart_model; }
// ------------------------------------------------------------------------
/** Sets the name of a mesh to be used for this kart.
* \param hat_name Name of the mesh.
*/
void setHatMeshName(const std::string &hat_name)
{
m_kart_model->setHatMeshName(hat_name);
} // setHatMeshName
void setHatMeshName(const std::string &hat_name);
// ------------------------------------------------------------------------
/** Returns the name of this kart.
\note Pass it through fridibi as needed, this is the LTR name
@ -324,13 +308,6 @@ public:
/** Returns friction slip. */
float getFrictionSlip () const {return m_friction_slip; }
// ------------------------------------------------------------------------
/** Returns parameters for the speed-weighted objects */
const SpeedWeightedObject::Properties& getSpeedWeightedObjectProperties() const
{
return m_speed_weighted_object_properties;
}
// ------------------------------------------------------------------------
/** Returns the wheel base (distance front to rear axis). */
float getWheelBase () const {return m_wheel_base; }

View File

@ -202,6 +202,7 @@
#include "items/projectile_manager.hpp"
#include "karts/combined_characteristic.hpp"
#include "karts/controller/ai_base_lap_controller.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/cutscene_world.hpp"

View File

@ -24,6 +24,7 @@
#include "graphics/material.hpp"
#include "karts/kart.hpp"
#include "karts/kart_model.hpp"
#include "physics/triangle_mesh.hpp"
#include "tracks/terrain_info.hpp"
#include "tracks/track.hpp"

View File

@ -29,6 +29,7 @@
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
#include "io/file_manager.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/cutscene_world.hpp"

View File

@ -30,6 +30,7 @@
#include "guiengine/widgets/label_widget.hpp"
#include "io/file_manager.hpp"
#include "items/item_manager.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/cutscene_world.hpp"

View File

@ -20,13 +20,13 @@
#define HEADER_GRAND_PRIX_LOSE_HPP
#include "guiengine/screen.hpp"
#include "karts/kart_model.hpp"
#include "states_screens/grand_prix_cutscene.hpp"
#include <vector>
#include <string>
namespace irr { namespace scene { class ISceneNode; class ICameraSceneNode; class ILightSceneNode; class IMeshSceneNode; } }
class KartModel;
class KartProperties;
class TrackObject;

View File

@ -32,6 +32,7 @@
#include "input/device_manager.hpp"
#include "items/item_manager.hpp"
#include "karts/abstract_characteristic.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/overworld.hpp"
@ -833,8 +834,10 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id,
ItemManager::getItemModel(Item::ITEM_BONUS_BOX);
w3->clearModels();
w3->addModel( model, Vec3(0.0f, -12.0f, 0.0f),
Vec3(35.0f, 35.0f, 35.0f) );
core::matrix4 model_location;
model_location.setTranslation(core::vector3df(0.0f, -12.0f, 0.0f));
model_location.setScale(core::vector3df(35.0f, 35.0f, 35.0f));
w3->addModel(model, model_location);
w3->update(0);
m_kart_widgets[widget_id].m_kart_name
->setText( _("Random Kart"), false );
@ -843,9 +846,11 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id,
else if (StringUtils::startsWith(selection, ID_LOCKED) && !m_multiplayer)
{
w3->clearModels();
core::matrix4 model_location;
model_location.setScale(core::vector3df(15.0f, 15.0f, 15.0f));
w3->addModel(irr_driver->getAnimatedMesh(
file_manager->getAsset(FileManager::MODEL, "chest.spm") )->getMesh(20),
Vec3(0,0,0), Vec3(15.0f, 15.0f, 15.0f) );
file_manager->getAsset(FileManager::MODEL, "chest.spm"))
->getMesh(20), model_location);
w3->update(0);
if (m_multiplayer)
@ -874,6 +879,8 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id,
scale = 30.0f;
}
core::matrix4 model_location;
model_location.setScale(core::vector3df(scale, scale, scale));
w3->clearModels();
const bool has_win_anime =
UserConfigParams::m_show_steering_animations != 0 &&
@ -882,8 +889,7 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id,
kart_model.getFrame(KartModel::AF_WIN_END) > -1) ||
(kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 &&
kart_model.getFrame(KartModel::AF_SELECTION_END) > -1));
w3->addModel( kart_model.getModel(), Vec3(0,0,0),
Vec3(scale, scale, scale),
w3->addModel( kart_model.getModel(), model_location,
has_win_anime ?
kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 ?
kart_model.getFrame(KartModel::AF_SELECTION_START) :
@ -898,18 +904,29 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id,
kart_model.getBaseFrame(),
false/*all_parts_colorized*/,
kart_model.getAnimationSpeed());
w3->addModel( kart_model.getWheelModel(0),
kart_model.getWheelGraphicsPosition(0) );
w3->addModel( kart_model.getWheelModel(1),
kart_model.getWheelGraphicsPosition(1) );
w3->addModel( kart_model.getWheelModel(2),
kart_model.getWheelGraphicsPosition(2) );
w3->addModel( kart_model.getWheelModel(3),
kart_model.getWheelGraphicsPosition(3) );
for (size_t i = 0; i < kart_model.getSpeedWeightedObjectsCount(); i++)
model_location.setScale(core::vector3df(1.0f, 1.0f, 1.0f));
for (unsigned i = 0; i < 4; i++)
{
const SpeedWeightedObject& obj = kart_model.getSpeedWeightedObject((int)i);
w3->addModel(obj.m_model, obj.m_position);
model_location.setTranslation(kart_model
.getWheelGraphicsPosition(i).toIrrVector());
w3->addModel(kart_model.getWheelModel(i), model_location);
}
for (unsigned i = 0;
i < kart_model.getSpeedWeightedObjectsCount(); i++)
{
const SpeedWeightedObject& obj =
kart_model.getSpeedWeightedObject(i);
core::matrix4 swol = obj.m_location;
if (!obj.m_bone_name.empty())
{
core::matrix4 inv =
kart_model.getInverseBoneMatrix(obj.m_bone_name);
swol = inv * obj.m_location;
}
w3->addModel(obj.m_model, swol, -1, -1, false, 0.0f,
obj.m_bone_name);
}
//w3->update(0);

View File

@ -161,46 +161,36 @@ void SoccerSetupScreen::beforeAddingWidget()
(info.team == SOCCER_TEAM_BLUE ? KRT_BLUE : KRT_RED);
}
core::matrix4 model_location;
model_location.setScale(core::vector3df(35.0f, 35.0f, 35.0f));
// Add the kart model (including wheels and speed weight objects)
kart_view->addModel(kart_model.getModel(), Vec3(0, 0, 0),
Vec3(35.0f, 35.0f, 35.0f), kart_model.getBaseFrame(),
kart_model.getBaseFrame());
kart_view->addModel(kart_model.getModel(), model_location,
kart_model.getBaseFrame(), kart_model.getBaseFrame());
kart_view->addModel( kart_model.getWheelModel(0),
kart_model.getWheelGraphicsPosition(0),
Vec3(1, 1, 1), /*scale*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
kart_view->addModel( kart_model.getWheelModel(1),
kart_model.getWheelGraphicsPosition(1),
Vec3(1, 1, 1), /*scale*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
kart_view->addModel( kart_model.getWheelModel(2),
kart_model.getWheelGraphicsPosition(2),
Vec3(1, 1, 1), /*scale*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
kart_view->addModel( kart_model.getWheelModel(3),
kart_model.getWheelGraphicsPosition(3),
Vec3(1, 1, 1), /*scale*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
for (size_t i = 0; i < kart_model.getSpeedWeightedObjectsCount(); i++)
model_location.setScale(core::vector3df(1.0f, 1.0f, 1.0f));
for (unsigned i = 0; i < 4; i++)
{
const SpeedWeightedObject& obj = kart_model.getSpeedWeightedObject((int)i);
kart_view->addModel(obj.m_model, obj.m_position,
Vec3(1, 1, 1), /*scale*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
model_location.setTranslation(kart_model
.getWheelGraphicsPosition(i).toIrrVector());
kart_view->addModel(kart_model.getWheelModel(i), model_location,
-1/*start_loop_frame*/ -1/*end_loop_frame*/,
true/*all_parts_colorized*/);
}
for (unsigned i = 0; i < kart_model.getSpeedWeightedObjectsCount();
i++)
{
const SpeedWeightedObject& obj =
kart_model.getSpeedWeightedObject(i);
core::matrix4 swol = obj.m_location;
if (!obj.m_bone_name.empty())
{
core::matrix4 inv =
kart_model.getInverseBoneMatrix(obj.m_bone_name);
swol = inv * obj.m_location;
}
kart_view->addModel(obj.m_model, swol, -1, -1, true, 0.0f,
obj.m_bone_name);
}
kart_view->setRotateContinuously( KART_CONTINUOUS_ROTATION_SPEED );