Just my 2 cents about your code

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Basiror
Engineer
Engineer
Posts: 12
Joined: 11 Dec 2004 23:26

Just my 2 cents about your code

Post by Basiror »

Hi

I have discovered OpenTTD a few days ago and i am really impressed how similar to the original ttd it was


I also had a look at the source code and i have to say its ugly like hell but well commented

just my 2 cents

- use the hungarian notation
- give it a more Object Oriented touch

Yes sometimes it s just easier and less time consuming to declare a function in the middle to nowhere to simplify a problem

Well thats old C style procedural programming and if you plan to develop openttd further on you might be better with the OOB approach in the long term

In my latest project a 3d world editor i use a very oo way and splitt every problem into smaller ones which greatly improves productivity

maybe we could start a little discussion about the pros and cons here?
Current projects:
- TICBuilder
TICBuilder is a MFC based 3D world editor pretty similar to Q3Radiant or Worldcraft
- War Tycoon *planned*
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

Thank you for the honest criticism.

If you want you can take a look at the map/ branch where hopefully things are looking better. That is almost a complete rewrite of the code.

About the hungarian notation; that is just a matter of preference. Some like it, others don't. We have chosen to use a style-guideline which can also be read in this forum. I'm not sure if we want to change, but even if we do we do not have the time to do such "meaningless" "development" when there are much better things to do.

Same goes for OOP actually. No one has the time to rewrite the whole game and when you get to know the code, after about 1-2 weeks, it is all logical and well-structured and you kinda forget why you wanted OOP in the first place :).
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
User avatar
dominik81
OpenTTD Developer
OpenTTD Developer
Posts: 768
Joined: 16 Aug 2003 12:55
Location: Bonn, Germany

Post by dominik81 »

As Darkvater said, it's a matter of personal prefetence.

Some people like hungarian notation, others don't. I personally don't think it helps to clarify things, it only makes the code less readable. Sure, when you start coding you would have to look up the data type of a variable but with modern development environment that's hardly a problem at all.

Same for object orientation. I'm no friend of oo overkill. Sure, in some places the code should be restructured a bit. But we're more focusing on writing new features than rewriting the old codebase. But I must say that the code is very descriptive. When I first joined the project, I didn't have many problems finding my way around.
"There's a readme that comes with the source. I suggest you read it."
- Korenn
Basiror
Engineer
Engineer
Posts: 12
Joined: 11 Dec 2004 23:26

Post by Basiror »

with oop i don t mean this classis java style oop

i am more thinking about a mixture of c++ oo and c procedural programming

and by no means id do things like this

object:function()
{
2ndobject a;
a.dosomethingreallytrivial();
}

i think ill add a little attachment of something i consider well written code
with a touch of oop

i have attached a zip which contains around 20 header files from my editor project

the entire editor code is inside of the header files and is structured in a way that i can implement it into any gui framework, the entire communication between the editorcode and the guiframe work is done by a few functions

