Skip to content
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

Merged
merged 2 commits into from
Jan 9, 2017

Conversation

nerzhul
Copy link
Member

@nerzhul nerzhul commented Jan 2, 2017

Commit 1

  • Split ClientEnvironment & ServerEnvironment from environment.h (better code separation & more friendly with IDE because those files are very huge)
  • environment.cpp/h now only contains common environment interface
  • 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.

Commit 2

Move ITextureSource* IGameDef::getTextureSource() to Client only.

  • Also move ITextureSource *IGameDef::tsrc() helper

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

  • drop getShaderSource, getSceneManager, getSoundManager & getCamera abstract call
  • drop unused emerge() call
  • cleanup server unused functions (mentionned before)
  • Drop one unused parameter from ContentFeatures::updateTextures

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

  • move checkLocalPrivilege to Client
  • Remove some unnecessary casts
  • create_formspec_menu: remove IWritableTextureSource pointer, as client already knows it
  • Fix some comments

@nerzhul nerzhul added @ Build CMake, build scripts, official builds, compiler and linker errors @ Server / Client / Env. Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements labels Jan 2, 2017
@nerzhul
Copy link
Member Author

nerzhul commented Jan 2, 2017

Note: i didn't fixed the code style issues, it's a pure code move

@rubenwardy
Copy link
Member

rubenwardy commented Jan 2, 2017

As a guess the abstraction of IGameDef is there for a reason - to discourage people from getting the Server or Client

@nerzhul nerzhul changed the title Environment code refactoring Environment & IGameDef code refactoring Jan 2, 2017
@nerzhul
Copy link
Member Author

nerzhul commented Jan 2, 2017

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

@nerzhul
Copy link
Member Author

nerzhul commented Jan 2, 2017

I think it's ready for a review.

To resume:

  • Enhance compilation times
  • Environment source split for client & server
  • IGameDef cleanups which trigger type modifications in many code parts to reflect the real objects types
  • Remove some dead functions & comments

@nerzhul
Copy link
Member Author

nerzhul commented Jan 3, 2017

I addressed some @Zeno- which shows that we sometimes pass duplicates pointers to same objects. All are now fixed.

Please review & merge @sfan5 @Zeno- @sofar @est31

There is no functional change, just re-organization & reducing client-server link + cleanups

Copy link
Contributor

@juhdanad juhdanad left a 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) {
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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,
Copy link
Contributor

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).

Copy link
Member Author

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

Copy link
Member Author

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));
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right i forgot it

Copy link
Member Author

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;
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like previous comment

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017

@juhdanad i fixed all possible points which doesn't need more huge refactoring
For the last points needing more refactoring, we will see in another PR, to limit the changeset size, which is already big

@sofar
Copy link
Contributor

sofar commented Jan 4, 2017

Can't compile (master with this PR git am'd):

In file included from /home/sofar/git/minetest/src/clientenvironment.h:24:0,
                 from /home/sofar/git/minetest/src/collision.cpp:26:
/home/sofar/git/minetest/src/clientobject.h:43:4: error: ‘IrrlichtDevice’ has not been declared
    IrrlichtDevice *irr){}
    ^
/home/sofar/git/minetest/src/clientobject.h:54:17: error: ‘ISceneNode’ in namespace ‘irr::scene’ does not name a type
  virtual scene::ISceneNode *getSceneNode(){return NULL;}
                 ^
/home/sofar/git/minetest/src/clientobject.h:55:17: error: ‘IMeshSceneNode’ in namespace ‘irr::scene’ does not name a type
  virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
                 ^
/home/sofar/git/minetest/src/clientobject.h:56:17: error: ‘IAnimatedMeshSceneNode’ in namespace ‘irr::scene’ does not name a type
  virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}
                 ^
/home/sofar/git/minetest/src/clientobject.h:58:17: error: ‘IBillboardSceneNode’ in namespace ‘irr::scene’ does not name a type
  virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;}
                 ^
