-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment & IGameDef code refactoring #4985
Conversation
0d1e597
to
aec8aeb
Compare
Note: i didn't fixed the code style issues, it's a pure code move |
As a guess the abstraction of IGameDef is there for a reason - to discourage people from getting the Server or Client |
IGameDef is a real problem as it share some common unused attributes, like shadersource (client only), emerge (server only) and many other client things. I will push another commit to cleanup some useless functions Also IGameDef add some irrlicht types declared to server, if at a moment we want to move outside irrlicht it's also a problem solved |
I think it's ready for a review. To resume:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should be merged as soon as possible before merge conflicts arise.
} | ||
|
||
// Protocol v29 make this behaviour obsolete | ||
if (((Client*) getGameDef())->getProtoVersion() < 29) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not happen in ClientEnvironment.
|
||
// Only usable on the server. Thread safe if not written while running threads. | ||
virtual EmergeManager *getEmergeManager() { return NULL; } | ||
virtual IRollbackManager* getRollbackManager() { return NULL; } | ||
|
||
// Used on the client | ||
virtual bool checkLocalPrivilege(const std::string &priv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed from there, since it is only overridden on the client and used by the camera.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exact, this should be moved to client
virtual ITextureSource* getTextureSource()=0; | ||
|
||
virtual IShaderSource* getShaderSource()=0; | ||
|
||
// Used for keeping track of names/ids of unknown nodes | ||
virtual u16 allocateUnknownNodeId(const std::string &name)=0; | ||
|
||
// Only usable on the client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be removed because the server has an event manager, too.
@@ -81,13 +81,12 @@ static unsigned int font_line_height(gui::IGUIFont *font) | |||
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev, | |||
JoystickController *joystick, | |||
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, | |||
InventoryManager *invmgr, IGameDef *gamedef, | |||
Client *client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The texture source is also in the client (and the device too, but there is no getter for that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client->tsrc() ? if i remember it's the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact i check TextureSource is needed here because one constructor was called and only knows texture source, not client
@@ -543,7 +543,7 @@ class CItemDefManager: public IWritableItemDefManager | |||
request = m_get_clientcached_queue.pop(); | |||
|
|||
m_get_clientcached_queue.pushResult(request, | |||
createClientCachedDirect(request.key, gamedef)); | |||
createClientCachedDirect(request.key, (Client *)gamedef)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gamedef
should be client
. This function is called only from the Game
object, and it already supplies the client as a parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right i forgot it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact no, at this moment it's not possible to change this because we depend on IWritableItemDefManager which is client & server side
IShaderSource *shdsrc = gamedef->getShaderSource(); | ||
scene::ISceneManager* smgr = gamedef->getSceneManager(); | ||
|
||
Client *client = (Client *)gamedef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter type should be Client
. This is called only once by the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it's not possible, please look at caller, it's a IGamedef because this function is at this moment shared between client and server
ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG); | ||
for (std::vector<RemotePlayer *>::iterator i = m_players.begin(); | ||
i != m_players.end(); ++i) { | ||
RemotePlayer *player = dynamic_cast<RemotePlayer *>(*i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not covered by this PR exactly because it's code move but yes
std::vector<v3s16> players_blockpos; | ||
for (std::vector<RemotePlayer *>::iterator i = m_players.begin(); | ||
i != m_players.end(); ++i) { | ||
RemotePlayer *player = dynamic_cast<RemotePlayer *>(*i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast can be removed, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like previous comment
@juhdanad i fixed all possible points which doesn't need more huge refactoring |
Can't compile (master with this PR git am'd):
Did I miss an irrlicht update? I'm on archlinux, 1.8.4 irrlicht. |
Which compiler do you use ? I'm also with archlinux
|
In my opinion it is good to go. 👍 |
I tested on another computer with g++ it works, testing now with clang++ Works also with clang, i don't understand your compilation error. CI is fine too @sofar clientenv.h include clientobj.h which include irrlichttypes_extrabloated.h which include if SERVER not def IrrlichtDevice.h I didn't build server alone, i'm doing it now |
f05fb14
to
1435e12
Compare
@sofar i forced pushed commit 5 with compilation fix, i missed to re-enable -DBUILD_SERVER=1 on my cmake installation |
1435e12
to
cfa2599
Compare
i rebased the branch |
cfa2599
to
1c4cfb2
Compare
stock arch gcc: |
@sofar ignore my compiler question is was a compilation problem with -DENABLE_SERVER=1 and now travis build with server |
compiles now. |
nice ! just wait for your review now |
1c4cfb2
to
922c99e
Compare
922c99e
to
9ed543f
Compare
I have reviewed the conflicting files (since the conflict was with my commit). |
9ed543f
to
cd28a1e
Compare
Fixed android build in last commit |
Still works fine for me. I agree that separation like this makes sense and it's something that is certainly needed. I'm fine with it. |
One big question. Why did you change all of the IGameDefs to Client or Server? This is wrong. |
In fact for this commit set there is two major reasons:
* Drop all unneeded casts in environment
* Cleanup Igamedef non common functions between client & serverPlease also note Igamedef was not replaced everywhere, just in this commit set required parts.This commit set is relatively big. If we wanted to re-use Igamedef properly in right places this requires to do more refactoring.
|
cd28a1e
to
0fb6ab0
Compare
rebased since last recent changes |
* Cleanup includes & class declarations in client & server environment to improve build speed * ServerEnvironment::m_gamedef is now a pointer to Server instead of IGameDef, permitting to cleanup many casts. * Cleanup IGameDef * Move ITextureSource* IGameDef::getTextureSource() to Client only. * Also move ITextureSource *IGameDef::tsrc() helper * drop getShaderSource, getSceneManager, getSoundManager & getCamera abstract call * drop unused emerge() call * cleanup server unused functions (mentionned before) * Drop one unused parameter from ContentFeatures::updateTextures * move checkLocalPrivilege to Client * Remove some unnecessary casts * create_formspec_menu: remove IWritableTextureSource pointer, as client already knows it * Fix some comments * Change required IGameDef to Server/Client pointers * Previous change that game.cpp sometimes calls functions with Client + InventoryManager + IGameDef in same functions but it's the same objects * Remove duplicate Client pointer in GUIFormSpecMenu::GUIFormSpecMenu
0fb6ab0
to
4734317
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 except mentioned issues
{ return m_env; } | ||
ClientEnvironment& getEnv() { return m_env; } | ||
ITextureSource *tsrc() { return getTextureSource(); } | ||
ISoundManager *sound() { return getSoundManager(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not properly aligned
virtual IShaderSource* getShaderSource(); | ||
virtual scene::ISceneManager* getSceneManager(); | ||
IShaderSource *shsrc() { return getShaderSource(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additional spaces
@@ -766,7 +766,7 @@ void ClientMap::renderPostFx(CameraMode cam_mode) | |||
const ContentFeatures& features = m_nodedef->get(n); | |||
video::SColor post_effect_color = features.post_effect_color; | |||
if(features.solidness == 2 && !(g_settings->getBool("noclip") && | |||
m_gamedef->checkLocalPrivilege("noclip")) && | |||
((Client *) m_gamedef)->checkLocalPrivilege("noclip")) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClientMap
has an m_client
that can be used instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exact, i will fix your issues soon, thanks for notice this
Also: In file included from /tmp/minetest/src/client.cpp:32: In file included from /tmp/minetest/src/client.h:24: /tmp/minetest/src/clientenvironment.h:33:1: warning: class 'PointedThing' was previously declared as a struct [-Wmismatched-tags] class PointedThing; ^ /tmp/minetest/src/util/pointedthing.h:36:8: note: previous use is here struct PointedThing ^ /tmp/minetest/src/clientenvironment.h:33:1: note: did you mean struct here? class PointedThing; ^~~~~ struct and In file included from /tmp/minetest/src/clientmap.cpp:20: In file included from /tmp/minetest/src/clientmap.h:25: In file included from /tmp/minetest/src/camera.h:32: /tmp/minetest/src/client.h:49:1: warning: struct 'PointedThing' was previously declared as a class [-Wmismatched-tags] struct PointedThing; ^ /tmp/minetest/src/clientenvironment.h:33:7: note: previous use is here class PointedThing; ^ |
did i missed to push ? it seems travis doesn't have problems... what is your compiler ? EDIT: Oh it's a warning pointed by clang, will fix, thanks |
@sfan5 i fixed the last points you mentionned and also removed a long time unused function & optimize compilation by not including networkpacket.h in client.h |
Commit 1
Commit 2
Move ITextureSource* IGameDef::getTextureSource() to Client only.
This needs a huge code refactor to use Client* instead of IGameDef* client side to use the right object type everywhere
This permits to remove some irrlicht implicit dependency server side
Commit 3
IGameDef cleanup & misc cleanups
Commit 4
Rename all Server *gamedef & Client *gamedef
Server *game => Server *server
Client *gamedef => Client *client
This also shows that game.cpp sent sometimes Client + InventoryManager + IGameDef in same functions but it's the same objects
Commit 5
Remove duplicate Client pointer in GUIFormSpecMenu::GUIFormSpecMenu
Commit 6