there isn t much done except the grid implementation and a nearly finished workspace with a workzone(which defines the selection area/primitiv creation area

as you see every problem is splitt into functions and added to the object it belongs to

this contributes to a pretty clear code without overwhelming detail

the communication between these classes if at all necessary can be done from the guis framework which holds instances of some of the major classes
Attachments
customheaders.zip
(20.73 KiB) Downloaded 512 times
Current projects:
- TICBuilder
TICBuilder is a MFC based 3D world editor pretty similar to Q3Radiant or Worldcraft
- War Tycoon *planned*
Basiror
Engineer
Engineer
Posts: 12
Joined: 11 Dec 2004 23:26

Post by Basiror »

with the map branch you mean the landscap.c right?

i had a look at it now

sadly there are not very much comments *G* *yeah good old c programming *

there are a lot of trivial functions like changeowner

in oop you could all these functions inside the header file and only add the more important functions to the c/cpp files *you don t have to scroll that much*

but otherwise i can t judge how much work it would be to make it oop style


what do i need to compile it?

zlib, sdl, sourceforge useful headers and?

i think this .dsw is a msvc++ workspace right? since you have stdafx included as well
maybe i should dl it and try porting it to oop to see how time intensive it is
Current projects:
- TICBuilder
TICBuilder is a MFC based 3D world editor pretty similar to Q3Radiant or Worldcraft
- War Tycoon *planned*
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

By the map/ branch I meant checking out the "svn://svn.openttd.org/branch/map" branch.

And as you know OpenTTD is written in C. If we want member functions, etc. it needs to be converted to C++. This means changing all malloc()'s etc. adding a ton of explicit casting, etc. etc.

If you want the bare minimum you just need some compiler; on windows preferrably VS.NET (map branch is not updated for VS6). You can remove zlib, png and sdl, those are not necessary for the code itself.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Basiror
Engineer
Engineer
Posts: 12
Joined: 11 Dec 2004 23:26

Post by Basiror »

i ll have to set up my svn first will take a few days til i have time to do this
Current projects:
- TICBuilder
TICBuilder is a MFC based 3D world editor pretty similar to Q3Radiant or Worldcraft
- War Tycoon *planned*
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Post by fabca2 »

Darkvater wrote:...preferrably VS.NET (map branch is not updated for VS6).

ho no!!!! :(
no, please, please...
maybe you wanted to say : "not updated for VS6 *yet*" :)

Please keep it compilable on that old good VS6 :roll:
or at least when you will merge...
traskjd
Engineer
Engineer
Posts: 40
Joined: 17 Nov 2004 04:18
Location: Wellington, New Zealand
Contact:

Post by traskjd »

Just as a side not - VS.NET != .net based code. You can use non-managed code (as in, not .net) and it would still work fine.

I compile the SVN source in VS.NET 2003 just fine :-)

While .net might make it more readable, I don't see much point when one of the advantages of openTTD is that it runs on many platforms and .net isn't there... yet.

- JD
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

I'm just using VS.NET as the developing environment; nothing more, nothing less. As I am the sole windows converter of map and I don't have VS6 I cannot update it. When it's done bociousz or someone else will probably complain, supply a project-file diff and all's well.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
User avatar
bociusz
Traffic Manager
Traffic Manager
Posts: 131
Joined: 24 Jul 2004 11:04
Location: Hungary
Contact:

Post by bociusz »

Darkvater wrote:As I am the sole windows converter of map and I don't have VS6 I cannot update it. When it's done bociusz or someone else will probably complain, supply a project-file diff and all's well.
Yeah, it's quite hard, because VS6 often do silly things, we tried to make it with Darkvater but we had problems with the vs6 linker...
Basiror
Engineer
Engineer
Posts: 12
Joined: 11 Dec 2004 23:26

Post by Basiror »

do you know a good tutorial about how to setup subversion?
Current projects:
- TICBuilder
TICBuilder is a MFC based 3D world editor pretty similar to Q3Radiant or Worldcraft
- War Tycoon *planned*
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

Just install TortoiseSVN and check out the code from svn://svn.openttd.org/trunk or svn://svn.openttd.org/map

Or look here: http://wiki.openttd.org/index.php/Development:Main_Page or http://wiki.openttd.org/index.php/SVN
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Post by fabca2 »

bociusz wrote:
Darkvater wrote:As I am the sole windows converter of map and I don't have VS6 I cannot update it. When it's done bociusz or someone else will probably complain, supply a project-file diff and all's well.
Yeah, it's quite hard, because VS6 often do silly things, we tried to make it with Darkvater but we had problems with the vs6 linker...
thank you to your effort.
I think not every one have VS.net2003 yet.
and we are all happy to compile source on VS6.
mylife : I 've 2 reasons to avoid switching to VS2003 :
* cost a lot of money (I keep my already paid VS6 "98")
and,
* my machine could not support it I think (PIII-733Mhz only)

thank you for your work !
you can be sure, a lot of people like what you do :)
traskjd
Engineer
Engineer
Posts: 40
Joined: 17 Nov 2004 04:18
Location: Wellington, New Zealand
Contact:

Post by traskjd »

fabca2 wrote: thank you to your effort.
I think not every one have VS.net2003 yet.
and we are all happy to compile source on VS6.
mylife : I 've 2 reasons to avoid switching to VS2003 :
* cost a lot of money (I keep my already paid VS6 "98")
and,
* my machine could not support it I think (PIII-733Mhz only)

thank you for your work !
you can be sure, a lot of people like what you do :)
There have been more than enough people on here who argue things shouldn't move forward because they have a slow system. While I feel for your situation I don't see this as a valuable reason to restrict innovation in OpenTTD. Eventually you'll upgrade at which point you'll be pleased to be able to use all the new features.