In file included from /home/sofar/git/minetest/src/collision.cpp:26:0:
/home/sofar/git/minetest/src/clientenvironment.h:67:3: error: ‘IrrlichtDevice’ has not been declared
   IrrlichtDevice *device);
   ^
/home/sofar/git/minetest/src/clientenvironment.h:140:2: error: ‘IrrlichtDevice’ does not name a type
  IrrlichtDevice *m_irr;
  ^
src/CMakeFiles/minetestserver.dir/build.make:2054: recipe for target 'src/CMakeFiles/minetestserver.dir/collision.cpp.o' failed
make[2]: *** [src/CMakeFiles/minetestserver.dir/collision.cpp.o] Error 1

Did I miss an irrlicht update? I'm on archlinux, 1.8.4 irrlicht.

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017 via email

@juhdanad
Copy link
Contributor

juhdanad commented Jan 4, 2017

In my opinion it is good to go. 👍
(as soon as @sofar's compilation error is solved)

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017

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

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017

@sofar i forced pushed commit 5 with compilation fix, i missed to re-enable -DBUILD_SERVER=1 on my cmake installation

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017

i rebased the branch

@sofar
Copy link
Contributor

sofar commented Jan 4, 2017

stock arch gcc: gcc version 5.3.0 (GCC)

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017

@sofar ignore my compiler question is was a compilation problem with -DENABLE_SERVER=1 and now travis build with server

@sofar
Copy link
Contributor

sofar commented Jan 4, 2017

compiles now.

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017

nice ! just wait for your review now

@nerzhul
Copy link
Member Author

nerzhul commented Jan 4, 2017

rebased since recent commits on master @sofar @Zeno- @juhdanad please re-test

@juhdanad
Copy link
Contributor

juhdanad commented Jan 4, 2017

I have reviewed the conflicting files (since the conflict was with my commit).
Everything is at the correct place, this still should be merged. 👍

@nerzhul
Copy link
Member Author

nerzhul commented Jan 5, 2017

Fixed android build in last commit

@nerzhul
Copy link
Member Author

nerzhul commented Jan 5, 2017

ping @sfan5 @est31 this change is requested to make more cleanups & refactoring in environment, please test it, @Zeno- tested it before last rebase and agreed with this. It's needed if we want to make things cleaner and start to have a best OOP model

@Zeno-
Copy link
Contributor

Zeno- commented Jan 6, 2017

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.

@nerzhul
Copy link
Member Author

nerzhul commented Jan 6, 2017

@sofar @est31 @sfan5 i will now wait 1 day before merging this, please add an eye on it , it's required to make more cleanups & refactors in the code.

Please don't merge more PR modifying environment during this period

@kwolekr
Copy link
Contributor

kwolekr commented Jan 6, 2017

One big question.

Why did you change all of the IGameDefs to Client or Server? This is wrong.

@nerzhul
Copy link
Member Author

nerzhul commented Jan 6, 2017 via email

@nerzhul
Copy link
Member Author

nerzhul commented Jan 8, 2017

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
Copy link
Member

@sfan5 sfan5 left a 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(); }
Copy link
Member

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(); }
Copy link
Member

@sfan5 sfan5 Jan 9, 2017

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")) &&
Copy link
Member

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

Copy link
Member Author

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

@sfan5
Copy link
Member

sfan5 commented Jan 9, 2017

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;
      ^

@nerzhul
Copy link
Member Author

nerzhul commented Jan 9, 2017

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

@nerzhul
Copy link
Member Author

nerzhul commented Jan 9, 2017

@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

@nerzhul nerzhul merged commit 8e7449e into minetest:master Jan 9, 2017
@nerzhul nerzhul deleted the clientenv_split branch June 6, 2017 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Build CMake, build scripts, official builds, compiler and linker errors Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements @ Server / Client / Env. >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants