Skip to content

Commit

Permalink
Merge pull request #5 from EleutherAI/keyboard-input
Browse files Browse the repository at this point in the history
Keyboard input
  • Loading branch information
AI-WAIFU committed Nov 19, 2022
2 parents e84bf6e + 53ad7e1 commit ea56815
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ build/.cmake/
# GNU Patch reject file
*.rej

newworld/
## Non-static Minetest directories or symlinks to these
/bin/
/games/*
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ endif()
# Library pack
find_package(GMP REQUIRED)
find_package(Json REQUIRED)
find_package(Zmq REQUIRED)
find_package(Zmqpp REQUIRED)
find_package(Lua REQUIRED)
find_package(Zmq REQUIRED)
find_package(Zmqpp REQUIRED)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ For Debian/Ubuntu users:

sudo apt install g++ make libc6-dev cmake libpng-dev libjpeg-dev libxi-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev libzstd-dev libluajit-5.1-dev libzmq3-dev libzmqpp-dev

For Fedora users(Unsupported):
For Fedora users (unsupported):

sudo dnf install make automake gcc gcc-c++ kernel-devel cmake libcurl-devel openal-soft-devel libvorbis-devel libXi-devel libogg-devel freetype-devel mesa-libGL-devel zlib-devel jsoncpp-devel gmp-devel sqlite-devel luajit-devel leveldb-devel ncurses-devel spatialindex-devel libzstd-devel

For Arch users(Unsupported):
For Arch users (unsupported):

sudo pacman -S base-devel libcurl-gnutls cmake libxi libpng sqlite libogg libvorbis openal freetype2 jsoncpp gmp luajit leveldb ncurses zstd

For Alpine users(Unsupported):
For Alpine users (unsupported):

sudo apk add build-base cmake libpng-dev jpeg-dev libxi-dev mesa-dev sqlite-dev libogg-dev libvorbis-dev openal-soft-dev curl-dev freetype-dev zlib-dev gmp-dev jsoncpp-dev luajit-dev zstd-dev

Expand Down
2 changes: 2 additions & 0 deletions hacking_testing/client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec bin/minetest --name me --password whyisthisnecessary --address 0.0.0.0 --port 30000 --dumb-port 'tcp:https://*:9000' --dumb --go
2 changes: 2 additions & 0 deletions hacking_testing/server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec bin/minetest --server --world newworld --gameid minetest --config hacking_testing/minetest.conf
1 change: 1 addition & 0 deletions src/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set(client_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/hud.cpp
${CMAKE_CURRENT_SOURCE_DIR}/imagefilters.cpp
${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dumbhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/joystick_controller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/keycode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/localplayer.cpp
Expand Down
11 changes: 10 additions & 1 deletion src/client/clientlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ void ClientLauncher::init_args(GameStartData &start_data, const Settings &cmd_ar
if (cmd_args.exists("name"))
start_data.name = cmd_args.get("name");

start_data.dumb = cmd_args.getFlag("dumb");
if(cmd_args.exists("dumb-port"))
start_data.dumb_client_port = cmd_args.get("dumb-port");

dumb = start_data.isDumbClient();
dumb_port = start_data.dumb_client_port;

random_input = g_settings->getBool("random_input")
|| cmd_args.getFlag("random-input");
}
Expand All @@ -342,7 +349,9 @@ bool ClientLauncher::init_engine()

void ClientLauncher::init_input()
{
if (random_input)
if(dumb)
input = new DumbClientInputHandler(dumb_port);
else if (random_input)
input = new RandomInputHandler();
else
input = new RealInputHandler(receiver);
Expand Down
3 changes: 3 additions & 0 deletions src/client/clientlauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "irrlichttypes_extrabloated.h"
#include "client/inputhandler.h"
#include "client/dumbhandler.h"
#include "gameparams.h"

class RenderingEngine;
Expand Down Expand Up @@ -48,6 +49,8 @@ class ClientLauncher

bool skip_main_menu = false;
bool random_input = false;
bool dumb = false;
std::string dumb_port = "";
RenderingEngine *m_rendering_engine = nullptr;
InputHandler *input = nullptr;
MyEventReceiver *receiver = nullptr;
Expand Down
20 changes: 20 additions & 0 deletions src/client/dumbhandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <[email protected]>
Copyright (C) 2017 nerzhul, Loic Blot <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

65 changes: 65 additions & 0 deletions src/client/dumbhandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include "irrlichttypes_extrabloated.h"
#include "client/inputhandler.h"
#include <zmqpp/zmqpp.hpp>
#include <string>

class DumbClientInputHandler : public InputHandler
{
public:
DumbClientInputHandler(std::string zmq_port): client(context, zmqpp::socket_type::reply) {
try {
client.bind(zmq_port);
} catch (zmqpp::zmq_internal_exception &e) {
errorstream << "ZeroMQ error: " << e.what() << " (port: " << zmq_port << ")" << std::endl;
throw e;
};
};

virtual bool isKeyDown(GameKeyType k) { return keydown[keycache.key[k]]; }
virtual bool wasKeyDown(GameKeyType k) { return false; }
virtual bool wasKeyPressed(GameKeyType k) { return false; }
virtual bool wasKeyReleased(GameKeyType k) { return false; }
virtual bool cancelPressed() { return false; }
virtual float getMovementSpeed() { return movementSpeed; }
virtual float getMovementDirection() { return movementDirection; }
virtual v2s32 getMousePos() { return mousepos; }
virtual void setMousePos(s32 x, s32 y) { mousepos = v2s32(x, y); }

virtual s32 getMouseWheel() { return 0; }

virtual void step(float dtime) {
// TODO
};

s32 Rand(s32 min, s32 max);

private:
zmqpp::context context;
zmqpp::socket client;
KeyList keydown;
v2s32 mousepos;
v2s32 mousespeed;
float movementSpeed;
float movementDirection;
};
4 changes: 4 additions & 0 deletions src/gameparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ struct GameStartData : GameParams
GameStartData() = default;

bool isSinglePlayer() const { return address.empty() && !local_server; }
bool isDumbClient() { return dumb && !dumb_client_port.empty(); }

std::string name;
std::string password;
std::string address;
bool local_server;

bool dumb;
std::string dumb_client_port;

ELoginRegister allow_login_or_register = ELoginRegister::Any;

// "world_path" must be kept in sync!
Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ int main(int argc, char *argv[])

sanity_check(!game_params.world_path.empty());

if (game_params.is_dedicated_server)
if (game_params.is_dedicated_server) {
return run_dedicated_server(game_params, cmd_args) ? 0 : 1;
}

#ifndef SERVER
retval = ClientLauncher().run(game_params, cmd_args) ? 0 : 1;
Expand Down Expand Up @@ -376,6 +377,10 @@ static void set_allowed_options(OptionList *allowed_options)
_("Disable main menu"))));
allowed_options->insert(std::make_pair("console", ValueSpec(VALUETYPE_FLAG,
_("Starts with the console (Windows only)"))));
allowed_options->insert(std::make_pair("dumb", ValueSpec(VALUETYPE_FLAG,
_("Makes this client a dumb client (Not for servers)"))));
allowed_options->insert(std::make_pair("dumb-port", ValueSpec(VALUETYPE_STRING,
_("ZeroMQ port for the dumb client."))));
#endif

}
Expand Down

0 comments on commit ea56815

Please sign in to comment.