start server part of clusterizer

This commit is contained in:
2025-02-20 22:43:39 +01:00
parent 5eee13a4e2
commit 960c4eb99c
10 changed files with 237 additions and 61 deletions

View File

@ -62,6 +62,9 @@ ALL_SRCS := $(IMGUI_SRCS) gl.cpp \
class/Renderer/imgui.cpp \ class/Renderer/imgui.cpp \
class/Renderer/movements.cpp\ class/Renderer/movements.cpp\
class/Renderer/saveLoad.cpp \ class/Renderer/saveLoad.cpp \
class/Clusterizer/Clusterizer.cpp\
class/Clusterizer/client.cpp \
class/Clusterizer/server.cpp \
SRCS := $(ALL_SRCS:%=$(SRCS_DIR)/%) SRCS := $(ALL_SRCS:%=$(SRCS_DIR)/%)
OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:%.cpp=%.o)) OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:%.cpp=%.o))

View File

@ -1,34 +0,0 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
[Window][Camera]
Pos=1617,8
Size=259,200
[Window][Material]
Pos=1594,206
Size=262,299
[Window][Fog settings]
Pos=1632,514
Size=247,130
Collapsed=1
[Window][Debug]
Pos=1642,668
Size=260,143
[Window][Debug BVH]
Pos=1628,542
Size=274,131
Collapsed=1
[Window][Renderer]
Pos=1556,610
Size=284,382
[Window][Settings]
Pos=1616,42
Size=340,941

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */ /* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */
/* Updated: 2025/02/04 23:39:14 by tomoron ### ########.fr */ /* Updated: 2025/02/20 21:28:15 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,6 +45,11 @@
# include <set> # include <set>
# include <map> # include <map>
# include <sys/socket.h>
# include <netinet/in.h>
# include <fcntl.h>
# include <arpa/inet.h>
struct Vertex { struct Vertex {
glm::vec2 position; glm::vec2 position;
glm::vec2 texCoord; glm::vec2 texCoord;
@ -70,6 +75,7 @@ struct Vertex {
# include "SceneParser.hpp" # include "SceneParser.hpp"
# include "ObjParser.hpp" # include "ObjParser.hpp"
# include "BVH.hpp" # include "BVH.hpp"
# include "Clusterizer.hpp"

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/04 01:07:08 by tomoron #+# #+# */ /* Created: 2025/02/04 01:07:08 by tomoron #+# #+# */
/* Updated: 2025/02/04 22:04:04 by tomoron ### ########.fr */ /* Updated: 2025/02/20 19:52:31 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,10 +31,17 @@ class Arguments
bool error(void) const; bool error(void) const;
void show(void); void show(void);
bool getBoolean(std::string name);
std::string *getString(std::string name);
std::string &getSceneName(void); std::string &getSceneName(void);
std::string *getRenderPath(void); std::string *getRenderPath(void);
bool getHeadless(void); bool getHeadless(void);
bool isServer(void);
bool isClient(void);
std::string *getServerIp(void);
private: private:
void printUsage(); void printUsage();

View File

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Clusterizer.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 18:25:18 by tomoron #+# #+# */
/* Updated: 2025/02/20 22:41:05 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CLUSTERIZER_HPP
# define CLUSTERIZER_HPP
# include "RT.hpp"
typedef struct s_job
{
std::string scene;
glm::vec3 pos;
glm::vec2 dir;
size_t samples;
} t_job;
class Clusterizer
{
public:
Clusterizer(Arguments args);
~Clusterizer();
private:
void update(void);
bool getError(void);
bool _isActive;
bool _isServer;
bool _error;
std::vector<t_job> _jobs;
private: //client
void initClient(void);
void updateClient(void);
std::string _serverIp;
private: //server
void initServer(std::string port);
void updateServer(void);
void initServerSocket(uint16_t port);
int _serverSocket;
};
#endif

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/04 01:05:44 by tomoron #+# #+# */ /* Created: 2025/02/04 01:05:44 by tomoron #+# #+# */
/* Updated: 2025/02/04 22:17:04 by tomoron ### ########.fr */ /* Updated: 2025/02/20 22:36:06 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,20 +38,28 @@ Arguments::Arguments(int argc, char **argv)
std::cerr << "missing scene name" << std::endl; std::cerr << "missing scene name" << std::endl;
_err = 1; _err = 1;
} }
if(getBoolean("server") && getBoolean("client"))
{
std::cerr << "RT can't be both a client and a server" << std::endl;
_err = 1;
}
} }
void Arguments::initArguments() void Arguments::initArguments()
{ {
addArgument('r', "renderpath", 0); addArgument('r', "renderpath", 0);
addArgument('h', "headless", 1); addArgument('h', "headless", 1);
addArgument('c', "client", 0);
addArgument('s', "server", 0);
} }
void Arguments::printUsage(void) void Arguments::printUsage(void)
{ { std::cerr << "usage : [options] <scene name> [options]" << std::endl;
std::cerr << "usage : [options] <scene name> [options]" << std::endl;
std::cerr << R""""(options : std::cerr << R""""(options :
-r | --renderpath <file>: filename for the renderer path -r | --renderpath <file>: filename for the renderer path
-h | --headless : does the program need to start rendering as soon as it starts(and close automatically) -h | --headless : does the program need to start rendering as soon as it starts(and close automatically)
-c | --client <server ip:port> : start RT as a client
-s | --server <port>: start a server
)""""; )"""";
} }
@ -67,25 +75,6 @@ bool Arguments::error(void) const
} }
std::string &Arguments::getSceneName(void)
{
return(_values["sceneName"]);
}
std::string *Arguments::getRenderPath(void)
{
if(_values.find("renderpath") != _values.end())
return(&_values["renderpath"]);
else
return(0);
}
bool Arguments::getHeadless(void)
{
return(_values.find("headless") != _values.end());
}
void Arguments::addArgument(char shortName, std::string longName, int isFlag) void Arguments::addArgument(char shortName, std::string longName, int isFlag)
{ {
t_arg arg; t_arg arg;
@ -161,3 +150,21 @@ int Arguments::handleArg(char **argv, int argc, int *i)
} }
return(1); return(1);
} }
bool Arguments::getBoolean(std::string name)
{
return(_values.find(name) != _values.end());
}
std::string *Arguments::getString(std::string name)
{
if(_values.find(name) != _values.end())
return(&_values[name]);
else
return(0);
}
std::string &Arguments::getSceneName(void)
{
return(_values["sceneName"]);
}

View File

@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Clusterizer.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 18:24:39 by tomoron #+# #+# */
/* Updated: 2025/02/20 22:42:42 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "RT.hpp"
Clusterizer::Clusterizer(Arguments args)
{
_isActive = 1;
_isServer = 0;
_error = 0;
_serverSocket = 0;
if(args.getBoolean("server"))
{
_isServer = 1;
initServer(*args.getString("server"));
}
else if(args.getBoolean("client"))
{
_isServer = 0;
_serverIp = *args.getString("client");
initClient();
}
else
_isActive = 0;
}
Clusterizer::~Clusterizer(void)
{
if(_serverSocket)
close(_serverSocket);
}
void Clusterizer::update(void)
{
if(!_isActive)
return ;
if(_isServer)
updateServer();
else
updateClient();
}
bool Clusterizer::getError(void)
{
return(_error);
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
/* Updated: 2025/02/20 21:21:45 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "RT.hpp"
void Clusterizer::initClient(void)
{
}
void Clusterizer::updateClient(void)
{
}

View File

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
/* Updated: 2025/02/20 22:43:00 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "RT.hpp"
void Clusterizer::initServer(std::string port)
{
try
{
initServerSocket(stoi(port));
}
catch(std::exception &e)
{
std::cerr << "server initialization error : " << e.what() << std::endl;
_error = 1;
}
}
void Clusterizer::initServerSocket(uint16_t port)
{
struct sockaddr_in s_addr;
_serverSocket = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (_serverSocket < 0)
throw std::runtime_error("can't create socket");
s_addr.sin_family = AF_INET;
s_addr.sin_addr.s_addr = INADDR_ANY;
s_addr.sin_port = port >> 8 | port << 8;
if (bind(_serverSocket, (struct sockaddr *)&s_addr, \
sizeof(struct sockaddr_in)) < 0)
throw std::runtime_error("can't bind socket");
if (::listen(_serverSocket, 50) < 0)
throw std::runtime_error("can't listen on socket");
}
void Clusterizer::updateServer(void)
{
}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */ /* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
/* Updated: 2025/02/20 16:06:18 by tomoron ### ########.fr */ /* Updated: 2025/02/20 20:02:05 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,8 +18,8 @@ Renderer::Renderer(Scene *scene, Window *win, Arguments &args)
std::string *renderPath; std::string *renderPath;
init(scene, win); init(scene, win);
_headless = args.getHeadless(); _headless = args.getBoolean("headless");
renderPath = args.getRenderPath(); renderPath = args.getString("renderpath");
if(renderPath) if(renderPath)
{ {