Some refactoring needed?
#1
Hey,
I´m new to this project and because of this I had to read into many codes.
But what i realized was, that there is often code just copied and pasted instead of creating reusable code / using the benefits of oop.

To give an example, I worked on the water and lava simulator and made them easier.
Code reduced by about 40% and as an additional benefit the simulator is much easier to config because it´s not so "hardcoded".

You can look at it in R108 ( http://code.google.com/p/mc-server/source/detail?r=108 )


What do you mean?
Or am I to reusable / oop fanatic?Big Grin
Reply
Thanks given by:
#2
The reason I use copy paste is when I don't have a clear idea of what the final outcome will be, and that's only when working with other people's concepts.

For example, I'm copy pasting some code in my local version of mcserver because there's slight changes and I'm not sure what the final outcome will be of what variables would be passed through to the function because I don't know 100% of all the other factors pertaining to it.

Top-down design only works when you're starting something new, it's not possible to know every single outcome and parameter when it's pre-existing until you know it, and then you can set it up exactly.

Hope this makes sense.
Reply
Thanks given by:
#3
Agreed, but you pointed to something extreme :p

I don't think you'll find much more of this in the source
Reply
Thanks given by:
#4
Yes, luckily this is something very extremeBig Grin
But this was the code which I wasn´t able to leave untouchedBig Grin

I think one thing could be the cWindow::Clicked but I´m not sure yet. Looks like there is the crafting part implemented in some different windows.
I think I will look into this in the next timeBig Grin

But fixing and adding has a higher priorityBig Grin
Reply
Thanks given by:
#5
With your change I got this warning

cfluidsimulator.cpp(76): warning C4355: 'this' : used in base member initializer list
http://stackoverflow.com/questions/35094...nitializer

It's dangerous. You can fix it by simply removing the initialization of m_Data from the intializer, and putting it in the constructor. Just use m_Data(0) in the intializer.
Reply
Thanks given by:
#6
Ohh,
My faultBig Grin
I will commit this in the next few minutes when the cobblestone thing is testedBig Grin
Reply
Thanks given by:
#7
Ohh Smile
I found something big for refactoringBig Grin
The mobsystem was very C & P ´edBig Grin

http://code.google.com/p/mc-server/source/detail?r=112

Removed bPassiveAggressive
Replaced by cPassiveAggressiveMonster Parentclass
state Aggressive is replaced by AggressiveMonster
and state Passive is replaced by PassiveMonster

This makes it much for easy to add new states because not every behavior is hardcoded in the cMonster class Smile

The cause for looking at it was a bug which caused mobs to follow player in creative mode.
I would had to implement this code for every partially aggressive mob. Now I only had to change the AggressiveMob class Smile
Reply
Thanks given by:
#8
I guessing a lot of you are using VC2010? I say this because every revision I find the makefile to be out of date. Could you fellas update the makefile when you add new files before you commit them?

Oh, and Merry Christmas!
Reply
Thanks given by:
#9
I've done a lot with linux but I'm not on the up and up with makefiles and all. Is there a specific way to auto generic the makefile? If so I could keep it up each revision as I have a Linux VM always ready to go.
Reply
Thanks given by:
#10
Nevermind that, edited the makefile, fixed up some files and got it to compile on Ubuntu 11.

Download page on google code has binary packages for linux and windows and SVN revision 121 is set up to compile with either.

I don't own any macs and don't plan to, so sorry about that.
Reply
Thanks given by:




Users browsing this thread: 15 Guest(s)