#include "clouds.h"
#include "config.h"
#include "content_cao.h"
+#include "content/subgames.h"
#include "client/event_manager.h"
#include "fontengine.h"
#include "itemdef.h"
#include "log.h"
#include "filesys.h"
+#include "gameparams.h"
#include "gettext.h"
#include "gui/guiChatConsole.h"
#include "gui/guiConfirmRegistration.h"
~Game();
bool startup(bool *kill,
- bool random_input,
InputHandler *input,
- const std::string &map_dir,
- const std::string &playername,
- const std::string &password,
- // If address is "", local server is used and address is updated
- std::string *address,
- u16 port,
+ const GameStartData &game_params,
std::string &error_message,
bool *reconnect,
- ChatBackend *chat_backend,
- const SubgameSpec &gamespec, // Used for local game
- bool simple_singleplayer_mode);
+ ChatBackend *chat_backend);
void run();
void shutdown();
void extendedResourceCleanup();
// Basic initialisation
- bool init(const std::string &map_dir, std::string *address,
- u16 port,
- const SubgameSpec &gamespec);
+ bool init(const std::string &map_dir, const std::string &address,
+ u16 port, const SubgameSpec &gamespec);
bool initSound();
bool createSingleplayerServer(const std::string &map_dir,
- const SubgameSpec &gamespec, u16 port, std::string *address);
+ const SubgameSpec &gamespec, u16 port);
// Client creation
- bool createClient(const std::string &playername,
- const std::string &password, std::string *address, u16 port);
+ bool createClient(const GameStartData &start_data);
bool initGui();
// Client connection
- bool connectToServer(const std::string &playername,
- const std::string &password, std::string *address, u16 port,
+ bool connectToServer(const GameStartData &start_data,
bool *connect_ok, bool *aborted);
bool getServerContent(bool *aborted);
bool *reconnect_requested;
scene::ISceneNode *skybox;
- bool random_input;
bool simple_singleplayer_mode;
/* End 'cache' */
}
bool Game::startup(bool *kill,
- bool random_input,
InputHandler *input,
- const std::string &map_dir,
- const std::string &playername,
- const std::string &password,
- std::string *address, // can change if simple_singleplayer_mode
- u16 port,
+ const GameStartData &start_data,
std::string &error_message,
bool *reconnect,
- ChatBackend *chat_backend,
- const SubgameSpec &gamespec,
- bool simple_singleplayer_mode)
+ ChatBackend *chat_backend)
{
+
// "cache"
this->device = RenderingEngine::get_raw_device();
this->kill = kill;
this->error_message = &error_message;
this->reconnect_requested = reconnect;
- this->random_input = random_input;
this->input = input;
this->chat_backend = chat_backend;
- this->simple_singleplayer_mode = simple_singleplayer_mode;
+ this->simple_singleplayer_mode = start_data.isSinglePlayer();
input->keycache.populate();
g_client_translations->clear();
- if (!init(map_dir, address, port, gamespec))
+ // address can change if simple_singleplayer_mode
+ if (!init(start_data.world_spec.path, start_data.address,
+ start_data.socket_port, start_data.game_spec))
return false;
- if (!createClient(playername, password, address, port))
+ if (!createClient(start_data))
return false;
RenderingEngine::initialize(client, hud);
if (formspec)
formspec->quitMenu();
+#ifdef HAVE_TOUCHSCREENGUI
+ g_touchscreengui->hide();
+#endif
+
showOverlayMessage(N_("Shutting down..."), 0, 0, false);
if (clouds)
bool Game::init(
const std::string &map_dir,
- std::string *address,
+ const std::string &address,
u16 port,
const SubgameSpec &gamespec)
{
return false;
// Create a server if not connecting to an existing one
- if (address->empty()) {
- if (!createSingleplayerServer(map_dir, gamespec, port, address))
+ if (address.empty()) {
+ if (!createSingleplayerServer(map_dir, gamespec, port))
return false;
}
}
bool Game::createSingleplayerServer(const std::string &map_dir,
- const SubgameSpec &gamespec, u16 port, std::string *address)
+ const SubgameSpec &gamespec, u16 port)
{
showOverlayMessage(N_("Creating server..."), 0, 5);
return true;
}
-bool Game::createClient(const std::string &playername,
- const std::string &password, std::string *address, u16 port)
+bool Game::createClient(const GameStartData &start_data)
{
showOverlayMessage(N_("Creating client..."), 0, 10);
g_touchscreengui->hide();
}
#endif
- if (!connectToServer(playername, password, address, port,
- &could_connect, &connect_aborted))
+ if (!connectToServer(start_data, &could_connect, &connect_aborted))
return false;
if (!could_connect) {
return true;
}
-bool Game::connectToServer(const std::string &playername,
- const std::string &password, std::string *address, u16 port,
+bool Game::connectToServer(const GameStartData &start_data,
bool *connect_ok, bool *connection_aborted)
{
*connect_ok = false; // Let's not be overly optimistic
showOverlayMessage(N_("Resolving address..."), 0, 15);
- Address connect_address(0, 0, 0, 0, port);
+ Address connect_address(0, 0, 0, 0, start_data.socket_port);
try {
- connect_address.Resolve(address->c_str());
+ connect_address.Resolve(start_data.address.c_str());
if (connect_address.isZero()) { // i.e. INADDR_ANY, IN6ADDR_ANY
//connect_address.Resolve("localhost");
return false;
}
- client = new Client(playername.c_str(), password, *address,
+ client = new Client(start_data.name.c_str(),
+ start_data.password, start_data.address,
*draw_control, texture_src, shader_src,
itemdef_manager, nodedef_manager, sound, eventmgr,
connect_address.isIPv6(), m_game_ui.get());
} else {
registration_confirmation_shown = true;
(new GUIConfirmRegistration(guienv, guienv->getRootGUIElement(), -1,
- &g_menumgr, client, playername, password,
+ &g_menumgr, client, start_data.name, start_data.password,
connection_aborted, texture_src))->drop();
}
} else {
wait_time += dtime;
// Only time out if we aren't waiting for the server we started
- if (!address->empty() && wait_time > 10) {
+ if (!start_data.isSinglePlayer() && wait_time > 10) {
*error_message = "Connection timed out.";
errorstream << *error_message << std::endl;
break;
void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
{
if ((device->isWindowActive() && device->isWindowFocused()
- && !isMenuActive()) || random_input) {
+ && !isMenuActive()) || input->isRandom()) {
#ifndef __ANDROID__
- if (!random_input) {
+ if (!input->isRandom()) {
// Mac OSX gets upset if this is set every frame
if (device->getCursorControl()->isVisible())
device->getCursorControl()->setVisible(false);
input->joystick.getAxisWithoutDead(JA_FORWARD_MOVE)
);
- u32 keypress_bits =
+ u32 keypress_bits = (
( (u32)(isKeyDown(KeyType::FORWARD) & 0x1) << 0) |
( (u32)(isKeyDown(KeyType::BACKWARD) & 0x1) << 1) |
( (u32)(isKeyDown(KeyType::LEFT) & 0x1) << 2) |
( (u32)(isKeyDown(KeyType::SPECIAL1) & 0x1) << 5) |
( (u32)(isKeyDown(KeyType::SNEAK) & 0x1) << 6) |
( (u32)(input->getLeftState() & 0x1) << 7) |
- ( (u32)(input->getRightState() & 0x1) << 8
+ ( (u32)(input->getRightState() & 0x1) << 8) |
+ ( (u32)(isKeyDown(KeyType::ZOOM) & 0x1) << 9)
);
#ifdef ANDROID
// Shows the mesh skybox
sky->setVisible(true);
// Update mesh based skybox colours if applicable.
- sky->setSkyColors(*event->set_sky);
+ sky->setSkyColors(event->set_sky->sky_color);
sky->setHorizonTint(
event->set_sky->fog_sun_tint,
event->set_sky->fog_moon_tint,
}
// formspec in meta
- if (meta && !meta->getString("formspec").empty() && !random_input
+ if (meta && !meta->getString("formspec").empty() && !input->isRandom()
&& !isKeyDown(KeyType::SNEAK)) {
// on_rightclick callbacks are called anyway
if (nodedef_manager->get(map.getNode(nodepos)).rightclickable)
/****************************************************************************/
void the_game(bool *kill,
- bool random_input,
InputHandler *input,
- const std::string &map_dir,
- const std::string &playername,
- const std::string &password,
- const std::string &address, // If empty local server is created
- u16 port,
-
+ const GameStartData &start_data,
std::string &error_message,
ChatBackend &chat_backend,
- bool *reconnect_requested,
- const SubgameSpec &gamespec, // Used for local game
- bool simple_singleplayer_mode)
+ bool *reconnect_requested) // Used for local game
{
Game game;
* is created then this is updated and we don't want to change the value
* passed to us by the calling function
*/
- std::string server_address = address;
try {
- if (game.startup(kill, random_input, input, map_dir,
- playername, password, &server_address, port, error_message,
- reconnect_requested, &chat_backend, gamespec,
- simple_singleplayer_mode)) {
+ if (game.startup(kill, input, start_data, error_message,
+ reconnect_requested, &chat_backend)) {
game.run();
}