Remove unneeded freeminer code.

This commit is contained in:
DustyBagel 2024-06-27 17:45:13 -05:00
parent eae9fa4e95
commit 9ff9b30e0f
10 changed files with 9 additions and 428 deletions

@ -656,7 +656,7 @@ bool CIrrDeviceSDL::run()
{
os::Timer::tick();
SEvent irrevent;
SEvent irrevent{};
SDL_Event SDL_event;
while (!Close && wrap_PollEvent(&SDL_event)) {

@ -1,96 +0,0 @@
#pragma once
#include "porting.h"
#if defined(linux) || defined(__linux)
#include <sys/prctl.h>
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
#include <pthread.h>
#include <pthread_np.h>
#elif defined(__NetBSD__)
#include <pthread.h>
#elif defined(__APPLE__)
#include <pthread.h>
#endif
#if defined(linux) || defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define PORTING_USE_PTHREAD 1
#include <pthread.h>
#endif
namespace porting
{
extern std::atomic_bool g_sighup, g_siginfo;
#if defined(linux) || defined(__linux)
inline void setThreadName(const char *name) {
/* It would be cleaner to do this with pthread_setname_np,
* which was added to glibc in version 2.12, but some major
* distributions are still runing 2.11 and previous versions.
*/
prctl(PR_SET_NAME, name);
}
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
inline void setThreadName(const char *name) {
pthread_set_name_np(pthread_self(), name);
}
#elif defined(__NetBSD__)
inline void setThreadName(const char *name) {
pthread_setname_np(pthread_self(), name);
}
#elif defined(_MSC_VER)
typedef struct tagTHREADNAME_INFO {
DWORD dwType; // must be 0x1000
LPCSTR szName; // pointer to name (in user addr space)
DWORD dwThreadID; // thread ID (-1=caller thread)
DWORD dwFlags; // reserved for future use, must be zero
} THREADNAME_INFO;
inline void setThreadName(const char *name) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
info.dwThreadID = -1;
info.dwFlags = 0;
__try {
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD), (ULONG_PTR *) &info);
} __except (EXCEPTION_CONTINUE_EXECUTION) {}
}
#elif defined(__APPLE__)
inline void setThreadName(const char *name) {
pthread_setname_np(name);
}
#elif defined(_WIN32) || defined(__GNU__)
inline void setThreadName(const char* name) {}
#else
#ifndef __EMSCRIPTEN__
#warning "Unrecognized platform, thread names will not be available."
#endif
inline void setThreadName(const char* name) {}
#endif
inline void setThreadPriority(int priority) {
#if PORTING_USE_PTHREAD
// http://en.cppreference.com/w/cpp/thread/thread/native_handle
sched_param sch;
//int policy;
//pthread_getschedparam(pthread_self(), &policy, &sch);
sch.sched_priority = priority;
if(pthread_setschedparam(pthread_self(), SCHED_FIFO /*SCHED_RR*/, &sch)) {
//std::cout << "Failed to setschedparam: " << std::strerror(errno) << '\n';
}
#endif
}
#ifndef SERVER
//void irr_device_wait_egl (irr::IrrlichtDevice * device = nullptr);
#endif
}

