Better way to code?

If something doesn't fit in any other forum then post it here.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
hivitro
Posts: 7
Joined: Sat Nov 13, 2010 6:27 am

Better way to code?

Post by hivitro »

Sorry if this question is so simple.. But

What is the best way to organize and to modify myself the project code, in your experience?

Normally I copy the files of the svn, to other folder, edit them with notepad ++ and support 2 copies of the svn, the original one and the other one that has the changes until they work and implement them in the original svn.

I use Eclipse, and Reading your wiki, undertand how to work the team -> create and apply pach

Because of it I wonder since they do for organizarce better?
Sylar88
Posts: 113
Joined: Sun Feb 06, 2011 6:34 pm

Re: Better way to code?

Post by Sylar88 »

Its pretty much impossible to have an edited pack which will be easily synchronized without conflicts or errors especially if you code big things. When it comes to changing an existing code all you wanna do is listen for events, respond to events or divert the normal execution of function calls.

To listen for events happening inside the l2jserver you can hook the core in multiple key locations with functions from your files. Responding is easier since it happens inside your own functions. Diverting the core to alter the behavior is the most difficult part since it needs the most editing, aka is prone to cause frequent conflicts with the svn updates.

I preffer to use a separate project to implement my changes and hook the l2j core with a set of one-line function calls. Then add dependancies between the two projects and customize the ant building config to look for source code in both projects. That way you can keep your code clean outside the l2j core and hooking will be the only major change you will do.

One extra step can be done to improve divertion control to classes that are implementing interfaces. Take for example a handler. If you want to add extra functionallity to a handler, without changing it at all, you can create your own handler with the same voiced command, replace the old handler and keep a reference to the old one in your new handler from where you will call that old one. Thats a relative method used a lot in C by passing a pointer- to - function so as you can replace the functionallity without changing the existing function.

Thats in general.

Speaking of the devil , checking that atm : http://www.ibm.com/developerworks/java/ ... n0916.html
Gonna come back with a tutorial if i get something interesting and practical in there.

EDIT: It is possible, the previous article works, you can simply inject inside a class before it gets loaded by the jvm. You throw one of your classes to load and do the injection before anything else loads in the server. Bye bye core patches and messed up source :)
Someone who didnt bother reading the svn or ant manual and just waited for you to make him a visual guide for eclipse is not a guy that is willing to learn ... He is the definition of the leecher.
Sylar88
Posts: 113
Joined: Sun Feb 06, 2011 6:34 pm

Re: Better way to code?

Post by Sylar88 »

Confirmed working. You can easily inject code inside compiled classes when they first get loaded from the JVM ( lazy load ).

PS: those guys from aionemu ( nemessis, luno ) had that 2 years ago :( Just noticed that in their commons.
Someone who didnt bother reading the svn or ant manual and just waited for you to make him a visual guide for eclipse is not a guy that is willing to learn ... He is the definition of the leecher.
Post Reply