Merge branch 'master' of https://github.com/supertuxkart/stk-code
This commit is contained in:
commit
4cf0b06d22
@ -398,7 +398,7 @@ if(MSVC OR MINGW)
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
|
||||
find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" "libgcc_s_seh-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
|
||||
if(LIBGCC)
|
||||
file(COPY ${LIBGCC} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
|
||||
endif()
|
||||
|
20
cmake/Toolchain-mingw-64bit.cmake
Normal file
20
cmake/Toolchain-mingw-64bit.cmake
Normal file
@ -0,0 +1,20 @@
|
||||
# Usage:
|
||||
# cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw-64bit.cmake
|
||||
|
||||
# the name of the target operating system
|
||||
SET(CMAKE_SYSTEM_NAME Windows)
|
||||
|
||||
# which compilers to use for C and C++
|
||||
SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-posix)
|
||||
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix)
|
||||
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||
|
||||
# here is the target environment located
|
||||
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 /usr/lib/gcc/x86_64-w64-mingw32/4.9-posix ${PROJECT_SOURCE_DIR}/dependencies)
|
||||
|
||||
# adjust the default behaviour of the FIND_XXX() commands:
|
||||
# search headers and libraries in the target environment, search
|
||||
# programs in the host environment
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ALWAYS)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
@ -1,3 +1,6 @@
|
||||
# Usage:
|
||||
# cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw.cmake
|
||||
|
||||
# the name of the target operating system
|
||||
SET(CMAKE_SYSTEM_NAME Windows)
|
||||
|
||||
|
BIN
data/CREDITS
BIN
data/CREDITS
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<stkgui>
|
||||
<div x="0" y="0" width="100%" height="100%" layout="vertical-row" >
|
||||
<header text_align="center" width="80%" align="center" I18N="In the server creation screen" text="Server Creation"/>
|
||||
<header id="title" text_align="center" width="80%" align="center" I18N="In the server creation screen" text="Server Creation"/>
|
||||
<spacer height="15" width="10"/>
|
||||
<box proportion="4" width="90%" layout="vertical-row" align="center">
|
||||
<div width="90%" align="center" layout="vertical-row" y="2%" height="96%">
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<stkgui>
|
||||
<div x="0" y="0" width="100%" height="100%" layout="vertical-row" >
|
||||
|
||||
<header text_align="center" width="80%" align="center" I18N="In the online multiplayer screen" text="Online Multiplayer"/>
|
||||
<spacer height="15" width="10"/>
|
||||
<box proportion="4" width="90%" layout="vertical-row" align="center">
|
||||
<div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" id="outer_box" >
|
||||
<!-- TODO: Here will come some information.. or statistics.. or whatever. Yet to be filled in! It will change depending on state. And I'd also like a close button at the right top. -->
|
||||
<label I18N="In the online multiplayer screen" proportion="4"
|
||||
word_wrap="true" text="" align="center"/>
|
||||
</div>
|
||||
</box>
|
||||
|
||||
<buttonbar id="menu_toprow" proportion="3" width="90%" align="center">
|
||||
<icon-button id="quick_play" width="128" height="128"
|
||||
icon="gui/online/menu_quick_play.png" focus_icon="gui/online/menu_quick_play_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Quick Play"/>
|
||||
<icon-button id="find_server" width="128" height="128"
|
||||
icon="gui/online/menu_find_server.png" focus_icon="gui/online/menu_find_server_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Find Server"/>
|
||||
<icon-button id="create_server" width="128" height="128"
|
||||
icon="gui/online/menu_create_server.png" focus_icon="gui/online/menu_create_server_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Create Server"/>
|
||||
</buttonbar>
|
||||
|
||||
<spacer width="10" height="7%"/>
|
||||
|
||||
<bottombar x="2%" width="96%" height="10%" layout="horizontal-row">
|
||||
<label text_align="left" align="center" height="100%" id="online_status" proportion="1" text=""/>
|
||||
|
||||
<spacer width="10" height="10" />
|
||||
|
||||
<buttonbar id="menu_bottomrow" x="0" y="0" width="12%" height="100%" align="center">
|
||||
<icon-button id="profile" width="64" height="64" icon="gui/green_check.png" extend_label="50"
|
||||
I18N="In the online multiplayer screen" text="Profile" label_location="hover"/>
|
||||
<icon-button id="sign_out" width="64" height="64" icon="gui/main_quit.png" extend_label="70"
|
||||
I18N="In the online multiplayer screen" text="Log Out" label_location="hover"/>
|
||||
</buttonbar>
|
||||
|
||||
</bottombar>
|
||||
|
||||
</div>
|
||||
|
||||
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
|
||||
</stkgui>
|
63
data/gui/online/online_screen.stkgui
Normal file
63
data/gui/online/online_screen.stkgui
Normal file
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<stkgui>
|
||||
<div x="0" y="0" width="100%" height="fit" layout="vertical-row">
|
||||
<button id="user-id" width="20%" height="fit" align="right"/>
|
||||
</div>
|
||||
|
||||
<div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" >
|
||||
|
||||
<header text_align="center" width="80%" align="center" I18N="In the online multiplayer screen" text="Online Multiplayer"/>
|
||||
|
||||
<spacer height="5%" width="25"/>
|
||||
<box width="100%" height="38%" padding="10" layout="vertical-row">
|
||||
<bright width="100%" text="Local Networking" align="center" text_align="left" />
|
||||
|
||||
<buttonbar id="lan" proportion="2" width="90%" align="center">
|
||||
<icon-button id="find_lan_server" width="128" height="128"
|
||||
icon="gui/online/menu_find_server.png" focus_icon="gui/online/menu_find_server_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Find Server"/>
|
||||
<icon-button id="create_lan_server" width="128" height="128"
|
||||
icon="gui/online/menu_create_server.png" focus_icon="gui/online/menu_create_server_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Create Server"/>
|
||||
<icon-button id="manage_user" width="128" height="128"
|
||||
icon="gui/options_players.png"
|
||||
I18N="In the online multiplayer screen" text="Users"/>
|
||||
</buttonbar>
|
||||
</box>
|
||||
|
||||
<spacer height="5%" width="25"/>
|
||||
|
||||
<box width="100%" height="38%" padding="10" layout="vertical-row">
|
||||
<bright width="100%" text="Global Networking" align="center" text_align="left" />
|
||||
|
||||
<buttonbar id="menu_top_row" proportion="2" width="90%" align="center">
|
||||
<icon-button id="find_wan_server" width="128" height="128"
|
||||
icon="gui/online/menu_find_server.png" focus_icon="gui/online/menu_find_server_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Find Server"/>
|
||||
<icon-button id="create_wan_server" width="128" height="128"
|
||||
icon="gui/online/menu_create_server.png" focus_icon="gui/online/menu_create_server_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Create Server"/>
|
||||
<icon-button id="quick_wan_play" width="128" height="128"
|
||||
icon="gui/online/menu_quick_play.png" focus_icon="gui/online/menu_quick_play_hover.png"
|
||||
I18N="In the online multiplayer screen" text="Quick Play"/>
|
||||
</buttonbar>
|
||||
</box>
|
||||
|
||||
<bottombar x="2%" width="96%" height="10%" layout="horizontal-row">
|
||||
<label text_align="left" align="center" height="100%" id="online_status" proportion="1" text=""/>
|
||||
|
||||
<spacer width="10" height="10" />
|
||||
|
||||
<buttonbar id="menu_bottomrow" x="0" y="0" width="12%" height="100%" align="center">
|
||||
<icon-button id="profile" width="64" height="64" icon="gui/green_check.png" extend_label="50"
|
||||
I18N="In the online multiplayer screen" text="Profile" label_location="hover"/>
|
||||
<icon-button id="sign_out" width="64" height="64" icon="gui/main_quit.png" extend_label="70"
|
||||
I18N="In the online multiplayer screen" text="Log Out" label_location="hover"/>
|
||||
</buttonbar>
|
||||
|
||||
</bottombar>
|
||||
|
||||
</div>
|
||||
|
||||
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
|
||||
</stkgui>
|
@ -2,9 +2,7 @@ layout(triangles) in;
|
||||
layout(triangle_strip, max_vertices=3) out;
|
||||
|
||||
in int layer[3];
|
||||
in vec2 uv_in[3];
|
||||
flat out int slice;
|
||||
out vec2 uv;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
@ -12,7 +10,6 @@ void main(void)
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
slice = layer[0];
|
||||
uv = uv_in[i];
|
||||
gl_Position = gl_in[i].gl_Position;
|
||||
EmitVertex();
|
||||
}
|
||||
|
@ -58,15 +58,24 @@ static inline void btAlignedFreeDefault(void *ptr)
|
||||
free(ptr);
|
||||
}
|
||||
#else
|
||||
|
||||
static inline void *btAlignedAllocDefault(size_t size, int alignment)
|
||||
{
|
||||
void *ret;
|
||||
char *real;
|
||||
#ifdef __MINGW64__
|
||||
uintptr_t offset;
|
||||
#else
|
||||
unsigned long offset;
|
||||
#endif
|
||||
|
||||
real = (char *)sAllocFunc(size + sizeof(void *) + (alignment-1));
|
||||
if (real) {
|
||||
#ifdef __MINGW64__
|
||||
offset = (alignment - (uintptr_t)(real + sizeof(void *))) & (alignment-1);
|
||||
#else
|
||||
offset = (alignment - (unsigned long)(real + sizeof(void *))) & (alignment-1);
|
||||
#endif
|
||||
ret = (void *)((real + sizeof(void *)) + offset);
|
||||
*((void **)(ret)-1) = (void *)(real);
|
||||
} else {
|
||||
|
@ -213,7 +213,11 @@ protected:
|
||||
|
||||
int *intPtr=0;
|
||||
short *shtPtr=0;
|
||||
#ifdef __MINGW64__
|
||||
char *cp = 0;int dataLen =0;intptr_t nr=0;
|
||||
#else
|
||||
char *cp = 0;int dataLen =0;long nr=0;
|
||||
#endif
|
||||
intPtr = (int*)m_dna;
|
||||
|
||||
/*
|
||||
@ -247,7 +251,11 @@ protected:
|
||||
cp++;
|
||||
}
|
||||
{
|
||||
#ifdef __MINGW64__
|
||||
nr= (intptr_t)cp;
|
||||
#else
|
||||
nr= (long)cp;
|
||||
#endif
|
||||
// long mask=3;
|
||||
nr= ((nr+3)&~3)-nr;
|
||||
while (nr--)
|
||||
@ -282,7 +290,11 @@ protected:
|
||||
}
|
||||
|
||||
{
|
||||
#ifdef __MINGW64__
|
||||
nr= (intptr_t)cp;
|
||||
#else
|
||||
nr= (long)cp;
|
||||
#endif
|
||||
// long mask=3;
|
||||
nr= ((nr+3)&~3)-nr;
|
||||
while (nr--)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Modify this file to change the last-modified date when you add/remove a file.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||
|
@ -626,12 +626,12 @@ namespace UserConfigParams
|
||||
PARAM_DEFAULT( BoolUserConfigParam(true, "weather_gfx",
|
||||
&m_graphics_quality, "Weather effects") );
|
||||
PARAM_PREFIX IntUserConfigParam m_show_steering_animations
|
||||
PARAM_DEFAULT( IntUserConfigParam(ANIMS_ALL,
|
||||
PARAM_DEFAULT( IntUserConfigParam(ANIMS_PLAYERS_ONLY,
|
||||
"steering_animations", &m_graphics_quality,
|
||||
"Whether to display kart animations (0=disabled for all; "
|
||||
"1=enabled for humans, disabled for AIs; 2=enabled for all") );
|
||||
PARAM_PREFIX IntUserConfigParam m_anisotropic
|
||||
PARAM_DEFAULT( IntUserConfigParam(8, "anisotropic",
|
||||
PARAM_DEFAULT( IntUserConfigParam(4, "anisotropic",
|
||||
&m_graphics_quality,
|
||||
"Quality of anisotropic filtering (usual values include 2-4-8-16; 0 to disable)") );
|
||||
PARAM_PREFIX BoolUserConfigParam m_trilinear
|
||||
@ -666,7 +666,7 @@ namespace UserConfigParams
|
||||
"shadows_resoltion", &m_graphics_quality,
|
||||
"Shadow resolution (0 = disabled") );
|
||||
PARAM_PREFIX BoolUserConfigParam m_degraded_IBL
|
||||
PARAM_DEFAULT(BoolUserConfigParam(false,
|
||||
PARAM_DEFAULT(BoolUserConfigParam(true,
|
||||
"Degraded_IBL", &m_graphics_quality,
|
||||
"Disable specular IBL"));
|
||||
|
||||
|
@ -96,6 +96,7 @@ GPUTimer m_perf_query[Q_LAST];
|
||||
|
||||
const int MIN_SUPPORTED_HEIGHT = 768;
|
||||
const int MIN_SUPPORTED_WIDTH = 1024;
|
||||
const bool ALLOW_1280_X_720 = true;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** The constructor creates the irrlicht device. It first creates a NULL
|
||||
@ -327,8 +328,9 @@ void IrrDriver::createListOfVideoModes()
|
||||
{
|
||||
const int w = modes->getVideoModeResolution(i).Width;
|
||||
const int h = modes->getVideoModeResolution(i).Height;
|
||||
if ( (h < MIN_SUPPORTED_HEIGHT || w < MIN_SUPPORTED_WIDTH) &&
|
||||
( ! (h==600 && w==800 && UserConfigParams::m_artist_debug_mode) ) )
|
||||
if ((h < MIN_SUPPORTED_HEIGHT || w < MIN_SUPPORTED_WIDTH) &&
|
||||
(!(h==600 && w==800 && UserConfigParams::m_artist_debug_mode) &&
|
||||
(!(h==720 && w==1280 && ALLOW_1280_X_720 == true))))
|
||||
continue;
|
||||
|
||||
VideoMode mode(w, h);
|
||||
|
@ -39,8 +39,9 @@
|
||||
#include "replay/replay_recorder.hpp"
|
||||
#include "states_screens/kart_selection.hpp"
|
||||
#include "states_screens/main_menu_screen.hpp"
|
||||
#include "states_screens/options_screen_input2.hpp"
|
||||
#include "states_screens/options_screen_device.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/debug.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#include <ISceneManager.h>
|
||||
@ -109,6 +110,14 @@ void InputManager::handleStaticAction(int key, int value)
|
||||
}
|
||||
|
||||
|
||||
if (world != NULL && UserConfigParams::m_artist_debug_mode &&
|
||||
control_is_pressed && value > 0)
|
||||
{
|
||||
if (Debug::handleStaticAction(key))
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: move debug shortcuts to Debug::handleStaticAction
|
||||
switch (key)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
@ -131,6 +140,7 @@ void InputManager::handleStaticAction(int key, int value)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case KEY_CONTROL:
|
||||
case KEY_RCONTROL:
|
||||
case KEY_LCONTROL:
|
||||
@ -425,7 +435,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID,
|
||||
sensed_input.m_device_id = deviceID;
|
||||
sensed_input.m_button_id = button;
|
||||
sensed_input.m_character = deviceID;
|
||||
OptionsScreenInput2::getInstance()->gotSensedInput(sensed_input);
|
||||
OptionsScreenDevice::getInstance()->gotSensedInput(sensed_input);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -437,7 +447,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID,
|
||||
sensed_input.m_device_id = deviceID;
|
||||
sensed_input.m_button_id = button;
|
||||
sensed_input.m_character = deviceID;
|
||||
OptionsScreenInput2::getInstance()->gotSensedInput(sensed_input);
|
||||
OptionsScreenDevice::getInstance()->gotSensedInput(sensed_input);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -472,7 +482,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID,
|
||||
: Input::AD_NEGATIVE;
|
||||
sensed_input.m_axis_range = Input::AR_FULL;
|
||||
sensed_input.m_character = deviceID;
|
||||
OptionsScreenInput2::getInstance()->gotSensedInput(sensed_input);
|
||||
OptionsScreenDevice::getInstance()->gotSensedInput(sensed_input);
|
||||
|
||||
}
|
||||
else m_sensed_input_high_gamepad.insert(input_id);
|
||||
@ -494,7 +504,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID,
|
||||
sensed_input.m_axis_range = id_was_zero ? Input::AR_HALF
|
||||
: Input::AR_FULL;
|
||||
sensed_input.m_character = deviceID;
|
||||
OptionsScreenInput2::getInstance()->gotSensedInput(sensed_input);
|
||||
OptionsScreenDevice::getInstance()->gotSensedInput(sensed_input);
|
||||
}
|
||||
else if( inverse_id_was_high )
|
||||
{
|
||||
@ -510,7 +520,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID,
|
||||
sensed_input.m_axis_range = id_was_zero ? Input::AR_HALF
|
||||
: Input::AR_FULL;
|
||||
sensed_input.m_character = deviceID;
|
||||
OptionsScreenInput2::getInstance()->gotSensedInput(sensed_input);
|
||||
OptionsScreenDevice::getInstance()->gotSensedInput(sensed_input);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -921,20 +931,8 @@ EventPropagation InputManager::input(const SEvent& event)
|
||||
// escape is a little special
|
||||
if (key == KEY_ESCAPE)
|
||||
{
|
||||
// Exit from first person view if activated
|
||||
if (!GUIEngine::ModalDialog::isADialogActive() &&
|
||||
StateManager::get()->getGameState() == GUIEngine::GAME &&
|
||||
UserConfigParams::m_camera_debug == 3)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 0;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
return EVENT_BLOCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
StateManager::get()->escapePressed();
|
||||
return EVENT_BLOCK;
|
||||
}
|
||||
StateManager::get()->escapePressed();
|
||||
return EVENT_BLOCK;
|
||||
}
|
||||
// 'backspace' in a text control must never be mapped, since user
|
||||
// can be in a text area trying to erase text (and if it's mapped
|
||||
|
@ -61,7 +61,7 @@ Event::Event(ENetEvent* event)
|
||||
if (peers[i]->m_peer == event->peer)
|
||||
{
|
||||
*peer = peers[i];
|
||||
Log::verbose("Event", "The peer you sought has been found on %lx", (long int)(peer));
|
||||
Log::verbose("Event", "The peer you sought has been found on %p", peer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -70,7 +70,7 @@ Event::Event(ENetEvent* event)
|
||||
STKPeer* new_peer = new STKPeer();
|
||||
new_peer->m_peer = event->peer;
|
||||
*peer = new_peer;
|
||||
Log::debug("Event", "Creating a new peer, address are STKPeer:%lx, Peer:%lx", (long int)(new_peer), (long int)(event->peer));
|
||||
Log::debug("Event", "Creating a new peer, address are STKPeer:%p, Peer:%p", new_peer, event->peer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
#include "network/protocol_manager.hpp"
|
||||
|
||||
#include "network/protocol.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include "network/protocol.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
@ -28,17 +28,25 @@
|
||||
#include <errno.h>
|
||||
#include <typeinfo>
|
||||
|
||||
void* protocolManagerUpdate(void* data)
|
||||
|
||||
ProtocolManager::ProtocolManager()
|
||||
{
|
||||
ProtocolManager* manager = static_cast<ProtocolManager*>(data);
|
||||
while(manager && !manager->exit())
|
||||
{
|
||||
manager->update();
|
||||
StkTime::sleep(2);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void* protocolManagerAsynchronousUpdate(void* data)
|
||||
pthread_mutex_init(&m_asynchronous_protocols_mutex, NULL);
|
||||
pthread_mutex_init(&m_requests_mutex, NULL);
|
||||
pthread_mutex_init(&m_id_mutex, NULL);
|
||||
pthread_mutex_init(&m_exit_mutex, NULL);
|
||||
m_next_protocol_id = 0;
|
||||
|
||||
pthread_mutex_lock(&m_exit_mutex); // will let the update function run
|
||||
|
||||
m_asynchronous_update_thread = (pthread_t*)(malloc(sizeof(pthread_t)));
|
||||
pthread_create(m_asynchronous_update_thread, NULL,
|
||||
ProtocolManager::mainLoop, this);
|
||||
} // ProtocolManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void* ProtocolManager::mainLoop(void* data)
|
||||
{
|
||||
ProtocolManager* manager = static_cast<ProtocolManager*>(data);
|
||||
manager->m_asynchronous_thread_running = true;
|
||||
@ -49,78 +57,56 @@ void* protocolManagerAsynchronousUpdate(void* data)
|
||||
}
|
||||
manager->m_asynchronous_thread_running = false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ProtocolManager::ProtocolManager()
|
||||
{
|
||||
pthread_mutex_init(&m_events_mutex, NULL);
|
||||
pthread_mutex_init(&m_protocols_mutex, NULL);
|
||||
pthread_mutex_init(&m_asynchronous_protocols_mutex, NULL);
|
||||
pthread_mutex_init(&m_requests_mutex, NULL);
|
||||
pthread_mutex_init(&m_id_mutex, NULL);
|
||||
pthread_mutex_init(&m_exit_mutex, NULL);
|
||||
m_next_protocol_id = 0;
|
||||
} // protocolManagerAsynchronousUpdate
|
||||
|
||||
|
||||
pthread_mutex_lock(&m_exit_mutex); // will let the update function run
|
||||
/// FIXME used on server because mainloop never running
|
||||
/*if (NetworkManager::getInstance()->isServer())
|
||||
{
|
||||
m_update_thread = (pthread_t*)(malloc(sizeof(pthread_t)));
|
||||
pthread_create(m_update_thread, NULL, protocolManagerUpdate, this);
|
||||
}*/
|
||||
// always run this one
|
||||
m_asynchronous_update_thread = (pthread_t*)(malloc(sizeof(pthread_t)));
|
||||
pthread_create(m_asynchronous_update_thread, NULL, protocolManagerAsynchronousUpdate, this);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
ProtocolManager::~ProtocolManager()
|
||||
{
|
||||
}
|
||||
|
||||
} // ~ProtocolManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::abort()
|
||||
{
|
||||
pthread_mutex_unlock(&m_exit_mutex); // will stop the update function
|
||||
pthread_join(*m_asynchronous_update_thread, NULL); // wait the thread to finish
|
||||
pthread_mutex_lock(&m_events_mutex);
|
||||
pthread_mutex_lock(&m_protocols_mutex);
|
||||
m_events_to_process.lock();
|
||||
m_protocols.lock();
|
||||
pthread_mutex_lock(&m_asynchronous_protocols_mutex);
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
pthread_mutex_lock(&m_id_mutex);
|
||||
for (unsigned int i = 0; i < m_protocols.size() ; i++)
|
||||
delete m_protocols[i].protocol;
|
||||
for (unsigned int i = 0; i < m_events_to_process.size() ; i++)
|
||||
delete m_events_to_process[i].event;
|
||||
m_protocols.clear();
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size() ; i++)
|
||||
delete m_protocols.getData()[i].protocol;
|
||||
for (unsigned int i = 0; i < m_events_to_process.getData().size() ; i++)
|
||||
delete m_events_to_process.getData()[i].event;
|
||||
m_protocols.getData().clear();
|
||||
m_requests.clear();
|
||||
m_events_to_process.clear();
|
||||
pthread_mutex_unlock(&m_events_mutex);
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
m_events_to_process.getData().clear();
|
||||
m_events_to_process.unlock();
|
||||
m_protocols.unlock();
|
||||
pthread_mutex_unlock(&m_asynchronous_protocols_mutex);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
pthread_mutex_unlock(&m_id_mutex);
|
||||
|
||||
pthread_mutex_destroy(&m_events_mutex);
|
||||
pthread_mutex_destroy(&m_protocols_mutex);
|
||||
pthread_mutex_destroy(&m_asynchronous_protocols_mutex);
|
||||
pthread_mutex_destroy(&m_requests_mutex);
|
||||
pthread_mutex_destroy(&m_id_mutex);
|
||||
pthread_mutex_destroy(&m_exit_mutex);
|
||||
}
|
||||
} // abort
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::notifyEvent(Event* event)
|
||||
{
|
||||
pthread_mutex_lock(&m_events_mutex);
|
||||
m_events_to_process.lock();
|
||||
Event* event2 = new Event(*event);
|
||||
// register protocols that will receive this event
|
||||
std::vector<unsigned int> protocols_ids;
|
||||
PROTOCOL_TYPE searchedProtocol = PROTOCOL_NONE;
|
||||
PROTOCOL_TYPE searched_protocol = PROTOCOL_NONE;
|
||||
if (event2->type == EVENT_TYPE_MESSAGE)
|
||||
{
|
||||
if (event2->data().size() > 0)
|
||||
{
|
||||
searchedProtocol = (PROTOCOL_TYPE)(event2->data()[0]);
|
||||
searched_protocol = (PROTOCOL_TYPE)(event2->data()[0]);
|
||||
event2->removeFront(1);
|
||||
}
|
||||
else
|
||||
@ -130,21 +116,26 @@ void ProtocolManager::notifyEvent(Event* event)
|
||||
}
|
||||
if (event2->type == EVENT_TYPE_CONNECTED)
|
||||
{
|
||||
searchedProtocol = PROTOCOL_CONNECTION;
|
||||
searched_protocol = PROTOCOL_CONNECTION;
|
||||
}
|
||||
Log::verbose("ProtocolManager", "Received event for protocols of type %d", searchedProtocol);
|
||||
pthread_mutex_lock(&m_protocols_mutex);
|
||||
for (unsigned int i = 0; i < m_protocols.size() ; i++)
|
||||
Log::verbose("ProtocolManager", "Received event for protocols of type %d",
|
||||
searched_protocol);
|
||||
m_protocols.lock();
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size() ; i++)
|
||||
{
|
||||
if (m_protocols[i].protocol->getProtocolType() == searchedProtocol || event2->type == EVENT_TYPE_DISCONNECTED) // pass data to protocols even when paused
|
||||
// Pass data to protocols even when paused
|
||||
if (m_protocols.getData()[i].protocol->getProtocolType() == searched_protocol ||
|
||||
event2->type == EVENT_TYPE_DISCONNECTED)
|
||||
{
|
||||
protocols_ids.push_back(m_protocols[i].id);
|
||||
protocols_ids.push_back(m_protocols.getData()[i].id);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
if (searchedProtocol == PROTOCOL_NONE) // no protocol was aimed, show the msg to debug
|
||||
m_protocols.unlock();
|
||||
// no protocol was aimed, show the msg to debug
|
||||
if (searched_protocol == PROTOCOL_NONE)
|
||||
{
|
||||
Log::debug("ProtocolManager", "NO PROTOCOL : Message is \"%s\"", event2->data().std_string().c_str());
|
||||
Log::debug("ProtocolManager", "NO PROTOCOL : Message is \"%s\"",
|
||||
event2->data().std_string().c_str());
|
||||
}
|
||||
|
||||
if (protocols_ids.size() != 0)
|
||||
@ -153,36 +144,47 @@ void ProtocolManager::notifyEvent(Event* event)
|
||||
epi.arrival_time = (double)StkTime::getTimeSinceEpoch();
|
||||
epi.event = event2;
|
||||
epi.protocols_ids = protocols_ids;
|
||||
m_events_to_process.push_back(epi); // add the event to the queue
|
||||
m_events_to_process.getData().push_back(epi); // add the event to the queue
|
||||
}
|
||||
else
|
||||
Log::warn("ProtocolManager", "Received an event for %d that has no destination protocol.", searchedProtocol);
|
||||
pthread_mutex_unlock(&m_events_mutex);
|
||||
}
|
||||
Log::warn("ProtocolManager",
|
||||
"Received an event for %d that has no destination protocol.",
|
||||
searched_protocol);
|
||||
m_events_to_process.lock();
|
||||
} // notifyEvent
|
||||
|
||||
void ProtocolManager::sendMessage(Protocol* sender, const NetworkString& message, bool reliable)
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::sendMessage(Protocol* sender, const NetworkString& message,
|
||||
bool reliable)
|
||||
{
|
||||
NetworkString newMessage;
|
||||
newMessage.ai8(sender->getProtocolType()); // add one byte to add protocol type
|
||||
newMessage += message;
|
||||
NetworkManager::getInstance()->sendPacket(newMessage, reliable);
|
||||
}
|
||||
} // sendMessage
|
||||
|
||||
void ProtocolManager::sendMessage(Protocol* sender, STKPeer* peer, const NetworkString& message, bool reliable)
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::sendMessage(Protocol* sender, STKPeer* peer,
|
||||
const NetworkString& message, bool reliable)
|
||||
{
|
||||
NetworkString newMessage;
|
||||
newMessage.ai8(sender->getProtocolType()); // add one byte to add protocol type
|
||||
newMessage += message;
|
||||
NetworkManager::getInstance()->sendPacket(peer, newMessage, reliable);
|
||||
}
|
||||
void ProtocolManager::sendMessageExcept(Protocol* sender, STKPeer* peer, const NetworkString& message, bool reliable)
|
||||
} // sendMessage
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::sendMessageExcept(Protocol* sender, STKPeer* peer,
|
||||
const NetworkString& message,
|
||||
bool reliable)
|
||||
{
|
||||
NetworkString newMessage;
|
||||
newMessage.ai8(sender->getProtocolType()); // add one byte to add protocol type
|
||||
newMessage += message;
|
||||
NetworkManager::getInstance()->sendPacketExcept(peer, newMessage, reliable);
|
||||
}
|
||||
} // sendMessageExcept
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
uint32_t ProtocolManager::requestStart(Protocol* protocol)
|
||||
{
|
||||
// create the request
|
||||
@ -199,8 +201,9 @@ uint32_t ProtocolManager::requestStart(Protocol* protocol)
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
|
||||
return info.id;
|
||||
}
|
||||
} // requestStart
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::requestStop(Protocol* protocol)
|
||||
{
|
||||
if (!protocol)
|
||||
@ -213,8 +216,9 @@ void ProtocolManager::requestStop(Protocol* protocol)
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
} // requestStop
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::requestPause(Protocol* protocol)
|
||||
{
|
||||
if (!protocol)
|
||||
@ -227,8 +231,9 @@ void ProtocolManager::requestPause(Protocol* protocol)
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
} // requestPause
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::requestUnpause(Protocol* protocol)
|
||||
{
|
||||
if (!protocol)
|
||||
@ -241,8 +246,9 @@ void ProtocolManager::requestUnpause(Protocol* protocol)
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
} // requestUnpause
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::requestTerminate(Protocol* protocol)
|
||||
{
|
||||
if (!protocol)
|
||||
@ -264,86 +270,111 @@ void ProtocolManager::requestTerminate(Protocol* protocol)
|
||||
}
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
} // requestTerminate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::startProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
// add the protocol to the protocol vector so that it's updated
|
||||
pthread_mutex_lock(&m_protocols_mutex);
|
||||
m_protocols.lock();
|
||||
pthread_mutex_lock(&m_asynchronous_protocols_mutex);
|
||||
Log::info("ProtocolManager", "A %s protocol with id=%u has been started. There are %ld protocols running.", typeid(*protocol.protocol).name(), protocol.id, m_protocols.size()+1);
|
||||
m_protocols.push_back(protocol);
|
||||
Log::info("ProtocolManager",
|
||||
"A %s protocol with id=%u has been started. There are %ld protocols running.",
|
||||
typeid(*protocol.protocol).name(), protocol.id,
|
||||
m_protocols.getData().size()+1);
|
||||
m_protocols.getData().push_back(protocol);
|
||||
// setup the protocol and notify it that it's started
|
||||
protocol.protocol->setListener(this);
|
||||
protocol.protocol->setup();
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
m_protocols.unlock();
|
||||
pthread_mutex_unlock(&m_asynchronous_protocols_mutex);
|
||||
}
|
||||
} // startProtocol
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::stopProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
} // stopProtocol
|
||||
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::pauseProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
// FIXME Does this need to be locked?
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol.protocol && m_protocols[i].state == PROTOCOL_STATE_RUNNING)
|
||||
ProtocolInfo &p = m_protocols.getData()[i];
|
||||
if (p.protocol == protocol.protocol &&
|
||||
p.state == PROTOCOL_STATE_RUNNING)
|
||||
{
|
||||
m_protocols[i].state = PROTOCOL_STATE_PAUSED;
|
||||
m_protocols[i].protocol->pause();
|
||||
p.state = PROTOCOL_STATE_PAUSED;
|
||||
p.protocol->pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // pauseProtocol
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::unpauseProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
// FIXME Does this need to be locked??
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol.protocol && m_protocols[i].state == PROTOCOL_STATE_PAUSED)
|
||||
ProtocolInfo &p = m_protocols.getData()[i];
|
||||
if (p.protocol == protocol.protocol &&
|
||||
p.state == PROTOCOL_STATE_PAUSED)
|
||||
{
|
||||
m_protocols[i].state = PROTOCOL_STATE_RUNNING;
|
||||
m_protocols[i].protocol->unpause();
|
||||
p.state = PROTOCOL_STATE_RUNNING;
|
||||
p.protocol->unpause();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // unpauseProtocol
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::protocolTerminated(ProtocolInfo protocol)
|
||||
{
|
||||
pthread_mutex_lock(&m_protocols_mutex); // be sure that noone accesses the protocols vector while we erase a protocol
|
||||
// Be sure that noone accesses the protocols vector while we erase a protocol
|
||||
m_protocols.lock();
|
||||
pthread_mutex_lock(&m_asynchronous_protocols_mutex);
|
||||
int offset = 0;
|
||||
std::string protocol_type = typeid(*protocol.protocol).name();
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i-offset].protocol == protocol.protocol)
|
||||
if (m_protocols.getData()[i-offset].protocol == protocol.protocol)
|
||||
{
|
||||
delete m_protocols[i].protocol;
|
||||
m_protocols.erase(m_protocols.begin()+(i-offset), m_protocols.begin()+(i-offset)+1);
|
||||
delete m_protocols.getData()[i].protocol;
|
||||
m_protocols.getData().erase(m_protocols.getData().begin()+(i-offset),
|
||||
m_protocols.getData().begin()+(i-offset)+1);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
Log::info("ProtocolManager", "A %s protocol has been terminated. There are %ld protocols running.", protocol_type.c_str(), m_protocols.size());
|
||||
Log::info("ProtocolManager",
|
||||
"A %s protocol has been terminated. There are %ld protocols running.",
|
||||
protocol_type.c_str(), m_protocols.getData().size());
|
||||
pthread_mutex_unlock(&m_asynchronous_protocols_mutex);
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
}
|
||||
m_protocols.unlock();
|
||||
} // protocolTerminated
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool ProtocolManager::propagateEvent(EventProcessingInfo* event, bool synchronous)
|
||||
{
|
||||
int index = 0;
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (event->protocols_ids[index] == m_protocols[i].id)
|
||||
if (event->protocols_ids[index] == m_protocols.getData()[i].id)
|
||||
{
|
||||
bool result = false;
|
||||
if (synchronous)
|
||||
result = m_protocols[i].protocol->notifyEvent(event->event);
|
||||
result = m_protocols.getData()[i].protocol
|
||||
->notifyEvent(event->event);
|
||||
else
|
||||
result = m_protocols[i].protocol->notifyEventAsynchronous(event->event);
|
||||
result = m_protocols.getData()[i].protocol
|
||||
->notifyEventAsynchronous(event->event);
|
||||
if (result)
|
||||
event->protocols_ids.pop_back();
|
||||
else
|
||||
index++;
|
||||
}
|
||||
}
|
||||
if (event->protocols_ids.size() == 0 || (StkTime::getTimeSinceEpoch()-event->arrival_time) >= TIME_TO_KEEP_EVENTS)
|
||||
if (event->protocols_ids.size() == 0 ||
|
||||
(StkTime::getTimeSinceEpoch()-event->arrival_time) >= TIME_TO_KEEP_EVENTS)
|
||||
{
|
||||
// because we made a copy of the event
|
||||
delete event->event->peer; // no more need of that
|
||||
@ -351,57 +382,64 @@ bool ProtocolManager::propagateEvent(EventProcessingInfo* event, bool synchronou
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // propagateEvent
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::update()
|
||||
{
|
||||
// before updating, notice protocols that they have received events
|
||||
pthread_mutex_lock(&m_events_mutex); // secure threads
|
||||
int size = (int)m_events_to_process.size();
|
||||
m_events_to_process.lock();
|
||||
int size = (int)m_events_to_process.getData().size();
|
||||
int offset = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
bool result = propagateEvent(&m_events_to_process[i+offset], true);
|
||||
bool result = propagateEvent(&m_events_to_process.getData()[i+offset], true);
|
||||
if (result)
|
||||
{
|
||||
m_events_to_process.erase(m_events_to_process.begin()+i+offset,m_events_to_process.begin()+i+offset+1);
|
||||
m_events_to_process.getData()
|
||||
.erase(m_events_to_process.getData().begin()+i+offset,
|
||||
m_events_to_process.getData().begin()+i+offset+1);
|
||||
offset --;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&m_events_mutex); // release the mutex
|
||||
m_events_to_process.unlock();
|
||||
// now update all protocols
|
||||
pthread_mutex_lock(&m_protocols_mutex);
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
m_protocols.lock();
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].state == PROTOCOL_STATE_RUNNING)
|
||||
m_protocols[i].protocol->update();
|
||||
if (m_protocols.getData()[i].state == PROTOCOL_STATE_RUNNING)
|
||||
m_protocols.getData()[i].protocol->update();
|
||||
}
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
}
|
||||
m_protocols.unlock();
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::asynchronousUpdate()
|
||||
{
|
||||
// before updating, notice protocols that they have received information
|
||||
pthread_mutex_lock(&m_events_mutex); // secure threads
|
||||
int size = (int)m_events_to_process.size();
|
||||
m_events_to_process.lock();
|
||||
int size = (int)m_events_to_process.getData().size();
|
||||
int offset = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
bool result = propagateEvent(&m_events_to_process[i+offset], false);
|
||||
bool result = propagateEvent(&m_events_to_process.getData()[i+offset], false);
|
||||
if (result)
|
||||
{
|
||||
m_events_to_process.erase(m_events_to_process.begin()+i+offset,m_events_to_process.begin()+i+offset+1);
|
||||
m_events_to_process.getData()
|
||||
.erase(m_events_to_process.getData().begin()+i+offset,
|
||||
m_events_to_process.getData().begin()+i+offset+1);
|
||||
offset --;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&m_events_mutex); // release the mutex
|
||||
m_events_to_process.unlock();
|
||||
|
||||
// now update all protocols that need to be updated in asynchronous mode
|
||||
pthread_mutex_lock(&m_asynchronous_protocols_mutex);
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
// FIXME: does m_protocols need to be locked???
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].state == PROTOCOL_STATE_RUNNING)
|
||||
m_protocols[i].protocol->asynchronousUpdate();
|
||||
if (m_protocols.getData()[i].state == PROTOCOL_STATE_RUNNING)
|
||||
m_protocols.getData()[i].protocol->asynchronousUpdate();
|
||||
}
|
||||
pthread_mutex_unlock(&m_asynchronous_protocols_mutex);
|
||||
|
||||
@ -431,79 +469,90 @@ void ProtocolManager::asynchronousUpdate()
|
||||
}
|
||||
m_requests.clear();
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
|
||||
int ProtocolManager::runningProtocolsCount()
|
||||
{
|
||||
return (int)m_protocols.size();
|
||||
}
|
||||
} // asynchronousUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
PROTOCOL_STATE ProtocolManager::getProtocolState(uint32_t id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
//FIXME that actually need a lock, but it also can be called from
|
||||
// a locked section anyway
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].id == id) // we know a protocol with that id
|
||||
return m_protocols[i].state; // return its state
|
||||
if (m_protocols.getData()[i].id == id) // we know a protocol with that id
|
||||
return m_protocols.getData()[i].state;
|
||||
}
|
||||
// the protocol isn't running right now
|
||||
for (unsigned int i = 0; i < m_requests.size(); i++)
|
||||
{
|
||||
if (m_requests[i].protocol_info.id == id) // the protocol is going to be started
|
||||
// the protocol is going to be started
|
||||
if (m_requests[i].protocol_info.id == id)
|
||||
return PROTOCOL_STATE_RUNNING; // we can say it's running
|
||||
}
|
||||
return PROTOCOL_STATE_TERMINATED; // else, it's already finished
|
||||
}
|
||||
} // getProtocolState
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
PROTOCOL_STATE ProtocolManager::getProtocolState(Protocol* protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
// FIXME Does this need to be locked?
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol) // the protocol is known
|
||||
return m_protocols[i].state; // return its state
|
||||
if (m_protocols.getData()[i].protocol == protocol) // the protocol is known
|
||||
return m_protocols.getData()[i].state;
|
||||
}
|
||||
for (unsigned int i = 0; i < m_requests.size(); i++)
|
||||
{
|
||||
if (m_requests[i].protocol_info.protocol == protocol) // the protocol is going to be started
|
||||
// the protocol is going to be started
|
||||
if (m_requests[i].protocol_info.protocol == protocol)
|
||||
return PROTOCOL_STATE_RUNNING; // we can say it's running
|
||||
}
|
||||
return PROTOCOL_STATE_TERMINATED; // we don't know this protocol at all, it's finished
|
||||
}
|
||||
// we don't know this protocol at all, it's finished
|
||||
return PROTOCOL_STATE_TERMINATED;
|
||||
} // getProtocolState
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
uint32_t ProtocolManager::getProtocolID(Protocol* protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
// FIXME: Does this need to be locked?
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol)
|
||||
return m_protocols[i].id;
|
||||
if (m_protocols.getData()[i].protocol == protocol)
|
||||
return m_protocols.getData()[i].id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // getProtocolID
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
Protocol* ProtocolManager::getProtocol(uint32_t id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
// FIXME: does m_protocols need to be locked??
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].id == id)
|
||||
return m_protocols[i].protocol;
|
||||
if (m_protocols.getData()[i].id == id)
|
||||
return m_protocols.getData()[i].protocol;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
} // getProtocol
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
Protocol* ProtocolManager::getProtocol(PROTOCOL_TYPE type)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
// FIXME: Does m_protocols need to be locked?
|
||||
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol->getProtocolType() == type)
|
||||
return m_protocols[i].protocol;
|
||||
if (m_protocols.getData()[i].protocol->getProtocolType() == type)
|
||||
return m_protocols.getData()[i].protocol;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
} // getProtocol
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool ProtocolManager::isServer()
|
||||
{
|
||||
return NetworkManager::getInstance()->isServer();
|
||||
}
|
||||
} // isServer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int ProtocolManager::exit()
|
||||
{
|
||||
switch(pthread_mutex_trylock(&m_exit_mutex)) {
|
||||
@ -514,14 +563,15 @@ int ProtocolManager::exit()
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
} // exit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ProtocolManager::assignProtocolId(ProtocolInfo* protocol_info)
|
||||
{
|
||||
pthread_mutex_lock(&m_id_mutex);
|
||||
protocol_info->id = m_next_protocol_id;
|
||||
m_next_protocol_id++;
|
||||
pthread_mutex_unlock(&m_id_mutex);
|
||||
}
|
||||
} // assignProtocolId
|
||||
|
||||
|
||||
|
@ -26,7 +26,9 @@
|
||||
#include "network/event.hpp"
|
||||
#include "network/network_string.hpp"
|
||||
#include "network/protocol.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
#include "utils/singleton.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
#include <vector>
|
||||
@ -102,10 +104,11 @@ typedef struct EventProcessingInfo
|
||||
* frames per second. Then, the management of protocols is thread-safe: any
|
||||
* object can start/pause/stop protocols whithout problems.
|
||||
*/
|
||||
class ProtocolManager : public AbstractSingleton<ProtocolManager>
|
||||
class ProtocolManager : public AbstractSingleton<ProtocolManager>,
|
||||
public NoCopy
|
||||
{
|
||||
friend class AbstractSingleton<ProtocolManager>;
|
||||
friend void* protocolManagerAsynchronousUpdate(void* data);
|
||||
static void* mainLoop(void *data);
|
||||
public:
|
||||
|
||||
/*! \brief Stops the protocol manager. */
|
||||
@ -189,11 +192,6 @@ class ProtocolManager : public AbstractSingleton<ProtocolManager>
|
||||
*/
|
||||
virtual void asynchronousUpdate();
|
||||
|
||||
/*!
|
||||
* \brief Get the number of protocols running.
|
||||
* \return The number of protocols that are actually running.
|
||||
*/
|
||||
virtual int runningProtocolsCount();
|
||||
/*!
|
||||
* \brief Get the state of a protocol using its id.
|
||||
* \param id : The id of the protocol you seek the state.
|
||||
@ -287,19 +285,15 @@ class ProtocolManager : public AbstractSingleton<ProtocolManager>
|
||||
bool propagateEvent(EventProcessingInfo* event, bool synchronous);
|
||||
|
||||
// protected members
|
||||
/*!
|
||||
* \brief Contains the running protocols.
|
||||
* This stores the protocols that are either running or paused, their
|
||||
* state and their unique id.
|
||||
*/
|
||||
std::vector<ProtocolInfo> m_protocols;
|
||||
/*!
|
||||
* \brief Contains the network events to pass to protocols.
|
||||
*/
|
||||
std::vector<EventProcessingInfo> m_events_to_process;
|
||||
/*!
|
||||
* \brief Contains the requests to start/stop etc... protocols.
|
||||
*/
|
||||
/** Contains the running protocols.
|
||||
* This stores the protocols that are either running or paused, their
|
||||
* state and their unique id. */
|
||||
Synchronised<std::vector<ProtocolInfo> >m_protocols;
|
||||
|
||||
/** Contains the network events to pass to protocols. */
|
||||
Synchronised<std::vector<EventProcessingInfo> > m_events_to_process;
|
||||
|
||||
/** Contains the requests to start/stop etc... protocols. */
|
||||
std::vector<ProtocolRequest> m_requests;
|
||||
/*! \brief The next id to assign to a protocol.
|
||||
* This value is incremented by 1 each time a protocol is started.
|
||||
@ -309,10 +303,6 @@ class ProtocolManager : public AbstractSingleton<ProtocolManager>
|
||||
uint32_t m_next_protocol_id;
|
||||
|
||||
// mutexes:
|
||||
/*! Used to ensure that the event queue is used thread-safely. */
|
||||
pthread_mutex_t m_events_mutex;
|
||||
/*! Used to ensure that the protocol vector is used thread-safely. */
|
||||
pthread_mutex_t m_protocols_mutex;
|
||||
/*! Used to ensure that the protocol vector is used thread-safely. */
|
||||
pthread_mutex_t m_asynchronous_protocols_mutex;
|
||||
/*! Used to ensure that the request vector is used thread-safely. */
|
||||
|
@ -80,9 +80,9 @@ bool STKPeer::connectToHost(STKHost* localhost, TransportAddress host,
|
||||
return false;
|
||||
}
|
||||
Log::verbose("STKPeer", "Connecting to %i.%i.%i.%i:%i.\nENetPeer address "
|
||||
"is %ld", (peer->address.host>>0)&0xff,
|
||||
"is %p", (peer->address.host>>0)&0xff,
|
||||
(peer->address.host>>8)&0xff,(peer->address.host>>16)&0xff,
|
||||
(peer->address.host>>24)&0xff,peer->address.port, (long int)(peer));
|
||||
(peer->address.host>>24)&0xff,peer->address.port, peer);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace Online
|
||||
{
|
||||
Server::SortOrder Server::m_sort_order = Server::SO_NAME;
|
||||
|
||||
Server::Server(const XMLNode & xml)
|
||||
Server::Server(const XMLNode & xml, bool is_lan)
|
||||
{
|
||||
assert(xml.getName() == "server");
|
||||
|
||||
@ -37,9 +37,10 @@ namespace Online
|
||||
m_server_id = 0;
|
||||
m_current_players = 0;
|
||||
m_max_players = 0;
|
||||
m_is_lan = is_lan;
|
||||
|
||||
xml.get("name", &m_lower_case_name);
|
||||
m_name = StringUtils::xmlDecode(m_lower_case_name);
|
||||
m_name = StringUtils::xmlDecode(m_lower_case_name);
|
||||
m_lower_case_name = StringUtils::toLowerCase(m_lower_case_name);
|
||||
|
||||
xml.get("id", &m_server_id);
|
||||
@ -49,6 +50,18 @@ namespace Online
|
||||
|
||||
} // Server(const XML&)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
Server::Server(const core::stringw &name, bool is_lan, int max_players,
|
||||
int current_players)
|
||||
{
|
||||
m_name = name;
|
||||
m_satisfaction_score = 0;
|
||||
m_server_id = 0;
|
||||
m_current_players = current_players;
|
||||
m_max_players = max_players;
|
||||
m_is_lan = is_lan;
|
||||
} // server(name, ...)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/**
|
||||
* \brief Filter the add-on with a list of words.
|
||||
|
@ -65,6 +65,9 @@ namespace Online
|
||||
/** The score/rating given */
|
||||
float m_satisfaction_score;
|
||||
|
||||
/** True if this server is on the LAN, false otherwise. */
|
||||
bool m_is_lan;
|
||||
|
||||
/** The sort order to be used in the comparison. */
|
||||
static SortOrder m_sort_order;
|
||||
|
||||
@ -73,8 +76,9 @@ namespace Online
|
||||
public:
|
||||
|
||||
/** Initialises the object from an XML node. */
|
||||
Server(const XMLNode & xml);
|
||||
|
||||
Server(const XMLNode &xml, bool is_lan);
|
||||
Server(const core::stringw &name, bool is_lan, int max_players,
|
||||
int current_players);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the sort order used in the comparison function. It is static, so
|
||||
* that each instance can access the sort order. */
|
||||
|
@ -18,13 +18,14 @@
|
||||
|
||||
#include "online/servers_manager.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <irrString.h>
|
||||
#include <assert.h>
|
||||
#include "config/user_config.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <irrString.h>
|
||||
#include <string>
|
||||
|
||||
#define SERVER_REFRESH_INTERVAL 5.0f
|
||||
|
||||
namespace Online
|
||||
@ -37,29 +38,31 @@ namespace Online
|
||||
manager_singleton = new ServersManager();
|
||||
|
||||
return manager_singleton;
|
||||
}
|
||||
} // get
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void ServersManager::deallocate()
|
||||
{
|
||||
delete manager_singleton;
|
||||
manager_singleton = NULL;
|
||||
} // deallocate
|
||||
|
||||
// ============================================================================
|
||||
// ========================================================================
|
||||
ServersManager::ServersManager()
|
||||
{
|
||||
m_last_load_time.setAtomic(0.0f);
|
||||
m_joined_server.setAtomic(NULL);
|
||||
}
|
||||
} // ServersManager
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
ServersManager::~ServersManager()
|
||||
{
|
||||
cleanUpServers();
|
||||
MutexLocker(m_joined_server);
|
||||
delete m_joined_server.getData();
|
||||
}
|
||||
} // ~ServersManager
|
||||
|
||||
// ============================================================================
|
||||
// ------------------------------------------------------------------------
|
||||
void ServersManager::cleanUpServers()
|
||||
{
|
||||
m_sorted_servers.lock();
|
||||
@ -68,12 +71,12 @@ namespace Online
|
||||
m_mapped_servers.lock();
|
||||
m_mapped_servers.getData().clear();
|
||||
m_mapped_servers.unlock();
|
||||
}
|
||||
} // cleanUpServers
|
||||
|
||||
// ============================================================================
|
||||
ServersManager::RefreshRequest * ServersManager::refreshRequest(bool request_now) const
|
||||
// ------------------------------------------------------------------------
|
||||
ServersManager::RefreshRequest* ServersManager::refreshRequest(bool request_now) const
|
||||
{
|
||||
RefreshRequest * request = NULL;
|
||||
RefreshRequest* request = NULL;
|
||||
if(StkTime::getRealTime() - m_last_load_time.getAtomic() > SERVER_REFRESH_INTERVAL)
|
||||
{
|
||||
request = new RefreshRequest();
|
||||
@ -84,9 +87,14 @@ namespace Online
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
} // refreshRequest
|
||||
|
||||
void ServersManager::refresh(bool success, const XMLNode * input)
|
||||
// ------------------------------------------------------------------------
|
||||
/** Callback from the refresh request.
|
||||
* \param success If the refresh was successful.
|
||||
* \param input The XML data describing the server.
|
||||
*/
|
||||
void ServersManager::refresh(bool success, const XMLNode *input)
|
||||
{
|
||||
if (!success)
|
||||
{
|
||||
@ -94,30 +102,31 @@ namespace Online
|
||||
return;
|
||||
}
|
||||
|
||||
const XMLNode * servers_xml = input->getNode("servers");
|
||||
const XMLNode *servers_xml = input->getNode("servers");
|
||||
cleanUpServers();
|
||||
for (unsigned int i = 0; i < servers_xml->getNumNodes(); i++)
|
||||
{
|
||||
addServer(new Server(*servers_xml->getNode(i)));
|
||||
addServer(new Server(*servers_xml->getNode(i), /*is_lan*/false));
|
||||
}
|
||||
m_last_load_time.setAtomic((float)StkTime::getRealTime());
|
||||
}
|
||||
} // refresh
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void ServersManager::RefreshRequest::callback()
|
||||
{
|
||||
ServersManager::get()->refresh(isSuccess(), getXMLData());
|
||||
}
|
||||
} // callback
|
||||
|
||||
// ============================================================================
|
||||
const Server * ServersManager::getQuickPlay() const
|
||||
// ------------------------------------------------------------------------
|
||||
const Server* ServersManager::getQuickPlay() const
|
||||
{
|
||||
if(m_sorted_servers.getData().size() > 0)
|
||||
return getServerBySort(0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
} // getQuickPlay
|
||||
|
||||
// ============================================================================
|
||||
// ------------------------------------------------------------------------
|
||||
void ServersManager::setJoinedServer(uint32_t id)
|
||||
{
|
||||
MutexLocker(m_joined_server);
|
||||
@ -125,18 +134,18 @@ namespace Online
|
||||
|
||||
// It's a copy!
|
||||
m_joined_server.getData() = new Server(*getServerByID(id));
|
||||
}
|
||||
} // setJoinedServer
|
||||
|
||||
// ============================================================================
|
||||
// ------------------------------------------------------------------------
|
||||
void ServersManager::unsetJoinedServer()
|
||||
{
|
||||
MutexLocker(m_joined_server);
|
||||
delete m_joined_server.getData();
|
||||
m_joined_server.getData() = NULL;
|
||||
}
|
||||
} // unsetJoinedServer
|
||||
|
||||
// ============================================================================
|
||||
void ServersManager::addServer(Server * server)
|
||||
// ------------------------------------------------------------------------
|
||||
void ServersManager::addServer(Server *server)
|
||||
{
|
||||
m_sorted_servers.lock();
|
||||
m_sorted_servers.getData().push_back(server);
|
||||
@ -145,40 +154,40 @@ namespace Online
|
||||
m_mapped_servers.lock();
|
||||
m_mapped_servers.getData()[server->getServerId()] = server;
|
||||
m_mapped_servers.unlock();
|
||||
}
|
||||
} // addServer
|
||||
|
||||
// ============================================================================
|
||||
// ------------------------------------------------------------------------
|
||||
int ServersManager::getNumServers () const
|
||||
{
|
||||
MutexLocker(m_sorted_servers);
|
||||
return m_sorted_servers.getData().size();
|
||||
}
|
||||
} // getNumServers
|
||||
|
||||
// ============================================================================
|
||||
const Server * ServersManager::getServerBySort (int index) const
|
||||
// ------------------------------------------------------------------------
|
||||
const Server* ServersManager::getServerBySort (int index) const
|
||||
{
|
||||
MutexLocker(m_sorted_servers);
|
||||
return m_sorted_servers.getData().get(index);
|
||||
}
|
||||
} // getServerBySort
|
||||
|
||||
// ============================================================================
|
||||
const Server * ServersManager::getServerByID (uint32_t id) const
|
||||
// ------------------------------------------------------------------------
|
||||
const Server* ServersManager::getServerByID (uint32_t id) const
|
||||
{
|
||||
MutexLocker(m_mapped_servers);
|
||||
return m_mapped_servers.getData().at(id);
|
||||
}
|
||||
} // getServerByID
|
||||
|
||||
// ============================================================================
|
||||
Server * ServersManager::getJoinedServer() const
|
||||
// ------------------------------------------------------------------------
|
||||
Server* ServersManager::getJoinedServer() const
|
||||
{
|
||||
return m_joined_server.getAtomic();
|
||||
}
|
||||
} // getJoinedServer
|
||||
|
||||
// ============================================================================
|
||||
// ------------------------------------------------------------------------
|
||||
void ServersManager::sort(bool sort_desc)
|
||||
{
|
||||
MutexLocker(m_sorted_servers);
|
||||
m_sorted_servers.getData().insertionSort(0, sort_desc);
|
||||
}
|
||||
} // sort
|
||||
|
||||
} // namespace Online
|
||||
|
@ -19,12 +19,12 @@
|
||||
#ifndef HEADER_SERVERS_MANAGER_HPP
|
||||
#define HEADER_SERVERS_MANAGER_HPP
|
||||
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "utils/types.hpp"
|
||||
#include "online/server.hpp"
|
||||
#include "online/request_manager.hpp"
|
||||
#include "online/server.hpp"
|
||||
#include "online/xml_request.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
namespace Online
|
||||
{
|
||||
@ -35,17 +35,19 @@ namespace Online
|
||||
class ServersManager
|
||||
{
|
||||
public:
|
||||
|
||||
// ====================================================================
|
||||
class RefreshRequest : public XMLRequest
|
||||
{
|
||||
virtual void callback ();
|
||||
public:
|
||||
RefreshRequest() : XMLRequest() {}
|
||||
};
|
||||
}; // RefreshRequest
|
||||
// ====================================================================
|
||||
|
||||
private:
|
||||
ServersManager();
|
||||
~ServersManager();
|
||||
|
||||
/** Sorted vector of servers */
|
||||
Synchronised<PtrVector<Server> > m_sorted_servers;
|
||||
|
||||
@ -53,29 +55,29 @@ namespace Online
|
||||
Synchronised<std::map<uint32_t, Server*> > m_mapped_servers;
|
||||
|
||||
/** This is a pointer to a copy of the server, the moment it got joined */
|
||||
Synchronised<Server *> m_joined_server;
|
||||
Synchronised<Server *> m_joined_server;
|
||||
|
||||
Synchronised<float> m_last_load_time;
|
||||
void refresh(bool success, const XMLNode * input);
|
||||
void cleanUpServers();
|
||||
Synchronised<float> m_last_load_time;
|
||||
void refresh(bool success, const XMLNode * input);
|
||||
void cleanUpServers();
|
||||
|
||||
public:
|
||||
// Singleton
|
||||
static ServersManager* get();
|
||||
static void deallocate();
|
||||
static ServersManager* get();
|
||||
static void deallocate();
|
||||
|
||||
RefreshRequest * refreshRequest(bool request_now = true) const;
|
||||
void setJoinedServer(uint32_t server_id);
|
||||
void unsetJoinedServer();
|
||||
void addServer(Server * server);
|
||||
int getNumServers () const;
|
||||
const Server * getServerByID (uint32_t server_id) const;
|
||||
const Server * getServerBySort (int index) const;
|
||||
void sort(bool sort_desc);
|
||||
Server * getJoinedServer() const;
|
||||
RefreshRequest * refreshRequest(bool request_now = true) const;
|
||||
void setJoinedServer(uint32_t server_id);
|
||||
void unsetJoinedServer();
|
||||
void addServer(Server * server);
|
||||
int getNumServers () const;
|
||||
const Server * getServerByID (uint32_t server_id) const;
|
||||
const Server * getServerBySort (int index) const;
|
||||
void sort(bool sort_desc);
|
||||
Server * getJoinedServer() const;
|
||||
|
||||
// Returns the best server to join
|
||||
const Server * getQuickPlay() const;
|
||||
const Server * getQuickPlay() const;
|
||||
|
||||
}; // class ServersManager
|
||||
} // namespace Online
|
||||
|
@ -11,13 +11,15 @@
|
||||
#ifndef SCRIPTSTDSTRING_H
|
||||
#define SCRIPTSTDSTRING_H
|
||||
|
||||
// String must be included before angelscript.h to avoid some errors during
|
||||
// compilation with GetObject function
|
||||
#include <string>
|
||||
|
||||
#ifndef ANGELSCRIPT_H
|
||||
// Avoid having to inform include path if header is already include before
|
||||
#include <angelscript.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
//---------------------------
|
||||
// Compilation settings
|
||||
//
|
||||
|
@ -47,6 +47,7 @@ DEFINE_SCREEN_SINGLETON( CreateServerScreen );
|
||||
CreateServerScreen::CreateServerScreen() : Screen("online/create_server.stkgui")
|
||||
{
|
||||
m_server_creation_request = NULL;
|
||||
m_is_lan = false;
|
||||
} // CreateServerScreen
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -80,8 +81,6 @@ void CreateServerScreen::beforeAddingWidget()
|
||||
|
||||
} // beforeAddingWidget
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void CreateServerScreen::init()
|
||||
{
|
||||
@ -89,7 +88,12 @@ void CreateServerScreen::init()
|
||||
setInitialFocus();
|
||||
DemoWorld::resetIdleTime();
|
||||
m_info_widget->setText("", false);
|
||||
}
|
||||
LabelWidget *title = getWidget<LabelWidget>("title");
|
||||
|
||||
title->setText(m_is_lan ? _("Create LAN Server")
|
||||
: _("Create Server") , false);
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void CreateServerScreen::onUpdate(float delta)
|
||||
{
|
||||
@ -99,7 +103,8 @@ void CreateServerScreen::onUpdate(float delta)
|
||||
{
|
||||
if(m_server_creation_request->isSuccess())
|
||||
{
|
||||
new ServerInfoDialog(m_server_creation_request->getCreatedServerID(), true);
|
||||
new ServerInfoDialog(m_server_creation_request->getCreatedServerID(),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -124,22 +129,36 @@ void CreateServerScreen::onUpdate(float delta)
|
||||
// ----------------------------------------------------------------------------
|
||||
void CreateServerScreen::serverCreationRequest()
|
||||
{
|
||||
if (m_is_lan)
|
||||
{
|
||||
const irr::core::stringw name = m_name_widget->getText().trim();
|
||||
const int max_players = m_max_players_widget->getValue();
|
||||
Server *server = new Server(name, /*lan*/true, max_players,
|
||||
/*current_player*/1);
|
||||
ServersManager::get()->addServer(server);
|
||||
return;
|
||||
}
|
||||
|
||||
// Now must be WAN: forward request to the stk server
|
||||
const irr::core::stringw name = m_name_widget->getText().trim();
|
||||
const int max_players = m_max_players_widget->getValue();
|
||||
m_info_widget->setErrorColor();
|
||||
if (name.size() < 4 || name.size() > 30)
|
||||
{
|
||||
m_info_widget->setText(_("Name has to be between 4 and 30 characters long!"), false);
|
||||
m_info_widget->setText(
|
||||
_("Name has to be between 4 and 30 characters long!"), false);
|
||||
}
|
||||
else if (max_players < 2 || max_players > 12)
|
||||
{
|
||||
m_info_widget->setText(_("The maxinum number of players has to be between 2 and 12."), false);
|
||||
m_info_widget->setText(
|
||||
_("The maxinum number of players has to be between 2 and 12."), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
m_server_creation_request = new ServerCreationRequest();
|
||||
PlayerManager::setUserDetails(m_server_creation_request, "create", Online::API::SERVER_PATH);
|
||||
PlayerManager::setUserDetails(m_server_creation_request, "create",
|
||||
Online::API::SERVER_PATH);
|
||||
m_server_creation_request->addParameter("name", name);
|
||||
m_server_creation_request->addParameter("max_players", max_players);
|
||||
m_server_creation_request->queue();
|
||||
@ -147,13 +166,18 @@ void CreateServerScreen::serverCreationRequest()
|
||||
return;
|
||||
}
|
||||
SFXManager::get()->quickSound("anvil");
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
} // serverCreationRequest
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Callbacks from the online create server request.
|
||||
*/
|
||||
void CreateServerScreen::ServerCreationRequest::callback()
|
||||
{
|
||||
if (isSuccess())
|
||||
{
|
||||
Server *server = new Server(*getXMLData()->getNode("server"));
|
||||
// Must be a WAN server
|
||||
Server *server = new Server(*getXMLData()->getNode("server"),
|
||||
/*is lan*/false);
|
||||
ServersManager::get()->addServer(server);
|
||||
m_created_server_id = server->getServerId();
|
||||
} // isSuccess
|
||||
@ -165,7 +189,8 @@ void CreateServerScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
{
|
||||
if (name == m_options_widget->m_properties[PROP_ID])
|
||||
{
|
||||
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
const std::string& selection =
|
||||
m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (selection == m_cancel_widget->m_properties[PROP_ID])
|
||||
{
|
||||
StateManager::get()->escapePressed();
|
||||
@ -173,7 +198,7 @@ void CreateServerScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
else if (selection == m_create_widget->m_properties[PROP_ID])
|
||||
{
|
||||
serverCreationRequest();
|
||||
}
|
||||
} // is create_widget
|
||||
}
|
||||
} // eventCallback
|
||||
|
||||
|
@ -35,6 +35,9 @@ class CreateServerScreen : public GUIEngine::Screen,
|
||||
private:
|
||||
friend class GUIEngine::ScreenSingleton<CreateServerScreen>;
|
||||
|
||||
/** */
|
||||
bool m_is_lan;
|
||||
|
||||
CreateServerScreen();
|
||||
|
||||
GUIEngine::TextBoxWidget * m_name_widget;
|
||||
@ -93,6 +96,10 @@ public:
|
||||
|
||||
/** \brief Implements the callback when a dialog gets closed. */
|
||||
virtual void onDialogClose() OVERRIDE;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets if a lan or wan server is to be created. */
|
||||
void setIsLan(bool is_lan) { m_is_lan = is_lan; }
|
||||
}; // class CreateServerScreen
|
||||
|
||||
#endif
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "input/input.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "states_screens/dialogs/press_a_key_dialog.hpp"
|
||||
#include "states_screens/options_screen_input2.hpp"
|
||||
#include "states_screens/options_screen_device.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
using namespace GUIEngine;
|
||||
@ -47,13 +47,13 @@ GUIEngine::EventPropagation PressAKeyDialog::processEvent(const std::string& eve
|
||||
else if (eventSource == "assignNone")
|
||||
{
|
||||
Input simulatedInput;
|
||||
OptionsScreenInput2::getInstance()->gotSensedInput(simulatedInput);
|
||||
OptionsScreenDevice::getInstance()->gotSensedInput(simulatedInput);
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (eventSource == "assignEsc")
|
||||
{
|
||||
Input simulatedInput(Input::IT_KEYBOARD, 0 /* deviceID */, KEY_ESCAPE);
|
||||
OptionsScreenInput2::getInstance()->gotSensedInput(simulatedInput);
|
||||
OptionsScreenDevice::getInstance()->gotSensedInput(simulatedInput);
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
|
||||
|
@ -35,25 +35,25 @@ using namespace GUIEngine;
|
||||
DEFINE_SCREEN_SINGLETON( EditGPScreen );
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
EditGPScreen::EditGPScreen()
|
||||
: Screen("gpedit.stkgui"), m_gp(NULL), m_list(NULL), m_icon_bank(NULL),
|
||||
m_selected(-1), m_modified(false)
|
||||
EditGPScreen::EditGPScreen() : Screen("edit_gp.stkgui"), m_gp(NULL),
|
||||
m_list(NULL), m_icon_bank(NULL),
|
||||
m_selected(-1), m_modified(false)
|
||||
{
|
||||
|
||||
}
|
||||
} // EditGPScreen
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
EditGPScreen::~EditGPScreen()
|
||||
{
|
||||
delete m_icon_bank;
|
||||
}
|
||||
} // ~EditGPScreen
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::setSelectedGP(GrandPrixData* gp)
|
||||
{
|
||||
assert(gp != NULL);
|
||||
m_gp = gp;
|
||||
}
|
||||
} // setSelectedGP
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::loadedFromFile()
|
||||
@ -66,11 +66,12 @@ void EditGPScreen::loadedFromFile()
|
||||
m_list->addColumn(_("Track"), 3);
|
||||
m_list->addColumn(_("Laps"), 1);
|
||||
m_list->addColumn(_("Reversed"), 1);
|
||||
}
|
||||
} // loadedFromFile
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::eventCallback(GUIEngine::Widget* widget, const std::string& name,
|
||||
const int playerID)
|
||||
void EditGPScreen::eventCallback(GUIEngine::Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
setSelected(m_list->getSelectionID());
|
||||
|
||||
@ -146,7 +147,7 @@ void EditGPScreen::eventCallback(GUIEngine::Widget* widget, const std::string& n
|
||||
back();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // eventCallback
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::init()
|
||||
@ -191,7 +192,7 @@ void EditGPScreen::init()
|
||||
m_action.clear();
|
||||
}
|
||||
enableButtons();
|
||||
}
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::onConfirm()
|
||||
@ -210,7 +211,7 @@ void EditGPScreen::onConfirm()
|
||||
save();
|
||||
back();
|
||||
}
|
||||
}
|
||||
} // onConfirm
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::onCancel()
|
||||
@ -221,7 +222,7 @@ void EditGPScreen::onCancel()
|
||||
m_gp->reload(); // Discard changes
|
||||
back();
|
||||
}
|
||||
}
|
||||
} // onCancel
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::loadList(const int selected)
|
||||
@ -268,7 +269,7 @@ void EditGPScreen::loadList(const int selected)
|
||||
{
|
||||
enableButtons();
|
||||
}
|
||||
}
|
||||
} // loadList
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::setModified(const bool modified)
|
||||
@ -285,14 +286,14 @@ void EditGPScreen::setModified(const bool modified)
|
||||
header->setText(modified ? _(L"%s (+)", m_gp->getName()) : L"", true);
|
||||
|
||||
enableButtons();
|
||||
}
|
||||
} // setModified
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::setSelected(const int selected)
|
||||
{
|
||||
m_selected = selected;
|
||||
enableButtons();
|
||||
}
|
||||
} // setSelected
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::edit()
|
||||
@ -308,7 +309,7 @@ void EditGPScreen::edit()
|
||||
m_gp->getReverse((unsigned int)m_selected));
|
||||
edit_screen->push();
|
||||
}
|
||||
}
|
||||
} // edit
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool EditGPScreen::save()
|
||||
@ -325,7 +326,7 @@ bool EditGPScreen::save()
|
||||
MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // save
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::back()
|
||||
@ -333,19 +334,19 @@ void EditGPScreen::back()
|
||||
m_action.clear();
|
||||
m_modified = false;
|
||||
StateManager::get()->popMenu();
|
||||
}
|
||||
} // back
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool EditGPScreen::canMoveUp() const
|
||||
{
|
||||
return (0 < m_selected && m_selected < m_list->getItemCount());
|
||||
}
|
||||
} // canMoveUp
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool EditGPScreen::canMoveDown() const
|
||||
{
|
||||
return (0 <= m_selected && m_selected < m_list->getItemCount() - 1);
|
||||
}
|
||||
} // canMoveDown
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void EditGPScreen::enableButtons()
|
||||
@ -365,4 +366,4 @@ void EditGPScreen::enableButtons()
|
||||
|
||||
edit_button->setActive(m_selected >= 0);
|
||||
remove_button->setActive(m_selected >= 0);
|
||||
}
|
||||
} // enableButtons
|
||||
|
@ -40,8 +40,9 @@ DEFINE_SCREEN_SINGLETON( GrandPrixEditorScreen );
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
GrandPrixEditorScreen::GrandPrixEditorScreen()
|
||||
: Screen("gpeditor.stkgui"), m_selection(NULL), m_gpgroup(GrandPrixData::GP_NONE)
|
||||
GrandPrixEditorScreen::GrandPrixEditorScreen()
|
||||
: Screen("grand_prix_editor.stkgui"), m_selection(NULL),
|
||||
m_gpgroup(GrandPrixData::GP_NONE)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ bool MainMenuScreen::m_enable_online = false;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
MainMenuScreen::MainMenuScreen() : Screen("main.stkgui")
|
||||
MainMenuScreen::MainMenuScreen() : Screen("main_menu.stkgui")
|
||||
{
|
||||
} // MainMenuScreen
|
||||
|
||||
|
@ -45,7 +45,7 @@ DEFINE_SCREEN_SINGLETON( NetworkingLobby );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
NetworkingLobby::NetworkingLobby() : Screen("online/lobby.stkgui")
|
||||
NetworkingLobby::NetworkingLobby() : Screen("online/networking_lobby.stkgui")
|
||||
{
|
||||
m_server = NULL;
|
||||
} // NetworkingLobby
|
||||
|
@ -26,21 +26,20 @@
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "main_loop.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
#include "network/protocols/request_connection.hpp"
|
||||
#include "online/profile_manager.hpp"
|
||||
#include "online/request.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/create_server_screen.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "states_screens/networking_lobby.hpp"
|
||||
#include "states_screens/server_selection.hpp"
|
||||
#include "states_screens/create_server_screen.hpp"
|
||||
#include "states_screens/online_profile_achievements.hpp"
|
||||
#include "states_screens/server_selection.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/user_screen.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@ -53,7 +52,7 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
|
||||
OnlineScreen::OnlineScreen() : Screen("online/online_screen.stkgui")
|
||||
{
|
||||
m_recorded_state = PlayerProfile::OS_SIGNED_OUT;
|
||||
} // OnlineScreen
|
||||
@ -68,26 +67,34 @@ OnlineScreen::~OnlineScreen()
|
||||
|
||||
void OnlineScreen::loadedFromFile()
|
||||
{
|
||||
m_user_id = getWidget<ButtonWidget>("user-id");
|
||||
assert(m_user_id);
|
||||
|
||||
m_back_widget = getWidget<IconButtonWidget>("back");
|
||||
assert(m_back_widget != NULL);
|
||||
|
||||
m_top_menu_widget = getWidget<RibbonWidget>("menu_toprow");
|
||||
m_top_menu_widget = getWidget<RibbonWidget>("menu_top_row");
|
||||
assert(m_top_menu_widget != NULL);
|
||||
m_quick_play_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("quick_play");
|
||||
assert(m_quick_play_widget != NULL);
|
||||
m_find_server_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("find_server");
|
||||
assert(m_find_server_widget != NULL);
|
||||
m_create_server_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("create_server");
|
||||
assert(m_create_server_widget != NULL);
|
||||
|
||||
m_online_status_widget = getWidget<LabelWidget>("online_status");
|
||||
assert(m_online_status_widget != NULL);
|
||||
m_find_lan_server_widget = getWidget<IconButtonWidget>("find_lan_server");
|
||||
assert(m_find_lan_server_widget != NULL);
|
||||
m_create_lan_server_widget = getWidget<IconButtonWidget>("create_lan_server");
|
||||
assert(m_create_lan_server_widget != NULL);
|
||||
m_manage_user = getWidget<IconButtonWidget>("manage_user");
|
||||
assert(m_manage_user);
|
||||
|
||||
m_find_wan_server_widget = getWidget<IconButtonWidget>("find_wan_server");
|
||||
assert(m_find_wan_server_widget != NULL);
|
||||
m_create_wan_server_widget = getWidget<IconButtonWidget>("create_wan_server");
|
||||
assert(m_create_wan_server_widget != NULL);
|
||||
m_quick_wan_play_widget = getWidget<IconButtonWidget>("quick_wan_play");
|
||||
assert(m_quick_wan_play_widget != NULL);
|
||||
|
||||
m_bottom_menu_widget = getWidget<RibbonWidget>("menu_bottomrow");
|
||||
assert(m_bottom_menu_widget != NULL);
|
||||
m_profile_widget = (IconButtonWidget *) m_bottom_menu_widget->findWidgetNamed("profile");
|
||||
m_profile_widget = getWidget<IconButtonWidget>("profile");
|
||||
assert(m_profile_widget != NULL);
|
||||
m_sign_out_widget = (IconButtonWidget *) m_bottom_menu_widget->findWidgetNamed("sign_out");
|
||||
m_sign_out_widget = getWidget<IconButtonWidget>("sign_out");
|
||||
assert(m_sign_out_widget != NULL);
|
||||
|
||||
} // loadedFromFile
|
||||
@ -107,7 +114,8 @@ bool OnlineScreen::hasStateChanged()
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineScreen::beforeAddingWidget()
|
||||
{
|
||||
//Set everything that could be set invisible or deactivated, to active and visible
|
||||
// Set everything that could be set invisible or deactivated
|
||||
// to active and visible
|
||||
m_bottom_menu_widget->setVisible(true);
|
||||
m_top_menu_widget->setVisible(true);
|
||||
hasStateChanged();
|
||||
@ -115,18 +123,26 @@ void OnlineScreen::beforeAddingWidget()
|
||||
m_recorded_state == PlayerProfile::OS_SIGNING_IN ||
|
||||
m_recorded_state == PlayerProfile::OS_SIGNING_OUT)
|
||||
{
|
||||
m_quick_play_widget->setActive(false);
|
||||
m_find_server_widget->setActive(false);
|
||||
m_create_server_widget->setActive(false);
|
||||
m_quick_wan_play_widget->setActive(false);
|
||||
m_find_wan_server_widget->setActive(false);
|
||||
m_create_wan_server_widget->setActive(false);
|
||||
m_sign_out_widget->setVisible(false);
|
||||
m_profile_widget->setVisible(false);
|
||||
}
|
||||
else if (m_recorded_state == PlayerProfile::OS_GUEST)
|
||||
{
|
||||
m_find_server_widget->setActive(false);
|
||||
m_create_server_widget->setActive(false);
|
||||
m_find_wan_server_widget->setActive(false);
|
||||
m_create_wan_server_widget->setActive(false);
|
||||
m_profile_widget->setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_quick_wan_play_widget->setActive(true);
|
||||
m_find_wan_server_widget->setActive(true);
|
||||
m_create_wan_server_widget->setActive(true);
|
||||
m_sign_out_widget->setVisible(true);
|
||||
m_profile_widget->setVisible(true);
|
||||
}
|
||||
|
||||
} // beforeAddingWidget
|
||||
|
||||
@ -136,30 +152,28 @@ void OnlineScreen::init()
|
||||
Screen::init();
|
||||
setInitialFocus();
|
||||
DemoWorld::resetIdleTime();
|
||||
core::stringw m = _("Logged in as: %s.",
|
||||
PlayerManager::getCurrentOnlineUserName());
|
||||
m_online_status_widget->setText(m, false);
|
||||
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineScreen::onUpdate(float delta)
|
||||
{
|
||||
PlayerProfile *player = PlayerManager::getCurrentPlayer();
|
||||
if (PlayerManager::getCurrentOnlineState() == PlayerProfile::OS_SIGNED_IN)
|
||||
{
|
||||
m_user_id->setText(player->getLastOnlineName() + "@stk");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_user_id->setText(player->getName());
|
||||
}
|
||||
|
||||
if (hasStateChanged())
|
||||
{
|
||||
GUIEngine::reshowCurrentScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_recorded_state == PlayerProfile::OS_SIGNING_IN)
|
||||
{
|
||||
m_online_status_widget->setText(StringUtils::loadingDots(_("Logging in")),
|
||||
false );
|
||||
}
|
||||
else if (m_recorded_state == PlayerProfile::OS_SIGNING_OUT)
|
||||
{
|
||||
m_online_status_widget->setText(StringUtils::loadingDots(_("Logging out")),
|
||||
false );
|
||||
}
|
||||
} // onUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -191,7 +205,8 @@ void OnlineScreen::doQuickPlay()
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerManager::setUserDetails(join_request, "request-connection", Online::API::SERVER_PATH);
|
||||
PlayerManager::setUserDetails(join_request, "request-connection",
|
||||
Online::API::SERVER_PATH);
|
||||
join_request->addParameter("server_id", server->getServerId());
|
||||
|
||||
join_request->executeNow();
|
||||
@ -230,20 +245,36 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
PlayerManager::requestSignOut();
|
||||
StateManager::get()->popMenu();
|
||||
}
|
||||
else if (selection == m_create_lan_server_widget->m_properties[PROP_ID])
|
||||
{
|
||||
CreateServerScreen::getInstance()->setIsLan(true);
|
||||
CreateServerScreen::getInstance()->push();
|
||||
// TODO: create lan server
|
||||
}
|
||||
else if (selection == m_find_lan_server_widget->m_properties[PROP_ID])
|
||||
{
|
||||
ServerSelection::getInstance()->push();
|
||||
// TODO: find lan server;
|
||||
}
|
||||
else if (selection == m_manage_user->m_properties[PROP_ID])
|
||||
{
|
||||
UserScreen::getInstance()->push();
|
||||
}
|
||||
else if (selection == m_profile_widget->m_properties[PROP_ID])
|
||||
{
|
||||
ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());
|
||||
OnlineProfileAchievements::getInstance()->push();
|
||||
}
|
||||
else if (selection == m_find_server_widget->m_properties[PROP_ID])
|
||||
else if (selection == m_find_wan_server_widget->m_properties[PROP_ID])
|
||||
{
|
||||
ServerSelection::getInstance()->push();
|
||||
}
|
||||
else if (selection == m_create_server_widget->m_properties[PROP_ID])
|
||||
else if (selection == m_create_wan_server_widget->m_properties[PROP_ID])
|
||||
{
|
||||
CreateServerScreen::getInstance()->setIsLan(false);
|
||||
CreateServerScreen::getInstance()->push();
|
||||
}
|
||||
else if (selection == m_quick_play_widget->m_properties[PROP_ID])
|
||||
else if (selection == m_quick_wan_play_widget->m_properties[PROP_ID])
|
||||
{
|
||||
doQuickPlay();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
namespace GUIEngine { class Widget; class ListWidget; }
|
||||
namespace GUIEngine { class Widget; class ListWidget; class ButtonWidget; }
|
||||
|
||||
/**
|
||||
* \brief Handles the main menu
|
||||
@ -40,19 +40,24 @@ private:
|
||||
OnlineScreen();
|
||||
~OnlineScreen();
|
||||
|
||||
GUIEngine::IconButtonWidget * m_back_widget;
|
||||
GUIEngine::IconButtonWidget *m_back_widget;
|
||||
|
||||
GUIEngine::RibbonWidget * m_top_menu_widget;
|
||||
GUIEngine::IconButtonWidget * m_quick_play_widget;
|
||||
GUIEngine::IconButtonWidget * m_find_server_widget;
|
||||
GUIEngine::IconButtonWidget * m_create_server_widget;
|
||||
GUIEngine::RibbonWidget *m_top_menu_widget;
|
||||
GUIEngine::IconButtonWidget *m_find_lan_server_widget;
|
||||
GUIEngine::IconButtonWidget *m_create_lan_server_widget;
|
||||
GUIEngine::IconButtonWidget *m_manage_user;
|
||||
|
||||
GUIEngine::LabelWidget * m_online_status_widget;
|
||||
GUIEngine::IconButtonWidget *m_find_wan_server_widget;
|
||||
GUIEngine::IconButtonWidget *m_create_wan_server_widget;
|
||||
GUIEngine::IconButtonWidget *m_quick_wan_play_widget;
|
||||
|
||||
GUIEngine::RibbonWidget * m_bottom_menu_widget;
|
||||
GUIEngine::IconButtonWidget * m_register_widget;
|
||||
GUIEngine::IconButtonWidget * m_profile_widget;
|
||||
GUIEngine::IconButtonWidget * m_sign_out_widget;
|
||||
GUIEngine::RibbonWidget *m_bottom_menu_widget;
|
||||
GUIEngine::IconButtonWidget *m_register_widget;
|
||||
GUIEngine::IconButtonWidget *m_profile_widget;
|
||||
GUIEngine::IconButtonWidget *m_sign_out_widget;
|
||||
|
||||
/** Keep the widget to to the user name. */
|
||||
GUIEngine::ButtonWidget *m_user_id;
|
||||
|
||||
PlayerProfile::OnlineState m_recorded_state;
|
||||
|
||||
|
@ -38,7 +38,6 @@ DEFINE_SCREEN_SINGLETON( OnlineUserSearch );
|
||||
|
||||
OnlineUserSearch::OnlineUserSearch() : Screen("online/user_search.stkgui")
|
||||
{
|
||||
m_selected_index = -1;
|
||||
m_search_request = NULL;
|
||||
m_search_string = "";
|
||||
m_last_search_string = "";
|
||||
@ -226,9 +225,9 @@ void OnlineUserSearch::eventCallback(GUIEngine::Widget* widget,
|
||||
}
|
||||
else if (name == m_user_list_widget->m_properties[GUIEngine::PROP_ID])
|
||||
{
|
||||
m_selected_index = m_user_list_widget->getSelectionID();
|
||||
if (m_selected_index != -1)
|
||||
new UserInfoDialog(m_users[m_selected_index]);
|
||||
int selected_index = m_user_list_widget->getSelectionID();
|
||||
if (selected_index != -1)
|
||||
new UserInfoDialog(m_users[selected_index]);
|
||||
}
|
||||
else if (name == m_search_button_widget->m_properties[GUIEngine::PROP_ID])
|
||||
{
|
||||
@ -239,22 +238,6 @@ void OnlineUserSearch::eventCallback(GUIEngine::Widget* widget,
|
||||
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Selects the last selected item on the list (which is the item that
|
||||
* is just being installed) again. This function is used from the
|
||||
* addons_loading screen: when it is closed, it will reset the
|
||||
* select item so that people can keep on installing from that
|
||||
* point on.
|
||||
*/
|
||||
void OnlineUserSearch::setLastSelected() //FIXME actually use this here and in server selection
|
||||
{
|
||||
if(m_selected_index>-1)
|
||||
{
|
||||
m_user_list_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
m_user_list_widget->setSelectionID(m_selected_index);
|
||||
}
|
||||
} // setLastSelected
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called every frame. It queries the search request for results and
|
||||
* displays them if necessary.
|
||||
|
@ -48,9 +48,6 @@ private:
|
||||
/** Pointer to the result list. */
|
||||
GUIEngine::ListWidget * m_user_list_widget;
|
||||
|
||||
/** The currently selected index, used to re-select this item after
|
||||
* addons_loading is being displayed. */
|
||||
int m_selected_index;
|
||||
/** Seach string entered in the search widget. */
|
||||
irr::core::stringw m_search_string;
|
||||
/** Last search string, used to avoid doing the same search again. */
|
||||
@ -86,7 +83,6 @@ public:
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void onUpdate(float dt) OVERRIDE;
|
||||
|
||||
void setLastSelected();
|
||||
/** Sets the search string to an initial value. */
|
||||
void setSearchString(const irr::core::stringw & search_string)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "states_screens/options_screen_input2.hpp"
|
||||
#include "states_screens/options_screen_device.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "guiengine/CGUISpriteBank.hpp"
|
||||
@ -45,24 +45,24 @@
|
||||
|
||||
using namespace GUIEngine;
|
||||
|
||||
DEFINE_SCREEN_SINGLETON( OptionsScreenInput2 );
|
||||
DEFINE_SCREEN_SINGLETON( OptionsScreenDevice );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
OptionsScreenInput2::OptionsScreenInput2() : Screen("options_device.stkgui")
|
||||
OptionsScreenDevice::OptionsScreenDevice() : Screen("options_device.stkgui")
|
||||
{
|
||||
m_config = NULL;
|
||||
} // OptionsScreenInput2
|
||||
} // OptionsScreenDevice
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::loadedFromFile()
|
||||
void OptionsScreenDevice::loadedFromFile()
|
||||
{
|
||||
} // loadedFromFile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::beforeAddingWidget()
|
||||
void OptionsScreenDevice::beforeAddingWidget()
|
||||
{
|
||||
GUIEngine::ListWidget* w_list =
|
||||
getWidget<GUIEngine::ListWidget>("actions");
|
||||
@ -75,7 +75,7 @@ void OptionsScreenInput2::beforeAddingWidget()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::init()
|
||||
void OptionsScreenDevice::init()
|
||||
{
|
||||
Screen::init();
|
||||
RibbonWidget* tabBar = getWidget<RibbonWidget>("options_choice");
|
||||
@ -165,9 +165,9 @@ void OptionsScreenInput2::init()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::addListItemSubheader(GUIEngine::ListWidget* actions,
|
||||
const char* id,
|
||||
const core::stringw& text)
|
||||
void OptionsScreenDevice::addListItemSubheader(GUIEngine::ListWidget* actions,
|
||||
const char* id,
|
||||
const core::stringw& text)
|
||||
{
|
||||
std::vector<GUIEngine::ListWidget::ListCell> row;
|
||||
row.push_back(GUIEngine::ListWidget::ListCell(text, -1, 1, false));
|
||||
@ -177,8 +177,8 @@ void OptionsScreenInput2::addListItemSubheader(GUIEngine::ListWidget* actions,
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::addListItem(GUIEngine::ListWidget* actions,
|
||||
PlayerAction pa)
|
||||
void OptionsScreenDevice::addListItem(GUIEngine::ListWidget* actions,
|
||||
PlayerAction pa)
|
||||
{
|
||||
std::vector<GUIEngine::ListWidget::ListCell> row;
|
||||
core::stringw s(KartActionStrings[pa].c_str());
|
||||
@ -189,10 +189,10 @@ void OptionsScreenInput2::addListItem(GUIEngine::ListWidget* actions,
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::renameRow(GUIEngine::ListWidget* actions,
|
||||
int idRow,
|
||||
const irr::core::stringw &translatedName,
|
||||
PlayerAction action) const
|
||||
void OptionsScreenDevice::renameRow(GUIEngine::ListWidget* actions,
|
||||
int idRow,
|
||||
const irr::core::stringw &translatedName,
|
||||
PlayerAction action) const
|
||||
{
|
||||
actions->renameCell(idRow, 0, core::stringw(" ") + translatedName);
|
||||
actions->renameCell(idRow, 1, m_config->getBindingAsString(action));
|
||||
@ -201,7 +201,7 @@ void OptionsScreenInput2::renameRow(GUIEngine::ListWidget* actions,
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::updateInputButtons()
|
||||
void OptionsScreenDevice::updateInputButtons()
|
||||
{
|
||||
assert(m_config != NULL);
|
||||
|
||||
@ -372,7 +372,7 @@ void OptionsScreenInput2::updateInputButtons()
|
||||
static PlayerAction binding_to_set;
|
||||
static std::string binding_to_set_button;
|
||||
|
||||
void OptionsScreenInput2::gotSensedInput(const Input& sensed_input)
|
||||
void OptionsScreenDevice::gotSensedInput(const Input& sensed_input)
|
||||
{
|
||||
const bool keyboard = (m_config->isKeyboard() &&
|
||||
sensed_input.m_type == Input::IT_KEYBOARD);
|
||||
@ -384,7 +384,7 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input)
|
||||
{
|
||||
if (UserConfigParams::logMisc())
|
||||
{
|
||||
Log::info("OptionsScreenInput2", "Binding %s: setting to keyboard key %d",
|
||||
Log::info("OptionsScreenDevice", "Binding %s: setting to keyboard key %d",
|
||||
KartActionStrings[binding_to_set].c_str(), sensed_input.m_button_id);
|
||||
}
|
||||
|
||||
@ -401,21 +401,21 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input)
|
||||
{
|
||||
if (UserConfigParams::logMisc())
|
||||
{
|
||||
Log::info("OptionsScreenInput2", "Binding %s: setting to gamepad #%d",
|
||||
Log::info("OptionsScreenDevice", "Binding %s: setting to gamepad #%d",
|
||||
KartActionStrings[binding_to_set].c_str(), sensed_input.m_device_id);
|
||||
|
||||
if (sensed_input.m_type == Input::IT_STICKMOTION)
|
||||
{
|
||||
Log::info("OptionsScreenInput2", "Axis %d; direction %s", sensed_input.m_button_id,
|
||||
Log::info("OptionsScreenDevice", "Axis %d; direction %s", sensed_input.m_button_id,
|
||||
sensed_input.m_axis_direction == Input::AD_NEGATIVE ? "-" : "+");
|
||||
}
|
||||
else if (sensed_input.m_type == Input::IT_STICKBUTTON)
|
||||
{
|
||||
Log::info("OptionsScreenInput2", "Button %d", sensed_input.m_button_id);
|
||||
Log::info("OptionsScreenDevice", "Button %d", sensed_input.m_button_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::info("OptionsScreenInput2", "Sensed unknown gamepad event type??");
|
||||
Log::info("OptionsScreenDevice", "Sensed unknown gamepad event type??");
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,7 +439,7 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input)
|
||||
{
|
||||
if (UserConfigParams::logMisc())
|
||||
{
|
||||
Log::info("OptionsScreenInput2", "Binding %s: setting to keyboard key NONE",
|
||||
Log::info("OptionsScreenDevice", "Binding %s: setting to keyboard key NONE",
|
||||
KartActionStrings[binding_to_set].c_str());
|
||||
}
|
||||
|
||||
@ -481,9 +481,9 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OptionsScreenInput2::eventCallback(Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID)
|
||||
void OptionsScreenDevice::eventCallback(Widget* widget,
|
||||
const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
//const std::string& screen_name = getName();
|
||||
|
||||
@ -529,7 +529,7 @@ void OptionsScreenInput2::eventCallback(Widget* widget,
|
||||
// we found which one. show the "press a key" dialog.
|
||||
if (UserConfigParams::logMisc())
|
||||
{
|
||||
Log::info("OptionsScreenInput2", "Entering sensing mode for %s",
|
||||
Log::info("OptionsScreenDevice", "Entering sensing mode for %s",
|
||||
m_config->getName().c_str());
|
||||
}
|
||||
|
||||
@ -547,7 +547,7 @@ void OptionsScreenInput2::eventCallback(Widget* widget,
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::error("OptionsScreenInput2", "Unknown selection device in options: %s",
|
||||
Log::error("OptionsScreenDevice", "Unknown selection device in options: %s",
|
||||
m_config->getName().c_str());
|
||||
}
|
||||
break;
|
||||
@ -583,13 +583,13 @@ void OptionsScreenInput2::eventCallback(Widget* widget,
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::unloaded()
|
||||
void OptionsScreenDevice::unloaded()
|
||||
{
|
||||
} // unloaded
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool OptionsScreenInput2::onEscapePressed()
|
||||
bool OptionsScreenDevice::onEscapePressed()
|
||||
{
|
||||
StateManager::get()
|
||||
->replaceTopMostScreen(OptionsScreenInput::getInstance());
|
||||
@ -599,13 +599,13 @@ bool OptionsScreenInput2::onEscapePressed()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput2::onConfirm()
|
||||
void OptionsScreenDevice::onConfirm()
|
||||
{
|
||||
const bool success =
|
||||
input_manager->getDeviceManager()->deleteConfig(m_config);
|
||||
assert(success);
|
||||
if (!success)
|
||||
Log::error("OptionsScreenInput2", "Failed to delete config!");
|
||||
Log::error("OptionsScreenDevice", "Failed to delete config!");
|
||||
|
||||
m_config = NULL;
|
||||
input_manager->getDeviceManager()->save();
|
||||
@ -617,8 +617,9 @@ void OptionsScreenInput2::onConfirm()
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool OptionsScreenInput2::conflictsBetweenKbdConfig(PlayerAction action,
|
||||
PlayerAction from, PlayerAction to)
|
||||
bool OptionsScreenDevice::conflictsBetweenKbdConfig(PlayerAction action,
|
||||
PlayerAction from,
|
||||
PlayerAction to)
|
||||
{
|
||||
KeyboardConfig* other_kbd_config;
|
||||
int id = m_config->getBinding(action).getId();
|
@ -16,8 +16,8 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#ifndef __HEADER_OPTIONS_SCREEN_INPUT2_HPP__
|
||||
#define __HEADER_OPTIONS_SCREEN_INPUT2_HPP__
|
||||
#ifndef HEADER_OPTIONS_SCREEN_DEVICE_HPP
|
||||
#define HEADER_OPTIONS_SCREEN_DEVICE_HPP
|
||||
|
||||
#include <string>
|
||||
#include <irrString.h>
|
||||
@ -37,11 +37,11 @@ struct Input;
|
||||
* \brief Input options screen
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class OptionsScreenInput2 : public GUIEngine::Screen,
|
||||
public GUIEngine::ScreenSingleton<OptionsScreenInput2>,
|
||||
class OptionsScreenDevice : public GUIEngine::Screen,
|
||||
public GUIEngine::ScreenSingleton<OptionsScreenDevice>,
|
||||
public MessageDialog::IConfirmDialogListener
|
||||
{
|
||||
OptionsScreenInput2();
|
||||
OptionsScreenDevice();
|
||||
|
||||
void updateInputButtons();
|
||||
|
||||
@ -62,7 +62,7 @@ class OptionsScreenInput2 : public GUIEngine::Screen,
|
||||
const core::stringw& text);
|
||||
|
||||
public:
|
||||
friend class GUIEngine::ScreenSingleton<OptionsScreenInput2>;
|
||||
friend class GUIEngine::ScreenSingleton<OptionsScreenDevice>;
|
||||
|
||||
/** Sets the configuration to be used. */
|
||||
void setDevice(DeviceConfig* config) { m_config = config; }
|
@ -28,7 +28,7 @@
|
||||
#include "input/gamepad_device.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "states_screens/options_screen_input2.hpp"
|
||||
#include "states_screens/options_screen_device.hpp"
|
||||
#include "states_screens/options_screen_audio.hpp"
|
||||
#include "states_screens/options_screen_video.hpp"
|
||||
#include "states_screens/options_screen_ui.hpp"
|
||||
@ -225,8 +225,8 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name,
|
||||
read = sscanf( selection.c_str(), "gamepad%i", &i );
|
||||
if (read == 1 && i != -1)
|
||||
{
|
||||
OptionsScreenInput2::getInstance()->setDevice( input_manager->getDeviceManager()->getGamepadConfig(i) );
|
||||
StateManager::get()->replaceTopMostScreen(OptionsScreenInput2::getInstance());
|
||||
OptionsScreenDevice::getInstance()->setDevice( input_manager->getDeviceManager()->getGamepadConfig(i) );
|
||||
StateManager::get()->replaceTopMostScreen(OptionsScreenDevice::getInstance());
|
||||
//updateInputButtons( input_manager->getDeviceList()->getGamepadConfig(i) );
|
||||
}
|
||||
else
|
||||
@ -242,8 +242,9 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name,
|
||||
if (read == 1 && i != -1)
|
||||
{
|
||||
// updateInputButtons( input_manager->getDeviceList()->getKeyboardConfig(i) );
|
||||
OptionsScreenInput2::getInstance()->setDevice( input_manager->getDeviceManager()->getKeyboardConfig(i) );
|
||||
StateManager::get()->replaceTopMostScreen(OptionsScreenInput2::getInstance());
|
||||
OptionsScreenDevice::getInstance()
|
||||
->setDevice( input_manager->getDeviceManager()->getKeyboardConfig(i) );
|
||||
StateManager::get()->replaceTopMostScreen(OptionsScreenDevice::getInstance());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ DEFINE_SCREEN_SINGLETON( RaceSetupScreen );
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
RaceSetupScreen::RaceSetupScreen() : Screen("racesetup.stkgui")
|
||||
RaceSetupScreen::RaceSetupScreen() : Screen("race_setup.stkgui")
|
||||
{
|
||||
} // RaceSetupScreen
|
||||
|
||||
|
@ -36,9 +36,7 @@ DEFINE_SCREEN_SINGLETON( ServerSelection );
|
||||
|
||||
ServerSelection::ServerSelection() : Screen("online/server_selection.stkgui")
|
||||
{
|
||||
m_selected_index = -1;
|
||||
m_refresh_request = NULL;
|
||||
|
||||
} // ServerSelection
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -66,7 +64,7 @@ void ServerSelection::refresh()
|
||||
m_server_list_widget->addItem("loading",
|
||||
StringUtils::loadingDots(_("Fetching servers")));
|
||||
m_reload_widget->setActive(false);
|
||||
}
|
||||
} // refresh
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -90,7 +88,8 @@ void ServerSelection::beforeAddingWidget()
|
||||
m_server_list_widget->clearColumns();
|
||||
m_server_list_widget->addColumn( _("Name"), 3 );
|
||||
m_server_list_widget->addColumn( _("Players"), 1);
|
||||
}
|
||||
} // beforeAddingWidget
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ServerSelection::init()
|
||||
@ -112,11 +111,11 @@ void ServerSelection::init()
|
||||
void ServerSelection::loadList()
|
||||
{
|
||||
m_server_list_widget->clear();
|
||||
ServersManager * manager = ServersManager::get();
|
||||
ServersManager *manager = ServersManager::get();
|
||||
manager->sort(m_sort_desc);
|
||||
for(int i=0; i < manager->getNumServers(); i++)
|
||||
{
|
||||
const Server * server = manager->getServerBySort(i);
|
||||
const Server *server = manager->getServerBySort(i);
|
||||
core::stringw num_players;
|
||||
num_players.append(StringUtils::toWString(server->getCurrentPlayers()));
|
||||
num_players.append("/");
|
||||
@ -159,30 +158,14 @@ void ServerSelection::eventCallback( GUIEngine::Widget* widget,
|
||||
|
||||
else if (name == m_server_list_widget->m_properties[GUIEngine::PROP_ID])
|
||||
{
|
||||
m_selected_index = m_server_list_widget->getSelectionID();
|
||||
uint32_t server_id = ServersManager::get()->getServerBySort(m_selected_index)->getServerId();
|
||||
uint32_t host_id = ServersManager::get()->getServerBySort(m_selected_index)->getHostId();
|
||||
int selected_index = m_server_list_widget->getSelectionID();
|
||||
uint32_t server_id = ServersManager::get()->getServerBySort(selected_index)->getServerId();
|
||||
uint32_t host_id = ServersManager::get()->getServerBySort(selected_index)->getHostId();
|
||||
new ServerInfoDialog(server_id, host_id);
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Selects the last selected item on the list (which is the item that
|
||||
* is just being installed) again. This function is used from the
|
||||
* addons_loading screen: when it is closed, it will reset the
|
||||
* select item so that people can keep on installing from that
|
||||
* point on.
|
||||
*/
|
||||
void ServerSelection::setLastSelected()
|
||||
{
|
||||
if(m_selected_index>-1)
|
||||
{
|
||||
m_server_list_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
m_server_list_widget->setSelectionID(m_selected_index);
|
||||
}
|
||||
} // setLastSelected
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ServerSelection::onUpdate(float dt)
|
||||
|
@ -43,16 +43,15 @@ private:
|
||||
GUIEngine::LabelWidget * m_update_status;
|
||||
GUIEngine::ListWidget * m_server_list_widget;
|
||||
|
||||
|
||||
/** The currently selected index, used to re-select this item after
|
||||
* addons_loading is being displayed. */
|
||||
int m_selected_index;
|
||||
|
||||
/** \brief To check (and set) if sort order is descending **/
|
||||
bool m_sort_desc;
|
||||
|
||||
const Online::ServersManager::RefreshRequest * m_refresh_request;
|
||||
const Online::ServersManager::RefreshRequest *m_refresh_request;
|
||||
bool m_fake_refresh;
|
||||
|
||||
/** True if only lan servers should be shown. */
|
||||
bool m_is_lan;
|
||||
|
||||
void refresh();
|
||||
|
||||
public:
|
||||
@ -79,8 +78,6 @@ public:
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void onUpdate(float dt) OVERRIDE;
|
||||
|
||||
void setLastSelected();
|
||||
|
||||
};
|
||||
}; // ServerSelection
|
||||
|
||||
#endif
|
||||
|
@ -218,7 +218,8 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
|
||||
core::matrix4 absTransform = node->getAbsoluteTransformation();
|
||||
node->setParent(irr_driver->getSceneManager()->getRootSceneNode());
|
||||
node->setPosition(absTransform.getTranslation());
|
||||
node->setRotation(absTransform.getRotationDegrees());
|
||||
// Doesn't seem necessary to set rotation here, TODO: not sure why
|
||||
//node->setRotation(absTransform.getRotationDegrees());
|
||||
node->setScale(absTransform.getScale());
|
||||
is_movable = true;
|
||||
}
|
||||
|
@ -188,6 +188,388 @@ LightNode* findNearestLight()
|
||||
return nearest;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool handleContextMenuAction(s32 cmdID)
|
||||
{
|
||||
|
||||
World *world = World::getWorld();
|
||||
Physics *physics = world ? world->getPhysics() : NULL;
|
||||
if (cmdID == DEBUG_GRAPHICS_RELOAD_SHADERS)
|
||||
{
|
||||
Log::info("Debug", "Reloading shaders...");
|
||||
ShaderBase::updateShaders();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_RESET)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_WIREFRAME)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleWireframe();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_MIPMAP_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleMipVisualization();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_NORMALS_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleNormals();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_SSAO_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleSSAOViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_RSM_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleRSM();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_RH_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleRH();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_GI_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleGI();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_SHADOW_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleShadowViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_LIGHT_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleLightViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_DISTORT_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleDistortViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_BULLET_1)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
|
||||
if (!world) return false;
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_KARTS_PHYSICS);
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_BULLET_2)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
|
||||
if (!world) return false;
|
||||
Physics *physics = world->getPhysics();
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NO_KARTS_GRAPHICS);
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_BOUNDING_BOXES_VIZ)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleBoundingBoxesViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_PROFILER)
|
||||
{
|
||||
UserConfigParams::m_profiler_enabled =
|
||||
!UserConfigParams::m_profiler_enabled;
|
||||
}
|
||||
else if (cmdID == DEBUG_PROFILER_GENERATE_REPORT)
|
||||
{
|
||||
profiler.setCaptureReport(!profiler.getCaptureReport());
|
||||
}
|
||||
else if (cmdID == DEBUG_THROTTLE_FPS)
|
||||
{
|
||||
main_loop->setThrottleFPS(false);
|
||||
}
|
||||
else if (cmdID == DEBUG_FPS)
|
||||
{
|
||||
UserConfigParams::m_display_fps =
|
||||
!UserConfigParams::m_display_fps;
|
||||
}
|
||||
else if (cmdID == DEBUG_SAVE_REPLAY)
|
||||
{
|
||||
ReplayRecorder::get()->Save();
|
||||
}
|
||||
else if (cmdID == DEBUG_SAVE_HISTORY)
|
||||
{
|
||||
history->Save();
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_BOWLING)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_BOWLING);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_BUBBLEGUM)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_BUBBLEGUM);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_CAKE)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_CAKE);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_PARACHUTE)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_PARACHUTE);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_PLUNGER)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_PLUNGER);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_RUBBERBALL)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_RUBBERBALL);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_SWATTER)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_SWATTER);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_SWITCH)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_SWITCH);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_ZIPPER)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_ZIPPER);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_NITRO)
|
||||
{
|
||||
if (!world) return false;
|
||||
const unsigned int num_local_players =
|
||||
race_manager->getNumLocalPlayers();
|
||||
for (unsigned int i = 0; i < num_local_players; i++)
|
||||
{
|
||||
AbstractKart* kart = world->getLocalPlayerKart(i);
|
||||
kart->setEnergy(100.0f);
|
||||
}
|
||||
}
|
||||
else if (cmdID == DEBUG_ATTACHMENT_ANVIL)
|
||||
{
|
||||
addAttachment(Attachment::ATTACH_ANVIL);
|
||||
}
|
||||
else if (cmdID == DEBUG_ATTACHMENT_BOMB)
|
||||
{
|
||||
addAttachment(Attachment::ATTACH_BOMB);
|
||||
}
|
||||
else if (cmdID == DEBUG_ATTACHMENT_PARACHUTE)
|
||||
{
|
||||
addAttachment(Attachment::ATTACH_PARACHUTE);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_TOGGLE)
|
||||
{
|
||||
if (!world) return false;
|
||||
RaceGUIBase* gui = world->getRaceGUI();
|
||||
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_HIDE_KARTS)
|
||||
{
|
||||
if (!world) return false;
|
||||
for (unsigned int n = 0; n<world->getNumKarts(); n++)
|
||||
{
|
||||
AbstractKart* kart = world->getKart(n);
|
||||
if (kart->getController()->isPlayerController())
|
||||
kart->getNode()->setVisible(false);
|
||||
}
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_TOP)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 1;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_WHEEL)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 2;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_BEHIND_KART)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 4;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_SIDE_OF_KART)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 5;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_FREE)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 3;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(false);
|
||||
// Reset camera rotation
|
||||
Camera *cam = Camera::getActiveCamera();
|
||||
cam->setDirection(vector3df(0, 0, 1));
|
||||
cam->setUpVector(vector3df(0, 1, 0));
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_NORMAL)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 0;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_SMOOTH)
|
||||
{
|
||||
Camera *cam = Camera::getActiveCamera();
|
||||
cam->setSmoothMovement(!cam->getSmoothMovement());
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_ATTACH)
|
||||
{
|
||||
Camera *cam = Camera::getActiveCamera();
|
||||
cam->setAttachedFpsCam(!cam->getAttachedFpsCam());
|
||||
}
|
||||
else if (cmdID == DEBUG_PRINT_START_POS)
|
||||
{
|
||||
if (!world) return false;
|
||||
for (unsigned int i = 0; i<world->getNumKarts(); i++)
|
||||
{
|
||||
AbstractKart *kart = world->getKart(i);
|
||||
Log::warn(kart->getIdent().c_str(),
|
||||
"<start position=\"%d\" x=\"%f\" y=\"%f\" z=\"%f\" h=\"%f\"/>",
|
||||
i, kart->getXYZ().getX(), kart->getXYZ().getY(),
|
||||
kart->getXYZ().getZ(), kart->getHeading()*RAD_TO_DEGREE
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (cmdID == DEBUG_VISUAL_VALUES)
|
||||
{
|
||||
#if !defined(__APPLE__)
|
||||
DebugSliderDialog *dsd = new DebugSliderDialog();
|
||||
dsd->setSliderHook("red_slider", 0, 255,
|
||||
[](){ return int(irr_driver->getAmbientLight().r * 255.f); },
|
||||
[](int v){
|
||||
video::SColorf ambient = irr_driver->getAmbientLight();
|
||||
ambient.setColorComponentValue(0, v / 255.f);
|
||||
irr_driver->setAmbientLight(ambient); }
|
||||
);
|
||||
dsd->setSliderHook("green_slider", 0, 255,
|
||||
[](){ return int(irr_driver->getAmbientLight().g * 255.f); },
|
||||
[](int v){
|
||||
video::SColorf ambient = irr_driver->getAmbientLight();
|
||||
ambient.setColorComponentValue(1, v / 255.f);
|
||||
irr_driver->setAmbientLight(ambient); }
|
||||
);
|
||||
dsd->setSliderHook("blue_slider", 0, 255,
|
||||
[](){ return int(irr_driver->getAmbientLight().b * 255.f); },
|
||||
[](int v){
|
||||
video::SColorf ambient = irr_driver->getAmbientLight();
|
||||
ambient.setColorComponentValue(2, v / 255.f);
|
||||
irr_driver->setAmbientLight(ambient); }
|
||||
);
|
||||
dsd->setSliderHook("ssao_radius", 0, 100,
|
||||
[](){ return int(irr_driver->getSSAORadius() * 10.f); },
|
||||
[](int v){irr_driver->setSSAORadius(v / 10.f); }
|
||||
);
|
||||
dsd->setSliderHook("ssao_k", 0, 100,
|
||||
[](){ return int(irr_driver->getSSAOK() * 10.f); },
|
||||
[](int v){irr_driver->setSSAOK(v / 10.f); }
|
||||
);
|
||||
dsd->setSliderHook("ssao_sigma", 0, 100,
|
||||
[](){ return int(irr_driver->getSSAOSigma() * 10.f); },
|
||||
[](int v){irr_driver->setSSAOSigma(v / 10.f); }
|
||||
);
|
||||
#endif
|
||||
}
|
||||
else if (cmdID == DEBUG_ADJUST_LIGHTS)
|
||||
{
|
||||
#if !defined(__APPLE__)
|
||||
// Some sliders use multipliers because the spinner widget
|
||||
// only supports integers
|
||||
DebugSliderDialog *dsd = new DebugSliderDialog();
|
||||
dsd->changeLabel("Red", "Red (x10)");
|
||||
dsd->setSliderHook("red_slider", 0, 100,
|
||||
[]()
|
||||
{
|
||||
return int(findNearestLight()->getColor().X * 100);
|
||||
},
|
||||
[](int intensity)
|
||||
{
|
||||
LightNode* nearest = findNearestLight();
|
||||
core::vector3df color = nearest->getColor();
|
||||
nearest->setColor(intensity / 100.0f, color.Y, color.Z);
|
||||
}
|
||||
);
|
||||
dsd->changeLabel("Green", "Green (x10)");
|
||||
dsd->setSliderHook("green_slider", 0, 100,
|
||||
[]()
|
||||
{
|
||||
return int(findNearestLight()->getColor().Y * 100);
|
||||
},
|
||||
[](int intensity)
|
||||
{
|
||||
LightNode* nearest = findNearestLight();
|
||||
core::vector3df color = nearest->getColor();
|
||||
nearest->setColor(color.X, intensity / 100.0f, color.Z);
|
||||
}
|
||||
);
|
||||
dsd->changeLabel("Blue", "Blue (x10)");
|
||||
dsd->setSliderHook("blue_slider", 0, 100,
|
||||
[]()
|
||||
{
|
||||
return int(findNearestLight()->getColor().Z * 100);
|
||||
},
|
||||
[](int intensity)
|
||||
{
|
||||
LightNode* nearest = findNearestLight();
|
||||
core::vector3df color = nearest->getColor();
|
||||
nearest->setColor(color.X, color.Y, intensity / 100.0f);
|
||||
}
|
||||
);
|
||||
dsd->changeLabel("SSAO radius", "energy (x10)");
|
||||
dsd->setSliderHook("ssao_radius", 0, 100,
|
||||
[]() { return int(findNearestLight()->getEnergy() * 10); },
|
||||
[](int v){ findNearestLight()->setEnergy(v / 10.0f); }
|
||||
);
|
||||
dsd->changeLabel("SSAO k", "radius");
|
||||
dsd->setSliderHook("ssao_k", 0, 100,
|
||||
[]() { return int(findNearestLight()->getRadius()); },
|
||||
[](int v){ findNearestLight()->setRadius(float(v)); }
|
||||
);
|
||||
dsd->changeLabel("SSAO Sigma", "[None]");
|
||||
#endif
|
||||
}
|
||||
else if (cmdID == DEBUG_SCRIPT_CONSOLE)
|
||||
{
|
||||
ScriptingConsole* console = new ScriptingConsole();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Debug menu handling */
|
||||
bool onEvent(const SEvent &event)
|
||||
@ -202,10 +584,11 @@ bool onEvent(const SEvent &event)
|
||||
if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN &&
|
||||
!g_debug_menu_visible)
|
||||
{
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
|
||||
// root menu
|
||||
gui::IGUIEnvironment* guienv = irr_driver->getGUI();
|
||||
core::rect<s32> r(event.MouseInput.X, event.MouseInput.Y,
|
||||
event.MouseInput.Y+100, event.MouseInput.Y+100);
|
||||
core::rect<s32> r(100, 50, 150, 500);
|
||||
IGUIContextMenu* mnu = guienv->addContextMenu(r, NULL);
|
||||
int graphicsMenuIndex = mnu->addItem(L"Graphics >",-1,true,true);
|
||||
|
||||
@ -255,8 +638,8 @@ bool onEvent(const SEvent &event)
|
||||
sub->addItem(L"Behind wheel view", DEBUG_GUI_CAM_WHEEL);
|
||||
sub->addItem(L"Behind kart view", DEBUG_GUI_CAM_BEHIND_KART);
|
||||
sub->addItem(L"Side of kart view", DEBUG_GUI_CAM_SIDE_OF_KART);
|
||||
sub->addItem(L"First person view", DEBUG_GUI_CAM_FREE);
|
||||
sub->addItem(L"Normal view", DEBUG_GUI_CAM_NORMAL);
|
||||
sub->addItem(L"First person view (Ctrl + F1)", DEBUG_GUI_CAM_FREE);
|
||||
sub->addItem(L"Normal view (Ctrl + F2)", DEBUG_GUI_CAM_NORMAL);
|
||||
sub->addItem(L"Toggle smooth camera", DEBUG_GUI_CAM_SMOOTH);
|
||||
sub->addItem(L"Attach fps camera to kart", DEBUG_GUI_CAM_ATTACH);
|
||||
|
||||
@ -292,394 +675,37 @@ bool onEvent(const SEvent &event)
|
||||
IGUIContextMenu *menu = (IGUIContextMenu*)event.GUIEvent.Caller;
|
||||
s32 cmdID = menu->getItemCommandId(menu->getSelectedItem());
|
||||
|
||||
if(event.GUIEvent.EventType == EGET_ELEMENT_CLOSED)
|
||||
if (event.GUIEvent.EventType == EGET_ELEMENT_CLOSED)
|
||||
{
|
||||
g_debug_menu_visible = false;
|
||||
}
|
||||
|
||||
if (event.GUIEvent.EventType == gui::EGET_MENU_ITEM_SELECTED)
|
||||
else if (event.GUIEvent.EventType == gui::EGET_MENU_ITEM_SELECTED)
|
||||
{
|
||||
World *world = World::getWorld();
|
||||
Physics *physics = world ? world->getPhysics() : NULL;
|
||||
if(cmdID == DEBUG_GRAPHICS_RELOAD_SHADERS)
|
||||
{
|
||||
Log::info("Debug", "Reloading shaders...");
|
||||
ShaderBase::updateShaders();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_RESET)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_WIREFRAME)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleWireframe();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_MIPMAP_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleMipVisualization();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_NORMALS_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleNormals();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_SSAO_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleSSAOViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_RSM_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleRSM();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_RH_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleRH();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_GI_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleGI();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_SHADOW_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleShadowViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_LIGHT_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleLightViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_DISTORT_VIZ)
|
||||
{
|
||||
if (physics)
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NONE);
|
||||
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleDistortViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_BULLET_1)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
|
||||
if (!world) return false;
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_KARTS_PHYSICS);
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_BULLET_2)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
|
||||
if (!world) return false;
|
||||
Physics *physics = world->getPhysics();
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NO_KARTS_GRAPHICS);
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_BOUNDING_BOXES_VIZ)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleBoundingBoxesViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_PROFILER)
|
||||
{
|
||||
UserConfigParams::m_profiler_enabled =
|
||||
!UserConfigParams::m_profiler_enabled;
|
||||
}
|
||||
else if (cmdID == DEBUG_PROFILER_GENERATE_REPORT)
|
||||
{
|
||||
profiler.setCaptureReport(!profiler.getCaptureReport());
|
||||
}
|
||||
else if (cmdID == DEBUG_THROTTLE_FPS)
|
||||
{
|
||||
main_loop->setThrottleFPS(false);
|
||||
}
|
||||
else if (cmdID == DEBUG_FPS)
|
||||
{
|
||||
UserConfigParams::m_display_fps =
|
||||
!UserConfigParams::m_display_fps;
|
||||
}
|
||||
else if (cmdID == DEBUG_SAVE_REPLAY)
|
||||
{
|
||||
ReplayRecorder::get()->Save();
|
||||
}
|
||||
else if (cmdID == DEBUG_SAVE_HISTORY)
|
||||
{
|
||||
history->Save();
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_BOWLING)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_BOWLING);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_BUBBLEGUM)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_BUBBLEGUM);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_CAKE)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_CAKE);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_PARACHUTE)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_PARACHUTE);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_PLUNGER)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_PLUNGER);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_RUBBERBALL)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_RUBBERBALL);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_SWATTER)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_SWATTER);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_SWITCH)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_SWITCH);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_ZIPPER)
|
||||
{
|
||||
addPowerup(PowerupManager::POWERUP_ZIPPER);
|
||||
}
|
||||
else if (cmdID == DEBUG_POWERUP_NITRO)
|
||||
{
|
||||
if (!world) return false;
|
||||
const unsigned int num_local_players =
|
||||
race_manager->getNumLocalPlayers();
|
||||
for(unsigned int i = 0; i < num_local_players; i++)
|
||||
{
|
||||
AbstractKart* kart = world->getLocalPlayerKart(i);
|
||||
kart->setEnergy(100.0f);
|
||||
}
|
||||
}
|
||||
else if (cmdID == DEBUG_ATTACHMENT_ANVIL)
|
||||
{
|
||||
addAttachment(Attachment::ATTACH_ANVIL);
|
||||
}
|
||||
else if (cmdID == DEBUG_ATTACHMENT_BOMB)
|
||||
{
|
||||
addAttachment(Attachment::ATTACH_BOMB);
|
||||
}
|
||||
else if (cmdID == DEBUG_ATTACHMENT_PARACHUTE)
|
||||
{
|
||||
addAttachment(Attachment::ATTACH_PARACHUTE);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_TOGGLE)
|
||||
{
|
||||
if (!world) return false;
|
||||
RaceGUIBase* gui = world->getRaceGUI();
|
||||
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_HIDE_KARTS)
|
||||
{
|
||||
if (!world) return false;
|
||||
for (unsigned int n = 0; n<world->getNumKarts(); n++)
|
||||
{
|
||||
AbstractKart* kart = world->getKart(n);
|
||||
if (kart->getController()->isPlayerController())
|
||||
kart->getNode()->setVisible(false);
|
||||
}
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_TOP)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 1;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_WHEEL)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 2;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_BEHIND_KART)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 4;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_SIDE_OF_KART)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 5;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_FREE)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 3;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(false);
|
||||
// Reset camera rotation
|
||||
Camera *cam = Camera::getActiveCamera();
|
||||
cam->setDirection(vector3df(0, 0, 1));
|
||||
cam->setUpVector(vector3df(0, 1, 0));
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_NORMAL)
|
||||
{
|
||||
UserConfigParams::m_camera_debug = 0;
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_SMOOTH)
|
||||
{
|
||||
Camera *cam = Camera::getActiveCamera();
|
||||
cam->setSmoothMovement(!cam->getSmoothMovement());
|
||||
}
|
||||
else if (cmdID == DEBUG_GUI_CAM_ATTACH)
|
||||
{
|
||||
Camera *cam = Camera::getActiveCamera();
|
||||
cam->setAttachedFpsCam(!cam->getAttachedFpsCam());
|
||||
}
|
||||
else if (cmdID == DEBUG_PRINT_START_POS)
|
||||
{
|
||||
if(!world) return false;
|
||||
for(unsigned int i=0; i<world->getNumKarts(); i++)
|
||||
{
|
||||
AbstractKart *kart = world->getKart(i);
|
||||
Log::warn(kart->getIdent().c_str(),
|
||||
"<start position=\"%d\" x=\"%f\" y=\"%f\" z=\"%f\" h=\"%f\"/>",
|
||||
i, kart->getXYZ().getX(), kart->getXYZ().getY(),
|
||||
kart->getXYZ().getZ(),kart->getHeading()*RAD_TO_DEGREE
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (cmdID == DEBUG_VISUAL_VALUES)
|
||||
{
|
||||
#if !defined(__APPLE__)
|
||||
DebugSliderDialog *dsd = new DebugSliderDialog();
|
||||
dsd->setSliderHook("red_slider", 0, 255,
|
||||
[](){ return int(irr_driver->getAmbientLight().r * 255.f); },
|
||||
[](int v){
|
||||
video::SColorf ambient = irr_driver->getAmbientLight();
|
||||
ambient.setColorComponentValue(0, v / 255.f);
|
||||
irr_driver->setAmbientLight(ambient); }
|
||||
);
|
||||
dsd->setSliderHook("green_slider", 0, 255,
|
||||
[](){ return int(irr_driver->getAmbientLight().g * 255.f); },
|
||||
[](int v){
|
||||
video::SColorf ambient = irr_driver->getAmbientLight();
|
||||
ambient.setColorComponentValue(1, v / 255.f);
|
||||
irr_driver->setAmbientLight(ambient); }
|
||||
);
|
||||
dsd->setSliderHook("blue_slider", 0, 255,
|
||||
[](){ return int(irr_driver->getAmbientLight().b * 255.f); },
|
||||
[](int v){
|
||||
video::SColorf ambient = irr_driver->getAmbientLight();
|
||||
ambient.setColorComponentValue(2, v / 255.f);
|
||||
irr_driver->setAmbientLight(ambient); }
|
||||
);
|
||||
dsd->setSliderHook("ssao_radius", 0, 100,
|
||||
[](){ return int(irr_driver->getSSAORadius() * 10.f); },
|
||||
[](int v){irr_driver->setSSAORadius(v / 10.f); }
|
||||
);
|
||||
dsd->setSliderHook("ssao_k", 0, 100,
|
||||
[](){ return int(irr_driver->getSSAOK() * 10.f); },
|
||||
[](int v){irr_driver->setSSAOK(v / 10.f); }
|
||||
);
|
||||
dsd->setSliderHook("ssao_sigma", 0, 100,
|
||||
[](){ return int(irr_driver->getSSAOSigma() * 10.f); },
|
||||
[](int v){irr_driver->setSSAOSigma(v / 10.f); }
|
||||
);
|
||||
#endif
|
||||
}
|
||||
else if (cmdID == DEBUG_ADJUST_LIGHTS)
|
||||
{
|
||||
#if !defined(__APPLE__)
|
||||
// Some sliders use multipliers because the spinner widget
|
||||
// only supports integers
|
||||
DebugSliderDialog *dsd = new DebugSliderDialog();
|
||||
dsd->changeLabel("Red", "Red (x10)");
|
||||
dsd->setSliderHook("red_slider", 0, 100,
|
||||
[]()
|
||||
{
|
||||
return int(findNearestLight()->getColor().X * 100);
|
||||
},
|
||||
[](int intensity)
|
||||
{
|
||||
LightNode* nearest = findNearestLight();
|
||||
core::vector3df color = nearest->getColor();
|
||||
nearest->setColor(intensity / 100.0f, color.Y, color.Z);
|
||||
}
|
||||
);
|
||||
dsd->changeLabel("Green", "Green (x10)");
|
||||
dsd->setSliderHook("green_slider", 0, 100,
|
||||
[]()
|
||||
{
|
||||
return int(findNearestLight()->getColor().Y * 100);
|
||||
},
|
||||
[](int intensity)
|
||||
{
|
||||
LightNode* nearest = findNearestLight();
|
||||
core::vector3df color = nearest->getColor();
|
||||
nearest->setColor(color.X, intensity / 100.0f, color.Z);
|
||||
}
|
||||
);
|
||||
dsd->changeLabel("Blue", "Blue (x10)");
|
||||
dsd->setSliderHook("blue_slider", 0, 100,
|
||||
[]()
|
||||
{
|
||||
return int(findNearestLight()->getColor().Z * 100);
|
||||
},
|
||||
[](int intensity)
|
||||
{
|
||||
LightNode* nearest = findNearestLight();
|
||||
core::vector3df color = nearest->getColor();
|
||||
nearest->setColor(color.X, color.Y, intensity / 100.0f);
|
||||
}
|
||||
);
|
||||
dsd->changeLabel("SSAO radius", "energy (x10)");
|
||||
dsd->setSliderHook("ssao_radius", 0, 100,
|
||||
[]() { return int(findNearestLight()->getEnergy() * 10); },
|
||||
[](int v){ findNearestLight()->setEnergy(v / 10.0f); }
|
||||
);
|
||||
dsd->changeLabel("SSAO k", "radius");
|
||||
dsd->setSliderHook("ssao_k", 0, 100,
|
||||
[]() { return int(findNearestLight()->getRadius()); },
|
||||
[](int v){ findNearestLight()->setRadius(float(v)); }
|
||||
);
|
||||
dsd->changeLabel("SSAO Sigma", "[None]");
|
||||
#endif
|
||||
}
|
||||
else if (cmdID == DEBUG_SCRIPT_CONSOLE)
|
||||
{
|
||||
ScriptingConsole* console = new ScriptingConsole();
|
||||
}
|
||||
return handleContextMenuAction(cmdID);
|
||||
}
|
||||
|
||||
return false; // event has been handled
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true; // continue event handling
|
||||
} // onEvent
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool handleStaticAction(int key)
|
||||
{
|
||||
if (key == KEY_F1)
|
||||
{
|
||||
handleContextMenuAction(DEBUG_GUI_CAM_FREE);
|
||||
}
|
||||
else if (key == KEY_F2)
|
||||
{
|
||||
handleContextMenuAction(DEBUG_GUI_CAM_NORMAL);
|
||||
}
|
||||
// TODO: create more keyboard shortcuts
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns if the debug menu is visible.
|
||||
*/
|
||||
|
@ -27,6 +27,7 @@ namespace Debug
|
||||
{
|
||||
bool onEvent(const irr::SEvent &event);
|
||||
bool isOpen();
|
||||
bool handleStaticAction(int key);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user