@ -1,101 +0,0 @@
/*
This file is part of Freeminer.
Freeminer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Freeminer 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "log_types.h"
#include "convert_json.h"
#include "irr_v3d.h"
#include "network/address.h"
std::ostream &operator<<(std::ostream &s, const v2s16 &p)
{
s << "(" << p.X << "," << p.Y << ")";
return s;
}
std::ostream &operator<<(std::ostream &s, const v2s32 &p)
{
s << "(" << p.X << "," << p.Y << ")";
return s;
}
std::ostream &operator<<(std::ostream &s, const v2f &p)
{
s << "(" << p.X << "," << p.Y << ")";
return s;
}
std::ostream &operator<<(std::ostream &s, const v3pos_t &p)
{
s << "(" << p.X << "," << p.Y << "," << p.Z << ")";
return s;
}
std::ostream &operator<<(std::ostream &s, const v3f &p)
{
s << "(" << p.X << "," << p.Y << "," << p.Z << ")";
return s;
}
#if USE_OPOS64
std::ostream &operator<<(std::ostream &s, const v3opos_t &p)
{
s << "(" << p.X << "," << p.Y << "," << p.Z << ")";
return s;
}
#endif
std::ostream &operator<<(std::ostream &s, const std::map<v3pos_t, unsigned int> &p)
{
for (auto &i : p)
s << i.first << "=" << i.second << " ";
return s;
}
std::ostream &operator<<(std::ostream &s, const irr::video::SColor &c)
{
s << "c32(" << c.color << ": a=" << c.getAlpha() << ",r=" << c.getRed()
<< ",g=" << c.getGreen() << ",b=" << c.getBlue() << ")";
return s;
}
std::ostream &operator<<(std::ostream &s, const irr::video::SColorf &c)
{
s << "cf32("
<< "a=" << c.getAlpha() << ",r=" << c.getRed() << ",g=" << c.getGreen()
<< ",b=" << c.getBlue() << ")";
return s;
}
#include "util/string.h"
std::ostream &operator<<(std::ostream &s, const std::wstring &w)
{
s << wide_to_utf8(w);
return s;
}
std::ostream &operator<<(std::ostream &s, const Json::Value &json)
{
s << fastWriteJson(json);
return s;
}
std::ostream &operator<<(std::ostream &s, const Address &addr)
{
addr.print(s);
// s << addr.getPort();
return s;
}

@ -1,55 +0,0 @@
/*
This file is part of Freeminer.
Freeminer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Freeminer 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOG_TYPES_HEADER
#define LOG_TYPES_HEADER
//#include "log.h" //for replacing log.h to log_types.h in includes
#include "irr_v2d.h"
#include "irr_v3d.h"
#include <ostream>
std::ostream &operator<<(std::ostream &s, const v2s16 &p);
std::ostream &operator<<(std::ostream &s, const v2s32 &p);
std::ostream &operator<<(std::ostream &s, const v2f &p);
std::ostream &operator<<(std::ostream &s, const v3pos_t &p);
std::ostream &operator<<(std::ostream &s, const v3f &p);
#if USE_OPOS64
std::ostream &operator<<(std::ostream &s, const v3opos_t &p);
#endif
#include <SColor.h>
std::ostream &operator<<(std::ostream &s, const irr::video::SColor &c);
std::ostream &operator<<(std::ostream &s, const irr::video::SColorf &c);
#include <map>
std::ostream &operator<<(std::ostream &s, const std::map<v3pos_t, unsigned int> &p);
std::ostream &operator<<(std::ostream &s, const std::wstring &w);
namespace Json
{
class Value;
};
//std::ostream &operator<<(std::ostream &s, const Json::Value &json);
class Address;
std::ostream &operator<<(std::ostream &s, const Address &addr);
#endif

@ -31,7 +31,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h"
#include "json/json.h"
#include "porting.h"
#include "threading/thread_vector.h"
#include "threading/thread.h"
#include "threading/concurrent_map.h"
#include "network/address.h"
@ -71,13 +71,13 @@ typedef int socket_t;
const static unsigned short int adv_port = 29998;
static std::string ask_str;
lan_adv::lan_adv() : thread_vector("lan_adv")
lan_adv::lan_adv() : Thread("lan_adv")
{
}
void lan_adv::ask()
{
reanimate();
if (!isRunning()) start();
if (ask_str.empty()) {
Json::Value j;
@ -169,14 +169,15 @@ void lan_adv::send_string(const std::string &str)
void lan_adv::serve(unsigned short port)
{
server_port = port;
restart();
if (isRunning()) stop();
start();
}
void *lan_adv::run()
{
BEGIN_DEBUG_EXCEPTION_HANDLER;
reg("LanAdv" + (server_port ? std::string("Server") : std::string("Client")));
setName("LanAdv" + (server_port ? std::string("Server") : std::string("Client")));
UDPSocket socket_recv(true);
int set_option_off = 0, set_option_on = 1;

@ -22,11 +22,11 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include <json/value.h>
#include <string>
#include <atomic>
#include "threading/thread_vector.h"
#include "threading/thread.h"
#include "threading/concurrent_map.h"
class lan_adv : public thread_vector
class lan_adv : public Thread
{
public:
void *run();

@ -50,18 +50,6 @@ void lan_get() {
lan_adv_client.ask();
}
/*
if (ask_str.empty()) {
Json::Value j;
j["cmd"] = "ask";
j["proto_min"] = Server::getProtocolVersionMin();
j["proto_max"] = Server::getProtocolVersionMax();
ask_str = fastWriteJson(j);
};
lan_adv_client.send_string(ask_str);
*/
bool lan_fresh() {
auto result = lan_adv_client.fresh.load();
lan_adv_client.fresh = false;

@ -3,6 +3,5 @@ set(JTHREAD_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/thread.cpp
${CMAKE_CURRENT_SOURCE_DIR}/semaphore.cpp
${CMAKE_CURRENT_SOURCE_DIR}/lock.cpp
${CMAKE_CURRENT_SOURCE_DIR}/thread_vector.cpp
PARENT_SCOPE)

@ -1,118 +0,0 @@
#include "thread_vector.h"
#include "fm_porting.h"
#include "log.h"
#include "porting.h"
thread_vector::thread_vector(const std::string &name, int priority) :
m_name(name), m_priority(priority)
{
request_stop = false;
};
thread_vector::~thread_vector()
{
join();
};
void thread_vector::func()
{
reg();
run();
};
void thread_vector::reg(const std::string &name, int priority)
{
if (!name.empty())
m_name = name;
porting::setThreadName(m_name.c_str());
g_logger.registerThread(m_name);
if (priority)
m_priority = priority;
if (m_priority)
porting::setThreadPriority(m_priority);
};
void thread_vector::start(const size_t n)
{
#if !NDEBUG
infostream << "start thread " << m_name << " n=" << n << std::endl;
#endif
request_stop = false;
for (size_t i = 0; i < n; ++i) {
workers.emplace_back(&thread_vector::func, this);
}
}
void thread_vector::stop()
{
request_stop = true;
}
void thread_vector::join()
{
stop();
for (auto &worker : workers) {
try {
if (worker.joinable()) {
worker.join();
}
} catch (...) {
}
}
workers.clear();
}
void thread_vector::restart(size_t n)
{
join();
start(n);
}
void thread_vector::reanimate(size_t n)
{
if (workers.empty()) {
start(n);
}
}
void thread_vector::sleep(const int seconds)
{
for (int i = 0; i <= seconds; ++i) {
std::this_thread::sleep_for(std::chrono::seconds(1));
if (request_stop) {
return;
}
}
}
// JThread compat:
bool thread_vector::stopRequested()
{
return request_stop;
}
bool thread_vector::isRunning()
{
return !workers.empty();
}
void thread_vector::wait()
{
join();
};
void thread_vector::kill()
{
join();
};
void *thread_vector::run()
{
return nullptr;
};
bool thread_vector::isCurrentThread()
{
auto thread_me = std::hash<std::thread::id>()(std::this_thread::get_id());
for (auto &worker : workers)
if (thread_me == std::hash<std::thread::id>()(worker.get_id()))
return true;
return false;
}

@ -1,37 +0,0 @@
#pragma once
#include <atomic>
#include <thread>
#include <vector>
#include <string>
class thread_vector {
public:
std::vector<std::thread> workers;
std::atomic_bool request_stop;
thread_vector(const std::string &name = "Unnamed", int priority = 0);
virtual ~thread_vector();
virtual void func();
void reg (const std::string &name = "", int priority = 0);
void start (const size_t n = 1);
void restart (const size_t n = 1);
void reanimate (const size_t n = 1);
void stop ();
void join ();
void sleep(const int second);
// Thread compat:
bool stopRequested();
bool isRunning();
void wait();
void kill();
virtual void * run() = 0;
bool isCurrentThread();
protected:
std::string m_name;
int m_priority = 0;
};