Newer version of the Microsoft C++ Compiler actually produce faster more optimised code (in general) so you should ultimatly be pushing harder for devs to use the latest compilers.

Visual Studio 2005 will be available mid next year so even if you did have access to buying VS 2003 I wouldn't bother as VS 2005 is like comparing DOS to XP - it's just such a jump forward.

I've been using VS 2005 beta and previews since around March this year in my personal time and I'm a full time coder in VS 2003 (all .net, hence why I'm not making huge contributions on the unmanaged front) and might get around to seeing how OpenTTD does on the C++ Unmanaged compiler in that since over time windows developers will probably move to that.

- JD
Basiror
Engineer
Engineer
Posts: 12
Joined: 11 Dec 2004 23:26

Post by Basiror »

Darkvater wrote:Just install TortoiseSVN and check out the code from svn://svn.openttd.org/trunk or svn://svn.openttd.org/map

Or look here: http://wiki.openttd.org/index.php/Development:Main_Page or http://wiki.openttd.org/index.php/SVN
ok that worked fine :)

another question

if i want to run svn on my laptop which isn t connected to the internet can i use svn and tell it to dl it from my main computer? so it acts like you svn server?


and yes it compiles fine with msvc++6.0 standard edition + service pack1
i just have to get png and zlib libraries :)

and what about updates ? i create a patch which gets uploaded to the server and one of the svn admins checks if its ok before you apply it right?
Current projects:
- TICBuilder
TICBuilder is a MFC based 3D world editor pretty similar to Q3Radiant or Worldcraft
- War Tycoon *planned*
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Post by fabca2 »

traskjd wrote: There have been more than enough people on here who argue things shouldn't move forward because they have a slow system. While I feel for your situation I don't see this as a valuable reason to restrict innovation in OpenTTD. Eventually you'll upgrade at which point you'll be pleased to be able to use all the new features.

Newer version of the Microsoft C++ Compiler actually produce faster more optimised code (in general) so you should ultimatly be pushing harder for devs to use the latest compilers.
...
ok, ok...
I'm sure there is no link beetween the compilator and the "inovation". I'm allways happy to have new feature in OTTD, the fact it have been compiled with GCC, VS6,VS2k3, VS2k5 will produce the same software.

After that, there is the question of code generation/optimization, ok that's true. will you earn about 5% ? 2% speedup ? not sure.
Depending on the way you code data structure/functions/classes/ you may earn or loss a lot also. a bad design can make your program to wast about 20% of speed... whatever the compiler you use. a smart and very good design can optimize AI about 10% in speed for example...

So we are never sure that compiling OTTD with VS6 or VS2003 will change a LOT.
But I'm really sure that trying to compile it on my system need too much ressources (200%?). I remember I tried to beta version of VS2003 from a magazine few years ago.

If I stay from this old good VS6, (and I'm not the only one) that's because I didn't see a lot of advantage to follow MS with new versions (need new hardware).

PS: for the one who didn't paid VS, remind that MSDN pro for 1 year is about 1200 euro. I paid, now I keep what I got, not plan to pay any more.

PPS: I remember the advertising about VS2003, light was pointed on "webservice", does OTTD use them ? finaly who really use these features ? :)
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

You could just as well use the online MSDN which is actually the same as the bought CD's; and is even free.

VS.NET2003 is a lot easier to use than VS6; as well as having less annoying bugs.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
User avatar
bociusz
Traffic Manager
Traffic Manager
Posts: 131
Joined: 24 Jul 2004 11:04
Location: Hungary
Contact:

Post by bociusz »

Darkvater!

I know that it isn't the proper forum, but I haven't meet you on irc for days. Basiror said: "hm i downloaded the map branch today and it seems to compile fine with msvc++6.0" (Problems forum > Compiling code under windows > reply 2004.12.19 12:42 GMT)
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

bociusz wrote:Darkvater!

I know that it isn't the proper forum, but I haven't meet you on irc for days. Basiror said: "hm i downloaded the map branch today and it seems to compile fine with msvc++6.0" (Problems forum > Compiling code under windows > reply 2004.12.19 12:42 GMT)
Yes, I have read that. Obviously something is borked with your compiler that it does not work. Indeed this is not the proper forum, it's much better to send a PM here.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Ahrefs [Bot] and 14 guests